project_account_csv.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. "Template Name",
  14. "Date",
  15. "Test ID",
  16. "Test Cost",
  17. "Bar Cost",
  18. "Test + Bar Cost",
  19. ];
  20. fputcsv($handle, $field_names);
  21. foreach($tests as $test) {
  22. $location = $test->getLocation();
  23. $project = $test->getProject();
  24. $values = $test->getValues(true);
  25. $test_cost = $test->getCustomerFee();
  26. $bar_cost = bcadd($values["bar_expenditure"] ?? "0.00", 0, 2);
  27. $test_and_bar_cost = bcadd($test_cost, $bar_cost, 2);
  28. $output = [];
  29. $output[] = $location->internal_id;
  30. $output[] = $location->name;
  31. $output[] = $template->name;
  32. $output[] = $test->getDateTimeStart()->format("d/m/Y");
  33. $output[] = $test->id;
  34. $output[] = $test_cost;
  35. $output[] = $bar_cost;
  36. $output[] = $test_and_bar_cost;
  37. fputcsv($handle, $output);
  38. }