summaryrefslogtreecommitdiff
path: root/locale/legacy/ch/menu
diff options
context:
space:
mode:
Diffstat (limited to 'locale/legacy/ch/menu')
0 files changed, 0 insertions, 0 deletions
n class="hl slc"># This program is distributed in the hope that it will be useful,
  • # but WITHOUT ANY WARRANTY; without even the implied warranty of
  • # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • # GNU General Public License for more details.
  • # You should have received a copy of the GNU General Public License
  • # along with this program; if not, write to the Free Software
  • # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  • #######################################################################
  • #
  • # common routines used in is, ir, oe
  • #
  • #######################################################################
  • use LedgerSMB::Tax;
  • use LedgerSMB::Sysconfig;
  • # any custom scripts for this one
  • if (-f "bin/custom/io.pl") {
  • eval { require "bin/custom/io.pl"; };
  • }
  • if (-f "bin/custom/$form->{login}_io.pl") {
  • eval { require "bin/custom/$form->{login}_io.pl"; };
  • }
  • 1;
  • # end of main
  • # this is for our long dates
  • # $locale->text('January')
  • # $locale->text('February')
  • # $locale->text('March')
  • # $locale->text('April')
  • # $locale->text('May ')
  • # $locale->text('June')
  • # $locale->text('July')
  • # $locale->text('August')
  • # $locale->text('September')
  • # $locale->text('October')
  • # $locale->text('November')
  • # $locale->text('December')
  • # this is for our short month
  • # $locale->text('Jan')
  • # $locale->text('Feb')
  • # $locale->text('Mar')
  • # $locale->text('Apr')
  • # $locale->text('May')
  • # $locale->text('Jun')
  • # $locale->text('Jul')
  • # $locale->text('Aug')
  • # $locale->text('Sep')
  • # $locale->text('Oct')
  • # $locale->text('Nov')
  • # $locale->text('Dec')
  • sub display_row {
  • my $numrows = shift;
  • @column_index = qw(runningnumber partnumber description qty);
  • if ($form->{type} eq "sales_order") {
  • push @column_index, "ship";
  • $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Ship').qq|</th>|;
  • }
  • if ($form->{type} eq "purchase_order") {
  • push @column_index, "ship";
  • $column_data{ship} = qq|<th class=listheading align=center width="auto">|.$locale->text('Recd').qq|</th>|;
  • }
  • for (qw(projectnumber partsgroup)) {
  • $form->{"select$_"} = $form->unescape($form->{"select$_"}) if $form->{"select$_"};
  • }
  • if ($form->{language_code} ne $form->{oldlanguage_code}) {
  • # rebuild partsgroup
  • $l{language_code} = $form->{language_code};
  • $l{searchitems} = 'nolabor' if $form->{vc} eq 'customer';
  • $form->get_partsgroup(\%myconfig, \%l);
  • if (@ { $form->{all_partsgroup} }) {
  • $form->{selectpartsgroup} = "<option>\n";
  • foreach $ref (@ { $form->{all_partsgroup} }) {
  • if ($ref->{translation}) {
  • $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
  • } else {
  • $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
  • }
  • }
  • }
  • $form->{oldlanguage_code} = $form->{language_code};
  • }
  • push @column_index, @{LedgerSMB::Sysconfig::io_lineitem_columns};
  • my $colspan = $#column_index + 1;
  • $form->{invsubtotal} = 0;
  • for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
  • $column_data{runningnumber} = qq|<th class=listheading nowrap>|.$locale->text('Item').qq|</th>|;
  • $column_data{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
  • $column_data{description} = qq|<th class=listheading nowrap>|.$locale->text('Description').qq|</th>|;
  • $column_data{qty} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
  • $column_data{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
  • $column_data{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Price').qq|</th>|;
  • $column_data{discount} = qq|<th class=listheading>%</th>|;
  • $column_data{linetotal} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
  • $column_data{bin} = qq|<th class=listheading nowrap>|.$locale->text('Bin').qq|</th>|;
  • $column_data{onhand} = qq|<th class=listheading nowrap>|.$locale->text('OH').qq|</th>|;
  • print qq|
  • <tr>
  • <td>
  • <table width=100%>
  • <tr class=listheading>|;
  • for (@column_index) { print "\n$column_data{$_}" }
  • print qq|
  • </tr>
  • |;
  • $deliverydate = $locale->text('Delivery Date');
  • $serialnumber = $locale->text('Serial No.');
  • $projectnumber = $locale->text('Project');
  • $group = $locale->text('Group');
  • $sku = $locale->text('SKU');
  • $delvar = 'deliverydate';
  • if ($form->{type} =~ /_(order|quotation)$/) {
  • $reqdate = $locale->text('Required by');
  • $delvar = 'reqdate';
  • }
  • $exchangerate = $form->parse_amount(\%myconfig, $form->{exchangerate});
  • $exchangerate = ($exchangerate) ? $exchangerate : 1;
  • $spc = substr($myconfig{numberformat},-3,1);
  • for $i (1 .. $numrows) {
  • if ($spc eq '.') {
  • ($null, $dec) = split /\./, $form->{"sellprice_$i"};
  • } else {
  • ($null, $dec) = split /,/, $form->{"sellprice_$i"};
  • }
  • $dec = length $dec;
  • $decimalplaces = ($dec > 2) ? $dec : 2;
  • # undo formatting
  • for (qw(qty oldqty ship discount sellprice)) { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
  • if ($form->{"qty_$i"} != $form->{"oldqty_$i"}) {
  • # check pricematrix
  • @a = split / /, $form->{"pricematrix_$i"};
  • if (scalar @a > 2) {
  • foreach $item (@a) {
  • ($q, $p) = split /:/, $item;
  • if (($p * 1) && ($form->{"qty_$i"} >= ($q * 1))) {
  • ($dec) = ($p =~ /\.(\d+)/);
  • $dec = length $dec;
  • $decimalplaces = ($dec > 2) ? $dec : 2;
  • $form->{"sellprice_$i"} = $form->round_amount($p / $exchangerate, $decimalplaces);
  • }
  • }
  • }
  • }
  • $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}/100, $decimalplaces);
  • $linetotal = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces);
  • $linetotal = $form->round_amount($linetotal * $form->{"qty_$i"}, 2);
  • if (($rows = $form->numtextrows($form->{"description_$i"}, 46, 6)) > 1) {
  • $form->{"description_$i"} = $form->quote($form->{"description_$i"});
  • $column_data{description} = qq|<td><textarea name="description_$i" rows=$rows cols=46 wrap=soft>$form->{"description_$i"}</textarea></td>|;
  • } else {
  • $form->{"description_$i"} = $form->quote($form->{"description_$i"});
  • $column_data{description} = qq|<td><input name="description_$i" size=48 value="$form->{"description_$i"}"></td>|;
  • }
  • for (qw(partnumber sku unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  • $skunumber = qq|
  • <p><b>$sku</b> $form->{"sku_$i"}| if ($form->{vc} eq 'vendor' && $form->{"sku_$i"});
  • if ($form->{selectpartsgroup}) {
  • if ($i < $numrows) {
  • $partsgroup = qq|
  • <b>$group</b>
  • <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">|;
  • ($form->{"partsgroup_$i"}) = split /--/, $form->{"partsgroup_$i"};
  • $partsgroup .= $form->{"partsgroup_$i"};
  • $partsgroup = "" unless $form->{"partsgroup_$i"};
  • }
  • }
  • $delivery = qq|
  • <td colspan=2 nowrap>
  • <b>${$delvar}</b>
  • <input name="${delvar}_$i" size=11 title="$myconfig{dateformat}" value="$form->{"${delvar}_$i"}"></td>
  • |;
  • $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|;
  • $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]">$skunumber</td>|;
  • $column_data{qty} = qq|<td align=right><input name="qty_$i" title="$form->{"onhand_$i"}" size=5 value=|.$form->format_amount(\%myconfig, $form->{"qty_$i"}).qq|></td>|;
  • $column_data{ship} = qq|<td align=right><input name="ship_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"ship_$i"}).qq|></td>|;
  • $column_data{unit} = qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
  • $column_data{sellprice} = qq|<td align=right><input name="sellprice_$i" size=9 value=|.$form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces).qq|></td>|;
  • $column_data{discount} = qq|<td align=right><input name="discount_$i" size=3 value=|.$form->format_amount(\%myconfig, $form->{"discount_$i"}).qq|></td>|;
  • $column_data{linetotal} = qq|<td align=right>|.$form->format_amount(\%myconfig, $linetotal, 2).qq|</td>|;
  • $column_data{bin} = qq|<td>$form->{"bin_$i"}</td>|;
  • $column_data{onhand} = qq|<td>$form->{"onhand_$i"}</td>|;
  • print qq|
  • <tr valign=top>|;
  • for (@column_index) {
  • print "\n$column_data{$_}";
  • }
  • print qq|
  • </tr>
  • <input type=hidden name="oldqty_$i" value="$form->{"qty_$i"}">
  • |;
  • for (qw(orderitems_id id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id)) {
  • $form->hide_form("${_}_$i");
  • }
  • $form->{selectprojectnumber} =~ s/ selected//;
  • $form->{selectprojectnumber} =~ s/(<option value="\Q$form->{"projectnumber_$i"}\E")/$1 selected/;
  • $project = qq|
  • <b>$projectnumber</b>
  • <select name="projectnumber_$i">$form->{selectprojectnumber}</select>
  • | if $form->{selectprojectnumber};
  • if (($rows = $form->numtextrows($form->{"notes_$i"}, 46, 6)) > 1) {
  • $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
  • $notes = qq|<td><textarea name="notes_$i" rows=$rows cols=46 wrap=soft>$form->{"notes_$i"}</textarea></td>|;
  • } else {
  • $form->{"notes_$i"} = $form->quote($form->{"notes_$i"});
  • $notes = qq|<td><input name="notes_$i" size=48 value="$form->{"notes_$i"}"></td>|;
  • }
  • $serial = qq|
  • <td colspan=6 nowrap><b>$serialnumber</b> <input name="serialnumber_$i" value="$form->{"serialnumber_$i"}"></td>| if $form->{type} !~ /_quotation/;
  • if ($i == $numrows) {
  • $partsgroup = "";
  • if ($form->{selectpartsgroup}) {
  • $partsgroup = qq|
  • <b>$group</b>
  • <select name="partsgroup_$i">$form->{selectpartsgroup}</select>
  • |;
  • }
  • $serial = "";
  • $project = "";
  • $delivery = "";
  • $notes = "";
  • }
  • # print second and third row
  • print qq|
  • <tr valign=top>
  • $delivery
  • $notes
  • $serial
  • </tr>
  • <tr valign=top>
  • <td colspan=$colspan>
  • $project
  • $partsgroup
  • </td>
  • </tr>
  • <tr>
  • <td colspan=$colspan><hr size=1 noshade></td>
  • </tr>
  • |;
  • $skunumber = "";
  • for (split / /, $form->{"taxaccounts_$i"}) {
  • $form->{"${_}_base"} += $linetotal;
  • }
  • $form->{invsubtotal} += $linetotal;
  • }
  • print qq|
  • </table>
  • </td>
  • </tr>
  • |;
  • $form->hide_form(qw(audittrail));
  • print qq|
  • <input type=hidden name=oldcurrency value=$form->{currency}>
  • <input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">
  • <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">
  • |;
  • }
  • sub select_item {
  • if ($form->{vc} eq "vendor") {
  • @column_index = qw(ndx partnumber sku description partsgroup onhand sellprice);
  • } else {
  • @column_index = qw(ndx partnumber description partsgroup onhand sellprice);
  • }
  • $column_data{ndx} = qq|<th>&nbsp;</th>|;
  • $column_data{partnumber} = qq|<th class=listheading>|.$locale->text('Number').qq|</th>|;
  • $column_data{sku} = qq|<th class=listheading>|.$locale->text('SKU').qq|</th>|;
  • $column_data{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
  • $column_data{partsgroup} = qq|<th class=listheading>|.$locale->text('Group').qq|</th>|;
  • $column_data{sellprice} = qq|<th class=listheading>|.$locale->text('Price').qq|</th>|;
  • $column_data{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
  • $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
  • # list items with radio button on a form
  • $form->header;
  • $title = $locale->text('Select items');
  • print qq|
  • <body>
  • <form method=post action="$form->{script}">
  • <table width=100%>
  • <tr>
  • <th class=listtop>$title</th>
  • </tr>
  • <tr height="5"></tr>
  • <tr>
  • <td>$option</td>
  • </tr>
  • <tr>
  • <td>
  • <table width=100%>
  • <tr class=listheading>|;
  • for (@column_index) { print "\n$column_data{$_}" }
  • print qq|
  • </tr>
  • |;
  • my $i = 0;
  • foreach $ref (@{ $form->{item_list} }) {
  • $i++;
  • for (qw(sku partnumber description unit notes partsgroup)) {
  • $ref->{$_} = $form->quote($ref->{$_});
  • }
  • $column_data{ndx} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value=$i></td>|;
  • for (qw(partnumber sku description partsgroup)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
  • $column_data{sellprice} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{sellprice} / $exchangerate, 2, "&nbsp;").qq|</td>|;
  • $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;").qq|</td>|;
  • $j++; $j %= 2;
  • print qq|
  • <tr class=listrow$j>|;
  • for (@column_index) {
  • print "\n$column_data{$_}";
  • }
  • print qq|
  • </tr>
  • |;
  • for (qw(partnumber sku description partsgroup partsgroup_id bin weight sellprice listprice lastcost onhand unit assembly taxaccounts inventory_accno_id income_accno_id expense_accno_id pricematrix id notes)) {
  • print qq|<input type=hidden name="new_${_}_$i" value="$ref->{$_}">\n|;
  • }
  • }
  • print qq|
  • </table>
  • </td>
  • </tr>
  • <tr>
  • <td><hr size=3 noshade></td>
  • </tr>
  • </table>
  • <input name=lastndx type=hidden value=$i>
  • |;
  • # delete variables
  • for (qw(nextsub item_list)) { delete $form->{$_} }
  • $form->{action} = "item_selected";
  • $form->hide_form;
  • print qq|
  • <input type="hidden" name="nextsub" value="item_selected">
  • <br>
  • <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  • </form>
  • </body>
  • </html>
  • |;
  • }
  • sub item_selected {
  • $i = $form->{rowcount} - 1;
  • $i = $form->{assembly_rows} - 1 if ($form->{item} eq 'assembly');
  • $qty = ($form->{"qty_$form->{rowcount}"}) ? $form->{"qty_$form->{rowcount}"} : 1;
  • for $j (1 .. $form->{lastndx}) {
  • if ($form->{"ndx_$j"}) {
  • $i++;
  • $form->{"qty_$i"} = $qty;
  • $form->{"discount_$i"} = $form->{discount} * 100;
  • $form->{"reqdate_$i"} = $form->{reqdate} if $form->{type} !~ /_quotation/;
  • for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
  • $form->{"${_}_$i"} = $form->{"new_${_}_$j"};
  • }
  • $form->{"partsgroup_$i"} = qq|$form->{"new_partsgroup_$j"}--$form->{"new_partsgroup_id_$j"}|;
  • ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
  • $dec = length $dec;
  • $decimalplaces1 = ($dec > 2) ? $dec : 2;
  • ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
  • $dec = length $dec;
  • $decimalplaces2 = ($dec > 2) ? $dec : 2;
  • # if there is an exchange rate adjust sellprice
  • if (($form->{exchangerate} * 1)) {
  • for (qw(sellprice listprice lastcost)) { $form->{"${_}_$i"} /= $form->{exchangerate} }
  • # don't format list and cost
  • $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces1);
  • }
  • # this is for the assembly
  • if ($form->{item} eq 'assembly') {
  • $form->{"adj_$i"} = 1;
  • for (qw(sellprice listprice weight)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  • $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
  • $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
  • }
  • $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
  • for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
  • if (!$form->{taxincluded}) {
  • my @taxlist= Tax::init_taxes($form, $form->{"taxaccounts_$i"});
  • $amount += Tax::calculate_taxes(\@taxlist, $form, $amount, 0);
  • }
  • $form->{creditremaining} -= $amount;
  • $form->{"runningnumber_$i"} = $i;
  • # format amounts
  • if ($form->{item} ne 'assembly') {
  • for (qw(sellprice listprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces1) }
  • $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces2);
  • }
  • $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
  • }
  • }
  • $form->{rowcount} = $i;
  • $form->{assembly_rows} = $i if ($form->{item} eq 'assembly');
  • $form->{focus} = "description_$i";
  • # delete all the new_ variables
  • for $i (1 .. $form->{lastndx}) {
  • for (qw(id partnumber sku description sellprice listprice lastcost bin unit weight assembly taxaccounts pricematrix onhand notes inventory_accno_id income_accno_id expense_accno_id)) {
  • delete $form->{"new_${_}_$i"};
  • }
  • }
  • for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  • &display_form;
  • }
  • sub new_item {
  • if ($form->{language_code} && $form->{"description_$form->{rowcount}"}) {
  • $form->error($locale->text('Translation not on file!'));
  • }
  • # change callback
  • $form->{old_callback} = $form->escape($form->{callback},1);
  • $form->{callback} = $form->escape("$form->{script}?action=display_form",1);
  • # delete action
  • delete $form->{action};
  • # save all other form variables in a previousform variable
  • if (!$form->{previousform}) {
  • foreach $key (keys %$form) {
  • # escape ampersands
  • $form->{$key} =~ s/&/%26/g;
  • $form->{previousform} .= qq|$key=$form->{$key}&|;
  • }
  • chop $form->{previousform};
  • $form->{previousform} = $form->escape($form->{previousform}, 1);
  • }
  • $i = $form->{rowcount};
  • for (qw(partnumber description)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  • $form->header;
  • print qq|
  • <body>
  • <h4 class=error>|.$locale->text('Item not on file!').qq|</h4>|;
  • if ($myconfig{acs} !~ /(Goods \& Services--Add Part|Goods \& Services--Add Service)/) {
  • print qq|
  • <h4>|.$locale->text('What type of item is this?').qq|</h4>
  • <form method=post action=ic.pl>
  • <p>
  • <input class=radio type=radio name=item value=part checked>&nbsp;|.$locale->text('Part')
  • .qq|<br>
  • <input class=radio type=radio name=item value=service>&nbsp;|.$locale->text('Service')
  • .qq|
  • <input type=hidden name=partnumber value="$form->{"partnumber_$i"}">
  • <input type=hidden name=description value="$form->{"description_$i"}">
  • <input type=hidden name=nextsub value=add>
  • <input type=hidden name=action value=add>
  • |;
  • $form->hide_form(qw(previousform rowcount path login sessionid));
  • print qq|
  • <p>
  • <button class="submit" type="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  • </form>
  • |;
  • }
  • print qq|
  • </body>
  • </html>
  • |;
  • }
  • sub display_form {
  • # if we have a display_form
  • if ($form->{display_form}) {
  • &{ "$form->{display_form}" };
  • exit;
  • }
  • &form_header;
  • $numrows = ++$form->{rowcount};
  • $subroutine = "display_row";
  • if ($form->{item} eq 'part') {
  • # create makemodel rows
  • &makemodel_row(++$form->{makemodel_rows});
  • &vendor_row(++$form->{vendor_rows});
  • $numrows = ++$form->{customer_rows};
  • $subroutine = "customer_row";
  • }
  • if ($form->{item} eq 'assembly') {
  • # create makemodel rows
  • &makemodel_row(++$form->{makemodel_rows});
  • $numrows = ++$form->{customer_rows};
  • $subroutine = "customer_row";
  • }
  • if ($form->{item} eq 'service') {
  • &vendor_row(++$form->{vendor_rows});
  • $numrows = ++$form->{customer_rows};
  • $subroutine = "customer_row";
  • }
  • if ($form->{item} eq 'labor') {
  • $numrows = 0;
  • }
  • # create rows
  • &{ $subroutine }($numrows) if $numrows;
  • &form_footer;
  • }
  • sub check_form {
  • my @a = ();
  • my $count = 0;
  • my $i;
  • my $j;
  • my @flds = qw(id runningnumber partnumber description partsgroup qty ship unit sellprice discount oldqty orderitems_id bin weight listprice lastcost taxaccounts pricematrix sku onhand assembly inventory_accno_id income_accno_id expense_accno_id notes reqdate deliverydate serialnumber projectnumber);
  • # remove any makes or model rows
  • if ($form->{item} eq 'part') {
  • for (qw(listprice sellprice lastcost avgcost weight rop markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  • &calc_markup;
  • @flds = qw(make model);
  • $count = 0;
  • @a = ();
  • for $i (1 .. $form->{makemodel_rows}) {
  • if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
  • push @a, {};
  • $j = $#a;
  • for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  • $count++;
  • }
  • }
  • $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
  • $form->{makemodel_rows} = $count;
  • &check_vendor;
  • &check_customer;
  • }
  • if ($form->{item} eq 'service') {
  • for (qw(sellprice listprice lastcost avgcost markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  • &calc_markup;
  • &check_vendor;
  • &check_customer;
  • }
  • if ($form->{item} eq 'assembly') {
  • if (!$form->{project_id}) {
  • $form->{sellprice} = 0;
  • $form->{listprice} = 0;
  • $form->{lastcost} = 0;
  • $form->{weight} = 0;
  • }
  • for (qw(rop stock markup)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  • @flds = qw(id qty unit bom adj partnumber description sellprice listprice lastcost weight assembly runningnumber partsgroup);
  • $count = 0;
  • @a = ();
  • for $i (1 .. ($form->{assembly_rows} - 1)) {
  • if ($form->{"qty_$i"}) {
  • push @a, {};
  • my $j = $#a;
  • $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
  • for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  • if (! $form->{project_id}) {
  • for (qw(sellprice listprice weight lastcost)) { $form->{$_} += ($form->{"${_}_$i"} * $form->{"qty_$i"}) }
  • }
  • $count++;
  • }
  • }
  • if ($form->{markup} && $form->{markup} != $form->{oldmarkup}) {
  • $form->{sellprice} = 0;
  • &calc_markup;
  • }
  • for (qw(sellprice lastcost listprice)) { $form->{$_} = $form->round_amount($form->{$_}, 2) }
  • $form->redo_rows(\@flds, \@a, $count, $form->{assembly_rows});
  • $form->{assembly_rows} = $count;
  • $count = 0;
  • @flds = qw(make model);
  • @a = ();
  • for $i (1 .. ($form->{makemodel_rows})) {
  • if (($form->{"make_$i"} ne "") || ($form->{"model_$i"} ne "")) {
  • push @a, {};
  • my $j = $#a;
  • for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  • $count++;
  • }
  • }
  • $form->redo_rows(\@flds, \@a, $count, $form->{makemodel_rows});
  • $form->{makemodel_rows} = $count;
  • &check_customer;
  • }
  • if ($form->{type}) {
  • # this section applies to invoices and orders
  • # remove any empty numbers
  • $count = 0;
  • @a = ();
  • if ($form->{rowcount}) {
  • for $i (1 .. $form->{rowcount} - 1) {
  • if ($form->{"partnumber_$i"}) {
  • push @a, {};
  • my $j = $#a;
  • for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  • $count++;
  • }
  • }
  • $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
  • $form->{rowcount} = $count;
  • $form->{creditremaining} -= &invoicetotal;
  • }
  • }
  • &display_form;
  • }
  • sub calc_markup {
  • if ($form->{markup}) {
  • if ($form->{markup} != $form->{oldmarkup}) {
  • if ($form->{lastcost}) {
  • $form->{sellprice} = $form->{lastcost} * (1 + $form->{markup}/100);
  • $form->{sellprice} = $form->round_amount($form->{sellprice}, 2);
  • } else {
  • $form->{lastcost} = $form->{sellprice} / (1 + $form->{markup}/100);
  • $form->{lastcost} = $form->round_amount($form->{lastcost}, 2);
  • }
  • }
  • } else {
  • if ($form->{lastcost}) {
  • $form->{markup} = $form->round_amount(((1 - $form->{sellprice} / $form->{lastcost}) * 100), 1);
  • }
  • $form->{markup} = "" if $form->{markup} == 0;
  • }
  • }
  • sub invoicetotal {
  • $form->{oldinvtotal} = 0;
  • # add all parts and deduct paid
  • for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 }
  • my ($amount, $sellprice, $discount, $qty);
  • for $i (1 .. $form->{rowcount}) {
  • $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
  • $discount = $form->parse_amount(\%myconfig, $form->{"discount_$i"});
  • $qty = $form->parse_amount(\%myconfig, $form->{"qty_$i"});
  • $amount = $sellprice * (1 - $discount / 100) * $qty;
  • for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount }
  • $form->{oldinvtotal} += $amount;
  • }
  • if (!$form->{taxincluded}) {
  • my @taxlist= Tax::init_taxes($form, $form->{taxaccounts});
  • $form->{oldinvtotal} += Tax::calculate_taxes(\@taxlist, $form,
  • $amount, 0);
  • }
  • $form->{oldtotalpaid} = 0;
  • for $i (1 .. $form->{paidaccounts}) {
  • $form->{oldtotalpaid} += $form->{"paid_$i"};
  • }
  • # return total
  • ($form->{oldinvtotal} - $form->{oldtotalpaid});
  • }
  • sub validate_items {
  • # check if items are valid
  • if ($form->{rowcount} == 1) {
  • &update;
  • exit;
  • }
  • for $i (1 .. $form->{rowcount} - 1) {
  • $form->isblank("partnumber_$i", $locale->text('Number missing in Row') . " $i");
  • }
  • }
  • sub purchase_order {
  • $form->{title} = $locale->text('Add Purchase Order');
  • $form->{vc} = 'vendor';
  • $form->{type} = 'purchase_order';
  • $buysell = 'sell';
  • &create_form;
  • }
  • sub sales_order {
  • $form->{title} = $locale->text('Add Sales Order');
  • $form->{vc} = 'customer';
  • $form->{type} = 'sales_order';
  • $buysell = 'buy';
  • &create_form;
  • }
  • sub rfq {
  • $form->{title} = $locale->text('Add Request for Quotation');
  • $form->{vc} = 'vendor';
  • $form->{type} = 'request_quotation';
  • $buysell = 'sell';
  • &create_form;
  • }
  • sub quotation {
  • $form->{title} = $locale->text('Add Quotation');
  • $form->{vc} = 'customer';
  • $form->{type} = 'sales_quotation';
  • $buysell = 'buy';
  • &create_form;
  • }
  • sub create_form {