diff --git a/application/models/Receiving.php b/application/models/Receiving.php index ca2420f33..25c3014ed 100644 --- a/application/models/Receiving.php +++ b/application/models/Receiving.php @@ -22,7 +22,7 @@ class Receiving extends CI_Model public function exists($receiving_id) { $this->db->from('receivings'); - $this->db->where('receiving_id',$receiving_id); + $this->db->where('receiving_id', $receiving_id); return ($this->db->get()->num_rows() == 1); } @@ -204,33 +204,38 @@ class Receiving extends CI_Model */ public function create_temp_table() { - $this->db->query("CREATE TEMPORARY TABLE IF NOT EXISTS " . $this->db->dbprefix('receivings_items_temp') . " - (SELECT - date(receiving_time) AS receiving_date, - " . $this->db->dbprefix('receivings_items') . " . receiving_id, - comment, - item_location, - reference, - payment_type, - employee_id, - " . $this->db->dbprefix('items') . " . item_id, - " . $this->db->dbprefix('receivings') . " . supplier_id, - quantity_purchased, - " . $this->db->dbprefix('receivings_items') . " . receiving_quantity, - item_cost_price, - item_unit_price, - discount_percent, - (item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent / 100) AS subtotal, - " . $this->db->dbprefix('receivings_items') . " . line AS line, - serialnumber, - " . $this->db->dbprefix('receivings_items') . " . description AS description, - (item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent / 100) AS total, - (item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent / 100) - (item_cost_price * quantity_purchased) AS profit, - (item_cost_price * quantity_purchased) AS cost - FROM " . $this->db->dbprefix('receivings_items') . " - INNER JOIN " . $this->db->dbprefix('receivings') . " ON " . $this->db->dbprefix('receivings_items') . '.receiving_id=' . $this->db->dbprefix('receivings') . '.receiving_id' . " - INNER JOIN " . $this->db->dbprefix('items') . " ON " . $this->db->dbprefix('receivings_items') . '.item_id=' . $this->db->dbprefix('items') . '.item_id' . " - GROUP BY receiving_id, item_id, line)" + $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('receivings_items_temp') . + '( + SELECT + DATE(receiving_time) AS receiving_date, + receiving_time, + receivings_items.receiving_id, + comment, + item_location, + reference, + payment_type, + employee_id, + items.item_id, + receivings.supplier_id, + quantity_purchased, + receivings_items.receiving_quantity, + item_cost_price, + item_unit_price, + discount_percent, + receivings_items.line, + serialnumber, + receivings_items.description, + (item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent / 100) AS subtotal, + (item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent / 100) AS total, + (item_unit_price * quantity_purchased - item_unit_price * quantity_purchased * discount_percent / 100) - (item_cost_price * quantity_purchased) AS profit, + (item_cost_price * quantity_purchased) AS cost + FROM ' . $this->db->dbprefix('receivings_items') . ' AS receivings_items + INNER JOIN ' . $this->db->dbprefix('receivings') . ' AS receivings + ON receivings_items.receiving_id = receivings.receiving_id + INNER JOIN ' . $this->db->dbprefix('items') . ' AS items + ON receivings_items.item_id = items.item_id + GROUP BY receivings_items.receiving_id, items.item_id, receivings_items.line + )' ); } } diff --git a/application/models/reports/Detailed_receivings.php b/application/models/reports/Detailed_receivings.php index e24635651..505f2448f 100644 --- a/application/models/reports/Detailed_receivings.php +++ b/application/models/reports/Detailed_receivings.php @@ -35,7 +35,7 @@ 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, supplier.company_name AS supplier_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(profit) AS profit, payment_type, comment, reference'); + $this->db->select('receiving_id, receiving_date, SUM(quantity_purchased) AS items_purchased, CONCAT(employee.first_name, " ", employee.last_name) AS employee_name, supplier.company_name AS supplier_name, SUM(subtotal) AS subtotal, SUM(total) AS total, SUM(profit) AS profit, payment_type, comment, reference'); $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 supplier', 'receivings_items_temp.supplier_id = supplier.person_id', 'left');