Преглед изворни кода

Add batch actions for sales orders

Alan Lam пре 2 година
родитељ
комит
c8bcc6248d
3 измењених фајлова са 149 додато и 55 уклоњено
  1. 32 0
      controllers/documents.php
  2. 7 0
      public/js/documents.js
  3. 110 55
      views/documents.php

+ 32 - 0
controllers/documents.php

@@ -65,6 +65,37 @@ $nvp = [
 
 $request = Request::fromRequest();
 
+$document_ids = $request->int("document_ids");
+$batch_action = $request->string("batch_action");
+
+if($type === DocumentTypes::SALES_ORDER && is_array($document_ids)) {
+	$batch_documents = Document::query([
+		"id" => $document_ids,
+		"type" => DocumentTypes::SALES_ORDER,
+	]);
+
+	foreach($batch_documents as $batch_document) {
+		switch($batch_action) {
+			case "mark-draft":
+				$batch_document->invoice_status = SalesOrderStatuses::DRAFT;
+				break;
+			case "mark-shipped":
+				$batch_document->invoice_status = SalesOrderStatuses::SHIPPED;
+				break;
+			case "mark-paid":
+				$batch_document->invoice_status = SalesOrderStatuses::PAID;
+				break;
+			case "mark-void":
+				$batch_document->invoice_status = SalesOrderStatuses::VOID;
+				break;
+			case "mark-uncollectible":
+				$batch_document->invoice_status = SalesOrderStatuses::UNCOLLECTIBLE;
+				break;
+		}
+		$batch_document->commit();
+	}
+}
+
 $supplier_id = $request->int("supplier_id");
 if($supplier_id) {
 	$nvp["supplier_id"] = $supplier_id;
@@ -121,6 +152,7 @@ $documents = Document::query($nvp, [
 ]);
 
 $core->addScript("/js/new-document-modal.js");
+$core->addScript("/js/documents.js");
 
 View::include("header");
 View::include("documents", compact("title", "type_string", "type", "documents", "pagination", "type_name", "supplier_id", "customer_id", "location_id", "status", "number", "custom_filter"));

+ 7 - 0
public/js/documents.js

@@ -0,0 +1,7 @@
+$(() => {
+	const $selectAll = $("#documents-table-select-all");
+	$selectAll.on("change", event => {
+		const $table = $(event.currentTarget).closest("table");
+		$table.find("tbody input[type=checkbox]").prop("checked", event.currentTarget.checked);
+	});
+});

+ 110 - 55
views/documents.php

@@ -45,6 +45,8 @@ if($is_aru) {
 	];
 }
 
+$show_batch_actions = $is_sale_order && $documents;
+
 ?>
 <div class="row mb-3">
 	<div class="col">
@@ -64,81 +66,82 @@ if($is_aru) {
 	?>
 </div>
 
+<form method="post">
+
+
 <div class="card mb-3">
 	<div class="card-header">
 		<?=htmlspecialchars(__("Filters"))?>
 	</div>
 	<div class="card-body">
-		<form action="/<?=$type_string?>" method="get">
-			<div class="row">
-				<?php
-				if($is_goods_in) {
-					?>
-					<div class="col-sm-4">
-						<?php
-						View::include("components/supplier_id_field", compact("supplier_id"));
-						?>
-					</div>
-					<?php
-				}
+		<div class="row">
+			<?php
+			if($is_goods_in) {
 				?>
 				<div class="col-sm-4">
 					<?php
-					View::include("components/customer_id_field", compact("customer_id"));
+					View::include("components/supplier_id_field", compact("supplier_id"));
 					?>
 				</div>
+				<?php
+			}
+			?>
+			<div class="col-sm-4">
+				<?php
+				View::include("components/customer_id_field", compact("customer_id"));
+				?>
+			</div>
+			<div class="col-sm-4">
+				<?php
+				View::include("components/location_id_field", compact("location_id"));
+				?>
+			</div>
+			<?php
+			if($status_options) {
+				?>
 				<div class="col-sm-4">
-					<?php
-					View::include("components/location_id_field", compact("location_id"));
-					?>
+					<div class="mb-3">
+						<label class="form-label" for="status"><?=htmlspecialchars(__("Status"))?></label>
+						<select class="form-select" name="status" id="status">
+							<option value=""><?=htmlspecialchars(__("Any Status"))?></option>
+							<?php
+							HtmlHelper::renderOptions($status_options, $status);
+							?>
+						</select>
+					</div>
 				</div>
 				<?php
-				if($status_options) {
-					?>
-					<div class="col-sm-4">
-						<div class="mb-3">
-							<label class="form-label" for="status"><?=htmlspecialchars(__("Status"))?></label>
-							<select class="form-select" name="status" id="status">
-								<option value=""><?=htmlspecialchars(__("Any Status"))?></option>
-								<?php
-								HtmlHelper::renderOptions($status_options, $status);
-								?>
-							</select>
-						</div>
-					</div>
-					<?php
-				}
+			}
+			?>
+			<div class="col-sm-4">
+				<div class="mb-3">
+					<label class="form-label" for="number"><?=htmlspecialchars(__("Number"))?></label>
+					<input class="form-control" type="number" name="number" id="number" value="<?=htmlspecialchars($number)?>" placeholder="<?=htmlspecialchars(__("Type number"))?>" />
+				</div>
+			</div>
+
+			<?php
+			if($custom_filter_options) {
 				?>
 				<div class="col-sm-4">
 					<div class="mb-3">
-						<label class="form-label" for="number"><?=htmlspecialchars(__("Number"))?></label>
-						<input class="form-control" type="number" name="number" id="number" value="<?=htmlspecialchars($number)?>" placeholder="<?=htmlspecialchars(__("Type number"))?>" />
+						<label class="form-label" for="custom-filter"><?=htmlspecialchars(__("Custom Filter"))?></label>
+						<select class="form-select" name="custom_filter" id="custom-filter">
+							<option value=""><?=htmlspecialchars(__("All %s", $title))?></option>
+							<?php
+							HtmlHelper::renderOptions($custom_filter_options, $custom_filter);
+							?>
+						</select>
 					</div>
 				</div>
-
 				<?php
-				if($custom_filter_options) {
-					?>
-					<div class="col-sm-4">
-						<div class="mb-3">
-							<label class="form-label" for="custom-filter"><?=htmlspecialchars(__("Custom Filter"))?></label>
-							<select class="form-select" name="custom_filter" id="custom-filter">
-								<option value=""><?=htmlspecialchars(__("All %s", $title))?></option>
-								<?php
-								HtmlHelper::renderOptions($custom_filter_options, $custom_filter);
-								?>
-							</select>
-						</div>
-					</div>
-					<?php
-				}
-				?>
+			}
+			?>
 
-			</div>
-			<button class="btn btn-primary" type="submit">
-				<?=htmlspecialchars(__("Submit"))?>
-			</button>
-		</form>
+		</div>
+		<button class="btn btn-primary" type="submit">
+			<?=htmlspecialchars(__("Submit"))?>
+		</button>
 	</div>
 </div>
 
@@ -157,6 +160,17 @@ else {
 	<table class="table table-bordered table-hover mb-3">
 		<thead>
 		<tr>
+			<?php
+			if($show_batch_actions) {
+				?>
+				<th class="text-center">
+					<label>
+						<input type="checkbox" id="documents-table-select-all" />
+					</label>
+				</th>
+				<?php
+			}
+			?>
 			<th><?=htmlspecialchars(__("Ref."))?></th>
 			<th><?=htmlspecialchars(__("Date"))?></th>
 			<?php
@@ -199,6 +213,17 @@ else {
 			$supplier = $document->getSupplier();
 			?>
 			<tr>
+				<?php
+				if($show_batch_actions) {
+					?>
+					<td class="text-center">
+						<label>
+							<input type="checkbox" name="document_ids[]" value="<?=$document->id?>" />
+						</label>
+					</td>
+					<?php
+				}
+				?>
 				<td class="text-end">
 					<a href="<?=htmlspecialchars($document->getUrl())?>"><?=$document->getReference()?></a>
 				</td>
@@ -268,4 +293,34 @@ else {
 	</table>
 	<?php
 	$pagination->render();
+
+	if($show_batch_actions) {
+		?>
+		<div class="card mb-3">
+			<div class="card-header">
+				<?=htmlspecialchars(__("Batch Actions"))?>
+			</div>
+			<div class="card-body">
+				<label class="sr-only" for="batch-action"><?=htmlspecialchars(__("Batch Action"))?></label>
+				<div class="input-group">
+					<select class="form-control" name="batch_action" id="batch-action">
+						<option value=""><?=htmlspecialchars(__("Select Batch Action"))?></option>
+						<option value="mark-draft"><?=htmlspecialchars(__("Mark As Draft"))?></option>
+						<option value="mark-shipped"><?=htmlspecialchars(__("Mark As Shipped"))?></option>
+						<option value="mark-paid"><?=htmlspecialchars(__("Mark As Paid"))?></option>
+						<option value="mark-void"><?=htmlspecialchars(__("Mark As Void"))?></option>
+						<option value="mark-uncollectible"><?=htmlspecialchars(__("Mark As Uncollectible"))?></option>
+					</select>
+					<button type="submit" class="btn btn-primary">
+						<?=htmlspecialchars(__("Submit"))?>
+					</button>
+				</div>
+			</div>
+		</div>
+		<?php
+	}
+	?>
+	<?php
 }
+?>
+</form>