1548 |
1548 |
sub assembly_row {
|
1549 |
1549 |
$lxdebug->enter_sub();
|
1550 |
1550 |
my ($numrows) = @_;
|
1551 |
|
my (@column_index, %column_data, %column_header);
|
1552 |
|
my ($nochange, $callback, $previousform, $linetotal, $href);
|
|
1551 |
my (@column_index);
|
|
1552 |
my ($nochange, $callback, $previousform, $linetotal, $line_purchase_price, $href);
|
1553 |
1553 |
|
1554 |
1554 |
our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
|
1555 |
1555 |
|
1556 |
|
@column_index =
|
1557 |
|
qw(runningnumber qty unit bom partnumber description partsgroup lastcost total);
|
|
1556 |
@column_index = qw(runningnumber qty unit bom partnumber description partsgroup lastcost total);
|
1558 |
1557 |
|
1559 |
1558 |
if ($form->{previousform}) {
|
1560 |
1559 |
$nochange = 1;
|
... | ... | |
1569 |
1568 |
# delete action
|
1570 |
1569 |
map { delete $form->{$_} } qw(action header);
|
1571 |
1570 |
|
1572 |
|
$previousform = "";
|
1573 |
|
|
1574 |
1571 |
# save form variables in a previousform variable
|
1575 |
|
foreach my $key (sort keys %$form) {
|
1576 |
|
next unless ref $form->{$key} eq '' && $form->{$key};
|
1577 |
|
next if $key =~ /^select/; # get rid of these stupid select things
|
1578 |
|
|
1579 |
|
# escape ampersands
|
1580 |
|
$form->{$key} =~ s/&/%26/g;
|
1581 |
|
if (any { $key eq $_ } qw(sellprice listprice lastcost)) {
|
1582 |
|
$previousform .= sprintf qq|%s=%s&|, $key, $form->format_amount(\%myconfig, $form->{$key});
|
1583 |
|
} else {
|
1584 |
|
$previousform .= qq|$key=$form->{$key}&|;
|
1585 |
|
}
|
1586 |
|
}
|
1587 |
|
chop $previousform;
|
1588 |
|
$previousform = $form->escape($form->escape($previousform, 1));
|
1589 |
|
$form->{callback} = $callback;
|
|
1572 |
$previousform = $form->escape($form->escape(join '&', map {
|
|
1573 |
sprintf "%s=%s", Q($_), /^listprice|lastcost|sellprice$/ ? $form->format_amount(\%myconfig, $form->{$key}) : $form->{$key}
|
|
1574 |
} grep { ref $form->{$_} eq '' && $form->{$_} } grep { !/^select/ } sort keys %$form ));
|
1590 |
1575 |
|
|
1576 |
$form->{callback} = $callback;
|
1591 |
1577 |
$form->{assemblytotal} = 0;
|
1592 |
1578 |
$form->{assembly_purchase_price_total} = 0;
|
1593 |
1579 |
$form->{weight} = 0;
|
1594 |
|
|
1595 |
1580 |
}
|
1596 |
|
$column_header{runningnumber} =
|
1597 |
|
qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
|
1598 |
|
$column_header{qty} =
|
1599 |
|
qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
|
1600 |
|
$column_header{unit} =
|
1601 |
|
qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
|
1602 |
|
$column_header{partnumber} =
|
1603 |
|
qq|<th align=left nowrap width=20%>|
|
1604 |
|
. $locale->text('Part Number')
|
1605 |
|
. qq|</th>|;
|
1606 |
|
$column_header{description} =
|
1607 |
|
qq|<th nowrap width=50% align="left">| . $locale->text('Part Description') . qq|</th>|;
|
1608 |
|
$column_header{lastcost} =
|
1609 |
|
qq|<th nowrap width=50%>| . $locale->text('Purchase Prices') . qq|</th>|;
|
1610 |
|
$column_header{total} =
|
1611 |
|
qq|<th align=right nowrap>| . $locale->text('Sale Prices') . qq|</th>|;
|
1612 |
|
$column_header{bom} = qq|<th>| . $locale->text('BOM') . qq|</th>|;
|
1613 |
|
$column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
|
1614 |
1581 |
|
1615 |
|
print qq|
|
1616 |
|
<tr class=listheading>
|
1617 |
|
<th class=listheading>| . $locale->text('Individual Items') . qq|</th>
|
1618 |
|
</tr>
|
1619 |
|
<tr>
|
1620 |
|
<td>
|
1621 |
|
<table width=100%>
|
1622 |
|
<tr>
|
1623 |
|
|;
|
1624 |
|
|
1625 |
|
map { print "\n$column_header{$_}" } @column_index;
|
|
1582 |
my %header = (
|
|
1583 |
runningnumber => { text => $locale->text('No.'), nowrap => 1, width => '5%' },
|
|
1584 |
qty => { text => $locale->text('Qty'), nowrap => 1, width => '10%' },
|
|
1585 |
unit => { text => $locale->text('Unit'), nowrap => 1, width => '5%' },
|
|
1586 |
partnumber => { text => $locale->text('Part Number'), nowrap => 1, width => '20%' },
|
|
1587 |
description => { text => $locale->text('Part Description'), nowrap => 1, width => '50%' },
|
|
1588 |
lastcost => { text => $locale->text('Purchase Prices'), nowrap => 1, width => '50%' },
|
|
1589 |
total => { text => $locale->text('Sale Prices'), nowrap => 1, },
|
|
1590 |
bom => { text => $locale->text('BOM'), },
|
|
1591 |
partsgroup => { text => $locale->text('Group'), },
|
|
1592 |
);
|
1626 |
1593 |
|
1627 |
|
print qq|
|
1628 |
|
</tr>
|
1629 |
|
|;
|
|
1594 |
my @ROWS;
|
1630 |
1595 |
|
1631 |
1596 |
for my $i (1 .. $numrows) {
|
|
1597 |
my (%row, @row_hiddens);
|
|
1598 |
|
1632 |
1599 |
$form->{"partnumber_$i"} =~ s/\"/"/g;
|
1633 |
1600 |
|
1634 |
|
$linetotal =
|
1635 |
|
$form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} / ($form->{"price_factor_$i"} || 1), 4);
|
1636 |
|
$line_purchase_price =
|
1637 |
|
$form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"} / ($form->{"price_factor_$i"} || 1), 4); #lastcost == purchase_price | ungenaue datenbankfeld-uebersetzung
|
1638 |
|
$form->{assemblytotal} += $linetotal;
|
|
1601 |
$linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} / ($form->{"price_factor_$i"} || 1), 4);
|
|
1602 |
$line_purchase_price = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"} / ($form->{"price_factor_$i"} || 1), 4);
|
|
1603 |
$form->{assemblytotal} += $linetotal;
|
1639 |
1604 |
$form->{assembly_purchase_price_total} += $line_purchase_price;
|
1640 |
|
|
1641 |
|
$form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
|
1642 |
|
|
1643 |
|
$linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
|
|
1605 |
$form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
|
|
1606 |
$linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
|
1644 |
1607 |
$line_purchase_price = $form->format_amount(\%myconfig, $line_purchase_price, 2);
|
|
1608 |
$href = qq|$form->{script}?action=edit&id=$form->{"id_$i"}&rowcount=$i&previousform=$previousform|;
|
|
1609 |
map { $row{$_}{data} = "" } qw(qty unit partnumber description bom partsgroup runningnumber);
|
1645 |
1610 |
|
|
1611 |
# last row
|
1646 |
1612 |
if (($i >= 1) && ($i == $numrows)) {
|
1647 |
|
|
1648 |
|
if ($nochange) {
|
1649 |
|
map { $column_data{$_} = qq|<td></td>| }
|
1650 |
|
qw(qty unit partnumber description bom partsgroup);
|
1651 |
|
} else {
|
1652 |
|
|
1653 |
|
map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
|
1654 |
|
|
1655 |
|
$column_data{qty} =
|
1656 |
|
qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
|
1657 |
|
$column_data{partnumber} =
|
1658 |
|
qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
|
1659 |
|
$column_data{description} =
|
1660 |
|
qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
|
1661 |
|
$column_data{partsgroup} =
|
1662 |
|
qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
|
1663 |
|
|
|
1613 |
if (!$form->{previousform}) {
|
|
1614 |
$row{partnumber}{data} = qq|<input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}">|;
|
|
1615 |
$row{qty}{data} = qq|<input name="qty_$i" size=5 value="$form->{"qty_$i"}">|;
|
|
1616 |
$row{description}{data} = qq|<input name="description_$i" size=40 value="$form->{"description_$i"}">|;
|
|
1617 |
$row{partsgroup}{data} = qq|<input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}">|;
|
1664 |
1618 |
}
|
1665 |
|
|
|
1619 |
# other rows
|
1666 |
1620 |
} else {
|
1667 |
|
|
1668 |
1621 |
if ($form->{previousform}) {
|
1669 |
|
$column_data{partnumber} =
|
1670 |
|
qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
|
1671 |
|
$column_data{qty} =
|
1672 |
|
qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
|
1673 |
|
|
1674 |
|
$column_data{bom} =
|
1675 |
|
qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
|
1676 |
|
$column_data{bom} .= ($form->{"bom_$i"}) ? "x" : " ";
|
1677 |
|
$column_data{bom} .= qq|</td>|;
|
1678 |
|
|
1679 |
|
$column_data{partsgroup} =
|
1680 |
|
qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
|
1681 |
|
|
|
1622 |
push @row_hiddens, qw(qty bom);
|
|
1623 |
$row{partnumber}{data} = $form->{"partnumber_$i"};
|
|
1624 |
$row{qty}{data} = $form->{"qty_$i"};
|
|
1625 |
$row{bom}{data} = $form->{"bom_$i"} ? "x" : " ";
|
|
1626 |
$row{qty}{align} = 'right';
|
1682 |
1627 |
} else {
|
1683 |
|
$href =
|
1684 |
|
qq|$form->{script}?action=edit&id=$form->{"id_$i"}&rowcount=$i&previousform=$previousform|;
|
1685 |
|
$column_data{partnumber} =
|
1686 |
|
qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
|
1687 |
|
$column_data{runningnumber} =
|
1688 |
|
qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
|
1689 |
|
$column_data{qty} =
|
1690 |
|
qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
|
1691 |
|
|
1692 |
|
$form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
|
1693 |
|
$column_data{bom} =
|
1694 |
|
qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
|
1695 |
|
|
1696 |
|
$column_data{partsgroup} =
|
1697 |
|
qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
|
|
1628 |
$row{partnumber}{data} = qq|<a href=$href>$form->{"partnumber_$i"}</a>|;
|
|
1629 |
$row{qty}{data} = qq|<input name="qty_$i" size=5 value="$form->{"qty_$i"}">|;
|
|
1630 |
$row{runningnumber}{data} = qq|<input name="runningnumber_$i" size=3 value="$i">|;
|
|
1631 |
$row{bom}{data} = sprintf qq|<input name="bom_$i" type=checkbox class=checkbox value=1 %s>|,
|
|
1632 |
$form->{"bom_$i"} ? 'checked' : '';
|
1698 |
1633 |
}
|
1699 |
|
|
1700 |
|
$column_data{unit} =
|
1701 |
|
qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
|
1702 |
|
$column_data{description} =
|
1703 |
|
qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
|
|
1634 |
push @row_hiddens, qw(unit description partnumber partsgroup);
|
|
1635 |
$row{unit}{data} = $form->{"unit_$i"};
|
|
1636 |
$row{description}{data} = $form->{"description_$i"};
|
|
1637 |
$row{partsgroup}{data} = $form->{"partsgroup_$i"};
|
|
1638 |
$row{bom}{align} = 'center';
|
1704 |
1639 |
}
|
1705 |
1640 |
|
1706 |
|
$column_data{lastcost} = qq|<td align=right>$line_purchase_price</td>|;
|
1707 |
|
$column_data{total} = qq|<td align=right>$linetotal</td>|;
|
1708 |
|
|
1709 |
|
$column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
|
|
1641 |
$row{lastcost}{data} = $line_purchase_price;
|
|
1642 |
$row{total}{data} = $linetotal;
|
|
1643 |
$row{deliverydate}{data} = $deliverydate;
|
|
1644 |
$row{lastcost}{align} = 'right';
|
|
1645 |
$row{total}{align} = 'right';
|
|
1646 |
$row{deliverydate}{align} = 'right';
|
1710 |
1647 |
|
1711 |
|
print qq|
|
1712 |
|
<tr>|;
|
1713 |
|
|
1714 |
|
map { print "\n$column_data{$_}" } @column_index;
|
|
1648 |
push @row_hiddens, qw(id sellprice lastcost weight price_factor_id price_factor);
|
|
1649 |
$row{hiddens} = [ map +{ name => "${_}_$i", value => $form->{"${_}_$i"} }, @row_hiddens ];
|
1715 |
1650 |
|
1716 |
|
print qq|
|
1717 |
|
</tr>
|
1718 |
|
<input type=hidden name="id_$i" value=$form->{"id_$i"}>
|
1719 |
|
<input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
|
1720 |
|
<input type=hidden name="lastcost_$i" value=$form->{"lastcost_$i"}>
|
1721 |
|
<input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
|
1722 |
|
<input type=hidden name="price_factor_id_$i" value=$form->{"price_factor_id_$i"}>
|
1723 |
|
<input type=hidden name="price_factor_$i" value=$form->{"price_factor_$i"}>
|
1724 |
|
|;
|
|
1651 |
push @ROWS, \%row;
|
1725 |
1652 |
}
|
1726 |
1653 |
|
1727 |
|
print qq|
|
1728 |
|
<tr>
|
1729 |
|
<td colspan="6"></td>
|
1730 |
|
<td>| . $locale->text('Totals') . qq|</td>
|
1731 |
|
<td align="right">| . $form->format_amount(\%myconfig, $form->{assembly_purchase_price_total}, 2) .
|
1732 |
|
qq|</td>
|
1733 |
|
<td align="right">| . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) .
|
1734 |
|
qq| </td>
|
1735 |
|
</tr>
|
1736 |
|
<input type="hidden" name="assembly_rows" value="| . $form->{assembly_rows} .
|
1737 |
|
qq|">
|
1738 |
|
</table>
|
1739 |
|
</td>
|
1740 |
|
</tr>
|
1741 |
|
|;
|
|
1654 |
print $form->parse_html_template('ic/assembly_row', { COLUMNS => \@column_index, ROWS => \@ROWS, HEADER => \%header });
|
1742 |
1655 |
|
1743 |
1656 |
$lxdebug->leave_sub();
|
1744 |
1657 |
}
|
Assembly Rows in templates ausgelagert.