Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 80a6d456

Von Thomas Heck vor fast 11 Jahren hinzugefügt

  • ID 80a6d456aa9f6222316394a79e3f2f31b6078110
  • Vorgänger 21243e6b
  • Nachfolger 96ca0b88

Nicht mehr benötigten Code aus bin/ct.pl entfernt

Unterschiede anzeigen:

bin/mozilla/ct.pl
412 412
  $::lxdebug->leave_sub;
413 413
}
414 414

  
415
sub edit {
416
  $main::lxdebug->enter_sub();
417

  
418
  $main::auth->assert('customer_vendor_edit');
419

  
420
  my $form     = $main::form;
421
  my %myconfig = %main::myconfig;
422

  
423
  # show history button
424
  $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
425
  #/show hhistory button
426

  
427
  CT->get_tuple(\%myconfig, \%$form);
428
  CT->populate_drop_down_boxes(\%myconfig, \%$form);
429

  
430
  $form->{title} = "Edit";
431

  
432
  # format discount
433
  $form->{discount} *= 100;
434
  # format uri
435
  $form->{homepage} = 'http://' . $form->{homepage} unless ((!$form->{homepage}) || $form->{homepage} =~ m|^https?://|);
436

  
437
  &form_header;
438
  &form_footer;
439

  
440
  $main::lxdebug->leave_sub();
441
}
442

  
443
sub _shipto_label {
444
  my $s = shift(@_);
445
  join('; ', grep { $_ } map { $s->{"shipto$_"} } qw(name department_1 street city)) || ' '
446
}
447

  
448
sub _contacts_label {
449
  join ", ", grep { $_ } $_[0]->{cp_name}, $_[0]->{cp_givenname};
450
}
451

  
452
sub form_header {
453
  $main::lxdebug->enter_sub();
454

  
455
  $main::auth->assert('customer_vendor_edit');
456

  
457
  my $form     = $main::form;
458
  my %myconfig = %main::myconfig;
459
  my $locale   = $main::locale;
460

  
461
  $form->get_lists(taxzones   => "ALL_TAXZONES",
462
                   currencies => "ALL_CURRENCIES");
463
  $form->get_pricegroup(\%myconfig, { all => 1 });
464

  
465
  $form->get_lists(customers => { key => "ALL_SALESMAN_CUSTOMERS", business_is_salesman => 1 }) if $::instance_conf->get_vertreter;
466
  $form->{ALL_EMPLOYEES}          = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{FU_created_for_user},  deleted => 0 ] ]);
467
  $form->{ALL_SALESMEN}           = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{salesman_id},  deleted => 0 ] ]);
468
  $form->{USER}                   = SL::DB::Manager::Employee->current;
469

  
470
  $form->{ALL_DELIVERY_TERMS}     = SL::DB::Manager::DeliveryTerm->get_all_sorted();
471

  
472
  $form->{taxincluded}    = ($form->{taxincluded}) ? "checked" : "";
473
  $form->{is_customer}    = $form->{db}     eq 'customer';
474
  $form->{shipto_label}   = \&_shipto_label;
475
  $form->{contacts_label} = \&_contacts_label;
476
  $form->{taxzone_id}     = 0                                                               if !$form->{id};
477
  $form->{SHIPTO_ALL}     = [ +{ shipto_id => '0', shiptoname => $::locale->text('All') }, @{ $form->{SHIPTO} } ];
478

  
479
  $form->{title} = $form->{title_save}
480
                || $locale->text("$form->{title} " . ucfirst $form->{db}) . ($form->{title} eq "Edit" ? " $form->{name}" : '');
481

  
482
  CT->query_titles_and_greetings(\%myconfig, \%$form);
483
  map { $form->{"MB_$_"} = [ map +{ id => $_, description => $_ }, @{ $form->{$_} } ] } qw(COMPANY_GREETINGS);
484

  
485
  $form->{NOTES} ||= [ ];
