diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index 82fa95975..6a0412204 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -117,7 +117,7 @@ class Suppliers extends Persons 'agency_name' => $this->input->post('agency_name'), 'category' => $this->input->post('category'), 'account_number' => $this->input->post('account_number') == '' ? NULL : $this->input->post('account_number'), - 'tax_id' => $this->input->post('tax_id') == '' ? NULL : $this->input->post('tax_id') + 'tax_id' => $this->input->post('tax_id') ); if($this->Supplier->save_supplier($person_data, $supplier_data, $supplier_id)) diff --git a/application/migrations/20190129212600_indiagst.php b/application/migrations/20190129212600_indiagst.php index 9e9836cf1..225e8df83 100644 --- a/application/migrations/20190129212600_indiagst.php +++ b/application/migrations/20190129212600_indiagst.php @@ -36,17 +36,19 @@ class Migration_IndiaGST extends CI_Migration } $count_of_sales_taxes_entries = $this->get_count_of_sales_taxes_entries(); + if($count_of_sales_taxes_entries > 0) { $this->migrate_sales_taxes_data(); } + $this->drop_backups(); + error_log('Migrating tax configuration completed'); } public function down() { - $this->drop_backups(); } private function get_count_of_tax_code_entries() @@ -60,7 +62,7 @@ class Migration_IndiaGST extends CI_Migration private function get_count_of_sales_taxes_entries() { $this->db->select('COUNT(*) as count'); - $this->db->from('sales_taxes'); + $this->db->from('sales_taxes_backup'); return $this->db->get()->row()->count; } @@ -143,9 +145,9 @@ class Migration_IndiaGST extends CI_Migration private function drop_backups() { - $this->db->query('DROP TABLE IF EXISTS' . $this->db->dbprefix('tax_codes_backup')); - $this->db->query('DROP TABLE IF EXISTS' . $this->db->dbprefix('sales_taxes_backup')); - $this->db->query('DROP TABLE IF EXISTS' . $this->db->dbprefix('tax_code_rates_backup')); + $this->db->query('DROP TABLE IF EXISTS ' . $this->db->dbprefix('tax_codes_backup')); + $this->db->query('DROP TABLE IF EXISTS ' . $this->db->dbprefix('sales_taxes_backup')); + $this->db->query('DROP TABLE IF EXISTS ' . $this->db->dbprefix('tax_code_rates_backup')); } } ?> diff --git a/application/migrations/20190213210000_indiagst1.php b/application/migrations/20190213210000_indiagst1.php new file mode 100644 index 000000000..e14dc8c6e --- /dev/null +++ b/application/migrations/20190213210000_indiagst1.php @@ -0,0 +1,24 @@ + diff --git a/application/migrations/20190220210000_indiagst2.php b/application/migrations/20190220210000_indiagst2.php new file mode 100644 index 000000000..a99d71ef3 --- /dev/null +++ b/application/migrations/20190220210000_indiagst2.php @@ -0,0 +1,20 @@ + diff --git a/application/migrations/sqlscripts/3.2.1_to_3.3.0.sql b/application/migrations/sqlscripts/3.2.1_to_3.3.0.sql index eb39e4595..e99727b23 100644 --- a/application/migrations/sqlscripts/3.2.1_to_3.3.0.sql +++ b/application/migrations/sqlscripts/3.2.1_to_3.3.0.sql @@ -148,6 +148,3 @@ ALTER TABLE `ospos_expenses` INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('default_receivings_discount_type', '0'), ('default_receivings_discount', '0'); - -ALTER TABLE `ospos_suppliers` - CHANGE COLUMN `tax_id` `tax_id` VARCHAR(32) NULL; \ No newline at end of file diff --git a/application/migrations/sqlscripts/3.3.0_indiagst.sql b/application/migrations/sqlscripts/3.3.0_indiagst.sql index f17bb2ea8..fcb44bf50 100644 --- a/application/migrations/sqlscripts/3.3.0_indiagst.sql +++ b/application/migrations/sqlscripts/3.3.0_indiagst.sql @@ -74,7 +74,7 @@ CREATE TABLE IF NOT EXISTS `ospos_tax_jurisdictions` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; ALTER TABLE `ospos_suppliers` - ADD COLUMN `tax_id` varchar(32) NOT NULL DEFAULT '' AFTER `account_number`; + ADD COLUMN `tax_id` varchar(32) DEFAULT NULL AFTER `account_number`; ALTER TABLE `ospos_tax_categories` ADD COLUMN `deleted` int(1) NOT NULL DEFAULT 0 AFTER `tax_group_sequence`; diff --git a/application/migrations/sqlscripts/3.3.0_indiagst1.sql b/application/migrations/sqlscripts/3.3.0_indiagst1.sql new file mode 100644 index 000000000..bb4c469b2 --- /dev/null +++ b/application/migrations/sqlscripts/3.3.0_indiagst1.sql @@ -0,0 +1,6 @@ +UPDATE `ospos_suppliers` + SET `tax_id` = '' + WHERE `tax_id`IS NULL; + +ALTER TABLE `ospos_suppliers` + CHANGE COLUMN `tax_id` `tax_id` varchar(32) NOT NULL DEFAULT ''; diff --git a/application/migrations/sqlscripts/3.3.0_indiagst2.sql b/application/migrations/sqlscripts/3.3.0_indiagst2.sql new file mode 100644 index 000000000..f1b3ca425 --- /dev/null +++ b/application/migrations/sqlscripts/3.3.0_indiagst2.sql @@ -0,0 +1,5 @@ +-- This is to cleanup any orphaned tax migration tables + +DROP TABLE IF EXISTS `ospos_tax_codes_backup`; +DROP TABLE IF EXISTS `ospos_sales_taxes_backup`; +DROP TABLE IF EXISTS `ospos_tax_code_rates_backup`; \ No newline at end of file diff --git a/application/models/reports/Summary_sales_taxes.php b/application/models/reports/Summary_sales_taxes.php index 84087ee86..f8d68b9a8 100644 --- a/application/models/reports/Summary_sales_taxes.php +++ b/application/models/reports/Summary_sales_taxes.php @@ -16,6 +16,8 @@ class Summary_sales_taxes extends Summary_report protected function _where(array $inputs) { + $this->db->where('sales.sale_status = ' . COMPLETED); + if(empty($this->config->item('date_or_time_format'))) { $this->db->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); @@ -28,17 +30,16 @@ class Summary_sales_taxes extends Summary_report public function getData(array $inputs) { - $where = ''; - - + $where = 'WHERE sale_status = ' . COMPLETED . ' '; if(empty($this->config->item('date_or_time_format'))) { - $where .= 'WHERE DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); + $where .= 'AND DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) + . ' AND ' . $this->db->escape($inputs['end_date']); } else { - $where .= 'WHERE sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date'])); + $where .= 'AND sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date'])); } $query = $this->db->query("SELECT reporting_authority, jurisdiction_name, tax_category, tax_rate, diff --git a/application/models/reports/Summary_taxes.php b/application/models/reports/Summary_taxes.php index 11ab9f343..2c21140e0 100644 --- a/application/models/reports/Summary_taxes.php +++ b/application/models/reports/Summary_taxes.php @@ -16,6 +16,8 @@ class Summary_taxes extends Summary_report protected function _where(array $inputs) { + $this->db->where('sales.sale_status = ' . COMPLETED); + if(empty($this->config->item('date_or_time_format'))) { $this->db->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); @@ -28,15 +30,15 @@ class Summary_taxes extends Summary_report public function getData(array $inputs) { - $where = ''; + $where = 'WHERE sale_status = ' . COMPLETED . ' '; if(empty($this->config->item('date_or_time_format'))) { - $where .= 'WHERE DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); + $where .= 'AND DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); } else { - $where .= 'WHERE sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date'])); + $where .= 'AND sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date'])); } if($this->config->item('tax_included'))