SHARE
TWEET

purchase_update

a guest Feb 25th, 2020 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function update(Request $request, $id)
  2.     {
  3.         dd($request);
  4.        
  5.             $purchase = Purchase::findOrFail($id);
  6.             $purchase['stockID'] = $request->stockID;
  7.             $purchase['supplier_id'] = $request->supplyer_id;
  8.             $purchase['payment_status_id'] = $request->payment_status;
  9.             $purchase['purchase_date'] = $request->purchase_date;
  10.             // dd($purchase);
  11.             $purchase->update();
  12.             $purchase_id = $purchase->id;
  13.             // dd($purchase_id);
  14.               /*----------------delete previous data : Start --------------------*/
  15.             $deleteddata = PurchaseDetails::where('purchase_id', $purchase_id)->delete();
  16.             /*----------------delete previous data END--------------------*/
  17.             // dd($insert_details_array);
  18.  
  19.             $insert_details_array=array();
  20.             // dd($income_id);
  21.             foreach($request->addmore as $details){
  22.                 // $data = new incomes_details();
  23.                 $data['purchase_id'] = $purchase_id;
  24.                 $data['product_id'] = $details['product_id'];
  25.                 $data['purchase_qty'] = $details['quantity'];
  26.                 $data['purchaseprice'] = $details['purchaseprice'];
  27.                 $totalpurchase = $data['purchaseprice']*$data['purchase_qty'];
  28.                 $data['total_amount'] = $totalpurchase;
  29.                 $data['created_at'] = now();
  30.                 // $product = new Product;
  31.                 // $product['id'] = $data['product_id'];
  32.                 // $product['AvlQty'] += $data['purchase_qty'];
  33.                 // $product->update();
  34.                 Product::where('id', $data['product_id'])->decrement('AvlQty',$data['purchase_qty']);
  35.                 $insert_details_array[]=$data;
  36.                 // dd($data);
  37.                 unset($data);
  38.             }
  39.             // dd($getqty);
  40.             // dd($product);
  41.            
  42.             if($insert_details_array)
  43.             {
  44.                
  45.                 PurchaseDetails::insert($insert_details_array);
  46.            
  47.             }
  48.            
  49.             return redirect()->back();
  50.        
  51.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top