X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIS.pm;h=ec744df2eba91e049438f2961a1db36c03ffaa0f;hb=33c46114fde417a185bcf6715e9903f08f977235;hp=b47944bdcdda58ea9581a0228b14f4ed91ba9c43;hpb=c9b8ad08645675a40f96bdeaa23b1d0e62d772e6;p=kivitendo-erp.git diff --git a/SL/IS.pm b/SL/IS.pm index b47944bdc..ec744df2e 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(); @@ -551,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; } @@ -681,15 +686,15 @@ sub post_invoice { # get pricegroup_id and save it ($null, my $pricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"}); $pricegroup_id *= 1; - my $subtotal = $form->{"subtotal_$i"} * 1; # save detail record in invoice table $query = 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"}, @@ -698,7 +703,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, $form->{"subtotal_$i"} ? 't' : 'f', + $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"}, + $form->{"lastcost_$i"}); do_query($form, $dbh, $query, @values); if ($form->{lizenzen} && $form->{"licensenumber_$i"}) { @@ -895,6 +902,9 @@ sub post_invoice { $form->{"exchangerate_$i"}, 0); } } + + } else { # if (!$form->{storno}) + $form->{marge_total} *= -1; } if ($payments_only) { @@ -931,24 +941,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 = ?, @@ -984,9 +976,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"}), @@ -999,8 +994,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); @@ -1209,19 +1205,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) @@ -1412,6 +1398,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) @@ -1477,7 +1464,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, @@ -2161,9 +2148,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 @@ -2172,7 +2159,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();