use Rose::Object::MakeMethods::Generic (
scalar => [ qw(db_args flat_filter) ],
- 'scalar --get_set_init' => [ qw(models all_edit_right vc) ],
+ 'scalar --get_set_init' => [ qw(models all_edit_right mode vc) ],
);
__PACKAGE__->run_before(sub { $::auth->assert('delivery_plan'); });
description => t8('Description'),
partnumber => t8('Part Number'),
qty => t8('Qty'),
+ unit => t8('Unit'),
shipped_qty => t8('shipped'),
delivered_qty => t8('transferred in / out'),
not_shipped_qty => t8('not shipped'),
my ($self) = @_;
my $vc = $self->vc;
+ my $mode = $self->mode;
my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
+ my $csv_option = $::form->{report_generator_output_format};
$self->{report} = $report;
my @columns = qw(reqdate customer vendor ordnumber partnumber description qty shipped_qty not_shipped_qty delivered_qty value_of_goods);
my @sortable = qw(reqdate customer vendor ordnumber partnumber description);
+ my $rp_csv_mod = ($csv_option eq 'CSV' && $mode eq 'delivery_value_report') ? 1 : '';
my %column_defs = (
reqdate => { sub => sub { $_[0]->reqdate_as_date || $_[0]->order->reqdate_as_date } },
obj_link => sub { $self->link_to($_[0]->part) } },
partnumber => { sub => sub { $_[0]->part->partnumber },
obj_link => sub { $self->link_to($_[0]->part) } },
- qty => { sub => sub { $_[0]->qty_as_number . ' ' . $_[0]->unit } },
- shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->shipped_qty, 2) . ' ' . $_[0]->unit } },
- not_shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]->shipped_qty, 2) . ' ' . $_[0]->unit } },
- delivered_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->delivered_qty, 2) . ' ' . $_[0]->unit } },
+ qty => { sub => sub { $_[0]->qty_as_number .
+ ($rp_csv_mod ? '' : ' ' . $_[0]->unit) } },
+ unit => { sub => sub { $_[0]->unit },
+ visible => $rp_csv_mod },
+ shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->shipped_qty, 2) .
+ ($rp_csv_mod ? '' : ' ' . $_[0]->unit) } },
+ not_shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]->shipped_qty, 2) .
+ ($rp_csv_mod ? '' : ' ' . $_[0]->unit) } },
+ delivered_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->delivered_qty, 2) .
+ ($rp_csv_mod ? '' : ' ' . $_[0]->unit) } },
ordnumber => { sub => sub { $_[0]->order->ordnumber },
obj_link => sub { $self->link_to($_[0]->order) } },
vendor => { sub => sub { $_[0]->order->vendor->name },
visible => $vc eq 'customer',
obj_link => sub { $self->link_to($_[0]->order->customer) } },
value_of_goods => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->value_of_goods, 2) . ' ' . $_[0]->taxincluded },
- visible => $::auth->assert('sales_order_edit', 1) && $::instance_conf->get_delivery_plan_show_value_of_goods, },
+ visible => $::auth->assert('sales_order_edit', 1) && $mode eq 'delivery_value_report' && $::instance_conf->get_delivery_plan_show_value_of_goods, },
);
$column_defs{$_}->{text} = $sort_columns{$_} for keys %column_defs;
std_column_visibility => 1,
controller_class => 'DeliveryPlan',
output_format => 'HTML',
- top_info_text => ($vc eq 'customer') ? $::locale->text('Delivery Plan for currently outstanding sales orders') :
+ top_info_text => ($vc eq 'customer') ? (($mode eq 'delivery_plan') ? $::locale->text('Delivery Plan for currently outstanding sales orders') :
+ $::locale->text('Delivery Value Report for currently open sales orders')) :
+ ($mode eq 'delivery_value_report') ? $::locale->text('Delivery Value Report for currently outstanding purchase orders') :
$::locale->text('Delivery Plan for currently outstanding purchase orders'),
- title => $::locale->text('Delivery Plan'),
+ title => ($mode eq 'delivery_plan') ? $::locale->text('Delivery Plan') : $::locale->text('Delivery Value Report'),
allow_pdf_export => 1,
allow_csv_export => 1,
);
$report->set_columns(%column_defs);
$report->set_column_order(@columns);
- $report->set_export_options(qw(list filter vc));
+ $report->set_export_options(qw(list filter vc mode));
$report->set_options_from_form;
$self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i;
$self->models->finalize; # for filter laundering
$self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
$report->set_options(
- raw_top_info_text => $self->render('delivery_plan/report_top', { output => 0 }, vc => $vc),
+ raw_top_info_text => $self->render('delivery_plan/report_top', { output => 0 }),
raw_bottom_info_text => $self->render('delivery_plan/report_bottom', { output => 0 }, models => $self->models),
);
}
sub make_filter_summary {
my ($self) = @_;
my $vc = $self->vc;
+ my $mode = $self->mode;
my $filter = $::form->{filter} || {};
my @filter_strings;
sub delivery_plan_query {
my ($self) = @_;
my $vc = $self->vc;
+ my $mode = $self->mode;
my $employee_id = SL::DB::Manager::Employee->current->id;
my $oe_owner = $_[0]->all_edit_right ? '' : " oe.employee_id = $employee_id AND";
# check delivered state for delivery_orders (transferred out) if enabled
- my $filter_delivered = $::instance_conf->get_delivery_plan_calculate_transferred_do ?
- "AND (SELECT delivered from delivery_orders where id = doi.delivery_order_id)" : '';
+ # OR if we are delivery_value_report mode
+ my $filter_delivered = ($::instance_conf->get_delivery_plan_calculate_transferred_do ||
+ $mode eq 'delivery_value_report' ) ?
+ "AND (SELECT delivered from delivery_orders where id = doi.delivery_order_id)" : '';
+ # Show ALL open orders in delivery_value_report mode
+ my $comment_show_all_open_orders = ($mode eq 'delivery_value_report' ) ? "-- " : "";
[
"order.${vc}_id" => { gt => 0 },
'order.closed' => 0,
FROM record_links rl
WHERE oi.trans_id = rl.from_id AND rl.from_table = 'oe' AND rl.to_table = 'delivery_orders'
) AND
- coalesce(sum, 0) < oi.qty AND
+ $comment_show_all_open_orders coalesce(sum, 0) < oi.qty AND
oe.${vc}_id IS NOT NULL AND
$oe_owner
(oe.quotation = 'f' OR oe.quotation IS NULL) AND NOT oe.closed
sub init_models {
my ($self) = @_;
my $vc = $self->vc;
-
+ my $mode = $self->mode;
SL::Controller::Helper::GetModels->new(
controller => $self,
model => 'OrderItem',
},
query => $self->delivery_plan_query,
with_objects => [ 'order', "order.$vc", 'part' ],
- additional_url_params => { vc => $vc },
+ additional_url_params => { vc => $vc, mode => $mode},
);
}
sub init_vc {
return $::form->{vc} if ($::form->{vc} eq 'customer' || $::form->{vc} eq 'vendor') || croak "self (DeliveryPlan) has no vc defined";
}
+sub init_mode {
+ return $::form->{mode} if ($::form->{mode} eq 'delivery_value_report' || $::form->{mode} eq 'delivery_plan') || croak "self (DeliveryPlan) has no mode defined";
+}
sub link_to {
my ($self, $object, %params) = @_;