/** * Processes the new meal form to create a new meal * @return Redirect */ public function create(Request $request) { // Construct candidate object $meal_data = $request->all(); // Use todays date as defaults if none are given if (empty($meal_data['meal_timestamp'])) { $meal_data['meal_timestamp'] = date('d-m-Y') . ' 18:30'; } if (empty($meal_data['locked_timestamp'])) { $meal_data['locked_timestamp'] = date('d-m-Y') . ' 15:00'; } // Validate the resulting input $validator = Validator::make($meal_data, ['meal_timestamp' => ['date_format:d-m-Y G:i', 'required', 'after:now', 'unique:meals'], 'locked_timestamp' => ['date_format:d-m-Y G:i', 'required', 'after:now']], ['meal_timestamp.date_format' => 'De ingevulde maaltijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'meal_timestamp.required' => 'De ingevulde maaltijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'meal_timestamp.after' => 'Je kunt geen maaltijden aanmaken in het verleden', 'meal_timestamp.unique' => 'Er is al een maaltijd op deze datum en tijd', 'locked_timestamp.date_format' => 'De ingevulde sluitingstijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'locked_timestamp.required' => 'De ingevulde sluitingstijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'locked_timestamp.after' => 'De deadline voor aanmelding mag niet al geweest zijn']); if ($validator->passes()) { // Format dates to database compatible values $meal_data['meal_timestamp'] = DateTime::createFromFormat('d-m-Y G:i', $meal_data['meal_timestamp']); $meal_data['locked_timestamp'] = DateTime::createFromFormat('d-m-Y G:i', $meal_data['locked_timestamp']); // Save new meal $meal = new Meal($meal_data); if ($meal->save()) { Log::info("Nieuwe maaltijd: {$meal->id}|{$meal->meal_timestamp}|{$meal->event}"); Flash::set(Flash::SUCCESS, 'Maaltijd toegevoegd op ' . $meal); return redirect('/administratie'); } else { Flash::set(Flash::ERROR, 'Maaltijd kon niet worden toegevoegd'); } } else { Session::flash('validation_errors', $validator->messages()); // Repopulate the form Input::flash(); } return redirect('/administratie/nieuwe_maaltijd'); }
/** * Sends an e-mail to all present registrations that a meal has been cancelled * @param App\Models\Meal $meal * @return void */ public static function mealIsDestroyedEmail(\App\Models\Meal $meal) { foreach ($meal->registrations as $registration) { Mail::send(['mails/mealIsDestroyed/html', 'mails/mealIsDestroyed/text'], ['meal' => $meal, 'registration' => $registration], function ($message) use($meal, $registration) { $message->to($registration->email, $registration->name); $message->subject("Maaltijd " . $meal->longDate() . ' gaat niet door'); }); } }
/** * Processes the edit meal form to update a meal * @return Redirect */ public function update($id, Request $request) { // Only update existing meals $meal = Meal::find($id); if (!$meal) { App::abort(404, "Maaltijd niet gevonden"); } // Construct candidate object $meal_data = $request->all(); // Validate the resulting input $validator = Validator::make($meal_data, ['meal_timestamp' => ['date_format:d-m-Y G:i', 'required', 'unique:meals,meal_timestamp,' . $meal->id], 'locked_timestamp' => ['date_format:d-m-Y G:i', 'required']], ['meal_timestamp.date_format' => 'De ingevulde maaltijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'meal_timestamp.required' => 'De ingevulde maaltijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'meal_timestamp.unique' => 'Er is al een maaltijd op deze datum en tijd', 'locked_timestamp.date_format' => 'De ingevulde sluitingstijd is ongeldig (formaat DD-MM-YYYY HH:MM)', 'locked_timestamp.required' => 'De ingevulde sluitingstijd is ongeldig (formaat DD-MM-YYYY HH:MM)']); if ($validator->passes()) { // Format dates to database compatible values $meal_data['meal_timestamp'] = DateTime::createFromFormat('d-m-Y G:i', $meal_data['meal_timestamp']); $meal_data['locked_timestamp'] = DateTime::createFromFormat('d-m-Y G:i', $meal_data['locked_timestamp']); // Update meal in database $meal->update($meal_data); if ($meal->save()) { Log::info("Maaltijd geupdate: {$meal->id}|{$meal->meal_timestamp}|{$meal->event}"); Flash::set(Flash::SUCCESS, 'Maaltijd geupdate'); return redirect('/administratie/' . $meal->id); } else { Flash::set(Flash::ERROR, 'Maaltijd kon niet worden geupdate'); } } else { Session::flash('validation_errors', $validator->messages()); return redirect('/administratie/' . $meal->id . '/edit')->withInput(); } }
/** * Execute the console command. * * @return mixed */ public function fire() { // Get next monday $date = strtotime('next monday'); // Walk until the thursday (4 days) for ($i = 0; $i < 4; $i++) { $current_date = date('Y-m-d', strtotime("+{$i} days", $date)); echo "Attempting {$current_date}..."; if (Meal::withTrashed()->whereRaw("DATE(meal_timestamp) = '{$current_date}'")->count() == 0) { Meal::create(['meal_timestamp' => $current_date . ' 18:30:00', 'locked_timestamp' => $current_date . ' 15:00:00']); echo "created\n"; } else { echo "exists\n"; } } }
public function aanmelden_anonmiem() { $meal = Meal::find((int) Request::input('meal_id')); if (!$meal) { return response()->json(['error' => 'meal_not_found', 'error_details' => 'Maaltijd bestaat niet'], 404); } // Create a new registration $registration = new Registration(['name' => e(Request::input('name')), 'handicap' => Request::input('handicap') != '' ? e(Request::input('handicap')) : null]); $registration->confirmed = true; $registration->meal_id = $meal->id; if ($registration->save()) { Log::info("Aangemeld: administratie|{$registration->id}|{$registration->name}"); return view('meal/_registration', ['registration' => $registration]); } else { return response()->json(['error' => 'create_registration_admin_unknown_error', 'error_details' => 'Deze registratie kon niet opgeslagen worden, reden onbekend.'], 500); } }
/** * Removes a meal * @param int $id the id of the meal to remove * @return Redirect */ public function verwijder($id) { // Find the meal $meal = Meal::find($id); if (!$meal) { \App::abort(404, "Maaltijd niet gevonden"); } // Store the name of the meal for usage in the flash message $date = (string) $meal; // Send an e-mail to the registrations for confirmation \App\Http\Helpers\Mailer::mealIsDestroyedEmail($meal); // Remove all guests foreach ($meal->registrations()->get() as $registration) { if ($registration->email !== null) { $registration->delete(); } } // Remove the meal $meal->delete(); // Update user Flash::set(Flash::SUCCESS, "Maaltijd op {$date} verwijderd. Alle aanmeldingen zijn gemaild met een bevestiging."); \Log::info("Maaltijd verwijderd: {$date}"); return \Redirect::to('/administratie'); }
$contractPeriodName = $row["CONTRACTDURATIONNAME"]; $contractStart = $row["CONTRACTDURATIONSTARTDATE"]; $contractEnd = $row["CONTRACTDURATIONENDDATE"]; $currency = $row["CURRENCYISOCODE"]; $buyPrice = $row["BUYPRICE"]; $margin = $row["MARGIN"]; $sellPrice = $row["SELLING"]; $serviceTypeObj = Models\ServiceType::firstOrCreate(array('name' => $serviceType)); $currencyObj = Models\Currency::firstOrCreate(array('code' => $currency)); $regionObj = Models\Region::firstOrCreate(array('name' => $region)); $supplierObj = $regionObj->suppliers()->firstOrCreate(array('name' => $supplierName, 'ts_id' => $supplierId)); if ($occupancyId) { $occupancyObj = Models\Occupancy::firstOrCreate(array('id' => $occupancyId, 'name' => $occupancyName)); } if ($mealName) { $mealObj = Models\Meal::firstOrCreate(array('name' => $mealName)); } // Find or Create Service $serviceParams = array('ts_id' => $serviceId, 'name' => $serviceName, 'region_id' => $regionObj->id, 'currency_id' => $currencyObj->id, 'service_type_id' => $serviceTypeObj->id, 'supplier_id' => $supplierObj->id, 'name' => $serviceName); $serviceObj = Models\Service::firstOrCreate($serviceParams); // Find or Create Policies $policyParams = array('ts_id' => $policyId, 'name' => $policyName); Models\Policy::firstOrCreate($policyParams); // Find or Create Contracts $contractObj = $serviceObj->contracts()->firstOrCreate(array('ts_id' => $contractId, 'name' => $contractName)); $contractPeriodParams = array('ts_id' => $contractPeriodId, 'name' => $contractPeriodName, 'start' => date("Y/m/d", strtotime($contractStart)), 'end' => date("Y/m/d", strtotime($contractEnd))); $contractPeriodObj = $contractObj->contractPeriods()->firstOrCreate($contractPeriodParams); // Find or Create Season $seasonObj = $contractPeriodObj->seasons()->firstOrCreate(array('ts_id' => $seasonId, 'name' => $seasonName)); $seasonPeriodParams = array('start' => date("Y/m/d", strtotime($seasonStart)), 'end' => date("Y/m/d", strtotime($seasonEnd))); $seasonPeriodObj = $seasonObj->seasonPeriods()->firstOrCreate($seasonPeriodParams);
/** * Unsubscribe a user from a meal * @return JSON */ public function afmelden() { // Find the meal $meal = Meal::find((int) Request::input('meal_id')); if (!$meal) { return response()->json(['error' => 'meal_not_found', 'error_details' => 'De maaltijd bestaat niet'], 404); } // Check if the meal is still open if (!$meal->open_for_registrations()) { return response()->json(['error' => 'meal_deadline_expired', 'error_details' => 'De aanmeldingsdeadline is verstreken'], 400); } // Find the registration data $user = OAuth::user(); $registration = $user->registrationFor($meal); if (!$registration) { return response()->json(['error' => 'no_registration', 'error_details' => 'Je bent niet aangemeld voor deze maaltijd'], 404); } // Destroy the registration $id = $registration->id; $name = $registration->name; $registration->delete(); \Log::info("Afgemeld {$registration->name} (ID: {$registration->id}) voor {$meal} (ID: {$meal->id}) door {$user->name} (ID: {$user->id})"); return response(null, 200); }