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/controllers/items.php b/application/controllers/items.php index 40014154c..d146d8cae 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..43a250876 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); } @@ -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'))); } } @@ -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/controllers/sales.php b/application/controllers/sales.php index c5eb5df22..73f0f30c0 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; @@ -299,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'))); } } @@ -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..f3136a7c3 100644 --- a/application/language/en/config_lang.php +++ b/application/language/en/config_lang.php @@ -36,6 +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 0babf19b8..668e2bcf9 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,7 @@ $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'; +$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 83dc494ce..00814dbc7 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'; @@ -87,6 +87,10 @@ $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'; +$lang['sales_one_or_multiple']='sale(s)'; +$lang['sales_invoice_enable']='Create Invoice'; ?> diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index fb223ea67..3cb32cd66 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -1,397 +1,363 @@ -CI =& get_instance(); + } + + function get_cart() + { + if(!$this->CI->session->userdata('cartRecv')) + $this->set_cart(array()); + + return $this->CI->session->userdata('cartRecv'); + } + + function set_cart($cart_data) + { + $this->CI->session->set_userdata('cartRecv',$cart_data); + } + + function get_supplier() + { + if(!$this->CI->session->userdata('supplier')) + $this->set_supplier(-1); + + return $this->CI->session->userdata('supplier'); + } + + function set_supplier($supplier_id) + { + $this->CI->session->set_userdata('supplier',$supplier_id); + } - function __construct() - { - $this->CI =& get_instance(); - } - - function get_cart() - { - if(!$this->CI->session->userdata('cartRecv')) - $this->set_cart(array()); - - return $this->CI->session->userdata('cartRecv'); - } - - function set_cart($cart_data) - { - $this->CI->session->set_userdata('cartRecv',$cart_data); - } - - function get_supplier() - { - if(!$this->CI->session->userdata('supplier')) - $this->set_supplier(-1); - - return $this->CI->session->userdata('supplier'); - } - - function set_supplier($supplier_id) - { - $this->CI->session->set_userdata('supplier',$supplier_id); - } - - function get_receiving_id() - { - return $this->CI->session->userdata('receiving_id'); - } - - function set_receiving_id($receiving_id) - { - $this->CI->session->set_userdata('receiving_id', $receiving_id); - } - - function clear_receiving_id() - { - $this->CI->session->unset_userdata('receiving_id'); - } - - function get_mode() - { - if(!$this->CI->session->userdata('recv_mode')) - $this->set_mode('receive'); - - return $this->CI->session->userdata('recv_mode'); - } - - function set_mode($mode) - { - $this->CI->session->set_userdata('recv_mode',$mode); - } + function get_mode() + { + if(!$this->CI->session->userdata('recv_mode')) + $this->set_mode('receive'); + + return $this->CI->session->userdata('recv_mode'); + } + + function set_mode($mode) + { + $this->CI->session->set_userdata('recv_mode',$mode); + } + + function get_stock_source() + { + if(!$this->CI->session->userdata('recv_stock_source')) + { + $location_id = $this->CI->Stock_locations->get_default_location_id(); + $this->set_stock_source($location_id); + } + return $this->CI->session->userdata('recv_stock_source'); + } + + function get_comment() + { + return $this->CI->session->userdata('comment'); + } + + function set_comment($comment) + { + $this->CI->session->set_userdata('comment', $comment); + } + + function clear_comment() + { + $this->CI->session->unset_userdata('comment'); + } + + function get_invoice_number() + { + return $this->CI->session->userdata('recv_invoice_number'); + } + + function set_invoice_number($invoice_number) + { + $this->CI->session->set_userdata('recv_invoice_number', $invoice_number); + } + + function clear_invoice_number() + { + $this->CI->session->unset_userdata('recv_invoice_number'); + } + + function set_stock_source($stock_source) + { + $this->CI->session->set_userdata('recv_stock_source',$stock_source); + } + + function clear_stock_source() + { + $this->CI->session->unset_userdata('recv_stock_source'); + } + + function get_stock_destination() + { + if(!$this->CI->session->userdata('recv_stock_destination')) + { + $location_id = $this->CI->Stock_locations->get_default_location_id(); + $this->set_stock_destination($location_id); + } + return $this->CI->session->userdata('recv_stock_destination'); + } + + function set_stock_destination($stock_destination) + { + $this->CI->session->set_userdata('recv_stock_destination',$stock_destination); + } + + function clear_stock_destination() + { + $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. + if(!$this->CI->Item->exists($item_id)) + { + //try to get item id given an item_number + $item_id = $this->CI->Item->get_item_id($item_id); + + if(!$item_id) + return false; + } + + //Get items in the receiving so far. + $items = $this->get_cart(); + + //We need to loop through all items in the cart. + //If the item is already there, get it's key($updatekey). + //We also need to get the next key that we are going to use in case we need to add the + //item to the list. Since items can be deleted, we can't use a count. we use the highest key + 1. + + $maxkey=0; //Highest key so far + $itemalreadyinsale=FALSE; //We did not find the item yet. + $insertkey=0; //Key to use for new entry. + $updatekey=0; //Key to use to update(quantity) + + foreach ($items as $item) + { + //We primed the loop so maxkey is 0 the first time. + //Also, we have stored the key in the element itself so we can compare. + //There is an array function to get the associated key for an element, but I like it better + //like that! + + if($maxkey <= $item['line']) + { + $maxkey = $item['line']; + } + + if($item['item_id']==$item_id && $item['item_location']==$item_location) + { + $itemalreadyinsale=TRUE; + $updatekey=$item['line']; + } + } + + $insertkey=$maxkey+1; + $item_info=$this->CI->Item->get_info($item_id,$item_location); + //array records are identified by $insertkey and item_id is just another field. + $item = array(($insertkey)=> + array( + 'item_id'=>$item_id, + 'item_location'=>$item_location, + 'stock_name'=>$this->CI->Stock_locations->get_location_name($item_location), + 'line'=>$insertkey, + 'name'=>$item_info->name, + 'description'=>$description!=null ? $description: $item_info->description, + 'serialnumber'=>$serialnumber!=null ? $serialnumber: '', + 'allow_alt_description'=>$item_info->allow_alt_description, + 'is_serialized'=>$item_info->is_serialized, + 'quantity'=>$quantity, + 'discount'=>$discount, + 'in_stock'=>$this->CI->Item_quantities->get_item_quantity($item_id, $item_location)->quantity, + 'price'=>$price!=null ? $price: $item_info->cost_price + ) + ); + + //Item already exists + if($itemalreadyinsale) + { + $items[$updatekey]['quantity']+=$quantity; + } + else + { + //add to existing array + $items+=$item; + } + + $this->set_cart($items); + return true; + + } + + function edit_item($line,$description,$serialnumber,$quantity,$discount,$price) + { + $items = $this->get_cart(); + if(isset($items[$line])) + { + $items[$line]['description'] = $description; + $items[$line]['serialnumber'] = $serialnumber; + $items[$line]['quantity'] = $quantity; + $items[$line]['discount'] = $discount; + $items[$line]['price'] = $price; + $this->set_cart($items); + } + + return false; + } + + function is_valid_receipt($receipt_receiving_id) + { + //RECV # + $pieces = explode(' ',$receipt_receiving_id); + + if(count($pieces)==2) + { + return $this->CI->Receiving->exists($pieces[1]); + } + else + { + return $this->CI->Receiving->get_receiving_by_invoice_number($receipt_receiving_id)->num_rows() > 0; + } + + return false; + } + + function is_valid_item_kit($item_kit_id) + { + //KIT # + $pieces = explode(' ',$item_kit_id); + + if(count($pieces)==2) + { + return $this->CI->Item_kit->exists($pieces[1]); + } + + return false; + } + + function return_entire_receiving($receipt_receiving_id) + { + //POS # + $pieces = explode(' ',$receipt_receiving_id); + if ($pieces[0] == "RECV") + { + $receiving_id = $pieces[1]; + } + else + { + $receiving = $this->CI->Receiving->get_receiving_by_invoice_number($receipt_receiving_id)->row(); + $receiving_id = $receiving->receiving_id; + } + + $this->empty_cart(); + $this->delete_supplier(); + $this->clear_comment(); + + foreach($this->CI->Receiving->get_receiving_items($receiving_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->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); + } + + function add_item_kit($external_item_kit_id,$item_location) + { + //KIT # + $pieces = explode(' ',$external_item_kit_id); + $item_kit_id = $pieces[1]; + + foreach ($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) + { + $this->add_item($item_kit_item['item_id'],$item_kit_item['quantity'],$item_location); + } + } + + function copy_entire_receiving($receiving_id) + { + $this->empty_cart(); + $this->delete_supplier(); + + foreach($this->CI->Receiving->get_receiving_items($receiving_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->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) + { + $this->empty_cart(); + $this->delete_supplier(); + + foreach($this->CI->Receiving->get_requisition_items($requisition_id)->result() as $row) + { + $this->add_item_unit($row->item_id,$row->requisition_quantity,$item_location,$row->description); + } + $this->set_supplier($this->CI->Receiving->get_supplier($requisition_id)->person_id); + $receiving_info=$this->CI->Receiving->get_info($receiving_id); + //$this->set_invoice_number($receiving_info->row()->invoice_number); + } + + function delete_item($line) + { + $items=$this->get_cart(); + unset($items[$line]); + $this->set_cart($items); + } + + function empty_cart() + { + $this->CI->session->unset_userdata('cartRecv'); + } + + function delete_supplier() + { + $this->CI->session->unset_userdata('supplier'); + } - function get_stock_source() - { - if(!$this->CI->session->userdata('recv_stock_source')) - { - $location_id = $this->CI->Stock_locations->get_default_location_id(); - $this->set_stock_source($location_id); - } - return $this->CI->session->userdata('recv_stock_source'); - } - - function get_comment() - { - return $this->CI->session->userdata('comment'); - } - - function set_comment($comment) - { - $this->CI->session->set_userdata('comment', $comment); - } - - function clear_comment() - { - $this->CI->session->unset_userdata('comment'); - } - - function get_invoice_number() - { - return $this->CI->session->userdata('recv_invoice_number'); - } - - function set_invoice_number($invoice_number) - { - $this->CI->session->set_userdata('recv_invoice_number', $invoice_number); - } - - function clear_invoice_number() - { - $this->CI->session->unset_userdata('recv_invoice_number'); - } - - function set_stock_source($stock_source) - { - $this->CI->session->set_userdata('recv_stock_source',$stock_source); - } - - function clear_stock_source() - { - $this->CI->session->unset_userdata('recv_stock_source'); - } - - function get_stock_destination() - { - if(!$this->CI->session->userdata('recv_stock_destination')) - { - $location_id = $this->CI->Stock_locations->get_default_location_id(); - $this->set_stock_destination($location_id); - } - return $this->CI->session->userdata('recv_stock_destination'); - } - - function set_stock_destination($stock_destination) - { - $this->CI->session->set_userdata('recv_stock_destination',$stock_destination); - } - - function clear_stock_destination() - { - $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. - if(!$this->CI->Item->exists($item_id)) - { - //try to get item id given an item_number - $item_id = $this->CI->Item->get_item_id($item_id); - - if(!$item_id) - return false; - } - - //Get items in the receiving so far. - $items = $this->get_cart(); - - //We need to loop through all items in the cart. - //If the item is already there, get it's key($updatekey). - //We also need to get the next key that we are going to use in case we need to add the - //item to the list. Since items can be deleted, we can't use a count. we use the highest key + 1. - - $maxkey=0; //Highest key so far - $itemalreadyinsale=FALSE; //We did not find the item yet. - $insertkey=0; //Key to use for new entry. - $updatekey=0; //Key to use to update(quantity) - - foreach ($items as $item) - { - //We primed the loop so maxkey is 0 the first time. - //Also, we have stored the key in the element itself so we can compare. - //There is an array function to get the associated key for an element, but I like it better - //like that! - - if($maxkey <= $item['line']) - { - $maxkey = $item['line']; - } - - if($item['item_id']==$item_id && $item['item_location']==$item_location) - { - $itemalreadyinsale=TRUE; - $updatekey=$item['line']; - } - } - - $insertkey=$maxkey+1; - $item_info=$this->CI->Item->get_info($item_id,$item_location); - //array records are identified by $insertkey and item_id is just another field. - $item = array(($insertkey)=> - array( - 'item_id'=>$item_id, - 'item_location'=>$item_location, - 'stock_name'=>$this->CI->Stock_locations->get_location_name($item_location), - 'line'=>$insertkey, - 'name'=>$item_info->name, - 'description'=>$description!=null ? $description: $item_info->description, - 'serialnumber'=>$serialnumber!=null ? $serialnumber: '', - 'allow_alt_description'=>$item_info->allow_alt_description, - 'is_serialized'=>$item_info->is_serialized, - 'quantity'=>$quantity, - 'receiving_quantity'=>$item_info->receiving_quantity, - 'discount'=>$discount, - 'in_stock'=>$this->CI->Item_quantities->get_item_quantity($item_id, $item_location)->quantity, - 'price'=>$price!=null ? $price: $item_info->cost_price - ) - ); - - //Item already exists - if($itemalreadyinsale) - { - $items[$updatekey]['quantity']+=$quantity; - } - else - { - //add to existing array - $items+=$item; - } - - $this->set_cart($items); - return true; - - } - - function edit_item($line,$description,$serialnumber,$quantity,$discount,$price) - { - $items = $this->get_cart(); - if(isset($items[$line])) - { - $items[$line]['description'] = $description; - $items[$line]['serialnumber'] = $serialnumber; - $items[$line]['quantity'] = $quantity; - $items[$line]['discount'] = $discount; - $items[$line]['price'] = $price; - $this->set_cart($items); - } - - return false; - } - - function is_valid_receipt($receipt_receiving_id) - { - //RECV # - $pieces = explode(' ',$receipt_receiving_id); - - if(count($pieces)==2) - { - return $this->CI->Receiving->exists($pieces[1]); - } - else - { - return $this->CI->Receiving->get_receiving_by_invoice_number($receipt_receiving_id)->num_rows() > 0; - } - - return false; - } - - function is_valid_item_kit($item_kit_id) - { - //KIT # - $pieces = explode(' ',$item_kit_id); - - if(count($pieces)==2) - { - return $this->CI->Item_kit->exists($pieces[1]); - } - - return false; - } - - function return_entire_receiving($receipt_receiving_id) - { - //POS # - $pieces = explode(' ',$receipt_receiving_id); - if ($pieces[0] == "RECV") - { - $receiving_id = $pieces[1]; - } - else - { - $receiving = $this->CI->Receiving->get_receiving_by_invoice_number($receipt_receiving_id)->row(); - $receiving_id = $receiving->receiving_id; - } - - $this->empty_cart(); - $this->delete_supplier(); - $this->clear_comment(); - - foreach($this->CI->Receiving->get_receiving_items($receiving_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->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); - //$this->set_invoice_number($this->CI->Receiving->get_invoice_number($receiving_id)); - } - - function add_item_kit($external_item_kit_id,$item_location) - { - //KIT # - $pieces = explode(' ',$external_item_kit_id); - $item_kit_id = $pieces[1]; - - foreach ($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) - { - $this->add_item($item_kit_item['item_id'],$item_kit_item['quantity'],$item_location); - } - } - - function copy_entire_receiving($receiving_id) - { - $this->empty_cart(); - $this->delete_supplier(); - - foreach($this->CI->Receiving->get_receiving_items($receiving_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->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); - } - - function copy_entire_requisition($requisition_id,$item_location) - { - $this->empty_cart(); - $this->delete_supplier(); - - foreach($this->CI->Receiving->get_requisition_items($requisition_id)->result() as $row) - { - $this->add_item_unit($row->item_id,$row->requisition_quantity,$item_location,$row->description); - } - $this->set_supplier($this->CI->Receiving->get_supplier($requisition_id)->person_id); - $receiving_info=$this->CI->Receiving->get_info($receiving_id); - //$this->set_invoice_number($receiving_info->row()->invoice_number); - } - - function copy_entire_receiving_inv($receiving_id) - { - $this->empty_cart(); - $this->delete_supplier(); - - foreach($this->CI->Receiving_inv->get_receiving_items($receiving_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->set_supplier($this->CI->Receiving_inv->get_supplier($receiving_id)->person_id); - $this->set_invoice_number($this->CI->Receiving_inv->get_invoice_number($receiving_id)); - $this->set_comment($this->CI->Receiving_inv->get_comment($receiving_id)); - } - - function delete_item($line) - { - $items=$this->get_cart(); - unset($items[$line]); - $this->set_cart($items); - } - - function empty_cart() - { - $this->CI->session->unset_userdata('cartRecv'); - } - - function delete_supplier() - { - $this->CI->session->unset_userdata('supplier'); - } - - /*function delete_invoice_number() - { - $this->CI->session->unset_userdata('recv_invoice_number'); - }*/ - - function clear_mode() - { - $this->CI->session->unset_userdata('receiving_mode'); - } - - function clear_all() - { - $this->clear_mode(); - $this->empty_cart(); - $this->delete_supplier(); - $this->clear_comment(); - $this->clear_invoice_number(); - } - - function get_item_total($quantity, $receiving_quantity, $price, $discount_percentage) - { - $total = bcmul($quantity, $price, PRECISION); - $total = bcmul($receiving_quantity, $total, PRECISION); - $discount_fraction = bcdiv($discount_percentage, 100, PRECISION); - $discount_amount = bcmul($total, $discount_fraction, PRECISION); - return bcsub($total, $discount_amount, PRECISION); - } - - function get_total() - { - $total = 0; - foreach($this->get_cart() as $item) - { - $total += $this->get_item_total($item['quantity'], $item['receiving_quantity'], $item['price'], $item['discount']); - } - - return $total; - } -} + function clear_mode() + { + $this->CI->session->unset_userdata('receiving_mode'); + } + + function clear_all() + { + $this->clear_mode(); + $this->empty_cart(); + $this->delete_supplier(); + $this->clear_comment(); + $this->clear_invoice_number(); + } + + function get_item_total($quantity, $price, $discount_percentage) + { + $total = bcmul($quantity, $price, PRECISION); + $discount_fraction = bcdiv($discount_percentage, 100, PRECISION); + $discount_amount = bcmul($total, $discount_fraction, PRECISION); + return bcsub($total, $discount_amount, PRECISION); + } + + function get_total() + { + $total = 0; + foreach($this->get_cart() as $item) + { + $total += $this->get_item_total($item['quantity'], $item['price'], $item['discount']); + } + + return $total; + } +} ?> 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..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; @@ -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/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/config.php b/application/views/config.php index b441f5408..ee1b7db58 100644 --- a/application/views/config.php +++ b/application/views/config.php @@ -268,6 +268,38 @@ 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')); ?> +
+ 'sales_invoice_format', + 'id'=>'sales_invoice_format', + 'value'=>$this->config->item('sales_invoice_format'))); ?> +
+
+ +
+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/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"); ?>'); 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/receivings/receiving.php b/application/views/receivings/receiving.php index 1e5e6eb3b..e77847fd4 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -238,6 +238,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').': ';?> @@ -356,6 +365,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/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: 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 8c6a0404d..10d70e6b1 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'));?> - @@ -211,6 +202,7 @@ else array('class'=>'thickbox none','title'=>$this->lang->line('sales_new_customer'))); ?> +
 
