+ <td><hr size=3 noshade></td>
+ </tr>
+</table>
+|;
+
+}
+
+
+
+sub form_footer {
+
+ $i = 1;
+ if ($form->{db} eq 'customer') {
+ if ($myconfig{acs} !~ /AR--AR/) {
+ $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |;
+ $button{'AR--Add Transaction'}{order} = $i++;
+ $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|"> |;
+ $button{'AR--Sales Invoice'}{order} = $i++;
+ }
+ if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
+ $button{'Order Entry--Sales Order'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Order').qq|"> |;
+ $button{'Order Entry--Sales Order'}{order} = $i++;
+ }
+ if ($myconfig{acs} !~ /Quotations--Quotations/) {
+ $button{'Quotations--Quotation'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Quotation').qq|"> |;
+ $button{'Quotations--Quotation'}{order} = $i++;
+ }
+ }
+ if ($form->{db} eq 'vendor') {
+ if ($myconfig{acs} !~ /AP--AP/) {
+ $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |;
+ $button{'AP--Add Transaction'}{order} = $i++;
+ $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|"> |;
+ $button{'AP--Vendor Invoice'}{order} = $i++;
+ }
+ if ($myconfig{acs} !~ /Order Entry--Order Entry/) {
+ $button{'Order Entry--Purchase Order'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Purchase Order').qq|"> |;
+ $button{'Order Entry--Purchase Order'}{order} = $i++;
+ }
+ if ($myconfig{acs} !~ /Quotations--Quotations/) {
+ $button{'Quotations--RFQ'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('RFQ').qq|"> |;
+ $button{'Quotations--RFQ'}{order} = $i++;
+ }
+ }
+ if ($myconfig{acs} !~ /Goods & Services--Goods & Services/) {
+ $myconfig{acs} =~ s/(Goods & Services--Add )(Service|Assembly).*;/$1--Add Part/g;
+ $button{'Goods & Services--Add Part'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Pricelist').qq|"> |;
+ $button{'Goods & Services--Add Part'}{order} = $i++;
+ }
+
+ foreach $item (split /;/, $myconfig{acs}) {
+ delete $button{$item};
+ }
+
+ print qq|
+<input name=id type=hidden value=$form->{id}>
+<input name=taxaccounts type=hidden value="$form->{taxaccounts}">
+
+<input type=hidden name=path value=$form->{path}>
+<input type=hidden name=login value=$form->{login}>
+<input type=hidden name=sessionid value=$form->{sessionid}>
+
+<input type=hidden name=callback value="$form->{callback}">
+<input type=hidden name=db value=$form->{db}>
+
+<br>
+|;
+
+ if ($form->{db} eq 'customer') {
+ $item = 'AR--Customers--Add Customer';
+ }
+ if ($form->{db} eq 'vendor') {
+ $item = 'AP--Vendors--Add Vendor';
+ }
+
+ if ($myconfig{acs} !~ /$item/) {
+ print qq|
+<input class=submit type=submit name=action value="|.$locale->text("Save").qq|">
+|;
+ if ($form->{id} && $form->{status} eq 'orphaned') {
+ print qq|<input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">\n|;
+ }
+ }
+
+ foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
+ print $item->{code};
+ }
+
+ if ($form->{menubar}) {
+ require "$form->{path}/menu.pl";
+ &menubar;
+ }
+
+ print qq|
+
+ </form>
+
+</body>
+</html>
+|;
+
+}
+
+
+sub pricelist {
+
+ $form->isblank("name", $locale->text('Name missing!'));
+
+ CT->pricelist(\%myconfig, \%$form);
+
+ foreach $ref (@{ $form->{"all_partspricelist"} }) {
+ $i++;
+ map { $form->{"${_}_$i"} = $ref->{$_} } keys %$ref;
+ }
+ $form->{rowcount} = $i;
+
+ # currencies
+ @curr = split /:/, $form->{currencies};
+ map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
+
+ if (@ { $form->{all_partsgroup} }) {
+ $form->{selectpartsgroup} = "<option>\n";
+ foreach $ref (@ { $form->{all_partsgroup} }) {
+ $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
+ }
+ }
+
+ map { delete $form->{$_} } ("currencies", "all_partsgroup", "all_partspricelist");
+
+ foreach $i (1 .. $form->{rowcount}) {
+
+ if ($form->{db} eq 'customer') {
+
+ $form->{"pricebreak_$i"} = $form->format_amount(\%myconfig, $form->{"pricebreak_$i"});
+
+ ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces = ($dec > 2) ? $dec : 2;
+
+ $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
+
+ }
+
+ if ($form->{db} eq 'vendor') {
+
+ $form->{"leadtime_$i"} = $form->format_amount(\%myconfig, $form->{"leadtime_$i"});
+ ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces = ($dec > 2) ? $dec : 2;
+
+ $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
+
+ }
+ }
+
+ $form->{rowcount}++;
+ &{ "$form->{db}_pricelist" };
+
+}
+
+
+sub customer_pricelist {
+
+ @flds = qw(runningnumber id partnumber description sellprice unit partsgroup pricebreak curr validfrom validto);
+
+ $form->{rowcount}--;
+
+ # remove empty rows
+ if ($form->{rowcount}) {
+
+ foreach $i (1 .. $form->{rowcount}) {
+
+ map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(pricebreak sellprice);
+
+ ($a, $b) = split /\./, $form->{"pricebreak_$i"};
+ $a = length $a;
+ $b = length $b;
+ $whole = ($whole > $a) ? $whole : $a;
+ $dec = ($dec > $b) ? $dec : $b;
+ }
+ $pad1 = '0' x $whole;
+ $pad2 = '0' x $dec;
+
+ foreach $i (1 .. $form->{rowcount}) {
+ ($a, $b) = split /\./, $form->{"pricebreak_$i"};
+
+ $a = substr("$pad1$a", -$whole);
+ $b = substr("$b$pad2", 0, $dec);
+ $ndx{qq|$form->{"partnumber_$i"}_$form->{"id_$i"}_$a$b|} = $i;
+ }
+
+ $i = 1;
+ map { $form->{"runningnumber_$ndx{$_}"} = $i++ } sort keys %ndx;
+
+ foreach $i (1 .. $form->{rowcount}) {
+ if ($form->{"partnumber_$i"} && $form->{"sellprice_$i"}) {
+ if ($form->{"id_$i"} eq $sameid) {
+ $j = $i + 1;
+ next if ($form->{"id_$j"} eq $sameid && !$form->{"pricebreak_$i"});
+ }
+
+ push @a, {};
+ $j = $#a;
+
+ map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
+ $count++;
+ }
+ $sameid = $form->{"id_$i"};
+ }
+
+ $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
+ $form->{rowcount} = $count;
+
+ }
+
+ $form->{rowcount}++;
+
+ &pricelist_header;
+ $form->hide_form();
+ &pricelist_footer;
+
+}
+
+
+sub vendor_pricelist {
+
+ @flds = qw(runningnumber id sku partnumber description lastcost unit partsgroup curr leadtime);
+
+ $form->{rowcount}--;
+
+ # remove empty rows
+ if ($form->{rowcount}) {
+
+ foreach $i (1 .. $form->{rowcount}) {
+
+ map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(leadtime lastcost);
+ $var = ($form->{"partnumber_$i"}) ? $form->{"sku_$i"} : qq|_$form->{"sku_$i"}|;
+ $ndx{$var} = $i;
+
+ }
+
+ $i = 1;
+ map { $form->{"runningnumber_$ndx{$_}"} = $i++ } sort keys %ndx;
+
+ foreach $i (1 .. $form->{rowcount}) {
+ if ($form->{"sku_$i"}) {
+ push @a, {};
+ $j = $#a;
+
+ map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
+ $count++;
+ }
+ }
+
+ $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
+ $form->{rowcount} = $count;
+
+ }
+
+ $form->{rowcount}++;
+
+ &pricelist_header;
+ $form->hide_form();
+ &pricelist_footer;
+
+}
+
+
+
+sub pricelist_header {
+
+ $form->{title} = $form->{name};
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action="$form->{script}">
+
+<table width=100%>
+ <tr>
+ <th class=listtop>$form->{title}</th>
+ </tr>
+ <tr height="5"></tr>
+|;
+
+ if ($form->{db} eq 'customer') {
+ @column_index = qw(partnumber description);
+ push @column_index, "partsgroup" if $form->{selectpartsgroup};
+ push @column_index, qw(pricebreak sellprice curr validfrom validto);
+
+ $column_header{pricebreak} = qq|<th class=listheading nowrap>|.$locale->text('Break').qq|</th>|;
+ $column_header{sellprice} = qq|<th class=listheading nowrap>|.$locale->text('Sell Price').qq|</th>|;
+ $column_header{validfrom} = qq|<th class=listheading nowrap>|.$locale->text('From').qq|</th>|;
+ $column_header{validto} = qq|<th class=listheading nowrap>|.$locale->text('To').qq|</th>|;
+ }
+
+ if ($form->{db} eq 'vendor') {
+ @column_index = qw(sku partnumber description);
+ push @column_index, "partsgroup" if $form->{selectpartsgroup};
+ push @column_index, qw(lastcost curr leadtime);
+
+
+ $column_header{sku} = qq|<th class=listheading nowrap>|.$locale->text('SKU').qq|</th>|;
+ $column_header{leadtime} = qq|<th class=listheading nowrap>|.$locale->text('Leadtime').qq|</th>|;
+ $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Cost').qq|</th>|;
+ }
+
+ $column_header{partnumber} = qq|<th class=listheading nowrap>|.$locale->text('Number').qq|</th>|;
+ $column_header{description} = qq|<th class=listheading nowrap width=80%>|.$locale->text('Description').qq|</th>|;
+ $column_header{partsgroup} = qq|<th class=listheading nowrap>|.$locale->text('Group').qq|</th>|;
+ $column_header{curr} = qq|<th class=listheading nowrap>|.$locale->text('Curr').qq|</th>|;
+
+ print qq|
+ <tr>