- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $form->get_lists("employees" => "ALL_EMPLOYEES",
- "taxzones" => "ALL_TAXZONES");
- $form->get_pricegroup(\%myconfig, { all => 1 });
-
- $form->{ALL_SALESMEN} = $form->{ALL_EMPLOYEES};
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
- $form->{is_admin} = $myconfig{role} eq 'admin';
- $form->{is_customer} = $form->{db} eq 'customer';
- $form->{salesman_label} = sub { $_[0]->{name} ne "" ? $_[0]->{name} : $_[0]->{login} };
- $form->{shipto_label} = sub { my $s = shift(@_); join('; ', grep { $_ } map { $s->{"shipto$_"} } qw(name department_1 street city)) || ' ' };
- $form->{contacts_label} = sub { join ", ", grep { $_ } $_[0]->{cp_name}, $_[0]->{cp_givenname} };
- $form->{taxzone_id} = 0 if !$form->{id};
- $form->{jsscript} = 1;
- $form->{fokus} = "ct.greeting";
- $form->{AJAX} = [ new CGI::Ajax( map {; "get_$_" => "$form->{script}?action=get_$_" } qw(shipto contact delivery) ) ];
-
- unshift @{ $form->{SHIPTO} }, +{ shipto_id => '0', shiptoname => '' }, +{ shipto_id => '0', shiptoname => 'Alle' };
- unshift @{ $form->{CONTACTS} }, +{ cp_id => '0', cp_name => $locale->text('New contact') };
-
- $form->{title} = $form->{title_save}
- || $locale->text("$form->{title} " . ucfirst $form->{db}) . ($form->{title} eq "Edit" ? " $form->{name}" : '');
-
- CT->query_titles_and_greetings(\%myconfig, \%$form);
- map { $form->{"MB_$_"} = [ map +{ id => $_, description => $_ }, @{ $form->{$_} } ] } qw(TITLES GREETINGS COMPANY_GREETINGS DEPARTMENT);
-
- $form->{NOTES} ||= [ ];
-
- $form->{CUSTOM_VARIABLES} = CVar->get_custom_variables('module' => 'CT', 'trans_id' => $form->{id});
-
- CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}) if (scalar @{ $form->{CUSTOM_VARIABLES} });
-
- $form->header;
- print $form->parse_html_template('ct/form_header');
-
- $main::lxdebug->leave_sub();
-}
-
-sub form_footer {
- $main::lxdebug->enter_sub();
-
- $main::auth->assert('customer_vendor_edit');
-
- my $form = $main::form;
-
- print $form->parse_html_template('ct/form_footer', { is_orphaned => $form->{status} eq 'orphaned',
- is_customer => $form->{db} eq 'customer' });
- $main::lxdebug->leave_sub();
-}
-
-sub add_transaction {
- $main::lxdebug->enter_sub();
-
- $main::auth->assert('customer_vendor_edit & ' .
- '(general_ledger | invoice_edit | vendor_invoice_edit | ' .
- ' request_quotation_edit | sales_quotation_edit | sales_order_edit | purchase_order_edit)');
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
-# # saving the history
-# if(!exists $form->{addition}) {
-# $form->{addition} = "ADD TRANSACTION";
-# $form->save_history($form->dbconnect(\%myconfig));
-# }
-# # /saving the history
-
- $form->isblank("name", $locale->text("Name missing!"));
- if ($form->{"db"} eq "customer") {
- CT->save_customer(\%myconfig, \%$form);
- } else {
- CT->save_vendor(\%myconfig, \%$form);
- }
-
- $form->{callback} = $form->escape($form->{callback}, 1);
- my $name = $form->escape("$form->{name}", 1);
-
- $form->{callback} =
- "$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
- $form->redirect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_and_ap_transaction {
- $main::lxdebug->enter_sub();
-
- $main::auth->assert('customer_vendor_edit & general_ledger');
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
-
- $form->{script} = "ap.pl";
- # saving the history
- if(!exists $form->{addition}) {
- $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
- $form->{addition} = "SAVED";
- $form->save_history($form->dbconnect(\%myconfig));
- }
- # /saving the history
- &add_transaction;
- $main::lxdebug->leave_sub();
-}
-
-sub save_and_ar_transaction {
- $main::lxdebug->enter_sub();
-
- $main::auth->assert('customer_vendor_edit & general_ledger');