Update inventory date if sale/receiving is edited (#2844)

This commit is contained in:
Jeroen Peelaerts
2020-12-01 22:41:05 +01:00
committed by jekkos
parent 9ee3557672
commit 87ea0c45f7
3 changed files with 13 additions and 3 deletions

View File

@@ -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));

View File

@@ -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));

View File

@@ -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');