InvoiceController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 Cassandra\Custom;
  45. use Illuminate\Pagination\LengthAwarePaginator;
  46. use Illuminate\Support\Facades\DB;
  47. use Illuminate\Support\Facades\Http;
  48. use PDF;
  49. use DateTime;
  50. use DateTimeZone;
  51. use Illuminate\Http\Request;
  52. use App\Models\SegmentTemplate;
  53. use App\Models\VisitTemplate;
  54. use App\Models\VisitTemplateSegmentTemplate;
  55. use App\Models\VisitTemplateAccess;
  56. class InvoiceController extends Controller
  57. {
  58. public function customers(Request $request) {
  59. $records = Customer::orderBy('created_at', 'DESC')->paginate();
  60. return view ('app.invoice-center.customers', compact('records'));
  61. }
  62. public function giftCards(Request $request) {
  63. $records = GiftCard::orderBy('created_at', 'DESC');
  64. $company = null;
  65. if($request->input('companyUid')) {
  66. $company = Company::where('uid', $request->input('companyUid'))->first();
  67. if($company) {
  68. $records = $records->where('company_id', $company->id);
  69. }
  70. }
  71. $records = $records->paginate();
  72. return view ('app.invoice-center.gift-cards', compact('records', 'company'));
  73. }
  74. public function invoices(Request $request) {
  75. $records = Invoice::orderBy('created_at', 'DESC');
  76. $customer = null;
  77. if($request->input('customerUid')) {
  78. $customer = Customer::where('uid', $request->input('customerUid'))->first();
  79. if($customer) {
  80. $records = $records->where('customer_id', $customer->id);
  81. }
  82. }
  83. $records = $records->paginate();
  84. return view ('app.invoice-center.invoices', compact('records', 'customer'));
  85. }
  86. public function customerTransactions(Request $request) {
  87. $records = CustomerTransaction::orderBy('created_at', 'DESC');
  88. $customer = null;
  89. if($request->input('customerUid')) {
  90. $customer = Customer::where('uid', $request->input('customerUid'))->first();
  91. if($customer) {
  92. $records = $records->where('customer_id', $customer->id);
  93. }
  94. }
  95. $records = $records->paginate();
  96. return view ('app.invoice-center.customer-transactions', compact('records', 'customer'));
  97. }
  98. public function invoiceTransactions(Request $request) {
  99. $records = InvoiceTransaction::orderBy('created_at', 'DESC');
  100. $invoice = null;
  101. if($request->input('invoiceUid')) {
  102. $invoice = Invoice::where('uid', $request->input('invoiceUid'))->first();
  103. if($invoice) {
  104. $records = $records->where('invoice_id', $invoice->id);
  105. }
  106. }
  107. $records = $records->paginate();
  108. return view ('app.invoice-center.invoice-transactions', compact('records', 'invoice'));
  109. }
  110. public function companySuggestJSON(Request $request) {
  111. $term = $request->input('term') ? trim($request->input('term')) : '';
  112. if (empty($term)) return '';
  113. $matches = DB::select("
  114. SELECT company.uid,
  115. company.name as text
  116. FROM company
  117. WHERE company.name ILIKE :term
  118. ORDER BY company.name",
  119. ['term' => $term . '%']
  120. );
  121. return json_encode([
  122. "success" => true,
  123. "data" => $matches
  124. ]);
  125. }
  126. public function clientSuggestJSON(Request $request) {
  127. $term = $request->input('term') ? trim($request->input('term')) : '';
  128. if (empty($term)) return '';
  129. // if multiple words in query, check for all (max 2)
  130. $term2 = '';
  131. if(strpos($term, ' ') !== FALSE) {
  132. $terms = explode(' ', $term);
  133. $term = trim($terms[0]);
  134. $term2 = trim($terms[1]);
  135. }
  136. if(!empty($term2)) {
  137. $matches = DB::select("
  138. SELECT client.uid,
  139. (client.name_first || ' ' || client.name_last) as text
  140. FROM client
  141. WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term OR client.name_first ILIKE :term2 OR client.name_last ILIKE :term2)
  142. ORDER BY client.name_first, client.name_last",
  143. ['term' => $term . '%', 'term2' => $term2 . '%']
  144. );
  145. }
  146. else {
  147. $matches = DB::select("
  148. SELECT client.uid,
  149. (client.name_first || ' ' || client.name_last) as text
  150. FROM client
  151. WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term)
  152. ORDER BY client.name_first, client.name_last",
  153. ['term' => $term . '%']
  154. );
  155. }
  156. return json_encode([
  157. "success" => true,
  158. "data" => $matches
  159. ]);
  160. }
  161. public function customerSuggestJSON(Request $request) {
  162. $term = $request->input('term') ? trim($request->input('term')) : '';
  163. if (empty($term)) return '';
  164. // if multiple words in query, check for all (max 2)
  165. $term2 = '';
  166. if(strpos($term, ' ') !== FALSE) {
  167. $terms = explode(' ', $term);
  168. $term = trim($terms[0]);
  169. $term2 = trim($terms[1]);
  170. }
  171. if(!empty($term2)) {
  172. $matches = DB::select("
  173. SELECT customer.uid,
  174. (client.name_first || ' ' || client.name_last) as text
  175. FROM client join customer on client.id = customer.client_id
  176. WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term OR client.name_first ILIKE :term2 OR client.name_last ILIKE :term2)
  177. ORDER BY client.name_first, client.name_last",
  178. ['term' => $term . '%', 'term2' => $term2 . '%']
  179. );
  180. }
  181. else {
  182. $matches = DB::select("
  183. SELECT customer.uid,
  184. (client.name_first || ' ' || client.name_last) as text
  185. FROM client join customer on client.id = customer.client_id
  186. WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term)
  187. ORDER BY client.name_first, client.name_last",
  188. ['term' => $term . '%']
  189. );
  190. }
  191. return json_encode([
  192. "success" => true,
  193. "data" => $matches
  194. ]);
  195. }
  196. public function customerInvoicesJSON(Request $request, Customer $customer) {
  197. $invoices = [];
  198. foreach ($customer->invoices as $invoice) {
  199. $invoices[] = [
  200. "uid" => $invoice->uid,
  201. "text" => $invoice->displayName()
  202. ];
  203. }
  204. return json_encode([
  205. "success" => true,
  206. "data" => $invoices
  207. ]);
  208. }
  209. }