Unstable release 2.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 3 Feb 2008 23:18:01 +0000 (23:18 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 3 Feb 2008 23:18:01 +0000 (23:18 +0000)
21 files changed:
admin/company_preferences.php
admin/create_coy.php
admin/db/company_db.inc
config.php
includes/ui/ui_input.inc
includes/ui/ui_lists.inc
purchasing/includes/db/invoice_items_db.inc
purchasing/includes/ui/po_ui.inc
purchasing/supplier_trans_gl.php
sales/credit_note_entry.php
sales/customer_credit_invoice.php
sales/customer_invoice.php
sales/includes/cart_class.inc
sales/includes/db/cust_trans_details_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_invoice_db.inc
sales/includes/db/sales_order_db.inc
sales/includes/ui/sales_credit_ui.inc
sales/includes/ui/sales_order_ui.inc
sales/manage/sales_people.php
sales/sales_order_entry.php

index b4c98781661fe385f42df6cacdc454f637fc31c3..d4f3839d94ab0d50fa936c3e2626b1ebfde837c8 100644 (file)
@@ -13,12 +13,12 @@ include_once($path_to_root . "/admin/db/company_db.inc");
 
 //-------------------------------------------------------------------------------------------------
 
-if (isset($_POST['submit']) && $_POST['submit'] != "") 
+if (isset($_POST['submit']) && $_POST['submit'] != "")
 {
 
        $input_error = 0;
 
-       if (strlen($_POST['coy_name'])==0) 
+       if (strlen($_POST['coy_name'])==0)
        {
                $input_error = 1;
                display_error(_("The company name must be entered."));
@@ -29,7 +29,8 @@ if (isset($_POST['submit']) && $_POST['submit'] != "")
                        $_POST['postal_address'], $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['coy_logo'], $_POST['domicile'],
                        $_POST['use_dimension'], $_POST['custom1_name'], $_POST['custom2_name'], $_POST['custom3_name'],
                        $_POST['custom1_value'], $_POST['custom2_value'], $_POST['custom3_value'],
-                       $_POST['curr_default'], $_POST['f_year']);
+                       $_POST['curr_default'], $_POST['f_year'], check_value('no_item_list'), check_value('no_customer_list'),
+                       check_value('no_supplier_list'));
 
                display_notification_centered(_("Company setup has been updated."));
        }
@@ -55,6 +56,9 @@ $_POST['email']  = $myrow["email"];
 $_POST['coy_logo']  = $myrow["coy_logo"];
 $_POST['domicile']  = $myrow["domicile"];
 $_POST['use_dimension']  = $myrow["use_dimension"];
+$_POST['no_item_list']  = $myrow["no_item_list"];
+$_POST['no_customer_list']  = $myrow["no_customer_list"];
+$_POST['no_supplier_list']  = $myrow["no_supplier_list"];
 $_POST['custom1_name']  = $myrow["custom1_name"];
 $_POST['custom2_name']  = $myrow["custom2_name"];
 $_POST['custom3_name']  = $myrow["custom3_name"];
@@ -86,6 +90,10 @@ text_row_ex(_("Domicile:"), 'domicile', 25, 55);
 
 number_list_row(_("Use Dimensions:"), 'use_dimension', null, 0, 2);
 
+check_row(_("No Item List"), 'no_item_list', $_POST['no_item_list']);
+check_row(_("No Customer List"), 'no_customer_list', $_POST['no_customer_list']);
+check_row(_("No Supplier List"), 'no_supplier_list', $_POST['no_supplier_list']);
+
 start_row();
 end_row();
 label_row(_("Custom Field Name"), _("Custom Field Value"));
