为什么我不能修复我的股票历史记录中的减值?我是Codeigniter 3的新手。
我的table是这样的
| 产品名称|数量|地位|
| - ------| - ------| - ------|
| REG冲绳|五百|主动|
| REG冲绳|五百|主动|
在我的POS机中,我的型号代码如下:为什么每当我输入数量800时,我都希望stock_history表看起来像这样
| 产品名称|数量|地位|
| - ------| - ------| - ------|
| REG冲绳|三百|主动|
但每当我处理输入时,表格就会变成这样
| 产品名称|数量|地位|
| - ------| - ------| - ------|
| REG冲绳|五百|主动|
在我的localhost表中它是这样的
| 产品名称|数量|地位|
| - ------| - ------| - ------|
| REG冲绳|-200人|主动|
| REG冲绳|五百|主动|
我该如何解决这个问题?
$count_product = count($this->input->post('product'));
for($x = 0; $x < $count_product; $x++) {
$prodid = $this->input->post('product')[$x];
$prod_quan = $this->model_products->getProductData($prodid);
if($prod_quan['qty']>=(int)$this->input->post('qty')[$x])
{
$this->db->where('id', $id);
$update = $this->db->update('orders', $data);
$this->db->where('order_id', $id);
$this->db->delete('order_items');
// Loop through the order items and keep track of the total quantity for each product
$product_quantities = array();
$count_product = count($this->input->post('product'));
for($x = 0; $x < $count_product; $x++) {
$product_id = $this->input->post('product')[$x];
$qty = $this->input->post('qty')[$x];
// If this is the first time we are seeing this product, initialize its quantity to 0
if (!isset($product_quantities[$product_id])) {
$product_quantities[$product_id] = 0;
}
// Add the quantity of this item to the total quantity for this product
$product_quantities[$product_id] += $qty;
}
// Loop through the product quantities and update the `order_items` table
foreach ($product_quantities as $product_id => $qty) {
$data = array(
'qty' => $qty
);
$this->db->where('product_id', $product_id);
$this->db->where('order_id', $id);
$this->db->update('order_items', $data);
$this->db->where('product_id', $product_id);
$this->db->where('st_code', $id);
$this->db->update('stock_history', $data);
}
$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];
if($prodid){
$inputQuantity = (int)$this->input->post('qty')[$x];
$this->db->where('id', $prodid);
$this->db->set('qty', "qty-$inputQuantity", false);
$this->db->update('products');
$inputQuantity = (int)$this->input->post('qty')[$x];
$this->db->where('product_id', $prodid);
$this->db->set('qty', "qty-$inputQuantity", false);
$this->db->limit(1);
$this->db->update('product_inventory');
$inputQuantity = (int)$this->input->post('qty')[$x];
$this->db->where('product_id', $prodid);
$this->db->set('qty', "qty-$inputQuantity", false);
$this->db->limit(1);
$this->db->update('stock_history');
}
}
return true;
}
else{
echo '<script>alert("NOT ENOUGH STOCKS");</script>';
}
}
}
1条答案
按热度按时间tct7dpnv1#
更新
product
表的步骤更新
stock_history
的步骤