document.php 16 KB

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