6f253adf7b05a1f405be2b99a9d470e3f1511573
[kivitendo-erp.git] / SL / Controller / CustomerVendor.pm
1 package SL::Controller::CustomerVendor;
2
3 use strict;
4 use parent qw(SL::Controller::Base);
5
6 use SL::JSON;
7 use SL::DBUtils;
8 use SL::Helper::Flash;
9
10 use SL::DB::Customer;
11 use SL::DB::Vendor;
12 use SL::DB::Business;
13 use SL::DB::Employee;
14 use SL::DB::Language;
15 use SL::DB::TaxZone;
16 use SL::DB::Note;
17 use SL::DB::PaymentTerm;
18 use SL::DB::Pricegroup;
19 use SL::DB::Contact;
20 use SL::DB::FollowUp;
21 use SL::DB::History;
22 use SL::DB::Currency;
23
24 # safety
25 __PACKAGE__->run_before(
26   sub {
27     $::auth->assert('customer_vendor_edit');
28   }
29 );
30
31 __PACKAGE__->run_before(
32   '_instantiate_args',
33   only => [
34     'save',
35     'save_and_ap_transaction',
36     'save_and_ar_transaction',
37     'save_and_close',
38     'save_and_invoice',
39     'save_and_order',
40     'save_and_quotation',
41     'save_and_rfq',
42     'delete',
43     'delete_contact',
44     'delete_shipto',
45   ]
46 );
47
48 __PACKAGE__->run_before(
49   '_load_customer_vendor',
50   only => [
51     'edit',
52     'update',
53     'ajaj_get_shipto',
54     'ajaj_get_contact',
55   ]
56 );
57 __PACKAGE__->run_before(
58   '_create_customer_vendor',
59   only => [
60     'add',
61   ]
62 );
63
64 sub action_add {
65   my ($self) = @_;
66
67   $self->_pre_render();
68   $self->render(
69     'customer_vendor/form',
70     title => ($self->is_vendor() ? $::locale->text('Add Vendor') : $::locale->text('Add Customer')),
71     %{$self->{template_args}}
72   );
73 }
74
75 sub action_edit {
76   my ($self) = @_;
77
78   $self->_pre_render();
79   $self->render(
80     'customer_vendor/form',
81     title => ($self->is_vendor() ? $::locale->text('Edit Vendor') : $::locale->text('Edit Customer')),
82     %{$self->{template_args}}
83   );
84 }
85
86 sub _save {
87   my ($self) = @_;
88
89   my $db = $self->{cv}->db;
90
91   $db->do_transaction(sub {
92     my $cvs_by_nr;
93     if ( $self->is_vendor() ) {
94       if ( $self->{cv}->vendornumber ) {
95         $cvs_by_nr = SL::DB::Manager::Vendor->get_all(query => [vendornumber => $self->{cv}->vendornumber]);
96       }
97     } else {
98       if ( $self->{cv}->customernumber ) {
99         $cvs_by_nr = SL::DB::Manager::Customer->get_all(query => [customernumber => $self->{cv}->customernumber]);
100       }
101     }
102
103     foreach my $entry (@{$cvs_by_nr}) {
104       if( $entry->id != $self->{cv}->id ) {
105         my $msg =
106           $self->is_vendor() ? $::locale->text('This vendor number is already in use.') : $::locale->text('This customer number is already in use.');
107
108         $::form->error($msg);
109       }
110     }
111
112     $self->{cv}->save(cascade => 1);
113
114     $self->{contact}->cp_cv_id($self->{cv}->id);
115     if( $self->{contact}->cp_name ne '' || $self->{contact}->cp_givenname ne '' ) {
116       $self->{contact}->save();
117     }
118
119     if( $self->{note}->subject ne '' && $self->{note}->body ne '' ) {
120
121       if ( !$self->{note_followup}->follow_up_date ) {
122         $::form->error($::locale->text('Date missing!'));
123       }
124
125       $self->{note}->trans_id($self->{cv}->id);
126       $self->{note}->save();
127       $self->{note_followup}->save();
128
129       SL::Helper::Flash::flash_later('info', $::locale->text('Follow-Up saved.'));
130
131       $self->{note} = SL::DB::Note->new();
132       $self->{note_followup} = SL::DB::FollowUp->new();
133     }
134
135     $self->{shipto}->trans_id($self->{cv}->id);
136     if( $self->{shipto}->shiptoname ne '' ) {
137       $self->{shipto}->save();
138     }
139
140     my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
141     SL::DB::History->new(
142       trans_id => $self->{cv}->id,
143       snumbers => $snumbers,
144       employee_id => SL::DB::Manager::Employee->current->id,
145       addition => 'SAVED',
146     )->save();
147   }) || die($db->error);
148
149 }
150
151 sub action_save {
152   my ($self) = @_;
153
154   $self->_save();
155
156   my @redirect_params = (
157     action => 'edit',
158     id     => $self->{cv}->id,
159     db     => ($self->is_vendor() ? 'vendor' : 'customer'),
160   );
161
162   if ( $self->{contact}->cp_id ) {
163     push(@redirect_params, contact_id => $self->{contact}->cp_id);
164   }
165
166   if ( $self->{shipto}->shipto_id ) {
167     push(@redirect_params, shipto_id => $self->{shipto}->shipto_id);
168   }
169
170   $self->redirect_to(@redirect_params);
171 }
172
173 sub action_save_and_close {
174   my ($self) = @_;
175
176   $self->_save();
177
178   my $msg = $self->is_vendor() ? $::locale->text('Vendor saved') : $::locale->text('Customer saved');
179   $::form->redirect($msg);
180 }
181
182 sub _transaction {
183   my ($self, $script) = @_;
184
185   $::auth->assert('general_ledger         | invoice_edit         | vendor_invoice_edit | ' .
186                  ' request_quotation_edit | sales_quotation_edit | sales_order_edit    | purchase_order_edit');
187
188   $self->_save();
189
190   my $callback = $::form->escape($::form->{callback}, 1);
191   my $name = $::form->escape($self->{cv}->name, 1);
192   my $db = $self->is_vendor() ? 'vendor' : 'customer';
193
194   my $url = $self->url_for(
195     controller => $script,
196     action     => 'add',
197     vc         => $db,
198     $db .'_id' => $self->{cv}->id,
199     $db        => $name,
200     type       => $::form->{type},
201     callback   => $callback,
202   );
203
204   print $::form->redirect_header($url);
205 }
206
207 sub action_save_and_ar_transaction {
208   my ($self) = @_;
209
210   $main::auth->assert('general_ledger');
211
212   $self->_transaction('ar.pl');
213 }
214
215 sub action_save_and_ap_transaction {
216   my ($self) = @_;
217
218   $main::auth->assert('general_ledger');
219
220   $self->_transaction('ap.pl');
221 }
222
223 sub action_save_and_invoice {
224   my ($self) = @_;
225
226   if ( $self->is_vendor() ) {
227     $::auth->assert('vendor_invoice_edit');
228   } else {
229     $::auth->assert('invoice_edit');
230   }
231
232   $::form->{type} = 'invoice';
233   $self->_transaction($self->is_vendor() ? 'ir.pl' : 'is.pl');
234 }
235
236 sub action_save_and_order {
237   my ($self) = @_;
238
239   if ( $self->is_vendor() ) {
240     $::auth->assert('purchase_order_edit');
241   } else {
242     $::auth->assert('sales_order_edit');
243   }
244
245   $::form->{type} = $self->is_vendor() ? 'purchase_order' : 'sales_order';
246   $self->_transaction('oe.pl');
247 }
248
249 sub action_save_and_rfq {
250   my ($self) = @_;
251
252   $::auth->assert('request_quotation_edit');
253
254   $::form->{type} = 'request_quotation';
255   $self->_transaction('oe.pl');
256 }
257
258 sub action_save_and_quotation {
259   my ($self) = @_;
260
261   $::auth->assert('sales_quotation_edit');
262
263   $::form->{type} = 'sales_quotation';
264   $self->_transaction('oe.pl');
265 }
266
267 sub action_delete {
268   my ($self) = @_;
269
270   my $db = $self->{cv}->db;
271
272   if( !$self->is_orphaned() ) {
273     $self->action_edit();
274   } else {
275
276     $db->do_transaction(sub {
277       $self->{cv}->delete(cascade => 1);
278
279       my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
280       SL::DB::History->new(
281         trans_id => $self->{cv}->id,
282         snumbers => $snumbers,
283         employee_id => SL::DB::Manager::Employee->current->id,
284         addition => 'DELETED',
285       )->save();
286     }) || die($db->error);
287
288     my $msg = $self->is_vendor() ? $::locale->text('Vendor deleted!') : $::locale->text('Customer deleted!');
289     $::form->redirect($msg);
290   }
291
292 }
293
294
295 sub action_delete_contact {
296   my ($self) = @_;
297
298   my $db = $self->{contact}->db;
299
300   if ( !$self->{contact}->cp_id ) {
301     SL::Helper::Flash::flash('error', $::locale->text('No contact selected to delete'));
302   } else {
303
304     $db->do_transaction(sub {
305       if ( $self->{contact}->used ) {
306         $self->{contact}->detach();
307         $self->{contact}->save();
308         SL::Helper::Flash::flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
309       } else {
310         $self->{contact}->delete(cascade => 1);
311         SL::Helper::Flash::flash('info', $::locale->text('Contact deleted.'));
312       }
313     }) || die($db->error);
314
315     $self->{contact} = SL::DB::Contact->new();
316   }
317
318   $self->action_edit();
319 }
320
321 sub action_delete_shipto {
322   my ($self) = @_;
323
324   my $db = $self->{shipto}->db;
325
326   if ( !$self->{shipto}->shipto_id ) {
327     SL::Helper::Flash::flash('error', $::locale->text('No shipto selected to delete'));
328   } else {
329
330     $db->do_transaction(sub {
331       if ( $self->{shipto}->used ) {
332         $self->{shipto}->detach();
333         $self->{shipto}->save(cascade => 1);
334         SL::Helper::Flash::flash('info', $::locale->text('Shipto is in use and was flagged invalid.'));
335       } else {
336         $self->{shipto}->delete(cascade => 1);
337         SL::Helper::Flash::flash('info', $::locale->text('Shipto deleted.'));
338       }
339     }) || die($db->error);
340
341     $self->{shipto} = SL::DB::Shipto->new();
342   }
343
344   $self->action_edit();
345 }
346
347
348 sub action_search {
349   my ($self) = @_;
350
351   my $url = 'ct.pl?action=search&db='. ($self->is_vendor() ? 'vendor' : 'customer');
352
353   if ( $::form->{callback} ) {
354     $url .= '&callback='. $::from->escape($::form->{callback});
355   }
356
357   print $::form->redirect_header($url);
358 }
359
360
361 sub action_search_contact {
362   my ($self) = @_;
363
364   my $url = 'ct.pl?action=search_contact&db=customer';
365
366   if ( $::form->{callback} ) {
367     $url .= '&callback='. $::from->escape($::form->{callback});
368   }
369
370   print $::form->redirect_header($url);
371 }
372
373
374 sub action_get_delivery {
375   my ($self) = @_;
376
377   my $dbh = $::form->get_standard_dbh();
378
379   my ($arap, $db, $qty_sign);
380   if ( $self->is_vendor() ) {
381     $arap = 'ap';
382     $db = 'vendor';
383     $qty_sign = ' * -1 AS qty';
384   } else {
385     $arap = 'ar';
386     $db = 'customer';
387     $qty_sign = '';
388   }
389
390   my $where = ' WHERE 1=1 ';
391   my @values;
392
393   if ( !$self->is_vendor() && $::form->{shipto_id} && $::form->{shipto_id} ne 'all' ) {
394     $where .= "AND ${arap}.shipto_id = ?";
395     push(@values, $::form->{shipto_id});
396   }
397
398   if ( $::form->{delivery_from} ) {
399     $where .= "AND ${arap}.transdate >= ?";
400     push(@values, conv_date($::form->{delivery_from}));
401   }
402
403   if ( $::form->{delivery_to} ) {
404     $where .= "AND ${arap}.transdate <= ?";
405     push(@values, conv_date($::form->{delivery_to}));
406   }
407
408   my $query =
409     "SELECT
410        s.shiptoname,
411        i.qty ${qty_sign},
412        ${arap}.id,
413        ${arap}.transdate,
414        ${arap}.invnumber,
415        ${arap}.ordnumber,
416        i.description,
417        i.unit,
418        i.sellprice,
419        oe.id AS oe_id,
420        invoice
421      FROM ${arap}
422
423      LEFT JOIN shipto s
424       ON ". ($arap eq 'ar' ? '(ar.shipto_id = s.shipto_id) ' : '(ap.id = s.trans_id) ') ."
425
426      LEFT JOIN invoice i
427        ON ${arap}.id = i.trans_id
428
429      LEFT JOIN parts p
430        ON p.id = i.parts_id
431
432      LEFT JOIN oe
433        ON (oe.ordnumber = ${arap}.ordnumber AND NOT ${arap}.ordnumber = '')
434
435      ${where}
436      ORDER BY ${arap}.transdate DESC LIMIT 15";
437
438   $self->{delivery} = selectall_hashref_query($::form, $dbh, $query, @values);
439
440   $self->render('customer_vendor/get_delivery', { layout => 0 });
441 }
442
443 sub action_ajaj_get_shipto {
444   my ($self) = @_;
445
446   my $data = {
447     map(
448       {
449         my $name = 'shipto'. $_;
450         $name => $self->{shipto}->$name;
451       }
452       qw(_id name department_1 department_2 street zipcode city country contact phone fax email)
453     )
454   };
455
456   $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
457 }
458
459 sub action_ajaj_get_contact {
460   my ($self) = @_;
461
462   my $data;
463
464   $data->{contact} = {
465     map(
466       {
467         my $name = 'cp_'. $_;
468
469         if ( $_ eq 'birthday' && $self->{contact}->$name ) {
470           $name => $self->{contact}->$name->to_lxoffice;
471         } else {
472           $name => $self->{contact}->$name;
473         }
474       }
475       qw(
476         id gender abteilung title position givenname name email phone1 phone2 fax mobile1 mobile2
477         satphone satfax project street zipcode city privatphone privatemail birthday
478       )
479     )
480   };
481
482   $data->{contact_cvars} = {
483     map(
484       {
485         if ( $_->config->type eq 'number' ) {
486           $_->config->name => $::form->format_amount(\%::myconfig, $_->value, -2);
487         } else {
488           $_->config->name => $_->value;
489         }
490       }
491       grep(
492         { $_->is_valid; }
493         @{$self->{contact}->cvars_by_config}
494       )
495     )
496   };
497
498   $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
499 }
500
501 sub action_ajaj_customer_autocomplete {
502   my ($self, %params) = @_;
503
504   my $limit = $::form->{limit} || 20;
505   my $type  = $::form->{type}  || {};
506   my $query = { ilike => '%'. $::form->{term} .'%' };
507
508   my @filter;
509   push(
510     @filter,
511     $::form->{column} ? ($::form->{column} => $query) : (or => [ customernumber => $query, name => $query ])
512   );
513
514   my $customers = SL::DB::Manager::Customer->get_all(query => [ @filter ], limit => $limit);
515   my $value_col = $::form->{column} || 'name';
516
517   my $data = [
518     map(
519       {
520         {
521           value => $_->can($value_col)->($_),
522           label => $_->displayable_name,
523           id    => $_->id,
524           customernumber => $_->customernumber,
525           name  => $_->name,
526         }
527       }
528       @{$customers}
529     )
530   ];
531
532   $self->render(\SL::JSON::to_json($data), { layout => 0, type => 'json' });
533 }
534
535 sub is_vendor {
536   return $::form->{db} eq 'vendor';
537 }
538
539 sub is_customer {
540   return $::form->{db} eq 'customer';
541 }
542
543 sub is_orphaned {
544   my ($self) = @_;
545
546   if ( defined($self->{_is_orphaned}) ) {
547     return $self->{_is_orphaned};
548   }
549
550   my $arap      = $self->is_vendor ? 'ap' : 'ar';
551   my $num_args  = 2;
552
553   my $cv = $self->is_vendor ? 'vendor' : 'customer';
554
555   my $query =
556    'SELECT a.id
557     FROM '. $arap .' AS a
558     JOIN '. $cv .' ct ON (a.'. $cv .'_id = ct.id)
559     WHERE ct.id = ?
560
561     UNION
562
563     SELECT a.id
564     FROM oe a
565     JOIN '. $cv .' ct ON (a.'. $cv .'_id = ct.id)
566     WHERE ct.id = ?';
567
568
569   if ( $self->is_vendor ) {
570     $query .=
571      ' UNION
572       SELECT 1 FROM makemodel mm WHERE mm.make = ?';
573     $num_args++;
574   }
575
576   my ($dummy) = selectrow_query($::form, $::form->get_standard_dbh(), $query, (conv_i($self->{cv}->id)) x $num_args);
577
578   return $self->{_is_orphaned} = !$dummy;
579 }
580
581 sub _instantiate_args {
582   my ($self) = @_;
583
584   my $curr_employee = SL::DB::Manager::Employee->current;
585
586   if ( $::form->{cv}->{id} ) {
587     if ( $self->is_vendor() ) {
588       $self->{cv} = SL::DB::Vendor->new(id => $::form->{cv}->{id})->load();
589     } else {
590       $self->{cv} = SL::DB::Customer->new(id => $::form->{cv}->{id})->load();
591     }
592   } else {
593     if ( $self->is_vendor() ) {
594       $self->{cv} = SL::DB::Vendor->new();
595     } else {
596       $self->{cv} = SL::DB::Customer->new();
597     }
598   }
599   $self->{cv}->assign_attributes(%{$::form->{cv}});
600
601   if ( $self->is_customer() && $::form->{cv}->{taxincluded_checked} eq '' ) {
602     $self->{cv}->taxincluded_checked(undef);
603   }
604
605
606   foreach my $cvar (@{$self->{cv}->cvars_by_config()}) {
607     my $value = $::form->{cv_cvars}->{$cvar->config->name};
608
609     if ( $cvar->config->type eq 'number' ) {
610       $value = $::form->parse_amount(\%::myconfig, $value);
611     }
612
613     $cvar->value($value);
614   }
615
616   if ( $::form->{note}->{id} ) {
617     $self->{note} = SL::DB::Note->new(id => $::form->{note}->{id})->load();
618   } else {
619     $self->{note} = SL::DB::Note->new();
620   }
621   $self->{note}->assign_attributes(%{$::form->{note}});
622   $self->{note}->created_by($curr_employee->id);
623   $self->{note}->trans_module('ct');
624
625   $self->{note_followup} = SL::DB::FollowUp->new();
626   $self->{note_followup}->assign_attributes(%{$::form->{note_followup}});
627   $self->{note_followup}->note($self->{note});
628   $self->{note_followup}->created_by($curr_employee->id);
629
630   if ( $::form->{shipto}->{shipto_id} ) {
631     $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto}->{shipto_id})->load();
632   } else {
633     $self->{shipto} = SL::DB::Shipto->new();
634   }
635   $self->{shipto}->assign_attributes(%{$::form->{shipto}});
636   $self->{shipto}->module('CT');
637
638   if ( $::form->{contact}->{cp_id} ) {
639     $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact}->{cp_id})->load();
640   } else {
641     $self->{contact} = SL::DB::Contact->new();
642   }
643   $self->{contact}->assign_attributes(%{$::form->{contact}});
644
645   foreach my $cvar (@{$self->{contact}->cvars_by_config()}) {
646     my $value = $::form->{contact_cvars}->{$cvar->config->name};
647
648     if ( $cvar->config->type eq 'number' ) {
649       $value = $::form->parse_amount(\%::myconfig, $value);
650     }
651
652     $cvar->value($value);
653   }
654 }
655
656 sub _load_customer_vendor {
657   my ($self) = @_;
658
659   if ( $self->is_vendor() ) {
660     $self->{cv} = SL::DB::Vendor->new(id => $::form->{id})->load();
661   } else {
662     $self->{cv} = SL::DB::Customer->new(id => $::form->{id})->load();
663   }
664
665   $self->{note} = SL::DB::Note->new();
666   $self->{note_followup} = SL::DB::FollowUp->new();
667
668   if ( $::form->{shipto_id} ) {
669     $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto_id})->load();
670
671     if ( $self->{shipto}->trans_id != $self->{cv}->id ) {
672       die($::locale->text('Error'));
673     }
674   } else {
675     $self->{shipto} = SL::DB::Shipto->new();
676   }
677
678   if ( $::form->{contact_id} ) {
679     $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact_id})->load();
680
681     if ( $self->{contact}->cp_cv_id != $self->{cv}->id ) {
682       die($::locale->text('Error'));
683     }
684   } else {
685     $self->{contact} = SL::DB::Contact->new();
686   }
687 }
688
689 sub _create_customer_vendor {
690   my ($self) = @_;
691
692   if ( $self->is_vendor() ) {
693     $self->{cv} = SL::DB::Vendor->new();
694   } else {
695     $self->{cv} = SL::DB::Customer->new();
696   }
697   $self->{cv}->currency_id($::instance_conf->get_currency_id());
698
699   $self->{note} = SL::DB::Note->new();
700
701   $self->{note_followup} = SL::DB::FollowUp->new();
702
703   $self->{shipto} = SL::DB::Shipto->new();
704
705   $self->{contact} = SL::DB::Contact->new();
706 }
707
708 sub _pre_render {
709   my ($self) = @_;
710
711   my $dbh = $::form->get_standard_dbh();
712
713   my $query;
714
715   $self->{all_business} = SL::DB::Manager::Business->get_all();
716
717   $self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
718
719   $query =
720     'SELECT DISTINCT(greeting)
721      FROM customer
722      WHERE greeting IS NOT NULL AND greeting != \'\'
723      UNION
724        SELECT DISTINCT(greeting)
725        FROM vendor
726        WHERE greeting IS NOT NULL AND greeting != \'\'
727      ORDER BY greeting';
728   $self->{all_greetings} = [
729     map(
730       { $_->{greeting}; }
731       selectall_hashref_query($::form, $dbh, $query)
732     )
733   ];
734
735   $query =
736     'SELECT DISTINCT(cp_title) AS title
737      FROM contacts
738      WHERE cp_title IS NOT NULL AND cp_title != \'\'
739      ORDER BY cp_title';
740   $self->{all_titles} = [
741     map(
742       { $_->{title}; }
743       selectall_hashref_query($::form, $dbh, $query)
744     )
745   ];
746
747   $self->{all_currencies} = SL::DB::Manager::Currency->get_all();
748
749   $self->{all_languages} = SL::DB::Manager::Language->get_all();
750
751   $self->{all_taxzones} = SL::DB::Manager::TaxZone->get_all();
752
753   if ( $::instance_conf->get_vertreter() ) {
754     $query =
755       'SELECT id
756        FROM business
757        WHERE salesman';
758     my $business_ids = [
759       map(
760         { $_->{id}; }
761         selectall_hashref_query($::form, $dbh, $query)
762       )
763     ];
764
765     if ( $business_ids->[0] ) {
766       $self->{all_salesman_customers} = SL::DB::Manager::Customer->get_all(query => [business_id => $business_ids]);
767     } else {
768       $self->{all_salesman_customers} = [];
769     }
770   } else {
771     $self->{all_salesmen} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $self->{cv}->salesman_id,  deleted => 0 ] ]);
772   }
773
774   $self->{all_payment_terms} = SL::DB::Manager::PaymentTerm->get_all();
775
776   $self->{all_pricegroups} = SL::DB::Manager::Pricegroup->get_all();
777
778   $query =
779     'SELECT DISTINCT(cp_abteilung) AS department
780      FROM contacts
781      WHERE cp_abteilung IS NOT NULL AND cp_abteilung != \'\'
782      ORDER BY cp_abteilung';
783   $self->{all_departments} = [
784     map(
785       { $_->{department}; }
786       selectall_hashref_query($::form, $dbh, $query)
787     )
788   ];
789
790   $self->{contacts} = $self->{cv}->contacts;
791   $self->{contacts} ||= [];
792
793   $self->{shiptos} = $self->{cv}->shipto;
794   $self->{shiptos} ||= [];
795
796   $self->{template_args} ||= {};
797
798   $::request->{layout}->add_javascripts('autocomplete_customer.js');
799   $::request->{layout}->add_javascripts('kivi.CustomerVendor.js');
800 }
801
802 1;