document.php 16 KB

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