From 868de15fcbd143fcfdead8f3e0f96ac52bb21882 Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Mon, 13 Oct 2014 12:30:37 +0200 Subject: [PATCH] Invoice number is now substituted correctly after complete Fix payments summary report Update upgrade script (not tested yet) --- application/controllers/receivings.php | 54 +++++++++++-------- .../models/reports/summary_payments.php | 6 +-- database/2.3_to_2.3.1.sql | 48 ++++++++++------- database/database.sql | 4 +- 4 files changed, 66 insertions(+), 46 deletions(-) diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index e917790d3..90e011f81 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -139,9 +139,6 @@ class Receivings extends Secure_area $comment = $this->input->post('comment'); $emp_info=$this->Employee->get_info($employee_id); $payment_type=$this->input->post('payment_type'); - $invoice_number=$this->receiving_lib->get_invoice_number(); - $data['payment_type']=$this->input->post('payment_type'); - $data['invoice_number']=$invoice_number; $data['stock_location']=$this->receiving_lib->get_stock_source(); if ($this->input->post('amount_tendered')) { @@ -155,7 +152,9 @@ class Receivings extends Secure_area $suppl_info=$this->Supplier->get_info($supplier_id); $data['supplier']=$suppl_info->first_name.' '.$suppl_info->last_name; } - + $invoice_number=$this->_substitute_invoice_number($suppl_info); + $data['invoice_number']=$invoice_number; + $data['payment_type']=$this->input->post('payment_type'); //SAVE receiving to database $data['receiving_id']='RECV '.$this->Receiving->save($data['cart'], $supplier_id,$employee_id,$comment,$payment_type,$data['stock_location'],$invoice_number); @@ -168,6 +167,32 @@ class Receivings extends Secure_area $this->receiving_lib->clear_all(); $this->_remove_duplicate_cookies(); } + + function _substitute_invoice_number($supplier_info='') + { + $invoice_number=$this->receiving_lib->get_invoice_number(); + if (empty($invoice_number)) + { + $invoice_number=$this->config->config['recv_invoice_format']; + } + $invoice_count=$this->Receiving->get_invoice_count(); + $invoice_number=str_replace('$CO',$invoice_count,$invoice_number); + $invoice_number=strftime($invoice_number); + + $supplier_id=$this->receiving_lib->get_supplier(); + if($supplier_id!=-1) + { + $invoice_number=str_replace('$SU',$supplier_info->company_name,$invoice_number); + $words = preg_split("/\s+/", $supplier_info->company_name); + $acronym = ""; + foreach ($words as $w) { + $acronym .= $w[0]; + } + $invoice_number=str_replace('$SI',$acronym,$invoice_number); + } + $this->receiving_lib->set_invoice_number($invoice_number); + return $invoice_number; + } function requisition_complete() { @@ -245,31 +270,14 @@ class Receivings extends Secure_area $this->lang->line('sales_credit') => $this->lang->line('sales_credit') ); - $invoice_number=$this->receiving_lib->get_invoice_number(); - if (empty($invoice_number)) - { - $invoice_number=$this->config->config['recv_invoice_format']; - } - $invoice_count=$this->Receiving->get_invoice_count(); - $invoice_number=str_replace('$CO',$invoice_count,$invoice_number); - $invoice_number=strftime($invoice_number); - $supplier_id=$this->receiving_lib->get_supplier(); + $info=''; if($supplier_id!=-1) { $info=$this->Supplier->get_info($supplier_id); - $invoice_number=str_replace('$SU',$info->company_name,$invoice_number); $data['supplier']=$info->first_name.' '.$info->last_name; - $words = preg_split("/\s+/", $info->company_name); - $acronym = ""; - foreach ($words as $w) { - $acronym .= $w[0]; - } - $invoice_number=str_replace('$SI',$acronym,$invoice_number); } - $this->receiving_lib->set_invoice_number($invoice_number); - $data['invoice_number']=$invoice_number; - + $data['invoice_number']=$this->_substitute_invoice_number($info); $this->load->view("receivings/receiving",$data); $this->_remove_duplicate_cookies(); diff --git a/application/models/reports/summary_payments.php b/application/models/reports/summary_payments.php index 2bfa4317e..4670b9127 100644 --- a/application/models/reports/summary_payments.php +++ b/application/models/reports/summary_payments.php @@ -20,12 +20,12 @@ class Summary_payments extends Report $this->db->where('date(sale_time) BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); if ($inputs['sale_type'] == 'sales') { - $this->db->where('quantity_purchased > 0'); + $this->db->where('payment_amount > 0'); } elseif ($inputs['sale_type'] == 'returns') { - $this->db->where('quantity_purchased < 0'); - } + $this->db->where('payment_amount < 0'); + } $this->db->group_by("payment_type"); return $this->db->get()->result_array(); } diff --git a/database/2.3_to_2.3.1.sql b/database/2.3_to_2.3.1.sql index 63e1069de..04be2291d 100644 --- a/database/2.3_to_2.3.1.sql +++ b/database/2.3_to_2.3.1.sql @@ -1,34 +1,44 @@ -- 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'); +INSERT INTO ospos_permissions (permission_id, module_id, location_id) VALUES +('reports_sales', 'reports', NULL), +('reports_receivings', 'reports', NULL), +('reports_items', 'reports', NULL), +('reports_inventory', 'reports', NULL), +('reports_customers', 'reports', NULL), +('reports_employees', 'reports', NULL), +('reports_suppliers', 'reports', NULL), +('reports_taxes', 'reports', NULL), +('reports_discounts', 'reports', NULL), +('reports_payments', 'reports', NULL), +('reports_categories', 'reports', NULL); -- 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; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_customers', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_receivings', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_items', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_inventory', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_employees', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_suppliers', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_sales', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_discounts', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_taxes', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_categories', person_id from ospos_employees; +INSERT INTO `ospos_grants` (`permssion_id`, `person_id`) SELECT 'reports_payments', person_id from ospos_employees; -- add config options for tax inclusive sales -INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('tax_included', '0'); +INSERT INTO `ospos_app_config` (`key`, `value`) VALUES +('tax_included', '0'), +('recv_invoice_format', ''); -- 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` ADD CONSTRAINT `ospos_permissions_ibfk_1` FOREIGN KEY (`location_id`) REFERENCES `ospos`.`ospos_stock_locations`(`location_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; +ALTER TABLE `ospos_grants` DROP FOREIGN KEY `ospos_grants_ibfk_1`; +ALTER TABLE `ospos_grants` ADD CONSTRAINT `ospos_grants_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `ospos`.`ospos_permissions`(`permission_id`) ON DELETE CASCADE ON UPDATE RESTRICT; -- add invoice_number column to receivings table ALTER TABLE `ospos_receivings` ADD COLUMN `invoice_number` varchar(32) DEFAULT NULL; diff --git a/database/database.sql b/database/database.sql index b81d55e8f..4501965f1 100644 --- a/database/database.sql +++ b/database/database.sql @@ -327,6 +327,7 @@ INSERT INTO `ospos_permissions` (`permission_id`, `module_id`) VALUES ('reports_taxes', 'reports'), ('reports_inventory', 'reports'), ('reports_categories', 'reports'), +('reports_payments', 'reports'), ('customers', 'customers'), ('employees', 'employees'), ('giftcards', 'giftcards'), @@ -369,7 +370,8 @@ INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES ('reports_sales', 1), ('reports_discounts', 1), ('reports_taxes', 1), -('reports_categories', 1), +('reports_categories', 1), +('reports_payments', 1), ('customers', 1), ('employees', 1), ('giftcards', 1),