use SL::DB::Pricegroup;
use SL::DB::Contact;
use SL::DB::FollowUp;
+use SL::DB::FollowUpLink;
use SL::DB::History;
use SL::DB::Currency;
}
if( $self->{note}->subject ne '' && $self->{note}->body ne '' ) {
+
+ if ( !$self->{note_followup}->follow_up_date ) {
+ $::form->error($::locale->text('Date missing!'));
+ }
+
$self->{note}->trans_id($self->{cv}->id);
$self->{note}->save();
+
$self->{note_followup}->save();
- $self->{note} = SL::DB::Note->new();
- $self->{note_followup} = SL::DB::FollowUp->new();
+ $self->{note_followup_link}->follow_up_id($self->{note_followup}->id);
+ $self->{note_followup_link}->trans_id($self->{cv}->id);
+ $self->{note_followup_link}->save();
+
+ SL::Helper::Flash::flash_later('info', $::locale->text('Follow-Up saved.'));
}
$self->{shipto}->trans_id($self->{cv}->id);
$self->_save();
- $self->redirect_to(action => 'edit', id => $self->{cv}->id);
+ my @redirect_params = (
+ action => 'edit',
+ id => $self->{cv}->id,
+ db => ($self->is_vendor() ? 'vendor' : 'customer'),
+ );
+
+ if ( $self->{contact}->cp_id ) {
+ push(@redirect_params, contact_id => $self->{contact}->cp_id);
+ }
+
+ if ( $self->{shipto}->shipto_id ) {
+ push(@redirect_params, shipto_id => $self->{shipto}->shipto_id);
+ }
+
+ if ( $self->{note}->id ) {
+ push(@redirect_params, note_id => $self->{note}->id);
+ }
+
+ $self->redirect_to(@redirect_params);
}
sub action_save_and_close {
my $name = $::form->escape($self->{cv}->name, 1);
my $db = $self->is_vendor() ? 'vendor' : 'customer';
- my $url =
- $script .'?'.
- 'action=add&'.
- 'vc='. $db .'&'.
- $db .'_id=' . $self->{cv}->id .'&'.
- $db .'='. $name .'&'.
- 'type='. $::form->{type} .'&'.
- 'callback='. $callback;
+ my $url = $self->url_for(
+ controller => $script,
+ action => 'add',
+ vc => $db,
+ $db .'_id' => $self->{cv}->id,
+ $db => $name,
+ type => $::form->{type},
+ callback => $callback,
+ );
print $::form->redirect_header($url);
}
sub action_search {
my ($self) = @_;
- my $url = 'ct.pl?action=search&db='. ($self->is_vendor() ? 'vendor' : 'customer');
+ my @url_params = (
+ controller => 'ct.pl',
+ action => 'search',
+ db => $self->is_vendor() ? 'vendor' : 'customer',
+ );
if ( $::form->{callback} ) {
- $url .= '&callback='. $::from->escape($::form->{callback});
+ push(@url_params, callback => $::form->{callback});
}
- print $::form->redirect_header($url);
+ $self->redirect_to(@url_params);
}
my $url = 'ct.pl?action=search_contact&db=customer';
if ( $::form->{callback} ) {
- $url .= '&callback='. $::from->escape($::form->{callback});
+ $url .= '&callback='. $::form->escape($::form->{callback});
}
print $::form->redirect_header($url);
}
$self->{cv}->assign_attributes(%{$::form->{cv}});
+ if ( $self->is_customer() && $::form->{cv}->{taxincluded_checked} eq '' ) {
+ $self->{cv}->taxincluded_checked(undef);
+ }
+
+
foreach my $cvar (@{$self->{cv}->cvars_by_config()}) {
my $value = $::form->{cv_cvars}->{$cvar->config->name};
$cvar->value($value);
}
-# foreach my $cvar_key (keys(%{$::form->{cv_cvars}})) {
-# my $cvar_value = $::form->{cv_cvars}->{$cvar_key};
-# my $cvar = $self->{cv}->cvar_by_name($cvar_key);
-# $cvar->value($cvar_value);
-# }
-
if ( $::form->{note}->{id} ) {
$self->{note} = SL::DB::Note->new(id => $::form->{note}->{id})->load();
+
+ $self->{note_followup_link} = SL::DB::Manager::FollowUpLink->get_all(
+ query => [
+ 'follow_up.note_id' => $self->{note}->id,
+ trans_id => $self->{cv}->id,
+ trans_type => ($self->is_vendor() ? 'vendor' : 'customer'),
+ ],
+ with_objects => ['follow_up'],
+ )->[0];
+
+ $self->{note_followup} = $self->{note_followup_link}->follow_up;
} else {
$self->{note} = SL::DB::Note->new();
+ $self->{note_followup} = SL::DB::FollowUp->new();
+ $self->{note_followup_link} = SL::DB::FollowUpLink->new();
}
+
$self->{note}->assign_attributes(%{$::form->{note}});
$self->{note}->created_by($curr_employee->id);
$self->{note}->trans_module('ct');
- # if ( $self->{note}->trans_id != $self->{cv}->id ) {
- # die($::locale->text('Error'));
- # }
-
- $self->{note_followup} = SL::DB::FollowUp->new();
$self->{note_followup}->assign_attributes(%{$::form->{note_followup}});
$self->{note_followup}->note($self->{note});
$self->{note_followup}->created_by($curr_employee->id);
+ $self->{note_followup_link}->trans_type($self->is_vendor() ? 'vendor' : 'customer');
+ $self->{note_followup_link}->trans_info($self->{cv}->name);
+
if ( $::form->{shipto}->{shipto_id} ) {
$self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto}->{shipto_id})->load();
} else {
}
$self->{shipto}->assign_attributes(%{$::form->{shipto}});
$self->{shipto}->module('CT');
-# if ( $self->{shipto}->trans_id != $self->{cv}->id ) {
-# die($::locale->text('Error'));
-# }
if ( $::form->{contact}->{cp_id} ) {
$self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact}->{cp_id})->load();
$self->{contact} = SL::DB::Contact->new();
}
$self->{contact}->assign_attributes(%{$::form->{contact}});
-# if ( $self->{contact}->cp_cv_id != $self->{cv}->id ) {
-# die($::locale->text('Error'));
-# }
foreach my $cvar (@{$self->{contact}->cvars_by_config()}) {
my $value = $::form->{contact_cvars}->{$cvar->config->name};
$self->{cv} = SL::DB::Customer->new(id => $::form->{id})->load();
}
- $self->{note} = SL::DB::Note->new();
- $self->{note_followup} = SL::DB::FollowUp->new();
+ if ( $::form->{note_id} ) {
+ $self->{note} = SL::DB::Note->new(id => $::form->{note_id})->load();
+
+ $self->{note_followup_link} = SL::DB::Manager::FollowUpLink->get_all(
+ query => [
+ 'follow_up.note_id' => $self->{note}->id,
+ trans_id => $self->{cv}->id,
+ trans_type => ($self->is_vendor() ? 'vendor' : 'customer'),
+ ],
+ with_objects => ['follow_up'],
+ )->[0];
+
+ $self->{note_followup} = $self->{note_followup_link}->follow_up;
+ } else {
+ $self->{note} = SL::DB::Note->new();
+ $self->{note_followup} = SL::DB::FollowUp->new();
+ $self->{note_followup_link} = SL::DB::FollowUpLink->new();
+ }
if ( $::form->{shipto_id} ) {
$self->{shipto} = SL::DB::Shipto->new(shipto_id => $::form->{shipto_id})->load();
} else {
$self->{cv} = SL::DB::Customer->new();
}
+ $self->{cv}->currency_id($::instance_conf->get_currency_id());
$self->{note} = SL::DB::Note->new();
$self->{all_business} = SL::DB::Manager::Business->get_all();
- $self->{all_employees} = SL::DB::Manager::Employee->get_all();
+ $self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
$query =
'SELECT DISTINCT(greeting)
$self->{all_taxzones} = SL::DB::Manager::TaxZone->get_all();
- #Employee:
- #TODO: ALL_SALESMAN
- #TODO: ALL_SALESMAN_CUSTOMERS
+ if ( $::instance_conf->get_vertreter() ) {
+ $query =
+ 'SELECT id
+ FROM business
+ WHERE salesman';
+ my $business_ids = [
+ map(
+ { $_->{id}; }
+ selectall_hashref_query($::form, $dbh, $query)
+ )
+ ];
+
+ if ( $business_ids->[0] ) {
+ $self->{all_salesman_customers} = SL::DB::Manager::Customer->get_all(query => [business_id => $business_ids]);
+ } else {
+ $self->{all_salesman_customers} = [];
+ }
+ } else {
+ $self->{all_salesmen} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $self->{cv}->salesman_id, deleted => 0 ] ]);
+ }
$self->{all_payment_terms} = SL::DB::Manager::PaymentTerm->get_all();
$self->{shiptos} = $self->{cv}->shipto;
$self->{shiptos} ||= [];
- $self->{template_args} = {};
+ $self->{template_args} ||= {};
$::request->{layout}->add_javascripts('autocomplete_customer.js');
+ $::request->{layout}->add_javascripts('kivi.CustomerVendor.js');
}
1;