X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/03f9eac39d30ffe348947910e98929292ef42617..9a128e8bfd4f08c24e12b4ab7387efb3001d629f:/SL/IS.pm diff --git a/SL/IS.pm b/SL/IS.pm index 6e9e96012..5b02041ba 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -525,10 +525,14 @@ sub invoice_details { $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}; @@ -969,15 +973,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; @@ -1244,6 +1253,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(); @@ -1291,7 +1302,7 @@ SQL if ($form->{storno}) { $query = qq!UPDATE ar SET - paid = paid + amount, + paid = amount, storno = 't', intnotes = ? || intnotes WHERE id = ?!; @@ -1299,6 +1310,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//; @@ -1474,7 +1487,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; @@ -1814,6 +1827,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(); @@ -2045,6 +2063,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); } @@ -2203,7 +2236,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); @@ -2215,7 +2248,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;