示例#1
0
 public function getDelete($id)
 {
     $stock = StockDetail::find($id);
     $stockCount = StockCount::where('product_id', '=', $stock->product_id)->where('stock_info_id', '=', $stock->stock_info_id)->get();
     if ($stock->entry_type == 'StockIn') {
         $stockCount[0]->product_quantity = $stockCount[0]->product_quantity - $stock->quantity;
         $stockCount[0]->save();
     } elseif ($stock->entry_type == 'StockOut') {
         $stockCount[0]->product_quantity = $stockCount[0]->product_quantity + $stock->quantity;
         $stockCount[0]->save();
     } elseif ($stock->entry_type == 'Transfer') {
         $stockCount[0]->product_quantity = $stockCount[0]->product_quantity + $stock->quantity;
         $stockCount[0]->save();
         $stockCountTo = StockCount::where('product_id', '=', $stock->product_id)->where('stock_info_id', '=', $stock->to_stock_info_id)->get();
         $stockCountTo[0]->product_quantity = $stockCountTo[0]->product_quantity - $stock->quantity;
         $stockCountTo[0]->save();
     }
     $invoice_id = $stock->invoice_id;
     $stock->delete();
     $checkStockDetailsRow = StockDetail::where('invoice_id', '=', $invoice_id)->get();
     if (empty($checkStockDetailsRow[0])) {
         $stock_invoice = StockInvoice::where('invoice_id', '=', $invoice_id)->get();
         if (!empty($stock_invoice[0])) {
             echo 'deleted';
             $stock_invoice[0]->delete();
         }
     }
     //Session::flash('message', 'Stock  has been Successfully Deleted.');
     //return Redirect::to('stocks/index');
 }