- onorder => $locale->text('On Order'),
- ordered => $locale->text('Ordered'),
- rfq => $locale->text('RFQ'),
- quoted => $locale->text('Quoted'),
- bought => $locale->text('Bought'),
- sold => $locale->text('Sold'),
- transdatefrom => $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1),
- transdateto => $locale->text('To (time)') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1),
- partnumber => $locale->text('Part Number') . ": '$form->{partnumber}'",
- partsgroup => $locale->text('Group') . ": '$form->{partsgroup}'",
- serialnumber => $locale->text('Serial Number') . ": '$form->{serialnumber}'",
- description => $locale->text('Part Description') . ": '$form->{description}'",
- make => $locale->text('Make') . ": '$form->{make}'",
- model => $locale->text('Model') . ": '$form->{model}'",
- drawing => $locale->text('Drawing') . ": '$form->{drawing}'",
- microfiche => $locale->text('Microfiche') . ": '$form->{microfiche}'",
- l_soldtotal => $locale->text('soldtotal'),
- );
-
- my @itemstatus_keys = qw(active obsolete orphaned onhand short);
- my @callback_keys = qw(onorder ordered rfq quoted bought sold partnumber partsgroup serialnumber description make model
- drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
-
- # calculate dependencies
- for (@itemstatus_keys, @callback_keys) {
- next if ($form->{itemstatus} ne $_ && !$form->{$_});
- map { $form->{$_} = 'Y' } @{ $dependencies{$_} } if $dependencies{$_};
- }
-
- # generate callback and optionstrings
- my @options;
- for my $key (@itemstatus_keys, @callback_keys) {
- next if ($form->{itemstatus} ne $key && !$form->{$key});
- push @options, $optiontexts{$key};
- }
-
- IC->all_parts(\%myconfig, \%$form);
-
- # special case for lastcost
- $form->{l_lastcost} = "" if $form->{ledgerchecks};
-
- if ($form->{description}) {
- $description = $form->{description};
- $description =~ s/\n/<br>/g;
- }
-
- if ($form->{l_linetotal}) {
- $form->{l_onhand} = "Y";
- $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
- if ($form->{l_lastcost}) {
- $form->{l_linetotallastcost} = "Y";
- if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
- $form->{l_linetotallastcost} = "";
- }
- }
- $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
- }
-
- if ($form->{searchitems} eq 'service') {
-
- # remove bin, weight and rop from list
- map { $form->{"l_$_"} = "" } qw(bin weight rop);
-
- $form->{l_onhand} = "";
-
- # qty is irrelevant unless bought or sold
- if ( $form->{bought}
- || $form->{sold}
- || $form->{onorder}
- || $form->{ordered}
- || $form->{rfq}
- || $form->{quoted}) {
- $form->{l_onhand} = "Y";
- } else {
- $form->{l_linetotalsellprice} = "";
- $form->{l_linetotallastcost} = "";
- }
- }
-
- $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom});
-
- my @columns =
- qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
- priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate);
-
- my %column_defs = (
- 'bin' => { 'text' => $locale->text('Bin'), },
- 'deliverydate' => { 'text' => $locale->text('deliverydate'), },
- 'description' => { 'text' => $locale->text('Part Description'), },
- 'drawing' => { 'text' => $locale->text('Drawing'), },
- 'image' => { 'text' => $locale->text('Image'), },
- 'invnumber' => { 'text' => $locale->text('Invoice Number'), },
- 'lastcost' => { 'text' => $locale->text('Last Cost'), },
- 'linetotallastcost' => { 'text' => $locale->text('Extended'), },
- 'linetotallistprice' => { 'text' => $locale->text('Extended'), },
- 'linetotalsellprice' => { 'text' => $locale->text('Extended'), },
- 'listprice' => { 'text' => $locale->text('List Price'), },
- 'microfiche' => { 'text' => $locale->text('Microfiche'), },
- 'name' => { 'text' => $locale->text('Name'), },
- 'onhand' => { 'text' => $locale->text('Qty'), },
- 'ordnumber' => { 'text' => $locale->text('Order Number'), },
- 'partnumber' => { 'text' => $locale->text('Part Number'), },
- 'partsgroup' => { 'text' => $locale->text('Group'), },
- 'priceupdate' => { 'text' => $locale->text('Updated'), },
- 'quonumber' => { 'text' => $locale->text('Quotation'), },
- 'rop' => { 'text' => $locale->text('ROP'), },
- 'sellprice' => { 'text' => $locale->text('Sell Price'), },
- 'serialnumber' => { 'text' => $locale->text('Serial Number'), },
- 'soldtotal' => { 'text' => $locale->text('soldtotal'), },
- 'unit' => { 'text' => $locale->text('Unit'), },
- 'weight' => { 'text' => $locale->text('Weight'), },
- );
-
- map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
- map { $column_defs{$_}->{align} = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
-
- my @hidden_variables = (qw(l_subtotal l_linetotal searchitems itemstatus bom), @itemstatus_keys, @callback_keys, map { "l_$_" } @columns);
- my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
-
- my @sort_full = qw(partnumber description onhand soldtotal deliverydate);
- my @sort_no_revers = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
-
- foreach my $col (@sort_full) {
- $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
- }
- map { $column_defs{$_}->{link} = "${callback}&sort=$_" } @sort_no_revers;
-
- # add order to callback
- $form->{callback} = join '&', ($callback, map { "${_}=" . E($form->{$_}) } qw(sort revers));
-
- my $report = SL::ReportGenerator->new(\%myconfig, $form);
-
- my %attachment_basenames = (
- 'part' => $locale->text('part_list'),
- 'service' => $locale->text('service_list'),
- 'assembly' => $locale->text('assembly_list'),
- );
-
- $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();
-
- $report->set_columns(%column_defs);
- $report->set_column_order(@columns);
-
- $report->set_export_options('generate_report', @hidden_variables, qw(sort revers));
-
- $report->set_sort_indicator($form->{sort}, $form->{revers} ? 0 : 1);
-
- 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} });
-
- # postprocess parts
- foreach my $ref (@{ $form->{parts} }) {
-
- # fresh row, for inserting later
- my $row = { map { $_ => { 'data' => $ref->{$_} } } @columns };
-
- $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
- my $onhand = $ref->{onhand};
-
- if ($ref->{assemblyitem}) {
- $row->{partnumber}{align} = 'right';
- $row->{onhand}{data} = 0;
- $onhand = 0 if ($form->{sold});
- }
-
- my $edit_link = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
- $row->{partnumber}->{link} = $edit_link;
- $row->{description}->{link} = $edit_link;
-
- foreach (qw(sellprice listprice lastcost)) {
- $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}, -2);
- $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
- }
-
- map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
-
- if (!$ref->{assemblyitem}) {
- foreach my $col (@subtotal_columns) {
- $totals{$col} += $onhand * $ref->{$col};
- $subtotals{$col} += $onhand * $ref->{$col};
- }
-
- $subtotals{onhand} += $onhand;
- }
-
- # 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});
-
- } else {
- $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
- }
-
- # set properties of images
- if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
- $row->{image}{data} = '';
- $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
- }
- map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
-
- $report->add_data($row);
-
- my $next_ref = $form->{parts}[$idx + 1];
-
- # 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 };
-
- if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
- $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
- }
-
- map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
- map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
-
- $report->add_data($row);
-
- $same_item = $next_ref->{ $form->{sort} };
- }
-
- $idx++;
- }
-
- if ($form->{"l_linetotal"}) {
- my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
-
- map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
-
- $report->add_separator();
- $report->add_data($row);
- }
-
- $report->generate_with_headers();
-
- $lxdebug->leave_sub();
-} #end generate_report
-
-sub parts_subtotal {
- $lxdebug->enter_sub();
-
- # imports
- our (%column_data, @column_index);
- our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
-
- map { $column_data{$_} = "<td> </td>" } @column_index;
- $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
-
- $column_data{onhand} =
- "<th class=listsubtotal align=right>"
- . $form->format_amount(\%myconfig, $subtotalonhand)
- . "</th>";
-
- $column_data{linetotalsellprice} =
- "<th class=listsubtotal align=right>"
- . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
- . "</th>";
- $column_data{linetotallistprice} =
- "<th class=listsubtotal align=right>"
- . $form->format_amount(\%myconfig, $subtotallistprice, 2)
- . "</th>";
- $column_data{linetotallastcost} =
- "<th class=listsubtotal align=right>"
- . $form->format_amount(\%myconfig, $subtotallastcost, 2)
- . "</th>";
-
- $subtotalonhand = 0;
- $subtotalsellprice = 0;
- $subtotallistprice = 0;
- $subtotallastcost = 0;
-
- print "<tr class=listsubtotal>";
-
- map { print "\n$column_data{$_}" } @column_index;
-
- print qq|
- </tr>
-|;
-
- $lxdebug->leave_sub();
-}
-
-sub edit {
- $lxdebug->enter_sub();
- # show history button
- $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
- #/show hhistory button
- IC->get_part(\%myconfig, \%$form);
-
- $form->{"original_partnumber"} = $form->{"partnumber"};
-
- $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
-
- &link_part;
- &display_form;
-
- $lxdebug->leave_sub();
-}
-
-sub link_part {
- $lxdebug->enter_sub();
-
- IC->create_links("IC", \%myconfig, \%$form);
-
- # currencies
- map({ $form->{selectcurrency} .= "<option>$_\n" }
- split(/:/, $form->{currencies}));
-
- # parts and assemblies have the same links
- my $item = $form->{item};
- if ($form->{item} eq 'assembly') {
- $item = 'part';
- }
-
- # build the popup menus
- $form->{taxaccounts} = "";
- foreach my $key (keys %{ $form->{IC_links} }) {
- foreach my $ref (@{ $form->{IC_links}{$key} }) {
-
- # if this is a tax field
- if ($key =~ /IC_tax/) {
- if ($key =~ /\Q$item\E/) {
- $form->{taxaccounts} .= "$ref->{accno} ";
- $form->{"IC_tax_$ref->{accno}_description"} =
- "$ref->{accno}--$ref->{description}";
-
- if ($form->{id}) {
- if ($form->{amount}{ $ref->{accno} }) {
- $form->{"IC_tax_$ref->{accno}"} = "checked";
- }
- } else {
- $form->{"IC_tax_$ref->{accno}"} = "checked";
- }
- }
- } else {
-
- $form->{"select$key"} .=
- "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
- if ($form->{amount}{$key} eq $ref->{accno}) {
- $form->{$key} = "$ref->{accno}--$ref->{description}";
- }
-
- }
- }
- }
- chop $form->{taxaccounts};
-
- if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
- $form->{selectIC_income} = $form->{selectIC_sale};
- $form->{selectIC_expense} = $form->{selectIC_cogs};
- $form->{IC_income} = $form->{IC_sale};
- $form->{IC_expense} = $form->{IC_cogs};
- }
-
- delete $form->{IC_links};
- delete $form->{amount};
-
- $form->get_partsgroup(\%myconfig, { all => 1 });
-
- $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
-
- if (@{ $form->{all_partsgroup} }) {
- $form->{selectpartsgroup} = qq|<option>\n|;
- map {
- $form->{selectpartsgroup} .=
- qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
- } @{ $form->{all_partsgroup} };
- }
-
- if ($form->{item} eq 'assembly') {
-
- foreach my $i (1 .. $form->{assembly_rows}) {
- if ($form->{"partsgroup_id_$i"}) {
- $form->{"partsgroup_$i"} =
- qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
- }
- }
- $form->get_partsgroup(\%myconfig);
-
- if (@{ $form->{all_partsgroup} }) {
- $form->{selectassemblypartsgroup} = qq|<option>\n|;
-
- map {
- $form->{selectassemblypartsgroup} .=
- qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
- } @{ $form->{all_partsgroup} };
- }
- }
- $lxdebug->leave_sub();
-}
-
-sub form_header {
- $lxdebug->enter_sub();
-
- my ($payment, $rows, $notes, $description, $ean, $buchungsgruppe, $partsgroup, $group, $tax, $lastcost, $eur, $linkaccounts, $weight, $n, $rop, $bin, $vegv);
- my ($notdiscountableok, $notdiscountable);
- my ($formula, $formula_label, $imagelinks, $obsolete, $shopok, $shop);
-
- $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
-
- map({ $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, -2) }
- qw(sellprice listprice lastcost gv));
-
- map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
- qw(weight rop stock);
-
- foreach my $item (qw(partnumber description unit notes)) {
- $form->{$item} =~ s/\"/"/g;
- }
-
- $payment = qq|<option value=""></option>|;
- foreach my $item (@{ $form->{payment_terms} }) {
- if ($form->{payment_id} eq $item->{id}) {
- $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
- } else {
- $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
- }
- }
-
-
- if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
- $rows = 4;
- }
-
- $notes =
- qq|<textarea name=notes rows=$rows cols=45 wrap=soft>$form->{notes}</textarea>|;
- if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
- $description =
- qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
- } else {
- $description =
- qq|<input name=description size=40 value="$form->{description}">|;
- }
-
- $ean = qq|<input name=ean size=40 value="$form->{ean}">|;
-
- foreach my $item (split / /, $form->{taxaccounts}) {
- $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
- }
-
- IC->retrieve_buchungsgruppen(\%myconfig, $form);
- if (@{ $form->{BUCHUNGSGRUPPEN} }) {
- foreach my $item (@{ $form->{BUCHUNGSGRUPPEN} }) {
- if ($item->{id} == $form->{buchungsgruppen_id}) {
- $form->{selectbuchungsgruppe} .=
- "<option value=$item->{id} selected>$item->{description}\n";
- } elsif (($form->{id} && $form->{orphaned}) || (!$form->{id})) {
- $form->{selectbuchungsgruppe} .=
- "<option value=$item->{id}>$item->{description}\n";
- }
-
- }
- }