#===================================================================== # LedgerSMB # Small Medium Business Accounting software # # See COPYRIGHT file for copyright information #====================================================================== # # This file has NOT undergone whitespace cleanup. # #====================================================================== # # Order entry module # Quotation module # #====================================================================== use LedgerSMB::OE; use LedgerSMB::IR; use LedgerSMB::IS; use LedgerSMB::PE; require "$form->{path}/arap.pl"; require "$form->{path}/io.pl"; 1; # end of main sub add { if ($form->{type} eq 'purchase_order') { $form->{title} = $locale->text('Add Purchase Order'); $form->{vc} = 'vendor'; } if ($form->{type} eq 'sales_order') { $form->{title} = $locale->text('Add Sales Order'); $form->{vc} = 'customer'; } if ($form->{type} eq 'request_quotation') { $form->{title} = $locale->text('Add Request for Quotation'); $form->{vc} = 'vendor'; } if ($form->{type} eq 'sales_quotation') { $form->{title} = $locale->text('Add Quotation'); $form->{vc} = 'customer'; } $form->{callback} = "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}" unless $form->{callback}; $form->{rowcount} = 0; &order_links; &prepare_order; &display_form; } sub edit { if ($form->{type} =~ /(purchase_order|bin_list)/) { $form->{title} = $locale->text('Edit Purchase Order'); $form->{vc} = 'vendor'; $form->{type} = 'purchase_order'; } if ($form->{type} =~ /((sales|work)_order|(packing|pick)_list)/) { $form->{title} = $locale->text('Edit Sales Order'); $form->{vc} = 'customer'; $form->{type} = 'sales_order'; } if ($form->{type} eq 'request_quotation') { $form->{title} = $locale->text('Edit Request for Quotation'); $form->{vc} = 'vendor'; } if ($form->{type} eq 'sales_quotation') { $form->{title} = $locale->text('Edit Quotation'); $form->{vc} = 'customer'; } &order_links; &prepare_order; &display_form; } sub order_links { # retrieve order/quotation OE->retrieve(\%myconfig, \%$form); # get customer/vendor $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP", undef, $form->{transdate}, 1); # currencies @curr = split /:/, $form->{currencies}; $form->{defaultcurrency} = $curr[0]; chomp $form->{defaultcurrency}; $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; for (@curr) { $form->{selectcurrency} .= "$_\n" } $form->{oldlanguage_code} = $form->{language_code}; $l{language_code} = $form->{language_code}; $l{searchitems} = 'nolabor' if $form->{vc} eq 'customer'; $form->get_partsgroup(\%myconfig, \%l); if (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} = "\n"; foreach $ref (@ { $form->{all_partsgroup} }) { if ($ref->{translation}) { $form->{selectpartsgroup} .= qq|$ref->{translation}\n|; } else { $form->{selectpartsgroup} .= qq|$ref->{partsgroup}\n|; } } } if (@{ $form->{all_project} }) { $form->{selectprojectnumber} = "\n"; for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|$_->{projectnumber}\n| } } if (@{ $form->{"all_$form->{vc}"} }) { unless ($form->{"$form->{vc}_id"}) { $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id}; } } for (qw(terms taxincluded)) { $temp{$_} = $form->{$_} } $form->{shipto} = 1 if $form->{id}; # get customer / vendor AA->get_name(\%myconfig, \%$form); if ($form->{id}) { for (qw(terms taxincluded)) { $form->{$_} = $temp{$_} } } ($form->{$form->{vc}}) = split /--/, $form->{$form->{vc}}; $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; # build selection list $form->{"select$form->{vc}"} = ""; if (@{ $form->{"all_$form->{vc}"} }) { $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|; for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|$_->{name}\n| } } # departments if (@{ $form->{all_department} }) { $form->{selectdepartment} = "\n"; $form->{department} = "$form->{department}--$form->{department_id}" if $form->{department_id}; for (@{ $form->{all_department} }) { $form->{selectdepartment} .= qq|$_->{description}\n| } } $form->{employee} = "$form->{employee}--$form->{employee_id}"; # sales staff if (@{ $form->{all_employee} }) { $form->{selectemployee} = ""; for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|$_->{name}\n| } } if (@{ $form->{all_language} }) { $form->{selectlanguage} = "\n"; for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|$_->{description}\n| } } # forex $form->{forex} = $form->{exchangerate}; } sub prepare_order { $form->{format} = "postscript" if $myconfig{printer}; $form->{media} = $myconfig{printer}; $form->{formname} = $form->{type}; $form->{sortby} ||= "runningnumber"; $form->{currency} =~ s/ //g; $form->{oldcurrency} = $form->{currency}; if ($form->{id}) { for (qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact)) { $form->{$_} = $form->quote($form->{$_}) } foreach $ref (@{ $form->{form_details} } ) { $i++; for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} } $form->{"projectnumber_$i"} = qq|$ref->{projectnumber}--$ref->{project_id}| if $ref->{project_id}; $form->{"partsgroup_$i"} = qq|$ref->{partsgroup}--$ref->{partsgroup_id}| if $ref->{partsgroup_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; for (map { "${_}_$i" } qw(sellprice listprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) } ($dec) = ($form->{"lastcost_$i"} =~ /\.(\d+)/); $dec = length $dec; $decimalplaces = ($dec > 2) ? $dec : 2; $form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces); $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); $form->{"oldqty_$i"} = $form->{"qty_$i"}; for (qw(partnumber sku description unit)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } $form->{rowcount} = $i; } } $form->{oldtransdate} = $form->{transdate}; if ($form->{type} eq 'sales_quotation') { if (! $form->{readonly}) { $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--Quotation/; } $form->{selectformname} = qq||.$locale->text('Quotation'); } if ($form->{type} eq 'request_quotation') { if (! $form->{readonly}) { $form->{readonly} = 1 if $myconfig{acs} =~ /Quotations--RFQ/; } $form->{selectformname} = qq||.$locale->text('RFQ'); } if ($form->{type} eq 'sales_order') { if (! $form->{readonly}) { $form->{readonly} = 1 if $myconfig{acs} =~ /Order Entry--Sales Order/; } $form->{selectformname} = qq||.$locale->text('Sales Order').qq| |.$locale->text('Work Order').qq| |.$locale->text('Pick List').qq| |.$locale->text('Packing List'); } if ($form->{type} eq 'purchase_order') { if (! $form->{readonly}) { $form->{readonly} = 1 if $myconfig{acs} =~ /Order Entry--Purchase Order/; } $form->{selectformname} = qq||.$locale->text('Purchase Order').qq| |.$locale->text('Bin List'); } if ($form->{type} eq 'ship_order') { $form->{selectformname} = qq||.$locale->text('Pick List').qq| |.$locale->text('Packing List'); } if ($form->{type} eq 'receive_order') { $form->{selectformname} = qq||.$locale->text('Bin List'); } } sub form_header { $checkedopen = ($form->{closed}) ? "" : "checked"; $checkedclosed = ($form->{closed}) ? "checked" : ""; if ($form->{id}) { $openclosed = qq| |.$locale->text('Open').qq| |.$locale->text('Closed').qq| |; } # set option selected $form->{selectcurrency} =~ s/ selected//; $form->{selectcurrency} =~ s/option>\Q$form->{currency}\E/option selected>$form->{currency}/; for ("$form->{vc}", "department", "employee") { $form->{"select$_"} = $form->unescape($form->{"select$_"}); $form->{"select$_"} =~ s/ selected//; $form->{"select$_"} =~ s/({exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); $exchangerate = qq||; $exchangerate .= qq| |.$locale->text('Currency').qq| $form->{selectcurrency} | if $form->{defaultcurrency}; $exchangerate .= qq| {defaultcurrency}> |; if ($form->{defaultcurrency} && $form->{currency} ne $form->{defaultcurrency}) { if ($form->{forex}) { $exchangerate .= qq||.$locale->text('Exchange Rate').qq|$form->{exchangerate} {exchangerate}> |; } else { $exchangerate .= qq||.$locale->text('Exchange Rate').qq|{exchangerate}>|; } } $exchangerate .= qq| {forex}> |; $vclabel = ucfirst $form->{vc}; $vclabel = $locale->text($vclabel); $terms = qq| |.$locale->text('Terms').qq| {terms}> |.$locale->text('days').qq| |; if ($form->{business}) { $business = qq| |.$locale->text('Business').qq| $form->{business} |; $business .= qq| |.$locale->text('Trade Discount').qq| |.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %| if $form->{vc} eq 'customer'; $business .= qq| |; } if ($form->{type} !~ /_quotation$/) { $ordnumber = qq| |.$locale->text('Order Number').qq| |.$locale->text('Order Date').qq| {transdate}> |.$locale->text('Required by').qq| {reqdate}> |.$locale->text('PO Number').qq| |; $n = ($form->{creditremaining} < 0) ? "0" : "1"; $creditremaining = qq| |.$locale->text('Credit Limit').qq| |.$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0").qq| |.$locale->text('Remaining').qq| |.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq| |; } else { $reqlabel = ($form->{type} eq 'sales_quotation') ? $locale->text('Valid until') : $locale->text('Required by'); if ($form->{type} eq 'sales_quotation') { $ordnumber = qq| |.$locale->text('Quotation Number').qq| |; } else { $ordnumber = qq| |.$locale->text('RFQ Number').qq| |; $terms = ""; } $ordnumber .= qq| |.$locale->text('Quotation Date').qq| {transdate}> $reqlabel {reqdate}> |; } $ordnumber .= qq| {oldtransdate}>|; if ($form->{"select$form->{vc}"}) { $vc = qq|{vc}>$form->{"select$form->{vc}"} {vc}"},1).qq|">|; } else { $vc = qq|{vc} value="$form->{$form->{vc}}" size=35>|; } $department = qq| |.$locale->text('Department').qq| $form->{selectdepartment} | if $form->{selectdepartment}; $employee = qq| |; if ($form->{type} eq 'sales_order') { if ($form->{selectemployee}) { $employee = qq| |.$locale->text('Salesperson').qq| $form->{selectemployee} |; } } else { if ($form->{selectemployee}) { $employee = qq| |.$locale->text('Employee').qq| $form->{selectemployee} |; } } $i = $form->{rowcount} + 1; $focus = "partnumber_$i"; $form->header; print qq| |; $form->hide_form(qw(id type formname media format printed emailed queued vc title discount creditlimit creditremaining tradediscount business recurring)); print qq| $form->{title} $vclabel $vc {vc}_id value=$form->{"$form->{vc}_id"}> {vc}"}"> $creditremaining $business $department $exchangerate |.$locale->text('Shipping Point').qq| |.$locale->text('Ship via').qq| $openclosed $employee $ordnumber $terms |; $form->hide_form(qw(shiptoname shiptoaddress1 shiptoaddress2 shiptocity shiptostate shiptozipcode shiptocountry shiptocontact shiptophone shiptofax shiptoemail message email subject cc bcc taxaccounts)); for (split / /, $form->{taxaccounts}) { print qq| {"${_}_rate"}> |; } } sub form_footer { $form->{invtotal} = $form->{invsubtotal}; if (($rows = $form->numtextrows($form->{notes}, 35, 8)) < 2) { $rows = 2; } if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) { $introws = 2; } $rows = ($rows > $introws) ? $rows : $introws; $notes = qq|$form->{notes}|; $intnotes = qq|$form->{intnotes}|; $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; $taxincluded = ""; if ($form->{taxaccounts}) { $taxincluded = qq| {taxincluded}> |.$locale->text('Tax Included').qq| |; } if (!$form->{taxincluded}) { for (split / /, $form->{taxaccounts}) { if ($form->{"${_}_base"}) { $form->{invtotal} += $form->{"${_}_total"} = $form->round_amount($form->{"${_}_base"} * $form->{"${_}_rate"}, 2); $form->{"${_}_total"} = $form->format_amount(\%myconfig, $form->{"${_}_total"}, 2); $tax .= qq| $form->{"${_}_description"} $form->{"${_}_total"} |; } } $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); $subtotal = qq| |.$locale->text('Subtotal').qq| $form->{invsubtotal} |; } $form->{oldinvtotal} = $form->{invtotal}; $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); print qq| |.$locale->text('Notes').qq| |.$locale->text('Internal Notes').qq| $notes $intnotes $subtotal $tax |.$locale->text('Total').qq| $form->{invtotal} $taxincluded {oldinvtotal}> |; &print_options; print qq| |; # type=submit $locale->text('Update') # type=submit $locale->text('Print') # type=submit $locale->text('Schedule') # type=submit $locale->text('Save') # type=submit $locale->text('Print and Save') # type=submit $locale->text('Ship to') # type=submit $locale->text('Save as new') # type=submit $locale->text('Print and Save as new') # type=submit $locale->text('E-mail') # type=submit $locale->text('Delete') # type=submit $locale->text('Sales Invoice') # type=submit $locale->text('Vendor Invoice') # type=submit $locale->text('Quotation') # type=submit $locale->text('RFQ') # type=submit $locale->text('Sales Order') # type=submit $locale->text('Purchase Order') if (! $form->{readonly}) { %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') }, 'Print' => { ndx => 2, key => 'P', value => $locale->text('Print') }, 'Save' => { ndx => 3, key => 'S', value => $locale->text('Save') }, 'Ship to' => { ndx => 4, key => 'T', value => $locale->text('Ship to') }, 'E-mail' => { ndx => 5, key => 'E', value => $locale->text('E-mail') }, 'Print and Save' => { ndx => 6, key => 'R', value => $locale->text('Print and Save') }, 'Save as new' => { ndx => 7, key => 'N', value => $locale->text('Save as new') }, 'Print and Save as new' => { ndx => 8, key => 'W', value => $locale->text('Print and Save as new') }, 'Sales Invoice' => { ndx => 9, key => 'I', value => $locale->text('Sales Invoice') }, 'Sales Order' => { ndx => 10, key => 'O', value => $locale->text('Sales Order') }, 'Quotation' => { ndx => 11, key => 'Q', value => $locale->text('Quotation') }, 'Vendor Invoice' => { ndx => 12, key => 'I', value => $locale->text('Vendor Invoice') }, 'Purchase Order' => { ndx => 13, key => 'O', value => $locale->text('Purchase Order') }, 'RFQ' => { ndx => 14, key => 'Q', value => $locale->text('RFQ') }, 'Schedule' => { ndx => 15, key => 'H', value => $locale->text('Schedule') }, 'Delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') }, ); %a = (); for ("Update", "Ship to", "Print", "E-mail", "Save") { $a{$_} = 1 } $a{'Print and Save'} = 1 if $latex; if ($form->{id}) { $a{'Delete'} = 1; $a{'Save as new'} = 1; $a{'Print and Save as new'} = 1 if $latex; if ($form->{type} =~ /sales_/) { if ($myconfig{acs} !~ /AR--Sales Invoice/) { $a{'Sales Invoice'} = 1; } } else { if ($myconfig{acs} !~ /AP--Vendor Invoice/) { $a{'Vendor Invoice'} = 1; } } if ($form->{type} eq 'sales_order') { if ($myconfig{acs} !~ /Quotations--RFQ/) { $a{'Quotation'} = 1; } } if ($form->{type} eq 'purchase_order') { if ($myconfig{acs} !~ /Quotations--RFQ/) { $a{'RFQ'} = 1; } } if ($form->{type} eq 'sales_quotation') { if ($myconfig{acs} !~ /Order Entry--Sales Order/) { $a{'Sales Order'} = 1; } } if ($myconfig{acs} !~ /Order Entry--Purchase Order/) { if ($form->{type} eq 'request_quotation') { $a{'Purchase Order'} = 1; } } } if ($form->{type} =~ /_order/) { $a{'Schedule'} = 1; } } for (keys %button) { delete $button{$_} if ! $a{$_} } for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) } if ($form->{menubar}) { require "$form->{path}/menu.pl"; &menubar; } $form->hide_form(qw(rowcount callback path login sessionid)); print qq|