X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIS.pm;h=c579aad8d831a49292104fd91e2538c40a0d41c4;hb=f9a93e326337ed219de49f575c02e5a8cb36a1b6;hp=19c41886bb009e76a827ce26e99318a0b77d759e;hpb=5902705e1674deb4a4e62c360f9d7d05be3110bd;p=kivitendo-erp.git diff --git a/SL/IS.pm b/SL/IS.pm index 19c41886b..c579aad8d 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -519,16 +519,26 @@ sub invoice_details { $form->{nodiscount} = $form->format_amount($myconfig, $nodiscount, 2); $form->{yesdiscount} = $form->format_amount($myconfig, $form->{nodiscount_total} - $nodiscount, 2); - $form->{invtotal} = ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax; - $form->{total} = $form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2); + my $grossamount = ($form->{taxincluded}) ? $form->{total} : $form->{total} + $tax; + $form->{invtotal} = $form->round_amount($grossamount, 2, 1); + $form->{rounding} = $form->round_amount( + $form->{invtotal} - $form->round_amount($grossamount, 2), + 2 + ); + $form->{rounding} = $form->format_amount($myconfig, $form->{rounding}, 2); + $form->{total} = $form->format_amount($myconfig, $form->{invtotal} - $form->{paid}, 2); $form->{invtotal} = $form->format_amount($myconfig, $form->{invtotal}, 2); $form->{paid} = $form->format_amount($myconfig, $form->{paid}, 2); - $form->set_payment_options($myconfig, $form->{invdate}); + $form->set_payment_options($myconfig, $form->{invdate}, 'sales_invoice'); $form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef); - $form->{delivery_term}->description_long($form->{delivery_term}->translated_attribute('description_long', $form->{language_id})) if $form->{delivery_term} && $form->{language_id}; + if ($form->{delivery_term} && $form->{language_id}) { + $form->{delivery_term}->description_long( $form->{delivery_term}->translated_attribute('description_long', $form->{language_id})); + $form->{delivery_term}->description_long_invoice($form->{delivery_term}->translated_attribute('description_long_invoice', $form->{language_id})); + } + $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id}; $form->{username} = $myconfig->{name}; @@ -591,6 +601,7 @@ sub customer_details { $ref->{street} = $customer->street; $ref->{zipcode} = $customer->zipcode; $ref->{country} = $customer->country; + $ref->{gln} = $customer->gln; } my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id}); if ($contact) { @@ -599,8 +610,8 @@ sub customer_details { $ref->{cp_gender} = $contact->cp_gender; } } - # remove id and taxincluded before copy back - delete @$ref{qw(id taxincluded)}; + # remove id,notes (double of customernotes) and taxincluded before copy back + delete @$ref{qw(id taxincluded notes)}; @wanted_vars = grep({ $_ } @wanted_vars); if (scalar(@wanted_vars) > 0) { @@ -968,15 +979,20 @@ SQL } # Invoice Summary includes Rounding + my $grossamount = $netamount + $tax; my $rounding = $form->round_amount( - $form->round_amount($netamount + $tax, 2, 1) - $form->round_amount($netamount + $tax, 2), 2 + $form->round_amount($grossamount, 2, 1) - $form->round_amount($grossamount, 2), + 2 ); my $rnd_accno = $rounding == 0 ? 0 : $rounding > 0 ? $form->{rndgain_accno} - : $form->{rndloss_accno}; - $form->{amount}{ $form->{id} }{ $form->{AR} } = $form->round_amount($netamount + $tax, 2, 1); - $form->{paid} = - $form->round_amount($form->{paid} * $form->{exchangerate} + $diff, 2); + : $form->{rndloss_accno} + ; + $form->{amount}{ $form->{id} }{ $form->{AR} } = $form->round_amount($grossamount, 2, 1); + $form->{paid} = $form->round_amount( + $form->{paid} * $form->{exchangerate} + $diff, + 2 + ); # reverse AR $form->{amount}{ $form->{id} }{ $form->{AR} } *= -1; @@ -1243,6 +1259,8 @@ SQL $query = qq|UPDATE ar SET paid = ? WHERE id = ?|; do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id})); + $form->new_lastmtime('ar'); + $dbh->commit if !$provided_dbh; $main::lxdebug->leave_sub(); @@ -1290,7 +1308,7 @@ SQL if ($form->{storno}) { $query = qq!UPDATE ar SET - paid = paid + amount, + paid = amount, storno = 't', intnotes = ? || intnotes WHERE id = ?!; @@ -1298,6 +1316,8 @@ SQL do_query($form, $dbh, qq|UPDATE ar SET paid = amount WHERE id = ?|, conv_i($form->{"id"})); } + $form->new_lastmtime('ar'); + $form->{name} = $form->{customer}; $form->{name} =~ s/--\Q$form->{customer_id}\E//; @@ -1473,7 +1493,7 @@ sub _determine_wh_and_bin { parts_id => $part->id, bin_id => $bin_id); if ($error == 1) { - push @errors, $::locale->text('Part "#1" has chargenumber or best before date set. So it cannot be transfered automaticaly.', + push @errors, $::locale->text('Part "#1" has chargenumber or best before date set. So it cannot be transfered automatically.', $part->description); } my $form_unit_obj = SL::DB::Unit->new(name => $unit)->load; @@ -1813,6 +1833,11 @@ sub reverse_invoice { # delete acc_trans my @values = (conv_i($form->{id})); do_query($form, $dbh, qq|DELETE FROM acc_trans WHERE trans_id = ?|, @values); + + $query = qq|DELETE FROM custom_variables + WHERE (config_id IN (SELECT id FROM custom_variable_configs WHERE (module = 'ShipTo'))) + AND (trans_id IN (SELECT shipto_id FROM shipto WHERE (module = 'AR') AND (trans_id = ?)))|; + do_query($form, $dbh, $query, @values); do_query($form, $dbh, qq|DELETE FROM shipto WHERE (trans_id = ?) AND (module = 'AR')|, @values); $main::lxdebug->leave_sub(); @@ -1906,7 +1931,7 @@ sub retrieve_invoice { qq|SELECT a.invnumber, a.ordnumber, a.quonumber, a.cusordnumber, a.orddate, a.quodate, a.globalproject_id, - a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.gldate, + a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.storno_id, a.gldate, a.shippingpoint, a.shipvia, a.notes, a.intnotes, a.taxzone_id, a.duedate, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.shipto_id, a.cp_id, a.employee_id, a.salesman_id, a.payment_id, @@ -2044,6 +2069,21 @@ sub retrieve_invoice { } $sth->finish; + # Fetch shipping address. + $query = qq|SELECT s.* FROM shipto s WHERE s.trans_id = ? AND s.module = 'AR'|; + $ref = selectfirst_hashref_query($form, $dbh, $query, $form->{id}); + + $form->{$_} = $ref->{$_} for grep { $_ ne 'id' } keys %$ref; + + if ($form->{shipto_id}) { + my $cvars = CVar->get_custom_variables( + dbh => $dbh, + module => 'ShipTo', + trans_id => $form->{shipto_id}, + ); + $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars }; + } + Common::webdav_folder($form); } @@ -2202,7 +2242,7 @@ sub retrieve_item { my ($table, $field) = split m/\./, $column; next if !$form->{"${field}_${i}"}; $where .= qq| AND lower(${column}) ILIKE ?|; - push @values, '%' . $form->{"${field}_${i}"} . '%'; + push @values, like($form->{"${field}_${i}"}); } my (%mm_by_id); @@ -2214,7 +2254,7 @@ sub retrieve_item { my $mm_query = qq| SELECT parts_id, model FROM makemodel LEFT JOIN parts ON parts.id = parts_id WHERE NOT parts.obsolete AND model ILIKE ?; |; - my $mm_results = selectall_hashref_query($::form, $dbh, $mm_query, '%' . $form->{"partnumber_$i"} . '%'); + my $mm_results = selectall_hashref_query($::form, $dbh, $mm_query, like($form->{"partnumber_$i"})); my @mm_ids = map { $_->{parts_id} } @$mm_results; push @{$mm_by_id{ $_->{parts_id} } ||= []}, $_ for @$mm_results;