486

  
487
  if (!$form->{'language_id'}) {
488
    my $l_id = SL::DB::Default->get->{'language_id'};
489
    if ($l_id) {
490
      $form->{'default_language_id'} = $l_id;
491
    }
492
  }
493

  
494
  if (!$form->{'id'}) {
495
    $form->{'currency'} = $form->get_default_currency(\%myconfig);
496
  } else {
497
    $form->{currency} = $form->{curr};
498
  }
499

  
500
  $::form->{CUSTOM_VARIABLES} = { };
501
  my %specs = ( CT       => { field => 'id',    name_prefix => '',   },
502
                Contacts => { field => 'cp_id', name_prefix => 'cp', },
503
              );
504

  
505
  for my $module (keys %specs) {
506
    my $spec = $specs{$module};
507

  
508
    $::form->{CUSTOM_VARIABLES}->{$module} = CVar->get_custom_variables(module => $module, trans_id => $::form->{ $spec->{field} });
509
    CVar->render_inputs(variables => $::form->{CUSTOM_VARIABLES}->{$module}, name_prefix => $spec->{name_prefix})
510
      if scalar @{ $::form->{CUSTOM_VARIABLES}->{$module} };
511
  }
512

  
513
  $form->header;
514
  print $form->parse_html_template('ct/form_header');
515

  
516
  $main::lxdebug->leave_sub();
