예제 #1
0
 private function updateStockData($stock)
 {
     $stockCount = StockCount::where('product_id', '=', Input::get('product_id'))->where('stock_info_id', '=', Input::get('stock_info_id'))->get();
     if (Input::get('entry_type') == 'StockIn') {
         $stock->consignment_name = Input::get('consignment_name');
         if (empty($stockCount[0])) {
             $stockCountOld = StockCount::where('product_id', '=', $stock->product_id)->where('stock_info_id', '=', $stock->stock_info_id)->get();
             $stockCountOld[0]->product_quantity = $stockCountOld[0]->product_quantity - $stock->product_quantity;
             $stockCountOld[0]->save();
             $stockCounts = new StockCount();
             $stockCounts->product_id = Input::get('product_id');
             $stockCounts->stock_info_id = Input::get('stock_info_id');
             $stockCounts->product_quantity = Input::get('product_quantity');
             $stockCounts->save();
             $this->insertStockData($stock);
             $stock->save();
         } else {
             $stockCount[0]->product_quantity = $stockCount[0]->product_quantity - $stock->product_quantity + Input::get('product_quantity');
             $stockCount[0]->save();
             $this->insertStockData($stock);
             $stock->save();
         }
         Session::flash('message', 'Stock has been Successfully Updated && Product Quantity Updated');
     } elseif (Input::get('entry_type') == 'StockOut') {
         if (!empty($stockCount[0])) {
             if ($stockCount[0]->product_quantity >= Input::get('product_quantity')) {
                 $stockCount[0]->product_quantity = $stockCount[0]->product_quantity + $stock->product_quantity - Input::get('product_quantity');
                 $stockCount[0]->save();
                 $this->insertStockData($stock);
                 $stock->save();
                 Session::flash('message', 'Stock has been Successfully Updated && Product Quantity Updated');
             } else {
                 Session::flash('message', 'You Dont have enough products in Stock');
             }
         } else {
             Session::flash('message', 'You Dont have This products in This Stock');
         }
     } elseif (Input::get('entry_type') == 'Transfer') {
         if (!empty($stockCount[0])) {
             if ($stockCount[0]->product_quantity >= Input::get('product_quantity')) {
                 $stockCount[0]->product_quantity = $stockCount[0]->product_quantity + $stock->product_quantity - Input::get('product_quantity');
                 $stockCount[0]->save();
                 $stockCountTo = StockCount::where('product_id', '=', Input::get('product_id'))->where('stock_info_id', '=', Input::get('to_stock_info_id'))->get();
                 if (!empty($stockCountTo[0])) {
                     $stockCountTo[0]->product_quantity = $stockCountTo[0]->product_quantity - $stock->product_quantity + Input::get('product_quantity');
                     $stockCountTo[0]->save();
                     $this->insertStockData($stock);
                     $stock->save();
                 } else {
                     $stockCountToOld = StockCount::where('product_id', '=', $stock->product_id)->where('stock_info_id', '=', $stock->to_stock_info_id)->get();
                     $stockCountToOld[0]->product_quantity = $stockCountToOld[0]->product_quantity - $stock->product_quantity;
                     $stockCountToOld[0]->save();
                     $stockCounts = new StockCount();
                     $stockCounts->product_id = Input::get('product_id');
                     $stockCounts->stock_info_id = Input::get('to_stock_info_id');
                     $stockCounts->product_quantity = Input::get('product_quantity');
                     $stockCounts->save();
                     $this->insertStockData($stock);
                     $stock->save();
                 }
                 Session::flash('message', 'Product Has been successfully Transfered and Updated');
             } else {
                 Session::flash('message', 'You Dont have enough products in Stock');
             }
         } else {
             Session::flash('message', 'You Dont have This products in This Stock');
         }
     } else {
         $this->insertStockData($stock);
         $stock->save();
         Session::flash('message', 'Stock has been Successfully Created && Wastage Product Updated');
     }
 }
예제 #2
0
 private function setStockData($import, $import_details, $stockDetails, $invoiceId, $to_stock_id)
 {
     $stock_Count = StockCount::where('product_id', '=', $import_details->product_id)->where('stock_info_id', '=', $to_stock_id)->get();
     $stockDetails->branch_id = $import->branch_id;
     $stockDetails->product_id = $import_details->product_id;
     $stockDetails->entry_type = "StockIn";
     $product = Product::find($import_details->product_id);
     $stockDetails->product_type = $product->product_type;
     $stockDetails->stock_info_id = $to_stock_id;
     $stockDetails->remarks = "";
     $stockDetails->invoice_id = $invoiceId;
     $stockDetails->quantity = $import_details->quantity;
     $import_details->stock_in_status = 1;
     $import_details->save();
     if ($stockDetails->entry_type == 'StockIn') {
         $stockDetails->consignment_name = $import->consignment_name;
         if (empty($stock_Count[0])) {
             $stock_Count = new StockCount();
             $stock_Count->product_id = $import_details->product_id;
             $stock_Count->stock_info_id = $stockDetails->stock_info_id;
             $stock_Count->product_quantity = $import_details->quantity;
             $stock_Count->save();
             $stockDetails->save();
             //$stockCounts->save();
         } else {
             $stock_Count[0]->product_quantity = $stock_Count[0]->product_quantity + $import_details->quantity;
             //$stock->save();
             $stock_Count[0]->save();
             $stockDetails->save();
         }
     }
 }