document.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Enums\Currencies;
  4. use App\Enums\DocumentTypes;
  5. use App\Enums\InvoiceStatuses;
  6. use App\Helpers\HtmlHelper;
  7. use NumberFormatter;
  8. /**
  9. * @var Sale $sale
  10. * @var Document $document
  11. */
  12. $core = Core::getInstance();
  13. $user = $core->getUser();
  14. $sale = $document->getSale();
  15. $related_document = $document->getRelatedDocument();
  16. ?>
  17. <section class="mb-4">
  18. <h3><?=htmlspecialchars($document->getTitle())?></h3>
  19. <form action="<?=htmlspecialchars($document->getUrl())?>/submit" method="post">
  20. <div class="row">
  21. <div class="col-xl-8">
  22. <h4><?=htmlspecialchars(__("Main Details"))?></h4>
  23. <?php
  24. $user->insertCsrfToken();
  25. ?>
  26. <div class="row">
  27. <?php
  28. if($document->isInvoice()) {
  29. ?>
  30. <div class="col-sm-6">
  31. <div class="mb-3">
  32. <label for="invoice-status" class="form-label">
  33. <?=htmlspecialchars(__("Status"))?>
  34. </label>
  35. <select class="form-control" name="invoice_status" id="invoice-status">
  36. <?php
  37. HtmlHelper::renderOptions(InvoiceStatuses::options(), $document->invoice_status);
  38. ?>
  39. </select>
  40. </div>
  41. </div>
  42. <?php
  43. }
  44. ?>
  45. <div class="col-sm-6">
  46. <div class="mb-3">
  47. <label for="date" class="form-label">
  48. <?=htmlspecialchars(__("Date"))?>
  49. </label>
  50. <input class="form-control" type="date" name="date" id="date" value="<?=$document->date?>" required />
  51. </div>
  52. </div>
  53. </div>
  54. <?php
  55. if($document->isInvoice()) {
  56. ?>
  57. <div class="row">
  58. <div class="col">
  59. <div class="mb-3">
  60. <label for="currency" class="form-label">
  61. <?=htmlspecialchars(__("Currency"))?>
  62. </label>
  63. <select class="form-control" name="currency" id="currency">
  64. <?php
  65. HtmlHelper::renderOptions(Currencies::options(), $document->currency);
  66. ?>
  67. </select>
  68. </div>
  69. </div>
  70. <div class="col">
  71. <div class="mb-3">
  72. <label for="tax-rate" class="form-label">
  73. <?=htmlspecialchars(__("Tax Rate (%)"))?>
  74. </label>
  75. <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 />
  76. </div>
  77. </div>
  78. </div>
  79. <?php
  80. }
  81. ?>
  82. <div class="row">
  83. <div class="col-sm-6">
  84. <div class="mb-3">
  85. <label for="billing-address" class="form-label">
  86. <?=htmlspecialchars(__("Billing Address"))?>
  87. </label>
  88. <textarea class="form-control" name="billing_address" id="billing-address" rows="6" placeholder="<?=htmlspecialchars(__("Type billing address"))?>" required><?=htmlspecialchars($document->billing_address)?></textarea>
  89. </div>
  90. </div>
  91. <div class="col-sm-6">
  92. <div class="mb-3">
  93. <label for="delivery-address" class="form-label">
  94. <?=htmlspecialchars(__("Delivery Address"))?>
  95. </label>
  96. <textarea class="form-control" name="delivery_address" id="delivery-address" rows="6" placeholder="<?=htmlspecialchars(__("Type delivery address"))?>"><?=htmlspecialchars($document->delivery_address)?></textarea>
  97. </div>
  98. </div>
  99. </div>
  100. <div class="row">
  101. <div class="col-sm-6">
  102. <div class="mb-3">
  103. <label for="po-number" class="form-label">
  104. <?=htmlspecialchars(__("PO Number"))?>
  105. </label>
  106. <input type="text" class="form-control" name="po_number" id="po-number" placeholder="<?=htmlspecialchars(__("Type PO number"))?>" value="<?=htmlspecialchars($document->po_number)?>" />
  107. </div>
  108. </div>
  109. <?php
  110. if($document->isInvoice()) {
  111. ?>
  112. <div class="col-sm-6">
  113. <div class="mb-3">
  114. <label for="terms" class="form-label">
  115. <?=htmlspecialchars(__("Terms"))?>
  116. </label>
  117. <input type="text" class="form-control" name="terms" id="terms" placeholder="<?=htmlspecialchars(__("Type terms"))?>" value="<?=htmlspecialchars($document->terms)?>" />
  118. </div>
  119. </div>
  120. <?php
  121. }
  122. ?>
  123. </div>
  124. <div class="mb-3">
  125. <label for="notes" class="form-label">
  126. <?=htmlspecialchars(__("Notes"))?>
  127. </label>
  128. <textarea class="form-control" name="notes" id="notes" rows="6" placeholder="<?=htmlspecialchars(__("Type notes"))?>"><?=htmlspecialchars($document->notes)?></textarea>
  129. </div>
  130. </div>
  131. <div class="col-xl-4">
  132. <h4><?=htmlspecialchars(__("Additional Details"))?></h4>
  133. <?php
  134. if($document->isInvoice()) {
  135. ?>
  136. <div class="mb-3">
  137. <label for="dts-finalised" class="form-label">
  138. <?=htmlspecialchars(__("Date/Time Finalised"))?>
  139. </label>
  140. <input class="form-control" type="datetime-local" name="dts_finalised" id="dts-finalised" value="<?=$document->dts_finalised?>" />
  141. </div>
  142. <div class="mb-3">
  143. <label for="dts-paid" class="form-label">
  144. <?=htmlspecialchars(__("Date/Time Paid"))?>
  145. </label>
  146. <input class="form-control" type="datetime-local" name="dts_paid" id="dts-paid" value="<?=$document->dts_paid?>" />
  147. </div>
  148. <?php
  149. }
  150. ?>
  151. <div class="mb-3">
  152. <label for="delivery-company" class="form-label">
  153. <?=htmlspecialchars(__("Delivery Company"))?>
  154. </label>
  155. <input type="text" class="form-control" name="delivery_company" id="delivery-company" placeholder="<?=htmlspecialchars(__("Type delivery company"))?>" value="<?=htmlspecialchars($document->delivery_company)?>" />
  156. </div>
  157. <div class="mb-3">
  158. <label for="tracking-number" class="form-label">
  159. <?=htmlspecialchars(__("Tracking Number"))?>
  160. </label>
  161. <input type="text" class="form-control" name="tracking_number" id="tracking-number" placeholder="<?=htmlspecialchars(__("Type tracking number"))?>" value="<?=htmlspecialchars($document->tracking_number)?>" />
  162. </div>
  163. <dl>
  164. <dt><?=htmlspecialchars(__("Created By"))?></dt>
  165. <dd><?=htmlspecialchars($document->getUser()->getDisplayName())?></dd>
  166. <dt><?=htmlspecialchars(__("Date/Time Created"))?></dt>
  167. <dd><?=htmlspecialchars($user->formatDateTime($document->getDateTimeCreated()))?></dd>
  168. <?php
  169. if($sale) {
  170. ?>
  171. <dt><?=htmlspecialchars(__("Related Sale"))?></dt>
  172. <dd>
  173. <a href="<?=htmlspecialchars($sale->getUrl())?>">
  174. <?=htmlspecialchars($sale->getTitle())?>
  175. </a>
  176. </dd>
  177. <?php
  178. }
  179. if($related_document) {
  180. ?>
  181. <dt><?=htmlspecialchars(__("Related Document"))?></dt>
  182. <dd>
  183. <a href="<?=htmlspecialchars($related_document->getUrl())?>">
  184. <?=htmlspecialchars($related_document->getTitle())?>
  185. </a>
  186. </dd>
  187. <?php
  188. }
  189. if($document->isInvoice()) {
  190. $delivery_notes = Document::query([
  191. "type" => DocumentTypes::DELIVERY_NOTE,
  192. "related_document_id" => $document->id
  193. ]);
  194. if($delivery_notes) {
  195. ?>
  196. <dt><?=htmlspecialchars(__("Delivery Notes"))?></dt>
  197. <dd>
  198. <?php
  199. foreach($delivery_notes as $delivery_note) {
  200. ?>
  201. <a href="<?=htmlspecialchars($delivery_note->getUrl())?>">
  202. <?=htmlspecialchars($delivery_note->getTitle())?>
  203. </a><br />
  204. <?php
  205. }
  206. ?>
  207. </dd>
  208. <?php
  209. }
  210. }
  211. ?>
  212. </dl>
  213. </div>
  214. </div>
  215. <button type="submit" class="btn btn-primary">
  216. <i class="fa fa-fw fa-save"></i>
  217. <?=htmlspecialchars(__("Save"))?>
  218. </button>
  219. <?php
  220. if($document->isInvoice()) {
  221. ?>
  222. <div class="dropdown d-inline-block">
  223. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  224. <i class="fa fa-fw fa-file-pdf"></i>
  225. <?=htmlspecialchars(__("Download PDF"))?>
  226. </button>
  227. <div class="dropdown-menu">
  228. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" target="_blank" class="dropdown-item"><?=htmlspecialchars(__("Proforma Invoice"))?></a>
  229. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl("commercial"))?>" target="_blank" class="dropdown-item"><?=htmlspecialchars(__("Commercial Invoice"))?></a>
  230. </div>
  231. </div>
  232. <?php
  233. }
  234. else {
  235. ?>
  236. <a href="<?=htmlspecialchars($document->getDownloadPdfUrl())?>" class="btn btn-primary" target="_blank">
  237. <i class="fa fa-fw fa-file-pdf"></i>
  238. <?=htmlspecialchars(__("Download PDF"))?>
  239. </a>
  240. <?php
  241. }
  242. ?>
  243. </form>
  244. </section>
  245. <?php
  246. View::include("document_items_section", ["document" => $document]);