From d6ccc05f1d97979ee67c33451fdfd9cf5f124bb9 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Wed, 6 Feb 2008 13:19:43 +0000 Subject: [PATCH] Huge sales module changes toward delivery and invoicing separation. Includes some cleanups i reporting directory. --- admin/db/voiding_db.inc | 1 + applications/customers.php | 11 +- reporting/includes/doctext.inc | 20 +- reporting/includes/doctext2.inc | 17 +- reporting/includes/form_types.inc | 9 +- reporting/includes/pdf_report.inc | 2 +- reporting/includes/reports_classes.inc | 10 + reporting/rep105.php | 2 +- reporting/rep107.php | 2 +- reporting/rep109.php | 4 +- reporting/rep110.php | 175 +++++++ reporting/rep209.php | 2 +- reporting/reports_main.php | 5 + sales/customer_credit_invoice.php | 11 +- sales/customer_delivery.php | 495 ++++++++++++++++++ sales/customer_invoice.php | 362 ++++++------- sales/includes/cart_class.inc | 60 +-- sales/includes/db/cust_trans_db.inc | 24 +- sales/includes/db/cust_trans_details_db.inc | 5 +- sales/includes/db/sales_credit_db.inc | 12 +- sales/includes/db/sales_delivery_db.inc | 250 +++++++++ sales/includes/db/sales_invoice_db.inc | 241 +++++---- sales/includes/db/sales_order_db.inc | 164 +++--- sales/includes/sales_db.inc | 1 + sales/includes/ui/print_invoice.inc | 9 + sales/includes/ui/sales_order_ui.inc | 176 +++---- sales/inquiry/customer_allocation_inquiry.php | 4 + sales/inquiry/customer_inquiry.php | 71 ++- sales/inquiry/sales_deliveries_view.php | 260 +++++++++ sales/inquiry/sales_orders_view.php | 13 +- sales/sales_order_entry.php | 392 ++++++-------- sales/view/view_dispatch.php | 161 ++++++ sales/view/view_invoice.php | 4 +- sales/view/view_sales_order.php | 43 +- sql/alter.sql | 5 + 35 files changed, 2167 insertions(+), 856 deletions(-) create mode 100644 reporting/rep110.php create mode 100644 sales/customer_delivery.php create mode 100644 sales/includes/db/sales_delivery_db.inc create mode 100644 sales/includes/ui/print_invoice.inc create mode 100644 sales/inquiry/sales_deliveries_view.php create mode 100644 sales/view/view_dispatch.php diff --git a/admin/db/voiding_db.inc b/admin/db/voiding_db.inc index 36fb7d87..f978ebfc 100644 --- a/admin/db/voiding_db.inc +++ b/admin/db/voiding_db.inc @@ -32,6 +32,7 @@ function void_transaction($type, $type_no, $date_, $memo_) case 10 : // it's a customer invoice case 11 : // it's a customer credit note case 12 : // it's a customer payment + case 13 : // it's a customer dispatch if (!exists_customer_trans($type, $type_no)) return false; post_void_customer_trans($type, $type_no); diff --git a/applications/customers.php b/applications/customers.php index 0fa8eba9..c390b6e0 100644 --- a/applications/customers.php +++ b/applications/customers.php @@ -10,15 +10,16 @@ $this->add_module(_("Transactions")); $this->add_lapp_function(0, _("Sales Order Entry"),"sales/sales_order_entry.php?NewOrder=Yes"); - $this->add_lapp_function(0, _("Select a Sales Order to Invoice"),"sales/inquiry/sales_orders_view.php?&OutstandingOnly=1"); + $this->add_lapp_function(0, _("Delivery Against Sales Orders"),"sales/inquiry/sales_orders_view.php?OutstandingOnly=1"); + $this->add_lapp_function(0, _("Direct Delivery"),"sales/sales_order_entry.php?NewDelivery=Yes"); + $this->add_rapp_function(0, _("Customer Payments"),"sales/customer_payments.php?"); - $this->add_rapp_function(0, "",""); - $this->add_rapp_function(0, _("Sales Invoices"),"sales/sales_order_entry.php?NewInvoice=Yes"); - $this->add_rapp_function(0, _("Customer Credit Notes"),"sales/credit_note_entry.php?&NewCredit=Yes"); + $this->add_rapp_function(0, _("Sales Invoices"),"sales/inquiry/sales_deliveries_view.php?OutstandingOnly=1"); + $this->add_rapp_function(0, _("Customer Credit Notes"),"sales/credit_note_entry.php?NewCredit=Yes"); $this->add_rapp_function(0, _("Allocate Customer Payments or Credit Notes"),"sales/allocations/customer_allocation_main.php?"); $this->add_module(_("Inquiries and Reports")); - $this->add_lapp_function(1, _("Sales Order Inquiry"),"sales/inquiry/sales_orders_view.php?"); + $this->add_lapp_function(1, _("Sales Order Inquiry"),"sales/inquiry/sales_orders_view.php?"); $this->add_lapp_function(1, _("Customer Transaction Inquiry"),"sales/inquiry/customer_inquiry.php?"); $this->add_lapp_function(1, "",""); $this->add_lapp_function(1, _("Customer Allocation Inquiry"),"sales/inquiry/customer_allocation_inquiry.php?"); diff --git a/reporting/includes/doctext.inc b/reporting/includes/doctext.inc index 8ef084b4..46e225e3 100644 --- a/reporting/includes/doctext.inc +++ b/reporting/includes/doctext.inc @@ -8,7 +8,7 @@ if (isset($header2type)) $doc_Shipping_Company = _("Shipping Company"); if ($doctype == 9) $doc_Due_Date = _("Delivery Date"); - else + else $doc_Due_Date = _("Due Date"); $doc_Your_Ref = _("Your Ref"); $doc_Our_Ref = _("Our Ref."); @@ -17,16 +17,24 @@ if (isset($header2type)) $doc_Payment_Terms = _("Payment Terms"); $doc_Our_Order_No = _("Our Order No"); $doc_Domicile = _("Domicile"); - $doc_Please_Quote = _("Please quote Invoice no. when paying. All amounts stated in"); + if($doctype == 13) { + $doc_Bank_Account = ''; + $doc_Please_Quote = _("All amounts stated in"); + } else { + $doc_Bank_Account = _("Bank Account"); + $doc_Please_Quote = _("Please quote Invoice no. when paying. All amounts stated in"); + } $doc_Address = _("Address"); $doc_Phone_Fax_Email = _("Phone/Fax/Email"); $doc_Bank = _("Bank"); $doc_Bank_Account = _("Bank Account"); $doc_Payment_Link = _("You can pay through"); - if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11) + if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11 || $doctype == 11) { if ($doctype == 8) $this->title = _("PURCHASE ORDER"); + else if ($doctype == 13) + $this->title = _("DELIVERY NOTE"); else if ($doctype == 9) $this->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER")); else if ($doctype == 10) @@ -56,12 +64,13 @@ if (isset($emailtype)) } if (isset($header2type) || isset($linetype)) { - $doc_Invoice_no = _("Invoice no."); + $doc_Document_no = $doctype==13 ? _("Delivery Note No.") : _("Invoice No."); + $doc_Delivery_no = "Delivery Note No."; $doc_Order_no = _("Order no."); } if (isset($linetype)) { - if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11) + if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11 || $doctype == 13) { $doc_Sub_total = _("Sub-total"); $doc_Shipping = _("Shipping"); @@ -70,6 +79,7 @@ if (isset($linetype)) $doc_TOTAL_INVOICE = _("TOTAL INVOICE"); $doc_TOTAL_ORDER = _("TOTAL ORDER EX VAT"); $doc_TOTAL_PO = _("TOTAL PO EX VAT"); + $doc_TOTAL_DELIVERY = _("TOTAL DELIVERY INCL. VAT"); } else if ($doctype == 12) { diff --git a/reporting/includes/doctext2.inc b/reporting/includes/doctext2.inc index f509b5d7..461877a8 100644 --- a/reporting/includes/doctext2.inc +++ b/reporting/includes/doctext2.inc @@ -17,13 +17,19 @@ if (isset($header2type)) $doc_Payment_Terms = "Payment Terms"; $doc_Our_Order_No = "Our Order No"; $doc_Domicile = "Domicile"; - $doc_Please_Quote = "Please quote Invoice no. when paying. All amounts stated in"; + if($doctype == 13) { + $doc_Bank_Account = ''; + $doc_Please_Quote = "All amounts stated in"; + } else { + $doc_Please_Quote = "Please quote Invoice no. when paying. All amounts stated in"; + $doc_Bank_Account = "Bank Account"; + } $doc_Address = "Address"; $doc_Phone_Fax_Email = "Phone/Fax/Email"; $doc_Bank = "Bank"; $doc_Bank_Account = "Bank Account"; $doc_Payment_Link = "You can pay through"; - if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11) + if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11 || $doctype == 13) { if ($doctype == 8) $this->title = "PURCHASE ORDER"; @@ -31,6 +37,8 @@ if (isset($header2type)) $this->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER")); else if ($doctype == 10) $this->title = "INVOICE"; + else if ($doctype == 13) + $this->title = _("DELIVERY NOTE"); else $this->title = "CREDIT NOTE"; if ($doctype == 8) @@ -56,12 +64,12 @@ if (isset($emailtype)) } if (isset($header2type) || isset($linetype)) { - $doc_Invoice_no = "Invoice No."; + $doc_Document_no = $doctype==13 ? "Delivery Note No." : "Invoice No."; $doc_Order_no = "Order no."; } if (isset($linetype)) { - if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11) + if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11 || $doctype == 13) { $doc_Sub_total = "Sub-total"; $doc_Shipping = "Shipping"; @@ -70,6 +78,7 @@ if (isset($linetype)) $doc_TOTAL_INVOICE = "TOTAL INVOICE"; $doc_TOTAL_ORDER = "TOTAL ORDER EX VAT"; $doc_TOTAL_PO = "TOTAL PO EX VAT"; + $doc_TOTAL_DELIVERY = "TOTAL DELIVERY INCL. VAT"; } else if ($doctype == 12) { diff --git a/reporting/includes/form_types.inc b/reporting/includes/form_types.inc index c70ee0ca..3050a660 100644 --- a/reporting/includes/form_types.inc +++ b/reporting/includes/form_types.inc @@ -42,15 +42,18 @@ function add_forms_for_sys_type($trans_type, $trans_id, $ParamFrom=null, $ParamT add_form_entry(51, $trans_type, $trans_id, $ParamFrom, $ParamTo); break; - case 4 : // bank transfer - withdraw and deposit + case 4 : // bank transfer - withdraw and deposit add_form_entry(50, $trans_type, $trans_id, $ParamFrom, $ParamTo); add_form_entry(51, $trans_type, $trans_id, $ParamTo, $ParamFrom); break; - case 10 : // sales invoice - inventory release and invoice forms - add_form_entry(60, $trans_type, $trans_id, $ParamFrom); + case 10 : // sales invoice - invoice form add_form_entry(10, $trans_type, $trans_id); break; + + case 13 : // sales dispatch - inventory release + add_form_entry(60, $trans_type, $trans_id, $ParamFrom); + break; case 11 : // sales credit - inventory return and credit note forms add_form_entry(62, $trans_type, $trans_id, $ParamFrom); diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index 4ccd6b4b..05bb203e 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -450,7 +450,7 @@ class FrontReport extends Cpdf $this->row = $iline5 - $this->lineHeight - 6; $this->Text($ccol, $doc_Please_Quote . " - " . $myrow['curr_code']); $this->NewLine(); - if ($branch['disable_branch'] > 0 && $doctype == 10) // payment links + if ($doctype == 10 && $branch['disable_branch'] > 0) // payment links { if ($branch['disable_branch'] == 1) { diff --git a/reporting/includes/reports_classes.inc b/reporting/includes/reports_classes.inc index badf6308..761ef43c 100644 --- a/reporting/includes/reports_classes.inc +++ b/reporting/includes/reports_classes.inc @@ -246,6 +246,16 @@ class Report FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC"; $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy); break; + case 'DELIVERY': + $DN = _("DN"); + $sql = "SELECT + concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ', + ".TB_PREF."debtors_master.name) as IName + FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans + WHERE type=13 AND ".TB_PREF."debtors_master.debtor_no=". + TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC"; + $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy); + break; case 'ORDERS': $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-', ".TB_PREF."debtors_master.name) as IName diff --git a/reporting/rep105.php b/reporting/rep105.php index 9e8c4936..ee7d3c21 100644 --- a/reporting/rep105.php +++ b/reporting/rep105.php @@ -99,7 +99,7 @@ function print_order_status_list() $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right'); $headers = array(_('Code'), _('Description'), _('Ordered'), _('Invoiced'), - _('Outstanding'), _(' ')); + _('Outstanding'), ''); $params = array( 0 => $comments, 1 => array( 'text' => _('Period'), 'from' => $from, 'to' => $to), diff --git a/reporting/rep107.php b/reporting/rep107.php index 966fe7dd..df08cd96 100644 --- a/reporting/rep107.php +++ b/reporting/rep107.php @@ -119,7 +119,7 @@ function print_invoices() $rep->TextCol(6, 7, $DisplayNet, -2); $rep->NewLine(1); if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight)) - $rep->Header2($myrow, $branch, $sales_order, $baccount); + $rep->Header2($myrow, $branch, $sales_order, $baccount,$j); } $comments = get_comments($j, $i); diff --git a/reporting/rep109.php b/reporting/rep109.php index 9d511385..db251ae5 100644 --- a/reporting/rep109.php +++ b/reporting/rep109.php @@ -5,7 +5,7 @@ $page_security = 2; // $ Revision: 2.0 $ // Creator: Joe Hunt // date_: 2005-05-19 -// Title: Print Invoices +// Title: Print Sales Orders // ---------------------------------------------------------------- $path_to_root="../"; @@ -25,7 +25,7 @@ function get_sales_order_details($order_no) { $sql = "SELECT stk_code, unit_price, ".TB_PREF."sales_order_details.description, ".TB_PREF."sales_order_details.quantity, discount_percent, - qty_invoiced, units, + qty_sent, units, ".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost AS standard_cost FROM ".TB_PREF."sales_order_details, ".TB_PREF."stock_master WHERE ".TB_PREF."sales_order_details.stk_code = ".TB_PREF."stock_master.stock_id diff --git a/reporting/rep110.php b/reporting/rep110.php new file mode 100644 index 00000000..7142c386 --- /dev/null +++ b/reporting/rep110.php @@ -0,0 +1,175 @@ + $comments); + + $cur = get_company_Pref('curr_default'); + + if ($email == 0) + { + $rep = new FrontReport(_('DELIVERY'), "DeliveryNoteBulk.pdf", user_pagesize()); + $rep->currency = $cur; + $rep->Font(); + $rep->Info($params, $cols, null, $aligns); + } + + for ($i = $fno[0]; $i <= $tno[0]; $i++) + { + if (!exists_customer_trans(13, $i)) + continue; + $myrow = get_customer_trans($i, 13); + $branch = get_branch($myrow["branch_code"]); + $sales_order = get_sales_order($myrow["order_"]); // ? + if ($email == 1) + { + $rep = new FrontReport("", "", user_pagesize()); + $rep->currency = $cur; + $rep->Font(); + $rep->title = _('DELIVERY NOTE'); + $rep->filename = "Delivery" . $myrow['reference'] . ".pdf"; + $rep->Info($params, $cols, null, $aligns); + } + else + $rep->title = _('DELIVERY NOTE'); + $rep->Header2($myrow, $branch, $sales_order, '', 13); + + $result = get_customer_trans_details(13, $i); + $SubTotal = 0; + while ($myrow2=db_fetch($result)) + { + $Net = ((1 - $myrow2["discount_percent"]) * $myrow2["FullUnitPrice"] * -$myrow2["quantity"]); + $SubTotal += $Net; + $DisplayPrice = number_format2($myrow2["FullUnitPrice"],$dec); + $DisplayQty = number_format2(-$myrow2["quantity"],user_qty_dec()); + $DisplayNet = number_format2($Net,$dec); + if ($myrow2["discount_percent"]==0) + $DisplayDiscount =""; + else + $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%"; + $rep->TextCol(0, 1, $myrow2['stock_id'], -2); + $rep->TextCol(1, 2, $myrow2['StockDescription'], -2); + $rep->TextCol(2, 3, $DisplayQty, -2); + $rep->TextCol(3, 4, $myrow2['units'], -2); + $rep->TextCol(4, 5, $DisplayPrice, -2); + $rep->TextCol(5, 6, $DisplayDiscount, -2); + $rep->TextCol(6, 7, $DisplayNet, -2); + $rep->NewLine(1); + if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight)) + $rep->Header2($myrow, $branch, $sales_order,'',13); + } + + $comments = get_comments(13, $i); + if ($comments && db_num_rows($comments)) + { + $rep->NewLine(); + while ($comment=db_fetch($comments)) + $rep->TextColLines(0, 6, $comment['memo_'], -2); + } + + $DisplaySubTot = number_format2($SubTotal,$dec); + $DisplayFreight = number_format2($myrow["ov_freight"],$dec); + + $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight); + $linetype = true; + $doctype=13; + if ($rep->currency != $myrow['curr_code']) + { + include($path_to_root . "reporting/includes/doctext2.inc"); + } + else + { + include($path_to_root . "reporting/includes/doctext.inc"); + } + + $rep->TextCol(3, 6, $doc_Sub_total, -2); + $rep->TextCol(6, 7, $DisplaySubTot, -2); + $rep->NewLine(); + $rep->TextCol(3, 6, $doc_Shipping, -2); + $rep->TextCol(6, 7, $DisplayFreight, -2); + $rep->NewLine(); + $tax_items = get_customer_trans_tax_details(13, $i); + while ($tax_item = db_fetch($tax_items)) + { + $DisplayTax = number_format2($tax_item['amount'], $dec); + if ($tax_item['included_in_price']) + { + $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] . + " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2); + } + else + { + $rep->TextCol(3, 6, $tax_item['tax_type_name'] . " (" . + $tax_item['rate'] . "%)", -2); + $rep->TextCol(6, 7, $DisplayTax, -2); + } + $rep->NewLine(); + } + $rep->NewLine(); + $DisplayTotal = number_format2($myrow["ov_freight"] + $myrow["ov_gst"] + + $myrow["ov_amount"],$dec); + $rep->Font('bold'); + $rep->TextCol(3, 6, $doc_TOTAL_DELIVERY, - 2); + $rep->TextCol(6, 7, $DisplayTotal, -2); + $rep->Font(); + if ($email == 1) + { + $myrow['dimension_id'] = $paylink; // helper for pmt link + if ($myrow['email'] == '') + { + $myrow['email'] = $branch['email']; + $myrow['DebtorName'] = $branch['br_name']; + } + $rep->End($email, $doc_Delivery_no . " " . $myrow['reference'], $myrow, 13); + } + } + if ($email == 0) + $rep->End(); +} + +?> \ No newline at end of file diff --git a/reporting/rep209.php b/reporting/rep209.php index 1f9f5697..32108d5a 100644 --- a/reporting/rep209.php +++ b/reporting/rep209.php @@ -5,7 +5,7 @@ $page_security = 2; // $ Revision: 2.0 $ // Creator: Joe Hunt // date_: 2005-05-19 -// Title: Print Invoices +// Title: Purchase Orders // ---------------------------------------------------------------- $path_to_root="../"; diff --git a/reporting/reports_main.php b/reporting/reports_main.php index fcaeab39..0d6031ed 100644 --- a/reporting/reports_main.php +++ b/reporting/reports_main.php @@ -55,6 +55,11 @@ $reports->addReport(_('Customer'),107,_('Print Invoices/Credit Notes'), new ReportParam(_('email Customers'),'YES_NO'), new ReportParam(_('Payment Link'),'PAYMENT_LINK'), new ReportParam(_('Comments'),'TEXTBOX'))); +$reports->addReport(_('Customer'),110,_('Print Deliveries'), + array( new ReportParam(_('From'),'DELIVERY'), + new ReportParam(_('To'),'DELIVERY'), + new ReportParam(_('email Customers'),'YES_NO'), + new ReportParam(_('Comments'),'TEXTBOX'))); $reports->addReport(_('Customer'),108,_('Print Statements'), array( new ReportParam(_('Customer'),'CUSTOMERS_NO_FILTER'), new ReportParam(_('Currency Filter'),'CURRENCY'), diff --git a/sales/customer_credit_invoice.php b/sales/customer_credit_invoice.php index 85eda971..ac892394 100644 --- a/sales/customer_credit_invoice.php +++ b/sales/customer_credit_invoice.php @@ -115,16 +115,12 @@ if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0) clear_globals(); - session_register("Items"); - session_register("InvoiceToCredit"); - session_Register("Order"); - $_SESSION['InvoiceToCredit'] = $_GET['InvoiceNumber']; $_SESSION['Items'] = new cart; /*read in all the guff from the selected invoice into the Items cart */ - // we need a distinct here so that it only returns 1 line - becuase there can be mutliple moves + // we need a distinct here so that it only returns 1 line - because there can be multiple moves // per item (for assemblies, etc) $sql = "SELECT DISTINCT ".TB_PREF."debtor_trans.*, ".TB_PREF."cust_branch.default_location, ".TB_PREF."cust_branch.default_ship_via, @@ -179,8 +175,9 @@ if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0) while ($myrow = db_fetch($result)) { - $_SESSION['Items']->add_to_cart($_SESSION['Items']->lines_on_order+1, $myrow["id"], $myrow["stock_id"],-$myrow["quantity"], - $myrow["FullUnitPrice"],$myrow["discount_percent"]); + $_SESSION['Items']->add_to_cart($myrow["stock_id"],-$myrow["quantity"], + $myrow["FullUnitPrice"],$myrow["discount_percent"],$myrow["qty_done"], + $myrow["standard_cost"],$myrow["description"],$myrow["id"]); $_SESSION['Items']->line_items[$_SESSION['Items']->lines_on_order]->standard_cost = $myrow["standard_cost"]; diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php new file mode 100644 index 00000000..c7ba4b61 --- /dev/null +++ b/sales/customer_delivery.php @@ -0,0 +1,495 @@ +trans_type=='invoice') + hyperlink_params("$path_to_root/sales/sales_order_entry.php", _("Make Another Dispatch"), "NewDispatch=Yes"); + else + hyperlink_params("$path_to_root/sales/inquiry/sales_orders_view.php", _("Select Another Order For Dispatch"), "OutstandingOnly=1"); + + display_footer_exit(); +} + +//--------------------------------------------------------------------------------------------------------------- + +if (!isset($_GET['OrderNumber']) && !isset($_SESSION['ProcessingOrder']) && + !isset($_GET['ModifyDelivery']) && !isset($_GET['process_delivery'])) +{ + /* This page can only be called with an order number for invoicing*/ + display_error(_("This page can only be opened if an order or delivery note has been selected. Please select it first.")); + + hyperlink_params("$path_to_root/sales/inquiry/sales_orders_view.php", _("Select a Sales Order to Delivery"), "OutstandingOnly=1"); + + end_page(); + exit; + +} +elseif (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) +{ + + if (isset($_SESSION['Items'])) + { + unset($_SESSION['Items']->line_items); + unset ($_SESSION['Items']); + } + + $_SESSION['ProcessingOrder'] = $_GET['OrderNumber']; + $_SESSION['Items'] = new cart; + + /*read in all the selected order into the Items cart */ + + if (read_sales_order($_SESSION['ProcessingOrder'], $_SESSION['Items'])) + { + if ($_SESSION['Items']->count_items() == 0) + { + hyperlink_params($path_to_root . "/sales/inquiry/sales_orders_view.php", _("Select a different sales order to delivery"), "OutstandingOnly=1"); + die ("
" . _("This order has no items. There is nothing to delivery.") . ""); + } + } + else + { + hyperlink_no_params("/sales_orders_view.php", _("Select a sales order to dispatch")); + die ("
" . _("This order items could not be retrieved. Please select another order.") . ""); + } + +} +elseif (isset($_GET['ModifyDelivery']) && $_GET['ModifyDelivery'] > 0) { + if (isset($_SESSION['Items'])) + { + unset($_SESSION['Items']->line_items); + unset ($_SESSION['Items']); + } + $_SESSION['Items'] = new cart; + + if(read_sales_delivery($_GET['ModifyDelivery'],$_SESSION['Items'] )) + { + if ($_SESSION['Items']->count_items() == 0) + { + hyperlink_params($path_to_root . "/sales/inquiry/sales_orders_view.php", _("Select a different delivery"), "OutstandingOnly=1"); + die ("
" . _("This delivery has all items invoiced. There is nothing to modify.") . ""); + } + } + else + { + hyperlink_no_params("/sales_orders_view.php", _("Select a sales order to dispatch")); + die ("
" . _("This sales delivery item could not be retrieved. Please select another delivery.") . ""); + } + + $_SESSION['ProcessingOrder'] = $_SESSION['Items']->order_no; +} else +{ + // Update cart delivery quantities/descriptions + foreach ($_SESSION['Items']->line_items as $line=>$itm) + { + if(isset($_POST['Line'.$line])) { + $line_qty = $_POST['Line'.$line]; + if (is_numeric($line_qty) && $_POST['Line'.$line] <= ($itm->quantity - $itm->qty_done)) + { + $_SESSION['Items']->line_items[$line]->qty_dispatched = $line_qty; + } + } + + if(isset($_POST['Line'.$line.'Desc'])) { + $line_desc = $_POST['Line'.$line.'Desc']; + if (strlen($line_desc) > 0) + { + $_SESSION['Items']->line_items[$line]->item_description = $line_desc; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------- + +function order_changed_error() +{ + global $path_to_root; + display_note(_("This order has been changed or invoiced since this delivery was started to be confirmed. Processing halted."), 1, 0); + display_note(_("To enter and confirm this dispatch the order must be re-selected and re-read again to update the changes made by the other user."), 1, 0); + + hyperlink_no_params("$path_to_root/sales/inquiry/sales_orders_view.php", _("Select a sales order for confirming deliveries")); + + unset($_SESSION['ProcessingOrder']); + exit; +} + +//--------------------------------------------------------------------------------------------------------------- + +function check_order_changed() +{ + global $debug; + + /*Now need to check that the order details are the same as they were when + they were read into the Items array. + If they've changed then someone else may have dispatch them */ + + $sql = "SELECT id, stk_code, quantity, qty_sent FROM ".TB_PREF."sales_order_details WHERE + order_no = " . $_SESSION['ProcessingOrder']. " ORDER BY id"; + + $result = db_query($sql,"retreive sales order details"); + + if (db_num_rows($result) != count($_SESSION['Items']->line_items)) + { + + /*there should be the same number of items returned from this query as + count of lines on the delivery notes - if not then someone has + already invoiced or credited some lines */ + if ($debug == 1) + { + display_note($sql, 1, 0); + display_note("No rows returned by sql:" . db_num_rows($result), 1, 0); + display_note("Count of items in the cart " . count($_SESSION['Items']->line_items), 1, 0); + } + + return false; + } + $line=0; + while ($myrow = db_fetch($result)) + { + $stk_itm = $myrow["stk_code"]; + if ($_SESSION['Items']->line_items[$line]->quantity != $myrow["quantity"] || + $_SESSION['Items']->line_items[$line]->qty_done != $myrow["qty_sent"]) + { + display_note(_("Original order for") . " '" . $myrow["stk_code"] . "' " . + _("has a quantity of") . " " . $myrow["quantity"] . " " . + _("and an delivered quantity of") . " " . $myrow["qty_sent"] . " " . + _("the cart shows quantity of") . " " . + $_SESSION['Items']->line_items[$line]->quantity . " " . + _("and delivered quantity of") . " " . + $_SESSION['Items']->line_items[$line]->qty_done, 1, 0); + + return false; + } + $line++; + } /*loop through all line items of the order to ensure none have been invoiced */ + return true; +} + +//--------------------------------------------------------------------------------------------------------------- + +function check_data() +{ + if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate'])) + { + display_error(_("The entered date of delivery is invalid.")); + return false; + } + if (!is_date_in_fiscalyear($_POST['DispatchDate'])) + { + display_error(_("The entered date of delivery is not in fiscal year.")); + return false; + } + if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) + { + display_error(_("The entered dead-line for invoice is invalid.")); + return false; + } + + if (!references::is_valid($_POST['ref'])) + { + display_error(_("You must enter a reference.")); + return false; + } + + if (!is_new_reference($_POST['ref'], 13)) + { + display_error(_("The entered reference is already in use.")); + return false; + } + if ($_POST['ChargeFreightCost'] == "") + $_POST['ChargeFreightCost'] = 0; + if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0) + { + display_error(_("The entered shipping value is not numeric.")); + return false; + } + + if ($_SESSION['Items']->has_items_dispatch() == 0 && $_POST['ChargeFreightCost'] == 0) + { + display_error(_("There are no item quantities on this delivery note.")); + return false; + } + + return true; +} + +//--------------------------------------------------------------------------------------------------------------- + +function check_qoh() +{ + if (!sys_prefs::allow_negative_stock()) + { + foreach ($_SESSION['Items']->line_items as $itm) + { + + if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag)) + { + $qoh = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']); + + if ($itm->qty_dispatched > $qoh) + { + display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:") . + " " . $itm->stock_id . " - " . $itm->item_description); + return false; + } + } + } + } + + return true; +} + +//--------------------------------------------------------------------------------------------------------------- + +function process_delivery($get_from_order=false) +{ + if ($get_from_order) + { // entry point for direct delivery - cart contains completed order; + // we should have qty_dispatched and standard cost set anyway + unset($_SESSION['Items']->line_items); + read_sales_order($_SESSION['Items']->order_no, $_SESSION['Items']); + + $duedate = get_invoice_duedate($_SESSION['Items']->customer_id, $_SESSION['Items']->delivery_date); + $delivery_no = add_sales_delivery($_SESSION['Items'], + $_SESSION['Items']->delivery_date, $duedate, $_SESSION['Items']->order_no, + $_SESSION['Items']->tax_group_id, $_SESSION['Items']->freight_cost, + $_SESSION['Items']->Location, $_SESSION['Items']->ship_via, + $_SESSION['Items']->default_sales_type, references::get_next(13), + $_SESSION['Items']->memo_,0); + } + else + { + + if (!check_data()) + return; + + if (!check_order_changed()) + order_changed_error(); + + if (!check_qoh()) + return; + + if ($_POST['bo_policy']) + $bo_policy = 0; + else + $bo_policy = 1; + + $delivery_no = add_sales_delivery($_SESSION['Items'], + $_POST['DispatchDate'], $_POST['due_date'], $_SESSION['ProcessingOrder'], + $_SESSION['Items']->tax_group_id,$_POST['ChargeFreightCost'], $_POST['Location'], + $_POST['ship_via'], $_POST['sales_type_id'], $_POST['ref'], + $_POST['InvoiceText'], $bo_policy); + unset($_SESSION['ProcessingOrder']); + } + meta_forward($_SERVER['PHP_SELF'], "AddedID=$delivery_no"); +} + +//--------------------------------------------------------------------------------------------------------------- +if (isset($_GET['process_delivery'])) + process_delivery(true); +elseif (isset($_POST['process_delivery'])) + process_delivery(); + +//------------------------------------------------------------------------------------------------- + +start_form(false, true); + +start_table("$table_style2 width=80%", 5); +echo ""; // outer table + +start_table("$table_style width=100%"); +start_row(); +label_cells(_("Customer"), $_SESSION['Items']->customer_name, "class='tableheader2'"); +label_cells(_("Branch"), get_branch_name($_SESSION['Items']->Branch), "class='tableheader2'"); +label_cells(_("Currency"), $_SESSION['Items']->customer_currency, "class='tableheader2'"); +end_row(); +start_row(); + +if (!isset($_POST['ref'])) + $_POST['ref'] = references::get_next(13); + +ref_cells(_("Reference"), 'ref', null, "class='tableheader2'"); + +label_cells(_("For Sales Order"), get_customer_trans_view_str(systypes::sales_order(), $_SESSION['ProcessingOrder']), "class='tableheader2'"); + +if (!isset($_POST['sales_type_id'])) + $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type; +label_cell(_("Sales Type"), "class='tableheader2'"); +sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']); + +end_row(); +start_row(); + +if (!isset($_POST['Location'])) + $_POST['Location'] = $_SESSION['Items']->Location; +label_cell(_("Delivery From"), "class='tableheader2'"); +locations_list_cells(null, 'Location', $_POST['Location'], false, true); + +if (!isset($_POST['ship_via'])) + $_POST['ship_via'] = $_SESSION['Items']->ship_via; +label_cell(_("Shipping Company"), "class='tableheader2'"); +shippers_list_cells(null, 'ship_via', $_POST['ship_via']); + +// set this up here cuz it's used to calc qoh +if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate'])) +{ + $_POST['DispatchDate'] = Today(); + if (!is_date_in_fiscalyear($_POST['DispatchDate'])) + $_POST['DispatchDate'] = end_fiscalyear(); +} +date_cells(_("Date"), 'DispatchDate', $_POST['DispatchDate'], 0, 0, 0, "class='tableheader'"); +end_row(); + +end_table(); + +echo "";// outer table + +start_table("$table_style width=90%"); + +if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) + + $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->customer_id, $_POST['DispatchDate']); + +date_row(_("Invoice Dead-line"), 'due_date', $_POST['due_date'], 0, 0, 0, "class='tableheader'"); +end_table(); + +echo ""; +end_table(1); // outer table + +display_heading(_("Invoice Items")); + +start_table("$table_style width=80%"); +$th = array(_("Item Code"), _("Item Description"), _("Ordered"), _("Units"), _("Delivered"), + _("This Delivery"), _("Price"), _("Tax Type"), _("Discount"), _("Total")); +table_header($th); +$k = 0; +$has_marked = false; +$show_qoh = true; + +foreach ($_SESSION['Items']->line_items as $line=>$ln_itm) +{ + if($ln_itm->quantity==$ln_itm->qty_done) continue; //this line is fully delivered + // if it's a non-stock item (eg. service) don't show qoh + if (sys_prefs::allow_negative_stock() || !has_stock_holding($ln_itm->mb_flag) || + $ln_itm->qty_dispatched == 0) + $show_qoh = false; + + if ($show_qoh) + $qoh = get_qoh_on_date($ln_itm->stock_id, $_POST['Location'], $_POST['DispatchDate']); + + if ($show_qoh && ($ln_itm->qty_dispatched > $qoh)) + { + // oops, we don't have enough of one of the component items + start_row("class='stockmankobg'"); + $has_marked = true; + } + else + alt_table_row_color($k); + + view_stock_status_cell($ln_itm->stock_id); + + text_cells(null, 'Line'.$line.'Desc', $ln_itm->item_description, 30, 50); + qty_cell($ln_itm->quantity); + label_cell($ln_itm->units); + qty_cell($ln_itm->qty_done); + + text_cells(null, 'Line'.$line, $ln_itm->qty_dispatched, 10, 10); + + $display_discount_percent = number_format2($ln_itm->discount_percent*100,user_percent_dec()) . "%"; + + $line_total = ($ln_itm->qty_dispatched * $ln_itm->price * (1 - $ln_itm->discount_percent)); + + amount_cell($ln_itm->price); + label_cell($ln_itm->tax_type_name); + label_cell($display_discount_percent, "nowrap align=right"); + amount_cell($line_total); + + end_row(); +} + +$_POST['ChargeFreightCost'] = $_SESSION['Items']->freight_cost; + +if (!is_numeric($_POST['ChargeFreightCost'])) +{ + $_POST['ChargeFreightCost'] = 0; +} + +start_row(); + +small_amount_cells(_("Shipping Cost"), 'ChargeFreightCost', null, "colspan=9 align=right"); + +$inv_items_total = $_SESSION['Items']->get_items_total_dispatch(); + +$display_sub_total = number_format2($inv_items_total + $_POST['ChargeFreightCost'],user_price_dec()); + +label_row(_("Sub-total"), $display_sub_total, "colspan=9 align=right","align=right"); + +$taxes = $_SESSION['Items']->get_taxes($_SESSION['Items']->tax_group_id, $_POST['ChargeFreightCost']); +$tax_total = display_edit_tax_items($taxes, 9); + +$display_total = number_format2(($inv_items_total + $_POST['ChargeFreightCost'] + $tax_total), user_price_dec()); + +label_row(_("Amount Total"), $display_total, "colspan=9 align=right","align=right"); + +end_table(1); + +if ($has_marked) + display_note(_("Marked items have insufficient quantities in stock."), 0, 1, "class='red'"); + +start_table($table_style2); + +policy_list_row(_("Action For Balance"), "bo_policy", null); + +textarea_row(_("Memo"), 'InvoiceText', null, 50, 4); + +end_table(1); + +submit_center_first('Update', _("Update")); +submit_center_last('process_delivery', _("Process Dispatch")); + +end_form(); + +//--------------------------------------------------------------------------------------------- + +end_page(); + +?> diff --git a/sales/customer_invoice.php b/sales/customer_invoice.php index 8e6fce15..27d5d220 100644 --- a/sales/customer_invoice.php +++ b/sales/customer_invoice.php @@ -18,138 +18,136 @@ if ($use_popup_windows) $js .= get_js_open_window(900, 500); if ($use_date_picker) $js .= get_js_date_picker(); -if ($_SESSION['Items']->direct_invoice) - page(_("Issue an Invoice"), false, false, "", $js); -else - page(_("Issue an Invoice and Deliver Items for a Sales Order"), false, false, "", $js); +page(_("Issue an Invoice for Delivery Note(s)"), false, false, "", $js); //--------------------------------------------------------------------------------------------------------------- -if (isset($_GET['AddedID'])) +if (isset($_GET['AddedID'])) { $invoice_no = $_GET['AddedID']; $trans_type = 10; - display_notification(_("Invoice processed"), true); + display_notification(_("Selected deliveries has been processed"), true); + display_note(get_customer_trans_view_str($trans_type, $invoice_no, _("View this invoice")), 0, 1); - display_note(get_gl_view_str($trans_type, $invoice_no, _("View the GL Journal Entries for this Invoice"))); + display_note(get_gl_view_str($trans_type, $invoice_no, _("View the GL Journal Entries for this Invoice"))); - if ($_SESSION['Items']->direct_invoice) - hyperlink_params("$path_to_root/sales/sales_order_entry.php", _("Issue Another Invoice"), "NewInvoice=Yes"); - else - hyperlink_params("$path_to_root/sales/inquiry/sales_orders_view.php", _("Select Another Order For Invoicing"), "OutstandingOnly=1"); + hyperlink_params("$path_to_root/sales/inquiry/sales_deliveries_view.php", _("Select Another Delivery For Invoicing"), "OutstandingOnly=1"); - unset($_SESSION['Items']->line_items); - unset($_SESSION['Items']); display_footer_exit(); } //--------------------------------------------------------------------------------------------------------------- -if (!isset($_GET['OrderNumber']) && !isset($_SESSION['ProcessingOrder']) && - !isset($_GET['process_invoice'])) +if (!isset($_GET['DeliveryNumber']) && !isset($_SESSION['ProcessingDelivery']) && + !isset($_GET['BatchInvoice']) && !isset($_GET['process_invoice'])) { - /* This page can only be called with an order number for invoicing*/ - display_error(_("This page can only be opened if an order has been selected. Please select an order first.")); + /* This page can only be called with a delivery for invoicing*/ + display_error(_("This page can only be opened after delivery selection. Please select delivery to invoicing first.")); - hyperlink_no_params("$path_to_root/sales/inquiry/sales_orders_view.php", _("Select a sales order to invoice")); + hyperlink_no_params("$path_to_root/sales/inquiry/sales_deliveries_view.php", _("Select Delivery to Invoice")); end_page(); exit; - -} -elseif (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) +} +elseif (isset($_GET['DeliveryNumber'])|| isset($_GET['BatchInvoice'])) { + if (isset($_SESSION['Items'])) { unset($_SESSION['Items']->line_items); unset ($_SESSION['Items']); } - session_register("Items"); - session_register("ProcessingOrder"); - - $_SESSION['ProcessingOrder'] = $_GET['OrderNumber']; - $_SESSION['Items'] = new cart; + if(isset($_GET['BatchInvoice'])) { + $_SESSION['ProcessingDelivery'] = $_SESSION['DeliveryBatch']; + unset($_SESSION['DeliveryBatch']); + } + else + $_SESSION['ProcessingDelivery'] = array($_GET['DeliveryNumber']); - /*read in all the selected order into the Items cart */ + $_SESSION['Items'] = new cart('delivery'); + $_SESSION['Items']->trans_no = $_SESSION['ProcessingDelivery']; - if (read_sales_order($_SESSION['ProcessingOrder'], $_SESSION['Items'], true)) + /*read in all the selected deliveries into the Items cart */ + if (read_sales_delivery($_SESSION['ProcessingDelivery'], $_SESSION['Items'])) { - - if ($_SESSION['Items']->count_items() == 0) - { - hyperlink_params($path_to_root . "/sales/inquiry/sales_orders_view.php", _("Select a different sales order to invoice"), "OutstandingOnly=1"); - die ("
" . _("There are no ordered items with a quantity left to deliver. There is nothing left to invoice.") . ""); - } - } - else + if ($_SESSION['Items']->count_items() == 0) + { + hyperlink_params($path_to_root . "/sales/inquiry/sales_deliveries_view.php", _("Select a different delivery to invoice"), "OutstandingOnly=1"); + die ("
" . _("There are no delivered items with a quantity left to invoice. There is nothing left to invoice.") . ""); + } + } + else { - hyperlink_no_params("/sales_orders_view.php", _("Select a sales order to invoice")); - die ("
" . _("This order item could not be retrieved. Please select another order.") . ""); + hyperlink_no_params("/sales_deliveries_view.php", _("Select a delivery note to invoice")); + die ("
" . _("This delivery note could not be retrieved. Please select another delivery.") . ""); } - -} -else +} +else { - /* if processing, a dispatch page has been called and ${$StkItm->stock_id} would have been set from the post */ - foreach ($_SESSION['Items']->line_items as $itm) + foreach ($_SESSION['Items']->line_items as $line=>$itm) { - - if (isset($_POST[$itm->stock_id]) && is_numeric($_POST[$itm->stock_id]) && - $_POST[$itm->stock_id] <= ($_SESSION['Items']->line_items[$itm->line_no]->quantity - - $_SESSION['Items']->line_items[$itm->line_no]->qty_inv)) + if(isset($_POST['Line'.$line])) { + $line_qty = $_POST['Line'.$line]; + if (is_numeric($line_qty) && $_POST['Line'.$line] <= ($itm->quantity - $itm->qty_done)) { - $_SESSION['Items']->line_items[$itm->line_no]->qty_dispatched = $_POST[$itm->stock_id]; + $_SESSION['Items']->line_items[$line]->qty_dispatched = $line_qty; } - - if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0) + } + + if(isset($_POST['Line'.$line.'Desc'])) { + $line_desc = $_POST['Line'.$line.'Desc']; + if (strlen($line_desc) > 0) { - $_SESSION['Items']->line_items[$itm->line_no]->item_description = $_POST[$itm->stock_id . "Desc"]; + $_SESSION['Items']->line_items[$line]->item_description = $line_desc; } + } } } //--------------------------------------------------------------------------------------------------------------- -function order_changed_error() +function delivery_changed_error() { global $path_to_root; - display_note(_("This order has been changed or invoiced since this delivery was started to be confirmed. Processing halted."), 1, 0); - display_note(_("To enter and confirm this dispatch/invoice the order must be re-selected and re-read again to update the changes made by the other user."), 1, 0); + display_note(_("This delivery note has been changed or invoiced since this invoice was started to be confirmed. Processing halted."), 1, 0); + display_note(_("To enter and confirm this invoice the order must be re-selected and re-read again to update the changes made by the other user."), 1, 0); - hyperlink_no_params("$path_to_root/sales/inquiry/sales_orders_view.php", _("Select a sales order for confirming deliveries and invoicing")); + hyperlink_no_params("$path_to_root/sales/inquiry/sales_deliveries_view.php", _("Select a sales order for invoicing")); - unset($_SESSION['Items']->line_items); - unset($_SESSION['Items']); - unset($_SESSION['ProcessingOrder']); + unset($_SESSION['ProcessingDelivery']); exit; } //--------------------------------------------------------------------------------------------------------------- -function check_order_changed() +function check_delivery_changed() { global $debug; - /*Now need to check that the order details are the same as they were when - they were read into the Items array. - If they've changed then someone else may have invoiced them - - as modified for bug pointed out by Sherif 1-7-03*/ + /*Now need to check that the delivery note details are the same + as they were when they were read into the Items array. + If they've changed then someone else may have invoiced them */ - $sql = "SELECT stk_code, quantity, qty_invoiced FROM ".TB_PREF."sales_order_details WHERE - quantity - qty_invoiced > 0 - AND order_no = " . $_SESSION['ProcessingOrder']; + $sql = "SELECT id, stock_id, quantity, qty_done FROM " + .TB_PREF."debtor_trans_details WHERE + debtor_trans_type = 13 AND ("; - $result = db_query($sql,"retreive sales order details"); + foreach($_SESSION['Items']->trans_no as $key=>$num) { + if($key!=0) $sql .= ' OR '; + $sql .= 'debtor_trans_no =' . $num; + } + $sql .= ') ORDER BY id'; + $result = db_query($sql,"while checking delivery changes"); if (db_num_rows($result) != count($_SESSION['Items']->line_items)) { /*there should be the same number of items returned from this query as there are lines on the invoice - - if not then someone has already invoiced or credited some lines */ + if not then someone has already invoiced or credited some lines */ if ($debug == 1) { display_note($sql, 1, 0); @@ -159,30 +157,26 @@ function check_order_changed() return false; } - - while ($myrow = db_fetch($result)) + $line=0; + while ($myrow = db_fetch($result)) { - foreach($_SESSION['Items']->line_items as $line) + $stk_itm = $myrow["stock_id"]; + + if ($_SESSION['Items']->line_items[$line]->quantity != -$myrow["quantity"] || + $_SESSION['Items']->line_items[$line]->qty_done != -$myrow["qty_done"]) { - if ($line->stock_id == $myrow["stk_code"]) - { - if ($line->quantity != $myrow["quantity"] || - $line->qty_inv != $myrow["qty_invoiced"]) - { - display_note(_("Original order for") . " " . $myrow["stk_code"] . " " . - _("has a quantity of") . " " . $myrow["quantity"] . " " . - _("and an invoiced quantity of") . " " . $myrow["qty_invoiced"] . " " . - _("the session shows quantity of") . " " . - $line->quantity . " " . - _("and quantity invoice of") . " " . - $line->qty_inv, 1, 0); - - return false; - } - } + display_note(_("Original delivery for line #") . $line+1 . ' '. + _("has a quantity of") . " " . -$myrow["quantity"] . " " . + _("and an delivered quantity of") . " " . -$myrow["qty_done"] . "." . + _("Now the quantity of") . " " . + $_SESSION['Items']->line_items[$line]->quantity . " " . + _("and invoiced quantity of") . " " . + $_SESSION['Items']->line_items[$line]->qty_done, 1, 0); + + return false; } + $line++; } /*loop through all line items of the order to ensure none have been invoiced */ - return true; } @@ -191,42 +185,42 @@ function check_order_changed() function check_data() { - if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate'])) + if (!isset($_POST['InvoiceDate']) || !is_date($_POST['InvoiceDate'])) { display_error(_("The entered invoice date is invalid.")); return false; } - if (!is_date_in_fiscalyear($_POST['DispatchDate'])) + if (!is_date_in_fiscalyear($_POST['InvoiceDate'])) { display_error(_("The entered invoice date is not in fiscal year.")); return false; } - if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) + if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) { display_error(_("The entered invoice due date is invalid.")); return false; } - if (!references::is_valid($_POST['ref'])) + if (!references::is_valid($_POST['ref'])) { display_error(_("You must enter a reference.")); return false; } - if (!is_new_reference($_POST['ref'], 10)) + if (!is_new_reference($_POST['ref'], 10)) { display_error(_("The entered reference is already in use.")); return false; } if ($_POST['ChargeFreightCost'] == "") $_POST['ChargeFreightCost'] = 0; - if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0) + if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0) { display_error(_("The entered shipping value is not numeric.")); return false; } - if ($_SESSION['Items']->has_items_dispatch() == 0 && $_POST['ChargeFreightCost'] == 0) + if ($_SESSION['Items']->has_items_dispatch() == 0 && $_POST['ChargeFreightCost'] == 0) { display_error(_("There are no item quantities on this invoice.")); return false; @@ -237,71 +231,37 @@ function check_data() //--------------------------------------------------------------------------------------------------------------- -function check_qoh() -{ - if (!sys_prefs::allow_negative_stock()) - { - foreach ($_SESSION['Items']->line_items as $itm) - { - - if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag)) - { - $qoh = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']); - - if ($itm->qty_dispatched > $qoh) - { - display_error(_("The invoice cannot be processed because there is an insufficient quantity for component:") . - " " . $itm->stock_id . " - " . $itm->item_description); - return false; - } - } - } - } - - return true; -} - -//--------------------------------------------------------------------------------------------------------------- - function process_invoice($invoicing=false) { - if ($invoicing) + if ($invoicing) { - - read_sales_order($_SESSION['Items']->order_no, $_SESSION['Items'], true); + read_sales_delivery($_SESSION['Items']->trans_no, $_SESSION['Items']); $duedate = get_invoice_duedate($_SESSION['Items']->customer_id, $_SESSION['Items']->delivery_date); $invoice_no = add_sales_invoice($_SESSION['Items'], - $_SESSION['Items']->delivery_date, $duedate, $_SESSION['Items']->order_no, + $_SESSION['Items']->delivery_date, $duedate, $_SESSION['Items']->tax_group_id, $_SESSION['Items']->freight_cost, $_SESSION['Items']->Location, $_SESSION['Items']->ship_via, $_SESSION['Items']->default_sales_type, references::get_next(10), - $_SESSION['Items']->memo_, 0); - } - else + $_SESSION['Items']->memo_); + } + else { - + if (!check_data()) return; - if (!check_order_changed()) - order_changed_error(); - - if (!check_qoh()) - return; - - if ($_POST['bo_policy']) - $bo_policy = 0; - else - $bo_policy = 1; + if (!check_delivery_changed()) + delivery_changed_error(); $invoice_no = add_sales_invoice($_SESSION['Items'], - $_POST['DispatchDate'], $_POST['due_date'], $_SESSION['ProcessingOrder'], - $_POST['tax_group_id'], $_POST['ChargeFreightCost'], $_POST['Location'], + $_POST['InvoiceDate'], $_POST['due_date'], + $_SESSION['Items']->tax_group_id, + $_POST['ChargeFreightCost'], + $_SESSION['Items']->Location, $_POST['ship_via'], $_POST['sales_type_id'], $_POST['ref'], - $_POST['InvoiceText'], $bo_policy); - unset($_SESSION['ProcessingOrder']); + $_POST['InvoiceText']); + unset($_SESSION['ProcessingDelivery']); } - meta_forward($_SERVER['PHP_SELF'], "AddedID=$invoice_no"); } @@ -316,9 +276,9 @@ elseif (isset($_POST['process_invoice'])) start_form(false, true); start_table("$table_style2 width=80%", 5); -echo ""; // outer table +//echo ""; // outer table -start_table("$table_style width=100%"); +//start_table("$table_style width=100%"); start_row(); label_cells(_("Customer"), $_SESSION['Items']->customer_name, "class='tableheader2'"); label_cells(_("Branch"), get_branch_name($_SESSION['Items']->Branch), "class='tableheader2'"); @@ -331,95 +291,75 @@ if (!isset($_POST['ref'])) ref_cells(_("Reference"), 'ref', null, "class='tableheader2'"); -if (!isset($_POST['tax_group_id'])) - $_POST['tax_group_id'] = $_SESSION['Items']->tax_group_id; -label_cell(_("Tax Group"), "class='tableheader2'"); -tax_groups_list_cells(null, 'tax_group_id', $_POST['tax_group_id'], false, null, true); +label_cells(_("Delivery Notes:"), get_customer_trans_view_str(systypes::cust_dispatch(), $_SESSION['ProcessingDelivery']), "class='tableheader2'"); -label_cells(_("For Sales Order"), get_customer_trans_view_str(systypes::sales_order(), $_SESSION['ProcessingOrder']), "class='tableheader2'"); - -end_row(); -start_row(); if (!isset($_POST['sales_type_id'])) $_POST['sales_type_id'] = $_SESSION['Items']->default_sales_type; -label_cell(_("Sales Type"), "class='tableheader2'"); +label_cell(_("Sales Type"), "class='tableheader2'"); sales_types_list_cells(null, 'sales_type_id', $_POST['sales_type_id']); -if (!isset($_POST['Location'])) - $_POST['Location'] = $_SESSION['Items']->Location; -label_cell(_("Delivery From"), "class='tableheader2'"); -locations_list_cells(null, 'Location', $_POST['Location'], false, true); +end_row(); +start_row(); if (!isset($_POST['ship_via'])) $_POST['ship_via'] = $_SESSION['Items']->ship_via; -label_cell(_("Shipping Company"), "class='tableheader2'"); +label_cell(_("Shipping Company"), "class='tableheader2'"); shippers_list_cells(null, 'ship_via', $_POST['ship_via']); -end_row(); -end_table(); +if (!isset($_POST['InvoiceDate']) || !is_date($_POST['InvoiceDate'])) +{ + $_POST['InvoiceDate'] = Today(); + if (!is_date_in_fiscalyear($_POST['InvoiceDate'])) + $_POST['InvoiceDate'] = end_fiscalyear(); +} -echo "";// outer table +date_cells(_("Date"), 'InvoiceDate', $_POST['InvoiceDate'], 0, 0, 0, "class='tableheader'"); +//end_table(); -start_table("$table_style width=90%"); +//echo "";// outer table -// set this up here cuz it's used to calc qoh -if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate'])) -{ - $_POST['DispatchDate'] = Today(); - if (!is_date_in_fiscalyear($_POST['DispatchDate'])) - $_POST['DispatchDate'] = end_fiscalyear(); -} -date_row(_("Date"), 'DispatchDate', $_POST['DispatchDate'], 0, 0, 0, "class='tableheader'"); +//start_table("$table_style width=90%"); if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) - //$_POST['due_date'] = $_POST['DispatchDate']; - $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->customer_id, $_POST['DispatchDate']); -date_row(_("Due Date"), 'due_date', $_POST['due_date'], 0, 0, 0, "class='tableheader'"); -end_table(); + $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->customer_id, $_POST['InvoiceDate']); -echo ""; -end_table(1); // outer table +date_cells(_("Due Date"), 'due_date', $_POST['due_date'], 0, 0, 0, "class='tableheader'"); +//end_table(); + +//echo ""; +end_row(); +end_table(); // outer table display_heading(_("Invoice Items")); start_table("$table_style width=80%"); -$th = array(_("Item Code"), _("Item Description"), _("Ordered"), _("Units"), _("Delivered"), - _("This Delivery"), _("Price"), _("Tax Type"), _("Discount"), _("Total")); +$th = array(_("Item Code"), _("Item Description"), _("Delivered"), _("Units"), _("Invoiced"), + _("This Invoice"), _("Price"), _("Tax Type"), _("Discount"), _("Total")); table_header($th); $k = 0; $has_marked = false; $show_qoh = true; -foreach ($_SESSION['Items']->line_items as $ln_itm) +foreach ($_SESSION['Items']->line_items as $line=>$ln_itm) { + if($ln_itm->quantity==$ln_itm->qty_done) continue; //this line is fully delivered + alt_table_row_color($k); - // if it's a non-stock item (eg. service) don't show qoh - if (sys_prefs::allow_negative_stock() || !has_stock_holding($ln_itm->mb_flag) || - $ln_itm->qty_dispatched == 0) - $show_qoh = false; - - if ($show_qoh) - $qoh = get_qoh_on_date($ln_itm->stock_id, $_POST['Location'], $_POST['DispatchDate']); - - if ($show_qoh && ($ln_itm->qty_dispatched > $qoh)) - { - // oops, we don't have enough of one of the component items - start_row("class='stockmankobg'"); - $has_marked = true; - } - else - alt_table_row_color($k); + view_stock_status_cell($ln_itm->stock_id); // ? - view_stock_status_cell($ln_itm->stock_id); - - text_cells(null, $ln_itm->stock_id . "Desc", $ln_itm->item_description, 30, 50); + text_cells(null, 'Line'.$line.'Desc', $ln_itm->item_description, 30, 50); qty_cell($ln_itm->quantity); label_cell($ln_itm->units); - qty_cell($ln_itm->qty_inv); + qty_cell($ln_itm->qty_done); - text_cells(null, $ln_itm->stock_id, $ln_itm->qty_dispatched, 10, 10); + if(count($_SESSION['Items']->trans_no)>1) { + // for batch invoices we can process only whole deliveries + qty_cell($ln_itm->qty_dispatched); + hidden('Line'.$line,$ln_itm->qty_dispatched ); + } else + text_cells(null, 'Line'.$line, $ln_itm->qty_dispatched, 10, 10); $display_discount_percent = number_format2($ln_itm->discount_percent*100,user_percent_dec()) . "%"; @@ -430,8 +370,6 @@ foreach ($_SESSION['Items']->line_items as $ln_itm) label_cell($display_discount_percent, "nowrap align=right"); amount_cell($line_total); - //label_cell(get_tax_free_price_for_item($ln_itm->stock_id, $line_total, $_POST['tax_group_id'])); - end_row(); } @@ -440,13 +378,13 @@ depending on the business logic required this condition may not be required. It seems unfair to charge the customer twice for freight if the order was not fully delivered the first time ?? */ -if (!isset($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] == "") +if (!isset($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] == "") { - if ($_SESSION['Items']->any_already_delivered() == 1) + if ($_SESSION['Items']->any_already_delivered() == 1) { $_POST['ChargeFreightCost'] = 0; - } - else + } + else { $_POST['ChargeFreightCost'] = $_SESSION['Items']->freight_cost; } @@ -466,7 +404,7 @@ $display_sub_total = number_format2($inv_items_total + $_POST['ChargeFreightCost label_row(_("Sub-total"), $display_sub_total, "colspan=9 align=right","align=right"); -$taxes = $_SESSION['Items']->get_taxes($_POST['tax_group_id'], $_POST['ChargeFreightCost']); +$taxes = $_SESSION['Items']->get_taxes($_SESSION['Items']->tax_group_id, $_POST['ChargeFreightCost']); $tax_total = display_edit_tax_items($taxes, 9); $display_total = number_format2(($inv_items_total + $_POST['ChargeFreightCost'] + $tax_total), user_price_dec()); @@ -475,13 +413,11 @@ label_row(_("Invoice Total"), $display_total, "colspan=9 align=right","align=rig end_table(1); -if ($has_marked) - display_note(_("Marked items have insufficient quantities in stock."), 0, 1, "class='red'"); +//if ($has_marked) +// display_note(_("Marked items have insufficient quantities in stock."), 0, 1, "class='red'"); start_table($table_style2); -policy_list_row(_("Action For Balance"), "bo_policy", null); - textarea_row(_("Memo"), 'InvoiceText', null, 50, 4); end_table(1); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index d5558d30..25de205d 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -6,7 +6,7 @@ this class can hold all the information for: i) a sales order ii) an invoice iii) a credit note - +iv) a delivery note */ include_once($path_to_root . "/inventory/includes/inventory_db.inc"); @@ -22,7 +22,7 @@ class cart var $sales_type_name; // set to customer's sales type name var $customer_currency; // set to the customer's currency var $default_discount; // set to the customer's discount % - var $direct_invoice; // direct invoicing + var $trans_type; // invoice, order, delivery note ... var $memo_; // memo_ on direct invoicing var $deliver_to; @@ -34,8 +34,8 @@ class cart var $Comments; var $Location; var $location_name; - - var $order_no; // the order number + var $order_no; // the original order number + var $trans_no;// transaction number var $customer_name; var $customer_id; @@ -49,26 +49,20 @@ class cart var $tax_group_id; var $tax_group_name; - var $lines_on_order; - - function Cart() + function Cart($type = 'order') { /*Constructor function initialises a new shopping cart */ $this->line_items = array(); $this->default_sales_type = ""; - $this->direct_invoice=false; - $this->lines_on_order = 0; + $this->trans_type = $type; } - function add_to_cart($line_no, $id, $stock_id, $qty, $price, $disc, $qty_invoiced=0, $standard_cost=0, $description=null) + function add_to_cart($stock_id, $qty, $price, $disc, $qty_done=0, $standard_cost=0, $description=null, $id=0) { - - if (isset($stock_id) && $stock_id != "" && isset($qty) && $qty > 0) + if (isset($stock_id) && $stock_id != "" && isset($qty)/* && $qty > 0*/) { - - $this->line_items[$line_no] = new line_details($line_no, $id, $stock_id, $qty, $price, $disc, - $qty_invoiced, $standard_cost, $description); - $this->lines_on_order++; + $this->line_items[] = new line_details($stock_id, $qty, $price, $disc, + $qty_done, $standard_cost, $description, $id); return 1; } else @@ -89,7 +83,6 @@ class cart $this->line_items[$line_no]->price = $price; $this->line_items[$line_no]->discount_percent = $disc; } - function update_add_cart_item_qty($line_no, $qty) { $this->line_items[$line_no]->quantity += $qty; @@ -97,7 +90,7 @@ class cart function remove_from_cart($line_no) { - $this->line_items[$line_no]->Deleted = true; + unset($this->line_items[$line_no]); } function clear_items() @@ -105,13 +98,17 @@ class cart unset($this->line_items); $this->line_items = array(); $this->default_sales_type = ""; + $this->trans_no = 0; $this->customer_id = $this->order_no = 0; - $this->lines_on_order = 0; } function count_items() { - return count($this->line_items); + $counter=0; + foreach($this->line_items as $line) { + if($line->quantity>$line->qty_done) $counter++; + } + return $counter; } function get_items_total_dispatch($tax_group_id=null) @@ -163,7 +160,7 @@ class cart foreach ($this->line_items as $stock_item) { - if ($stock_item->qty_inv !=0) + if ($stock_item->qty_done !=0) { return 1; } @@ -176,8 +173,8 @@ class cart function some_already_delivered($line_no) { /* Checks if there have been deliveries of a specific line item */ - if (isset($this->line_items[$line_no]) && - $this->line_items[$line_no]->qty_inv != 0) + if (isset($this->line_items[$line_no]) && + $this->line_items[$line_no]->qty_done != 0) { return 1; } @@ -197,11 +194,8 @@ class cart foreach ($this->line_items as $ln_itm) { - if (!$ln_itm->Deleted) - { $items[] = $ln_itm->stock_id; $prices[] = ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent)); - } } @@ -226,17 +220,15 @@ class line_details var $quantity; var $price; var $discount_percent; - var $qty_inv; - var $qty_dispatched; + var $qty_done; // quantity processed so far + var $qty_dispatched; // quantity selected to process var $standard_cost; - var $Deleted; - function line_details ($line_no, $id, $stock_id, $qty, $prc, $disc_percent, - $qty_invoiced, $standard_cost, $description) + function line_details ($stock_id, $qty, $prc, $disc_percent, + $qty_done, $standard_cost, $description, $id=0) { /* Constructor function to add a new LineDetail object with passed params */ - $this->line_no = $line_no; $this->id = $id; $item_row = get_item($stock_id); @@ -257,10 +249,8 @@ class line_details $this->quantity = $qty; $this->price = $prc; $this->discount_percent = $disc_percent; - $this->qty_inv = $qty_invoiced; - $this->qty_dispatched = $qty - $qty_invoiced; + $this->qty_done = $qty_done; $this->standard_cost = $standard_cost; - $this->Deleted = false; } function full_price() diff --git a/sales/includes/db/cust_trans_db.inc b/sales/includes/db/cust_trans_db.inc index 48af1690..e0623103 100644 --- a/sales/includes/db/cust_trans_db.inc +++ b/sales/includes/db/cust_trans_db.inc @@ -7,7 +7,7 @@ function add_customer_trans($trans_type, $debtor_no, $BranchNo, $date_, $reference, $Total, $discount=0, $Tax=0, $Freight=0, - $sales_type=0, $order_no=0, $ship_via="", $due_date=null, + $sales_type=0, $order_no=0, $trans_link=0, $ship_via="", $due_date=null, $AllocAmt=0) { $trans_no = get_next_trans_no($trans_type); @@ -25,11 +25,11 @@ function add_customer_trans($trans_type, $debtor_no, $BranchNo, reference, tpe, order_, ov_amount, ov_discount, ov_gst, ov_freight, rate, - ship_via, alloc) - VALUES ($trans_no, $trans_type, '$debtor_no', '$BranchNo', + ship_via, alloc, trans_link + ) VALUES ($trans_no, $trans_type, '$debtor_no', '$BranchNo', '$SQLDate', '$SQLDueDate', '$reference', '$sales_type', $order_no, $Total, $discount, $Tax, $Freight, $rate, - '$ship_via', $AllocAmt)"; + '$ship_via', $AllocAmt, $trans_link)"; db_query($sql, "The debtor transaction record could not be inserted"); @@ -52,7 +52,7 @@ function get_customer_trans($trans_id, $trans_type) ".TB_PREF."bank_trans_types.name AS BankTransType "; } - if ($trans_type == 10 OR $trans_type == 11) + if ($trans_type == 10 OR $trans_type == 11 OR $trans_type == 13) { // it's an invoice so also get the shipper and salestype $sql .= ", ".TB_PREF."shippers.shipper_name, ".TB_PREF."sales_types.sales_type "; @@ -67,7 +67,7 @@ function get_customer_trans($trans_id, $trans_type) $sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts, ".TB_PREF."bank_trans_types "; } - if ($trans_type == 10 OR $trans_type == 11) + if ($trans_type == 10 OR $trans_type == 11 OR $trans_type == 13) { // it's an invoice so also get the shipper, salestypes $sql .= ", ".TB_PREF."shippers, ".TB_PREF."sales_types "; @@ -85,7 +85,7 @@ function get_customer_trans($trans_id, $trans_type) AND ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id AND ".TB_PREF."bank_accounts.account_code=".TB_PREF."bank_trans.bank_act "; } - if ($trans_type == 10 OR $trans_type == 11) + if ($trans_type == 10 OR $trans_type == 11 OR $trans_type == 13) { // it's an invoice so also get the shipper $sql .= " AND ".TB_PREF."shippers.shipper_id=".TB_PREF."debtor_trans.ship_via @@ -198,6 +198,9 @@ function post_void_customer_trans($type, $type_no) case 11 : void_sales_invoice($type, $type_no); break; + case 13 : + void_sales_delivery($type, $type_no); + break; case systypes::cust_payment() : void_customer_payment($type, $type_no); break; @@ -206,5 +209,12 @@ function post_void_customer_trans($type, $type_no) //---------------------------------------------------------------------------------------- +function get_customer_trans_link($type, $type_no) +{ + $row = db_query("SELECT trans_link from debtor_trans + WHERE type=$type AND trans_no=$type_no", "could not get transaction link for type=$type and trans_no=$type_no"); + return $row[0]; +} +//---------------------------------------------------------------------------------------- ?> \ No newline at end of file diff --git a/sales/includes/db/cust_trans_details_db.inc b/sales/includes/db/cust_trans_details_db.inc index b0f7a90a..c3e021bc 100644 --- a/sales/includes/db/cust_trans_details_db.inc +++ b/sales/includes/db/cust_trans_details_db.inc @@ -20,7 +20,7 @@ function get_customer_trans_details($debtor_trans_type, $debtor_trans_no) ".TB_PREF."stock_master.units FROM ".TB_PREF."debtor_trans_details,".TB_PREF."stock_master WHERE debtor_trans_no=$debtor_trans_no - AND debtor_trans_type=$debtor_trans_type + AND debtor_trans_type=$debtor_trans_type AND ".TB_PREF."stock_master.stock_id=".TB_PREF."debtor_trans_details.stock_id ORDER BY id"; @@ -46,11 +46,12 @@ function void_customer_trans_details($type, $type_no) function add_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description, $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent, - $reference, $std_cost) + $reference, $std_cost) { add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description, $quantity, $unit_price, $unit_tax, $discount_percent, $std_cost); + if($debtor_trans_type==13) add_stock_move_customer($debtor_trans_type, $stock_id, $debtor_trans_no, $Location, $date_, $reference, $quantity, $std_cost, 1, $unit_price+$unit_tax, $discount_percent); diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 84d5fb68..e0951cb6 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -114,14 +114,14 @@ function credit_invoice($credit_items, $invoice_no, $order_no, { // always deduct the credited/returned quantities from the sales order - dispatch_sales_order_item($order_no, $order_line->id, -$order_line->qty_dispatched); - + dispatch_sales_order_item($order_no, $order_line->stock_id, -$order_line->qty_dispatched, $order_line->id); + //if (($_POST['credit_type']=="Return") OR ($_POST['ItemsAction']==1)) /*{ - $sql = "UPDATE ".TB_PREF."sales_order_details - SET qty_invoiced = qty_invoiced - " . $order_line->qty_dispatched . " - WHERE order_no = " . $order_no . " - AND id = '" . $order_line->id . "'"; + $sql = "UPDATE ".TB_PREF."sales_order_details + SET qty_sent = qty_sent - " . $order_line->qty_dispatched . " + WHERE order_no = " . $order_no . " + AND stk_code = '" . $order_line->stock_id . "'"; $result = db_query($sql,"The sales order detail record could not be updated for the reduced quantity invoiced"); }*/ diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc new file mode 100644 index 00000000..5ab4180b --- /dev/null +++ b/sales/includes/db/sales_delivery_db.inc @@ -0,0 +1,250 @@ +Branch); + + $delivery_items_total = $delivery->get_items_total_dispatch($tax_group_id); + + $tax_total = 0; + $taxes = $delivery->get_taxes($tax_group_id, $charge_shipping); + foreach ($taxes as $taxitem) + $tax_total += $taxitem['Value']; + + /*Now insert the debtor_trans */ + $delivery_no = add_customer_trans(13, $delivery->customer_id, $delivery->Branch, $date_, + $reference, $delivery_items_total, 0, $tax_total, $charge_shipping, + $sales_type, $sales_order, 0, $ship_via, $due_date); + + // If balance of this delivery cancelled update sales order details quantity. + foreach ($delivery->line_items as $delivery_line) + { + $line_taxfree_price = $delivery_line->taxfree_price($tax_group_id); + /* add delivery details for _all_ lines */ + add_customer_trans_detail_item(13, $delivery_no, $delivery_line->stock_id, + $delivery_line->item_description, $location, $date_, + -$delivery_line->qty_dispatched, $line_taxfree_price, 0, + $delivery_line->discount_percent, $reference, $delivery_line->standard_cost); + + if ($delivery_line->qty_dispatched != 0) + { + // Now update sales_order_details for the quantity delivered + dispatch_sales_order_item($sales_order, $delivery_line->stock_id, + $delivery_line->qty_dispatched, $delivery_line->id); + + $stock_gl_code = get_stock_gl_code($delivery_line->stock_id); + + /* insert gl_trans to credit stock and debit cost of sales at standard cost*/ + if ($delivery_line->standard_cost != 0) + { + + /*first the cost of sales entry*/ + add_gl_trans_std_cost(13, $delivery_no, $date_, $stock_gl_code["cogs_account"], + $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], "", + $delivery_line->standard_cost * $delivery_line->qty_dispatched, + payment_person_types::customer(), $delivery->customer_id, + "The cost of sales GL posting could not be inserted"); + + /*now the stock entry*/ + //$stock_gl_code = get_stock_gl_code($order_line->stock_id); + + add_gl_trans_std_cost(13, $delivery_no, $date_, $stock_gl_code["inventory_account"], 0, 0, "", + (-$delivery_line->standard_cost * $delivery_line->qty_dispatched), + payment_person_types::customer(), $delivery->customer_id, + "The stock side of the cost of sales GL posting could not be inserted"); + + } /* end of if GL and stock integrated and standard cost !=0 */ + + } /*quantity dispatched is more than 0 */ + } /*end of order_line loop */ + + if ($bo_policy == 0) + { + // if cancelling any remaining quantities + close_sales_order($sales_order); + } + + add_comments(13, $delivery_no, $date_, $memo_); + + add_forms_for_sys_type(13, $delivery_no, $location); + + references::save_last($reference, 13); + + commit_transaction(); + + return $delivery_no; +} + +//-------------------------------------------------------------------------------------------------- + +function void_sales_delivery($type, $type_no) +{ + begin_transaction(); + + void_gl_trans($type, $type_no, true); + + // for invoices and credits related to invoices, + // reverse all the changes in the sales order + $items_result = get_customer_trans_details($type, $type_no); + + $order = get_customer_trans_order($type, $type_no); + + if ($order) + { + while ($row = db_fetch($items_result)) + { + dispatch_sales_order_item($order, $row["stock_id"], $row["quantity"]); + } + } + + // clear details after they've been reversed in the sales order + void_customer_trans_details($type, $type_no); + + void_customer_trans_tax_details($type, $type_no); + + void_cust_allocations($type, $type_no); + + // do this last because other voidings can depend on it + // DO NOT MOVE THIS ABOVE VOIDING or we can end up with trans with alloc < 0 + void_customer_trans($type, $type_no); + + commit_transaction(); +} + +//---------------------------------------------------------------------------------------- + +function get_sales_delivery($trans_no) +{ + $sql = "SELECT ".TB_PREF."debtor_trans.*, cust_branch.*, + ".TB_PREF."debtors_master.name, + ".TB_PREF."debtors_master.curr_code, + ".TB_PREF."debtors_master.payment_terms, + ".TB_PREF."debtors_master.discount, + ".TB_PREF."sales_types.sales_type, + ".TB_PREF."shippers.shipper_name, + ".TB_PREF."tax_groups.name AS tax_group_name , + ".TB_PREF."tax_groups.id AS tax_group_id + FROM ".TB_PREF."debtor_trans, + ".TB_PREF."debtors_master, + ".TB_PREF."sales_types, + ".TB_PREF."tax_groups, + ".TB_PREF."cust_branch, + ".TB_PREF."shippers + WHERE ".TB_PREF."debtor_trans.type=13 + AND ".TB_PREF."debtor_trans.tpe=".TB_PREF."sales_types.id + AND ".TB_PREF."cust_branch.branch_code = ".TB_PREF."debtor_trans.branch_code + AND ".TB_PREF."cust_branch.tax_group_id = ".TB_PREF."tax_groups.id + AND ".TB_PREF."debtor_trans.debtor_no = ".TB_PREF."debtors_master.debtor_no + AND ".TB_PREF."shippers.shipper_id = ".TB_PREF."debtor_trans.ship_via + AND ".TB_PREF."debtor_trans.trans_no = "; + + if(is_array($trans_no)) { //assume all transactions are for the same customer/branch + $sql .= $trans_no[0]; + } else { + $sql .= $trans_no; + } + + $result = db_query($sql, "delivery Retreival"); + + $num = db_num_rows($result); + if ($num > 1) + { + display_db_error("FATAL : delivery note query returned a duplicate - " . db_num_rows($result), $sql, true); + } + else if ($num == 1) + { + return db_fetch($result); + } + else + display_db_error("FATAL : delivery note search return nothing - " . db_num_rows($result), $sql, true); + +} + +//function get_sales_delivery_details($delivery) { +// if(!is_array($delivery)) { +// +// } +//} +//-------------------------------------------------------------------------------------------------- + +function read_sales_delivery($trans_no, &$cart) +{ + $myrow = get_sales_delivery($trans_no); + + if(!is_array($trans_no)) $trans_no = array($trans_no); + + $cart->customer_id = $myrow["debtor_no"]; + $cart->Branch = $myrow["branch_code"]; + $cart->customer_name = $myrow["name"]; + $cart->cust_ref = $myrow["reference"]; + $cart->default_sales_type =$myrow["tpe"]; + $cart->sales_type_name =$myrow["sales_type"]; + $cart->customer_currency = $myrow["curr_code"]; + $cart->default_discount = $myrow["discount"]; + $cart->order_no = $myrow["order_"]; + +// $cart->Comments = get_comments(13,$trans_no); + + $cart->ship_via = $myrow["ship_via"]; + $cart->deliver_to = $myrow["br_name"]; + $cart->delivery_date = sql2date($myrow["due_date"]); + $cart->freight_cost = $myrow["ov_freight"]; + $cart->delivery_address = $myrow["br_address"]; + $cart->phone = $myrow["phone"]; + $cart->email = $myrow["email"]; + +// $cart->Location = $myrow["location"]; +// $cart->location_name = $myrow["location_name"]; + + $cart->orig_order_date = sql2date($myrow["tran_date"]); + + $cart->tax_group_name = $myrow["tax_group_name"]; + $cart->tax_group_id = $myrow["tax_group_id"]; + + $sql = "SELECT ".TB_PREF."debtor_trans_details.stock_id, unit_price, + debtor_trans_no, + ".TB_PREF."debtor_trans_details.description, + ".TB_PREF."debtor_trans_details.id, + ".TB_PREF."debtor_trans_details.quantity, discount_percent, + qty_done, ".TB_PREF."stock_master.units, + ".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost AS standard_cost + FROM ".TB_PREF."debtor_trans_details, ".TB_PREF."stock_master + WHERE ".TB_PREF."debtor_trans_details.debtor_trans_type=13 AND + " .TB_PREF."debtor_trans_details.stock_id = ".TB_PREF."stock_master.stock_id"; + + $sql .= ' AND ('; + foreach($trans_no as $key=>$num) { + if($key!=0) $sql .= ' OR '; + $sql .= 'debtor_trans_no =' . $num; + } + $sql .= ') ORDER BY id'; + + $result = db_query($sql, "Retreive Delivery Note Items"); + + if (db_num_rows($result) > 0) + { + + while ($myrow = db_fetch($result)) + { + $cart->add_to_cart($myrow["stock_id"],-$myrow["quantity"], + $myrow["unit_price"], $myrow["discount_percent"], + -$myrow["qty_done"], $myrow["standard_cost"], $myrow["description"],$myrow["id"]); + } + } + + foreach($cart->line_items as $key=>$line) + $cart->line_items[$key]->qty_dispatched = + $cart->line_items[$key]->quantity - $cart->line_items[$key]->qty_done; + + return true; +} + +?> \ No newline at end of file diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 3fd2aa09..49f9252f 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -1,144 +1,146 @@ trans_no)==1) { + + $del = $cart->trans_no; + if(is_array($del)) $del = $del[0]; + $sql = 'UPDATE debtor_trans SET trans_link = ' . $del . + ' WHERE type=10 AND trans_no='.$invoice; + db_query($sql, 'Invoice link cannot be updated'); + + foreach($cart->line_items as $line) { + if($line->quantity!=$line->qty_dispatched) { + // this is partial invoice + return 1; + } + } + + } -// $bo_policy = 0, cancel remaining quantities on order -// = 1, backorder remaining quantities + $sql = 'UPDATE debtor_trans SET trans_link = ' . $invoice . + ' WHERE type=13 AND ('; + + $deliveries = $cart->trans_no; + + foreach($deliveries as $key=>$del) + $deliveries[$key] = 'trans_no='.$del; + $sql .= implode(' OR ', $deliveries) . ')'; + + db_query($sql, 'Delivery links cannot be updated'); + return 0; // batch or complete invoice +} -function add_sales_invoice(&$invoice, $date_, $due_date, $sales_order, $tax_group_id, - $charge_shipping, $location, $ship_via, $sales_type, $reference, $memo_, $bo_policy) +function add_sales_invoice(&$cart, $date_, $due_date, $tax_group_id, + $charge_shipping, $location, $ship_via, $sales_type, $reference, $memo_) { begin_transaction(); - + $company_data = get_company_prefs(); - - $branch_data = get_branch_accounts($invoice->Branch); - - $invoice_items_total = $invoice->get_items_total_dispatch($tax_group_id); - + + $branch_data = get_branch_accounts($cart->Branch); + + $cart_items_total = $cart->get_items_total_dispatch($tax_group_id); + + $delivery_no = $cart->trans_no; + if(is_array($delivery_no)) $delivery_no = 0; + $tax_total = 0; - $taxes = $invoice->get_taxes($tax_group_id, $charge_shipping); + $taxes = $cart->get_taxes($tax_group_id, $charge_shipping); foreach ($taxes as $taxitem) $tax_total += $taxitem['Value']; /*Now insert the debtor_trans */ + $sales_order=$cart->order_no; + if(is_array($sales_order)) $sales_order = $sales_order[0]; // assume all crucial SO data are same for every delivery - $invoice_no = add_customer_trans(10, $invoice->customer_id, $invoice->Branch, $date_, - $reference, $invoice_items_total, 0, $tax_total, $charge_shipping, - $sales_type, $sales_order, $ship_via, $due_date); + $invoice_no = add_customer_trans(10, $cart->customer_id, $cart->Branch, $date_, + $reference, $cart_items_total, 0, $tax_total, $charge_shipping, + $sales_type, $sales_order, $delivery_no, $ship_via, $due_date); - // If balance of the order cancelled update sales order details quantity. - foreach ($invoice->line_items as $order_line) + set_invoice_links($cart,$invoice_no); + + // If balance of the order cancelled update sales order details quantity. + foreach ($cart->line_items as $delivery_line) { - if ($order_line->qty_dispatched != 0) + if ($delivery_line->qty_dispatched != 0) { - - $line_taxfree_price = $order_line->taxfree_price($tax_group_id); - $line_tax = $order_line->full_price() - $line_taxfree_price; - - // Now update sales_order_details for the quantity invoiced - dispatch_sales_order_item($sales_order, $order_line->id, - $order_line->qty_dispatched); - + + $line_taxfree_price = $delivery_line->taxfree_price($tax_group_id); + $line_tax = $delivery_line->full_price() - $line_taxfree_price; + + // Now update delivery items for the quantity invoiced + invoice_delivery_item($delivery_line->id,$delivery_line->qty_dispatched); + /* add invoice details and stock movements */ - $memo_ = ""; - add_customer_trans_detail_item(10, $invoice_no, $order_line->stock_id, - $order_line->item_description, $location, $date_, - -$order_line->qty_dispatched, $line_taxfree_price, $line_tax, - $order_line->discount_percent, $memo_, $order_line->standard_cost); + add_customer_trans_detail_item(10, $invoice_no, $delivery_line->stock_id, + $delivery_line->item_description, $location, $date_, + -$delivery_line->qty_dispatched, $line_taxfree_price, $line_tax, + $delivery_line->discount_percent, $reference, $delivery_line->standard_cost); + + $stock_gl_code = get_stock_gl_code($delivery_line->stock_id); - $stock_gl_code = get_stock_gl_code($order_line->stock_id); - - /* insert gl_trans to credit stock and debit cost of sales at standard cost*/ - if ($order_line->standard_cost != 0) - { - - /*first the cost of sales entry*/ - add_gl_trans_std_cost(10, $invoice_no, $date_, $stock_gl_code["cogs_account"], - $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], "", - $order_line->standard_cost * $order_line->qty_dispatched, - payment_person_types::customer(), $invoice->customer_id, - "The cost of sales GL posting could not be inserted"); - - /*now the stock entry*/ - //$stock_gl_code = get_stock_gl_code($order_line->stock_id); - - add_gl_trans_std_cost(10, $invoice_no, $date_, $stock_gl_code["inventory_account"], 0, 0, "", - (-$order_line->standard_cost * $order_line->qty_dispatched), - payment_person_types::customer(), $invoice->customer_id, - "The stock side of the cost of sales GL posting could not be inserted"); - - } /* end of if GL and stock integrated and standard cost !=0 */ - - if ($order_line->price != 0) + if ($delivery_line->price != 0) { //Post sales transaction to GL credit sales - - add_gl_trans_customer(10, $invoice_no, $date_, $stock_gl_code["sales_account"], - $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], - (-$line_taxfree_price * $order_line->qty_dispatched), - $invoice->customer_id, "The sales price GL posting could not be inserted"); - - if ($order_line->discount_percent != 0) + + add_gl_trans_customer(10, $invoice_no, $date_, $stock_gl_code["sales_account"], + $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], + (-$line_taxfree_price * $delivery_line->qty_dispatched), + $cart->customer_id, "The sales price GL posting could not be inserted"); + + if ($delivery_line->discount_percent != 0) { - - add_gl_trans_customer(10, $invoice_no, $date_, - $branch_data["sales_discount_account"], $stock_gl_code["dimension_id"], + + add_gl_trans_customer(10, $invoice_no, $date_, + $branch_data["sales_discount_account"], $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], - ($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent), - $invoice->customer_id, "The sales discount GL posting could not be inserted"); + ($line_taxfree_price * $delivery_line->qty_dispatched * $delivery_line->discount_percent), + $cart->customer_id, "The sales discount GL posting could not be inserted"); } /*end of if discount !=0 */ } /*end of if sales integrated with debtors */ } /*quantity dispatched is more than 0 */ - } /*end of order_line loop */ - - - if ($bo_policy == 0) - { - // if cancelling any remaining quantities - close_sales_order($sales_order); - } + } /*end of delivery_line loop */ /*Post debtors transaction to GL debit debtors, credit freight re-charged and credit sales */ - if (($invoice_items_total + $charge_shipping + $tax_total) != 0) + if (($cart_items_total + $charge_shipping + $tax_total) != 0) { - add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0, - ($invoice_items_total + $charge_shipping + $tax_total), - $invoice->customer_id, "The total debtor GL posting could not be inserted"); + ($cart_items_total + $charge_shipping + $tax_total), + $cart->customer_id, "The total debtor GL posting could not be inserted"); } - if ($charge_shipping != 0) + if ($charge_shipping != 0) { - add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0, - (-$charge_shipping), $invoice->customer_id, - "The freight GL posting could not be inserted"); + (-$charge_shipping), $cart->customer_id, + "The freight GL posting could not be inserted"); } - - foreach ($taxes as $taxitem) + + foreach ($taxes as $taxitem) { - if ($taxitem['Value'] != 0) + if ($taxitem['Value'] != 0) { add_customer_trans_tax_detail_item(10, $invoice_no, $taxitem['tax_type_id'], - $taxitem['rate'], $taxitem['included_in_price'], $taxitem['Value']); - + $taxitem['rate'], $taxitem['included_in_price'], $taxitem['Value']); + add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0, - (-$taxitem['Value']), $invoice->customer_id, + (-$taxitem['Value']), $cart->customer_id, "A tax GL posting could not be inserted"); - } - } - - add_comments(10, $invoice_no, $date_, $memo_); - + } + } + + add_comments(10, $invoice_no, $date_, $memo_); + add_forms_for_sys_type(10, $invoice_no, $location); - - references::save_last($reference, 10); - - commit_transaction(); - + + references::save_last($reference, 10); + + commit_transaction(); + return $invoice_no; } @@ -147,42 +149,51 @@ function add_sales_invoice(&$invoice, $date_, $due_date, $sales_order, $tax_grou function void_sales_invoice($type, $type_no) { begin_transaction(); - + void_bank_trans($type, $type_no, true); void_gl_trans($type, $type_no, true); - - // for invoices and credits related to invoices, + + // for invoices and credits related to invoices, // reverse all the changes in the sales order $items_result = get_customer_trans_details($type, $type_no); - - $order = get_customer_trans_order($type, $type_no); - - if ($order) + + $delivery = get_customer_trans_link($type, $type_no); + + if ($delivery) { while ($row = db_fetch($items_result)) { - dispatch_sales_order_item($order, $row["id"], $row["quantity"]); + invoice_delivery_item($row['id'], $row['quantity']); } } - + // clear details after they've been reversed in the sales order void_customer_trans_details($type, $type_no); - - void_customer_trans_tax_details($type, $type_no); - + + void_customer_trans_tax_details($type, $type_no); + void_cust_allocations($type, $type_no); - + // do this last because other voidings can depend on it - especially voiding // DO NOT MOVE THIS ABOVE VOIDING or we can end up with trans with alloc < 0 - void_customer_trans($type, $type_no); - - commit_transaction(); + void_customer_trans($type, $type_no); + + commit_transaction(); } //-------------------------------------------------------------------------------------------------- +function invoice_delivery_item($id, $qty_dispatched) +{ + $sql = "UPDATE ".TB_PREF."debtor_trans_details "; + $sql .= "SET qty_done = qty_done - $qty_dispatched "; + $sql .= " WHERE id=$id"; +// AND debtor_trans_type = 13 +// AND debtor_trans_no = $delivery_no +// AND stock_id = '$stock_id'"; - + db_query($sql, "The sales delivery detail record could not be updated"); +} ?> \ No newline at end of file diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index f12da111..bd46233a 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -3,7 +3,7 @@ //---------------------------------------------------------------------------------------- function get_demand_qty($stockid, $location) { - $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_invoiced) AS QtyDemand + $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS QtyDemand FROM ".TB_PREF."sales_order_details, ".TB_PREF."sales_orders WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND @@ -17,7 +17,7 @@ function get_demand_qty($stockid, $location) function get_demand_asm_qty($stockid, $location) { - $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_invoiced)*".TB_PREF."bom.quantity) + $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity) AS Dem FROM ".TB_PREF."sales_order_details, ".TB_PREF."sales_orders, @@ -26,7 +26,7 @@ function get_demand_asm_qty($stockid, $location) WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND ".TB_PREF."sales_orders.from_stk_loc='$location' AND - ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_invoiced > 0 AND + ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND ".TB_PREF."bom.component='$stockid' AND ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND ".TB_PREF."stock_master.mb_flag='A'"; @@ -49,7 +49,7 @@ function add_sales_order($order) begin_transaction(); - if ($order->direct_invoice) + if ($order->trans_type=='invoice') $del_date = date2sql($order->orig_order_date); else $del_date = date2sql($order->delivery_date); @@ -80,41 +80,39 @@ function add_sales_order($order) } foreach ($order->line_items as $line) { - if ($line->Deleted == false) + if ($loc_notification == 1 && is_inventory_item($line->stock_id)) { - if ($loc_notification == 1 && is_inventory_item($line->stock_id)) + $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email + FROM ".TB_PREF."loc_stock, ".TB_PREF."locations + WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code + AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "' + AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'"; + $res = db_query($sql,"a location could not be retreived"); + $loc = db_fetch($res); + if ($loc['email'] != "") { - $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email - FROM ".TB_PREF."loc_stock, ".TB_PREF."locations - WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code - AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "' - AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'"; - $res = db_query($sql,"a location could not be retreived"); - $loc = db_fetch($res); - if ($loc['email'] != "") + $qoh = get_qoh_on_date($line->stock_id, $order->Location); + $qoh -= get_demand_qty($line->stock_id, $order->Location); + $qoh -= get_demand_asm_qty($line->stock_id, $order->Location); + $qoh -= $line->quantity; + if ($qoh < $loc['reorder_level']) { - $qoh = get_qoh_on_date($line->stock_id, $order->Location); - $qoh -= get_demand_qty($line->stock_id, $order->Location); - $qoh -= get_demand_asm_qty($line->stock_id, $order->Location); - $qoh -= $line->quantity; - if ($qoh < $loc['reorder_level']) - { - $st_ids[] = $line->stock_id; - $st_names[] = $line->item_description; - $st_num[] = $qoh - $loc['reorder_level']; - $st_reorder[] = $loc['reorder_level']; - } + $st_ids[] = $line->stock_id; + $st_names[] = $line->item_description; + $st_num[] = $qoh - $loc['reorder_level']; + $st_reorder[] = $loc['reorder_level']; } } - $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent) VALUES ("; - $sql .= $order_no . - ",'$line->stock_id', '$line->item_description', $line->price, - $line->quantity, - $line->discount_percent)"; - db_query($sql, "order Details Cannot be Added"); - - } /* inserted line items into sales order details */ - } + } + $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent) VALUES ("; + $sql .= $order_no . + ",'$line->stock_id', '$line->item_description', $line->price, + $line->quantity, + $line->discount_percent)"; + db_query($sql, "order Details Cannot be Added"); + + } /* inserted line items into sales order details */ + add_forms_for_sys_type(systypes::sales_order(), $order_no); commit_transaction(); @@ -195,41 +193,37 @@ function update_sales_order($order_no, $order) } foreach ($order->line_items as $line) { - if ($line->Deleted == false) + if ($loc_notification == 1 && is_inventory_item($line->stock_id)) { - if ($loc_notification == 1 && is_inventory_item($line->stock_id)) + $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email + FROM ".TB_PREF."loc_stock, ".TB_PREF."locations + WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code + AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "' + AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'"; + $res = db_query($sql,"a location could not be retreived"); + $loc = db_fetch($res); + if ($loc['email'] != "") { - $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email - FROM ".TB_PREF."loc_stock, ".TB_PREF."locations - WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code - AND ".TB_PREF."loc_stock.stock_id = '" . $line->stock_id . "' - AND ".TB_PREF."loc_stock.loc_code = '" . $order->Location . "'"; - $res = db_query($sql,"a location could not be retreived"); - $loc = db_fetch($res); - if ($loc['email'] != "") + $qoh = get_qoh_on_date($line->stock_id, $order->Location); + $qoh -= get_demand_qty($line->stock_id, $order->Location); + $qoh -= get_demand_asm_qty($line->stock_id, $order->Location); + $qoh -= $line->quantity; + if ($qoh < $loc['reorder_level']) { - $qoh = get_qoh_on_date($line->stock_id, $order->Location); - $qoh -= get_demand_qty($line->stock_id, $order->Location); - $qoh -= get_demand_asm_qty($line->stock_id, $order->Location); - $qoh -= $line->quantity; - if ($qoh < $loc['reorder_level']) - { - $st_ids[] = $line->stock_id; - $st_names[] = $line->item_description; - $st_num[] = $qoh - $loc['reorder_level']; - $st_reorder[] = $loc['reorder_level']; - } + $st_ids[] = $line->stock_id; + $st_names[] = $line->item_description; + $st_num[] = $qoh - $loc['reorder_level']; + $st_reorder[] = $loc['reorder_level']; } } + } + $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent, qty_sent) VALUES ("; + $sql .= $order_no . ",'" . $line->stock_id . "','" . $line->item_description . "', " . $line->price . ", " . $line->quantity . ", " . $line->discount_percent . ", " . $line->qty_done ." )"; - $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent, qty_invoiced) VALUES ("; - - $sql .= $order_no . ",'" . $line->stock_id . "','" . $line->item_description . "', " . $line->price . ", " . $line->quantity . ", " . $line->discount_percent . ", " . $line->qty_inv . " )"; + db_query($sql, "Old order Cannot be Inserted"); - db_query($sql, "Old order Cannot be Inserted"); + } /* inserted line items into sales order details */ - } /* inserted line items into sales order details */ - } commit_transaction(); if ($loc_notification == 1 && count($st_ids) > 0) { @@ -265,7 +259,7 @@ function get_sales_order($order_no) AND ".TB_PREF."sales_orders.debtor_no = ".TB_PREF."debtors_master.debtor_no AND ".TB_PREF."locations.loc_code = ".TB_PREF."sales_orders.from_stk_loc AND ".TB_PREF."shippers.shipper_id = ".TB_PREF."sales_orders.ship_via - AND ".TB_PREF."sales_orders.order_no = " . $order_no; + AND ".TB_PREF."sales_orders.order_no = " . $order_no ; $result = db_query($sql, "order Retreival"); @@ -285,10 +279,11 @@ function get_sales_order($order_no) //---------------------------------------------------------------------------------------- -function read_sales_order($order_no, &$order, $skip_completed_items=false) +function read_sales_order($order_no, &$order) { $myrow = get_sales_order($order_no); + $order->trans_no = $order_no; $order->customer_id = $myrow["debtor_no"]; $order->Branch = $myrow["branch_code"]; $order->customer_name = $myrow["name"]; @@ -314,19 +309,16 @@ function read_sales_order($order_no, &$order, $skip_completed_items=false) $order->tax_group_name = $myrow["tax_group_name"]; $order->tax_group_id = $myrow["tax_group_id"]; - $sql = "SELECT stk_code, unit_price, ".TB_PREF."sales_order_details.description, - ".TB_PREF."sales_order_details.quantity, ".TB_PREF."sales_order_details.id, discount_percent, - qty_invoiced, ".TB_PREF."stock_master.units, + $sql = "SELECT id, stk_code, unit_price, ".TB_PREF."sales_order_details.description, + ".TB_PREF."sales_order_details.quantity, discount_percent, + qty_sent, ".TB_PREF."stock_master.units, ".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost AS standard_cost FROM ".TB_PREF."sales_order_details, ".TB_PREF."stock_master WHERE ".TB_PREF."sales_order_details.stk_code = ".TB_PREF."stock_master.stock_id - AND order_no =" . $order_no; - - if ($skip_completed_items) - $sql .= " - AND ".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_invoiced > 0 "; - $sql .= " ORDER BY ".TB_PREF."sales_order_details.id"; + AND order_no =" . $order_no . " ORDER BY id"; +// $sql .= " +// AND ".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent > 0 "; $result = db_query($sql, "Retreive order Line Items"); if (db_num_rows($result) > 0) @@ -334,20 +326,25 @@ function read_sales_order($order_no, &$order, $skip_completed_items=false) while ($myrow = db_fetch($result)) { - $order->add_to_cart($order->lines_on_order+1, $myrow["id"], $myrow["stk_code"],$myrow["quantity"], + $order->add_to_cart($myrow["stk_code"],$myrow["quantity"], $myrow["unit_price"], $myrow["discount_percent"], - $myrow["qty_invoiced"], $myrow["standard_cost"], $myrow["description"]); + $myrow["qty_sent"], $myrow["standard_cost"], $myrow["description"], $myrow["id"] ); } } + foreach($order->line_items as $key=>$line) + $order->line_items[$key]->qty_dispatched = + $order->line_items[$key]->quantity - $order->line_items[$key]->qty_done; + return true; } //---------------------------------------------------------------------------------------- -function sales_order_has_invoices($order_no) +function sales_order_has_deliveries($order_no) { - $sql = "SELECT COUNT(*) FROM ".TB_PREF."debtor_trans WHERE order_=$order_no"; + $sql = "SELECT SUM(qty_sent) FROM ".TB_PREF. + "sales_order_details WHERE order_no=$order_no"; $result = db_query($sql, "could not query for sales order usage"); @@ -360,9 +357,9 @@ function sales_order_has_invoices($order_no) function close_sales_order($order_no) { - // set the quantity of each item to the already invoiced quantity. this will mark item as closed. + // set the quantity of each item to the already sent quantity. this will mark item as closed. $sql = "UPDATE ".TB_PREF."sales_order_details - SET quantity = qty_invoiced + SET quantity = qty_sent WHERE order_no = $order_no"; db_query($sql, "The sales order detail record could not be updated"); @@ -370,12 +367,13 @@ function close_sales_order($order_no) //---------------------------------------------------------------------------------------- -function dispatch_sales_order_item($order_no, $id, $qty_dispatched) +function dispatch_sales_order_item($order_no, $stock_id, $qty_dispatched, $id) { - $sql = "UPDATE ".TB_PREF."sales_order_details - SET qty_invoiced = qty_invoiced + $qty_dispatched "; - $sql .= " WHERE order_no = $order_no - AND id = $id"; + $sql = "UPDATE ".TB_PREF."sales_order_details "; + + $sql .= "SET qty_sent = qty_sent + $qty_dispatched "; + + $sql .= " WHERE id = $id"; db_query($sql, "The sales order detail record could not be updated"); } diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index 1bd5842f..fce9f44e 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -7,6 +7,7 @@ include_once($path_to_root . "/includes/db/inventory_db.inc"); include_once($path_to_root . "/sales/includes/db/sales_order_db.inc"); include_once($path_to_root . "/sales/includes/db/sales_credit_db.inc"); include_once($path_to_root . "/sales/includes/db/sales_invoice_db.inc"); +include_once($path_to_root . "/sales/includes/db/sales_delivery_db.inc"); include_once($path_to_root . "/sales/includes/db/custalloc_db.inc"); include_once($path_to_root . "/sales/includes/db/cust_trans_db.inc"); include_once($path_to_root . "/sales/includes/db/cust_trans_details_db.inc"); diff --git a/sales/includes/ui/print_invoice.inc b/sales/includes/ui/print_invoice.inc new file mode 100644 index 00000000..9ee4d9c2 --- /dev/null +++ b/sales/includes/ui/print_invoice.inc @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index 4a5dee02..c5a8d317 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -5,25 +5,19 @@ include_once($path_to_root . "/includes/manufacturing.inc"); //-------------------------------------------------------------------------------- -function add_to_order(&$order, $line_no, $new_item, $new_item_qty, $price, $discount) +function add_to_order(&$order, $new_item, $new_item_qty, $price, $discount) { -/* - $already_on_order = 0; - foreach ($order->line_items AS $order_item) + foreach ($order->line_items AS $order_item) { - if (strcasecmp($order_item->stock_id, $new_item) == 0) + if (strcasecmp($order_item->stock_id, $new_item) == 0) { - $already_on_order = 1; - display_error(_("For Part :") . $new_item . " " . "This item is already on this order. You can change the quantity ordered of the existing line if necessary."); - } + display_notification(_("For Part :") . $new_item . " " . _("This item is already on this order. You have been warned.")); + break; + } } - - - if ($already_on_order != 1) - { -*/ - $order->add_to_cart ($line_no, 0, $new_item, $new_item_qty, $price, $discount); + + $order->add_to_cart ($new_item, $new_item_qty, $price, $discount); } //--------------------------------------------------------------------------------- @@ -51,7 +45,7 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id) if ($myrow['dissallow_invoices'] == 1) $ret_error = _("The selected customer account is currently on hold. Please contact the credit control personnel to discuss."); - if (!isset($_POST['branch_id']) || $_POST['branch_id'] == "") + if (!isset($_POST['branch_id']) || $_POST['branch_id'] == "") { $ret_error = _("The selected customer does not have any branches. Please create at least one branch."); unset($_POST['branch_id']); @@ -108,50 +102,51 @@ function display_order_summary($title, &$order, $editable_items=false) display_heading($title); start_table("$table_style colspan=7 width=90%"); $th = array(_("Item Code"), _("Item Description"), _("Quantity"), - _("Unit"), _("Price"), _("Discount %"), _("Total"), "", ""); - table_header($th); + _("Unit"), _("Price"), _("Discount %"), _("Total"), ""); + + if(count($order->line_items)) $th[]= ''; + + table_header($th); $total = 0; $k = 0; //row colour counter - foreach ($order->line_items as $line) + foreach ($order->line_items as $line_no=>$stock_item) { - if ($line->Deleted == false) + + $line_total = $stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent); + + if (!isset($_GET['Edit'])) + $id = -1; + else + $id = $_GET['Edit']; + if (!$editable_items || $id != $line_no) + { + alt_table_row_color($k); + + view_stock_status_cell($stock_item->stock_id); + + label_cell($stock_item->item_description); + qty_cell($stock_item->quantity); + label_cell($stock_item->units); + amount_cell($stock_item->price); + + amount_cell($stock_item->discount_percent * 100); + amount_cell($line_total); + + if ($editable_items) + { + edit_link_cell(SID . "Edit=$line_no"); + delete_link_cell(SID . "Delete=$line_no"); + } + end_row(); + } + else { - $line_total = $line->quantity * $line->price * (1 - $line->discount_percent); - - if (!isset($_GET['Edit'])) - $id = ""; - else - $id = $_GET['Edit']; - if (!$editable_items || $id != $line->line_no) - { - alt_table_row_color($k); - - view_stock_status_cell($line->stock_id); - - label_cell($line->item_description); - qty_cell($line->quantity); - label_cell($line->units); - amount_cell($line->price); - - amount_cell($line->discount_percent * 100); - amount_cell($line_total); - - if ($editable_items) - { - edit_link_cell(SID . "Edit=$line->line_no"); - delete_link_cell(SID . "Delete=$line->line_no"); - } - end_row(); - } - else - { - sales_order_item_controls($order, $line->stock_id); - } - - $total += $line_total; + sales_order_item_controls($order, $line_no); } + + $total += $line_total; } if (!isset($_GET['Edit']) && $editable_items) @@ -179,8 +174,8 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group { // can't change the customer/branch if items already received on this order echo $order->customer_name . " - " . $order->deliver_to; - } - else + } + else { if (!isset($_POST['customer_id']) && (get_global_customer() != reserved_words::get_all())) @@ -190,14 +185,14 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group if (!isset($_POST['delivery_date'])) { - if ($order->direct_invoice) - $_POST['delivery_date'] = $_SESSION['Items']->delivery_date = + if ($order->trans_type=='invoice') + $_POST['delivery_date'] = $_SESSION['Items']->delivery_date = get_invoice_duedate($_POST['customer_id'], $_POST['OrderDate']); - else - $_POST['delivery_date'] = $_SESSION['Items']->delivery_date = + else + $_POST['delivery_date'] = $_SESSION['Items']->delivery_date = add_days($_POST['OrderDate'], 10); - } - if ($order->customer_id != $_POST['customer_id']) + } + if ($order->customer_id != $_POST['customer_id']) { // customer has changed @@ -214,7 +209,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group if (!isset($_POST['branch_id'])) $_POST['branch_id'] = ""; //set_global_customer($_POST['customer_id']); - if (($order->customer_id != $_POST['customer_id']) || + if (($order->customer_id != $_POST['customer_id']) || ($order->Branch != $_POST['branch_id'])) $customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']); @@ -228,7 +223,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group { echo ""; label_row(_("Customer Currency:"), $order->customer_currency); - exchange_rate_display($order->customer_currency, get_company_currency(), + exchange_rate_display($order->customer_currency, get_company_currency(), ($editable?$_POST['OrderDate']:$order->orig_order_date), $editable); echo "
"; echo ""; // outer table @@ -243,28 +238,28 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group echo ""; - if ($editable) + if ($editable) { if (!isset($_POST['OrderDate']) || $_POST['OrderDate'] == "") $_POST['OrderDate'] = $order->orig_order_date; date_row($date_text, 'OrderDate'); } - else + else { label_row($date_text, $order->orig_order_date); hidden('OrderDate', $order->orig_order_date); } - if ($display_tax_group) + if ($display_tax_group) { - if ($editable) + if ($editable) { if (!isset($_POST['tax_group_id'])) $_POST['tax_group_id'] = $_SESSION['Items']->tax_group_id; tax_groups_list_row(_("Tax Group:"), 'tax_group_id', $_POST['tax_group_id'], true); - } - else + } + else { label_row(_("Tax Group:"), $order->tax_group_name); hidden('tax_group_id', $_SESSION['Items']->tax_group_id); @@ -273,7 +268,7 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group echo "
"; echo ""; - + end_table(1); // outer table return $customer_error; @@ -281,34 +276,28 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group //-------------------------------------------------------------------------------- -function sales_order_item_controls(&$order, $stock_id=null) +function sales_order_item_controls(&$order, $line_no=-1) { start_row(); - - if (isset($_GET['Edit']) && $stock_id != null) + if (isset($_GET['Edit']) && $line_no != -1) { - $line_no = $_GET['Edit']; - hidden('line_no', $line_no); - if (!isset($_POST['stock_id'])) - $_POST['stock_id'] = $order->line_items[$line_no]->stock_id; + $_POST['stock_id'] = $order->line_items[$_GET['Edit']]->stock_id; if (!isset($_POST['qty']) || ($_POST['qty'] == "")) - $_POST['qty'] = $order->line_items[$line_no]->quantity; + $_POST['qty'] = $order->line_items[$_GET['Edit']]->quantity; if (!isset($_POST['price']) || ($_POST['price'] == "")) - $_POST['price'] = $order->line_items[$line_no]->price; + $_POST['price'] = $order->line_items[$_GET['Edit']]->price; if (!isset($_POST['Disc']) || ($_POST['Disc'] == "")) - $_POST['Disc'] = ($order->line_items[$line_no]->discount_percent)*100; - - $_POST['units'] = $order->line_items[$line_no]->units; + $_POST['Disc'] = ($order->line_items[$_GET['Edit']]->discount_percent)*100; + $_POST['units'] = $order->line_items[$_GET['Edit']]->units; hidden('stock_id', $_POST['stock_id']); label_cell($_POST['stock_id']); label_cell($order->line_items[$line_no]->item_description); - } - else + } + else { - hidden('line_no', ($_SESSION['Items']->lines_on_order + 1)); - $no_item_list = get_company_pref('no_item_list'); + global $no_item_list; if ($no_item_list) { echo "\n"; @@ -317,7 +306,7 @@ function sales_order_item_controls(&$order, $stock_id=null) } else { - text_cells(null, "StockID2", "", 12, 10, "", "", "onkeyup='recalcAccounts();' onKeyDown='if(event.keyCode==13) event.keyCode=9;' onblur='return setAccount(0, true);'"); + text_cells(null, "StockID2", "", 12, 10, "", "", "onkeyup='recalcAccounts();' onKeyDown='if(event.keyCode==13) event.keyCode=9;' onblur='return setAccount(0, true);'"); stock_items_list_cells(null, 'stock_id', null, false, false, "onchange='return setAccount(1, true)'"); } $item_info = get_item_edit_info($_POST['stock_id']); @@ -338,12 +327,13 @@ function sales_order_item_controls(&$order, $stock_id=null) $line_total = $_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc'] / 100); amount_cell($line_total); - if (isset($_GET['Edit'])) + if (isset($_GET['Edit'])) { submit_cells('UpdateItem', _("Update")); submit_cells('CancelItemChanges', _("Cancel")); - } - else + hidden('LineNo', $line_no); + } + else { submit_cells('AddItem', _("Add Item"), "colspan=2"); } @@ -357,12 +347,12 @@ function display_delivery_details(&$order) { global $table_style2; - if ($order->direct_invoice) + if ($order->trans_type=='invoice') { $title = _("Invoice Delivery Details"); $delname = _("Due Date"); - } - else + } + else { $title = _("Order Delivery Details"); $delname = _("Required Delivery Date:"); @@ -394,7 +384,7 @@ function display_delivery_details(&$order) text_row(_("Shipping Charge:"), 'freight_cost', $order->freight_cost, 10, 10); shippers_list_row(_("Shipping Company:"), 'ship_via', $order->ship_via); - if ($_SESSION['Items']->direct_invoice) + if ($_SESSION['Items']->trans_type=='delivery') textarea_row(_("Memo"), 'InvoiceText', null, 31, 3); echo ""; diff --git a/sales/inquiry/customer_allocation_inquiry.php b/sales/inquiry/customer_allocation_inquiry.php index 07aad1e3..f8cc1afc 100644 --- a/sales/inquiry/customer_allocation_inquiry.php +++ b/sales/inquiry/customer_allocation_inquiry.php @@ -90,8 +90,12 @@ function get_transactions() $sql .= " AND ".TB_PREF."debtor_trans.due_date < '$today' AND (round(abs(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount) - ".TB_PREF."debtor_trans.alloc,6) > 0) "; } + }else + { + $sql .= " AND ".TB_PREF."debtor_trans.type != 13 "; } + if (!check_value('showSettled')) { $sql .= " AND (round(abs(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount) - ".TB_PREF."debtor_trans.alloc,6) != 0) "; diff --git a/sales/inquiry/customer_inquiry.php b/sales/inquiry/customer_inquiry.php index ee8d4b3d..1d440c94 100644 --- a/sales/inquiry/customer_inquiry.php +++ b/sales/inquiry/customer_inquiry.php @@ -12,7 +12,7 @@ if ($use_popup_windows) $js .= get_js_open_window(900, 500); if ($use_date_picker) $js .= get_js_date_picker(); -page(_("Customer Inquiry"), false, false, "", $js); +page(_("Customer Transactions"), false, false, "", $js); if (isset($_GET['customer_id'])) @@ -37,7 +37,7 @@ date_cells(_("To:"), 'TransToDate', null, 1); if (!isset($_POST['filterType'])) $_POST['filterType'] = 0; -cust_allocations_list_cells(null, 'filterType', $_POST['filterType']); +cust_allocations_list_cells(null, 'filterType', $_POST['filterType'], true); submit_cells('Refresh Inquiry', _("Search")); @@ -121,6 +121,10 @@ function get_transactions() { $sql .= " AND ".TB_PREF."debtor_trans.type = 11 "; } + elseif ($_POST['filterType'] == '5') + { + $sql .= " AND ".TB_PREF."debtor_trans.type = 13 "; + } if ($_POST['filterType'] == '2') { @@ -130,7 +134,8 @@ function get_transactions() } } - $sql .= " ORDER BY ".TB_PREF."debtor_trans.tran_date"; + $sql .= " ORDER BY ".TB_PREF."debtor_trans.tran_date DESC, + debtor_trans.type,debtor_trans.trans_no "; return db_query($sql,"No transactions were returned"); } @@ -161,10 +166,10 @@ start_table("$table_style width='80%'"); if ($_POST['customer_id'] == reserved_words::get_all()) $th = array(_("Type"), _("#"), _("Order"), _("Reference"), _("Date"), _("Due Date"), - _("Customer"), _("Branch"), _("Currency"), _("Debit"), _("Credit"), "", ""); + _("Customer"), _("Branch"), _("Currency"), _("Debit"), _("Credit"), "", "",""); else $th = array(_("Type"), _("#"), _("Order"), _("Reference"), _("Date"), _("Due Date"), - _("Branch"), _("Debit"), _("Credit"), "", ""); + _("Branch"), _("Debit"), _("Credit"), "", "",""); table_header($th); @@ -182,6 +187,25 @@ while ($myrow = db_fetch($result)) else alt_table_row_color($k); + $edit_page=''; + $due_date_str = ''; + $credit_me_str = ''; + + switch($myrow['type']) { + case 10: + $due_date_str = sql2date($myrow["due_date"]); + /*Show a link to allow an invoice to be credited */ + // only allow crediting if it's not been totally allocated + if ($myrow["TotalAmount"] - $myrow["Allocated"] > 0) + $credit_me_str = "" . _("Credit This") . ""; + $edit_page= $path_to_root.'/sales/customer_invoice.php?ModifyInvoice=' + . $myrow['trans_no']; + break; + case 13: + $edit_page= $path_to_root.'/sales/customer_delivery.php?ModifyDelivery=' + . $myrow['trans_no']; break; + } + $date = sql2date($myrow["tran_date"]); if ($myrow["order_"] > 0) @@ -191,22 +215,8 @@ while ($myrow = db_fetch($result)) $gl_trans_str = get_gl_view_str_cell($myrow["type"], $myrow["trans_no"]); - $credit_me_str = ""; - - $credit_invoice_str = "" . _("Credit This") . ""; +// $print_str = "" . _("Print") . ""; - $due_date_str = ""; - - if ($myrow["type"] == 10) - $due_date_str = sql2date($myrow["due_date"]); - - if ($myrow["type"] == 10) - { - /*Show a link to allow an invoice to be credited */ - // only allow crediting if it's not been totally allocated - if ($myrow["TotalAmount"] - $myrow["Allocated"] > 0) - $credit_me_str = $credit_invoice_str; - } $branch_name = ""; if ($myrow["branch_code"] > 0) @@ -230,21 +240,28 @@ while ($myrow = db_fetch($result)) label_cell($myrow["CustCurrCode"]); display_debit_or_credit_cells($myrow["TotalAmount"]); echo $gl_trans_str; + + label_cell($edit_page=='' ? '' : "" . _('Edit') . ''); + if ($credit_me_str != "") label_cell($credit_me_str, "nowrap"); - - + else + label_cell(''); + +// if ($myrow["type"] == 10) +// label_cell($print_str, 'nowrap'); +// else +// label_cell(''); + end_row(); $j++; - If ($j == 12) + if ($j == 12) { $j = 1; table_header($th); - } -//end of page full new headings if -} -//end of while loop + } //end of page full new headings if +} //end of transaction while loop end_table(1); diff --git a/sales/inquiry/sales_deliveries_view.php b/sales/inquiry/sales_deliveries_view.php new file mode 100644 index 00000000..3063b84c --- /dev/null +++ b/sales/inquiry/sales_deliveries_view.php @@ -0,0 +1,260 @@ += '$date_after'"; + $sql .= " AND ".TB_PREF."debtor_trans.tran_date <= '$date_before'"; + + if ($selected_customer != -1) + $sql .= " AND ".TB_PREF."debtor_trans.debtor_no='" . $selected_customer . "' "; + + if (isset($selected_stock_item)) + $sql .= " AND ".TB_PREF."debtor_trans_details.stock_id='". $selected_stock_item ."' "; + +// if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != reserved_words::get_all()) +// $sql .= " AND ".TB_PREF."sales_orders.from_stk_loc = '". $_POST['StockLocation'] . "' "; + + if ($_POST['OutstandingOnly'] == true) { + $sql .= " AND ".TB_PREF."-debtor_trans_details.qty_done < ".TB_PREF."-debtor_trans_details.quantity "; + } + + $sql .= " GROUP BY ".TB_PREF."debtor_trans.trans_no "; +// .TB_PREF."debtor_trans.debtor_no, " +// .TB_PREF."debtor_trans.branch_code, " +// ".TB_PREF."sales_orders.customer_ref, " +// .TB_PREF."debtor_trans.tran_date"; + +} //end no delivery number selected + +$result = db_query($sql,"No deliveries were returned"); + +//----------------------------------------------------------------------------------- +if(isset($_SESSION['Batch'])) { + foreach($_SESSION['Batch'] as $trans=>$del) unset($_SESSION['Batch'][$trans]); + unset($_SESSION['Batch']); +} +if ($result) +{ + + /*show a table of the deliveries returned by the sql */ + + start_table("$table_style colspan=7 width=95%"); + $th = array(_("Delivery #"), _("Customer"), _("Branch"), _("Reference"), _("Delivery Date"), + _("Due By"), _("Delivery Total"), _("Currency"), + submit('BatchInvoice','Batch Inv', false), + "", ""); + table_header($th); + + $j = 1; + $k = 0; //row colour counter + $overdue_items = false; + while ($myrow = db_fetch($result)) + { + $_SESSION['Batch'][] = array('trans'=>$myrow["trans_no"], + 'cust'=>$myrow["name"],'branch'=>$myrow["br_name"] ); + + $view_page = get_customer_trans_view_str(13, $myrow["trans_no"]); + $formated_del_date = sql2date($myrow["tran_date"]); + $formated_due_date = sql2date($myrow["due_date"]); + $not_closed = $myrow["Outstanding"]!=0; + + // if overdue orders, then highlight as so + + if (date1_greater_date2(Today(), $formated_due_date) && $not_closed ) + { + start_row("class='overduebg'"); + $overdue_items = true; + } + else + { + alt_table_row_color($k); + } + + label_cell($view_page); + label_cell($myrow["name"]); + label_cell($myrow["br_name"]); + label_cell($myrow["reference"]); + label_cell($formated_del_date); + label_cell($formated_due_date); + amount_cell($myrow["DeliveryValue"]); + label_cell($myrow["curr_code"]); + if(!$myrow['Partial']) + check_cells(null,'Sel_'. $myrow['trans_no'],0,false); + else + label_cell(""); + if ($_POST['OutstandingOnly'] == true || $not_closed) + { + $modify_page = $path_to_root . "/sales/customer_delivery.php?" . SID . "ModifyDelivery=" . $myrow["trans_no"]; + $invoice_page = $path_to_root . "/sales/customer_invoice.php?" . SID . "DeliveryNumber=" .$myrow["trans_no"]; + label_cell("" . _("Edit") . ""); + + label_cell($not_closed ? "" . _("Invoice") . "" : ''); + + } + else + { + label_cell(""); + label_cell(""); + } + end_row();; + + $j++; + If ($j == 12) + { + $j = 1; + table_header($th); + } + //end of page full new headings if + } + //end of while loop + + end_table(); + + if ($overdue_items) + display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'"); +} + +echo "
"; +end_form(); + +end_page(); +?> + diff --git a/sales/inquiry/sales_orders_view.php b/sales/inquiry/sales_orders_view.php index d6409e56..e34e3ab9 100644 --- a/sales/inquiry/sales_orders_view.php +++ b/sales/inquiry/sales_orders_view.php @@ -73,7 +73,7 @@ else $sql = "SELECT ".TB_PREF."sales_orders.order_no, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."debtors_master.name, ".TB_PREF."cust_branch.br_name, ".TB_PREF."sales_orders.customer_ref, ".TB_PREF."sales_orders.ord_date, ".TB_PREF."sales_orders.deliver_to, ".TB_PREF."sales_orders.delivery_date, "; -$sql .= " Sum(".TB_PREF."sales_order_details.qty_invoiced) AS TotInvoiced, "; +$sql .= " Sum(".TB_PREF."sales_order_details.qty_sent) AS TotDelivered, "; $sql .= " Sum(".TB_PREF."sales_order_details.quantity) AS TotQuantity, "; $sql .= " Sum(".TB_PREF."sales_order_details.unit_price*".TB_PREF."sales_order_details.quantity*(1-".TB_PREF."sales_order_details.discount_percent)) AS OrderValue @@ -107,7 +107,7 @@ else $sql .= " AND ".TB_PREF."sales_orders.from_stk_loc = '". $_POST['StockLocation'] . "' "; if ($_POST['OutstandingOnly'] == true) - $sql .= " AND ".TB_PREF."sales_order_details.qty_invoiced < ".TB_PREF."sales_order_details.quantity"; + $sql .= " AND ".TB_PREF."sales_order_details.qty_sent < ".TB_PREF."sales_order_details.quantity"; $sql .= " GROUP BY ".TB_PREF."sales_orders.order_no, ".TB_PREF."sales_orders.debtor_no, ".TB_PREF."sales_orders.branch_code, ".TB_PREF."sales_orders.customer_ref, ".TB_PREF."sales_orders.ord_date, ".TB_PREF."sales_orders.deliver_to"; @@ -137,9 +137,10 @@ if ($result) $view_page = get_customer_trans_view_str(systypes::sales_order(), $myrow["order_no"]); $formated_del_date = sql2date($myrow["delivery_date"]); $formated_order_date = sql2date($myrow["ord_date"]); + $not_closed = $myrow["TotDelivered"] < $myrow["TotQuantity"]; // if overdue orders, then highlight as so - if (date1_greater_date2(Today(), $formated_del_date)) + if (date1_greater_date2(Today(), $formated_del_date) & $not_closed) { start_row("class='overduebg'"); $overdue_items = true; @@ -159,13 +160,13 @@ if ($result) amount_cell($myrow["OrderValue"]); label_cell($myrow["curr_code"]); - if ($_POST['OutstandingOnly'] == true || $myrow["TotInvoiced"] < $myrow["TotQuantity"]) + if ($_POST['OutstandingOnly'] == true || $not_closed) { $modify_page = $path_to_root . "/sales/sales_order_entry.php?" . SID . "ModifyOrderNumber=" . $myrow["order_no"]; - $issue_invoice = $path_to_root . "/sales/customer_invoice.php?" . SID . "OrderNumber=" .$myrow["order_no"]; + $delivery_note = $path_to_root . "/sales/customer_delivery.php?" . SID . "OrderNumber=" .$myrow["order_no"]; label_cell("" . _("Edit") . ""); - label_cell("" . _("Invoice") . ""); + label_cell("" . _("Dispatch") . ""); } else { diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index c90eaa92..d9e48f15 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -3,11 +3,8 @@ $page_security = 1; $path_to_root=".."; include_once($path_to_root . "/sales/includes/cart_class.inc"); - include_once($path_to_root . "/includes/session.inc"); - include_once($path_to_root . "/includes/data_checks.inc"); - include_once($path_to_root . "/sales/includes/sales_ui.inc"); include_once($path_to_root . "/sales/includes/ui/sales_order_ui.inc"); include_once($path_to_root . "/sales/includes/sales_db.inc"); @@ -18,22 +15,23 @@ if ($use_popup_windows) if ($use_date_picker) $js .= get_js_date_picker(); -if (isset($_GET['ModifyOrderNumber'])) -{ - page(_("Modifying Sales Order") . " #".$_GET['ModifyOrderNumber'], false, false, "", $js); +if(isset($_GET['NewDelivery'])) { + $_SESSION['page_title'] = _("Sales Delivery"); + create_cart('delivery',0); } -elseif (isset($_GET['NewInvoice']) || (isset($_SESSION['Items']) && $_SESSION['Items']->direct_invoice)) -{ - page(_("Sales Invoices"), false, false, "", $js); +elseif(isset($_GET['NewOrder'])) { + $_SESSION['page_title'] = _("Sales Order Entry"); + create_cart('order',0); } -else -{ - page(_("Sales Order Entry"), false, false, "", $js); +elseif(isset($_GET['ModifyOrderNumber'])) { + $_SESSION['page_title'] = _("Modifying Sales Order") . " #".$_GET['ModifyOrderNumber']; + create_cart('order', $_GET['ModifyOrderNumber']); } +page($_SESSION['page_title'], false, false, "", $js); //-------------------------------------------------------------------------------- -if (isset($_GET['AddedID'])) +if (isset($_GET['AddedID'])) { $order_no = $_GET['AddedID']; $trans_type = systypes::sales_order(); @@ -42,7 +40,7 @@ if (isset($_GET['AddedID'])) display_note(get_trans_view_str($trans_type, $order_no, _("View this order"))); - hyperlink_params($path_to_root . "/sales/customer_invoice.php", _("Confirm Order Delivery Quantities and Produce Invoice"), "OrderNumber=$order_no"); + hyperlink_params($path_to_root . "/sales/customer_delivery.php", _("Make Delivery Against This Order"), "OrderNumber=$order_no"); hyperlink_params($_SERVER['PHP_SELF'], _("Enter a New Order"), "NewOrder=Yes"); @@ -50,16 +48,16 @@ if (isset($_GET['AddedID'])) } //-------------------------------------------------------------------------------- -if (isset($_GET['UpdatedID'])) +if (isset($_GET['UpdatedID'])) { $order_no = $_GET['UpdatedID']; $trans_type = systypes::sales_order(); - display_notification_centered(_("Order has been updated.") . " #$order_no"); + display_notification_centered(_('Order # ').$order_no. _( ' has been updated.')); display_note(get_trans_view_str($trans_type, $order_no, _("View this order"))); - hyperlink_params($path_to_root . "/sales/customer_invoice.php", _("Confirm Order Delivery Quantities and Produce Invoice"), "OrderNumber=$order_no"); + hyperlink_params($path_to_root . "/sales/customer_delivery.php", _("Confirm Order Quantities and Make Delivery"), "OrderNumber=$order_no"); hyperlink_params($path_to_root . "/sales/inquiry/sales_orders_view.php", _("Select A Different Order"), "OutstandingOnly=1"); @@ -68,9 +66,9 @@ if (isset($_GET['UpdatedID'])) //-------------------------------------------------------------------------------------------------- -function copy_to_so() +function copy_to_cart() { - if ($_SESSION['Items']->direct_invoice) + if ($_SESSION['Items']->trans_type=='delivery') $_SESSION['Items']->memo_ = $_POST['InvoiceText']; $_SESSION['Items']->orig_order_date = $_POST['OrderDate']; @@ -80,17 +78,25 @@ function copy_to_so() $_SESSION['Items']->Comments = $_POST['Comments']; $_SESSION['Items']->deliver_to = $_POST['deliver_to']; - $_SESSION['Items']->delivery_address = $_POST["delivery_address"]; - $_SESSION['Items']->phone = $_POST["phone"]; - $_SESSION['Items']->Location = $_POST["Location"]; - $_SESSION['Items']->ship_via = $_POST["ship_via"]; + $_SESSION['Items']->delivery_address = $_POST['delivery_address']; + $_SESSION['Items']->phone = $_POST['phone']; + $_SESSION['Items']->Location = $_POST['Location']; + $_SESSION['Items']->ship_via = $_POST['ship_via']; + + if (isset($_POST['email'])) + $_SESSION['Items']->email =$_POST['email']; + else + $_SESSION['Items']->email = ''; + + $_SESSION['Items']->customer_id = $_POST['customer_id']; + $_SESSION['Items']->Branch = $_POST['branch_id']; } //-------------------------------------------------------------------------------------------------- -function copy_from_so() +function copy_from_cart() { - if ($_SESSION['Items']->direct_invoice) + if ($_SESSION['Items']->trans_type=='delivery') $_POST['InvoiceText'] = $_SESSION['Items']->memo_; $_POST['OrderDate'] = $_SESSION['Items']->orig_order_date; @@ -100,29 +106,33 @@ function copy_from_so() $_POST['Comments'] = $_SESSION['Items']->Comments; $_POST['deliver_to'] = $_SESSION['Items']->deliver_to; - $_POST["delivery_address"] = $_SESSION['Items']->delivery_address; - $_POST["phone"] = $_SESSION['Items']->phone; - $_POST["Location"] = $_SESSION['Items']->Location; - $_POST["ship_via"] = $_SESSION['Items']->ship_via; + $_POST['delivery_address'] = $_SESSION['Items']->delivery_address; + $_POST['phone'] = $_SESSION['Items']->phone; + $_POST['Location'] = $_SESSION['Items']->Location; + $_POST['ship_via'] = $_SESSION['Items']->ship_via; + + $_POST['customer_id'] = $_SESSION['Items']->customer_id; + $_POST['branch_id'] = $_SESSION['Items']->Branch; + } function can_process() { - if ($_SESSION['Items']->direct_invoice) - { - $edate = _("The entered invoice date is invalid."); - } - else + if ($_SESSION['Items']->trans_type=='delivery') { + $edate = _("The entered delivery date is invalid."); + } + else + { $edate = _("The entered order date is invalid."); - } - if (!is_date($_POST['OrderDate'])) + } + if (!is_date($_POST['OrderDate'])) { display_error($edate); return false; } - if ($_SESSION['Items']->direct_invoice && !is_date_in_fiscalyear($_POST['OrderDate'])) + if (($_SESSION['Items']->trans_type=='delivery') && !is_date_in_fiscalyear($_POST['OrderDate'])) { display_error(_("The entered date is not in fiscal year")); return false; @@ -157,130 +167,111 @@ function can_process() return false; } - if (!is_date($_POST['delivery_date'])) + if (!is_date($_POST['delivery_date'])) { display_error(_("The delivery date is invalid.")); return false; } - if (date1_greater_date2($_SESSION['Items']->orig_order_date, $_POST['delivery_date'])) + if (date1_greater_date2($_SESSION['Items']->orig_order_date, $_POST['delivery_date'])) { display_error(_("The requested delivery date is before the date of the order.")); return false; } - $_SESSION['Items']->deliver_to = $_POST['deliver_to']; - $_SESSION['Items']->delivery_date = $_POST['delivery_date']; - $_SESSION['Items']->delivery_address = $_POST['delivery_address']; - $_SESSION['Items']->phone =$_POST['phone']; - if (isset($_POST['email'])) - $_SESSION['Items']->email =$_POST['email']; - else - $_SESSION['Items']->email = ""; - $_SESSION['Items']->Location = $_POST['Location']; - $_SESSION['Items']->cust_ref = $_POST['cust_ref']; - $_SESSION['Items']->Comments = $_POST['Comments']; - $_SESSION['Items']->freight_cost = $_POST['freight_cost']; - $_SESSION['Items']->ship_via = $_POST['ship_via']; - - return true; + return true; } //----------------------------------------------------------------------------------------------------------- -if (isset($_POST['ProcessOrder']) && $_SESSION['Items']->order_no == 0 && can_process()) +if (isset($_POST['ProcessOrder']) && can_process()) { - + copy_to_cart(); + + if($_SESSION['Items']->order_no == 0) { $order_no = add_sales_order($_SESSION['Items']); - - if ($_SESSION['Items']->direct_invoice) + if ($_SESSION['Items']->trans_type=='delivery') { - $_SESSION['Items']->clear_items(); $_SESSION['Items']->memo_ = $_POST['InvoiceText']; $_SESSION['Items']->memo_ = str_replace("'", "\\'", $_SESSION['Items']->memo_); $_SESSION['Items']->order_no = $order_no; - meta_forward("$path_to_root/sales/customer_invoice.php", "process_invoice=Yes"); - } - else + meta_forward("$path_to_root/sales/customer_delivery.php", "process_delivery=Yes"); + } + else { - - unset($_SESSION['Items']->line_items); - unset($_SESSION['Items']); - - meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no"); - } -} - -//------------------------------------------------------------------------------------------------------------- - -if (isset($_POST['ProcessOrder']) && $_SESSION['Items']->order_no != 0 && can_process()) -{ - + meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no"); + } + } else { // store modified sales order update_sales_order($_SESSION['Items']->order_no, $_SESSION['Items']); - $order_no = $_SESSION['Items']->order_no; - - unset($_SESSION['Items']->line_items); - unset($_SESSION['Items']); - meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$order_no"); + } } - //-------------------------------------------------------------------------------- -function check_item_data() +function check_item_data() { - if (!is_numeric($_POST['qty']) || $_POST['qty'] < 0 || $_POST['Disc'] > 100 || + if (!is_numeric($_POST['qty']) || $_POST['qty'] < 0 || $_POST['Disc'] > 100 || $_POST['Disc'] < 0) { display_error( _("The item could not be updated because you are attempting to set the quantity ordered to less than 0, or the discount percent to more than 100.")); return false; - } - elseif($_SESSION['Items']->some_already_delivered($_POST['line_no']) != 0 && - $_SESSION['Items']->line_items[$_POST['line_no']]->price != $_POST['price']) + } + else + if (!is_numeric($_POST['price']) || $_POST['price']<0) { - display_error(_("The item you attempting to modify the price for has already had some quantity invoiced at the old price. The item unit price cannot be modified retrospectively.")); - return false; - } - elseif($_SESSION['Items']->some_already_delivered($_POST['line_no']) != 0 && - $_SESSION['Items']->line_items[$_POST['line_no']]->discount_percent != ($_POST['Disc']/100)) - { - display_error(_("The item you attempting to modify has had some quantity invoiced at the old discount percent. The items discount cannot be modified retrospectively.")); - return false; - } - elseif (isset($_SESSION['Items']->line_items[$_POST['line_no']]) && $_SESSION['Items']->line_items[$_POST['line_no']]->qty_inv > $_POST['qty']) + display_error( _("Price for item must be entered and can not be less then 0")); + return false; + } + else +// should this be checked for delivery ? +// if($_SESSION['Items']->some_already_delivered($_POST['stock_id']) != 0 && +// $_SESSION['Items']->line_items[$_POST['stock_id']]->price != $_POST['price']) +// { +// display_error(_("The item you attempting to modify the price for has already had some quantity invoiced at the old price. The item unit price cannot be modified retrospectively.")); +// return false; +// } +// else +// if($_SESSION['Items']->some_already_delivered($_POST['stock_id']) != 0 && +// $_SESSION['Items']->line_items[$_POST['stock_id']]->discount_percent != ($_POST['Disc']/100)) +// { +// display_error(_("The item you attempting to modify has had some quantity invoiced at the old discount percent. The items discount cannot be modified retrospectively.")); +// return false; +// } +// else + if (isset($_POST['LineNo']) && isset($_SESSION['Items']->line_items[$_POST['LineNo']]) && $_SESSION['Items']->line_items[$_POST['LineNo']]->qty_done > $_POST['qty']) { - display_error(_("You attempting to make the quantity ordered a quantity less than has already been invoiced. The quantity delivered and invoiced cannot be modified retrospectively.")); + display_error(_("You attempting to make the quantity ordered a quantity less than has already been delivered. The quantity delivered cannot be modified retrospectively.")); return false; - } + } return true; } -function handle_update_item() +function handle_update_item() { - if($_POST['UpdateItem'] != "" && check_item_data()) + if($_POST['UpdateItem'] != '' && check_item_data()) { - $_SESSION['Items']->update_cart_item($_POST['line_no'], $_POST['qty'], + $_SESSION['Items']->update_cart_item($_POST['LineNo'], $_POST['qty'], $_POST['price'], ($_POST['Disc'] / 100)); } } //-------------------------------------------------------------------------------- -function handle_delete_item() -{ +function handle_delete_item() +{ if($_GET['Delete'] != "") { - $line_no = $_GET['Delete']; + $line_no = $_GET['Delete']; if($_SESSION['Items']->some_already_delivered($line_no) == 0) { $_SESSION['Items']->remove_from_cart($line_no); - } - else + } + else { - display_error(_("This item cannot be deleted because some of it has already been invoiced.")); + display_error(_("This item cannot be deleted because some of it has already been delivered.")); } } } @@ -291,59 +282,55 @@ function handle_new_item() { if (!check_item_data()) return; - - add_to_order($_SESSION['Items'], $_POST['line_no'], $_POST['stock_id'], $_POST['qty'], + add_to_order($_SESSION['Items'], $_POST['stock_id'], $_POST['qty'], $_POST['price'], $_POST['Disc']/100); + $_POST['StockID2'] = $_POST['stock_id'] = ""; } -//-------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------- function handle_cancel_order() { global $path_to_root; - - if ($_POST['CancelOrder'] != "") + + if ($_POST['CancelOrder'] != "") { $ok_to_delete = 1; //assume this in the first instance - - if (($_SESSION['Items']->order_no != 0) && - sales_order_has_invoices($_SESSION['Items']->order_no)) + + if (($_SESSION['Items']->order_no != 0) && sales_order_has_deliveries($_SESSION['Items']->order_no)) { $ok_to_delete = 0; - display_error(_("This order cannot be cancelled because some of it has already been invoiced. However, the line item quantities may be modified.")); + display_error(_("This order cannot be cancelled because some of it has already been invoiced or dispatched. However, the line item quantities may be modified.")); } - + if ($ok_to_delete == 1) { if($_SESSION['Items']->order_no != 0) { delete_sales_order($_SESSION['Items']->order_no); } - $diriv = $_SESSION['Items']->direct_invoice; - $_SESSION['Items']->clear_items(); - $_SESSION['Items'] = new cart; - $_SESSION['Items']->direct_invoice = $diriv; - if ($diriv) + + if ($_SESSION['Items']->trans_type=='delivery') { - display_note(_("This sales invoice has been cancelled as requested."), 1); - hyperlink_params($path_to_root . "/sales/sales_order_entry.php", _("Enter a New Sales Invoice"), SID . "&NewInvoice=Yes"); - } - else + display_note(_("This sales delivery has been cancelled as requested."), 1); + hyperlink_params($path_to_root . "/sales/sales_order_entry.php", _("Enter a New Sales Delivery"), SID . "&NewDelivery=Yes"); + } + else { - display_note(_("This sales order has been cancelled as requested."), 1); - hyperlink_params($path_to_root . "/sales/sales_order_entry.php", _("Enter a New Sales Order"), SID . "&NewOrder=Yes"); + display_note(_("This sales order has been cancelled as requested."), 1); + hyperlink_params($path_to_root . "/sales/sales_order_entry.php", _("Enter a New Sales Order"), SID . "&NewOrder=Yes"); } br(1); - end_page(); + end_page(); exit; } } } - + //-------------------------------------------------------------------------------- -function handle_new_order() +function create_cart($type, $trans_num) { /*New order entry - clear any existing order details from the Items object and initiate a newy*/ if (isset($_SESSION['Items'])) @@ -351,38 +338,22 @@ function handle_new_order() unset ($_SESSION['Items']->line_items); unset ($_SESSION['Items']); } - - session_register("Items"); - - $_SESSION['Items'] = new cart; - if (isset($_GET['NewInvoice'])) - $_SESSION['Items']->direct_invoice = true; - $_SESSION['Items']->customer_id = ""; - $_POST['OrderDate'] = Today(); - if (!is_date_in_fiscalyear($_POST['OrderDate'])) + + $_SESSION['Items'] = new cart($type); + + if( $trans_num==0 ) { // new transaction + $_SESSION['Items']->customer_id = ""; + $_POST['OrderDate'] = Today(); + $_SESSION['Items']->order_no = 0; + if (!is_date_in_fiscalyear($_POST['OrderDate'])) $_POST['OrderDate'] = end_fiscalyear(); - $_SESSION['Items']->orig_order_date = $_POST['OrderDate']; -} - -//-------------------------------------------------------------------------------- - -if (isset($_GET['ModifyOrderNumber']) && $_GET['ModifyOrderNumber'] != "") -{ - - if (isset($_SESSION['Items'])) - { - unset ($_SESSION['Items']->line_items); - unset ($_SESSION['Items']); - } - - session_register("Items"); - - $_SESSION['Items'] = new cart; - $_SESSION['Items']->order_no = $_GET['ModifyOrderNumber']; - - /*read in all the selected order into the Items cart */ - - read_sales_order($_SESSION['Items']->order_no, $_SESSION['Items']); + $_SESSION['Items']->orig_order_date = $_POST['OrderDate']; + } else { // read sales order to modify + $_SESSION['Items']->order_no = $trans_num; + /*read in all the selected order into the Items cart */ + read_sales_order($_SESSION['Items']->order_no, $_SESSION['Items']); + copy_from_cart(); // load POST variables + } } //-------------------------------------------------------------------------------- @@ -391,49 +362,30 @@ if (isset($_POST['CancelOrder'])) handle_cancel_order(); if (isset($_GET['Delete']) || isset($_GET['Edit'])) - copy_from_so(); - + copy_from_cart(); + if (isset($_GET['Delete'])) handle_delete_item(); -if (isset($_POST['UpdateItem']) || isset($_POST['AddItem'])) - copy_to_so(); - if (isset($_POST['UpdateItem'])) handle_update_item(); if (isset($_POST['AddItem'])) handle_new_item(); - -//-------------------------------------------------------------------------------- - -if (isset($_GET['NewOrder']) || isset($_GET['NewInvoice'])) -{ - handle_new_order(); -} -else -{ - if (!isset($_POST['customer_id'])) - $_POST['customer_id'] = $_SESSION['Items']->customer_id; - if (!isset($_POST['branch_id'])) - $_POST['branch_id'] = $_SESSION['Items']->Branch; - if (!isset($_POST['OrderDate'])) - $_POST['OrderDate'] = $_SESSION['Items']->orig_order_date; -} - -//-------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------- check_db_has_stock_items(_("There are no inventory items defined in the system.")); -check_db_has_customer_branches(_("There are no customers, or there are no customers with branches. Please define customers and customer branches.")); +check_db_has_customer_branches(_("There are no customers, or there are no customers with branches. Please define customers and customer branches.")); -if ($_SESSION['Items']->direct_invoice) +if ($_SESSION['Items']->trans_type=='delivery') { - $idate = _("Invoice Date:"); - $orderitems = _("Sales Invoice Items"); - $deliverydetails = _("Enter Delivery Details and Confirm Invoice"); - $cancelorder = _("Cancel Invoice"); -} + $idate = _("Delivery Date:"); + $orderitems = _("Delivery Note Items"); + $deliverydetails = _("Enter Delivery Details and Confirm Dispatch"); + $cancelorder = _("Cancel Delivery"); +} else { $idate = _("Order Date:"); @@ -443,32 +395,32 @@ else } start_form(false, true); -$customer_error = display_order_header($_SESSION['Items'], +$customer_error = display_order_header($_SESSION['Items'], ($_SESSION['Items']->any_already_delivered() == 0), $idate); if ($customer_error == "") { start_table("$table_style width=80%", 10); - echo ""; + echo ""; display_order_summary($orderitems, $_SESSION['Items'], true); echo ""; - echo ""; + echo ""; display_delivery_details($_SESSION['Items']); echo ""; - end_table(1); -} + end_table(1); +} else { display_error($customer_error); } -if ($_SESSION['Items']->direct_invoice) +if ($_SESSION['Items']->trans_type=='delivery') { - $porder = _("Place Invoice"); - $corder = _("Commit Invoice Changes"); - $eorder = _("Edit Invoice Items"); -} -else + $porder = _("Place Delivery"); + $corder = _("Commit Delivery Changes"); + $eorder = _("Edit Delivery Items"); +} +else { $porder = _("Place Order"); $corder = _("Commit Order Changes"); @@ -478,42 +430,16 @@ else if ($_SESSION['Items']->order_no == 0) { submit_center_first('ProcessOrder', $porder); -} -else +} +else { submit_center_first('ProcessOrder', $corder); } -/* -echo " "; -submit('EditOrder', $eorder); -if ($_SESSION['Items']->count_items() >= 1) -{ - echo " "; - submit('DeliveryDetails', $deliverydetails); - echo " "; -} -*/ -submit_center_last('CancelOrder', $cancelorder); - + submit_center_last('CancelOrder', $cancelorder); + end_form(); //-------------------------------------------------------------------------------- - -if (!isset($_SESSION['Items'])) -{ - /* It must be a new order being created $_SESSION['Items'] would be set up from the order - modification code above if a modification to an existing order. */ - - session_register("Items"); - - $_SESSION['Items'] = new cart; - if (isset($_GET['NewInvoice'])) - $_SESSION['Items']->direct_invoice = true; - $_SESSION['Items']->order_no = 0; -} - -//-------------------------------------------------------------------------------- - end_page(); ?> \ No newline at end of file diff --git a/sales/view/view_dispatch.php b/sales/view/view_dispatch.php new file mode 100644 index 00000000..0d56ffc7 --- /dev/null +++ b/sales/view/view_dispatch.php @@ -0,0 +1,161 @@ +"; +start_table("$table_style2 width=95%"); +echo ""; // outer table + +/*Now the customer charged to details in a sub table*/ +start_table("$table_style width=100%"); +$th = array(_("Charge To")); +table_header($th); + +label_row(null, $myrow["DebtorName"] . "
" . nl2br($myrow["address"]), "nowrap"); + +end_table(); + +/*end of the small table showing charge to account details */ + +echo ""; // outer table + +/*end of the main table showing the company name and charge to details */ + +start_table("$table_style width=100%"); +$th = array(_("Charge Branch")); +table_header($th); + +label_row(null, $branch["br_name"] . "
" . nl2br($branch["br_address"]), "nowrap"); +end_table(); + +echo ""; // outer table + +start_table("$table_style width=100%"); +$th = array(_("Delivered To")); +table_header($th); + +label_row(null, $sales_order["deliver_to"] . "
" . nl2br($sales_order["delivery_address"]), + "nowrap"); +end_table(); + +echo ""; // outer table + +start_table("$table_style width=100%"); +start_row(); +label_cells(_("Reference"), $myrow["reference"], "class='tableheader2'"); +label_cells(_("Currency"), $sales_order["curr_code"], "class='tableheader2'"); +label_cells(_("Our Order No"), + get_customer_trans_view_str(systypes::sales_order(),$sales_order["order_no"]), "class='tableheader2'"); +end_row(); +start_row(); +label_cells(_("Customer Order Ref."), $sales_order["customer_ref"], "class='tableheader2'"); +label_cells(_("Shipping Company"), $myrow["shipper_name"], "class='tableheader2'"); +label_cells(_("Sales Type"), $myrow["sales_type"], "class='tableheader2'"); +end_row(); +start_row(); +label_cells(_("Dispatch Date"), sql2date($myrow["tran_date"]), "class='tableheader2'", "nowrap"); +label_cells(_("Due Date"), sql2date($myrow["due_date"]), "class='tableheader2'", "nowrap"); +end_row(); +comments_display_row(13, $trans_id); +end_table(); + +echo ""; +end_table(1); // outer table + + +$result = get_customer_trans_details(13, $trans_id); + +start_table("$table_style width=95%"); + +if (db_num_rows($result) > 0) +{ + $th = array(_("Item Code"), _("Item Description"), _("Quantity"), + _("Unit"), _("Price"), _("Discount %"), _("Total")); + table_header($th); + + $k = 0; //row colour counter + $sub_total = 0; + while ($myrow2 = db_fetch($result)) + { + if($myrow2['quantity']==0) continue; + alt_table_row_color($k); + + $net = ((1 - $myrow2["discount_percent"]) * $myrow2["FullUnitPrice"] * -$myrow2["quantity"]); + $sub_total += $net; + + if ($myrow2["discount_percent"] == 0) + { + $display_discount = ""; + } + else + { + $display_discount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%"; + } + + label_cell($myrow2["stock_id"]); + label_cell($myrow2["StockDescription"]); + qty_cell(-$myrow2["quantity"]); + label_cell($myrow2["units"], "align=right"); + amount_cell($myrow2["FullUnitPrice"]); + label_cell($display_discount, "nowrap align=right"); + amount_cell($net); + end_row(); + } //end while there are line items to print out + +} +else + display_note(_("There are no line items on this dispatch."), 1, 2); + +$display_sub_tot = number_format2($sub_total,user_price_dec()); +$display_freight = number_format2($myrow["ov_freight"],user_price_dec()); + +/*Print out the delivery note text entered */ +label_row(_("Sub-total"), $display_sub_tot, "colspan=6 align=right", + "nowrap align=right width=15%"); +label_row(_("Shipping"), $display_freight, "colspan=6 align=right", "nowrap align=right"); + +$tax_items = get_customer_trans_tax_details(13, $trans_id); +display_customer_trans_tax_details($tax_items, 6); + +$display_total = number_format2($myrow["ov_freight"]+$myrow["ov_amount"],user_price_dec()); + +label_row(_("TOTAL VALUE"), $display_total, "colspan=6 align=right", + "nowrap align=right"); +end_table(1); + +is_voided_display(13, $trans_id, _("This dispatch has been voided.")); + +end_page(true); + +?> \ No newline at end of file diff --git a/sales/view/view_invoice.php b/sales/view/view_invoice.php index 8c2fb857..498eb4e2 100644 --- a/sales/view/view_invoice.php +++ b/sales/view/view_invoice.php @@ -65,8 +65,8 @@ start_table("$table_style width=100%"); $th = array(_("Delivered To")); table_header($th); -label_row(null, $sales_order["deliver_to"] . "
" . nl2br($sales_order["delivery_address"]), - "nowrap"); +//label_row(null, $sales_order["deliver_to"] . "
" . nl2br($sales_order["delivery_address"]), +// "nowrap"); end_table(); echo ""; // outer table diff --git a/sales/view/view_sales_order.php b/sales/view/view_sales_order.php index a1b63862..e717e4be 100644 --- a/sales/view/view_sales_order.php +++ b/sales/view/view_sales_order.php @@ -32,9 +32,9 @@ start_table("$table_style2 width=95%", 5); echo ""; display_heading2(_("Order Information")); echo ""; -display_heading2(_("Sales Invoices")); +display_heading2(_("Deliveries")); echo ""; -display_heading2(_("Credit Notes")); +display_heading2(_("Invoices/Credits")); echo ""; echo ""; @@ -66,6 +66,40 @@ end_table(); echo ""; start_table($table_style); +display_heading2(_("Delivery Notes")); + +$th = array(_("#"), _("Ref"), _("Date"), _("Total")); +table_header($th); + +$sql = "SELECT * FROM ".TB_PREF."debtor_trans WHERE type=13 AND order_=" . $_GET['trans_no']; +$result = db_query($sql,"The related delivery notes could not be retreived"); + +$delivery_total = 0; +$k = 0; + +while ($del_row = db_fetch($result)) +{ + + alt_table_row_color($k); + + $this_total = $del_row["ov_freight"] + $del_row["ov_gst"] + $del_row["ov_amount"]; + $delivery_total += $this_total; + + label_cell(get_customer_trans_view_str($del_row["type"], $del_row["trans_no"])); + label_cell($del_row["reference"]); + label_cell(sql2date($del_row["tran_date"])); + amount_cell($this_total); + end_row(); + +} + +label_row(null, number_format2($delivery_total,user_price_dec()), "", "colspan=4 align=right"); + +end_table(); +echo ""; + +start_table($table_style); +display_heading2(_("Sales Invoices")); $th = array(_("#"), _("Ref"), _("Date"), _("Total")); table_header($th); @@ -96,7 +130,8 @@ label_row(null, number_format2($invoices_total,user_price_dec()), "", "colspan=4 end_table(); -echo ""; +display_heading2(_("Credit Notes")); + start_table($table_style); $th = array(_("#"), _("Ref"), _("Date"), _("Total")); table_header($th); @@ -157,7 +192,7 @@ foreach ($_SESSION['Items']->line_items as $stock_item) { amount_cell($stock_item->discount_percent * 100); amount_cell($line_total); - qty_cell($stock_item->qty_inv); + qty_cell($stock_item->qty_done); end_row(); } diff --git a/sql/alter.sql b/sql/alter.sql index f53456ec..b6021979 100644 --- a/sql/alter.sql +++ b/sql/alter.sql @@ -20,6 +20,7 @@ ALTER TABLE `0_supp_invoice_items` CHANGE `gl_code` `gl_code` VARCHAR(11) NOT NU ALTER TABLE `0_sales_order_details` DROP PRIMARY KEY; ALTER TABLE `0_sales_order_details` ADD `id` INTEGER(11) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`); +ALTER TABLE `0_sales_order_details` CHANGE `qty_invoiced` `qty_sent` DOUBLE NOT NULL default '0'; ALTER TABLE `0_company` ADD `no_item_list` TINYINT(1) NOT NULL DEFAULT '0' AFTER `f_year`; ALTER TABLE `0_company` ADD `no_customer_list` TINYINT(1) NOT NULL DEFAULT '0' AFTER `no_item_list`; @@ -29,3 +30,7 @@ ALTER TABLE `0_salesman` ADD `provision` DOUBLE NOT NULL DEFAULT '0' AFTER `sale ALTER TABLE `0_salesman` ADD `break_pt` DOUBLE NOT NULL DEFAULT '0' AFTER `provision`; ALTER TABLE `0_salesman` ADD `provision2` DOUBLE NOT NULL DEFAULT '0' AFTER `break_pt`; +ALTER TABLE `0_debtor_trans_details` ADD COLUMN `qty_done` double NOT NULL default '0'; +ALTER TABLE `0_debtor_trans` ADD COLUMN `trans_link` int(11) NOT NULL default '0'; + +INSERT INTO `0_sys_types` VALUES ('13', 'Delivery', '1', '1'); -- 2.30.2