index 85579e0f92f1c37eae2ac47247911a492ed94bef..2730b7cfd130fdbde716f02e522fdb5740aef8b2 100644 (file)
@@ -52,7 +52,7 @@ function handle_submit()
        $db_connections[$id]['dbname'] = $_POST['dbname'];
        if (isset($_GET['ul']) && $_GET['ul'] == 1)
        {
-               if ($_POST['tbpref'] == 1)
+               if (is_numeric($_POST['tbpref']) && $_POST['tbpref'] == 1)
                {
                        $db_connections[$id]['tbpref'] = $tb_pref_counter."_";
                        $new = true;
index ee98b4638f92e836ca3c379487b8ad5fd065c406..29c1caf900da1f9159155fbdaef176fa989c69c9 100644 (file)
@@ -51,7 +51,8 @@ function update_company_gl_setup($debtors_act, $pyt_discount_act, $creditors_act
 
 function update_company_setup($coy_name, $coy_no, $gst_no, $tax_prd, $tax_last, $postal_address, $phone, $fax, $email,
                $coy_logo, $domicile, $Dimension, $custom1_name, $custom2_name, $custom3_name,
-               $custom1_value, $custom2_value, $custom3_value, $curr_default, $f_year)
+               $custom1_value, $custom2_value, $custom3_value, $curr_default, $f_year, $no_item_list, $no_customer_list,
+               $no_supplier_list)
 {
        if ($f_year == null)
                $f_year = 0;
@@ -66,6 +67,9 @@ function update_company_setup($coy_name, $coy_no, $gst_no, $tax_prd, $tax_last,
                coy_logo='$coy_logo',
                domicile='$domicile',
                use_dimension=$Dimension,
+               no_item_list=$no_item_list,
+               no_customer_list=$no_customer_list,
+               no_supplier_list=$no_supplier_list,
         custom1_name='$custom1_name',
         custom2_name='$custom2_name',
         custom3_name='$custom3_name',
index 550efbe98dd5313135dcb9d0cd1ccbca62eb2f6d..685372efb99caaf301ea42d9ddce3c142e6d3760 100644 (file)
@@ -39,8 +39,8 @@
 
     $debug                     = 1;
        $show_sql               = 0;
-       $go_debug               = 0;
-       if ($go_debug == 1)
+       $go_debug               = 1;
+       if ($go_debug == 0)
        {
                error_reporting(E_ALL);
                ini_set("display_errors", "On");
        // Main Title
        $app_title = "FrontAccounting";
     // application version
-    $version           = "1.16";
+    $version           = "2.0 Pre Alpha";
 
     // Build for development purposes
-    $build_version     = "15";
+    $build_version     = "2";
 
        // Powered by
        $power_by               = "FrontAccounting";
        /* print_invoice_no. 0 = print reference number, 1 = print invoice number */
        $print_invoice_no = 0;
 
-       /* Flags for no item, customer and supplier lists. The list can only hold about 1000 items in the lists */
-       $no_item_list =         0; // change value to 1 if you do not want all items in list
-       $no_customer_list = 0; // change value to 1 if you do not want all customers in list
-       $no_supplier_list = 0; // change value to 1 if you do not want all suppliers in list
-
        $dateformats    = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD");
        $dateseps               = array("/", ".", "-", " ");
        $thoseps                = array(",", ".", " ");
index 0220b7be55db4538642974f4c05c3b46a15be2ee..fdb55200bd2ef899ed913fb162402feba502e75f 100644 (file)
@@ -86,14 +86,14 @@ function submit_row($name, $value, $right=true, $extra="")
                echo "<td>&nbsp;</td>\n";
        submit_cells($name, $value, $extra);
        echo "</tr>\n";
-}      
+}
 //-----------------------------------------------------------------------------------
 
-function check_value($name) 
+function check_value($name)
 {
        if (!isset($_POST[$name]))
                return 0;
-       return 1;       
+       return 1;
 }
 
 function check($label, $name, $value, $submit_on_change=false)
@@ -130,12 +130,12 @@ function check_row($label, $name, $value, $submit_on_change=false)
 
 //-----------------------------------------------------------------------------------
 
-function labelheader_cell($label, $params="") 
+function labelheader_cell($label, $params="")
 {
        echo "<td class='tableheader' $params>$label</td>\n";
 }
 
-function label_cell($label, $params="") 
+function label_cell($label, $params="")
 {
        echo "<td $params>$label</td>\n";
 }
@@ -144,15 +144,23 @@ function amount_cell($label, $bold=false)
 {
        if ($bold)
                label_cell("<b>".number_format2($label,user_price_dec())."</b>", "nowrap align=right");
-       else    
+       else
                label_cell(number_format2($label,user_price_dec()), "nowrap align=right");
 }
 
+function percent_cell($label, $bold=false)
+{
+       if ($bold)
+               label_cell("<b>".number_format2($label,user_percent_dec())." %</b>", "nowrap align=right");
+       else
+               label_cell(number_format2($label,user_percent_dec())." %", "nowrap align=right");
+}
+
 function qty_cell($label, $bold=false)
 {
        if ($bold)
                label_cell("<b>".number_format2($label,user_qty_dec())."</b>", "nowrap align=right");
-       else    
+       else
                label_cell(number_format2($label,user_qty_dec()), "nowrap align=right");
 }
 
@@ -190,7 +198,7 @@ function text_cells($label, $name, $value, $size="", $max="", $params="", $post_
 
 function text_cells_ex($label, $name, $size, $max=null, $init=null, $params=null, $post_label=null)
 {
-       if (!isset($_POST[$name]) || $_POST[$name] == "") 
+       if (!isset($_POST[$name]) || $_POST[$name] == "")
        {
                if ($init)
                        $_POST[$name] = $init;
@@ -238,7 +246,7 @@ function text_row_ex($label, $name, $size, $max=null, $value=null, $params=null,
 function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_years=0, $params=null)
 {
        global $use_date_picker, $path_to_root;
-       if (!isset($_POST[$name]) || $_POST[$name] == "") 
+       if (!isset($_POST[$name]) || $_POST[$name] == "")
        {
                if (!$init)
                {
@@ -254,8 +262,8 @@ function date_cells($label, $name, $init=null, $inc_days=0, $inc_months=0, $inc_
                                if ($inc_years != 0)
                                        $dd = add_years($dd, $inc_years);
                                $_POST[$name] = $dd;
-                       }       
-               }               
+                       }
+               }
                else
                        $_POST[$name] = $init;
        }
@@ -295,7 +303,7 @@ function ref_row($label, $name, $init=null)
 function percent_row($label, $name, $init=null)
 {
 
-       if (!isset($_POST[$name]) || $_POST[$name]=="") 
+       if (!isset($_POST[$name]) || $_POST[$name]=="")
        {
                if ($init)
                        $_POST[$name] = $init;
index a29dda765317e30b0fa476cd15a35a50a620e728..3c7fd1e59ee23bc73e5f09a2fa4abf32f2bd760a 100644 (file)
@@ -13,11 +13,11 @@ $all_items = reserved_words::get_all();
 
 function supplier_list($name, $selected_id, $all_option=false, $submit_on_change=false)
 {
-       global $no_supplier_list, $all_items;
+       global $all_items;
 
        if ($selected_id == null)
                $selected_id = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]);
-
+       $no_supplier_list = get_company_pref('no_supplier_list');
        if ($no_supplier_list)
        {
                global $search_button;
@@ -127,11 +127,11 @@ function supplier_list_row($label, $name, $selected_id, $all_option=false, $subm
 
 function customer_list($name, $selected_id, $all_option=false, $submit_on_change=false)
 {
-       global $no_customer_list, $all_items;
+       global $all_items;
 
        if ($selected_id == null)
                $selected_id = ((!isset($_POST[$name]) || $_POST[$name] == "") ? "" : $_POST[$name]);
-
+       $no_customer_list = get_company_pref('no_customer_list');
        if ($no_customer_list)
        {
                global $search_button;
@@ -606,11 +606,11 @@ function dimensions_list_row($label, $name, $selected_id, $no_option=false, $sho
 
 function stock_items_list($name, $selected_id, $all_option=false, $submit_on_change=false, $extra="")
 {
-       global $all_items, $no_item_list;
+       global $all_items;
 
        if ($selected_id == null)
                $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
-
+       $no_item_list = get_company_pref('no_item_list');
        if ($no_item_list)
        {
                global $search_button;
@@ -898,14 +898,13 @@ function stock_component_items_list($name, $parent_stock_id, &$selected_id,
 
 function stock_purchasable_items_list($name, &$selected_id,    $all_option=false, $submit_on_change=false, $extra="")
 {
-       global $no_item_list, $all_items;
+       global $all_items;
 
        if ($selected_id == null)
                $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
-
+       $no_item_list = get_company_pref('no_item_list');
        if ($no_item_list)
        {
-               global $search_button;
                $edit_name = $name."_edit";
                $edit_button = $name."_button";
 
@@ -938,9 +937,9 @@ function stock_purchasable_items_list($name, &$selected_id, $all_option=false, $
                                $result = false;
                }
 
-               echo "<input type='text' name='$edit_name' size='8' maxlength='50' value='$val' onblur='this.form.$edit_button.click();'> ";
+               echo "<input type='text' name='$edit_name' size='8' maxlength='50' value='$val' > ";
 
-               echo sprintf($search_button, $edit_button);
+               echo "<input type='submit' class='inputsubmit' name='$edit_button' value='?'> ";
        }
        else
        {
index e072e6f68847778055998dd49d036cf53edc67a2..78849f7b018e61f4b449f11856b841ef0b21e6d8 100644 (file)
@@ -2,40 +2,40 @@
 
 //-------------------------------------------------------------------------------------------------------------
 
-function add_supp_invoice_item($supp_trans_type, $supp_trans_no, $stock_id, $description, 
-       $gl_code, $unit_price, $unit_tax, $quantity, $grn_item_id, $po_detail_item_id, $memo_, 
-       $err_msg="")                                                    
+function add_supp_invoice_item($supp_trans_type, $supp_trans_no, $stock_id, $description,
+       $gl_code, $unit_price, $unit_tax, $quantity, $grn_item_id, $po_detail_item_id, $memo_,
+       $err_msg="")
 {
        $sql = "INSERT INTO ".TB_PREF."supp_invoice_items (supp_trans_type, supp_trans_no, stock_id, description, gl_code, unit_price, unit_tax, quantity,
                grn_item_id, po_detail_item_id, memo_) ";
-       $sql .= "VALUES ($supp_trans_type, $supp_trans_no, '$stock_id', '$description', $gl_code, $unit_price, $unit_tax, $quantity, 
+       $sql .= "VALUES ($supp_trans_type, $supp_trans_no, '$stock_id', '$description', '$gl_code', $unit_price, $unit_tax, $quantity,
                $grn_item_id, $po_detail_item_id, '$memo_')";
-       
+
        if ($err_msg == "")
                $err_msg = "Cannot insert a supplier transaction detail record";
-               
-       db_query($sql, $err_msg);               
 
-       return db_insert_id();                                                                  
+       db_query($sql, $err_msg);
+
+       return db_insert_id();
 }
 
 //-------------------------------------------------------------------------------------------------------------
 
-function add_supp_invoice_gl_item($supp_trans_type, $supp_trans_no, $gl_code, $amount, $memo_, $err_msg="")                                                    
+function add_supp_invoice_gl_item($supp_trans_type, $supp_trans_no, $gl_code, $amount, $memo_, $err_msg="")
 {
-       return add_supp_invoice_item($supp_trans_type, $supp_trans_no,  "", "", $gl_code, $amount, 
-               0, 0, /*$grn_item_id*/0, /*$po_detail_item_id*/0, $memo_, $err_msg);    
-}      
+       return add_supp_invoice_item($supp_trans_type, $supp_trans_no,  "", "", $gl_code, $amount,
+               0, 0, /*$grn_item_id*/0, /*$po_detail_item_id*/0, $memo_, $err_msg);
+}
 
 
 //----------------------------------------------------------------------------------------
 
 function get_supp_invoice_items($supp_trans_type, $supp_trans_no)
 {
-       $sql = "SELECT *,unit_price+unit_tax AS FullUnitPrice FROM ".TB_PREF."supp_invoice_items 
-               WHERE supp_trans_type = $supp_trans_type 
+       $sql = "SELECT *,unit_price+unit_tax AS FullUnitPrice FROM ".TB_PREF."supp_invoice_items
+               WHERE supp_trans_type = $supp_trans_type
                AND supp_trans_no = $supp_trans_no ORDER BY id";
-       return db_query($sql, "Cannot retreive supplier transaction detail records");   
+       return db_query($sql, "Cannot retreive supplier transaction detail records");
 }
 
 //----------------------------------------------------------------------------------------
@@ -44,7 +44,7 @@ function void_supp_invoice_items($type, $type_no)
 {
        $sql = "UPDATE ".TB_PREF."supp_invoice_items SET quantity=0, unit_price=0
                WHERE supp_trans_type = $type AND supp_trans_no=$type_no";
-       db_query($sql, "could not void supptrans details");     
+       db_query($sql, "could not void supptrans details");
 }
 
 //----------------------------------------------------------------------------------------
@@ -54,8 +54,8 @@ function add_supp_invoice_tax_item($supp_trans_type, $supp_trans_no, $tax_type_i
 {
        $sql = "INSERT INTO ".TB_PREF."supp_invoice_tax_items (supp_trans_type, supp_trans_no, tax_type_id, rate, included_in_price, amount)
                VALUES ($supp_trans_type, $supp_trans_no, $tax_type_id, $rate, $included_in_price, $amount)";
-                       
-       db_query($sql, "The supplier transaction tax detail could not be added");       
+
+       db_query($sql, "The supplier transaction tax detail could not be added");
 }
 
 //----------------------------------------------------------------------------------------
@@ -63,9 +63,9 @@ function add_supp_invoice_tax_item($supp_trans_type, $supp_trans_no, $tax_type_i
 function get_supp_invoice_tax_items($supp_trans_type, $supp_trans_no)
 {
        $sql = "SELECT ".TB_PREF."supp_invoice_tax_items.*, ".TB_PREF."tax_types.name AS tax_type_name
-               FROM ".TB_PREF."supp_invoice_tax_items,".TB_PREF."tax_types 
-               WHERE supp_trans_type = $supp_trans_type 
-               AND supp_trans_no = $supp_trans_no 
+               FROM ".TB_PREF."supp_invoice_tax_items,".TB_PREF."tax_types
+               WHERE supp_trans_type = $supp_trans_type
+               AND supp_trans_no = $supp_trans_no
                AND ".TB_PREF."tax_types.id = ".TB_PREF."supp_invoice_tax_items.tax_type_id";
 
        return db_query($sql, "The supplier transaction tax details could not be queried");
@@ -76,9 +76,9 @@ function get_supp_invoice_tax_items($supp_trans_type, $supp_trans_no)
 function void_supp_invoice_tax_items($type, $type_no)
 {
        $sql = "UPDATE ".TB_PREF."supp_invoice_tax_items SET amount=0
-               WHERE supp_trans_type = $type 
+               WHERE supp_trans_type = $type
                AND supp_trans_no=$type_no";
-                               
+
        db_query($sql, "The supplier transaction tax details could not be voided");
 }
 
index a78263a89271caf8de02d1b47981a10631df0703..240012538af61f25f0ff4c104300df29bc7fd8c8 100644 (file)
@@ -290,10 +290,9 @@ function po_item_controls(&$order, $stock_id=null)
        }
        else
        {
-               global $no_item_list;
-
                hidden('line_no', ($_SESSION['PO']->lines_on_order + 1));
 
+               $no_item_list = get_company_pref('no_item_list');
                if ($no_item_list)
                {
                        echo "<td colspan=2>\n";
index 903dc56980ba1b91e14e71972d5368fc3880fca8..cc78626998f5f2d480ec7707bdd2ab4565050bd7 100644 (file)
@@ -22,7 +22,7 @@ if (!isset($_SESSION['supp_trans']))
 
 //------------------------------------------------------------------------------------------------
 
-function clear_fields() 
+function clear_fields()
 {
        unset($_POST['gl_code']);
        unset($_POST['dimension_id']);
@@ -30,7 +30,7 @@ function clear_fields()
        unset($_POST['amount']);
        unset($_POST['memo_']);
        unset($_POST['AcctSelection']);
-       unset($_POST['AddGLCodeToTrans']);      
+       unset($_POST['AddGLCodeToTrans']);
 }
 
 //------------------------------------------------------------------------------------------------
@@ -43,14 +43,14 @@ if (isset($_POST['AddGLCodeToTrans'])){
                $_POST['gl_code'] = $_POST['AcctSelection'];
        }
 
-       $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code=" . $_POST['gl_code'];
+       $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code='" . $_POST['gl_code'] . "'";
        $result = db_query($sql,"get account information");
        if (db_num_rows($result) == 0)
        {
                display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction."));
                $input_error = true;
-       } 
-       else 
+       }
+       else
        {
                $myrow = db_fetch_row($result);
                $gl_act_name = $myrow[1];
@@ -63,7 +63,7 @@ if (isset($_POST['AddGLCodeToTrans'])){
 
        if ($input_error == false)
        {
-               $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name, 
+               $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name,
                        $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['amount'], $_POST['memo_']);
                clear_fields();
        }
@@ -74,24 +74,24 @@ if (isset($_POST['AddGLCodeToTrans'])){
 if (isset($_GET['Delete']))
 {
        $_SESSION['supp_trans']->remove_gl_codes_from_trans($_GET['Delete']);
-       clear_fields(); 
+       clear_fields();
 }
 
 //------------------------------------------------------------------------------------------------
 
-display_heading($_SESSION['supp_trans']->supplier_name);       
+display_heading($_SESSION['supp_trans']->supplier_name);
 
 display_gl_items($_SESSION['supp_trans'], 1);
-                                               
+
 echo "<br>";
 
 if ($_SESSION['supp_trans']->is_invoice == true)
 {
        hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Invoice Entry"));
-} 
-else 
+}
+else
 {
-       hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Back to Credit Note Entry"));    
+       hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Back to Credit Note Entry"));
 }
 
 echo "<hr>";
index 98a7442f3feaa70e93204ea785ec2b3f7ab67b29..c53cc062b6eeeae4d46c90c671605b8262368140 100644 (file)
@@ -33,14 +33,14 @@ check_db_has_customer_branches(_("There are no customers, or there are no custom
 
 //---------------------------------------------------------------------------------------------------------------
 
-if (isset($_GET['AddedID'])) 
+if (isset($_GET['AddedID']))
 {
        $credit_no = $_GET['AddedID'];
        $trans_type = 11;
 
        display_notification_centered(_("Credit Note has been processed"));
        display_note(get_customer_trans_view_str($trans_type, $credit_no, _("View this credit note")), 0, 1);
-       
+
        display_note(get_gl_view_str($trans_type, $credit_no, _("View the GL Journal Entries for this Credit Note")));
 
        hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Credit Note"), "NewCredit=yes");
@@ -94,8 +94,8 @@ function handle_new_order()
        $_POST['OrderDate'] = Today();
        if (!is_date_in_fiscalyear($_POST['OrderDate']))
                $_POST['OrderDate'] = end_fiscalyear();
-       $_SESSION['credit_items']->orig_order_date = $_POST['OrderDate'];       
-    
+       $_SESSION['credit_items']->orig_order_date = $_POST['OrderDate'];
+
 }
 
 //-----------------------------------------------------------------------------------------------
@@ -105,22 +105,22 @@ if (isset($_POST['ProcessCredit']))
 
        $input_error = 0;
 
-       if (!references::is_valid($_POST['ref'])) 
+       if (!references::is_valid($_POST['ref']))
        {
                display_error( _("You must enter a reference."));
                $input_error = 1;
-       } 
-       elseif (!is_new_reference($_POST['ref'], 11)) 
+       }
+       elseif (!is_new_reference($_POST['ref'], 11))
        {
                display_error( _("The entered reference is already in use."));
                $input_error = 1;
-       } 
-       elseif (!is_date($_POST['OrderDate'])) 
+       }
+       elseif (!is_date($_POST['OrderDate']))
        {
                display_error(_("The entered date for the credit note is invalid."));
                $input_error = 1;
-       } 
-       elseif (!is_date_in_fiscalyear($_POST['OrderDate'])) 
+       }
+       elseif (!is_date_in_fiscalyear($_POST['OrderDate']))
        {
                display_error(_("The entered date is not in fiscal year."));
                $input_error = 1;
@@ -134,7 +134,7 @@ if (isset($_POST['ProcessCredit']))
 if (isset($_POST['ProcessCredit']))
 {
        //alert("WriteOffGLCode = ".$_POST['WriteOffGLCode'].", CreditType = ".$_POST['CreditType']);
-       if ($_POST['CreditType'] == "WriteOff" && (!isset($_POST['WriteOffGLCode']) || 
+       if ($_POST['CreditType'] == "WriteOff" && (!isset($_POST['WriteOffGLCode']) ||
                $_POST['WriteOffGLCode'] == ''))
        {
                display_note(_("For credit notes created to write off the stock, a general ledger account is required to be selected."), 1, 0);
@@ -192,7 +192,7 @@ function handle_update_item()
 {
     if($_POST['UpdateItem'] != "" && check_item_data())
     {
-       $_SESSION['credit_items']->update_cart_item($_POST['stock_id'], $_POST['qty'], 
+       $_SESSION['credit_items']->update_cart_item($_POST['line_no'], $_POST['qty'],
                $_POST['price'], ($_POST['Disc'] / 100));
     }
 }
@@ -211,7 +211,7 @@ function handle_new_item()
        if (!check_item_data())
                return;
 
-       add_to_order($_SESSION['credit_items'], $_POST['stock_id'], $_POST['qty'],
+       add_to_order($_SESSION['credit_items'], $_POST['line_no'], $_POST['stock_id'], $_POST['qty'],
                $_POST['price'], $_POST['Disc'] / 100);
 }
 
@@ -236,8 +236,8 @@ if (isset($_POST['UpdateItem']))
 if (isset($_GET['NewCredit']) || !isset($_SESSION['credit_items']))
 {
        handle_new_order();
-} 
-else 
+}
+else
 {
        if (!isset($_POST['customer_id']))
                $_POST['customer_id'] = $_SESSION['credit_items']->customer_id;
@@ -259,7 +259,7 @@ if ($customer_error == "")
     credit_options_controls();
     echo "</td></tr>";
     end_table();
-} 
+}
 else
 {
        display_error($customer_error);
index 468d4f4a13a3a4267fc4a6e1b857f063f8263faa..85eda971ea577a638788b5e05766d6658e5ecd72 100644 (file)
@@ -20,7 +20,7 @@ page(_("Credit all or part of an Invoice"), false, false, "", $js);
 
 //---------------------------------------------------------------------------------------------------------------
 
-if (isset($_GET['AddedID'])) 
+if (isset($_GET['AddedID']))
 {
        $credit_no = $_GET['AddedID'];
        $trans_type = 11;
@@ -28,7 +28,7 @@ if (isset($_GET['AddedID']))
        echo "<center>";
        display_notification_centered(_("Credit Note has been processed"));
        display_note(get_customer_trans_view_str($trans_type, $credit_no, _("View this credit note")), 0, 0);
-       
+
        display_note(get_gl_view_str($trans_type, $credit_no, _("View the GL Journal Entries for this Credit Note")));
 
        display_footer_exit();
@@ -36,7 +36,7 @@ if (isset($_GET['AddedID']))
 
 //--------------------------------------------------------------------------------------
 
-if (!isset($_GET['InvoiceNumber']) && !$_SESSION['InvoiceToCredit']) 
+if (!isset($_GET['InvoiceNumber']) && !$_SESSION['InvoiceToCredit'])
 {
        /* This page can only be called with an invoice number for crediting*/
        die (_("This page can only be opened if an invoice has been selected for crediting."));
@@ -46,30 +46,30 @@ if (!isset($_GET['InvoiceNumber']) && !$_SESSION['InvoiceToCredit'])
 
 function can_process()
 {
-       if (!is_date($_POST['CreditDate'])) 
+       if (!is_date($_POST['CreditDate']))
        {
                display_error(_("The entered date is invalid."));;
                return false;
-       } 
-       elseif (!is_date_in_fiscalyear($_POST['CreditDate'])) 
+       }
+       elseif (!is_date_in_fiscalyear($_POST['CreditDate']))
        {
                display_error(_("The entered date is not in fiscal year."));
                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'], 11)) 
+       if (!is_new_reference($_POST['ref'], 11))
        {
                display_error(_("The entered reference is already in use."));;
                return false;
        }
 
-       if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0) 
+       if (!is_numeric($_POST['ChargeFreightCost']) || $_POST['ChargeFreightCost'] < 0)
        {
                display_error(_("The entered shipping cost is invalid or less than zero."));;
                return false;
@@ -82,7 +82,7 @@ function can_process()
 
 function clear_globals()
 {
-       if (isset($_SESSION['Items'])) 
+       if (isset($_SESSION['Items']))
        {
                unset($_SESSION['Items']->line_items);
                unset($_SESSION['Items']);
@@ -98,8 +98,8 @@ function process_credit()
        if (can_process())
        {
                $credit_no = credit_invoice($_SESSION['Items'], $_SESSION['InvoiceToCredit'],
-                       $_SESSION['Order'],     $_POST['CreditDate'], $_POST['CreditType'], 
-                       $_POST['tax_group_id'], $_POST['ChargeFreightCost'], $_POST['ref'], 
+                       $_SESSION['Order'],     $_POST['CreditDate'], $_POST['CreditType'],
+                       $_POST['tax_group_id'], $_POST['ChargeFreightCost'], $_POST['ref'],
                        $_POST['CreditText'], $_POST['WriteOffGLCode']);
 
                clear_globals();
@@ -110,7 +110,7 @@ function process_credit()
 
 //--------------------------------------------------------------------------------------
 
-if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0) 
+if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0)
 {
 
        clear_globals();
@@ -142,7 +142,7 @@ if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0)
 
        $result = db_query($sql,"The invoice details cannot be retrieved");
 
-       if (db_num_rows($result) == 1) 
+       if (db_num_rows($result) == 1)
        {
 
                $myrow = db_fetch($result);
@@ -173,16 +173,16 @@ if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0)
 
                $result = get_customer_trans_details(10, $_GET['InvoiceNumber']);
 
-               if (db_num_rows($result) > 0) 
+               if (db_num_rows($result) > 0)
                {
 
-                       while ($myrow = db_fetch($result)) 
+                       while ($myrow = db_fetch($result))
                        {
 
-                               $_SESSION['Items']->add_to_cart($myrow["stock_id"],-$myrow["quantity"],
+                               $_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']->line_items[$myrow["stock_id"]]->standard_cost = $myrow["standard_cost"];
+                               $_SESSION['Items']->line_items[$_SESSION['Items']->lines_on_order]->standard_cost = $myrow["standard_cost"];
 
                        }
 
@@ -195,8 +195,8 @@ if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0)
 
                }*/ //end of checks on returned data set
                db_free_result($result);
-       } 
-       else 
+       }
+       else
        {
                display_error(_("This invoice can not be credited using the automatic facility."));
                display_error("Please report that a duplicate debtor_trans header record was found for invoice " . $SESSION['InvoiceToCredit']);
@@ -204,18 +204,18 @@ if (isset($_GET['InvoiceNumber']) && $_GET['InvoiceNumber'] > 0)
                exit;
        } //valid invoice record returned from the entered invoice number
 
-} 
-else 
+}
+else
 {
 
 /* if processing, the 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 $itm)
        {
-               $_SESSION['Items']->line_items[$itm->stock_id]->qty_dispatched = $_POST[$itm->stock_id];
+               $_SESSION['Items']->line_items[$itm->line_no]->qty_dispatched = $_POST[$itm->stock_id];
 
-               if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0) 
+               if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0)
                {
-                       $_SESSION['Items']->line_items[$itm->stock_id]->item_description = $_POST[$itm->stock_id . "Desc"];
+                       $_SESSION['Items']->line_items[$itm->line_no]->item_description = $_POST[$itm->stock_id . "Desc"];
                }
        }
 }
@@ -252,7 +252,7 @@ function display_credit_items()
     label_cells(_("Currency"), $_SESSION['Items']->customer_currency, "class='tableheader2'");
     end_row();
     start_row();
-    
+
        if (!isset($_POST['ref']))
                $_POST['ref'] = references::get_next(11);
 
@@ -262,7 +262,7 @@ function display_credit_items()
 
     if (!isset($_POST['tax_group_id']))
        $_POST['tax_group_id'] = $_SESSION['Items']->tax_group_id;
-    label_cell(_("Tax Group"), "class='tableheader2'");        
+    label_cell(_("Tax Group"), "class='tableheader2'");
     tax_groups_list_cells(null, 'tax_group_id', $_POST['tax_group_id'], false, null, true);
        end_row();
        end_table();
@@ -278,17 +278,17 @@ function display_credit_items()
     end_table();
 
        echo "</td></tr>";
-       
+
        end_table(1); // outer table
 
     start_table("$table_style width=80%");
     $th = array(_("Item Code"), _("Item Description"), _("Invoiced Quantity"), _("Units"),
        _("Credit Quantity"), _("Price"), _("Discount %"), _("Total"));
-    table_header($th); 
+    table_header($th);
 
     $k = 0; //row colour counter
 
-    foreach ($_SESSION['Items']->line_items as $ln_itm) 
+    foreach ($_SESSION['Items']->line_items as $ln_itm)
     {
 
        alt_table_row_color($k);
@@ -338,7 +338,7 @@ function display_credit_items()
 function display_credit_options()
 {
        global $table_style2;
-       
+
     echo "<br>";
     start_table($table_style2);
 
@@ -348,8 +348,8 @@ function display_credit_options()
     {
        echo "<option value='WriteOff'>" . _("Items Written Off") . "</option>";
        echo "<option selected value='Return'>" . _("Items Returned to Inventory Location") . "</option>";
-    } 
-    else 
+    }
+    else
     {
        echo "<option selected value='WriteOff'>" . _("Items Written Off") . "</option>";
        echo "<option value='Return'>" . _("Items Returned to Inventory Location") . "</option>";
@@ -368,8 +368,8 @@ function display_credit_options()
 
        locations_list_row(_("Items Returned to Inventory Location"), 'Location', $_POST['Location']);
 
-    } 
-    else 
+    }
+    else
     {  /* the goods are to be written off to somewhere */
 
        gl_all_accounts_list_row(_("Write Off the Cost of the Items to"), 'WriteOffGLCode', $_POST['WriteOffGLCode']);
index fa6c1a2668ddeadf7dedc4937c4ddcb4b3a0fbfc..8e6fce155926e80303b0851d7be375cf180c6b54 100644 (file)
@@ -18,11 +18,14 @@ if ($use_popup_windows)
        $js .= get_js_open_window(900, 500);
 if ($use_date_picker)
        $js .= get_js_date_picker();
-page(_("Issue an Invoice and Deliver Items for a Sales Order"), false, false, "", $js);
+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);
 
 //---------------------------------------------------------------------------------------------------------------
 
-if (isset($_GET['AddedID'])) 
+if (isset($_GET['AddedID']))
 {
        $invoice_no = $_GET['AddedID'];
        $trans_type = 10;
@@ -44,8 +47,8 @@ if (isset($_GET['AddedID']))
 
 //---------------------------------------------------------------------------------------------------------------
 
-if (!isset($_GET['OrderNumber']) && !isset($_SESSION['ProcessingOrder']) && 
-       !isset($_GET['process_invoice'])) 
+if (!isset($_GET['OrderNumber']) && !isset($_SESSION['ProcessingOrder']) &&
+       !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."));
@@ -55,8 +58,8 @@ if (!isset($_GET['OrderNumber']) && !isset($_SESSION['ProcessingOrder']) &&
        end_page();
        exit;
 
-} 
-elseif (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) 
+}
+elseif (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0)
 {
 
        if (isset($_SESSION['Items']))
@@ -73,39 +76,38 @@ elseif (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0)
 
        /*read in all the selected order into the Items cart  */
 
-       if (read_sales_order($_SESSION['ProcessingOrder'], $_SESSION['Items'], true)) 
+       if (read_sales_order($_SESSION['ProcessingOrder'], $_SESSION['Items'], true))
        {
 
-       if ($_SESSION['Items']->count_items() == 0) 
+       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 ("<br><b>" . _("There are no ordered items with a quantity left to deliver. There is nothing left to invoice.") . "</b>");
        }
-       } 
-       else 
+       }
+       else
        {
                hyperlink_no_params("/sales_orders_view.php", _("Select a sales order to invoice"));
                die ("<br><b>" . _("This order item could not be retrieved. Please select another order.") . "</b>");
        }
 
-} 
-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 $itm)
        {
 
-               if (isset($_SESSION['Items']->line_items[$itm->stock_id]) && 
-                       isset($_POST[$itm->stock_id]) && is_numeric($_POST[$itm->stock_id]) && 
-                       $_POST[$itm->stock_id] <= ($_SESSION['Items']->line_items[$itm->stock_id]->quantity - 
-                       $_SESSION['Items']->line_items[$itm->stock_id]->qty_inv))
+               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))
                {
-                       $_SESSION['Items']->line_items[$itm->stock_id]->qty_dispatched = $_POST[$itm->stock_id];
+                       $_SESSION['Items']->line_items[$itm->line_no]->qty_dispatched = $_POST[$itm->stock_id];
                }
 
-               if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0) 
+               if (isset($_POST[$itm->stock_id . "Desc"]) && strlen($_POST[$itm->stock_id . "Desc"]) > 0)
                {
-                       $_SESSION['Items']->line_items[$itm->stock_id]->item_description = $_POST[$itm->stock_id . "Desc"];
+                       $_SESSION['Items']->line_items[$itm->line_no]->item_description = $_POST[$itm->stock_id . "Desc"];
                }
        }
 }
@@ -158,21 +160,26 @@ function check_order_changed()
                return false;
        }
 
-       while ($myrow = db_fetch($result)) 
+       while ($myrow = db_fetch($result))
        {
-               $stk_itm = $myrow["stk_code"];
-               if ($_SESSION['Items']->line_items[$stk_itm]->quantity != $myrow["quantity"] ||
-                       $_SESSION['Items']->line_items[$stk_itm]->qty_inv != $myrow["qty_invoiced"])
+               foreach($_SESSION['Items']->line_items as $line)
                {
-                       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") . " " . 
-                               $_SESSION['Items']->line_items[$stk_itm]->quantity . " " . 
-                               _("and quantity invoice of") . " " . 
-                               $_SESSION['Items']->line_items[$stk_itm]->qty_inv, 1, 0);
-
-                       return false;
+                       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;
+                               }
+                       }
                }
        } /*loop through all line items of the order to ensure none have been invoiced */
 
@@ -184,42 +191,42 @@ function check_order_changed()
 
 function check_data()
 {
-       if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate'])) 
+       if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate']))
        {
                display_error(_("The entered invoice date is invalid."));
                return false;
        }
-       if (!is_date_in_fiscalyear($_POST['DispatchDate'])) 
+       if (!is_date_in_fiscalyear($_POST['DispatchDate']))
        {
                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;
@@ -234,14 +241,14 @@ function check_qoh()
 {
        if (!sys_prefs::allow_negative_stock())
        {
-       foreach ($_SESSION['Items']->line_items as $itm) 
+       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) 
+                       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);
@@ -258,8 +265,9 @@ function check_qoh()
 
 function process_invoice($invoicing=false)
 {
-       if ($invoicing) 
+       if ($invoicing)
        {
+
                read_sales_order($_SESSION['Items']->order_no, $_SESSION['Items'], true);
                $duedate = get_invoice_duedate($_SESSION['Items']->customer_id, $_SESSION['Items']->delivery_date);
                $invoice_no = add_sales_invoice($_SESSION['Items'],
@@ -268,10 +276,10 @@ function process_invoice($invoicing=false)
                        $_SESSION['Items']->Location, $_SESSION['Items']->ship_via,
                        $_SESSION['Items']->default_sales_type, references::get_next(10),
                        $_SESSION['Items']->memo_, 0);
-       } 
-       else 
+       }
+       else
        {
-       
+
                if (!check_data())
                        return;
 
@@ -325,7 +333,7 @@ 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'");    
+label_cell(_("Tax Group"), "class='tableheader2'");
 tax_groups_list_cells(null, 'tax_group_id', $_POST['tax_group_id'], false, null, true);
 
 label_cells(_("For Sales Order"), get_customer_trans_view_str(systypes::sales_order(), $_SESSION['ProcessingOrder']), "class='tableheader2'");
@@ -335,17 +343,17 @@ 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'");        
+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'");     
+label_cell(_("Shipping Company"), "class='tableheader2'");
 shippers_list_cells(null, 'ship_via', $_POST['ship_via']);
 end_row();
 
@@ -384,7 +392,7 @@ $k = 0;
 $has_marked = false;
 $show_qoh = true;
 
-foreach ($_SESSION['Items']->line_items as $ln_itm) 
+foreach ($_SESSION['Items']->line_items as $ln_itm)
 {
 
     // if it's a non-stock item (eg. service) don't show qoh
@@ -395,12 +403,12 @@ foreach ($_SESSION['Items']->line_items as $ln_itm)
        if ($show_qoh)
                $qoh = get_qoh_on_date($ln_itm->stock_id, $_POST['Location'], $_POST['DispatchDate']);
 
-       if ($show_qoh && ($ln_itm->qty_dispatched > $qoh)) 
+       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);
 
@@ -432,13 +440,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;
     }
index 1bb715895825ec9282f4f1e53666e91c1dc024bc..d5558d30e36da8333355b1c70c011c8c1f959806 100644 (file)
@@ -12,7 +12,7 @@ iii) a credit note
 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
 include_once($path_to_root . "/taxes/tax_calc.inc");
 
-class cart 
+class cart
 {
 
        var $line_items; /*array of objects of class line_details using the product id as the pointer */
@@ -24,50 +24,54 @@ class cart
        var $default_discount; // set to the customer's discount %
        var $direct_invoice;  // direct invoicing
        var $memo_; // memo_ on direct invoicing
-       
+
        var $deliver_to;
        var $delivery_address;
        var $phone;
-       
+
        var $email;
        var $cust_ref;
        var $Comments;
        var $Location;
        var $location_name;
-       
-       var $order_no; // the order number 
+
+       var $order_no; // the order number
 
        var $customer_name;
        var $customer_id;
        var $Branch;
-       
+
        var $orig_order_date;
-       
+
        var $ship_via;
        var $freight_cost;
-       
+
        var $tax_group_id;
        var $tax_group_name;
 
+       var $lines_on_order;
+
        function Cart()
        {
                /*Constructor function initialises a new shopping cart */
                $this->line_items = array();
                $this->default_sales_type = "";
                $this->direct_invoice=false;
+               $this->lines_on_order = 0;
        }
 
-       function add_to_cart($stock_id, $qty, $price, $disc, $qty_invoiced=0, $standard_cost=0, $description=null)
+       function add_to_cart($line_no, $id, $stock_id, $qty, $price, $disc, $qty_invoiced=0, $standard_cost=0, $description=null)
        {
 
                if (isset($stock_id) && $stock_id != "" && isset($qty) && $qty > 0)
                {
 
-                       $this->line_items[$stock_id] = new line_details($stock_id, $qty, $price, $disc, 
+                       $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++;
                        return 1;
-               } 
-               else 
+               }
+               else
                {
                        // shouldn't come here under normal circumstances
                        display_db_error("unexpected - adding an invalid item or null quantity", "", true);
@@ -75,98 +79,89 @@ class cart
                return 0;
        }
 
-       function find_cart_item($stock_id) 
-       {
-               if (isset($this->line_items[$stock_id]) && $this->line_items[$stock_id] != null)
-                       return $this->line_items[$stock_id];
-               return null;
-       }
-       
-       function update_cart_item($update_item, $qty, $price, $disc)
+       function update_cart_item($line_no, $qty, $price, $disc)
        {
 
                if ($qty > 0)
                {
-                       $this->line_items[$update_item]->quantity = $qty;
+                       $this->line_items[$line_no]->quantity = $qty;
                }
-               $this->line_items[$update_item]->price = $price;
-               $this->line_items[$update_item]->discount_percent = $disc;
+               $this->line_items[$line_no]->price = $price;
+               $this->line_items[$line_no]->discount_percent = $disc;
        }
-       
-       function update_add_cart_item_qty($update_item, $qty)
+
+       function update_add_cart_item_qty($line_no, $qty)
        {
-               $this->line_items[$update_item]->quantity += $qty;
-       }       
+               $this->line_items[$line_no]->quantity += $qty;
+       }
 
-       function remove_from_cart(&$stock_id)
+       function remove_from_cart($line_no)
        {
-               if (isset($stock_id))
-               {
-                       unset($this->line_items[$stock_id]);
-               }
+               $this->line_items[$line_no]->Deleted = true;
        }
-       
-       function clear_items() 
+
+       function clear_items()
        {
        unset($this->line_items);
                $this->line_items = array();
                $this->default_sales_type = "";
                $this->customer_id = $this->order_no = 0;
+               $this->lines_on_order = 0;
        }
-       
-       function count_items() 
+
+       function count_items()
        {
                return count($this->line_items);
        }
-       
+
        function get_items_total_dispatch($tax_group_id=null)
        {
                $total = 0;
-               
+
                // preload the taxgroup !
                if ($tax_group_id != null)
                        $tax_group_array = get_tax_group_items_as_array($tax_group_id);
-               else            
+               else
                        $tax_group_array = null;
-               
-               foreach ($this->line_items as $ln_itm) 
+
+               foreach ($this->line_items as $ln_itm)
                {
-                       $total += ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));                        
-               }               
+                       $total += ($ln_itm->qty_dispatched * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
+               }
                return $total;
        }
-       
+
        function has_items_dispatch()
        {
-               foreach ($this->line_items as $ln_itm) 
+               foreach ($this->line_items as $ln_itm)
                {
                        if ($ln_itm->qty_dispatched > 0)
-                               return true;                    
-               }               
+                               return true;
+               }
                return false;
        }
-       
+
        function get_items_total($tax_group_id=null)
        {
                $total = 0;
-               
+
                // preload the taxgroup !
                if ($tax_group_id != null)
                        $tax_group_array = get_tax_group_items_as_array($tax_group_id);
-               else            
-                       $tax_group_array = null;                
-               
+               else
+                       $tax_group_array = null;
+
                foreach ($this->line_items as $ln_itm) {
-                       $total += ($ln_itm->quantity * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));                                              
-               }               
+                       $total += ($ln_itm->quantity * $ln_itm->taxfree_price($tax_group_id, $tax_group_array) * (1 - $ln_itm->discount_percent));
+               }
                return $total;
-       }       
+       }
 
        function any_already_delivered()
        {
                /* Checks if there have been deliveries of line items */
 
-               foreach ($this->line_items as $stock_item) 
+               foreach ($this->line_items as $stock_item)
                {
                        if ($stock_item->qty_inv !=0)
                        {
@@ -178,74 +173,83 @@ class cart
 
        }
 
-       function some_already_delivered($stock_id)
+       function some_already_delivered($line_no)
        {
                /* Checks if there have been deliveries of a specific line item */
-               if (isset($stock_id) && isset($this->line_items[$stock_id]) && 
-                       $this->line_items[$stock_id]->qty_inv != 0)
+               if (isset($this->line_items[$line_no]) &&
+                       $this->line_items[$line_no]->qty_inv != 0)
                {
                        return 1;
                }
                return 0;
        }
-       
+
     function get_taxes($tax_group_id=null, $shipping_cost=0)
     {
        $items = array();
        $prices = array();
-       
+
         if ($tax_group_id == null)
                $tax_group_id = $this->tax_group_id;
-               
+
                // preload the taxgroup !
                $tax_group_array = get_tax_group_items_as_array($tax_group_id);
-       
-        foreach ($this->line_items as $ln_itm) 
+
+        foreach ($this->line_items as $ln_itm)
         {
-               $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));
+               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));
+               }
         }
-               
+
 
         $taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id, $tax_group_array);
-        
+
         return $taxes;
-    }  
-       
+    }
+
 } /* end of class defintion */
 
-class line_details 
+class line_details
 {
+       var $line_no;
+       var $id;
        var $stock_id;
        var $item_description;
        var $units;
        var $mb_flag;
        var $tax_type;
        var $tax_type_name;
-                       
+
        var $quantity;
        var $price;
        var $discount_percent;
        var $qty_inv;
        var $qty_dispatched;
        var $standard_cost;
+       var $Deleted;
 
-       function line_details ($stock_id, $qty, $prc, $disc_percent,  
+       function line_details ($line_no, $id, $stock_id, $qty, $prc, $disc_percent,
                $qty_invoiced, $standard_cost, $description)
        {
        /* 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);
-               
+
                if ($item_row == null)
                        display_db_error("invalid item added to order : $stock_id", "");
-               
+
                $this->mb_flag = $item_row["mb_flag"];
                $this->units = $item_row["units"];
                if ($description == null)
                        $this->item_description = $item_row["description"];
                else
                        $this->item_description = $description;
-               //$this->standard_cost = $item_row["material_cost"] + $item_row["labour_cost"] + $item_row["overhead_cost"]; 
+               //$this->standard_cost = $item_row["material_cost"] + $item_row["labour_cost"] + $item_row["overhead_cost"];
                $this->tax_type = $item_row["tax_type_id"];
                $this->tax_type_name = $item_row["tax_type_name"];
 
@@ -256,13 +260,14 @@ class line_details
                $this->qty_inv = $qty_invoiced;
                $this->qty_dispatched = $qty - $qty_invoiced;
                $this->standard_cost = $standard_cost;
+               $this->Deleted = false;
        }
-       
+
        function full_price()
        {
                return $this->price;
        }
-       
+
        function taxfree_price($tax_group_id, $tax_group_array=null)
        {
                if ($tax_group_id==null)
index be04db16fb9d94eaa0d81683e75eafd107c838e1..b0f7a90a399704552fc2172fa7062b01a5e83c24 100644 (file)
@@ -2,26 +2,27 @@
 
 //----------------------------------------------------------------------------------------
 
-function add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description, $quantity, 
+function add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description, $quantity,
        $unit_price, $unit_tax, $discount_percent, $standard_cost)
 {
        $sql = "INSERT INTO ".TB_PREF."debtor_trans_details (debtor_trans_no, debtor_trans_type, stock_id, description, quantity, unit_price, unit_tax, discount_percent, standard_cost)
                VALUES ($debtor_trans_no, $debtor_trans_type, '$stock_id', '$description', $quantity, $unit_price, $unit_tax, $discount_percent, $standard_cost)";
-                       
-       db_query($sql, "The debtor transaction detail could not be added");                     
+
+       db_query($sql, "The debtor transaction detail could not be added");
 }
 
 //----------------------------------------------------------------------------------------
 
 function get_customer_trans_details($debtor_trans_type, $debtor_trans_no)
 {
-       $sql = "SELECT ".TB_PREF."debtor_trans_details.*, ".TB_PREF."debtor_trans_details.unit_price+".TB_PREF."debtor_trans_details.unit_tax AS FullUnitPrice, 
+       $sql = "SELECT ".TB_PREF."debtor_trans_details.*, ".TB_PREF."debtor_trans_details.unit_price+".TB_PREF."debtor_trans_details.unit_tax AS FullUnitPrice,
                ".TB_PREF."debtor_trans_details.description As StockDescription,
-               ".TB_PREF."stock_master.units 
-               FROM ".TB_PREF."debtor_trans_details,".TB_PREF."stock_master 
+               ".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 ".TB_PREF."stock_master.stock_id=".TB_PREF."debtor_trans_details.stock_id";
+               AND debtor_trans_type=$debtor_trans_type
+               AND ".TB_PREF."stock_master.stock_id=".TB_PREF."debtor_trans_details.stock_id
+               ORDER BY id";
 
        return db_query($sql, "The debtor transaction detail could not be queried");
 }
@@ -30,59 +31,59 @@ function get_customer_trans_details($debtor_trans_type, $debtor_trans_no)
 
 function void_customer_trans_details($type, $type_no)
 {
-       $sql = "UPDATE ".TB_PREF."debtor_trans_details SET quantity=0, unit_price=0, 
+       $sql = "UPDATE ".TB_PREF."debtor_trans_details SET quantity=0, unit_price=0,
                unit_tax=0, discount_percent=0, standard_cost=0
                WHERE debtor_trans_no=$type_no
                AND debtor_trans_type=$type";
-                               
+
        db_query($sql, "The debtor transaction details could not be voided");
-                               
+
        // clear the stock move items
-       void_stock_move($type, $type_no);       
+       void_stock_move($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, 
+       $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
        $reference,     $std_cost)
 {
-       add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description, 
+       add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
                $quantity, $unit_price, $unit_tax, $discount_percent, $std_cost);
-       
+
        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);
-       
+
        return $std_cost;
 }
 
 //----------------------------------------------------------------------------------------
 
 function add_customer_trans_detail_item_writeoff($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
-       $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent, 
+       $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
        $reference, $std_cost)
 {
        $retCost = add_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
-               $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent, 
+               $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent,
                $reference,     $std_cost);
-                                                                                                                       
+
        $reference = _("Write off") . " " . $reference;
 
        add_stock_move_customer($debtor_trans_type, $stock_id, $debtor_trans_no, $Location,
                $date_, $reference, -$quantity, $std_cost, 0, $unit_price+$unit_tax, $discount_percent);
-                                       
-       return $retCost;                                                                                                                                
-}                                                                                                                      
+
+       return $retCost;
+}
 
 //----------------------------------------------------------------------------------------
 
-function add_customer_trans_tax_detail_item($debtor_trans_type, $debtor_trans_no,  
+function add_customer_trans_tax_detail_item($debtor_trans_type, $debtor_trans_no,
        $tax_type_id, $rate, $included_in_price, $amount)
 {
        $sql = "INSERT INTO ".TB_PREF."debtor_trans_tax_details (debtor_trans_no, debtor_trans_type, tax_type_id, rate, included_in_price, amount)
                VALUES ($debtor_trans_no, $debtor_trans_type, $tax_type_id, $rate, $included_in_price, $amount)";
-                       
-       db_query($sql, "The debtor transaction tax detail could not be added"); 
+
+       db_query($sql, "The debtor transaction tax detail could not be added");
 }
 
 //----------------------------------------------------------------------------------------
@@ -90,9 +91,9 @@ function add_customer_trans_tax_detail_item($debtor_trans_type, $debtor_trans_no
 function get_customer_trans_tax_details($debtor_trans_type, $debtor_trans_no)
 {
        $sql = "SELECT ".TB_PREF."debtor_trans_tax_details.*, ".TB_PREF."tax_types.name AS tax_type_name
-               FROM ".TB_PREF."debtor_trans_tax_details,".TB_PREF."tax_types 
+               FROM ".TB_PREF."debtor_trans_tax_details,".TB_PREF."tax_types
                WHERE debtor_trans_no=$debtor_trans_no
-               AND debtor_trans_type=$debtor_trans_type 
+               AND debtor_trans_type=$debtor_trans_type
                AND ".TB_PREF."tax_types.id = ".TB_PREF."debtor_trans_tax_details.tax_type_id";
 
        return db_query($sql, "The debtor transaction tax details could not be queried");
@@ -105,7 +106,7 @@ function void_customer_trans_tax_details($type, $type_no)
        $sql = "UPDATE ".TB_PREF."debtor_trans_tax_details SET amount=0
                WHERE debtor_trans_no=$type_no
                AND debtor_trans_type=$type";
-                               
+
        db_query($sql, "The debtor transaction tax details could not be voided");
 }
 
index b77736d6fc073b0d9f429eb0a87a28c4980daadc..84d5fb6871061cb172ecd59d6f0542d6a69b92df 100644 (file)
@@ -2,25 +2,25 @@
 
 //----------------------------------------------------------------------------------------
 
-function add_credit_note($credit_items, $credit_date, $credit_type, $tax_group_id, 
+function add_credit_note($credit_items, $credit_date, $credit_type, $tax_group_id,
        $charge_freight, $sales_type, $shipper, $reference, $memo_, $write_off_gl_code)
 {
        begin_transaction();
-       
+
        $branch_data = get_branch_accounts($credit_items->Branch);
 
        $credit_items_total = $credit_items->get_items_total($tax_group_id);
-       
+
     $tax_total = 0;
     $taxes = $credit_items->get_taxes($tax_group_id, $charge_freight);
     foreach ($taxes as $taxitem)
-       $tax_total +=  $taxitem['Value'];               
-       
-       $credit_no = add_customer_trans(11, $credit_items->customer_id, $credit_items->Branch, 
-       $credit_date, $reference, -($credit_items_total), 0, -$tax_total, -$charge_freight, 
-       $sales_type, 0, $credit_items->ship_via);       
+       $tax_total +=  $taxitem['Value'];
+
+       $credit_no = add_customer_trans(11, $credit_items->customer_id, $credit_items->Branch,
+       $credit_date, $reference, -($credit_items_total), 0, -$tax_total, -$charge_freight,
+       $sales_type, 0, $credit_items->ship_via);
 
-       foreach ($credit_items->line_items as $credit_line) 
+       foreach ($credit_items->line_items as $credit_line)
        {
 
                if ($credit_line->quantity > 0)
@@ -28,54 +28,54 @@ function add_credit_note($credit_items, $credit_date, $credit_type, $tax_group_i
                        // the functions use qty_dispatched - so until that's fixed make sure it's set
                        // or KABOOOOM
                        $credit_line->qty_dispatched = $credit_line->quantity;
-                       
-                       add_gl_trans_credit_order_item($credit_items, $credit_line, $credit_no, $credit_date, 
+
+                       add_gl_trans_credit_order_item($credit_items, $credit_line, $credit_no, $credit_date,
                        $tax_group_id, $credit_type);
 
-               add_gl_trans_credit_costs($credit_items, $credit_line, $credit_no, $credit_date, 
+               add_gl_trans_credit_costs($credit_items, $credit_line, $credit_no, $credit_date,
                        $tax_group_id, $credit_type, $write_off_gl_code, $branch_data);
 
                  } /*quantity credited is more than 0 */
         } /*end of credit_line loop */
-        
-       /*Post credit note transaction to GL credit debtors, 
+
+       /*Post credit note transaction to GL credit debtors,
        debit freight re-charged and debit sales */
-       
+
        add_g_trans_credit_common($credit_items, $credit_no, $credit_date,
-               $credit_items_total, $charge_freight, $taxes, $tax_total, $branch_data);        
-                       
-       add_comments(11, $credit_no, $credit_date, $memo_); 
-       
-       add_forms_for_sys_type(11, $credit_no, $credit_items->Location);                
-       
-       references::save_last($reference, 11);          
-       
-       commit_transaction();   
-       
+               $credit_items_total, $charge_freight, $taxes, $tax_total, $branch_data);
+
+       add_comments(11, $credit_no, $credit_date, $memo_);
+
+       add_forms_for_sys_type(11, $credit_no, $credit_items->Location);
+
+       references::save_last($reference, 11);
+
+       commit_transaction();
+
        return $credit_no;
 }
 
 //----------------------------------------------------------------------------------------
 
-function credit_invoice($credit_items, $invoice_no, $order_no, 
-       $default_dispatch_date, $credit_type, $tax_group_id, 
+function credit_invoice($credit_items, $invoice_no, $order_no,
+       $default_dispatch_date, $credit_type, $tax_group_id,
        $charge_freight, $reference, $memo_, $write_off_gl_code)
 {
        begin_transaction();
-       
-       $branch_data = get_branch_accounts($credit_items->Branch);      
-       
+
+       $branch_data = get_branch_accounts($credit_items->Branch);
+
        $invoice_alloc_balance = get_DebtorTrans_allocation_balance(10, $invoice_no);
 
        $invoice_items_total = $credit_items->get_items_total_dispatch($tax_group_id);
-       
+
     $tax_total = 0;
     $taxes = $credit_items->get_taxes($tax_group_id, $charge_freight);
     foreach ($taxes as $taxitem)
        $tax_total +=  $taxitem['Value'];
-       
-       $allocate_amount = 0;                   
-       
+
+       $allocate_amount = 0;
+
        if ($invoice_alloc_balance > 0)
        {       /*the invoice is not already fully allocated */
 
@@ -83,8 +83,8 @@ function credit_invoice($credit_items, $invoice_no, $order_no,
                {
 
                        $allocate_amount = $invoice_items_total + $charge_freight + $tax_total;
-               } 
-               else 
+               }
+               else
                {       /*the balance left to allocate is less than the credit note value */
                        $allocate_amount = $invoice_alloc_balance;
                }
@@ -94,201 +94,201 @@ function credit_invoice($credit_items, $invoice_no, $order_no,
 
        /*Now insert the Credit Note into the debtor_trans table with the allocations as calculated above*/
        // all amounts in debtor's currency
-       
-       $credit_no = add_customer_trans(11, $credit_items->customer_id, $credit_items->Branch, 
-       $default_dispatch_date, $reference,     -($invoice_items_total), 0, -$tax_total, 
-       -$charge_freight, $credit_items->default_sales_type,    $order_no,       
+
+       $credit_no = add_customer_trans(11, $credit_items->customer_id, $credit_items->Branch,
+       $default_dispatch_date, $reference,     -($invoice_items_total), 0, -$tax_total,
+       -$charge_freight, $credit_items->default_sales_type,    $order_no,
        $credit_items->ship_via, "", $allocate_amount);
-       
+
        /*Now insert the allocation record if > 0 */
        if ($allocate_amount != 0)
        {
                add_cust_allocation($allocate_amount, 11, $credit_no, 10, $invoice_no);
        }
-       
+
        /* Update sales order details quantity invoiced less this credit quantity. */
-       foreach ($credit_items->line_items as $order_line) 
+       foreach ($credit_items->line_items as $order_line)
        {
 
                if ($order_line->qty_dispatched >0)
                {
-                       
+
                        // always deduct the credited/returned quantities from the sales order
-                       dispatch_sales_order_item($order_no, $order_line->stock_id, -$order_line->qty_dispatched);
-                       
+                       dispatch_sales_order_item($order_no, $order_line->id, -$order_line->qty_dispatched);
+
                        //if (($_POST['credit_type']=="Return") OR ($_POST['ItemsAction']==1))
                        /*{
-                               $sql = "UPDATE ".TB_PREF."sales_order_details 
+                               $sql = "UPDATE ".TB_PREF."sales_order_details
                                                        SET qty_invoiced = qty_invoiced - " . $order_line->qty_dispatched . "
-                                               WHERE order_no = " . $order_no . " 
-                                               AND stk_code = '" . $order_line->stock_id . "'";
+                                               WHERE order_no = " . $order_no . "
+                                               AND id = '" . $order_line->id . "'";
                                $result = db_query($sql,"The sales order detail record could not be updated for the reduced quantity invoiced");
-                       }*/                     
-                       
+                       }*/
+
                        /*Now update sales_order_details for the quantity invoiced and the actual dispatch dates. */
-                       
-                       add_gl_trans_credit_order_item($credit_items, $order_line, $credit_no, 
+
+                       add_gl_trans_credit_order_item($credit_items, $order_line, $credit_no,
                                $default_dispatch_date, $tax_group_id, $credit_type, $invoice_no);
-                       
-               add_gl_trans_credit_costs($credit_items, $order_line, $credit_no, $default_dispatch_date, 
+
+               add_gl_trans_credit_costs($credit_items, $order_line, $credit_no, $default_dispatch_date,
                        $tax_group_id, $credit_type, $write_off_gl_code, $branch_data);
 
                } /*quantity dispatched is more than 0 */
        } /*end of order_line loop */
-       
+
        add_g_trans_credit_common($credit_items, $credit_no, $default_dispatch_date,
                $invoice_items_total, $charge_freight, $taxes, $tax_total, $branch_data);
-                       
-       add_comments(11, $credit_no, $default_dispatch_date, $memo_); 
-       
+
+       add_comments(11, $credit_no, $default_dispatch_date, $memo_);
+
        add_forms_for_sys_type(11, $credit_no);
-       
-       references::save_last($reference, 11);                                  
+
+       references::save_last($reference, 11);
 
        commit_transaction();
-       
+
        return $credit_no;
 }
 
 //----------------------------------------------------------------------------------------
 
-function add_gl_trans_credit_order_item(&$order, &$order_line, $credit_no, $date_, $tax_group_id, 
+function add_gl_trans_credit_order_item(&$order, &$order_line, $credit_no, $date_, $tax_group_id,
        $credit_type, $credited_invoice=0)
 {
        $line_taxfree_price = $order_line->taxfree_price($tax_group_id);
        $line_tax = $order_line->full_price() - $line_taxfree_price;
-                       
+
        if ($credit_type == "Return")
        {
 
                /* Insert stock movements for the stock coming back in - with unit cost */
-               
+
                $reference = "";
                if ($credited_invoice)
                        $reference .= "Ex Inv: " . $credited_invoice;
-                       
-               add_customer_trans_detail_item(11, $credit_no, $order_line->stock_id, 
-                       $order_line->item_description, $order->Location, $date_, 
+
+               add_customer_trans_detail_item(11, $credit_no, $order_line->stock_id,
+                       $order_line->item_description, $order->Location, $date_,
                        $order_line->qty_dispatched, $line_taxfree_price, $line_tax,
-                       $order_line->discount_percent, $reference, $order_line->standard_cost); 
+                       $order_line->discount_percent, $reference, $order_line->standard_cost);
 
-       }  
-       elseif ($credit_type == "WriteOff") 
+       }
+       elseif ($credit_type == "WriteOff")
        {
           /*Insert a stock movement coming back in to show the credit note and
                a reversing stock movement to show the write off
                no mods to location stock records*/
-               
+
           $reference = "";
           if ($credited_invoice)
                        $reference .= "Ex Inv: " . $credited_invoice;
-          
+
                add_customer_trans_detail_item_writeoff(11, $credit_no, $order_line->stock_id,
-                       $order_line->item_description, $order->Location, $date_, 
+                       $order_line->item_description, $order->Location, $date_,
                        $order_line->qty_dispatched, $line_taxfree_price, $line_tax,
-                       $order_line->discount_percent, $reference, $order_line->standard_cost); 
-       }       
+                       $order_line->discount_percent, $reference, $order_line->standard_cost);
+       }
 }
 
 //----------------------------------------------------------------------------------------
 
-function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, $tax_group_id, 
+function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, $tax_group_id,
        $credit_type, $write_off_gl_code, &$branch_data)
 {
-       $stock_gl_codes = get_stock_gl_code($order_line->stock_id);     
-       
+       $stock_gl_codes = 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(11, $credit_no, $date_, $stock_gl_codes["cogs_account"], 
-                       $stock_gl_codes["dimension_id"], $stock_gl_codes["dimension2_id"], "", 
-                       -($order_line->standard_cost * $order_line->qty_dispatched), 
-                       payment_person_types::customer(), $order->customer_id, 
-                       "The cost of sales GL posting could not be inserted"); 
-               
+               add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
+                       $stock_gl_codes["dimension_id"], $stock_gl_codes["dimension2_id"], "",
+                       -($order_line->standard_cost * $order_line->qty_dispatched),
+                       payment_person_types::customer(), $order->customer_id,
+                       "The cost of sales GL posting could not be inserted");
+
                /*now the stock entry*/
                if ($credit_type == "WriteOff")
                {
                        $stock_entry_account = $write_off_gl_code;
-               } 
-               else 
+               }
+               else
                {
-                       $stock_gl_code = get_stock_gl_code($order_line->stock_id);                                      
+                       $stock_gl_code = get_stock_gl_code($order_line->stock_id);
                        $stock_entry_account = $stock_gl_code["inventory_account"];
                }
-               
+
                add_gl_trans_std_cost(11, $credit_no, $date_, $stock_entry_account, 0, 0,
-                       "", ($order_line->standard_cost * $order_line->qty_dispatched), 
-                       payment_person_types::customer(), $order->customer_id, 
+                       "", ($order_line->standard_cost * $order_line->qty_dispatched),
+                       payment_person_types::customer(), $order->customer_id,
                        "The stock side (or write off) of the cost of sales GL posting could not be inserted");
-               
-       } /* end of if GL and stock integrated and standard cost !=0 */ 
-       
+
+       } /* end of if GL and stock integrated and standard cost !=0 */
+
        if ($order_line->price != 0)
        {
-               
+
        $line_taxfree_price = $order_line->taxfree_price($tax_group_id);
-               $line_tax = $order_line->full_price() - $line_taxfree_price;            
+               $line_tax = $order_line->full_price() - $line_taxfree_price;
 
                //Post sales transaction to GL credit sales
-               
+
                add_gl_trans_customer(11, $credit_no, $date_, $stock_gl_codes["sales_account"], 0, 0,
-                       ($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id, 
+                       ($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id,
                        "The credit note GL posting could not be inserted");
 
                if ($order_line->discount_percent != 0)
                {
-                       
+
                        add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"], 0, 0,
-                               -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent), 
-                               $order->customer_id, 
-                               "The credit note discount GL posting could not be inserted");                           
+                               -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent),
+                               $order->customer_id,
+                               "The credit note discount GL posting could not be inserted");
 
                } /*end of if discount !=0 */
