From e1bfac5eaef0853be7c682ee4308b749e3bfe1ef Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Sun, 15 Jun 2014 15:30:32 +0200 Subject: [PATCH] requisition receipt fixed database.sql script merged with current ospos one remaining problems in reporting (sale_type to add in sales_temp query?) data model should be refactored to allow more genericity for custom item locations (2+) inventory tracking should be adapted to use multiple locations (instead of duplicating items for different locations) --- .gitignore | 3 + application/config/autoload.php | 3 +- application/config/routes.php | 4 +- application/controllers/items.php | 208 ++++++++++-------- application/controllers/receivings.php | 83 ++++++- application/controllers/reports.php | 58 ++++- application/controllers/sales.php | 21 +- application/language/en/employees_lang.php | 1 + application/language/en/items_lang.php | 115 +++++----- application/language/en/receivings_lang.php | 45 ++-- application/language/en/reports_lang.php | 15 +- application/language/en/sales_lang.php | 67 +++--- application/language/th/common_lang.php | 82 +++++++ application/language/th/config_lang.php | 72 ++++++ application/language/th/customers_lang.php | 32 +++ application/language/th/employees_lang.php | 54 +++++ application/language/th/error_lang.php | 8 + application/language/th/giftcards_lang.php | 140 ++++++++++++ application/language/th/index.html | 20 ++ application/language/th/item_kits_lang.php | 40 ++++ application/language/th/items_lang.php | 170 ++++++++++++++ application/language/th/login_lang.php | 16 ++ application/language/th/module_lang.php | 68 ++++++ application/language/th/receivings_lang.php | 72 ++++++ application/language/th/reports_lang.php | 204 +++++++++++++++++ application/language/th/sales_lang.php | 160 ++++++++++++++ application/language/th/suppliers_lang.php | 34 +++ application/libraries/Receiving_lib.php | 117 ++++++++++ application/libraries/Sale_lib.php | 51 +++-- application/models/item.php | 186 +++++++++------- application/models/item_unit.php | 60 +++++ application/models/receiving.php | 192 +++++++++++++++- .../models/reports/detailed_receivings.php | 8 +- .../models/reports/detailed_requisition.php | 62 ++++++ application/models/reports/detailed_sales.php | 44 ++-- application/models/reports/report.php | 1 + .../models/reports/specific_customer.php | 44 ++-- .../models/reports/specific_employee.php | 44 ++-- .../models/reports/summary_categories.php | 44 ++-- .../models/reports/summary_customers.php | 44 ++-- .../models/reports/summary_discounts.php | 44 ++-- .../models/reports/summary_employees.php | 44 ++-- application/models/reports/summary_items.php | 44 ++-- .../models/reports/summary_payments.php | 44 ++-- application/models/reports/summary_sales.php | 34 ++- .../models/reports/summary_suppliers.php | 45 ++-- application/models/reports/summary_taxes.php | 22 +- application/views/config.php | 3 +- application/views/items/form.php | 55 ++++- application/views/items/manage.php | 10 +- application/views/receivings/receiving.php | 168 ++++++++++---- .../views/receivings/requisition_receipt.php | 77 +++++++ application/views/reports/date_input.php | 44 +++- .../views/reports/date_input_excel_export.php | 5 +- application/views/reports/listing.php | 6 + application/views/reports/specific_input.php | 5 +- application/views/sales/register.php | 5 +- database/database.sql | 83 ++++++- 58 files changed, 2866 insertions(+), 564 deletions(-) create mode 100644 application/language/th/common_lang.php create mode 100644 application/language/th/config_lang.php create mode 100644 application/language/th/customers_lang.php create mode 100644 application/language/th/employees_lang.php create mode 100644 application/language/th/error_lang.php create mode 100644 application/language/th/giftcards_lang.php create mode 100644 application/language/th/index.html create mode 100644 application/language/th/item_kits_lang.php create mode 100644 application/language/th/items_lang.php create mode 100644 application/language/th/login_lang.php create mode 100644 application/language/th/module_lang.php create mode 100644 application/language/th/receivings_lang.php create mode 100644 application/language/th/reports_lang.php create mode 100644 application/language/th/sales_lang.php create mode 100644 application/language/th/suppliers_lang.php create mode 100644 application/models/item_unit.php create mode 100644 application/models/reports/detailed_requisition.php create mode 100644 application/views/receivings/requisition_receipt.php diff --git a/.gitignore b/.gitignore index f278bb8e7..7e5d0303b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ git-svn-diff.py .buildpath .project .settings/* +*.swp +*.rej +*.orig diff --git a/application/config/autoload.php b/application/config/autoload.php index 9cd3f57ff..148e43ad7 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -66,6 +66,7 @@ $autoload['libraries'] = array('database','form_validation','session','user_agen $autoload['helper'] = array('form','url','table','text','currency', 'html', 'download', 'directory'); + /* | ------------------------------------------------------------------- | Auto-load Config files @@ -108,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'); +$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'); /* End of file autoload.php */ diff --git a/application/config/routes.php b/application/config/routes.php index 331fff2ff..e3715274a 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -50,7 +50,9 @@ $route['reports/inventory_:any'] = "reports/excel_export"; $route['reports/(detailed_sales)/(:any)/(:any)'] = "reports/$1/$2/$3"; $route['reports/detailed_sales'] = "reports/date_input"; $route['reports/(detailed_receivings)/(:any)/(:any)'] = "reports/$1/$2/$3"; -$route['reports/detailed_receivings'] = "reports/date_input"; +$route['reports/detailed_receivings'] = "reports/date_input_recv"; +$route['reports/(detailed_requisition)/(:any)/(:any)'] = "reports/$1/$2/$3"; +$route['reports/detailed_requisition'] = "reports/date_input_reqs"; $route['reports/(specific_:any)/(:any)/(:any)/(:any)'] = "reports/$1/$2/$3/$4"; $route['reports/specific_customer'] = "reports/specific_customer_input"; $route['reports/specific_employee'] = "reports/specific_employee_input"; diff --git a/application/controllers/items.php b/application/controllers/items.php index 7f5b504f0..a5f2839c3 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -27,18 +27,20 @@ class Items extends Secure_area implements iData_controller $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 - + $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'); + $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),$this);//GARRISON MODIFIED 4/13/2013, Parq 131215 + $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 $this->load->view('items/manage',$data); } @@ -66,7 +68,7 @@ class Items extends Secure_area implements iData_controller function item_search() { - $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit')); + $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit'),'warehouse'); echo implode("\n",$suggestions); } @@ -80,104 +82,104 @@ class Items extends Secure_area implements iData_controller } /**GARRISON ADDED 5/18/2013**/ - /* - Gives search suggestions based on what is being searched for - */ - function suggest_location() - { - $suggestions = $this->Item->get_location_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_location() + { + $suggestions = $this->Item->get_location_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom1() - { - $suggestions = $this->Item->get_custom1_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom1() + { + $suggestions = $this->Item->get_custom1_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom2() - { - $suggestions = $this->Item->get_custom2_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom2() + { + $suggestions = $this->Item->get_custom2_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom3() - { - $suggestions = $this->Item->get_custom3_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom3() + { + $suggestions = $this->Item->get_custom3_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom4() - { - $suggestions = $this->Item->get_custom4_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom4() + { + $suggestions = $this->Item->get_custom4_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom5() - { - $suggestions = $this->Item->get_custom5_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom5() + { + $suggestions = $this->Item->get_custom5_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom6() - { - $suggestions = $this->Item->get_custom6_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom6() + { + $suggestions = $this->Item->get_custom6_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom7() - { - $suggestions = $this->Item->get_custom7_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom7() + { + $suggestions = $this->Item->get_custom7_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom8() - { - $suggestions = $this->Item->get_custom8_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom8() + { + $suggestions = $this->Item->get_custom8_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom9() - { - $suggestions = $this->Item->get_custom9_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom9() + { + $suggestions = $this->Item->get_custom9_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } - /* - Gives search suggestions based on what is being searched for - */ - function suggest_custom10() - { - $suggestions = $this->Item->get_custom10_suggestions($this->input->post('q')); - echo implode("\n",$suggestions); - } + /* + Gives search suggestions based on what is being searched for + */ + function suggest_custom10() + { + $suggestions = $this->Item->get_custom10_suggestions($this->input->post('q')); + echo implode("\n",$suggestions); + } /**END GARRISON ADDED**/ @@ -202,6 +204,9 @@ class Items extends Secure_area implements iData_controller $data['selected_supplier'] = $this->Item->get_info($item_id)->supplier_id; $data['default_tax_1_rate']=($item_id==-1) ? $this->Appconfig->get('default_tax_1_rate') : ''; $data['default_tax_2_rate']=($item_id==-1) ? $this->Appconfig->get('default_tax_2_rate') : ''; + $data['stock_type'] = $data['item_info']->stock_type; + + $data['item_unit_info']=$this->Item_unit->get_info($item_id); $this->load->view("items/form",$data); } @@ -271,7 +276,7 @@ class Items extends Secure_area implements iData_controller 'allow_alt_description'=>$this->input->post('allow_alt_description'), 'is_serialized'=>$this->input->post('is_serialized'), 'deleted'=>$this->input->post('is_deleted'), /** Parq 131215 **/ - + 'stock_type'=>$this->input->post('stock_type'), 'custom1'=>$this->input->post('custom1'), /**GARRISON ADDED 4/21/2013**/ 'custom2'=>$this->input->post('custom2'),/**GARRISON ADDED 4/21/2013**/ 'custom3'=>$this->input->post('custom3'),/**GARRISON ADDED 4/21/2013**/ @@ -323,6 +328,16 @@ 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) + { + $items_unit_data['related_number'] = $item_data['item_number']; + } + $this->Item_unit->save($items_unit_data, $item_id); } else//failure { @@ -552,5 +567,10 @@ class Items extends Secure_area implements iData_controller { return 360; } + + function is_sale_store_item($item_number) + { + echo $this->Item->is_sale_store_item_exist($item_number); + } } ?> \ No newline at end of file diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index 7945064d7..ddd265326 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')); + $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit'),'warehouse'); $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,7 @@ class Receivings extends Secure_area { $mode = $this->input->post("mode"); $this->receiving_lib->set_mode($mode); + $this->receiving_lib->empty_cart(); $this->_reload(); } @@ -45,7 +46,7 @@ class Receivings extends Secure_area $data=array(); $mode = $this->receiving_lib->get_mode(); $item_id_or_number_or_item_kit_or_receipt = $this->input->post("item"); - $quantity = $mode=="receive" ? 1:-1; + $quantity = ($mode=="receive" or $mode=="requisition") ? 1:-1; if($this->receiving_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt) && $mode=='return') { @@ -55,9 +56,19 @@ class Receivings extends Secure_area { $this->receiving_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt); } - elseif(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt,$quantity)) + else { - $data['error']=$this->lang->line('recvs_unable_to_add_item'); + if($mode == 'requisition') + { + if(!$this->receiving_lib->add_item_unit($item_id_or_number_or_item_kit_or_receipt)) + $data['error']=$this->lang->line('reqs_unable_to_add_item'); + } + else + { + if(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt,$quantity)) + $data['error']=$this->lang->line('recvs_unable_to_add_item'); + } + } $this->_reload($data); } @@ -88,6 +99,26 @@ class Receivings extends Secure_area $this->_reload($data); } + function edit_item_unit($item_id) + { + $data= array(); + + $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|integer'); + $quantity = $this->input->post("quantity"); + + + if ($this->form_validation->run() != FALSE) + { + $this->receiving_lib->edit_item_unit($item_id,$description,$quantity,0,0); + } + else + { + $data['error']=$this->lang->line('recvs_error_editing_item'); + } + + $this->_reload($data); + } + function delete_item($item_number) { $this->receiving_lib->delete_item($item_number); @@ -138,6 +169,48 @@ class Receivings extends Secure_area $this->receiving_lib->clear_all(); } + function requisition_complete() + { + $data['cart']=$this->receiving_lib->get_cart(); + $data['receipt_title']=$this->lang->line('reqs_receipt'); + $data['transaction_time']= date('m/d/Y h:i:s a'); + + $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; + $emp_info=$this->Employee->get_info($employee_id); + $data['employee']=$emp_info->first_name.' '.$emp_info->last_name; + + $comment = $this->input->post('comment'); + + //SAVE requisition to database + $data['requisition_id']='REQS '.$this->Receiving->save_requisition($data['cart'],$employee_id,$comment); + + if ($data['requisition_id'] == 'REQS -1') + { + $data['error_message'] = $this->lang->line('reqs_transaction_failed'); + } + + $this->load->view("receivings/requisition_receipt",$data); + $this->receiving_lib->clear_all(); + } + + function requisition_receipt($requisition_id) + { + $requisition_info = $this->Receiving->get_requisition_info($requisition_id)->row_array(); + $this->receiving_lib->copy_entire_requisition($requisition_id); + + $data['cart']=$this->receiving_lib->get_cart(); + $data['receipt_title']=$this->lang->line('reqs_receipt'); + $data['transaction_time']= date('m/d/Y h:i:s a'); + + $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; + $emp_info=$this->Employee->get_info($employee_id); + $data['employee']=$emp_info->first_name.' '.$emp_info->last_name; + + $data['requisition_id']='REQS '.$requisition_id; + $this->load->view("receivings/requisition_receipt",$data); + $this->receiving_lib->clear_all(); + } + function receipt($receiving_id) { $receiving_info = $this->Receiving->get_info($receiving_id)->row_array(); @@ -167,7 +240,7 @@ class Receivings extends Secure_area { $person_info = $this->Employee->get_logged_in_employee_info(); $data['cart']=$this->receiving_lib->get_cart(); - $data['modes']=array('receive'=>$this->lang->line('recvs_receiving'),'return'=>$this->lang->line('recvs_return')); + $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['total']=$this->receiving_lib->get_total(); $data['items_module_allowed'] = $this->Employee->has_permission('items', $person_info->person_id); diff --git a/application/controllers/reports.php b/application/controllers/reports.php index 029303de6..23f4b3cc8 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -302,9 +302,24 @@ class Reports extends Secure_area function date_input() { $data = $this->_get_common_report_data(); + $data['mode'] = 'sale'; $this->load->view("reports/date_input",$data); } + function date_input_recv() + { + $data = $this->_get_common_report_data(); + $data['mode'] = 'receiving'; + $this->load->view("reports/date_input",$data); + } + + function date_input_reqs() + { + $data = $this->_get_common_report_data(); + $data['mode'] = 'requisition'; + $this->load->view("reports/date_input",$data); + } + //Graphical summary sales report function graphical_summary_sales($start_date, $end_date, $sale_type) { @@ -827,14 +842,14 @@ class Reports extends Secure_area $this->load->view("reports/tabular_details",$data); } - - function detailed_receivings($start_date, $end_date, $sale_type, $export_excel=0) + + function detailed_receivings($start_date, $end_date, $receiving_type, $export_excel=0) { $this->load->model('reports/Detailed_receivings'); $model = $this->Detailed_receivings; $headers = $model->getDataColumns(); - $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)); + $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'receiving_type' => $receiving_type)); $summary_data = array(); $details_data = array(); @@ -855,13 +870,46 @@ class Reports extends Secure_area "headers" => $model->getDataColumns(), "summary_data" => $summary_data, "details_data" => $details_data, - "overall_summary_data" => $model->getSummaryData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'sale_type' => $sale_type)), + "overall_summary_data" => $model->getSummaryData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'receiving_type' => $receiving_type)), "export_excel" => $export_excel ); $this->load->view("reports/tabular_details",$data); } - + + function detailed_requisition($start_date, $end_date , $export_excel=0) + { + $this->load->model('reports/Detailed_requisition'); + $model = $this->Detailed_requisition; + $report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date)); + + $summary_data = array(); + $details_data = array(); + + foreach($report_data['summary'] as $key=>$row) + { + $summary_data[] = array(anchor('receivings/requisition_receipt/'.$row['requisition_id'], 'REQS '.$row['requisition_id'], array('target' => '_blank')), $row['requisition_date'], $row['employee_name'], $row['comment']); + + foreach($report_data['details'][$key] as $drow) + { + $details_data[$key][] = array($drow['name'], $drow['requisition_quantity'], + $drow['related_item_id'], $drow['related_item_quantity'], + $drow['related_item_total_quantity']); + } + } + + $data = array( + "title" =>$this->lang->line('reports_detailed_requisition_report'), + "subtitle" => date('m/d/Y', strtotime($start_date)) .'-'.date('m/d/Y', strtotime($end_date)), + "headers" => $model->getDataColumns(), + "summary_data" => $summary_data, + "details_data" => $details_data, + "overall_summary_data" => '', + "export_excel" => $export_excel + ); + $this->load->view("reports/tabular_details",$data); + } + function excel_export() { $this->load->view("reports/excel_export",array()); diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 9528b244d..b0a2622c6 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -15,7 +15,16 @@ class Sales extends Secure_area function item_search() { - $suggestions = $this->Item->get_item_search_suggestions($this->input->post('q'),$this->input->post('limit')); + $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 = array_merge($suggestions, $this->Item_kit->get_item_kit_search_suggestions($this->input->post('q'),$this->input->post('limit'))); echo implode("\n",$suggestions); } @@ -35,8 +44,9 @@ class Sales extends Secure_area function change_mode() { + $this->sale_lib->clear_all(); $mode = $this->input->post("mode"); - $this->sale_lib->set_mode($mode); + $this->sale_lib->set_mode($mode); $this->_reload(); } @@ -112,7 +122,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" ? 1:-1; + $quantity = (($mode=="sale_wholesale") or ($mode=="sale_retail"))? 1:-1; if($this->sale_lib->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt) && $mode=='return') { @@ -329,7 +339,8 @@ class Sales extends Secure_area } /* Changed the conditional to account for floating point rounding */ - if ( ( $this->sale_lib->get_mode() == 'sale' ) && ( ( to_currency_no_money( $this->sale_lib->get_total() ) - $total_payments ) > 1e-6 ) ) + if ( ( ($this->sale_lib->get_mode() == 'sale_retail') || ($this->sale_lib->get_mode() == 'sale_wholesale')) && + ( ( to_currency_no_money( $this->sale_lib->get_total() ) - $total_payments ) > 1e-6 ) ) { return false; } @@ -341,7 +352,7 @@ class Sales extends Secure_area { $person_info = $this->Employee->get_logged_in_employee_info(); $data['cart']=$this->sale_lib->get_cart(); - $data['modes']=array('sale'=>$this->lang->line('sales_sale'),'return'=>$this->lang->line('sales_return')); + $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['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/employees_lang.php b/application/language/en/employees_lang.php index f70776bd7..5f77c5a85 100644 --- a/application/language/en/employees_lang.php +++ b/application/language/en/employees_lang.php @@ -23,4 +23,5 @@ $lang['employees_login_info'] = 'Employee Login Info'; $lang['employees_permission_info'] = 'Employee Permissions and Access'; $lang['employees_permission_desc'] = 'Check the boxes below to grant access to modules'; $lang['employees_error_updating_demo_admin'] = 'You can not change the demo admin user'; +$lang['employees_error_deleting_demo_admin'] = 'You can not delete the demo admin user'; ?> diff --git a/application/language/en/items_lang.php b/application/language/en/items_lang.php index 84a3118ad..5b4b38ff6 100644 --- a/application/language/en/items_lang.php +++ b/application/language/en/items_lang.php @@ -1,56 +1,56 @@ diff --git a/application/language/en/receivings_lang.php b/application/language/en/receivings_lang.php index 5212e5b22..6e1e03bce 100644 --- a/application/language/en/receivings_lang.php +++ b/application/language/en/receivings_lang.php @@ -1,26 +1,35 @@ diff --git a/application/language/en/reports_lang.php b/application/language/en/reports_lang.php index 3f92d44bb..063321c81 100644 --- a/application/language/en/reports_lang.php +++ b/application/language/en/reports_lang.php @@ -43,8 +43,8 @@ $lang['reports_all_time'] = 'All Time'; $lang['reports_detailed_sales_report'] = 'Detailed Sales Report'; $lang['reports_comments'] = 'Comments'; $lang['reports_discount'] = 'Discount'; +$lang['reports_sales']= 'Sale'; $lang['reports_payment_type'] = 'Payment Type'; -$lang['reports_sales'] = 'Sales'; $lang['reports_categories'] = 'Categories'; $lang['reports_customers'] = 'Customers'; $lang['reports_suppliers'] = 'Suppliers'; @@ -84,7 +84,20 @@ $lang['reports_supplied_by'] = 'Supplied by'; $lang['reports_items_received'] = 'Items Received'; $lang['reports_detailed_receivings_report'] = 'Detailed Receivings Report'; $lang['reports_sale_type'] = 'Sale Type'; +$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_requisition'] = 'Requisition'; +$lang['reports_receiving_id'] = 'Receiving ID'; +$lang['reports_requisition_id'] = 'Requisition ID'; +$lang['reports_requisition_by'] = 'Requisition by'; +$lang['reports_requisition_item'] = 'Name'; +$lang['reports_requisition_item_quantity'] = 'Requisition qty.'; +$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'; ?> diff --git a/application/language/en/sales_lang.php b/application/language/en/sales_lang.php index a0ab4134e..a5dfa415d 100644 --- a/application/language/en/sales_lang.php +++ b/application/language/en/sales_lang.php @@ -1,42 +1,42 @@ + \ No newline at end of file diff --git a/application/language/th/config_lang.php b/application/language/th/config_lang.php new file mode 100644 index 000000000..60438ce85 --- /dev/null +++ b/application/language/th/config_lang.php @@ -0,0 +1,72 @@ + + \ No newline at end of file diff --git a/application/language/th/customers_lang.php b/application/language/th/customers_lang.php new file mode 100644 index 000000000..3633d40f6 --- /dev/null +++ b/application/language/th/customers_lang.php @@ -0,0 +1,32 @@ + + diff --git a/application/language/th/employees_lang.php b/application/language/th/employees_lang.php new file mode 100644 index 000000000..d997b1995 --- /dev/null +++ b/application/language/th/employees_lang.php @@ -0,0 +1,54 @@ + + diff --git a/application/language/th/error_lang.php b/application/language/th/error_lang.php new file mode 100644 index 000000000..7ea3d00bf --- /dev/null +++ b/application/language/th/error_lang.php @@ -0,0 +1,8 @@ + + diff --git a/application/language/th/giftcards_lang.php b/application/language/th/giftcards_lang.php new file mode 100644 index 000000000..f18a7ee12 --- /dev/null +++ b/application/language/th/giftcards_lang.php @@ -0,0 +1,140 @@ + + diff --git a/application/language/th/index.html b/application/language/th/index.html new file mode 100644 index 000000000..87e766a7d --- /dev/null +++ b/application/language/th/index.html @@ -0,0 +1,20 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/application/language/th/item_kits_lang.php b/application/language/th/item_kits_lang.php new file mode 100644 index 000000000..cbe0d9e09 --- /dev/null +++ b/application/language/th/item_kits_lang.php @@ -0,0 +1,40 @@ + + diff --git a/application/language/th/items_lang.php b/application/language/th/items_lang.php new file mode 100644 index 000000000..a22680d57 --- /dev/null +++ b/application/language/th/items_lang.php @@ -0,0 +1,170 @@ + + diff --git a/application/language/th/login_lang.php b/application/language/th/login_lang.php new file mode 100644 index 000000000..7440d6b48 --- /dev/null +++ b/application/language/th/login_lang.php @@ -0,0 +1,16 @@ + + diff --git a/application/language/th/module_lang.php b/application/language/th/module_lang.php new file mode 100644 index 000000000..10857a328 --- /dev/null +++ b/application/language/th/module_lang.php @@ -0,0 +1,68 @@ + + diff --git a/application/language/th/receivings_lang.php b/application/language/th/receivings_lang.php new file mode 100644 index 000000000..ac6ab3522 --- /dev/null +++ b/application/language/th/receivings_lang.php @@ -0,0 +1,72 @@ + + diff --git a/application/language/th/reports_lang.php b/application/language/th/reports_lang.php new file mode 100644 index 000000000..854f67638 --- /dev/null +++ b/application/language/th/reports_lang.php @@ -0,0 +1,204 @@ + + diff --git a/application/language/th/sales_lang.php b/application/language/th/sales_lang.php new file mode 100644 index 000000000..684597900 --- /dev/null +++ b/application/language/th/sales_lang.php @@ -0,0 +1,160 @@ + + \ No newline at end of file diff --git a/application/language/th/suppliers_lang.php b/application/language/th/suppliers_lang.php new file mode 100644 index 000000000..77a53cc4e --- /dev/null +++ b/application/language/th/suppliers_lang.php @@ -0,0 +1,34 @@ + + diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 407293658..7a1c7ba7a 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -125,6 +125,98 @@ class Receiving_lib } + function add_item_unit($item_id,$quantity=1, $description=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; + } + + $related_item_number = $this->CI->Item_unit->get_info($item_id)->related_number; + if($related_item_number!= null && !$this->CI->Item->is_warehouse_item_exist($related_item_number)) + { + return false; + } + + //Get items in the requisition 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) + { + $itemalreadyinsale=TRUE; + $updatekey=$item['line']; + } + } + + $insertkey=$maxkey+1; + + + //array records are identified by $insertkey and item_id is just another field. + $item = array(($insertkey)=> + array( + 'item_id'=>$item_id, + 'line'=>$insertkey, + 'name'=>$this->CI->Item->get_info($item_id)->name, + 'description'=>$description!=null ? $description: $this->CI->Item->get_info($item_id)->description, + 'quantity'=>$quantity + ) + ); + + $item[$insertkey]['unit_quantity']= $this->CI->Item_unit->get_info($item_id)->unit_quantity; + $related_item_id = $this->CI->Item->get_item_id($related_item_number,'warehouse'); + if($related_item_id == null) + { + $related_item_id = $this->CI->Item->get_item_id($related_item_number,'sale_stock'); + if($related_item_id == null) + { + return false; + } + } + $item[$insertkey]['related_item'] = $this->CI->Item->get_info($related_item_id)->name; + + //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(); @@ -140,6 +232,18 @@ class Receiving_lib return false; } + + function edit_item_unit($line,$description,$quantity,$unit_quantity,$related_item) + { + $items = $this->get_cart(); + if(isset($items[$line])) + { + $items[$line]['quantity'] = $quantity; + $this->set_cart($items); + } + + return false; + } function is_valid_receipt($receipt_receiving_id) { @@ -207,6 +311,19 @@ class Receiving_lib $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); } + + function copy_entire_requisition($requisition_id) + { + $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->quantity_purchased,$row->description); + } + $this->set_supplier($this->CI->Receiving->get_supplier($requisition_id)->person_id); + + } function delete_item($line) { diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index f7c75eb44..80017796a 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'); + $this->set_mode('sale_retail'); return $this->CI->session->userdata('sale_mode'); } @@ -169,16 +169,11 @@ class Sale_lib function add_item($item_id,$quantity=1,$discount=0,$price=null,$description=null,$serialnumber=null) { - //make sure item exists - 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; - } - + //make sure item exists + if($this->validate_item($item_id) == false) + { + return false; + } //Alain Serialization and Description @@ -250,14 +245,11 @@ class Sale_lib function out_of_stock($item_id) { //make sure item exists - 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($this->validate_item($item_id) == false) + { + return false; + } - if(!$item_id) - return false; - } $item = $this->CI->Item->get_info($item_id); $quanity_added = $this->get_quantity_already_added($item_id); @@ -494,5 +486,28 @@ class Sale_lib return to_currency_no_money($total); } + + function validate_item(&$item_id) + { + //make sure item exists + if(!$this->CI->Item->exists($item_id)) + { + //try to get item id given an item_number + $mode = $this->get_mode(); + $item_id; + if($mode == 'sale_retail') + { + $item_id = $this->CI->Item->get_item_id($item_id, 'sale_stock'); + } + elseif($mode == 'sale_wholesale') + { + $item_id = $this->CI->Item->get_item_id($item_id, 'warehouse'); + } + + if(!$item_id) + return false; + } + return true; + } } ?> \ No newline at end of file diff --git a/application/models/item.php b/application/models/item.php index ab9a9c8f1..47558c8fc 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -33,7 +33,7 @@ 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)/**GARRISON MODIFIED 4/21/2013, Parq 131215 **/ + 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 **/ { $this->db->from('items'); if ($low_inventory !=0 ) @@ -48,10 +48,17 @@ class Item extends CI_Model { $this->db->where('description',''); } + + if($stock_type!='all') + { + $this->db->where('stock_type',$stock_type); + } + + /**GARRISON SECTION ADDED 4/21/2013**/ /** - if ($search_custom!=0 ) - { + if ($search_custom!=0 ) + { $this->db->like('custom1',$search); $this->db->or_like('custom2',$search); $this->db->or_like('custom3',$search); @@ -63,7 +70,7 @@ class Item extends CI_Model $this->db->or_like('custom9',$search); $this->db->or_like('custom10',$search); } -**/ +**/ /* Parq 131215 start*/ if ($is_deleted !=0 ) { @@ -110,12 +117,13 @@ class Item extends CI_Model /* Get an item id given an item number */ - function get_item_id($item_number) + function get_item_id($item_number, $stock_type='warehouse') { $this->db->from('items'); $this->db->where('item_number',$item_number); - $this->db->where('deleted',0); // Parq 131226 - + $this->db->where('deleted',0); // Parq 131226 + $this->db->where('stock_type',$stock_type); + $query = $this->db->get(); if($query->num_rows()==1) @@ -223,19 +231,19 @@ class Item extends CI_Model } /** GARRISON ADDED 4/21/2013 **/ //Search by description - $this->db->from('items'); - $this->db->like('description', $search); - $this->db->where('deleted',0); - $this->db->order_by("description", "asc"); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[]=$row->name; - } + $this->db->from('items'); + $this->db->like('description', $search); + $this->db->where('deleted',0); + $this->db->order_by("description", "asc"); + $by_name = $this->db->get(); + foreach($by_name->result() as $row) + { + $suggestions[]=$row->name; + } /** END GARRISON ADDED **/ /** GARRISON ADDED 4/22/2013 **/ - //Search by custom fields + //Search by custom fields $this->db->from('items'); $this->db->like('custom1', $search); $this->db->or_like('custom2', $search); @@ -246,13 +254,13 @@ class Item extends CI_Model $this->db->or_like('custom7', $search); $this->db->or_like('custom8', $search); $this->db->or_like('custom9', $search); - $this->db->or_like('custom10', $search); - $this->db->where('deleted',0); - $this->db->order_by("name", "asc"); - $by_name = $this->db->get(); - foreach($by_name->result() as $row) - { - $suggestions[]=$row->name; + $this->db->or_like('custom10', $search); + $this->db->where('deleted',0); + $this->db->order_by("name", "asc"); + $by_name = $this->db->get(); + foreach($by_name->result() as $row) + { + $suggestions[]=$row->name; } /** END GARRISON ADDED **/ @@ -265,12 +273,13 @@ class Item extends CI_Model } - function get_item_search_suggestions($search,$limit=25) + function get_item_search_suggestions($search,$limit=25,$stock_type='warehouse') { $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(); @@ -281,6 +290,7 @@ 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(); @@ -290,20 +300,22 @@ class Item extends CI_Model } /** GARRISON ADDED 4/21/2013 **/ //Search by description - $this->db->from('items'); - $this->db->where('deleted',0); - $this->db->like('description', $search); - $this->db->order_by("description", "asc"); - $by_description = $this->db->get(); - foreach($by_description->result() as $row) - { - $suggestions[]=$row->item_id.'|'.$row->name; - } + $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(); + foreach($by_description->result() as $row) + { + $suggestions[]=$row->item_id.'|'.$row->name; + } /** END GARRISON ADDED **/ /** GARRISON ADDED 4/22/2013 **/ - //Search by custom fields - $this->db->from('items'); + //Search by custom fields + /*$this->db->from('items'); $this->db->where('deleted',0); + $this->db->where('stock_type',$stock_type); $this->db->like('custom1', $search); $this->db->or_like('custom2', $search); $this->db->or_like('custom3', $search); @@ -313,13 +325,13 @@ class Item extends CI_Model $this->db->or_like('custom7', $search); $this->db->or_like('custom8', $search); $this->db->or_like('custom9', $search); - $this->db->or_like('custom10', $search); - $this->db->order_by("name", "asc"); - $by_description = $this->db->get(); - foreach($by_description->result() as $row) - { - $suggestions[]=$row->item_id.'|'.$row->name; - } + $this->db->or_like('custom10', $search); + $this->db->order_by("name", "asc"); + $by_description = $this->db->get(); + foreach($by_description->result() as $row) + { + $suggestions[]=$row->item_id.'|'.$row->name; + }*/ /** END GARRISON ADDED **/ //only return $limit suggestions @@ -349,40 +361,40 @@ class Item extends CI_Model } /** GARRISON ADDED 5/18/2013 **/ - function get_location_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('location'); - $this->db->from('items'); - $this->db->like('location', $search); - $this->db->where('deleted', 0); - $this->db->order_by("location", "asc"); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[]=$row->location; - } - - return $suggestions; - } + function get_location_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('location'); + $this->db->from('items'); + $this->db->like('location', $search); + $this->db->where('deleted', 0); + $this->db->order_by("location", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->location; + } + + return $suggestions; + } - function get_custom1_suggestions($search) - { - $suggestions = array(); - $this->db->distinct(); - $this->db->select('custom1'); - $this->db->from('items'); - $this->db->like('custom1', $search); - $this->db->where('deleted', 0); - $this->db->order_by("custom1", "asc"); - $by_category = $this->db->get(); - foreach($by_category->result() as $row) - { - $suggestions[]=$row->custom1; - } - - return $suggestions; + function get_custom1_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom1'); + $this->db->from('items'); + $this->db->like('custom1', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom1", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom1; + } + + return $suggestions; } function get_custom2_suggestions($search) @@ -583,5 +595,27 @@ class Item extends CI_Model return $this->db->get(); } + + function is_sale_store_item_exist($item_number) + { + $this->db->from('items'); + $this->db->where('item_number',$item_number); + $this->db->where('stock_type','sale_stock'); + $this->db->where('deleted',0); + + $query = $this->db->get(); + return ($query->num_rows()==1); + } + + function is_warehouse_item_exist($item_number) + { + $this->db->from('items'); + $this->db->where('item_number',$item_number); + $this->db->where('stock_type','warehouse'); + $this->db->where('deleted',0); + + $query = $this->db->get(); + return ($query->num_rows()==1); + } } ?> diff --git a/application/models/item_unit.php b/application/models/item_unit.php new file mode 100644 index 000000000..782f3e9ca --- /dev/null +++ b/application/models/item_unit.php @@ -0,0 +1,60 @@ +db->from('item_unit'); + $this->db->where('item_id',$item_id); + + $query = $this->db->get(); + + if($query->num_rows()==1) + { + return $query->row(); + } + else + { + //Get empty base parent object, as $item_id is NOT an item + $item_obj=new stdClass(); + + //Get all the fields from items table + $fields = $this->db->list_fields('item_unit'); + + foreach ($fields as $field) + { + $item_obj->$field=''; + } + + return $item_obj; + } + } + + /* + Inserts or updates an item's unit + */ + function save(&$items_unit_data, $item_id) + { + //Run these queries as a transaction, we want to make sure we do all or nothing + $this->db->trans_start(); + + $this->delete($item_id); + + $this->db->insert('item_unit',$items_unit_data); + + + $this->db->trans_complete(); + return true; + } + + /* + Deletes unit given an item + */ + function delete($item_id) + { + return $this->db->delete('item_unit', array('item_id' => $item_id)); + } +} +?> diff --git a/application/models/receiving.php b/application/models/receiving.php index 48ae9dca1..2d3453c6d 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -1,12 +1,19 @@ db->from('receivings'); $this->db->where('receiving_id',$receiving_id); return $this->db->get(); } + + function get_requisition_info($requisition_id) + { + $this->db->from('requisitions'); + $this->db->where('requisition_id',$requisition_id); + return $this->db->get(); + } function exists($receiving_id) { @@ -83,12 +90,182 @@ class Receiving extends CI_Model return $receiving_id; } + function save_requisition ($items,$employee_id,$comment,$receiving_id=false) + { + if(count($items)==0) + return -1; + + $requisition_data = array( + 'employee_id'=>$employee_id, + 'comment'=>$comment + ); + + //Run these queries as a transaction, we want to make sure we do all or nothing + $this->db->trans_start(); + + $this->db->insert('requisitions',$requisition_data); + + $requisition_id = $this->db->insert_id(); + + + foreach($items as $line=>$item) + { + $cur_item_info = $this->Item->get_info($item['item_id']); + $related_item_number = $this->Item_unit->get_info($item['item_id'])->related_number; + $related_item_unit_quantity = $this->Item_unit->get_info($item['item_id'])->unit_quantity; + $related_item_total_quantity = $item['quantity']*$related_item_unit_quantity; + $related_item_id; + //Update stock quantity + $related_item_data = array(); + if((strlen($related_item_number) == 0) or ($related_item_number == $cur_item_info->item_number)) + { + if($this->Item->is_sale_store_item_exist($cur_item_info->item_number)) + { + $related_item_id = $this->Item->get_item_id($cur_item_info->item_number,'sale_stock'); + $related_item_data = array('quantity'=>$this->Item->get_info($related_item_id)->quantity + $related_item_total_quantity); + $this->Item->save($related_item_data,$related_item_id); + } + else + { + $related_item_data = array( + 'name'=>$cur_item_info->name, + 'description'=>$cur_item_info->description, + 'category'=>$cur_item_info->category, + 'supplier_id'=>$cur_item_info->supplier_id, + 'item_number'=>$cur_item_info->item_number, + 'cost_price'=>$cur_item_info->cost_price, + 'unit_price'=>$cur_item_info->unit_price, + 'quantity'=>$related_item_total_quantity, + 'reorder_level'=>$cur_item_info->reorder_level, + 'location'=>$cur_item_info->location, + 'allow_alt_description'=>$cur_item_info->allow_alt_description, + 'is_serialized'=>$cur_item_info->is_serialized, + 'stock_type'=>'sale_stock', + 'custom1'=>$cur_item_info->custom1, /**GARRISON ADDED 4/21/2013**/ + 'custom2'=>$cur_item_info->custom2,/**GARRISON ADDED 4/21/2013**/ + 'custom3'=>$cur_item_info->custom3,/**GARRISON ADDED 4/21/2013**/ + 'custom4'=>$cur_item_info->custom4,/**GARRISON ADDED 4/21/2013**/ + 'custom5'=>$cur_item_info->custom5,/**GARRISON ADDED 4/21/2013**/ + 'custom6'=>$cur_item_info->custom6,/**GARRISON ADDED 4/21/2013**/ + 'custom7'=>$cur_item_info->custom7,/**GARRISON ADDED 4/21/2013**/ + 'custom8'=>$cur_item_info->custom8,/**GARRISON ADDED 4/21/2013**/ + 'custom9'=>$cur_item_info->custom9,/**GARRISON ADDED 4/21/2013**/ + 'custom10'=>$cur_item_info->custom10/**GARRISON ADDED 4/21/2013**/ + ); + $this->Item->save($related_item_data); + $related_item_id = $related_item_data[item_id]; + } + + } + else if($this->Item->is_sale_store_item_exist($related_item_number)) + { + $related_item_id = $this->Item->get_item_id($related_item_number,'sale_stock'); + $related_item_data = array('quantity'=>$this->Item->get_info($related_item_id)->quantity + $related_item_total_quantity); + $this->Item->save($related_item_data,$related_item_id); + } + else if($this->Item->is_warehouse_item_exist($related_item_number)) + { + $related_item_id = $this->Item->get_item_id($related_item_number,'warehouse'); + $item_data_temp= $this->Item->get_info($related_item_id,'warehouse'); + $related_item_data = array( + 'name'=>$item_data_temp->name, + 'description'=>$item_data_temp->description, + 'category'=>$item_data_temp->category, + 'supplier_id'=>$item_data_temp->supplier_id, + 'item_number'=>$item_data_temp->item_number, + 'cost_price'=>$item_data_temp->cost_price, + 'unit_price'=>$item_data_temp->unit_price, + 'quantity'=>$related_item_total_quantity, + 'reorder_level'=>$item_data_temp->reorder_level, + 'location'=>$item_data_temp->location, + 'allow_alt_description'=>$item_data_temp->allow_alt_description, + 'is_serialized'=>$item_data_temp->is_serialized, + 'stock_type'=>'sale_stock', + 'custom1'=>$item_data_temp->custom1, /**GARRISON ADDED 4/21/2013**/ + 'custom2'=>$item_data_temp->custom2,/**GARRISON ADDED 4/21/2013**/ + 'custom3'=>$item_data_temp->custom3,/**GARRISON ADDED 4/21/2013**/ + 'custom4'=>$item_data_temp->custom4,/**GARRISON ADDED 4/21/2013**/ + 'custom5'=>$item_data_temp->custom5,/**GARRISON ADDED 4/21/2013**/ + 'custom6'=>$item_data_temp->custom6,/**GARRISON ADDED 4/21/2013**/ + 'custom7'=>$item_data_temp->custom7,/**GARRISON ADDED 4/21/2013**/ + 'custom8'=>$item_data_temp->custom8,/**GARRISON ADDED 4/21/2013**/ + 'custom9'=>$item_data_temp->custom9,/**GARRISON ADDED 4/21/2013**/ + 'custom10'=>$item_data_temp->custom10/**GARRISON ADDED 4/21/2013**/ + ); + $this->Item->save($related_item_data); + $related_item_id = $related_item_data[item_id]; + } + else + { + return false; + } + + $item_data = array('quantity'=>$cur_item_info->quantity - $item['quantity']); + $this->Item->save($item_data,$item['item_id']); + + //update requisition item + $requisition_items_data = array + ( + 'requisition_id'=>$requisition_id, + 'item_id'=>$item['item_id'], + 'line'=>$item['line'], + 'requisition_quantity'=>$item['quantity'], + 'related_item_id'=>$related_item_id, + 'related_item_quantity'=>$related_item_unit_quantity, + 'related_item_total_quantity' => $item['quantity']*$related_item_unit_quantity + ); + + $this->db->insert('requisitions_items',$requisition_items_data); + + //update inventory + $qty_recv = $item['quantity']*(-1); + $recv_remarks ='REQS '.$requisition_id; + $inv_data = array + ( + 'trans_date'=>date('Y-m-d H:i:s'), + 'trans_items'=>$item['item_id'], + 'trans_user'=>$employee_id, + 'trans_comment'=>$recv_remarks, + 'trans_inventory'=>$qty_recv + ); + $this->Inventory->insert($inv_data); + + $related_item_qty_recv = $requisition_items_data['related_item_total_quantity']; + $recv_remarks ='REQS '.$requisition_id; + $related_item_inv_data = array + ( + 'trans_date'=>date('Y-m-d H:i:s'), + 'trans_items'=>$related_item_id, + 'trans_user'=>$employee_id, + 'trans_comment'=>$recv_remarks, + 'trans_inventory'=>$related_item_qty_recv + ); + $this->Inventory->insert($related_item_inv_data); + + } + $this->db->trans_complete(); + + if ($this->db->trans_status() === FALSE) + { + return -1; + } + + return $requisition_id; + } + function get_receiving_items($receiving_id) { $this->db->from('receivings_items'); $this->db->where('receiving_id',$receiving_id); return $this->db->get(); } + + function get_requisition_items($requisition_id) + { + $this->db->from('requisitions_items'); + $this->db->where('requisition_id',$requisition_id); + return $this->db->get(); + } function get_supplier($receiving_id) { @@ -112,7 +289,18 @@ class Receiving extends CI_Model INNER JOIN ".$this->db->dbprefix('items')." ON ".$this->db->dbprefix('receivings_items').'.item_id='.$this->db->dbprefix('items').'.item_id'." GROUP BY receiving_id, item_id, line)"); } - + + public function create_requisition_items_temp_table() + { + $this->db->query("CREATE TEMPORARY TABLE ".$this->db->dbprefix('requisition_items_temp')." + (SELECT date(requisition_time) as requisition_date, ".$this->db->dbprefix('requisitions_items').".requisition_id, comment, employee_id, + ".$this->db->dbprefix('items').".item_id, related_item_id, requisition_quantity, related_item_quantity, + related_item_total_quantity, ".$this->db->dbprefix('requisitions_items').".line as line + FROM ".$this->db->dbprefix('requisitions_items')." + INNER JOIN ".$this->db->dbprefix('requisitions')." ON ".$this->db->dbprefix('requisitions_items').'.requisition_id='.$this->db->dbprefix('requisitions').'.requisition_id'." + INNER JOIN ".$this->db->dbprefix('items')." ON ".$this->db->dbprefix('requisitions_items').'.item_id='.$this->db->dbprefix('items').'.item_id'." + GROUP BY requisition_id, item_id, line)"); + } } ?> diff --git a/application/models/reports/detailed_receivings.php b/application/models/reports/detailed_receivings.php index 0af71d504..0b3990102 100644 --- a/application/models/reports/detailed_receivings.php +++ b/application/models/reports/detailed_receivings.php @@ -21,11 +21,11 @@ class Detailed_receivings extends Report $this->db->join('people as employee', 'receivings_items_temp.employee_id = employee.person_id'); $this->db->join('people as supplier', 'receivings_items_temp.supplier_id = supplier.person_id', 'left'); $this->db->where('receiving_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales') + if ($inputs['receiving_type'] == 'receiving') { $this->db->where('quantity_purchased > 0'); } - elseif ($inputs['sale_type'] == 'returns') + elseif ($inputs['receiving_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); } @@ -53,11 +53,11 @@ class Detailed_receivings extends Report $this->db->select('sum(total) as total'); $this->db->from('receivings_items_temp'); $this->db->where('receiving_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); - if ($inputs['sale_type'] == 'sales') + if ($inputs['receiving_type'] == 'receiving') { $this->db->where('quantity_purchased > 0'); } - elseif ($inputs['sale_type'] == 'returns') + elseif ($inputs['receiving_type'] == 'returns') { $this->db->where('quantity_purchased < 0'); } diff --git a/application/models/reports/detailed_requisition.php b/application/models/reports/detailed_requisition.php new file mode 100644 index 000000000..0d7a332e5 --- /dev/null +++ b/application/models/reports/detailed_requisition.php @@ -0,0 +1,62 @@ + array($this->lang->line('reports_requisition_id'), + $this->lang->line('reports_date'), + $this->lang->line('reports_requisition_by'), + $this->lang->line('reports_comments')), + 'details' => array($this->lang->line('reports_requisition_item'), + $this->lang->line('reports_requisition_item_quantity'), + $this->lang->line('reports_requisition_related_item'), + $this->lang->line('reports_requisition_related_item_unit_quantity'), + $this->lang->line('reports_requisition_related_item_total_quantity')) + ); + } + + public function getData(array $inputs) + { + $this->db->select('requisition_id, requisition_date, CONCAT(employee.first_name," ",employee.last_name) as employee_name, comment', false); + $this->db->from('requisition_items_temp'); + $this->db->join('people as employee', 'requisition_items_temp.employee_id = employee.person_id'); + $this->db->where('requisition_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + + $this->db->group_by('requisition_id'); + $this->db->order_by('requisition_date'); + + $data = array(); + $data['summary'] = $this->db->get()->result_array(); + $data['details'] = array(); + + foreach($data['summary'] as $key=>$value) + { + $this->db->select('name, requisition_quantity, related_item_id, related_item_quantity, related_item_total_quantity'); + $this->db->from('requisition_items_temp'); + $this->db->join('items', 'requisition_items_temp.item_id = items.item_id'); + $this->db->where('requisition_id = '.$value['requisition_id']); + $data['details'][$key] = $this->db->get()->result_array(); + + foreach($data['details'][$key] as $arr_index=>$deatil_reqs) + { + $related_item_name = $this->Item->get_info($deatil_reqs['related_item_id'])->name; + $data['details'][$key][$arr_index]['related_item_id'] = $related_item_name; + } + + } + + return $data; + } + + public function getSummaryData(array $inputs) + { + //Do nothing + } +} +?> \ No newline at end of file diff --git a/application/models/reports/detailed_sales.php b/application/models/reports/detailed_sales.php index 9a19decb4..fcbec7a21 100644 --- a/application/models/reports/detailed_sales.php +++ b/application/models/reports/detailed_sales.php @@ -39,14 +39,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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'); @@ -71,14 +77,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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/report.php b/application/models/reports/report.php index 0a7f6e31a..51b251ab2 100644 --- a/application/models/reports/report.php +++ b/application/models/reports/report.php @@ -14,6 +14,7 @@ abstract class Report extends CI_Model //Create our temp tables to work with the data in our report $this->Sale->create_sales_items_temp_table(); $this->Receiving->create_receivings_items_temp_table(); + $this->Receiving->create_requisition_items_temp_table(); } //Returns the column names used for the report diff --git a/application/models/reports/specific_customer.php b/application/models/reports/specific_customer.php index 0b2f8c342..45ad090f7 100644 --- a/application/models/reports/specific_customer.php +++ b/application/models/reports/specific_customer.php @@ -20,14 +20,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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'); @@ -52,14 +58,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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 39fff80f9..dada0395f 100644 --- a/application/models/reports/specific_employee.php +++ b/application/models/reports/specific_employee.php @@ -21,14 +21,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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'); @@ -54,14 +60,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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 27c30ae46..f6d7778a6 100644 --- a/application/models/reports/summary_categories.php +++ b/application/models/reports/summary_categories.php @@ -18,14 +18,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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'); @@ -38,14 +44,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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 1f8fa6aea..4712ddab9 100644 --- a/application/models/reports/summary_customers.php +++ b/application/models/reports/summary_customers.php @@ -19,14 +19,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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'); @@ -40,14 +46,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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 6b3949eb0..7e09b80d5 100644 --- a/application/models/reports/summary_discounts.php +++ b/application/models/reports/summary_discounts.php @@ -17,14 +17,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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(); @@ -35,14 +41,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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 5308e8e95..63e960ec9 100644 --- a/application/models/reports/summary_employees.php +++ b/application/models/reports/summary_employees.php @@ -19,14 +19,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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'); @@ -40,14 +46,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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_items.php b/application/models/reports/summary_items.php index 8aefb5475..9752d822f 100644 --- a/application/models/reports/summary_items.php +++ b/application/models/reports/summary_items.php @@ -18,14 +18,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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'); @@ -38,14 +44,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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_payments.php b/application/models/reports/summary_payments.php index 2c95ac69c..1f7f863db 100644 --- a/application/models/reports/summary_payments.php +++ b/application/models/reports/summary_payments.php @@ -18,14 +18,20 @@ 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') - { - $this->db->where('payment_amount > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('payment_amount < 0'); - } + 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') + { + $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(); } @@ -36,14 +42,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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 e7914a9ee..a13ba4dd3 100644 --- a/application/models/reports/summary_sales.php +++ b/application/models/reports/summary_sales.php @@ -16,15 +16,21 @@ 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') + 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') + { + $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_date'); $this->db->having('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); $this->db->order_by('sale_date'); @@ -36,14 +42,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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 98566c343..f81af5286 100644 --- a/application/models/reports/summary_suppliers.php +++ b/application/models/reports/summary_suppliers.php @@ -19,14 +19,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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'); @@ -40,15 +46,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } - + 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') + { + $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 824a72749..c35669001 100644 --- a/application/models/reports/summary_taxes.php +++ b/application/models/reports/summary_taxes.php @@ -51,14 +51,20 @@ 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') - { - $this->db->where('quantity_purchased > 0'); - } - elseif ($inputs['sale_type'] == 'returns') - { - $this->db->where('quantity_purchased < 0'); - } + 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') + { + $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/views/config.php b/application/views/config.php index 75053ee39..4460c03d6 100644 --- a/application/views/config.php +++ b/application/views/config.php @@ -148,7 +148,8 @@ echo form_open('config/save/',array('id'=>'config_form')); 'ru' => 'Russian', 'nl-BE' => 'Dutch', 'zh' => 'Chinese', - 'id' => 'Indonesia' + 'id' => 'Indonesia', + 'th' => 'Thailand' ), $this->config->item('language')); ?> diff --git a/application/views/items/form.php b/application/views/items/form.php index 5b0db5da9..89fa23970 100644 --- a/application/views/items/form.php +++ b/application/views/items/form.php @@ -159,8 +159,37 @@ echo form_open('items/save/'.$item_info->item_id,array('id'=>'item_form')); +
+lang->line('items_unit_quantity').':', 'unit_quantity',array('class'=>'wide')); ?> +
+ 'unit_quantity', + 'id'=>'unit_quantity', + 'value'=>($item_unit_info->unit_quantity) ? $item_unit_info->unit_quantity : 1) + );?> +
+
+ +
+lang->line('items_related_number').':', 'related_number',array('class'=>'wide')); ?> +
+ 'related_number', + 'id'=>'related_number', + 'value'=>$item_unit_info->related_number) + );?> +
+
+ +
+ +
+ +
-lang->line('items_allow_alt_description').':', 'allow_alt_description',array('class'=>'wide')); ?> +lang->line('items_allow_alt_desciption').':', 'allow_alt_description',array('class'=>'wide')); ?>
'allow_alt_description', @@ -403,7 +432,28 @@ $(document).ready(function() $("#custom10").search(); /** END GARRISON ADDED **/ - + //custom function. I leave this function as an example for creating JS custom function + //Please note that this function is not used + $.validator.addMethod( + "relatedItemNumber", + function(value) + { + var site_url = ""; + var ajax_return_result; + jQuery.ajax({ + mode: "abort", + url: site_url+"/"+value, + type: "get", + success: function(result) { + ajax_return_result = result; + }, + async: false + }); + + return ajax_return_result; + }, + "relatedItemNumber failed"); + $('#item_form').validate({ submitHandler:function(form) { @@ -454,6 +504,7 @@ $(document).ready(function() required:true, number:true } + }, messages: { diff --git a/application/views/items/manage.php b/application/views/items/manage.php index a9002f4c7..ca282590c 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -143,8 +143,10 @@ function show_hide_search_filter(search_filter_section, switchImgTag) { '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_is_deleted').' '.':', 'is_deleted');// Parq 131215?> - 'is_deleted','id'=>'is_deleted','value'=>1,'checked'=> isset($is_deleted)? ( ($is_deleted)? 1 : 0) : 0)).' | ';// Parq 131215?> + 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();"'); ?> +
@@ -163,8 +165,8 @@ function show_hide_search_filter(search_filter_section, switchImgTag) {
-
+
-load->view("partial/footer"); ?> +load->view("partial/footer"); ?> \ No newline at end of file diff --git a/application/views/receivings/receiving.php b/application/views/receivings/receiving.php index 09912398f..6f8b24b8e 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -20,7 +20,7 @@ if(isset($error))
+load->view("partial/footer"); ?> + +Appconfig->get('print_after_sale')) +{ +?> + + \ No newline at end of file diff --git a/application/views/reports/date_input.php b/application/views/reports/date_input.php index 3f2095ad2..c49c4e0e9 100644 --- a/application/views/reports/date_input.php +++ b/application/views/reports/date_input.php @@ -39,6 +39,36 @@ if(isset($error)) } ?> + + + lang->line('reports_sale_type'), 'reports_sale_type_label', array('class'=>'required')); ?> +
+ $this->lang->line('reports_all'), + 'sales_retail' => $this->lang->line('reports_sales_retail'), + 'sales_wholesale' => $this->lang->line('reports_sales_wholesale'), + 'returns' => $this->lang->line('reports_returns')), 'all', 'id="input_type"'); ?> +
+ + lang->line('reports_receiving_type'), 'reports_receiving_type_label', array('class'=>'required')); ?> +
+ $this->lang->line('reports_all'), + 'receiving' => $this->lang->line('reports_receivings'), + 'returns' => $this->lang->line('reports_returns')), 'all', 'id="input_type"'); ?> +
+ 'generate_report', @@ -55,18 +85,24 @@ $(document).ready(function() { $("#generate_report").click(function() { - var sale_type = $("#sale_type").val(); + var input_type = $("#input_type").val(); if ($("#simple_radio").attr('checked')) { - window.location = window.location+'/'+$("#report_date_range_simple option:selected").val() + '/' + sale_type; + window.location = window.location+'/'+$("#report_date_range_simple option:selected").val() + '/' + input_type; } else { var start_date = $("#start_year").val()+'-'+$("#start_month").val()+'-'+$('#start_day').val(); var end_date = $("#end_year").val()+'-'+$("#end_month").val()+'-'+$('#end_day').val(); - - window.location = window.location+'/'+start_date + '/'+ end_date+ '/' + sale_type; + if(input_type == null) + { + window.location = window.location+'/'+start_date + '/'+ end_date; + } + else + { + window.location = window.location+'/'+start_date + '/'+ end_date+ '/' + input_type; + } } }); diff --git a/application/views/reports/date_input_excel_export.php b/application/views/reports/date_input_excel_export.php index 188e26b79..94d63ece6 100644 --- a/application/views/reports/date_input_excel_export.php +++ b/application/views/reports/date_input_excel_export.php @@ -25,7 +25,10 @@ if(isset($error)) lang->line('reports_sale_type'), 'reports_sale_type_label', array('class'=>'required')); ?>
- $this->lang->line('reports_all'), 'sales' => $this->lang->line('reports_sales'), 'returns' => $this->lang->line('reports_returns')), 'all', 'id="sale_type"'); ?> + $this->lang->line('reports_all'), + 'sales_retail' => $this->lang->line('reports_sales_retail'), + 'sales_wholesale' => $this->lang->line('reports_sales_wholesale'), + 'returns' => $this->lang->line('reports_returns')), 'all', 'id="sale_type"'); ?>
diff --git a/application/views/reports/listing.php b/application/views/reports/listing.php index 28e3152ce..827c0790f 100644 --- a/application/views/reports/listing.php +++ b/application/views/reports/listing.php @@ -35,6 +35,7 @@