Explorar o código

Add "Recent Sales Orders" to the entity form for locations

Alan Lam hai 1 ano
pai
achega
e3ed8d2345
Modificáronse 3 ficheiros con 47 adicións e 8 borrados
  1. 18 1
      engine/Location.php
  2. 10 1
      views/entity_form.php
  3. 19 6
      views/sale_invoices_section.php

+ 18 - 1
engine/Location.php

@@ -2,9 +2,12 @@
 
 namespace App;
 
-use App\Enums\AruStatuses;
+use App\Constraint\MoreThanOrEqualsConstraint;
+use App\Constraint\NotInConstraint;
+use App\Enums\SalesOrderStatuses;
 use App\Traits\DateTimeTrait;
 use App\Traits\SoftDeleteTrait;
+use Carbon\CarbonImmutable;
 use Exception;
 use RuntimeException;
 
@@ -164,4 +167,18 @@ class Location extends Model {
 		$customer = $this->getCustomer();
 		return sprintf("%s - %s", $customer->name, $this->name);
 	}
+
+	public function getRecentSalesOrders(): array {
+		$dt_threshold = CarbonImmutable::now($_ENV["TIMEZONE"])->subYear();
+
+		return Document::query([
+			"location_id" => $this->id,
+			"date" => new MoreThanOrEqualsConstraint($dt_threshold->toDateString()),
+			"invoice_status" => new NotInConstraint(SalesOrderStatuses::VOID, SalesOrderStatuses::UNCOLLECTIBLE),
+			"dts_deleted" => null,
+		], [
+			"sort" => "date",
+			"order" => "desc",
+		]);
+	}
 }

+ 10 - 1
views/entity_form.php

@@ -57,7 +57,7 @@ if($is_entity) {
 	</div>
 </div>
 
-<form method="post">
+<form class="mb-4" method="post">
 
 	<?php
 	$user->insertCsrfToken();
@@ -297,3 +297,12 @@ if($is_entity) {
 	</div>
 
 </form>
+
+<?php
+if($model instanceof Location) {
+	View::include("sale_invoices_section", [
+		"title" => __("Recent Sales Orders"),
+		"sales_orders" => $model->getRecentSalesOrders(),
+		"show_location_column" => false,
+	]);
+}

+ 19 - 6
views/sale_invoices_section.php

@@ -10,6 +10,7 @@ namespace App;
 use App\Helpers\HtmlHelper;
 
 $title ??= __("Sales Orders");
+$show_location_column ??= true;
 
 ?>
 
@@ -26,7 +27,13 @@ $title ??= __("Sales Orders");
 			<tr>
 				<th><?=htmlspecialchars(__("No."))?></th>
 				<th><?=htmlspecialchars(__("Date"))?></th>
-				<th><?=htmlspecialchars(__("Location"))?></th>
+				<?php
+				if($show_location_column) {
+					?>
+					<th><?=htmlspecialchars(__("Location"))?></th>
+					<?php
+				}
+				?>
 				<th><?=htmlspecialchars(__("Status"))?></th>
 				<th><?=htmlspecialchars(__("Item"))?></th>
 				<th><?=htmlspecialchars(__("S/N"))?></th>
@@ -54,11 +61,17 @@ $title ??= __("Sales Orders");
 					<td rowspan="<?=$rowspan?>">
 						<?=htmlspecialchars($sales_order->getDisplayDate())?>
 					</td>
-					<td rowspan="<?=$rowspan?>">
-						<a href="<?=htmlspecialchars($location->getUrl())?>">
-							<?=htmlspecialchars($location->name)?>
-						</a>
-					</td>
+					<?php
+					if($show_location_column) {
+						?>
+						<td rowspan="<?=$rowspan?>">
+							<a href="<?=htmlspecialchars($location->getUrl())?>">
+								<?=htmlspecialchars($location->name)?>
+							</a>
+						</td>
+						<?php
+					}
+					?>
 					<td rowspan="<?=$rowspan?>">
 						<?=htmlspecialchars($sales_order->getDisplaySalesOrderStatus())?>
 					</td>