document.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Enums\AruStatuses;
  4. use App\Enums\Currencies;
  5. use App\Enums\SaleOrderStatuses;
  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>
  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="row">
  45. <?php
  46. if($document->isSaleOrder()) {
  47. ?>
  48. <div class="col-sm-6">
  49. <div class="mb-3">
  50. <div class="row">
  51. <div class="col">
  52. <label for="invoice-status" class="form-label">
  53. <b><?=htmlspecialchars(__("Status"))?></b>
  54. </label>
  55. </div>
  56. <div class="col-auto">
  57. <span class="badge rounded-pill text-bg-danger">
  58. <?=htmlspecialchars(__("Important"))?>
  59. </span>
  60. </div>
  61. </div>
  62. <select class="form-control" name="invoice_status" id="invoice-status">
  63. <?php
  64. HtmlHelper::renderOptions(SaleOrderStatuses::options(), $document->invoice_status);
  65. ?>
  66. </select>
  67. </div>
  68. </div>
  69. <?php
  70. }
  71. if($document->isAru()) {
  72. ?>
  73. <div class="col-sm-6">
  74. <div class="mb-3">
  75. <div class="row">
  76. <div class="col">
  77. <label for="aru-status" class="form-label">
  78. <b><?=htmlspecialchars(__("Status"))?></b>
  79. </label>
  80. </div>
  81. <div class="col-auto">
  82. <span class="badge rounded-pill text-bg-danger">
  83. <?=htmlspecialchars(__("Important"))?>
  84. </span>
  85. </div>
  86. </div>
  87. <select class="form-control" name="aru_status" id="aru-status">
  88. <?php
  89. HtmlHelper::renderOptions(AruStatuses::options(), $document->aru_status);
  90. ?>
  91. </select>
  92. </div>
  93. </div>
  94. <?php
  95. }
  96. ?>
  97. <div class="col-sm-6">
  98. <div class="mb-3">
  99. <label for="date" class="form-label">
  100. <?=htmlspecialchars(__("Date"))?>
  101. </label>
  102. <input class="form-control" type="date" name="date" id="date" value="<?=$document->date?>" required />
  103. </div>
  104. </div>
  105. </div>
  106. <?php
  107. if($document->hasCosts()) {
  108. ?>
  109. <div class="row">
  110. <div class="col">
  111. <div class="mb-3">
  112. <label for="currency" class="form-label">
  113. <?=htmlspecialchars(__("Currency"))?>
  114. </label>
  115. <select class="form-control" name="currency" id="currency">
  116. <?php
  117. HtmlHelper::renderOptions(Currencies::options(), $document->currency);
  118. ?>
  119. </select>
  120. </div>
  121. </div>
  122. <div class="col">
  123. <div class="mb-3">
  124. <label for="tax-rate" class="form-label">
  125. <?=htmlspecialchars(__("Tax Rate (%)"))?>
  126. </label>
  127. <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 />
  128. </div>
  129. </div>
  130. </div>
  131. <?php
  132. }
  133. if($document->hasCosts() || $document->isDeliveryNote()) {
  134. ?>
  135. <div class="row">
  136. <div class="col-sm-6">
  137. <div class="mb-3">
  138. <label for="billing-address" class="form-label">
  139. <?=htmlspecialchars(__("Billing Address"))?>
  140. </label>
  141. <textarea class="form-control" name="billing_address" id="billing-address" rows="6" placeholder="<?=htmlspecialchars(__("Type billing address"))?>" required><?=htmlspecialchars($document->billing_address)?></textarea>
  142. </div>
  143. </div>
  144. <div class="col-sm-6">
  145. <div class="mb-3">
  146. <label for="delivery-address" class="form-label">
  147. <?=htmlspecialchars(__("Delivery Address"))?>
  148. </label>
  149. <textarea class="form-control" name="delivery_address" id="delivery-address" rows="6" placeholder="<?=htmlspecialchars(__("Type delivery address"))?>"><?=htmlspecialchars($document->delivery_address)?></textarea>
  150. </div>
  151. </div>
  152. </div>
  153. <?php
  154. }
  155. ?>
  156. <div class="row">
  157. <?php
  158. if($document->isSaleOrder() || $document->isDeliveryNote()) {
  159. ?>
  160. <div class="col-sm-6">
  161. <div class="mb-3">
  162. <label for="po-number" class="form-label">
  163. <?=htmlspecialchars(__("PO Number"))?>
  164. </label>
  165. <input type="text" class="form-control" name="po_number" id="po-number" placeholder="<?=htmlspecialchars(__("Type PO number"))?>" value="<?=htmlspecialchars($document->po_number)?>" />
  166. </div>
  167. </div>
  168. <?php
  169. }
  170. if($document->isSaleOrder()) {
  171. ?>
  172. <div class="col-sm-6">
  173. <div class="mb-3">
  174. <label for="terms" class="form-label">
  175. <?=htmlspecialchars(__("Terms"))?>
  176. </label>
  177. <input type="text" class="form-control" name="terms" id="terms" placeholder="<?=htmlspecialchars(__("Type terms"))?>" value="<?=htmlspecialchars($document->terms)?>" />
  178. </div>
  179. </div>
  180. <?php
  181. }
  182. ?>
  183. </div>
  184. <div class="mb-3">
  185. <label for="notes" class="form-label">
  186. <?=htmlspecialchars(__("Notes"))?>
  187. </label>
  188. <textarea class="form-control" name="notes" id="notes" rows="6" placeholder="<?=htmlspecialchars(__("Type notes"))?>"><?=htmlspecialchars($document->notes)?></textarea>
  189. </div>
  190. </div>
  191. <div class="col-xl-4">
  192. <h4><?=htmlspecialchars(__("Additional Details"))?></h4>
  193. <?php
  194. if($document->isSaleOrder()) {
  195. ?>
  196. <div class="mb-3">
  197. <label for="dts-finalised" class="form-label">
  198. <?=htmlspecialchars(__("Date/Time Finalised"))?>
  199. </label>
  200. <input class="form-control" type="datetime-local" name="dts_finalised" id="dts-finalised" value="<?=$document->dts_finalised?>" />
  201. </div>
  202. <div class="mb-3">
  203. <label for="dts-paid" class="form-label">
  204. <?=htmlspecialchars(__("Date/Time Paid"))?>
  205. </label>
  206. <input class="form-control" type="datetime-local" name="dts_paid" id="dts-paid" value="<?=$document->dts_paid?>" />
  207. </div>
  208. <?php
  209. }
  210. ?>
  211. <div class="mb-3">
  212. <label for="delivery-company" class="form-label">
  213. <?=htmlspecialchars(__("Delivery Company"))?>
  214. </label>
  215. <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" />
  216. <datalist id="delivery-company-options">
  217. <option value="Royal Mail"></option>
  218. <option value="FedEx"></option>
  219. <option value="DHL"></option>
  220. <option value="UPS"></option>
  221. <option value="Palletways"></option>
  222. <option value="Evri"></option>
  223. <option value="Hermes"></option>
  224. <option value="Other"></option>
  225. </datalist>
  226. </div>
  227. <div class="mb-3">
  228. <label for="tracking-number" class="form-label">
  229. <?=htmlspecialchars(__("Tracking Number"))?>
  230. </label>
  231. <input type="text" class="form-control" name="tracking_number" id="tracking-number" placeholder="<?=htmlspecialchars(__("Type tracking number"))?>" value="<?=htmlspecialchars($document->tracking_number)?>" />
  232. </div>
  233. <?php
  234. if($document->isDeliveryNote() && $document->isPartOfAru()) {
  235. ?>
  236. <div class="mb-3">
  237. <label for="delivery-cost" class="form-label">
  238. <?=htmlspecialchars(__("Delivery Cost"))?>
  239. </label>
  240. <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 />
  241. </div>
  242. <?php
  243. }
  244. ?>
  245. <div class="mb-3">
  246. <label for="contact-name" class="form-label">
  247. <?=htmlspecialchars(__("Contact Name"))?>
  248. </label>
  249. <input type="text" class="form-control" name="contact_name" id="contact-name" placeholder="<?=htmlspecialchars(__("Type contact name"))?>" value="<?=htmlspecialchars($document->contact_name)?>" />
  250. </div>
  251. <div class="mb-3">
  252. <label for="contact-phone" class="form-label">
  253. <?=htmlspecialchars(__("Contact Phone / Mobile"))?>
  254. </label>
  255. <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)?>" />
  256. </div>
  257. <div class="mb-3">
  258. <label for="contact-email" class="form-label">
  259. <?=htmlspecialchars(__("Contact Email Address"))?>
  260. </label>
  261. <input type="text" class="form-control" name="contact_email" id="contact-email" placeholder="<?=htmlspecialchars(__("Type contact email address"))?>" value="<?=htmlspecialchars($document->contact_email)?>" />
  262. </div>
  263. <div class="mb-3">
  264. <label class="form-label" for="company-id">
  265. <?=htmlspecialchars(__("Company"))?>
  266. </label>
  267. <select class="form-control" name="company_id" id="company-id" required>
  268. <option value=""><?=htmlspecialchars(__("Select Company"))?></option>
  269. <?php
  270. HtmlHelper::renderOptions(Company::getOptions(), $document->company_id);
  271. ?>
  272. </select>
  273. </div>
  274. <dl>
  275. <?php
  276. if($document->isAru()) {
  277. $tickets = $document->getTickets();
  278. if($tickets) {
  279. ?>
  280. <dt><?=htmlspecialchars(__("Related Tickets"))?></dt>
  281. <dd>
  282. <?php
  283. foreach($tickets as $ticket) {
  284. ?>
  285. <a href="<?=htmlspecialchars($ticket->getUrl())?>"><?=htmlspecialchars(__("Ticket %d - %s", $ticket->id, $ticket->subject))?></a>
  286. <?php
  287. }
  288. ?>
  289. </dd>
  290. <?php
  291. }
  292. }
  293. ?>
  294. <dt><?=htmlspecialchars(__("Created By"))?></dt>
  295. <dd><?=htmlspecialchars($document->getUser()->getDisplayName())?></dd>
  296. <dt><?=htmlspecialchars(__("Date/Time Created"))?></dt>
  297. <dd><?=htmlspecialchars($user->formatDateTime($document->getDateTimeCreated()))?></dd>
  298. <?php
  299. if($location) {
  300. ?>
  301. <dt><?=htmlspecialchars(__("Location"))?></dt>
  302. <dd>
  303. <a href="<?=htmlspecialchars($location->getUrl())?>"><?=htmlspecialchars($location->getDisplayName())?></a>
  304. </dd>
  305. <?php
  306. }
  307. if($document->hasCosts()) {
  308. $delivery_notes = $document->getDeliveryNotes();
  309. if($delivery_notes) {
  310. ?>
  311. <dt><?=htmlspecialchars(__("Delivery Notes"))?></dt>
  312. <dd>
  313. <?php
  314. foreach($delivery_notes as $delivery_note) {
  315. ?>
  316. <a href="<?=htmlspecialchars($delivery_note->getUrl())?>">
  317. <?=htmlspecialchars($delivery_note->getTitle())?>
  318. </a><br />
  319. <?php
  320. }
  321. ?>
  322. </dd>
  323. <?php
  324. }
  325. $sale_orders = $document->getSaleOrders();
  326. if($sale_orders) {
  327. ?>
  328. <dt><?=htmlspecialchars(__("Sale Orders"))?></dt>
  329. <dd>
  330. <?php
  331. foreach($sale_orders as $sale_order) {
  332. ?>
  333. <a href="<?=htmlspecialchars($sale_order->getUrl())?>">
  334. <?=htmlspecialchars($sale_order->getTitle())?>
  335. </a><br />
  336. <?php
  337. }
  338. ?>
  339. </dd>
  340. <?php
  341. }
  342. }
  343. ?>
  344. </dl>
  345. </div>
  346. </div>
  347. <button type="submit" class="btn btn-primary">
  348. <i class="fa fa-fw fa-save"></i>
  349. <?=htmlspecialchars(__("Save"))?>
  350. </button>
  351. <?php
  352. if($document->isSaleOrder()) {
  353. ?>
  354. <div class="dropdown d-inline-block">
  355. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  356. <i class="fa fa-fw fa-file-pdf"></i>
  357. <?=htmlspecialchars(__("Download PDF"))?>
  358. </button>
  359. <div class="dropdown-menu">
  360. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" target="_blank" class="dropdown-item pdf-action"><?=htmlspecialchars(__("Proforma Invoice"))?></a>
  361. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl("commercial"))?>" target="_blank" class="dropdown-item pdf-action"><?=htmlspecialchars(__("Commercial Invoice"))?></a>
  362. </div>
  363. </div>
  364. <?php
  365. }
  366. else {
  367. ?>
  368. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" class="btn btn-primary pdf-action" target="_blank">
  369. <i class="fa fa-fw fa-file-pdf"></i>
  370. <?=htmlspecialchars(__("Download PDF"))?>
  371. </a>
  372. <?php
  373. }
  374. ?>
  375. </form>
  376. </section>
  377. <?php
  378. View::include("document_items_section", ["document" => $document]);