public function store(ContractRequest $request) { //dd($request); $input = $request->all(); Contract::create($input); return redirect('contracts'); }
/** * Run the database seeds. * * @return void */ public function run() { // $limit = 30; for ($i = 0; $i < $limit; $i++) { $date = \Carbon\Carbon::now()->addWeeks(rand(-4, 4)); $end_date = $date->copy()->addWeeks(rand(1, 5))->addDays($i); Contract::create(['car_id' => rand(1, 20), 'driver_id' => rand(1, 40), 'status' => rand(1, 4), 'start_date' => $date, 'end_date' => $end_date, 'rate' => rand(20, 40), 'currency' => 'GBP']); } }
public function api_new(Request $request) { $contract = Contract::create($request->all()); $contract->car_id = $request->input('car.id'); $contract->driver_id = $request->input('driver.id'); $contract->save(); // Get an instance of Monolog $monolog = Log::getMonolog(); // Choose FirePHP as the log handler $monolog->pushHandler(new \Monolog\Handler\FirePHPHandler()); // Start logging $monolog->debug('Created', [$contract]); return $contract; }
/** * Function that creates a Contract. * * @return Response */ public function makeContract() { // Validate Input. $validator = Validator::make(Input::all(), array('items' => 'required', 'client' => 'required', 'ocupation' => 'required', 'interval' => 'required', 'paymentDates' => 'required', 'startDate' => 'required', 'span' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'No se recibieron los datos necesarios!']); } // Validate file input. $validator = Validator::make(Request::all(), array('contractImage' => 'required|mimes:jpeg,jpg,png|max:2000')); if ($validator->fails()) { return response()->json(['error' => $validator->messages()]); } // 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 user branch. $worker = Worker::find(Auth::user()->TypeId); $userBranch = $worker->BranchId; // Get client. $client = Client::where('Cedula', '=', Input::get('client'))->first(); if (!$client) { return response()->json(['error' => 'El cliente no existe!']); } // Get Dollar value. $config = Configuration::find(0); // Update the client's ocupation. $client->Ocupation = Input::get('ocupation'); $client->save(); // Create the contract. // TODO: Generate contract code automatically. $contract = Contract::create(array('Code' => '14213-2', 'ClientId' => $client->Id, 'Created' => date('Y-m-d H:i:s'), 'Visited' => false, 'QuotaInterval' => Input::get('interval'), 'Quota' => 0, 'StartDate' => Input::get('startDate'), 'Interest' => Input::get('interest'), 'PaymentDates' => Input::get('paymentDates'), 'Debt' => 0, 'State' => 'good', 'BranchId' => $userBranch)); $itemsPrice = 0; // Loop through all items. $items = json_decode(Input::get('items')); foreach ($items as $code => $info) { // Check if it is a product. $product = Stock::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); if (!$product) { // Check if it is a service. $service = Service::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); if (!$service) { $response['state'] = 'Error'; $response['error'] = 'No se reconocio uno de los productos o servicios!'; return response()->json($response); } // Check it's the right category. if ($service->Category != 2) { $response['state'] = 'Error'; $response['error'] = $service->Description . ' no puede ser incluido en un contrato!'; return response()->json($response); } // Add price to total. $itemsPrice += $service->Price * $info->quantity; // Create contract breakdown. ContractBreakdown::create(array('ContractId' => $contract->Id, 'Code' => $code, 'Quantity' => $info->quantity, 'Price' => $service->Price)); } else { // Check it's the right category. if ($product->Category != 1) { $response['state'] = 'Error'; $response['error'] = $product->Description . ' no puede ser incluido en un contrato!'; return response()->json($response); } // Add price to total. $itemsPrice += $product->Price * $info->quantity; // Create contract breakdown. ContractBreakdown::create(array('ContractId' => $contract->Id, 'Code' => $code, 'Quantity' => $info->quantity, 'Price' => $product->Price)); } } // Update contract debt and quota. $contract->Quota = round($itemsPrice / $config->Dollar / Input::get('span'), 2); $contract->Debt = round($itemsPrice / $config->Dollar, 2); $contract->save(); // Save the scanned contract. $disk = Storage::disk('local'); // Check if directory for this Provider exists. $directory = 'Contracts/'; if (!$disk->exists($directory)) { // Create directory for this provider. $disk->makeDirectory($directory); } $file = Request::file('contractImage'); $extension = $file->getClientOriginalExtension(); // Now move the save the file to directory. $disk->put($directory . $contract->Id . '.' . $extension, file_get_contents($file)); $response['state'] = 'Success'; // Return response. return response()->json($response); }