";
-
+
map { print "\n$column_data{$_}" } @column_index;
print qq|
@@ -1408,8 +1900,7 @@ sub subtotal {
$lxdebug->leave_sub();
}
-
-sub save {
+sub save_and_close {
$lxdebug->enter_sub();
if ($form->{type} =~ /_order$/) {
@@ -1417,15 +1908,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 +1927,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 +1937,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,20 +1956,101 @@ sub save {
$numberfld = "rfqnumber";
$ordnumber = "quonumber";
}
-
+
$err = $locale->text('Cannot save quotation!');
-
+
+ }
+
+ # get new number in sequence if no number is given or if saveasnew was requested
+ if (!$form->{$ordnumber} || $form->{saveasnew}) {
+ $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
}
- $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld) unless $form->{$ordnumber};
-
- $form->redirect($form->{label}." $form->{$ordnumber} ".$locale->text('saved!')) if (OE->save(\%myconfig, \%$form));
+ relink_accounts();
+
+ $form->redirect(
+ $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
+ if (OE->save(\%myconfig, \%$form));
$form->error($err);
$lxdebug->leave_sub();
}
+sub save {
+ $lxdebug->enter_sub();
+ if ($form->{type} =~ /_order$/) {
+ $form->isblank("transdate", $locale->text('Order Date missing!'));
+ } 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});
+
+ &validate_items;
+
+ # if the name changed get new values
+ if (&check_name($form->{vc})) {
+ &update;
+ exit;
+ }
+
+ $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') {
+ $form->{label} = $locale->text('Sales Order');
+
+ $numberfld = "sonumber";
+ $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 {
+ $form->{label} = $locale->text('Request for Quotation');
+
+ $numberfld = "rfqnumber";
+ $ordnumber = "quonumber";
+ }
+
+ $err = $locale->text('Cannot save quotation!');
+
+ }
+
+ $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
+ unless $form->{$ordnumber};
+
+ relink_accounts();
+
+ OE->save(\%myconfig, \%$form);
+ $form->{simple_save} = 1;
+ if(!$form->{print_and_save}) {
+ set_headings("edit");
+ &update;
+ exit;
+ }
+ $lxdebug->leave_sub();
+}
sub delete {
$lxdebug->enter_sub();
@@ -1485,13 +2058,13 @@ sub delete {
$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 +2080,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 +2105,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!'));
@@ -1562,15 +2140,18 @@ sub invoice {
exit;
}
- ($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 +2159,24 @@ 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 '')) {
+ relink_accounts();
+ 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 +2186,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 +2213,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 +2287,7 @@ sub backorder_exchangerate {
}
$form->{title} = $locale->text('Add Exchangerate');
-
+
print qq|
{path}>
@@ -1699,15 +2304,15 @@ sub backorder_exchangerate {
@@ -1720,7 +2325,8 @@ sub backorder_exchangerate {
-
+
@@ -1728,43 +2334,43 @@ sub backorder_exchangerate {
|;
-
$lxdebug->leave_sub();
}
-
sub save_exchangerate {
$lxdebug->enter_sub();
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
- $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
- $form->save_exchangerate(\%myconfig, $form->{currency}, $form->{exchangeratedate}, $form->{exchangerate}, $form->{buysell});
-
+ $form->{exchangerate} =
+ $form->parse_amount(\%myconfig, $form->{exchangerate});
+ $form->save_exchangerate(\%myconfig, $form->{currency},
+ $form->{exchangeratedate},
+ $form->{exchangerate}, $form->{buysell});
+
&invoice;
$lxdebug->leave_sub();
}
-
sub create_backorder {
$lxdebug->enter_sub();
-
+
$form->{shipped} = 1;
-
+
# figure out if we need to create a backorder
# items aren't saved if qty != 0
for $i (1 .. $form->{rowcount}) {
- $totalqty += $qty = $form->{"qty_$i"};
+ $totalqty += $qty = $form->{"qty_$i"};
$totalship += $ship = $form->{"ship_$i"};
-
+
$form->{"qty_$i"} = $qty - $ship;
}
if ($totalship == 0) {
map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
$form->{ordtotal} = 0;
- $form->{shipped} = 0;
+ $form->{shipped} = 0;
return;
}
@@ -1774,17 +2380,23 @@ sub create_backorder {
return;
}
- @flds = (qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup));
+ @flds = (
+ qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
+ );
for $i (1 .. $form->{rowcount}) {
- map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(sellprice discount);
+ map {
+ $form->{"${_}_$i"} =
+ $form->format_amount(\%myconfig, $form->{"${_}_$i"})
+ } qw(sellprice discount);
}
+ relink_accounts();
OE->save(\%myconfig, \%$form);
-
+
# rebuild rows for invoice
- @a = ();
+ @a = ();
$count = 0;
for $i (1 .. $form->{rowcount}) {
@@ -1797,97 +2409,102 @@ sub create_backorder {
$count++;
}
}
-
+
$form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
$form->{rowcount} = $count;
-
+
$lxdebug->leave_sub();
}
-
-
sub save_as_new {
$lxdebug->enter_sub();
$form->{saveasnew} = 1;
- $form->{closed} = 0;
- map { delete $form->{$_} } qw(printed emailed queued);
+ $form->{closed} = 0;
+ map { delete $form->{$_} } qw(printed emailed queued ordnumber quonumber);
&save;
$lxdebug->leave_sub();
}
-
sub purchase_order {
$lxdebug->enter_sub();
-
+
+ if ( $form->{type} eq 'sales_quotation'
+ || $form->{type} eq 'request_quotation') {
+ $form->{closed} = 1;
+ relink_accounts();
+ OE->save(\%myconfig, \%$form);
+ }
+
+ $form->{cp_id} *= 1;
+
$form->{title} = $locale->text('Add Purchase Order');
- $form->{vc} = "vendor";
- $form->{type} = "purchase_order";
-
+ $form->{vc} = "vendor";
+ $form->{type} = "purchase_order";
+
&poso;
-
+
$lxdebug->leave_sub();
}
-
sub sales_order {
$lxdebug->enter_sub();
-
- if ($form->{type} eq 'sales_quotation'|| $form->{type} eq 'request_quotation') {
+ if ( $form->{type} eq 'sales_quotation'
+ || $form->{type} eq 'request_quotation') {
$form->{closed} = 1;
- OE->save(\%myconfig, \%$form);
+ relink_accounts();
+ OE->save(\%myconfig, \%$form);
}
-
- ($null, $form->{cp_id}) = split /--/, $form->{contact};
+
$form->{cp_id} *= 1;
-
+
$form->{title} = $locale->text('Add Sales Order');
- $form->{vc} = "customer";
- $form->{type} = "sales_order";
-
+ $form->{vc} = "customer";
+ $form->{type} = "sales_order";
+
&poso;
-
+
$lxdebug->leave_sub();
}
-
sub poso {
$lxdebug->enter_sub();
-
-
+
$form->{transdate} = $form->current_date(\%myconfig);
delete $form->{duedate};
-
+
$form->{closed} = 0;
# reset
- map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
-
+ map { delete $form->{$_} }
+ qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
+
&order_links;
&prepare_order;
# format amounts
for $i (1 .. $form->{rowcount} - 1) {
- map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
+ map { $form->{"${_}_$i"} =~ s/\"/"/g }
+ qw(partnumber description unit);
}
- map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") } qw(creditlimit creditremaining);
+ map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
+ qw(creditlimit creditremaining);
&update;
$lxdebug->leave_sub();
}
-
sub ship_receive {
$lxdebug->enter_sub();
&order_links;
-
+
&prepare_order;
OE->get_warehouses(\%myconfig, \%$form);
@@ -1896,7 +2513,8 @@ sub ship_receive {
if (@{ $form->{all_warehouses} }) {
$form->{selectwarehouse} = " |
$department