ソースを参照

Add invoices page; factorise document tables

Alan Lam 3 年 前
親
コミット
bb61d7ee04
7 ファイル変更、127 行追加、187 行削除
  1. 0 36
      controllers/arus.php
  2. 66 0
      controllers/documents.php
  3. 0 36
      controllers/goods_in.php
  4. 1 2
      routes/default.php
  5. 0 99
      views/arus.php
  6. 59 14
      views/documents.php
  7. 1 0
      views/header.php

+ 0 - 36
controllers/arus.php

@@ -1,36 +0,0 @@
-<?php /** @noinspection PhpUnhandledExceptionInspection */
-
-namespace App;
-
-use App\Enums\DocumentTypes;
-
-$core = Core::getInstance();
-
-$user = $core->getUser();
-$user->requireAdmin();
-
-$core->addBreadcrumb("/arus", __("ARUs"));
-
-$nvp = [
-	"type" => DocumentTypes::ADVANCE_REPLACEMENT_UNIT,
-	"dts_deleted" => null
-];
-
-$count = Document::count($nvp);
-
-$pagination = new Pagination($count);
-$pagination->setTerms(__("%s ARU"), __("%s ARUs"));
-
-$documents = Document::query($nvp, [
-	"sort" => "id",
-	"order" => "desc",
-	"offset" => $pagination->getOffset(),
-	"limit" => $pagination->getPageSize()
-]);
-
-$core->addScript("/js/new-document-modal.js");
-
-View::include("header");
-View::include("arus", compact("documents", "pagination"));
-View::include("modals/new_document");
-View::include("footer");

+ 66 - 0
controllers/documents.php

@@ -0,0 +1,66 @@
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+
+namespace App;
+
+/**
+ * @var string $type_string
+ */
+
+use App\Enums\DocumentTypes;
+use RuntimeException;
+
+$core = Core::getInstance();
+
+$user = $core->getUser();
+$user->requireAdmin();
+
+switch($type_string) {
+	case "invoices":
+		$title = __("Invoices");
+		$type = DocumentTypes::INVOICE;
+		$singular = __("%s invoice");
+		$plural = __("%s invoices");
+		break;
+	case "goods-in":
+		$title = __("Goods-In");
+		$type = DocumentTypes::GOODS_IN;
+		$singular = __("%s goods-in documents");
+		$plural = __("%s goods-in documents");
+		break;
+	case "arus":
+		$title = __("ARUs");
+		$type = DocumentTypes::ADVANCE_REPLACEMENT_UNIT;
+		$singular = __("%s ARU");
+		$plural = __("%s ARUs");
+		break;
+	default:
+		throw new RuntimeException(__("Invalid type string."));
+}
+
+$core->addBreadcrumb("/$type_string", $title);
+
+$type_name = DocumentTypes::enumToText($type);
+
+$nvp = [
+	"type" => $type,
+	"dts_deleted" => null
+];
+
+$count = Document::count($nvp);
+
+$pagination = new Pagination($count);
+$pagination->setTerms($singular, $plural);
+
+$documents = Document::query($nvp, [
+	"sort" => "id",
+	"order" => "desc",
+	"offset" => $pagination->getOffset(),
+	"limit" => $pagination->getPageSize()
+]);
+
+$core->addScript("/js/new-document-modal.js");
+
+View::include("header");
+View::include("documents", compact("title", "type", "documents", "pagination", "type_name"));
+View::include("modals/new_document");
+View::include("footer");

+ 0 - 36
controllers/goods_in.php

@@ -1,36 +0,0 @@
-<?php /** @noinspection PhpUnhandledExceptionInspection */
-
-namespace App;
-
-use App\Enums\DocumentTypes;
-
-$core = Core::getInstance();
-
-$user = $core->getUser();
-$user->requireAdmin();
-
-$core->addBreadcrumb("/goods-in", __("Goods-In"));
-
-$nvp = [
-	"type" => DocumentTypes::GOODS_IN,
-	"dts_deleted" => null
-];
-
-$count = Document::count($nvp);
-
-$pagination = new Pagination($count);
-$pagination->setTerms(__("%s Goods-In"), __("%s Goods-In"));
-
-$documents = Document::query($nvp, [
-	"sort" => "id",
-	"order" => "desc",
-	"offset" => $pagination->getOffset(),
-	"limit" => $pagination->getPageSize()
-]);
-
-$core->addScript("/js/new-document-modal.js");
-
-View::include("header");
-View::include("goods_in", compact("documents", "pagination"));
-View::include("modals/new_document");
-View::include("footer");

