X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIS.pm;h=1836a6bfa6ec059ca6c775715d03bdcb0232099c;hb=088f6a9721fece191bcc8d11a144b3b958b6c0c8;hp=3f5b9a30c774d0cc799f9664c91764b9194eeb81;hpb=6bd1a382b5c6b5f39039b970d383e5a232f6497c;p=kivitendo-erp.git diff --git a/SL/IS.pm b/SL/IS.pm index 3f5b9a30c..1836a6bfa 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -38,6 +38,7 @@ use SL::AM; use SL::Common; use SL::DBUtils; use SL::MoreCommon; +use Data::Dumper; sub invoice_details { $main::lxdebug->enter_sub(); @@ -492,6 +493,8 @@ sub post_invoice { if (!$form->{employee_id}) { $form->get_employee($dbh); } + + $form->{defaultcurrency} = $form->get_default_currency($myconfig); ($null, $form->{department_id}) = split(/--/, $form->{department}); @@ -549,6 +552,10 @@ sub post_invoice { my $basefactor; my $basqty; + $form->{"marge_percent_$i"} = $form->parse_amount($myconfig, $form->{"marge_percent_$i"}) * 1; + $form->{"marge_absolut_$i"} = $form->parse_amount($myconfig, $form->{"marge_absolut_$i"}) * 1; + $form->{"lastcost_$i"} = $form->{"lastcost_$i"} * 1; + if ($form->{storno}) { $form->{"qty_$i"} *= -1; } @@ -686,8 +693,9 @@ sub post_invoice { qq|INSERT INTO invoice (trans_id, parts_id, description, longdescription, qty, sellprice, fxsellprice, discount, allocated, assemblyitem, unit, deliverydate, project_id, serialnumber, pricegroup_id, - ordnumber, transdate, cusordnumber, base_qty, subtotal) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; + ordnumber, transdate, cusordnumber, base_qty, subtotal, + marge_percent, marge_total, lastcost) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; @values = (conv_i($form->{id}), conv_i($form->{"id_$i"}), $form->{"description_$i"}, $form->{"longdescription_$i"}, $form->{"qty_$i"}, @@ -696,7 +704,9 @@ sub post_invoice { $form->{"unit_$i"}, conv_date($form->{"deliverydate_$i"}), conv_i($form->{"project_id_$i"}), $form->{"serialnumber_$i"}, conv_i($pricegroup_id), $form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}), - $form->{"cusordnumber_$i"}, $baseqty, $subtotal); + $form->{"cusordnumber_$i"}, $baseqty, $subtotal, + $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"}, + $form->{"lastcost_$i"}); do_query($form, $dbh, $query, @values); if ($form->{lizenzen} && $form->{"licensenumber_$i"}) { @@ -893,6 +903,9 @@ sub post_invoice { $form->{"exchangerate_$i"}, 0); } } + + } else { # if (!$form->{storno}) + $form->{marge_total} *= -1; } if ($payments_only) { @@ -929,24 +942,6 @@ sub post_invoice { $amount = $netamount + $tax; - # fill in subject if there is none - $form->{subject} = qq|$form->{label} $form->{invnumber}| - unless $form->{subject}; - - # if there is a message stuff it into the intnotes - my $cc = "Cc: $form->{cc}\\r\n" if $form->{cc}; - my $bcc = "Bcc: $form->{bcc}\\r\n" if $form->{bcc}; - my $now = scalar localtime; - $form->{intnotes} .= qq|\r -\r| if $form->{intnotes}; - - $form->{intnotes} .= qq|[email]\r -Date: $now -To: $form->{email}\r -$cc${bcc}Subject: $form->{subject}\r -\r -Message: $form->{message}\r| if $form->{message}; - # save AR record $query = qq|UPDATE ar set invnumber = ?, @@ -982,9 +977,12 @@ Message: $form->{message}\r| if $form->{message}; employee_id = ?, salesman_id = ?, storno = ?, + storno_id = ?, globalproject_id = ?, cp_id = ?, - transaction_description = ? + transaction_description = ?, + marge_total = ?, + marge_percent = ? WHERE id = ?|; @values = ($form->{"invnumber"}, $form->{"ordnumber"}, $form->{"quonumber"}, $form->{"cusordnumber"}, conv_date($form->{"invdate"}), conv_date($form->{"orddate"}), conv_date($form->{"quodate"}), @@ -997,8 +995,9 @@ Message: $form->{message}\r| if $form->{message}; conv_i($form->{"shipto_id"}), conv_i($form->{"delivery_customer_id"}), conv_i($form->{"delivery_vendor_id"}), conv_i($form->{"employee_id"}), conv_i($form->{"salesman_id"}), - $form->{"storno"} ? 't' : 'f', conv_i($form->{"globalproject_id"}), + $form->{"storno"} ? 't' : 'f', conv_i($form->{storno_id}), conv_i($form->{"globalproject_id"}), conv_i($form->{"cp_id"}), $form->{transaction_description}, + $form->{marge_total} * 1, $form->{marge_percent} * 1, conv_i($form->{"id"})); do_query($form, $dbh, $query, @values); @@ -1099,9 +1098,6 @@ sub post_payment { # Delete all entries in acc_trans from prior payments. $self->_delete_payments($form, $dbh); - my @after_dp; - push @after_dp, selectall_hashref_query($form, $dbh, qq|SELECT * FROM acc_trans WHERE trans_id = ? ORDER BY oid|, $form->{id}); - # Save the new payments the user made before cleaning up $form. map { $payments{$_} = $form->{$_} } grep m/^datepaid_\d+$|^memo_\d+$|^source_\d+$|^exchangerate_\d+$|^paid_\d+$|^AR_paid_\d+$|^paidaccounts$/, keys %{ $form }; @@ -1112,7 +1108,7 @@ sub post_payment { # Retrieve the invoice from the database. $self->retrieve_invoice($myconfig, $form); - # Set up the content of $form in the way that IR::post_invoice() expects. + # Set up the content of $form in the way that IS::post_invoice() expects. $form->{exchangerate} = $form->format_amount($myconfig, $form->{exchangerate}); for $row (1 .. scalar @{ $form->{invoice_details} }) { @@ -1210,19 +1206,9 @@ sub cogs { my $taxzone_id = $form->{"taxzone_id"} * 1; my $query = qq|SELECT i.id, i.trans_id, i.base_qty, i.allocated, i.sellprice, - - c1.accno AS inventory_accno, - c1.new_chart_id AS inventory_new_chart, - date($transdate) - c1.valid_from AS inventory_valid, - - c2.accno AS income_accno, - c2.new_chart_id AS income_new_chart, - date($transdate) - c2.valid_from AS income_valid, - - c3.accno AS expense_accno, - c3.new_chart_id AS expense_new_chart, - date($transdate) - c3.valid_from AS expense_valid - + c1.accno AS inventory_accno, c1.new_chart_id AS inventory_new_chart, date($transdate) - c1.valid_from AS inventory_valid, + c2.accno AS income_accno, c2.new_chart_id AS income_new_chart, date($transdate) - c2.valid_from AS income_valid, + c3.accno AS expense_accno, c3.new_chart_id AS expense_new_chart, date($transdate) - c3.valid_from AS expense_valid FROM invoice i, parts p LEFT JOIN chart c1 ON ((SELECT inventory_accno_id FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c1.id) LEFT JOIN chart c2 ON ((SELECT income_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c2.id) @@ -1413,6 +1399,7 @@ sub retrieve_invoice { a.employee_id, a.salesman_id, a.payment_id, a.language_id, a.delivery_customer_id, a.delivery_vendor_id, a.type, a.transaction_description, + a.marge_total, a.marge_percent, e.name AS employee FROM ar a LEFT JOIN employee e ON (e.id = a.employee_id) @@ -1478,7 +1465,7 @@ sub retrieve_invoice { i.description, i.longdescription, i.qty, i.fxsellprice AS sellprice, i.discount, i.parts_id AS id, i.unit, i.deliverydate, i.project_id, i.serialnumber, i.id AS invoice_pos, i.pricegroup_id, - i.ordnumber, i.transdate, i.cusordnumber, i.subtotal, + i.ordnumber, i.transdate, i.cusordnumber, i.subtotal, i.lastcost, p.partnumber, p.assembly, p.bin, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id, p.formel, @@ -1795,7 +1782,7 @@ sub retrieve_item { my $query = qq|SELECT p.id, p.partnumber, p.description, p.sellprice, - p.listprice, p.inventory_accno_id, + p.listprice, p.inventory_accno_id, p.lastcost, c1.accno AS inventory_accno, c1.new_chart_id AS inventory_new_chart, @@ -2162,9 +2149,9 @@ sub has_storno { sub is_storno { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $form, $table) = @_; + my ($self, $myconfig, $form, $table, $id) = @_; - $main::lxdebug->leave_sub() and return 0 unless ($form->{id}); + $main::lxdebug->leave_sub() and return 0 unless ($id); # make sure there's no funny stuff in $table # ToDO: die when this happens and throw an error @@ -2173,7 +2160,7 @@ sub is_storno { my $dbh = $form->dbconnect($myconfig); my $query = qq|SELECT storno FROM $table WHERE id = ?|; - my ($result) = selectrow_query($form, $dbh, $query, $form->{id}); + my ($result) = selectrow_query($form, $dbh, $query, $id); $dbh->disconnect();