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);
52 use SL::Request qw(flatten);
55 use SL::Helper::Flash;
56 use SL::ReportGenerator;
58 require "bin/mozilla/common.pl";
59 require "bin/mozilla/reportgenerator.pl";
67 $main::lxdebug->enter_sub();
69 $main::auth->assert('customer_vendor_edit');
71 my $form = $main::form;
72 my %myconfig = %main::myconfig;
74 $form->{title} = "Add";
75 $form->{callback} = "$form->{script}?action=add&db=$form->{db}" unless $form->{callback};
77 CT->populate_drop_down_boxes(\%myconfig, \%$form);
82 $main::lxdebug->leave_sub();
86 $main::lxdebug->enter_sub();
88 $main::auth->assert('customer_vendor_edit');
90 my $form = $main::form;
91 my $locale = $main::locale;
93 $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
95 $form->get_lists("business_types" => "ALL_BUSINESS_TYPES");
96 $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
98 $form->{CUSTOM_VARIABLES} = CVar->get_configs('module' => 'CT');
99 ($form->{CUSTOM_VARIABLES_FILTER_CODE},
100 $form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $form->{CUSTOM_VARIABLES},
101 'include_prefix' => 'l_',
102 'include_value' => 'Y');
104 $form->{jsscript} = 1;
105 $form->{title} = $form->{IS_CUSTOMER} ? $locale->text('Customers') : $locale->text('Vendors');
106 $::request->{layout}->focus('#name');
109 print $form->parse_html_template('ct/search');
111 $main::lxdebug->leave_sub();
115 $::lxdebug->enter_sub;
116 $::auth->assert('customer_vendor_edit');
118 $::form->{CUSTOM_VARIABLES} = CVar->get_configs('module' => 'Contacts');
119 ($::form->{CUSTOM_VARIABLES_FILTER_CODE},
120 $::form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $::form->{CUSTOM_VARIABLES},
121 'include_prefix' => 'l.',
122 'filter_prefix' => 'filter.',
123 'include_value' => 'Y');
125 $::form->{title} = $::locale->text('Search contacts');
127 print $::form->parse_html_template('ct/search_contact');
129 $::lxdebug->leave_sub;
133 $main::lxdebug->enter_sub();
135 $main::auth->assert('customer_vendor_edit');
137 my $form = $main::form;
138 my %myconfig = %main::myconfig;
139 my $locale = $main::locale;
141 $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
143 report_generator_set_default_sort('name', 1);
145 CT->search(\%myconfig, \%$form);
147 my $cvar_configs = CVar->get_configs('module' => 'CT');
150 if ($form->{status} eq 'all') {
151 push @options, $locale->text('All');
152 } elsif ($form->{status} eq 'orphaned') {
153 push @options, $locale->text('Orphaned');
156 push @options, $locale->text('Name') . " : $form->{name}" if $form->{name};
157 push @options, $locale->text('Contact') . " : $form->{contact}" if $form->{contact};
158 push @options, $locale->text('Number') . qq| : $form->{"$form->{db}number"}| if $form->{"$form->{db}number"};
159 push @options, $locale->text('E-mail') . " : $form->{email}" if $form->{email};
160 push @options, $locale->text('Contact person (surname)') . " : $form->{cp_name}" if $form->{cp_name};
161 push @options, $locale->text('Billing/shipping address (city)') . " : $form->{addr_city}" if $form->{addr_city};
162 push @options, $locale->text('Billing/shipping address (zipcode)') . " : $form->{zipcode}" if $form->{addr_zipcode};
163 push @options, $locale->text('Billing/shipping address (street)') . " : $form->{street}" if $form->{addr_street};
165 if ($form->{business_id}) {
166 my $business = SL::DB::Manager::Business->find_by(id => $form->{business_id});
168 my $label = $form->{IS_CUSTOMER} ? $::locale->text('Customer type') : $::locale->text('Vendor type');
169 push @options, $label . " : " . $business->description;
174 'id', 'name', "$form->{db}number", 'contact', 'phone',
175 'fax', 'email', 'taxnumber', 'street', 'zipcode' , 'city',
176 'business', 'invnumber', 'ordnumber', 'quonumber'
179 my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs };
180 my @searchable_custom_variables = grep { $_->{searchable} } @{ $cvar_configs };
181 my %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables;
183 push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
186 'id' => { 'text' => $locale->text('ID'), },
187 "$form->{db}number" => { 'text' => $locale->text('Number'), },
188 'name' => { 'text' => $form->{IS_CUSTOMER} ? $::locale->text('Customer Name') : $::locale->text('Vendor Name'), },
189 'contact' => { 'text' => $locale->text('Contact'), },
190 'phone' => { 'text' => $locale->text('Phone'), },
191 'fax' => { 'text' => $locale->text('Fax'), },
192 'email' => { 'text' => $locale->text('E-mail'), },
193 'cc' => { 'text' => $locale->text('Cc'), },
194 'taxnumber' => { 'text' => $locale->text('Tax Number'), },
195 'business' => { 'text' => $locale->text('Type of Business'), },
196 'invnumber' => { 'text' => $locale->text('Invoice'), },
197 'ordnumber' => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Sales Order') : $locale->text('Purchase Order'), },
198 'quonumber' => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Quotation') : $locale->text('Request for Quotation'), },
199 'street' => { 'text' => $locale->text('Street'), },
200 'zipcode' => { 'text' => $locale->text('Zipcode'), },
201 'city' => { 'text' => $locale->text('City'), },
205 map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns;
207 my @hidden_variables = ( qw(
208 db status obsolete name contact email cp_name addr_street addr_zipcode
209 addr_city business_id
210 ), "$form->{db}number",
211 map({ "cvar_$_->{name}" } @searchable_custom_variables),
212 map({'cvar_'. $_->{name} .'_qtyop'} grep({$_->{type} eq 'number'} @searchable_custom_variables)),
213 map({ "l_$_" } @columns),
216 my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables);
217 my $callback = build_std_url('action=list_names', grep { $form->{$_} } @hidden_nondefault);
218 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
221 my $sortdir = $form->{sort} eq $_ ? 1 - $form->{sortdir} : $form->{sortdir};
222 $column_defs{$_}->{link} = "${callback}&sort=${_}&sortdir=${sortdir}";
225 my ($ordertype, $quotationtype, $attachment_basename);
226 if ($form->{IS_CUSTOMER}) {
227 $form->{title} = $locale->text('Customers');
228 $ordertype = 'sales_order';
229 $quotationtype = 'sales_quotation';
230 $attachment_basename = $locale->text('customer_list');
233 $form->{title} = $locale->text('Vendors');
234 $ordertype = 'purchase_order';
235 $quotationtype = 'request_quotation';
236 $attachment_basename = $locale->text('vendor_list');
239 my $report = SL::ReportGenerator->new(\%myconfig, $form);
241 $report->set_options('top_info_text' => join("\n", @options),
242 'raw_bottom_info_text' => $form->parse_html_template('ct/list_names_bottom'),
243 'output_format' => 'HTML',
244 'title' => $form->{title},
245 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
247 $report->set_options_from_form();
248 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
250 $report->set_columns(%column_defs);
251 $report->set_column_order(@columns);
253 $report->set_export_options('list_names', @hidden_variables, qw(sort sortdir));
255 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
257 CVar->add_custom_variables_to_report('module' => 'CT',
258 'trans_id_field' => 'id',
259 'configs' => $cvar_configs,
260 'column_defs' => \%column_defs,
261 'data' => $form->{CT});
265 foreach my $ref (@{ $form->{CT} }) {
266 my $row = { map { $_ => { 'data' => '' } } @columns };
268 if ($ref->{id} ne $previous_id) {
269 $previous_id = $ref->{id};
270 map { $row->{$_}->{data} = $ref->{$_} } @columns;
272 $row->{name}->{link} = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback', @hidden_nondefault);
273 $row->{email}->{link} = 'mailto:' . E($ref->{email});
276 my $base_url = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{invid}), 'callback', @hidden_nondefault);
277 $row->{invnumber}->{link} = $base_url;
278 $row->{ordnumber}->{link} = $base_url . "&type=${ordertype}";
279 $row->{quonumber}->{link} = $base_url . "&type=${quotationtype}";
280 my $column = $ref->{formtype} eq 'invoice' ? 'invnumber' : $ref->{formtype} eq 'order' ? 'ordnumber' : 'quonumber';
281 $row->{$column}->{data} = $ref->{$column};
283 $report->add_data($row);
286 $report->generate_with_headers();
288 $main::lxdebug->leave_sub();
292 $::lxdebug->enter_sub;
293 $::auth->assert('customer_vendor_edit');
295 $::form->{sortdir} = 1 unless defined $::form->{sortdir};
297 my @contacts = CT->search_contacts(
298 search_term => $::form->{search_term},
299 filter => $::form->{filter},
302 my $cvar_configs = CVar->get_configs('module' => 'Contacts');
305 cp_id vcname vcnumber cp_name cp_givenname cp_street cp_zipcode cp_city cp_phone1 cp_phone2
306 cp_mobile1 cp_mobile2 cp_email cp_abteilung cp_birthday cp_gender
309 my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs };
310 my @searchable_custom_variables = grep { $_->{searchable} } @{ $cvar_configs };
311 my %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables;
313 push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
317 @visible_columns = grep { $::form->{l}{$_} } @columns;
318 push @visible_columns, qw(cp_phone1 cp_phone2) if $::form->{l}{cp_phone};
319 push @visible_columns, qw(cp_mobile1 cp_mobile2) if $::form->{l}{cp_mobile};
321 @visible_columns = qw(vcname vcnumber cp_name cp_givenname cp_phone1 cp_phone2 cp_mobile1 cp_email);
325 'cp_id' => { 'text' => $::locale->text('ID'), },
326 'vcname' => { 'text' => $::locale->text('Customer/Vendor'), },
327 'vcnumber' => { 'text' => $::locale->text('Customer/Vendor Number'), },
328 'cp_name' => { 'text' => $::locale->text('Name'), },
329 'cp_givenname' => { 'text' => $::locale->text('Given Name'), },
330 'cp_street' => { 'text' => $::locale->text('Street'), },
331 'cp_zipcode' => { 'text' => $::locale->text('Zipcode'), },
332 'cp_city' => { 'text' => $::locale->text('City'), },
333 'cp_phone1' => { 'text' => $::locale->text('Phone1'), },
334 'cp_phone2' => { 'text' => $::locale->text('Phone2'), },
335 'cp_mobile1' => { 'text' => $::locale->text('Mobile1'), },
336 'cp_mobile2' => { 'text' => $::locale->text('Mobile2'), },
337 'cp_email' => { 'text' => $::locale->text('E-mail'), },
338 'cp_abteilung' => { 'text' => $::locale->text('Department'), },
339 'cp_birthday' => { 'text' => $::locale->text('Birthday'), },
340 'cp_gender' => { 'text' => $::locale->text('Gender'), },
344 map { $column_defs{$_}->{visible} = 1 } @visible_columns;
346 my @hidden_variables = (qw(search_term filter l));
347 my $hide_vars = { map { $_ => $::form->{$_} } @hidden_variables };
348 my @hidden_nondefault = grep({ $::form->{$_} } @hidden_variables);
349 my $callback = build_std_url('action=list_contacts', join '&', map { E($_->[0]) . '=' . E($_->[1]) } @{ flatten($hide_vars) });
350 $::form->{callback} = "$callback&sort=" . E($::form->{sort});
352 map { $column_defs{$_}->{link} = "${callback}&sort=${_}&sortdir=" . ($::form->{sort} eq $_ ? 1 - $::form->{sortdir} : $::form->{sortdir}) } @columns;
354 $::form->{title} = $::locale->text('Contacts');
356 my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
359 push @options, $::locale->text('Search term') . ': ' . $::form->{search_term} if $::form->{search_term};
360 for (qw(cp_name cp_givenname cp_title cp_email cp_abteilung cp_project)) {
361 push @options, $column_defs{$_}{text} . ': ' . $::form->{filter}{$_} if $::form->{filter}{$_};
363 if ($::form->{filter}{status}) {
364 push @options, $::locale->text('Status') . ': ' . (
365 $::form->{filter}{status} =~ /active/ ? $::locale->text('Active') :
366 $::form->{filter}{status} =~ /orphaned/ ? $::locale->text('Orphaned') :
367 $::form->{filter}{status} =~ /all/ ? $::locale->text('All') : ''
372 $report->set_options('top_info_text' => join("\n", @options),
373 'output_format' => 'HTML',
374 'title' => $::form->{title},
375 'attachment_basename' => $::locale->text('contact_list') . strftime('_%Y%m%d', localtime time),
377 $report->set_options_from_form;
379 $report->set_columns(%column_defs);
380 $report->set_column_order(@columns);
382 $report->set_export_options('list_contacts', @hidden_variables);
384 $report->set_sort_indicator($::form->{sort}, $::form->{sortdir});
386 CVar->add_custom_variables_to_report('module' => 'Contacts',
387 'trans_id_field' => 'cp_id',
388 'configs' => $cvar_configs,
389 'column_defs' => \%column_defs,
390 'data' => \@contacts);
393 foreach my $ref (@contacts) {
394 my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
396 $row->{vcname}->{link} = build_std_url('action=edit', 'id=' . E($ref->{vcid}), 'db=' . E($ref->{db}), 'callback', @hidden_nondefault);
397 $row->{vcnumber}->{link} = $row->{vcname}->{link};
398 $row->{cp_email}->{link} = 'mailto:' . E($ref->{cp_email});
400 $report->add_data($row);
403 $report->generate_with_headers;
405 $::lxdebug->leave_sub;
409 $main::lxdebug->enter_sub();
411 $main::auth->assert('customer_vendor_edit');
413 my $form = $main::form;
414 my %myconfig = %main::myconfig;
416 # show history button
417 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
418 #/show hhistory button
420 CT->get_tuple(\%myconfig, \%$form);
421 CT->populate_drop_down_boxes(\%myconfig, \%$form);
423 $form->{title} = "Edit";
426 $form->{discount} *= 100;
428 $form->{homepage} = 'http://' . $form->{homepage} unless ((!$form->{homepage}) || $form->{homepage} =~ m|^https?://|);
433 $main::lxdebug->leave_sub();
438 join('; ', grep { $_ } map { $s->{"shipto$_"} } qw(name department_1 street city)) || ' '
441 sub _contacts_label {
442 join ", ", grep { $_ } $_[0]->{cp_name}, $_[0]->{cp_givenname};
446 $main::lxdebug->enter_sub();
448 $main::auth->assert('customer_vendor_edit');
450 my $form = $main::form;
451 my %myconfig = %main::myconfig;
452 my $locale = $main::locale;
454 $form->get_lists(taxzones => "ALL_TAXZONES",
455 currencies => "ALL_CURRENCIES");
456 $form->get_pricegroup(\%myconfig, { all => 1 });
458 $form->get_lists(customers => { key => "ALL_SALESMAN_CUSTOMERS", business_is_salesman => 1 }) if $::lx_office_conf{features}->{vertreter};
459 $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{FU_created_for_user}, deleted => 0 ] ]);
460 $form->{ALL_SALESMEN} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{salesman_id}, deleted => 0 ] ]);
461 $form->{USER} = SL::DB::Manager::Employee->current;
463 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
464 $form->{is_customer} = $form->{db} eq 'customer';
465 $form->{shipto_label} = \&_shipto_label;
466 $form->{contacts_label} = \&_contacts_label;
467 $form->{taxzone_id} = 0 if !$form->{id};
468 $form->{jsscript} = 1;
469 $form->{SHIPTO_ALL} = [ +{ shipto_id => '0', shiptoname => $::locale->text('All') }, @{ $form->{SHIPTO} } ];
470 $::request->{layout}->focus("#greeting");
472 $form->{title} = $form->{title_save}
473 || $locale->text("$form->{title} " . ucfirst $form->{db}) . ($form->{title} eq "Edit" ? " $form->{name}" : '');
475 CT->query_titles_and_greetings(\%myconfig, \%$form);
476 map { $form->{"MB_$_"} = [ map +{ id => $_, description => $_ }, @{ $form->{$_} } ] } qw(COMPANY_GREETINGS);
478 $form->{NOTES} ||= [ ];
480 if (!$form->{'language_id'}) {
481 my $l_id = SL::DB::Default->get->{'language_id'};
483 $form->{'default_language_id'} = $l_id;
487 if (!$form->{'id'}) {
488 $form->{'currency'} = $form->get_default_currency(\%myconfig);
490 $form->{currency} = $form->{curr};
493 $::form->{CUSTOM_VARIABLES} = { };
494 my %specs = ( CT => { field => 'id', name_prefix => '', },
495 Contacts => { field => 'cp_id', name_prefix => 'cp', },
498 for my $module (keys %specs) {
499 my $spec = $specs{$module};
501 $::form->{CUSTOM_VARIABLES}->{$module} = CVar->get_custom_variables(module => $module, trans_id => $::form->{ $spec->{field} });
502 CVar->render_inputs(variables => $::form->{CUSTOM_VARIABLES}->{$module}, name_prefix => $spec->{name_prefix})
503 if scalar @{ $::form->{CUSTOM_VARIABLES}->{$module} };
507 print $form->parse_html_template('ct/form_header');
509 $main::lxdebug->leave_sub();
513 $main::lxdebug->enter_sub();
515 $main::auth->assert('customer_vendor_edit');
517 my $form = $main::form;
519 print $form->parse_html_template('ct/form_footer', { is_orphaned => $form->{status} eq 'orphaned',
520 is_customer => $form->{db} eq 'customer' });
521 $main::lxdebug->leave_sub();
525 $main::auth->assert('customer_vendor_edit');
527 $::form->isblank("name", $::locale->text("Name missing!"));
529 if ($::form->{new_salesman_id} && $::lx_office_conf{features}->{vertreter}) {
530 $::form->{salesman_id} = $::form->{new_salesman_id};
531 delete $::form->{new_salesman_id};
534 my $res = $::form->{db} eq 'customer' ? CT->save_customer(\%::myconfig, $::form) : CT->save_vendor(\%::myconfig, $::form);
537 if ($::form->{"db"} eq "customer") {
538 $::form->error($::locale->text('This customer number is already in use.'));
540 $::form->error($::locale->text('This vendor number is already in use.'));
545 sub add_transaction {
546 $main::lxdebug->enter_sub();
548 $main::auth->assert('customer_vendor_edit & ' .
549 '(general_ledger | invoice_edit | vendor_invoice_edit | ' .
550 ' request_quotation_edit | sales_quotation_edit | sales_order_edit | purchase_order_edit)');
552 my $form = $main::form;
553 my %myconfig = %main::myconfig;
554 my $locale = $main::locale;
556 # # saving the history
557 # if(!exists $form->{addition}) {
558 # $form->{addition} = "ADD TRANSACTION";
559 # $form->save_history;
561 # # /saving the history
565 $form->{callback} = $form->escape($form->{callback}, 1);
566 my $name = $form->escape("$form->{name}", 1);
569 "$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
572 $main::lxdebug->leave_sub();
575 sub save_and_ap_transaction {
576 $main::lxdebug->enter_sub();
578 $main::auth->assert('customer_vendor_edit & general_ledger');
580 my $form = $main::form;
581 my %myconfig = %main::myconfig;
583 $form->{script} = "ap.pl";
585 if(!exists $form->{addition}) {
586 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
587 $form->{addition} = "SAVED";
590 # /saving the history
592 $main::lxdebug->leave_sub();
595 sub save_and_ar_transaction {
596 $main::lxdebug->enter_sub();
598 $main::auth->assert('customer_vendor_edit & general_ledger');
600 my $form = $main::form;
601 my %myconfig = %main::myconfig;
603 $form->{script} = "ar.pl";
605 if(!exists $form->{addition}) {
606 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
607 $form->{addition} = "SAVED";
610 # /saving the history
612 $main::lxdebug->leave_sub();
615 sub save_and_invoice {
616 $main::lxdebug->enter_sub();
618 my $form = $main::form;
619 my %myconfig = %main::myconfig;
621 if ($form->{db} eq 'customer') {
622 $main::auth->assert('customer_vendor_edit & invoice_edit');
624 $main::auth->assert('customer_vendor_edit & vendor_invoice_edit');
627 $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
628 $form->{type} = "invoice";
630 if(!exists $form->{addition}) {
631 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
632 $form->{addition} = "SAVED";
635 # /saving the history
637 $main::lxdebug->leave_sub();
641 $main::lxdebug->enter_sub();
643 $main::auth->assert('customer_vendor_edit & request_quotation_edit');
645 my $form = $main::form;
646 my %myconfig = %main::myconfig;
648 $form->{script} = "oe.pl";
649 $form->{type} = "request_quotation";
651 if(!exists $form->{addition}) {
652 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
653 $form->{addition} = "SAVED";
656 # /saving the history
658 $main::lxdebug->leave_sub();
661 sub save_and_quotation {
662 $main::lxdebug->enter_sub();
664 $main::auth->assert('customer_vendor_edit & sales_quotation_edit');
666 my $form = $main::form;
667 my %myconfig = %main::myconfig;
669 $form->{script} = "oe.pl";
670 $form->{type} = "sales_quotation";
672 if(!exists $form->{addition}) {
673 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
674 $form->{addition} = "SAVED";
677 # /saving the history
679 $main::lxdebug->leave_sub();
683 $main::lxdebug->enter_sub();
685 my $form = $main::form;
686 my %myconfig = %main::myconfig;
688 if ($form->{db} eq 'customer') {
689 $main::auth->assert('customer_vendor_edit & sales_order_edit');
691 $main::auth->assert('customer_vendor_edit & purchase_order_edit');
694 $form->{script} = "oe.pl";
696 ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
698 if(!exists $form->{addition}) {
699 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
700 $form->{addition} = "SAVED";
703 # /saving the history
705 $main::lxdebug->leave_sub();
709 $main::lxdebug->enter_sub();
711 $main::auth->assert('customer_vendor_edit');
713 my $form = $main::form;
714 my %myconfig = %main::myconfig;
715 my $locale = $main::locale;
717 my $msg = ucfirst $form->{db};
723 if(!exists $form->{addition}) {
724 $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
725 $form->{addition} = "SAVED";
728 # /saving the history
729 $form->redirect($locale->text($msg));
731 $main::lxdebug->leave_sub();
735 $main::lxdebug->enter_sub();
737 $main::auth->assert('customer_vendor_edit');
739 my $form = $main::form;
740 my %myconfig = %main::myconfig;
741 my $locale = $main::locale;
743 my $msg = ucfirst $form->{db};
749 if(!exists $form->{addition}) {
750 $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
751 $form->{addition} = "SAVED";
754 # /saving the history
757 $main::lxdebug->leave_sub();
762 $main::lxdebug->enter_sub();
764 $main::auth->assert('customer_vendor_edit');
766 my $form = $main::form;
767 my %myconfig = %main::myconfig;
768 my $locale = $main::locale;
770 CT->delete(\%myconfig, \%$form);
772 my $msg = ucfirst $form->{db};
775 if(!exists $form->{addition}) {
776 $form->{snumbers} = ($form->{"db"} eq "customer" ? qq|customernumber_| . $form->{customernumber} : qq|vendornumber_| . $form->{vendornumber});
777 $form->{addition} = "DELETED";
780 # /saving the history
781 $form->redirect($locale->text($msg));
783 $main::lxdebug->leave_sub();
787 $main::lxdebug->enter_sub();
789 $main::auth->assert('customer_vendor_edit');
791 my $form = $main::form;
796 $main::lxdebug->leave_sub();
800 $main::lxdebug->enter_sub();
802 $main::auth->assert('customer_vendor_edit');
804 my $form = $main::form;
807 $main::lxdebug->leave_sub();
811 $main::lxdebug->enter_sub();
813 $main::auth->assert('customer_vendor_edit');
815 CT->populate_drop_down_boxes(\%::myconfig, $::form);
816 CT->query_titles_and_greetings(\%::myconfig, $::form);
817 CT->get_contact(\%::myconfig, $::form) if $::form->{cp_id};
819 $::form->{CUSTOM_VARIABLES}{Contacts} = CVar->get_custom_variables(module => 'Contacts', trans_id => $::form->{cp_id});
820 CVar->render_inputs(variables => $::form->{CUSTOM_VARIABLES}{Contacts}, name_prefix => 'cp')
821 if scalar @{ $::form->{CUSTOM_VARIABLES}->{Contacts} };
823 $::form->{contacts_label} = \&_contacts_label;
825 print $::form->ajax_response_header(), $::form->parse_html_template('ct/_contact');
827 $main::lxdebug->leave_sub();
831 $main::lxdebug->enter_sub();
833 $main::auth->assert('customer_vendor_edit');
835 CT->populate_drop_down_boxes(\%::myconfig, $::form);
836 CT->get_shipto(\%::myconfig, $::form) if $::form->{shipto_id};
838 $::form->{shipto_label} = \&_shipto_label;
840 print $::form->ajax_response_header(), $::form->parse_html_template('ct/_shipto');
842 $main::lxdebug->leave_sub();
846 $::lxdebug->enter_sub;
848 $::auth->assert('customer_vendor_edit');
849 $::auth->assert('sales_all_edit');
851 CT->get_delivery(\%::myconfig, $::form );
853 print $::form->ajax_response_header,
854 $::form->parse_html_template('ct/get_delivery', {
855 is_customer => $::form->{db} eq 'customer',
858 $::lxdebug->leave_sub;
862 $::lxdebug->enter_sub;
863 $::auth->assert('customer_vendor_edit');
865 if (!$::form->{shipto_id}) {
866 flash('error', $::locale->text('No shipto selected to delete'));
869 CT->get_shipto(\%::myconfig, $::form);
871 my $shipto = SL::DB::Manager::Shipto->find_by(shipto_id => $::form->{shipto_id});
874 $shipto->detach->save;
875 flash('info', $::locale->text('Shipto is in use and was flagged invalid.'));
878 flash('info', $::locale->text('Shipto deleted.'));
880 delete $::form->{$_} for grep /^shipto/, keys %$::form;
885 $::lxdebug->leave_sub;
889 $::lxdebug->enter_sub;
890 $::auth->assert('customer_vendor_edit');
892 if (!$::form->{cp_id}) {
893 flash('error', $::locale->text('No contact selected to delete'));
896 CT->get_contact(\%::myconfig, $::form);
898 my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id});
900 if ($contact->used) {
901 $contact->detach->save;
902 flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
905 flash('info', $::locale->text('Contact deleted.'));
907 delete $::form->{$_} for grep /^cp_/, keys %$::form;
912 $::lxdebug->leave_sub;
915 sub ajax_autocomplete {
916 $main::lxdebug->enter_sub();
918 my $form = $main::form;
919 my %myconfig = %main::myconfig;
921 $form->{column} = 'name' unless $form->{column} =~ /^name$/;
922 $form->{vc} = 'customer' unless $form->{vc} =~ /^customer|vendor$/;
923 $form->{db} = $form->{vc}; # CT expects this
924 $form->{$form->{column}} = $form->{q} || '';
925 $form->{limit} = ($form->{limit} * 1) || 10;
926 $form->{searchitems} ||= '';
928 CT->search(\%myconfig, $form);
930 print $form->ajax_response_header(),
931 $form->parse_html_template('ct/ajax_autocomplete');
933 $main::lxdebug->leave_sub();
936 sub continue { call_sub($main::form->{nextsub}); }