Merge branch 'feature/sale_numbering'

Conflicts:
	application/libraries/Receiving_lib.php
	database/2.3_to_2.3.1.sql
	js/manage_tables.js
This commit is contained in:
jekkos-t520
2014-11-25 17:20:05 +01:00
25 changed files with 757 additions and 499 deletions

View File

@@ -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**/

View File

@@ -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;
}

View File

@@ -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')
{

View File

@@ -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')));
}
}
?>

View File

@@ -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 . '<br/>';
} */
$table_data_row='<tr>';
$table_data_row.="<td width='3%'><input type='checkbox' id='item_$item->item_id' value='".$item->item_id."'/></td>";

View File

@@ -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';
?>

View File

@@ -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';
?>

View File

@@ -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';
?>

View File

@@ -1,397 +1,363 @@
<?php
class Receiving_lib
{
var $CI;
<?php
class Receiving_lib
{
var $CI;
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 __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;
}
}
?>

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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

View File

@@ -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()

View File

@@ -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');

View File

@@ -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;
}
}
?>
?>

View File

@@ -268,6 +268,38 @@ echo form_open('config/save/',array('id'=>'config_form'));
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_sales_invoice_enable').':', 'sales_invoice_enable',array('class'=>'wide')); ?>
<div class='form_field'>
<?php echo form_checkbox(array(
'name'=>'sales_invoice_enable',
'id'=>'sales_invoice_enable',
'value'=>'sales_invoice_enable',
'checked'=>$this->config->item('sales_invoice_enable')));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_sales_invoice_format').':', 'sales_invoice_format',array('class'=>'wide')); ?>
<div class='form_field'>
<?php echo form_input(array(
'name'=>'sales_invoice_format',
'id'=>'sales_invoice_format',
'value'=>$this->config->item('sales_invoice_format'))); ?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_recv_invoice_enable').':', 'recv_invoice_enable',array('class'=>'wide')); ?>
<div class='form_field'>
<?php echo form_checkbox(array(
'name'=>'recv_invoice_enable',
'id'=>'recv_invoice_enable',
'value'=>'recv_invoice_enable',
'checked'=>$this->config->item('recv_invoice_enable')));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_recv_invoice_format').':', 'recv_invoice_format',array('class'=>'wide')); ?>
<div class='form_field'>

View File

@@ -88,7 +88,7 @@ $(document).ready(function()
success=response.success;
},
async:false,
dataType: 'json'
dataType: 'json'
}).response).success;
}, '<?php echo $this->lang->line("recvs_invoice_number_duplicate"); ?>');

View File

@@ -18,7 +18,7 @@ if (isset($error_message))
<?php if(isset($supplier))
{
?>
<div id="customer"><?php echo $this->lang->line('suppliers_supplier').": ".$supplier; ?></div>
<div id="customer"><?php echo $this->lang->line('suppliers_supplier').": ".$supplier; ?></div>
<?php
}
?>

View File

@@ -238,6 +238,15 @@ else
<?php if ($mode == "receive")
{
?>
<tr>
<td>
<?php echo $this->lang->line('recvs_invoice_enable'); ?>
</td>
<td>
<?php echo form_checkbox(array('name'=>'recv_invoice_enable','id'=>'recv_invoice_enable','size'=>10,'checked'=>$this->config->item('recv_invoice_enable')));?>
</td>
</tr>
<tr>
<td>
<?php echo $this->lang->line('recvs_invoice_number').': ';?>
@@ -356,6 +365,22 @@ $(document).ready(function()
$.post('<?php echo site_url("receivings/set_invoice_number");?>', {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('<?php echo $this->lang->line("recvs_confirm_finish_receiving"); ?>'))

View File

@@ -20,6 +20,13 @@
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('sales_invoice_number').':', 'invoice_number'); ?>
<div class='form_field'>
<?php echo form_input(array('name' => 'invoice_number', 'value' => $sale_info['invoice_number'], 'id' => 'invoice_number'));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('sales_customer').':', 'customer'); ?>
<div class='form_field'>
@@ -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: '<?php echo site_url($controller_name . "/check_invoice_number")?>',
data: {'sale_id' : id, 'invoice_number' : $(element).val() },
success: function(response)
{
success=response.success;
},
async:false,
dataType: 'json'
}).response).success;
}, '<?php echo $this->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:

