7 |
7 |
our @EXPORT = qw(linked_records link_to_record sales_order_centric_linked_records);
|
8 |
8 |
|
9 |
9 |
use Carp;
|
10 |
|
use List::MoreUtils qw(any);
|
|
10 |
use List::MoreUtils qw(any none);
|
11 |
11 |
use List::UtilsBy qw(uniq_by);
|
12 |
12 |
use Sort::Naturally;
|
13 |
13 |
use SL::DBUtils;
|
... | ... | |
396 |
396 |
}
|
397 |
397 |
|
398 |
398 |
sub sales_order_centric_linked_records {
|
399 |
|
my ($self) = @_;
|
|
399 |
my ($self, %params) = @_;
|
|
400 |
|
|
401 |
my $with_sales_quotations = $params{with_sales_quotations};
|
|
402 |
my $with_myself = $params{with_myself};
|
|
403 |
|
|
404 |
my $all_linked_records = $self->linked_records(direction => 'both', recursive => 1, save_path => 1);
|
|
405 |
|
|
406 |
if (!$with_sales_quotations) {
|
|
407 |
$all_linked_records = [ grep { !('SL::DB::Order' eq ref $_ && $_->is_sales && $_->quotation) } @$all_linked_records ];
|
|
408 |
}
|
|
409 |
|
|
410 |
if ($with_myself) {
|
|
411 |
$self->{_record_link_to_myself} = 1;
|
|
412 |
push @$all_linked_records, $self;
|
|
413 |
}
|
400 |
414 |
|
401 |
|
my $all_linked_records = $self->linked_records(direction => 'from', recursive => 1);
|
402 |
|
my $filtered_orders = [ grep { 'SL::DB::Order' eq ref $_ && $_->is_type('sales_order') } @$all_linked_records ];
|
|
415 |
my $filtered_orders = [ grep { 'SL::DB::Order' eq ref $_ && $_->is_type('sales_order') && $_->{_record_link_direction} eq 'from' } @$all_linked_records ];
|
403 |
416 |
|
404 |
417 |
# no orders no call to linked_records via batch mode
|
405 |
418 |
# but instead return default list
|
406 |
|
return $self->linked_records(direction => 'both', recursive => 1, save_path => 1)
|
407 |
|
unless scalar @$filtered_orders;
|
|
419 |
return $all_linked_records unless scalar @$filtered_orders;
|
408 |
420 |
|
409 |
|
# we have a order, therefore get the tree view from the top (order)
|
|
421 |
# we have an order, therefore get the tree view from the top (order)
|
410 |
422 |
my $id_ref = [ map { $_->id } @$filtered_orders ];
|
|
423 |
|
411 |
424 |
my $linked_records = SL::DB::Order->new->linked_records(direction => 'to', recursive => 1, batch => $id_ref);
|
412 |
|
push @{ $linked_records }, @$filtered_orders;
|
|
425 |
|
|
426 |
# Remove entries that are already in all_linked_records.
|
|
427 |
$linked_records = [ grep { my $id = $_->id; none { $_->id == $id } @$all_linked_records } @$linked_records ];
|
|
428 |
|
|
429 |
# Remove quotations if requested.
|
|
430 |
if (!$with_sales_quotations) {
|
|
431 |
$linked_records = [ grep { !('SL::DB::Order' eq ref $_ && $_->is_sales && $_->quotation) } @$linked_records ];
|
|
432 |
}
|
|
433 |
|
|
434 |
# Mark or remove myself.
|
|
435 |
if ($with_myself) {
|
|
436 |
$_->{_record_link_to_myself} = 1 for grep { $_->id == $self->id } @$linked_records;
|
|
437 |
} else {
|
|
438 |
$linked_records = [ grep { $_->id != $self->id } @$linked_records ];
|
|
439 |
}
|
|
440 |
|
|
441 |
# All remaining links found via order are two more steps away from myself.
|
|
442 |
$_->{_record_link_depth} += 2 for @{ $linked_records };
|
|
443 |
|
|
444 |
push @{ $linked_records }, @$all_linked_records;
|
413 |
445 |
|
414 |
446 |
return $linked_records;
|
415 |
447 |
}
|
... | ... | |
477 |
509 |
%params,
|
478 |
510 |
);
|
479 |
511 |
|
|
512 |
# get order centric linked records
|
|
513 |
$invoice->sales_order_centric_linked_records(
|
|
514 |
with_myself => 1,
|
|
515 |
with_sales_quotations => 1
|
|
516 |
);
|
|
517 |
|
480 |
518 |
# add a new link
|
481 |
519 |
$order->link_to_record($invoice);
|
482 |
520 |
$order->link_to_record($purchase_order, bidirectional => 1);
|
... | ... | |
701 |
739 |
|
702 |
740 |
Can only be called as a class function since it is not exported.
|
703 |
741 |
|
|
742 |
=item C<sales_order_centric_linked_records %params>
|
|
743 |
|
|
744 |
Get linked records from the view of a reachable sales order in the path
|
|
745 |
prior to this record. If no sales order is found, recursive linked records
|
|
746 |
for both directions are returned.
|
|
747 |
|
|
748 |
=over 2
|
|
749 |
|
|
750 |
=item * C<with_sales_quotations>
|
|
751 |
|
|
752 |
Since the view from a sales order is requested, normally no sales quotation
|
|
753 |
prior to the sales order will be returned. If this parameter is truish, then
|
|
754 |
a sales quotation would be included.
|
|
755 |
This parameter is optional and defaults to false.
|
|
756 |
|
|
757 |
=item * C<with_myself>
|
|
758 |
|
|
759 |
The records returned by L</linked_records> do not include the requesting record
|
|
760 |
itself. However, if you want to display the same linked records for every
|
|
761 |
record in the same workflow, it can be usefull to include the record itself.
|
|
762 |
C<_record_link_to_myself> will be set to a truish value in that record in
|
|
763 |
that case.
|
|
764 |
This parameter is optional and defaults to false.
|
|
765 |
|
|
766 |
=back
|
|
767 |
|
704 |
768 |
=back
|
705 |
769 |
|
706 |
770 |
=head1 EXPORTS
|
707 |
771 |
|
708 |
|
This mixin exports the functions L</linked_records> and
|
|
772 |
This mixin exports the functions L</linked_records>,
|
|
773 |
L</sales_order_centric_linked_records> and
|
709 |
774 |
L</link_to_record>.
|
710 |
775 |
|
711 |
776 |
=head1 BUGS
|
Auftragszentrische verknüpfte Belege überarbeitet
- alle über den Auftrag gefundenen Verknüpfungen sind mindestens
zwei Verknüpfungen weiter entfernt
- auch die Verknüpfungen in die Richtung "to" (also vom Beleg weg)
werden angezeigt
- Möglichkeit, um auch Verkaufsangebote zu liefern, die vor dem Auftrag
liegen
- Möglichkeit, auch den aktuellen Beleg zu liefern. Dieser wird besonders
markiert. Das war auch schon vorher so, aber es war nicht klar, das es der
Beleg selbst ist. Zudem ist dieses Verhalten jetzt nicht per default an.