From 87ea0c45f735981f3601592981f12ee16f7e1d45 Mon Sep 17 00:00:00 2001 From: Jeroen Peelaerts Date: Tue, 1 Dec 2020 22:41:05 +0100 Subject: [PATCH] Update inventory date if sale/receiving is edited (#2844) --- application/controllers/Receivings.php | 6 ++++-- application/controllers/Sales.php | 4 +++- application/models/Inventory.php | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 2ffe6672e..af59a0e47 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -378,15 +378,17 @@ class Receivings extends Secure_Controller $newdate = $this->input->post('date'); $date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $newdate); + $receiving_time = $date_formatter->format('Y-m-d H:i:s'); $receiving_data = array( - 'receiving_time' => $date_formatter->format('Y-m-d H:i:s'), + 'receiving_time' => $receiving_time, 'supplier_id' => $this->input->post('supplier_id') ? $this->input->post('supplier_id') : NULL, 'employee_id' => $this->input->post('employee_id'), 'comment' => $this->input->post('comment'), 'reference' => $this->input->post('reference') != '' ? $this->input->post('reference') : NULL ); - + + $this->Inventory->update('RECV '.$receiving_id, ['trans_date' => $receiving_time]); if($this->Receiving->update($receiving_data, $receiving_id)) { echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('receivings_successfully_updated'), 'id' => $receiving_id)); diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 1f1313a47..62a549cbb 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -1227,9 +1227,10 @@ class Sales extends Secure_Controller $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; $date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $newdate); + $sale_time = $date_formatter->format('Y-m-d H:i:s'); $sale_data = array( - 'sale_time' => $date_formatter->format('Y-m-d H:i:s'), + 'sale_time' => $sale_time, 'customer_id' => $this->input->post('customer_id') != '' ? $this->input->post('customer_id') : NULL, 'employee_id' => $this->input->post('employee_id') != '' ? $this->input->post('employee_id') : NULL, 'comment' => $this->input->post('comment'), @@ -1276,6 +1277,7 @@ class Sales extends Secure_Controller $payments[] = array('payment_id' => $payment_id, 'payment_type' => $payment_type, 'payment_amount' => $payment_amount, 'cash_refund' => 0.00, 'employee_id' => $employee_id); } + $this->Inventory->update('POS '.$sale_id, ['trans_date' => $sale_time]); if($this->Sale->update($sale_id, $sale_data, $payments)) { echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('sales_successfully_updated'), 'id' => $sale_id)); diff --git a/application/models/Inventory.php b/application/models/Inventory.php index 78904d7d3..6021a61c3 100644 --- a/application/models/Inventory.php +++ b/application/models/Inventory.php @@ -11,6 +11,12 @@ class Inventory extends CI_Model return $this->db->insert('inventory', $inventory_data); } + public function update($comment, $inventory_data) + { + $this->db->where('trans_comment', $comment); + return $this->db->update('inventory', $inventory_data); + } + public function get_inventory_data_for_item($item_id, $location_id = FALSE) { $this->db->from('inventory');