test.php 19 KB

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