-       } /*end of if sales integrated with debtors */          
+       } /*end of if sales integrated with debtors */
 }
 
 //----------------------------------------------------------------------------------------
 
-function add_g_trans_credit_common($order, $credit_no, $date_, 
+function add_g_trans_credit_common($order, $credit_no, $date_,
        $credit_items_total, $freight, $taxes, $tax_total, &$branch_data)
 {
        $company_data = get_company_prefs();
-               
-       /*Post credit note transaction to GL credit debtors, 
+
+       /*Post credit note transaction to GL credit debtors,
        debit freight re-charged and debit sales */
-       
-       if (($credit_items_total + $freight + $tax_total) != 0) 
+
+       if (($credit_items_total + $freight + $tax_total) != 0)
        {
-               
+
                add_gl_trans_customer(11, $credit_no, $date_, $branch_data["receivables_account"], 0, 0,
-                       -($credit_items_total + $freight + $tax_total), $order->customer_id, 
-                       "The total debtor GL posting for the credit note could not be inserted");                       
+                       -($credit_items_total + $freight + $tax_total), $order->customer_id,
+                       "The total debtor GL posting for the credit note could not be inserted");
        }
-       
-       if ($freight !=0) 
+
+       if ($freight !=0)
        {
                add_gl_trans_customer(11, $credit_no, $date_, $company_data["freight_act"], 0, 0,
-                       $freight, $order->customer_id, 
-                       "The freight GL posting for this credit note could not be inserted");                   
+                       $freight, $order->customer_id,
+                       "The freight GL posting for this credit note 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(11, $credit_no, $taxitem['tax_type_id'],
-                               $taxitem['rate'], $taxitem['included_in_price'], $taxitem['Value']);                    
-               
-               add_gl_trans_customer(11, $credit_no, $date_, $taxitem['sales_gl_code'], 0, 0, 
-                       $taxitem['Value'], $order->customer_id, 
-                       "A tax GL posting for this credit note could not be inserted");                                         
-       }       
-    }          
+                               $taxitem['rate'], $taxitem['included_in_price'], $taxitem['Value']);
+
+               add_gl_trans_customer(11, $credit_no, $date_, $taxitem['sales_gl_code'], 0, 0,
+                       $taxitem['Value'], $order->customer_id,
+                       "A tax GL posting for this credit note could not be inserted");
+       }
+    }
 }
 
 //----------------------------------------------------------------------------------------
