set_headings($form->{"id"} ? "edit" : "add");
+ $form->{insertdate} = SL::DB::DeliveryOrder->new(id => $form->{id})->load->itime_as_date if $form->{id};
+
$form->{update} = 1;
my $payment_id;
if ($rows > 1) {
- select_item(mode => $mode);
+ select_item(mode => $mode, pre_entered_qty => $form->{"qty_$i"});
::end_of_request();
} else {
+ my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+
map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
$form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
+
+ if ($sellprice) {
+ $form->{"sellprice_$i"} = $sellprice;
+ } else {
+ 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"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
- $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"});
+ $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"});
$form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100.0);
}
display_form();
$form->{vc} = $form->{type} eq 'purchase_delivery_order' ? 'vendor' : 'customer';
- $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
- "all" => 1 },
- "departments" => "ALL_DEPARTMENTS",
- "$form->{vc}s" => "ALL_VC");
+ $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
+ "all" => 1 },
+ "departments" => "ALL_DEPARTMENTS",
+ "$form->{vc}s" => "ALL_VC",
+ "business_types" => "ALL_BUSINESS_TYPES");
$form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
$form->{SHOW_VC_DROP_DOWN} = $myconfig{vclimit} > scalar @{ $form->{ALL_VC} };
shipvia globalprojectnumber
transaction_description department
open delivered
+ insertdate
);
$form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed});
my @hidden_variables = map { "l_${_}" } @columns;
push @hidden_variables, $form->{vc}, qw(l_closed l_notdelivered open closed delivered notdelivered donumber ordnumber serialnumber cusordnumber
transaction_description transdatefrom transdateto reqdatefrom reqdateto
- type vc employee_id salesman_id project_id);
+ type vc employee_id salesman_id project_id
+ insertdatefrom insertdateto business_id);
my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
'open' => { 'text' => $locale->text('Open'), },
'delivered' => { 'text' => $locale->text('Delivered'), },
'department' => { 'text' => $locale->text('Department'), },
+ 'insertdate' => { 'text' => $locale->text('Insert Date'), },
);
- foreach my $name (qw(id transdate reqdate donumber ordnumber name employee salesman shipvia transaction_description department)) {
+ foreach my $name (qw(id transdate reqdate donumber ordnumber name employee salesman shipvia transaction_description department insertdate)) {
my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
$column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
}
push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
}
push @options, $locale->text('Serial Number') . " : $form->{serialnumber}" if $form->{serialnumber};
+ if ($form->{business_id}) {
+ my $vc_type_label = $form->{vc} eq 'customer' ? $locale->text('Customer type') : $locale->text('Vendor type');
+ push @options, $vc_type_label . " : " . SL::DB::Business->new(id => $form->{business_id})->load->description;
+ }
if ($form->{transaction_description}) {
push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
}
push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{reqdatefrom}, 1) if $form->{reqdatefrom};
push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{reqdateto}, 1) if $form->{reqdateto};
};
+ if ( $form->{insertdatefrom} or $form->{insertdateto} ) {
+ push @options, $locale->text('Insert Date');
+ push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{insertdatefrom}, 1) if $form->{insertdatefrom};
+ push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{insertdateto}, 1) if $form->{insertdateto};
+ };
if ($form->{open}) {
push @options, $locale->text('Open');
}
}
}
}
- map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"} } qw(ship qty sellprice listprice lastcost basefactor);
+ map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"} } qw(ship qty sellprice lastcost basefactor);
$form->{"donumber_$i"} = $form->{donumber};
$form->{"converted_from_delivery_order_items_id_$i"} = delete $form->{"delivery_order_items_id_$i"};
}
$form->{type} = "invoice";
# locale messages
- $main::locale = new Locale "$myconfig{countrycode}", "$script";
+ $main::locale = Locale->new("$myconfig{countrycode}", "$script");
$locale = $main::locale;
require "bin/mozilla/$form->{script}";
my $currency = $form->{currency};
invoice_links();
- if ($form->{ordnumber}) {
- require SL::DB::Order;
- if (my $order = SL::DB::Manager::Order->find_by(ordnumber => $form->{ordnumber})) {
- $order->load;
- $form->{orddate} = $order->transdate_as_date;
- $form->{$_} = $order->$_ for qw(payment_id salesman_id taxzone_id quonumber);
- }
- }
-
$form->{currency} = $currency;
$form->{exchangerate} = "";
$form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell);
}
delete $form->{form_details};
- $locale = new Locale "$myconfig{countrycode}", "$script";
+ $locale = Locale->new("$myconfig{countrycode}", "$script");
require "bin/mozilla/$form->{script}";