Преглед изворни кода

Add support to filter Projects by Report Month

Alan Lam пре 7 година
родитељ
комит
fa2f610c27
3 измењених фајлова са 52 додато и 2 уклоњено
  1. 7 2
      controllers/projects.php
  2. 23 0
      engine/project.php
  3. 22 0
      views/projects.php

+ 7 - 2
controllers/projects.php

@@ -1,4 +1,4 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
 
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account/projects", "Projects");
@@ -31,11 +31,13 @@ else {
 $id = http::value("id", "int");
 $name = http::value("name", "trim");
 $year = http::value("year", "int");
+$report_month = http::value("report_month", "db");
 
 if($year === false) {
 	$year = date("Y");
 }
 
+
 if($id) $nvp["id"] = $id;
 if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues($name);
 if($year) {
@@ -43,6 +45,9 @@ if($year) {
 	$max_dts = "{$year}-12-31 23:59:59";
 	$nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($min_dts, $max_dts);
 }
+if($report_month) {
+	$nvp["dts_report"] = (new Constraint("BEGINS_WITH"))->setValues($report_month);
+}
 
 $projects = Project::query($nvp, ["sort" => "dts_start", "order" => "desc"]);
 $templates = Template::load(array_column($projects, "template_id"));
@@ -50,5 +55,5 @@ $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"));
+View::include("projects", compact("customer", "filter_count", "projects", "year", "report_month"));
 View::includeOnce("footer");

+ 23 - 0
engine/project.php

@@ -58,6 +58,29 @@ class Project extends Model {
 		fclose($handle);
 	}
 
+	/**
+	 * @return string[]
+	 * @throws Exception
+	 */
+	public static function getReportMonths(): array {
+
+		$current_report_month = new DateTime("2018-01-01", new DateTimeZone("UTC"));
+
+		$month_interval = new DateInterval("P1M");
+
+		$report_months = [];
+
+		do {
+			$key = $current_report_month->format("Y-m");
+			$report_months[$key] = $current_report_month->format("M Y");
+			$current_report_month->add($month_interval);
+			$time = $current_report_month->format("U");
+			if($time > time()) break;
+		} while(true);
+
+		return $report_months;
+	}
+
 	// Object methods
 
 	/**

+ 22 - 0
views/projects.php

@@ -1,3 +1,8 @@
+<?php
+
+$report_months = array_reverse(Project::getReportMonths());
+
+?>
 <div class="container mt-3 py-4">
 
 	<div class="row">
@@ -62,6 +67,23 @@
 								</select>
 							</div>
 						</div>
+                        <div class="row mb-1">
+                            <label for="report-month" class="col-sm-4 col-form-label"><?=htmlspecialchars(__("Report Month"))?></label>
+                            <div class="col-sm">
+                                <select class="form-control" name="report_month" id="report-month">
+                                    <option value=""><?=htmlspecialchars(__("Select Report Month"))?></option>
+                                    <?php
+                                    foreach($report_months as $value => $display) {
+                                        $selected = ($value == $report_month) ? "selected" : "";
+                                        ?>
+                                        <option value="<?=$value?>" <?=$selected?>><?=$display?></option>
+                                        <?php
+                                    }
+                                    ?>
+                                </select>
+                            </div>
+
+                        </div>
 						<div class="row">
 							<div class="col-sm offset-sm-4">
 								<button class="btn btn-primary" type="submit">Submit</button>