index 617abd7f6c36f1e2d248e2c3395556435a1f5bbf..3fd2aa09d99f7044338893624e30c70352deb4ae 100644 (file)
@@ -1,72 +1,72 @@
 <?php
 
 // $bo_policy = 0, cancel remaining quantities on order
-// = 1, backorder remaining quantities 
+// = 1, backorder remaining quantities
 
-function add_sales_invoice(&$invoice, $date_, $due_date, $sales_order, $tax_group_id, 
+function add_sales_invoice(&$invoice, $date_, $due_date, $sales_order, $tax_group_id,
        $charge_shipping, $location, $ship_via, $sales_type, $reference, $memo_, $bo_policy)
 {
        begin_transaction();
-       
+
        $company_data = get_company_prefs();
-       
-       $branch_data = get_branch_accounts($invoice->Branch);   
-       
+
+       $branch_data = get_branch_accounts($invoice->Branch);
+
        $invoice_items_total = $invoice->get_items_total_dispatch($tax_group_id);
-       
+
     $tax_total = 0;
     $taxes = $invoice->get_taxes($tax_group_id, $charge_shipping);
     foreach ($taxes as $taxitem)
        $tax_total +=  $taxitem['Value'];
 
        /*Now insert the debtor_trans */
-       
-       $invoice_no = add_customer_trans(10, $invoice->customer_id, $invoice->Branch, $date_, 
-               $reference, $invoice_items_total, 0, $tax_total, $charge_shipping, 
+
+       $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);
-       
-       // If balance of the order cancelled update sales order details quantity. 
-       foreach ($invoice->line_items as $order_line) 
+
+       // If balance of the order cancelled update sales order details quantity.
+       foreach ($invoice->line_items as $order_line)
        {
 
-               if ($order_line->qty_dispatched != 0) 
+               if ($order_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->stock_id, 
+
+                       // Now update sales_order_details for the quantity invoiced
+                       dispatch_sales_order_item($sales_order, $order_line->id,
                                $order_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->item_description, $location, $date_,
                                -$order_line->qty_dispatched, $line_taxfree_price, $line_tax,
                                $order_line->discount_percent, $memo_, $order_line->standard_cost);
-                                                                                               
-                       $stock_gl_code = get_stock_gl_code($order_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, 
+                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");                                
+
+                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 */
 
@@ -74,20 +74,20 @@ function add_sales_invoice(&$invoice, $date_, $due_date, $sales_order, $tax_grou
                        {
 
                                //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), 
+
+                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_, 
-                                       $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 * $order_line->qty_dispatched * $order_line->discount_percent),
+                                       $invoice->customer_id, "The sales discount GL posting could not be inserted");
                                } /*end of if discount !=0 */
                        } /*end of if sales integrated with debtors */
 
@@ -102,43 +102,43 @@ function add_sales_invoice(&$invoice, $date_, $due_date, $sales_order, $tax_grou
        }
 
        /*Post debtors transaction to GL debit debtors, credit freight re-charged and credit sales */
-       if (($invoice_items_total + $charge_shipping + $tax_total) != 0) 
+       if (($invoice_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");                            
+                       ($invoice_items_total + $charge_shipping + $tax_total),
+                       $invoice->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), $invoice->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']), $invoice->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,36 +147,36 @@ 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) 
+
+       if ($order)
        {
                while ($row = db_fetch($items_result))
                {
-                       dispatch_sales_order_item($order, $row["stock_id"], $row["quantity"]);                  
+                       dispatch_sales_order_item($order, $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();
 }
 
 //--------------------------------------------------------------------------------------------------
index 4f75e6d08986373aeddbdd3afa0feac6b6bd51df..f12da11150f527124b01cb29ac9bb5038b247d3a 100644 (file)
@@ -78,41 +78,43 @@ function add_sales_order($order)
                $st_num = array();
                $st_reorder = array();
        }
-       foreach ($order->line_items as $stock_item)
+       foreach ($order->line_items as $line)
        {
-               if ($loc_notification == 1 && is_inventory_item($stock_item->stock_id))
+               if ($line->Deleted == false)
                {
-                       $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 = '" . $stock_item->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'] != "")
+                       if ($loc_notification == 1 && is_inventory_item($line->stock_id))
                        {
-                               $qoh = get_qoh_on_date($stock_item->stock_id, $order->Location);
-                               $qoh -= get_demand_qty($stock_item->stock_id, $order->Location);
-                               $qoh -= get_demand_asm_qty($stock_item->stock_id, $order->Location);
-                               $qoh -= $stock_item->quantity;
-                               if ($qoh < $loc['reorder_level'])
+                               $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'] != "")
                                {
-                                       $st_ids[] = $stock_item->stock_id;
-                                       $st_names[] = $stock_item->item_description;
-                                       $st_num[] = $qoh - $loc['reorder_level'];
-                                       $st_reorder[] = $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'];
+                                       }
                                }
                        }
-               }
-               $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code, description, unit_price, quantity, discount_percent) VALUES (";
-               $sql .= $order_no .
-                               ",'$stock_item->stock_id', '$stock_item->item_description', $stock_item->price,
-                               $stock_item->quantity,
-                               $stock_item->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();
@@ -191,41 +193,43 @@ function update_sales_order($order_no, $order)
                $st_num = array();
                $st_reorder = array();
        }
-       foreach ($order->line_items as $stock_item)
+       foreach ($order->line_items as $line)
        {
-               if ($loc_notification == 1 && is_inventory_item($stock_item->stock_id))
+               if ($line->Deleted == false)
                {
-                       $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 = '" . $stock_item->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'] != "")
+                       if ($loc_notification == 1 && is_inventory_item($line->stock_id))
                        {
-                               $qoh = get_qoh_on_date($stock_item->stock_id, $order->Location);
-                               $qoh -= get_demand_qty($stock_item->stock_id, $order->Location);
-                               $qoh -= get_demand_asm_qty($stock_item->stock_id, $order->Location);
-                               $qoh -= $stock_item->quantity;
-                               if ($qoh < $loc['reorder_level'])
+                               $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'] != "")
                                {
-                                       $st_ids[] = $stock_item->stock_id;
-                                       $st_names[] = $stock_item->item_description;
-                                       $st_num[] = $qoh - $loc['reorder_level'];
-                                       $st_reorder[] = $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'];
+                                       }
                                }
                        }
-               }
-
-               $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code,  description, unit_price, quantity, discount_percent, qty_invoiced) VALUES (";
 
-               $sql .= $order_no . ",'" . $stock_item->stock_id . "','" . $stock_item->item_description . "', " . $stock_item->price . ", " . $stock_item->quantity . ", " . $stock_item->discount_percent . ", " . $stock_item->qty_inv . " )";
+                       $sql = "INSERT INTO ".TB_PREF."sales_order_details (order_no, stk_code,  description, unit_price, quantity, discount_percent, qty_invoiced) VALUES (";
 
-               db_query($sql, "Old order Cannot be Inserted");
+                       $sql .= $order_no . ",'" . $line->stock_id . "','" . $line->item_description . "', " . $line->price . ", " . $line->quantity . ", " . $line->discount_percent . ", " . $line->qty_inv . " )";
 
-       } /* inserted line items into sales order details */
+                       db_query($sql, "Old order Cannot be Inserted");
 
