project_quickbooks_csv.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. $utc_timezone = new DateTimeZone("UTC");
  3. $invoice_interval = new DateInterval("P30D");
  4. $field_names = [
  5. "BillNo",
  6. "Supplier",
  7. "BillDate",
  8. "DueDate",
  9. "Terms",
  10. "Location",
  11. "Memo",
  12. "Account",
  13. "LineDescription",
  14. "LineAmount",
  15. "LineTaxCode",
  16. "LineTaxAmount",
  17. ];
  18. fputcsv($handle, $field_names);
  19. foreach($tests as $test) {
  20. if($test->dts_tester_invoice_paid === null) continue;
  21. $project = $test->getProject();
  22. $template = $project->getTemplate();
  23. $location = $test->getLocation();
  24. $tester = $test->getTester();
  25. $values = $test->getValues(true);
  26. $test_cost = $test->test_fee > 0 ? $test->test_fee : $project->default_tester_fee;
  27. $travel_costs = $test->test_travel_cost > 0 ? $test->test_travel_cost : 0;
  28. $other_costs = $template->getTesterInvoiceCosts($values);
  29. $total_cost = $test_cost + $travel_costs + $other_costs;
  30. $invoice_generated_dt = new DateTime($test->dts_tester_invoice_generated, $utc_timezone);
  31. $invoice_date = $invoice_generated_dt->format("d/m/Y");
  32. $invoice_generated_dt->add($invoice_interval);
  33. $invoice_due_date = $invoice_generated_dt->format("d/m/Y");
  34. $output = [];
  35. $output[] = $test->getTesterInvoiceReference();
  36. $output[] = sprintf("%d %s %s", $tester->id, $tester->first_name, $tester->last_name);
  37. $output[] = $invoice_date;
  38. $output[] = $invoice_due_date;
  39. $output[] = "Net 30";
  40. $output[] = $location->id;
  41. $output[] = "";
  42. $output[] = "Tester Fees";
  43. $output[] = "";
  44. $output[] = $total_cost;
  45. $output[] = "No VAT";
  46. $output[] = "0";
  47. fputcsv($handle, $output);
  48. }