public function run() { $faker = Faker\Factory::create(); for ($i = 0; $i < 20; $i++) { Request::create(['songname' => 'test', 'name' => $faker->name, 'singer' => $faker->name, 'email' => $faker->email]); } }
public function store() { if (!Input::get('title') or Input::get('body')) { return $this->setStatusCode(422)->respondWithError('Validation failed'); } else { Request::create(Input::all()); return $this->respondCreated('Request Created'); } }
/** * Function that requests discount. * * @return Response */ public function requestDiscount() { // Validate Input. $validator = Validator::make(Input::all(), array('discount' => 'required', 'reason' => 'required')); $response = array(); if ($validator->fails()) { $response['state'] = 'Error'; $response['error'] = 'Informacion incompleta!'; return response()->json($response); } // 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 worker. $worker = Worker::find(Auth::user()->TypeId); // Create Request. $request = Request::create(array('Amount' => Input::get('discount'), 'Reason' => Input::get('reason'), 'RequestBy' => Auth::user()->Id, 'State' => 'pending', 'GrantedBy' => 0, 'Used' => false)); // Get admins and notify them. $users = User::where('UserLevel', '=', 1)->get(); foreach ($users as $admin) { Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => $worker->Name . ' ha solicitado permiso para dar un descuento del ' . $request->Amount . '% en una venta.', 'Url' => '/sales/discountRequest/' . $request->Id, 'Seen' => false)); } $response['state'] = 'Success'; $response['request'] = $request; return response()->json($response); }
public function store(LCCBRequest $request) { $request->request->add(['submitted_by' => Auth::user()->id]); if (is_string($request->equipment_id)) { $newEquip = Equipment::firstOrNew(['name' => $request->equipment_id]); $newEquip->user_id = Auth::user()->id; $newEquip->save(); $request->request->set('equipment_id', $newEquip->id); } $newRequest = Request::create($request->all()); if (!is_null($request->file('files'))) { foreach ($request->file('files') as $file) { Upload::create(['request_id' => $newRequest->id, 'file_name' => $file->getClientOriginalName()]); $destinationPath = 'D:\\www\\lccb\\uploads\\lccbRequests\\' . $newRequest->id; $file->move($destinationPath, $file->getClientOriginalName()); } } Event::fire(new RequestWasSubmitted($newRequest)); $json['success'] = 1; $json['message'] = "Request saved"; $json['redirect'] = "/lccb/" . $newRequest->id . "/edit"; return json_encode($json); }
/** * Function that adds a loan to defined worker. * * @return Response */ public function requestLoan() { // Validate Input. $validator = Validator::make(Input::all(), array('worker' => 'required', 'formData' => 'required')); if ($validator->fails()) { // No reason why staffId and dayType would not be provided so return nothing. return response()->json(array()); } // 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()); } // Create request. $request = Request::create(array('Amount' => Input::get('formData')['plsamounts'], 'Reason' => Input::get('formData')['plsReasons'], 'RequestBy' => Auth::user()->Id, 'State' => 'pending', 'GrantedBy' => 0, 'Used' => false, 'Created' => date('Y-m-d H:i:s'))); // Notify admins. $worker = Worker::find(Auth::user()->TypeId); $loanTo = Worker::where('Cedula', '=', Input::get('worker'))->first(); $users = User::where('UserLevel', '=', 1)->get(); foreach ($users as $admin) { Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => $worker->Name . ' ha solicitado permiso para prestar dinero a ' . $loanTo->Name . '.', 'Url' => '/requestLoan/' . $request->Id, 'Seen' => false)); } $response['state'] = 'Success'; $response['message'] = 'La solicitud fue realizada exitosamente! Recibiras una notificacion cuando haya respuesta de algun administrador.'; return response()->json($response); }
/** * Function that requests permission to authorized users to make a withdrawal. * * @return Response */ public function othersRequest() { // Validate Input. $validator = Validator::make(Input::all(), array('amount' => 'required', 'reason' => 'required')); $response = array(); if ($validator->fails()) { $response['state'] = 'Error'; $response['error'] = 'No se envio la informacion completa para realizar esta operacion!'; return response()->json($response); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { $response['state'] = 'No autorizado'; $response['error'] = 'El usuario no esta autorizado para realizar esta operacion!'; return response()->json($response); } // Check that cashbox is open. $cashbox = Cashbox::where('UserId', '=', Auth::user()->Id)->where('Close', '=', NULL)->first(); if (!$cashbox) { $response['state'] = 'Error'; $response['error'] = 'La caja no esta abierta, por lo tanto no se puede solicitar el retiro!'; return response()->json($response); } // Generate Request. $request = Request::create(array('RequestBy' => Auth::user()->Id, 'State' => 'pending', 'GrantedBy' => 0, 'Used' => false, 'Amount' => Input::get('amount'), 'Reason' => Input::get('reason'))); // Get users that have permission to withdraw money from cashbox. /*$canWithdraw = array(); $levels = UserLevel::all(); foreach($levels as $level) { $permissions = json_decode($level->Permissions); if($permissions->cashbox->withdraw) { array_push($canWithdraw, array($permissions->role => $level->Id)); } } // Get info on worker that is making request. $worker = Worker::find(Auth::user()->TypeId); // Send notifications to all users that are admins or are within same branch. foreach($canWithdraw as $role => $id) { $users = User::where('UserLevel', '=', $id)->get(); foreach($users as $user) { if($role == 'admin') { Notification::create(array('UserId' => $user->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => $worker->Name.' ha solicitado permiso para retirar dinero de la caja para otros gastos.', 'Url' => '/request/'.$request->Id, 'Seen' => false)); } else { $workerWithPermission = Worker::find($user->TypeId); if($workerWithPermission->BranchId == $worker->BranchId) { Notification::create(array('UserId' => $user->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => $worker->Name.' ha solicitado permiso para retirar dinero de la caja para otros gastos.', 'Url' => '/request/'.$request->Id, 'Seen' => false)); } } } }*/ // Get info on worker that is making request. $worker = Worker::find(Auth::user()->TypeId); $users = User::where('UserLevel', '=', 1)->get(); foreach ($users as $admin) { Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => $worker->Name . ' ha solicitado permiso para retirar dinero de la caja.', 'Url' => '/request/' . $request->Id, 'Seen' => false)); } // Get the total amount of cash that the cashbox was opened with. $initial = 0; $cash = 0; foreach (json_decode($cashbox->Open) as $bill => $amount) { if ($bill != 'dollar') { $cash += $bill * $amount; } else { $cash += Configuration::find(0)->Dollar * $amount; } } $initial = $cash; // Now get all transactions. $transactions = CashboxTransaction::where('CashboxId', '=', $cashbox->Id)->get(); // Go through transactions to get total of all kind of transactions. $card = 0; $providers = 0; $staff = 0; $others = 0; $withdrawals = 0; $refunds = 0; $sales = 0; foreach ($transactions as $transaction) { switch ($transaction->Type) { case 1: $sales += $transaction->Amount; // Check if a credit card was used for sale. if (Sale::where('TransactionId', '=', $transaction->Id)->first()->Card) { $card += $transaction->Amount; } else { $cash += $transaction->Amount; } break; case 2: $providers += $transaction->Amount; break; case 3: $staff += $transaction->Amount; break; case 4: $others += $transaction->Amount; break; case 5: $withdrawals += $transaction->Amount; break; case 6: $refunds += $transaction->Amount; break; // Contract Payments. // Contract Payments. case 7: $sales += $transaction->Amount; break; // Credit sales. // Credit sales. case 8: $sales += $transaction->Amount; break; // Deposits for reservations. // Deposits for reservations. case 9: $sales += $transaction->Amount; break; } } $cash = $cash + $refunds - $providers - $withdrawals - $others; $total = $initial + $sales + $refunds - $providers - $staff - $withdrawals - $others; // Inform user operation was completed succesfully. $response['state'] = 'Success'; $response['total'] = $total; $response['cash'] = $cash; $response['card'] = $card; $response['providers'] = $providers; $response['staff'] = $staff; $response['others'] = $others; $response['withdrawals'] = $withdrawals; $response['refunds'] = $refunds; $response['sales'] = $sales; $response['request'] = $request; return response()->json($response); }