From d8a369f39dffc5de0c997a7f9de3962a54bfb95c Mon Sep 17 00:00:00 2001 From: jekkos Date: Wed, 7 Oct 2015 08:48:59 +0200 Subject: [PATCH] Remove unique constriant from invoice_number column in suspended_sales --- application/controllers/sales.php | 76 +++++++++++++------------------ database/2.3.2_to_2.3.3.sql | 3 ++ database/database.sql | 3 +- 3 files changed, 35 insertions(+), 47 deletions(-) diff --git a/application/controllers/sales.php b/application/controllers/sales.php index a5c366508..0fcb5ef04 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -269,13 +269,6 @@ class Sales extends Secure_area { $this->sale_lib->return_entire_sale($item_id_or_number_or_item_kit_or_receipt); } - else if($this->Sale_suspended->invoice_number_exists($item_id_or_number_or_item_kit_or_receipt)) - { - $this->sale_lib->clear_all(); - $sale_id=$this->Sale_suspended->get_sale_by_invoice_number($item_id_or_number_or_item_kit_or_receipt)->row()->sale_id; - $this->sale_lib->copy_entire_suspended_sale($sale_id); - $this->Sale_suspended->delete($sale_id); - } else if($this->sale_lib->is_valid_item_kit($item_id_or_number_or_item_kit_or_receipt)) { $this->sale_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt,$item_location); @@ -548,7 +541,7 @@ class Sales extends Secure_area $this->sale_lib->set_invoice_number($invoice_number); return $invoice_number; } - + private function _load_sale_data($sale_id) { $this->Sale->create_sales_items_temp_table(); @@ -780,51 +773,44 @@ class Sales extends Secure_area $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; $comment = $this->sale_lib->get_comment(); $invoice_number = $this->sale_lib->get_invoice_number(); - + $emp_info = $this->Employee->get_info($employee_id); $data['payment_type'] = $this->input->post('payment_type'); // Multiple payments $data['payments'] = $this->sale_lib->get_payments(); $data['amount_change'] = to_currency($this->sale_lib->get_amount_due() * -1); $data['employee'] = $emp_info->first_name.' '.$emp_info->last_name; - - if ($this->Sale_suspended->invoice_number_exists($invoice_number)) - { - $this->_reload(array('error' => $data['error']=$this->lang->line('sales_invoice_number_duplicate'))); - } - else - { - if($customer_id!=-1) - { - $cust_info = $this->Customer->get_info($customer_id); - if (isset($cust_info->company_name)) - { - $data['customer'] = $cust_info->company_name; - } - else - { - $data['customer'] = $cust_info->first_name.' '.$cust_info->last_name; - } - } - - $total_payments = 0; - - foreach($data['payments'] as $payment) - { - $total_payments = bcadd($total_payments, $payment['payment_amount'], PRECISION); - } - - //SAVE sale to database - $data['sale_id'] = 'POS '.$this->Sale_suspended->save($data['cart'], $customer_id, $employee_id, $comment, $invoice_number, $data['payments']); - if ($data['sale_id'] == 'POS -1') - { - $data['error_message'] = $this->lang->line('sales_transaction_failed'); - } - $this->sale_lib->clear_all(); - - $this->_reload(array('success' => $this->lang->line('sales_successfully_suspended_sale'))); + if($customer_id!=-1) + { + $cust_info = $this->Customer->get_info($customer_id); + if (isset($cust_info->company_name)) + { + $data['customer'] = $cust_info->company_name; + } + else + { + $data['customer'] = $cust_info->first_name.' '.$cust_info->last_name; + } } + + $total_payments = 0; + + foreach($data['payments'] as $payment) + { + $total_payments = bcadd($total_payments, $payment['payment_amount'], PRECISION); + } + + //SAVE sale to database + $data['sale_id'] = 'POS '.$this->Sale_suspended->save($data['cart'], $customer_id, $employee_id, $comment, $invoice_number, $data['payments']); + if ($data['sale_id'] == 'POS -1') + { + $data['error_message'] = $this->lang->line('sales_transaction_failed'); + } + + $this->sale_lib->clear_all(); + + $this->_reload(array('success' => $this->lang->line('sales_successfully_suspended_sale'))); } function suspended() diff --git a/database/2.3.2_to_2.3.3.sql b/database/2.3.2_to_2.3.3.sql index 440386d33..958e5b5ae 100644 --- a/database/2.3.2_to_2.3.3.sql +++ b/database/2.3.2_to_2.3.3.sql @@ -4,3 +4,6 @@ ALTER TABLE `ospos_suppliers` INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('dateformat', 'm-d-Y'), ('timeformat', 'H:i:s'); + +ALTER TABLE `ospos_sales_suspended` + DROP KEY `invoice_number`; \ No newline at end of file diff --git a/database/database.sql b/database/database.sql index 74ece2b57..fa821739d 100644 --- a/database/database.sql +++ b/database/database.sql @@ -583,8 +583,7 @@ CREATE TABLE `ospos_sales_suspended` ( `sale_id` int(10) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`sale_id`), KEY `customer_id` (`customer_id`), - KEY `employee_id` (`employee_id`), - UNIQUE KEY `invoice_number` (`invoice_number`) + KEY `employee_id` (`employee_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; --