+ 1 - 2
routes/default.php

@@ -62,8 +62,7 @@ $this->addRoute("/^tickets\/(\d+)$/", "ticket", ["id"], ["requireUser" => true])
 
 $this->addRoute("/^(goods-in|arus)\/(create)$/", "document", ["document_type_string", "action"], ["requireUser" => true]);
 
-$this->addRoute("/^goods-in$/", "goods_in", [], ["requireUser" => true]);
-$this->addRoute("/^arus$/", "arus", [], ["requireUser" => true]);
+$this->addRoute("/^(goods-in|arus|invoices)$/", "documents", ["type_string"], ["requireUser" => true]);
 
 $this->addRoute("/^(goods-in|arus)\/(\d+)$/", "document", ["document_type_string", "document_number"], ["requireUser" => true]);
 $this->addRoute("/^(goods-in|arus)\/(\d+)\/(submit|submit-item|delete-item|items-batch-action|download-pdf)$/", "document", ["document_type_string", "document_number", "action"], ["requireUser" => true]);

+ 0 - 99
views/arus.php

@@ -1,99 +0,0 @@
-<?php /** @noinspection PhpUnhandledExceptionInspection */
-
-namespace App;
-
-use App\Enums\DocumentTypes;
-
-/**
- * @var Document[] $documents
- * @var Pagination $pagination
- */
-
-?>
-<div class="row mb-3">
-	<div class="col">
-		<h3><?=htmlspecialchars(__("ARUs"))?></h3>
-	</div>
-	<div class="col-auto">
-		<a class="btn btn-success" data-bs-toggle="modal" data-bs-target="#new-document-modal" data-type="<?=DocumentTypes::ADVANCE_REPLACEMENT_UNIT?>">
-			<i class="fa fa-fw fa-plus"></i>
-			<?=htmlspecialchars(__("Add"))?>
-		</a>
-	</div>
-</div>
-
-<?php
-
-if(empty($documents)) {
-	?>
-	<div class="alert alert-info">
-		<i class="fa fa-fw fa-info-circle"></i>
-		<?=htmlspecialchars(__("No ARU documents to display."))?>
-	</div>
-	<?php
-}
-else {
-	?>
-	<table class="table table-bordered table-hover mb-3">
-		<thead>
-		<tr>
-			<th><?=htmlspecialchars(__("Number"))?></th>
-			<th><?=htmlspecialchars(__("Location"))?></th>
-			<th><?=htmlspecialchars(__("Status"))?></th>
-			<th><?=htmlspecialchars(__("Items"))?></th>
-			<th><?=htmlspecialchars(__("Actions"))?></th>
-		</tr>
-		</thead>
-		<tbody>
-		<?php
-		foreach($documents as $document) {
-			$location = $document->getLocation();
-			?>
-			<tr>
-				<td class="text-end">
-					<?=htmlspecialchars($document->number)?>
-				</td>
-				<td>
-					<a href="<?=htmlspecialchars($location->getUrl())?>">
-						<?=htmlspecialchars($location->getDisplayName())?>
-					</a>
-				</td>
-				<td>
-					<?=htmlspecialchars($document->getDisplayAruStatus())?>
-				</td>
-				<td>
-					<ul class="list-unstyled mb-0">
-						<?php
-						foreach($document->getItems() as $item) {
-							?>
-							<li>
-								<?=htmlspecialchars($item->description)?> &times; <?=$item->quantity?>
-								<?php
-								if($item->serial_number) {
-									?>
-									<span class="text-muted">
-										(S/N: <?=htmlspecialchars($item->serial_number)?>)
-									</span>
-									<?php
-								}
-								?>
-							</li>
-							<?php
-						}
-						?>
-					</ul>
-				</td>
-				<td class="p-1">
-					<a class="btn btn-sm btn-primary" href="<?=htmlspecialchars($document->getUrl())?>">
-						<?=htmlspecialchars(__("View"))?>
-					</a>
-				</td>
-			</tr>
-			<?php
-		}
-		?>
-		</tbody>
-	</table>
-	<?php
-	$pagination->render();
-}

+ 59 - 14
views/goods_in.php → views/documents.php

@@ -5,21 +5,33 @@ namespace App;
 use App\Enums\DocumentTypes;
 
 /**
+ * @var string $title
+ * @var int $type
  * @var Document[] $documents
  * @var Pagination $pagination
  */
 