+               } /* inserted line items into sales order details */
+       }
        commit_transaction();
        if ($loc_notification == 1 && count($st_ids) > 0)
        {
@@ -311,7 +315,7 @@ function read_sales_order($order_no, &$order, $skip_completed_items=false)
        $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, discount_percent,
+               ".TB_PREF."sales_order_details.quantity, ".TB_PREF."sales_order_details.id, discount_percent,
                qty_invoiced, ".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
@@ -321,6 +325,7 @@ function read_sales_order($order_no, &$order, $skip_completed_items=false)
        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";
 
        $result = db_query($sql, "Retreive order Line Items");
 
@@ -329,7 +334,7 @@ function read_sales_order($order_no, &$order, $skip_completed_items=false)
 
                while ($myrow = db_fetch($result))
                {
-                       $order->add_to_cart($myrow["stk_code"],$myrow["quantity"],
+                       $order->add_to_cart($order->lines_on_order+1, $myrow["id"], $myrow["stk_code"],$myrow["quantity"],
                                $myrow["unit_price"], $myrow["discount_percent"],
                                $myrow["qty_invoiced"], $myrow["standard_cost"], $myrow["description"]);
                }
@@ -365,12 +370,12 @@ function close_sales_order($order_no)
 
 //----------------------------------------------------------------------------------------
 
-function dispatch_sales_order_item($order_no, $stock_id, $qty_dispatched)
+function dispatch_sales_order_item($order_no, $id, $qty_dispatched)
 {
        $sql = "UPDATE ".TB_PREF."sales_order_details
                SET qty_invoiced = qty_invoiced + $qty_dispatched ";
        $sql .= " WHERE order_no = $order_no
-               AND stk_code = '$stock_id'";
+               AND id = $id";
 
        db_query($sql, "The sales order detail record could not be updated");
 }
index 555a9b3f8211f450d4ee0141307b7dbf8f673a03..7b7002291c11af3c9c1d3274ff6dc5d08ada8904 100644 (file)
@@ -18,7 +18,7 @@ function display_credit_header(&$order)
 
        customer_list_row(_("Customer:"), 'customer_id', null, false, true);
 
-       if ($order->customer_id != $_POST['customer_id']) 
+       if ($order->customer_id != $_POST['customer_id'])
        {
                // customer has changed
 
@@ -32,11 +32,11 @@ function display_credit_header(&$order)
 
        customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'branch_id', null, false, true, true);
 
-       //if (($_SESSION['Items']->order_no == 0) ||
-       //      ($order->customer_id != $_POST['customer_id']) || 
+       //if (($_SESSION['credit_items']->order_no == 0) ||
+       //      ($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']);
-       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']);
 
@@ -102,39 +102,39 @@ function display_credit_items($title, &$order)
        start_table("$table_style width=90%");
        $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),
                _("Price"), _("Discount %"), _("Total"));
