our ($form, $locale, %myconfig, $lxdebug);
require "bin/mozilla/io.pl";
+require "bin/mozilla/invoice_io.pl";
require "bin/mozilla/common.pl";
require "bin/mozilla/reportgenerator.pl";
|;
#write Trigger
- $jsscript =
- Form->write_trigger(\%myconfig, "2", "transdatefrom", "BL", "trigger1",
- "transdateto", "BL", "trigger2");
+ $jsscript = Form->write_trigger(\%myconfig, "2", "transdatefrom", "BL", "trigger1", "transdateto", "BL", "trigger2");
} else {
# without JavaScript Calendar
- $button1 = qq|
- <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
- $button2 = qq|
- <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
+ $button1 = qq| <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
+ $button2 = qq| <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
}
unless ($form->{searchitems} eq 'service') {
- $onhand = qq|
- <input name=itemstatus class=radio type=radio value=onhand> |
- . $locale->text('On Hand') . qq|
- <input name=itemstatus class=radio type=radio value=short> |
- . $locale->text('Short') . qq|
+ $onhand = qq| <input name=itemstatus class=radio type=radio value=onhand> | . $locale->text('On Hand') . qq|
+ <input name=itemstatus class=radio type=radio value=short> | . $locale->text('Short') . qq|
|;
$makemodel = qq|
<tr>
- <th align=right nowrap>| . $locale->text('Make') . qq|</th>
- <td><input name=make size=20></td>
- <th align=right nowrap>| . $locale->text('Model') . qq|</th>
- <td><input name=model size=20></td>
+ <th align=right nowrap>| . $locale->text('Make') . qq|</th> <td><input name=make size=20></td>
+ <th align=right nowrap>| . $locale->text('Model') . qq|</th> <td><input name=model size=20></td>
</tr>
|;
$serialnumber = qq|
- <th align=right nowrap>| . $locale->text('Serial Number') . qq|</th>
- <td><input name=serialnumber size=20></td>
+ <th align=right nowrap>| . $locale->text('Serial Number') . qq|</th> <td><input name=serialnumber size=20></td>
|;
$l_serialnumber = qq|
- <td><input name=l_serialnumber class=checkbox type=checkbox value=Y> |
- . $locale->text('Serial Number') . qq|</td>
+ <td><input name=l_serialnumber class=checkbox type=checkbox value=Y> | . $locale->text('Serial Number') . qq|</td>
|;
}
$form->{ledgerchecks} = 'Y' if ( $form->{bought} || $form->{sold} || $form->{onorder}
|| $form->{ordered} || $form->{rfq} || $form->{quoted});
- # if something should be aktivated if something else is active, enter it here
+ # if something should be activated if something else is active, enter it here
my %dependencies = (
onhand => [ qw(l_onhand) ],
short => [ qw(l_onhand) ],
);
map { $column_defs{$_}->{visible} = $form->{"l_$_"} ? 1 : 0 } @columns;
-
- my %column_alignment = map { $_ => 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal);
+ 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);
'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);
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} }) {
- my $row = { };
- foreach (@columns) {
- $row->{$_} = {
- 'align' => $column_alignment{$_},
- 'data' => $ref->{$_},
- };
- }
+ # 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
my $onhand = $ref->{onhand};
if ($ref->{assemblyitem}) {
- $row->{partnumber}->{align} = 'right';
- $row->{onhand}->{data} = 0;
+ $row->{partnumber}{align} = 'right';
+ $row->{onhand}{data} = 0;
$onhand = 0 if ($form->{sold});
}
$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);
+ $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);
+ map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
if (!$ref->{assemblyitem}) {
foreach my $col (@subtotal_columns) {
$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});
+ $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');
+ $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>';
+ $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);
+ map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
$report->add_data($row);
- my $next_ref = $form->{parts}->[$idx + 1];
+ my $next_ref = $form->{parts}[$idx + 1];
+ # insert subtotal rows
if (($form->{l_subtotal} eq 'Y') &&
(!$next_ref ||
- (!$next_ref->{assemblyitem} && ($ref->{$form->{sort}} ne $next_ref->{$form->{sort}})))) {
- my $row = { map { $_ => { 'class' => 'listsubtotal', 'align' => 'right' } } @columns };
+ (!$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 { $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', 'align' => 'right' } } @columns };
+ my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
# if this is a tax field
if ($key =~ /IC_tax/) {
- if ($key =~ /$item/) {
+ if ($key =~ /\Q$item\E/) {
$form->{taxaccounts} .= "$ref->{accno} ";
$form->{"IC_tax_$ref->{accno}_description"} =
"$ref->{accno}--$ref->{description}";
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));
$unit_select .= AM->unit_select_html($units, "unit", $form->{"unit"});
}
+ my $price_factor;
+ if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
+ my @values = ('', map { $_->{id} } @{ $form->{ALL_PRICE_FACTORS} });
+ my %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
+
+ $price_factor =
+ qq|<tr><th align="right">|
+ . $locale->text('Price Factor')
+ . qq|</th><td>|
+ . NTI($cgi->popup_menu('-name' => 'price_factor_id',
+ '-default' => $form->{price_factor_id},
+ '-values' => \@values,
+ '-labels' => \%labels))
+ . qq|</td></tr>|;
+ }
+
$form->{fokus} = "ic.partnumber";
$form->header;
<tr valign=top>
<td width=70%>
<table width="100%" height="100%">
- <tr class="listheading">
- <th class="listheading" align="center" colspan=2>|
- . $locale->text('') . qq|</th>
+ <tr>
+ <td colspan=2>
+ <table>
+ $buchungsgruppe
+ $linkaccounts
+ </table>
+ </td>
</tr>
- <td colspan=2>
- <table>
- $buchungsgruppe
- $linkaccounts
- </table>
- </td>
<tr>
<th align="left">| . $locale->text('Notes') . qq|</th>
<th align="left">$formula_label</th>
<td><input name=sellprice size=11 value=$form->{sellprice}></td>
</tr>
$lastcost
+ $price_factor
<tr>
<th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
<td>$unit_select</td>
}
}
- }
- if ($form->{item} eq "part") {
+ } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
&check_form;
}
- if ($form->{item} eq 'service') {
- map({ $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
- qw(sellprice listprice lastcost));
- &form_header;
- &price_row;
- &form_footer;
- }
-
$lxdebug->leave_sub();
}
# now take it apart and restore original values
foreach my $item (split /&/, $previousform) {
- my ($key, $value) = split /=/, $item, 2;
+ my ($key, $value) = split m/=/, $item, 2;
$value =~ s/%26/&/g;
$form->{$key} = $value;
}
$form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
# change/add values for assembly item
- map { $form->{"${_}_$i"} = $newform{$_} }
- qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno);
+ map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
$form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
$form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
$i = $form->{rowcount};
$form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
- map { $form->{"${_}_$i"} = $newform{$_} }
- qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice);
+ map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
+
$form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
+
if ($form->{exchangerate} != 0) {
$form->{"sellprice_$i"} /= $form->{exchangerate};
}
+
$lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
- map { $form->{"taxaccounts_$i"} .= "$_ " } split / /,
- $newform{taxaccount};
+
+ map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
chop $form->{"taxaccounts_$i"};
foreach my $item (qw(description rate taxnumber)) {
my $index = $form->{"taxaccounts_$i"} . "_$item";
}
# credit remaining calculation
- $amount =
- $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
- $form->{"qty_$i"};
- map { $form->{"${_}_base"} += $amount }
- (split / /, $form->{"taxaccounts_$i"});
- map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
- split / /, $form->{"taxaccounts_$i"}
- if !$form->{taxincluded};
+ $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
+
+ map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
+ map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
$form->{creditremaining} -= $amount;
# redo number formatting, because invoice parse them!
- $i = $form->{rowcount};
- map {
- $form->{"${_}_$i"} =
- $form->format_amount(\%myconfig, $form->{"${_}_$i"})
- } qw(weight listprice sellprice rop);
+ map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
}
$form->{"id_$i"} = $parts_id;
+
+ # Get the actual price factor (not just the ID) for the marge calculation.
+ $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
+ foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
+ next if ($pfac->{id} != $newform{price_factor_id});
+ $form->{"marge_price_factor_$i"} = $pfac->{factor};
+ last;
+ }
+ delete $form->{ALL_PRICE_FACTORS};
+
delete $form->{action};
# restore original callback