diff --git a/.gitignore b/.gitignore index 58bf03044..1ce5a940a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ git-svn-diff.py *.swp *.rej *.orig +*~ diff --git a/application/config/config.php b/application/config/config.php index 315d10762..1d098dd89 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -9,7 +9,7 @@ | | */ -$config['application_version'] = '2.3'; +$config['application_version'] = '2.3.1'; /* |-------------------------------------------------------------------------- diff --git a/application/config/constants.php b/application/config/constants.php index 4a879d360..17c81baa6 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -36,6 +36,10 @@ define('FOPEN_READ_WRITE_CREATE', 'a+b'); define('FOPEN_WRITE_CREATE_STRICT', 'xb'); define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); +/* + | Precision for calculations performed on decimals + */ +define("PRECISION", 3); /* End of file constants.php */ /* Location: ./application/config/constants.php */ \ No newline at end of file diff --git a/application/controllers/items.php b/application/controllers/items.php index 4526148d6..6b1a71a63 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -6,6 +6,7 @@ class Items extends Secure_area implements iData_controller function __construct() { parent::__construct('items'); + $this->load->library('item_lib'); } function index() @@ -16,9 +17,14 @@ class Items extends Secure_area implements iData_controller $config['uri_segment'] = 3; $this->pagination->initialize($config); + $stock_location=$this->item_lib->get_item_location(); + $stock_locations=$this->Stock_locations->get_allowed_locations(); + $data['stock_location']=$this->item_lib->get_item_location(); + $data['stock_locations']=$stock_locations; + $data['controller_name']=strtolower(get_class()); $data['form_width']=$this->get_form_width(); - $data['manage_table']=get_items_manage_table( $this->Item->get_all( $config['per_page'], $this->uri->segment( $config['uri_segment'] ) ), $this ); + $data['manage_table']=get_items_manage_table( $this->Item->get_all( $stock_location, $config['per_page'], $this->uri->segment( $config['uri_segment'] ) ), $this ); $this->load->view('items/manage',$data); } @@ -27,7 +33,13 @@ class Items extends Secure_area implements iData_controller $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 + $is_deleted=$this->input->post('is_deleted'); // Parq 131215 + $this->item_lib->set_item_location($this->input->post('stock_location')); + + $stock_location=$this->input->post('stock_location'); + $stock_locations=$this->Stock_locations->get_allowed_locations(); + $data['stock_location']=$this->item_lib->get_item_location(); + $data['stock_locations']=$stock_locations; $data['search_section_state']=$this->input->post('search_section_state'); $data['is_serialized']=$this->input->post('is_serialized'); @@ -36,7 +48,7 @@ class Items extends Secure_area implements iData_controller $data['is_deleted']=$this->input->post('is_deleted'); // Parq 131215 $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($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($stock_location,$is_serialized,$no_description,$search_custom,$is_deleted),$this);//GARRISON MODIFIED 4/13/2013, Parq 131215 $this->load->view('items/manage',$data); } @@ -182,13 +194,15 @@ class Items extends Secure_area implements iData_controller function get_row() { $item_id = $this->input->post('row_id'); - $data_row=get_item_data_row($this->Item->get_info($item_id),$this); + $stock_location_id=$this->item_lib->get_item_location(); + $data_row=get_item_data_row($this->Item->get_info($item_id,$stock_location_id),$this); echo $data_row; } function view($item_id=-1) { - $data['item_info']=$this->Item->get_info($item_id); + $stock_location_id=$this->item_lib->get_item_location(); + $data['item_info']=$this->Item->get_info($item_id,$stock_location_id); $data['item_tax_info']=$this->Item_taxes->get_info($item_id); $suppliers = array('' => $this->lang->line('items_none')); foreach($this->Supplier->get_all()->result_array() as $row) @@ -197,20 +211,19 @@ class Items extends Secure_area implements iData_controller } $data['suppliers']=$suppliers; - $data['selected_supplier'] = $this->Item->get_info($item_id)->supplier_id; + $data['selected_supplier'] = $this->Item->get_info($item_id,$stock_location_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') : ''; $locations_data = $this->Stock_locations->get_undeleted_all()->result_array(); - $location_array; foreach($locations_data as $location) { $quantity = $this->Item_quantities->get_item_quantity($item_id, $location['location_id'])->quantity; $quantity = ($item_id == -1) ? null: $quantity; $location_array[$location['location_id']] = array('location_name'=>$location['location_name'], 'quantity'=>$quantity); + $data['stock_locations']= $location_array; } - $data['stock_locations']= $location_array; $this->load->view("items/form",$data); } diff --git a/application/controllers/no_access.php b/application/controllers/no_access.php index cba136e5c..eec4334ed 100644 --- a/application/controllers/no_access.php +++ b/application/controllers/no_access.php @@ -6,7 +6,7 @@ class No_Access extends CI_Controller parent::__construct(); } - function index($module_id='') + function index($module_id='',$submodule_id='') { $data['module_name']=$this->Module->get_module_name($module_id); $this->load->view('no_access',$data); diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index c620210d7..39de5c527 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -4,7 +4,7 @@ class Receivings extends Secure_area { function __construct() { - parent::__construct('receivings'); + parent::__construct('receivings','items'); $this->load->library('receiving_lib'); } diff --git a/application/controllers/reports.php b/application/controllers/reports.php index 294594f0e..8729b2ed1 100644 --- a/application/controllers/reports.php +++ b/application/controllers/reports.php @@ -6,9 +6,19 @@ define("FORM_WIDTH", "400"); class Reports extends Secure_area { + function __construct() { parent::__construct('reports'); + $method_name = $this->uri->segment(2); + $exploder = explode('_', $method_name); + $submodule_id = preg_match("/([^_.]*)(?:_graph)?$/", $method_name, $matches); + $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; + // check access to report submodule + /* if (sizeof($exploder) > 1 && !$this->Employee->has_permission('reports_'.$matches[1],$employee_id)) + { + redirect('no_access/'.$submodule_id); + } */ $this->load->helper('report'); } @@ -927,7 +937,7 @@ class Reports extends Secure_area } $data = array( - "title" => $this->lang->line('reports_low_inventory_report'), + "title" => $this->lang->line('reports_inventory_low_report'), "subtitle" => '', "headers" => $model->getDataColumns(), "data" => $tabular_data, diff --git a/application/controllers/sales.php b/application/controllers/sales.php index c6eeddb17..f5432f50c 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -4,7 +4,7 @@ class Sales extends Secure_area { function __construct() { - parent::__construct('sales'); + parent::__construct('sales','items'); $this->load->library('sale_lib'); } @@ -361,17 +361,8 @@ class Sales extends Secure_area $data['modes']=array('sale'=>$this->lang->line('sales_sale'),'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(); - $show_stock_locations = count($stock_locations) > 1; - if ($show_stock_locations) { - foreach($stock_locations as $location_data) - { - $data['stock_locations'][$location_data['location_id']] = $location_data['location_name']; - } - $data['stock_location']=$this->sale_lib->get_sale_location(); - } - $data['show_stock_locations'] = $show_stock_locations; + $data['stock_locations']=$this->Stock_locations->get_allowed_locations(); + $data['stock_location']=$this->sale_lib->get_sale_location(); $data['subtotal']=$this->sale_lib->get_subtotal(); $data['taxes']=$this->sale_lib->get_taxes(); diff --git a/application/controllers/secure_area.php b/application/controllers/secure_area.php index 5dda41ed0..dbdd750bc 100644 --- a/application/controllers/secure_area.php +++ b/application/controllers/secure_area.php @@ -5,7 +5,7 @@ class Secure_area extends CI_Controller Controllers that are considered secure extend Secure_area, optionally a $module_id can be set to also check if a user can access a particular module in the system. */ - function __construct($module_id=null) + function __construct($module_id=null,$submodule_id=null) { parent::__construct(); $this->load->model('Employee'); @@ -13,8 +13,9 @@ class Secure_area extends CI_Controller { redirect('login'); } - - if(!$this->Employee->has_permission($module_id,$this->Employee->get_logged_in_employee_info()->person_id)) + $submodule_id = empty($submodule_id) ? $module_id : $submodule_id; + $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; + if(!$this->Employee->has_permission($module_id,$employee_id) || !$this->Employee->has_subpermission($submodule_id,$employee_id)) { redirect('no_access/'.$module_id); } diff --git a/application/helpers/report_helper.php b/application/helpers/report_helper.php index 2b380e316..8367f2785 100644 --- a/application/helpers/report_helper.php +++ b/application/helpers/report_helper.php @@ -84,4 +84,26 @@ function random_color() $c .= sprintf("%02X", mt_rand(0, 255)); } return $c; +} + +function show_report_if_allowed($allowed_modules, $report_prefix, $report_name, $permission='') +{ + $CI =& get_instance(); + $lang_line = 'reports_' .$report_name; + $report_label = $CI->lang->line($lang_line); + $permission = empty($permission) ? $report_name : $permission; + $report_prefix = empty($report_prefix) ? '' : $report_prefix . '_'; + // no summary nor detailed reports for receivings + if (!empty($report_label) && !(preg_match('/.*summary_?$/', $report_prefix) && $report_name === "receivings")) + { + foreach($allowed_modules->result() as $module) + { + if ($module->module_id == 'reports_'. $permission) + { + ?> +
  • + get_form_width(); $item_quantity=''; - $locations_data = $CI->Stock_locations->get_undeleted_all()->result_array(); + /* $locations_data = $CI->Stock_locations->get_allowed_locations()->result_array(); foreach($locations_data as $location) { if (count($locations_data) > 1) @@ -219,7 +219,7 @@ function get_item_data_row($item,$controller) $item_quantity .= $location['location_name'].': '; } $item_quantity .= $CI->Item_quantities->get_item_quantity($item->item_id, $location['location_id'])->quantity . '
    '; - } + } */ $table_data_row=''; $table_data_row.=""; @@ -228,7 +228,7 @@ function get_item_data_row($item,$controller) $table_data_row.=''.$item->category.''; $table_data_row.=''.to_currency($item->cost_price).''; $table_data_row.=''.to_currency($item->unit_price).''; - $table_data_row.=''.$item_quantity.''; + $table_data_row.=''.$item->quantity.''; $table_data_row.=''.$tax_percents.''; $table_data_row.=''.anchor($controller_name."/view/$item->item_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).''; diff --git a/application/language/en/items_lang.php b/application/language/en/items_lang.php index a3b18c509..ee57d0a34 100644 --- a/application/language/en/items_lang.php +++ b/application/language/en/items_lang.php @@ -77,10 +77,6 @@ $lang['items_manually_editing_of_quantity'] = 'Manual Edit of Quantity'; $lang['items_inventory'] = 'Inventory'; $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_unit_quantity'] = 'Unit quantity'; -$lang['items_related_number'] = 'Related item number'; $lang['items_stock_location']='Stock location'; ?> diff --git a/application/language/en/reports_lang.php b/application/language/en/reports_lang.php index e380f931a..775c30ac4 100644 --- a/application/language/en/reports_lang.php +++ b/application/language/en/reports_lang.php @@ -68,11 +68,11 @@ $lang['reports_summary_reports'] = 'Summary Reports'; $lang['reports_graphical_reports'] = 'Graphical Reports'; $lang['reports_detailed_reports'] = 'Detailed Reports'; $lang['reports_inventory_reports'] = 'Inventory Reports'; -$lang['reports_low_inventory'] = 'Low Inventory'; +$lang['reports_inventory_low'] = 'Low Inventory'; $lang['reports_inventory_summary'] = ' Inventory Summary'; $lang['reports_item_number'] = 'Item Number'; $lang['reports_reorder_level'] = 'Reorder Level'; -$lang['reports_low_inventory_report'] = 'Low Inventory Report'; +$lang['reports_inventory_low_report'] = 'Low Inventory Report'; $lang['reports_item_name'] = 'Item Name'; $lang['reports_inventory_summary_report'] = 'Inventory Summary Report'; $lang['reports_payment_type'] = 'Payment Type'; @@ -92,4 +92,5 @@ $lang['reports_sales'] = 'Sales'; $lang['reports_requisitions'] = 'Requisitions'; $lang['reports_receiving_id'] = 'Receiving ID'; $lang['reports_stock_location'] = 'Stock location'; +$lang['reports_inventory'] = 'Inventory'; ?> diff --git a/application/language/es/reports_lang.php b/application/language/es/reports_lang.php index 93b7df5a4..ac5d8267b 100644 --- a/application/language/es/reports_lang.php +++ b/application/language/es/reports_lang.php @@ -66,11 +66,11 @@ $lang['reports_summary_reports'] = 'Reportes Resumidos'; $lang['reports_graphical_reports'] = 'Reportes Gráficos'; $lang['reports_detailed_reports'] = 'Reportes Detallados'; $lang['reports_inventory_reports'] = 'Reportes de Inventario'; -$lang['reports_low_inventory'] = 'Inventario Bajo'; +$lang['reports_inventory_low'] = 'Inventario Bajo'; $lang['reports_inventory_summary'] = 'Resumen de Inventario'; $lang['reports_item_number'] = 'Número de Artículo'; $lang['reports_reorder_level'] = 'Cantidad Mínima'; -$lang['reports_low_inventory_report'] = 'Reporte de Inventario Bajo'; +$lang['reports_inventory_low_report'] = 'Reporte de Inventario Bajo'; $lang['reports_item_name'] = 'Nombre del Artículo'; $lang['reports_inventory_summary_report'] = 'Reporte de Resumen de Inventario'; $lang['reports_payment_type'] = 'Tipo de Pago'; diff --git a/application/language/fr/reports_lang.php b/application/language/fr/reports_lang.php index 1a1cdac35..a00c4a96f 100644 --- a/application/language/fr/reports_lang.php +++ b/application/language/fr/reports_lang.php @@ -68,11 +68,11 @@ $lang['reports_summary_reports'] = 'Rapports de Résumés'; $lang['reports_graphical_reports'] = 'Rapports Graphiques'; $lang['reports_detailed_reports'] = 'Rapports Détaillés'; $lang['reports_inventory_reports'] = 'Rapports d\'Inventaire'; -$lang['reports_low_inventory'] = 'Niveau d\'Inventaire Bas'; +$lang['reports_inventory_low'] = 'Niveau d\'Inventaire Bas'; $lang['reports_inventory_summary'] = ' Résumé d\'Inventaire'; $lang['reports_item_number'] = 'Numéro d\'Item'; $lang['reports_reorder_level'] = 'Seuil de Réapprovisionnement'; -$lang['reports_low_inventory_report'] = 'Rapport de Niveau d\'Inventaire Bas'; +$lang['reports_inventory_low_report'] = 'Rapport de Niveau d\'Inventaire Bas'; $lang['reports_item_name'] = 'Nom d\'Item'; $lang['reports_inventory_summary_report'] = 'Rapport: Résumé d\'Inventaire'; $lang['reports_payment_type'] = 'Type Paiement'; diff --git a/application/language/id/reports_lang.php b/application/language/id/reports_lang.php index ac6fb5741..61a78a6a9 100644 --- a/application/language/id/reports_lang.php +++ b/application/language/id/reports_lang.php @@ -66,11 +66,11 @@ $lang['reports_summary_reports'] = 'Ringkasan Laporan'; $lang['reports_graphical_reports'] = 'Laporan Dalam Bentuk Grafis'; $lang['reports_detailed_reports'] = 'Perincian Laporan'; $lang['reports_inventory_reports'] = 'Laporan Inventori'; -$lang['reports_low_inventory'] = 'Laporan Inventori Rendah'; +$lang['reports_inventory_low'] = 'Laporan Inventori Rendah'; $lang['reports_inventory_summary'] = 'Laporan Ringkasan Inventori'; $lang['reports_item_number'] = 'Nomor Barang'; $lang['reports_reorder_level'] = 'Level Pesan Ulang'; -$lang['reports_low_inventory_report'] = 'Laporan Inventori Rendah'; +$lang['reports_inventory_low_report'] = 'Laporan Inventori Rendah'; $lang['reports_item_name'] = 'Nama Barang'; $lang['reports_inventory_summary_report'] = 'Laporan Ringkasan Inventori'; $lang['reports_payment_type'] = 'Jenis Pembayaran'; diff --git a/application/language/nl-BE/reports_lang.php b/application/language/nl-BE/reports_lang.php index 9975b6af3..4f4377758 100755 --- a/application/language/nl-BE/reports_lang.php +++ b/application/language/nl-BE/reports_lang.php @@ -66,11 +66,11 @@ $lang['reports_summary_reports'] = 'Overzicht Rapporten'; $lang['reports_graphical_reports'] = 'Grafische Rapporten'; $lang['reports_detailed_reports'] = 'Gedetailleerde Rapporten'; $lang['reports_inventory_reports'] = 'Rapporten Bevoorrading'; -$lang['reports_low_inventory'] = 'Herbevoorrading'; +$lang['reports_inventory_low'] = 'Herbevoorrading'; $lang['reports_inventory_summary'] = 'Overzicht Vooraad'; $lang['reports_item_number'] = 'Productnummer'; $lang['reports_reorder_level'] = 'Reorder Level'; -$lang['reports_low_inventory_report'] = 'Rapport Herbevoorrading'; +$lang['reports_inventory_low_report'] = 'Rapport Herbevoorrading'; $lang['reports_item_name'] = 'Product Naam'; $lang['reports_inventory_summary_report'] = 'Rapport Overzicht Vooraad'; $lang['reports_payment_type'] = 'Payment Type'; diff --git a/application/language/ru/reports_lang.php b/application/language/ru/reports_lang.php index 2fd82dab8..6a34447a4 100644 --- a/application/language/ru/reports_lang.php +++ b/application/language/ru/reports_lang.php @@ -66,11 +66,11 @@ $lang['reports_summary_reports'] = 'Сводные отчеты'; $lang['reports_graphical_reports'] = 'графических отчетов'; $lang['reports_detailed_reports'] = 'Подробные отчеты'; $lang['reports_inventory_reports'] = 'Инвентаризация Отчеты'; -$lang['reports_low_inventory'] = 'Низкий инвентаризации'; +$lang['reports_inventory_low'] = 'Низкий инвентаризации'; $lang['reports_inventory_summary'] = ' Сводка инвентаризации'; $lang['reports_item_number'] = 'Номер Товара'; $lang['reports_reorder_level'] = 'минимальный уровень'; -$lang['reports_low_inventory_report'] = 'отчет Низкии инвентаризации'; +$lang['reports_inventory_low_report'] = 'отчет Низкии инвентаризации'; $lang['reports_item_name'] = 'Название товара'; $lang['reports_inventory_summary_report'] = 'Отчет Сводка инвентаризации'; $lang['reports_payment_type'] = 'Вид оплаты'; diff --git a/application/language/th/items_lang.php b/application/language/th/items_lang.php index ce415f097..6201438ce 100644 --- a/application/language/th/items_lang.php +++ b/application/language/th/items_lang.php @@ -77,9 +77,6 @@ $lang['items_use_inventory_menu'] = 'ใช้สินค้าคงเหล $lang['items_manually_editing_of_quantity'] = 'แก้ไขจำนวน'; $lang['items_inventory'] = 'สินค้าคงเหลือ'; $lang['items_location'] = 'ที่ตั้ง'; -$lang['items_unit_quantity'] = 'จำนวนหน่วย'; -$lang['items_related_number'] = 'สินค้าที่เกี่ยวข้อง'; -$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 05a198ca0..07d26d52a 100644 --- a/application/language/th/reports_lang.php +++ b/application/language/th/reports_lang.php @@ -66,11 +66,11 @@ $lang['reports_summary_reports'] = 'สรุปรายงาน'; $lang['reports_graphical_reports'] = 'รายงายแบบกราฟ'; $lang['reports_detailed_reports'] = 'รายละเอียดรายงาน'; $lang['reports_inventory_reports'] = 'รายงานสินค้าคงเหลือ'; -$lang['reports_low_inventory'] = 'สินค้าเหลือน้อย'; +$lang['reports_inventory_low'] = 'สินค้าเหลือน้อย'; $lang['reports_inventory_summary'] = ' รายงานสินค้าคงเหลือ'; $lang['reports_item_number'] = 'เลขสินค้า'; $lang['reports_reorder_level'] = 'ระดับการสั่งใหม่'; -$lang['reports_low_inventory_report'] = 'รายงานสินค้าที่เหลือน้อย'; +$lang['reports_inventory_low_report'] = 'รายงานสินค้าที่เหลือน้อย'; $lang['reports_item_name'] = 'ชื่อสินค้า'; $lang['reports_inventory_summary_report'] = 'รายงานสรุปสินค้าคงเหลือ'; $lang['reports_payment_type'] = 'ชนิดการจ่าย'; @@ -166,11 +166,11 @@ $lang['reports_summary_reports'] = 'สรุปรายงาน'; $lang['reports_graphical_reports'] = 'รายงายแบบกราฟ'; $lang['reports_detailed_reports'] = 'รายละเอียดรายงาน'; $lang['reports_inventory_reports'] = 'รายงานสินค้าคงเหลือ'; -$lang['reports_low_inventory'] = 'สินค้าเหลือน้อย'; +$lang['reports_inventory_low'] = 'สินค้าเหลือน้อย'; $lang['reports_inventory_summary'] = ' รายงานสินค้าคงเหลือ'; $lang['reports_item_number'] = 'เลขสินค้า'; $lang['reports_reorder_level'] = 'ระดับการสั่งใหม่'; -$lang['reports_low_inventory_report'] = 'รายงานสินค้าที่เหลือน้อย'; +$lang['reports_inventory_low_report'] = 'รายงานสินค้าที่เหลือน้อย'; $lang['reports_item_name'] = 'ชื่อสินค้า'; $lang['reports_inventory_summary_report'] = 'รายงานสรุปสินค้าคงเหลือ'; $lang['reports_payment_type'] = 'ชนิดการจ่าย'; diff --git a/application/language/zh/reports_lang.php b/application/language/zh/reports_lang.php index 7b1b1501c..7e439d1ea 100755 --- a/application/language/zh/reports_lang.php +++ b/application/language/zh/reports_lang.php @@ -66,11 +66,11 @@ $lang['reports_summary_reports'] = '摘要報表'; $lang['reports_graphical_reports'] = '圖表'; $lang['reports_detailed_reports'] = '詳細報表'; $lang['reports_inventory_reports'] = '庫存報告'; -$lang['reports_low_inventory'] = '低庫存'; +$lang['reports_inventory_low'] = '低庫存'; $lang['reports_inventory_summary'] = ' 庫存摘要'; $lang['reports_item_number'] = '產品數量'; $lang['reports_reorder_level'] = '補貨點'; -$lang['reports_low_inventory_report'] = '低庫存報告'; +$lang['reports_inventory_low_report'] = '低庫存報告'; $lang['reports_item_name'] = '產品名稱'; $lang['reports_inventory_summary_report'] = '庫存報告摘要'; $lang['reports_payment_type'] = '付款模式'; diff --git a/application/libraries/Item_lib.php b/application/libraries/Item_lib.php new file mode 100644 index 000000000..4658391fe --- /dev/null +++ b/application/libraries/Item_lib.php @@ -0,0 +1,34 @@ +CI =& get_instance(); + } + + function get_item_location() + { + if(!$this->CI->session->userdata('item_location')) + { + $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); + $location_name = $stock_locations[0]['location_id']; + $this->set_item_location($location_name); + } + return $this->CI->session->userdata('item_location'); + } + + function set_item_location($location) + { + $this->CI->session->set_userdata('item_location',$location); + } + + function clear_item_location() + { + $this->CI->session->unset_userdata('item_location'); + } +} + +?> diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 5b58023b1..ca9351abc 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -135,7 +135,7 @@ class Receiving_lib } $insertkey=$maxkey+1; - $item_info=$this->CI->Item->get_info($item_id); + $item_info=$this->CI->Item->get_info($item_id,$item_location); //array records are identified by $insertkey and item_id is just another field. $item = array(($insertkey)=> array( diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 5736df515..2c0eb9096 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -1,5 +1,4 @@ CI->Item->get_info($item_id); + $item_info=$this->CI->Item->get_info($item_id,$item_location); //array/cart records are identified by $insertkey and item_id is just another field. $item = array(($insertkey)=> array( diff --git a/application/models/employee.php b/application/models/employee.php index e0d0b3606..45d469214 100644 --- a/application/models/employee.php +++ b/application/models/employee.php @@ -303,6 +303,26 @@ class Employee extends Person return false; } + /* + * Determines whether the employee has access to at least one submodule + */ + function has_subpermission($submodule_id,$person_id) + { + $this->db->from('modules'); + $this->db->where('module_id like "' . $submodule_id . '_%"'); + // has no submodules + $result = $this->db->get(); + if ($result->num_rows() > 0) + { + $this->db->from('permissions'); + $this->db->where('permissions.module_id like "' . $submodule_id . '_%"'); + $this->db->where("permissions.person_id",$person_id); + $result = $this->db->get(); + return $result->num_rows() > 0; + } + return true; + } + /* Determins whether the employee specified employee has access the specific module. */ @@ -315,10 +335,7 @@ class Employee extends Person } $query = $this->db->get_where('permissions', array('person_id' => $person_id,'module_id'=>$module_id), 1); - return $query->num_rows() == 1; - - - return false; + return ($query->num_rows() == 1); } } diff --git a/application/models/item.php b/application/models/item.php index 2a5347118..a566bc3e9 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -16,11 +16,13 @@ class Item extends CI_Model /* Returns all the items */ - function get_all($limit=10000, $offset=0) + function get_all($stock_location_id,$limit=10000,$offset=0) { $this->db->from('items'); + $this->db->join('item_quantities','item_quantities.item_id=items.item_id'); $this->db->where('deleted',0); - $this->db->order_by("name", "asc"); + $this->db->where('location_id',$stock_location_id); + $this->db->order_by("name","asc"); $this->db->limit($limit); $this->db->offset($offset); return $this->db->get(); @@ -33,9 +35,11 @@ class Item extends CI_Model return $this->db->count_all_results(); } - function get_all_filtered($is_serialized=0,$no_description,$search_custom,$is_deleted)/**GARRISON MODIFIED 4/21/2013, Parq 131215 **/ + function get_all_filtered($stock_location_id,$is_serialized=0,$no_description,$search_custom,$is_deleted)/**GARRISON MODIFIED 4/21/2013, Parq 131215 **/ { $this->db->from('items'); + $this->db->join('item_quantities','item_quantities.item_id=items.item_id'); + $this->db->where('location_id',$stock_location_id); if ($is_serialized !=0 ) { $this->db->where('is_serialized',1); @@ -62,14 +66,7 @@ class Item extends CI_Model $this->db->or_like('custom10',$search); } **/ -/* Parq 131215 start*/ - if ($is_deleted !=0 ) - { - $this->db->where('deleted',1); - } else { - $this->db->where('deleted',0); - } -/* Parq 131215 end*/ + $this->db->where('deleted',$is_deleted); $this->db->order_by("name", "asc"); return $this->db->get(); } @@ -77,10 +74,15 @@ class Item extends CI_Model /* Gets information about a particular item */ - function get_info($item_id) + function get_info($item_id,$stock_location_id=0) { $this->db->from('items'); - $this->db->where('item_id',$item_id); + $this->db->join('item_quantities','item_quantities.item_id=items.item_id'); + if ($stock_location_id > 0) + { + $this->db->where('location_id',$stock_location_id); + } + $this->db->where('items.item_id',$item_id); $query = $this->db->get(); diff --git a/application/models/module.php b/application/models/module.php index 1e14c6d85..4f5ff99c8 100644 --- a/application/models/module.php +++ b/application/models/module.php @@ -46,5 +46,6 @@ class Module extends CI_Model $this->db->order_by("sort", "asc"); return $this->db->get(); } + } ?> diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index 4ad2107de..2a8b21bc2 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -13,6 +13,9 @@ class Stock_locations extends CI_Model function get_all($limit=10000, $offset=0) { $this->db->from('stock_locations'); + $this->db->join('modules', 'modules.module_id=concat(\'items_stock\', location_id)'); + $this->db->join('permissions', 'permissions.module_id=modules.module_id'); + $this->db->where('person_id', $this->session->userdata('person_id')); $this->db->limit($limit); $this->db->offset($offset); return $this->db->get(); @@ -22,6 +25,9 @@ class Stock_locations extends CI_Model { $this->db->select('location_name'); $this->db->from('stock_locations'); + $this->db->join('modules', 'modules.module_id=concat(\'items_stock\', location_id)'); + $this->db->join('permissions', 'permissions.module_id=modules.module_id'); + $this->db->where('person_id', $this->session->userdata('person_id')); $this->db->where('deleted', 0); return $this->db->get(); } @@ -34,27 +40,30 @@ class Stock_locations extends CI_Model return $this->db->get()->row(); } - function get_undeleted_all($limit=10000, $offset=0) + function get_undeleted_all() { $this->db->from('stock_locations'); + $this->db->join('modules', 'modules.module_id=concat(\'items_stock\', location_id)'); + $this->db->join('permissions', 'permissions.module_id=modules.module_id'); + $this->db->where('person_id', $this->session->userdata('person_id')); $this->db->where('deleted',0); - $this->db->limit($limit); - $this->db->offset($offset); return $this->db->get(); } - function get_location_id($location_name) + function get_allowed_locations() { - $this->db->from('stock_locations'); - $this->db->where('deleted',0); - $this->db->where('location_name',$location_name); - return $this->db->get()->row()->location_id; + $stock = $this->get_undeleted_all()->result_array(); + $stock_locations = array(); + foreach($stock as $location_data) + { + $stock_locations[$location_data['location_id']] = $location_data['location_name']; + } + return $stock_locations; } function get_location_name($location_id) { $this->db->from('stock_locations'); - $this->db->where('deleted',0); $this->db->where('location_id',$location_id); return $this->db->get()->row()->location_name; } @@ -91,6 +100,8 @@ class Stock_locations extends CI_Model $this->db->where('location_id', $db['location_id']); $this->db->update('stock_locations',array('location_name'=>$db['location_name'],'deleted'=>0)); + // remmove module (and permissions) for stock location + $this->db->delete('modules', array('module_id' => 'items_stock'.$db['location_id'])); } $to_create = false; break; @@ -101,6 +112,18 @@ class Stock_locations extends CI_Model { $location_data = array('location_name'=>$location,'deleted'=>0); $this->db->insert('stock_locations',$location_data); + // insert new module for stock location + $module_id = 'items_stock'.$this->db->insert_id(); + $module_name = 'module_'.$module_id; + $module_data = array('name_lang_key' => $module_name, 'desc_lang_key' => $module_name.'_desc', 'module_id' => $module_id); + $this->db->insert('modules', $module_data); + // insert permissions for stock location + $employees = $this->Employee->get_all(); + foreach ($employees->result_array() as $employee) + { + $permission_data = array('module_id' => $module_id, 'person_id' => $employee['person_id']); + $this->db->insert('permissions', $permission_data); + } } } $this->db->trans_complete(); diff --git a/application/views/employees/form.php b/application/views/employees/form.php index 389c04612..03d928f69 100644 --- a/application/views/employees/form.php +++ b/application/views/employees/form.php @@ -54,15 +54,35 @@ $password_label_attributes = $person_info->person_id == "" ? array('class'=>'req result() as $module) { + if (sizeof(explode('_', $module->module_id)) == 1) + { ?>
  • module_id,$this->Employee->has_permission($module->module_id,$person_info->person_id)); ?> lang->line('module_'.$module->module_id);?>: lang->line('module_'.$module->module_id.'_desc');?> -
  • result() as $submodule) + { + $exploded_submodule_id = explode('_', $submodule->module_id); + if (sizeof($exploded_submodule_id) > 1 && $exploded_submodule_id[0] == $module->module_id) + { + $lang_line = $this->lang->line('reports_'.$exploded_submodule_id[1]); + $lang_line = empty($lang_line) ? $this->Stock_locations->get_location_name(substr($exploded_submodule_id[1], -1)) : $lang_line; + ?> + + + li > input[name='permissions[]']").each(function() + { + var $this = $(this); + $("ul > li > input", $this.parent()).each(function() + { + var $that = $(this); + var updateCheckboxes = function (checked) + { + if (checked) { + $that.removeAttr("disabled"); + } else { + $that.attr("disabled", "disabled"); + $that.removeAttr("checked", ""); + } + } + $this.change(function() { + updateCheckboxes($this.is(":checked")); + }); + }); + }); + $('#employee_form').validate({ submitHandler:function(form) { @@ -123,7 +164,30 @@ $(document).ready(function() { equalTo: "#password" }, - email: "email" + email: "email", "permissions[]" : { + required : function(element) { + var checked = false; + $("ul#permission_list > li > input:checkbox").each(function() + { + if ($(this).is(":checked")) { + var has_children = false; + $("ul > li > input:checkbox", $(this).parent()).each(function() + { + has_children = true; + checked |= $(this).is(":checked"); + console.log("checking.. " + $(this).val() + " required " + checked); + }); + if (has_children && !checked) + { + return false; + } + } + }); + console.log("returning " + !checked); + return !checked; + }, + minlength: 1 + } }, messages: { @@ -151,7 +215,8 @@ $(document).ready(function() { equalTo: "lang->line('employees_password_must_match'); ?>" }, - email: "lang->line('common_email_invalid_format'); ?>" + email: "lang->line('common_email_invalid_format'); ?>", + "permissions[]": "fill in correctly!!" } }); }); diff --git a/application/views/home.php b/application/views/home.php index caaccb417..4cd22743e 100644 --- a/application/views/home.php +++ b/application/views/home.php @@ -5,6 +5,8 @@ result() as $module) { + if (sizeof(explode('_', $module->module_id)) == 1) + { ?>
    module_id");?>"> @@ -13,6 +15,7 @@ - lang->line('module_'.$module->module_id.'_desc');?>
    diff --git a/application/views/items/manage.php b/application/views/items/manage.php index 0a36e1f47..5a0abbee2 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -152,6 +152,12 @@ function show_hide_search_filter(search_filter_section, switchImgTag) {
  • lang->line("common_delete"),array('id'=>'delete')); ?>
  • lang->line("items_bulk_edit"),array('id'=>'bulk_edit','title'=>$this->lang->line('items_edit_multiple_items'))); ?>
  • lang->line("items_generate_barcodes"),array('id'=>'generate_barcodes', 'target' =>'_blank','title'=>$this->lang->line('items_generate_barcodes'))); ?>
  • + 1): ?> +
  • + 'stock_filter_form')); ?> + +
  • +
  • spinner 'search_form')); ?> diff --git a/application/views/partial/header.php b/application/views/partial/header.php index 3f65a343f..9b2514a18 100644 --- a/application/views/partial/header.php +++ b/application/views/partial/header.php @@ -44,13 +44,16 @@ html { result() as $module) { - ?> + if (sizeof(explode('_', $module->module_id)) == 1) + { + ?> - diff --git a/application/views/reports/graphical.php b/application/views/reports/graphical.php index 3a89407ee..847f70505 100644 --- a/application/views/reports/graphical.php +++ b/application/views/reports/graphical.php @@ -4,7 +4,6 @@ $this->load->view("partial/header");
    - +load->view("partial/footer"); ?> \ No newline at end of file diff --git a/application/views/sales/register.php b/application/views/sales/register.php index d22ba61ef..599f308ea 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -20,7 +20,7 @@ if (isset($success)) 'mode_form')); ?> lang->line('sales_mode') ?> - + 0): ?> lang->line('sales_stock_location') ?> diff --git a/css/general.css b/css/general.css index 19629b365..41cd7ddfd 100644 --- a/css/general.css +++ b/css/general.css @@ -145,6 +145,11 @@ input#search padding: 0px; } +select#stock_location +{ + border: none; +} + #select_customer_form input, #select_supplier_form input { width: 95%; diff --git a/css/popupbox.css b/css/popupbox.css index 64f967764..bd4b54169 100644 --- a/css/popupbox.css +++ b/css/popupbox.css @@ -49,6 +49,13 @@ padding:5px; } +#permission_list ul li +{ + padding-left:20px; + padding-bottom: 0px; + list-style:none; +} + #permission_list input { top:3px; diff --git a/css/tables.css b/css/tables.css index a584c61a7..7457dd9b7 100644 --- a/css/tables.css +++ b/css/tables.css @@ -26,7 +26,7 @@ } -#table_action_header ul li span +#table_action_header ul li span a { background-color:#0a6184; border:2px solid #DDDDDD; diff --git a/database/2.3_to_2.3.1.sql b/database/2.3_to_2.3.1.sql new file mode 100644 index 000000000..c76c87580 --- /dev/null +++ b/database/2.3_to_2.3.1.sql @@ -0,0 +1,33 @@ +-- add granular report permissions +INSERT INTO ospos_modules (name_lang_key, desc_lang_key, sort, module_id) VALUES +('module_reports_sales', 'module_reports_sales_desc', 51, 'reports_sales'), +('module_reports_receivings', 'module_reports_receivings_desc', 52, 'reports_receivings'), +('module_reports_items', 'module_reports_items_desc', 54, 'reports_items'), +('module_reports_inventory', 'module_reports_inventory_desc', 55, 'reports_inventory'), +('module_reports_customers', 'module_reports_customers_desc', 56, 'reports_customers'), +('module_reports_employees', 'module_reports_employees_desc', 57, 'reports_employees'), +('module_reports_suppliers', 'module_reports_suppliers_desc', 57, 'reports_suppliers'); + +-- add modules for existing stock locations +INSERT INTO ospos_modules (name_lang_key, desc_lang_key, sort, module_id) (SELECT CONCAT('module_items_stock', location_id), CONCAT('module_items_stock', location_id, '_desc'), (SELECT MAX(sort)+1 FROM ospos_modules WHERE module_id LIKE 'items_stock%' OR module_id = 'items'), CONCAT('items_stock', location_id) from ospos_stock_locations); + +-- add permissions for all employees +INSERT INTO `ospos_permissions` (`module_id`, `person_id`) SELECT 'reports_customers', person_id from ospos_employees; +INSERT INTO `ospos_permissions` (`module_id`, `person_id`) SELECT 'reports_receivings', person_id from ospos_employees; +INSERT INTO `ospos_permissions` (`module_id`, `person_id`) SELECT 'reports_items', person_id from ospos_employees; +INSERT INTO `ospos_permissions` (`module_id`, `person_id`) SELECT 'reports_inventory', person_id from ospos_employees; +INSERT INTO `ospos_permissions` (`module_id`, `person_id`) SELECT 'reports_employees', person_id from ospos_employees; +INSERT INTO `ospos_permissions` (`module_id`, `person_id`) SELECT 'reports_suppliers', person_id from ospos_employees; +INSERT INTO `ospos_permissions` (`module_id`, `person_id`) SELECT 'reports_sales', person_id from ospos_employees; + +-- add config options for tax inclusive sales +INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('tax_included', '0'); + +-- add cascading deletes on modules +ALTER TABLE `ospos_permissions` DROP FOREIGN KEY `ospos_permissions_ibfk_1`; +ALTER TABLE `ospos_permissions` ADD CONSTRAINT `ospos_permissions_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos`.`ospos_employee`(`person_id`) ON DELETE CASCADE ON UPDATE RESTRICT; + +ALTER TABLE `ospos_permissions` DROP FOREIGN KEY `ospos_permissions_ibfk_2`; +ALTER TABLE `ospos_permissions` ADD CONSTRAINT `ospos_permissions_ibfk_2` FOREIGN KEY (`module_id`) REFERENCES `ospos`.`ospos_modules`(`module_id`) ON DELETE CASCADE ON UPDATE RESTRICT; + + diff --git a/database/database.sql b/database/database.sql index 06c6b70ef..025d542cc 100644 --- a/database/database.sql +++ b/database/database.sql @@ -36,7 +36,8 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('phone', '555-555-5555'), ('return_policy', 'Test'), ('timezone', 'America/New_York'), -('website', ''); +('website', ''), +('tax_included', '0'); -- -------------------------------------------------------- @@ -94,7 +95,7 @@ CREATE TABLE `ospos_giftcards` ( `person_id` INT NOT NULL, PRIMARY KEY (`giftcard_id`), UNIQUE KEY `giftcard_number` (`giftcard_number`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=48 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ; -- -- Dumping data for table `ospos_giftcards` @@ -142,7 +143,6 @@ CREATE TABLE `ospos_items` ( `unit_price` decimal(15,2) NOT NULL, `quantity` decimal(15,2) NOT NULL DEFAULT '0.00', `reorder_level` decimal(15,2) NOT NULL DEFAULT '0.00', - `location` varchar(255) NOT NULL, `item_id` int(10) NOT NULL AUTO_INCREMENT, `allow_alt_description` tinyint(1) NOT NULL, `is_serialized` tinyint(1) NOT NULL, @@ -262,9 +262,17 @@ INSERT INTO `ospos_modules` (`name_lang_key`, `desc_lang_key`, `sort`, `module_i ('module_employees', 'module_employees_desc', 80, 'employees'), ('module_giftcards', 'module_giftcards_desc', 90, 'giftcards'), ('module_items', 'module_items_desc', 20, 'items'), +('module_items_stock0', 'module_items_stock0_desc', 20, 'items_stock0'), ('module_item_kits', 'module_item_kits_desc', 30, 'item_kits'), ('module_receivings', 'module_receivings_desc', 60, 'receivings'), ('module_reports', 'module_reports_desc', 50, 'reports'), +('module_reports_sales', 'module_reports_sales_desc', 51, 'reports_sales'), +('module_reports_receivings', 'module_reports_receivings_desc', 52, 'reports_receivings'), +('module_reports_items', 'module_reports_items_desc', 54, 'reports_items'), +('module_reports_inventory', 'module_reports_inventory_desc', 55, 'reports_inventory'), +('module_reports_customers', 'module_reports_customers_desc', 56, 'reports_customers'), +('module_reports_employees', 'module_reports_employees_desc', 57, 'reports_employees'), +('module_reports_suppliers', 'module_reports_suppliers_desc', 57, 'reports_suppliers'), ('module_sales', 'module_sales_desc', 70, 'sales'), ('module_suppliers', 'module_suppliers_desc', 40, 'suppliers'); @@ -315,7 +323,14 @@ CREATE TABLE `ospos_permissions` ( -- INSERT INTO `ospos_permissions` (`module_id`, `person_id`) VALUES -('config', 1), +('reports_customers', 1), +('reports_receivings', 1), +('reports_items', 1), +('reports_inventory', 1), +('reports_employees', 1), +('reports_suppliers', 1), +('reports_sales', 1), +('items_stock0', 1), ('customers', 1), ('employees', 1), ('giftcards', 1), @@ -586,8 +601,7 @@ CREATE TABLE `ospos_stock_locations` ( `location_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL, `deleted` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`location_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8; - +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0; -- -- Dumping data for table `ospos_stock_locations` @@ -661,8 +675,8 @@ ALTER TABLE `ospos_item_kit_items` -- Constraints for table `ospos_permissions` -- ALTER TABLE `ospos_permissions` - ADD CONSTRAINT `ospos_permissions_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_employees` (`person_id`), - ADD CONSTRAINT `ospos_permissions_ibfk_2` FOREIGN KEY (`module_id`) REFERENCES `ospos_modules` (`module_id`); + ADD CONSTRAINT `ospos_permissions_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_employees` (`person_id`) ON DELETE CASCADE, + ADD CONSTRAINT `ospos_permissions_ibfk_2` FOREIGN KEY (`module_id`) REFERENCES `ospos_modules` (`module_id`) ON DELETE CASCADE; -- -- Constraints for table `ospos_receivings`