document.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. </div>
  302. <div class="col-xl-4">
  303. <div class="row">
  304. <div class="col-sm-6 col-xl-12">
  305. <?php
  306. $root_document = $document->getRootDocument();
  307. View::include("related_items_section", [
  308. "sale" => $root_document->getSale(),
  309. "document" => $root_document,
  310. "current" => $document
  311. ]);
  312. ?>
  313. </div>
  314. <div class="col-sm-6 col-xl-12">
  315. <section class="mb-4">
  316. <h4><?=htmlspecialchars(__("Additional Details"))?></h4>
  317. <div class="mb-3">
  318. <label for="delivery-company" class="form-label">
  319. <?=htmlspecialchars(__("Delivery Company"))?>
  320. </label>
  321. <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" />
  322. <datalist id="delivery-company-options">
  323. <option value="Royal Mail"></option>
  324. <option value="FedEx"></option>
  325. <option value="DHL"></option>
  326. <option value="UPS"></option>
  327. <option value="Palletways"></option>
  328. <option value="Evri"></option>
  329. <option value="Hermes"></option>
  330. <option value="Other"></option>
  331. </datalist>
  332. </div>
  333. <div class="mb-3">
  334. <label for="tracking-number" class="form-label">
  335. <?=htmlspecialchars(__("Tracking Number"))?>
  336. </label>
  337. <input type="text" class="form-control" name="tracking_number" id="tracking-number" placeholder="<?=htmlspecialchars(__("Type tracking number"))?>" value="<?=htmlspecialchars($document->tracking_number)?>" />
  338. </div>
  339. <?php
  340. if($document->isDeliveryNote() && $document->isPartOfAru()) {
  341. ?>
  342. <div class="mb-3">
  343. <label for="delivery-cost" class="form-label">
  344. <?=htmlspecialchars(__("Delivery Cost"))?>
  345. </label>
  346. <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 />
  347. </div>
  348. <?php
  349. }
  350. ?>
  351. <dl>
  352. <dt><?=htmlspecialchars(__("Created By"))?></dt>
  353. <dd><?=htmlspecialchars($document->getUser()->getDisplayName())?></dd>
  354. <dt><?=htmlspecialchars(__("Date/Time Created"))?></dt>
  355. <dd><?=htmlspecialchars($user->formatDateTime($document->getDateTimeCreated()))?></dd>
  356. </dl>
  357. </section>
  358. </div>
  359. </div>
  360. </div>
  361. </div>
  362. <button type="submit" class="btn btn-primary">
  363. <i class="fa fa-fw fa-save"></i>
  364. <?=htmlspecialchars(__("Save"))?>
  365. </button>
  366. <?php
  367. if($document->isSalesOrder()) {
  368. ?>
  369. <div class="btn-group">
  370. <a class="btn btn-primary pdf-action" href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" target="_blank" class="dropdown-item pdf-action">
  371. <i class="fa fa-fw fa-file-invoice"></i>
  372. <?=htmlspecialchars(__("Proforma Invoice PDF"))?>
  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. <div class="btn-group">
  382. <a class="btn btn-primary pdf-action" href="<?=htmlspecialchars($document->getDownloadPdfUrl("commercial"))?>" target="_blank" class="dropdown-item pdf-action">
  383. <i class="fa fa-fw fa-file-invoice"></i>
  384. <?=htmlspecialchars(__("Commercial Invoice PDF"))?>
  385. </a>
  386. <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  387. <span class="visually-hidden"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
  388. </button>
  389. <div class="dropdown-menu dropdown-menu-end">
  390. <button type="button" class="dropdown-item email-pdf-action" data-variant="commercial"><?=htmlspecialchars(__("Email PDF"))?></button>
  391. </div>
  392. </div>
  393. <?php
  394. }
  395. else {
  396. ?>
  397. <div class="btn-group">
  398. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" class="btn btn-primary pdf-action" target="_blank">
  399. <i class="fa fa-fw fa-file-pdf"></i>
  400. <?=htmlspecialchars(__("%s PDF", $document->getDisplayType()))?>
  401. </a>
  402. <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  403. <span class="visually-hidden"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
  404. </button>
  405. <div class="dropdown-menu dropdown-menu-end">
  406. <button type="button" class="dropdown-item email-pdf-action"><?=htmlspecialchars(__("Email PDF"))?></button>
  407. </div>
  408. </div>
  409. <?php
  410. }
  411. ?>
  412. </form>
  413. </section>
  414. <?php
  415. View::include("document_items_section", ["document" => $document]);
  416. if($document->isSalesOrder() && !$document->isPartOfAru()) {
  417. $delivery_notes = $document->getDeliveryNotes();
  418. ?>
  419. <div class="row mb-3">
  420. <div class="col">
  421. </div>
  422. <h3><?=htmlspecialchars(__("Delivery Notes"))?></h3>
  423. </div>
  424. <?php
  425. if(!$delivery_notes) {
  426. HtmlHelper::renderInfoAlert(__("No delivery notes to display."));
  427. }
  428. else {
  429. ?>
  430. <table class="table table-bordered">
  431. <colgroup>
  432. <col style="width: 1%"/>
  433. <col style="width: 15%"/>
  434. <col style="width: 15%"/>
  435. <col style="width: 45%"/>
  436. <col style="width: 15%"/>
  437. <col style="width: 10%"/>
  438. <col style="width: 1%"/>
  439. </colgroup>
  440. <thead>
  441. <tr>
  442. <th><?=htmlspecialchars(__("No."))?></th>
  443. <th><?=htmlspecialchars(__("Delivery Company"))?></th>
  444. <th><?=htmlspecialchars(__("Tracking Number"))?></th>
  445. <th><?=htmlspecialchars(__("Item"))?></th>
  446. <th><?=htmlspecialchars(__("S/N"))?></th>
  447. <th><?=htmlspecialchars(__("Qty"))?></th>
  448. <th><?=htmlspecialchars(__("Actions"))?></th>
  449. </tr>
  450. </thead>
  451. <tbody>
  452. <?php
  453. foreach($delivery_notes as $index => $delivery_note) {
  454. $items = $delivery_note->getItems();
  455. $rowspan = count($items) ?: 1;
  456. $item = array_shift($items);
  457. $row_class = ($index % 2) ? "table-light" : "";
  458. ?>
  459. <tr class="<?=$row_class?>">
  460. <td class="text-end" rowspan="<?=$rowspan?>">
  461. <a href="<?=htmlspecialchars($delivery_note->getUrl())?>"><?=$delivery_note->number?></a>
  462. </td>
  463. <td rowspan="<?=$rowspan?>">
  464. <?=htmlspecialchars($delivery_note->delivery_company)?>
  465. </td>
  466. <td rowspan="<?=$rowspan?>">
  467. <?=htmlspecialchars($delivery_note->tracking_number)?>
  468. </td>
  469. <td>
  470. <?=htmlspecialchars($item->description ?? "")?>
  471. </td>
  472. <td>
  473. <?=$item->getSerialNumberHtml()?>
  474. </td>
  475. <td class="text-end">
  476. <?=htmlspecialchars($item->quantity ?? "")?>
  477. </td>
  478. <td class="p-1" rowspan="<?=$rowspan?>">
  479. <a href="<?=htmlspecialchars($delivery_note->getUrl())?>" class="btn btn-sm btn-primary">
  480. <?=htmlspecialchars(__("View"))?>
  481. </a>
  482. </td>
  483. </tr>
  484. <?php
  485. foreach($items as $item) {
  486. ?>
  487. <tr class="<?=$row_class?>">
  488. <td>
  489. <?=htmlspecialchars($item->description)?>
  490. </td>
  491. <td>
  492. <?=$item->getSerialNumberHtml()?>
  493. </td>
  494. <td class="text-end">
  495. <?=htmlspecialchars($item->quantity)?>
  496. </td>
  497. </tr>
  498. <?php
  499. }
  500. }
  501. ?>
  502. </tbody>
  503. </table>
  504. <?php
  505. }
  506. }