X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Foe.pl;h=3dbb113d11c9f60923338c5fcb685bf44771293f;hb=c1a8c6325abd3a4af242e9e6fd03b439d9b7c32f;hp=a6050945c63d4ffbdb8d918b67e21995be036588;hpb=8d8d1aab328b1c47d7983aca59c1c99592336eff;p=kivitendo-erp.git diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index a6050945c..3dbb113d1 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -31,6 +31,8 @@ # Quotation module #====================================================================== + +use Carp; use POSIX qw(strftime); use SL::DO; @@ -42,9 +44,11 @@ use SL::MoreCommon qw(ary_diff); use SL::PE; use SL::ReportGenerator; use List::MoreUtils qw(any none); -use List::Util qw(max reduce sum); +use List::Util qw(min max reduce sum); use Data::Dumper; +use SL::DB::Customer; + require "bin/mozilla/io.pl"; require "bin/mozilla/arap.pl"; require "bin/mozilla/reportgenerator.pl"; @@ -411,7 +415,7 @@ sub form_header { # emulate click for resubmitting actions $dispatch_to_popup = "document.oe.${_}.click(); " for grep { /^action_/ } keys %$form; } elsif ($creditwarning) { - $::request->{layout}->add_javascripts_inline("alert('$credittext')"); + $::request->{layout}->add_javascripts_inline("alert('$credittext');"); } $::request->{layout}->add_javascripts_inline("\$(function(){$dispatch_to_popup})"); @@ -477,12 +481,9 @@ sub form_footer { $TMPL_VAR{notes} = qq||; $TMPL_VAR{intnotes} = qq||; - my $paymet_id = $::form->{payment_id}; - IS->get_customer(\%myconfig, $::form) if $form->{type} =~ /sales_(order|quotation)/; - $::form->{payment_id} = $paymet_id; - - if ( $form->{vc} eq 'customer' && !$form->{taxincluded_changed_by_user} ) { - $form->{taxincluded} = defined($form->{taxincluded_checked}) ? $form->{taxincluded_checked} : $myconfig{taxincluded_checked}; + if( $form->{customer_id} && !$form->{taxincluded_changed_by_user} ) { + my $customer = SL::DB::Customer->new(id => $form->{customer_id})->load(); + $form->{taxincluded} = defined($customer->taxincluded_checked) ? $customer->taxincluded_checked : $myconfig{taxincluded_checked}; } if (!$form->{taxincluded}) { @@ -1335,6 +1336,8 @@ sub invoice { ::end_of_request(); } + _oe_remove_delivered_or_billed_rows(id => $form->{id}, type => 'billed'); + $form->{cp_id} *= 1; for my $i (1 .. $form->{rowcount}) { @@ -1614,7 +1617,7 @@ sub save_as_new { $form->{saveasnew} = 1; map { delete $form->{$_} } qw(printed emailed queued delivered closed); - # Let Lx-Office assign a new order number if the user hasn't changed the + # Let kivitendo assign a new order number if the user hasn't changed the # previous one. If it has been changed manually then use it as-is. my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber"; $form->{$idx} =~ s/^\s*//g; @@ -1870,6 +1873,8 @@ sub delivery_order { $form->{old_employee_id} = $form->{employee_id}; $form->{old_salesman_id} = $form->{salesman_id}; + _oe_remove_delivered_or_billed_rows(id => $form->{id}, type => 'delivered'); + # reset delete @{$form}{qw(id subject message cc bcc printed emailed queued creditlimit creditremaining discount tradediscount oldinvtotal closed delivered)}; @@ -2043,6 +2048,32 @@ sub save_periodic_invoices_config { $::lxdebug->leave_sub(); } +sub _oe_remove_delivered_or_billed_rows { + my (%params) = @_; + + return if !$params{id} || !$params{type}; + + my $ord_quot = SL::DB::Order->new(id => $params{id})->load; + return if !$ord_quot; + + my %args = ( + direction => 'to', + to => $params{type} eq 'delivered' ? 'DeliveryOrder' : 'Invoice', + via => [ $params{type} eq 'delivered' ? qw(Order) : qw(Order DeliveryOrder) ], + ); + + my %handled_base_qtys; + foreach my $record (@{ $ord_quot->linked_records(%args) }) { + next if $ord_quot->is_sales != $record->is_sales; + + foreach my $item (@{ $record->items }) { + $handled_base_qtys{ $item->parts_id } += $item->qty * $item->unit_obj->base_factor; + } + } + + _remove_billed_or_delivered_rows(quantities => \%handled_base_qtys); +} + sub dispatcher { foreach my $action (qw(delete delivery_order e_mail invoice print purchase_order purchase_order quotation request_for_quotation sales_order sales_order save save_and_close save_as_new ship_to update)) {