-       table_header($th);      
+       table_header($th);
 
        $subtotal = 0;
        $k = 0;  //row colour counter
 
-       foreach ($order->line_items as $stock_item) 
+       foreach ($order->line_items as $line)
        {
 
-               $line_total =   $stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent);
+               $line_total =   $line->quantity * $line->price * (1 - $line->discount_percent);
 
-               if (!isset($_GET['Edit']) || $_GET['Edit'] != $stock_item->stock_id)
+               if (!isset($_GET['Edit']) || $_GET['Edit'] != $line->line_no)
                {
                alt_table_row_color($k);
 
-               label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $stock_item->stock_id . "'>$stock_item->stock_id</a>");
-               label_cell($stock_item->item_description);
-               qty_cell($stock_item->quantity);
-               label_cell($stock_item->units);
-               amount_cell($stock_item->price);
+               label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $line->stock_id . "'>$line->stock_id</a>");
+               label_cell($line->item_description);
+               qty_cell($line->quantity);
+               label_cell($line->units);
+               amount_cell($line->price);
 
-                       amount_cell($stock_item->discount_percent * 100);
+                       amount_cell($line->discount_percent * 100);
                amount_cell($line_total);
 
-               edit_link_cell(SID . "Edit=$stock_item->stock_id");
-               delete_link_cell(SID . "Delete=$stock_item->stock_id");
+               edit_link_cell(SID . "Edit=$line->line_no");
+               delete_link_cell(SID . "Delete=$line->line_no");
 
