document.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. <div class="row">
  128. <div class="col-sm-6">
  129. <div class="mb-3">
  130. <label for="contact-name" class="form-label">
  131. <?=htmlspecialchars(__("Contact Name"))?>
  132. </label>
  133. <input type="text" class="form-control" name="contact_name" id="contact-name" placeholder="<?=htmlspecialchars(__("Type contact name"))?>" value="<?=htmlspecialchars($document->contact_name)?>" />
  134. </div>
  135. </div>
  136. <div class="col-sm-6">
  137. <div class="mb-3">
  138. <label for="contact-phone" class="form-label">
  139. <?=htmlspecialchars(__("Contact Phone / Mobile"))?>
  140. </label>
  141. <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)?>" />
  142. </div>
  143. </div>
  144. <div class="col-sm-6">
  145. <div class="mb-3">
  146. <label for="contact-email" class="form-label">
  147. <?=htmlspecialchars(__("Contact Email Address"))?>
  148. </label>
  149. <input type="text" class="form-control" name="contact_email" id="contact-email" placeholder="<?=htmlspecialchars(__("Type contact email address"))?>" value="<?=htmlspecialchars($document->contact_email)?>" />
  150. </div>
  151. </div>
  152. </div>
  153. <?php
  154. if($document->hasCosts()) {
  155. ?>
  156. <div class="row">
  157. <div class="col">
  158. <div class="mb-3">
  159. <label for="currency" class="form-label">
  160. <?=htmlspecialchars(__("Currency"))?>
  161. </label>
  162. <select class="form-select" name="currency" id="currency">
  163. <?php
  164. HtmlHelper::renderOptions(Currencies::options(), $document->currency);
  165. ?>
  166. </select>
  167. </div>
  168. </div>
  169. <div class="col">
  170. <div class="mb-3">
  171. <label for="tax-rate" class="form-label">
  172. <?=htmlspecialchars(__("Tax Rate (%)"))?>
  173. </label>
  174. <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 />
  175. </div>
  176. </div>
  177. </div>
  178. <?php
  179. }
  180. if($document->hasCosts() || $document->isDeliveryNote()) {
  181. ?>
  182. <div class="row">
  183. <div class="col-sm-6">
  184. <div class="mb-3">
  185. <label for="billing-address" class="form-label">
  186. <?=htmlspecialchars(__("Billing Address"))?>
  187. </label>
  188. <textarea class="form-control" name="billing_address" id="billing-address" rows="6" placeholder="<?=htmlspecialchars(__("Type billing address"))?>" required><?=htmlspecialchars($document->billing_address)?></textarea>
  189. </div>
  190. </div>
  191. <div class="col-sm-6">
  192. <div class="mb-3">
  193. <label for="delivery-address" class="form-label">
  194. <?=htmlspecialchars(__("Delivery Address"))?>
  195. </label>
  196. <textarea class="form-control" name="delivery_address" id="delivery-address" rows="6" placeholder="<?=htmlspecialchars(__("Type delivery address"))?>"><?=htmlspecialchars($document->delivery_address)?></textarea>
  197. </div>
  198. </div>
  199. </div>
  200. <?php
  201. }
  202. ?>
  203. <div class="row">
  204. <?php
  205. if($document->isSalesOrder() || $document->isDeliveryNote()) {
  206. ?>
  207. <div class="col-sm-6">
  208. <div class="mb-3">
  209. <label for="po-number" class="form-label">
  210. <?=htmlspecialchars(__("PO Number"))?>
  211. </label>
  212. <input type="text" class="form-control" name="po_number" id="po-number" placeholder="<?=htmlspecialchars(__("Type PO number"))?>" value="<?=htmlspecialchars($document->po_number)?>" />
  213. </div>
  214. </div>
  215. <?php
  216. }
  217. if($document->isSalesOrder()) {
  218. ?>
  219. <div class="col-sm-6">
  220. <div class="mb-3">
  221. <label for="terms" class="form-label">
  222. <?=htmlspecialchars(__("Terms"))?>
  223. </label>
  224. <input type="text" class="form-control" name="terms" id="terms" placeholder="<?=htmlspecialchars(__("Type terms"))?>" value="<?=htmlspecialchars($document->terms)?>" />
  225. </div>
  226. </div>
  227. <div class="col-sm-6">
  228. <div class="mb-3">
  229. <label for="vat-number" class="form-label">
  230. <?=htmlspecialchars(__("VAT No."))?>
  231. </label>
  232. <input type="text" class="form-control" name="vat_number" id="vat-number" placeholder="<?=htmlspecialchars(__("Type VAT no."))?>" value="<?=htmlspecialchars($document->vat_number)?>" maxlength="32" />
  233. </div>
  234. </div>
  235. <?php
  236. }
  237. ?>
  238. </div>
  239. <div class="mb-3">
  240. <label for="notes" class="form-label">
  241. <?=htmlspecialchars(__("Internal Notes"))?>
  242. </label>
  243. <textarea class="form-control" name="notes" id="notes" rows="3" placeholder="<?=htmlspecialchars(__("Type notes"))?>"><?=htmlspecialchars($document->notes)?></textarea>
  244. </div>
  245. <?php
  246. if($document->isSalesOrder()) {
  247. ?>
  248. <div class="mb-3">
  249. <label for="proforma-notes" class="form-label">
  250. <?=htmlspecialchars(__("Proforma Invoice Notes"))?>
  251. </label>
  252. <textarea class="form-control" name="proforma_notes" id="proforma-notes" rows="3" placeholder="<?=htmlspecialchars(__("Type notes"))?>"><?=htmlspecialchars($document->proforma_notes)?></textarea>
  253. </div>
  254. <div class="mb-3">
  255. <label for="commercial-notes" class="form-label">
  256. <?=htmlspecialchars(__("Commercial Invoice Notes"))?>
  257. </label>
  258. <textarea class="form-control" name="commercial_notes" id="commercial-notes" rows="3" placeholder="<?=htmlspecialchars(__("Type notes"))?>"><?=htmlspecialchars($document->commercial_notes)?></textarea>
  259. </div>
  260. <?php
  261. }
  262. ?>
  263. </div>
  264. <div class="col-xl-4">
  265. <div class="row">
  266. <div class="col-sm-6 col-xl-12">
  267. <?php
  268. $root_document = $document->getRootDocument();
  269. View::include("related_items_section", [
  270. "sale" => $root_document->getSale(),
  271. "document" => $root_document,
  272. "current" => $document
  273. ]);
  274. ?>
  275. </div>
  276. <div class="col-sm-6 col-xl-12">
  277. <section class="mb-4">
  278. <h4><?=htmlspecialchars(__("Additional Details"))?></h4>
  279. <?php
  280. if($document->isSalesOrder()) {
  281. ?>
  282. <div class="mb-3">
  283. <label for="dts-finalised" class="form-label">
  284. <?=htmlspecialchars(__("Date/Time Finalised"))?>
  285. </label>
  286. <input class="form-control" type="datetime-local" name="dts_finalised" id="dts-finalised" value="<?=$document->dts_finalised?>" />
  287. </div>
  288. <div class="mb-3">
  289. <label for="dts-paid" class="form-label">
  290. <?=htmlspecialchars(__("Date/Time Paid"))?>
  291. </label>
  292. <input class="form-control" type="datetime-local" name="dts_paid" id="dts-paid" value="<?=$document->dts_paid?>" />
  293. </div>
  294. <?php
  295. }
  296. ?>
  297. <div class="mb-3">
  298. <label for="delivery-company" class="form-label">
  299. <?=htmlspecialchars(__("Delivery Company"))?>
  300. </label>
  301. <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" />
  302. <datalist id="delivery-company-options">
  303. <option value="Royal Mail"></option>
  304. <option value="FedEx"></option>
  305. <option value="DHL"></option>
  306. <option value="UPS"></option>
  307. <option value="Palletways"></option>
  308. <option value="Evri"></option>
  309. <option value="Hermes"></option>
  310. <option value="Other"></option>
  311. </datalist>
  312. </div>
  313. <div class="mb-3">
  314. <label for="tracking-number" class="form-label">
  315. <?=htmlspecialchars(__("Tracking Number"))?>
  316. </label>
  317. <input type="text" class="form-control" name="tracking_number" id="tracking-number" placeholder="<?=htmlspecialchars(__("Type tracking number"))?>" value="<?=htmlspecialchars($document->tracking_number)?>" />
  318. </div>
  319. <?php
  320. if($document->isDeliveryNote() && $document->isPartOfAru()) {
  321. ?>
  322. <div class="mb-3">
  323. <label for="delivery-cost" class="form-label">
  324. <?=htmlspecialchars(__("Delivery Cost"))?>
  325. </label>
  326. <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 />
  327. </div>
  328. <?php
  329. }
  330. ?>
  331. <dl>
  332. <dt><?=htmlspecialchars(__("Created By"))?></dt>
  333. <dd><?=htmlspecialchars($document->getUser()->getDisplayName())?></dd>
  334. <dt><?=htmlspecialchars(__("Date/Time Created"))?></dt>
  335. <dd><?=htmlspecialchars($user->formatDateTime($document->getDateTimeCreated()))?></dd>
  336. </dl>
  337. </section>
  338. </div>
  339. </div>
  340. </div>
  341. </div>
  342. <button type="submit" class="btn btn-primary">
  343. <i class="fa fa-fw fa-save"></i>
  344. <?=htmlspecialchars(__("Save"))?>
  345. </button>
  346. <?php
  347. if($document->isSalesOrder()) {
  348. ?>
  349. <div class="btn-group">
  350. <a class="btn btn-primary pdf-action" href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" target="_blank" class="dropdown-item pdf-action">
  351. <i class="fa fa-fw fa-file-invoice"></i>
  352. <?=htmlspecialchars(__("Proforma Invoice PDF"))?>
  353. </a>
  354. <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  355. <span class="visually-hidden"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
  356. </button>
  357. <div class="dropdown-menu dropdown-menu-end">
  358. <button type="button" class="dropdown-item email-pdf-action"><?=htmlspecialchars(__("Email PDF"))?></button>
  359. </div>
  360. </div>
  361. <div class="btn-group">
  362. <a class="btn btn-primary pdf-action" href="<?=htmlspecialchars($document->getDownloadPdfUrl("commercial"))?>" target="_blank" class="dropdown-item pdf-action">
  363. <i class="fa fa-fw fa-file-invoice"></i>
  364. <?=htmlspecialchars(__("Commercial Invoice PDF"))?>
  365. </a>
  366. <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  367. <span class="visually-hidden"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
  368. </button>
  369. <div class="dropdown-menu dropdown-menu-end">
  370. <button type="button" class="dropdown-item email-pdf-action" data-variant="commercial"><?=htmlspecialchars(__("Email PDF"))?></button>
  371. </div>
  372. </div>
  373. <?php
  374. }
  375. else {
  376. ?>
  377. <div class="btn-group">
  378. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" class="btn btn-primary pdf-action" target="_blank">
  379. <i class="fa fa-fw fa-file-pdf"></i>
  380. <?=htmlspecialchars(__("%s PDF", $document->getDisplayType()))?>
  381. </a>
  382. <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  383. <span class="visually-hidden"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
  384. </button>
  385. <div class="dropdown-menu dropdown-menu-end">
  386. <button type="button" class="dropdown-item email-pdf-action"><?=htmlspecialchars(__("Email PDF"))?></button>
  387. </div>
  388. </div>
  389. <?php
  390. }
  391. ?>
  392. </form>
  393. </section>
  394. <?php
  395. View::include("document_items_section", ["document" => $document]);
  396. if($document->isSalesOrder() && !$document->isPartOfAru()) {
  397. $delivery_notes = $document->getDeliveryNotes();
  398. ?>
  399. <div class="row mb-3">
  400. <div class="col">
  401. </div>
  402. <h3><?=htmlspecialchars(__("Delivery Notes"))?></h3>
  403. </div>
  404. <?php
  405. if(!$delivery_notes) {
  406. HtmlHelper::renderInfoAlert(__("No delivery notes to display."));
  407. }
  408. else {
  409. ?>
  410. <table class="table table-bordered">
  411. <colgroup>
  412. <col style="width: 1%"/>
  413. <col style="width: 15%"/>
  414. <col style="width: 15%"/>
  415. <col style="width: 45%"/>
  416. <col style="width: 15%"/>
  417. <col style="width: 10%"/>
  418. <col style="width: 1%"/>
  419. </colgroup>
  420. <thead>
  421. <tr>
  422. <th><?=htmlspecialchars(__("No."))?></th>
  423. <th><?=htmlspecialchars(__("Delivery Company"))?></th>
  424. <th><?=htmlspecialchars(__("Tracking Number"))?></th>
  425. <th><?=htmlspecialchars(__("Item"))?></th>
  426. <th><?=htmlspecialchars(__("S/N"))?></th>
  427. <th><?=htmlspecialchars(__("Qty"))?></th>
  428. <th><?=htmlspecialchars(__("Actions"))?></th>
  429. </tr>
  430. </thead>
  431. <tbody>
  432. <?php
  433. foreach($delivery_notes as $index => $delivery_note) {
  434. $items = $delivery_note->getItems();
  435. $rowspan = count($items) ?: 1;
  436. $item = array_shift($items);
  437. $row_class = ($index % 2) ? "table-light" : "";
  438. ?>
  439. <tr class="<?=$row_class?>">
  440. <td class="text-end" rowspan="<?=$rowspan?>">
  441. <a href="<?=htmlspecialchars($delivery_note->getUrl())?>"><?=$delivery_note->number?></a>
  442. </td>
  443. <td rowspan="<?=$rowspan?>">
  444. <?=htmlspecialchars($delivery_note->delivery_company)?>
  445. </td>
  446. <td rowspan="<?=$rowspan?>">
  447. <?=htmlspecialchars($delivery_note->tracking_number)?>
  448. </td>
  449. <td>
  450. <?=htmlspecialchars($item->description ?? "")?>
  451. </td>
  452. <td>
  453. <?=$item->getSerialNumberHtml()?>
  454. </td>
  455. <td class="text-end">
  456. <?=htmlspecialchars($item->quantity ?? "")?>
  457. </td>
  458. <td class="p-1" rowspan="<?=$rowspan?>">
  459. <a href="<?=htmlspecialchars($delivery_note->getUrl())?>" class="btn btn-sm btn-primary">
  460. <?=htmlspecialchars(__("View"))?>
  461. </a>
  462. </td>
  463. </tr>
  464. <?php
  465. foreach($items as $item) {
  466. ?>
  467. <tr class="<?=$row_class?>">
  468. <td>
  469. <?=htmlspecialchars($item->description)?>
  470. </td>
  471. <td>
  472. <?=$item->getSerialNumberHtml()?>
  473. </td>
  474. <td class="text-end">
  475. <?=htmlspecialchars($item->quantity)?>
  476. </td>
  477. </tr>
  478. <?php
  479. }
  480. }
  481. ?>
  482. </tbody>
  483. </table>
  484. <?php
  485. }
  486. }