Guest User

contract

a guest
Mar 6th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. public function generateBirthdayContract(Birthday $birthday): string
  2. {
  3. $birdayService = new BirthdayService($this->container);
  4. $data = $birdayService->getBirthdayAsArrayFormated($birthday);
  5.  
  6. $birthdayDateAsArray = explode('-', $data['schedule']['date']);
  7. $birthdayDateContract = $birthdayDateAsArray[2].$birthdayDateAsArray[1].$birthdayDateAsArray[0];
  8. $pdfName = [
  9. 'contrat',
  10. strtoupper($data['customer']['lastname']),
  11. $birthdayDateContract,
  12. $data['birthday_id'],
  13. ];
  14.  
  15. $pdfName = implode('_', $pdfName);
  16. $pdfName .= '.pdf';
  17.  
  18. if (file_exists(Constants::BIRTHDAY_CONTRACT_STORAGE . $pdfName)) {
  19. return $pdfName;
  20. }
  21.  
  22. $customer = $birthday->getCustomer($this->container);
  23. $customerAddress = $customer->getAddress($this->container);
  24.  
  25.  
  26. $birthdayContractTemplate = file_get_contents(Constants::BIRTHDAY_CONTRACT_CONTENT);
  27.  
  28. $childLastname = $data['children'][0]['lastname'];
  29. $childFirstname = $data['children'][0]['firstname'];
  30. $childBirthdateAsArray = explode('-', $data['children'][0]['birthdate']);
  31. $childBirthdate = count($childBirthdateAsArray) === 3
  32. ? implode('/', array_reverse($childBirthdateAsArray))
  33. : ''
  34. ;
  35. $childAge = date('Y') - $childBirthdateAsArray[0];
  36.  
  37. $birthdayDate = count($birthdayDateAsArray) === 3
  38. ? implode('/', array_reverse($birthdayDateAsArray))
  39. : ''
  40. ;
  41. $birthdayPackage = !is_null($data['package']) ? $data['package']['name'] : '';
  42. $birthdayNbChildren = $data['number_children'];
  43. $birthdayCake = !is_null($data['cake']) ? $data['cake']['name'] : '';
  44. $birthdayAdvance = $data['advance_payment'] . '€';
  45. $birthdayAdvanceDateAsArray = explode('-', $data['advance_payment_date']);
  46. $birthdayAdvanceDate = count($birthdayAdvanceDateAsArray) === 3
  47. ? implode('/', array_reverse($birthdayAdvanceDateAsArray))
  48. : ''
  49. ;
  50. $birthdayPaymentType = !is_null($data['payment_type']) ? $data['payment_type']['name'] : '';
  51.  
  52. $parentName = strtoupper($data['customer']['lastname']) . ' ' . ucfirst($data['customer']['firstname']);
  53. $parentAddress = $customerAddress->getStreet() . ', '
  54. . $customerAddress->getZipCode() . ', '
  55. . $customerAddress->getCity()
  56. ;
  57. $parentPhone = empty($data['customer']['phone'])
  58. ? $data['customer']['mobile_phone']
  59. : $data['customer']['phone']
  60. ;
  61. $parentMail = $data['customer']['email'];
  62.  
  63. $totalPrice = '';
  64. $birthdaySupplements = '';
  65. $toPaid = '';
  66. $closedOn = '';
  67. $closedBy = '';
  68.  
  69. $values = [
  70. '%child_lastname%' => $childLastname,
  71. '%child_firstname%' => $childFirstname,
  72. '%child_age%' => $childAge,
  73. '%child_birthdate%' => $childBirthdate,
  74. '%birthday_date%' => $birthdayDate,
  75. '%birthday_package%' => $birthdayPackage,
  76. '%birthday_nb_children%' => $birthdayNbChildren,
  77. '%birthday_cake%' => $birthdayCake,
  78. '%birthday_advance%' => $birthdayAdvance,
  79. '%birthday_advance_date%' => $birthdayAdvanceDate,
  80. '%birthday_payment_type%' => $birthdayPaymentType,
  81. '%parent_name%' => $parentName,
  82. '%parent_address%' => $parentAddress,
  83. '%parent_phone%' => $parentPhone,
  84. '%parent_email%' => $parentMail,
  85. '%birthday_price%' => $totalPrice,
  86. '%birthday_supplements%' => $birthdaySupplements,
  87. '%birthday_to_paid%' => $toPaid,
  88. '%birthday_finished%' => $closedOn,
  89. '%birthday_finished_by%' => $closedBy
  90. ];
  91.  
  92. $content = str_ireplace(array_keys($values), array_values($values), $birthdayContractTemplate);
  93.  
  94. $pdf = new Pdf($content,
  95. ['commandOptions' =>
  96. [
  97. 'useExec' => false,
  98. 'escapeArgs' => false,
  99. 'procOptions' => array(
  100. // This will bypass the cmd.exe which seems to be recommended on Windows
  101. 'bypass_shell' => true,
  102. // Also worth a try if you get unexplainable errors
  103. 'suppress_errors' => true,
  104. ),
  105. ]
  106. ]);
  107.  
  108. $pdf->setOptions(array(
  109. 'footer-font-size' => 8,
  110. 'footer-font-name' => 'Cambria',
  111. 'footer-html' => Constants::BIRTHDAY_CONTRACT_FOOTER
  112. ));
  113.  
  114.  
  115. if (!$pdf->saveAs(Constants::BIRTHDAY_CONTRACT_STORAGE . $pdfName)) {
  116. echo $pdf->getError();
  117. return null;
  118. }
  119.  
  120. return $pdfName;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment