X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIS.pm;h=7b67528896913f9caa708a26b726145f08975417;hb=1c0845108811070224404f367b0e7bee1d5bbe9e;hp=c37b1aa8260ee23d53ee294b31c3648d5c518fcb;hpb=7eae8facf962ddf359ab295b0e402c142be31548;p=kivitendo-erp.git diff --git a/SL/IS.pm b/SL/IS.pm index c37b1aa82..7b6752889 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -421,7 +421,7 @@ sub customer_details { # get contact id, set it if nessessary $form->{cp_id} *= 1; - my @values; + my @values = (conv_i($form->{customer_id})); my $where = ""; if ($form->{cp_id}) { @@ -438,7 +438,6 @@ sub customer_details { WHERE (ct.id = ?) $where ORDER BY cp.cp_id LIMIT 1|; - push(@values, conv_i($form->{customer_id})); my $ref = selectfirst_hashref_query($form, $dbh, $query, @values); # remove id and taxincluded before copy back @@ -490,8 +489,7 @@ sub post_invoice { my ($query, $sth, $null, $project_id, $deliverydate, @values); my $exchangerate = 0; - ($null, $form->{employee_id}) = split(/--/, $form->{employee}); - unless ($form->{employee_id}) { + if (!$form->{employee_id}) { $form->get_employee($dbh); } @@ -992,7 +990,15 @@ Message: $form->{message}\r| if $form->{message}; conv_i($form->{"cp_id"}), $form->{transaction_description}, conv_i($form->{"id"})); do_query($form, $dbh, $query, @values); - + + if($form->{"formname"} eq "credit_note") { + for my $i (1 .. $form->{paidaccounts}) { + $query = qq|UPDATE parts SET onhand = onhand - ? WHERE id = ?|; + @values = (conv_i($form->{"qty_$i"}), conv_i($form->{"id_$i"})); + do_query($form, $dbh, $query, @values); + } + } + if ($form->{storno}) { $query = qq!UPDATE ar SET @@ -1525,7 +1531,7 @@ sub retrieve_invoice { (SELECT tk.tax_id FROM taxkeys tk WHERE tk.chart_id = (SELECT id FROM chart WHERE accno = ?) - AND startdate <= $transdate + AND startdate <= date($transdate) ORDER BY startdate DESC LIMIT 1) ORDER BY c.accno|; @@ -1712,7 +1718,7 @@ sub get_customer { qq|SELECT tk.tax_id, t.rate FROM taxkeys tk LEFT JOIN tax t ON tk.tax_id = t.id - WHERE (tk.chart_id = ?) AND (startdate <= ?) + WHERE (tk.chart_id = ?) AND (startdate <= date(?)) ORDER BY tk.startdate DESC LIMIT 1|; my ($tax_id, $rate) = @@ -1869,7 +1875,7 @@ sub retrieve_item { ORDER BY startdate DESC LIMIT 1) ORDER BY c.accno|; - @values = ($accno_id, $transdate); + @values = ($accno_id, $transdate eq "current_date" ? "now" : $transdate); $stw = $dbh->prepare($query); $stw->execute(@values) || $form->dberror($query); @@ -2132,6 +2138,29 @@ sub has_storno { my $dbh = $form->dbconnect($myconfig); + my $query = qq|SELECT storno FROM $table WHERE storno_id = ?|; + my ($result) = selectrow_query($form, $dbh, $query, $form->{id}); + + $dbh->disconnect(); + + $main::lxdebug->leave_sub(); + + return $result; +} + +sub is_storno { + $main::lxdebug->enter_sub(); + + my ($self, $myconfig, $form, $table) = @_; + + $main::lxdebug->leave_sub() and return 0 unless ($form->{id}); + + # make sure there's no funny stuff in $table + # ToDO: die when this happens and throw an error + $main::lxdebug->leave_sub() and return 0 if ($table =~ /\W/); + + my $dbh = $form->dbconnect($myconfig); + my $query = qq|SELECT storno FROM $table WHERE id = ?|; my ($result) = selectrow_query($form, $dbh, $query, $form->{id});