";
-
+
map { print "\n$column_data{$_}" } @column_index;
print qq|
@@ -1408,7 +1677,6 @@ sub subtotal {
$lxdebug->leave_sub();
}
-
sub save {
$lxdebug->enter_sub();
@@ -1417,15 +1685,16 @@ sub save {
} else {
$form->isblank("transdate", $locale->text('Quotation Date missing!'));
}
-
+
$msg = ucfirst $form->{vc};
$form->isblank($form->{vc}, $locale->text($msg . " missing!"));
-# $locale->text('Customer missing!');
-# $locale->text('Vendor missing!');
-
- $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
-
+ # $locale->text('Customer missing!');
+ # $locale->text('Vendor missing!');
+
+ $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
+ if ($form->{currency} ne $form->{defaultcurrency});
+
&validate_items;
# if the name changed get new values
@@ -1435,7 +1704,7 @@ sub save {
}
$form->{id} = 0 if $form->{saveasnew};
-
+
# this is for the internal notes section for the [email] Subject
if ($form->{type} =~ /_order$/) {
if ($form->{type} eq 'sales_order') {
@@ -1445,17 +1714,17 @@ sub save {
$ordnumber = "ordnumber";
} else {
$form->{label} = $locale->text('Purchase Order');
-
+
$numberfld = "ponumber";
$ordnumber = "ordnumber";
}
$err = $locale->text('Cannot save order!');
-
+
} else {
if ($form->{type} eq 'sales_quotation') {
$form->{label} = $locale->text('Quotation');
-
+
$numberfld = "sqnumber";
$ordnumber = "quonumber";
} else {
@@ -1464,34 +1733,35 @@ sub save {
$numberfld = "rfqnumber";
$ordnumber = "quonumber";
}
-
+
$err = $locale->text('Cannot save quotation!');
-
+
}
- $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld) unless $form->{$ordnumber};
-
- $form->redirect($form->{label}." $form->{$ordnumber} ".$locale->text('saved!')) if (OE->save(\%myconfig, \%$form));
+ $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
+ unless $form->{$ordnumber};
+
+ $form->redirect(
+ $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
+ if (OE->save(\%myconfig, \%$form));
$form->error($err);
$lxdebug->leave_sub();
}
-
-
sub delete {
$lxdebug->enter_sub();
$form->header;
if ($form->{type} =~ /_order$/) {
- $msg = $locale->text('Are you sure you want to delete Order Number');
+ $msg = $locale->text('Are you sure you want to delete Order Number');
$ordnumber = 'ordnumber';
} else {
$msg = $locale->text('Are you sure you want to delete Quotation Number');
$ordnumber = 'quonumber';
}
-
+
print qq|
@@ -1507,23 +1777,21 @@ sub delete {
}
print qq|
-|.$locale->text('Confirm!').qq|
+| . $locale->text('Confirm!') . qq|
$msg $form->{$ordnumber}
-
+
|;
-
$lxdebug->leave_sub();
}
-
-
sub yes {
$lxdebug->enter_sub();
@@ -1534,22 +1802,29 @@ sub yes {
$msg = $locale->text('Quotation deleted!');
$err = $locale->text('Cannot delete quotation!');
}
-
+
$form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool));
$form->error($err);
$lxdebug->leave_sub();
}
-
-
sub invoice {
$lxdebug->enter_sub();
-
+
if ($form->{type} =~ /_order$/) {
- $form->isblank("ordnumber", $locale->text('Order Number missing!'));
- $form->isblank("transdate", $locale->text('Order Date missing!'));
+ # these checks only apply if the items don't bring their own ordnumbers/transdates.
+ # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
+ $form->isblank("ordnumber", $locale->text('Order Number missing!'))
+ if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
+ ->{''});
+ $form->isblank("transdate", $locale->text('Order Date missing!'))
+ if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
+ ->{''});
+
+ # also copy deliverydate from the order
+ $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
} else {
$form->isblank("quonumber", $locale->text('Quotation Number missing!'));
$form->isblank("transdate", $locale->text('Quotation Date missing!'));
@@ -1564,13 +1839,17 @@ sub invoice {
($null, $form->{cp_id}) = split /--/, $form->{contact};
$form->{cp_id} *= 1;
-
- if ($form->{type} =~ /_order/ && $form->{currency} ne $form->{defaultcurrency}) {
+
+ if ( $form->{type} =~ /_order/
+ && $form->{currency} ne $form->{defaultcurrency}) {
+
# check if we need a new exchangerate
$buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
-
- $orddate = $form->current_date(\%myconfig);
- $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate, $buysell);
+
+ $orddate = $form->current_date(\%myconfig);
+ $exchangerate =
+ $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
+ $buysell);
if (!$exchangerate) {
&backorder_exchangerate($orddate, $buysell);
@@ -1578,16 +1857,23 @@ sub invoice {
}
}
-
# close orders/quotations
$form->{closed} = 1;
- OE->save(\%myconfig, \%$form);
+ # save order if one ordnumber has been given
+ # if not it's most likely a collective order, which can't be saved back
+ # so they just have to be closed
+ if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
+ OE->save(\%myconfig, \%$form);
+ } else {
+ OE->close_orders(\%myconfig, \%$form);
+ }
$form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
- $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
-
- $form->{id} = '';
+ $form->{duedate} =
+ $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+
+ $form->{id} = '';
$form->{closed} = 0;
$form->{rowcount}--;
$form->{shipto} = 1;
@@ -1597,26 +1883,26 @@ sub invoice {
&create_backorder;
}
-
- if ($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation') {
- $form->{title} = $locale->text('Add Vendor Invoice');
+ if ( $form->{type} eq 'purchase_order'
+ || $form->{type} eq 'request_quotation') {
+ $form->{title} = $locale->text('Add Vendor Invoice');
$form->{script} = 'ir.pl';
- $script = "ir";
- $buysell = 'sell';
+ $script = "ir";
+ $buysell = 'sell';
}
if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
- $form->{title} = $locale->text('Add Sales Invoice');
+ $form->{title} = $locale->text('Add Sales Invoice');
$form->{script} = 'is.pl';
- $script = "is";
- $buysell = 'buy';
+ $script = "is";
+ $buysell = 'buy';
}
-
-
+
# bo creates the id, reset it
- map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);
- $form->{$form->{vc}} =~ s/--.*//g;
+ map { delete $form->{$_} }
+ qw(id subject message cc bcc printed emailed queued);
+ $form->{ $form->{vc} } =~ s/--.*//g;
$form->{type} = "invoice";
-
+
# locale messages
$locale = new Locale "$myconfig{countrycode}", "$script";
@@ -1624,43 +1910,59 @@ sub invoice {
map { $form->{"select$_"} = "" } ($form->{vc}, currency);
- map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(creditlimit creditremaining);
+ map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+ qw(creditlimit creditremaining);
$currency = $form->{currency};
&invoice_links;
- $form->{currency} = $currency;
+ $form->{currency} = $currency;
$form->{exchangerate} = "";
- $form->{forex} = "";
- $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, $buysell)));
-
+ $form->{forex} = "";
+ $form->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate =
+ $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{invdate}, $buysell
+ )));
+
$form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
&prepare_invoice;
# format amounts
for $i (1 .. $form->{rowcount}) {
- $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
-
+ $form->{"discount_$i"} =
+ $form->format_amount(\%myconfig, $form->{"discount_$i"});
+
($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
+ $dec = length $dec;
$decimalplaces = ($dec > 2) ? $dec : 2;
- $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ # copy delivery date from reqdate for order -> invoice conversion
+ $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
+ unless $form->{"deliverydate_$i"};
+
+ $form->{"sellprice_$i"} =
+ $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
+ $decimalplaces);
+
+ (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
+ $dec_qty = length $dec_qty;
+ $form->{"qty_$i"} =
+ $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
+
+ map { $form->{"${_}_$i"} =~ s/\"/"/g }
+ qw(partnumber description unit);
- map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
-
}
-
&display_form;
$lxdebug->leave_sub();
}
-
-
sub backorder_exchangerate {
$lxdebug->enter_sub();
my ($orddate, $buysell) = @_;
@@ -1682,7 +1984,7 @@ sub backorder_exchangerate {
}
$form->{title} = $locale->text('Add Exchangerate');
-
+
print qq|
{path}>
@@ -1699,15 +2001,15 @@ sub backorder_exchangerate {
@@ -1720,7 +2022,8 @@ sub backorder_exchangerate {
-
+
@@ -1728,43 +2031,43 @@ sub backorder_exchangerate {
|