/** * Function that gets order Information. * * @return Response */ public function addReturn() { // Validate Input. $validator = Validator::make(Input::all(), array('code' => 'required', 'worker' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'El codigo del ataud es necesario!']); } // 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 Item in question. $item = Production::find(Input::get('code')); if (!$item) { return response()->json(['error' => 'No existe un ataud con este codigo!']); } // Make sure item has finished production. $maxStage = $item->maxStage(); if ($item->Stage <= $maxStage) { return response()->json(['error' => 'Este ataud no ha salido del proceso de produccion!']); } // Verify that worker exists and is of correct branch. $worker = Worker::find(Input::get('worker')); if (!$worker) { return response()->json(['error' => 'Este trabajador no existe']); } if ($worker->BranchId != 2) { return response()->json(['error' => 'Este trabajador no es parte de la sucursal correcta!']); } // Set item as being repaired. $item->Stage = 0; $item->save(); // Create Repair Stage for item. $itemStage = ProductionStage::create(array('ProductionId' => $item->Id, 'Stage' => 0, 'WorkerId' => $worker->Id, 'Materials' => '{}', 'Date' => date('Y-m-d'))); // Return information. $response['success'] = 'Devolucion hecha exitosamente!'; return response()->json($response); }
/** * Function that updates record of specified item. * * @return Response */ public function updateItemProduction() { // Validate Input. $validator = Validator::make(Input::all(), array('code' => 'required', 'productCode' => 'required|integer', 'worker' => 'required|integer', 'stage' => 'required|integer')); if ($validator->fails()) { return response()->json(['error' => 'All fields are required!']); } // 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 Item in production. $item = Production::find(Input::get('productCode')); if (!$item) { return response()->json(['error' => 'No existe un ataud con este codigo!']); } // Make sure that item is still in production. $maxStage = $item->maxStage(); if ($item->Stage > $maxStage) { return response()->json(['error' => 'Este ataud ya no esta en produccion!']); } // Now check if we are changing the stage of the item. $itemStage = $item->currentStage(); if (Input::get('stage') != $item->Stage) { // Check if they are trying to take it down a stage. if (Input::get('stage') < $item->Stage) { return response()->json(['error' => 'No puede retroceder un ataud en produccion!']); } // Get current worker of current stage. $worker = Worker::find($itemStage->WorkerId); // Check that he is working today. $salary = $worker->getDateSalary(date('Y-m-d')); if (!$salary) { return response()->json(['error' => "El trabajador asignado para la etapa {$item->Stage} no ha sido agregado a la asistencia de hoy!"]); } // Get the value of the bono. $expense = $item->currentExpense(); $salary->Bonus += $expense->Bonus; $salary->save(); // Now update the stage of item. $item->Stage = Input::get('stage'); $item->save(); // Create new item Stage. $itemStage = ProductionStage::create(array('ProductionId' => $item->Id, 'Stage' => Input::get('stage'), 'WorkerId' => Input::get('worker'), 'Materials' => '{}', 'Date' => date('Y-m-d H:i:s'))); } // Go ahead and save the item. $itemStage->WorkerId = Input::get('worker'); $itemStage->save(); // Inform user. return response()->json(['success' => 'Cambios guardados exitosamente!']); }