document.php 18 KB

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