# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
__PACKAGE__->meta->make_manager_class;
+sub used {
+ my ($self) = @_;
+
+ return unless $self->cp_id;
+
+ require SL::DB::Order;
+ require SL::DB::Invoice;
+ require SL::DB::PurchaseInvoice;
+ require SL::DB::DeliveryOrder;
+
+ return SL::DB::Manager::Order->get_all_count(query => [ cp_id => $self->cp_id ])
+ + SL::DB::Manager::Invoice->get_all_count(query => [ cp_id => $self->cp_id ])
+ + SL::DB::Manager::PurchaseInvoice->get_all_count(query => [ cp_id => $self->cp_id ])
+ + SL::DB::Manager::DeliveryOrder->get_all_count(query => [ cp_id => $self->cp_id ]);
+}
+
+sub detach {
+ $_[0]->cp_cv_id(undef);
+ $_[0]->save;
+}
+
sub full_name {
my ($self) = @_;
die 'not an accessor' if @_ > 1;
use SL::CVar;
use SL::DB::Business;
use SL::DB::Default;
+use SL::Helper::Flash;
use SL::ReportGenerator;
require "bin/mozilla/common.pl";
}
sub delete_contact {
- $main::lxdebug->enter_sub();
-
- $main::auth->assert('customer_vendor_edit');
+ $::lxdebug->enter_sub;
+ $::auth->assert('customer_vendor_edit');
- my $form = $main::form;
- my %myconfig = %main::myconfig;
+ CT->get_contact(\%::myconfig, $::form);
- CT->get_contact(\%myconfig, \%$form);
+ my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id});
- unless ($form->{cp_used}) {
- CT->delete_contact($form->{cp_id});
- @$form{ grep /^cp_/, keys %$form } = undef;
+ if ($contact->used) {
+ $contact->detach;
+ flash('info', $::locale->text('Contact is in use and was flagged invalid.'));
+ } else {
+ $contact->delete;
+ flash('info', $::locale->text('Contact deleted.'));
}
+ delete $::form->{$_} for grep /^cp_/, keys %$::form;
edit();
- $main::lxdebug->leave_sub();
+ $::lxdebug->leave_sub;
}
sub ajax_autocomplete {
if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
- $form->get_lists("contacts" => "ALL_CONTACTS",
- "shipto" => "ALL_SHIPTO",
+ $form->get_lists("shipto" => "ALL_SHIPTO",
"projects" => {
"key" => "ALL_PROJECTS",
"all" => 0,
"departments" => "ALL_DEPARTMENTS",
"business_types" => "ALL_BUSINESS_TYPES",
);
+ $::form->{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
+ or => [
+ cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+ and => [
+ cp_cv_id => undef,
+ cp_id => $::form->{cp_id} * 1
+ ]
+ ]
+ ]);
map { $_->{value} = "$_->{description}--$_->{id}" } @{ $form->{ALL_DEPARTMENTS} };
map { $_->{value} = "$_->{name}--$_->{id}" } @{ $form->{ALL_VC} };
my @old_project_ids = ($form->{"globalproject_id"});
map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
- $form->get_lists("contacts" => "ALL_CONTACTS",
- "shipto" => "ALL_SHIPTO",
+ $form->get_lists("shipto" => "ALL_SHIPTO",
"projects" => { "key" => "ALL_PROJECTS",
"all" => 0,
"old_id" => \@old_project_ids },
"departments" => "all_departments",
"price_factors" => "ALL_PRICE_FACTORS");
+ $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
+ or => [
+ cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+ and => [
+ cp_cv_id => undef,
+ cp_id => $::form->{cp_id} * 1
+ ]
+ ]
+ ]);
$TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
# $TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
- $TMPL_VAR{contact_labels} = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
$TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
# customer
my @old_project_ids = ($form->{"globalproject_id"});
map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
- $form->get_lists("contacts" => "ALL_CONTACTS",
- "shipto" => "ALL_SHIPTO",
+ $form->get_lists("shipto" => "ALL_SHIPTO",
"projects" => { "key" => "ALL_PROJECTS",
"all" => 0,
"old_id" => \@old_project_ids },
"departments" => "all_departments",
"price_factors" => "ALL_PRICE_FACTORS");
+ $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
+ or => [
+ cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+ and => [
+ cp_cv_id => undef,
+ cp_id => $::form->{cp_id} * 1
+ ]
+ ]
+ ]);
$TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
$TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
- $TMPL_VAR{contact_labels} = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
$TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
# customer
my @old_project_ids = ($form->{"globalproject_id"}, grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{"rowcount"});
my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
- $form->get_lists("contacts" => "ALL_CONTACTS",
- "shipto" => "ALL_SHIPTO",
+ $form->get_lists("shipto" => "ALL_SHIPTO",
"projects" => { "key" => "ALL_PROJECTS",
"all" => 0,
"old_id" => \@old_project_ids },
"price_factors" => "ALL_PRICE_FACTORS");
# label subs
+ $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
+ or => [
+ cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+ and => [
+ cp_cv_id => undef,
+ cp_id => $::form->{cp_id} * 1
+ ]
+ ]
+ ]);
$TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
$TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
- $TMPL_VAR{contact_labels} = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
$TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
# vendor/customer
'Confirmation' => 'Auftragsbestätigung',
'Contact' => 'Kontakt',
'Contact Person' => 'Ansprechpartner',
+ 'Contact deleted.' => 'Ansprechpartner gelöscht.',
+ 'Contact is in use and was flagged invalid.' => 'Ansprechpartner ist noch in Verwendung, und wurde als ungültig markiert.',
'Contact person (surname)' => 'Ansprechpartner (Nachname)',
'Contacts' => 'Ansprechpartner',
'Continue' => 'Weiter',
[% USE L %][% USE HTML %][% USE T8 %][% USE LxERP %]
- <table id="contact_table">
+ <table>
<input type="hidden" name="cp_id" value="[% HTML.escape(cp_id) %]">
<tr>
<th align="left">[% 'Contacts' | $T8 %]</th>
<td>
[%- L.select_tag('cp_id', L.options_for_select(CONTACTS, default => cp_id, with_empty => 1, empty_title => LxERP.t8('New contact'), value => 'cp_id', title_sub => \contacts_label),
- onchange => "\$('#contact_table').load('ct.pl?action=get_contact&id=' + \$('#cvid').attr('value') + '&db=' + \$('#db').attr('value') + '&cp_id=' + \$('#cp_id').attr('value'))") %]
+ onchange => "\$('#contacts').load('ct.pl?action=get_contact&id=' + \$('#cvid').attr('value') + '&db=' + \$('#db').attr('value') + '&cp_id=' + \$('#cp_id').attr('value'))") %]
</td>
</tr>
<td><input name="bcc" size="40" value="[% HTML.escape(bcc) %]"></td>
</tr>
</table>
+
+ <input type="submit" id="delete_contact" name="action" value="[% 'Delete Contact' | $T8 %]" [% IF cp_used %]'disabled'[% END %]>
+
+ <br style="clear: left" />
<div id="contacts" class="tabcontent">
[% INCLUDE 'ct/_contact.html' %]
-
- <input type="submit" id="delete_contact" name="action" value="[% 'Delete Contact' | $T8 %]" disabled>
- <br style="clear: left" />
</div>
<div id="deliveries" class="tabcontent">
[%- HTML.escape(row.cp_name) %][%- IF row.cp_abteilung %] ([% HTML.escape(row.cp_abteilung) %])[% END -%]
[%- END %]
[%- ELSE %]
- <select name="cp_id" class="fixed_width" >
- <option></option>
- [%- FOREACH row = ALL_CONTACTS %]
- <option value="[% HTML.escape(row.cp_id) %]"[% IF cp_id == row.cp_id %] selected[% END %]>
- [%- HTML.escape(row.cp_name) %][%- IF row.cp_abteilung %] ([% HTML.escape(row.cp_abteilung) %])[% END -%]
- </option>
- [%- END %]
- </select>
+ [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title='full_name_dep', with_empty=1), style='width: 250px') %]
[%- END %]
</td>
</tr>
<tr>
<th align="right">[% 'Contact Person' | $T8 %]</th>
<td>
- [%- INCLUDE 'generic/multibox.html'
- name = 'cp_id',
- style = 'width: 250px',
- DATA = ALL_CONTACTS,
- id_key = 'cp_id',
- label_sub = 'contact_labels',
- show_empty = 1 -%]
+ [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title='full_name_dep', with_empty=1), style='width: 250px') %]
</td>
</tr>
[%- END %]
<tr>
<th align="right">[% 'Contact Person' | $T8 %]</th>
<td>
- [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title_sub=\contact_labels, with_empty=1), style='width: 250px') %]
+ [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title='full_name_dep', with_empty=1), style='width: 250px') %]
</td>
</tr>
[%- END %]
<tr>
<th align="right">[% 'Contact Person' | $T8 %]</th>
<td>
- [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title_sub=\contact_labels, with_empty=1), style='width: 250px') %]
+ [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title='full_name_dep', with_empty=1), style='width: 250px') %]
</td>
</tr>
[%- END %]