-                       //labelt_cell(get_tax_free_price_for_item($stock_item->stock_id, $line_total, $_POST['tax_group_id']));
+                       //labelt_cell(get_tax_free_price_for_item($line->stock_id, $line_total, $_POST['tax_group_id']));
 
                end_row();
-               } 
-               else 
+               }
+               else
                {
-                       credit_edit_item_controls($order, $stock_item->stock_id);
+                       credit_edit_item_controls($order, $line->stock_id);
                }
 
                $subtotal += $line_total;
@@ -169,23 +169,27 @@ function credit_edit_item_controls(&$order, $stock_id=null)
 
        if (isset($_GET['Edit']) and $stock_id!=null)
        {
+               $line_no = $_GET['Edit'];
+               hidden('line_no', $line_no);
+
                if (!isset($_POST['stock_id']))
-                       $_POST['stock_id'] = $order->line_items[$stock_id]->stock_id;
+                       $_POST['stock_id'] = $order->line_items[$line_no]->stock_id;
                if (!isset($_POST['qty']) OR ($_POST['qty']==""))
-                       $_POST['qty'] = $order->line_items[$stock_id]->quantity;
+                       $_POST['qty'] = $order->line_items[$line_no]->quantity;
                if (!isset($_POST['price']) OR ($_POST['price']==""))
-                       $_POST['price'] = $order->line_items[$stock_id]->price;
+                       $_POST['price'] = $order->line_items[$line_no]->price;
                if (!isset($_POST['Disc']) OR ($_POST['Disc']==""))
-                       $_POST['Disc'] = ($order->line_items[$stock_id]->discount_percent)*100;
+                       $_POST['Disc'] = ($order->line_items[$line_no]->discount_percent)*100;
 
-               $_POST['units'] = $order->line_items[$stock_id]->units;
+               $_POST['units'] = $order->line_items[$line_no]->units;
 
                hidden('stock_id', $_POST['stock_id']);
                label_cell($_POST['stock_id']);
-               label_cell($order->line_items[$stock_id]->item_description);
+               label_cell($order->line_items[$line_no]->item_description);
        }
        else
        {
+               hidden('line_no', ($_SESSION['credit_items']->lines_on_order + 1));
        echo "<td colspan=2>";
        stock_items_list('stock_id', null, false, true);
        echo "</td>";
@@ -207,12 +211,12 @@ function credit_edit_item_controls(&$order, $stock_id=null)
        text_cells(null, 'Disc', $_POST['Disc'], 7, 5);
        amount_cell($_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc']/100));
 
-       if (isset($_GET['Edit'])) 
+       if (isset($_GET['Edit']))
        {
        submit_cells('UpdateItem', _("Update"));
        submit_cells('CancelItemChanges', _("Cancel"));
-       } 
-       else 
+       }
+       else
        {
                submit_cells('AddItem', _("Add Item"), "colspan=2");
        }
@@ -239,8 +243,8 @@ function credit_options_controls()
                        $_POST['Location'] = $_SESSION['credit_items']->Location;
                locations_list_row(_("Items Returned to Location"), 'Location', $_POST['Location']);
 
-       } 
-       else 
+       }
+       else
        {
                /* the goods are to be written off to somewhere */
                gl_all_accounts_list_row(_("Write off the cost of the items to"), 'WriteOffGLCode', null);
index ea0c819dc7ea76e5f2d5f37b980f7c2d37ffd77b..4a5dee024277a90d1ee1dd06c489b46b8d20a75e 100644 (file)
@@ -5,8 +5,9 @@ include_once($path_to_root . "/includes/manufacturing.inc");
 
 //--------------------------------------------------------------------------------
 
-function add_to_order(&$order, $new_item, $new_item_qty, $price, $discount)
+function add_to_order(&$order, $line_no, $new_item, $new_item_qty, $price, $discount)
 {
+/*
     $already_on_order = 0;
 
        foreach ($order->line_items AS $order_item)
@@ -21,8 +22,8 @@ function add_to_order(&$order, $new_item, $new_item_qty, $price, $discount)
 
     if ($already_on_order != 1)
     {
-         $order->add_to_cart ($new_item, $new_item_qty, $price, $discount);
-    } /* end of if not already on the order */
+*/
+    $order->add_to_cart ($line_no, 0, $new_item, $new_item_qty, $price, $discount);
 }
 
 //---------------------------------------------------------------------------------
@@ -113,42 +114,44 @@ function display_order_summary($title, &$order, $editable_items=false)
        $total = 0;
        $k = 0;  //row colour counter
 
-       foreach ($order->line_items as $stock_item)
+       foreach ($order->line_items as $line)
        {
-
-               $line_total = $stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent);
-
-               if (!isset($_GET['Edit']))
-                       $id = "";
-               else
-                       $id = $_GET['Edit'];
-               if (!$editable_items || $id != $stock_item->stock_id)
+               if ($line->Deleted == false)
                {
-               alt_table_row_color($k);
+                       $line_total = $line->quantity * $line->price * (1 - $line->discount_percent);
 
-                       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 (!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);
+                       }
 
-               if ($editable_items)
-               {
-                       edit_link_cell(SID . "Edit=$stock_item->stock_id");
-                       delete_link_cell(SID . "Delete=$stock_item->stock_id");
-               }
-               end_row();
-               }
-               else
-               {
-                       sales_order_item_controls($order, $stock_item->stock_id);
+                       $total += $line_total;
                }
-
-               $total += $line_total;
        }
 
        if (!isset($_GET['Edit']) && $editable_items)
@@ -284,24 +287,28 @@ function sales_order_item_controls(&$order, $stock_id=null)
 
        if (isset($_GET['Edit']) && $stock_id != null)
        {
+               $line_no = $_GET['Edit'];
+               hidden('line_no', $line_no);
+
                if (!isset($_POST['stock_id']))
-                       $_POST['stock_id'] = $order->line_items[$_GET['Edit']]->stock_id;
+                       $_POST['stock_id'] = $order->line_items[$line_no]->stock_id;
                if (!isset($_POST['qty']) || ($_POST['qty'] == ""))
-                       $_POST['qty'] = $order->line_items[$_GET['Edit']]->quantity;
+                       $_POST['qty'] = $order->line_items[$line_no]->quantity;
                if (!isset($_POST['price']) || ($_POST['price'] == ""))
-                       $_POST['price'] = $order->line_items[$_GET['Edit']]->price;
+                       $_POST['price'] = $order->line_items[$line_no]->price;
                if (!isset($_POST['Disc']) || ($_POST['Disc'] == ""))
-                       $_POST['Disc'] = ($order->line_items[$_GET['Edit']]->discount_percent)*100;
+                       $_POST['Disc'] = ($order->line_items[$line_no]->discount_percent)*100;
 
-               $_POST['units'] = $order->line_items[$_GET['Edit']]->units;
+               $_POST['units'] = $order->line_items[$line_no]->units;
 
                hidden('stock_id', $_POST['stock_id']);
                label_cell($_POST['stock_id']);
-               label_cell($order->line_items[$stock_id]->item_description);
+               label_cell($order->line_items[$line_no]->item_description);
        }
        else
        {
-               global $no_item_list;
+               hidden('line_no', ($_SESSION['Items']->lines_on_order + 1));
+               $no_item_list = get_company_pref('no_item_list');
                if ($no_item_list)
                {
                        echo "<td colspan=2>\n";
index 4acd11494450594fd940e9b63bed97aab65ed039..b8bc94bc8ac1e19300a5f31d653dee291c57c682 100644 (file)
@@ -11,7 +11,7 @@ include($path_to_root . "/includes/ui.inc");
 if (isset($_GET['selected_id']))
 {
        $selected_id = strtoupper($_GET['selected_id']);
-} 
+}
 elseif (isset($_POST['selected_id']))
 {
        $selected_id = strtoupper($_POST['selected_id']);
@@ -19,44 +19,49 @@ elseif (isset($_POST['selected_id']))
 
 //------------------------------------------------------------------------------------------------
 
-if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
+if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
 {
 
        //initialise no input errors assumed initially before we test
        $input_error = 0;
 
-       if (strlen($_POST['salesman_name']) == 0) 
+       if (strlen($_POST['salesman_name']) == 0)
        {
                $input_error = 1;
                display_error(_("The sales person name cannot be empty."));
-       } 
+       }
 
        if ($input_error != 1)
        {
-       if (isset($selected_id)) 
+       if (isset($selected_id))
        {
                /*selected_id could also exist if submit had not been clicked this code would not run in this case cos submit is false of course  see the delete code below*/
-    
-               $sql = "UPDATE ".TB_PREF."salesman SET salesman_name='" . $_POST['salesman_name'] . "', 
-                       salesman_phone='" . $_POST['salesman_phone'] . "', 
+
+               $sql = "UPDATE ".TB_PREF."salesman SET salesman_name='" . $_POST['salesman_name'] . "',
+                       salesman_phone='" . $_POST['salesman_phone'] . "',
                        salesman_fax='" . $_POST['salesman_fax'] . "',
-                       salesman_email='" . $_POST['salesman_email'] . "'
+                       salesman_email='" . $_POST['salesman_email'] . "',
+                       provision=".$_POST['provision'].",
+                       break_pt=".$_POST['break_pt'].",
+                       provision2=".$_POST['provision2']."
                        WHERE salesman_code = '$selected_id'";
-       } 
-       else 
+       }
+       else
        {
                /*Selected group is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Sales-person form */
-               $sql = "INSERT INTO ".TB_PREF."salesman (salesman_name, salesman_phone, salesman_fax, salesman_email) 
-                       VALUES ('" . $_POST['salesman_name'] . "', '" . $_POST['salesman_phone'] . "', '" . $_POST['salesman_fax'] . "', '" . $_POST['salesman_email'] . "')";
+               $sql = "INSERT INTO ".TB_PREF."salesman (salesman_name, salesman_phone, salesman_fax, salesman_email,
+                       provision, break_pt, provision2)
+                       VALUES ('" . $_POST['salesman_name'] . "', '" . $_POST['salesman_phone'] . "', '" . $_POST['salesman_fax'] . "', '" . $_POST['salesman_email'] . "', ".
+                       $_POST['provision'].", ".$_POST['break_pt'].", ".$_POST['provision2'].")";
        }
 
        //run the sql from either of the above possibilites
        db_query($sql,"The insert or update of the salesperson failed");
-    
-               meta_forward($_SERVER['PHP_SELF']);             
+
+               meta_forward($_SERVER['PHP_SELF']);
        }
-} 
-if (isset($_GET['delete'])) 
+}
+if (isset($_GET['delete']))
 {
        //the link to delete a selected record was clicked instead of the submit button
 
@@ -65,45 +70,48 @@ if (isset($_GET['delete']))
        $sql= "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE salesman='$selected_id'";
        $result = db_query($sql,"check failed");
        $myrow = db_fetch_row($result);
-       if ($myrow[0] > 0) 
+       if ($myrow[0] > 0)
        {
                display_error("Cannot delete this sales-person because branches are set up referring to this sales-person - first alter the branches concerned.");
-       } 
-       else 
+       }
+       else
        {
                $sql="DELETE FROM ".TB_PREF."salesman WHERE salesman_code='$selected_id'";
                db_query($sql,"The sales-person could not be deleted");
 
-               meta_forward($_SERVER['PHP_SELF']);                     
+               meta_forward($_SERVER['PHP_SELF']);
        }
 }
 
