Auto Increase of Document References (company setup)
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 16 Apr 2018 06:25:44 +0000 (08:25 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 16 Apr 2018 06:25:44 +0000 (08:25 +0200)
admin/company_preferences.php
sales/includes/cart_class.inc

index b23c92c7bf520dcd4848fe7fb8091221f162afe4..9407f15c5458d7024297a90713b3c74edc273867 100644 (file)
@@ -113,7 +113,7 @@ if (isset($_POST['update']) && $_POST['update'] != "")
                                'postal_address','phone', 'fax', 'email', 'coy_logo', 'domicile',
                                'use_dimension', 'curr_default', 'f_year', 'shortname_name_in_list',
                                'no_item_list' => 0, 'no_customer_list' => 0, 
-                               'no_supplier_list' =>0, 'base_sales', 
+                               'no_supplier_list' =>0, 'base_sales', 'ref_no_auto_increase' => 0,
                                'time_zone' => 0, 'company_logo_report' => 0, 'barcodes_on_stock' => 0, 'add_pct', 'round_to', 'login_tout', 
                                'auto_curr_reval', 'bcc_email', 'alternative_tax_include_on_docs', 'suppress_tax_rates',
                                'use_manufacturing', 'use_fixed_assets'))
@@ -161,6 +161,12 @@ if (!isset($myrow["company_logo_report"]))
        $myrow["company_logo_report"] = get_company_pref("company_logo_report");
 }
 $_POST['company_logo_report']  = $myrow["company_logo_report"];
+if (!isset($myrow["ref_no_auto_increase"]))
+{
+       set_company_pref("ref_no_auto_increase", "setup.company", "tinyint", 1, '0');
+       $myrow["ref_no_auto_increase"] = get_company_pref("ref_no_auto_increase");
+}
+$_POST['ref_no_auto_increase']  = $myrow["ref_no_auto_increase"];
 if (!isset($myrow["barcodes_on_stock"]))
 {
        set_company_pref("barcodes_on_stock", "setup.company", "tinyint", 1, '0');
@@ -208,6 +214,7 @@ check_row(_("Automatic Revaluation Currency Accounts"), 'auto_curr_reval', $_POS
 check_row(_("Time Zone on Reports"), 'time_zone', $_POST['time_zone']);
 check_row(_("Company Logo on Reports"), 'company_logo_report', $_POST['company_logo_report']);
 check_row(_("Use Barcodes on Stocks"), 'barcodes_on_stock', $_POST['barcodes_on_stock']);
+check_row(_("Auto Increase of Document References"), 'ref_no_auto_increase', $_POST['ref_no_auto_increase']);
 label_row(_("Database Scheme Version"), $_POST['version_id']);
 
 table_section(2);
index 7d68e2a4622fc60cfccf6bee5298556fd1c079b5..6aefabf72f7fcffb65b7ca39c162c681e5ddbae0 100644 (file)
@@ -285,12 +285,19 @@ class Cart
        // Makes parent documents for direct delivery/invoice by recurent call.
        // $policy - 0 or 1:  writeoff/return for IV, back order/cancel for DN
        function write($policy=0) {
-
+               
+               global $SysPrefs, $Refs;
+               
                begin_transaction(); // prevents partial database changes in case of direct delivery/invoice
                if ($this->reference != 'auto' && $this->trans_no == 0 && !is_new_reference($this->reference, $this->trans_type))
                {
-                       commit_transaction();
-                       return -1;
+                       if (!empty($SysPrefs->prefs['ref_no_auto_increase']))
+                               $this->reference = $Refs->get_next($this->trans_type, null, array('date' => Today()));
+                       if (!is_new_reference($this->reference, $this->trans_type))     
+                       {
+                               commit_transaction();
+                               return -1;
+                       }       
                }
                if (count($this->src_docs) == 0 && ($this->trans_type == ST_SALESINVOICE || $this->trans_type == ST_CUSTDELIVERY) && !$this->is_prepaid()) {
                        // this is direct document - first add parent