1 package SL::Controller::CustomerVendor;
4 use parent qw(SL::Controller::Base);
9 use SL::Locale::String;
10 use SL::Controller::Helper::GetModels;
19 use SL::DB::PaymentTerm;
20 use SL::DB::Pricegroup;
23 use SL::DB::FollowUpLink;
27 use Rose::Object::MakeMethods::Generic (
28 'scalar --get_set_init' => [ qw(customer_models vendor_models) ],
32 __PACKAGE__->run_before(
34 $::auth->assert('customer_vendor_edit');
37 __PACKAGE__->run_before(
41 'save_and_ap_transaction',
42 'save_and_ar_transaction',
54 __PACKAGE__->run_before(
55 '_load_customer_vendor',
65 # make sure this comes after _load_customer_vendor
66 __PACKAGE__->run_before(
67 '_check_customer_vendor_all_edit',
74 'save_and_ap_transaction',
75 'save_and_ar_transaction',
87 __PACKAGE__->run_before(
88 '_create_customer_vendor',
94 __PACKAGE__->run_before('normalize_name');
100 $self->_pre_render();
101 $self->{cv}->assign_attributes(hourly_rate => $::instance_conf->get_customer_hourly_rate) if $self->{cv}->is_customer;
103 'customer_vendor/form',
104 title => ($self->is_vendor() ? $::locale->text('Add Vendor') : $::locale->text('Add Customer')),
105 %{$self->{template_args}}
112 $self->_pre_render();
114 'customer_vendor/form',
115 title => ($self->is_vendor() ? $::locale->text('Edit Vendor') : $::locale->text('Edit Customer')),
116 %{$self->{template_args}}
123 if ($::request->type eq 'json') {
128 $cv_hash = $self->{cv}->as_tree;
129 $cv_hash->{cvars} = $self->{cv}->cvar_as_hashref;
132 $self->render(\ SL::JSON::to_json($cv_hash), { layout => 0, type => 'json', process => 0 });
139 my @errors = $self->{cv}->validate;
141 flash('error', @errors);
142 $self->_pre_render();
144 'customer_vendor/form',
145 title => ($self->is_vendor() ? t8('Edit Vendor') : t8('Edit Customer')),
146 %{$self->{template_args}}
151 my $db = $self->{cv}->db;
153 $db->do_transaction(sub {
155 if ( $self->is_vendor() ) {
156 if ( $self->{cv}->vendornumber ) {
157 $cvs_by_nr = SL::DB::Manager::Vendor->get_all(query => [vendornumber => $self->{cv}->vendornumber]);
160 if ( $self->{cv}->customernumber ) {
161 $cvs_by_nr = SL::DB::Manager::Customer->get_all(query => [customernumber => $self->{cv}->customernumber]);
165 foreach my $entry (@{$cvs_by_nr}) {
166 if( $entry->id != $self->{cv}->id ) {
168 $self->is_vendor() ? $::locale->text('This vendor number is already in use.') : $::locale->text('This customer number is already in use.');
170 $::form->error($msg);
174 $self->{cv}->save(cascade => 1);
176 $self->{contact}->cp_cv_id($self->{cv}->id);
177 if( $self->{contact}->cp_name ne '' || $self->{contact}->cp_givenname ne '' ) {
178 $self->{contact}->save(cascade => 1);
181 if( $self->{note}->subject ne '' && $self->{note}->body ne '' ) {
183 if ( !$self->{note_followup}->follow_up_date ) {
184 $::form->error($::locale->text('Date missing!'));
187 $self->{note}->trans_id($self->{cv}->id);
188 $self->{note}->save();
190 $self->{note_followup}->save();
192 $self->{note_followup_link}->follow_up_id($self->{note_followup}->id);
193 $self->{note_followup_link}->trans_id($self->{cv}->id);
194 $self->{note_followup_link}->save();
196 SL::Helper::Flash::flash_later('info', $::locale->text('Follow-Up saved.'));
199 $self->{shipto}->trans_id($self->{cv}->id);
200 if( $self->{shipto}->shiptoname ne '' ) {
201 $self->{shipto}->save();
204 my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
205 SL::DB::History->new(
206 trans_id => $self->{cv}->id,
207 snumbers => $snumbers,
208 employee_id => SL::DB::Manager::Employee->current->id,
212 if ( $::form->{delete_notes} ) {
213 foreach my $note_id (@{ $::form->{delete_notes} }) {
214 my $note = SL::DB::Note->new(id => $note_id)->load();
215 if ( $note->follow_up ) {
216 if ( $note->follow_up->follow_up_link ) {
217 $note->follow_up->follow_up_link->delete(cascade => 'delete');
219 $note->follow_up->delete(cascade => 'delete');
221 $note->delete(cascade => 'delete');
224 }) || die($db->error);
233 my @redirect_params = (
235 id => $self->{cv}->id,
236 db => ($self->is_vendor() ? 'vendor' : 'customer'),
239 if ( $self->{contact}->cp_id ) {
240 push(@redirect_params, contact_id => $self->{contact}->cp_id);
243 if ( $self->{shipto}->shipto_id ) {
244 push(@redirect_params, shipto_id => $self->{shipto}->shipto_id);
247 $self->redirect_to(@redirect_params);
250 sub action_save_and_close {
255 my $msg = $self->is_vendor() ? $::locale->text('Vendor saved') : $::locale->text('Customer saved');
256 $::form->redirect($msg);
260 my ($self, $script) = @_;
262 $::auth->assert('general_ledger | invoice_edit | vendor_invoice_edit | ' .
263 ' request_quotation_edit | sales_quotation_edit | sales_order_edit | purchase_order_edit');
267 my $callback = $::form->escape($::form->{callback}, 1);
268 my $name = $::form->escape($self->{cv}->name, 1);
269 my $db = $self->is_vendor() ? 'vendor' : 'customer';
271 my $url = $self->url_for(
272 controller => $script,
275 $db .'_id' => $self->{cv}->id,
277 type => $::form->{type},
278 callback => $callback,
281 print $::form->redirect_header($url);
284 sub action_save_and_ar_transaction {
287 $main::auth->assert('general_ledger');
289 $self->_transaction('ar.pl');
292 sub action_save_and_ap_transaction {
295 $main::auth->assert('general_ledger');
297 $self->_transaction('ap.pl');
300 sub action_save_and_invoice {
303 if ( $self->is_vendor() ) {
304 $::auth->assert('vendor_invoice_edit');
306 $::auth->assert('invoice_edit');
309 $::form->{type} = 'invoice';
310 $self->_transaction($self->is_vendor() ? 'ir.pl' : 'is.pl');
313 sub action_save_and_order {
316 if ( $self->is_vendor() ) {
317 $::auth->assert('purchase_order_edit');
319 $::auth->assert('sales_order_edit');
322 $::form->{type} = $self->is_vendor() ? 'purchase_order' : 'sales_order';
323 $self->_transaction('oe.pl');
326 sub action_save_and_rfq {
329 $::auth->assert('request_quotation_edit');
331 $::form->{type} = 'request_quotation';
332 $self->_transaction('oe.pl');
335 sub action_save_and_quotation {
338 $::auth->assert('sales_quotation_edit');
340 $::form->{type} = 'sales_quotation';
341 $self->_transaction('oe.pl');
347 my $db = $self->{cv}->db;
349 if( !$self->is_orphaned() ) {
350 $self->action_edit();
353 $db->do_transaction(sub {
354 $self->{cv}->delete(cascade => 1);
356 my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber;
357 SL::DB::History->new(
358 trans_id => $self->{cv}->id,
359 snumbers => $snumbers,
360 employee_id => SL::DB::Manager::Employee->current->id,
361 addition => 'DELETED',
363 }) || die($db->error);
365 my $msg = $self->is_vendor() ? $::locale->text('Vendor deleted!') : $::locale->text('Customer deleted!');
366 $::form->redirect($msg);
372 sub action_delete_contact {
375 my $db = $self->{contact}->db;
377 if ( !$self->{contact}->cp_id ) {
378 SL::Helper::Flash::flash('error', $::locale->text('No contact selected to delete'));
381 $db->do_transaction(sub {
382 if ( $self->{contact}->used ) {
383 $self->{contact}->detach();
384 $self->{contact}->save();
385 SL::Helper::Flash::flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
387 $self->{contact}->delete(cascade => 1);
388 SL::Helper::Flash::flash('info', $::locale->text('Contact deleted.'));
390 }) || die($db->error);
392 $self->{contact} = $self->_new_contact_object;
395 $self->action_edit();
398 sub action_delete_shipto {
401 my $db = $self->{shipto}->db;
403 if ( !$self->{shipto}->shipto_id ) {
404 SL::Helper::Flash::flash('error', $::locale->text('No shipto selected to delete'));
407 $db->do_transaction(sub {
408 if ( $self->{shipto}->used ) {
409 $self->{shipto}->detach();
410 $self->{shipto}->save(cascade => 1);
411 SL::Helper::Flash::flash('info', $::locale->text('Shipto is in use and was flagged invalid.'));
413 $self->{shipto}->delete(cascade => 1);
414 SL::Helper::Flash::flash('info', $::locale->text('Shipto deleted.'));
416 }) || die($db->error);
418 $self->{shipto} = SL::DB::Shipto->new();
421 $self->action_edit();
429 controller => 'ct.pl',
431 db => $self->is_vendor() ? 'vendor' : 'customer',
434 if ( $::form->{callback} ) {
435 push(@url_params, callback => $::form->{callback});
438 $self->redirect_to(@url_params);
442 sub action_search_contact {
445 my $url = 'ct.pl?action=search_contact&db=customer';
447 if ( $::form->{callback} ) {
448 $url .= '&callback='. $::form->escape($::form->{callback});
451 print $::form->redirect_header($url);
455 sub action_get_delivery {
458 $::auth->assert('sales_all_edit');
460 my $dbh = $::form->get_standard_dbh();
462 my ($arap, $db, $qty_sign);
463 if ( $self->is_vendor() ) {
466 $qty_sign = ' * -1 AS qty';
473 my $where = ' WHERE 1=1';
476 if ( !$self->is_vendor() && $::form->{shipto_id} && $::form->{shipto_id} ne 'all' ) {
477 $where .= " AND ${arap}.shipto_id = ?";
478 push(@values, $::form->{shipto_id});
480 $where .= " AND ${arap}.${db}_id = ?";
481 push(@values, $::form->{id});
484 if ( $::form->{delivery_from} ) {
485 $where .= " AND ${arap}.transdate >= ?";
486 push(@values, conv_date($::form->{delivery_from}));
489 if ( $::form->{delivery_to} ) {
490 $where .= " AND ${arap}.transdate <= ?";
491 push(@values, conv_date($::form->{delivery_to}));
510 ON ". ($arap eq 'ar' ? '(ar.shipto_id = s.shipto_id) ' : '(ap.id = s.trans_id) ') ."
513 ON ${arap}.id = i.trans_id
519 ON (oe.ordnumber = ${arap}.ordnumber AND NOT ${arap}.ordnumber = ''
520 AND ". ($arap eq 'ar' ? 'oe.customer_id IS NOT NULL' : 'oe.vendor_id IS NOT NULL') ." )
523 ORDER BY ${arap}.transdate DESC LIMIT 15";
525 $self->{delivery} = selectall_hashref_query($::form, $dbh, $query, @values);
527 $self->render('customer_vendor/get_delivery', { layout => 0 });
530 sub action_ajaj_get_shipto {
536 my $name = 'shipto'. $_;
537 $name => $self->{shipto}->$name;
539 qw(_id name department_1 department_2 street zipcode city country contact phone fax email)
543 $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
546 sub action_ajaj_get_contact {
554 my $name = 'cp_'. $_;
556 if ( $_ eq 'birthday' && $self->{contact}->$name ) {
557 $name => $self->{contact}->$name->to_lxoffice;
559 $name => $self->{contact}->$name;
563 id gender abteilung title position givenname name email phone1 phone2 fax mobile1 mobile2
564 satphone satfax project street zipcode city privatphone privatemail birthday
569 $data->{contact_cvars} = {
572 my $result = { type => $cvar->config->type };
574 if ($cvar->config->type eq 'number') {
575 $result->{value} = $::form->format_amount(\%::myconfig, $cvar->value, -2);
577 } elsif ($result->{type} =~ m{customer|vendor|part}) {
578 my $object = $cvar->value;
579 my $method = $result->{type} eq 'part' ? 'description' : 'name';
581 $result->{id} = int($cvar->number_value) || undef;
582 $result->{value} = $object ? $object->$method // '' : '';
585 $result->{value} = $cvar->value;
588 ( $cvar->config->name => $result )
590 } grep { $_->is_valid } @{ $self->{contact}->cvars_by_config }
593 $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
596 sub action_ajaj_autocomplete {
597 my ($self, %params) = @_;
599 my ($model, $manager, $number, $matches);
601 # first see if this is customer or vendor picking
602 if ($::form->{type} eq 'customer') {
603 $model = $self->customer_models;
604 $manager = 'SL::DB::Manager::Customer';
605 $number = 'customernumber';
606 } elsif ($::form->{type} eq 'vendor') {
607 $model = $self->vendor_models;
608 $manager = 'SL::DB::Manager::Vendor';
609 $number = 'vendornumber';
611 die "unknown type $::form->{type}";
614 # if someone types something, and hits enter, assume he entered the full name.
615 # if something matches, treat that as sole match
616 # unfortunately get_models can't do more than one per package atm, so we d it
617 # the oldfashioned way.
618 if ($::form->{prefer_exact}) {
620 if (1 == scalar @{ $exact_matches = $manager->get_all(
623 (salesman_id => SL::DB::Manager::Employee->current->id) x !$::auth->assert('customer_vendor_all_edit', 1),
625 name => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
626 $number => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
631 $matches = $exact_matches;
635 $matches //= $model->get;
639 value => $_->displayable_name,
640 label => $_->displayable_name,
642 $number => $_->$number,
644 type => $::form->{type},
645 cvars => { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $_->cvars_by_config } },
649 $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
652 sub action_test_page {
653 $::request->{layout}->add_javascripts('autocomplete_customer.js');
654 $_[0]->render('customer_vendor/test_page');
658 return $::form->{db} eq 'vendor';
662 return $::form->{db} eq 'customer';
668 if ( defined($self->{_is_orphaned}) ) {
669 return $self->{_is_orphaned};
672 my $arap = $self->is_vendor ? 'ap' : 'ar';
675 my $cv = $self->is_vendor ? 'vendor' : 'customer';
679 FROM '. $arap .' AS a
680 JOIN '. $cv .' ct ON (a.'. $cv .'_id = ct.id)
687 JOIN '. $cv .' ct ON (a.'. $cv .'_id = ct.id)
693 FROM delivery_orders a
694 JOIN '. $cv .' ct ON (a.'. $cv .'_id = ct.id)
698 if ( $self->is_vendor ) {
701 SELECT 1 FROM makemodel mm WHERE mm.make = ?';
705 my ($dummy) = selectrow_query($::form, $::form->get_standard_dbh(), $query, (conv_i($self->{cv}->id)) x $num_args);
707 return $self->{_is_orphaned} = !$dummy;
710 sub _instantiate_args {
713 my $curr_employee = SL::DB::Manager::Employee->current;
715 if ( $::form->{cv}->{id} ) {
716 if ( $self->is_vendor() ) {
717 $self->{cv} = SL::DB::Vendor->new(id => $::form->{cv}->{id})->load();
719 $self->{cv} = SL::DB::Customer->new(id => $::form->{cv}->{id})->load();
722 $self->{cv} = $self->_new_customer_vendor_object;
724 $self->{cv}->assign_attributes(%{$::form->{cv}});
726 if ( $self->is_customer() && $::form->{cv}->{taxincluded_checked} eq '' ) {
727 $self->{cv}->taxincluded_checked(undef);
730 $self->{cv}->hourly_rate($::instance_conf->get_customer_hourly_rate) if $self->is_customer && !$self->{cv}->hourly_rate;
732 foreach my $cvar (@{$self->{cv}->cvars_by_config()}) {
733 my $value = $::form->{cv_cvars}->{$cvar->config->name};
735 if ( $cvar->config->type eq 'number' ) {
736 $value = $::form->parse_amount(\%::myconfig, $value);
739 $cvar->value($value);
742 if ( $::form->{note}->{id} ) {
743 $self->{note} = SL::DB::Note->new(id => $::form->{note}->{id})->load();
744 $self->{note_followup} = $self->{note}->follow_up;
745 $self->{note_followup_link} = $self->{note_followup}->follow_up_link;
747 $self->{note} = SL::DB::Note->new();
748 $self->{note_followup} = SL::DB::FollowUp->new();
749 $self->{note_followup_link} = SL::DB::FollowUpLink->new();
752 $self->{note}->assign_attributes(%{$::form->{note}});
753 $self->{note}->created_by($curr_employee->id);
754 $self->{note}->trans_module('ct');
756 $self->{note_followup}->assign_attributes(%{$::form->{note_followup}});
757 $self->{note_followup}->note($self->{note});
758 $self->{note_followup}->created_by($curr_employee->id);
760 $self->{note_followup_link}->trans_type($self->is_vendor() ? 'vendor' : 'customer');
761 $self->{note_followup_link}->trans_info($self->{cv}->name);
763 if ( $::form->{shipto}->{shipto_id} ) {
764 $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto}->{shipto_id})->load();
766 $self->{shipto} = SL::DB::Shipto->new();
768 $self->{shipto}->assign_attributes(%{$::form->{shipto}});
769 $self->{shipto}->module('CT');
771 if ( $::form->{contact}->{cp_id} ) {
772 $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact}->{cp_id})->load();
774 $self->{contact} = $self->_new_contact_object;
776 $self->{contact}->assign_attributes(%{$::form->{contact}});
778 foreach my $cvar (@{$self->{contact}->cvars_by_config()}) {
779 my $value = $::form->{contact_cvars}->{$cvar->config->name};
781 if ( $cvar->config->type eq 'number' ) {
782 $value = $::form->parse_amount(\%::myconfig, $value);
785 $cvar->value($value);
789 sub _load_customer_vendor {
792 if ( $self->is_vendor() ) {
793 $self->{cv} = SL::DB::Vendor->new(id => $::form->{id})->load();
795 $self->{cv} = SL::DB::Customer->new(id => $::form->{id})->load();
798 if ( $::form->{note_id} ) {
799 $self->{note} = SL::DB::Note->new(id => $::form->{note_id})->load();
800 $self->{note_followup} = $self->{note}->follow_up;
801 $self->{note_followup_link} = $self->{note_followup}->follow_up_link;
803 $self->{note} = SL::DB::Note->new();
804 $self->{note_followup} = SL::DB::FollowUp->new();
805 $self->{note_followup_link} = SL::DB::FollowUpLink->new();
808 if ( $::form->{shipto_id} ) {
809 $self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto_id})->load();
811 if ( $self->{shipto}->trans_id != $self->{cv}->id ) {
812 die($::locale->text('Error'));
815 $self->{shipto} = SL::DB::Shipto->new();
818 if ( $::form->{contact_id} ) {
819 $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact_id})->load();
821 if ( $self->{contact}->cp_cv_id != $self->{cv}->id ) {
822 die($::locale->text('Error'));
825 $self->{contact} = $self->_new_contact_object;
829 sub _check_customer_vendor_all_edit {
832 unless ($::auth->assert('customer_vendor_all_edit', 1)) {
833 die($::locale->text("You don't have the rights to edit this customer.") . "\n")
834 if $self->{cv}->is_customer and
835 SL::DB::Manager::Employee->current->id != $self->{cv}->salesman_id;
839 sub _create_customer_vendor {
842 $self->{cv} = $self->_new_customer_vendor_object;
843 $self->{cv}->currency_id($::instance_conf->get_currency_id());
845 $self->{note} = SL::DB::Note->new();
847 $self->{note_followup} = SL::DB::FollowUp->new();
849 $self->{shipto} = SL::DB::Shipto->new();
851 $self->{contact} = $self->_new_contact_object;
857 my $dbh = $::form->get_standard_dbh();
861 $self->{all_business} = SL::DB::Manager::Business->get_all();
863 $self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
866 'SELECT DISTINCT(greeting)
868 WHERE greeting IS NOT NULL AND greeting != \'\'
870 SELECT DISTINCT(greeting)
872 WHERE greeting IS NOT NULL AND greeting != \'\'
874 $self->{all_greetings} = [
877 selectall_hashref_query($::form, $dbh, $query)
882 'SELECT DISTINCT(cp_title) AS title
884 WHERE cp_title IS NOT NULL AND cp_title != \'\'
886 $self->{all_titles} = [
889 selectall_hashref_query($::form, $dbh, $query)
893 $self->{all_currencies} = SL::DB::Manager::Currency->get_all();
895 $self->{all_languages} = SL::DB::Manager::Language->get_all();
897 $self->{all_taxzones} = SL::DB::Manager::TaxZone->get_all_sorted();
899 if ( $::instance_conf->get_vertreter() ) {
907 selectall_hashref_query($::form, $dbh, $query)
911 if ( $business_ids->[0] ) {
912 $self->{all_salesman_customers} = SL::DB::Manager::Customer->get_all(query => [business_id => $business_ids]);
914 $self->{all_salesman_customers} = [];
917 $self->{all_salesmen} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $self->{cv}->salesman_id, deleted => 0 ] ]);
920 $self->{all_payment_terms} = SL::DB::Manager::PaymentTerm->get_all();
922 $self->{all_delivery_terms} = SL::DB::Manager::DeliveryTerm->get_all();
924 $self->{all_pricegroups} = SL::DB::Manager::Pricegroup->get_all();
927 'SELECT DISTINCT(cp_abteilung) AS department
929 WHERE cp_abteilung IS NOT NULL AND cp_abteilung != \'\'
930 ORDER BY cp_abteilung';
931 $self->{all_departments} = [
933 { $_->{department}; }
934 selectall_hashref_query($::form, $dbh, $query)
938 $self->{contacts} = $self->{cv}->contacts;
939 $self->{contacts} ||= [];
941 $self->{shiptos} = $self->{cv}->shipto;
942 $self->{shiptos} ||= [];
944 $self->{notes} = SL::DB::Manager::Note->get_all(
946 trans_id => $self->{cv}->id,
947 trans_module => 'ct',
949 with_objects => ['follow_up'],
952 $self->{template_args} ||= {};
954 $::request->{layout}->add_javascripts('autocomplete_customer.js');
955 $::request->{layout}->add_javascripts('kivi.CustomerVendor.js');
961 # check if feature is enabled (select normalize_vc_names from defaults)
962 return unless ($::instance_conf->get_normalize_vc_names);
964 return unless $self->{cv};
965 my $name = $self->{cv}->name;
969 $self->{cv}->name($name);
972 sub home_address_for_google_maps {
975 my $address = $::instance_conf->get_address // '';
976 $address =~ s{^\s+|\s+$|\r+}{}g;
977 $address =~ s{\n+}{,}g;
978 $address =~ s{\s+}{ }g;
983 sub init_customer_models {
986 SL::Controller::Helper::GetModels->new(
991 by => 'customernumber',
994 customernumber => t8('Customer Number'),
997 ( salesman_id => SL::DB::Manager::Employee->current->id) x !$::auth->assert('customer_vendor_all_edit', 1),
1002 sub init_vendor_models {
1005 SL::Controller::Helper::GetModels->new(
1006 controller => $self,
1010 by => 'vendornumber',
1013 vendornumber => t8('Vendor Number'),
1018 sub _new_customer_vendor_object {
1021 my $class = 'SL::DB::' . ($self->is_vendor ? 'Vendor' : 'Customer');
1025 custom_variables => [],
1029 sub _new_contact_object {
1032 return SL::DB::Contact->new(custom_variables => []);