You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FormController.php 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace App\Http\Controllers\API;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests\RegisterRequest;
  5. use App\Http\Controllers\Api\BaseController;
  6. use Illuminate\Support\Facades\Auth;
  7. Use App\Model\Form;
  8. Use App\Model\PackageDetail;
  9. Use App\Model\Subscriber;
  10. Use App\Model\WorkOrder;
  11. use App\Staff;
  12. use App\Model\StaffDetail;
  13. use App\Model\Company;
  14. use Carbon\Carbon;
  15. class FormController extends BaseController
  16. {
  17. /**
  18. /* Schedule Function
  19. **/
  20. public function getFormStatistic(Request $request)
  21. {
  22. $dateS = Carbon::createFromFormat('Y-m-d', '2019-12-12');
  23. $start = $dateS->copy()->startOfDay();
  24. $dateE = Carbon::createFromFormat('Y-m-d', '2020-02-11');
  25. $end = $dateE->copy()->endOfDay();
  26. $result = array();
  27. $data = Form::with('PackageDetail', 'Subscriber')->whereBetween('created_at', array($start, $end))->get();
  28. if(count($data) > 0) {
  29. foreach($data as $f) {
  30. $name = ''; $contact_no = '';
  31. $address = ''; $building = '';
  32. $labelD = '';
  33. if(!empty($f->dealer_id)){
  34. $c = Company::find($f->company_id);
  35. $labelD = $c->name;
  36. }else{
  37. $labelD = "";
  38. }
  39. if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
  40. if($f->type_application == 'R'){
  41. $name = $f->Subscriber->name;
  42. $contact_no = $f->Subscriber->phone1;
  43. $building = $f->Subscriber->building_name;
  44. if($f->Subscriber->street != ''){
  45. $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  46. }else {
  47. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  48. }
  49. }else if($f->type_application == 'B'){
  50. $name = $f->Subscriber->company_name;
  51. $contact_no = $f->Subscriber->company_num;
  52. $building = $f->Subscriber->street;
  53. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  54. }
  55. if($f->Subscriber->city == 'Jasin'){
  56. array_push($result,array(
  57. 'type_application' => $f->type_application,
  58. "type_service" => $f->type_service,
  59. "customer_name"=> $name,
  60. "contact_no"=> $contact_no,
  61. "unit_no"=>$f->Subscriber->unit_no,
  62. "building"=>$building,
  63. "street"=>$address,
  64. "submitted_date" => $f->created_at->toDateTimeString(),
  65. 'dealer' => $labelD,
  66. ));
  67. }
  68. }
  69. }
  70. return json_encode($result);
  71. // return $this->sendResponse($result, 'Get Schedule Successfully');
  72. }else {
  73. return $this->sendError('Invalid User', 'User Not Exist!');
  74. }
  75. }
  76. public function get_data_form(){
  77. $dateS = Carbon::createFromFormat('Y-m-d', '2020-01-01');
  78. $start = $dateS->copy()->startOfDay();
  79. $dateE = Carbon::createFromFormat('Y-m-d', '2020-06-17');
  80. $end = $dateE->copy()->endOfDay();
  81. $result = array();
  82. // $data = Form::with('PackageDetail', 'Subscriber')->where('dealer_id', 'exists', false)->whereBetween('created_at', array($start, $end))->get();
  83. // $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->where('type_service', '!=', 'Rectification')->whereBetween('created_at', array($start, $end))->get();
  84. // $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->where('type_service','New')->whereBetween('created_at', array($start, $end))->get();
  85. $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->withTrashed()->get();
  86. if(count($data) > 0) {
  87. foreach($data as $f) {
  88. $name = ''; $contact_no = '';
  89. $address = ''; $building = '';
  90. $labelD = '';
  91. if(!empty($f->dealer_id)){
  92. $c = Company::find($f->company_id);
  93. $labelD = $c->name;
  94. }else{
  95. $labelD = "";
  96. }
  97. if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
  98. if($f->type_application == 'R'){
  99. $name = $f->Subscriber->name;
  100. $contact_no = $f->Subscriber->phone1;
  101. $building = $f->Subscriber->building_name;
  102. if($f->Subscriber->street != ''){
  103. $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  104. }else {
  105. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  106. }
  107. }else if($f->type_application == 'B'){
  108. $name = $f->Subscriber->company_name;
  109. $contact_no = $f->Subscriber->company_num;
  110. $building = $f->Subscriber->street;
  111. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  112. }
  113. $woD = '-'; $woId = 'none';
  114. if(!empty($f->WorkOrder)){
  115. $woId = $f->WorkOrder->wo;
  116. if(!empty($f->WorkOrder->Docket)){
  117. $woD = $f->WorkOrder->Docket->end_job;
  118. // array_push($result,array(
  119. // 'type_application' => $f->type_application,
  120. // "type_service" => $f->type_service,
  121. // "customer_name"=> $name,
  122. // "contact_no"=> $contact_no,
  123. // "unit_no"=>$f->Subscriber->unit_no,
  124. // "building"=>$building,
  125. // "street"=>$address,
  126. // "submitted_date" => $f->created_at->toDateTimeString(),
  127. // "package_contract" => $f->PackageDetail->contract,
  128. // "package_name" => $f->PackageDetail->name,
  129. // 'dealer' => $labelD,
  130. // 'wo' => $woId,
  131. // 'activated_date' => $woD,
  132. // ));
  133. }
  134. }
  135. array_push($result,array(
  136. 'type_application' => $f->type_application,
  137. "type_service" => $f->type_service,
  138. "customer_name"=> $name,
  139. "contact_no"=> $contact_no,
  140. "unit_no"=>$f->Subscriber->unit_no,
  141. "building"=>$building,
  142. "street"=>$address,
  143. "submitted_date" => $f->created_at->toDateTimeString(),
  144. "package_contract" => $f->PackageDetail->contract,
  145. "package_name" => $f->PackageDetail->name,
  146. 'dealer' => $labelD,
  147. 'wo' => $woId,
  148. 'activated_date' => $woD,
  149. ));
  150. }
  151. }
  152. }
  153. // return json_encode(count($result));
  154. return json_encode($result);
  155. }
  156. /***********************************
  157. /* Form Deleted by Company
  158. ***********************************/
  159. public function get_deleted_by_company($company_id)
  160. {
  161. $data = Form::with('PackageDetail', 'Subscriber')->withTrashed()->where('company_id', $company_id)->get();
  162. return $this->sendResponse($data, 'Form deleted by specific company');
  163. }
  164. }