document.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Enums\AruStatuses;
  4. use App\Enums\Currencies;
  5. use App\Enums\SalesOrderStatuses;
  6. use App\Helpers\HtmlHelper;
  7. /**
  8. * @var Sale $sale
  9. * @var Document $document
  10. */
  11. $core = Core::getInstance();
  12. $user = $core->getUser();
  13. $sale = $document->getSale();
  14. $related_document = $document->getRelatedDocument();
  15. ?>
  16. <section class="mb-4">
  17. <h3 class="mb-3">
  18. <?php
  19. if($related_document) {
  20. echo __("%s for %s",
  21. htmlspecialchars($document->getTitle()),
  22. "<a href=\"" . htmlspecialchars($related_document->getUrl()) . "\">" . htmlspecialchars($related_document->getTitle()) . "</a>"
  23. );
  24. }
  25. else if($sale) {
  26. echo __("%s for %s",
  27. htmlspecialchars($document->getTitle()),
  28. "<a href=\"" . htmlspecialchars($sale->getUrl()) . "\">" . htmlspecialchars($sale->getTitle()) . "</a>"
  29. );
  30. }
  31. else {
  32. echo htmlspecialchars($document->getTitle());
  33. }
  34. ?>
  35. </h3>
  36. <form id="document-form" action="<?=htmlspecialchars($document->getUrl())?>/submit" method="post">
  37. <div class="row">
  38. <div class="col-xl-8">
  39. <h4><?=htmlspecialchars(__("Main Details"))?></h4>
  40. <?php
  41. $user->insertCsrfToken();
  42. ?>
  43. <div class="row">
  44. <div class="col-sm-6">
  45. <?php
  46. if($document->isSalesOrder()) {
  47. ?>
  48. <div class="mb-3">
  49. <label for="invoice-status" class="form-label">
  50. <b><?=htmlspecialchars(__("Status"))?></b>
  51. </label>
  52. <span class="ms-1"></span>
  53. <span class="badge rounded-pill text-bg-danger">
  54. <?=htmlspecialchars(__("Important"))?>
  55. </span>
  56. <select class="form-select" name="invoice_status" id="invoice-status">
  57. <?php
  58. HtmlHelper::renderOptions(SalesOrderStatuses::options(), $document->invoice_status);
  59. ?>
  60. </select>
  61. </div>
  62. <?php
  63. }
  64. else if($document->isAru()) {
  65. ?>
  66. <div class="mb-3">
  67. <label for="aru-status" class="form-label">
  68. <b><?=htmlspecialchars(__("Status"))?></b>
  69. </label>
  70. <span class="ms-1"></span>
  71. <span class="badge rounded-pill text-bg-danger">
  72. <?=htmlspecialchars(__("Important"))?>
  73. </span>
  74. <select class="form-select" name="aru_status" id="aru-status">
  75. <?php
  76. HtmlHelper::renderOptions(AruStatuses::options(), $document->aru_status);
  77. ?>
  78. </select>
  79. </div>
  80. <?php
  81. }
  82. ?>
  83. </div>
  84. <div class="col-sm-6">
  85. <div class="mb-3">
  86. <label for="location" class="form-label">
  87. <?=htmlspecialchars(__("Location"))?>
  88. </label>
  89. <select class="form-select" name="location_id" id="location" <?=HtmlHelper::required($document->location_id)?>>
  90. <option value=""><?=htmlspecialchars(__("Select Location"))?></option>
  91. <?php
  92. HtmlHelper::renderOptions(Location::getOptions(), $document->location_id);
  93. ?>
  94. </select>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="row">
  99. <?php
  100. if($document->isSalesOrder()) {
  101. ?>
  102. <div class="col-sm-6">
  103. <div class="mb-3">
  104. <label class="form-label" for="company-id">
  105. <?=htmlspecialchars(__("Company"))?>
  106. </label>
  107. <select class="form-select" name="company_id" id="company-id" required>
  108. <option value=""><?=htmlspecialchars(__("Select Company"))?></option>
  109. <?php
  110. HtmlHelper::renderOptions(Company::getOptions(), $document->company_id);
  111. ?>
  112. </select>
  113. </div>
  114. </div>
  115. <?php
  116. }
  117. ?>
  118. <div class="col-sm-6">
  119. <div class="mb-3">
  120. <label for="date" class="form-label">
  121. <?=htmlspecialchars(__("Date"))?>
  122. </label>
  123. <input class="form-control" type="date" name="date" id="date" value="<?=$document->date?>" required />
  124. </div>
  125. </div>
  126. </div>
  127. <?php
  128. if($document->hasCosts()) {
  129. ?>
  130. <div class="row">
  131. <div class="col">
  132. <div class="mb-3">
  133. <label for="currency" class="form-label">
  134. <?=htmlspecialchars(__("Currency"))?>
  135. </label>
  136. <select class="form-select" name="currency" id="currency">
  137. <?php
  138. HtmlHelper::renderOptions(Currencies::options(), $document->currency);
  139. ?>
  140. </select>
  141. </div>
  142. </div>
  143. <div class="col">
  144. <div class="mb-3">
  145. <label for="tax-rate" class="form-label">
  146. <?=htmlspecialchars(__("Tax Rate (%)"))?>
  147. </label>
  148. <input type="number" class="form-control" name="tax_rate" id="tax-rate" min="0" step="0.01" value="<?=htmlspecialchars($document->tax_rate)?>" placeholder="<?=htmlspecialchars(__("Type tax rate"))?>" required />
  149. </div>
  150. </div>
  151. </div>
  152. <?php
  153. }
  154. if($document->hasCosts() || $document->isDeliveryNote()) {
  155. ?>
  156. <div class="row">
  157. <div class="col-sm-6">
  158. <div class="mb-3">
  159. <label for="billing-address" class="form-label">
  160. <?=htmlspecialchars(__("Billing Address"))?>
  161. </label>
  162. <textarea class="form-control" name="billing_address" id="billing-address" rows="6" placeholder="<?=htmlspecialchars(__("Type billing address"))?>" required><?=htmlspecialchars($document->billing_address)?></textarea>
  163. </div>
  164. </div>
  165. <div class="col-sm-6">
  166. <div class="mb-3">
  167. <label for="delivery-address" class="form-label">
  168. <?=htmlspecialchars(__("Delivery Address"))?>
  169. </label>
  170. <textarea class="form-control" name="delivery_address" id="delivery-address" rows="6" placeholder="<?=htmlspecialchars(__("Type delivery address"))?>"><?=htmlspecialchars($document->delivery_address)?></textarea>
  171. </div>
  172. </div>
  173. </div>
  174. <?php
  175. }
  176. ?>
  177. <div class="row">
  178. <?php
  179. if($document->isSalesOrder() || $document->isDeliveryNote()) {
  180. ?>
  181. <div class="col-sm-6">
  182. <div class="mb-3">
  183. <label for="po-number" class="form-label">
  184. <?=htmlspecialchars(__("PO Number"))?>
  185. </label>
  186. <input type="text" class="form-control" name="po_number" id="po-number" placeholder="<?=htmlspecialchars(__("Type PO number"))?>" value="<?=htmlspecialchars($document->po_number)?>" />
  187. </div>
  188. </div>
  189. <?php
  190. }
  191. if($document->isSalesOrder()) {
  192. ?>
  193. <div class="col-sm-6">
  194. <div class="mb-3">
  195. <label for="terms" class="form-label">
  196. <?=htmlspecialchars(__("Terms"))?>
  197. </label>
  198. <input type="text" class="form-control" name="terms" id="terms" placeholder="<?=htmlspecialchars(__("Type terms"))?>" value="<?=htmlspecialchars($document->terms)?>" />
  199. </div>
  200. </div>
  201. <div class="col-sm-6">
  202. <div class="mb-3">
  203. <label for="vat-number" class="form-label">
  204. <?=htmlspecialchars(__("VAT No."))?>
  205. </label>
  206. <input type="text" class="form-control" name="vat_number" id="vat-number" placeholder="<?=htmlspecialchars(__("Type VAT no."))?>" value="<?=htmlspecialchars($document->vat_number)?>" maxlength="32" />
  207. </div>
  208. </div>
  209. <?php
  210. }
  211. ?>
  212. </div>
  213. <div class="mb-3">
  214. <label for="notes" class="form-label">
  215. <?=htmlspecialchars(__("Internal Notes"))?>
  216. </label>
  217. <textarea class="form-control" name="notes" id="notes" rows="3" placeholder="<?=htmlspecialchars(__("Type notes"))?>"><?=htmlspecialchars($document->notes)?></textarea>
  218. </div>
  219. <?php
  220. if($document->isSalesOrder()) {
  221. ?>
  222. <div class="mb-3">
  223. <label for="proforma-notes" class="form-label">
  224. <?=htmlspecialchars(__("Proforma Invoice Notes"))?>
  225. </label>
  226. <textarea class="form-control" name="proforma_notes" id="proforma-notes" rows="3" placeholder="<?=htmlspecialchars(__("Type notes"))?>"><?=htmlspecialchars($document->proforma_notes)?></textarea>
  227. </div>
  228. <div class="mb-3">
  229. <label for="commercial-notes" class="form-label">
  230. <?=htmlspecialchars(__("Commercial Invoice Notes"))?>
  231. </label>
  232. <textarea class="form-control" name="commercial_notes" id="commercial-notes" rows="3" placeholder="<?=htmlspecialchars(__("Type notes"))?>"><?=htmlspecialchars($document->commercial_notes)?></textarea>
  233. </div>
  234. <?php
  235. }
  236. ?>
  237. </div>
  238. <div class="col-xl-4">
  239. <div class="row">
  240. <div class="col-sm-6 col-xl-12">
  241. <?php
  242. $root_document = $document->getRootDocument();
  243. View::include("related_items_section", [
  244. "sale" => $root_document->getSale(),
  245. "document" => $root_document,
  246. "current" => $document
  247. ]);
  248. ?>
  249. </div>
  250. <div class="col-sm-6 col-xl-12">
  251. <section class="mb-4">
  252. <h4><?=htmlspecialchars(__("Additional Details"))?></h4>
  253. <?php
  254. if($document->isSalesOrder()) {
  255. ?>
  256. <div class="mb-3">
  257. <label for="dts-finalised" class="form-label">
  258. <?=htmlspecialchars(__("Date/Time Finalised"))?>
  259. </label>
  260. <input class="form-control" type="datetime-local" name="dts_finalised" id="dts-finalised" value="<?=$document->dts_finalised?>" />
  261. </div>
  262. <div class="mb-3">
  263. <label for="dts-paid" class="form-label">
  264. <?=htmlspecialchars(__("Date/Time Paid"))?>
  265. </label>
  266. <input class="form-control" type="datetime-local" name="dts_paid" id="dts-paid" value="<?=$document->dts_paid?>" />
  267. </div>
  268. <?php
  269. }
  270. ?>
  271. <div class="mb-3">
  272. <label for="delivery-company" class="form-label">
  273. <?=htmlspecialchars(__("Delivery Company"))?>
  274. </label>
  275. <input type="text" class="form-control" name="delivery_company" id="delivery-company" placeholder="<?=htmlspecialchars(__("Type delivery company"))?>" value="<?=htmlspecialchars($document->delivery_company)?>" list="delivery-company-options" />
  276. <datalist id="delivery-company-options">
  277. <option value="Royal Mail"></option>
  278. <option value="FedEx"></option>
  279. <option value="DHL"></option>
  280. <option value="UPS"></option>
  281. <option value="Palletways"></option>
  282. <option value="Evri"></option>
  283. <option value="Hermes"></option>
  284. <option value="Other"></option>
  285. </datalist>
  286. </div>
  287. <div class="mb-3">
  288. <label for="tracking-number" class="form-label">
  289. <?=htmlspecialchars(__("Tracking Number"))?>
  290. </label>
  291. <input type="text" class="form-control" name="tracking_number" id="tracking-number" placeholder="<?=htmlspecialchars(__("Type tracking number"))?>" value="<?=htmlspecialchars($document->tracking_number)?>" />
  292. </div>
  293. <?php
  294. if($document->isDeliveryNote() && $document->isPartOfAru()) {
  295. ?>
  296. <div class="mb-3">
  297. <label for="delivery-cost" class="form-label">
  298. <?=htmlspecialchars(__("Delivery Cost"))?>
  299. </label>
  300. <input type="number" class="form-control" name="delivery_cost" id="delivery-cost" placeholder="<?=htmlspecialchars(__("Type delivery cost"))?>" value="<?=htmlspecialchars($document->delivery_cost)?>" min="0" required />
  301. </div>
  302. <?php
  303. }
  304. ?>
  305. <div class="mb-3">
  306. <label for="contact-name" class="form-label">
  307. <?=htmlspecialchars(__("Contact Name"))?>
  308. </label>
  309. <input type="text" class="form-control" name="contact_name" id="contact-name" placeholder="<?=htmlspecialchars(__("Type contact name"))?>" value="<?=htmlspecialchars($document->contact_name)?>" />
  310. </div>
  311. <div class="mb-3">
  312. <label for="contact-phone" class="form-label">
  313. <?=htmlspecialchars(__("Contact Phone / Mobile"))?>
  314. </label>
  315. <input type="tel" class="form-control" name="contact_phone" id="contact-phone" placeholder="<?=htmlspecialchars(__("Type contact phone or mobile number"))?>" value="<?=htmlspecialchars($document->contact_phone)?>" />
  316. </div>
  317. <div class="mb-3">
  318. <label for="contact-email" class="form-label">
  319. <?=htmlspecialchars(__("Contact Email Address"))?>
  320. </label>
  321. <input type="text" class="form-control" name="contact_email" id="contact-email" placeholder="<?=htmlspecialchars(__("Type contact email address"))?>" value="<?=htmlspecialchars($document->contact_email)?>" />
  322. </div>
  323. <dl>
  324. <dt><?=htmlspecialchars(__("Created By"))?></dt>
  325. <dd><?=htmlspecialchars($document->getUser()->getDisplayName())?></dd>
  326. <dt><?=htmlspecialchars(__("Date/Time Created"))?></dt>
  327. <dd><?=htmlspecialchars($user->formatDateTime($document->getDateTimeCreated()))?></dd>
  328. </dl>
  329. </section>
  330. </div>
  331. </div>
  332. </div>
  333. </div>
  334. <button type="submit" class="btn btn-primary">
  335. <i class="fa fa-fw fa-save"></i>
  336. <?=htmlspecialchars(__("Save"))?>
  337. </button>
  338. <?php
  339. if($document->isSalesOrder()) {
  340. ?>
  341. <div class="btn-group">
  342. <a class="btn btn-primary pdf-action" href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" target="_blank" class="dropdown-item pdf-action">
  343. <i class="fa fa-fw fa-file-invoice"></i>
  344. <?=htmlspecialchars(__("Proforma Invoice PDF"))?>
  345. </a>
  346. <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  347. <span class="visually-hidden"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
  348. </button>
  349. <div class="dropdown-menu dropdown-menu-end">
  350. <button type="button" class="dropdown-item email-pdf-action"><?=htmlspecialchars(__("Email PDF"))?></button>
  351. </div>
  352. </div>
  353. <div class="btn-group">
  354. <a class="btn btn-primary pdf-action" href="<?=htmlspecialchars($document->getDownloadPdfUrl("commercial"))?>" target="_blank" class="dropdown-item pdf-action">
  355. <i class="fa fa-fw fa-file-invoice"></i>
  356. <?=htmlspecialchars(__("Commercial Invoice PDF"))?>
  357. </a>
  358. <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  359. <span class="visually-hidden"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
  360. </button>
  361. <div class="dropdown-menu dropdown-menu-end">
  362. <button type="button" class="dropdown-item email-pdf-action" data-variant="commercial"><?=htmlspecialchars(__("Email PDF"))?></button>
  363. </div>
  364. </div>
  365. <?php
  366. }
  367. else {
  368. ?>
  369. <div class="btn-group">
  370. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" class="btn btn-primary pdf-action" target="_blank">
  371. <i class="fa fa-fw fa-file-pdf"></i>
  372. <?=htmlspecialchars(__("%s PDF", $document->getDisplayType()))?>
  373. </a>
  374. <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  375. <span class="visually-hidden"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
  376. </button>
  377. <div class="dropdown-menu dropdown-menu-end">
  378. <button type="button" class="dropdown-item email-pdf-action"><?=htmlspecialchars(__("Email PDF"))?></button>
  379. </div>
  380. </div>
  381. <?php
  382. }
  383. ?>
  384. </form>
  385. </section>
  386. <?php
  387. View::include("document_items_section", ["document" => $document]);
  388. if($document->isSalesOrder() && !$document->isPartOfAru()) {
  389. $delivery_notes = $document->getDeliveryNotes();
  390. ?>
  391. <div class="row mb-3">
  392. <div class="col">
  393. </div>
  394. <h3><?=htmlspecialchars(__("Delivery Notes"))?></h3>
  395. </div>
  396. <?php
  397. if(!$delivery_notes) {
  398. HtmlHelper::renderInfoAlert(__("No delivery notes to display."));
  399. }
  400. else {
  401. ?>
  402. <table class="table table-bordered">
  403. <colgroup>
  404. <col style="width: 1%"/>
  405. <col style="width: 15%"/>
  406. <col style="width: 15%"/>
  407. <col style="width: 45%"/>
  408. <col style="width: 15%"/>
  409. <col style="width: 10%"/>
  410. <col style="width: 1%"/>
  411. </colgroup>
  412. <thead>
  413. <tr>
  414. <th><?=htmlspecialchars(__("No."))?></th>
  415. <th><?=htmlspecialchars(__("Delivery Company"))?></th>
  416. <th><?=htmlspecialchars(__("Tracking Number"))?></th>
  417. <th><?=htmlspecialchars(__("Item"))?></th>
  418. <th><?=htmlspecialchars(__("S/N"))?></th>
  419. <th><?=htmlspecialchars(__("Qty"))?></th>
  420. <th><?=htmlspecialchars(__("Actions"))?></th>
  421. </tr>
  422. </thead>
  423. <tbody>
  424. <?php
  425. foreach($delivery_notes as $index => $delivery_note) {
  426. $items = $delivery_note->getItems();
  427. $rowspan = count($items) ?: 1;
  428. $item = array_shift($items);
  429. $row_class = ($index % 2) ? "table-light" : "";
  430. ?>
  431. <tr class="<?=$row_class?>">
  432. <td class="text-end" rowspan="<?=$rowspan?>">
  433. <a href="<?=htmlspecialchars($delivery_note->getUrl())?>"><?=$delivery_note->number?></a>
  434. </td>
  435. <td rowspan="<?=$rowspan?>">
  436. <?=htmlspecialchars($delivery_note->delivery_company)?>
  437. </td>
  438. <td rowspan="<?=$rowspan?>">
  439. <?=htmlspecialchars($delivery_note->tracking_number)?>
  440. </td>
  441. <td>
  442. <?=htmlspecialchars($item->description ?? "")?>
  443. </td>
  444. <td>
  445. <?=$item->getSerialNumberHtml()?>
  446. </td>
  447. <td class="text-end">
  448. <?=htmlspecialchars($item->quantity ?? "")?>
  449. </td>
  450. <td class="p-1" rowspan="<?=$rowspan?>">
  451. <a href="<?=htmlspecialchars($delivery_note->getUrl())?>" class="btn btn-sm btn-primary">
  452. <?=htmlspecialchars(__("View"))?>
  453. </a>
  454. </td>
  455. </tr>
  456. <?php
  457. foreach($items as $item) {
  458. ?>
  459. <tr class="<?=$row_class?>">
  460. <td>
  461. <?=htmlspecialchars($item->description)?>
  462. </td>
  463. <td>
  464. <?=$item->getSerialNumberHtml()?>
  465. </td>
  466. <td class="text-end">
  467. <?=htmlspecialchars($item->quantity)?>
  468. </td>
  469. </tr>
  470. <?php
  471. }
  472. }
  473. ?>
  474. </tbody>
  475. </table>
  476. <?php
  477. }
  478. }