use SL::Common;
use SL::DBUtils;
use SL::MoreCommon;
+use List::Util qw(min);
sub post_invoice {
$main::lxdebug->enter_sub();
if (!$payments_only) {
if ($form->{id}) {
&reverse_invoice($dbh, $form);
-
} else {
($form->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('glid')|);
-
do_query($form, $dbh, qq|INSERT INTO ap (id, invnumber) VALUES (?, '')|, $form->{id});
}
}
if ($form->{currency} eq $defaultcurrency) {
$form->{exchangerate} = 1;
} else {
- $exchangerate =
- $form->check_exchangerate($myconfig, $form->{currency},
- $form->{transdate}, 'sell');
+ $exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, 'sell');
}
- $form->{exchangerate} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount($myconfig, $form->{exchangerate});
-
+ $form->{exchangerate} = $exchangerate || $form->parse_amount($myconfig, $form->{exchangerate});
$form->{exchangerate} = 1 unless ($form->{exchangerate} * 1);
my %item_units;
for my $i (1 .. $form->{rowcount}) {
next unless $form->{"id_$i"};
- $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
+ $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
+ $form->{"qty_$i"} *= -1 if $form->{storno};
- if ($form->{storno}) {
- $form->{"qty_$i"} *= -1;
- }
-
- if ($main::eur) {
- $form->{"inventory_accno_$i"} = $form->{"expense_accno_$i"};
- }
+ $form->{"inventory_accno_$i"} = $form->{"expense_accno_$i"} if $main::eur;
# get item baseunit
if (!$item_units{$form->{"id_$i"}}) {
my $item_unit = $item_units{$form->{"id_$i"}};
if (defined($all_units->{$item_unit}->{factor})
- && ($all_units->{$item_unit}->{factor} ne '')
- && ($all_units->{$item_unit}->{factor} * 1 != 0)) {
+ && ($all_units->{$item_unit}->{factor} ne '')
+ && ($all_units->{$item_unit}->{factor} * 1 != 0)) {
$basefactor = $all_units->{$form->{"unit_$i"}}->{factor} / $all_units->{$item_unit}->{factor};
} else {
$basefactor = 1;
$taxrate = 0;
$form->{"sellprice_$i"} = $form->parse_amount($myconfig, $form->{"sellprice_$i"});
- my $fxsellprice = $form->{"sellprice_$i"};
-
- my ($dec) = ($fxsellprice =~ /\.(\d+)/);
- $dec = length $dec;
+ (my $fxsellprice = $form->{"sellprice_$i"}) =~ /\.(\d+)/;
+ my $dec = length $1;
my $decimalplaces = ($dec > 2) ? $dec : 2;
map { $taxrate += $form->{"${_}_rate"} } @taxaccounts;
$form->{amount}{ $form->{id} }{ $form->{"inventory_accno_$i"} } -= $linetotal;
# adjust and round sellprice
- $form->{"sellprice_$i"} =
- $form->round_amount($form->{"sellprice_$i"} * $form->{exchangerate}, $decimalplaces);
+ $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} * $form->{exchangerate}, $decimalplaces);
$lastinventoryaccno = $form->{"inventory_accno_$i"};
@values = ($form->{"sellprice_$i"}, conv_i($form->{"id_$i"}));
do_query($form, $dbh, $query, @values);
- if (!$form->{shipped}) {
- $form->update_balance($dbh, "parts", "onhand", qq|id = ?|, $baseqty, $form->{"id_$i"})
- }
+ $form->update_balance($dbh, "parts", "onhand", qq|id = ?|, $baseqty, $form->{"id_$i"}) if !$form->{shipped};
# check if we sold the item already and
# make an entry for the expense and inventory
my $totalqty = $base_qty;
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-
- my $qty = $ref->{base_qty} + $ref->{allocated};
-
- if (($qty - $totalqty) > 0) {
- $qty = $totalqty;
- }
-
+ my $qty = min $totalqty, ($ref->{base_qty} + $ref->{allocated});
$linetotal = $form->round_amount(($form->{"sellprice_$i"} * $qty) / $basefactor, 2);
if ($ref->{allocated} < 0) {
} elsif ($linetotal != 0) {
# add entry for inventory, this one is for the sold item
- $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey)
- VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?))|;
- @values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal,
- $ref->{transdate}, $ref->{inventory_accno_id});
+ $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?))|;
+ @values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id});
do_query($form, $dbh, $query, @values);
# add expense
- $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey)
- VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?))|;
- @values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1),
- $ref->{transdate}, $ref->{expense_accno_id});
+ $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?))|;
+ @values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id});
do_query($form, $dbh, $query, @values);
}
$allocated += $qty;
- last if (($totalqty -= $qty) <= 0);
+ last if ($totalqty -= $qty) <= 0;
}
$sth->finish();
if ($form->round_amount($taxrate, 7) == 0) {
if ($form->{taxincluded}) {
foreach $item (@taxaccounts) {
- $taxamount =
- $linetotal * $form->{"${item}_rate"}
- / (1 + abs($form->{"${item}_rate"}));
+ $taxamount = $linetotal * $form->{"${item}_rate"} / (1 + abs($form->{"${item}_rate"}));
$totaltax += $taxamount;
$form->{amount}{ $form->{id} }{$item} -= $taxamount;
}
-
} else {
map { $form->{amount}{ $form->{id} }{$_} -= $linetotal * $form->{"${_}_rate"} } @taxaccounts;
}
-
} else {
map { $form->{amount}{ $form->{id} }{$_} -= $taxamount * $form->{"${_}_rate"} / $taxrate } @taxaccounts;
}
for my $i (1 .. $form->{paidaccounts}) {
$form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"});
$form->{paid} += $form->{"paid_$i"};
- $form->{datepaid} = $form->{"datepaid_$i"} if ($form->{"datepaid_$i"});
+ $form->{datepaid} = $form->{"datepaid_$i"} if $form->{"datepaid_$i"};
}
my ($tax, $paiddiff) = (0, 0);
$expensediff += $paiddiff;
######## this only applies to tax included
- if ($lastinventoryaccno) {
- $form->{amount}{ $form->{id} }{$lastinventoryaccno} -= $invoicediff;
- }
- if ($lastexpenseaccno) {
- $form->{amount}{ $form->{id} }{$lastexpenseaccno} -= $expensediff;
- }
+
+ $form->{amount}{ $form->{id} }{$lastinventoryaccno} -= $invoicediff if $lastinventoryaccno;
+ $form->{amount}{ $form->{id} }{$lastexpenseaccno} -= $expensediff if $lastexpenseaccno;
} else {
$amount = $form->round_amount($netamount * $form->{exchangerate}, 2);
$form->{amount}{ $form->{id} }{ $form->{AP} } = $netamount + $tax;
- if ($form->{paid} != 0) {
- $form->{paid} = $form->round_amount($form->{paid} * $form->{exchangerate} + $paiddiff, 2);
- }
+
+ $form->{paid} = $form->round_amount($form->{paid} * $form->{exchangerate} + $paiddiff, 2) if $form->{paid} != 0;
# update exchangerate
- if (($form->{currency} ne $defaultcurrency) && !$exchangerate) {
- $form->update_exchangerate($dbh, $form->{currency}, $form->{invdate}, 0, $form->{exchangerate});
- }
+
+ $form->update_exchangerate($dbh, $form->{currency}, $form->{invdate}, 0, $form->{exchangerate})
+ if ($form->{currency} ne $defaultcurrency) && !$exchangerate;
# record acc_trans transactions
foreach my $trans_id (keys %{ $form->{amount} }) {
foreach my $accno (keys %{ $form->{amount}{$trans_id} }) {
$form->{amount}{$trans_id}{$accno} = $form->round_amount($form->{amount}{$trans_id}{$accno}, 2);
- next if ($payments_only || !$form->{amount}{$trans_id}{$accno});
+ next if $payments_only || !$form->{amount}{$trans_id}{$accno};
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
}
# force AP entry if 0
- if ($form->{amount}{ $form->{id} }{ $form->{AP} } == 0) {
- $form->{amount}{ $form->{id} }{ $form->{AP} } = $form->{paid};
- }
+
+ $form->{amount}{ $form->{id} }{ $form->{AP} } = $form->{paid} if $form->{amount}{$form->{id}}{$form->{AP}} == 0;
# record payments and offsetting AP
for my $i (1 .. $form->{paidaccounts}) {
- next if ($form->{"paid_$i"} == 0);
+ next if $form->{"paid_$i"} == 0;
my ($accno) = split /--/, $form->{"AP_paid_$i"};
$form->{"datepaid_$i"} = $form->{invdate} unless ($form->{"datepaid_$i"});
if ($form->{currency} eq $defaultcurrency) {
$form->{"exchangerate_$i"} = 1;
} else {
- $exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
-
- $form->{"exchangerate_$i"} =
- ($exchangerate)
- ? $exchangerate
- : $form->parse_amount($myconfig, $form->{"exchangerate_$i"});
+ $exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
+ $form->{"exchangerate_$i"} = $exchangerate || $form->parse_amount($myconfig, $form->{"exchangerate_$i"});
}
# exchangerate difference
- $form->{fx}{$accno}{ $form->{"datepaid_$i"} } +=
- $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) + $paiddiff;
+ $form->{fx}{$accno}{ $form->{"datepaid_$i"} } += $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) + $paiddiff;
# gain/loss
$amount =
($form->{"paid_$i"} * $form->{"exchangerate_$i"});
if ($amount > 0) {
$form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } += $amount;
-
} else {
$form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } += $amount;
}
$paiddiff = 0;
# update exchange rate
- if (($form->{currency} ne $defaultcurrency) && !$exchangerate) {
- $form->update_exchangerate($dbh, $form->{currency},
- $form->{"datepaid_$i"},
- 0, $form->{"exchangerate_$i"});
- }
+ $form->update_exchangerate($dbh, $form->{currency}, $form->{"datepaid_$i"}, 0, $form->{"exchangerate_$i"})
+ if ($form->{currency} ne $defaultcurrency) && !$exchangerate;
}
# record exchange rate differences and gains/losses
$form->{department_id} = (split /--/, $form->{department})[1];
$form->{invnumber} = $form->{id} unless $form->{invnumber};
- $taxzone_id = 0 if ((3 < $taxzone_id) || (0 > $taxzone_id));
+ $taxzone_id = 0 if (3 < $taxzone_id) || (0 > $taxzone_id);
# save AP record
$query = qq|UPDATE ap SET
- invnumber = ?,
- ordnumber = ?,
- quonumber = ?,
- transdate = ?,
- orddate = ?,
- quodate = ?,
- vendor_id = ?,
- amount = ?,
- netamount = ?,
- paid = ?,
- datepaid = ?,
- duedate = ?,
- invoice = '1',
- taxzone_id = ?,
- taxincluded = ?,
- notes = ?,
- intnotes = ?,
- curr = ?,
- department_id = ?,
- storno = ?,
- storno_id = ?,
- globalproject_id = ?,
- cp_id = ?,
- employee_id = ?
+ invnumber = ?, ordnumber = ?, quonumber = ?, transdate = ?,
+ orddate = ?, quodate = ?, vendor_id = ?, amount = ?,
+ netamount = ?, paid = ?, duedate = ?, datepaid = ?,
+ invoice = ?, taxzone_id = ?, notes = ?, taxincluded = ?,
+ intnotes = ?, curr = ?, storno_id = ?, storno = ?,
+ cp_id = ?, employee_id = ?, department_id = ?,
+ globalproject_id = ?
WHERE id = ?|;
- @values = ($form->{invnumber}, $form->{ordnumber}, $form->{quonumber},
- conv_date($form->{invdate}), conv_date($form->{orddate}), conv_date($form->{quodate}),
- conv_i($form->{vendor_id}), $amount, $netamount, $form->{paid},
- $form->{paid} ? conv_date($form->{datepaid}) : undef,
- conv_date($form->{duedate}), $taxzone_id,
- $form->{taxincluded} ? 't' : 'f',
- $form->{notes}, $form->{intnotes}, $form->{currency}, conv_i($form->{department_id}),
- $form->{storno} ? 't' : 'f', conv_i($form->{storno_id}),
- conv_i($form->{globalproject_id}), conv_i($form->{cp_id}),
- conv_i($form->{employee_id}),
- conv_i($form->{id}));
+ @values = (
+ $form->{invnumber}, $form->{ordnumber}, $form->{quonumber}, conv_date($form->{invdate}),
+ conv_date($form->{orddate}), conv_date($form->{quodate}), conv_i($form->{vendor_id}), $amount,
+ $netamount, $form->{paid}, conv_date($form->{duedate}), $form->{paid} ? conv_date($form->{datepaid}) : undef,
+ '1', $taxzone_id, $form->{notes}, $form->{taxincluded} ? 't' : 'f',
+ $form->{intnotes}, $form->{currency}, conv_i($form->{storno_id}), $form->{storno} ? 't' : 'f',
+ conv_i($form->{cp_id}), conv_i($form->{employee_id}), conv_i($form->{department_id}),
+ conv_i($form->{globalproject_id}),
+ conv_i($form->{id})
+ );
do_query($form, $dbh, $query, @values);
if ($form->{storno}) {
# save AR record
$query = qq|UPDATE ar set
- invnumber = ?,
- ordnumber = ?,
- quonumber = ?,
- cusordnumber = ?,
- transdate = ?,
- orddate = ?,
- quodate = ?,
- customer_id = ?,
- amount = ?,
- netamount = ?,
- paid = ?,
- datepaid = ?,
- duedate = ?,
- deliverydate = ?,
- invoice = '1',
- shippingpoint = ?,
- shipvia = ?,
- terms = ?,
- notes = ?,
- intnotes = ?,
- taxincluded = ?,
- curr = ?,
- department_id = ?,
- payment_id = ?,
- type = ?,
- language_id = ?,
- taxzone_id = ?,
- shipto_id = ?,
- delivery_customer_id = ?,
- delivery_vendor_id = ?,
- employee_id = ?,
- salesman_id = ?,
- storno = ?,
- storno_id = ?,
- globalproject_id = ?,
- cp_id = ?,
- transaction_description = ?,
- marge_total = ?,
- marge_percent = ?
+ invnumber = ?, ordnumber = ?, quonumber = ?, cusordnumber = ?,
+ transdate = ?, orddate = ?, quodate = ?, customer_id = ?,
+ amount = ?, netamount = ?, paid = ?, datepaid = ?,
+ duedate = ?, deliverydate = ?, invoice = ?, shippingpoint = ?,
+ shipvia = ?, terms = ?, notes = ?, intnotes = ?,
+ curr = ?, department_id = ?, payment_id = ?, taxincluded = ?,
+ type = ?, language_id = ?, taxzone_id = ?, shipto_id = ?,
+ employee_id = ?, salesman_id = ?, storno_id = ?, storno = ?,
+ cp_id = ?, marge_total = ?, marge_percent = ?,
+ globalproject_id = ?, delivery_customer_id = ?,
+ transaction_description = ?, delivery_vendor_id = ?
WHERE id = ?|;
- @values = ($form->{"invnumber"}, $form->{"ordnumber"}, $form->{"quonumber"}, $form->{"cusordnumber"},
- conv_date($form->{"invdate"}), conv_date($form->{"orddate"}), conv_date($form->{"quodate"}),
- conv_i($form->{"customer_id"}), $amount, $netamount, $form->{"paid"},
- conv_date($form->{"datepaid"}), conv_date($form->{"duedate"}), conv_date($form->{"deliverydate"}),
- $form->{"shippingpoint"}, $form->{"shipvia"}, conv_i($form->{"terms"}),
- $form->{"notes"}, $form->{"intnotes"}, $form->{"taxincluded"} ? 't' : 'f',
- $form->{"currency"}, conv_i($form->{"department_id"}), conv_i($form->{"payment_id"}),
- $form->{"type"}, conv_i($form->{"language_id"}), conv_i($form->{"taxzone_id"}),
- conv_i($form->{"shipto_id"}),
- conv_i($form->{"delivery_customer_id"}), conv_i($form->{"delivery_vendor_id"}),
- conv_i($form->{"employee_id"}), conv_i($form->{"salesman_id"}),
- $form->{"storno"} ? 't' : 'f', conv_i($form->{storno_id}), conv_i($form->{"globalproject_id"}),
- conv_i($form->{"cp_id"}), $form->{transaction_description},
- $form->{marge_total} * 1, $form->{marge_percent} * 1,
- conv_i($form->{"id"}));
+ @values = ( $form->{"invnumber"}, $form->{"ordnumber"}, $form->{"quonumber"}, $form->{"cusordnumber"},
+ conv_date($form->{"invdate"}), conv_date($form->{"orddate"}), conv_date($form->{"quodate"}), conv_i($form->{"customer_id"}),
+ $amount, $netamount, $form->{"paid"}, conv_date($form->{"datepaid"}),
+ conv_date($form->{"duedate"}), conv_date($form->{"deliverydate"}), '1', $form->{"shippingpoint"},
+ $form->{"shipvia"}, conv_i($form->{"terms"}), $form->{"notes"}, $form->{"intnotes"},
+ $form->{"currency"}, conv_i($form->{"department_id"}), conv_i($form->{"payment_id"}), $form->{"taxincluded"} ? 't' : 'f',
+ $form->{"type"}, conv_i($form->{"language_id"}), conv_i($form->{"taxzone_id"}), conv_i($form->{"shipto_id"}),
+ conv_i($form->{"employee_id"}), conv_i($form->{"salesman_id"}), conv_i($form->{storno_id}), $form->{"storno"} ? 't' : 'f',
+ conv_i($form->{"cp_id"}), 1 * $form->{marge_total} , 1 * $form->{marge_percent},
+ conv_i($form->{"globalproject_id"}), conv_i($form->{"delivery_customer_id"}),
+ $form->{transaction_description}, conv_i($form->{"delivery_vendor_id"}),
+ conv_i($form->{"id"}));
do_query($form, $dbh, $query, @values);
if($form->{"formname"} eq "credit_note") {
s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
}
- if ($form->{old_employee_id}) {
- $form->{employee_id} = $form->{old_employee_id};
- }
- if ($form->{old_salesman_id}) {
- $form->{salesman_id} = $form->{old_salesman_id};
- }
-
+ $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
+ $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
-
-
- $form->{radier} =
- ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
-
- $form->{exchangerate} =
- $form->format_amount(\%myconfig, $form->{exchangerate});
-
- $form->{creditlimit} =
- $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
- $form->{creditremaining} =
- $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
+ $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
+ $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
+ $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
+ $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
$exchangerate = "";
if ($form->{currency} ne $form->{defaultcurrency}) {
if ($form->{forex}) {
- $exchangerate .= qq|
- <th align=right nowrap>|
- . $locale->text('Exchangerate') . qq|</th>
- <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
-|;
+ $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
+ <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>\n|;
} else {
- $exchangerate .= qq|
- <th align=right nowrap>|
- . $locale->text('Exchangerate') . qq|</th>
- <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
-|;
+ $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
+ <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>\n|;
}
}
- $exchangerate .= qq|
-<input type=hidden name=forex value=$form->{forex}>
-|;
+ $exchangerate .= qq| <input type=hidden name=forex value=$form->{forex}>\n|;
my @old_project_ids = ($form->{"globalproject_id"});
- map({ push(@old_project_ids, $form->{"project_id_$_"})
- if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
+ map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
- $form->get_lists("contacts" => "ALL_CONTACTS",
- "projects" => { "key" => "ALL_PROJECTS",
- "all" => 0,
+ $form->get_lists("contacts" => "ALL_CONTACTS",
+ "projects" => { "key" => "ALL_PROJECTS",
+ "all" => 0,
"old_id" => \@old_project_ids },
- "taxzones" => "ALL_TAXZONES",
- "employees" => "ALL_SALESMEN",
+ "taxzones" => "ALL_TAXZONES",
+ "employees" => "ALL_SALESMEN",
"currencies" => "ALL_CURRENCIES",
- "vendors" => "ALL_VENDORS");
+ "vendors" => "ALL_VENDORS");
my %labels;
my @values = (undef);
foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
push(@values, $item->{"cp_id"});
- $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
- ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
+ $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
}
my $contact;
$contact = qq|
<tr>
<th align="right">| . $locale->text('Contact Person') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
- '-labels' => \%labels, '-default' => $form->{"cp_id"}))
- . qq|
+ <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
+ '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
</td>
</tr>|;
}
push(@values, $item->{"id"});
$labels{$item->{"id"}} = $item->{"projectnumber"};
}
- my $globalprojectnumber =
- NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
- '-labels' => \%labels,
- '-default' => $form->{"globalproject_id"}));
+ my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels,
+ '-default' => $form->{"globalproject_id"}));
%labels = ();
@values = ();
$currencies = qq|
<tr>
<th align="right">| . $locale->text('Currency') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
- '-values' => \@values, '-labels' => \%labels)) . qq|
+ <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
+ '-values' => \@values, '-labels' => \%labels)) . qq|
</td>
</tr>|;
}
$labels{$item->{"id"}} = $item->{"name"};
}
my $employees = qq|
- <tr>
+ <tr>
<th align="right">| . $locale->text('Employee') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
- '-values' => \@values, '-labels' => \%labels)) . qq|
+ <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
+ '-values' => \@values, '-labels' => \%labels)) . qq|
</td>
- </tr>|;
+ </tr>|;
%labels = ();
@values = ();
$taxzone = qq|
<tr>
<th align="right">| . $locale->text('Steuersatz') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
- '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
+ <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
+ '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
</td>
</tr>|;
-
} else {
$taxzone = qq|
<tr>
}
$department = qq|
- <tr>
+ <tr>
<th align="right" nowrap>| . $locale->text('Department') . qq|</th>
<td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
<input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
$button1 = qq|
<td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
- <input type=button name=invdate id="trigger1" value=|
- . $locale->text('button') . qq|></td>
- |;
+ <input type=button name=invdate id="trigger1" value=| . $locale->text('button') . qq|></td>\n|;
$button2 = qq|
<td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
- <input type=button name=duedate id="trigger2" value=|
- . $locale->text('button') . qq|></td></td>
- |;
+ <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|></td></td>\n|;
#write Trigger
$jsscript =
$form->{"javascript"} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
$form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
- $jsscript .=
- $form->write_trigger(\%myconfig, 2,
- "orddate", "BL", "trigger_orddate",
- "quodate", "BL", "trigger_quodate");
+ $jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate");
$form->header;
$onload = qq|focus()|;
sub form_header {
$lxdebug->enter_sub();
- if ($form->{old_employee_id}) {
- $form->{employee_id} = $form->{old_employee_id};
- }
- if ($form->{old_salesman_id}) {
- $form->{salesman_id} = $form->{old_salesman_id};
- }
+ $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
+ $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
if ($edit) {
-
if ($form->{type} eq "credit_note") {
$form->{title} = $locale->text('Edit Credit Note');
-
- if ($form->{storno}) {
- $form->{title} = $locale->text('Edit Storno Credit Note');
- }
+ $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
} else {
$form->{title} = $locale->text('Edit Sales Invoice');
-
- if ($form->{storno}) {
- $form->{title} = $locale->text('Edit Storno Invoice');
- }
+ $form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
}
}
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- $form->{radier} =
- ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
+ $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
$payment = qq|<option value=""></option>|;
foreach $item (@{ $form->{payment_terms} }) {
}
}
- my $set_duedate_url =
- "$form->{script}?login=$form->{login}&password=$form->{password}&action=set_duedate";
+ my $set_duedate_url = "$form->{script}?login=$form->{login}&password=$form->{password}&action=set_duedate";
my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
push(@ { $form->{AJAX} }, $pjx);
my @old_project_ids = ($form->{"globalproject_id"});
- map({ push(@old_project_ids, $form->{"project_id_$_"})
- if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
-
- $form->get_lists("contacts" => "ALL_CONTACTS",
- "shipto" => "ALL_SHIPTO",
- "projects" => { "key" => "ALL_PROJECTS",
- "all" => 0,
- "old_id" => \@old_project_ids },
- "employees" => "ALL_SALESMEN",
- "taxzones" => "ALL_TAXZONES",
+ map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
+
+ $form->get_lists("contacts" => "ALL_CONTACTS",
+ "shipto" => "ALL_SHIPTO",
+ "projects" => { "key" => "ALL_PROJECTS",
+ "all" => 0,
+ "old_id" => \@old_project_ids },
+ "employees" => "ALL_SALESMEN",
+ "taxzones" => "ALL_TAXZONES",
"currencies" => "ALL_CURRENCIES",
- "customers" => "ALL_CUSTOMERS");
+ "customers" => "ALL_CUSTOMERS");
my %labels;
my @values = (undef);
foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
push(@values, $item->{"cp_id"});
- $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
- ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
+ $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
}
my $contact;
if (scalar @values > 1) {
$contact = qq|
<tr>
<th align="right">| . $locale->text('Contact Person') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
- '-labels' => \%labels, '-default' => $form->{"cp_id"}))
- . qq|
+ <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
+ '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
</td>
</tr>|;
}
my $employees = qq|
<tr>
<th align="right">| . $locale->text('Employee') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
- '-values' => \@values, '-labels' => \%labels)) . qq|
+ <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
+ '-values' => \@values, '-labels' => \%labels)) . qq|
</td>
</tr>|;
$shipto = qq|
<tr>
<th align="right">| . $locale->text('Shipping Address') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
- '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
- . qq|</td>|;
+ <td>| . NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
+ '-labels' => \%labels, '-default' => $form->{"shipto_id"})). qq|
+ </td>|;
}
%labels = ();
$currencies = qq|
<tr>
<th align="right">| . $locale->text('Currency') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
- '-values' => \@values, '-labels' => \%labels)) . qq|
+ <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
+ '-values' => \@values, '-labels' => \%labels)) . qq|
</td>
</tr>|;
}
push(@values, $item->{"id"});
$labels{$item->{"id"}} = $item->{"projectnumber"};
}
- my $globalprojectnumber =
- NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
- '-labels' => \%labels,
- '-default' => $form->{"globalproject_id"}));
+ my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
+ '-labels' => \%labels,
+ '-default' => $form->{"globalproject_id"}));
%labels = ();
@values = ();
}
$salesman =
- qq|<tr>
- <th align="right">| . $locale->text('Salesman') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id},
- '-values' => \@values, '-labels' => \%labels))
- . qq|</td>
- </tr>|;
+ qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
+ <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
+ '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
+ </td>
+ </tr>|;
%labels = ();
@values = ();
$taxzone = qq|
<tr>
<th align="right">| . $locale->text('Steuersatz') . qq|</th>
- <td>| .
- NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
- '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
+ <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
+ '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px',)) . qq|
</td>
</tr>|;
# set option selected
foreach $item (qw(AR customer currency department employee)) {
$form->{"select$item"} =~ s/ selected//;
- $form->{"select$item"} =~
- s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
+ $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
}
if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
$creditwarning = 0;
}
- $form->{exchangerate} =
- $form->format_amount(\%myconfig, $form->{exchangerate});
-
- $form->{creditlimit} =
- $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
- $form->{creditremaining} =
- $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
+ $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
+ $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
+ $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
$exchangerate = "";
if ($form->{currency} ne $form->{defaultcurrency}) {
if ($form->{forex}) {
- $exchangerate .=
- qq|<th align="right">|
- . $locale->text('Exchangerate')
- . qq|</th><td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
+ $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
+ <td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
} else {
- $exchangerate .=
- qq|<th align="right">|
- . $locale->text('Exchangerate')
- . qq|</th><td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
+ $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
+ <td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
}
}
- $exchangerate .= qq|
-<input type="hidden" name="forex" value="$form->{forex}">
-|;
+ $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
$department = qq|
<tr>
<th align="right" nowrap>| . $locale->text('Department') . qq|</th>
<td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
- <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
+ <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
</td>
</tr>
| if $form->{selectdepartment};
}
if ($form->{resubmit} && ($form->{format} eq "html")) {
- $onload =
- qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
+ $onload = qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
} elsif ($form->{resubmit}) {
$onload = qq|document.invoice.submit()|;
} else {
# also copy deliverydate from the order
$form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
- $form->{orddate} = $form->{transdate};
+ $form->{orddate} = $form->{transdate};
} else {
$form->isblank("quonumber", $locale->text('Quotation Number missing!'));
$form->isblank("transdate", $locale->text('Quotation Date missing!'));
- $form->{ordnumber} = "";
- $form->{quodate} = $form->{transdate};
+ $form->{ordnumber} = "";
+ $form->{quodate} = $form->{transdate};
}
- if($form->{payment_id}) {
- $payment_id = $form->{payment_id};
- }
+ $payment_id = $form->{payment_id} if $form->{payment_id};
# if the name changed get new values
if (&check_name($form->{vc})) {
- if($form->{payment_id} eq "") {
- $form->{payment_id} = $payment_id;
- }
+ $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
&update;
exit;
}
$form->{cp_id} *= 1;
for $i (1 .. $form->{rowcount}) {
- map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
- $form->{"${_}_${i}"})
- if ($form->{"${_}_${i}"}) }
- qw(ship qty sellprice listprice basefactor));
+ for (qw(ship qty sellprice listprice basefactor)) {
+ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"};
+ }
}
if ( $form->{type} =~ /_order/
$buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
$orddate = $form->current_date(\%myconfig);
- $exchangerate =
- $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
- $buysell);
+ $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate, $buysell);
if (!$exchangerate) {
&backorder_exchangerate($orddate, $buysell);
}
$form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
- $form->{duedate} =
- $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+ $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
$form->{id} = '';
$form->{closed} = 0;
$script = "ir";
$buysell = 'sell';
}
- if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
+
+ if ( $form->{type} eq 'sales_order'
+ || $form->{type} eq 'sales_quotation') {
$form->{title} = $locale->text('Add Sales Invoice');
$form->{script} = 'is.pl';
$script = "is";
}
# bo creates the id, reset it
- map { delete $form->{$_} }
- qw(id subject message cc bcc printed emailed queued);
+ map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);
$form->{ $form->{vc} } =~ s/--.*//g;
$form->{type} = "invoice";