34 |
34 |
|
35 |
35 |
package IS;
|
36 |
36 |
|
|
37 |
use strict;
|
|
38 |
|
37 |
39 |
use List::Util qw(max);
|
38 |
40 |
|
39 |
41 |
use SL::AM;
|
... | ... | |
74 |
76 |
}
|
75 |
77 |
|
76 |
78 |
# sort items by partsgroup
|
77 |
|
for $i (1 .. $form->{rowcount}) {
|
78 |
|
$partsgroup = "";
|
79 |
|
if ($form->{"partsgroup_$i"} && $form->{groupitems}) {
|
80 |
|
$partsgroup = $form->{"partsgroup_$i"};
|
81 |
|
}
|
82 |
|
push @partsgroup, [$i, $partsgroup];
|
|
79 |
for my $i (1 .. $form->{rowcount}) {
|
|
80 |
# $partsgroup = "";
|
|
81 |
# if ($form->{"partsgroup_$i"} && $form->{groupitems}) {
|
|
82 |
# $partsgroup = $form->{"partsgroup_$i"};
|
|
83 |
# }
|
|
84 |
# push @partsgroup, [$i, $partsgroup];
|
83 |
85 |
push(@project_ids, $form->{"project_id_$i"}) if ($form->{"project_id_$i"});
|
84 |
86 |
}
|
85 |
87 |
|
... | ... | |
198 |
200 |
if ($form->{lizenzen}) {
|
199 |
201 |
if ($form->{"licensenumber_$i"}) {
|
200 |
202 |
$query = qq|SELECT licensenumber, validuntil FROM license WHERE id = ?|;
|
201 |
|
($licensenumber, $validuntil) = selectrow_query($form, $dbh, $query, conv_i($form->{"licensenumber_$i"}));
|
|
203 |
my ($licensenumber, $validuntil) = selectrow_query($form, $dbh, $query, conv_i($form->{"licensenumber_$i"}));
|
202 |
204 |
push(@{ $form->{licensenumber} }, $licensenumber);
|
203 |
205 |
push(@{ $form->{validuntil} }, $locale->date($myconfig, $validuntil, 0));
|
204 |
206 |
|
... | ... | |
300 |
302 |
$taxbase{$accno} += $taxbase;
|
301 |
303 |
}
|
302 |
304 |
}
|
303 |
|
$tax_rate = $taxrate * 100;
|
|
305 |
my $tax_rate = $taxrate * 100;
|
304 |
306 |
push(@{ $form->{tax_rate} }, qq|$tax_rate|);
|
305 |
307 |
if ($form->{"assembly_$i"}) {
|
306 |
308 |
$sameitem = "";
|
... | ... | |
322 |
324 |
WHERE (a.bom = '1') AND (a.id = ?) $sortorder|;
|
323 |
325 |
$sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{"id_$i"}));
|
324 |
326 |
|
325 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
|
327 |
while (my $ref = $sth->fetchrow_hashref('NAME_lc')) {
|
326 |
328 |
if ($form->{groupitems} && $ref->{partsgroup} ne $sameitem) {
|
327 |
329 |
map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays));
|
328 |
330 |
$sameitem = ($ref->{partsgroup}) ? $ref->{partsgroup} : "--";
|
... | ... | |
398 |
400 |
$main::lxdebug->enter_sub();
|
399 |
401 |
|
400 |
402 |
my ($self, $dbh, $id) = @_;
|
|
403 |
my $form = \%main::form;
|
401 |
404 |
|
402 |
405 |
my $query = qq|SELECT description FROM project WHERE id = ?|;
|
403 |
406 |
my ($description) = selectrow_query($form, $dbh, $query, conv_i($id));
|
... | ... | |
554 |
557 |
$form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
|
555 |
558 |
}
|
556 |
559 |
my $basefactor;
|
557 |
|
my $basqty;
|
|
560 |
my $baseqty;
|
558 |
561 |
|
559 |
562 |
$form->{"marge_percent_$i"} = $form->parse_amount($myconfig, $form->{"marge_percent_$i"}) * 1;
|
560 |
563 |
$form->{"marge_total_$i"} = $form->parse_amount($myconfig, $form->{"marge_total_$i"}) * 1;
|
... | ... | |
1136 |
1139 |
WHERE (a.id = ?)|;
|
1137 |
1140 |
my $sth = prepare_execute_query($form, $dbh, $query, conv_i($id));
|
1138 |
1141 |
|
1139 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
|
1142 |
while (my $ref = $sth->fetchrow_hashref('NAME_lc')) {
|
1140 |
1143 |
|
1141 |
1144 |
my $allocated = 0;
|
1142 |
1145 |
|
... | ... | |
1159 |
1162 |
$query =
|
1160 |
1163 |
qq|INSERT INTO invoice (trans_id, description, parts_id, qty, sellprice, fxsellprice, allocated, assemblyitem, unit)
|
1161 |
1164 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)|;
|
1162 |
|
@values = (conv_i($form->{id}), $ref->{description}, conv_i($ref->{parts_id}), $ref->{qty}, 0, 0, $allocated, 't', $ref->{unit});
|
|
1165 |
my @values = (conv_i($form->{id}), $ref->{description}, conv_i($ref->{parts_id}), $ref->{qty}, 0, 0, $allocated, 't', $ref->{unit});
|
1163 |
1166 |
do_query($form, $dbh, $query, @values);
|
1164 |
1167 |
|
1165 |
1168 |
}
|
... | ... | |
1194 |
1197 |
my $allocated = 0;
|
1195 |
1198 |
my $qty;
|
1196 |
1199 |
|
1197 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
|
1200 |
while (my $ref = $sth->fetchrow_hashref('NAME_lc')) {
|
1198 |
1201 |
if (($qty = (($ref->{base_qty} * -1) - $ref->{allocated})) > $totalqty) {
|
1199 |
1202 |
$qty = $totalqty;
|
1200 |
1203 |
}
|
... | ... | |
1203 |
1206 |
|
1204 |
1207 |
# total expenses and inventory
|
1205 |
1208 |
# sellprice is the cost of the item
|
1206 |
|
$linetotal = $form->round_amount(($ref->{sellprice} * $qty) / $basefactor, 2);
|
|
1209 |
my $linetotal = $form->round_amount(($ref->{sellprice} * $qty) / $basefactor, 2);
|
1207 |
1210 |
|
1208 |
1211 |
if (!$main::eur) {
|
1209 |
1212 |
$ref->{expense_accno} = ($form->{"expense_accno_$row"}) ? $form->{"expense_accno_$row"} : $ref->{expense_accno};
|
... | ... | |
1242 |
1245 |
WHERE i.trans_id = ?|;
|
1243 |
1246 |
my $sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{"id"}));
|
1244 |
1247 |
|
1245 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
|
1248 |
while (my $ref = $sth->fetchrow_hashref('NAME_lc')) {
|
1246 |
1249 |
|
1247 |
1250 |
if ($ref->{inventory_accno_id}) {
|
1248 |
1251 |
# de-allocated purchases
|
... | ... | |
1253 |
1256 |
ORDER BY i.trans_id DESC|;
|
1254 |
1257 |
my $sth2 = prepare_execute_query($form, $dbh, $query, conv_i($ref->{"parts_id"}));
|
1255 |
1258 |
|
1256 |
|
while (my $inhref = $sth2->fetchrow_hashref(NAME_lc)) {
|
1257 |
|
$qty = $ref->{qty};
|
|
1259 |
while (my $inhref = $sth2->fetchrow_hashref('NAME_lc')) {
|
|
1260 |
my $qty = $ref->{qty};
|
1258 |
1261 |
if (($ref->{qty} - $inhref->{allocated}) > 0) {
|
1259 |
1262 |
$qty = $inhref->{allocated};
|
1260 |
1263 |
}
|
... | ... | |
1271 |
1274 |
$sth->finish;
|
1272 |
1275 |
|
1273 |
1276 |
# delete acc_trans
|
1274 |
|
@values = (conv_i($form->{id}));
|
|
1277 |
my @values = (conv_i($form->{id}));
|
1275 |
1278 |
do_query($form, $dbh, qq|DELETE FROM acc_trans WHERE trans_id = ?|, @values);
|
1276 |
1279 |
do_query($form, $dbh, qq|DELETE FROM invoice WHERE trans_id = ?|, @values);
|
1277 |
1280 |
|
... | ... | |
1312 |
1315 |
$dbh->disconnect;
|
1313 |
1316 |
|
1314 |
1317 |
if ($rc) {
|
1315 |
|
map { unlink "$spool/$_" if -f "$spool/$_"; } @{ $spoolfiles };
|
|
1318 |
map { unlink "$spool/$_" if -f "$spool/$_"; } @spoolfiles;
|
1316 |
1319 |
}
|
1317 |
1320 |
|
1318 |
1321 |
$main::lxdebug->leave_sub();
|
... | ... | |
1386 |
1389 |
$query = qq|SELECT printed, emailed, spoolfile, formname FROM status WHERE trans_id = ?|;
|
1387 |
1390 |
$sth = prepare_execute_query($form, $dbh, $query, $id);
|
1388 |
1391 |
|
1389 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
|
1392 |
while ($ref = $sth->fetchrow_hashref('NAME_lc')) {
|
1390 |
1393 |
$form->{printed} .= "$ref->{formname} " if $ref->{printed};
|
1391 |
1394 |
$form->{emailed} .= "$ref->{formname} " if $ref->{emailed};
|
1392 |
1395 |
$form->{queued} .= "$ref->{formname} $ref->{spoolfile} " if $ref->{spoolfile};
|
... | ... | |
1429 |
1432 |
|
1430 |
1433 |
$sth = prepare_execute_query($form, $dbh, $query, $id);
|
1431 |
1434 |
|
1432 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
|
1435 |
while (my $ref = $sth->fetchrow_hashref('NAME_lc')) {
|
1433 |
1436 |
map({ delete($ref->{$_}); } qw(inventory_accno inventory_new_chart inventory_valid)) if !$ref->{"part_inventory_accno_id"};
|
1434 |
1437 |
delete($ref->{"part_inventory_accno_id"});
|
1435 |
1438 |
|
... | ... | |
1454 |
1457 |
my $stw = prepare_execute_query($form, $dbh, $query, $accno_id);
|
1455 |
1458 |
$ref->{taxaccounts} = "";
|
1456 |
1459 |
my $i=0;
|
1457 |
|
while ($ptr = $stw->fetchrow_hashref(NAME_lc)) {
|
|
1460 |
while (my $ptr = $stw->fetchrow_hashref('NAME_lc')) {
|
1458 |
1461 |
|
1459 |
1462 |
if (($ptr->{accno} eq "") && ($ptr->{rate} == 0)) {
|
1460 |
1463 |
$i++;
|
... | ... | |
1574 |
1577 |
WHERE o.customer_id = ?
|
1575 |
1578 |
AND o.quotation = '0'
|
1576 |
1579 |
AND o.closed = '0'|;
|
1577 |
|
$sth = prepare_execute_query($form, $dbh, $query, $cid);
|
|
1580 |
my $sth = prepare_execute_query($form, $dbh, $query, $cid);
|
1578 |
1581 |
|
1579 |
1582 |
while (my ($amount, $exch) = $sth->fetchrow_array) {
|
1580 |
1583 |
$exch = 1 unless $exch;
|
... | ... | |
1608 |
1611 |
$sth = prepare_execute_query($form, $dbh, $query, $cid, $cid);
|
1609 |
1612 |
|
1610 |
1613 |
my $i = 0;
|
1611 |
|
while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
|
|
1614 |
while ($ref = $sth->fetchrow_hashref('NAME_lc')) {
|
1612 |
1615 |
if ($ref->{category} eq 'I') {
|
1613 |
1616 |
$i++;
|
1614 |
1617 |
$form->{"AR_amount_$i"} = "$ref->{accno}--$ref->{description}";
|
... | ... | |
1725 |
1728 |
WHERE $where|;
|
1726 |
1729 |
my $sth = prepare_execute_query($form, $dbh, $query, @values);
|
1727 |
1730 |
|
1728 |
|
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
|
1731 |
while (my $ref = $sth->fetchrow_hashref('NAME_lc')) {
|
1729 |
1732 |
|
1730 |
1733 |
# In der Buchungsgruppe ist immer ein Bestandskonto verknuepft, auch wenn
|
1731 |
1734 |
# es sich um eine Dienstleistung handelt. Bei Dienstleistungen muss das
|
... | ... | |
1753 |
1756 |
}
|
1754 |
1757 |
|
1755 |
1758 |
# get tax rates and description
|
1756 |
|
$accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
|
|
1759 |
my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
|
1757 |
1760 |
$query =
|
1758 |
1761 |
qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber
|
1759 |
1762 |
FROM tax t
|
... | ... | |
1767 |
1770 |
LIMIT 1)
|
1768 |
1771 |
ORDER BY c.accno|;
|
1769 |
1772 |
@values = ($accno_id, $transdate eq "current_date" ? "now" : $transdate);
|
1770 |
|
$stw = $dbh->prepare($query);
|
|
1773 |
my $stw = $dbh->prepare($query);
|
1771 |
1774 |
$stw->execute(@values) || $form->dberror($query);
|
1772 |
1775 |
|
1773 |
1776 |
$ref->{taxaccounts} = "";
|
1774 |
1777 |
my $i = 0;
|
1775 |
|
while ($ptr = $stw->fetchrow_hashref(NAME_lc)) {
|
|
1778 |
while (my $ptr = $stw->fetchrow_hashref('NAME_lc')) {
|
1776 |
1779 |
|
1777 |
|
# if ($customertax{$ref->{accno}}) {
|
|
1780 |
# if ($customertax{$ref->{accno}})
|
1778 |
1781 |
if (($ptr->{accno} eq "") && ($ptr->{rate} == 0)) {
|
1779 |
1782 |
$i++;
|
1780 |
1783 |
$ptr->{accno} = $i;
|
... | ... | |
1833 |
1836 |
FROM license l
|
1834 |
1837 |
WHERE l.parts_id = ? AND NOT l.id IN (SELECT li.license_id FROM licenseinvoice li)|;
|
1835 |
1838 |
my $stw = prepare_execute_query($form, $dbh, $query, conv_i($ref->{id}));
|
1836 |
|
while (my $ptr = $stw->fetchrow_hashref(NAME_lc)) {
|
|
1839 |
while (my $ptr = $stw->fetchrow_hashref('NAME_lc')) {
|
1837 |
1840 |
push @{ $form->{LIZENZEN}{ $ref->{id} } }, $ptr;
|
1838 |
1841 |
}
|
1839 |
1842 |
$stw->finish;
|
... | ... | |
1875 |
1878 |
$id = $form->{"new_id_$i"};
|
1876 |
1879 |
}
|
1877 |
1880 |
|
1878 |
|
($price, $selectedpricegroup_id) = split(/--/,
|
|
1881 |
my ($price, $selectedpricegroup_id) = split(/--/,
|
1879 |
1882 |
$form->{"sellprice_pg_$i"});
|
1880 |
1883 |
|
1881 |
|
$pricegroup_old = $form->{"pricegroup_old_$i"};
|
|
1884 |
my $pricegroup_old = $form->{"pricegroup_old_$i"};
|
1882 |
1885 |
$form->{"new_pricegroup_$i"} = $selectedpricegroup_id;
|
1883 |
1886 |
$form->{"old_pricegroup_$i"} = $pricegroup_old;
|
1884 |
1887 |
|
1885 |
|
$price_new = $form->{"price_new_$i"};
|
1886 |
|
$price_old = $form->{"price_old_$i"};
|
|
1888 |
my $price_new = $form->{"price_new_$i"};
|
|
1889 |
my $price_old = $form->{"price_old_$i"};
|
1887 |
1890 |
|
1888 |
1891 |
if (!$form->{"unit_old_$i"}) {
|
1889 |
1892 |
# Neue Ware aus der Datenbank. In diesem Fall ist unit_$i die
|
... | ... | |
1919 |
1922 |
$form->{"basefactor_$i"} = 1;
|
1920 |
1923 |
}
|
1921 |
1924 |
|
1922 |
|
$query =
|
|
1925 |
my $query =
|
1923 |
1926 |
qq|SELECT
|
1924 |
1927 |
pricegroup_id,
|
1925 |
1928 |
(SELECT p.sellprice FROM parts p WHERE p.id = ?) AS default_sellprice,
|
... | ... | |
1940 |
1943 |
FROM prices
|
1941 |
1944 |
|
1942 |
1945 |
ORDER BY pricegroup|;
|
1943 |
|
@values = (conv_i($id), conv_i($id), conv_i($id), conv_i($id));
|
|
1946 |
my @values = (conv_i($id), conv_i($id), conv_i($id), conv_i($id));
|
1944 |
1947 |
my $pkq = prepare_execute_query($form, $dbh, $query, @values);
|
1945 |
1948 |
|
1946 |
|
while ($pkr = $pkq->fetchrow_hashref(NAME_lc)) {
|
|
1949 |
while (my $pkr = $pkq->fetchrow_hashref('NAME_lc')) {
|
1947 |
1950 |
$pkr->{id} = $id;
|
1948 |
1951 |
$pkr->{selected} = '';
|
1949 |
1952 |
|
Mehr Perlcode strict gemacht.