Revision 0d6c87b0
Von Sven Schöling vor mehr als 7 Jahren hinzugefügt
SL/Helper/ShippedQty.pm | ||
---|---|---|
12 | 12 |
use SL::Locale::String qw(t8); |
13 | 13 |
|
14 | 14 |
use Rose::Object::MakeMethods::Generic ( |
15 |
'scalar' => [ qw(objects objects_or_ids shipped_qty ) ], |
|
16 |
'scalar --get_set_init' => [ qw(oe_ids dbh require_stock_out fill_up item_identity_fields oi2oe oi_qty delivered) ], |
|
15 |
'scalar' => [ qw(objects objects_or_ids shipped_qty keep_matches) ],
|
|
16 |
'scalar --get_set_init' => [ qw(oe_ids dbh require_stock_out fill_up item_identity_fields oi2oe oi_qty delivered matches) ],
|
|
17 | 17 |
); |
18 | 18 |
|
19 | 19 |
my $no_stock_item_links_query = <<''; |
20 |
SELECT oi.trans_id, oi.id AS oi_id, oi.qty AS oi_qty, oi.unit AS oi_unit, doi.qty AS doi_qty, doi.unit AS doi_unit |
|
20 |
SELECT oi.trans_id, oi.id AS oi_id, oi.qty AS oi_qty, oi.unit AS oi_unit, doi.id AS doi_id, doi.qty AS doi_qty, doi.unit AS doi_unit
|
|
21 | 21 |
FROM record_links rl |
22 | 22 |
INNER JOIN orderitems oi ON oi.id = rl.from_id AND rl.from_table = 'orderitems' |
23 | 23 |
INNER JOIN delivery_order_items doi ON doi.id = rl.to_id AND rl.to_table = 'delivery_order_items' |
... | ... | |
50 | 50 |
AND to_id = doi.id) |
51 | 51 |
|
52 | 52 |
my $stock_item_links_query = <<''; |
53 |
SELECT oi.trans_id, oi.id AS oi_id, oi.qty AS oi_qty, oi.unit AS oi_unit, |
|
53 |
SELECT oi.trans_id, oi.id AS oi_id, oi.qty AS oi_qty, oi.unit AS oi_unit, doi.id AS doi_id,
|
|
54 | 54 |
(CASE WHEN doe.customer_id > 0 THEN -1 ELSE 1 END) * i.qty AS doi_qty, p.unit AS doi_unit |
55 | 55 |
FROM record_links rl |
56 | 56 |
INNER JOIN orderitems oi ON oi.id = rl.from_id AND rl.from_table = 'orderitems' |
... | ... | |
128 | 128 |
my $data = selectall_hashref_query($::form, $self->dbh, $query, @oe_ids); |
129 | 129 |
|
130 | 130 |
for (@$data) { |
131 |
my $qty = $_->{doi_qty} * AM->convert_unit($_->{doi_unit} => $_->{oi_unit}); |
|
131 | 132 |
$self->shipped_qty->{$_->{oi_id}} //= 0; |
132 |
$self->shipped_qty->{$_->{oi_id}} += $_->{doi_qty} * AM->convert_unit($_->{doi_unit} => $_->{oi_unit});
|
|
133 |
$self->shipped_qty->{$_->{oi_id}} += $qty;
|
|
133 | 134 |
$self->oi2oe->{$_->{oi_id}} = $_->{trans_id}; |
134 | 135 |
$self->oi_qty->{$_->{oi_id}} = $_->{oi_qty}; |
136 |
|
|
137 |
push @{ $self->matches }, [ $_->{oi_id}, $_->{doi_id}, $qty, 1 ] if $self->keep_matches; |
|
135 | 138 |
} |
136 | 139 |
} |
137 | 140 |
|
... | ... | |
194 | 197 |
|
195 | 198 |
$self->shipped_qty->{$oi->{id}} += $min_qty; |
196 | 199 |
$doi->{qty} -= $min_qty / $factor; # TODO: find a way to avoid float rounding |
200 |
push @{ $self->matches }, [ $oi->{id}, $doi->{id}, $min_qty, 0 ] if $self->keep_matches; |
|
197 | 201 |
} |
198 | 202 |
} |
199 | 203 |
} |
... | ... | |
278 | 282 |
|
279 | 283 |
sub init_oi2oe { {} } |
280 | 284 |
sub init_oi_qty { {} } |
285 |
sub init_matches { [] } |
|
281 | 286 |
sub init_delivered { |
282 | 287 |
my ($self) = @_; |
283 | 288 |
my $d = { }; |
... | ... | |
442 | 447 |
|
443 | 448 |
=back |
444 | 449 |
|
450 |
=item * C<keep_matches> |
|
451 |
|
|
452 |
Boolean. If set to true the internal matchings of OrderItems and |
|
453 |
DeliveryOrderItems will be kept for later postprocessing, in case you need more |
|
454 |
than this modules provides. |
|
455 |
|
|
456 |
See C<matches> for the returned format. |
|
457 |
|
|
445 | 458 |
=back |
446 | 459 |
|
447 | 460 |
=item C<calculate OBJECTS> |
... | ... | |
483 | 496 |
|
484 | 497 |
Valid after L</calculate>. Returns a hashref with a delivered flag by order id. |
485 | 498 |
|
499 |
=item C<matches> |
|
500 |
|
|
501 |
Valid after L</calculate> with C<with_matches> set. Returns an arrayref of |
|
502 |
individual matches. Each match is an arrayref with these fields: |
|
503 |
|
|
504 |
=over 4 |
|
505 |
|
|
506 |
=item * |
|
507 |
|
|
508 |
The id of the OrderItem. |
|
509 |
|
|
510 |
=item * |
|
511 |
|
|
512 |
The id of the DeliveryOrderItem. |
|
513 |
|
|
514 |
=item * |
|
515 |
|
|
516 |
The qty that was matched between the two converted to the unit of the OrderItem. |
|
517 |
|
|
518 |
=item * |
|
519 |
|
|
520 |
A boolean flag indicating if this match was found with record_item links. If |
|
521 |
false, the match was made in the fill up stage. |
|
522 |
|
|
486 | 523 |
=back |
487 | 524 |
|
488 | 525 |
=head1 REPLACED FUNCTIONALITY |
Auch abrufbar als: Unified diff
ShippedQty: keep_matches option