diff --git a/admin/company_preferences.php b/admin/company_preferences.php index b23c92c7b..9407f15c5 100644 --- a/admin/company_preferences.php +++ b/admin/company_preferences.php @@ -113,7 +113,7 @@ '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 @@ $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(_("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); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 7d68e2a46..6aefabf72 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -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