EMfinanga
1 year ago
134
0
Laravel

to check if satisfy the condition statement

Posted 1 year ago by EMfinanga

i want to have the condition regarding on my code to check few thing as per below

  1. check if the quantity is less than entered with user, and if is less don't save the data display the list of that product which is less
  • right now my code is working only for one products and save others which is not less than.
  1. Also i i want to check if the product is selected as per query says, if not true then display the error of that products is not satisfy the condition.
    • right now my code is working fine but it checks well but if there is error it save only product which is sastify condition.

below is my code of controller

                $ids=$request->name;

    
     for ($a=0; $a < count($ids); $a++)
     {
        //create detail on data faktur

        $ido=$request->name[$a];
        $store=$request->store[$a];

        $model=([
            'invoice_no'=>$fk, 
            'customer_id'=>$request->customer_id, 
            //'product_code'=>$request->product_code[$a], 
            'name'=>$request->name[$a],
            'store'=>$request->store[$a],
            'selling_price'=>$request->selling_price[$a], 
            'amount'=>$request->amount[$a],
            'qty'=>$request->qty[$a], 
        ]);
        //update stok
         $data=Stock::select('quantity','store')->where([
                        ['id', '=', $ido],
                        ['store', '=', $store],
                          ])->first();
        // apply  conditions
        //check if available

        $check=(int)$data->quantity < (int)$request->qty[$a];
        dd($data);
        if($check){
        
        return redirect()->back()
                    ->with('success','quantity is Less that entered');
            // return view('sales.index')->with('success', 'not register'); 
        }
        else{
        $stokl=(int)$data->quantity-(int)$request->qty[$a];
        // dd($stokl);

        $model1=([
            'quantity'=>$stokl,

        ]);
        $x=Stock::find($ido);

        if($x->update($model1))
        {
            Sales::create($model);
        }
        }

i need the help on declare the condition

Please sign in or create an account to participate in this conversation.