| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App;
- use App\Helpers\HtmlHelper;
- use NumberFormatter;
- /**
- * @var Document $document
- */
- $items = $document->getItems();
- $title = __("Items");
- if($document->isSalesOrder()) {
- $title = __("Sales Order Items");
- }
- if($document->isDeliveryNote()) {
- $title = __("Delivery Items");
- }
- if($document->isAru()) {
- $title = __("Return Items");
- }
- ?>
- <section class="mb-4" id="document-items-section">
- <div class="row mb-3">
- <div class="col">
- <h3><?=htmlspecialchars($title)?></h3>
- </div>
- <div class="col-auto">
- <button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#document-item-modal" data-document-type="<?=$document->type?>">
- <i class="fa fa-fw fa-plus"></i>
- <?=htmlspecialchars(__("Add Item"))?>
- </button>
- </div>
- </div>
- <?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-3">
- <colgroup>
- <col style="width: 1%"/>
- <col style="width: 35%"/>
- <col style="width: 20%"/>
- <col style="width: 15%"/>
- <?php
- if($document->hasCosts()) {
- ?>
- <col style="width: 15%"/>
- <col style="width: 15%"/>
- <?php
- }
- if($document->isDeliveryNote()) {
- ?>
- <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 Numbers"))?></th>
- <th><?=htmlspecialchars(__("Quantity"))?></th>
- <?php
- if($document->hasCosts()) {
- ?>
- <th><?=htmlspecialchars(__("Unit Price"))?></th>
- <th><?=htmlspecialchars(__("Amount"))?></th>
- <?php
- }
- if($document->isDeliveryNote()) {
- ?>
- <th><?=htmlspecialchars(__("Insurance Value"))?></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) {
- ?>
- <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>
- <?=$item->getSerialNumberHtml()?>
- </td>
- <td class="text-end">
- <?=$item->quantity?>
- </td>
- <?php
- if($document->hasCosts()) {
- ?>
- <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());
- }
- if($document->isDeliveryNote()) {
- ?>
- <td class="text-end">
- <?=htmlspecialchars($formatter->formatCurrency($item->insurance_value, $currency))?>
- </td>
- <?php
- }
- ?>
- <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-document-type="<?=$document->type?>" 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->hasCosts()) {
- $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->isAru()) {
- ?>
- <button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-sales-order" disabled>
- <i class="fa fa-fw fa-file-invoice"></i>
- <?=htmlspecialchars(__("Create Sales Order"))?>
- </button>
- <button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-goods-in" disabled>
- <i class="fa fa-fw fa-truck"></i>
- <?=htmlspecialchars(__("Create Goods-In"))?>
- </button>
- <?php
- }
- if($document->hasCosts() && !$document->isPartOfAru()) {
- ?>
- <button type="submit" class="btn btn-primary batch-action" name="batch_action" value="create-delivery-note" disabled>
- <i class="fa fa-fw fa-file-invoice"></i>
- <?=htmlspecialchars(__("Create Delivery Note"))?>
- </button>
- <?php
- }
- ?>
- <button type="submit" class="btn btn-danger batch-action" name="batch_action" value="delete" disabled>
- <i class="fa fa-fw fa-trash"></i>
- <?=htmlspecialchars(__("Delete"))?>
- </button>
- </form>
- <?php
- }
- ?>
- </section>
|