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

Display more info on sales invoice table

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

+ 14 - 7
engine/Document.php

@@ -197,16 +197,19 @@ class Document extends Model {
 		return AruStatuses::enumToText($this->aru_status);
 	}
 
-	public function getDisplayTotal(): string {
-		$formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
+	public function getDisplaySubtotal(): string {
+		return (new NumberFormatter("en_GB", NumberFormatter::CURRENCY))->formatCurrency($this->getSubtotal(), $this->currency);
+	}
 
-		$subtotal = "0.00";
+	public function getDisplayTax(): string {
+		return (new NumberFormatter("en_GB", NumberFormatter::CURRENCY))->formatCurrency($this->getTax(), $this->currency);
+	}
 
-		foreach($this->getItems() as $item) {
-			$subtotal = bcadd($item->getAmount(), $subtotal, 2);
-		}
+	public function getDisplayTotal(): string {
+		$formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
 
-		$tax = bcmul($subtotal, $this->tax_rate / 100, 2);
+		$subtotal = $this->getSubtotal();
+		$tax = $this->getTax();
 		$total = bcadd($subtotal, $tax, 2);
 
 		return $formatter->formatCurrency($total, $this->currency);
@@ -345,6 +348,10 @@ class Document extends Model {
 		return $subtotal;
 	}
 
+	public function getTax(): string {
+		return bcmul($this->getSubtotal(), $this->tax_rate / 100, 2);
+	}
+
 	public function getNotesHtml(): string {
 		return nl2br(htmlspecialchars($this->notes));
 	}

+ 29 - 0
views/components/document_items_unstyled_list.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace App;
+
+/**
+ * @var \App\DocumentItem[] $items
+ */
+
+?>
+<ul class="list-unstyled mb-0">
+	<?php
+	foreach($items 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>

+ 22 - 21
views/documents.php

@@ -151,9 +151,27 @@ if(empty($documents)) {
 else {
 	?>
 	<table class="table table-bordered table-hover mb-3">
+		<colgroup>
+			<col style="width: 1%"/>
+			<?php
+			if($is_goods_in) {
+				?>
+				<col style="width: 20%"/>
+				<?php
+			}
+			else {
+				?>
+				<col style="width: 20%"/>
+				<col style="width: 20%"/>
+				<?php
+			}
+			?>
+			<col style="width: 60%"/>
+			<col style="width: 1%"/>
+		</colgroup>
 		<thead>
 		<tr>
-			<th><?=htmlspecialchars(__("Number"))?></th>
+			<th><?=htmlspecialchars(__("No."))?></th>
 			<?php
 			if($is_goods_in) {
 				?>
@@ -219,26 +237,9 @@ else {
 				}
 				?>
 				<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>
+					<?php
+					View::include("components/document_items_unstyled_list", ["items" => $document->getItems()]);
+					?>
 				</td>
 				<td class="p-1">
 					<a class="btn btn-sm btn-primary" href="<?=htmlspecialchars($document->getUrl())?>">

+ 2 - 2
views/sale.php

@@ -108,9 +108,9 @@ View::include("sale_notes_section", compact("sale"));
 		?>
 		<table class="table table-bordered table-hover">
 			<colgroup>
+				<col style="width: 1%"/>
 				<col style="width: 10%"/>
-				<col style="width: 10%"/>
-				<col style="width: 35%"/>
+				<col style="width: 45%"/>
 				<col style="width: 10%"/>
 				<col style="width: 20%"/>
 				<col style="width: 15%"/>

+ 25 - 2
views/sale_invoices_section.php

@@ -20,10 +20,22 @@ use App\Helpers\HtmlHelper;
 	else {
 		?>
 		<table class="table table-bordered table-hover">
+			<colgroup>
+				<col style="width: 1%"/>
+				<col style="width: 15%"/>
+				<col style="width: 55%"/>
+				<col style="width: 10%"/>
+				<col style="width: 10%"/>
+				<col style="width: 10%"/>
+				<col style="width: 1%"/>
+			</colgroup>
 			<thead>
 			<tr>
-				<th><?=htmlspecialchars(__("Number"))?></th>
+				<th><?=htmlspecialchars(__("No."))?></th>
 				<th><?=htmlspecialchars(__("Status"))?></th>
+				<th><?=htmlspecialchars(__("Items"))?></th>
+				<th><?=htmlspecialchars(__("Subtotal"))?></th>
+				<th><?=htmlspecialchars(__("Tax"))?></th>
 				<th><?=htmlspecialchars(__("Total"))?></th>
 				<th><?=htmlspecialchars(__("Actions"))?></th>
 			</tr>
@@ -34,11 +46,22 @@ use App\Helpers\HtmlHelper;
 				?>
 				<tr>
 					<td class="text-end">
-						<?=$invoice->number?>
+						<a href="<?=htmlspecialchars($invoice->getUrl())?>"><?=$invoice->number?></a>
 					</td>
 					<td>
 						<?=htmlspecialchars($invoice->getDisplayInvoiceStatus())?>
 					</td>
+					<td>
+						<?php
+						View::include("components/document_items_unstyled_list", ["items" => $invoice->getItems()]);
+						?>
+					</td>
+					<td class="text-end">
+						<?=htmlspecialchars($invoice->getDisplaySubtotal())?>
+					</td>
+					<td class="text-end">
+						<?=htmlspecialchars($invoice->getDisplayTax())?>
+					</td>
 					<td class="text-end">
 						<?=htmlspecialchars($invoice->getDisplayTotal())?>
 					</td>

+ 7 - 1
views/sales_table.php

@@ -6,9 +6,15 @@ namespace App;
  */
 ?>
 <table class="table table-bordered table-hover mb-3">
+	<colgroup>
+		<col style="width: 1%"/>
+		<col style="width: 50%"/>
+		<col style="width: 50%"/>
+		<col style="width: 1%"/>
+	</colgroup>
 	<thead>
 	<tr>
-		<th><?=htmlspecialchars(__("Number"))?></th>
+		<th><?=htmlspecialchars(__("No."))?></th>
 		<th><?=htmlspecialchars(__("Location"))?></th>
 		<th><?=htmlspecialchars(__("Status"))?></th>
 		<th><?=htmlspecialchars(__("Actions"))?></th>