517
}
518

  
519
sub form_footer {
520
  $main::lxdebug->enter_sub();
521

  
522
  $main::auth->assert('customer_vendor_edit');
523

  
524
  my $form     = $main::form;
525

  
526
  print $form->parse_html_template('ct/form_footer', { is_orphaned => $form->{status} eq 'orphaned',
527
                                                       is_customer => $form->{db}     eq 'customer' });
528
  $main::lxdebug->leave_sub();
529
}
530

  
531
sub _do_save {
532
  $main::auth->assert('customer_vendor_edit');
533

  
534
  $::form->isblank("name", $::locale->text("Name missing!"));
535

  
536
  if ($::form->{new_salesman_id} && $::instance_conf->get_vertreter) {
537
    $::form->{salesman_id} = $::form->{new_salesman_id};
538
    delete $::form->{new_salesman_id};
539
  }
540

  
541
  my $res = $::form->{db} eq 'customer' ? CT->save_customer(\%::myconfig, $::form) : CT->save_vendor(\%::myconfig, $::form);
542

  
543
  if (3 == $res) {
544
    if ($::form->{"db"} eq "customer") {
545
      $::form->error($::locale->text('This customer number is already in use.'));
546
    } else {
547
      $::form->error($::locale->text('This vendor number is already in use.'));
548
    }
549
  }
550
}
551

  
552
sub add_transaction {
553
  $main::lxdebug->enter_sub();
554

  
555
  $main::auth->assert('customer_vendor_edit & ' .
556
                '(general_ledger         | invoice_edit         | vendor_invoice_edit | ' .
557
                ' request_quotation_edit | sales_quotation_edit | sales_order_edit    | purchase_order_edit)');
558

  
559
  my $form     = $main::form;
560
  my %myconfig = %main::myconfig;
561
  my $locale   = $main::locale;
562

  
563
#  # saving the history
564
#  if(!exists $form->{addition}) {
565
#    $form->{addition} = "ADD TRANSACTION";
566
#    $form->save_history;
567
#  }
568
#  # /saving the history
569

  
570
  _do_save();
571

  
572
  $form->{callback} = $form->escape($form->{callback}, 1);
573
  my $name = $form->escape("$form->{name}", 1);
574

  
575
  $form->{callback} =
576
    "$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
577
  $form->redirect;
578

  
579
  $main::lxdebug->leave_sub();
580
}
581

  
582
sub save_and_ap_transaction {
583
  $main::lxdebug->enter_sub();
584

  
585
  $main::auth->assert('customer_vendor_edit & general_ledger');
586

  
587
  my $form     = $main::form;
588
  my %myconfig = %main::myconfig;
589

  
590
  $form->{script} = "ap.pl";
591
  # saving the history
592
  if(!exists $form->{addition}) {
593
    $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
594
    $form->{addition} = "SAVED";
595
    $form->save_history;
596
  }
597
  # /saving the history
598
  &add_transaction;
599
  $main::lxdebug->leave_sub();
600
}
601

  
602
sub save_and_ar_transaction {
603
  $main::lxdebug->enter_sub();
604

  
605
  $main::auth->assert('customer_vendor_edit & general_ledger');
606

  
607
  my $form     = $main::form;
608
  my %myconfig = %main::myconfig;
609

  
610
  $form->{script} = "ar.pl";
611
  # saving the history
612
  if(!exists $form->{addition}) {
613
    $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
614
    $form->{addition} = "SAVED";
615
    $form->save_history;
616
  }
617
  # /saving the history
618
  &add_transaction;
619
  $main::lxdebug->leave_sub();
620
}
621

  
622
sub save_and_invoice {
623
  $main::lxdebug->enter_sub();
624

  
625
  my $form     = $main::form;
626
  my %myconfig = %main::myconfig;
627

  
628
  if ($form->{db} eq 'customer') {
629
    $main::auth->assert('customer_vendor_edit & invoice_edit');
630
  } else {
631
    $main::auth->assert('customer_vendor_edit & vendor_invoice_edit');
632
  }
633

  
634
  $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
635
  $form->{type} = "invoice";
636
  # saving the history
637
  if(!exists $form->{addition}) {
638
    $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
639
    $form->{addition} = "SAVED";
640
    $form->save_history;
641
  }
642
  # /saving the history
643
  &add_transaction;
644
  $main::lxdebug->leave_sub();
645
}
646

  
647
sub save_and_rfq {
648
  $main::lxdebug->enter_sub();
649

  
650
  $main::auth->assert('customer_vendor_edit & request_quotation_edit');
651

  
652
  my $form     = $main::form;
653
  my %myconfig = %main::myconfig;
654

  
655
  $form->{script} = "oe.pl";
656
  $form->{type}   = "request_quotation";
657
  # saving the history
658
  if(!exists $form->{addition}) {
659
    $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
660
    $form->{addition} = "SAVED";
661
    $form->save_history;
662
  }
663
  # /saving the history
664
  &add_transaction;
665
  $main::lxdebug->leave_sub();
666
}
667

  
668
sub save_and_quotation {
669
  $main::lxdebug->enter_sub();
670

  
671
  $main::auth->assert('customer_vendor_edit & sales_quotation_edit');
672

  
673
  my $form     = $main::form;
674
  my %myconfig = %main::myconfig;
675

  
676
  $form->{script} = "oe.pl";
677
  $form->{type}   = "sales_quotation";
678
  # saving the history
679
  if(!exists $form->{addition}) {
680
    $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
681
    $form->{addition} = "SAVED";
682
    $form->save_history;
683
  }
684
  # /saving the history
685
  &add_transaction;
686
  $main::lxdebug->leave_sub();
687
}
688

  
689
sub save_and_order {
690
  $main::lxdebug->enter_sub();
691

  
692
  my $form     = $main::form;
693
  my %myconfig = %main::myconfig;
694

  
695
  if ($form->{db} eq 'customer') {
696
    $main::auth->assert('customer_vendor_edit & sales_order_edit');
697
  } else {
698
    $main::auth->assert('customer_vendor_edit & purchase_order_edit');
699
  }
700

  
701
  $form->{script} = "oe.pl";
702
  $form->{type}   =
703
    ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
704
  # saving the history
705
  if(!exists $form->{addition}) {
706
    $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
707
    $form->{addition} = "SAVED";
708
    $form->save_history;
709
  }
710
  # /saving the history
711
  &add_transaction;
712
  $main::lxdebug->leave_sub();
713
}
714

  
715
sub save_and_close {
716
  $main::lxdebug->enter_sub();
717

  
718
  $main::auth->assert('customer_vendor_edit');
719

  
720
  my $form     = $main::form;
721
  my %myconfig = %main::myconfig;
722
  my $locale   = $main::locale;
723

  
724
  my $msg = ucfirst $form->{db};
725
  $msg .= " saved!";
726

  
727
  _do_save();
728

  
729
  # saving the history
730
  if(!exists $form->{addition}) {
731
    $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
732
    $form->{addition} = "SAVED";
733
    $form->save_history;
734
  }
735
  # /saving the history
736
  $form->redirect($locale->text($msg));
737

  
738
  $main::lxdebug->leave_sub();
739
}
740

  
741
sub save {
742
  $main::lxdebug->enter_sub();
743

  
744
  $main::auth->assert('customer_vendor_edit');
745

  
746
  my $form     = $main::form;
747
  my %myconfig = %main::myconfig;
748
  my $locale   = $main::locale;
749

  
750
  my $msg = ucfirst $form->{db};
751
  $msg .= " saved!";
752

  
753
  _do_save();
754

  
755
  # saving the history
756
  if(!exists $form->{addition}) {
757
    $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
758
    $form->{addition} = "SAVED";
759
    $form->save_history;
760
  }
761
  # /saving the history
762
  &edit;
763

  
764
  $main::lxdebug->leave_sub();
765
  ::end_of_request();
766
}
767

  
768
sub delete {
769
  $main::lxdebug->enter_sub();
770

  
771
  $main::auth->assert('customer_vendor_edit');
772

  
773
  my $form     = $main::form;
774
  my %myconfig = %main::myconfig;
775
  my $locale   = $main::locale;
776

  
777
  CT->delete(\%myconfig, \%$form);
778

  
779
  my $msg = ucfirst $form->{db};
780
  $msg .= " deleted!";
781
  # saving the history
782
  if(!exists $form->{addition}) {
783
    $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
784
    $form->{addition} = "DELETED";
785
    $form->save_history;
786
  }
787
  # /saving the history
788
  $form->redirect($locale->text($msg));
789

  
790
  $main::lxdebug->leave_sub();
791
}
792

  
793
sub display {
794
  $main::lxdebug->enter_sub();
795

  
796
  $main::auth->assert('customer_vendor_edit');
797

  
798
  my $form     = $main::form;
799

  
800
  &form_header();
801
  &form_footer();
802

  
803
  $main::lxdebug->leave_sub();
804
}
805

  
806
sub update {
807
  $main::lxdebug->enter_sub();
808

  
809
  $main::auth->assert('customer_vendor_edit');
810

  
811
  my $form     = $main::form;
812

  
813
  &display();
814
  $main::lxdebug->leave_sub();
815
}
816

  
817
sub get_contact {
818
  $main::lxdebug->enter_sub();
819

  
820
  $main::auth->assert('customer_vendor_edit');
821

  
822
  CT->populate_drop_down_boxes(\%::myconfig, $::form);
823
  CT->query_titles_and_greetings(\%::myconfig, $::form);
824
  CT->get_contact(\%::myconfig, $::form) if $::form->{cp_id};
825

  
826
  $::form->{CUSTOM_VARIABLES}{Contacts} = CVar->get_custom_variables(module => 'Contacts', trans_id => $::form->{cp_id});
827
  CVar->render_inputs(variables => $::form->{CUSTOM_VARIABLES}{Contacts}, name_prefix => 'cp')
828
    if scalar @{ $::form->{CUSTOM_VARIABLES}->{Contacts} };
829

  
830
  $::form->{contacts_label} = \&_contacts_label;
831

  
832
  print $::form->ajax_response_header(), $::form->parse_html_template('ct/_contact');
833

  
834
  $main::lxdebug->leave_sub();
835
}
836

  
837
sub get_shipto {
838
  $main::lxdebug->enter_sub();
839

  
840
  $main::auth->assert('customer_vendor_edit');
841

  
842
  CT->populate_drop_down_boxes(\%::myconfig, $::form);
843
  CT->get_shipto(\%::myconfig, $::form) if $::form->{shipto_id};
844

  
845
  $::form->{shipto_label} = \&_shipto_label;
846

  
847
  print $::form->ajax_response_header(), $::form->parse_html_template('ct/_shipto');
848

  
849
  $main::lxdebug->leave_sub();
850
}
851

  
852
sub get_delivery {
853
  $::lxdebug->enter_sub;
854

  
855
  $::auth->assert('customer_vendor_edit');
856
  $::auth->assert('sales_all_edit');
857

  
858
  CT->get_delivery(\%::myconfig, $::form );
859

  
860
  print $::form->ajax_response_header,
861
        $::form->parse_html_template('ct/get_delivery', {
862
          is_customer =>  $::form->{db} eq 'customer',
863
        });
864

  
865
  $::lxdebug->leave_sub;
866
}
867

  
868
sub delete_shipto {
869
  $::lxdebug->enter_sub;
870
  $::auth->assert('customer_vendor_edit');
871

  
872
  if (!$::form->{shipto_id}) {
873
    flash('error', $::locale->text('No shipto selected to delete'));
874
  } else {
875

  
876
    CT->get_shipto(\%::myconfig, $::form);
877

  
878
    my $shipto = SL::DB::Manager::Shipto->find_by(shipto_id => $::form->{shipto_id});
879

  
880
    if ($shipto->used) {
881
      $shipto->detach->save;
882
      flash('info', $::locale->text('Shipto is in use and was flagged invalid.'));
883
    } else {
884
      $shipto->delete;
885
      flash('info', $::locale->text('Shipto deleted.'));
886
    }
887
    delete $::form->{$_} for grep /^shipto/, keys %$::form;
888
  }
889

  
890
  edit();
891

  
892
  $::lxdebug->leave_sub;
893
}
894

  
895
sub delete_contact {
896
  $::lxdebug->enter_sub;
897
  $::auth->assert('customer_vendor_edit');
898

  
899
  if (!$::form->{cp_id}) {
900
    flash('error', $::locale->text('No contact selected to delete'));
901
  } else {
902

  
903
    CT->get_contact(\%::myconfig, $::form);
904

  
905
    my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id});
