project_account_csv.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var Template $template
  4. * @var object[] $fields
  5. * @var resource $handle
  6. * @var Test[] $tests
  7. * @var Constraint $year_cycle_constraint
  8. */
  9. $config = $template->getConfiguration();
  10. $field_names = [
  11. "Internal ID",
  12. "Location Name",
  13. "Division",
  14. "Template Name",
  15. "Date",
  16. "Test ID",
  17. "Test Cost",
  18. "Bar Cost",
  19. "Test + Bar Cost",
  20. ];
  21. fputcsv($handle, $field_names);
  22. foreach($tests as $test) {
  23. $location = $test->getLocation();
  24. $project = $test->getProject();
  25. $values = $test->getValues(true);
  26. $test_cost = $test->getCustomerFee();
  27. $bar_cost = bcadd($values["bar_expenditure"] ?? "0.00", 0, 2);
  28. $test_and_bar_cost = bcadd($test_cost, $bar_cost, 2);
  29. $dt_start = $test->getDateTimeStart();
  30. $output = [];
  31. $output[] = $location->internal_id;
  32. $output[] = $location->name;
  33. $output[] = $location->brand;
  34. $output[] = $template->name;
  35. $output[] = $dt_start ? $dt_start->format("d/m/Y") : "";
  36. $output[] = $test->id;
  37. $output[] = $test_cost;
  38. $output[] = $bar_cost;
  39. $output[] = $test_and_bar_cost;
  40. fputcsv($handle, $output);
  41. }