X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fct.pl;h=a05158289fc80f6fa46837884c91c2152f828ae8;hb=bb800c52769934354b53caa7a81ee52e88e3b4d4;hp=b0f72b43a9d9b876f925ebc25b3d4f12b0d02363;hpb=f536ffb111b455f830b26add666faaeda56f101f;p=kivitendo-erp.git diff --git a/bin/mozilla/ct.pl b/bin/mozilla/ct.pl index b0f72b43a..a05158289 100644 --- a/bin/mozilla/ct.pl +++ b/bin/mozilla/ct.pl @@ -50,6 +50,7 @@ use POSIX qw(strftime); use SL::CT; use SL::CVar; +use SL::DB::Business; use SL::ReportGenerator; require "bin/mozilla/common.pl"; @@ -141,6 +142,14 @@ sub list_names { push @options, $locale->text('Billing/shipping address (zipcode)') . " : $form->{zipcode}" if $form->{addr_zipcode}; push @options, $locale->text('Billing/shipping address (street)') . " : $form->{street}" if $form->{addr_street}; + if ($form->{business_id}) { + my $business = SL::DB::Manager::Business->find_by(id => $form->{business_id}); + if ($business) { + my $label = $form->{IS_CUSTOMER} ? $::locale->text('Customer type') : $::locale->text('Vendor type'); + push @options, $label . " : " . $business->description; + } + } + my @columns = ( 'id', 'name', "$form->{db}number", 'contact', 'phone', 'fax', 'email', 'taxnumber', 'street', 'zipcode' , 'city', @@ -156,7 +165,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'), }, @@ -175,7 +184,8 @@ sub list_names { map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns; - my @hidden_variables = (qw(db status obsolete name contact email cp_name addr_city), "$form->{db}number", @searchable_custom_variables, map { "l_$_" } @columns); + my @hidden_variables = (qw(db status obsolete name contact email cp_name addr_street addr_zipcode addr_city business_id), + "$form->{db}number", @searchable_custom_variables, map { "l_$_" } @columns); my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables); my $callback = build_std_url('action=list_names', grep { $form->{$_} } @hidden_nondefault); $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir}); @@ -208,6 +218,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 +296,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 $::lx_office_conf{system}->{vertreter}; + $form->{ALL_SALESMEN} = $form->{ALL_EMPLOYEES}; $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; $form->{is_admin} = $myconfig{role} eq 'admin'; @@ -334,6 +347,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} && $::lx_office_conf{system}->{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(); @@ -348,16 +384,11 @@ sub add_transaction { # # saving the history # if(!exists $form->{addition}) { # $form->{addition} = "ADD TRANSACTION"; -# $form->save_history($form->dbconnect(\%myconfig)); +# $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); @@ -382,7 +413,7 @@ sub save_and_ap_transaction { if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history &add_transaction; @@ -402,7 +433,7 @@ sub save_and_ar_transaction { if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history &add_transaction; @@ -427,7 +458,7 @@ sub save_and_invoice { if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history &add_transaction; @@ -448,7 +479,7 @@ sub save_and_rfq { if(!exists $form->{addition}) { $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history &add_transaction; @@ -469,7 +500,7 @@ sub save_and_quotation { if(!exists $form->{addition}) { $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history &add_transaction; @@ -495,7 +526,7 @@ sub save_and_order { if(!exists $form->{addition}) { $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; $form->{addition} = "SAVED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history &add_transaction; @@ -514,21 +545,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 +571,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->save_history; } # /saving the history &edit; - exit; + $main::lxdebug->leave_sub(); + ::end_of_request(); } sub delete { @@ -593,14 +603,11 @@ sub delete { 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->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,8 +659,7 @@ 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(); }