906

  
907
    if ($contact->used) {
908
      $contact->detach->save;
909
      flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
910
    } else {
911
      $contact->delete;
912
      flash('info', $::locale->text('Contact deleted.'));
913
    }
914
    delete $::form->{$_} for grep /^cp_/, keys %$::form;
915
  }
916

  
917
  edit();
918

  
919
  $::lxdebug->leave_sub;
920
}
921

  
922
sub ajax_autocomplete {
923
  $main::lxdebug->enter_sub();
924

  
925
  my $form     = $main::form;
926
  my %myconfig = %main::myconfig;
927

  
928
  $form->{column}          = 'name'     unless $form->{column} =~ /^name$/;
929
  $form->{vc}              = 'customer' unless $form->{vc} =~ /^customer|vendor$/;
930
  $form->{db}              = $form->{vc}; # CT expects this
931
  $form->{$form->{column}} = $form->{q}           || '';
932
  $form->{limit}           = ($form->{limit} * 1) || 10;
933
  $form->{searchitems}   ||= '';
934

  
935
  CT->search(\%myconfig, $form);
936

  
937
  print $form->ajax_response_header(),
938
        $form->parse_html_template('ct/ajax_autocomplete');
939

  
940
  $main::lxdebug->leave_sub();
941
}
942

  
943 415
sub continue { call_sub($main::form->{nextsub}); }

Auch abrufbar als: Unified diff