Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function generateBirthdayContract(Birthday $birthday): string
- {
- $birdayService = new BirthdayService($this->container);
- $data = $birdayService->getBirthdayAsArrayFormated($birthday);
- $birthdayDateAsArray = explode('-', $data['schedule']['date']);
- $birthdayDateContract = $birthdayDateAsArray[2].$birthdayDateAsArray[1].$birthdayDateAsArray[0];
- $pdfName = [
- 'contrat',
- strtoupper($data['customer']['lastname']),
- $birthdayDateContract,
- $data['birthday_id'],
- ];
- $pdfName = implode('_', $pdfName);
- $pdfName .= '.pdf';
- if (file_exists(Constants::BIRTHDAY_CONTRACT_STORAGE . $pdfName)) {
- return $pdfName;
- }
- $customer = $birthday->getCustomer($this->container);
- $customerAddress = $customer->getAddress($this->container);
- $birthdayContractTemplate = file_get_contents(Constants::BIRTHDAY_CONTRACT_CONTENT);
- $childLastname = $data['children'][0]['lastname'];
- $childFirstname = $data['children'][0]['firstname'];
- $childBirthdateAsArray = explode('-', $data['children'][0]['birthdate']);
- $childBirthdate = count($childBirthdateAsArray) === 3
- ? implode('/', array_reverse($childBirthdateAsArray))
- : ''
- ;
- $childAge = date('Y') - $childBirthdateAsArray[0];
- $birthdayDate = count($birthdayDateAsArray) === 3
- ? implode('/', array_reverse($birthdayDateAsArray))
- : ''
- ;
- $birthdayPackage = !is_null($data['package']) ? $data['package']['name'] : '';
- $birthdayNbChildren = $data['number_children'];
- $birthdayCake = !is_null($data['cake']) ? $data['cake']['name'] : '';
- $birthdayAdvance = $data['advance_payment'] . '€';
- $birthdayAdvanceDateAsArray = explode('-', $data['advance_payment_date']);
- $birthdayAdvanceDate = count($birthdayAdvanceDateAsArray) === 3
- ? implode('/', array_reverse($birthdayAdvanceDateAsArray))
- : ''
- ;
- $birthdayPaymentType = !is_null($data['payment_type']) ? $data['payment_type']['name'] : '';
- $parentName = strtoupper($data['customer']['lastname']) . ' ' . ucfirst($data['customer']['firstname']);
- $parentAddress = $customerAddress->getStreet() . ', '
- . $customerAddress->getZipCode() . ', '
- . $customerAddress->getCity()
- ;
- $parentPhone = empty($data['customer']['phone'])
- ? $data['customer']['mobile_phone']
- : $data['customer']['phone']
- ;
- $parentMail = $data['customer']['email'];
- $totalPrice = '';
- $birthdaySupplements = '';
- $toPaid = '';
- $closedOn = '';
- $closedBy = '';
- $values = [
- '%child_lastname%' => $childLastname,
- '%child_firstname%' => $childFirstname,
- '%child_age%' => $childAge,
- '%child_birthdate%' => $childBirthdate,
- '%birthday_date%' => $birthdayDate,
- '%birthday_package%' => $birthdayPackage,
- '%birthday_nb_children%' => $birthdayNbChildren,
- '%birthday_cake%' => $birthdayCake,
- '%birthday_advance%' => $birthdayAdvance,
- '%birthday_advance_date%' => $birthdayAdvanceDate,
- '%birthday_payment_type%' => $birthdayPaymentType,
- '%parent_name%' => $parentName,
- '%parent_address%' => $parentAddress,
- '%parent_phone%' => $parentPhone,
- '%parent_email%' => $parentMail,
- '%birthday_price%' => $totalPrice,
- '%birthday_supplements%' => $birthdaySupplements,
- '%birthday_to_paid%' => $toPaid,
- '%birthday_finished%' => $closedOn,
- '%birthday_finished_by%' => $closedBy
- ];
- $content = str_ireplace(array_keys($values), array_values($values), $birthdayContractTemplate);
- $pdf = new Pdf($content,
- ['commandOptions' =>
- [
- 'useExec' => false,
- 'escapeArgs' => false,
- 'procOptions' => array(
- // This will bypass the cmd.exe which seems to be recommended on Windows
- 'bypass_shell' => true,
- // Also worth a try if you get unexplainable errors
- 'suppress_errors' => true,
- ),
- ]
- ]);
- $pdf->setOptions(array(
- 'footer-font-size' => 8,
- 'footer-font-name' => 'Cambria',
- 'footer-html' => Constants::BIRTHDAY_CONTRACT_FOOTER
- ));
- if (!$pdf->saveAs(Constants::BIRTHDAY_CONTRACT_STORAGE . $pdfName)) {
- echo $pdf->getError();
- return null;
- }
- return $pdfName;
- }
Advertisement
Add Comment
Please, Sign In to add comment