diff --git a/application/config/autoload.php b/application/config/autoload.php index 148e43ad7..3a5b7cd9d 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -109,7 +109,7 @@ $autoload['language'] = array(); | */ -$autoload['model'] = array('Appconfig','Person','Customer','Employee','Module','Item', 'Item_taxes', 'Sale', 'Sale_suspended', 'Supplier','Inventory','Receiving','Giftcard', 'Item_kit', 'Item_kit_items','Item_unit'); +$autoload['model'] = array('Appconfig','Person','Customer','Employee','Module','Item', 'Item_taxes', 'Sale', 'Sale_suspended', 'Supplier','Inventory','Receiving','Giftcard', 'Item_kit', 'Item_kit_items','Item_unit','Stock_locations','Item_quantitys'); /* End of file autoload.php */ diff --git a/application/controllers/config.php b/application/controllers/config.php index 028c4bff5..78d278427 100644 --- a/application/controllers/config.php +++ b/application/controllers/config.php @@ -30,6 +30,7 @@ class Config extends Secure_area 'return_policy'=>$this->input->post('return_policy'), 'language'=>$this->input->post('language'), 'timezone'=>$this->input->post('timezone'), + 'stock_location'=>$this->input->post('stock_location'), 'print_after_sale'=>$this->input->post('print_after_sale'), 'custom1_name'=>$this->input->post('custom1_name'),/**GARRISON ADDED 4/20/2013**/ 'custom2_name'=>$this->input->post('custom2_name'),/**GARRISON ADDED 4/20/2013**/ @@ -43,7 +44,13 @@ class Config extends Secure_area 'custom10_name'=>$this->input->post('custom10_name')/**GARRISON ADDED 4/20/2013**/ ); - if( $this->Appconfig->batch_save( $batch_save_data ) ) + $stock_locations = explode( ',', $this->input->post('stock_location')); + $stock_locations_trimmed=array(); + foreach($stock_locations as $location) + { + array_push($stock_locations_trimmed, trim($location, ' ')); + } + if( $this->Appconfig->batch_save( $batch_save_data ) && $this->Stock_locations->array_save($stock_locations_trimmed)) { echo json_encode(array('success'=>true,'message'=>$this->lang->line('config_saved_successfully'))); } diff --git a/application/controllers/items.php b/application/controllers/items.php index a5f2839c3..57d6d1852 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -24,23 +24,19 @@ class Items extends Secure_area implements iData_controller function refresh() { - $low_inventory=$this->input->post('low_inventory'); $is_serialized=$this->input->post('is_serialized'); $no_description=$this->input->post('no_description'); $search_custom=$this->input->post('search_custom');//GARRISON ADDED 4/13/2013 - $is_deleted=$this->input->post('is_deleted'); // Parq 131215 - $stock_type=$this->input->post('stock_type'); + $is_deleted=$this->input->post('is_deleted'); // Parq 131215 $data['search_section_state']=$this->input->post('search_section_state'); - $data['low_inventory']=$this->input->post('low_inventory'); $data['is_serialized']=$this->input->post('is_serialized'); $data['no_description']=$this->input->post('no_description'); $data['search_custom']=$this->input->post('search_custom');//GARRISON ADDED 4/13/2013 $data['is_deleted']=$this->input->post('is_deleted'); // Parq 131215 - $data['stock_type']=$this->input->post('stock_type'); $data['controller_name']=strtolower(get_class()); $data['form_width']=$this->get_form_width(); - $data['manage_table']=get_items_manage_table($this->Item->get_all_filtered($low_inventory,$is_serialized,$no_description,$search_custom,$is_deleted,$stock_type),$this);//GARRISON MODIFIED 4/13/2013, Parq 131215 + $data['manage_table']=get_items_manage_table($this->Item->get_all_filtered($is_serialized,$no_description,$search_custom,$is_deleted),$this);//GARRISON MODIFIED 4/13/2013, Parq 131215 $this->load->view('items/manage',$data); } @@ -206,20 +202,48 @@ class Items extends Secure_area implements iData_controller $data['default_tax_2_rate']=($item_id==-1) ? $this->Appconfig->get('default_tax_2_rate') : ''; $data['stock_type'] = $data['item_info']->stock_type; + $locations_data = $this->Stock_locations->get_undeleted_all()->result_array(); + $location_array; + foreach($locations_data as $location) + { + $location_array['stock_'.$location['location_id']] = array('location_name'=>$location['location_name'], + 'quantity'=>($item_id == -1)?null:$this->Item_quantitys->get_item_quantity($item_id, $location['location_id'])->quantity); + } + $data['stock_locations']= $location_array; + $data['item_unit_info']=$this->Item_unit->get_info($item_id); $this->load->view("items/form",$data); } - + + //Ramel Inventory Tracking function inventory($item_id=-1) { $data['item_info']=$this->Item->get_info($item_id); + + $data['stock_locations'] = array(); + $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + foreach($stock_locations as $location_data) + { + $data['stock_locations']['stock_'.$location_data['location_id']] = $location_data['location_name']; + $data['item_quantitys']['stock_'.$location_data['location_id']] = $this->Item_quantitys->get_item_quantity($item_id,$location_data['location_id'])->quantity; + } + $this->load->view("items/inventory",$data); } function count_details($item_id=-1) { $data['item_info']=$this->Item->get_info($item_id); + + $data['stock_locations'] = array(); + $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + foreach($stock_locations as $location_data) + { + $data['stock_locations']['stock_'.$location_data['location_id']] = $location_data['location_name']; + $data['item_quantitys']['stock_'.$location_data['location_id']] = $this->Item_quantitys->get_item_quantity($item_id,$location_data['location_id'])->quantity; + } + $this->load->view("items/count_details",$data); } //------------------------------------------- Ramel @@ -262,6 +286,7 @@ class Items extends Secure_area implements iData_controller function save($item_id=-1) { + //Save item data $item_data = array( 'name'=>$this->input->post('name'), 'description'=>$this->input->post('description'), @@ -270,7 +295,6 @@ class Items extends Secure_area implements iData_controller 'item_number'=>$this->input->post('item_number')=='' ? null:$this->input->post('item_number'), 'cost_price'=>$this->input->post('cost_price'), 'unit_price'=>$this->input->post('unit_price'), - 'quantity'=>$this->input->post('quantity'), 'reorder_level'=>$this->input->post('reorder_level'), 'location'=>$this->input->post('location'), 'allow_alt_description'=>$this->input->post('allow_alt_description'), @@ -308,15 +332,6 @@ class Items extends Secure_area implements iData_controller $item_data['name'],'item_id'=>$item_id)); } - $inv_data = array - ( - 'trans_date'=>date('Y-m-d H:i:s'), - 'trans_items'=>$item_id, - 'trans_user'=>$employee_id, - 'trans_comment'=>$this->lang->line('items_manually_editing_of_quantity'), - 'trans_inventory'=>$cur_item_info ? $this->input->post('quantity') - $cur_item_info->quantity : $this->input->post('quantity') - ); - $this->Inventory->insert($inv_data); $items_taxes_data = array(); $tax_names = $this->input->post('tax_names'); $tax_percents = $this->input->post('tax_percents'); @@ -328,16 +343,31 @@ class Items extends Secure_area implements iData_controller } } $this->Item_taxes->save($items_taxes_data, $item_id); + - $items_unit_data = array( - 'item_id'=>$item_id, - 'unit_quantity'=>$this->input->post('unit_quantity'), - 'related_number'=>$this->input->post('related_number')); - if($items_unit_data['related_number'] == null) + //Save item quantity + $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + foreach($stock_locations as $location_data) { - $items_unit_data['related_number'] = $item_data['item_number']; - } - $this->Item_unit->save($items_unit_data, $item_id); + $updated_quantity = $this->input->post('stock_'.$location_data['location_id'].'_quantity'); + $location_detail = array('item_id'=>$item_id, + 'location_id'=>$location_data['location_id'], + 'quantity'=>$updated_quantity); + + $item_quantity = $this->Item_quantitys->get_item_quantity($item_id, $location_data['location_id']); + $this->Item_quantitys->save($location_detail, $item_quantity->item_quantity_id); + + $inv_data = array + ( + 'trans_date'=>date('Y-m-d H:i:s'), + 'trans_items'=>$item_id, + 'trans_user'=>$employee_id, + 'location_id'=>$location_data['location_id'], + 'trans_comment'=>$this->lang->line('items_manually_editing_of_quantity'), + 'trans_inventory'=>$item_quantity->item_quantity_id ? $updated_quantity - $item_quantity->quantity : $updated_quantity + ); + $this->Inventory->insert($inv_data); + } } else//failure { @@ -352,21 +382,27 @@ class Items extends Secure_area implements iData_controller { $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $cur_item_info = $this->Item->get_info($item_id); + $location_id = $this->get_location_id_from_stock_location($this->input->post('stock_location')); $inv_data = array ( 'trans_date'=>date('Y-m-d H:i:s'), 'trans_items'=>$item_id, 'trans_user'=>$employee_id, + 'location_id'=>$location_id, 'trans_comment'=>$this->input->post('trans_comment'), 'trans_inventory'=>$this->input->post('newquantity') ); $this->Inventory->insert($inv_data); //Update stock quantity - $item_data = array( - 'quantity'=>$cur_item_info->quantity + $this->input->post('newquantity') + + $item_quantity= $this->Item_quantitys->get_item_quantity($item_id,$location_id); + $item_quantity_data = array( + 'item_id'=>$item_id, + 'location_id'=>$location_id, + 'quantity'=>$item_quantity->quantity + $this->input->post('newquantity') ); - if($this->Item->save($item_data,$item_id)) + if($this->Item_quantitys->save($item_quantity_data,$item_quantity->item_quantity_id)) { echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_updating').' '. $cur_item_info->name,'item_id'=>$item_id)); @@ -572,5 +608,10 @@ class Items extends Secure_area implements iData_controller { echo $this->Item->is_sale_store_item_exist($item_number); } + + function get_location_id_from_stock_location($location) + { + return substr($location, 6); + } } ?> \ No newline at end of file diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index ddd265326..e339e559f 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -15,7 +15,7 @@ class Receivings extends Secure_area function item_search() { - $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit'),'warehouse'); + $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit')); $suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($this->input->post('q'),$this->input->post('limit'))); echo implode("\n",$suggestions); } @@ -37,6 +37,12 @@ class Receivings extends Secure_area { $mode = $this->input->post("mode"); $this->receiving_lib->set_mode($mode); + + $stock_source = $this->input->post("stock_source"); + $this->receiving_lib->set_stock_source($stock_source); + + $stock_deatination = $this->input->post("stock_deatination"); + $this->receiving_lib->set_stock_destination($stock_deatination); $this->receiving_lib->empty_cart(); $this->_reload(); } @@ -143,6 +149,7 @@ class Receivings extends Secure_area $emp_info=$this->Employee->get_info($employee_id); $payment_type = $this->input->post('payment_type'); $data['payment_type']=$this->input->post('payment_type'); + $data['stock_location']=$this->receiving_lib->get_stock_source(); if ($this->input->post('amount_tendered')) { @@ -158,7 +165,7 @@ class Receivings extends Secure_area } //SAVE receiving to database - $data['receiving_id']='RECV '.$this->Receiving->save($data['cart'], $supplier_id,$employee_id,$comment,$payment_type); + $data['receiving_id']='RECV '.$this->Receiving->save($data['cart'], $supplier_id,$employee_id,$comment,$payment_type,$data['stock_location']); if ($data['receiving_id'] == 'RECV -1') { @@ -242,6 +249,17 @@ class Receivings extends Secure_area $data['cart']=$this->receiving_lib->get_cart(); $data['modes']=array('receive'=>$this->lang->line('recvs_receiving'),'return'=>$this->lang->line('recvs_return'), 'requisition'=>$this->lang->line('recvs_requisition')); $data['mode']=$this->receiving_lib->get_mode(); + + $data['stock_locations'] = array(); + $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + foreach($stock_locations as $location_data) + { + $data['stock_locations']['stock_'.$location_data['location_id']] = $location_data['location_name']; + } + + $data['stock_source']=$this->receiving_lib->get_stock_source(); + $data['stock_destination']=$this->receiving_lib->get_stock_destination(); + $data['total']=$this->receiving_lib->get_total(); $data['items_module_allowed'] = $this->Employee->has_permission('items', $person_info->person_id); $data['payment_options']=array( diff --git a/application/controllers/reports.php b/application/controllers/reports.php index 23f4b3cc8..294594f0e 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -923,7 +923,7 @@ class Reports extends Secure_area $report_data = $model->getData(array()); foreach($report_data as $row) { - $tabular_data[] = array($row['name'], $row['item_number'], $row['description'], $row['quantity'], $row['reorder_level']); + $tabular_data[] = array($row['name'], $row['item_number'], $row['description'], $row['quantity'], $row['reorder_level'], $row['location_name']); } $data = array( @@ -946,7 +946,7 @@ class Reports extends Secure_area $report_data = $model->getData(array()); foreach($report_data as $row) { - $tabular_data[] = array($row['name'], $row['item_number'], $row['description'], $row['quantity'], $row['reorder_level']); + $tabular_data[] = array($row['name'], $row['item_number'], $row['description'], $row['quantity'], $row['reorder_level'],$row['location_name']); } $data = array( diff --git a/application/controllers/sales.php b/application/controllers/sales.php index b0a2622c6..3efdb4b12 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -15,16 +15,7 @@ class Sales extends Secure_area function item_search() { - $stock_type; - if($this->sale_lib->get_mode()=='sale_wholesale') - { - $stock_type = 'warehouse'; - } - else - { - $stock_type = 'sale_stock'; - } - $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit'),$stock_type); + $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit')); $suggestions = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($this->input->post('q'),$this->input->post('limit'))); echo implode("\n",$suggestions); } @@ -46,7 +37,10 @@ class Sales extends Secure_area { $this->sale_lib->clear_all(); $mode = $this->input->post("mode"); - $this->sale_lib->set_mode($mode); + $this->sale_lib->set_mode($mode); + + $stock_location = $this->input->post("stock_location"); + $this->sale_lib->set_sale_location($stock_location); $this->_reload(); } @@ -122,7 +116,7 @@ class Sales extends Secure_area $data=array(); $mode = $this->sale_lib->get_mode(); $item_id_or_number_or_item_kit_or_receipt = $this->input->post("item"); - $quantity = (($mode=="sale_wholesale") or ($mode=="sale_retail"))? 1:-1; + $quantity = ($mode=="return")? -1:1; if($this->sale_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt) && $mode=='return') { @@ -203,7 +197,8 @@ 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; - + $data['stock_location']=$this->sale_lib->get_sale_location(); + if($customer_id!=-1) { $cust_info=$this->Customer->get_info($customer_id); @@ -211,7 +206,7 @@ class Sales extends Secure_area } //SAVE sale to database - $data['sale_id']='POS '.$this->Sale->save($data['cart'], $customer_id,$employee_id,$comment,$data['payments']); + $data['sale_id']='POS '.$this->Sale->save($data['cart'], $customer_id,$employee_id,$comment,$data['payments'], $data['stock_location']); if ($data['sale_id'] == 'POS -1') { $data['error_message'] = $this->lang->line('sales_transaction_failed'); @@ -351,8 +346,19 @@ class Sales extends Secure_area function _reload($data=array()) { $person_info = $this->Employee->get_logged_in_employee_info(); - $data['cart']=$this->sale_lib->get_cart(); - $data['modes']=array('sale_retail'=>$this->lang->line('sales_sale_retail'),'sale_wholesale'=>$this->lang->line('sales_wholesale'),'return'=>$this->lang->line('sales_return')); + $data['cart']=$this->sale_lib->get_cart(); + $data['modes']['return']=$this->lang->line('sales_return'); + $data['mode']=$this->sale_lib->get_mode(); + + $data['stock_locations'] = array(); + $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + foreach($stock_locations as $location_data) + { + $data['stock_locations']['stock_'.$location_data['location_id']] = $location_data['location_name']; + } + $data['stock_location']=$this->sale_lib->get_sale_location(); + + $data['modes']=array('sale'=>$this->lang->line('sales_sale'),'return'=>$this->lang->line('sales_return')); $data['mode']=$this->sale_lib->get_mode(); $data['subtotal']=$this->sale_lib->get_subtotal(); $data['taxes']=$this->sale_lib->get_taxes(); diff --git a/application/language/en/config_lang.php b/application/language/en/config_lang.php index 6f9a5a8ac..eb9bb7c95 100644 --- a/application/language/en/config_lang.php +++ b/application/language/en/config_lang.php @@ -32,4 +32,7 @@ $lang['config_custom7'] = 'Custom Field 7'; //GARRISON ADDED 4/21/2013 $lang['config_custom8'] = 'Custom Field 8'; //GARRISON ADDED 4/21/2013 $lang['config_custom9'] = 'Custom Field 9'; //GARRISON ADDED 4/21/2013 $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'; ?> \ No newline at end of file diff --git a/application/language/en/items_lang.php b/application/language/en/items_lang.php index 5b4b38ff6..a3b18c509 100644 --- a/application/language/en/items_lang.php +++ b/application/language/en/items_lang.php @@ -58,7 +58,6 @@ $lang['items_must_select_item_for_barcode'] = 'You must select at least 1 item t $lang['items_excel_import_failed'] = 'Excel import failed'; $lang['items_allow_alt_description'] = 'Allow Alt Description'; $lang['items_is_serialized'] = 'Item has Serial Number'; -$lang['items_low_inventory_items'] = 'Low Inventory Items'; $lang['items_serialized_items'] = 'Serialized Items'; $lang['items_no_description_items'] = 'No Description Items'; $lang['items_search_custom_items'] = 'Search Custom Fields';//GARRISON ADDED @@ -80,7 +79,8 @@ $lang['items_location'] = 'Location'; $lang['items_is_deleted'] = 'Deleted';// Parq 131215 $lang['items_stock_type_sale'] = 'Sale stock'; $lang['items_stock_type_warehouse'] = 'Warehouse stock'; -$lang['items_stock_type'] = 'Stock type'; $lang['items_unit_quantity'] = 'Unit quantity'; $lang['items_related_number'] = 'Related item number'; + +$lang['items_stock_location']='Stock location'; ?> diff --git a/application/language/en/receivings_lang.php b/application/language/en/receivings_lang.php index 6e1e03bce..763123dc6 100644 --- a/application/language/en/receivings_lang.php +++ b/application/language/en/receivings_lang.php @@ -32,4 +32,8 @@ $lang['reqs_related_item_quantity']='Related item qty.'; $lang['reqs_receipt']='Requisition Receipt'; $lang['reqs_transaction_failed'] = 'Requisition Transactions Failed'; $lang['reqs_unable_to_add_item']='Unable to add item to requisition'; + +$lang['recvs_stock_source']='Stock source'; +$lang['recvs_stock_destination']='Stock destination'; +$lang['recvs_stock_locaiton']='Stock location'; ?> diff --git a/application/language/en/reports_lang.php b/application/language/en/reports_lang.php index 063321c81..495142f12 100644 --- a/application/language/en/reports_lang.php +++ b/application/language/en/reports_lang.php @@ -88,8 +88,7 @@ $lang['reports_receiving_type'] = 'Receiving Type'; $lang['reports_all'] = 'All'; $lang['reports_returns'] = 'Returns'; $lang['reports_discount'] = 'Discounts'; -$lang['reports_sales_retail'] = 'Sales retail'; -$lang['reports_sales_wholesale'] = 'Sales wholesale'; +$lang['reports_sales'] = 'Sales'; $lang['reports_requisition'] = 'Requisition'; $lang['reports_receiving_id'] = 'Receiving ID'; $lang['reports_requisition_id'] = 'Requisition ID'; @@ -100,4 +99,6 @@ $lang['reports_requisition_related_item'] = 'Related item'; $lang['reports_requisition_related_item_unit_quantity'] = 'Unit qty.'; $lang['reports_requisition_related_item_total_quantity'] = 'Total qty.'; $lang['reports_detailed_requisition_report'] = 'Detailed Requisitions Report'; + +$lang['reports_stock_location'] = 'Stock location'; ?> diff --git a/application/language/en/sales_lang.php b/application/language/en/sales_lang.php index a5dfa415d..be0d2dc4e 100644 --- a/application/language/en/sales_lang.php +++ b/application/language/en/sales_lang.php @@ -34,8 +34,6 @@ $lang['sales_cancel_sale']='Cancel Sale'; $lang['sales_add_payment']='Add Payment'; $lang['sales_receipt']='Sales Receipt'; $lang['sales_id']='Sale ID'; -$lang['sales_sale_retail']='Sale retail'; -$lang['sales_wholesale']='Sale wholesale'; $lang['sales_return']='Return'; $lang['sales_confirm_finish_sale'] = 'Are you sure you want to submit this sale? This cannot be undone.'; $lang['sales_confirm_cancel_sale'] = 'Are you sure you want to clear this sale? All items will cleared.'; @@ -85,4 +83,7 @@ $lang['sales_amount_due'] = 'Amount Due'; $lang['sales_payment_type'] = "Type"; $lang['sales_payment_amount'] = "Amount"; $lang['sales_basic_information']='Sale information'; + +$lang['sales_stock_location']='Stock location'; +$lang['sales_sale']='Sale'; ?> diff --git a/application/language/th/items_lang.php b/application/language/th/items_lang.php index a22680d57..ce415f097 100644 --- a/application/language/th/items_lang.php +++ b/application/language/th/items_lang.php @@ -79,92 +79,7 @@ $lang['items_inventory'] = 'สินค้าคงเหลือ'; $lang['items_location'] = 'ที่ตั้ง'; $lang['items_unit_quantity'] = 'จำนวนหน่วย'; $lang['items_related_number'] = 'สินค้าที่เกี่ยวข้อง'; -$lang['items_stock_type_sale'] = 'สินค้าหน้าร้าน'; -$lang['items_stock_type_warehouse'] = 'สินค้าหลังร้าน'; -$lang['items_stock_type'] = 'ชนิดของสินค้า'; -?> - diff --git a/application/language/th/reports_lang.php b/application/language/th/reports_lang.php index 854f67638..05a198ca0 100644 --- a/application/language/th/reports_lang.php +++ b/application/language/th/reports_lang.php @@ -43,8 +43,6 @@ $lang['reports_comments'] = 'หมายเหตุ'; $lang['reports_discount'] = 'ส่วนลด'; $lang['reports_payment_type'] = 'ชนิดของการจ่าย'; $lang['reports_sales'] = 'ขาย'; -$lang['reports_sales_retail'] = 'ขายปลีก'; -$lang['reports_sales_wholesale'] = 'ขายส่ง'; $lang['reports_categories'] = 'หมวดหมู่'; $lang['reports_customers'] = 'ลูกค้า'; $lang['reports_suppliers'] = 'ผู้ผลิต'; @@ -145,8 +143,6 @@ $lang['reports_comments'] = 'หมายเหตุ'; $lang['reports_discount'] = 'ส่วนลด'; $lang['reports_payment_type'] = 'ชนิดของการจ่าย'; $lang['reports_sales'] = 'ขาย'; -$lang['reports_sales_retail'] = 'ขายปลีก'; -$lang['reports_sales_wholesale'] = 'ขายส่ง'; $lang['reports_categories'] = 'หมวดหมู่'; $lang['reports_customers'] = 'ลูกค้า'; $lang['reports_suppliers'] = 'ผู้ผลิต'; diff --git a/application/language/th/sales_lang.php b/application/language/th/sales_lang.php index 684597900..66a7fa4ab 100644 --- a/application/language/th/sales_lang.php +++ b/application/language/th/sales_lang.php @@ -34,8 +34,6 @@ $lang['sales_cancel_sale']='ยกเลิกการขาย'; $lang['sales_add_payment']='เพิ่มบิล'; $lang['sales_receipt']='บิลขาย'; $lang['sales_id']='เลขที่ขาย'; -$lang['sales_sale_retail']='ขายปลีก'; -$lang['sales_wholesale']='ขายส่ง'; $lang['sales_return']='คืน'; $lang['sales_confirm_finish_sale'] = 'แน่ใจหรือไม่ที่จะสำเร็จการขาย? ไม่สามารถย้อนกลับได้.'; $lang['sales_confirm_cancel_sale'] = 'แน่ใจหรือไม่ที่จะล้างรายการขาย? สินค้าทุกอย่างจะถูกลบจากบอร์ด.'; @@ -114,8 +112,6 @@ $lang['sales_cancel_sale']='ยกเลิกการขาย'; $lang['sales_add_payment']='เพิ่มบิล'; $lang['sales_receipt']='บิลขาย'; $lang['sales_id']='เลขที่ขาย'; -$lang['sales_sale_retail']='ขายปลีก'; -$lang['sales_wholesale']='ขายส่ง'; $lang['sales_return']='คืน'; $lang['sales_confirm_finish_sale'] = 'แน่ใจหรือไม่ที่จะสำเร็จการขาย? ไม่สามารถย้อนกลับได้.'; $lang['sales_confirm_cancel_sale'] = 'แน่ใจหรือไม่ที่จะล้างรายการขาย? สินค้าทุกอย่างจะถูกลบจากบอร์ด.'; diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 6eda6d333..8798d1e46 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -46,7 +46,44 @@ class Receiving_lib { $this->CI->session->set_userdata('recv_mode',$mode); } + + function get_stock_source() + { + if(!$this->CI->session->userdata('recv_stock_source')) + { + $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); + $location_name = 'stock_'.$stock_locations[0]['location_id']; + $this->set_stock_source($location_name); + } + return $this->CI->session->userdata('recv_stock_source'); + } + function set_stock_source($stock_source) + { + $this->CI->session->set_userdata('recv_stock_source',$stock_source); + } + + function get_stock_destination() + { + if(!$this->CI->session->userdata('recv_stock_destination')) + { + $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); + $location_name = 'stock_'.$stock_locations[0]['location_id']; + $this->set_stock_destination($location_name); + } + 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 get_location_id_from_stock_location($location) + { + return substr($location, 6); + } + function add_item($item_id,$quantity=1,$discount=0,$price=null,$description=null,$serialnumber=null) { //make sure item exists in database. diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 80017796a..4474410d0 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -157,7 +157,7 @@ class Sale_lib function get_mode() { if(!$this->CI->session->userdata('sale_mode')) - $this->set_mode('sale_retail'); + $this->set_mode('sale'); return $this->CI->session->userdata('sale_mode'); } @@ -167,6 +167,22 @@ class Sale_lib $this->CI->session->set_userdata('sale_mode',$mode); } + function get_sale_location() + { + if(!$this->CI->session->userdata('sale_location')) + { + $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); + $location_name = 'stock_'.$stock_locations[0]['location_id']; + $this->set_sale_location($location_name); + } + return $this->CI->session->userdata('sale_location'); + } + + function set_sale_location($location) + { + $this->CI->session->set_userdata('sale_location',$location); + } + function add_item($item_id,$quantity=1,$discount=0,$price=null,$description=null,$serialnumber=null) { //make sure item exists @@ -242,6 +258,11 @@ class Sale_lib } + function get_location_id_from_stock_location($location) + { + return substr($location, 6); + } + function out_of_stock($item_id) { //make sure item exists @@ -251,10 +272,12 @@ class Sale_lib } - $item = $this->CI->Item->get_info($item_id); + //$item = $this->CI->Item->get_info($item_id); + $location_id = $this->get_location_id_from_stock_location($this->get_sale_location()); + $item_quantity = $this->CI->Item_quantitys->get_item_quantity($item_id, $location_id)->quantity; $quanity_added = $this->get_quantity_already_added($item_id); - if ($item->quantity - $quanity_added < 0) + if ($item_quantity - $quanity_added < 0) { return true; } diff --git a/application/models/Item_quantitys.php b/application/models/Item_quantitys.php new file mode 100644 index 000000000..cc12e1a81 --- /dev/null +++ b/application/models/Item_quantitys.php @@ -0,0 +1,37 @@ +db->from('item_quantitys'); + $this->db->where('item_quantity_id',$item_quantity_id); + $query = $this->db->get(); + + return ($query->num_rows()==1); + } + + function save($location_detail, $item_quantity_id=false) + { + if (!$item_quantity_id or !$this->exists($item_quantity_id)) + { + if($this->db->insert('item_quantitys',$location_detail)) + { + $location_detail['item_quantity_id']=$this->db->insert_id(); + return true; + } + return false; + } + + $this->db->where('item_quantity_id', $item_quantity_id); + return $this->db->update('item_quantitys',$location_detail); + } + + function get_item_quantity($item_id, $location_id) + { + $this->db->from('item_quantitys'); + $this->db->where('item_id',$item_id); + $this->db->where('location_id',$location_id); + return $this->db->get()->row(); + } +} +?> \ No newline at end of file diff --git a/application/models/inventory.php b/application/models/inventory.php index 2c18e0277..9b6ba757c 100644 --- a/application/models/inventory.php +++ b/application/models/inventory.php @@ -6,10 +6,14 @@ class Inventory extends CI_Model return $this->db->insert('inventory',$inventory_data); } - function get_inventory_data_for_item($item_id) + function get_inventory_data_for_item($item_id, $location_id=false) { $this->db->from('inventory'); $this->db->where('trans_items',$item_id); + if($location_id != false) + { + $this->db->where('location_id',$location_id); + } $this->db->order_by("trans_date", "desc"); return $this->db->get(); } diff --git a/application/models/item.php b/application/models/item.php index 47558c8fc..cc90a6dcf 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -33,13 +33,9 @@ class Item extends CI_Model return $this->db->count_all_results(); } - function get_all_filtered($low_inventory=0,$is_serialized=0,$no_description,$search_custom,$is_deleted,$stock_type)/**GARRISON MODIFIED 4/21/2013, Parq 131215 **/ + function get_all_filtered($is_serialized=0,$no_description,$search_custom,$is_deleted)/**GARRISON MODIFIED 4/21/2013, Parq 131215 **/ { $this->db->from('items'); - if ($low_inventory !=0 ) - { - $this->db->where('quantity <=','reorder_level', false); - } if ($is_serialized !=0 ) { $this->db->where('is_serialized',1); @@ -47,12 +43,7 @@ class Item extends CI_Model if ($no_description!=0 ) { $this->db->where('description',''); - } - - if($stock_type!='all') - { - $this->db->where('stock_type',$stock_type); - } + } /**GARRISON SECTION ADDED 4/21/2013**/ @@ -273,13 +264,12 @@ class Item extends CI_Model } - function get_item_search_suggestions($search,$limit=25,$stock_type='warehouse') + function get_item_search_suggestions($search,$limit=25) { $suggestions = array(); $this->db->from('items'); $this->db->where('deleted',0); - $this->db->where('stock_type',$stock_type); $this->db->like('name', $search); $this->db->order_by("name", "asc"); $by_name = $this->db->get(); @@ -290,7 +280,6 @@ class Item extends CI_Model $this->db->from('items'); $this->db->where('deleted',0); - $this->db->where('stock_type',$stock_type); $this->db->like('item_number', $search); $this->db->order_by("item_number", "asc"); $by_item_number = $this->db->get(); @@ -302,7 +291,6 @@ class Item extends CI_Model //Search by description $this->db->from('items'); $this->db->where('deleted',0); - $this->db->where('stock_type',$stock_type); $this->db->like('description', $search); $this->db->order_by("description", "asc"); $by_description = $this->db->get(); diff --git a/application/models/receiving.php b/application/models/receiving.php index 2d3453c6d..aa26c85db 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -24,7 +24,7 @@ class Receiving extends CI_Model return ($query->num_rows()==1); } - function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$receiving_id=false) + function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$stock_location,$receiving_id=false) { if(count($items)==0) return -1; @@ -63,8 +63,11 @@ class Receiving extends CI_Model $this->db->insert('receivings_items',$receivings_items_data); //Update stock quantity - $item_data = array('quantity'=>$cur_item_info->quantity + $item['quantity']); - $this->Item->save($item_data,$item['item_id']); + $item_quantity = $this->Item_quantitys->get_item_quantity($item['item_id'], $this->receiving_lib->get_location_id_from_stock_location($stock_location)); + $this->Item_quantitys->save(array('quantity'=>$item_quantity->quantity + $item['quantity'], + 'item_id'=>$item['item_id'], + 'location_id'=>$this->receiving_lib->get_location_id_from_stock_location($stock_location)), $item_quantity->item_quantity_id); + $qty_recv = $item['quantity']; $recv_remarks ='RECV '.$receiving_id; @@ -73,6 +76,7 @@ class Receiving extends CI_Model 'trans_date'=>date('Y-m-d H:i:s'), 'trans_items'=>$item['item_id'], 'trans_user'=>$employee_id, + 'location_id'=>$this->receiving_lib->get_location_id_from_stock_location($stock_location), 'trans_comment'=>$recv_remarks, 'trans_inventory'=>$qty_recv ); diff --git a/application/models/reports/detailed_sales.php b/application/models/reports/detailed_sales.php index fcbec7a21..edb330aa7 100644 --- a/application/models/reports/detailed_sales.php +++ b/application/models/reports/detailed_sales.php @@ -39,16 +39,11 @@ class Detailed_sales extends Report $this->db->join('people as employee', 'sales_items_temp.employee_id = employee.person_id'); $this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); $this->db->where('sale_type', 'sale_stock'); } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); - } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); @@ -77,15 +72,9 @@ class Detailed_sales extends Report $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { diff --git a/application/models/reports/inventory_low.php b/application/models/reports/inventory_low.php index 98652e6a7..17ded4608 100644 --- a/application/models/reports/inventory_low.php +++ b/application/models/reports/inventory_low.php @@ -9,19 +9,25 @@ class Inventory_low extends Report public function getDataColumns() { - return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_reorder_level')); + return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_reorder_level'), $this->lang->line('reports_stock_location')); } - public function getData(array $inputs) - { - $this->db->select('name, item_number, quantity, reorder_level, description'); - $this->db->from('items'); - $this->db->where('quantity <= reorder_level and deleted=0'); - $this->db->order_by('name'); - - return $this->db->get()->result_array(); + public function getData(array $inputs) + { + $this->db->from('items'); + $this->db->join('item_quantitys','items.item_id=item_quantitys.item_id'); + $this->db->join('stock_locations','item_quantitys.location_id=stock_locations.location_id'); + + $this->db->select('name, item_number, reorder_level, item_quantitys.quantity,description,location_name'); - } + $this->db->where('item_quantitys.quantity <= reorder_level'); + $this->db->where('items.deleted = 0'); + + $this->db->order_by('name'); + + return $this->db->get()->result_array(); + + } public function getSummaryData(array $inputs) { diff --git a/application/models/reports/inventory_summary.php b/application/models/reports/inventory_summary.php index a6130f891..a10180bb5 100644 --- a/application/models/reports/inventory_summary.php +++ b/application/models/reports/inventory_summary.php @@ -9,15 +9,18 @@ class Inventory_summary extends Report public function getDataColumns() { - return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_reorder_level')); + return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_reorder_level'),$this->lang->line('reports_stock_location')); } public function getData(array $inputs) { - $this->db->select('name, item_number, quantity, reorder_level, description'); - $this->db->from('items'); - $this->db->where('deleted', 0); - $this->db->order_by('name'); + $this->db->from('items'); + $this->db->join('item_quantitys','items.item_id=item_quantitys.item_id'); + $this->db->join('stock_locations','item_quantitys.location_id=stock_locations.location_id'); + + $this->db->select('name, item_number, reorder_level, item_quantitys.quantity, description,location_name'); + $this->db->where('items.deleted', 0); + $this->db->order_by('items.name'); return $this->db->get()->result_array(); diff --git a/application/models/reports/specific_customer.php b/application/models/reports/specific_customer.php index 45ad090f7..5a9d93907 100644 --- a/application/models/reports/specific_customer.php +++ b/application/models/reports/specific_customer.php @@ -20,15 +20,9 @@ class Specific_customer extends Report $this->db->from('sales_items_temp'); $this->db->join('people', 'sales_items_temp.employee_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and customer_id='.$inputs['customer_id']); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { @@ -58,20 +52,14 @@ class Specific_customer extends Report $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and customer_id='.$inputs['customer_id']); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } return $this->db->get()->row_array(); } } diff --git a/application/models/reports/specific_employee.php b/application/models/reports/specific_employee.php index dada0395f..80b1cef39 100644 --- a/application/models/reports/specific_employee.php +++ b/application/models/reports/specific_employee.php @@ -21,20 +21,14 @@ class Specific_employee extends Report $this->db->join('people', 'sales_items_temp.customer_id = people.person_id', 'left'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and employee_id='.$inputs['employee_id']); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } $this->db->group_by('sale_id'); $this->db->order_by('sale_date'); @@ -60,20 +54,14 @@ class Specific_employee extends Report $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and employee_id='.$inputs['employee_id']); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'sale_stock\''); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'warehouse\''); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_categories.php b/application/models/reports/summary_categories.php index f6d7778a6..bf00bb974 100644 --- a/application/models/reports/summary_categories.php +++ b/application/models/reports/summary_categories.php @@ -18,20 +18,14 @@ class Summary_categories extends Report $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } $this->db->group_by('category'); $this->db->order_by('category'); @@ -44,20 +38,14 @@ class Summary_categories extends Report $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'sale_stock\''); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'warehouse\''); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } return $this->db->get()->row_array(); } diff --git a/application/models/reports/summary_customers.php b/application/models/reports/summary_customers.php index 4712ddab9..0e500be0c 100644 --- a/application/models/reports/summary_customers.php +++ b/application/models/reports/summary_customers.php @@ -19,20 +19,14 @@ class Summary_customers extends Report $this->db->join('customers', 'customers.person_id = sales_items_temp.customer_id'); $this->db->join('people', 'customers.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } $this->db->group_by('customer_id'); $this->db->order_by('last_name'); @@ -46,20 +40,14 @@ class Summary_customers extends Report $this->db->join('customers', 'customers.person_id = sales_items_temp.customer_id'); $this->db->join('people', 'customers.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_discounts.php b/application/models/reports/summary_discounts.php index 7e09b80d5..0b98450a8 100644 --- a/application/models/reports/summary_discounts.php +++ b/application/models/reports/summary_discounts.php @@ -17,20 +17,14 @@ class Summary_discounts extends Report $this->db->select('CONCAT(discount_percent, "%") as discount_percent, count(*) as count', false); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'" and discount_percent > 0'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } $this->db->group_by('sales_items_temp.discount_percent'); $this->db->order_by('discount_percent'); return $this->db->get()->result_array(); @@ -41,20 +35,14 @@ class Summary_discounts extends Report $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax,sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'sale_stock\''); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'warehouse\''); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_employees.php b/application/models/reports/summary_employees.php index 63e960ec9..214293f8e 100644 --- a/application/models/reports/summary_employees.php +++ b/application/models/reports/summary_employees.php @@ -19,20 +19,14 @@ class Summary_employees extends Report $this->db->join('employees', 'employees.person_id = sales_items_temp.employee_id'); $this->db->join('people', 'employees.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } $this->db->group_by('employee_id'); $this->db->order_by('last_name'); @@ -46,15 +40,9 @@ class Summary_employees extends Report $this->db->join('employees', 'employees.person_id = sales_items_temp.employee_id'); $this->db->join('people', 'employees.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'sale_stock\''); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'warehouse\''); } elseif ($inputs['sale_type'] == 'returns') { diff --git a/application/models/reports/summary_items.php b/application/models/reports/summary_items.php index 9752d822f..e1d08ad3d 100644 --- a/application/models/reports/summary_items.php +++ b/application/models/reports/summary_items.php @@ -18,20 +18,14 @@ class Summary_items extends Report $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } $this->db->group_by('items.item_id'); $this->db->order_by('name'); @@ -44,15 +38,9 @@ class Summary_items extends Report $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'sale_stock\''); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'warehouse\''); } elseif ($inputs['sale_type'] == 'returns') { diff --git a/application/models/reports/summary_payments.php b/application/models/reports/summary_payments.php index 1f7f863db..2bfa4317e 100644 --- a/application/models/reports/summary_payments.php +++ b/application/models/reports/summary_payments.php @@ -18,20 +18,14 @@ class Summary_payments extends Report $this->db->from('sales_payments'); $this->db->join('sales', 'sales.sale_id=sales_payments.sale_id'); $this->db->where('date(sale_time) BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } $this->db->group_by("payment_type"); return $this->db->get()->result_array(); } @@ -42,20 +36,14 @@ class Summary_payments extends Report $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'sale_stock\''); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'warehouse\''); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_sales.php b/application/models/reports/summary_sales.php index a13ba4dd3..97c90757b 100644 --- a/application/models/reports/summary_sales.php +++ b/application/models/reports/summary_sales.php @@ -16,20 +16,14 @@ class Summary_sales extends Report { $this->db->select('sale_date, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax,sum(profit) as profit'); $this->db->from('sales_items_temp'); - if ($inputs['sale_type'] == 'sales_retail') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } $this->db->group_by('sale_date'); $this->db->having('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); @@ -42,20 +36,14 @@ class Summary_sales extends Report $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax,sum(profit) as profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'sale_stock\''); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'warehouse\''); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } return $this->db->get()->row_array(); } diff --git a/application/models/reports/summary_suppliers.php b/application/models/reports/summary_suppliers.php index f81af5286..6ee376a3f 100644 --- a/application/models/reports/summary_suppliers.php +++ b/application/models/reports/summary_suppliers.php @@ -19,20 +19,14 @@ class Summary_suppliers extends Report $this->db->join('suppliers', 'suppliers.person_id = sales_items_temp.supplier_id'); $this->db->join('people', 'suppliers.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } $this->db->group_by('supplier_id'); $this->db->order_by('last_name'); @@ -46,20 +40,14 @@ class Summary_suppliers extends Report $this->db->join('suppliers', 'suppliers.person_id = sales_items_temp.supplier_id'); $this->db->join('people', 'suppliers.person_id = people.person_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'sale_stock\''); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type = \'warehouse\''); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } return $this->db->get()->row_array(); } } diff --git a/application/models/reports/summary_taxes.php b/application/models/reports/summary_taxes.php index c35669001..d434b5818 100644 --- a/application/models/reports/summary_taxes.php +++ b/application/models/reports/summary_taxes.php @@ -51,20 +51,15 @@ class Summary_taxes extends Report $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales_retail') + if ($inputs['sale_type'] == 'sales') { $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'sale_stock'); - } - elseif($inputs['sale_type'] == 'sales_wholesale') - { - $this->db->where('quantity_purchased > 0'); - $this->db->where('sale_type', 'warehouse'); } elseif ($inputs['sale_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); - } + } + return $this->db->get()->row_array(); } diff --git a/application/models/sale.php b/application/models/sale.php index fb9a72a8d..b5d4be07d 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -28,7 +28,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,$stock_location, $sale_id=false) { if(count($items)==0) return -1; @@ -94,8 +94,11 @@ class Sale extends CI_Model $this->db->insert('sales_items',$sales_items_data); //Update stock quantity - $item_data = array('quantity'=>$cur_item_info->quantity - $item['quantity']); - $this->Item->save($item_data,$item['item_id']); + $item_quantity = $this->Item_quantitys->get_item_quantity($item['item_id'], $this->sale_lib->get_location_id_from_stock_location($this->sale_lib->get_sale_location())); + $this->Item_quantitys->save(array('quantity'=>$item_quantity->quantity - $item['quantity'], + 'item_id'=>$item['item_id'], + 'location_id'=>$this->sale_lib->get_location_id_from_stock_location($stock_location)), $item_quantity->item_quantity_id); + //Ramel Inventory Tracking //Inventory Count Details @@ -106,6 +109,7 @@ class Sale extends CI_Model 'trans_date'=>date('Y-m-d H:i:s'), 'trans_items'=>$item['item_id'], 'trans_user'=>$employee_id, + 'location_id'=>$this->sale_lib->get_location_id_from_stock_location($stock_location), 'trans_comment'=>$sale_remarks, 'trans_inventory'=>$qty_buy ); diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php new file mode 100644 index 000000000..20e485b5a --- /dev/null +++ b/application/models/stock_locations.php @@ -0,0 +1,84 @@ +db->from('stock_locations'); + $this->db->where('location_name',$location_name); + $query = $this->db->get(); + + return ($query->num_rows()==1); + } + + function get_all($limit=10000, $offset=0) + { + $this->db->from('stock_locations'); + $this->db->limit($limit); + $this->db->offset($offset); + return $this->db->get(); + } + + function get_undeleted_all($limit=10000, $offset=0) + { + $this->db->from('stock_locations'); + $this->db->where('deleted',0); + $this->db->limit($limit); + $this->db->offset($offset); + return $this->db->get(); + } + + function get_location_id($location_name) + { + $this->db->from('stock_locations'); + $this->db->where('deleted',0); + $this->db->where('location_name',$location_name); + return $this->db->get()->row()->location_id; + } + + function array_save($stock_locations) + { + $location_db = $this->get_all()->result_array(); + //Delete all in db + $this->db->trans_start(); + $location_ids=array(); + foreach($location_db as $db) + { + array_push($location_ids,$db['location_id']); + } + $this->db->where_in('location_id', $location_ids); + $this->db->update('stock_locations',array('deleted'=>1)); + $this->db->trans_complete(); + + $location_db = $this->get_all()->result_array(); + //Update the stock location + $this->db->trans_start(); + foreach ($stock_locations as $location) + { + $to_create = true; + foreach($location_db as $db) + { + if($db['location_name'] == $location) + { + if($db['deleted'] == 1) + { + $this->db->where('location_id', $db['location_id']); + + $this->db->update('stock_locations',array('location_name'=>$db['location_name'],'deleted'=>0)); + } + $to_create = false; + break; + } + } + + if($to_create) + { + $location_data = array('location_name'=>$location,'deleted'=>0); + $this->db->insert('stock_locations',$location_data); + } + } + $this->db->trans_complete(); + return true; + } +} +?> + \ No newline at end of file diff --git a/application/views/config.php b/application/views/config.php index b85afcba9..fb526b819 100644 --- a/application/views/config.php +++ b/application/views/config.php @@ -258,6 +258,16 @@ echo form_open('config/save/',array('id'=>'config_form')); +
+lang->line('config_stock_location').':', 'stock_location',array('class'=>'required wide')); ?> +
+ 'stock_location', + 'id'=>'stock_location', + 'value'=>$this->config->item('stock_location')));?> +
+
+
lang->line('config_print_after_sale').':', 'print_after_sale',array('class'=>'wide')); ?>
@@ -420,7 +430,9 @@ $(document).ready(function() number:true }, email:"email", - return_policy: "required" + return_policy: "required", + stock_location_number:"required" + }, messages: { @@ -433,7 +445,8 @@ $(document).ready(function() number:"lang->line('config_default_tax_rate_number'); ?>" }, email: "lang->line('common_email_invalid_format'); ?>", - return_policy:"lang->line('config_return_policy_required'); ?>" + return_policy:"lang->line('config_return_policy_required'); ?>", + stock_location_number:"lang->line('config_stock_location_required'); ?>" } }); diff --git a/application/views/items/count_details.php b/application/views/items/count_details.php index 22b48115c..bb27e3e0e 100644 --- a/application/views/items/count_details.php +++ b/application/views/items/count_details.php @@ -59,6 +59,16 @@ echo form_open('items/save_inventory/'.$item_info->item_id,array('id'=>'item_for +lang->line('items_stock_location').':', 'stock_location',array('class'=>'wide')); ?> + + + + + + + lang->line('items_current_quantity').':', 'quantity',array('class'=>'wide')); ?> @@ -66,7 +76,7 @@ echo form_open('items/save_inventory/'.$item_info->item_id,array('id'=>'item_for 'name'=>'quantity', 'id'=>'quantity', - 'value'=>$item_info->quantity, + 'value'=>current($item_quantitys), 'style' => 'border:none', 'readonly' => 'readonly' ); @@ -89,26 +99,74 @@ echo form_open('items/save_inventory/'.$item_info->item_id,array('id'=>'item_for - - -Inventory->get_inventory_data_for_item($item_info->item_id)->result_array() as $row) +$inventory_array = $this->Inventory->get_inventory_data_for_item($item_info->item_id)->result_array(); +$employee_name = array(); +foreach( $inventory_array as $row) { -?> - - - - - - - -Employee->get_info($person_id); + array_push($employee_name, $employee->first_name." ".$employee->last_name); } ?> -
Inventory Data Tracking
DateEmployeeIn/Out QtyRemarks
Employee->get_info($person_id); - echo $employee->first_name." ".$employee->last_name; - ?> -
\ No newline at end of file + + + +
Inventory Data Tracking
DateEmployeeIn/Out QtyRemarks
+ + \ No newline at end of file diff --git a/application/views/items/form.php b/application/views/items/form.php index 89fa23970..2dcdc17ce 100644 --- a/application/views/items/form.php +++ b/application/views/items/form.php @@ -112,17 +112,25 @@ echo form_open('items/save/'.$item_info->item_id,array('id'=>'item_form'));
- -
-lang->line('items_quantity').':', 'quantity',array('class'=>'required wide')); ?> -
- 'quantity', - 'id'=>'quantity', - 'value'=>$item_info->quantity) - );?> -
-
+$location_detail) +{ +?> +
+ lang->line('items_quantity').' '.$location_detail['location_name'] .':', + $key.'_quantity', + array('class'=>'required wide')); ?> +
+ $key.'_quantity', + 'id'=>$key.'_quantity', + 'value'=>$location_detail['quantity']) + );?> +
+
+
lang->line('items_reorder_level').':', 'reorder_level',array('class'=>'required wide')); ?> diff --git a/application/views/items/inventory.php b/application/views/items/inventory.php index 178c2d3b4..0d4192b0c 100644 --- a/application/views/items/inventory.php +++ b/application/views/items/inventory.php @@ -62,6 +62,16 @@ echo form_open('items/save_inventory/'.$item_info->item_id,array('id'=>'item_for +lang->line('items_stock_location').':', 'stock_location',array('class'=>'wide')); ?> + + + + + + + lang->line('items_current_quantity').':', 'quantity',array('class'=>'wide')); ?> @@ -69,7 +79,7 @@ echo form_open('items/save_inventory/'.$item_info->item_id,array('id'=>'item_for 'name'=>'quantity', 'id'=>'quantity', - 'value'=>$item_info->quantity, + 'value'=>current($item_quantitys), 'style' => 'border:none', 'readonly' => 'readonly' ); @@ -154,4 +164,11 @@ $(document).ready(function() } }); }); + + +function fill_quantity(val) +{ + var item_quantitys= ; + document.getElementById("quantity").value = item_quantitys[val]; +} \ No newline at end of file diff --git a/application/views/items/manage.php b/application/views/items/manage.php index ca282590c..7210092d1 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -22,7 +22,7 @@ $(document).ready(function() $(this).attr('href','index.php/items/generate_barcodes/'+selected.join(':')); }); - $("#low_inventory, #is_serialized, #no_description, #search_custom, #is_deleted").click(function() + $("#is_serialized, #no_description, #search_custom, #is_deleted").click(function() { $('#items_filter_form').submit(); }); @@ -135,18 +135,12 @@ function show_hide_search_filter(search_filter_section, switchImgTag) {
'items_filter_form')); ?> - lang->line('items_low_inventory_items').' '.':', 'low_inventory');?> - 'low_inventory','id'=>'low_inventory','value'=>1,'checked'=> isset($low_inventory)? ( ($low_inventory)? 1 : 0) : 0)).' | ';?> lang->line('items_serialized_items').' '.':', 'is_serialized');?> 'is_serialized','id'=>'is_serialized','value'=>1,'checked'=> isset($is_serialized)? ( ($is_serialized)? 1 : 0) : 0)).' | ';?> lang->line('items_no_description_items').' '.':', 'no_description');?> 'no_description','id'=>'no_description','value'=>1,'checked'=> isset($no_description)? ( ($no_description)? 1 : 0) : 0)).' | ';?> lang->line('items_search_custom_items').' '.':', 'search_custom');//GARRISON ADDED 4/21/2013?> - 'search_custom','id'=>'search_custom','value'=>1,'checked'=> isset($search_custom)? ( ($search_custom)? 1 : 0) : 0)).' | ';//GARRISON ADDED 4/21/2013?> - lang->line('items_stock_type').' '.':', 'stock_type');?> - 'All','sale_stock'=>$this->lang->line('items_stock_type_sale'),'warehouse'=>$this->lang->line('items_stock_type_warehouse')); - echo form_dropdown('stock_type',$stock_type_array,$stock_type,'onchange="$(\'#items_filter_form\').submit();"'); ?> - + 'search_custom','id'=>'search_custom','value'=>1,'checked'=> isset($search_custom)? ( ($search_custom)? 1 : 0) : 0));//GARRISON ADDED 4/21/2013?>
diff --git a/application/views/receivings/receiving.php b/application/views/receivings/receiving.php index 6f8b24b8e..1d3219d3d 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -13,8 +13,28 @@ if(isset($error))
'mode_form')); ?> - lang->line('recvs_mode') ?> + lang->line('recvs_mode') ?> + + + lang->line('recvs_stock_source') ?> + + lang->line('recvs_stock_destination') ?> + + + lang->line('recvs_stock_locaiton') ?> + + + 'add_item_form')); ?>