X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Foe.pl;h=8a14425d5da3442eade6cf24ea08a4bb1960f28c;hb=b8125c17c8add08c9b84fb054f797547a853dd3a;hp=66b2dbaa8363a7c11e3ef0abbfc16e556f63fb7e;hpb=02022dc2c7dca5f12d37feb3c4edbb1c7b7dad36;p=kivitendo-erp.git diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 66b2dbaa8..8a14425d5 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -375,7 +375,7 @@ sub form_header { @old_ids_cond, ]); - $TMPL_VAR{ALL_PROJECTS} = SL::DB::Manager::Project->get_all(query => \@conditions); + $TMPL_VAR{ALL_PROJECTS} = SL::DB::Manager::Project->get_all_sorted(query => \@conditions); # label subs my $employee_list_query_gen = sub { $::form->{$_[0]} ? [ or => [ id => $::form->{$_[0]}, deleted => 0 ] ] : [ deleted => 0 ] }; @@ -465,7 +465,7 @@ sub form_header { } } - $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase show_form_details show_history show_vc_details ckeditor/ckeditor ckeditor/adapters/jquery)); + $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase show_form_details show_history show_vc_details ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part)); $form->header; if ($form->{CFDD_shipto} && $form->{CFDD_shipto_id} ) { @@ -678,7 +678,20 @@ sub update { if ($sellprice) { $form->{"sellprice_$i"} = $sellprice; } else { - $form->{"sellprice_$i"} *= (1 - $form->{tradediscount}); + my $record = _make_record(); + my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record); + my $best_price = $price_source->best_price; + my $best_discount = $price_source->best_discount; + + if ($best_price) { + $::form->{"sellprice_$i"} = $best_price->price; + $::form->{"active_price_source_$i"} = $best_price->source; + } + if ($best_discount) { + $::form->{"discount_$i"} = $best_discount->discount; + $::form->{"active_discount_source_$i"} = $best_discount->source; + } + $form->{"sellprice_$i"} /= $exchangerate; # if there is an exchange rate adjust sellprice } @@ -692,12 +705,6 @@ sub update { $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces); $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); - - # get pricegroups for parts - IS->get_pricegroups_for_parts(\%myconfig, \%$form); - - # build up html code for prices_$i - &set_pricegroup($i); } display_form(); @@ -1344,9 +1351,14 @@ sub delete { if (OE->delete(\%myconfig, \%$form)){ # saving the history if(!exists $form->{addition}) { - $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; - $form->{addition} = "DELETED"; - $form->save_history; + if ( $form->{formname} eq 'sales_quotation' or $form->{formname} eq 'request_quotation' ) { + $form->{snumbers} = qq|quonumber_| . $form->{quonumber}; + } elsif ( $form->{formname} eq 'sales_order' or $form->{formname} eq 'purchase_order') { + $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; + }; + $form->{what_done} = $form->{formname}; + $form->{addition} = "DELETED"; + $form->save_history; } # /saving the history $form->info($msg); @@ -1411,6 +1423,7 @@ sub invoice { for (qw(ship qty sellprice listprice basefactor)) { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"}; } + $form->{"converted_from_orderitems_id_$i"} = delete $form->{"orderitems_id_$i"}; } my ($buysell, $orddate, $exchangerate); @@ -1505,10 +1518,6 @@ sub invoice { $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); } - # show pricegroup in newly loaded invoice when creating invoice from quotation/order - IS->get_pricegroups_for_parts(\%myconfig, \%$form); - set_pricegroup($_) for 1 .. $form->{rowcount}; - &display_form; $main::lxdebug->leave_sub(); @@ -1612,7 +1621,7 @@ sub save_as_new { $form->{saveasnew} = 1; map { delete $form->{$_} } qw(printed emailed queued delivered closed); - delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"}; + $form->{"converted_from_orderitems_id_$_"} = delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"}; # 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. @@ -1628,25 +1637,14 @@ sub save_as_new { if ( $form->{reqdate} && $form->{id} ) { my $saved_order = OE->retrieve_simple(id => $form->{id}); if ( $saved_order && $saved_order->{reqdate} eq $form->{reqdate} && $saved_order->{transdate} eq $form->{transdate} ) { + my $extra_days = $form->{type} eq 'sales_quotation' ? $::instance_conf->get_reqdate_interval : 1; + my $next_workday = DateTime->today_local->add(days => $extra_days); + my $day_of_week = $next_workday->day_of_week; - my $dbh = $form->get_standard_dbh; + $next_workday->add(days => (8 - $day_of_week)) if $day_of_week >= 6; - my $wday = (localtime(time))[6]; - my $next_workday = $wday == 5 ? 3 : $wday == 6 ? 2 : 1; - - # if we have a client configured interval for sales quotation, we add this - $next_workday += $::instance_conf->get_reqdate_interval if ($::instance_conf->get_reqdate_interval && - $form->{type} eq 'sales_quotation' ); - - my $query = 'SELECT - date(current_date + interval \''. $next_workday .' days\') AS reqdate, - date(current_date) AS transdate'; - my $ref = selectfirst_hashref_query($form, $dbh, $query); - - map( - { $form->{$_} = $ref->{$_} } - keys %{$ref} - ); + $form->{transdate} = DateTime->today_local->to_kivitendo; + $form->{reqdate} = $next_workday->to_kivitendo; } } @@ -1811,7 +1809,8 @@ sub poso { # reset map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal delivered ordnumber); - delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"}; + # this converted variable is also used for sales_order to purchase order and vice versa + $form->{"converted_from_orderitems_id_$_"} = delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"}; # if purchase_order was generated from sales_order, use lastcost_$i as sellprice_$i # also reset discounts @@ -1819,7 +1818,6 @@ sub poso { for my $i (1 .. $form->{rowcount}) { $form->{"sellprice_${i}"} = $form->{"lastcost_${i}"}; $form->{"discount_${i}"} = 0; - delete $form->{"orderitems_id_$_"}; }; }; @@ -1887,6 +1885,7 @@ sub delivery_order { for my $i (1 .. $form->{rowcount}) { map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice lastcost basefactor discount); + $form->{"converted_from_orderitems_id_$i"} = delete $form->{"orderitems_id_$i"}; } my %old_values = map { $_ => $form->{$_} } qw(customer_id oldcustomer customer vendor_id oldvendor vendor shipto_id); @@ -2104,8 +2103,8 @@ sub check_transport_cost_reminder_article_number { $main::lxdebug->leave_sub(); } 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)) { + foreach my $action (qw(delete delivery_order e_mail invoice print purchase_order quotation + request_for_quotation sales_order save save_and_close save_as_new ship_to update)) { if ($::form->{"action_${action}"}) { call_sub($action); return; @@ -2114,3 +2113,4 @@ sub dispatcher { $::form->error($::locale->text('No action defined.')); } +