Пример #1
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);
 }