【发布时间】:2022-12-04 00:31:49
【问题描述】:
每次我在我的销售中处理我如何触发以获得总和而不仅仅是我想要的表的第一行我有相同的产品名称和数量这是我的产品库存
例如,我有 50 个,在第 2 项中我有 100 个这样的
| name | qty | date |
|---|---|---|
| milktea | 50 | december 3 2022 |
| milktea | 100 | december 1 2022 |
在我的 SALES 中,如果我输入 140,它应该是
| name | qty | date |
|---|---|---|
| milktea | 0 | december 3 2022 |
| milktea | 10 | december 1 2022 |
但它只是删除第一个数量,第二个 1 保持这样
| name | qty | date |
|---|---|---|
| milktea | 0 | december 3 2022 |
| milktea | 100 | december 1 2022 |
我的代码在这里
public function update($id)
{
if($id) {
$user_id = $this->session->userdata('id');
$user_data = $this->model_users->getUserData($user_id);
// update the table info
$order_data = $this->getOrdersData($id);
$data = $this->model_tables->update($order_data['table_id'], array('available' => 1));
if($this->input->post('paid_status') == 1) {
$this->model_tables->update($this->input->post('table_name'), array('available' => 1));
}
else {
$this->model_tables->update($this->input->post('table_name'), array('available' => 2));
}
$data = array(
'gross_amount' => $this->input->post('gross_amount_value'),
'service_charge_rate' => $this->input->post('service_charge_rate'),
'service_charge_amount' => ($this->input->post('service_charge_value') > 0) ?$this->input->post('service_charge_value'):0,
'vat_charge_rate' => $this->input->post('vat_charge_rate'),
'vat_charge_amount' => ($this->input->post('vat_charge_value') > 0) ? $this->input->post('vat_charge_value') : 0,
'net_amount' => $this->input->post('net_amount_value'),
'discount' => $this->input->post('discount_amount_value'),
'paid_status' => ($this->input->post('change_value') > 0) ? $this->input->post('paid_status') : 2,
'user_id' => $user_id,
'table_id' => $this->input->post('table_name'),
'cash_tendered' => $this->input->post('cash_tendered'),
'total_change' => ($this->input->post('change_value') > 0) ? $this->input->post('change_value') : 0,
'discount_id' => json_encode($this->input->post('discount')),
'discount_percent' => $this->input->post('discount_perct_value'),
'remarks' => $this->input->post('remarks'),
);
$this->db->where('id', $id);
$update = $this->db->update('orders', $data);
// now remove the order item data
$this->db->where('order_id', $id);
$this->db->delete('order_items');
$count_product = count($this->input->post('product'));
for($x = 0; $x < $count_product; $x++) {
$items = array(
'order_id' => $id,
'product_id' => $this->input->post('product')[$x],
'qty' => $this->input->post('qty')[$x],
'rate' => $this->input->post('rate_value')[$x],
'amount' => $this->input->post('amount_value')[$x],
);
$this->db->insert('order_items', $items);
$prodid = $this->input->post('product')[$x];
$product_data = $this->model_products->getProductData([$prodid]);
$prodname = $product_data['name'];
$inputQuantity = (int)$this->input->post('qty')[$x];
$this->db->where('qty >', 0);
$this->db->order_by('expiration_date', 'ASC');
$this->db->limit(1);
$this->db->set('qty', "qty-$inputQuantity", false);
$this->db->update('product_inventory');
}
return true;
}
}
【问题讨论】:
标签: php mysql codeigniter post codeigniter-3