1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
   9 # Copyright (c) 1998-2002
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  15 #  Contributors: Reed White <alta@alta-research.com>
 
  17 # This program is free software; you can redistribute it and/or modify
 
  18 # it under the terms of the GNU General Public License as published by
 
  19 # the Free Software Foundation; either version 2 of the License, or
 
  20 # (at your option) any later version.
 
  22 # This program is distributed in the hope that it will be useful,
 
  23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  25 # GNU General Public License for more details.
 
  26 # You should have received a copy of the GNU General Public License
 
  27 # along with this program; if not, write to the Free Software
 
  28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  29 #======================================================================
 
  31 # customer/vendor module
 
  33 #======================================================================
 
  35 # $locale->text('Customers')
 
  36 # $locale->text('Vendors')
 
  37 # $locale->text('Add Customer')
 
  38 # $locale->text('Add Vendor')
 
  39 # $locale->text('Edit Customer')
 
  40 # $locale->text('Edit Vendor')
 
  41 # $locale->text('Customer saved!')
 
  42 # $locale->text('Vendor saved!')
 
  43 # $locale->text('Customer deleted!')
 
  44 # $locale->text('Cannot delete customer!')
 
  45 # $locale->text('Vendor deleted!')
 
  46 # $locale->text('Cannot delete vendor!')
 
  48 use POSIX qw(strftime);
 
  54 use SL::Helper::Flash;
 
  55 use SL::ReportGenerator;
 
  57 require "bin/mozilla/common.pl";
 
  58 require "bin/mozilla/reportgenerator.pl";
 
  66   $main::lxdebug->enter_sub();
 
  68   $main::auth->assert('customer_vendor_edit');
 
  70   my $form     = $main::form;
 
  71   my %myconfig = %main::myconfig;
 
  73   $form->{title}    = "Add";
 
  74   $form->{callback} = "$form->{script}?action=add&db=$form->{db}" unless $form->{callback};
 
  76   CT->populate_drop_down_boxes(\%myconfig, \%$form);
 
  81   $main::lxdebug->leave_sub();
 
  85   $main::lxdebug->enter_sub();
 
  87   $main::auth->assert('customer_vendor_edit');
 
  89   my $form     = $main::form;
 
  90   my $locale   = $main::locale;
 
  92   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
  94   $form->get_lists("business_types" => "ALL_BUSINESS_TYPES");
 
  95   $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
 
  97   $form->{CUSTOM_VARIABLES}                  = CVar->get_configs('module' => 'CT');
 
  98   ($form->{CUSTOM_VARIABLES_FILTER_CODE},
 
  99    $form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables'      => $form->{CUSTOM_VARIABLES},
 
 100                                                                            'include_prefix' => 'l_',
 
 101                                                                            'include_value'  => 'Y');
 
 103   $form->{jsscript} = 1;
 
 104   $form->{title}    = $form->{IS_CUSTOMER} ? $locale->text('Customers') : $locale->text('Vendors');
 
 105   $form->{fokus}    = 'Form.name';
 
 108   print $form->parse_html_template('ct/search');
 
 110   $main::lxdebug->leave_sub();
 
 114   $main::lxdebug->enter_sub();
 
 116   $main::auth->assert('customer_vendor_edit');
 
 118   my $form     = $main::form;
 
 119   my %myconfig = %main::myconfig;
 
 120   my $locale   = $main::locale;
 
 122   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
 124   report_generator_set_default_sort('name', 1);
 
 126   CT->search(\%myconfig, \%$form);
 
 128   my $cvar_configs = CVar->get_configs('module' => 'CT');
 
 131   if ($form->{status} eq 'all') {
 
 132     push @options, $locale->text('All');
 
 133   } elsif ($form->{status} eq 'orphaned') {
 
 134     push @options, $locale->text('Orphaned');
 
 137   push @options, $locale->text('Name') . " : $form->{name}"                                    if $form->{name};
 
 138   push @options, $locale->text('Contact') . " : $form->{contact}"                              if $form->{contact};
 
 139   push @options, $locale->text('Number') . qq| : $form->{"$form->{db}number"}|                 if $form->{"$form->{db}number"};
 
 140   push @options, $locale->text('E-mail') . " : $form->{email}"                                 if $form->{email};
 
 141   push @options, $locale->text('Contact person (surname)')           . " : $form->{cp_name}"   if $form->{cp_name};
 
 142   push @options, $locale->text('Billing/shipping address (city)')    . " : $form->{addr_city}" if $form->{addr_city};
 
 143   push @options, $locale->text('Billing/shipping address (zipcode)') . " : $form->{zipcode}"   if $form->{addr_zipcode};
 
 144   push @options, $locale->text('Billing/shipping address (street)')  . " : $form->{street}"    if $form->{addr_street};
 
 146   if ($form->{business_id}) {
 
 147     my $business = SL::DB::Manager::Business->find_by(id => $form->{business_id});
 
 149       my $label = $form->{IS_CUSTOMER} ? $::locale->text('Customer type') : $::locale->text('Vendor type');
 
 150       push @options, $label . " : " . $business->description;
 
 155     'id',        'name',      "$form->{db}number",   'contact',  'phone',
 
 156     'fax',       'email',     'taxnumber',           'street',   'zipcode' , 'city',
 
 157     'business',  'invnumber', 'ordnumber',           'quonumber'
 
 160   my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs };
 
 161   my @searchable_custom_variables  = grep { $_->{searchable} }  @{ $cvar_configs };
 
 162   my %column_defs_cvars            = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables;
 
 164   push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
 
 167     'id'                => { 'text' => $locale->text('ID'), },
 
 168     "$form->{db}number" => { 'text' => $locale->text('Number'), },
 
 169     'name'              => { 'text' => $form->{IS_CUSTOMER} ? $::locale->text('Customer Name') : $::locale->text('Vendor Name'), },
 
 170     'contact'           => { 'text' => $locale->text('Contact'), },
 
 171     'phone'             => { 'text' => $locale->text('Phone'), },
 
 172     'fax'               => { 'text' => $locale->text('Fax'), },
 
 173     'email'             => { 'text' => $locale->text('E-mail'), },
 
 174     'cc'                => { 'text' => $locale->text('Cc'), },
 
 175     'taxnumber'         => { 'text' => $locale->text('Tax Number'), },
 
 176     'business'          => { 'text' => $locale->text('Type of Business'), },
 
 177     'invnumber'         => { 'text' => $locale->text('Invoice'), },
 
 178     'ordnumber'         => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Sales Order') : $locale->text('Purchase Order'), },
 
 179     'quonumber'         => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Quotation')   : $locale->text('Request for Quotation'), },
 
 180     'street'            => { 'text' => $locale->text('Street'), },
 
 181     'zipcode'           => { 'text' => $locale->text('Zipcode'), },
 
 182     'city'              => { 'text' => $locale->text('City'), },
 
 186   map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns;
 
 188   my @hidden_variables  = ( qw(
 
 189       db status obsolete name contact email cp_name addr_street addr_zipcode
 
 190       addr_city business_id
 
 191     ), "$form->{db}number",
 
 192     map({ "cvar_$_->{name}" } @searchable_custom_variables),
 
 193     map({ "l_$_" } @columns),
 
 196   my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables);
 
 197   my $callback          = build_std_url('action=list_names', grep { $form->{$_} } @hidden_nondefault);
 
 198   $form->{callback}     = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
 
 201     my $sortdir              = $form->{sort} eq $_ ? 1 - $form->{sortdir} : $form->{sortdir};
 
 202     $column_defs{$_}->{link} = "${callback}&sort=${_}&sortdir=${sortdir}";
 
 205   my ($ordertype, $quotationtype, $attachment_basename);
 
 206   if ($form->{IS_CUSTOMER}) {
 
 207     $form->{title}       = $locale->text('Customers');
 
 208     $ordertype           = 'sales_order';
 
 209     $quotationtype       = 'sales_quotation';
 
 210     $attachment_basename = $locale->text('customer_list');
 
 213     $form->{title}       = $locale->text('Vendors');
 
 214     $ordertype           = 'purchase_order';
 
 215     $quotationtype       = 'request_quotation';
 
 216     $attachment_basename = $locale->text('vendor_list');
 
 219   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
 221   $report->set_options('top_info_text'         => join("\n", @options),
 
 222                        'raw_bottom_info_text'  => $form->parse_html_template('ct/list_names_bottom'),
 
 223                        'output_format'         => 'HTML',
 
 224                        'title'                 => $form->{title},
 
 225                        'attachment_basename'   => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
 227   $report->set_options_from_form();
 
 228   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
 230   $report->set_columns(%column_defs);
 
 231   $report->set_column_order(@columns);
 
 233   $report->set_export_options('list_names', @hidden_variables, qw(sort sortdir));
 
 235   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
 237   CVar->add_custom_variables_to_report('module'         => 'CT',
 
 238                                        'trans_id_field' => 'id',
 
 239                                        'configs'        => $cvar_configs,
 
 240                                        'column_defs'    => \%column_defs,
 
 241                                        'data'           => $form->{CT});
 
 245   foreach my $ref (@{ $form->{CT} }) {
 
 246     my $row = { map { $_ => { 'data' => '' } } @columns };
 
 248     if ($ref->{id} ne $previous_id) {
 
 249       $previous_id = $ref->{id};
 
 250       map { $row->{$_}->{data} = $ref->{$_} } @columns;
 
 252       $row->{name}->{link}  = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback', @hidden_nondefault);
 
 253       $row->{email}->{link} = 'mailto:' . E($ref->{email});
 
 256     my $base_url              = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{invid}), 'callback', @hidden_nondefault);
 
 257     $row->{invnumber}->{link} = $base_url;
 
 258     $row->{ordnumber}->{link} = $base_url . "&type=${ordertype}";
 
 259     $row->{quonumber}->{link} = $base_url . "&type=${quotationtype}";
 
 260     my $column                = $ref->{formtype} eq 'invoice' ? 'invnumber' : $ref->{formtype} eq 'order' ? 'ordnumber' : 'quonumber';
 
 261     $row->{$column}->{data}   = $ref->{$column};
 
 263     $report->add_data($row);
 
 266   $report->generate_with_headers();
 
 268   $main::lxdebug->leave_sub();
 
 272   $main::lxdebug->enter_sub();
 
 274   $main::auth->assert('customer_vendor_edit');
 
 276   my $form     = $main::form;
 
 277   my %myconfig = %main::myconfig;
 
 279   # show history button
 
 280   $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
 
 281   #/show hhistory button
 
 283   CT->get_tuple(\%myconfig, \%$form);
 
 284   CT->populate_drop_down_boxes(\%myconfig, \%$form);
 
 286   $form->{title} = "Edit";
 
 289   $form->{discount} *= 100;
 
 291   $form->{homepage} = 'http://' . $form->{homepage} unless ((!$form->{homepage}) || $form->{homepage} =~ m|^https?://|);
 
 296   $main::lxdebug->leave_sub();
 
 301   join('; ', grep { $_ } map { $s->{"shipto$_"} } qw(name department_1 street city)) || ' '
 
 304 sub _contacts_label {
 
 305   join ", ", grep { $_ } $_[0]->{cp_name}, $_[0]->{cp_givenname};
 
 309   $main::lxdebug->enter_sub();
 
 311   $main::auth->assert('customer_vendor_edit');
 
 313   my $form     = $main::form;
 
 314   my %myconfig = %main::myconfig;
 
 315   my $locale   = $main::locale;
 
 317   $form->get_lists(employees  => "ALL_EMPLOYEES",
 
 318                    taxzones   => "ALL_TAXZONES",
 
 319                    currencies => "ALL_CURRENCIES");
 
 320   $form->get_pricegroup(\%myconfig, { all => 1 });
 
 322   $form->get_lists(customers => { key => "ALL_SALESMAN_CUSTOMERS", business_is_salesman => 1 }) if $::lx_office_conf{features}->{vertreter};
 
 324   $form->{ALL_SALESMEN}   = $form->{ALL_EMPLOYEES};
 
 325   $form->{taxincluded}    = ($form->{taxincluded}) ? "checked" : "";
 
 326   $form->{is_customer}    = $form->{db}     eq 'customer';
 
 327   $form->{salesman_label} = sub { $_[0]->{name} ne "" ? $_[0]->{name} : $_[0]->{login} };
 
 328   $form->{shipto_label}   = \&_shipto_label;
 
 329   $form->{contacts_label} = \&_contacts_label;
 
 330   $form->{taxzone_id}     = 0                                                               if !$form->{id};
 
 331   $form->{jsscript}       = 1;
 
 332   $form->{fokus}          = "ct.greeting";
 
 333   $form->{SHIPTO_ALL}     = [ +{ shipto_id => '0', shiptoname => $::locale->text('All') }, @{ $form->{SHIPTO} } ];
 
 335   $form->{title} = $form->{title_save}
 
 336                 || $locale->text("$form->{title} " . ucfirst $form->{db}) . ($form->{title} eq "Edit" ? " $form->{name}" : '');
 
 338   CT->query_titles_and_greetings(\%myconfig, \%$form);
 
 339   map { $form->{"MB_$_"} = [ map +{ id => $_, description => $_ }, @{ $form->{$_} } ] } qw(COMPANY_GREETINGS);
 
 341   $form->{NOTES} ||= [ ];
 
 343   if (!$form->{'language_id'}) {
 
 344     my $l_id = SL::DB::Default->get->{'language_id'};
 
 346       $form->{'default_language_id'} = $l_id;
 
 350   if (!$form->{'id'}) {
 
 351     $form->{'currency'} = $form->get_default_currency(\%myconfig);
 
 353     $form->{currency} = $form->{curr};
 
 356   $form->{CUSTOM_VARIABLES} = CVar->get_custom_variables('module' => 'CT', 'trans_id' => $form->{id});
 
 358   CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}) if (scalar @{ $form->{CUSTOM_VARIABLES} });
 
 361   print $form->parse_html_template('ct/form_header');
 
 363   $main::lxdebug->leave_sub();
 
 367   $main::lxdebug->enter_sub();
 
 369   $main::auth->assert('customer_vendor_edit');
 
 371   my $form     = $main::form;
 
 373   print $form->parse_html_template('ct/form_footer', { is_orphaned => $form->{status} eq 'orphaned',
 
 374                                                        is_customer => $form->{db}     eq 'customer' });
 
 375   $main::lxdebug->leave_sub();
 
 379   $main::auth->assert('customer_vendor_edit & ' .
 
 380                       '(general_ledger         | invoice_edit         | vendor_invoice_edit | ' .
 
 381                       ' request_quotation_edit | sales_quotation_edit | sales_order_edit    | purchase_order_edit)');
 
 383   $::form->isblank("name", $::locale->text("Name missing!"));
 
 385   if ($::form->{new_salesman_id} && $::lx_office_conf{features}->{vertreter}) {
 
 386     $::form->{salesman_id} = $::form->{new_salesman_id};
 
 387     delete $::form->{new_salesman_id};
 
 390   my $res = $::form->{db} eq 'customer' ? CT->save_customer(\%::myconfig, $::form) : CT->save_vendor(\%::myconfig, $::form);
 
 393     if ($::form->{"db"} eq "customer") {
 
 394       $::form->error($::locale->text('This customer number is already in use.'));
 
 396       $::form->error($::locale->text('This vendor number is already in use.'));
 
 401 sub add_transaction {
 
 402   $main::lxdebug->enter_sub();
 
 404   $main::auth->assert('customer_vendor_edit & ' .
 
 405                 '(general_ledger         | invoice_edit         | vendor_invoice_edit | ' .
 
 406                 ' request_quotation_edit | sales_quotation_edit | sales_order_edit    | purchase_order_edit)');
 
 408   my $form     = $main::form;
 
 409   my %myconfig = %main::myconfig;
 
 410   my $locale   = $main::locale;
 
 412 #  # saving the history
 
 413 #  if(!exists $form->{addition}) {
 
 414 #    $form->{addition} = "ADD TRANSACTION";
 
 415 #    $form->save_history;
 
 417 #  # /saving the history
 
 421   $form->{callback} = $form->escape($form->{callback}, 1);
 
 422   my $name = $form->escape("$form->{name}", 1);
 
 425     "$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
 
 428   $main::lxdebug->leave_sub();
 
 431 sub save_and_ap_transaction {
 
 432   $main::lxdebug->enter_sub();
 
 434   $main::auth->assert('customer_vendor_edit & general_ledger');
 
 436   my $form     = $main::form;
 
 437   my %myconfig = %main::myconfig;
 
 439   $form->{script} = "ap.pl";
 
 441   if(!exists $form->{addition}) {
 
 442     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
 443     $form->{addition} = "SAVED";
 
 446   # /saving the history
 
 448   $main::lxdebug->leave_sub();
 
 451 sub save_and_ar_transaction {
 
 452   $main::lxdebug->enter_sub();
 
 454   $main::auth->assert('customer_vendor_edit & general_ledger');
 
 456   my $form     = $main::form;
 
 457   my %myconfig = %main::myconfig;
 
 459   $form->{script} = "ar.pl";
 
 461   if(!exists $form->{addition}) {
 
 462     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
 463     $form->{addition} = "SAVED";
 
 466   # /saving the history
 
 468   $main::lxdebug->leave_sub();
 
 471 sub save_and_invoice {
 
 472   $main::lxdebug->enter_sub();
 
 474   my $form     = $main::form;
 
 475   my %myconfig = %main::myconfig;
 
 477   if ($form->{db} eq 'customer') {
 
 478     $main::auth->assert('customer_vendor_edit & invoice_edit');
 
 480     $main::auth->assert('customer_vendor_edit & vendor_invoice_edit');
 
 483   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
 
 484   $form->{type} = "invoice";
 
 486   if(!exists $form->{addition}) {
 
 487     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
 488     $form->{addition} = "SAVED";
 
 491   # /saving the history
 
 493   $main::lxdebug->leave_sub();
 
 497   $main::lxdebug->enter_sub();
 
 499   $main::auth->assert('customer_vendor_edit & request_quotation_edit');
 
 501   my $form     = $main::form;
 
 502   my %myconfig = %main::myconfig;
 
 504   $form->{script} = "oe.pl";
 
 505   $form->{type}   = "request_quotation";
 
 507   if(!exists $form->{addition}) {
 
 508     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
 509     $form->{addition} = "SAVED";
 
 512   # /saving the history
 
 514   $main::lxdebug->leave_sub();
 
 517 sub save_and_quotation {
 
 518   $main::lxdebug->enter_sub();
 
 520   $main::auth->assert('customer_vendor_edit & sales_quotation_edit');
 
 522   my $form     = $main::form;
 
 523   my %myconfig = %main::myconfig;
 
 525   $form->{script} = "oe.pl";
 
 526   $form->{type}   = "sales_quotation";
 
 528   if(!exists $form->{addition}) {
 
 529     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
 530     $form->{addition} = "SAVED";
 
 533   # /saving the history
 
 535   $main::lxdebug->leave_sub();
 
 539   $main::lxdebug->enter_sub();
 
 541   my $form     = $main::form;
 
 542   my %myconfig = %main::myconfig;
 
 544   if ($form->{db} eq 'customer') {
 
 545     $main::auth->assert('customer_vendor_edit & sales_order_edit');
 
 547     $main::auth->assert('customer_vendor_edit & purchase_order_edit');
 
 550   $form->{script} = "oe.pl";
 
 552     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
 
 554   if(!exists $form->{addition}) {
 
 555     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
 556     $form->{addition} = "SAVED";
 
 559   # /saving the history
 
 561   $main::lxdebug->leave_sub();
 
 565   $main::lxdebug->enter_sub();
 
 567   $main::auth->assert('customer_vendor_edit');
 
 569   my $form     = $main::form;
 
 570   my %myconfig = %main::myconfig;
 
 571   my $locale   = $main::locale;
 
 573   my $msg = ucfirst $form->{db};
 
 579   if(!exists $form->{addition}) {
 
 580     $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
 
 581     $form->{addition} = "SAVED";
 
 584   # /saving the history
 
 585   $form->redirect($locale->text($msg));
 
 587   $main::lxdebug->leave_sub();
 
 591   $main::lxdebug->enter_sub();
 
 593   $main::auth->assert('customer_vendor_edit');
 
 595   my $form     = $main::form;
 
 596   my %myconfig = %main::myconfig;
 
 597   my $locale   = $main::locale;
 
 599   my $msg = ucfirst $form->{db};
 
 605   if(!exists $form->{addition}) {
 
 606     $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
 
 607     $form->{addition} = "SAVED";
 
 610   # /saving the history
 
 613   $main::lxdebug->leave_sub();
 
 618   $main::lxdebug->enter_sub();
 
 620   $main::auth->assert('customer_vendor_edit');
 
 622   my $form     = $main::form;
 
 623   my %myconfig = %main::myconfig;
 
 624   my $locale   = $main::locale;
 
 626   CT->delete(\%myconfig, \%$form);
 
 628   my $msg = ucfirst $form->{db};
 
 631   if(!exists $form->{addition}) {
 
 632     $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
 
 633     $form->{addition} = "DELETED";
 
 636   # /saving the history
 
 637   $form->redirect($locale->text($msg));
 
 639   $main::lxdebug->leave_sub();
 
 643   $main::lxdebug->enter_sub();
 
 645   $main::auth->assert('customer_vendor_edit');
 
 647   my $form     = $main::form;
 
 652   $main::lxdebug->leave_sub();
 
 656   $main::lxdebug->enter_sub();
 
 658   $main::auth->assert('customer_vendor_edit');
 
 660   my $form     = $main::form;
 
 663   $main::lxdebug->leave_sub();
 
 667   $main::lxdebug->enter_sub();
 
 669   $main::auth->assert('customer_vendor_edit');
 
 671   CT->populate_drop_down_boxes(\%::myconfig, $::form);
 
 672   CT->query_titles_and_greetings(\%::myconfig, $::form);
 
 673   CT->get_contact(\%::myconfig, $::form) if $::form->{cp_id};
 
 675   $::form->{contacts_label} = \&_contacts_label;
 
 677   print $::form->ajax_response_header(), $::form->parse_html_template('ct/_contact');
 
 679   $main::lxdebug->leave_sub();
 
 683   $main::lxdebug->enter_sub();
 
 685   $main::auth->assert('customer_vendor_edit');
 
 687   CT->populate_drop_down_boxes(\%::myconfig, $::form);
 
 688   CT->get_shipto(\%::myconfig, $::form) if $::form->{shipto_id};
 
 690   $::form->{shipto_label} = \&_shipto_label;
 
 692   print $::form->ajax_response_header(), $::form->parse_html_template('ct/_shipto');
 
 694   $main::lxdebug->leave_sub();
 
 698   $::lxdebug->enter_sub;
 
 700   $::auth->assert('customer_vendor_edit');
 
 701   $::auth->assert('sales_all_edit');
 
 703   CT->get_delivery(\%::myconfig, $::form );
 
 705   print $::form->ajax_response_header,
 
 706         $::form->parse_html_template('ct/get_delivery', {
 
 707           is_customer =>  $::form->{db} eq 'customer',
 
 710   $::lxdebug->leave_sub;
 
 714   $main::lxdebug->enter_sub();
 
 716   $main::auth->assert('customer_vendor_edit');
 
 718   my $form     = $main::form;
 
 719   my %myconfig = %main::myconfig;
 
 721   CT->get_shipto(\%myconfig, \%$form);
 
 723   unless ($form->{shiptoused}) {
 
 724     CT->delete_shipto($form->{shipto_id});
 
 725     @$form{ grep /^shipto/, keys %$form } = undef;
 
 730   $main::lxdebug->leave_sub();
 
 734   $::lxdebug->enter_sub;
 
 735   $::auth->assert('customer_vendor_edit');
 
 737   CT->get_contact(\%::myconfig, $::form);
 
 739   my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id});
 
 741   if ($contact->used) {
 
 743     flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
 
 746     flash('info', $::locale->text('Contact deleted.'));
 
 748   delete $::form->{$_} for grep /^cp_/, keys %$::form;
 
 752   $::lxdebug->leave_sub;
 
 755 sub ajax_autocomplete {
 
 756   $main::lxdebug->enter_sub();
 
 758   my $form     = $main::form;
 
 759   my %myconfig = %main::myconfig;
 
 761   $form->{column}          = 'name'     unless $form->{column} =~ /^name$/;
 
 762   $form->{vc}              = 'customer' unless $form->{vc} =~ /^customer|vendor$/;
 
 763   $form->{db}              = $form->{vc}; # CT expects this
 
 764   $form->{$form->{column}} = $form->{q}           || '';
 
 765   $form->{limit}           = ($form->{limit} * 1) || 10;
 
 766   $form->{searchitems}   ||= '';
 
 768   CT->search(\%myconfig, $form);
 
 770   print $form->ajax_response_header(),
 
 771         $form->parse_html_template('ct/ajax_autocomplete');
 
 773   $main::lxdebug->leave_sub();
 
 776 sub continue { call_sub($main::form->{nextsub}); }