Revision e3ccd940
Von Thomas Heck vor mehr als 11 Jahren hinzugefügt
SL/Controller/CustomerVendor.pm | ||
---|---|---|
85 | 85 |
sub _save { |
86 | 86 |
my ($self) = @_; |
87 | 87 |
|
88 |
my $cvs_by_nr; |
|
89 |
if ( $self->is_vendor() ) { |
|
90 |
if ( $self->{cv}->vendornumber ) { |
|
91 |
$cvs_by_nr = SL::DB::Manager::Vendor->get_all(query => [vendornumber => $self->{cv}->vendornumber]); |
|
88 |
my $db = $self->{cv}->db; |
|
89 |
|
|
90 |
$db->do_transaction(sub { |
|
91 |
my $cvs_by_nr; |
|
92 |
if ( $self->is_vendor() ) { |
|
93 |
if ( $self->{cv}->vendornumber ) { |
|
94 |
$cvs_by_nr = SL::DB::Manager::Vendor->get_all(query => [vendornumber => $self->{cv}->vendornumber]); |
|
95 |
} |
|
92 | 96 |
} |
93 |
}
|
|
94 |
else {
|
|
95 |
if ( $self->{cv}->customernumber ) {
|
|
96 |
$cvs_by_nr = SL::DB::Manager::Customer->get_all(query => [customernumber => $self->{cv}->customernumber]);
|
|
97 |
else {
|
|
98 |
if ( $self->{cv}->customernumber ) {
|
|
99 |
$cvs_by_nr = SL::DB::Manager::Customer->get_all(query => [customernumber => $self->{cv}->customernumber]);
|
|
100 |
}
|
|
97 | 101 |
} |
98 |
} |
|
99 | 102 |
|
100 |
foreach my $entry (@{$cvs_by_nr}) { |
|
101 |
if( $entry->id != $self->{cv}->id ) { |
|
102 |
my $msg = |
|
103 |
$self->is_vendor() ? $::locale->text('This vendor number is already in use.') : $::locale->text('This customer number is already in use.'); |
|
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.');
|
|
104 | 107 |
|
105 |
$::form->error($msg); |
|
108 |
$::form->error($msg); |
|
109 |
} |
|
106 | 110 |
} |
107 |
} |
|
108 | 111 |
|
109 |
$self->{cv}->save(cascade => 1); |
|
112 |
$self->{cv}->save(cascade => 1);
|
|
110 | 113 |
|
111 |
$self->{contact}->cp_cv_id($self->{cv}->id); |
|
112 |
if( $self->{contact}->cp_name ne '' || $self->{contact}->cp_givenname ne '' ) { |
|
113 |
$self->{contact}->save(); |
|
114 |
} |
|
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 |
}
|
|
115 | 118 |
|
116 |
if( $self->{note}->subject ne '' && $self->{note}->body ne '' ) { |
|
117 |
$self->{note}->trans_id($self->{cv}->id); |
|
118 |
$self->{note}->save(); |
|
119 |
$self->{note_followup}->save(); |
|
119 |
if( $self->{note}->subject ne '' && $self->{note}->body ne '' ) {
|
|
120 |
$self->{note}->trans_id($self->{cv}->id);
|
|
121 |
$self->{note}->save();
|
|
122 |
$self->{note_followup}->save();
|
|
120 | 123 |
|
121 |
$self->{note} = SL::DB::Note->new(); |
|
122 |
$self->{note_followup} = SL::DB::FollowUp->new(); |
|
123 |
} |
|
124 |
$self->{note} = SL::DB::Note->new();
|
|
125 |
$self->{note_followup} = SL::DB::FollowUp->new();
|
|
126 |
}
|
|
124 | 127 |
|
125 |
$self->{shipto}->trans_id($self->{cv}->id); |
|
126 |
if( $self->{shipto}->shiptoname ne '' ) { |
|
127 |
$self->{shipto}->save(); |
|
128 |
} |
|
128 |
$self->{shipto}->trans_id($self->{cv}->id); |
|
129 |
if( $self->{shipto}->shiptoname ne '' ) { |
|
130 |
$self->{shipto}->save(); |
|
131 |
} |
|
132 |
|
|
133 |
my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber; |
|
134 |
SL::DB::History->new( |
|
135 |
trans_id => $self->{cv}->id, |
|
136 |
snumbers => $snumbers, |
|
137 |
employee_id => SL::DB::Manager::Employee->current->id, |
|
138 |
addition => 'SAVED', |
|
139 |
)->save(); |
|
140 |
}) || die($db->error); |
|
129 | 141 |
|
130 |
my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber; |
|
131 |
SL::DB::History->new( |
|
132 |
trans_id => $self->{cv}->id, |
|
133 |
snumbers => $snumbers, |
|
134 |
employee_id => SL::DB::Manager::Employee->current->id, |
|
135 |
addition => 'SAVED', |
|
136 |
)->save(); |
|
137 | 142 |
} |
138 | 143 |
|
139 | 144 |
sub action_save { |
... | ... | |
240 | 245 |
sub action_delete { |
241 | 246 |
my ($self) = @_; |
242 | 247 |
|
248 |
my $db = $self->{cv}->db; |
|
249 |
|
|
243 | 250 |
if( !$self->is_orphaned() ) { |
244 | 251 |
$self->action_edit(); |
245 | 252 |
} |
246 | 253 |
else { |
247 |
$self->{cv}->delete(); |
|
248 | 254 |
|
249 |
my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber; |
|
250 |
SL::DB::History->new( |
|
251 |
trans_id => $self->{cv}->id, |
|
252 |
snumbers => $snumbers, |
|
253 |
employee_id => SL::DB::Manager::Employee->current->id, |
|
254 |
addition => 'DELETED', |
|
255 |
)->save(); |
|
255 |
$db->do_transaction(sub { |
|
256 |
$self->{cv}->delete(); |
|
257 |
|
|
258 |
my $snumbers = $self->is_vendor() ? 'vendornumber_'. $self->{cv}->vendornumber : 'customernumber_'. $self->{cv}->customernumber; |
|
259 |
SL::DB::History->new( |
|
260 |
trans_id => $self->{cv}->id, |
|
261 |
snumbers => $snumbers, |
|
262 |
employee_id => SL::DB::Manager::Employee->current->id, |
|
263 |
addition => 'DELETED', |
|
264 |
)->save(); |
|
265 |
}) || die($db->error); |
|
256 | 266 |
|
257 | 267 |
my $msg = $self->is_vendor() ? $::locale->text('Vendor deleted!') : $::locale->text('Customer deleted!'); |
258 | 268 |
$::form->redirect($msg); |
... | ... | |
264 | 274 |
sub action_delete_contact { |
265 | 275 |
my ($self) = @_; |
266 | 276 |
|
277 |
my $db = $self->{contact}->db; |
|
278 |
|
|
267 | 279 |
if ( !$self->{contact}->cp_id ) { |
268 | 280 |
SL::Helper::Flash::flash('error', $::locale->text('No contact selected to delete')); |
269 | 281 |
} else { |
270 |
if ( $self->{contact}->used ) { |
|
271 |
$self->{contact}->detach(); |
|
272 |
$self->{contact}->save(); |
|
273 |
SL::Helper::Flash::flash('info', $::locale->text('Contact is in use and was flagged invalid.')); |
|
274 |
} else { |
|
275 |
$self->{contact}->delete(); |
|
276 |
SL::Helper::Flash::flash('info', $::locale->text('Contact deleted.')); |
|
277 |
} |
|
282 |
|
|
283 |
$db->do_transaction(sub { |
|
284 |
if ( $self->{contact}->used ) { |
|
285 |
$self->{contact}->detach(); |
|
286 |
$self->{contact}->save(); |
|
287 |
SL::Helper::Flash::flash('info', $::locale->text('Contact is in use and was flagged invalid.')); |
|
288 |
} else { |
|
289 |
$self->{contact}->delete(); |
|
290 |
SL::Helper::Flash::flash('info', $::locale->text('Contact deleted.')); |
|
291 |
} |
|
292 |
}) || die($db->error); |
|
278 | 293 |
|
279 | 294 |
$self->{contact} = SL::DB::Contact->new(); |
280 | 295 |
} |
... | ... | |
285 | 300 |
sub action_delete_shipto { |
286 | 301 |
my ($self) = @_; |
287 | 302 |
|
303 |
my $db = $self->{shipto}->db; |
|
304 |
|
|
288 | 305 |
if ( !$self->{shipto}->shipto_id ) { |
289 | 306 |
SL::Helper::Flash::flash('error', $::locale->text('No shipto selected to delete')); |
290 | 307 |
} else { |
291 |
if ( $self->{shipto}->used ) { |
|
292 |
$self->{shipto}->detach(); |
|
293 |
$self->{shipto}->save(); |
|
294 |
SL::Helper::Flash::flash('info', $::locale->text('Shipto is in use and was flagged invalid.')); |
|
295 |
} else { |
|
296 |
$self->{shipto}->delete(); |
|
297 |
SL::Helper::Flash::flash('info', $::locale->text('Shipto deleted.')); |
|
298 |
} |
|
308 |
|
|
309 |
$db->do_transaction(sub { |
|
310 |
if ( $self->{shipto}->used ) { |
|
311 |
$self->{shipto}->detach(); |
|
312 |
$self->{shipto}->save(); |
|
313 |
SL::Helper::Flash::flash('info', $::locale->text('Shipto is in use and was flagged invalid.')); |
|
314 |
} else { |
|
315 |
$self->{shipto}->delete(); |
|
316 |
SL::Helper::Flash::flash('info', $::locale->text('Shipto deleted.')); |
|
317 |
} |
|
318 |
}) || die($db->error); |
|
299 | 319 |
|
300 | 320 |
$self->{shipto} = SL::DB::Shipto->new(); |
301 | 321 |
} |
Auch abrufbar als: Unified diff
CustomerVendor: Abfragen in Transaktionen ausführen