'add_payment_form')); ?>
+ + lang->line('sales_invoice_enable'); ?> + + 'sales_invoice_enable','id'=>'sales_invoice_enable','size'=>10,'checked'=>$this->config->item('sales_invoice_enable')));?> + + + + + + + + + +
- lang->line('sales_payment').': ';?> - - -
+ lang->line('sales_invoice_number').': ';?> + + 'sales_invoice_number','id'=>'sales_invoice_number','value'=>$invoice_number,'size'=>10));?> +
+ lang->line('sales_payment').': ';?> + + +
lang->line( 'sales_amount_tendered' ).': '; ?> @@ -438,6 +452,27 @@ $(document).ready(function() { $.post('', {comment: $('#comment').val()}); }); + + $('#sales_invoice_number').keyup(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() { @@ -454,7 +489,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 bf5fdea88..37e008487 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` @@ -99,6 +101,6 @@ ALTER TABLE `ospos_sales_suspended` ADD COLUMN `invoice_number` varchar(32) DEFAULT NULL, ADD UNIQUE `invoice_number` (`invoice_number`); - -- add invoice_number column to receivings table +-- add invoice_number column to receivings table ALTER TABLE `ospos_items` - ADD COLUMN `receiving_quantity` int(11) DEFAULT '1'; \ No newline at end of file + ADD COLUMN `receiving_quantity` int(11) DEFAULT '1'; diff --git a/database/database.sql b/database/database.sql index 64f2f163c..506e5e123 100644 --- a/database/database.sql +++ b/database/database.sql @@ -38,7 +38,11 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('timezone', 'America/New_York'), ('website', ''), ('recv_invoice_format', ''), -('tax_included', '0'); +('sales_invoice_format', ''), +('tax_included', '0'), +('recv_invoice_enable', '1'), +('sales_invoice_enable', '1'); + -- -------------------------------------------------------- @@ -445,11 +449,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 ; -- @@ -537,11 +543,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 ; -- diff --git a/js/manage_tables.js b/js/manage_tables.js index a0530f570..06d41922c 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.length === 0) { - $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; }