X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fct.pl;h=63aa8313f7a15b5ccf3f5bf430b3ddcdea63c8fa;hb=afed390f75f0dad7df9d5aa5fbdac8f3005c852e;hp=10ff70675c38e89ff7e58405168decfa233f7c0b;hpb=57bf9c89a037036fcf433de39643778854defe51;p=kivitendo-erp.git diff --git a/bin/mozilla/ct.pl b/bin/mozilla/ct.pl index 10ff70675..63aa8313f 100644 --- a/bin/mozilla/ct.pl +++ b/bin/mozilla/ct.pl @@ -156,7 +156,7 @@ sub list_names { my %column_defs = ( 'id' => { 'text' => $locale->text('ID'), }, "$form->{db}number" => { 'text' => $locale->text('Number'), }, - 'name' => { 'text' => $locale->text('Name'), }, + 'name' => { 'text' => $form->{IS_CUSTOMER} ? $::locale->text('Customer Name') : $::locale->text('Vendor Name'), }, 'contact' => { 'text' => $locale->text('Contact'), }, 'phone' => { 'text' => $locale->text('Phone'), }, 'fax' => { 'text' => $locale->text('Fax'), }, @@ -208,6 +208,7 @@ sub list_names { 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time), ); $report->set_options_from_form(); + $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv'; $report->set_columns(%column_defs); $report->set_column_order(@columns); @@ -285,10 +286,12 @@ sub form_header { my %myconfig = %main::myconfig; my $locale = $main::locale; - $form->get_lists("employees" => "ALL_EMPLOYEES", - "taxzones" => "ALL_TAXZONES"); + $form->get_lists(employees => "ALL_EMPLOYEES", + taxzones => "ALL_TAXZONES"); $form->get_pricegroup(\%myconfig, { all => 1 }); + $form->get_lists(customers => { key => "ALL_SALESMAN_CUSTOMERS", business_is_salesman => 1 }) if $::vertreter; + $form->{ALL_SALESMEN} = $form->{ALL_EMPLOYEES}; $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; $form->{is_admin} = $myconfig{role} eq 'admin'; @@ -334,6 +337,29 @@ sub form_footer { $main::lxdebug->leave_sub(); } +sub _do_save { + $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)'); + + $::form->isblank("name", $::locale->text("Name missing!")); + + if ($::form->{new_salesman_id} && $::vertreter) { + $::form->{salesman_id} = $::form->{new_salesman_id}; + delete $::form->{new_salesman_id}; + } + + my $res = $::form->{db} eq 'customer' ? CT->save_customer(\%::myconfig, $::form) : CT->save_vendor(\%::myconfig, $::form); + + if (3 == $res) { + if ($::form->{"db"} eq "customer") { + $::form->error($::locale->text('This customer number is already in use.')); + } else { + $::form->error($::locale->text('This vendor number is already in use.')); + } + } +} + sub add_transaction { $main::lxdebug->enter_sub(); @@ -347,17 +373,12 @@ sub add_transaction { # # saving the history # if(!exists $form->{addition}) { -# $form->{addition} = "ADD TRANSACTION"; -# $form->save_history($form->dbconnect(\%myconfig)); +# $form->{addition} = "ADD TRANSACTION"; +# $form->save_history; # } # # /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); - } + _do_save(); $form->{callback} = $form->escape($form->{callback}, 1); my $name = $form->escape("$form->{name}", 1); @@ -381,8 +402,8 @@ sub save_and_ap_transaction { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "SAVED"; + $form->save_history; } # /saving the history &add_transaction; @@ -401,8 +422,8 @@ sub save_and_ar_transaction { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "SAVED"; + $form->save_history; } # /saving the history &add_transaction; @@ -426,8 +447,8 @@ sub save_and_invoice { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "SAVED"; + $form->save_history; } # /saving the history &add_transaction; @@ -447,8 +468,8 @@ sub save_and_rfq { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; - $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "SAVED"; + $form->save_history; } # /saving the history &add_transaction; @@ -468,8 +489,8 @@ sub save_and_quotation { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; - $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "SAVED"; + $form->save_history; } # /saving the history &add_transaction; @@ -494,8 +515,8 @@ sub save_and_order { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; - $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "SAVED"; + $form->save_history; } # /saving the history &add_transaction; @@ -514,21 +535,13 @@ sub save_and_close { my $msg = ucfirst $form->{db}; $msg .= " saved!"; - $form->isblank("name", $locale->text("Name missing!")); - my $rc; - if ($form->{"db"} eq "customer") { - $rc = CT->save_customer(\%myconfig, \%$form); - } else { - $rc = CT->save_vendor(\%myconfig, \%$form); - } - if ($rc == 3) { - $form->error($locale->text('customernumber not unique!')); - } + _do_save(); + # saving the history if(!exists $form->{addition}) { $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber}); $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history $form->redirect($locale->text($msg)); @@ -548,32 +561,19 @@ sub save { my $msg = ucfirst $form->{db}; $msg .= " saved!"; - $form->isblank("name", $locale->text("Name missing!")); + _do_save(); - my $res; - if ($form->{"db"} eq "customer") { - $res = CT->save_customer(\%myconfig, \%$form); - } else { - $res = CT->save_vendor(\%myconfig, \%$form); - } - - if (3 == $res) { - if ($form->{"db"} eq "customer") { - $form->error($locale->text('This customer number is already in use.')); - } else { - $form->error($locale->text('This vendor number is already in use.')); - } - } # saving the history if(!exists $form->{addition}) { $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber}); - $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "SAVED"; + $form->save_history; } # /saving the history &edit; - exit; + $main::lxdebug->leave_sub(); + ::end_of_request(); } sub delete { @@ -592,15 +592,12 @@ sub delete { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber}); - $form->{addition} = "DELETED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "DELETED"; + $form->save_history; } # /saving the history $form->redirect($locale->text($msg)); - $msg = "Cannot delete $form->{db}"; - $form->error($locale->text($msg)); - $main::lxdebug->leave_sub(); } @@ -652,26 +649,25 @@ sub get_shipto { my %myconfig = %main::myconfig; CT->get_shipto(\%myconfig, \%$form); - print $form->ajax_response_header(), join '__pjx__', map $form->{"shipto$_"}, - qw(name department_1 department_2 street zipcode city country contact phone fax email used); + print $form->ajax_response_header(), join('__pjx__', map($form->{"shipto$_"}, qw(name department_1 department_2 street zipcode city country contact phone fax email used))); $main::lxdebug->leave_sub(); } sub get_delivery { - $main::lxdebug->enter_sub(); - - $main::auth->assert('customer_vendor_edit'); + $::lxdebug->enter_sub; - my $form = $main::form; - my %myconfig = %main::myconfig; + $::auth->assert('customer_vendor_edit'); + $::auth->assert('sales_all_edit'); - CT->get_delivery(\%myconfig, \%$form ); - $form->{IS_CUSTOMER} = $form->{db} eq 'customer'; + CT->get_delivery(\%::myconfig, $::form ); - print $form->ajax_response_header(), $form->parse_html_template('ct/get_delivery'); + print $::form->ajax_response_header, + $::form->parse_html_template('ct/get_delivery', { + is_customer => $::form->{db} eq 'customer', + }); - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub delete_shipto { @@ -714,4 +710,25 @@ sub delete_contact { $main::lxdebug->leave_sub(); } +sub ajax_autocomplete { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $form->{column} = 'name' unless $form->{column} =~ /^name$/; + $form->{vc} = 'customer' unless $form->{vc} =~ /^customer|vendor$/; + $form->{db} = $form->{vc}; # CT expects this + $form->{$form->{column}} = $form->{q} || ''; + $form->{limit} = ($form->{limit} * 1) || 10; + $form->{searchitems} ||= ''; + + CT->search(\%myconfig, $form); + + print $form->ajax_response_header(), + $form->parse_html_template('ct/ajax_autocomplete'); + + $main::lxdebug->leave_sub(); +} + sub continue { call_sub($main::form->{nextsub}); }