InvoiceController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\AppSession;
  4. use App\Models\BillingReport;
  5. use App\Models\CareMonth;
  6. use App\Models\ClaimEDI;
  7. use App\Models\ClientProChange;
  8. use App\Models\Company;
  9. use App\Models\Customer;
  10. use App\Models\CustomerTransaction;
  11. use App\Models\GiftCard;
  12. use App\Models\Handout;
  13. use App\Models\Invoice;
  14. use App\Models\InvoiceTransaction;
  15. use App\Models\MBClaim;
  16. use App\Models\Measurement;
  17. use App\Models\Bill;
  18. use App\Models\Claim;
  19. use App\Models\Client;
  20. use App\Models\McpRequest;
  21. use App\Models\McCodeCheck;
  22. use App\Models\Note;
  23. use App\Models\Pack;
  24. use App\Models\Pro;
  25. use App\Models\Product;
  26. use App\Models\ProFavorite;
  27. use App\Models\ProGeneralAvailability;
  28. use App\Models\ProProAccess;
  29. use App\Models\ProRate;
  30. use App\Models\ProSpecificAvailability;
  31. use App\Models\ProSpecificUnavailability;
  32. use App\Models\ProTeam;
  33. use App\Models\ProTextShortcut;
  34. use App\Models\ProTransaction;
  35. use App\Models\Shipment;
  36. use App\Models\SupplyOrder;
  37. use App\Models\Team;
  38. use App\Models\Ticket;
  39. use App\Models\AccountInvite;
  40. use App\Models\ClientMeasurementDaysPerMonth;
  41. use App\Models\ClientBDTDevice;
  42. use App\Models\ClientMemo;
  43. use Carbon\Carbon;
  44. use Illuminate\Pagination\LengthAwarePaginator;
  45. use Illuminate\Support\Facades\DB;
  46. use Illuminate\Support\Facades\Http;
  47. use PDF;
  48. use DateTime;
  49. use DateTimeZone;
  50. use Illuminate\Http\Request;
  51. use App\Models\SegmentTemplate;
  52. use App\Models\VisitTemplate;
  53. use App\Models\VisitTemplateSegmentTemplate;
  54. use App\Models\VisitTemplateAccess;
  55. class InvoiceController extends Controller
  56. {
  57. public function customers(Request $request) {
  58. $records = Customer::orderBy('created_at', 'DESC')->paginate();
  59. return view ('app.invoice-center.customers', compact('records'));
  60. }
  61. public function giftCards(Request $request) {
  62. $records = GiftCard::orderBy('created_at', 'DESC')->paginate();
  63. return view ('app.invoice-center.gift-cards', compact('records'));
  64. }
  65. public function invoices(Request $request) {
  66. $records = Invoice::orderBy('created_at', 'DESC')->paginate();
  67. return view ('app.invoice-center.invoices', compact('records'));
  68. }
  69. public function customerTransactions(Request $request) {
  70. $records = CustomerTransaction::orderBy('created_at', 'DESC')->paginate();
  71. return view ('app.invoice-center.customer-transactions', compact('records'));
  72. }
  73. public function invoiceTransactions(Request $request) {
  74. $records = InvoiceTransaction::orderBy('created_at', 'DESC')->paginate();
  75. return view ('app.invoice-center.invoice-transactions', compact('records'));
  76. }
  77. public function companySuggestJSON(Request $request) {
  78. $term = $request->input('term') ? trim($request->input('term')) : '';
  79. if (empty($term)) return '';
  80. $matches = DB::select("
  81. SELECT company.uid,
  82. company.name as text
  83. FROM company
  84. WHERE company.name ILIKE :term
  85. ORDER BY company.name",
  86. ['term' => $term . '%']
  87. );
  88. return json_encode([
  89. "success" => true,
  90. "data" => $matches
  91. ]);
  92. }
  93. public function clientSuggestJSON(Request $request) {
  94. $term = $request->input('term') ? trim($request->input('term')) : '';
  95. if (empty($term)) return '';
  96. // if multiple words in query, check for all (max 2)
  97. $term2 = '';
  98. if(strpos($term, ' ') !== FALSE) {
  99. $terms = explode(' ', $term);
  100. $term = trim($terms[0]);
  101. $term2 = trim($terms[1]);
  102. }
  103. if(!empty($term2)) {
  104. $matches = DB::select("
  105. SELECT client.uid,
  106. (client.name_first || ' ' || client.name_last) as text
  107. FROM client
  108. WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term OR client.name_first ILIKE :term2 OR client.name_last ILIKE :term2)
  109. ORDER BY client.name_first, client.name_last",
  110. ['term' => $term . '%', 'term2' => $term2 . '%']
  111. );
  112. }
  113. else {
  114. $matches = DB::select("
  115. SELECT client.uid,
  116. (client.name_first || ' ' || client.name_last) as text
  117. FROM client
  118. WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term)
  119. ORDER BY client.name_first, client.name_last",
  120. ['term' => $term . '%']
  121. );
  122. }
  123. return json_encode([
  124. "success" => true,
  125. "data" => $matches
  126. ]);
  127. }
  128. public function customerSuggestJSON(Request $request) {
  129. $term = $request->input('term') ? trim($request->input('term')) : '';
  130. if (empty($term)) return '';
  131. // if multiple words in query, check for all (max 2)
  132. $term2 = '';
  133. if(strpos($term, ' ') !== FALSE) {
  134. $terms = explode(' ', $term);
  135. $term = trim($terms[0]);
  136. $term2 = trim($terms[1]);
  137. }
  138. if(!empty($term2)) {
  139. $matches = DB::select("
  140. SELECT customer.uid,
  141. (client.name_first || ' ' || client.name_last) as text
  142. FROM client join customer on client.id = customer.client_id
  143. WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term OR client.name_first ILIKE :term2 OR client.name_last ILIKE :term2)
  144. ORDER BY client.name_first, client.name_last",
  145. ['term' => $term . '%', 'term2' => $term2 . '%']
  146. );
  147. }
  148. else {
  149. $matches = DB::select("
  150. SELECT customer.uid,
  151. (client.name_first || ' ' || client.name_last) as text
  152. FROM client join customer on client.id = customer.client_id
  153. WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term)
  154. ORDER BY client.name_first, client.name_last",
  155. ['term' => $term . '%']
  156. );
  157. }
  158. return json_encode([
  159. "success" => true,
  160. "data" => $matches
  161. ]);
  162. }
  163. }