X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIR.pm;h=22c1a286631e55cf3da5dc97d5e92c6431aa1918;hb=740a0719dcc7d9dbe1001664a23e5791e4c859e7;hp=875059bfacf397090bbb1244042671abd08481b2;hpb=d94820d09f4848d06bf3b74bb85c2c52820fbc48;p=kivitendo-erp.git diff --git a/SL/IR.pm b/SL/IR.pm index 875059bfa..22c1a2866 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -46,6 +46,7 @@ sub post_invoice { # connect to database, turn off autocommit my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig); + $form->{defaultcurrency} = $form->get_default_currency($myconfig); my ($query, $sth, @values, $project_id); my ($allocated, $taxrate, $taxamount, $taxdiff, $item); @@ -723,7 +724,19 @@ sub retrieve_invoice { my ($query, $sth, $ref, $q_invdate); - $q_invdate = ", current_date AS invdate" unless $form->{id}; + if (!$form->{id}) { + $q_invdate = qq|, COALESCE((SELECT transdate FROM ar WHERE id = (SELECT MAX(id) FROM ar)), current_date) AS invdate|; + if ($form->{vendor_id}) { + my $vendor_id = $dbh->quote($form->{vendor_id} * 1); + $q_invdate .= + qq|, COALESCE((SELECT transdate FROM ar WHERE id = (SELECT MAX(id) FROM ar)), current_date) + + COALESCE((SELECT pt.terms_netto + FROM vendor v + LEFT JOIN payment_terms pt ON (v.payment_id = pt.id) + WHERE v.id = $vendor_id), + 0) AS duedate|; + } + } # get default accounts and last invoice number @@ -1007,7 +1020,7 @@ sub retrieve_item { foreach my $table_column (qw(p.partnumber p.description pg.partsgroup)) { my $field = (split m{\.}, $table_column)[1]; next unless $form->{"${field}_${i}"}; - $where .= " AND lower(${table_column}) LIKE ?"; + $where .= " AND lower(${table_column}) LIKE lower(?)"; push @values, '%' . $form->{"${field}_${i}"} . '%'; }