-#=====================================================================
+# #=====================================================================
# LX-Office ERP
# Copyright (C) 2004
# Based on SQL-Ledger Version 2.1.9
# Order entry module
# Quotation module
#======================================================================
+use Data::Dumper;
use SL::OE;
use SL::IR;
sub edit {
$lxdebug->enter_sub();
+ # editing without stuff to edit? try adding it first
+ if ($form->{rowcount}) {
+ map { $id++ if $form->{"id_$_"} } (1 .. $form->{rowcount});
+ if (!$id) {
+
+ # reset rowcount
+ undef $form->{rowcount};
+ &add;
+ return;
+ }
+ } else {
+ if (!$form->{id}) {
+ &add;
+ return;
+ }
+ }
+
if ($form->{type} eq 'purchase_order') {
$form->{title} = $locale->text('Edit Purchase Order');
$form->{heading} = $locale->text('Purchase Order');
# retrieve order/quotation
$form->{webdav} = $webdav;
-
# set jscalendar
$form->{jscalendar} = $jscalendar;
OE->retrieve(\%myconfig, \%$form);
+ # if multiple rowcounts (== collective order) then check if the
+ # there were more than one customer (in that case OE::retrieve removes
+ # the content from the field)
+ if ( $form->{rowcount}
+ && $form->{type} eq 'sales_order'
+ && defined $form->{customer}
+ && $form->{customer} eq '') {
+
+ # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
+ $form->error(
+ $locale->text(
+ 'Collective Orders only work for orders from one customer!')
+ );
+ }
+
$taxincluded = $form->{taxincluded};
$form->{shipto} = 1 if $form->{id};
# get customer / vendor
if ($form->{type} =~ /(purchase_order|request_quotation|receive_order)/) {
IR->get_vendor(\%myconfig, \%$form);
+
+ #quote all_vendor Bug 133
+ foreach $ref (@{ $form->{all_vendor} }) {
+ $ref->{name} = $form->quote($ref->{name});
+ }
+
}
if ($form->{type} =~ /(sales|ship)_(order|quotation)/) {
IS->get_customer(\%myconfig, \%$form);
+
+ #quote all_vendor Bug 133
+ foreach $ref (@{ $form->{all_customer} }) {
+ $ref->{name} = $form->quote($ref->{name});
+ }
+
}
$form->{cp_id} = $cp_id;
sub prepare_order {
$lxdebug->enter_sub();
- $form->{format} = "html";
+ $form->{format} = "pdf";
$form->{media} = "screen";
$form->{formname} = $form->{type};
- if ($form->{id}) {
+ map { $form->{$_} =~ s/\"/"/g }
+ qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact);
- map { $form->{$_} =~ s/\"/"/g }
- qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact);
+ foreach $ref (@{ $form->{form_details} }) {
+ $form->{rowcount} = ++$i;
- foreach $ref (@{ $form->{form_details} }) {
- $i++;
- map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
+ map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
+ }
+ for my $i (1 .. $form->{rowcount}) {
+ if ($form->{id}) {
$form->{"discount_$i"} =
$form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $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"});
-
- map { $form->{"${_}_$i"} =~ s/\"/"/g }
- qw(partnumber description unit);
- $form->{rowcount} = $i;
+ } else {
+ $form->{"discount_$i"} =
+ $form->format_amount(\%myconfig, $form->{"discount_$i"});
}
- } elsif ($form->{rowcount}) {
- for my $i (1 .. $form->{rowcount}) {
- $form->{"discount_$i"} =
- $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
+ ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+ $dec = length $dec;
+ $decimalplaces = ($dec > 2) ? $dec : 2;
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
+ # copy reqdate from deliverydate for invoice -> order conversion
+ $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
+ unless $form->{"reqdate_$i"};
- $form->{"sellprice_$i"} =
- $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
- $decimalplaces);
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ $form->{"sellprice_$i"} =
+ $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
+ $decimalplaces);
- map { $form->{"${_}_$i"} =~ s/\"/"/g }
- qw(partnumber description unit);
- }
+ (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);
}
$lxdebug->leave_sub();
s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
}
+ #quote select[customer|vendor] Bug 133
+ $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
+
#build contacts
if ($form->{all_contacts}) {
. $locale->text('Save as new') . qq|">
<input class=submit type=submit name=action value="|
. $locale->text('Delete') . qq|">|;
- if ($form->{type} =~ /quotation$/) {
+ if ($form->{type} =~ /sales_quotation$/) {
+ print qq|
+<input class=submit type=submit name=action value="|
+ . $locale->text('Sales Order') . qq|">|;
+ }
+ if ($form->{type} =~ /request_quotation$/) {
print qq|
<input class=submit type=submit name=action value="|
- . $locale->text('Order') . qq|">|;
+ . $locale->text('Purchase Order') . qq|">|;
}
print qq|
<input class=submit type=submit name=action value="|
. $locale->text('Order') . qq|">
|;
}
+ } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount}) {
+ print qq|
+<br>Workflow $form->{heading}<br>
+<input class=submit type=submit name=action value="|
+ . $locale->text('Save as new') . qq|">
+<input class=submit type=submit name=action value="|
+ . $locale->text('Invoice') . qq|">
+|;
}
if ($form->{menubar}) {
} else {
$form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
+
# if there is an exchange rate adjust sellprice
$form->{"sellprice_$i"} /= $exchangerate;
}
$form->format_amount(\%myconfig, $form->{"sellprice_$i"},
$decimalplaces);
$form->{"qty_$i"} =
- $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
# get pricegroups for parts
IS->get_pricegroups_for_parts(\%myconfig, \%$form);
}
}
-
$lxdebug->leave_sub();
}
}
}
+ # only show checkboxes if gotten here via sales_order form.
+ if ($form->{type} =~ /sales_order/) {
+ unshift @column_index, "ids";
+ }
+
if ($form->{l_subtotal} eq 'Y') {
$callback .= "&l_subtotal=Y";
$href .= "&l_subtotal=Y";
$column_header{employee} =
qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
+ $column_header{ids} = qq|<th></th>|;
+
if ($form->{ $form->{vc} }) {
$option = $locale->text(ucfirst $form->{vc});
$option .= " : $form->{$form->{vc}}";
print qq|
<body>
+<form method="post" action="oe.pl">
<table width=100%>
<tr>
<th class=listtop>$form->{title}</th>
|;
# add sort and escape callback
- $callback = $form->escape($callback . "&sort=$form->{sort}");
+ $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
if (@{ $form->{OE} }) {
$sameitem = $form->{OE}->[0]->{ $form->{sort} };
$warehouse = $form->escape($form->{warehouse});
foreach $oe (@{ $form->{OE} }) {
+ $form->{rowcount} = ++$j;
if ($form->{l_subtotal} eq 'Y') {
if ($sameitem ne $oe->{ $form->{sort} }) {
$subtotalnetamount += $oe->{netamount};
$subtotalamount += $oe->{amount};
+ $column_data{ids} =
+ qq|<td><input name="id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
$column_data{id} = "<td>$oe->{id}</td>";
$column_data{transdate} = "<td>$oe->{transdate} </td>";
$column_data{reqdate} = "<td>$oe->{reqdate} </td>";
$column_data{$ordnumber} =
- "<td><a href=oe.pl?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback>$oe->{$ordnumber}</a></td>";
+ "<td><a href=oe.pl?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
$column_data{name} = "<td>$oe->{name}</td>";
$column_data{employee} = "<td>$oe->{employee} </td>";
<tr>
<td><hr size=3 noshade></td>
</tr>
-</table>
+</table>|;
+
+ # multiple invoice edit button only if gotten there via sales_order form.
+
+ if ($form->{type} =~ /sales_order/) {
+ print qq|
+ <input type="hidden" name="path" value="$form->{path}">
+ <input class"submit" type="submit" name="action" value="|
+ . $locale->text('Continue') . qq|">
+ <input type="hidden" name="nextsub" value="edit">
+ <input type="hidden" name="type" value="$form->{type}">
+ <input type="hidden" name="warehouse" value="$warehouse">
+ <input type="hidden" name="vc" value="$form->{vc}">
+ <input type="hidden" name="login" value="$form->{login}">
+ <input type="hidden" name="password" value="$form->{password}">
+ <input type="hidden" name="callback" value="$callback">
+ <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
+ }
+
+ print qq|
+</form>
<br>
<form method=post action=$form->{script}>
}
- $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
- unless $form->{$ordnumber};
+ # get new number in sequence if no number is given or if saveasnew was requested
+ if (!$form->{$ordumber} || $form->{saveasnew}) {
+ $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
+ }
$form->redirect(
$form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
$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!'));
# 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} =
$dec = length $dec;
$decimalplaces = ($dec > 2) ? $dec : 2;
+ # 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);
- $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
+
+ (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);
sub purchase_order {
$lxdebug->enter_sub();
+ if ( $form->{type} eq 'sales_quotation'
+ || $form->{type} eq 'request_quotation') {
+ $form->{closed} = 1;
+ OE->save(\%myconfig, \%$form);
+ }
+
+ ($null, $form->{cp_id}) = split /--/, $form->{contact};
+ $form->{cp_id} *= 1;
+
$form->{title} = $locale->text('Add Purchase Order');
$form->{vc} = "vendor";
$form->{type} = "purchase_order";
qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|;
$column_data{qty} =
qq|<td align=right>|
- . $form->format_amount(\%myconfig, $form->{"qty_$i"})
+ . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty)
. qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></td>|;
$column_data{ship} =
qq|<td align=right><input name="ship_$i" size=5 value=|
qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse} </td>|;
$column_data{qty} =
qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|
- . $form->format_amount(\%myconfig, $ref->{qty})
+ . $form->format_amount(\%myconfig, $ref->{qty}, $dec_qty)
. qq|</td>|;
$column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;