From 96c349b09915832a4724606519cf429865107743 Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Thu, 30 Oct 2014 19:22:49 +0100 Subject: [PATCH 1/6] Add invoice numbering to sales module --- application/controllers/items.php | 3 +- application/controllers/receivings.php | 2 +- application/controllers/sales.php | 157 ++++++++++++++++------- application/helpers/table_helper.php | 9 -- application/language/en/config_lang.php | 1 + application/language/en/sales_lang.php | 2 + application/libraries/Receiving_lib.php | 4 +- application/libraries/Sale_lib.php | 29 ++++- application/models/item.php | 4 +- application/models/receiving.php | 4 +- application/models/sale.php | 31 ++++- application/models/sale_suspended.php | 35 ++++- application/views/config.php | 10 ++ application/views/receivings/receipt.php | 2 +- application/views/sales/receipt.php | 9 +- application/views/sales/register.php | 41 +++--- database/2.3_to_2.3.1.sql | 16 ++- database/database.sql | 9 +- 18 files changed, 274 insertions(+), 94 deletions(-) diff --git a/application/controllers/items.php b/application/controllers/items.php index c9ef537b5..5321f7669 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -60,7 +60,8 @@ class Items extends Secure_area implements iData_controller function search() { $search=$this->input->post('search'); - $data_rows=get_items_manage_table_data_rows($this->Item->search($search),$this); + $stock_location=$this->item_lib->get_item_location(); + $data_rows=get_items_manage_table_data_rows($this->Item->search($search,$stock_location),$this); echo $data_rows; } diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index 8bd096234..9fd363f86 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -69,7 +69,7 @@ class Receivings extends Secure_area $item_id_or_number_or_item_kit_or_receipt = $this->input->post("item"); $quantity = ($mode=="receive" or $mode=="requisition") ? 1:-1; $item_location = $this->receiving_lib->get_stock_source(); - if($this->receiving_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt) && $mode=='return') + if($mode=='return' && $this->receiving_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt)) { $this->receiving_lib->return_entire_receiving($item_id_or_number_or_item_kit_or_receipt); } diff --git a/application/controllers/sales.php b/application/controllers/sales.php index c5eb5df22..8e5b9766c 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -54,6 +54,11 @@ class Sales extends Secure_area $this->sale_lib->set_comment($this->input->post('comment')); } + function set_invoice_number() + { + $this->sale_lib->set_invoice_number($this->input->post('sales_invoice_number')); + } + function set_email_receipt() { $this->sale_lib->set_email_receipt($this->input->post('email_receipt')); @@ -124,10 +129,17 @@ class Sales extends Secure_area $quantity = ($mode=="return")? -1:1; $item_location = $this->sale_lib->get_sale_location(); - if($this->sale_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt) && $mode=='return') + if($mode == 'return' && $this->sale_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt)) { $this->sale_lib->return_entire_sale($item_id_or_number_or_item_kit_or_receipt); } + elseif($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); + } elseif($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); @@ -185,6 +197,7 @@ class Sales extends Secure_area function remove_customer() { + $this->sale_lib->clear_invoice_number(); $this->sale_lib->remove_customer(); $this->_reload(); } @@ -206,39 +219,77 @@ class Sales extends Secure_area $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; - + $cust_info=''; if($customer_id!=-1) { $cust_info=$this->Customer->get_info($customer_id); $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; } - - //SAVE sale to database - $data['sale_id']='POS '.$this->Sale->save($data['cart'], $customer_id,$employee_id,$comment,$data['payments']); - if ($data['sale_id'] == 'POS -1') + $invoice_number=$this->_substitute_invoice_number($cust_info); + if ($this->Sale->invoice_number_exists($invoice_number)) { - $data['error_message'] = $this->lang->line('sales_transaction_failed'); + $data['error']=$this->lang->line('sales_invoice_number_duplicate'); + $this->_reload($data); } - else + else { - if ($this->sale_lib->get_email_receipt() && !empty($cust_info->email)) + $data['invoice_number']=$invoice_number; + //SAVE sale to database + $data['sale_id']='POS '.$this->Sale->save($data['cart'], $customer_id,$employee_id,$comment,$data['payments'],$invoice_number); + if ($data['sale_id'] == 'POS -1') { - $this->load->library('email'); - $config['mailtype'] = 'html'; - $this->email->initialize($config); - $this->email->from($this->config->item('email'), $this->config->item('company')); - $this->email->to($cust_info->email); - - $this->email->subject($this->lang->line('sales_receipt')); - $this->email->message($this->load->view("sales/receipt_email",$data, true)); - $this->email->send(); + $data['error_message'] = $this->lang->line('sales_transaction_failed'); } + else + { + if ($this->sale_lib->get_email_receipt() && !empty($cust_info->email)) + { + $this->load->library('email'); + $config['mailtype'] = 'html'; + $this->email->initialize($config); + $this->email->from($this->config->item('email'), $this->config->item('company')); + $this->email->to($cust_info->email); + + $this->email->subject($this->lang->line('sales_receipt')); + $this->email->message($this->load->view("sales/receipt_email",$data, true)); + $this->email->send(); + } + } + $this->load->view("sales/receipt",$data); + $this->sale_lib->clear_all(); } - $this->load->view("sales/receipt",$data); - $this->sale_lib->clear_all(); + $this->_remove_duplicate_cookies(); } + function _substitute_invoice_number($customer_info='') + { + $invoice_number=$this->sale_lib->get_invoice_number(); + if (empty($invoice_number)) + { + $invoice_number=$this->config->config['sales_invoice_format']; + } + $invoice_count=$this->Sale->get_invoice_count(); + $invoice_number=str_replace('$CO',$invoice_count,$invoice_number); + $invoice_count=$this->Sale_suspended->get_invoice_count(); + $invoice_number=str_replace('$SCO',$invoice_count,$invoice_number); + $invoice_number=strftime($invoice_number); + + $customer_id=$this->sale_lib->get_customer(); + if($customer_id!=-1) + { + $invoice_number=str_replace('$CU',$customer_info->first_name . ' ' . $customer_info->last_name,$invoice_number); + $words = preg_split("/\s+/", $customer_info->first_name . ' ' . $customer_info->last_name); + $acronym = ""; + foreach ($words as $w) { + $acronym .= $w[0]; + } + $invoice_number=str_replace('$CI',$acronym,$invoice_number); + } + $this->sale_lib->set_invoice_number($invoice_number); + return $invoice_number; + } + function receipt($sale_id) { $sale_info = $this->Sale->get_info($sale_id)->row_array(); @@ -255,6 +306,7 @@ class Sales extends Secure_area $customer_id=$this->sale_lib->get_customer(); $emp_info=$this->Employee->get_info($sale_info['employee_id']); $data['payment_type']=$sale_info['payment_type']; + $data['invoice_number']=$this->sale_lib->get_invoice_number(); $data['amount_change']=to_currency($this->sale_lib->get_amount_due() * -1); $data['employee']=$emp_info->first_name.' '.$emp_info->last_name; @@ -314,7 +366,8 @@ class Sales extends Secure_area 'sale_time' => date('Y-m-d', strtotime($this->input->post('date'))), 'customer_id' => $this->input->post('customer_id') ? $this->input->post('customer_id') : null, 'employee_id' => $this->input->post('employee_id'), - 'comment' => $this->input->post('comment') + 'comment' => $this->input->post('comment'), + 'invoice_number' => $this->input->post('invoice_number') ); if ($this->Sale->update($sale_data, $sale_id)) @@ -382,12 +435,14 @@ class Sales extends Secure_area ); $customer_id=$this->sale_lib->get_customer(); + $cust_info=''; if($customer_id!=-1) { - $info=$this->Customer->get_info($customer_id); - $data['customer']=$info->first_name.' '.$info->last_name; - $data['customer_email']=$info->email; + $cust_info=$this->Customer->get_info($customer_id); + $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + $data['customer_email']=$cust_info->email; } + $data['invoice_number']=$this->_substitute_invoice_number($cust_info); $data['payments_cover_total'] = $this->_payments_cover_total(); $this->load->view("sales/register",$data); $this->_remove_duplicate_cookies(); @@ -397,7 +452,6 @@ class Sales extends Secure_area { $this->sale_lib->clear_all(); $this->_reload(); - } function suspend() @@ -411,6 +465,8 @@ class Sales extends Secure_area $customer_id=$this->sale_lib->get_customer(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $comment = $this->input->post('comment'); + $invoice_number=$this->sale_lib->get_invoice_number(); + $emp_info=$this->Employee->get_info($employee_id); $payment_type = $this->input->post('payment_type'); $data['payment_type']=$this->input->post('payment_type'); @@ -418,28 +474,35 @@ class Sales extends Secure_area $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($customer_id!=-1) + + if ($this->Sale_suspended->invoice_number_exists($invoice_number)) { - $cust_info=$this->Customer->get_info($customer_id); - $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + $this->_reload(array('error' => $data['error']=$this->lang->line('sales_invoice_number_duplicate'))); } - - $total_payments = 0; - - foreach($data['payments'] as $payment) + else { - $total_payments += $payment['payment_amount']; + if($customer_id!=-1) + { + $cust_info=$this->Customer->get_info($customer_id); + $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + } + + $total_payments = 0; + + foreach($data['payments'] as $payment) + { + $total_payments += $payment['payment_amount']; + } + + //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'))); } - - //SAVE sale to database - $data['sale_id']='POS '.$this->Sale_suspended->save($data['cart'], $customer_id,$employee_id,$comment,$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() @@ -457,5 +520,13 @@ class Sales extends Secure_area $this->Sale_suspended->delete($sale_id); $this->_reload(); } + + function check_invoice_number() + { + $sale_id=$this->input->post('sale_id'); + $invoice_number=$this->input->post('invoice_number'); + $exists=!empty($invoice_number) && $this->Sale->invoice_number_exists($invoice_number,$sale_id); + echo json_encode(array('success'=>!$exists,'message'=>$this->lang->line('sales_invoice_number_duplicate'))); + } } ?> diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index 72fa6e346..6ecb80354 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -211,15 +211,6 @@ function get_item_data_row($item,$controller) $width = $controller->get_form_width(); $item_quantity=''; - /* $locations_data = $CI->Stock_locations->get_allowed_locations()->result_array(); - foreach($locations_data as $location) - { - if (count($locations_data) > 1) - { - $item_quantity .= $location['location_name'].': '; - } - $item_quantity .= $CI->Item_quantities->get_item_quantity($item->item_id, $location['location_id'])->quantity . '
'; - } */ $table_data_row=''; $table_data_row.=""; diff --git a/application/language/en/config_lang.php b/application/language/en/config_lang.php index ac38121a6..89ea76ad3 100644 --- a/application/language/en/config_lang.php +++ b/application/language/en/config_lang.php @@ -37,5 +37,6 @@ $lang['config_stock_location'] = 'Stock location'; $lang['config_stock_location_required'] = 'Stock location number is a required field'; $lang['config_tax_included'] = 'Tax Included'; $lang['config_recv_invoice_format'] = 'Receivings Invoice'; +$lang['config_sales_invoice_format'] = 'Sales Invoice'; ?> \ No newline at end of file diff --git a/application/language/en/sales_lang.php b/application/language/en/sales_lang.php index 83dc494ce..fe682f3ba 100644 --- a/application/language/en/sales_lang.php +++ b/application/language/en/sales_lang.php @@ -87,6 +87,8 @@ $lang['sales_basic_information']='Sale information'; $lang['sales_stock_location']='Stock location'; $lang['sales_sale']='Sale'; $lang['sales_receipt_number']='Sale #'; +$lang['sales_invoice_number']='Invoice #'; $lang['sales_date_required']='A correct date needs to be filled in'; $lang['sales_date_type']='Date field is required'; +$lang['sales_invoice_number_duplicate'] = 'Please enter an unique invoice number'; ?> diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 3edb03922..ab0cbb5db 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -117,7 +117,7 @@ class Receiving_lib { $this->CI->session->unset_userdata('recv_stock_destination'); } - + function add_item($item_id,$quantity=1,$item_location,$discount=0,$price=null,$description=null,$serialnumber=null) { //make sure item exists in database. @@ -292,8 +292,6 @@ class Receiving_lib $this->add_item($row->item_id,$row->quantity_purchased,$row->item_location,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); } $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); - $receiving_info=$this->CI->Receiving->get_info($receiving_id); - //$this->set_invoice_number($receiving_info->row()->invoice_number); } function copy_entire_requisition($requisition_id,$item_location) diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 5178b8b4d..c6283ca2a 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -52,6 +52,21 @@ class Sale_lib $this->CI->session->unset_userdata('comment'); } + function get_invoice_number() + { + return $this->CI->session->userdata('sales_invoice_number'); + } + + function set_invoice_number($invoice_number) + { + $this->CI->session->set_userdata('sales_invoice_number', $invoice_number); + } + + function clear_invoice_number() + { + $this->CI->session->unset_userdata('sales_invoice_number'); + } + function get_email_receipt() { return $this->CI->session->userdata('email_receipt'); @@ -342,6 +357,10 @@ class Sale_lib { return $this->CI->Sale->exists($pieces[1]); } + else + { + return $this->CI->Sale->get_sale_by_invoice_number($receipt_sale_id)->num_rows() > 0; + } return false; } @@ -394,14 +413,13 @@ class Sale_lib foreach($this->CI->Sale->get_sale_items($sale_id)->result() as $row) { - $this->add_item($row->item_id,$row->quantity_purchased,$row->item_location,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber); + $this->add_item($row->item_id,$row->quantity_purchased,$row->item_location,$row->discount_percent,$row->item_unit_price,$row->description,$row->serialnumber,$row->invoice_number); } foreach($this->CI->Sale->get_sale_payments($sale_id)->result() as $row) { $this->add_payment($row->payment_type,$row->payment_amount); } $this->set_customer($this->CI->Sale->get_customer($sale_id)->person_id); - } function copy_entire_suspended_sale($sale_id) @@ -417,8 +435,10 @@ class Sale_lib { $this->add_payment($row->payment_type,$row->payment_amount); } - $this->set_customer($this->CI->Sale_suspended->get_customer($sale_id)->person_id); - $this->set_comment($this->CI->Sale_suspended->get_comment($sale_id)); + $suspended_sale_info=$this->CI->Sale_suspended->get_info($sale_id)->row(); + $this->set_customer($suspended_sale_info->person_id); + $this->set_comment($suspended_sale_info->comment); + $this->set_invoice_number($suspended_sale_info->invoice_number); } function delete_item($line) @@ -449,6 +469,7 @@ class Sale_lib $this->empty_cart(); $this->clear_comment(); $this->clear_email_receipt(); + $this->clear_invoice_number(); $this->empty_payments(); $this->remove_customer(); } diff --git a/application/models/item.php b/application/models/item.php index a80c7a7ca..134712eb4 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -549,9 +549,11 @@ class Item extends CI_Model /* Preform a search on items */ - function search($search) + function search($search,$stock_location_id) { $this->db->from('items'); + $this->db->join('item_quantities','item_quantities.item_id=items.item_id'); + $this->db->where('location_id',$stock_location_id); $this->db->where("( name LIKE '%".$this->db->escape_like_str($search)."%' or diff --git a/application/models/receiving.php b/application/models/receiving.php index e44db43a4..38de653da 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -40,7 +40,7 @@ class Receiving extends CI_Model return $success; } - function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$receiving_id=false,$invoice_number=null) + function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$receiving_id=false,$invoice_number=NULL) { if(count($items)==0) return -1; @@ -50,7 +50,7 @@ class Receiving extends CI_Model 'employee_id'=>$employee_id, 'payment_type'=>$payment_type, 'comment'=>$comment, - 'invoice_number'=>empty($invoice_number) ? null : $invoice_number + 'invoice_number'=>empty($invoice_number) ? NULL : $invoice_number ); //Run these queries as a transaction, we want to make sure we do all or nothing diff --git a/application/models/sale.php b/application/models/sale.php index 2963fe5cb..253597d18 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -8,6 +8,20 @@ class Sale extends CI_Model $this->db->where('sale_id',$sale_id); return $this->db->get(); } + + function get_invoice_count() + { + $this->db->from('sales'); + $this->db->where('invoice_number is not null'); + return $this->db->count_all_results(); + } + + function get_sale_by_invoice_number($invoice_number) + { + $this->db->from('sales'); + $this->db->where('invoice_number', $invoice_number); + return $this->db->get(); + } function exists($sale_id) { @@ -26,7 +40,7 @@ class Sale extends CI_Model return $success; } - function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=false) + function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=false,$invoice_number=NULL) { if(count($items)==0) return -1; @@ -44,7 +58,8 @@ class Sale extends CI_Model 'customer_id'=> $this->Customer->exists($customer_id) ? $customer_id : null, 'employee_id'=>$employee_id, 'payment_type'=>$payment_types, - 'comment'=>$comment + 'comment'=>$comment, + 'invoice_number'=>empty($invoice_number) ? NULL : $invoice_number ); //Run these queries as a transaction, we want to make sure we do all or nothing @@ -206,6 +221,18 @@ class Sale extends CI_Model $this->db->where('sale_id',$sale_id); return $this->Customer->get_info($this->db->get()->row()->customer_id); } + + function invoice_number_exists($invoice_number,$sale_id='') + { + $this->db->from('sales'); + $this->db->where('invoice_number', $invoice_number); + if (!empty($sale_id)) + { + $this->db->where('sale_id !=', $sale_id); + } + $query=$this->db->get(); + return ($query->num_rows()==1); + } //We create a temp table that allows us to do easy report/sales queries public function create_sales_items_temp_table() diff --git a/application/models/sale_suspended.php b/application/models/sale_suspended.php index 78bfd453c..b8475d447 100644 --- a/application/models/sale_suspended.php +++ b/application/models/sale_suspended.php @@ -12,6 +12,21 @@ class Sale_suspended extends CI_Model { $this->db->from('sales_suspended'); $this->db->where('sale_id',$sale_id); + $this->db->join('people', 'people.person_id = sales_suspended.customer_id', 'LEFT'); + return $this->db->get(); + } + + function get_invoice_count() + { + $this->db->from('sales_suspended'); + $this->db->where('invoice_number is not null'); + return $this->db->count_all_results(); + } + + function get_sale_by_invoice_number($invoice_number) + { + $this->db->from('sales_suspended'); + $this->db->where('invoice_number', $invoice_number); return $this->db->get(); } @@ -32,7 +47,7 @@ class Sale_suspended extends CI_Model return $success; } - function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=false) + function save ($items,$customer_id,$employee_id,$comment,$invoice_number,$payments,$sale_id=false) { if(count($items)==0) return -1; @@ -50,7 +65,8 @@ class Sale_suspended extends CI_Model 'customer_id'=> $this->Customer->exists($customer_id) ? $customer_id : null, 'employee_id'=>$employee_id, 'payment_type'=>$payment_types, - 'comment'=>$comment + 'comment'=>$comment, + 'invoice_number'=>$invoice_number ); //Run these queries as a transaction, we want to make sure we do all or nothing @@ -143,14 +159,19 @@ class Sale_suspended extends CI_Model $this->db->where('sale_id',$sale_id); return $this->db->get(); } - - function get_customer($sale_id) + + function invoice_number_exists($invoice_number,$sale_id='') { $this->db->from('sales_suspended'); - $this->db->where('sale_id',$sale_id); - return $this->Customer->get_info($this->db->get()->row()->customer_id); + $this->db->where('invoice_number', $invoice_number); + if (!empty($sale_id)) + { + $this->db->where('sale_id !=', $sale_id); + } + $query=$this->db->get(); + return ($query->num_rows()==1); } - + function get_comment($sale_id) { $this->db->from('sales_suspended'); diff --git a/application/views/config.php b/application/views/config.php index b441f5408..c0a0f6ba4 100644 --- a/application/views/config.php +++ b/application/views/config.php @@ -268,6 +268,16 @@ echo form_open('config/save/',array('id'=>'config_form')); +
+lang->line('config_sales_invoice_format').':', 'sales_invoice_format',array('class'=>'wide')); ?> +
+ 'sales_invoice_format', + 'id'=>'sales_invoice_format', + 'value'=>$this->config->item('sales_invoice_format'))); ?> +
+
+
lang->line('config_recv_invoice_format').':', 'recv_invoice_format',array('class'=>'wide')); ?>
diff --git a/application/views/receivings/receipt.php b/application/views/receivings/receipt.php index ba82ac87f..174bbef71 100644 --- a/application/views/receivings/receipt.php +++ b/application/views/receivings/receipt.php @@ -18,7 +18,7 @@ if (isset($error_message)) -
lang->line('suppliers_supplier').": ".$supplier; ?>
+
lang->line('suppliers_supplier').": ".$supplier; ?>
diff --git a/application/views/sales/receipt.php b/application/views/sales/receipt.php index 57dc7960d..d66b13875 100644 --- a/application/views/sales/receipt.php +++ b/application/views/sales/receipt.php @@ -18,11 +18,18 @@ if (isset($error_message)) -
lang->line('customers_customer').": ".$customer; ?>
+
lang->line('customers_customer').": ".$customer; ?>
lang->line('sales_id').": ".$sale_id; ?>
+ +
lang->line('recvs_invoice_number').": ".$invoice_number; ?>
+
lang->line('employees_employee').": ".$employee; ?>
diff --git a/application/views/sales/register.php b/application/views/sales/register.php index 4b93040ca..ec6fb9aba 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -35,26 +35,17 @@ if (isset($success)) 'item','id'=>'item','size'=>'40'));?> - @@ -212,6 +203,7 @@ else array('class'=>'thickbox none','title'=>$this->lang->line('sales_new_customer'))); ?> +
 
