document.php 18 KB

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