-//------------------------------------------------------------------------------------------------ 
+//------------------------------------------------------------------------------------------------
 
 $sql = "SELECT * FROM ".TB_PREF."salesman";
 $result = db_query($sql,"could not get sales persons");
 
-start_table("$table_style width=40%");
-$th = array(_("Name"), _("Phone"), _("Fax"), _("Email"), "", "");
+start_table("$table_style width=60%");
+$th = array(_("Name"), _("Phone"), _("Fax"), _("Email"), _("Provision"), _("Break Pt."), _("Provision")." 2", "", "");
 table_header($th);
 
 $k = 0;
 
-while ($myrow = db_fetch($result)) 
+while ($myrow = db_fetch($result))
 {
-       
-       alt_table_row_color($k);                
-    
+
+       alt_table_row_color($k);
+
     label_cell($myrow["salesman_name"]);
        label_cell($myrow["salesman_phone"]);
        label_cell($myrow["salesman_fax"]);
        label_cell($myrow["salesman_email"]);
+       percent_cell($myrow["provision"]);
+       amount_cell($myrow["break_pt"]);
+       percent_cell($myrow["provision2"]);
        edit_link_cell(SID . "selected_id=" . $myrow["salesman_code"]);
        delete_link_cell(SID . "selected_id=" . $myrow["salesman_code"]. "&delete=1");
        end_row();
-    
+
 } //END WHILE LIST LOOP
+
 end_table();
 
 //------------------------------------------------------------------------------------------------
@@ -114,7 +122,7 @@ hyperlink_no_params($_SERVER['PHP_SELF'], _("New Sales Person"));
 
 start_form();
 
-if (isset($selected_id)) 
+if (isset($selected_id))
 {
        //editing an existing Sales-person
        $sql = "SELECT *  FROM ".TB_PREF."salesman WHERE salesman_code='$selected_id'";
@@ -126,17 +134,22 @@ if (isset($selected_id))
        $_POST['salesman_phone'] = $myrow["salesman_phone"];
        $_POST['salesman_fax'] = $myrow["salesman_fax"];
        $_POST['salesman_email'] = $myrow["salesman_email"];
+       $_POST['provision'] = $myrow["provision"];
+       $_POST['break_pt'] = $myrow["break_pt"];
+       $_POST['provision2'] = $myrow["provision2"];
 
        hidden('selected_id', $selected_id);
 }
 
-start_table("$table_style2 width=40%");
+start_table("$table_style2 width=60%");
 
 text_row_ex(_("Sales person name:"), 'salesman_name', 30);
 text_row_ex(_("Telephone number:"), 'salesman_phone', 20);
 text_row_ex(_("Fax number:"), 'salesman_fax', 20);
 text_row_ex(_("Email:"), 'salesman_email', 40);
-
+percent_row(_("Provision"), 'provision');
+amount_row(_("Break Pt.:"), 'break_pt');
+percent_row(_("Provision")." 2", 'provision2');
 end_table(1);
 
 submit_add_or_update_center(!isset($selected_id));
index c8c75bd468187983008f9eb2211f64a0d01497bc..c90eaa927c3435b29416c6391ce081cba6cd9b73 100644 (file)
@@ -18,22 +18,22 @@ if ($use_popup_windows)
 if ($use_date_picker)
        $js .= get_js_date_picker();
 
-if (isset($_GET['ModifyOrderNumber'])) 
+if (isset($_GET['ModifyOrderNumber']))
 {
-       page(_("Modifying Sales Order") . " #".$_GET['ModifyOrderNumber'], false, false, "", $js); 
-}      
-elseif (isset($_GET['NewInvoice']) || (isset($_SESSION['Items']) && $_SESSION['Items']->direct_invoice)) 
+       page(_("Modifying Sales Order") . " #".$_GET['ModifyOrderNumber'], false, false, "", $js);
+}
+elseif (isset($_GET['NewInvoice']) || (isset($_SESSION['Items']) && $_SESSION['Items']->direct_invoice))
 {
-       page(_("Sales Invoices"), false, false, "", $js); 
-} 
-else 
+       page(_("Sales Invoices"), false, false, "", $js);
+}
+else
 {
-       page(_("Sales Order Entry"), false, false, "", $js); 
+       page(_("Sales Order Entry"), false, false, "", $js);
 }
 
 
 //--------------------------------------------------------------------------------
-if (isset($_GET['AddedID'])) 
+if (isset($_GET['AddedID']))
 {
        $order_no = $_GET['AddedID'];
        $trans_type = systypes::sales_order();
@@ -50,7 +50,7 @@ if (isset($_GET['AddedID']))
 }
 //--------------------------------------------------------------------------------
 
-if (isset($_GET['UpdatedID'])) 
+if (isset($_GET['UpdatedID']))
 {
        $order_no = $_GET['UpdatedID'];
        $trans_type = systypes::sales_order();
@@ -109,20 +109,20 @@ function copy_from_so()
 
 function can_process()
 {
-       if ($_SESSION['Items']->direct_invoice) 
+       if ($_SESSION['Items']->direct_invoice)
        {
                $edate = _("The entered invoice date is invalid.");
-       } 
-       else 
-       {       
+       }
+       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']->direct_invoice && !is_date_in_fiscalyear($_POST['OrderDate']))
        {
                display_error(_("The entered date is not in fiscal year"));
                return false;
@@ -157,13 +157,13 @@ 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;
@@ -175,7 +175,7 @@ function can_process()
        $_SESSION['Items']->phone =$_POST['phone'];
        if (isset($_POST['email']))
                $_SESSION['Items']->email =$_POST['email'];
-       else    
+       else
                $_SESSION['Items']->email = "";
        $_SESSION['Items']->Location = $_POST['Location'];
        $_SESSION['Items']->cust_ref = $_POST['cust_ref'];
@@ -192,23 +192,24 @@ if (isset($_POST['ProcessOrder']) && $_SESSION['Items']->order_no == 0 && can_pr
 {
 
        $order_no = add_sales_order($_SESSION['Items']);
-       
-       if ($_SESSION['Items']->direct_invoice) 
+
+       if ($_SESSION['Items']->direct_invoice)
        {
+               $_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 
+
+       }
+       else
        {
-       
+
                unset($_SESSION['Items']->line_items);
                unset($_SESSION['Items']);
 
                meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no");
-       }       
+       }
 }
 
 //-------------------------------------------------------------------------------------------------------------
@@ -229,55 +230,55 @@ if (isset($_POST['ProcessOrder']) && $_SESSION['Items']->order_no != 0 && can_pr
 
 //--------------------------------------------------------------------------------
 
-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['stock_id']) != 0 &&
-               $_SESSION['Items']->line_items[$_POST['stock_id']]->price != $_POST['price']) 
+       }
+       elseif($_SESSION['Items']->some_already_delivered($_POST['line_no']) != 0 &&
+               $_SESSION['Items']->line_items[$_POST['line_no']]->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;
-       } 
-       elseif($_SESSION['Items']->some_already_delivered($_POST['stock_id']) != 0 && 
-               $_SESSION['Items']->line_items[$_POST['stock_id']]->discount_percent != ($_POST['Disc']/100)) 
+       }
+       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['stock_id']]) && $_SESSION['Items']->line_items[$_POST['stock_id']]->qty_inv > $_POST['qty'])
+       }
+       elseif (isset($_SESSION['Items']->line_items[$_POST['line_no']]) && $_SESSION['Items']->line_items[$_POST['line_no']]->qty_inv > $_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."));
                return false;
-       }       
+       }
        return true;
 }
 
-function handle_update_item() 
+function handle_update_item()
 {
     if($_POST['UpdateItem'] != "" && check_item_data())
     {
-       $_SESSION['Items']->update_cart_item($_POST['stock_id'], $_POST['qty'], 
+       $_SESSION['Items']->update_cart_item($_POST['line_no'], $_POST['qty'],
                $_POST['price'], ($_POST['Disc'] / 100));
     }
 }
 
 //--------------------------------------------------------------------------------
 
-function handle_delete_item() 
-{   
+function handle_delete_item()
+{
     if($_GET['Delete'] != "")
     {
-       $stock_id = $_GET['Delete']; 
-       if($_SESSION['Items']->some_already_delivered($stock_id) == 0)
+       $line_no = $_GET['Delete'];
+       if($_SESSION['Items']->some_already_delivered($line_no) == 0)
        {
-               $_SESSION['Items']->remove_from_cart($stock_id);
-       } 
-       else 
+               $_SESSION['Items']->remove_from_cart($line_no);
+       }
+       else
        {
                display_error(_("This item cannot be deleted because some of it has already been invoiced."));
        }
@@ -290,29 +291,29 @@ function handle_new_item()
 {
        if (!check_item_data())
                return;
-               
-       add_to_order($_SESSION['Items'], $_POST['stock_id'], $_POST['qty'], 
+
+       add_to_order($_SESSION['Items'], $_POST['line_no'], $_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_invoices($_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."));
                }
-    
+
        if ($ok_to_delete == 1)
        {
                if($_SESSION['Items']->order_no != 0)
@@ -323,26 +324,26 @@ function  handle_cancel_order()
                $_SESSION['Items']->clear_items();
                $_SESSION['Items'] = new cart;
                $_SESSION['Items']->direct_invoice = $diriv;
-               if ($diriv) 
+               if ($diriv)
                {
                        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 
+               }
+               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");
                }
                br(1);
-               end_page();                     
+               end_page();
                exit;
        }
     }
 }
-       
+
 //--------------------------------------------------------------------------------
 
-function handle_new_order() 
+function handle_new_order()
 {
        /*New order entry - clear any existing order details from the Items object and initiate a newy*/
        if (isset($_SESSION['Items']))
@@ -350,20 +351,20 @@ 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();          
+       $_POST['OrderDate'] = Today();
        if (!is_date_in_fiscalyear($_POST['OrderDate']))
                $_POST['OrderDate'] = end_fiscalyear();
        $_SESSION['Items']->orig_order_date = $_POST['OrderDate'];
 }
 
-//--------------------------------------------------------------------------------     
+//--------------------------------------------------------------------------------
 
 if (isset($_GET['ModifyOrderNumber']) && $_GET['ModifyOrderNumber'] != "")
 {
@@ -377,10 +378,10 @@ if (isset($_GET['ModifyOrderNumber']) && $_GET['ModifyOrderNumber'] != "")
        session_register("Items");
 
        $_SESSION['Items'] = new cart;
-       $_SESSION['Items']->order_no = $_GET['ModifyOrderNumber']; 
+       $_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']);
 }
 
@@ -391,49 +392,49 @@ if (isset($_POST['CancelOrder']))
 
 if (isset($_GET['Delete']) || isset($_GET['Edit']))
        copy_from_so();
-       
+
 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 
+}
+else
 {
        if (!isset($_POST['customer_id']))
                $_POST['customer_id'] = $_SESSION['Items']->customer_id;
-       if (!isset($_POST['branch_id']))                
+       if (!isset($_POST['branch_id']))
                $_POST['branch_id'] = $_SESSION['Items']->Branch;
-       if (!isset($_POST['OrderDate']))                
+       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']->direct_invoice)
 {
        $idate = _("Invoice Date:");
        $orderitems = _("Sales Invoice Items");
        $deliverydetails = _("Enter Delivery Details and Confirm Invoice");
        $cancelorder = _("Cancel Invoice");
-} 
-else 
+}
+else
 {
        $idate = _("Order Date:");
        $orderitems = _("Sales Order Items");
@@ -442,32 +443,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 "<tr><td>";                
+       echo "<tr><td>";
        display_order_summary($orderitems, $_SESSION['Items'], true);
        echo "</td></tr>";
-       echo "<tr><td>";                
+       echo "<tr><td>";
        display_delivery_details($_SESSION['Items']);
        echo "</td></tr>";
-       end_table(1);           
-} 
+       end_table(1);
+}
 else
 {
        display_error($customer_error);
 }
 
-if ($_SESSION['Items']->direct_invoice) 
+if ($_SESSION['Items']->direct_invoice)
 {
        $porder = _("Place Invoice");
        $corder = _("Commit Invoice Changes");
        $eorder = _("Edit Invoice Items");
-} 
-else 
+}
+else
 {
        $porder = _("Place Order");
        $corder = _("Commit Order Changes");
@@ -477,13 +478,13 @@ 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)
@@ -492,9 +493,9 @@ if ($_SESSION['Items']->count_items() >= 1)
        submit('DeliveryDetails', $deliverydetails);
        echo "   ";
 }
-*/             
+*/
 submit_center_last('CancelOrder', $cancelorder);
-       
+
 end_form();
 
 //--------------------------------------------------------------------------------
@@ -509,7 +510,7 @@ if (!isset($_SESSION['Items']))
        $_SESSION['Items'] = new cart;
        if (isset($_GET['NewInvoice']))
                $_SESSION['Items']->direct_invoice = true;
-       $_SESSION['Items']->order_no = 0;       
+       $_SESSION['Items']->order_no = 0;
 }
 
 //--------------------------------------------------------------------------------