document.php 13 KB

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