| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App;
- use App\Enums\AruStatuses;
- use App\Enums\DocumentTypes;
- use App\Enums\SalesOrderStatuses;
- use App\Helpers\HtmlHelper;
- /**
- * @var string $title
- * @var string $type_string
- * @var int $type
- * @var Document[] $documents
- * @var Pagination $pagination
- * @var int $supplier_id
- * @var int $customer_id
- * @var int $location_id
- * @var int $status
- * @var int $number
- * @var int $custom_filter
- */
- $is_sale_order = ($type === DocumentTypes::SALES_ORDER);
- $is_goods_in = ($type === DocumentTypes::GOODS_IN);
- $is_aru = ($type === DocumentTypes::ADVANCE_REPLACEMENT_UNIT);
- $is_delivery_note = ($type === DocumentTypes::DELIVERY_NOTE);
- $status_options = [];
- $custom_filter_options = [];
- if($is_sale_order) {
- $status_options = SalesOrderStatuses::options();
- $custom_filter_options = [
- "open" => "Open Sales Orders",
- ];
- }
- if($is_aru) {
- $status_options = AruStatuses::options();
- $custom_filter_options = [
- "open" => "Open ARUs",
- ];
- }
- ?>
- <div class="row mb-3">
- <div class="col">
- <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>
- <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="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">
- <div class="mb-3">
- <label class="form-label" for="status"><?=htmlspecialchars(__("Status"))?></label>
- <select class="form-control" 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="custom-filter"><?=htmlspecialchars(__("Custom Filter"))?></label>
- <select class="form-control" 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>
- </div>
- <?php
- if(empty($documents)) {
- ?>
- <div class="alert alert-info">
- <i class="fa fa-fw fa-info-circle"></i>
- <?=htmlspecialchars(__("No %s to display.", $title))?>
- </div>
- <?php
- }
- else {
- ?>
- <table class="table table-bordered table-hover mb-3">
- <colgroup>
- <col style="width: 1%"/>
- <?php
- if(!$status_options) {
- ?>
- <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(__("No."))?></th>
- <?php
- if(!$status_options) {
- if($is_goods_in) {
- $column_name = __("Location / Supplier");
- }
- else {
- $column_name = __("Location");
- }
- ?>
- <th><?=htmlspecialchars($column_name)?></th>
- <?php
- }
- else {
- ?>
- <th><?=htmlspecialchars(__("Location"))?></th>
- <th><?=htmlspecialchars(__("Status"))?></th>
- <?php
- }
- ?>
- <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-end">
- <a href="<?=htmlspecialchars($document->getUrl())?>"><?=$document->number?></a>
- </td>
- <td>
- <?php
- if($location) {
- ?>
- <a href="<?=htmlspecialchars($location->getUrl())?>">
- <?=htmlspecialchars($location->getDisplayName())?>
- </a>
- <?php
- }
- if($supplier) {
- ?>
- <a href="<?=htmlspecialchars($supplier->getUrl())?>">
- <?=htmlspecialchars($supplier->name)?>
- </a>
- <?php
- }
- ?>
- </td>
- <?php
- if($status_options) {
- if($is_sale_order) {
- ?>
- <td>
- <?=htmlspecialchars($document->getDisplaySalesOrderStatus())?>
- </td>
- <?php
- }
- else {
- ?>
- <td>
- <?=htmlspecialchars($document->getDisplayAruStatus())?>
- </td>
- <?php
- }
- }
- ?>
- <td>
- <?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())?>">
- <?=htmlspecialchars(__("View"))?>
- </a>
- </td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- <?php
- $pagination->render();
- }
|