test.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <?php /** @noinspection HtmlDeprecatedTag */
  2. /** @noinspection HtmlDeprecatedAttribute */
  3. use Mpdf\Mpdf;
  4. /**
  5. * @property int $id
  6. * @property int $project_id
  7. * @property int $location_id
  8. * @property int $tester_id
  9. * @property int $status
  10. * @property int $status_tester_invoice
  11. * @property float $customer_fee
  12. * @property float $test_fee
  13. * @property string $test_time
  14. * @property float $test_travel_cost
  15. * @property string $shop_left
  16. * @property string $shop_right
  17. * @property string $attire
  18. * @property int $challenge_stage
  19. * @property string $challenge_description
  20. * @property string $challenger_name
  21. * @property string $challenger_description
  22. * @property string $challenger_gender
  23. * @property string $challenger_eye_contact
  24. * @property string $additional_notes
  25. * @property string $dts_due
  26. * @property string $dts_start
  27. * @property string $dts_end
  28. * @property string $dts_tester_invoice_generated
  29. * @property string $dts_tester_invoice_paid
  30. * @property int $verifier_id
  31. * @property string $verifier_notes
  32. * @property bool $pass
  33. * @property bool $retest
  34. * @property string $dts_created
  35. * @property string $dts_updated
  36. * @property string $dts_assigned
  37. * @property string $dts_verified
  38. */
  39. class Test extends Model {
  40. protected static $table = "test";
  41. protected static $id_field = "id";
  42. protected static $fillable_fields = ["project_id", "location_id", "tester_id", "status", "status_tester_invoice", "customer_fee", "test_fee", "test_time", "test_travel_cost", "shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes", "dts_due", "dts_start", "dts_end", "dts_tester_invoice_generated", "dts_tester_invoice_paid", "verifier_id", "verifier_notes", "pass", "retest", "dts_created", "dts_updated", "dts_assigned", "dts_verified"];
  43. const TEST_FIELDS = ["shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes"];
  44. // Constants
  45. const STATUS_CANCELLED = 0;
  46. const STATUS_UNASSIGNED = 1; // Location needs a tester
  47. const STATUS_ASSIGNED = 2; // Tester assigned
  48. const STATUS_CONFIRMED = 3; // Tester has said they can do it
  49. const STATUS_STARTED = 4;
  50. const STATUS_PENDING_VERIFICATION = 8;
  51. const STATUS_COMPLETED = 16;
  52. const STATUS_TESTER_INVOICE_NONE = 0;
  53. const STATUS_TESTER_INVOICE_PENDING = 100;
  54. const STATUS_TESTER_INVOICE_PAID = 200;
  55. const STATUSES = [
  56. 0 => "Cancelled",
  57. 1 => "Unassigned",
  58. 2 => "Assigned",
  59. 3 => "Confirmed",
  60. 4 => "Started",
  61. 8 => "Pending Verification",
  62. 16 => "Completed",
  63. ];
  64. const STATUSES_TESTER_INVOICE = [
  65. Test::STATUS_TESTER_INVOICE_NONE,
  66. Test::STATUS_TESTER_INVOICE_PENDING,
  67. Test::STATUS_TESTER_INVOICE_PAID
  68. ];
  69. const STAGES = [
  70. 0 => "",
  71. 1 => "Challenge on entry",
  72. 2 => "Challenge while browsing",
  73. 3 => "Challenge during play",
  74. 4 => "Challenge on exit",
  75. 5 => "No challenge",
  76. ];
  77. const TEST_TIME_ANYTIME = 1;
  78. const TEST_TIME_DAY = 2;
  79. const TEST_TIME_NIGHT = 3;
  80. // Static methods
  81. /**
  82. * @param int $status
  83. * @return string
  84. */
  85. public static function getStatusTesterInvoiceText(int $status): string {
  86. switch($status) {
  87. case Test::STATUS_TESTER_INVOICE_NONE:
  88. return __("No Invoice Generated");
  89. case Test::STATUS_TESTER_INVOICE_PENDING:
  90. return __("Pending Payment");
  91. case Test::STATUS_TESTER_INVOICE_PAID:
  92. return __("Paid");
  93. }
  94. return __("Unknown");
  95. }
  96. /**
  97. * @param int $status
  98. * @return string
  99. */
  100. public static function getStatusTesterInvoiceClass(int $status): string {
  101. switch($status) {
  102. case Test::STATUS_TESTER_INVOICE_NONE:
  103. return "secondary";
  104. case Test::STATUS_TESTER_INVOICE_PENDING:
  105. return "warning";
  106. case Test::STATUS_TESTER_INVOICE_PAID:
  107. return "success";
  108. }
  109. return "";
  110. }
  111. /**
  112. * @param string $processing_file
  113. * @param array $tests
  114. * @throws Exception
  115. */
  116. public static function exportCSV(string $processing_file, array $tests = []): void {
  117. // Preload
  118. Project::load(array_column($tests, "project_id"));
  119. Location::load(array_column($tests, "location_id"));
  120. User::load(array_column($tests, "tester_id"));
  121. // Get processing file
  122. $processing_file_path = ROOT_DIR . "/export_processing/{$processing_file}";
  123. if(!file_exists($processing_file_path)) throw new Exception("Processing file not found.");
  124. // Output
  125. HTTP::setDownloadHeaders("export.csv");
  126. $handle = fopen("php://output", "w");
  127. require $processing_file_path;
  128. fclose($handle);
  129. }
  130. // Object methods
  131. /**
  132. * @param string $message
  133. * @return bool
  134. * @throws Exception
  135. */
  136. public function sendAssignEmail(string $message): bool {
  137. $tester = $this->getTester();
  138. $location = $this->getLocation();
  139. $project = $this->getProject();
  140. // Content
  141. $name = htmlspecialchars($tester->first_name);
  142. $message = htmlspecialchars($message);
  143. $base_url = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/account/tests/" . $this->id);
  144. $address = htmlspecialchars($location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code"]));
  145. $date_due = date("j M Y", strtotime($this->dts_due));
  146. $admin_first_name = htmlspecialchars(Core::$user->first_name);
  147. $admin_phone = htmlspecialchars(Core::$user->phone);
  148. // Build
  149. $builder = new EmailBuilder;
  150. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  151. $builder->addLeadParagraph(__("Congrats, you have been allocated a test!"));
  152. if($project->isNighttime()) {
  153. $builder->addParagraph("<b><font color=\"red\">" . __("Evening Test to be done between 7PM and midnight.") . "</font></b>");
  154. }
  155. if($message) {
  156. $builder->addParagraph($message);
  157. }
  158. $builder->addParagraph(sprintf(__("We need you to confirm if you are able to do the test. Please check the details below and then confirm by pressing the %sAccept%s or %sDecline%s buttons and once you tap %sAccept%s, the test will be allocated to you."),
  159. '<b>', '</b>',
  160. '<b>', '</b>',
  161. '<b>', '</b>'
  162. ));
  163. $builder->addAcceptDeclineButtons($base_url);
  164. $builder->addParagraph(sprintf(__("The site address is: %s"), "<b>{$address}</b>"));
  165. $builder->addParagraph(sprintf(__("The date that need to complete and submit the results by is: %s"), "<font color=\"red\"><b>$date_due</b></font>"));
  166. $builder->addParagraph(sprintf(__("For methodology and further notes please check the %sUseful Documents%s section on the %sAccount%s page."),
  167. '<b>', '</b>',
  168. '<b>', '</b>'
  169. ));
  170. $builder->addParagraph(sprintf(__("If you agree to conduct the test, log in and then go to %sTests%s where you will be able to see the tests available to you. Please tap the %sBegin%s button and follow the instructions that is shown."),
  171. '<b>', '</b>',
  172. '<b>', '</b>'
  173. ));
  174. $builder->addParagraph(sprintf(__("If you have any questions please send them to %s or call %s on %s."),
  175. "<a href=\"mailto:tests@check-policy.com\">tests@check-policy.com</a>",
  176. "<b>$admin_first_name</b>",
  177. "<b>$admin_phone</b>"
  178. ));
  179. $builder->addParagraph(sprintf(__("If you are unable to submit the results via the web-based app please contact us and we can send you an offline form to complete. Please accept the test by tapping the %sAccept%s button and email us back saying you would like an offline form."),
  180. '<b>', '</b>'
  181. ));
  182. $content = $builder->build();
  183. // Send
  184. $mail = new Email;
  185. $mail->setHtmlContent($content);
  186. $mail->setFrom(EMAIL_CONTACT, EMAIL_FROM_NAME);
  187. $mail->addAddress($tester->email, $tester->getDisplayName());
  188. $mail->setSubject(__("You have been allocated a test"));
  189. $mail->send();
  190. return true;
  191. }
  192. /**
  193. * @return bool
  194. * @throws Exception
  195. */
  196. public function sendClaimedEmail(): bool {
  197. $tester = $this->getTester();
  198. $location = $this->getLocation();
  199. $project = $this->getProject();
  200. // Content
  201. $name = htmlspecialchars($tester->first_name);
  202. $address = htmlspecialchars($location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code"]));
  203. $date_due = date("j M Y", strtotime($this->dts_due));
  204. // Build
  205. $builder = new EmailBuilder;
  206. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  207. $builder->addLeadParagraph(__("Congrats, you have claimed a test!"));
  208. if($project->isNighttime()) {
  209. $builder->addParagraph("<b><font color=\"red\">" . __("Evening Test to be done between 7PM and midnight.") . "</font></b>");
  210. }
  211. $builder->addParagraph(sprintf(__("The site address is: %s"), "<b>$address</b>"));
  212. $builder->addParagraph(sprintf(__("The date that need to complete and submit the results by is: %s"), "<font color=\"red\"><b>$date_due</b></font>"));
  213. $builder->addParagraph(sprintf(__("For methodology and further notes please check the %sUseful Documents%s section on the %sAccount%s page."),
  214. '<b>', '</b>',
  215. '<b>', '</b>'
  216. ));
  217. $builder->addParagraph(sprintf(__("Log in and then go to %sTests%s where you will be able to see the tests available to you. Please tap the %sBegin%s button and follow the instructions that is shown."),
  218. '<b>', '</b>',
  219. '<b>', '</b>'
  220. ));
  221. $builder->addParagraph(sprintf(__("If you have any questions please send them to %s."),
  222. "<a href=\"mailto:tests@check-policy.com\">tests@check-policy.com</a>"
  223. ));
  224. $builder->addParagraph(__("If you are unable to submit the results via the web-based app please contact us and we can send you an offline form to complete."));
  225. $content = $builder->build();
  226. // Send
  227. $mail = new Email;
  228. $mail->setHtmlContent($content);
  229. $mail->setFrom(EMAIL_CONTACT, EMAIL_FROM_NAME);
  230. $mail->addAddress($tester->email, $tester->getDisplayName());
  231. $mail->setSubject(__("You have claimed a test"));
  232. $mail->send();
  233. return true;
  234. }
  235. /**
  236. * @return bool
  237. * @throws Exception
  238. */
  239. public function sendDeclineEmail(): bool {
  240. $tester = $this->getTester();
  241. $location = $this->getLocation();
  242. $project = $this->getProject();
  243. // Content
  244. $name = htmlspecialchars($tester->getDisplayName());
  245. $address = htmlspecialchars($location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code"]));
  246. $project_name = htmlspecialchars($project->name);
  247. $project_url = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/account/projects/" . $project->id);
  248. $internal_id = "N/A";
  249. if($location->internal_id) $internal_id = htmlspecialchars($location->internal_id);
  250. // Build
  251. $builder = new EmailBuilder;
  252. $builder->addParagraph("<b>Hi,</b>");
  253. $builder->addLeadParagraph("A tester has declined a test.");
  254. $builder->addParagraph("<b>Project:</b><br />$project_name");
  255. $builder->addParagraph("<b>Site:</b><br />$address<br />ID: $location->id | Internal ID: $internal_id");
  256. $builder->addParagraph("<b>Who:</b><br />$name<br />ID: $tester->id");
  257. $builder->addParagraph("<a href=\"$project_url\">Click here</a> to manage the project and reassign the test.");
  258. $content = $builder->build();
  259. // Send
  260. $mail = new Email;
  261. $mail->setHtmlContent($content);
  262. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  263. $mail->addAddress(EMAIL_CONTACT, APP_NAME . " Contact");
  264. $mail->setSubject("Test declined: $project->name / $location->name");
  265. $mail->send();
  266. return true;
  267. }
  268. /**
  269. * @param string $to_address
  270. * @return bool
  271. * @throws Exception
  272. */
  273. public function sendResultEmail(string $to_address): bool {
  274. $location = $this->getLocation();
  275. $project = $this->getProject();
  276. $template = $project->getTemplate();
  277. $subject_format_file_path = $template->getProcessingFilePath("result_email_subject_format.txt");
  278. $subject_format = file_get_contents($subject_format_file_path);
  279. // Content
  280. $pass_text = strtoupper($this->getPassText());
  281. $stage = $this->challenge_stage;
  282. $location_parts = [$location->internal_id, $location->name];
  283. $location_string = implode(" : ", array_filter($location_parts));
  284. $unix_start = strtotime($this->dts_start . " UTC");
  285. $date_time = date("d/m/Y H:i", $unix_start);
  286. // Subject
  287. $search_replace = [
  288. "{pass}" => $pass_text,
  289. "{stage}" => $stage,
  290. "{location}" => $location_string,
  291. "{date-time}" => $date_time,
  292. ];
  293. $subject = str_replace(
  294. array_keys($search_replace),
  295. array_values($search_replace),
  296. $subject_format
  297. );
  298. // Attachments
  299. $pdf_path = $this->getDirectory() . "/pdf.pdf";
  300. $pdf_name = implode(" - ", array_filter([$location->internal_id, date("jS M Y")])) . ".pdf";
  301. // Lead paragraph
  302. $lead_paragraph = "";
  303. if($this->pass) {
  304. $lead_paragraph .= "Congratulations!<br />";
  305. }
  306. $lead_paragraph .= "A test has been completed at your location.";
  307. // Build
  308. $builder = new EmailBuilder;
  309. $builder->addLeadParagraph($lead_paragraph);
  310. $builder->addParagraph("Please see attached PDF and do not hesitate to contact us if you have any questions.");
  311. $content = $builder->build();
  312. // Send
  313. $mail = new Email;
  314. $mail->setHtmlContent($content);
  315. $mail->setFrom(EMAIL_CONTACT, EMAIL_FROM_NAME);
  316. $mail->addAddress($to_address);
  317. $mail->addAttachment($pdf_path, $pdf_name);
  318. $mail->setSubject($subject);
  319. $mail->send();
  320. return true;
  321. }
  322. /**
  323. * @return bool
  324. * @throws Exception
  325. */
  326. public function decline(): bool {
  327. $this->sendDeclineEmail();
  328. $this->status = Test::STATUS_UNASSIGNED;
  329. $this->tester_id = null;
  330. $this->dts_due = null;
  331. $this->dts_assigned = null;
  332. $this->dts_updated = Util::getDateTime();
  333. return $this->commit();
  334. }
  335. /**
  336. * @return string
  337. */
  338. public function getChallengeStageText(): string {
  339. if(is_null($this->challenge_stage)) return "";
  340. return Test::STAGES[$this->challenge_stage];
  341. }
  342. /**
  343. * @return string
  344. */
  345. public function getStatusText(): string {
  346. return Test::STATUSES[$this->status];
  347. }
  348. /**
  349. * @return string
  350. */
  351. public function getStatusClass(): string {
  352. switch($this->status) {
  353. case Test::STATUS_CANCELLED:
  354. return "secondary";
  355. case Test::STATUS_UNASSIGNED:
  356. return "danger";
  357. case Test::STATUS_ASSIGNED:
  358. case Test::STATUS_CONFIRMED:
  359. case Test::STATUS_STARTED:
  360. return "warning";
  361. case Test::STATUS_PENDING_VERIFICATION:
  362. return "primary";
  363. case Test::STATUS_COMPLETED:
  364. return "success";
  365. }
  366. return "";
  367. }
  368. /**
  369. * @return Project|null
  370. * @throws Exception
  371. */
  372. public function getProject(): ?Project {
  373. return Project::get($this->project_id);
  374. }
  375. /**
  376. * @return Location
  377. * @throws Exception
  378. */
  379. public function getLocation(): ?Location {
  380. return Location::get($this->location_id);
  381. }
  382. /**
  383. * @return User
  384. * @throws Exception
  385. */
  386. public function getTester(): ?User {
  387. return User::get($this->tester_id);
  388. }
  389. /**
  390. * @return User
  391. * @throws Exception
  392. */
  393. public function getVerifier(): ?User {
  394. return User::get($this->verifier_id);
  395. }
  396. /**
  397. * @param bool $as_assoc_array
  398. * @return array
  399. * @throws Exception
  400. */
  401. public function getValues(bool $as_assoc_array = false): array {
  402. $rows = TestValue::query(["test_id" => $this->id]);
  403. if($as_assoc_array) {
  404. $k = array_column($rows, "name");
  405. $v = array_column($rows, "value");
  406. $values = array_combine($k, $v);
  407. }
  408. else {
  409. $values = $rows;
  410. }
  411. return $values;
  412. }
  413. /**
  414. * @return string
  415. */
  416. public function getDirectory(): string {
  417. $directory = ROOT_DIR . "/files/tests/" . $this->id;
  418. if(!file_exists($directory)) mkdir($directory, 0777, true);
  419. return $directory;
  420. }
  421. /**
  422. * @return bool|float|int
  423. */
  424. public function getDuration() {
  425. if(is_null($this->dts_end)) return false;
  426. $seconds = Util::getDurationFromDTS($this->dts_start, $this->dts_end);
  427. return $seconds;
  428. }
  429. /**
  430. * @return string
  431. */
  432. public function getDisplayDuration(): string {
  433. $secs = $this->getDuration();
  434. $mins = floor($secs / 60);
  435. $secs = $secs % 60;
  436. return "$mins min. $secs sec.";
  437. }
  438. /**
  439. * @return string Bootstrap class name
  440. */
  441. public function getPassClass(): string {
  442. if(is_null($this->pass)) return "secondary";
  443. return $this->pass ? "success" : "danger";
  444. }
  445. /**
  446. * @return string FA icon name without prefix
  447. */
  448. public function getPassIcon(): string {
  449. if(is_null($this->pass)) return "clock";
  450. return $this->pass ? "check-circle" : "times-circle";
  451. }
  452. /**
  453. * @return string Pending, Pass or Fail
  454. */
  455. public function getPassText(): string {
  456. if(is_null($this->pass)) return __("Pending");
  457. return $this->pass ? __("Pass") : __("Fail");
  458. }
  459. public function getMPDF(): Mpdf {
  460. /** @var Mpdf $mpdf */
  461. $id = $this->id;
  462. $output = false;
  463. require ROOT_DIR . "/controllers/test_pdf.php";
  464. return $mpdf;
  465. }
  466. /**
  467. * @param User $tester
  468. * @return bool
  469. * @throws Exception
  470. */
  471. public function assignTester(User $tester): bool {
  472. $this->tester_id = $tester->id;
  473. $this->dts_assigned = Util::getDateTime();
  474. $success = $this->commit();
  475. // TODO: Notify tester
  476. return $success;
  477. }
  478. /**
  479. * @return Test|null
  480. * @throws Exception
  481. */
  482. public function getPreviousTest(): ?Test {
  483. $nvp = [
  484. "dts_start" => (new Constraint("LESS_THAN"))->setValues($this->dts_start),
  485. "location_id" => $this->location_id,
  486. "status" => Test::STATUS_COMPLETED,
  487. ];
  488. $tests = Test::query($nvp, [
  489. "sort" => "dts_start",
  490. "order" => "desc",
  491. ]);
  492. return $tests ? $tests[0] : null;
  493. }
  494. /**
  495. * @return bool
  496. * @throws Exception
  497. */
  498. public function unassignTester(): bool {
  499. $this->status = Test::STATUS_UNASSIGNED;
  500. $this->tester_id = null;
  501. $this->dts_due = null;
  502. $this->dts_assigned = null;
  503. return $this->commit();
  504. }
  505. /**
  506. * @return bool
  507. */
  508. public function isPass(): bool {
  509. if(is_null($this->pass)) return false;
  510. return !empty($this->pass);
  511. }
  512. /**
  513. * @return bool
  514. */
  515. public function isPending(): bool {
  516. return is_null($this->pass);
  517. }
  518. /**
  519. * @return bool
  520. */
  521. public function isFail(): bool {
  522. if(is_null($this->pass)) return false;
  523. return empty($this->pass);
  524. }
  525. /**
  526. * @return bool
  527. */
  528. public function isCompleted() {
  529. return $this->status == Test::STATUS_COMPLETED;
  530. }
  531. /**
  532. * @return bool
  533. */
  534. public function isPendingVerification() {
  535. return $this->status == Test::STATUS_PENDING_VERIFICATION;
  536. }
  537. /**
  538. * @return bool
  539. */
  540. public function hasPDF(): bool {
  541. $directory = $this->getDirectory();
  542. return file_exists($directory . "/pdf.pdf");
  543. }
  544. /**
  545. * @return string
  546. */
  547. public function getPDFUrl(): string {
  548. return "/account/tests/{$this->id}/files/pdf";
  549. }
  550. /**
  551. * @return bool
  552. */
  553. public function hasTesterInvoicePDF(): bool {
  554. $directory = $this->getDirectory();
  555. return file_exists($directory . "/tester_invoice.pdf");
  556. }
  557. /**
  558. * @return bool
  559. * @throws Exception
  560. */
  561. public function markTesterInvoicePaid(): bool {
  562. if($this->status_tester_invoice == Test::STATUS_TESTER_INVOICE_PENDING) {
  563. $this->status_tester_invoice = Test::STATUS_TESTER_INVOICE_PAID;
  564. $this->dts_tester_invoice_paid = Util::getDateTime();
  565. return $this->commit();
  566. }
  567. return false;
  568. }
  569. /**
  570. * @return bool
  571. * @throws Exception
  572. */
  573. public function rejectTesterInvoice(): bool {
  574. if($this->status_tester_invoice == Test::STATUS_TESTER_INVOICE_PENDING) {
  575. $this->status_tester_invoice = Test::STATUS_TESTER_INVOICE_NONE;
  576. $this->dts_tester_invoice_generated = null;
  577. $pdf_filepath = $this->getDirectory() . "/tester_invoice.pdf";
  578. unlink($pdf_filepath);
  579. return $this->commit();
  580. }
  581. return false;
  582. }
  583. /**
  584. * @return string
  585. * @throws Exception
  586. */
  587. public function getTesterInvoiceReference(): string {
  588. $location = $this->getLocation();
  589. $tester = $this->getTester();
  590. return
  591. "T" . str_pad($this->id, 3, "0", STR_PAD_LEFT) .
  592. "/L" . str_pad($location->id, 3, "0", STR_PAD_LEFT) .
  593. "/U" . str_pad($tester->id, 3, "0", STR_PAD_LEFT);
  594. }
  595. }