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!')
 
  49 use POSIX qw(strftime);
 
  53 use SL::ReportGenerator;
 
  55 require "bin/mozilla/common.pl";
 
  56 require "bin/mozilla/reportgenerator.pl";
 
  64   $main::lxdebug->enter_sub();
 
  66   $main::auth->assert('customer_vendor_edit');
 
  68   my $form     = $main::form;
 
  69   my %myconfig = %main::myconfig;
 
  71   $form->{title}    = "Add";
 
  72   $form->{callback} = "$form->{script}?action=add&db=$form->{db}" unless $form->{callback};
 
  74   CT->populate_drop_down_boxes(\%myconfig, \%$form);
 
  79   $main::lxdebug->leave_sub();
 
  83   $main::lxdebug->enter_sub();
 
  85   $main::auth->assert('customer_vendor_edit');
 
  87   my $form     = $main::form;
 
  88   my $locale   = $main::locale;
 
  90   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
  92   $form->get_lists("business_types" => "ALL_BUSINESS_TYPES");
 
  93   $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
 
  95   $form->{CUSTOM_VARIABLES}                  = CVar->get_configs('module' => 'CT');
 
  96   ($form->{CUSTOM_VARIABLES_FILTER_CODE},
 
  97    $form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables'      => $form->{CUSTOM_VARIABLES},
 
  98                                                                            'include_prefix' => 'l_',
 
  99                                                                            'include_value'  => 'Y');
 
 101   $form->{jsscript} = 1;
 
 102   $form->{title}    = $form->{IS_CUSTOMER} ? $locale->text('Customers') : $locale->text('Vendors');
 
 103   $form->{fokus}    = 'Form.name';
 
 106   print $form->parse_html_template('ct/search');
 
 108   $main::lxdebug->leave_sub();
 
 112   $main::lxdebug->enter_sub();
 
 114   $main::auth->assert('customer_vendor_edit');
 
 116   my $form     = $main::form;
 
 117   my %myconfig = %main::myconfig;
 
 118   my $locale   = $main::locale;
 
 120   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
 122   report_generator_set_default_sort('name', 1);
 
 124   CT->search(\%myconfig, \%$form);
 
 126   my $cvar_configs = CVar->get_configs('module' => 'CT');
 
 129   if ($form->{status} eq 'all') {
 
 130     push @options, $locale->text('All');
 
 131   } elsif ($form->{status} eq 'orphaned') {
 
 132     push @options, $locale->text('Orphaned');
 
 135   push @options, $locale->text('Name') . " : $form->{name}"                                    if $form->{name};
 
 136   push @options, $locale->text('Contact') . " : $form->{contact}"                              if $form->{contact};
 
 137   push @options, $locale->text('Number') . qq| : $form->{"$form->{db}number"}|                 if $form->{"$form->{db}number"};
 
 138   push @options, $locale->text('E-mail') . " : $form->{email}"                                 if $form->{email};
 
 139   push @options, $locale->text('Contact person (surname)')           . " : $form->{cp_name}"   if $form->{cp_name};
 
 140   push @options, $locale->text('Billing/shipping address (city)')    . " : $form->{addr_city}" if $form->{addr_city};
 
 141   push @options, $locale->text('Billing/shipping address (zipcode)') . " : $form->{zipcode}"   if $form->{addr_zipcode};
 
 142   push @options, $locale->text('Billing/shipping address (street)')  . " : $form->{street}"    if $form->{addr_street};
 
 145     'id',        'name',      "$form->{db}number",   'contact',  'phone',
 
 146     'fax',       'email',     'taxnumber',           'street',   'zipcode' , 'city',
 
 147     'business',  'invnumber', 'ordnumber',           'quonumber'
 
 150   my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs };
 
 151   my @searchable_custom_variables  = grep { $_->{searchable} }  @{ $cvar_configs };
 
 152   my %column_defs_cvars            = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables;
 
 154   push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
 
 157     'id'                => { 'text' => $locale->text('ID'), },
 
 158     "$form->{db}number" => { 'text' => $locale->text('Number'), },
 
 159     'name'              => { 'text' => $form->{IS_CUSTOMER} ? $::locale->text('Customer Name') : $::locale->text('Vendor Name'), },
 
 160     'contact'           => { 'text' => $locale->text('Contact'), },
 
 161     'phone'             => { 'text' => $locale->text('Phone'), },
 
 162     'fax'               => { 'text' => $locale->text('Fax'), },
 
 163     'email'             => { 'text' => $locale->text('E-mail'), },
 
 164     'cc'                => { 'text' => $locale->text('Cc'), },
 
 165     'taxnumber'         => { 'text' => $locale->text('Tax Number'), },
 
 166     'business'          => { 'text' => $locale->text('Type of Business'), },
 
 167     'invnumber'         => { 'text' => $locale->text('Invoice'), },
 
 168     'ordnumber'         => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Sales Order') : $locale->text('Purchase Order'), },
 
 169     'quonumber'         => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Quotation')   : $locale->text('Request for Quotation'), },
 
 170     'street'            => { 'text' => $locale->text('Street'), },
 
 171     'zipcode'           => { 'text' => $locale->text('Zipcode'), },
 
 172     'city'              => { 'text' => $locale->text('City'), },
 
 176   map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns;
 
 178   my @hidden_variables  = (qw(db status obsolete name contact email cp_name addr_city), "$form->{db}number", @searchable_custom_variables, map { "l_$_" } @columns);
 
 179   my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables);
 
 180   my $callback          = build_std_url('action=list_names', grep { $form->{$_} } @hidden_nondefault);
 
 181   $form->{callback}     = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
 
 184     my $sortdir              = $form->{sort} eq $_ ? 1 - $form->{sortdir} : $form->{sortdir};
 
 185     $column_defs{$_}->{link} = "${callback}&sort=${_}&sortdir=${sortdir}";
 
 188   my ($ordertype, $quotationtype, $attachment_basename);
 
 189   if ($form->{IS_CUSTOMER}) {
 
 190     $form->{title}       = $locale->text('Customers');
 
 191     $ordertype           = 'sales_order';
 
 192     $quotationtype       = 'sales_quotation';
 
 193     $attachment_basename = $locale->text('customer_list');
 
 196     $form->{title}       = $locale->text('Vendors');
 
 197     $ordertype           = 'purchase_order';
 
 198     $quotationtype       = 'request_quotation';
 
 199     $attachment_basename = $locale->text('vendor_list');
 
 202   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
 204   $report->set_options('top_info_text'         => join("\n", @options),
 
 205                        'raw_bottom_info_text'  => $form->parse_html_template('ct/list_names_bottom'),
 
 206                        'output_format'         => 'HTML',
 
 207                        'title'                 => $form->{title},
 
 208                        'attachment_basename'   => $attachment_basename . strftime('_%Y%m%d', localtime time),
 
 210   $report->set_options_from_form();
 
 212   $report->set_columns(%column_defs);
 
 213   $report->set_column_order(@columns);
 
 215   $report->set_export_options('list_names', @hidden_variables, qw(sort sortdir));
 
 217   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
 219   CVar->add_custom_variables_to_report('module'         => 'CT',
 
 220                                        'trans_id_field' => 'id',
 
 221                                        'configs'        => $cvar_configs,
 
 222                                        'column_defs'    => \%column_defs,
 
 223                                        'data'           => $form->{CT});
 
 227   foreach my $ref (@{ $form->{CT} }) {
 
 228     my $row = { map { $_ => { 'data' => '' } } @columns };
 
 230     if ($ref->{id} ne $previous_id) {
 
 231       $previous_id = $ref->{id};
 
 232       map { $row->{$_}->{data} = $ref->{$_} } @columns;
 
 234       $row->{name}->{link}  = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback', @hidden_nondefault);
 
 235       $row->{email}->{link} = 'mailto:' . E($ref->{email});
 
 238     my $base_url              = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{invid}), 'callback', @hidden_nondefault);
 
 239     $row->{invnumber}->{link} = $base_url;
 
 240     $row->{ordnumber}->{link} = $base_url . "&type=${ordertype}";
 
 241     $row->{quonumber}->{link} = $base_url . "&type=${quotationtype}";
 
 242     my $column                = $ref->{formtype} eq 'invoice' ? 'invnumber' : $ref->{formtype} eq 'order' ? 'ordnumber' : 'quonumber';
 
 243     $row->{$column}->{data}   = $ref->{$column};
 
 245     $report->add_data($row);
 
 248   $report->generate_with_headers();
 
 250   $main::lxdebug->leave_sub();
 
 254   $main::lxdebug->enter_sub();
 
 256   $main::auth->assert('customer_vendor_edit');
 
 258   my $form     = $main::form;
 
 259   my %myconfig = %main::myconfig;
 
 261   # show history button
 
 262   $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
 
 263   #/show hhistory button
 
 265   CT->get_tuple(\%myconfig, \%$form);
 
 266   CT->populate_drop_down_boxes(\%myconfig, \%$form);
 
 268   $form->{title} = "Edit";
 
 271   $form->{discount} *= 100;
 
 276   $main::lxdebug->leave_sub();
 
 280   $main::lxdebug->enter_sub();
 
 282   $main::auth->assert('customer_vendor_edit');
 
 284   my $form     = $main::form;
 
 285   my %myconfig = %main::myconfig;
 
 286   my $locale   = $main::locale;
 
 288   $form->get_lists(employees => "ALL_EMPLOYEES",
 
 289                    taxzones  => "ALL_TAXZONES");
 
 290   $form->get_pricegroup(\%myconfig, { all => 1 });
 
 292   $form->get_lists(customers => { key => "ALL_SALESMAN_CUSTOMERS", business_is_salesman => 1 }) if $::vertreter;
 
 294   $form->{ALL_SALESMEN}   = $form->{ALL_EMPLOYEES};
 
 295   $form->{taxincluded}    = ($form->{taxincluded}) ? "checked" : "";
 
 296   $form->{is_admin}       = $myconfig{role} eq 'admin';
 
 297   $form->{is_customer}    = $form->{db}     eq 'customer';
 
 298   $form->{salesman_label} = sub { $_[0]->{name} ne "" ? $_[0]->{name} : $_[0]->{login} };
 
 299   $form->{shipto_label}   = sub { my $s = shift(@_); join('; ', grep { $_ } map { $s->{"shipto$_"} } qw(name department_1 street city)) || ' ' };
 
 300   $form->{contacts_label} = sub { join ", ", grep { $_ } $_[0]->{cp_name}, $_[0]->{cp_givenname} };
 
 301   $form->{taxzone_id}     = 0                                                               if !$form->{id};
 
 302   $form->{jsscript}       = 1;
 
 303   $form->{fokus}          = "ct.greeting";
 
 304   $form->{AJAX}           = [ new CGI::Ajax( map {; "get_$_" => "$form->{script}?action=get_$_" } qw(shipto contact delivery) ) ];
 
 306   unshift @{ $form->{SHIPTO} },   +{ shipto_id => '0', shiptoname => '' }, +{ shipto_id => '0', shiptoname => 'Alle' };
 
 307   unshift @{ $form->{CONTACTS} }, +{ cp_id     => '0', cp_name => $locale->text('New contact') };
 
 309   $form->{title} = $form->{title_save}
 
 310                 || $locale->text("$form->{title} " . ucfirst $form->{db}) . ($form->{title} eq "Edit" ? " $form->{name}" : '');
 
 312   CT->query_titles_and_greetings(\%myconfig, \%$form);
 
 313   map { $form->{"MB_$_"} = [ map +{ id => $_, description => $_ }, @{ $form->{$_} } ] } qw(TITLES GREETINGS COMPANY_GREETINGS DEPARTMENT);
 
 315   $form->{NOTES} ||= [ ];
 
 317   $form->{CUSTOM_VARIABLES} = CVar->get_custom_variables('module' => 'CT', 'trans_id' => $form->{id});
 
 319   CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}) if (scalar @{ $form->{CUSTOM_VARIABLES} });
 
 322   print $form->parse_html_template('ct/form_header');
 
 324   $main::lxdebug->leave_sub();
 
 328   $main::lxdebug->enter_sub();
 
 330   $main::auth->assert('customer_vendor_edit');
 
 332   my $form     = $main::form;
 
 334   print $form->parse_html_template('ct/form_footer', { is_orphaned => $form->{status} eq 'orphaned',
 
 335                                                        is_customer => $form->{db}     eq 'customer' });
 
 336   $main::lxdebug->leave_sub();
 
 339 sub add_transaction {
 
 340   $main::lxdebug->enter_sub();
 
 342   $main::auth->assert('customer_vendor_edit & ' .
 
 343                 '(general_ledger         | invoice_edit         | vendor_invoice_edit | ' .
 
 344                 ' request_quotation_edit | sales_quotation_edit | sales_order_edit    | purchase_order_edit)');
 
 346   my $form     = $main::form;
 
 347   my %myconfig = %main::myconfig;
 
 348   my $locale   = $main::locale;
 
 350 #  # saving the history
 
 351 #  if(!exists $form->{addition}) {
 
 352 #    $form->{addition} = "ADD TRANSACTION";
 
 353 #    $form->save_history($form->dbconnect(\%myconfig));
 
 355 #  # /saving the history
 
 357   $form->isblank("name", $locale->text("Name missing!"));
 
 358   if ($form->{"db"} eq "customer") {
 
 359     CT->save_customer(\%myconfig, \%$form);
 
 361     CT->save_vendor(\%myconfig, \%$form);
 
 364   $form->{callback} = $form->escape($form->{callback}, 1);
 
 365   my $name = $form->escape("$form->{name}", 1);
 
 368     "$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
 
 371   $main::lxdebug->leave_sub();
 
 374 sub save_and_ap_transaction {
 
 375   $main::lxdebug->enter_sub();
 
 377   $main::auth->assert('customer_vendor_edit & general_ledger');
 
 379   my $form     = $main::form;
 
 380   my %myconfig = %main::myconfig;
 
 382   $form->{script} = "ap.pl";
 
 384   if(!exists $form->{addition}) {
 
 385     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
 386     $form->{addition} = "SAVED";
 
 387     $form->save_history($form->dbconnect(\%myconfig));
 
 389   # /saving the history
 
 391   $main::lxdebug->leave_sub();
 
 394 sub save_and_ar_transaction {
 
 395   $main::lxdebug->enter_sub();
 
 397   $main::auth->assert('customer_vendor_edit & general_ledger');
 
 399   my $form     = $main::form;
 
 400   my %myconfig = %main::myconfig;
 
 402   $form->{script} = "ar.pl";
 
 404   if(!exists $form->{addition}) {
 
 405     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
 406     $form->{addition} = "SAVED";
 
 407     $form->save_history($form->dbconnect(\%myconfig));
 
 409   # /saving the history
 
 411   $main::lxdebug->leave_sub();
 
 414 sub save_and_invoice {
 
 415   $main::lxdebug->enter_sub();
 
 417   my $form     = $main::form;
 
 418   my %myconfig = %main::myconfig;
 
 420   if ($form->{db} eq 'customer') {
 
 421     $main::auth->assert('customer_vendor_edit & invoice_edit');
 
 423     $main::auth->assert('customer_vendor_edit & vendor_invoice_edit');
 
 426   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
 
 427   $form->{type} = "invoice";
 
 429   if(!exists $form->{addition}) {
 
 430     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
 
 431     $form->{addition} = "SAVED";
 
 432     $form->save_history($form->dbconnect(\%myconfig));
 
 434   # /saving the history
 
 436   $main::lxdebug->leave_sub();
 
 440   $main::lxdebug->enter_sub();
 
 442   $main::auth->assert('customer_vendor_edit & request_quotation_edit');
 
 444   my $form     = $main::form;
 
 445   my %myconfig = %main::myconfig;
 
 447   $form->{script} = "oe.pl";
 
 448   $form->{type}   = "request_quotation";
 
 450   if(!exists $form->{addition}) {
 
 451     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
 452     $form->{addition} = "SAVED";
 
 453     $form->save_history($form->dbconnect(\%myconfig));
 
 455   # /saving the history
 
 457   $main::lxdebug->leave_sub();
 
 460 sub save_and_quotation {
 
 461   $main::lxdebug->enter_sub();
 
 463   $main::auth->assert('customer_vendor_edit & sales_quotation_edit');
 
 465   my $form     = $main::form;
 
 466   my %myconfig = %main::myconfig;
 
 468   $form->{script} = "oe.pl";
 
 469   $form->{type}   = "sales_quotation";
 
 471   if(!exists $form->{addition}) {
 
 472     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
 473     $form->{addition} = "SAVED";
 
 474     $form->save_history($form->dbconnect(\%myconfig));
 
 476   # /saving the history
 
 478   $main::lxdebug->leave_sub();
 
 482   $main::lxdebug->enter_sub();
 
 484   my $form     = $main::form;
 
 485   my %myconfig = %main::myconfig;
 
 487   if ($form->{db} eq 'customer') {
 
 488     $main::auth->assert('customer_vendor_edit & sales_order_edit');
 
 490     $main::auth->assert('customer_vendor_edit & purchase_order_edit');
 
 493   $form->{script} = "oe.pl";
 
 495     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
 
 497   if(!exists $form->{addition}) {
 
 498     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
 
 499     $form->{addition} = "SAVED";
 
 500     $form->save_history($form->dbconnect(\%myconfig));
 
 502   # /saving the history
 
 504   $main::lxdebug->leave_sub();
 
 508   $main::lxdebug->enter_sub();
 
 510   $main::auth->assert('customer_vendor_edit');
 
 512   my $form     = $main::form;
 
 513   my %myconfig = %main::myconfig;
 
 514   my $locale   = $main::locale;
 
 516   my $msg = ucfirst $form->{db};
 
 519   $form->isblank("name", $locale->text("Name missing!"));
 
 521   if ($form->{"db"} eq "customer") {
 
 522     $rc = CT->save_customer(\%myconfig, \%$form);
 
 524     $rc = CT->save_vendor(\%myconfig, \%$form);
 
 527     $form->error($locale->text('customernumber not unique!'));
 
 530   if(!exists $form->{addition}) {
 
 531     $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
 
 532     $form->{addition} = "SAVED";
 
 533     $form->save_history($form->dbconnect(\%myconfig));
 
 535   # /saving the history
 
 536   $form->redirect($locale->text($msg));
 
 538   $main::lxdebug->leave_sub();
 
 542   $main::lxdebug->enter_sub();
 
 544   $main::auth->assert('customer_vendor_edit');
 
 546   my $form     = $main::form;
 
 547   my %myconfig = %main::myconfig;
 
 548   my $locale   = $main::locale;
 
 550   my $msg = ucfirst $form->{db};
 
 553   $form->isblank("name", $locale->text("Name missing!"));
 
 556   if ($form->{"db"} eq "customer") {
 
 557     $res = CT->save_customer(\%myconfig, \%$form);
 
 559     $res = CT->save_vendor(\%myconfig, \%$form);
 
 563     if ($form->{"db"} eq "customer") {
 
 564       $form->error($locale->text('This customer number is already in use.'));
 
 566       $form->error($locale->text('This vendor number is already in use.'));
 
 570   if(!exists $form->{addition}) {
 
 571     $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
 
 572     $form->{addition} = "SAVED";
 
 573     $form->save_history($form->dbconnect(\%myconfig));
 
 575   # /saving the history
 
 578   $main::lxdebug->leave_sub();
 
 582   $main::lxdebug->enter_sub();
 
 584   $main::auth->assert('customer_vendor_edit');
 
 586   my $form     = $main::form;
 
 587   my %myconfig = %main::myconfig;
 
 588   my $locale   = $main::locale;
 
 590   CT->delete(\%myconfig, \%$form);
 
 592   my $msg = ucfirst $form->{db};
 
 595   if(!exists $form->{addition}) {
 
 596     $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
 
 597     $form->{addition} = "DELETED";
 
 598     $form->save_history($form->dbconnect(\%myconfig));
 
 600   # /saving the history
 
 601   $form->redirect($locale->text($msg));
 
 603   $msg = "Cannot delete $form->{db}";
 
 604   $form->error($locale->text($msg));
 
 606   $main::lxdebug->leave_sub();
 
 610   $main::lxdebug->enter_sub();
 
 612   $main::auth->assert('customer_vendor_edit');
 
 614   my $form     = $main::form;
 
 619   $main::lxdebug->leave_sub();
 
 623   $main::lxdebug->enter_sub();
 
 625   $main::auth->assert('customer_vendor_edit');
 
 627   my $form     = $main::form;
 
 630   $main::lxdebug->leave_sub();
 
 634   $main::lxdebug->enter_sub();
 
 636   $main::auth->assert('customer_vendor_edit');
 
 638   my $form     = $main::form;
 
 639   my %myconfig = %main::myconfig;
 
 641   CT->get_contact(\%myconfig, \%$form);
 
 642   print $form->ajax_response_header(), join '__pjx__', map $form->{"cp_$_"},
 
 643     qw(name title givenname phone1 phone2 email abteilung fax mobile1 mobile2 satphone satfax project privatphone privatemail birthday used gender);
 
 644   $main::lxdebug->leave_sub();
 
 649   $main::lxdebug->enter_sub();
 
 651   $main::auth->assert('customer_vendor_edit');
 
 653   my $form     = $main::form;
 
 654   my %myconfig = %main::myconfig;
 
 656   CT->get_shipto(\%myconfig, \%$form);
 
 657   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)));
 
 658   $main::lxdebug->leave_sub();
 
 663   $::lxdebug->enter_sub;
 
 665   $::auth->assert('customer_vendor_edit');
 
 666   $::auth->assert('sales_all_edit');
 
 668   CT->get_delivery(\%::myconfig, $::form );
 
 670   print $::form->ajax_response_header,
 
 671         $::form->parse_html_template('ct/get_delivery', {
 
 672           is_customer =>  $::form->{db} eq 'customer',
 
 675   $::lxdebug->leave_sub;
 
 679   $main::lxdebug->enter_sub();
 
 681   $main::auth->assert('customer_vendor_edit');
 
 683   my $form     = $main::form;
 
 684   my %myconfig = %main::myconfig;
 
 686   CT->get_shipto(\%myconfig, \%$form);
 
 688   unless ($form->{shiptoused}) {
 
 689     CT->delete_shipto($form->{shipto_id});
 
 690     @$form{ grep /^shipto/, keys %$form } = undef;
 
 695   $main::lxdebug->leave_sub();
 
 699   $main::lxdebug->enter_sub();
 
 701   $main::auth->assert('customer_vendor_edit');
 
 703   my $form     = $main::form;
 
 704   my %myconfig = %main::myconfig;
 
 706   CT->get_contact(\%myconfig, \%$form);
 
 708   unless ($form->{cp_used}) {
 
 709     CT->delete_shipto($form->{cp_id});
 
 710     @$form{ grep /^cp_/, keys %$form } = undef;
 
 715   $main::lxdebug->leave_sub();
 
 718 sub ajax_autocomplete {
 
 719   $main::lxdebug->enter_sub();
 
 721   my $form     = $main::form;
 
 722   my %myconfig = %main::myconfig;
 
 724   $form->{column}          = 'name'     unless $form->{column} =~ /^name$/;
 
 725   $form->{vc}              = 'customer' unless $form->{vc} =~ /^customer|vendor$/;
 
 726   $form->{db}              = $form->{vc}; # CT expects this
 
 727   $form->{$form->{column}} = $form->{q}           || '';
 
 728   $form->{limit}           = ($form->{limit} * 1) || 10;
 
 729   $form->{searchitems}   ||= '';
 
 731   CT->search(\%myconfig, $form);
 
 733   print $form->ajax_response_header(),
 
 734         $form->parse_html_template('ct/ajax_autocomplete');
 
 736   $main::lxdebug->leave_sub();
 
 739 sub continue { call_sub($main::form->{nextsub}); }