push @hidden_vars, qw(orderitems_id converted_from_orderitems_id converted_from_invoice_id);
}
if ($is_invoice) {
- push @hidden_vars, qw(invoice_id converted_from_orderitems_id converted_from_delivery_order_items_id);
+ push @hidden_vars, qw(invoice_id converted_from_orderitems_id converted_from_delivery_order_items_id converted_from_invoice_id);
}
if ($::form->{type} =~ /credit_note/) {
push @hidden_vars, qw(invoice_id converted_from_invoice_id);
map { $form->{"${_}_${i}"} = $form->format_amount(\%myconfig, $form->{"${_}_${i}"}) } qw(sellprice discount lastcost);
push @hidden_vars, grep { defined $form->{"${_}_${i}"} } qw(sellprice discount not_discountable price_factor_id lastcost);
push @hidden_vars, "stock_${stock_in_out}_sum_qty", "stock_${stock_in_out}";
- push @hidden_vars, qw(delivery_order_items_id converted_from_orderitems_id);
+ push @hidden_vars, qw(delivery_order_items_id converted_from_orderitems_id converted_from_delivery_order_items_id);
}
my @HIDDENS = map { value => $_}, (
print $::form->parse_html_template('io/select_item', { PREVIOUS_FORM => $previous_form,
MODE => $mode,
ITEM_LIST => \@item_list,
+ IS_ASSEMBLY => $mode eq 'IC',
IS_PURCHASE => $mode eq 'IS' });
$main::lxdebug->leave_sub();
}
sub item_selected {
+
+ # this function is used for adding parts to records (mode = IR/IS)
+ # and to assemblies (mode = IC)
+
$main::lxdebug->enter_sub();
my $form = $main::form;
my $id = delete($form->{select_item_id}) || croak 'Missing item selection ID';
my $i = $form->{ $mode eq 'IC' ? 'assembly_rows' : 'rowcount' };
+ if ( $mode eq 'IC' ) {
+ # assembly mode:
+ # the qty variables of the existing assembly items are all still formatted, so we parse them here (1 .. $i-1)
+ # including the qty of the just added part ($i)
+ $form->{"qty_$_"} = $form->parse_amount(\%myconfig, $form->{"qty_$_"}) for (1 .. $i);
+ };
+
$form->{"id_${i}"} = $id;
if ($mode eq 'IS') {
my $new_item = $form->{item_list}->[0] || croak "No item found for mode '${mode}' and ID '${id}'";
# if there was a price entered, override it
- my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+ my $sellprice;
+ unless ( $mode eq 'IC' ) {
+ $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+ };
my @new_fields =
qw(id partnumber description sellprice listprice inventory_accno
map { $form->{"${_}_$i"} = $new_item->{$_} } @new_fields;
- 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;
+ if (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;
- if ($best_price) {
- $::form->{"sellprice_$i"} = $best_price->price;
- $::form->{"active_price_source_$i"} = $best_price->source;
- }
+ if ($best_price) {
+ $::form->{"sellprice_$i"} = $best_price->price;
+ $::form->{"active_price_source_$i"} = $best_price->source;
+ }
- my $best_discount = $price_source->best_discount;
+ my $best_discount = $price_source->best_discount;
- if ($best_discount) {
- $::form->{"discount_$i"} = $best_discount->discount;
- $::form->{"active_discount_source_$i"} = $best_discount->source;
+ if ($best_discount) {
+ $::form->{"discount_$i"} = $best_discount->discount;
+ $::form->{"active_discount_source_$i"} = $best_discount->source;
+ }
}
-
$form->{"marge_price_factor_$i"} = $new_item->{price_factor};
if ($form->{"part_payment_id_$i"} ne "") {
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
qw(sellprice listprice weight);
+ # at this stage qty of newly added part needs to be have been parsed
$form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
if ($form->{"not_discountable_$i"}) {
$form->{old_employee_id} = $form->{employee_id};
$form->{old_salesman_id} = $form->{salesman_id};
- map { delete $form->{$_} } qw(id printed emailed queued);
+ # link doc invoice -> quotation (single id no multi mode)
+ $form->{convert_from_ar_ids} = delete $form->{id};
+
+ delete $form->{$_} foreach (qw(printed emailed queued));
my $buysell;
if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
$form->{title} = $locale->text('Add Purchase Order');
if ($form->{type} =~ /(sales|purchase)_order/) {
$form->{"converted_from_orderitems_id_$_"} = delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};
}
+ # link doc order -> quotation (single id no multi mode)
+ $form->{convert_from_oe_ids} = delete $form->{id};
+
if ($form->{second_run}) {
$form->{print_and_post} = 0;
}
- map { delete $form->{$_} } qw(id printed emailed queued);
+ delete $form->{$_} foreach (qw(printed emailed queued));
my $buysell;
if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
$form->{TEMPLATE_DRIVER_OPTIONS}->{variable_content_types} = {
longdescription => 'html',
partnotes => 'html',
+ notes => 'html',
};
}