diff --git a/application/models/Appconfig.php b/application/models/Appconfig.php index d64bdaac2..61dcb3fe4 100644 --- a/application/models/Appconfig.php +++ b/application/models/Appconfig.php @@ -48,17 +48,21 @@ class Appconfig extends CI_Model public function batch_save($data) { + $success = TRUE; + //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); foreach($data as $key=>$value) { - $this->save($key, $value); + $success &= $this->save($key, $value); } $this->db->trans_complete(); - return $this->db->trans_status(); + $success &= $this->db->trans_status(); + + return $success; } public function delete($key) diff --git a/application/models/Customer.php b/application/models/Customer.php index b0b41dc22..2a9a86df3 100644 --- a/application/models/Customer.php +++ b/application/models/Customer.php @@ -93,7 +93,7 @@ class Customer extends Person */ public function get_totals($customer_id) { - $this->db->select('SUM(payment_amount) as total'); + $this->db->select('SUM(payment_amount) AS total'); $this->db->from('sales'); $this->db->join('sales_payments', 'sales.sale_id = sales_payments.sale_id'); $this->db->where('sales.customer_id', $customer_id); @@ -119,26 +119,30 @@ class Customer extends Person */ public function save_customer(&$person_data, &$customer_data, $customer_id = FALSE) { + $success = FALSE; + //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); if(parent::save($person_data, $customer_id)) { - if(!$customer_id or !$this->exists($customer_id)) + if(!$customer_id || !$this->exists($customer_id)) { $customer_data['person_id'] = $person_data['person_id']; - $this->db->insert('customers', $customer_data); + $success = $this->db->insert('customers', $customer_data); } else { $this->db->where('person_id', $customer_id); - $this->db->update('customers', $customer_data); + $success = $this->db->update('customers', $customer_data); } } $this->db->trans_complete(); - return $this->db->trans_status(); + $success &= $this->db->trans_status(); + + return $success; } /* diff --git a/application/models/Employee.php b/application/models/Employee.php index 9a39363a6..defb30e8d 100644 --- a/application/models/Employee.php +++ b/application/models/Employee.php @@ -94,7 +94,7 @@ class Employee extends Person if(parent::save($person_data, $employee_id)) { - if(!$employee_id or !$this->exists($employee_id)) + if(!$employee_id || !$this->exists($employee_id)) { $employee_data['person_id'] = $employee_id = $person_data['person_id']; $success = $this->db->insert('employees', $employee_data); @@ -124,6 +124,8 @@ class Employee extends Person $this->db->trans_complete(); + $success &= $this->db->trans_status(); + return $success; } diff --git a/application/models/Giftcard.php b/application/models/Giftcard.php index a3537d052..2a38602f4 100644 --- a/application/models/Giftcard.php +++ b/application/models/Giftcard.php @@ -102,7 +102,7 @@ class Giftcard extends CI_Model */ public function save(&$giftcard_data, $giftcard_id = FALSE) { - if(!$giftcard_id or !$this->exists($giftcard_id)) + if(!$giftcard_id || !$this->exists($giftcard_id)) { if($this->db->insert('giftcards', $giftcard_data)) { diff --git a/application/models/Item.php b/application/models/Item.php index c85c2fb1f..eca147fa5 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -177,9 +177,7 @@ class Item extends CI_Model $item_obj = new stdClass(); //Get all the fields from items table - $fields = $this->db->list_fields('items'); - - foreach($fields as $field) + foreach($this->db->list_fields('items') as $field) { $item_obj->$field = ''; } @@ -227,7 +225,7 @@ class Item extends CI_Model */ public function save(&$item_data, $item_id = FALSE) { - if(!$item_id or !$this->exists($item_id)) + if(!$item_id || !$this->exists($item_id)) { if($this->db->insert('items', $item_data)) { @@ -265,11 +263,13 @@ class Item extends CI_Model // set to 0 quantities $this->Item_quantity->reset_quantity($item_id); $this->db->where('item_id', $item_id); - $this->db->update('items', array('deleted'=>1)); + $success = $this->db->update('items', array('deleted'=>1)); $this->db->trans_complete(); - return $this->db->trans_status(); + $success &= $this->db->trans_status(); + + return $success; } /* @@ -293,11 +293,13 @@ class Item extends CI_Model // set to 0 quantities $this->Item_quantity->reset_quantity_list($item_ids); $this->db->where_in('item_id', $item_ids); - $this->db->update('items', array('deleted'=>1)); - + $success = $this->db->update('items', array('deleted'=>1)); + $this->db->trans_complete(); - return $this->db->trans_status(); + $success &= $this->db->trans_status(); + + return $success; } public function get_search_suggestions($search, $filters = array('is_deleted'=>FALSE, 'search_custom'=>FALSE), $unique = FALSE, $limit = 25) diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 402f6cabf..8e4202565 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -42,9 +42,7 @@ class Item_kit extends CI_Model $item_obj = new stdClass(); //Get all the fields from items table - $fields = $this->db->list_fields('item_kits'); - - foreach($fields as $field) + foreach($this->db->list_fields('item_kits') as $field) { $item_obj->$field = ''; } @@ -70,7 +68,7 @@ class Item_kit extends CI_Model */ public function save(&$item_kit_data, $item_kit_id = FALSE) { - if(!$item_kit_id or !$this->exists($item_kit_id)) + if(!$item_kit_id || !$this->exists($item_kit_id)) { if($this->db->insert('item_kits', $item_kit_data)) { diff --git a/application/models/Item_kit_items.php b/application/models/Item_kit_items.php index 3c02454a7..ab4e0b3fa 100644 --- a/application/models/Item_kit_items.php +++ b/application/models/Item_kit_items.php @@ -18,6 +18,8 @@ class Item_kit_items extends CI_Model */ public function save(&$item_kit_items_data, $item_kit_id) { + $success = TRUE; + //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); @@ -26,12 +28,14 @@ class Item_kit_items extends CI_Model foreach($item_kit_items_data as $row) { $row['item_kit_id'] = $item_kit_id; - $this->db->insert('item_kit_items', $row); + $success &= $this->db->insert('item_kit_items', $row); } $this->db->trans_complete(); - return $this->db->trans_status(); + $success &= $this->db->trans_status(); + + return $success; } /* diff --git a/application/models/Item_taxes.php b/application/models/Item_taxes.php index 562ef88ca..270a6925f 100644 --- a/application/models/Item_taxes.php +++ b/application/models/Item_taxes.php @@ -18,6 +18,8 @@ class Item_taxes extends CI_Model */ public function save(&$items_taxes_data, $item_id) { + $success = TRUE; + //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); @@ -26,12 +28,14 @@ class Item_taxes extends CI_Model foreach($items_taxes_data as $row) { $row['item_id'] = $item_id; - $this->db->insert('items_taxes', $row); + $success &= $this->db->insert('items_taxes', $row); } $this->db->trans_complete(); - return $this->db->trans_status(); + $success &= $this->db->trans_status(); + + return $success; } /* @@ -39,6 +43,8 @@ class Item_taxes extends CI_Model */ public function save_multiple(&$items_taxes_data, $item_ids) { + $success = TRUE; + //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); @@ -49,13 +55,15 @@ class Item_taxes extends CI_Model foreach($items_taxes_data as $row) { $row['item_id'] = $item_id; - $this->db->insert('items_taxes', $row); + $success &= $this->db->insert('items_taxes', $row); } } $this->db->trans_complete(); - return $this->db->trans_status(); + $success &= $this->db->trans_status(); + + return $success; } /* diff --git a/application/models/Person.php b/application/models/Person.php index 24aae3dc2..2ae0dff13 100644 --- a/application/models/Person.php +++ b/application/models/Person.php @@ -78,7 +78,7 @@ class Person extends CI_Model */ public function save(&$person_data, $person_id = FALSE) { - if(!$person_id or !$this->exists($person_id)) + if(!$person_id || !$this->exists($person_id)) { if($this->db->insert('people', $person_data)) { @@ -114,9 +114,8 @@ class Person extends CI_Model // $this->db->or_like('phone_number', $search); // $this->db->group_end(); // $this->db->order_by('last_name', 'asc'); - $by_person_id = $this->db->get(); - foreach($by_person_id->result() as $row) + foreach($this->db->get()->result() as $row) { $suggestions[] = array('label' => $row->person_id); } diff --git a/application/models/Receiving.php b/application/models/Receiving.php index 1c09186ac..7c03909f5 100644 --- a/application/models/Receiving.php +++ b/application/models/Receiving.php @@ -58,7 +58,7 @@ class Receiving extends CI_Model public function save($items, $supplier_id, $employee_id, $comment, $invoice_number, $payment_type, $receiving_id = FALSE) { - if(count($items)==0) + if(count($items) == 0) { return -1; } @@ -141,18 +141,22 @@ class Receiving extends CI_Model public function delete_list($receiving_ids, $employee_id, $update_inventory = TRUE) { + $success = TRUE; + // start a transaction to assure data integrity $this->db->trans_start(); foreach($receiving_ids as $receiving_id) { - $this->delete($receiving_id, $employee_id, $update_inventory); + $success &= $this->delete($receiving_id, $employee_id, $update_inventory); } // execute transaction $this->db->trans_complete(); - - return $this->db->trans_status(); + + $success &= $this->db->trans_status(); + + return $success; } public function delete($receiving_id, $employee_id, $update_inventory = TRUE) diff --git a/application/models/Sale.php b/application/models/Sale.php index 35c57ae73..d65034804 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -278,7 +278,7 @@ class Sale extends CI_Model $this->db->trans_complete(); - $success = $this->db->trans_status(); + $success &= $this->db->trans_status(); } return $success; @@ -367,7 +367,7 @@ class Sale extends CI_Model $this->Inventory->insert($inv_data); $customer = $this->Customer->get_info($customer_id); - if($customer_id == -1 or $customer->taxable) + if($customer_id == -1 || $customer->taxable) { foreach($this->Item_taxes->get_info($item['item_id']) as $row) { @@ -381,6 +381,7 @@ class Sale extends CI_Model } } } + $this->db->trans_complete(); if($this->db->trans_status() === FALSE) diff --git a/application/models/Sale_suspended.php b/application/models/Sale_suspended.php index 715ad05ec..c80609d3d 100644 --- a/application/models/Sale_suspended.php +++ b/application/models/Sale_suspended.php @@ -104,7 +104,7 @@ class Sale_suspended extends CI_Model $this->db->insert('sales_suspended_items', $sales_items_data); $customer = $this->Customer->get_info($customer_id); - if($customer_id == -1 or $customer->taxable) + if($customer_id == -1 || $customer->taxable) { foreach($this->Item_taxes->get_info($item['item_id']) as $row) { diff --git a/application/models/Supplier.php b/application/models/Supplier.php index 3934e2326..03d130f6d 100644 --- a/application/models/Supplier.php +++ b/application/models/Supplier.php @@ -89,26 +89,30 @@ class Supplier extends Person */ public function save_supplier(&$person_data, &$supplier_data, $supplier_id = FALSE) { + $success = FALSE; + //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->trans_start(); if(parent::save($person_data,$supplier_id)) { - if(!$supplier_id or !$this->exists($supplier_id)) + if(!$supplier_id || !$this->exists($supplier_id)) { $supplier_data['person_id'] = $person_data['person_id']; - $this->db->insert('suppliers', $supplier_data); + $success = $this->db->insert('suppliers', $supplier_data); } else { $this->db->where('person_id', $supplier_id); - $this->db->update('suppliers', $supplier_data); + $success = $this->db->update('suppliers', $supplier_data); } } $this->db->trans_complete(); + + $success &= $this->db->trans_status(); - return $this->db->trans_status(); + return $success; } /* diff --git a/application/models/reports/Detailed_receivings.php b/application/models/reports/Detailed_receivings.php index 1da060842..ce9df2327 100644 --- a/application/models/reports/Detailed_receivings.php +++ b/application/models/reports/Detailed_receivings.php @@ -39,10 +39,10 @@ class Detailed_receivings extends Report public function getDataByReceivingId($receiving_id) { - $this->db->select('receiving_id, DATE_FORMAT(receiving_date, "%d-%m-%Y") AS receiving_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name, " ", employee.last_name) as employee_name, suppliers.company_name as supplier_name, sum(subtotal) as subtotal, sum(total) as total, sum(profit) as profit, payment_type, comment, invoice_number', false); + $this->db->select('receiving_id, DATE_FORMAT(receiving_date, "%d-%m-%Y") AS receiving_date, SUM(quantity_purchased) AS items_purchased, CONCAT(employee.first_name, " ", employee.last_name) AS employee_name, suppliers.company_name AS supplier_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(profit) AS profit, payment_type, comment, invoice_number'); $this->db->from('receivings_items_temp'); - $this->db->join('people as employee', 'receivings_items_temp.employee_id = employee.person_id'); - $this->db->join('suppliers as suppliers', 'receivings_items_temp.supplier_id = suppliers.person_id', 'left'); + $this->db->join('people AS employee', 'receivings_items_temp.employee_id = employee.person_id'); + $this->db->join('suppliers AS suppliers', 'receivings_items_temp.supplier_id = suppliers.person_id', 'left'); $this->db->where('receiving_id', $receiving_id); return $this->db->get()->row_array(); @@ -50,10 +50,10 @@ class Detailed_receivings extends Report public function getData(array $inputs) { - $this->db->select('receiving_id, receiving_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, CONCAT(supplier.first_name," ",supplier.last_name) as supplier_name, sum(total) as total, sum(profit) as profit, payment_type, comment, invoice_number', false); + $this->db->select('receiving_id, receiving_date, SUM(quantity_purchased) AS items_purchased, CONCAT(employee.first_name," ",employee.last_name) AS employee_name, CONCAT(supplier.first_name," ",supplier.last_name) AS supplier_name, SUM(total) AS total, SUM(profit) AS profit, payment_type, comment, invoice_number'); $this->db->from('receivings_items_temp'); - $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->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 '. $this->db->escape($inputs['start_date']). ' AND '. $this->db->escape($inputs['end_date'])); if ($inputs['location_id'] != 'all') @@ -94,9 +94,9 @@ class Detailed_receivings extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(total) as total'); + $this->db->select('SUM(total) AS total'); $this->db->from('receivings_items_temp'); - $this->db->where('receiving_date BETWEEN '. $this->db->escape($inputs['start_date']). ' and '. $this->db->escape($inputs['end_date'])); + $this->db->where('receiving_date BETWEEN '. $this->db->escape($inputs['start_date']). ' AND '. $this->db->escape($inputs['end_date'])); if ($inputs['location_id'] != 'all') { diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index a76e54c6a..79513c5d1 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -41,10 +41,10 @@ class Detailed_sales extends Report public function getDataBySaleId($sale_id) { - $this->db->select('sale_id, DATE_FORMAT(sale_time, "%d-%m-%Y") AS sale_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name, " ", employee.last_name) as employee_name, CONCAT(customer.first_name," ",customer.last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, payment_type, comment', false); + $this->db->select('sale_id, DATE_FORMAT(sale_time, "%d-%m-%Y") AS sale_date, SUM(quantity_purchased) AS items_purchased, CONCAT(employee.first_name, " ", employee.last_name) AS employee_name, CONCAT(customer.first_name," ",customer.last_name) AS customer_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); - $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->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_id', $sale_id); return $this->db->get()->row_array(); @@ -52,10 +52,10 @@ class Detailed_sales extends Report public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, CONCAT(customer.first_name," ",customer.last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, payment_type, comment', false); + $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, CONCAT(employee.first_name," ",employee.last_name) AS employee_name, CONCAT(customer.first_name," ",customer.last_name) AS customer_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); - $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->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 '. $this->db->escape($inputs['start_date']). ' AND '. $this->db->escape($inputs['end_date'])); if ($inputs['location_id'] != 'all') @@ -93,7 +93,7 @@ class Detailed_sales extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->where('sale_date BETWEEN '. $this->db->escape($inputs['start_date']). ' AND '. $this->db->escape($inputs['end_date'])); diff --git a/application/models/reports/Inventory_summary.php b/application/models/reports/Inventory_summary.php index 5c0280b66..a99a418d7 100644 --- a/application/models/reports/Inventory_summary.php +++ b/application/models/reports/Inventory_summary.php @@ -25,17 +25,17 @@ class Inventory_summary extends Report $this->db->from('items'); $this->db->join('item_quantities','items.item_id=item_quantities.item_id'); $this->db->join('stock_locations','item_quantities.location_id=stock_locations.location_id'); - $this->db->select('name, item_number, reorder_level, item_quantities.quantity, description, location_name, cost_price, unit_price, (cost_price*quantity) as sub_total_value'); + $this->db->select('name, item_number, reorder_level, item_quantities.quantity, description, location_name, cost_price, unit_price, (cost_price*quantity) AS sub_total_value'); $this->db->where('items.deleted', 0); // should be corresponding to values Inventory_summary::getItemCountDropdownArray() returns... if($inputs['item_count'] == 'zero_and_less') { - $this->db->where('quantity <=', 0); + $this->db->where('quantity <= '); } elseif($inputs['item_count'] == 'more_than_zero') { - $this->db->where('quantity >', 0); + $this->db->where('quantity > 0'); } if($inputs['location_id'] != 'all') diff --git a/application/models/reports/Report.php b/application/models/reports/Report.php index 0a7f6e31a..f89f6bd77 100644 --- a/application/models/reports/Report.php +++ b/application/models/reports/Report.php @@ -8,7 +8,7 @@ abstract class Report extends CI_Model //Make sure the report is not cached by the browser $this->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate"); - $this->output->set_header("Cache-Control: post-check=0, pre-check=0", false); + $this->output->set_header("Cache-Control: post-check=0, pre-check=0", FALSE); $this->output->set_header("Pragma: no-cache"); //Create our temp tables to work with the data in our report diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index e72c84922..4c5d57442 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -16,7 +16,7 @@ class Specific_customer extends Report public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, sum(quantity_purchased) as items_purchased, CONCAT(first_name, " ", last_name) as employee_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, payment_type, comment', false); + $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, CONCAT(first_name, " ", last_name) AS employee_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); $this->db->join('people', 'sales_items_temp.employee_id = people.person_id'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']) . " AND customer_id=" . $this->db->escape($inputs['customer_id'])); @@ -51,7 +51,7 @@ class Specific_customer extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']) . " AND customer_id=" . $this->db->escape($inputs['customer_id'])); diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index 474c021b6..156d2a915 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -16,9 +16,9 @@ class Specific_discount extends Report public function getData(array $inputs) { - $this->db->select('sale_id, DATE_FORMAT(sale_time, "%d-%m-%Y") AS sale_date, sum(quantity_purchased) as items_purchased, CONCAT(first_name, " ", last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, payment_type, comment', false); + $this->db->select('sale_id, DATE_FORMAT(sale_time, "%d-%m-%Y") AS sale_date, SUM(quantity_purchased) AS items_purchased, CONCAT(first_name, " ", last_name) AS customer_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); - $this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left'); + $this->db->join('people AS customer', 'sales_items_temp.customer_id = customer.person_id', 'left'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']) . " AND discount_percent >=" . $this->db->escape($inputs['discount'])); if ($inputs['sale_type'] == 'sales') @@ -51,7 +51,7 @@ class Specific_discount extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']) . " AND discount_percent >=" . $this->db->escape($inputs['discount'])); diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 97610fead..1d1615f3d 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -16,7 +16,7 @@ class Specific_employee extends Report public function getData(array $inputs) { - $this->db->select('sale_id, sale_date, sum(quantity_purchased) as items_purchased, CONCAT(first_name, " ", last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, payment_type, comment', false); + $this->db->select('sale_id, sale_date, SUM(quantity_purchased) AS items_purchased, CONCAT(first_name, " ", last_name) AS customer_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit, payment_type, comment'); $this->db->from('sales_items_temp'); $this->db->join('people', 'sales_items_temp.customer_id = people.person_id', 'left'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']) . " AND employee_id=" . $this->db->escape($inputs['employee_id'])); @@ -51,7 +51,7 @@ class Specific_employee extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']) . " AND employee_id=" . $this->db->escape($inputs['employee_id'])); diff --git a/application/models/reports/Summary_categories.php b/application/models/reports/Summary_categories.php index 7c20e4ecc..5f0c79c68 100644 --- a/application/models/reports/Summary_categories.php +++ b/application/models/reports/Summary_categories.php @@ -14,7 +14,7 @@ class Summary_categories extends Report public function getData(array $inputs) { - $this->db->select('category, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('category, SUM(quantity_purchased) AS quantity_purchased, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); @@ -36,7 +36,7 @@ class Summary_categories extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); diff --git a/application/models/reports/Summary_customers.php b/application/models/reports/Summary_customers.php index d6c5acb1e..cb2ccf979 100644 --- a/application/models/reports/Summary_customers.php +++ b/application/models/reports/Summary_customers.php @@ -14,7 +14,7 @@ class Summary_customers extends Report public function getData(array $inputs) { - $this->db->select('CONCAT(first_name, " ", last_name) as customer, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit', false); + $this->db->select('CONCAT(first_name, " ", last_name) AS customer, SUM(quantity_purchased) AS quantity_purchased, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('customers', 'customers.person_id = sales_items_temp.customer_id'); $this->db->join('people', 'customers.person_id = people.person_id'); @@ -37,7 +37,7 @@ class Summary_customers extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('customers', 'customers.person_id = sales_items_temp.customer_id'); $this->db->join('people', 'customers.person_id = people.person_id'); diff --git a/application/models/reports/Summary_discounts.php b/application/models/reports/Summary_discounts.php index 03c2e6a86..d69c3ece8 100644 --- a/application/models/reports/Summary_discounts.php +++ b/application/models/reports/Summary_discounts.php @@ -14,7 +14,7 @@ class Summary_discounts extends Report public function getData(array $inputs) { - $this->db->select('CONCAT(discount_percent, "%") as discount_percent, count(*) as count', false); + $this->db->select('CONCAT(discount_percent, "%") AS discount_percent, count(*) AS count'); $this->db->from('sales_items_temp'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); $this->db->where('discount_percent > 0'); @@ -36,7 +36,7 @@ class Summary_discounts extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); diff --git a/application/models/reports/Summary_employees.php b/application/models/reports/Summary_employees.php index fcf5d8ccf..7cd316fda 100644 --- a/application/models/reports/Summary_employees.php +++ b/application/models/reports/Summary_employees.php @@ -14,7 +14,7 @@ class Summary_employees extends Report public function getData(array $inputs) { - $this->db->select('CONCAT(first_name, " ", last_name) as employee, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit', false); + $this->db->select('CONCAT(first_name, " ", last_name) AS employee, SUM(quantity_purchased) AS quantity_purchased, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('employees', 'employees.person_id = sales_items_temp.employee_id'); $this->db->join('people', 'employees.person_id = people.person_id'); @@ -37,7 +37,7 @@ class Summary_employees extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('employees', 'employees.person_id = sales_items_temp.employee_id'); $this->db->join('people', 'employees.person_id = people.person_id'); diff --git a/application/models/reports/Summary_items.php b/application/models/reports/Summary_items.php index b3fe529c3..241efb136 100644 --- a/application/models/reports/Summary_items.php +++ b/application/models/reports/Summary_items.php @@ -14,7 +14,7 @@ class Summary_items extends Report public function getData(array $inputs) { - $this->db->select('name, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('name, SUM(quantity_purchased) AS quantity_purchased, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); @@ -36,7 +36,7 @@ class Summary_items extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); diff --git a/application/models/reports/Summary_payments.php b/application/models/reports/Summary_payments.php index eae8c2eed..76eed64eb 100644 --- a/application/models/reports/Summary_payments.php +++ b/application/models/reports/Summary_payments.php @@ -14,7 +14,7 @@ class Summary_payments extends Report public function getData(array $inputs) { - $this->db->select('sales_payments.payment_type, count(*) AS count, SUM(payment_amount) AS payment_amount', false); + $this->db->select('sales_payments.payment_type, count(*) AS count, SUM(payment_amount) AS payment_amount'); $this->db->from('sales_payments'); $this->db->join('sales', 'sales.sale_id=sales_payments.sale_id'); $this->db->where("date(sale_time) BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); @@ -57,7 +57,7 @@ class Summary_payments extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) AS subtotal, sum(total) AS total, sum(tax) AS tax, sum(cost) AS cost, sum(profit) AS profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); diff --git a/application/models/reports/Summary_sales.php b/application/models/reports/Summary_sales.php index 01c238995..bc10bd6e9 100644 --- a/application/models/reports/Summary_sales.php +++ b/application/models/reports/Summary_sales.php @@ -14,7 +14,7 @@ class Summary_sales extends Report public function getData(array $inputs) { - $this->db->select('sale_date, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('sale_date, SUM(quantity_purchased) AS quantity_purchased, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); @@ -35,7 +35,7 @@ class Summary_sales extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date'])); diff --git a/application/models/reports/Summary_suppliers.php b/application/models/reports/Summary_suppliers.php index a9c78f707..225cac213 100644 --- a/application/models/reports/Summary_suppliers.php +++ b/application/models/reports/Summary_suppliers.php @@ -14,7 +14,7 @@ class Summary_suppliers extends Report public function getData(array $inputs) { - $this->db->select('CONCAT(company_name, " (", first_name, " ",last_name, ")") as supplier, sum(quantity_purchased) as quantity_purchased, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit', false); + $this->db->select('CONCAT(company_name, " (", first_name, " ", last_name, ")") AS supplier, SUM(quantity_purchased) AS quantity_purchased, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('suppliers', 'suppliers.person_id = sales_items_temp.supplier_id'); $this->db->join('people', 'suppliers.person_id = people.person_id'); @@ -37,7 +37,7 @@ class Summary_suppliers extends Report public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('suppliers', 'suppliers.person_id = sales_items_temp.supplier_id'); $this->db->join('people', 'suppliers.person_id = people.person_id'); diff --git a/application/models/reports/Summary_taxes.php b/application/models/reports/Summary_taxes.php index ce1175538..c3304ac70 100644 --- a/application/models/reports/Summary_taxes.php +++ b/application/models/reports/Summary_taxes.php @@ -26,39 +26,39 @@ class Summary_taxes extends Report if ($this->config->item('tax_included')) { - $total = "1"; + $total = "1"; $subtotal = "(100/(100+percent))"; - $tax="(1 - (100/(100 +percent)))"; + $tax = "(1 - (100/(100 +percent)))"; } else { - $tax = "(percent/100)"; - $total = "(1+(percent/100))"; + $tax = "(percent/100)"; + $total = "(1+(percent/100))"; $subtotal = "1"; } $decimals = totals_decimals(); - $query = $this->db->query("SELECT percent, count(*) as count, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax - FROM (SELECT name, CONCAT(ROUND(percent, $decimals), '%') AS percent, - ROUND((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100) * $subtotal, $decimals) AS subtotal, - ROUND((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100) * $total, $decimals) AS total, - ROUND((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100) * $tax, $decimals) AS tax - FROM ".$this->db->dbprefix('sales_items_taxes')." - JOIN ".$this->db->dbprefix('sales_items')." ON " - .$this->db->dbprefix('sales_items').'.sale_id='.$this->db->dbprefix('sales_items_taxes').'.sale_id'." and " - .$this->db->dbprefix('sales_items').'.item_id='.$this->db->dbprefix('sales_items_taxes').'.item_id'." and " - .$this->db->dbprefix('sales_items').'.line='.$this->db->dbprefix('sales_items_taxes').'.line' - ." JOIN ".$this->db->dbprefix('sales')." ON ".$this->db->dbprefix('sales_items_taxes').".sale_id=".$this->db->dbprefix('sales').".sale_id - WHERE date(sale_time) BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']) . " $quantity_cond) AS temp_taxes - GROUP BY percent"); + $query = $this->db->query("SELECT percent, count(*) AS count, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax + FROM (SELECT name, CONCAT(ROUND(percent, $decimals), '%') AS percent, + ROUND((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100) * $subtotal, $decimals) AS subtotal, + ROUND((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100) * $total, $decimals) AS total, + ROUND((item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent /100) * $tax, $decimals) AS tax + FROM ".$this->db->dbprefix('sales_items_taxes')." + JOIN ".$this->db->dbprefix('sales_items')." ON " + .$this->db->dbprefix('sales_items').'.sale_id='.$this->db->dbprefix('sales_items_taxes').'.sale_id'." AND " + .$this->db->dbprefix('sales_items').'.item_id='.$this->db->dbprefix('sales_items_taxes').'.item_id'." AND " + .$this->db->dbprefix('sales_items').'.line='.$this->db->dbprefix('sales_items_taxes').'.line' + ." JOIN ".$this->db->dbprefix('sales')." ON ".$this->db->dbprefix('sales_items_taxes').".sale_id=".$this->db->dbprefix('sales').".sale_id + WHERE date(sale_time) BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']) . " $quantity_cond) AS temp_taxes + GROUP BY percent"); return $query->result_array(); } public function getSummaryData(array $inputs) { - $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit'); + $this->db->select('SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(tax) AS tax, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); $this->db->join('items', 'sales_items_temp.item_id = items.item_id'); $this->db->where("sale_date BETWEEN " . $this->db->escape($inputs['start_date']) . " AND " . $this->db->escape($inputs['end_date']));