View File

@@ -18,11 +18,18 @@ if (isset($error_message))
<?php if(isset($customer))
{
?>
<div id="customer"><?php echo $this->lang->line('customers_customer').": ".$customer; ?></div>
<div id="customer"><?php echo $this->lang->line('customers_customer').": ".$customer; ?></div>
<?php
}
?>
<div id="sale_id"><?php echo $this->lang->line('sales_id').": ".$sale_id; ?></div>
<?php if (!empty($invoice_number))
{
?>
<div id="invoice_number"><?php echo $this->lang->line('recvs_invoice_number').": ".$invoice_number; ?></div>
<?php
}
?>
<div id="employee"><?php echo $this->lang->line('employees_employee').": ".$employee; ?></div>
</div>

View File

@@ -35,26 +35,17 @@ if (isset($success))
<label id="item_label" for="item">
<?php
if($mode=='sale_retail' or $mode=='sale_wholesale')
{
echo $this->lang->line('sales_find_or_scan_item');
}
else
{
echo $this->lang->line('sales_find_or_scan_item_or_receipt');
}
echo $this->lang->line('sales_find_or_scan_item_or_receipt');
?>
</label>
<?php echo form_input(array('name'=>'item','id'=>'item','size'=>'40'));?>
<!-- no need the new item button in sale page
<div id="new_item_button_register" >
<?php echo anchor("items/view/-1/width:360",
"<div class='small_button'><span>".$this->lang->line('sales_new_item')."</span></div>",
array('class'=>'thickbox none','title'=>$this->lang->line('sales_new_item')));
?>
</div>
-->
</form>
<table id="register">
<thead>
@@ -211,6 +202,7 @@ else
array('class'=>'thickbox none','title'=>$this->lang->line('sales_new_customer')));
?>
</div>
<div class="clearfix">&nbsp;</div>
<?php
}
@@ -304,13 +296,35 @@ else
<?php echo form_open("sales/add_payment",array('id'=>'add_payment_form')); ?>
<table width="100%">
<?php if ($mode == "sale")
{
?>
<tr>
<td>
<?php echo $this->lang->line('sales_payment').': ';?>
</td>
<?php echo $this->lang->line('sales_invoice_enable'); ?>
</td>
<td>
<?php echo form_dropdown( 'payment_type', $payment_options, array(), 'id="payment_types"' ); ?>
</td>
<?php echo form_checkbox(array('name'=>'sales_invoice_enable','id'=>'sales_invoice_enable','size'=>10,'checked'=>$this->config->item('sales_invoice_enable')));?>
</td>
</tr>
<tr>
<td>
<?php echo $this->lang->line('sales_invoice_number').': ';?>
</td>
<td>
<?php echo form_input(array('name'=>'sales_invoice_number','id'=>'sales_invoice_number','value'=>$invoice_number,'size'=>10));?>
</td>
</tr>
<?php
}
?>
<tr>
<td>
<?php echo $this->lang->line('sales_payment').': ';?>
</td>
<td>
<?php echo form_dropdown( 'payment_type', $payment_options, array(), 'id="payment_types"' ); ?>
</td>
</tr>
<tr>
<td><span id="amount_tendered_label"><?php echo $this->lang->line( 'sales_amount_tendered' ).': '; ?></span>
@@ -438,6 +452,27 @@ $(document).ready(function()
{
$.post('<?php echo site_url("sales/set_comment");?>', {comment: $('#comment').val()});
});
$('#sales_invoice_number').keyup(function()
{
$.post('<?php echo site_url("sales/set_invoice_number");?>', {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('<?php echo $this->lang->line("sales_confirm_suspend_sale"); ?>'))
{
$('#finish_sale_form').attr('action', '<?php echo site_url("sales/suspend"); ?>');

View File

@@ -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';
ADD COLUMN `receiving_quantity` int(11) DEFAULT '1';

View File

@@ -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 ;
--

View File

@@ -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;
}