sale.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Enums\Currencies;
  4. use App\Enums\SaleStatuses;
  5. use App\Helpers\HtmlHelper;
  6. /**
  7. * @var Sale $sale
  8. */
  9. $core = Core::getInstance();
  10. $user = $core->getUser();
  11. $location = $sale->getLocation();
  12. $customers = Customer::getAll();
  13. $location_options = [];
  14. foreach($customers as $customer) {
  15. foreach($customer->getLocations() as $customer_location) {
  16. $location_options[$customer_location->id] = $customer_location->getDisplayName();
  17. }
  18. }
  19. ?>
  20. <section class="mb-4">
  21. <h3 class="mb-3"><?=htmlspecialchars($sale->getTitle())?></h3>
  22. <form id="sale-form" class="mb-4" action="<?=htmlspecialchars($sale->getUrl())?>/submit" method="post">
  23. <div class="row">
  24. <div class="col-xl-8">
  25. <h4><?=htmlspecialchars(__("Main Details"))?></h4>
  26. <div class="mb-3">
  27. <label class="form-label" for="status">
  28. <b><?=htmlspecialchars(__("Status"))?></b>
  29. </label>
  30. <span class="ms-1"></span>
  31. <span class="badge rounded-pill text-bg-danger">
  32. <?=htmlspecialchars(__("Important"))?>
  33. </span>
  34. <select class="form-select" name="status" id="status">
  35. <?php
  36. HtmlHelper::renderOptions(SaleStatuses::options(), $sale->status);
  37. ?>
  38. </select>
  39. </div>
  40. <div class="row">
  41. <div class="col-md-6">
  42. <div class="mb-3">
  43. <label class="form-label" for="company-id">
  44. <?=htmlspecialchars(__("Company"))?>
  45. </label>
  46. <select class="form-select" name="company_id" id="company-id" required>
  47. <option value=""><?=htmlspecialchars(__("Select Company"))?></option>
  48. <?php
  49. HtmlHelper::renderOptions(Company::getOptions(), $sale->company_id);
  50. ?>
  51. </select>
  52. </div>
  53. </div>
  54. <div class="col-md-6">
  55. <div class="mb-3">
  56. <label class="form-label" for="location-id"><?= htmlspecialchars(__("Location")) ?></label>
  57. <select class="form-select" name="location_id" id="location-id">
  58. <?php
  59. HtmlHelper::renderOptions($location_options, $sale->location_id);
  60. ?>
  61. </select>
  62. </div>
  63. </div>
  64. <div class="col-md-6">
  65. <div class="mb-3">
  66. <label class="form-label" for="date-predicted-sold"><?=htmlspecialchars(__("Predicted Sold Date"))?></label>
  67. <input class="form-control" type="date" name="date_predicted_sold" id="date-predicted-sold" value="<?=htmlspecialchars($sale->date_predicted_sold)?>" required />
  68. </div>
  69. </div>
  70. </div>
  71. <div class="row">
  72. <div class="col-md">
  73. <div class="mb-3">
  74. <label class="form-label" for="currency"><?=htmlspecialchars(__("Currency"))?></label>
  75. <select class="form-select" name="currency" id="currency">
  76. <?php
  77. HtmlHelper::renderOptions(Currencies::options(), $sale->currency);
  78. ?>
  79. </select>
  80. </div>
  81. </div>
  82. <div class="col-md">
  83. <div class="mb-3">
  84. <label for="tax-rate" class="form-label">
  85. <?=htmlspecialchars(__("Tax Rate (%)"))?>
  86. </label>
  87. <input class="form-control" type="number" name="tax_rate" id="tax-rate" value="<?=$sale->tax_rate?>" min="0" max="100.00" step="0.01" placeholder="Type tax rate" required />
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. <div class="col-xl-4">
  93. <div class="row">
  94. <div class="col-sm-6 col-xl-12">
  95. <?php
  96. View::include("related_items_section", [
  97. "sale" => $sale,
  98. "current" => $sale
  99. ]);
  100. ?>
  101. </div>
  102. <div class="col-sm-6 col-xl-12">
  103. <section class="mb-4">
  104. <h4><?=htmlspecialchars(__("Additional Details"))?></h4>
  105. <dl>
  106. <dt><?=htmlspecialchars(__("Location"))?></dt>
  107. <dd>
  108. <a href="<?=htmlspecialchars($location->getUrl())?>">
  109. <?=htmlspecialchars($location->getDisplayName())?>
  110. </a>
  111. </dd>
  112. <dt><?=htmlspecialchars(__("Created By"))?></dt>
  113. <dd><?=htmlspecialchars($sale->getUser()->getDisplayName())?></dd>
  114. <dt><?=htmlspecialchars(__("Created Date/Time"))?></dt>
  115. <dd><?=htmlspecialchars($sale->getDateTimeCreated()->format("d/m/Y H:i"))?></dd>
  116. </dl>
  117. </section>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <button type="submit" class="btn btn-primary">
  123. <i class="fa fa-fw fa-save"></i>
  124. <?=htmlspecialchars(__("Save Lead"))?>
  125. </button>
  126. </form>
  127. </section>
  128. <?php
  129. View::include("sale_items_section", compact("sale"));
  130. View::include("sale_invoices_section", ["sales_orders" => $sale->getSalesOrders()]);
  131. View::include("sale_notes_section", compact("sale"));
  132. ?>
  133. <section class="mb-4">
  134. <div class="row mb-3">
  135. <div class="col">
  136. <h3><?=htmlspecialchars(__("Tickets"))?></h3>
  137. </div>
  138. <div class="col-auto">
  139. <button class="btn btn-success" type="button" data-bs-toggle="modal" data-bs-target="#ticket-modal" data-location-id="<?=$sale->location_id?>" data-sale-number="<?=$sale->getNumber()?>">
  140. <i class="fa fa-fw fa-plus"></i>
  141. <?=htmlspecialchars(__("Add Ticket"))?>
  142. </button>
  143. </div>
  144. </div>
  145. <?php
  146. $tickets = $sale->getTickets();
  147. if(empty($tickets)) {
  148. HtmlHelper::renderInfoAlert(__("No tickets to display."));
  149. }
  150. else {
  151. ?>
  152. <table class="table table-bordered table-hover">
  153. <colgroup>
  154. <col style="width: 1%"/>
  155. <col style="width: 10%"/>
  156. <col style="width: 45%"/>
  157. <col style="width: 10%"/>
  158. <col style="width: 20%"/>
  159. <col style="width: 15%"/>
  160. <col style="width: 1%"/>
  161. </colgroup>
  162. <thead>
  163. <tr>
  164. <th><?=htmlspecialchars(__("ID"))?></th>
  165. <th><?=htmlspecialchars(__("Date"))?></th>
  166. <th><?=htmlspecialchars(__("Subject"))?></th>
  167. <th><?=htmlspecialchars(__("Status"))?></th>
  168. <th><?=htmlspecialchars(__("Assigned To"))?></th>
  169. <th><?=htmlspecialchars(__("Last Updated"))?></th>
  170. <th><?=htmlspecialchars(__("Actions"))?></th>
  171. </tr>
  172. </thead>
  173. <tbody>
  174. <?php
  175. foreach($tickets as $ticket) {
  176. ?>
  177. <tr>
  178. <td class="text-end">
  179. <a href="<?=htmlspecialchars($ticket->getUrl())?>"><?=htmlspecialchars($ticket->id)?></a>
  180. </td>
  181. <td>
  182. <?=htmlspecialchars($user->formatDate($ticket->getDateTimeCreated()))?>
  183. </td>
  184. <td>
  185. <?=htmlspecialchars($ticket->subject)?>
  186. </td>
  187. <td>
  188. <?=htmlspecialchars($ticket->getDisplayStatus())?>
  189. </td>
  190. <td>
  191. <?=htmlspecialchars($ticket->getDisplayAssignedTo())?>
  192. </td>
  193. <td>
  194. <?=htmlspecialchars($user->formatDateTime($ticket->getDateTimeUpdated()))?>
  195. </td>
  196. <td class="p-1">
  197. <a class="btn btn-sm btn-primary" href="<?=htmlspecialchars($ticket->getUrl())?>"><?=htmlspecialchars(__("View"))?></a>
  198. </td>
  199. </tr>
  200. <?php
  201. }
  202. ?>
  203. </tbody>
  204. </table>
  205. <?php
  206. }
  207. ?>
  208. </section>