Revision 08e12ce7
Von Tamino Steinert vor etwa 2 Jahren hinzugefügt
SL/DB/Reclamation.pm | ||
---|---|---|
181 | 181 |
where => [ $valid_for_type => 1 ]); |
182 | 182 |
} |
183 | 183 |
|
184 |
sub convert_to_order { |
|
185 |
my ($self, %params) = @_; |
|
186 |
|
|
187 |
my $order; |
|
188 |
$params{destination_type} = $self->is_sales ? 'sales_order' |
|
189 |
: 'purchase_order'; |
|
190 |
if (!$self->db->with_transaction(sub { |
|
191 |
require SL::DB::Order; |
|
192 |
$order = SL::DB::Order->new_from($self, %params); |
|
193 |
$order->save; |
|
194 |
$self->link_to_record($order); |
|
195 |
foreach my $item (@{ $order->items }) { |
|
196 |
foreach (qw(reclamation_item)) { |
|
197 |
if ($item->{"converted_from_${_}_id"}) { |
|
198 |
die unless $item->{id}; |
|
199 |
RecordLinks->create_links('dbh' => $self->db->dbh, |
|
200 |
'mode' => 'ids', |
|
201 |
'from_table' => 'reclamation_items', |
|
202 |
'from_ids' => $item->{"converted_from_${_}_id"}, |
|
203 |
'to_table' => 'orderitems', |
|
204 |
'to_id' => $item->{id}, |
|
205 |
) || die; |
|
206 |
delete $item->{"converted_from_${_}_id"}; |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
1; |
|
212 |
})) { |
|
213 |
return undef; |
|
214 |
} |
|
215 |
|
|
216 |
return $order; |
|
217 |
} |
|
218 |
|
|
184 | 219 |
#TODO(Werner): überprüfen ob alle Felder richtig gestetzt werden |
185 | 220 |
sub new_from { |
186 | 221 |
my ($class, $source, %params) = @_; |
187 | 222 |
my %allowed_sources = map { $_ => 1 } qw( |
188 | 223 |
SL::DB::Reclamation |
224 |
SL::DB::Order |
|
189 | 225 |
); |
190 | 226 |
unless( $allowed_sources{ref $source} ) { |
191 | 227 |
croak("Unsupported source object type '" . ref($source) . "'"); |
... | ... | |
200 | 236 |
{ from => 'purchase_reclamation', to => 'purchase_reclamation', abbr => 'prpr', }, |
201 | 237 |
{ from => 'sales_reclamation', to => 'purchase_reclamation', abbr => 'srpr', }, |
202 | 238 |
{ from => 'purchase_reclamation', to => 'sales_reclamation', abbr => 'prsr', }, |
239 |
#Order |
|
240 |
{ from => 'sales_order', to => 'sales_reclamation', abbr => 'sosr', }, |
|
241 |
{ from => 'purchase_order', to => 'purchase_reclamation', abbr => 'popr', }, |
|
203 | 242 |
); |
204 | 243 |
my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0]; |
205 | 244 |
if (!$from_to) { |
... | ... | |
244 | 283 |
transaction_description |
245 | 284 |
vendor_id |
246 | 285 |
); # }}} for vim folds |
286 |
} elsif ( $is_abbr_any->(qw(sosr popr)) ) { #Order |
|
287 |
map { $record_args{$_} = $source->$_ } # {{{ for vim folds |
|
288 |
qw( |
|
289 |
amount |
|
290 |
currency_id |
|
291 |
customer_id |
|
292 |
delivery_term_id |
|
293 |
department_id |
|
294 |
exchangerate |
|
295 |
globalproject_id |
|
296 |
intnotes |
|
297 |
language_id |
|
298 |
netamount |
|
299 |
notes |
|
300 |
payment_id |
|
301 |
salesman_id |
|
302 |
shippingpoint |
|
303 |
shipvia |
|
304 |
tax_point |
|
305 |
taxincluded |
|
306 |
taxzone_id |
|
307 |
transaction_description |
|
308 |
vendor_id |
|
309 |
); |
|
310 |
$record_args{contact_id} = $source->cp_id; |
|
311 |
$record_args{cv_record_number} = $source->cusordnumber; |
|
312 |
# }}} for vim folds |
|
247 | 313 |
} |
248 | 314 |
|
249 | 315 |
if ( ($from_to->{from} =~ m{sales}) && ($from_to->{to} =~ m{purchase}) ) { |
Auch abrufbar als: Unified diff
Workflow: order ↔ reclamation