Example #1
0
 public function postUpdateStock($id)
 {
     $ruless = array('product_id' => 'required', 'branch_id' => 'required', 'product_quantity' => 'required', 'entry_type' => 'required');
     $validate = Validator::make(Input::all(), $ruless);
     if ($validate->fails()) {
         return Redirect::to('stocks/edit', $id)->withErrors($validate);
     } else {
         $stock = Stock::find($id);
         $this->updateStockData($stock);
         return Redirect::to('stocks/index');
     }
 }
 public function acceptOrder(Request $request)
 {
     $clientStock = ClientStock::find($request['orderId']);
     $stock = Stock::find($clientStock->stockId);
     $login = Login::where('remember_token', '=', $request->header('token'))->where('login_from', '=', $request->ip())->join('members', 'members.id', '=', 'logins.member_id')->where('logins.status', '=', '1')->first();
     $stock->quantity = AddProduct::where('stockId', $stock->id)->where('added', 1)->sum('quantity') - AddProduct::where('stockId', $stock->id)->where('added', 0)->sum('quantity');
     if ($stock->quantity < $clientStock->amount) {
         $returnData = array('status' => 'ok', 'code' => '422', 'clientStock' => $clientStock, 'message' => 'Insufficient Stock');
         return Response::json($returnData, 422);
     }
     if ($request['status'] == 1) {
         $clientStock->acceptedBy = $login->member_id;
         $clientStock->status = 1;
         $clientStock->save();
         $addProduct = new AddProduct();
         $addProduct->stockId = $clientStock->stockId;
         $addProduct->quantity = $clientStock->amount;
         $addProduct->addedBy = $login->member_id;
         $addProduct->added = 0;
         $addProduct->ticket = $clientStock->ticket;
         $addProduct->save();
         $returnData = array('status' => 'ok', 'code' => '200', 'clientStock' => $clientStock, 'addProduct' => $addProduct);
         return Response::json($returnData, 200);
     }
     if ($request['status'] == 0) {
         $clientStock->acceptedBy = $login->member_id;
         $clientStock->status = 3;
         $clientStock->save();
         $account = new Account();
         $account->ticket = $clientStock->ticket;
         $account->amount = $clientStock->commission + $clientStock->margin;
         $account->type = 1;
         $account->addedBy = $login->member_id;
         $account->memberId = $clientStock->memberId;
         $account->save();
         $returnData = array('status' => 'ok', 'code' => '200', 'clientStock' => $clientStock, 'account' => $account);
         return Response::json($returnData, 200);
     }
 }
 public function getProduct()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('product' => 'required', 'usingCode' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'Informacion incompleta!']);
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         // If they are unauthorized no point in returning anything.
         return response()->json(['state' => 'Unauthorized']);
     }
     // Get the product.
     $product;
     if (Input::get('usingCode') == 'true') {
         $branchId = Worker::find(Auth::user()->TypeId)->BranchId;
         $product = Stock::where('Code', '=', Input::get('product'))->where('BranchId', '=', $branchId)->first();
     } else {
         $product = Stock::find(Input::get('product'));
     }
     if (!$product) {
         $response['state'] = 'Error';
         $response['error'] = 'No existe un producto con este codigo!';
         return response()->json($response);
     }
     // Return provider info.
     $response['state'] = 'Success';
     $response['product'] = $product;
     return response()->json($response);
 }
 public function getDelete($id)
 {
     $stock = Stock::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->product_quantity;
         $stockCount[0]->save();
     } elseif ($stock->entry_type == 'StockOut') {
         $stockCount[0]->product_quantity = $stockCount[0]->product_quantity + $stock->product_quantity;
         $stockCount[0]->save();
     } elseif ($stock->entry_type == 'Transfer') {
         $stockCount[0]->product_quantity = $stockCount[0]->product_quantity + $stock->product_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->product_quantity;
         $stockCountTo[0]->save();
     }
     $stock->delete();
     Session::flash('message', 'Stock  has been Successfully Deleted.');
     return Redirect::to('stocks/index');
 }
