Просмотр исходного кода

Add ability to create Goods-In documents

Alan Lam 3 лет назад
Родитель
Сommit
87a8210ce6

+ 8 - 3
controllers/404.php

@@ -4,6 +4,11 @@ namespace App;
 
 http_response_code(404);
 
-View::include("header");
-View::include("error", ["message" => __("Page not found.")]);
-View::include("footer");
+if(Http::isAjax()) {
+	JSON::fail(__("Page not found."), 404);
+}
+else {
+	View::include("header");
+	View::include("error", ["message" => __("Page not found.")]);
+	View::include("footer");
+}

+ 9 - 3
controllers/500.php

@@ -8,6 +8,12 @@ http_response_code(500);
  * @var string $message
  */
 
-View::include("header");
-View::include("error", ["message" => $message]);
-View::include("footer");
+if(Http::isAjax()) {
+	JSON::fail($message, 500);
+}
+else {
+	View::include("header");
+	View::include("error", ["message" => $message]);
+	View::include("footer");
+}
+

+ 85 - 12
controllers/document.php

@@ -12,6 +12,7 @@ use RuntimeException;
  */
 
 $action = $action ?? null;
+$document_number = $document_number ?? null;
 
 switch($document_type_string) {
 	case "invoices":
@@ -22,6 +23,14 @@ switch($document_type_string) {
 		$document_type = DocumentTypes::DELIVERY_NOTE;
 		break;
 
+	case "goods-in":
+		$document_type = DocumentTypes::GOODS_IN;
+		break;
+
+	case "arus":
+		$document_type = DocumentTypes::ADVANCE_REPLACEMENT_UNIT;
+		break;
+
 	default:
 		throw new RuntimeException(__("Invalid document type."));
 }
@@ -32,10 +41,10 @@ $controller = new class($document_type, $document_number) {
 
 	private ?User $user;
 	private int $documentType;
-	private int $documentNumber;
+	private ?int $documentNumber;
 	private Request $request;
 
-	public function __construct(int $document_type, int $document_number) {
+	public function __construct(int $document_type, ?int $document_number) {
 		$core = Core::getInstance();
 		$this->user = $core->getUser();
 		$this->documentType = $document_type;
@@ -64,10 +73,33 @@ $controller = new class($document_type, $document_number) {
 		return $items[0];
 	}
 
+	private function requireCompany(int $id): Company {
+		$company = Company::get($id);
+		if(!$company) {
+			throw new RuntimeException(__("Company not found."));
+		}
+		return $company;
+	}
+
+	private function requireLocation(int $id): Location {
+		$location = Location::get($id);
+		if(!$location) {
+			throw new RuntimeException(__("Location not found."));
+		}
+		return $location;
+	}
+
+	private function requireSupplier(int $id): Supplier {
+		$supplier = Supplier::get($id);
+		if(!$supplier) {
+			throw new RuntimeException(__("Supplier not found."));
+		}
+		return $supplier;
+	}
+
 	public function view(): void {
 		$document = $this->requireDocument();
 
-
 		$core = Core::getInstance();
 		$this->user->requireAdmin();
 
@@ -95,6 +127,45 @@ $controller = new class($document_type, $document_number) {
 		View::include("footer");
 	}
 
+	public function create(): void {
+		$type = $this->documentType;
+		if(!DocumentTypes::validate($type)) {
+			throw new RuntimeException(__("Invalid document type."));
+		}
+
+		$supplier_id = $this->request->int("supplier_id");
+		$supplier = $supplier_id ? $this->requireSupplier($supplier_id) : null;
+
+//		$company_id = $this->request->int("company_id");
+//		$company = $company_id ? $this->requireCompany($company_id) : null;
+
+		$location_id = $this->request->int("location_id");
+		$location = $location_id ? $this->requireLocation($location_id) : null;
+
+		$document = new Document();
+		$document->user_id = $this->user->id;
+		$document->supplier_id = $supplier->id ?? null;
+//		$document->company_id = $company->id ?? null;
+		$document->location_id = $location->id ?? null;
+		$document->type = $type;
+		$document->number = Document::getNextNumber($type);
+		$document->date = date("Y-m-d");
+		$document->dts_created = Database::dts();
+
+		if($document->isGoodsIn() && !$document->supplier_id && !$document->location_id) {
+			throw new RuntimeException(__("Supplier or location must be selected for a Goods-In document."));
+		}
+		if($document->isAru() && !$document->location_id) {
+			throw new RuntimeException(__("Location must be selected for an ARU document."));
+		}
+
+		$document->commit();
+
+		JSON::success([
+			"url" => $document->getUrl()
+		]);
+	}
+
 	public function update(): void {
 		$document = $this->requireDocument();
 
@@ -108,9 +179,13 @@ $controller = new class($document_type, $document_number) {
 		}
 
 		$document->date = $this->request->string("date");
-		$document->billing_address = $this->request->string("billing_address");
-		$document->delivery_address = $this->request->string("delivery_address");
-		$document->po_number = $this->request->string("po_number");
+
+		if($document->isInvoice() || $document->isDeliveryNote()) {
+			$document->billing_address = $this->request->string("billing_address");
+			$document->delivery_address = $this->request->string("delivery_address");
+			$document->po_number = $this->request->string("po_number");
+		}
+
 		$document->notes = $this->request->string("notes");
 
 		$document->delivery_company = $this->request->string("delivery_company");
@@ -118,12 +193,7 @@ $controller = new class($document_type, $document_number) {
 
 		$document->commit();
 
-		if($document->isInvoice()) {
-			Session::addAlert("success", __("Invoice updated successfully."));
-		}
-		if($document->isDeliveryNote()) {
-			Session::addAlert("success", __("Delivery note updated successfully."));
-		}
+		Session::addAlert("success", __("%s document updated successfully.", $document->getDisplayType()));
 
 		Http::redirect($document->getUrl());
 
@@ -285,6 +355,9 @@ $controller = new class($document_type, $document_number) {
 };
 
 switch($action) {
+	case "create":
+		$controller->create();
+
 	case "submit":
 		$controller->update();
 		break;

+ 26 - 0
controllers/goods_in.php

@@ -0,0 +1,26 @@
+<?php
+
+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
+];
+
+$documents = Document::query($nvp, ["sort" => "id", "order" => "desc"]);
+
+$core->addScript("/js/new-document-modal.js");
+
+View::include("header");
+View::include("goods_in", compact("documents"));
+View::include("modals/new_document");
+View::include("footer");

+ 25 - 7
engine/Document.php

@@ -80,6 +80,22 @@ class Document extends Model {
 		return Sale::get($this->sale_id);
 	}
 
+	/**
+	 * @return Supplier|null
+	 * @throws Exception
+	 */
+	public function getSupplier(): ?Supplier {
+		return Supplier::get($this->supplier_id);
+	}
+
+	/**
+	 * @return Location|null
+	 * @throws Exception
+	 */
+	public function getLocation(): ?Location {
+		return Location::get($this->location_id);
+	}
+
 	/**
 	 * @return string
 	 * @throws Exception
@@ -96,6 +112,10 @@ class Document extends Model {
 			return sprintf("%s/delivery-notes/%s", $sale->getUrl(), $this->number);
 		}
 
+		if($this->isGoodsIn()) {
+			return sprintf("/goods-in/%s", $this->number);
+		}
+
 		throw new RuntimeException(__("Unimplemented getUrl for document type: $this->type"));
 	}
 
@@ -142,13 +162,7 @@ class Document extends Model {
 	}
 
 	public function getTitle(): string {
-		if($this->isInvoice()) {
-			return __("Invoice %d", $this->number);
-		}
-		if($this->isDeliveryNote()) {
-			return __("Delivery Note %d", $this->number);
-		}
-		return __("Document %d", $this->number);
+		return __("%s %d", $this->getDisplayType(), $this->number);
 	}
 
 	/**
@@ -205,4 +219,8 @@ class Document extends Model {
 		return sprintf("%s/download-pdf?access_token=%s&variant=%s", $this->getUrl(), $this->getAccessToken(), $variant);
 	}
 
+	public function isAru(): bool {
+		return $this->getType() === DocumentTypes::ADVANCE_REPLACEMENT_UNIT;
+	}
+
 }

+ 1 - 1
engine/Enums/DocumentTypes.php

@@ -13,7 +13,7 @@ class DocumentTypes extends AbstractEnum {
 		return [
 			self::INVOICE => __("Invoice"),
 			self::DELIVERY_NOTE => __("Delivery Note"),
-			self::GOODS_IN => __("Goods In"),
+			self::GOODS_IN => __("Goods-In"),
 			self::ADVANCE_REPLACEMENT_UNIT => __("Advance Replacement Unit (ARU)"),
 			self::CREDIT_NOTE => __("Credit Note"),
 		];

+ 4 - 0
engine/Http.php

@@ -24,4 +24,8 @@ class Http {
 		readfile($path);
 	}
 
+	public static function isAjax(): bool {
+		return strtolower($_SERVER["HTTP_X_REQUESTED_WITH"] ?? "") === "xmlhttprequest";
+	}
+
 }

+ 65 - 0
public/js/new-document-modal.js

@@ -0,0 +1,65 @@
+class NewDocumentModal {
+	constructor() {
+		this.$modal = $("#new-document-modal");
+		this.modal = bootstrap.Modal.getInstance(this.$modal.get(0));
+
+		this.$modal.on("show.bs.modal", event => this.onShow(event));
+		this.$modal.on("shown.bs.modal", () => this.onShown());
+		this.$modal.on("hidden.bs.modal", () => this.onHidden());
+
+		this.$title = this.$modal.find(".modal-title");
+
+		this.$form = this.$modal.find("form");
+		this.$form.on("submit", event => this.onSubmit(event));
+
+		this.$typeField = this.$form.find("[name=type]");
+		this.$locationDropdown = this.$form.find("[name=location_id]");
+		this.$supplierDropdown = this.$form.find("[name=supplier_id]");
+
+	}
+
+	// Modal lifecycle
+	onShow(event) {
+	    const $element = $(event.relatedTarget);
+	    const data = $element.data();
+
+		const { type } = data;
+
+		switch(type) {
+			case 2: // Goods-In
+				this.$title.text("New Goods-In");
+				this.baseUrl = "/goods-in";
+				break;
+
+			case 3: // ARU
+				this.$title.text("New ARU");
+				this.baseUrl = "/arus";
+				break;
+		}
+	}
+
+	onShown() {
+	    this.$supplierDropdown.trigger("focus");
+	}
+
+	onHidden() {
+		this.$form.get(0).reset();
+		this.$typeField.val(null);
+	}
+
+	onSubmit(event) {
+		event.preventDefault();
+
+		const data = this.$form.serialize();
+
+		$.post(`${this.baseUrl}/create`, data).then(response => {
+			this.$modal.modal("hide");
+			window.location = response.url;
+		}).catch(error => {
+			console.log(error);
+		});
+	}
+
+}
+
+$(() => new NewDocumentModal());

+ 7 - 0
routes/default.php

@@ -58,6 +58,13 @@ $this->addRoute("/^tickets$/", "tickets", [], ["requireUser" => true]);
 $this->addRoute("/^tickets\/(create)$/", "tickets_ajax", ["action"], ["requireUser" => true]);
 $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("/^(goods-in)\/(\d+)$/", "document", ["document_type_string", "document_number"], ["requireUser" => true]);
+$this->addRoute("/^(goods-in)\/(\d+)\/(submit|submit-item|delete-item|items-batch-action|download-pdf)$/", "document", ["document_type_string", "document_number", "action"], ["requireUser" => true]);
+$this->addRoute("/^(goods-in)\/(\d+)\/(render-pdf)$/", "document", ["document_type_string", "document_number", "action"]);
+
 $this->addRoute("/^download-file\/(ticket-comment-attachment)\/(\d+)$/", "download_file", ["type", "id"], ["requireUser" => true]);
 
 $this->addRoute("/^reset-password$/", "reset_password");

+ 34 - 24
views/document.php

@@ -89,37 +89,47 @@ $related_document = $document->getRelatedDocument();
 					</div>
 					<?php
 				}
-				?>
 
-				<div class="row">
-					<div class="col-sm-6">
-						<div class="mb-3">
-							<label for="billing-address" class="form-label">
-								<?=htmlspecialchars(__("Billing Address"))?>
-							</label>
-							<textarea class="form-control" name="billing_address" id="billing-address" rows="6" placeholder="<?=htmlspecialchars(__("Type billing address"))?>" required><?=htmlspecialchars($document->billing_address)?></textarea>
+				if($document->isInvoice() || $document->isDeliveryNote()) {
+					?>
+					<div class="row">
+						<div class="col-sm-6">
+							<div class="mb-3">
+								<label for="billing-address" class="form-label">
+									<?=htmlspecialchars(__("Billing Address"))?>
+								</label>
+								<textarea class="form-control" name="billing_address" id="billing-address" rows="6" placeholder="<?=htmlspecialchars(__("Type billing address"))?>" required><?=htmlspecialchars($document->billing_address)?></textarea>
+							</div>
 						</div>
-					</div>
-					<div class="col-sm-6">
-						<div class="mb-3">
-							<label for="delivery-address" class="form-label">
-								<?=htmlspecialchars(__("Delivery Address"))?>
-							</label>
-							<textarea class="form-control" name="delivery_address" id="delivery-address" rows="6" placeholder="<?=htmlspecialchars(__("Type delivery address"))?>"><?=htmlspecialchars($document->delivery_address)?></textarea>
+						<div class="col-sm-6">
+							<div class="mb-3">
+								<label for="delivery-address" class="form-label">
+									<?=htmlspecialchars(__("Delivery Address"))?>
+								</label>
+								<textarea class="form-control" name="delivery_address" id="delivery-address" rows="6" placeholder="<?=htmlspecialchars(__("Type delivery address"))?>"><?=htmlspecialchars($document->delivery_address)?></textarea>
+							</div>
 						</div>
 					</div>
-				</div>
+					<?php
+				}
+
+				?>
+
 
 				<div class="row">
-					<div class="col-sm-6">
-						<div class="mb-3">
-							<label for="po-number" class="form-label">
-								<?=htmlspecialchars(__("PO Number"))?>
-							</label>
-							<input type="text" class="form-control" name="po_number" id="po-number" placeholder="<?=htmlspecialchars(__("Type PO number"))?>" value="<?=htmlspecialchars($document->po_number)?>" />
-						</div>
-					</div>
 					<?php
+					if($document->isInvoice() || $document->isDeliveryNote()) {
+						?>
+						<div class="col-sm-6">
+							<div class="mb-3">
+								<label for="po-number" class="form-label">
+									<?=htmlspecialchars(__("PO Number"))?>
+								</label>
+								<input type="text" class="form-control" name="po_number" id="po-number" placeholder="<?=htmlspecialchars(__("Type PO number"))?>" value="<?=htmlspecialchars($document->po_number)?>" />
+							</div>
+						</div>
+						<?php
+					}
 					if($document->isInvoice()) {
 						?>
 						<div class="col-sm-6">

+ 134 - 122
views/document_items_section.php

@@ -1,12 +1,15 @@
 <?php
 namespace App;
 
+use App\Helpers\HtmlHelper;
 use NumberFormatter;
 
 /**
  * @var Document $document
  */
 
+$items = $document->getItems();
+
 ?>
 <section class="mb-4" id="document-items-section">
 
@@ -22,148 +25,157 @@ use NumberFormatter;
 		</div>
 	</div>
 
-	<form action="<?=htmlspecialchars($document->getUrl())?>/items-batch-action" method="post">
+	<?php
+	if(empty($items)) {
+		HtmlHelper::renderInfoAlert(__("No items to display."));
+	}
+	else {
+		?>
+		<form action="<?=htmlspecialchars($document->getUrl())?>/items-batch-action" method="post">
 
-		<table class="table table-bordered table-hover mb-2">
-			<colgroup>
-				<col style="width: 1%"/>
-				<col style="width: 35%"/>
-				<col style="width: 20%"/>
-				<col style="width: 15%"/>
-				<?php
-				if($document->isInvoice()) {
-					?>
-					<col style="width: 15%"/>
+			<table class="table table-bordered table-hover mb-2">
+				<colgroup>
+					<col style="width: 1%"/>
+					<col style="width: 35%"/>
+					<col style="width: 20%"/>
 					<col style="width: 15%"/>
 					<?php
-				}
-				?>
-				<col style="width: 1%"/>
-			</colgroup>
-			<thead>
-			<tr>
-				<th>
-					<!--suppress HtmlFormInputWithoutLabel -->
-					<input class="form-check-input" id="all-items-checkbox" type="checkbox" />
-				</th>
-				<th><?=htmlspecialchars(__("Description"))?></th>
-				<th><?=htmlspecialchars(__("Serial Number"))?></th>
-				<th><?=htmlspecialchars(__("Quantity"))?></th>
-				<?php
-				if($document->isInvoice()) {
+					if($document->isInvoice()) {
+						?>
+						<col style="width: 15%"/>
+						<col style="width: 15%"/>
+						<?php
+					}
 					?>
-					<th><?=htmlspecialchars(__("Unit Price"))?></th>
-					<th><?=htmlspecialchars(__("Amount"))?></th>
-					<?php
-				}
-				?>
-				<th><?=htmlspecialchars(__("Actions"))?></th>
-			</tr>
-			</thead>
-			<tbody>
-			<?php
-			$formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
-			$currency = $document->currency;
-			$subtotal = "0.00";
-
-			foreach($document->getItems() as $item) {
-				?>
+					<col style="width: 1%"/>
+				</colgroup>
+				<thead>
 				<tr>
-					<td>
+					<th>
 						<!--suppress HtmlFormInputWithoutLabel -->
-						<input class="form-check-input" type="checkbox" name="document_item_ids[]" value="<?=$item->id?>" />
-					</td>
-					<td>
-						<?=htmlspecialchars($item->description)?>
-					</td>
-					<td>
-						<?=htmlspecialchars($item->serial_number)?>
-					</td>
-					<td class="text-end">
-						<?=$item->quantity?>
-					</td>
+						<input class="form-check-input" id="all-items-checkbox" type="checkbox" />
+					</th>
+					<th><?=htmlspecialchars(__("Description"))?></th>
+					<th><?=htmlspecialchars(__("Serial Number"))?></th>
+					<th><?=htmlspecialchars(__("Quantity"))?></th>
 					<?php
 					if($document->isInvoice()) {
 						?>
-						<td class="text-end">
-							<?=htmlspecialchars($formatter->formatCurrency($item->unit_price, $currency))?>
-						</td>
-						<td class="text-end">
-							<?=htmlspecialchars($formatter->formatCurrency($item->getAmount(), $currency))?>
-						</td>
+						<th><?=htmlspecialchars(__("Unit Price"))?></th>
+						<th><?=htmlspecialchars(__("Amount"))?></th>
 						<?php
-						$subtotal = bcadd($subtotal, $item->getAmount());
 					}
 					?>
-					<td class="p-1 text-nowrap">
-						<button class="btn btn-sm btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#document-item-modal" data-document-id="<?=$document->id?>" data-item="<?=htmlspecialchars(json_encode($item))?>">
-							<i class="fa fa-fw fa-pencil"></i>
-						</button>
-						<button class="btn btn-sm btn-danger btn-delete-document-item" type="button" data-document-item-id="<?=$item->id?>">
-							<i class="fa fa-fw fa-trash"></i>
-						</button>
-					</td>
+					<th><?=htmlspecialchars(__("Actions"))?></th>
 				</tr>
+				</thead>
+				<tbody>
 				<?php
-			}
-			?>
-			</tbody>
+				$formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
+				$currency = $document->currency;
+				$subtotal = "0.00";
+
+				foreach($document->getItems() as $item) {
+					?>
+					<tr>
+						<td>
+							<!--suppress HtmlFormInputWithoutLabel -->
+							<input class="form-check-input" type="checkbox" name="document_item_ids[]" value="<?=$item->id?>" />
+						</td>
+						<td>
+							<?=htmlspecialchars($item->description)?>
+						</td>
+						<td>
+							<?=htmlspecialchars($item->serial_number)?>
+						</td>
+						<td class="text-end">
+							<?=$item->quantity?>
+						</td>
+						<?php
+						if($document->isInvoice()) {
+							?>
+							<td class="text-end">
+								<?=htmlspecialchars($formatter->formatCurrency($item->unit_price, $currency))?>
+							</td>
+							<td class="text-end">
+								<?=htmlspecialchars($formatter->formatCurrency($item->getAmount(), $currency))?>
+							</td>
+							<?php
+							$subtotal = bcadd($subtotal, $item->getAmount());
+						}
+						?>
+						<td class="p-1 text-nowrap">
+							<button class="btn btn-sm btn-primary" type="button" data-bs-toggle="modal" data-bs-target="#document-item-modal" data-document-id="<?=$document->id?>" data-item="<?=htmlspecialchars(json_encode($item))?>">
+								<i class="fa fa-fw fa-pencil"></i>
+							</button>
+							<button class="btn btn-sm btn-danger btn-delete-document-item" type="button" data-document-item-id="<?=$item->id?>">
+								<i class="fa fa-fw fa-trash"></i>
+							</button>
+						</td>
+					</tr>
+					<?php
+				}
+				?>
+				</tbody>
+				<?php
+				if($document->isInvoice()) {
+					$tax = bcmul($subtotal, $document->tax_rate / 100, 2);
+					$total = bcadd($subtotal, $tax, 2);
+					?>
+					<tfoot>
+					<tr>
+						<th colspan="5" class="text-end"><?=htmlspecialchars(__("Subtotal"))?></th>
+						<td class="text-end"><?=htmlspecialchars($formatter->formatCurrency($subtotal, $currency))?></td>
+						<td></td>
+					</tr>
+					<tr>
+						<th colspan="5" class="text-end"><?=htmlspecialchars(__("Tax Rate"))?></th>
+						<td class="text-end">
+							<?=$document->tax_rate?>%
+						</td>
+						<td></td>
+					</tr>
+					<tr>
+						<th colspan="5" class="text-end"><?=htmlspecialchars(__("Tax"))?></th>
+						<td class="text-end">
+							<?=htmlspecialchars($formatter->formatCurrency($tax, $currency))?>
+						</td>
+						<td></td>
+					</tr>
+					<tr>
+						<th colspan="5" class="text-end"><?=htmlspecialchars(__("Total"))?></th>
+						<td class="text-end">
+							<?=htmlspecialchars($formatter->formatCurrency($total, $currency))?>
+						</td>
+						<td></td>
+					</tr>
+					</tfoot>
+					<?php
+				}
+				?>
+			</table>
+
+			<div class="mb-1">
+				<?=htmlspecialchars(__("With selected items:"))?>
+			</div>
+
 			<?php
 			if($document->isInvoice()) {
-				$tax = bcmul($subtotal, $document->tax_rate / 100, 2);
-				$total = bcadd($subtotal, $tax, 2);
 				?>
-				<tfoot>
-				<tr>
-					<th colspan="5" class="text-end"><?=htmlspecialchars(__("Subtotal"))?></th>
-					<td class="text-end"><?=htmlspecialchars($formatter->formatCurrency($subtotal, $currency))?></td>
-					<td></td>
-				</tr>
-				<tr>
-					<th colspan="5" class="text-end"><?=htmlspecialchars(__("Tax Rate"))?></th>
-					<td class="text-end">
-						<?=$document->tax_rate?>%
-					</td>
-					<td></td>
-				</tr>
-				<tr>
-					<th colspan="5" class="text-end"><?=htmlspecialchars(__("Tax"))?></th>
-					<td class="text-end">
-						<?=htmlspecialchars($formatter->formatCurrency($tax, $currency))?>
-					</td>
-					<td></td>
-				</tr>
-				<tr>
-					<th colspan="5" class="text-end"><?=htmlspecialchars(__("Total"))?></th>
-					<td class="text-end">
-						<?=htmlspecialchars($formatter->formatCurrency($total, $currency))?>
-					</td>
-					<td></td>
-				</tr>
-				</tfoot>
+				<button type="submit" class="btn btn-primary" name="batch_action" value="create-delivery-note">
+					<i class="fa fa-fw fa-file-invoice"></i>
+					<?=htmlspecialchars(__("Create Delivery Note"))?>
+				</button>
 				<?php
 			}
 			?>
-		</table>
 
-		<div class="mb-1">
-			<?=htmlspecialchars(__("With selected items:"))?>
-		</div>
-
-		<?php
-		if($document->isInvoice()) {
-			?>
-			<button type="submit" class="btn btn-primary" name="batch_action" value="create-delivery-note">
-				<i class="fa fa-fw fa-file-invoice"></i>
-				<?=htmlspecialchars(__("Create Delivery Note"))?>
+			<button type="submit" class="btn btn-danger" name="batch_action" value="delete">
+				<i class="fa fa-fw fa-trash"></i>
+				<?=htmlspecialchars(__("Delete"))?>
 			</button>
-			<?php
-		}
-		?>
-
-		<button type="submit" class="btn btn-danger" name="batch_action" value="delete">
-			<i class="fa fa-fw fa-trash"></i>
-			<?=htmlspecialchars(__("Delete"))?>
-		</button>
-	</form>
+		</form>
+		<?php
+	}
+	?>
 </section>

+ 29 - 16
views/document_pdf.php

@@ -42,6 +42,9 @@ if($document->isCreditNote()) {
 if($document->isDeliveryNote()) {
 	$background_colour = "#ab47bc";
 }
+if($document->isGoodsIn()) {
+	$background_colour = "#ff7043";
+}
 
 $sale = $document->getSale();
 $company = $sale ? $sale->getCompany() : null;
@@ -148,24 +151,30 @@ $company = $sale ? $sale->getCompany() : null;
 		<div class="row mb-4">
 			<div class="col-6">
 
-				<div class="card mb-2">
-					<div class="card-header bg-document">
-						Bill To
-					</div>
-					<div class="card-body">
-						<?=$document->getBillingAddressHtml()?>
+				<?php
+				if($document->isInvoice() || $document->isDeliveryNote()) {
+					?>
+					<div class="card mb-2">
+						<div class="card-header bg-document">
+							Bill To
+						</div>
+						<div class="card-body">
+							<?=$document->getBillingAddressHtml()?>
+						</div>
 					</div>
-				</div>
 
-				<div class="card mb-2">
-					<div class="card-header bg-document">
-						Delivery Address
-					</div>
-					<div class="card-body">
-						<?=$document->getDeliveryAddressHtml()?>
+					<div class="card mb-2">
+						<div class="card-header bg-document">
+							Delivery Address
+						</div>
+						<div class="card-body">
+							<?=$document->getDeliveryAddressHtml()?>
+						</div>
 					</div>
-				</div>
 
+					<?php
+				}
+				?>
 			</div>
 			<div class="col-6">
 
@@ -194,12 +203,16 @@ $company = $sale ? $sale->getCompany() : null;
 					if($sale) {
 						$render_card("Sales Order", $sale->getNumber());
 					}
+
 					if($document->isInvoice()) {
 						$render_card("Terms", $document->terms ?? " ");
 					}
-					$render_card("Client PO No.", $document->po_number);
 
-					if(!$document->isDeliveryNote()) {
+					if($document->isInvoice() || $document->isDeliveryNote()) {
+						$render_card("Client PO No.", $document->po_number);
+					}
+
+					if($document->isInvoice()) {
 						$render_card("Delivery Note No.", $delivery_note_number);
 					}
 

+ 88 - 0
views/goods_in.php

@@ -0,0 +1,88 @@
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+
+namespace App;
+
+use App\Enums\DocumentTypes;
+
+/**
+ * @var Document[] $documents
+ */
+
+?>
+<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>
+	</div>
+</div>
+
+<?php
+
+if(empty($documents)) {
+	?>
+	<div class="alert alert-info">
+		<i class="fa fa-fw fa-info-circle"></i>
+		<?=htmlspecialchars(__("No goods-in documents to display."))?>
+	</div>
+	<?php
+}
+else {
+	?>
+	<table class="table table-bordered table-hover">
+		<thead>
+		<tr>
+			<th><?=htmlspecialchars(__("Number"))?></th>
+			<th><?=htmlspecialchars(__("Location"))?></th>
+			<th><?=htmlspecialchars(__("Items"))?></th>
+			<th><?=htmlspecialchars(__("Actions"))?></th>
+		</tr>
+		</thead>
+		<tbody>
+		<?php
+		foreach($documents as $document) {
+			$location = $document->getLocation();
+			$supplier = $document->getSupplier();
+			?>
+			<tr>
+				<td class="text-right">
+					<?=htmlspecialchars($document->number)?>
+				</td>
+				<td>
+					<?php
+					if($location) {
+						?>
+						<a href="<?=htmlspecialchars($location->getUrl())?>">
+							<?=htmlspecialchars($location->getDisplayName())?>
+						</a>
+						<?php
+					}
+					else if($supplier) {
+						?>
+						<a href="<?=htmlspecialchars($supplier->getUrl())?>">
+							<?=htmlspecialchars($supplier->name)?>
+						</a>
+						<?php
+					}
+					?>
+				</td>
+				<td>
+					Items
+				</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
+}

+ 23 - 7
views/header.php

@@ -78,21 +78,32 @@ $google_api_key = $_ENV["GOOGLE_API_KEY"] ?? null;
 				?>
 				<div class="card mb-3">
 					<div class="card-header">
-						<?=htmlspecialchars(__("CRM"))?>
+						<?=htmlspecialchars(__("Home"))?>
 					</div>
 					<div class="list-group list-group-flush">
 						<a class="list-group-item list-group-item-action" href="/dashboard"><?=htmlspecialchars(__("Dashboard"))?></a>
 						<a class="list-group-item list-group-item-action" href="/map"><?=htmlspecialchars(__("Map"))?></a>
+					</div>
+				</div>
 
-						<a class="list-group-item list-group-item-action" href="/customers"><?=htmlspecialchars(__("Customers"))?></a>
-						<a class="list-group-item list-group-item-action" href="/locations"><?=htmlspecialchars(__("Locations"))?></a>
 
-						<a class="list-group-item list-group-item-action" href="/suppliers"><?=htmlspecialchars(__("Suppliers"))?></a>
-						<a class="list-group-item list-group-item-action" href="/products"><?=htmlspecialchars(__("Products"))?></a>
+				<div class="card mb-3">
+					<div class="card-header">
+						<?=htmlspecialchars(__("Company"))?>
+					</div>
+					<div class="list-group list-group-flush">
 						<a class="list-group-item list-group-item-action" href="/sales"><?=htmlspecialchars(__("Sales"))?></a>
-						<a class="list-group-item list-group-item-action" href="/tickets"><?=htmlspecialchars(__("Tickets"))?></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>
+					</div>
+				</div>
 
-						<a class="list-group-item list-group-item-action" href="/companies"><?=htmlspecialchars(__("Companies"))?></a>
+				<div class="card mb-3">
+					<div class="card-header">
+						<?=htmlspecialchars(__("Support"))?>
+					</div>
+					<div class="list-group list-group-flush">
+						<a class="list-group-item list-group-item-action" href="/tickets"><?=htmlspecialchars(__("Tickets"))?></a>
 					</div>
 				</div>
 
@@ -101,6 +112,11 @@ $google_api_key = $_ENV["GOOGLE_API_KEY"] ?? null;
 						<?=htmlspecialchars(__("Admin"))?>
 					</div>
 					<div class="list-group list-group-flush">
+						<a class="list-group-item list-group-item-action" href="/companies"><?=htmlspecialchars(__("Companies"))?></a>
+						<a class="list-group-item list-group-item-action" href="/customers"><?=htmlspecialchars(__("Customers"))?></a>
+						<a class="list-group-item list-group-item-action" href="/locations"><?=htmlspecialchars(__("Locations"))?></a>
+						<a class="list-group-item list-group-item-action" href="/products"><?=htmlspecialchars(__("Products"))?></a>
+						<a class="list-group-item list-group-item-action" href="/suppliers"><?=htmlspecialchars(__("Suppliers"))?></a>
 						<a class="list-group-item list-group-item-action" href="/users"><?=htmlspecialchars(__("Users"))?></a>
 					</div>
 				</div>

+ 61 - 0
views/modals/new_document.php

@@ -0,0 +1,61 @@
+<?php
+namespace App;
+
+?>
+<div class="modal fade" role="dialog" tabindex="-1" data-backdrop="static" id="new-document-modal">
+	<div class="modal-dialog modal-lg">
+		<form class="modal-content" method="post" action="/documents/submit">
+			<?php
+			View::include("modals/header", ["title" => __("New Document")]);
+			?>
+			<input type="hidden" name="type" value="" />
+			<div class="modal-body">
+				<div class="mb-3">
+					<label class="form-label" for="new-document-supplier-id"><?= htmlspecialchars(__("Supplier")) ?></label>
+					<select class="form-control" name="supplier_id" id="new-document-supplier-id">
+						<option value=""><?=htmlspecialchars(__("Select Supplier"))?></option>
+						<?php
+						foreach(Supplier::getAll() as $supplier) {
+							?>
+							<option value="<?=$supplier->id?>">
+								<?=htmlspecialchars($supplier->name)?>
+							</option>
+							<?php
+						}
+						?>
+					</select>
+				</div>
+
+				<div class="mb-3">
+					<label class="form-label" for="location-id"><?= htmlspecialchars(__("Location")) ?></label>
+					<select class="form-control" name="location_id" id="location-id">
+						<option value=""><?=htmlspecialchars(__("Select Location"))?></option>
+						<?php
+						foreach(Customer::getAll() as $customer) {
+							?>
+							<optgroup label="<?=htmlspecialchars($customer->name)?>">
+								<?php
+								foreach($customer->getLocations() as $location) {
+									?>
+									<option value="<?=$location->id?>">
+										<?=htmlspecialchars($location->name)?>
+									</option>
+									<?php
+								}
+								?>
+							</optgroup>
+							<?php
+						}
+						?>
+					</select>
+				</div>
+
+			</div>
+			<div class="modal-footer">
+				<button type="submit" class="btn btn-success">
+					<?= htmlspecialchars(__("Submit")) ?>
+				</button>
+			</div>
+		</form>
+	</div>
+</div>