-
- $form->{title} |
-
-
-
- $option |
-
-
-|;
+ my %attachment_basenames = (
+ 'part' => $locale->text('part_list'),
+ 'service' => $locale->text('service_list'),
+ 'assembly' => $locale->text('assembly_list'),
+ );
- map { print "\n$column_header{$_}" } @column_index;
+ $report->set_options('top_info_text' => $locale->text('Options') . ': ' . join(', ', grep $_, @options),
+ 'raw_bottom_info_text' => $form->parse_html_template2('ic/generate_report_bottom'),
+ 'output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $attachment_basenames{$form->{searchitems}} . strftime('_%Y%m%d', localtime time),
+ );
+ $report->set_options_from_form();
- print qq|
-
- |;
+ $report->set_columns(%column_defs);
+ $report->set_column_order(@columns);
- # add order to callback
- $form->{callback} = $callback .= "&sort=$form->{sort}";
+ $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
- # escape callback for href
- $callback = $form->escape($callback);
+ $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
- if (@{ $form->{parts} }) {
- $sameitem = $form->{parts}->[0]->{ $form->{sort} };
- }
+ my @subtotal_columns = qw(sellprice listprice lastcost);
+ my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns);
+ my %totals = map { $_ => 0 } @subtotal_columns;
+ my $idx = 0;
+ my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} });
- foreach $ref (@{ $form->{parts} }) {
+ # postprocess parts
+ foreach my $ref (@{ $form->{parts} }) {
- if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
- if ($sameitem ne $ref->{ $form->{sort} }) {
- &parts_subtotal;
- $sameitem = $ref->{ $form->{sort} };
- }
- }
+ # fresh row, for inserting later
+ my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
- $ref->{exchangerate} = 1 unless $ref->{exchangerate};
- $ref->{sellprice} *= $ref->{exchangerate};
- $ref->{listprice} *= $ref->{exchangerate};
- $ref->{lastcost} *= $ref->{exchangerate};
+ $ref->{exchangerate} ||= 1;
+ $ref->{price_factor} ||= 1;
+ $ref->{sellprice} *= $ref->{exchangerate} / $ref->{price_factor};
+ $ref->{listprice} *= $ref->{exchangerate} / $ref->{price_factor};
+ $ref->{lastcost} *= $ref->{exchangerate} / $ref->{price_factor};
# use this for assemblies
- $onhand = $ref->{onhand};
+ my $onhand = $ref->{onhand};
- $align = "left";
if ($ref->{assemblyitem}) {
- $align = "right";
- $onhand = 0 if ($form->{sold});
+ $row->{partnumber}{align} = 'right';
+ $row->{onhand}{data} = 0;
+ $onhand = 0 if ($form->{sold});
}
- $ref->{description} =~ s/
-/
/g;
+ my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
+ $row->{partnumber}->{link} = $edit_link;
+ $row->{description}->{link} = $edit_link;
- $column_data{partnumber} =
- "{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{partnumber} | ";
- $column_data{description} = "{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description} | ";
- $column_data{partsgroup} = "$ref->{partsgroup} | ";
+ foreach (qw(sellprice listprice lastcost)) {
+ $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
+ $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
+ }
- $column_data{onhand} =
- ""
- . $form->format_amount(\%myconfig, $ref->{onhand})
- . " | ";
- $column_data{sellprice} =
- ""
- . $form->format_amount(\%myconfig, $ref->{sellprice}, -2)
- . " | ";
- $column_data{listprice} =
- ""
- . $form->format_amount(\%myconfig, $ref->{listprice}, -2)
- . " | ";
- $column_data{lastcost} =
- ""
- . $form->format_amount(\%myconfig, $ref->{lastcost}, -2)
- . " | ";
-
- $column_data{linetotalsellprice} = ""
- . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
- . " | ";
- $column_data{linetotallastcost} = ""
- . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
- . " | ";
- $column_data{linetotallistprice} = ""
- . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
- . " | ";
+ map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
if (!$ref->{assemblyitem}) {
- $totalsellprice += $onhand * $ref->{sellprice};
- $totallastcost += $onhand * $ref->{lastcost};
- $totallistprice += $onhand * $ref->{listprice};
+ foreach my $col (@subtotal_columns) {
+ $totals{$col} += $onhand * $ref->{$col};
+ $subtotals{$col} += $onhand * $ref->{$col};
+ }
- $subtotalonhand += $onhand;
- $subtotalsellprice += $onhand * $ref->{sellprice};
- $subtotallastcost += $onhand * $ref->{lastcost};
- $subtotallistprice += $onhand * $ref->{listprice};
+ $subtotals{onhand} += $onhand;
}
- $column_data{rop} =
- ""
- . $form->format_amount(\%myconfig, $ref->{rop}) . " | ";
- $column_data{weight} =
- ""
- . $form->format_amount(\%myconfig, $ref->{weight})
- . " | ";
- $column_data{unit} = "$ref->{unit} | ";
- $column_data{bin} = "$ref->{bin} | ";
- $column_data{priceupdate} = "$ref->{priceupdate} | ";
-
- $column_data{invnumber} =
- ($ref->{module} ne 'oe')
- ? "{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber} | "
- : "$ref->{invnumber} | ";
- $column_data{ordnumber} =
- ($ref->{module} eq 'oe')
- ? "{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber} | "
- : "$ref->{ordnumber} | ";
- $column_data{quonumber} =
- ($ref->{module} eq 'oe' && !$ref->{ordnumber})
- ? "{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber} | "
- : "$ref->{quonumber} | ";
+ # set module stuff
+ if ($ref->{module} eq 'oe') {
+ my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
+ $row->{ordnumber}{link} = $edit_oe_link;
+ $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
- $column_data{name} = "$ref->{name} | ";
+ } else {
+ $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
+ }
- $column_data{image} =
- ($ref->{image})
- ? "{image}> {image} height=32 border=0> | "
- : " | ";
- $column_data{drawing} =
- ($ref->{drawing})
- ? "{drawing}>$ref->{drawing} | "
- : " | ";
- $column_data{microfiche} =
- ($ref->{microfiche})
- ? "{microfiche}>$ref->{microfiche} | "
- : " | ";
+ # set properties of images
+ if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
+ $row->{image}{data} = '';
+ $row->{image}{raw_data} = '
';
+ }
+ map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
- $column_data{serialnumber} = "$ref->{serialnumber} | ";
+ $report->add_data($row);
- $column_data{soldtotal} =
- ""
- . $form->format_amount(\%myconfig, $ref->{soldtotal})
- . " | ";
+ my $next_ref = $form->{parts}[$idx + 1];
- $column_data{deliverydate} = "$ref->{deliverydate} | ";
+ # insert subtotal rows
+ if (($form->{l_subtotal} eq 'Y') &&
+ (!$next_ref ||
+ (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
+ my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
- $i++;
- $i %= 2;
- print "";
+ if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
+ $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
+ }
- map { print "\n$column_data{$_}" } @column_index;
+ map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
+ map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
- print qq|
-
-|;
+ $report->add_data($row);
- }
+ $same_item = $next_ref->{ $form->{sort} };
+ }
- if ($form->{l_subtotal} eq 'Y') {
- &parts_subtotal;
+ $idx++;
}
if ($form->{"l_linetotal"}) {
- map { $column_data{$_} = " | " } @column_index;
- $column_data{linetotalsellprice} =
- ""
- . $form->format_amount(\%myconfig, $totalsellprice, 2)
- . " | ";
- $column_data{linetotallastcost} =
- ""
- . $form->format_amount(\%myconfig, $totallastcost, 2)
- . " | ";
- $column_data{linetotallistprice} =
- ""
- . $form->format_amount(\%myconfig, $totallistprice, 2)
- . " | ";
+ my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
- print "";
+ map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
- map { print "\n$column_data{$_}" } @column_index;
-
- print qq|
- |;
+ $report->add_separator();
+ $report->add_data($row);
}
- print qq|
-
|
-
-
-|;
-
- print qq|
-
-