| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- use Carbon\CarbonImmutable;
- Core::addBreadcrumb("/account", "Account");
- Core::addBreadcrumb("/account/projects", "Projects");
- Core::addScript("public/js/app-projects.js");
- Core::$allow_all_customers = true;
- $customer_id = http::value("customer_id");
- if(Core::$user->isAdmin() && $customer_id === "ALL") {
- $page_title = "All Projects";
- Core::addBreadcrumb("/account/projects?customer_id=ALL", $page_title);
- $nvp = [];
- $customer = new Customer();
- $customer->id = "ALL";
- $customer->name = "All";
- }
- else {
- $customer = Customer::getForAdmin();
- $page_title = "$customer->name Projects";
- Core::addBreadcrumb("/account/projects?customer_id=$customer->id", $page_title);
- $nvp = ["customer_id" => $customer->id];
- }
- $id = http::value("id", "int");
- if($id) {
- $nvp["id"] = $id;
- }
- $name = http::value("name", "trim");
- if($name) {
- $nvp["name"] = (new Constraint("CONTAINS"))->setValues($name);
- }
- $year = http::value("year", "int");
- $month = http::value("month", "int");
- if($year === false) {
- $year = date("Y");
- }
- if($year && $month) {
- $dt_min = CarbonImmutable::now()->setYear($year)->setMonth($month)->startOfMonth();
- $dt_max = $dt_min->endOfMonth();
- $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues((string) $dt_min, (string) $dt_max);
- }
- else if($year) {
- $min_dts = "{$year}-01-01 00:00:00";
- $max_dts = "{$year}-12-31 23:59:59";
- $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($min_dts, $max_dts);
- }
- $report_month = http::value("report_month", "db");
- if($report_month) {
- $nvp["dts_report"] = (new Constraint("BEGINS_WITH"))->setValues($report_month);
- }
- $finished = http::value("finished", "int");
- if($finished !== null) {
- $nvp["dts_finished"] = $finished ? Constraint::isNotNull() : null;
- }
- $projects = Project::query($nvp, ["sort" => "dts_start", "order" => "desc"]);
- $templates = Template::load(array_column($projects, "template_id"));
- $filter_count = count($nvp);
- View::includeOnce("header", compact("page_title"));
- View::include("projects", compact("customer", "filter_count", "projects", "year", "month", "report_month", "finished"));
- View::includeOnce("footer");
|