X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FOE.pm;h=72c11ed3249d38f7e14d9490d98c4d81889337d2;hb=0f33c880b8fdb7ab48bc40dd0464e7458ac00c8a;hp=f662615506d419cdf4d52dcfa8a0a8925c37361a;hpb=5cf977e52788c523150fa19225b90914e6ddc909;p=kivitendo-erp.git diff --git a/SL/OE.pm b/SL/OE.pm index f66261550..72c11ed32 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -149,17 +149,18 @@ sub transactions { } my $sortorder = join(', ', ("o.id", $form->sort_columns("transdate", $ordnumber, "name"))); - my %allowed_sort_columns = - ("transdate" => "o.transdate", - "reqdate" => "o.reqdate", - "id" => "o.id", - "ordnumber" => "o.ordnumber", - "quonumber" => "o.quonumber", - "name" => "ct.name", - "employee" => "e.name", - "salesman" => "e.name", - "shipvia" => "o.shipvia", - "transaction_description" => "o.transaction_description"); + my %allowed_sort_columns = ( + "transdate" => "o.transdate", + "reqdate" => "o.reqdate", + "id" => "o.id", + "ordnumber" => "o.ordnumber", + "quonumber" => "o.quonumber", + "name" => "ct.name", + "employee" => "e.name", + "salesman" => "e.name", + "shipvia" => "o.shipvia", + "transaction_description" => "o.transaction_description" + ); if ($form->{sort} && grep($form->{sort}, keys(%allowed_sort_columns))) { $sortorder = $allowed_sort_columns{$form->{sort}}; } @@ -183,6 +184,41 @@ sub transactions { $main::lxdebug->leave_sub(); } +sub transactions_for_todo_list { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + my $query = qq|SELECT id FROM employee WHERE login = ?|; + my ($e_id) = selectrow_query($form, $dbh, $query, $form->{login}); + + $query = + qq|SELECT oe.id, oe.transdate, oe.reqdate, oe.quonumber, oe.transaction_description, oe.amount, + c.name AS customer, + e.name AS employee + FROM oe + LEFT JOIN customer c ON (oe.customer_id = c.id) + LEFT JOIN employee e ON (oe.employee_id = e.id) + WHERE (COALESCE(quotation, FALSE) = TRUE) + AND (COALESCE(closed, FALSE) = FALSE) + AND ((oe.employee_id = ?) OR (oe.salesman_id = ?)) + AND NOT (oe.reqdate ISNULL) + AND (oe.reqdate < current_date) + ORDER BY transdate|; + + my $quotations = selectall_hashref_query($form, $dbh, $query, $e_id, $e_id); + + $main::lxdebug->leave_sub(); + + return $quotations; +} + sub save { $main::lxdebug->enter_sub(); @@ -206,8 +242,6 @@ sub save { if ($form->{id}) { - &adj_onhand($dbh, $form, $ml) if $form->{type} =~ /_order$/; - $query = qq|DELETE FROM orderitems WHERE trans_id = ?|; do_query($form, $dbh, $query, $form->{id}); @@ -243,8 +277,7 @@ sub save { for my $i (1 .. $form->{rowcount}) { - map({ $form->{"${_}_$i"} = - $form->parse_amount($myconfig, $form->{"${_}_$i"}) } qw(qty ship)); + map({ $form->{"${_}_$i"} = $form->parse_amount($myconfig, $form->{"${_}_$i"}) } qw(qty ship)); if ($form->{"id_$i"}) { @@ -255,8 +288,7 @@ sub save { my $basefactor = 1; if (defined($all_units->{$item_unit}->{factor}) && (($all_units->{$item_unit}->{factor} * 1) != 0)) { - $basefactor = $all_units->{$form->{"unit_$i"}}->{factor} / - $all_units->{$item_unit}->{factor}; + $basefactor = $all_units->{$form->{"unit_$i"}}->{factor} / $all_units->{$item_unit}->{factor}; } my $baseqty = $form->{"qty_$i"} * $basefactor; @@ -265,23 +297,17 @@ sub save { $form->{"lastcost_$i"} = $form->{"lastcost_$i"} * 1; # set values to 0 if nothing entered - $form->{"discount_$i"} = - $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100; + $form->{"discount_$i"} = $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100; - $form->{"sellprice_$i"} = - $form->parse_amount($myconfig, $form->{"sellprice_$i"}); + $form->{"sellprice_$i"} = $form->parse_amount($myconfig, $form->{"sellprice_$i"}); $fxsellprice = $form->{"sellprice_$i"}; my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); $dec = length($dec); my $decimalplaces = ($dec > 2) ? $dec : 2; - $discount = - $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}, - $decimalplaces); - $form->{"sellprice_$i"} = - $form->round_amount($form->{"sellprice_$i"} - $discount, - $decimalplaces); + $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}, $decimalplaces); + $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces); $form->{"inventory_accno_$i"} *= 1; $form->{"expense_accno_$i"} *= 1; @@ -310,15 +336,10 @@ sub save { if ($form->round_amount($taxrate, 7) == 0) { if ($form->{taxincluded}) { foreach $item (@taxaccounts) { - $taxamount = - $form->round_amount($linetotal * $form->{"${item}_rate"} / - (1 + abs($form->{"${item}_rate"})), - 2); - + $taxamount = $form->round_amount($linetotal * $form->{"${item}_rate"} / (1 + abs($form->{"${item}_rate"})), 2); $taxaccounts{$item} += $taxamount; $taxdiff += $taxamount; - - $taxbase{$item} += $taxbase; + $taxbase{$item} += $taxbase; } $taxaccounts{ $taxaccounts[0] } += $taxdiff; } else { @@ -329,16 +350,14 @@ sub save { } } else { foreach $item (@taxaccounts) { - $taxaccounts{$item} += - $taxamount * $form->{"${item}_rate"} / $taxrate; + $taxaccounts{$item} += $taxamount * $form->{"${item}_rate"} / $taxrate; $taxbase{$item} += $taxbase; } } $netamount += $form->{"sellprice_$i"} * $form->{"qty_$i"} / $price_factor; - $reqdate = - ($form->{"reqdate_$i"}) ? $form->{"reqdate_$i"} : undef; + $reqdate = ($form->{"reqdate_$i"}) ? $form->{"reqdate_$i"} : undef; # get pricegroup_id and save ist ($null, my $pricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"}); @@ -361,7 +380,7 @@ sub save { } $query .= qq|?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, (SELECT factor FROM price_factors WHERE id = ?), ?)|; - push(@values, + push(@values, conv_i($form->{id}), conv_i($form->{"id_$i"}), $form->{"description_$i"}, $form->{"longdescription_$i"}, $form->{"qty_$i"}, $baseqty, @@ -393,21 +412,14 @@ sub save { if ($form->{currency} eq $form->{defaultcurrency}) { $form->{exchangerate} = 1; } else { - $exchangerate = - $form->check_exchangerate($myconfig, - $form->{currency}, - $form->{transdate}, - ($form->{vc} eq 'customer') ? 'buy' : 'sell'); + $exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{transdate}, ($form->{vc} eq 'customer') ? 'buy' : 'sell'); } - $form->{exchangerate} = - ($exchangerate) - ? $exchangerate - : $form->parse_amount($myconfig, $form->{exchangerate}); + $form->{exchangerate} = $exchangerate || $form->parse_amount($myconfig, $form->{exchangerate}); my $quotation = $form->{type} =~ /_order$/ ? 'f' : 't'; - ($null, $form->{department_id}) = split(/--/, $form->{department}); + ($null, $form->{department_id}) = split(/--/, $form->{department}) if $form->{department}; # save OE record $query = @@ -455,29 +467,21 @@ sub save { if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) { if ($form->{vc} eq 'customer') { - $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, - $form->{exchangerate}, 0); + $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, $form->{exchangerate}, 0); } if ($form->{vc} eq 'vendor') { - $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, - 0, $form->{exchangerate}); + $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, 0, $form->{exchangerate}); } } - if ($form->{type} =~ /_order$/) { - - # adjust onhand - &adj_onhand($dbh, $form, $ml * -1); - } - - my $rc = $dbh->commit; - $dbh->disconnect; - $form->{saved_xyznumber} = $form->{$form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber"}; Common::webdav_folder($form) if ($main::webdav); + my $rc = $dbh->commit; + $dbh->disconnect; + $main::lxdebug->leave_sub(); return $rc; @@ -544,25 +548,9 @@ sub delete { } $sth->finish; - $query = qq|SELECT o.parts_id, o.ship FROM orderitems o | . - qq|WHERE o.trans_id = ?|; - @values = (conv_i($form->{id})); - $sth = $dbh->prepare($query); - $sth->execute(@values) || $self->dberror($query); - - while (my ($id, $ship) = $sth->fetchrow_array) { - $form->update_balance($dbh, "parts", "onhand", qq|id = $id|, $ship * -1); - } - $sth->finish; - # delete-values @values = (conv_i($form->{id})); - # delete inventory - $query = qq|DELETE FROM inventory | . - qq|WHERE oe_id = ?|; - do_query($form, $dbh, $query, @values); - # delete status entries $query = qq|DELETE FROM status | . qq|WHERE trans_id = ?|; @@ -632,7 +620,7 @@ sub retrieve { my $ref = selectfirst_hashref_query($form, $dbh, $query); map { $form->{$_} = $ref->{$_} } keys %$ref; - ($form->{currency}) = split(/:/, $form->{currencies}); + ($form->{currency}) = split(/:/, $form->{currencies}) unless ($form->{currency}); # set reqdate if this is an invoice->order conversion. If someone knows a better check to ensure # we come from invoices, feel free. @@ -917,8 +905,7 @@ sub order_details { $sth->finish(); } - $form->{"globalprojectnumber"} = - $projectnumbers{$form->{"globalproject_id"}}; + $form->{"globalprojectnumber"} = $projectnumbers{$form->{"globalproject_id"}}; my @arrays = qw(runningnumber number description longdescription qty ship unit bin @@ -1040,9 +1027,8 @@ sub order_details { if ($taxamount != 0) { foreach my $item (split / /, $form->{"taxaccounts_$i"}) { - $taxaccounts{$item} += - $taxamount * $form->{"${item}_rate"} / $taxrate; - $taxbase{$item} += $taxbase; + $taxaccounts{$item} += $taxamount * $form->{"${item}_rate"} / $taxrate; + $taxbase{$item} += $taxbase; } } @@ -1055,8 +1041,7 @@ sub order_details { # get parts and push them onto the stack my $sortorder = ""; if ($form->{groupitems}) { - $sortorder = - qq|ORDER BY pg.partsgroup, a.$oid{$myconfig->{dbdriver}}|; + $sortorder = qq|ORDER BY pg.partsgroup, a.$oid{$myconfig->{dbdriver}}|; } else { $sortorder = qq|ORDER BY a.$oid{$myconfig->{dbdriver}}|; } @@ -1074,19 +1059,13 @@ sub order_details { while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { if ($form->{groupitems} && $ref->{partsgroup} ne $sameitem) { - map({ push(@{ $form->{$_} }, "") } - grep({ $_ ne "description" } @arrays)); + map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays)); $sameitem = ($ref->{partsgroup}) ? $ref->{partsgroup} : "--"; push(@{ $form->{description} }, $sameitem); } - push(@{ $form->{description} }, - $form->format_amount($myconfig, $ref->{qty} * $form->{"qty_$i"} - ) - . qq|, $ref->{partnumber}, $ref->{description}|); - - map({ push(@{ $form->{$_} }, "") } - grep({ $_ ne "description" } @arrays)); + push(@{ $form->{description} }, $form->format_amount($myconfig, $ref->{qty} * $form->{"qty_$i"}) . qq|, $ref->{partnumber}, $ref->{description}|); + map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays)); } $sth->finish; } @@ -1150,67 +1129,4 @@ sub project_description { return $value; } -sub adj_onhand { - $main::lxdebug->enter_sub(); - - my ($dbh, $form, $ml) = @_; - - my $all_units = $form->{all_units}; - - my $query = - qq|SELECT oi.parts_id, oi.ship, oi.unit, p.inventory_accno_id, p.assembly | . - qq| FROM orderitems oi | . - qq| JOIN parts p ON (p.id = oi.parts_id) | . - qq| WHERE oi.trans_id = ?|; - my @values = ($form->{id}); - my $sth = $dbh->prepare($query); - $sth->execute(@values) || $form->dberror($query); - - $query = - qq|SELECT sum(p.inventory_accno_id) | . - qq|FROM parts p | . - qq|JOIN assembly a ON (a.parts_id = p.id) | . - qq|WHERE a.id = ?|; - my $ath = $dbh->prepare($query) || $form->dberror($query); - - my $ispa; - - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - if ($ref->{inventory_accno_id} || $ref->{assembly}) { - - # do not update if assembly consists of all services - if ($ref->{assembly}) { - $ath->execute($ref->{parts_id}) || $form->dberror($query); - - ($ispa) = $sth->fetchrow_array; - $ath->finish; - - next unless $ispa; - - } - - # get item baseunit - $query = qq|SELECT unit FROM parts WHERE id = ?|; - my ($item_unit) = selectrow_query($form, $dbh, $query, $ref->{parts_id}); - - my $basefactor = 1; - if (defined($all_units->{$item_unit}->{factor}) && - (($all_units->{$item_unit}->{factor} * 1) != 0)) { - $basefactor = $all_units->{$ref->{unit}}->{factor} / - $all_units->{$item_unit}->{factor}; - } - my $baseqty = $ref->{ship} * $basefactor; - - # adjust onhand in parts table - $form->update_balance($dbh, "parts", "onhand", - qq|id = $ref->{parts_id}|, - $baseqty * $ml); - } - } - - $sth->finish; - - $main::lxdebug->leave_sub(); -} - 1;