1 package SL::Controller::CustomerVendor;
4 use parent qw(SL::Controller::Base);
6 use List::MoreUtils qw(any);
10 use SL::Helper::Flash;
11 use SL::Locale::String;
12 use SL::Controller::Helper::GetModels;
13 use SL::Controller::Helper::ReportGenerator;
14 use SL::Controller::Helper::ParseFilter;
23 use SL::DB::PaymentTerm;
24 use SL::DB::Pricegroup;
27 use SL::DB::FollowUpLink;
31 use SL::DB::PurchaseInvoice;
36 use Rose::Object::MakeMethods::Generic (
37 'scalar --get_set_init' => [ qw(customer_models vendor_models) ],
41 __PACKAGE__->run_before(
43 $::auth->assert('customer_vendor_edit');
46 __PACKAGE__->run_before(
50 'save_and_ap_transaction',
51 'save_and_ar_transaction',
63 __PACKAGE__->run_before(
64 '_load_customer_vendor',
74 # make sure this comes after _load_customer_vendor
75 __PACKAGE__->run_before(
76 '_check_customer_vendor_all_edit',
83 'save_and_ap_transaction',
84 'save_and_ar_transaction',
96 __PACKAGE__->run_before(
97 '_create_customer_vendor',
103 __PACKAGE__->run_before('normalize_name');
109 $self->_pre_render();
110 $self->{cv}->assign_attributes(hourly_rate => $::instance_conf->get_customer_hourly_rate) if $self->{cv}->is_customer;
113 'customer_vendor/form',
114 title => ($self->is_vendor() ? $::locale->text('Add Vendor') : $::locale->text('Add Customer')),
115 %{$self->{template_args}}
122 $self->_pre_render();
124 'customer_vendor/form',
125 title => ($self->is_vendor() ? $::locale->text('Edit Vendor') : $::locale->text('Edit Customer')),
126 %{$self->{template_args}}
133 if ($::request->type eq 'json') {
138 $cv_hash = $self->{cv}->as_tree;
139 $cv_hash->{cvars} = $self->{cv}->cvar_as_hashref;
142 $self->render(\ SL::JSON::to_json($cv_hash), { layout => 0, type => 'json', process => 0 });
149 my @errors = $self->{cv}->validate;
151 flash('error', @errors);
152 $self->_pre_render();
154 'customer_vendor/form',
155 title => ($self->is_vendor() ? t8('Edit Vendor') : t8('Edit Customer')),
156 %{$self->{template_args}}
158 $::dispatcher->end_request;
161 my $db = $self->{cv}->db;
163 $db->with_transaction(sub {
165 if ( $self->is_vendor() ) {
166 if ( $self->{cv}->vendornumber ) {
167 $cvs_by_nr = SL::DB::Manager::Vendor->get_all(query => [vendornumber => $self->{cv}->vendornumber]);
170 if ( $self->{cv}->customernumber ) {
171 $cvs_by_nr = SL::DB::Manager::Customer->get_all(query => [customernumber => $self->{cv}->customernumber]);
175 foreach my $entry (@{$cvs_by_nr}) {
176 if( $entry->id != $self->{cv}->id ) {
178 $self->is_vendor() ? $::locale->text('This vendor number is already in use.') : $::locale->text('This customer number is already in use.');
180 $::form->error($msg);
184 $self->{cv}->save(cascade => 1);
186 $self->{contact}->cp_cv_id($self->{cv}->id);
187 if( $self->{contact}->cp_name ne '' || $self->{contact}->cp_givenname ne '' ) {
188 $self->{contact}->save(cascade => 1);
191 if( $self->{note}->subject ne '' && $self->{note}->body ne '' ) {
193 if ( !$self->{note_followup}->follow_up_date ) {
194 $::form->error($::locale->text('Date missing!'));
197 $self->{note}->trans_id($self->{cv}->id);
198 $self->{note}->save();
200 $self->{note_followup}->save();
202 $self->{note_followup_link}->follow_up_id($self->{note_followup}->id);
203 $self->{note_followup_link}->trans_id($self->{cv}->id);
204 $self->{note_followup_link}->save();
206 SL::Helper::Flash::flash_later('info', $::locale->text('Follow-Up saved.'));
209 $self->{shipto}->trans_id($self->{cv}->id);
210 if(any { $self->{shipto}->$_ ne '' } qw(shiptoname shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact shiptophone shiptofax shiptoemail)) {
211 $self->{shipto}->save(cascade => 1);
214 my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
215 SL::DB::History->new(
216 trans_id => $self->{cv}->id,
217 snumbers => $snumbers,
218 employee_id => SL::DB::Manager::Employee->current->id,
222 if ( $::form->{delete_notes} ) {
223 foreach my $note_id (@{ $::form->{delete_notes} }) {
224 my $note = SL::DB::Note->new(id => $note_id)->load();
225 if ( $note->follow_up ) {
226 if ( $note->follow_up->follow_up_link ) {
227 $note->follow_up->follow_up_link->delete(cascade => 'delete');
229 $note->follow_up->delete(cascade => 'delete');
231 $note->delete(cascade => 'delete');
236 }) || die($db->error);
245 my @redirect_params = (
247 id => $self->{cv}->id,
248 db => ($self->is_vendor() ? 'vendor' : 'customer'),
251 if ( $self->{contact}->cp_id ) {
252 push(@redirect_params, contact_id => $self->{contact}->cp_id);
255 if ( $self->{shipto}->shipto_id ) {
256 push(@redirect_params, shipto_id => $self->{shipto}->shipto_id);
259 $self->redirect_to(@redirect_params);
262 sub action_save_and_close {
267 my $msg = $self->is_vendor() ? $::locale->text('Vendor saved') : $::locale->text('Customer saved');
268 $::form->redirect($msg);
272 my ($self, $script) = @_;
274 $::auth->assert('gl_transactions | ap_transactions | ar_transactions'.
275 '| invoice_edit | vendor_invoice_edit | ' .
276 ' request_quotation_edit | sales_quotation_edit | sales_order_edit | purchase_order_edit');
280 my $name = $::form->escape($self->{cv}->name, 1);
281 my $db = $self->is_vendor() ? 'vendor' : 'customer';
284 if ($::instance_conf->get_feature_experimental && 'oe.pl' eq $script) {
285 $script = 'controller.pl';
286 $action = 'Order/' . $action;
289 my $url = $self->url_for(
290 controller => $script,
293 $db .'_id' => $self->{cv}->id,
295 type => $::form->{type},
296 callback => $::form->{callback},
299 print $::form->redirect_header($url);
302 sub action_save_and_ar_transaction {
305 $main::auth->assert('ar_transactions');
307 $self->_transaction('ar.pl');
310 sub action_save_and_ap_transaction {
313 $main::auth->assert('ap_transactions');
315 $self->_transaction('ap.pl');
318 sub action_save_and_invoice {
321 if ( $self->is_vendor() ) {
322 $::auth->assert('vendor_invoice_edit');
324 $::auth->assert('invoice_edit');
327 $::form->{type} = 'invoice';
328 $self->_transaction($self->is_vendor() ? 'ir.pl' : 'is.pl');
331 sub action_save_and_order {
334 if ( $self->is_vendor() ) {
335 $::auth->assert('purchase_order_edit');
337 $::auth->assert('sales_order_edit');
340 $::form->{type} = $self->is_vendor() ? 'purchase_order' : 'sales_order';
341 $self->_transaction('oe.pl');
344 sub action_save_and_rfq {
347 $::auth->assert('request_quotation_edit');
349 $::form->{type} = 'request_quotation';
350 $self->_transaction('oe.pl');
353 sub action_save_and_quotation {
356 $::auth->assert('sales_quotation_edit');
358 $::form->{type} = 'sales_quotation';
359 $self->_transaction('oe.pl');
365 my $db = $self->{cv}->db;
367 if( !$self->is_orphaned() ) {
368 $self->action_edit();
371 $db->with_transaction(sub {
372 $self->{cv}->delete(cascade => 1);
374 my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
375 SL::DB::History->new(
376 trans_id => $self->{cv}->id,
377 snumbers => $snumbers,
378 employee_id => SL::DB::Manager::Employee->current->id,
379 addition => 'DELETED',
381 }) || die($db->error);
383 my $msg = $self->is_vendor() ? $::locale->text('Vendor deleted!') : $::locale->text('Customer deleted!');
384 $::form->redirect($msg);
390 sub action_delete_contact {
393 my $db = $self->{contact}->db;
395 if ( !$self->{contact}->cp_id ) {
396 SL::Helper::Flash::flash('error', $::locale->text('No contact selected to delete'));
399 $db->with_transaction(sub {
400 if ( $self->{contact}->used ) {
401 $self->{contact}->detach();
402 $self->{contact}->save();
403 SL::Helper::Flash::flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
405 $self->{contact}->delete(cascade => 1);
406 SL::Helper::Flash::flash('info', $::locale->text('Contact deleted.'));
410 }) || die($db->error);
412 $self->{contact} = $self->_new_contact_object;
415 $self->action_edit();
418 sub action_delete_shipto {
421 my $db = $self->{shipto}->db;
423 if ( !$self->{shipto}->shipto_id ) {
424 SL::Helper::Flash::flash('error', $::locale->text('No shipto selected to delete'));
427 $db->with_transaction(sub {
428 if ( $self->{shipto}->used ) {
429 $self->{shipto}->detach();
430 $self->{shipto}->save(cascade => 1);
431 SL::Helper::Flash::flash('info', $::locale->text('Shipto is in use and was flagged invalid.'));
433 $self->{shipto}->delete(cascade => 1);
434 SL::Helper::Flash::flash('info', $::locale->text('Shipto deleted.'));
438 }) || die($db->error);
440 $self->{shipto} = SL::DB::Shipto->new();
443 $self->action_edit();
451 controller => 'ct.pl',
453 db => $self->is_vendor() ? 'vendor' : 'customer',
456 if ( $::form->{callback} ) {
457 push(@url_params, callback => $::form->{callback});
460 $self->redirect_to(@url_params);
464 sub action_search_contact {
467 my $url = 'ct.pl?action=search_contact&db=customer';
469 if ( $::form->{callback} ) {
470 $url .= '&callback='. $::form->escape($::form->{callback});
473 print $::form->redirect_header($url);
476 sub action_get_delivery {
479 $::auth->assert('sales_all_edit');
481 my $dbh = $::form->get_standard_dbh();
483 my ($arap, $db, $qty_sign);
484 if ( $self->is_vendor() ) {
487 $qty_sign = ' * -1 AS qty';
494 my $where = ' WHERE 1=1';
497 if ( !$self->is_vendor() && $::form->{shipto_id} && $::form->{shipto_id} ne 'all' ) {
498 $where .= " AND ${arap}.shipto_id = ?";
499 push(@values, $::form->{shipto_id});
501 $where .= " AND ${arap}.${db}_id = ?";
502 push(@values, $::form->{id});
505 if ( $::form->{delivery_from} ) {
506 $where .= " AND ${arap}.transdate >= ?";
507 push(@values, conv_date($::form->{delivery_from}));
510 if ( $::form->{delivery_to} ) {
511 $where .= " AND ${arap}.transdate <= ?";
512 push(@values, conv_date($::form->{delivery_to}));
531 ON ". ($arap eq 'ar' ? '(ar.shipto_id = s.shipto_id) ' : '(ap.id = s.trans_id) ') ."
534 ON ${arap}.id = i.trans_id
540 ON (oe.ordnumber = ${arap}.ordnumber AND NOT ${arap}.ordnumber = ''
541 AND ". ($arap eq 'ar' ? 'oe.customer_id IS NOT NULL' : 'oe.vendor_id IS NOT NULL') ." )
544 ORDER BY ${arap}.transdate DESC LIMIT 15";
546 $self->{delivery} = selectall_hashref_query($::form, $dbh, $query, @values);
548 $self->render('customer_vendor/get_delivery', { layout => 0 });
551 sub action_ajaj_get_shipto {
558 my $name = 'shipto'. $_;
559 $name => $self->{shipto}->$name;
561 qw(_id name department_1 department_2 street zipcode city gln country contact phone fax email)
565 $data->{shipto_cvars} = $self->_prepare_cvar_configs_for_ajaj($self->{shipto}->cvars_by_config);
567 $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
570 sub action_ajaj_get_contact {
578 my $name = 'cp_'. $_;
580 if ( $_ eq 'birthday' && $self->{contact}->$name ) {
581 $name => $self->{contact}->$name->to_lxoffice;
583 $name => $self->{contact}->$name;
587 id gender abteilung title position givenname name email phone1 phone2 fax mobile1 mobile2
588 satphone satfax project street zipcode city privatphone privatemail birthday
593 $data->{contact_cvars} = $self->_prepare_cvar_configs_for_ajaj($self->{contact}->cvars_by_config);
595 $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
598 sub action_ajaj_autocomplete {
599 my ($self, %params) = @_;
601 my ($model, $manager, $number, $matches);
603 # first see if this is customer or vendor picking
604 if ($::form->{type} eq 'customer') {
605 $model = $self->customer_models;
606 $manager = 'SL::DB::Manager::Customer';
607 $number = 'customernumber';
608 } elsif ($::form->{type} eq 'vendor') {
609 $model = $self->vendor_models;
610 $manager = 'SL::DB::Manager::Vendor';
611 $number = 'vendornumber';
613 die "unknown type $::form->{type}";
616 # if someone types something, and hits enter, assume he entered the full name.
617 # if something matches, treat that as sole match
618 # unfortunately get_models can't do more than one per package atm, so we d it
619 # the oldfashioned way.
620 if ($::form->{prefer_exact}) {
622 if (1 == scalar @{ $exact_matches = $manager->get_all(
625 (salesman_id => SL::DB::Manager::Employee->current->id) x !$::auth->assert('customer_vendor_all_edit', 1),
627 name => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
628 $number => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
633 $matches = $exact_matches;
637 $matches //= $model->get;
641 value => $_->displayable_name,
642 label => $_->displayable_name,
644 $number => $_->$number,
646 type => $::form->{type},
647 cvars => { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $_->cvars_by_config } },
651 $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
654 sub action_test_page {
655 $_[0]->render('customer_vendor/test_page');
659 return $::form->{db} eq 'vendor';
663 return $::form->{db} eq 'customer';
669 if ( defined($self->{_is_orphaned}) ) {
670 return $self->{_is_orphaned};
673 my $arap = $self->is_vendor ? 'ap' : 'ar';
676 my $cv = $self->is_vendor ? 'vendor' : 'customer';
680 FROM '. $arap .' AS a
681 JOIN '. $cv .' ct ON (a.'. $cv .'_id = ct.id)
688 JOIN '. $cv .' ct ON (a.'. $cv .'_id = ct.id)
694 FROM delivery_orders a
695 JOIN '. $cv .' ct ON (a.'. $cv .'_id = ct.id)
699 if ( $self->is_vendor ) {
702 SELECT 1 FROM makemodel mm WHERE mm.make = ?';
706 my ($dummy) = selectrow_query($::form, $::form->get_standard_dbh(), $query, (conv_i($self->{cv}->id)) x $num_args);
708 return $self->{_is_orphaned} = !$dummy;
711 sub _copy_form_to_cvars {
712 my ($self, %params) = @_;
714 foreach my $cvar (@{ $params{target}->cvars_by_config }) {
715 my $value = $params{source}->{$cvar->config->name};
716 $value = $::form->parse_amount(\%::myconfig, $value) if $cvar->config->type eq 'number';
718 $cvar->value($value);
722 sub _instantiate_args {
725 my $curr_employee = SL::DB::Manager::Employee->current;
727 if ( $::form->{cv}->{id} ) {
728 if ( $self->is_vendor() ) {
729 $self->{cv} = SL::DB::Vendor->new(id => $::form->{cv}->{id})->load();
731 $self->{cv} = SL::DB::Customer->new(id => $::form->{cv}->{id})->load();
734 $self->{cv} = $self->_new_customer_vendor_object;
736 $self->{cv}->assign_attributes(%{$::form->{cv}});
738 if ( $self->is_customer() && $::form->{cv}->{taxincluded_checked} eq '' ) {
739 $self->{cv}->taxincluded_checked(undef);
742 $self->{cv}->hourly_rate($::instance_conf->get_customer_hourly_rate) if $self->is_customer && !$self->{cv}->hourly_rate;
744 if ( $::form->{note}->{id} ) {
745 $self->{note} = SL::DB::Note->new(id => $::form->{note}->{id})->load();
746 $self->{note_followup} = $self->{note}->follow_up;
747 $self->{note_followup_link} = $self->{note_followup}->follow_up_link;
749 $self->{note} = SL::DB::Note->new();
750 $self->{note_followup} = SL::DB::FollowUp->new();
751 $self->{note_followup_link} = SL::DB::FollowUpLink->new();
754 $self->{note}->assign_attributes(%{$::form->{note}});
755 $self->{note}->created_by($curr_employee->id);
756 $self->{note}->trans_module('ct');
758 $self->{note_followup}->assign_attributes(%{$::form->{note_followup}});
759 $self->{note_followup}->note($self->{note});
760 $self->{note_followup}->created_by($curr_employee->id);
762 $self->{note_followup_link}->trans_type($self->is_vendor() ? 'vendor' : 'customer');
763 $self->{note_followup_link}->trans_info($self->{cv}->name);
765 if ( $::form->{shipto}->{shipto_id} ) {
766 $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto}->{shipto_id})->load();
768 $self->{shipto} = SL::DB::Shipto->new();
770 $self->{shipto}->assign_attributes(%{$::form->{shipto}});
771 $self->{shipto}->module('CT');
773 if ( $::form->{contact}->{cp_id} ) {
774 $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact}->{cp_id})->load();
776 $self->{contact} = $self->_new_contact_object;
778 $self->{contact}->assign_attributes(%{$::form->{contact}});
780 $self->_copy_form_to_cvars(target => $self->{cv}, source => $::form->{cv_cvars});
781 $self->_copy_form_to_cvars(target => $self->{contact}, source => $::form->{contact_cvars});
782 $self->_copy_form_to_cvars(target => $self->{shipto}, source => $::form->{shipto_cvars});
785 sub _load_customer_vendor {
788 if ( $self->is_vendor() ) {
789 $self->{cv} = SL::DB::Vendor->new(id => $::form->{id})->load();
791 $self->{cv} = SL::DB::Customer->new(id => $::form->{id})->load();
794 if ( $::form->{note_id} ) {
795 $self->{note} = SL::DB::Note->new(id => $::form->{note_id})->load();
796 $self->{note_followup} = $self->{note}->follow_up;
797 $self->{note_followup_link} = $self->{note_followup}->follow_up_link;
799 $self->{note} = SL::DB::Note->new();
800 $self->{note_followup} = SL::DB::FollowUp->new();
801 $self->{note_followup_link} = SL::DB::FollowUpLink->new();
804 if ( $::form->{shipto_id} ) {
805 $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto_id})->load();
807 if ( $self->{shipto}->trans_id != $self->{cv}->id ) {
808 die($::locale->text('Error'));
811 $self->{shipto} = SL::DB::Shipto->new();
814 if ( $::form->{contact_id} ) {
815 $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact_id})->load();
817 if ( $self->{contact}->cp_cv_id != $self->{cv}->id ) {
818 die($::locale->text('Error'));
821 $self->{contact} = $self->_new_contact_object;
825 sub _check_customer_vendor_all_edit {
828 unless ($::auth->assert('customer_vendor_all_edit', 1)) {
829 die($::locale->text("You don't have the rights to edit this customer.") . "\n")
830 if $self->{cv}->is_customer and
831 SL::DB::Manager::Employee->current->id != $self->{cv}->salesman_id;
835 sub _create_customer_vendor {
838 $self->{cv} = $self->_new_customer_vendor_object;
839 $self->{cv}->currency_id($::instance_conf->get_currency_id());
841 $self->{note} = SL::DB::Note->new();
843 $self->{note_followup} = SL::DB::FollowUp->new();
845 $self->{shipto} = SL::DB::Shipto->new();
847 $self->{contact} = $self->_new_contact_object;
853 my $dbh = $::form->get_standard_dbh();
857 $self->{all_business} = SL::DB::Manager::Business->get_all();
859 $self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
862 'SELECT DISTINCT(greeting)
864 WHERE greeting IS NOT NULL AND greeting != \'\'
866 SELECT DISTINCT(greeting)
868 WHERE greeting IS NOT NULL AND greeting != \'\'
870 $self->{all_greetings} = [
873 selectall_hashref_query($::form, $dbh, $query)
878 'SELECT DISTINCT(cp_title) AS title
880 WHERE cp_title IS NOT NULL AND cp_title != \'\'
882 $self->{all_titles} = [
885 selectall_hashref_query($::form, $dbh, $query)
889 $self->{all_currencies} = SL::DB::Manager::Currency->get_all();
891 $self->{all_languages} = SL::DB::Manager::Language->get_all();
893 $self->{all_taxzones} = SL::DB::Manager::TaxZone->get_all_sorted();
895 if ( $::instance_conf->get_vertreter() ) {
903 selectall_hashref_query($::form, $dbh, $query)
907 if ( $business_ids->[0] ) {
908 $self->{all_salesman_customers} = SL::DB::Manager::Customer->get_all(query => [business_id => $business_ids]);
910 $self->{all_salesman_customers} = [];
913 $self->{all_salesmen} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $self->{cv}->salesman_id, deleted => 0 ] ]);
916 $self->{all_payment_terms} = SL::DB::Manager::PaymentTerm->get_all_sorted(where => [ or => [ id => $self->{cv}->payment_id,
919 $self->{all_delivery_terms} = SL::DB::Manager::DeliveryTerm->get_all();
921 if ($self->{cv}->is_customer) {
922 $self->{all_pricegroups} = SL::DB::Manager::Pricegroup->get_all_sorted(query => [ or => [ id => $self->{cv}->pricegroup_id, obsolete => 0 ] ]);
926 'SELECT DISTINCT(cp_abteilung) AS department
928 WHERE cp_abteilung IS NOT NULL AND cp_abteilung != \'\'
929 ORDER BY cp_abteilung';
930 $self->{all_departments} = [
932 { $_->{department}; }
933 selectall_hashref_query($::form, $dbh, $query)
937 $self->{contacts} = $self->{cv}->contacts;
938 $self->{contacts} ||= [];
940 $self->{shiptos} = $self->{cv}->shipto;
941 $self->{shiptos} ||= [];
943 $self->{notes} = SL::DB::Manager::Note->get_all(
945 trans_id => $self->{cv}->id,
946 trans_module => 'ct',
948 with_objects => ['follow_up'],
951 if ( $self->is_vendor()) {
952 $self->{open_items} = SL::DB::Manager::PurchaseInvoice->get_all_count(
954 vendor_id => $self->{cv}->id,
955 paid => {lt_sql => 'amount'},
959 $self->{open_items} = SL::DB::Manager::Invoice->get_all_count(
961 customer_id => $self->{cv}->id,
962 paid => {lt_sql => 'amount'},
967 if ( $self->is_vendor() ) {
968 $self->{open_orders} = SL::DB::Manager::Order->get_all_count(
970 vendor_id => $self->{cv}->id,
975 $self->{open_orders} = SL::DB::Manager::Order->get_all_count(
977 customer_id => $self->{cv}->id,
982 $self->{template_args} ||= {};
984 $::request->{layout}->add_javascripts('kivi.CustomerVendor.js');
985 $::request->{layout}->add_javascripts('kivi.File.js');
987 $self->_setup_form_action_bar;
990 sub _setup_form_action_bar {
993 for my $bar ($::request->layout->get('actionbar')) {
998 submit => [ '#form', { action => "CustomerVendor/save" } ],
999 checks => [ 'check_taxzone_and_ustid' ],
1000 accesskey => 'enter',
1003 t8('Save and Close'),
1004 submit => [ '#form', { action => "CustomerVendor/save_and_close" } ],
1005 checks => [ 'check_taxzone_and_ustid' ],
1007 ], # end of combobox "Save"
1010 action => [ t8('Workflow') ],
1012 t8('Save and AP Transaction'),
1013 submit => [ '#form', { action => "CustomerVendor/save_and_ap_transaction" } ],
1014 checks => [ 'check_taxzone_and_ustid' ],
1015 ]) x !!$self->is_vendor,
1017 t8('Save and AR Transaction'),
1018 submit => [ '#form', { action => "CustomerVendor/save_and_ar_transaction" } ],
1019 checks => [ 'check_taxzone_and_ustid' ],
1020 ]) x !$self->is_vendor,
1022 t8('Save and Invoice'),
1023 submit => [ '#form', { action => "CustomerVendor/save_and_invoice" } ],
1024 checks => [ 'check_taxzone_and_ustid' ],
1027 t8('Save and Order'),
1028 submit => [ '#form', { action => "CustomerVendor/save_and_order" } ],
1029 checks => [ 'check_taxzone_and_ustid' ],
1033 submit => [ '#form', { action => "CustomerVendor/save_and_rfq" } ],
1034 checks => [ 'check_taxzone_and_ustid' ],
1035 ]) x !!$self->is_vendor,
1037 t8('Save and Quotation'),
1038 submit => [ '#form', { action => "CustomerVendor/save_and_quotation" } ],
1039 checks => [ 'check_taxzone_and_ustid' ],
1040 ]) x !$self->is_vendor,
1041 ], # end of combobox "Workflow"
1045 submit => [ '#form', { action => "CustomerVendor/delete" } ],
1046 confirm => t8('Do you really want to delete this object?'),
1047 disabled => !$self->{cv}->id ? t8('This object has not been saved yet.')
1048 : !$self->is_orphaned ? t8('This object has already been used.')
1056 call => [ 'kivi.CustomerVendor.showHistoryWindow', $self->{cv}->id ],
1057 disabled => !$self->{cv}->id ? t8('This object has not been saved yet.') : undef,
1063 sub _prepare_cvar_configs_for_ajaj {
1064 my ($self, $cvars) = @_;
1069 my $result = { type => $cvar->config->type };
1071 if ($cvar->config->type eq 'number') {
1072 $result->{value} = $::form->format_amount(\%::myconfig, $cvar->value, -2);
1074 } elsif ($result->{type} eq 'date') {
1075 $result->{value} = $cvar->value ? $cvar->value->to_kivitendo : undef;
1077 } elsif ($result->{type} =~ m{customer|vendor|part}) {
1078 my $object = $cvar->value;
1079 my $method = $result->{type} eq 'part' ? 'description' : 'name';
1081 $result->{id} = int($cvar->number_value) || undef;
1082 $result->{value} = $object ? $object->$method // '' : '';
1085 $result->{value} = $cvar->value;
1088 ( $cvar->config->name => $result )
1090 } grep { $_->is_valid } @{ $cvars }
1094 sub normalize_name {
1097 # check if feature is enabled (select normalize_vc_names from defaults)
1098 return unless ($::instance_conf->get_normalize_vc_names);
1100 return unless $self->{cv};
1101 my $name = $self->{cv}->name;
1105 $self->{cv}->name($name);
1108 sub home_address_for_google_maps {
1111 my $address = $::instance_conf->get_address // '';
1112 $address =~ s{^\s+|\s+$|\r+}{}g;
1113 $address =~ s{\n+}{,}g;
1114 $address =~ s{\s+}{ }g;
1119 sub init_customer_models {
1122 SL::Controller::Helper::GetModels->new(
1123 controller => $self,
1124 model => 'Customer',
1127 by => 'customernumber',
1130 customernumber => t8('Customer Number'),
1133 ( salesman_id => SL::DB::Manager::Employee->current->id) x !$::auth->assert('customer_vendor_all_edit', 1),
1138 sub init_vendor_models {
1141 SL::Controller::Helper::GetModels->new(
1142 controller => $self,
1146 by => 'vendornumber',
1149 vendornumber => t8('Vendor Number'),
1154 sub _new_customer_vendor_object {
1157 my $class = 'SL::DB::' . ($self->is_vendor ? 'Vendor' : 'Customer');
1161 custom_variables => [],
1165 sub _new_contact_object {
1168 return SL::DB::Contact->new(custom_variables => []);