Example #5
0
 /**
  * Function that submits stocktake.
  *
  * @return Response
  */
 public function submitStockTake()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('stockItems' => 'required'));
     $response = array();
     if ($validator->fails()) {
         $response['state'] = 'Error';
         $response['error'] = 'Es necesario escribir el codigo del producto';
         return response()->json($response);
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         $response['state'] = 'No Autorizado';
         $response['error'] = 'Usuario no autorizado!';
         return response()->json($response);
     }
     // Get the branch of the current worker.
     $branchId = Worker::find(Auth::user()->TypeId)->BranchId;
     // Create Stocktake.
     $stocktake = StockTake::create(array('Created' => date('Y-m-d H:i:s'), 'BranchId' => $branchId));
     // Now insert the breakdown of the stock.
     foreach (Input::get('stockItems') as $item) {
         // Get product.
         $product = Stock::find($item['id']);
         // Insert breakdown.
         StockTakeBreakdown::create(array('StockTakeId' => $stocktake->Id, 'Code' => $product->Code, 'SystemQuantity' => $product->Quantity, 'Counted' => $item['quantity'], 'Difference' => $item['quantity'] - $product->Quantity, 'State' => 0, 'ExtraData' => ''));
     }
     $response['state'] = 'Success';
     $response['message'] = 'Toma de inventario agregado exitosamente!';
     return response()->json($response);
 }
Example #6
0
 public function adjustDuringArrival($stock_id, $doses, $item_id, $lot_number, $original_amount)
 {
     $stock = Stock::find($stock_id);
     $amount = $stock->amount + ($original_amount - $doses);
     $storeStock = StoreStock::where('store_id', $stock->store_id)->where('vaccine_id', $item_id)->where('lot_number', $lot_number)->first();
     //        $stock->amount = $doses;
     //        $storeStock->amount = $doses;
     $volume = ($original_amount - $doses) * PackagingInformation::find($stock->packaging_id)->cm_per_dose * 0.001;
     //        $current_occupied_volume = $amount * PackagingInformation::find($stock->packaging_id)->cm_per_dose * 0.001;
     //        $volume_to_use = $current_occupied_volume - $volume;
     //        $stock->save();
     //        $storeStock->save();
     //        if($stock->amount == 0){
     //            $stock->delete();
     //        }
     //        if($storeStock->amount == 0){
     //            $storeStock->delete();
     //        }
     //updating volumes
     //        $store = Store::find($stock->store_id);
     //        $store->used_volume = $store->used_volume - $volume_to_use ;
     //        $store->save();
     $reason = AdjustmentReason::where('code', 'AR')->first();
     if ($reason) {
         $adjustment_reason = $reason->id;
     } else {
         $adjustment_reason = 1;
     }
     $adjustment = new Adjustment();
     $nextNumber = $this->getNextAdjustmentNumber();
     $str = "";
     for ($sj = 6; $sj > strlen($nextNumber); $sj--) {
         $str .= "0";
     }
     $adjustment->reference = date('Y') . "3" . $str + "" . $nextNumber;
     $adjustment->adjustment_reason = $adjustment_reason;
     $adjustment->adjustment_type = 'stock';
     $adjustment->resource_id = $stock->id;
     $adjustment->year = date('Y');
     $adjustment->order_no = $nextNumber;
     $adjustment->vaccine_id = $stock->vaccine_id;
     $adjustment->store_id = $stock->store_id;
     $adjustment->lot_number = $stock->lot_number;
     $adjustment->packaging_id = $stock->packaging_id;
     $adjustment->expiry_date = $stock->expiry_date;
     $adjustment->source_id = $stock->source_id;
     $adjustment->activity_id = $stock->activity_id;
     $adjustment->recipient_id = $stock->recipient_id;
     $adjustment->previous_amount = $amount;
     $adjustment->current_amount = $stock->amount;
     $adjustment->adjusted_volume = abs($volume);
     $adjustment->save();
     Log::create(array("user_id" => Auth::user()->id, "action" => "Stock Adjustment with reference Number " . $adjustment->reference));
     return $adjustment->reference;
 }
Example #7
0
 /**
  * Function that deletes products.
  *
  * @return Response
  */
 public function deleteProduct()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('formData' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'Informacion incompleta!']);
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         // If they are unauthorized no point in returning anything.
         return response()->json(array());
     }
     $worker = Worker::find(Auth::user()->TypeId);
     $branchId = $worker->BranchId;
     // Check if we want to delete the product.
     if (Input::get('formData')['ppeChoice'] == 1) {
         // Get the product.
         $product = Stock::find(Input::get('product'));
         // Delete the product.
         $product->delete();
         $response['state'] = 'Success';
         $response['message'] = 'El producto ha sido eliminado exitosamente!';
         return response()->json($response);
     }
     $response['state'] = 'Success';
     return response()->json($response);
 }
Example #8
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $stock = Stock::find($id);
     if (Gate::denies('delete-stock', $stock)) {
         abort(403);
     }
     $exec = $stock->delete();
     if ($exec) {
         return response()->json(["status" => "success"]);
     }
 }