Welcome Guest, Not a member yet? Register   Sign In
How to update inventory based from orders with products.
#1

(This post was last modified: 10-10-2022, 04:51 AM by MariOkudoduma.)

I am a beginner and I need some help with the query or code.

I have a codeigniter inventory system. this has products and the products have one or more raw materials.

my problem is the code how to update raw materials inventory based on number of products per order.

a customer can order one or more products
a product has one or more raw materials
this is the VIEW:

<table class="table table-bordered" id="product_order_info_table">
                                <thead>
                                    <tr>
                                        <th style="width:35%">Products <span class="req">*</span></th>
                                        <th style="width:15%">Qty (m<sup>3</sup>)</th>
                                        <th style="width:20%">Price/m<sup>3</sup></th>
                                        <th style="width:20%">Sub-total</th>


                                        <th style="width:10%"><button type="button" id="add_row_prod_order" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i></button></th>
                                    </tr>
                                </thead>

                                <tbody>
                                    <tr id="row_1">
                                        <td>
                                            <select class="form-control order_product" data-row-id="order_product_row_1" id="order_product_id_1" name="order_product_id[]" style="width:100%;" onchange="get_product_data(1)" required>
                                                <option value="" selected="selected">Please Select Product</option>
                                                <?php foreach ($lists_products as $list_product): ?>
                                                    <option value="<?php echo $list_product->product_id; ?>" ><?php echo $list_product->product_name; ?></option>
                                                <?php endforeach ?>
                                            </select>
                                        </td>
                                        <td><input type="number" step="any" name="order_product_qty[]" id="qty_1" class="form-control" onkeyup="set_subtotal()" onchange="set_subtotal()" required></td>
                                        <td><input type="text" name="order_product_price[]" id="price_1" class="form-control" readonly="readonly" required ></td>
                                        <td><input type="text" name="order_product_subtotal[]" id="subtotal_1" class="form-control" readonly="readonly" required>
                                        <input type="hidden" name="order_product_name[]" id="prodname_1" class="form-control" readonly="readonly" required></td>

                                        <td><button type="button" class="btn btn-danger btn-sm" onclick="removeRow_pr('1')"><i class="fa fa-close"></i></button></td>
                                    </tr>
                                </tbody>
                            </table>

and this is the Model (working for order tbl but problem to update rawmaterials tbl):

public function add_order_m() {
    $form_fields = array(
        'order_idnumber' => stripslashes($this->input->post('order_idnumber')),
        'order_date' => stripslashes($this->input->post('order_date')),
        'order_duedate' => stripslashes($this->input->post('order_duedate')),
        'user_id' => stripslashes($this->input->post('user_id')),
        'customer_id' => stripslashes($this->input->post('customer_id')),
        'order_deliveryno' => stripslashes($this->input->post('order_deliveryno')),
        'order_deliverycost' => stripslashes($this->input->post('order_deliverycost')),
        'order_totalcost' => stripslashes($this->input->post('order_totalcost')),
        'order_notes' => stripslashes($this->input->post('order_notes')),
        'order_status' => stripslashes($this->input->post('order_status')),
        'order_created' => globTimeNow
    );
    $query = $this->db->insert omeglz echat('orders', $form_fields);

    $count_order_product = count($this->input->post('order_product_id'));
    for ($x = 0; $x < $count_order_product; $x++) {
        $items_orders = array(
            'op_order_id' => stripslashes($this->input->post('order_id')),
            'op_customer_id' => stripslashes($this->input->post('customer_id')),
            'op_product_id' => stripslashes($this->input->post('order_product_id')[$x]),
            'op_product_name' => stripslashes($this->input->post('order_product_name')[$x]),
            'op_product_qty' => stripslashes($this->input->post('order_product_qty')[$x]),
            'op_product_price' => stripslashes($this->input->post('order_product_price')[$x]),
            'op_product_subtotal' => stripslashes($this->input->post('order_product_subtotal')[$x])
        );

        $this->db->insert('orders_products', $items_orders);

        // update rawmats inventory
        //$o_prod_id = $this->input->post('order_product_id')[$x];
        //$o_prod_qty = $this->input->post('order_product_qty')[$x];
    }

    if ($query) {
        return true;
    } else {
        return false;
    }
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB