コード例 #1
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);
 }
コード例 #2
0
 public function getStockTakeData()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('stocktake' => '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());
     }
     // Get the branch of the current worker.
     $branchId = Worker::find(Auth::user()->TypeId)->BranchId;
     // Get the stocktake.
     $stocktake = StockTake::find(Input::get('stocktake'));
     // Get the breakdown.
     $stocktakeBreakdown = StockTakeBreakdown::where('StockTakeId', '=', $stocktake->Id)->get();
     // Save the data.
     $stocktakedata = array();
     foreach ($stocktakeBreakdown as $breakdown) {
         $product = Stock::where('BranchId', '=', $branchId)->where('Code', '=', $breakdown->Code)->first();
         array_push($stocktakedata, array('Id' => $breakdown->Id, 'Code' => $breakdown->Code, 'Description' => $product->Description, 'SystemQuantity' => $breakdown->SystemQuantity, 'Counted' => $breakdown->Counted, 'Difference' => $breakdown->Difference, 'State' => $breakdown->State));
     }
     $response['state'] = 'Success';
     $response['stocktake'] = $stocktake;
     $response['stocktakedata'] = $stocktakedata;
     return response()->json($response);
 }