+$is_invoice = ($type === DocumentTypes::INVOICE);
+$is_goods_in = ($type === DocumentTypes::GOODS_IN);
+$is_aru = ($type === DocumentTypes::ADVANCE_REPLACEMENT_UNIT);
+
 ?>
 <div class="row mb-3">
 	<div class="col">
-		<h3><?=htmlspecialchars(__("Goods-In"))?></h3>
-	</div>
-	<div class="col-auto">
-		<a class="btn btn-success" data-bs-toggle="modal" data-bs-target="#new-document-modal" data-type="<?=DocumentTypes::GOODS_IN?>">
-			<i class="fa fa-fw fa-plus"></i>
-			<?=htmlspecialchars(__("Add"))?>
-		</a>
+		<h3><?=htmlspecialchars($title)?></h3>
 	</div>
+	<?php
+	if($is_goods_in || $is_aru) {
+		?>
+		<div class="col-auto">
+			<a class="btn btn-success" data-bs-toggle="modal" data-bs-target="#new-document-modal" data-type="<?=$type?>">
+				<i class="fa fa-fw fa-plus"></i>
+				<?=htmlspecialchars(__("Add"))?>
+			</a>
+		</div>
+		<?php
+	}
+	?>
 </div>
 
 <?php
@@ -28,7 +40,7 @@ if(empty($documents)) {
 	?>
 	<div class="alert alert-info">
 		<i class="fa fa-fw fa-info-circle"></i>
-		<?=htmlspecialchars(__("No goods-in documents to display."))?>
+		<?=htmlspecialchars(__("No documents to display."))?>
 	</div>
 	<?php
 }
@@ -38,7 +50,20 @@ else {
 		<thead>
 		<tr>
 			<th><?=htmlspecialchars(__("Number"))?></th>
-			<th><?=htmlspecialchars(__("Supplier / Location"))?></th>
+			<?php
+			if($is_goods_in) {
+				?>
+				<th><?=htmlspecialchars(__("Location / Supplier"))?></th>
+				<?php
+			}
+			else {
+				?>
+				<th><?=htmlspecialchars(__("Location"))?></th>
+				<th><?=htmlspecialchars(__("Status"))?></th>
+				<?php
+			}
+			?>
+
 			<th><?=htmlspecialchars(__("Items"))?></th>
 			<th><?=htmlspecialchars(__("Actions"))?></th>
 		</tr>
@@ -57,18 +82,38 @@ else {
 					<?php
 					if($location) {
 						?>
-						<a href="<?=htmlspecialchars($location->getUrl())?>"><?=htmlspecialchars($location->getDisplayName())?></a>
-						<i class="fa fa-fw fa-shop"></i>
+						<a href="<?=htmlspecialchars($location->getUrl())?>">
+							<?=htmlspecialchars($location->getDisplayName())?>
+						</a>
 						<?php
 					}
-					else if($supplier) {
+					if($supplier) {
 						?>
-						<a href="<?=htmlspecialchars($supplier->getUrl())?>"><?=htmlspecialchars($supplier->name)?></a>
-						<i class="fa fa-fw fa-truck"></i>
+						<a href="<?=htmlspecialchars($supplier->getUrl())?>">
+							<?=htmlspecialchars($supplier->name)?>
+						</a>
 						<?php
 					}
 					?>
 				</td>
+				<?php
+				if(!$is_goods_in) {
+					if($is_invoice) {
+						?>
+						<td>
+							<?=htmlspecialchars($document->getDisplayInvoiceStatus())?>
+						</td>
+						<?php
+					}
+					else {
+						?>
+						<td>
+							<?=htmlspecialchars($document->getDisplayAruStatus())?>
+						</td>
+						<?php
+					}
+				}
+				?>
 				<td>
 					<ul class="list-unstyled mb-0">
 						<?php

+ 1 - 0
views/header.php

@@ -102,6 +102,7 @@ $google_api_key = $_ENV["GOOGLE_API_KEY"] ?? null;
 						<a class="list-group-item list-group-item-action" href="/sales"><?=htmlspecialchars(__("Sales"))?></a>
 						<a class="list-group-item list-group-item-action" href="/goods-in"><?=htmlspecialchars(__("Goods-In"))?></a>
 						<a class="list-group-item list-group-item-action" href="/arus"><?=htmlspecialchars(__("ARUs"))?></a>
+						<a class="list-group-item list-group-item-action" href="/invoices"><?=htmlspecialchars(__("Invoices"))?></a>
 					</div>
 				</div>