Browse Source

Add ability to add a sales order when viewing a customer

Alan Lam 8 tháng trước cách đây
mục cha
commit
23f43ae7aa

+ 2 - 0
controllers/customer.php

@@ -17,6 +17,7 @@ $user->requireAdmin();
 
 $core->addScript("/js/new-sale-modal.js");
 $core->addScript("/js/ticket-modal.js");
+$core->addScript("/js/new-document-modal.js");
 $core->addScript("/js/map.js");
 
 $location_ids = array_column($customer->getLocations(), "id");
@@ -35,4 +36,5 @@ View::include("header");
 View::include("customer", compact("customer", "sales", "tickets"));
 View::include("modals/new_sale", compact("customer"));
 View::include("modals/ticket", compact("customer"));
+View::include("modals/new_document", compact("customer"));
 View::include("footer");

+ 5 - 1
views/customer.php

@@ -61,7 +61,11 @@ $entities = $customer->getEntities();
 </section>
 
 <?php
-View::include("sale_invoices_section", ["title" => __("Recent Sales Orders"), "sales_orders" => $customer->getRecentSalesOrders()]);
+View::include("sale_invoices_section", [
+	"title" => __("Recent Sales Orders"),
+	"sales_orders" => $customer->getRecentSalesOrders(),
+	"show_add_button" => true,
+]);
 ?>
 
 <section class="mb-4">

+ 14 - 2
views/modals/new_document.php

@@ -1,5 +1,11 @@
 <?php /** @noinspection PhpUnhandledExceptionInspection */
+
 namespace App;
+
+/**
+ * @var Customer $customer
+ */
+
 use App\Helpers\HtmlHelper;
 
 $core = Core::getInstance();
@@ -12,13 +18,19 @@ $default_location_id = $request->int("add_location_id");
 
 $location_options = [];
 
-foreach(Customer::getAll() as $customer) {
+if(!isset($customer)) {
+	foreach(Customer::getAll() as $customer) {
+		foreach($customer->getLocations() as $location) {
+			$location_options[$location->id] = $location->getDisplayName();
+		}
+	}
+}
+else {
 	foreach($customer->getLocations() as $location) {
 		$location_options[$location->id] = $location->getDisplayName();
 	}
 }
 
-
 ?>
 <div class="modal fade" role="dialog" tabindex="-1" data-backdrop="static" id="new-document-modal">
 	<div class="modal-dialog modal-lg">

+ 20 - 1
views/sale_invoices_section.php

@@ -5,17 +5,36 @@ namespace App;
 /**
  * @var string $title
  * @var Document[] $sales_orders
+ * @var bool $show_add_button
  */
 
+use App\Enums\DocumentTypes;
 use App\Helpers\HtmlHelper;
 
 $title ??= __("Sales Orders");
 $show_location_column ??= true;
+$show_add_button ??= false;
 
 ?>
 
 <section class="mb-4">
-	<h3><?=htmlspecialchars($title)?></h3>
+	<div class="row">
+		<div class="col">
+			<h3><?=htmlspecialchars($title)?></h3>
+		</div>
+		<?php
+		if($show_add_button) {
+			?>
+			<div class="col-auto">
+				<button type="button" id="new-document-button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#new-document-modal" data-type="<?=DocumentTypes::SALES_ORDER?>">
+					<i class="fa fa-fw fa-plus"></i>
+					<?=htmlspecialchars(__("Add"))?>
+				</button>
+			</div>
+			<?php
+		}
+		?>
+	</div>
 	<?php
 	if(empty($sales_orders)) {
 		HtmlHelper::renderInfoAlert(__("No sales orders to display."));