1
0

projects.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. use Carbon\CarbonImmutable;
  3. Core::addBreadcrumb("/account", "Account");
  4. Core::addBreadcrumb("/account/projects", "Projects");
  5. Core::addScript("public/js/app-projects.js");
  6. Core::$allow_all_customers = true;
  7. $customer_id = http::value("customer_id");
  8. if(Core::$user->isAdmin() && $customer_id === "ALL") {
  9. $page_title = "All Projects";
  10. Core::addBreadcrumb("/account/projects?customer_id=ALL", $page_title);
  11. $nvp = [];
  12. $customer = new Customer();
  13. $customer->id = "ALL";
  14. $customer->name = "All";
  15. }
  16. else {
  17. $customer = Customer::getForAdmin();
  18. $page_title = "$customer->name Projects";
  19. Core::addBreadcrumb("/account/projects?customer_id=$customer->id", $page_title);
  20. $nvp = ["customer_id" => $customer->id];
  21. }
  22. $id = http::value("id", "int");
  23. if($id) {
  24. $nvp["id"] = $id;
  25. }
  26. $name = http::value("name", "trim");
  27. if($name) {
  28. $nvp["name"] = (new Constraint("CONTAINS"))->setValues($name);
  29. }
  30. $year = http::value("year", "int");
  31. $month = http::value("month", "int");
  32. if($year === false) {
  33. $year = date("Y");
  34. }
  35. if($year && $month) {
  36. $dt_min = CarbonImmutable::now()->setYear($year)->setMonth($month)->startOfMonth();
  37. $dt_max = $dt_min->endOfMonth();
  38. $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues((string) $dt_min, (string) $dt_max);
  39. }
  40. else if($year) {
  41. $min_dts = "{$year}-01-01 00:00:00";
  42. $max_dts = "{$year}-12-31 23:59:59";
  43. $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($min_dts, $max_dts);
  44. }
  45. $report_month = http::value("report_month", "db");
  46. if($report_month) {
  47. $nvp["dts_report"] = (new Constraint("BEGINS_WITH"))->setValues($report_month);
  48. }
  49. $finished = http::value("finished", "int");
  50. if($finished !== null) {
  51. $nvp["dts_finished"] = $finished ? Constraint::isNotNull() : null;
  52. }
  53. $projects = Project::query($nvp, ["sort" => "dts_start", "order" => "desc"]);
  54. $templates = Template::load(array_column($projects, "template_id"));
  55. $filter_count = count($nvp);
  56. View::includeOnce("header", compact("page_title"));
  57. View::include("projects", compact("customer", "filter_count", "projects", "year", "month", "report_month", "finished"));
  58. View::includeOnce("footer");