document.php 16 KB

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