Development Stock Control


#1

I really want to thank the work done in this project! I would be interested to collaborate and be part of it .

I am currently trying to generate a control product stock . I’ve managed to include in the product load the stock available , but I 've worked in the query to check stock when creating the invoice.
Need to validate when storing the stock placed in the quantity field is less than or equal to field stock that have crept into the table ip_product
On the other hand you need to subtract the aggregate in the "quantity " field in the creation of invoce amount .
And my next goal is to warn those responsible of stock product An alert via run -mail when the stock is below X quantity .

My main problem now is I can not validate the quantity of products placed on the quantity field with those who are in the table ip_products

Now, my code in invoice/controller/ajax.php is:

 foreach ($items as $item) {
                   $this->load->model('products/mdl_products');    
               $cantidad = $this->mdl_products->where('product_id',$item->product_id)->get()->result();
           
                if ($cantidad['product_id'] != $item->item_quantity){
                    $this->form_validation->set_rules('item_quantity', lang('quantity'), 'required');
                    $this->form_validation->run();
                     $response = array(
                        'success' => 0,
                        'validation_errors' => array(
                            'item_quantity' => form_error('item_quantity', '','')
                        )
                        
                    );
                    
                    echo json_encode($response);
                    
                    exit;

When I call the product model brings me an empty value.
Share below function model

public function check_stock($item_id){
        $this->db->select('stock');
        $this->db->where('product_id', $item_id);
    }

when stock is the name of column. I try to return data… but… nothing is happend.

If you can help me… I’ll be very greatful
and if you need some help, please contact me.
Regards


#2

Sorrry, i forgot say in the conditional if ($cantidad['product_id'] != $item->item_quantity){ must be

if ($cantidad < $item->item_quantity){

#3

i solved :smiley:

foreach ($items as $item) {

            $this->db->select('stock');
            $this->db->where('product_id', $item->product_id);
            $cantidad = $this->db->get('ip_products')->result();
            foreach ($cantidad as $row)
                {
                    $cant = $row->stock;
                }
           
            if ($cant < $item->item_quantity){
                $this->form_validation->set_rules('item_quantity', lang('quantity'), 'required');
                $this->form_validation->run();
                 $response = array(
                    'success' => 0,
                    'validation_errors' => array(
                        'item_quantity' => form_error('item_quantity', '',  'No hay stock suficiente en el producto:'. $item->item_name )
                    )
                    
                );
                
                echo json_encode($response);
                
                exit;
            }
        // Check if an item has either a quantity + price or name or description
           else if (!empty($item->item_quantity) && !empty($item->item_price)
                || !empty($item->item_name)
                || !empty($item->item_description )
            ) {

#4

Is it possible you can provide me with your code to include stock control please because im having such a nightmare, fairly new to php.

I have managed to be able to add stock but I cannot make it deduct the stock once the invoice has been generated, I know its something around these lines but im not sure where to place it, please help if possible.

$db_up = mysql_query("SELECT * FROM `ip_products` WHERE `product_name`='$invoice_item->item_name'") or die(mysql_error());
            $up_db = mysql_fetch_array($db_up);
            $up_db_quantity = $up_db[product_stock]-$invoice_item->item_quantity;
            
            $new_up = mysql_query("UPDATE `ip_product` SET `product_stock`='$up_db_quantity' WHERE `product_name`='$up_db[product_name]'") or die(mysql_error());

#5

Hi

Can you please tell me how to include stock control . Is it possible to explain step by step process