private function createBill(Course $course) { $user = $course->user()->getResults(); // $name = 'Fritz'; // $lastname ='Hauser'; // $courseName ='Parties für Introvertierte'; $id = 1; $date = date('m.d.Y'); // $maxPart=34; $pdf = new FPDI(); $disk = Storage::disk('local'); $templatePath = base_path() . '/resources/assets/pdf/bill_template.pdf'; $filename = $this->generateFileName(); # set fonts and whatnot $pdf->AddFont('Calibri', '', 'calibri.php'); $pdf->AddFont('Calibri', 'B', 'calibrib.php'); $pdf->SetFont('Calibri', '', 11); # load template PDF $pdf->AddPage(); $pdf->setSourceFile($templatePath); $tplIdx = $pdf->importPage(1); $pdf->useTemplate($tplIdx); #put text into PDF $pdf->SetXY(23, 55); $pdf->Write(0, $this->sanitizeString($user->firstName)); $pdf->SetXY(23, 60); $pdf->Write(0, $this->sanitizeString($user->lastName)); $pdf->SetXY(23, 65); $pdf->Write(0, $this->sanitizeString($user->address)); $pdf->SetXY(23, 70); $pdf->Write(0, $this->sanitizeString($user->zip)); $pdf->SetXY(33, 70); $pdf->Write(0, $this->sanitizeString($user->city)); $pdf->SetXY(23, 75); $pdf->Write(0, $this->sanitizeString($user->country)); $pdf->SetXY(55, 101); $pdf->Write(0, $this->sanitizeString(mt_rand(1232, 3545345))); $pdf->SetXY(55, 106); $pdf->Write(0, $this->sanitizeString(utf8_decode($date))); $pdf->SetXY(26, 124); $pdf->Write(0, $this->sanitizeString($course->courseName)); $pdf->SetXY(32, 128.2); $pdf->Write(0, $course->id); $pdf->SetXY(70, 124); $pdf->Write(0, utf8_decode($date)); $pdf->SetXY(110, 124); $pdf->Write(0, $course->participantNum); $pdf->SetXY(165, 124); $pdf->Write(0, $course->participantNum); $pdf->SetXY(165, 138); $pdf->SetFont('Calibri', 'B', 11); $pdf->Write(0, $course->participantNum); $output = $pdf->Output('', 's'); $disk->put($filename, $output); return $filename; }
/** * @param $id * @return \Illuminate\Http\RedirectResponse * */ private function storeORUpdate(Request $request, Course $course) { $this->validate($request, ['institution' => 'required|integer', 'courseName' => 'required|max:64', 'description' => 'required|min:10', 'price' => 'numeric|required|min:0|max:9999', 'startDate' => 'required|date', 'duration' => 'required|min:0|max:480|integer', 'participantNum' => 'required|min:1|max:50|Integer']); $institution = Institution::find($request->institution); #TODO validate the institute here. #$this->validator->after(function($validator) { # if ($this->somethingElseIsInvalid()) { # $validator->errors()->add('field', 'Something is wrong with this field!'); # } #}); $course->institution()->associate($institution); $course->courseName = $request->courseName; $course->description = $request->description; $course->price = $request->price; $course->startDate = $request->startDate; $course->duration = $request->duration; $course->participantNum = $request->participantNum; $course->user()->associate(Auth::user()); if ($course->save()) { \Session::flash('flash_message', "Der Kurs wurde erfolgreich gespeichert"); \Session::flash('flash_message_type', "success"); return redirect()->action('CourseController@show', [$course->id]); } else { return Redirect::back()->withError("Der Kurs konnte leider nicht gespeichert werden.")->withInput(); } }