'add_payment_form')); ?>
+ + lang->line('sales_invoice_number').': ';?> + + 'sales_invoice_number','id'=>'sales_invoice_number','value'=>$invoice_number,'size'=>10));?> + + + + + + + + + + + + +
- lang->line('sales_payment').': ';?> - - -
+ lang->line('sales_payment').': ';?> + + +
lang->line( 'sales_amount_tendered' ).': '; ?> @@ -436,6 +442,11 @@ $(document).ready(function() { $.post('', {comment: $('#comment').val()}); }); + + $('#sales_invoice_number').keyup(function() + { + $.post('', {sales_invoice_number: $('#sales_invoice_number').val()}); + }); $('#email_receipt').change(function() { @@ -452,7 +463,7 @@ $(document).ready(function() }); $("#suspend_sale_button").click(function() - { + { if (confirm('lang->line("sales_confirm_suspend_sale"); ?>')) { $('#finish_sale_form').attr('action', ''); diff --git a/database/2.3_to_2.3.1.sql b/database/2.3_to_2.3.1.sql index 329ae79f6..b1ad0bea1 100644 --- a/database/2.3_to_2.3.1.sql +++ b/database/2.3_to_2.3.1.sql @@ -62,6 +62,10 @@ INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES ('reports_taxes', 1), ('reports_categories', 1), ('reports_payments', 1), +('reports_discounts', 1), +('reports_categories', 1), +('reports_payments', 1), +('reports_taxes', 1), ('customers', 1), ('employees', 1), ('giftcards', 1), @@ -77,12 +81,20 @@ INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES -- add config options for tax inclusive sales INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('tax_included', '0'), -('recv_invoice_format', ''); +('recv_invoice_format', ''), +('sales_invoice_format', ''); -- add invoice_number column to receivings table ALTER TABLE `ospos_receivings` ADD COLUMN `invoice_number` varchar(32) DEFAULT NULL, ADD UNIQUE `invoice_number` (`invoice_number`); +-- add invoice_number column to sales table +ALTER TABLE `ospos_sales` + ADD COLUMN `invoice_number` varchar(32) DEFAULT NULL, + ADD UNIQUE `invoice_number` (`invoice_number`); - +-- add invoice_number column to suspended sales table +ALTER TABLE `ospos_sales_suspended` + ADD COLUMN `invoice_number` varchar(32) DEFAULT NULL, + ADD UNIQUE `invoice_number` (`invoice_number`); diff --git a/database/database.sql b/database/database.sql index 4501965f1..7114510fc 100644 --- a/database/database.sql +++ b/database/database.sql @@ -38,6 +38,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('timezone', 'America/New_York'), ('website', ''), ('recv_invoice_format', ''), +('sales_invoice_format', ''), ('tax_included', '0'); -- -------------------------------------------------------- @@ -444,11 +445,13 @@ CREATE TABLE `ospos_sales` ( `customer_id` int(10) DEFAULT NULL, `employee_id` int(10) NOT NULL DEFAULT '0', `comment` text NOT NULL, + `invoice_number` varchar(32) DEFAULT NULL, `sale_id` int(10) NOT NULL AUTO_INCREMENT, `payment_type` varchar(512) DEFAULT NULL, PRIMARY KEY (`sale_id`), KEY `customer_id` (`customer_id`), - KEY `employee_id` (`employee_id`) + KEY `employee_id` (`employee_id`), + UNIQUE KEY `invoice_number` (`invoice_number`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; -- @@ -536,11 +539,13 @@ CREATE TABLE `ospos_sales_suspended` ( `customer_id` int(10) DEFAULT NULL, `employee_id` int(10) NOT NULL DEFAULT '0', `comment` text NOT NULL, + `invoice_number` varchar(32) DEFAULT NULL, `sale_id` int(10) NOT NULL AUTO_INCREMENT, `payment_type` varchar(512) DEFAULT NULL, PRIMARY KEY (`sale_id`), KEY `customer_id` (`customer_id`), - KEY `employee_id` (`employee_id`) + KEY `employee_id` (`employee_id`), + UNIQUE KEY `invoice_number` (`invoice_number`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; -- From 3007173833b5b602d3d6b78118e0e633eaf9b72a Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Thu, 30 Oct 2014 19:22:49 +0100 Subject: [PATCH 2/6] Add invoice numbering to sales module --- application/models/stock_locations.php | 4 +++- application/views/receivings/form.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index 96349648d..b7950c5f7 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -122,10 +122,12 @@ class Stock_locations extends CI_Model { $this->db->where('location_id', $location_id); $this->db->update('stock_locations', array('deleted' => 1)); + + $this->db->delete('permissions', array('permission_id' => 'items_'.$location_name)); } } return true; } } -?> +?> \ No newline at end of file diff --git a/application/views/receivings/form.php b/application/views/receivings/form.php index 0570c2ccf..19383a8df 100755 --- a/application/views/receivings/form.php +++ b/application/views/receivings/form.php @@ -88,7 +88,7 @@ $(document).ready(function() success=response.success; }, async:false, - dataType: 'json' + dataType: 'json' }).response).success; }, 'lang->line("recvs_invoice_number_duplicate"); ?>'); From 54fe0c4c30cbce87a1a14e394a6a59a9b8cac795 Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Mon, 3 Nov 2014 19:22:36 +0100 Subject: [PATCH 3/6] Fix sales/receivings deletion --- application/controllers/receivings.php | 4 +-- application/controllers/sales.php | 4 +-- application/language/en/receivings_lang.php | 7 +++-- application/language/en/sales_lang.php | 5 ++-- application/views/sales/form.php | 29 +++++++++++++++++++++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index 9fd363f86..cb18ad937 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -149,12 +149,12 @@ class Receivings extends Secure_area if($this->Receiving->delete_list($receiving_ids, $employee_id, $update_inventory)) { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('recvs_delete_successful').' '. + echo json_encode(array('success'=>true,'message'=>$this->lang->line('recvs_successfully_deleted').' '. count($receiving_ids).' '.$this->lang->line('recvs_one_or_multiple'),'ids'=>$receiving_ids)); } else { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('recvs_delete_unsuccessful'))); + echo json_encode(array('success'=>false,'message'=>$this->lang->line('recvs_cannot_be_deleted'))); } } diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 8e5b9766c..73f0f30c0 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -351,12 +351,12 @@ class Sales extends Secure_area if($this->Sale->delete_list($sale_ids, $employee_id, $update_inventory)) { - echo json_encode(array('success'=>true,'message'=>$this->lang->line('sales_delete_successful').' '. + echo json_encode(array('success'=>true,'message'=>$this->lang->line('sales_successfully_deleted').' '. count($sale_ids).' '.$this->lang->line('sales_one_or_multiple'),'ids'=>$sale_ids)); } else { - echo json_encode(array('success'=>false,'message'=>$this->lang->line('sales_delete_unsuccessful'))); + echo json_encode(array('success'=>false,'message'=>$this->lang->line('sales_unsuccessfully_deleted'))); } } diff --git a/application/language/en/receivings_lang.php b/application/language/en/receivings_lang.php index 0babf19b8..33624c580 100644 --- a/application/language/en/receivings_lang.php +++ b/application/language/en/receivings_lang.php @@ -45,8 +45,9 @@ $lang['recvs_date'] = 'Receiving Date'; $lang['recvs_successfully_updated'] = 'Receiving successfully updated'; $lang['recvs_unsuccessfully_updated'] = 'Receiving unsuccessfully updated'; $lang['recvs_edit_sale'] = 'Edit Receiving'; -$lang['recvs_successfully_deleted'] = 'Receiving successfully deleted'; -$lang['recvs_unsuccessfully_deleted'] = 'Receiving unsuccessfully deleted'; + +$lang['recvs_successfully_deleted']='You have successfully deleted'; + $lang['recvs_delete_entire_sale'] = 'Delete entire sale'; $lang['recvs_comments'] = 'Comments'; $lang['recvs_basic_information']='Receiving information'; @@ -56,4 +57,6 @@ $lang['recvs_date_required']='A correct date needs to be filled in'; $lang['recvs_date_type']='Date field is required'; $lang['recvs_delete_confirmation'] = 'Are you sure you want to delete this receiving, this action cannot be undone'; $lang['recvs_invoice_number_duplicate'] = 'Please enter an unique invoice number'; +$lang['recvs_one_or_multiple']='receiving(s)'; +$lang['recvs_cannot_be_deleted'] = 'Receiving(s) could not be deleted'; ?> \ No newline at end of file diff --git a/application/language/en/sales_lang.php b/application/language/en/sales_lang.php index fe682f3ba..d3a6be9f8 100644 --- a/application/language/en/sales_lang.php +++ b/application/language/en/sales_lang.php @@ -57,8 +57,8 @@ $lang['sales_successfully_updated'] = 'Sale successfully updated'; $lang['sales_unsuccessfully_updated'] = 'Sale unsuccessfully updated'; $lang['sales_edit_sale'] = 'Edit Sale'; $lang['sales_employee'] = 'Employee'; -$lang['sales_successfully_deleted'] = 'Sale successfully deleted'; -$lang['sales_unsuccessfully_deleted'] = 'Sale unsuccessfully deleted'; +$lang['sales_successfully_deleted'] = 'You have successfully deleted'; +$lang['sales_cannot_be_deleted'] = 'Sale(s) could not be deleted'; $lang['sales_delete_entire_sale'] = 'Delete entire sale'; $lang['sales_delete_confirmation'] = 'Are you sure you want to delete this sale, this action cannot be undone'; $lang['sales_date'] = 'Sale Date'; @@ -91,4 +91,5 @@ $lang['sales_invoice_number']='Invoice #'; $lang['sales_date_required']='A correct date needs to be filled in'; $lang['sales_date_type']='Date field is required'; $lang['sales_invoice_number_duplicate'] = 'Please enter an unique invoice number'; +$lang['sales_one_or_multiple']='sale(s)'; ?> diff --git a/application/views/sales/form.php b/application/views/sales/form.php index 7d8f659a2..55d0d0af0 100755 --- a/application/views/sales/form.php +++ b/application/views/sales/form.php @@ -20,6 +20,13 @@ +
+ lang->line('sales_invoice_number').':', 'invoice_number'); ?> +
+ 'invoice_number', 'value' => $sale_info['invoice_number'], 'id' => 'invoice_number'));?> +
+
+
lang->line('sales_customer').':', 'customer'); ?>
@@ -67,6 +74,25 @@ $(document).ready(function() { + + $.validator.addMethod("invoice_number", function(value, element) + { + var id = $("input[name='sale_id']").val(); + + return JSON.parse($.ajax( + { + type: 'POST', + url: '', + data: {'sale_id' : id, 'invoice_number' : $(element).val() }, + success: function(response) + { + success=response.success; + }, + async:false, + dataType: 'json' + }).response).success; + }, 'lang->line("sales_invoice_number_duplicate"); ?>'); + $('#date').datePicker({startDate: '01/01/1970'}); $("#sales_delete_form").submit(function() { @@ -131,6 +157,9 @@ $(document).ready(function() { required:true, date:true + }, + invoice_number: { + invoice_number: true } }, messages: From 094a293c78915b57054489dc46ff7cfda0b56071 Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Thu, 6 Nov 2014 07:35:54 +0100 Subject: [PATCH 4/6] Fix invoice number insert in receivings --- application/controllers/receivings.php | 2 +- application/models/receiving.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index cb18ad937..43a250876 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -203,7 +203,7 @@ class Receivings extends Secure_area $data['invoice_number']=$invoice_number; $data['payment_type']=$this->input->post('payment_type'); //SAVE receiving to database - $data['receiving_id']='RECV '.$this->Receiving->save($data['cart'], $supplier_id,$employee_id,$comment,$payment_type,$data['stock_location'],$invoice_number); + $data['receiving_id']='RECV '.$this->Receiving->save($data['cart'], $supplier_id,$employee_id,$comment,$invoice_number,$payment_type,$data['stock_location']); if ($data['receiving_id'] == 'RECV -1') { diff --git a/application/models/receiving.php b/application/models/receiving.php index 38de653da..7204249b2 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -40,7 +40,7 @@ class Receiving extends CI_Model return $success; } - function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$receiving_id=false,$invoice_number=NULL) + function save ($items,$supplier_id,$employee_id,$comment,$invoice_number,$payment_type,$receiving_id=false) { if(count($items)==0) return -1; From 1b41c93441eb5cc3fdfffed7d30b34b60f357f7e Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Fri, 7 Nov 2014 18:03:45 +0100 Subject: [PATCH 5/6] Fix item row refresh in detailed receivings and sales --- js/manage_tables.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/manage_tables.js b/js/manage_tables.js index eb6baf176..eca555372 100644 --- a/js/manage_tables.js +++ b/js/manage_tables.js @@ -277,7 +277,11 @@ function get_table_row(id) { id = id || $("input[name='sale_id']").val(); var $element = $("#sortable_table tbody :checkbox[value='" + id + "']"); if ($element.index() === -1) { - $element = $("#sortable_table tbody a[href*='" + id + "']"); + // parse link + var row_id = $("#sortable_table tbody a").each(function(index, element) { + var result = $(element).attr("href").match(/\/(\d+)\//); + $element = result && result[1] == id ? $(element) : $element; + }); } return $element; } From 4893da0e43cfec94a819fa02ebf217fa041d8c8f Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Thu, 13 Nov 2014 13:10:21 +0100 Subject: [PATCH 6/6] Added enable invoice checkbox --- application/controllers/config.php | 3 +++ application/language/en/config_lang.php | 2 ++ application/language/en/receivings_lang.php | 1 + application/language/en/sales_lang.php | 1 + application/views/config.php | 22 ++++++++++++++++++ application/views/receivings/receiving.php | 25 +++++++++++++++++++++ application/views/sales/register.php | 24 ++++++++++++++++++++ database/2.3_to_2.3.1.sql | 4 +++- database/database.sql | 5 ++++- 9 files changed, 85 insertions(+), 2 deletions(-) diff --git a/application/controllers/config.php b/application/controllers/config.php index 8895bd595..d70bafde3 100644 --- a/application/controllers/config.php +++ b/application/controllers/config.php @@ -39,7 +39,10 @@ class Config extends Secure_area 'timezone'=>$this->input->post('timezone'), 'print_after_sale'=>$this->input->post('print_after_sale'), 'tax_included'=>$this->input->post('tax_included'), + 'recv_invoice_enable'=>$this->input->post('recv_invoice_enable'), 'recv_invoice_format'=>$this->input->post('recv_invoice_format'), + 'sales_invoice_enable'=>$this->input->post('sales_invoice_enable'), + 'sales_invoice_format'=>$this->input->post('sales_invoice_format'), 'custom1_name'=>$this->input->post('custom1_name'),/**GARRISON ADDED 4/20/2013**/ 'custom2_name'=>$this->input->post('custom2_name'),/**GARRISON ADDED 4/20/2013**/ 'custom3_name'=>$this->input->post('custom3_name'),/**GARRISON ADDED 4/20/2013**/ diff --git a/application/language/en/config_lang.php b/application/language/en/config_lang.php index 89ea76ad3..f3136a7c3 100644 --- a/application/language/en/config_lang.php +++ b/application/language/en/config_lang.php @@ -36,7 +36,9 @@ $lang['config_custom10'] = 'Custom Field 10'; //GARRISON ADDED 4/21/2013 $lang['config_stock_location'] = 'Stock location'; $lang['config_stock_location_required'] = 'Stock location number is a required field'; $lang['config_tax_included'] = 'Tax Included'; +$lang['config_recv_invoice_enable'] = 'Enable Recvs Inv#'; $lang['config_recv_invoice_format'] = 'Receivings Invoice'; +$lang['config_sales_invoice_enable'] = 'Enable Sales Inv#'; $lang['config_sales_invoice_format'] = 'Sales Invoice'; ?> \ No newline at end of file diff --git a/application/language/en/receivings_lang.php b/application/language/en/receivings_lang.php index 33624c580..668e2bcf9 100644 --- a/application/language/en/receivings_lang.php +++ b/application/language/en/receivings_lang.php @@ -59,4 +59,5 @@ $lang['recvs_delete_confirmation'] = 'Are you sure you want to delete this recei $lang['recvs_invoice_number_duplicate'] = 'Please enter an unique invoice number'; $lang['recvs_one_or_multiple']='receiving(s)'; $lang['recvs_cannot_be_deleted'] = 'Receiving(s) could not be deleted'; +$lang['recvs_invoice_enable']='Create Invoice'; ?> \ No newline at end of file diff --git a/application/language/en/sales_lang.php b/application/language/en/sales_lang.php index d3a6be9f8..00814dbc7 100644 --- a/application/language/en/sales_lang.php +++ b/application/language/en/sales_lang.php @@ -92,4 +92,5 @@ $lang['sales_date_required']='A correct date needs to be filled in'; $lang['sales_date_type']='Date field is required'; $lang['sales_invoice_number_duplicate'] = 'Please enter an unique invoice number'; $lang['sales_one_or_multiple']='sale(s)'; +$lang['sales_invoice_enable']='Create Invoice'; ?> diff --git a/application/views/config.php b/application/views/config.php index c0a0f6ba4..ee1b7db58 100644 --- a/application/views/config.php +++ b/application/views/config.php @@ -268,6 +268,17 @@ echo form_open('config/save/',array('id'=>'config_form'));
+
+lang->line('config_sales_invoice_enable').':', 'sales_invoice_enable',array('class'=>'wide')); ?> +
+ 'sales_invoice_enable', + 'id'=>'sales_invoice_enable', + 'value'=>'sales_invoice_enable', + 'checked'=>$this->config->item('sales_invoice_enable')));?> +
+
+
lang->line('config_sales_invoice_format').':', 'sales_invoice_format',array('class'=>'wide')); ?>
@@ -278,6 +289,17 @@ echo form_open('config/save/',array('id'=>'config_form'));
+
+lang->line('config_recv_invoice_enable').':', 'recv_invoice_enable',array('class'=>'wide')); ?> +
+ 'recv_invoice_enable', + 'id'=>'recv_invoice_enable', + 'value'=>'recv_invoice_enable', + 'checked'=>$this->config->item('recv_invoice_enable')));?> +
+
+
lang->line('config_recv_invoice_format').':', 'recv_invoice_format',array('class'=>'wide')); ?>
diff --git a/application/views/receivings/receiving.php b/application/views/receivings/receiving.php index 4f30311cf..4b6c0c8c2 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -224,6 +224,15 @@ else +
+ lang->line('recvs_invoice_enable'); ?> + + 'recv_invoice_enable','id'=>'recv_invoice_enable','size'=>10,'checked'=>$this->config->item('recv_invoice_enable')));?> +
lang->line('recvs_invoice_number').': ';?> @@ -342,6 +351,22 @@ $(document).ready(function() $.post('', {recv_invoice_number: $('#recv_invoice_number').val()}); }); + var enable_invoice_number = function() + { + if ($("#recv_invoice_enable").is(":checked")) + { + $("#recv_invoice_number").removeAttr("disabled").parents('tr').show(); + } + else + { + $("#recv_invoice_number").attr("disabled", "disabled").parents('tr').hide(); + } + } + + enable_invoice_number(); + + $("#recv_invoice_enable").change(enable_invoice_number); + $("#finish_sale_button").click(function() { if (confirm('lang->line("recvs_confirm_finish_receiving"); ?>')) diff --git a/application/views/sales/register.php b/application/views/sales/register.php index ec6fb9aba..7a9bd26aa 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -300,6 +300,14 @@ else +
+ lang->line('sales_invoice_enable'); ?> + + 'sales_invoice_enable','id'=>'sales_invoice_enable','size'=>10,'checked'=>$this->config->item('sales_invoice_enable')));?> +
lang->line('sales_invoice_number').': ';?> @@ -447,6 +455,22 @@ $(document).ready(function() { $.post('', {sales_invoice_number: $('#sales_invoice_number').val()}); }); + + var enable_invoice_number = function() + { + if ($("#sales_invoice_enable").is(":checked")) + { + $("#sales_invoice_number").removeAttr("disabled").parents('tr').show(); + } + else + { + $("#sales_invoice_number").attr("disabled", "disabled").parents('tr').hide(); + } + } + + enable_invoice_number(); + + $("#sales_invoice_enable").change(enable_invoice_number); $('#email_receipt').change(function() { diff --git a/database/2.3_to_2.3.1.sql b/database/2.3_to_2.3.1.sql index b1ad0bea1..ce3effa2f 100644 --- a/database/2.3_to_2.3.1.sql +++ b/database/2.3_to_2.3.1.sql @@ -82,7 +82,9 @@ INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('tax_included', '0'), ('recv_invoice_format', ''), -('sales_invoice_format', ''); +('sales_invoice_format', ''), +('sales_invoice_enable', '1'), +('recv_invoice_enable', '1'); -- add invoice_number column to receivings table ALTER TABLE `ospos_receivings` diff --git a/database/database.sql b/database/database.sql index 7114510fc..d1611aaa9 100644 --- a/database/database.sql +++ b/database/database.sql @@ -39,7 +39,10 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('website', ''), ('recv_invoice_format', ''), ('sales_invoice_format', ''), -('tax_included', '0'); +('tax_included', '0'), +('recv_invoice_enable', '1'), +('sales_invoice_enable', '1'); + -- --------------------------------------------------------