X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Foe.pl;h=10e71ac17ae2e3365e226536d55f492c3462607d;hb=7804fab3bb495ddedd90159071c51b35a7e603ce;hp=cf6bd40b2f4f5b13190d7f8f5752ee11588332c0;hpb=e44cbe168d7cdaedc952a23102d8c834bd3a2993;p=kivitendo-erp.git diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index cf6bd40b2..10e71ac17 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -1,4 +1,4 @@ -#===================================================================== +# #===================================================================== # LX-Office ERP # Copyright (C) 2004 # Based on SQL-Ledger Version 2.1.9 @@ -30,6 +30,7 @@ # Order entry module # Quotation module #====================================================================== +use Data::Dumper; use SL::OE; use SL::IR; @@ -43,26 +44,59 @@ require "$form->{path}/arap.pl"; # end of main -sub add { +# For locales.pl: +# $locale->text('Edit the purchase_order'); +# $locale->text('Edit the sales_order'); +# $locale->text('Edit the request_quotation'); +# $locale->text('Edit the sales_quotation'); + +# $locale->text('Workflow purchase_order'); +# $locale->text('Workflow sales_order'); +# $locale->text('Workflow request_quotation'); +# $locale->text('Workflow sales_quotation'); + +sub set_headings { $lxdebug->enter_sub(); + my ($action) = @_; + if ($form->{type} eq 'purchase_order') { - $form->{title} = $locale->text('Add Purchase Order'); - $form->{vc} = 'vendor'; + $form->{title} = $action eq "edit" ? + $locale->text('Edit Purchase Order') : + $locale->text('Add Purchase Order'); + $form->{heading} = $locale->text('Purchase Order'); + $form->{vc} = 'vendor'; } if ($form->{type} eq 'sales_order') { - $form->{title} = $locale->text('Add Sales Order'); - $form->{vc} = 'customer'; + $form->{title} = $action eq "edit" ? + $locale->text('Edit Sales Order') : + $locale->text('Add Sales Order'); + $form->{heading} = $locale->text('Sales Order'); + $form->{vc} = 'customer'; } if ($form->{type} eq 'request_quotation') { - $form->{title} = $locale->text('Add Request for Quotation'); - $form->{vc} = 'vendor'; + $form->{title} = $action eq "edit" ? + $locale->text('Edit Request for Quotation') : + $locale->text('Add Request for Quotation'); + $form->{heading} = $locale->text('Request for Quotation'); + $form->{vc} = 'vendor'; } if ($form->{type} eq 'sales_quotation') { - $form->{title} = $locale->text('Add Quotation'); - $form->{vc} = 'customer'; + $form->{title} = $action eq "edit" ? + $locale->text('Edit Quotation') : + $locale->text('Add Quotation'); + $form->{heading} = $locale->text('Quotation'); + $form->{vc} = 'customer'; } + $lxdebug->leave_sub(); +} + +sub add { + $lxdebug->enter_sub(); + + set_headings("add"); + $form->{callback} = "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}" unless $form->{callback}; @@ -77,29 +111,42 @@ sub add { sub edit { $lxdebug->enter_sub(); - if ($form->{type} eq 'purchase_order') { - $form->{title} = $locale->text('Edit Purchase Order'); - $form->{heading} = $locale->text('Purchase Order'); - $form->{vc} = 'vendor'; - } - if ($form->{type} eq 'sales_order') { - $form->{title} = $locale->text('Edit Sales Order'); - $form->{heading} = $locale->text('Sales Order'); - $form->{vc} = 'customer'; - } - if ($form->{type} eq 'request_quotation') { - $form->{title} = $locale->text('Edit Request for Quotation'); - $form->{heading} = $locale->text('Request for Quotation'); - $form->{vc} = 'vendor'; + $form->{simple_save} = 0; + + set_headings("edit"); + + # 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 'sales_quotation') { - $form->{title} = $locale->text('Edit Quotation'); - $form->{heading} = $locale->text('Quotation'); - $form->{vc} = 'customer'; + + if ($form->{print_and_save}) { + $form->{action} = "print"; + $form->{resubmit} = 1; + $language_id = $form->{language_id}; + $printer_id = $form->{printer_id}; } + set_headings("edit"); + &order_links; &prepare_order; + if ($form->{print_and_save}) { + $form->{language_id} = $language_id; + $form->{printer_id} = $printer_id; + } &display_form; $lxdebug->leave_sub(); @@ -114,13 +161,37 @@ sub order_links { # retrieve order/quotation $form->{webdav} = $webdav; - - # set jscalendar $form->{jscalendar} = $jscalendar; OE->retrieve(\%myconfig, \%$form); + if ($form->{payment_id}) { + $payment_id = $form->{payment_id}; + } + if ($form->{language_id}) { + $language_id = $form->{language_id}; + } + if ($form->{taxzone_id}) { + $taxzone_id = $form->{taxzone_id}; + } + + + # 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}; @@ -136,12 +207,32 @@ sub order_links { # 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; - + if ($payment_id) { + $form->{payment_id} = $payment_id; + } + if ($language_id) { + $form->{language_id} = $language_id; + } + if ($taxzone_id) { + $form->{taxzone_id} = $taxzone_id; + } $form->{intnotes} = $intnotes; ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} }; $form->{"old$form->{vc}"} = @@ -156,7 +247,7 @@ sub order_links { } # currencies - @curr = split /:/, $form->{currencies}; + @curr = split(/:/, $form->{currencies}); chomp $curr[0]; $form->{defaultcurrency} = $curr[0]; $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; @@ -193,58 +284,41 @@ sub order_links { sub prepare_order { $lxdebug->enter_sub(); - $form->{format} = "html"; - $form->{media} = "screen"; - $form->{formname} = $form->{type}; + $form->{formname} = $form->{type} unless $form->{formname}; - if ($form->{id}) { + my $i = 0; + foreach $ref (@{ $form->{form_details} }) { + $form->{rowcount} = ++$i; - map { $form->{$_} =~ s/\"/"/g } - qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact); - - 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); - - (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); - $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); - - (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/); - $dec_qty = length $dec_qty; - $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); + $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(); @@ -253,13 +327,26 @@ sub prepare_order { sub form_header { $lxdebug->enter_sub(); - $checkedopen = ($form->{closed}) ? "" : "checked"; - $checkedclosed = ($form->{closed}) ? "checked" : ""; + my $checkedclosed = $form->{"closed"} ? "checked" : ""; + my $checkeddelivered = $form->{"delivered"} ? "checked" : ""; + + map { $form->{$_} =~ s/\"/"/g } + qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname + shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact + shiptophone shiptofax shiptodepartment_1 shiptodepartment_2); # use JavaScript Calendar or not $form->{jsscript} = $form->{jscalendar}; $jsscript = ""; + $payment = qq||; + foreach $item (@{ $form->{payment_terms} }) { + if ($form->{payment_id} eq $item->{id}) { + $payment .= qq||; + } else { + $payment .= qq||; + } + } if ($form->{jsscript}) { # with JavaScript Calendar @@ -292,43 +379,92 @@ sub form_header { $openclosed = qq| - - - - - -
| - . $locale->text('Open') . qq| | - . $locale->text('Closed') . qq|
- + + +|; + + if (($form->{"type"} eq "sales_order") || + ($form->{"type"} eq "purchase_order")) { + $openclosed .= qq| + + +|; + } + + $openclosed .= qq| + |; } # set option selected - foreach $item ($form->{vc}, currency, department, employee, contact) { + foreach $item ($form->{vc}, currency, department, employee) { $form->{"select$item"} =~ s/ selected//; $form->{"select$item"} =~ 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}) { - $form->{selectcontact} = ""; + $form->{selectcontact} = ""; foreach $item (@{ $form->{all_contacts} }) { + my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : ""; if ($form->{cp_id} == $item->{cp_id}) { $form->{selectcontact} .= - ""; + } else { + $form->{selectcontact} .= ""; + } + } + } else { + $form->{selectcontact} =~ s/ selected//g; + if ($form->{cp_id} ne "") { + $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/; + } + } + + + if (@{ $form->{SHIPTO} }) { + $form->{selectshipto} = ""; + foreach $item (@{ $form->{SHIPTO} }) { + if ($item->{shipto_id} == $form->{shipto_id}) { + $form->{selectshipto} .= + ""; } else { - $form->{selectcontact} .= ""; } + + } + } else { + $form->{selectshipto} = $form->unquote($form->{selectshipto}); + $form->{selectshipto} =~ s/ selected//g; + if ($form->{shipto_id} ne "") { + $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/; } } + $shipto = qq| + | . $locale->text('Shipping Address') . qq| + |; + $form->{selectshipto} = $form->quote($form->{selectshipto}); + $shipto .= qq| |; + + + $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); + if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) { + $creditwarning = 1; + } else { + $creditwarning = 0; + } + $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); $form->{creditremaining} = @@ -336,7 +472,7 @@ sub form_header { $contact = ($form->{selectcontact}) - ? qq|\n| + ? qq|\n| : qq||; $exchangerate = qq| @@ -362,13 +498,7 @@ sub form_header { $vclabel = ucfirst $form->{vc}; $vclabel = $locale->text($vclabel); - $terms = qq| - - | . $locale->text('Terms: Net') . qq| - {terms}> | - . $locale->text('days') . qq| - -|; + if ($form->{business}) { $business = qq| @@ -383,6 +513,53 @@ sub form_header { |; } + if ($form->{max_dunning_level}) { + $dunning = qq| + + + + + + + + + +
| . $locale->text('Max. Dunning Level') . qq|:$form->{max_dunning_level}| . $locale->text('Dunning Amount') . qq|:| + . $form->format_amount(\%myconfig, $form->{dunning_amount},2) + . qq|
+ + +|; + } + + if (@{ $form->{TAXZONE} }) { + $form->{selecttaxzone} = ""; + foreach $item (@{ $form->{TAXZONE} }) { + if ($item->{id} == $form->{taxzone_id}) { + $form->{selecttaxzone} .= + ""; + } else { + $form->{selecttaxzone} .= + ""; + } + + } + } else { + $form->{selecttaxzone} =~ s/ selected//g; + if ($form->{taxzone_id} ne "") { + $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}>/value=$form->{taxzone_id} selected>/; + } + } + + $taxzone = qq| + + | . $locale->text('Steuersatz') . qq| + + + |; + + if ($form->{type} !~ /_quotation$/) { $ordnumber = qq| @@ -422,10 +599,11 @@ sub form_header { $form->{creditlimit} | . $locale->text('Remaining') . qq| - $form->{creditremaining} + $form->{creditremaining} + $shipto |; } else { @@ -451,7 +629,6 @@ sub form_header { |; - $terms = ""; } $ordnumber .= qq| @@ -464,7 +641,10 @@ sub form_header { $button2 |; - + $creditremaining = qq| + + $shipto + |; } $vc = @@ -508,20 +688,41 @@ sub form_header { |; } + if ($form->{resubmit} && ($form->{format} eq "html")) { + $onload = + qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|; + } elsif ($form->{resubmit}) { + $onload = qq|document.oe.submit()|; + } else { + $onload = "fokus()"; + } + + $credittext = $locale->text('Credit Limit exceeded!!!'); + if ($creditwarning) { + $onload = qq|alert('$credittext')|; + } + + $form->{"javascript"} .= qq||; $form->header; print qq| - + -
{script}> +{script}> + + + + {id}> +{action}> {type}> {formname}> {media}> {format}> +{proforma}> @@ -561,6 +762,8 @@ sub form_header { $creditremaining $business + $dunning + $taxzone $department | . $locale->text('Currency') . qq| @@ -576,15 +779,34 @@ sub form_header { | . $locale->text('Ship via') . qq| - - + |; +# +# +# +# +# +# +# +# +# +# +# +#
+# +# +#
+# +# +#
+# +# +print qq| $openclosed $employee $ordnumber - $terms
@@ -604,6 +826,8 @@ $jsscript + + @@ -739,6 +963,9 @@ sub form_footer { $notes $intnotes + | . $locale->text('Payment Terms') . qq| + @@ -805,8 +1032,8 @@ sub form_footer { -Bearbeiten des $form->{heading}
-{type}") . qq|
+ @@ -816,24 +1043,33 @@ Bearbeiten des $form->{heading}
. $locale->text('E-mail') . qq|"> + |; - if ($form->{id}) { + if (($form->{id})) { print qq| -
Workflow $form->{heading}
+
| . $locale->text("Workflow $form->{type}") . qq|
|; - if ($form->{type} =~ /quotation$/) { + if (($form->{type} =~ /sales_quotation$/)) { print qq| |; + . $locale->text('Sales Order') . qq|">|; } + if ($form->{type} =~ /request_quotation$/) { + print qq| +|; + } + if (1) { print qq| |; +} if ($form->{type} =~ /sales_order$/) { print qq| @@ -850,7 +1086,7 @@ Bearbeiten des $form->{heading}
+ . $locale->text('Request for Quotation') . qq|"> |; } else { @@ -860,11 +1096,14 @@ Bearbeiten des $form->{heading}
. $locale->text('Order') . qq|"> |; } - } - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; + } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) { + print qq| +
Workflow $form->{heading}
+ + +|; } print qq| @@ -888,8 +1127,11 @@ Bearbeiten des $form->{heading}
sub update { $lxdebug->enter_sub(); + set_headings($form->{"id"} ? "edit" : "add"); + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); + $form->{update} = 1; &check_name($form->{vc}); @@ -917,7 +1159,7 @@ sub update { $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid}); &check_form; - } else { + } else { if ( $form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation') { @@ -943,11 +1185,16 @@ sub update { } else { $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); - + if ($form->{"not_discountable_$i"}) { + $form->{"discount_$i"} = 0; + } map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit); map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; + if ($form->{"part_payment_id_$i"} ne "") { + $form->{payment_id} = $form->{"part_payment_id_$i"}; + } $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"}; @@ -960,6 +1207,7 @@ sub update { } else { $form->{"sellprice_$i"} *= (1 - $form->{tradediscount}); + # if there is an exchange rate adjust sellprice $form->{"sellprice_$i"} /= $exchangerate; } @@ -1002,7 +1250,7 @@ sub update { $form->{rowcount}--; $form->{"discount_$i"} = ""; &display_form; - } else { + } else { $form->{"id_$i"} = 0; $form->{"unit_$i"} = $locale->text('ea'); @@ -1013,7 +1261,6 @@ sub update { } } - $lxdebug->leave_sub(); } @@ -1140,6 +1387,19 @@ sub search { |; } + my $delivered; + if (($form->{"type"} eq "sales_order") || + ($form->{"type"} eq "purchase_order")) { + $delivered = qq| + + + + + + +|; + } + # use JavaScript Calendar or not $form->{jsscript} = $jscalendar; $jsscript = ""; @@ -1207,6 +1467,7 @@ sub search { $openclosed + $delivered @@ -1282,7 +1543,7 @@ sub orders { # construct href $href = - "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&$ordnumber=$number&$form->{vc}=$name&department=$department&warehouse=$warehouse"; + "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}¬delivered=$form->{notdelivered}&delivered=$form->{delivered}&$ordnumber=$number&$form->{vc}=$name&department=$department&warehouse=$warehouse"; # construct callback $number = $form->escape($form->{$ordnumber}, 1); @@ -1291,17 +1552,20 @@ sub orders { $warehouse = $form->escape($form->{warehouse}, 1); $callback = - "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&$ordnumber=$number&$form->{vc}=$name&department=$department&warehouse=$warehouse"; + "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}¬delivered=$form->{notdelivered}&delivered=$form->{delivered}&$ordnumber=$number&$form->{vc}=$name&department=$department&warehouse=$warehouse"; @columns = $form->sort_columns("transdate", "reqdate", "id", "$ordnumber", "name", "netamount", "tax", "amount", "curr", "employee", "shipvia", "open", - "closed"); + "closed", "delivered"); $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed}); + $form->{"l_delivered"} = "Y" + if ($form->{"delivered"} && $form->{"notdelivered"}); + foreach $item (@columns) { if ($form->{"l_$item"} eq "Y") { push @column_index, $item; @@ -1312,6 +1576,11 @@ sub orders { } } + # 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"; @@ -1360,7 +1629,9 @@ sub orders { . qq||; $column_header{quonumber} = qq||; $column_header{name} = qq||; @@ -1380,10 +1651,14 @@ sub orders { qq||; $column_header{closed} = qq||; + $column_header{"delivered"} = + qq||; $column_header{employee} = qq||; + $column_header{ids} = qq||; + if ($form->{ $form->{vc} }) { $option = $locale->text(ucfirst $form->{vc}); $option .= " : $form->{$form->{vc}}"; @@ -1423,6 +1698,7 @@ sub orders { print qq| +
| . $locale->text('ID') . qq|| - . $locale->text('Quotation') + . ($form->{"type"} eq "request_quotation" ? + $locale->text('RFQ') : + $locale->text('Quotation')) . qq|$name| . $locale->text('O') . qq|| . $locale->text('C') . qq|| . $locale->text("Delivered") . qq|$employee
@@ -1443,7 +1719,7 @@ sub orders { |; # 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} }; @@ -1455,6 +1731,7 @@ sub orders { $warehouse = $form->escape($form->{warehouse}); foreach $oe (@{ $form->{OE} }) { + $form->{rowcount} = ++$j; if ($form->{l_subtotal} eq 'Y') { if ($sameitem ne $oe->{ $form->{sort} }) { @@ -1483,12 +1760,14 @@ sub orders { $subtotalnetamount += $oe->{netamount}; $subtotalamount += $oe->{amount}; + $column_data{ids} = + qq||; $column_data{id} = ""; $column_data{transdate} = ""; $column_data{reqdate} = ""; $column_data{$ordnumber} = - ""; + ""; $column_data{name} = ""; $column_data{employee} = ""; @@ -1501,6 +1780,9 @@ sub orders { $column_data{closed} = ""; $column_data{open} = ""; } + $column_data{"delivered"} = ""; $i++; $i %= 2; @@ -1546,7 +1828,27 @@ sub orders { -
$form->{title}$oe->{id}$oe->{transdate} $oe->{reqdate} {path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback>$oe->{$ordnumber}{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}$oe->{name}$oe->{employee}  X" . + ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) . + "

+|; + + # multiple invoice edit button only if gotten there via sales_order form. + + if ($form->{type} =~ /sales_order/) { + print qq| + + + + + + + + + + |; + } + + print qq| +

{script}> @@ -1567,11 +1869,6 @@ sub orders { . $locale->text('Add') . qq|">|; } - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - print qq|
@@ -1615,7 +1912,7 @@ sub subtotal { $lxdebug->leave_sub(); } -sub save { +sub save_and_close { $lxdebug->enter_sub(); if ($form->{type} =~ /_order$/) { @@ -1676,8 +1973,12 @@ sub save { } - $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->{$ordnumber} || $form->{saveasnew}) { + $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld); + } + + relink_accounts(); $form->redirect( $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!')) @@ -1687,6 +1988,82 @@ sub save { $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(); @@ -1751,9 +2128,18 @@ 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!')); @@ -1766,9 +2152,15 @@ sub invoice { exit; } - ($null, $form->{cp_id}) = split /--/, $form->{contact}; $form->{cp_id} *= 1; + for $i (1 .. $form->{rowcount}) { + map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, + $form->{"${_}_${i}"}) + if ($form->{"${_}_${i}"}) } + qw(ship qty sellprice listprice basefactor)); + } + if ( $form->{type} =~ /_order/ && $form->{currency} ne $form->{defaultcurrency}) { @@ -1788,7 +2180,15 @@ 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->close_order(\%myconfig, \%$form); + } else { + OE->close_orders(\%myconfig, \%$form); + } $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig); $form->{duedate} = @@ -1861,13 +2261,18 @@ sub invoice { $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); - + (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/); - $dec_qty = length $dec_qty; - $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty); + $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); @@ -2004,6 +2409,8 @@ sub create_backorder { } qw(sellprice discount); } + relink_accounts(); + OE->save(\%myconfig, \%$form); # rebuild rows for invoice @@ -2032,7 +2439,7 @@ sub save_as_new { $form->{saveasnew} = 1; $form->{closed} = 0; - map { delete $form->{$_} } qw(printed emailed queued); + map { delete $form->{$_} } qw(printed emailed queued ordnumber quonumber); &save; @@ -2042,6 +2449,13 @@ sub save_as_new { sub purchase_order { $lxdebug->enter_sub(); + if ( $form->{type} eq 'sales_quotation' + || $form->{type} eq 'request_quotation') { + OE->close_order(\%myconfig, \%$form); + } + + $form->{cp_id} *= 1; + $form->{title} = $locale->text('Add Purchase Order'); $form->{vc} = "vendor"; $form->{type} = "purchase_order"; @@ -2056,11 +2470,9 @@ sub sales_order { if ( $form->{type} eq 'sales_quotation' || $form->{type} eq 'request_quotation') { - $form->{closed} = 1; - OE->save(\%myconfig, \%$form); + OE->close_order(\%myconfig, $form); } - ($null, $form->{cp_id}) = split /--/, $form->{contact}; $form->{cp_id} *= 1; $form->{title} = $locale->text('Add Sales Order'); @@ -2084,6 +2496,13 @@ sub poso { map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal); + for $i (1 .. $form->{rowcount}) { + map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, + $form->{"${_}_${i}"}) + if ($form->{"${_}_${i}"}) } + qw(ship qty sellprice listprice basefactor)); + } + &order_links; &prepare_order; @@ -2291,6 +2710,8 @@ sub display_ship_receive { + + @@ -2436,14 +2857,6 @@ sub display_ship_receive { -|; - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| {rowcount}> @@ -2715,14 +3128,8 @@ sub list_transfer { {password}> |; - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } + . $locale->text('Transfer') . qq|"> - print qq|