Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FormController.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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-04-31');
  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. if(count($data) > 0) {
  86. foreach($data as $f) {
  87. $name = ''; $contact_no = '';
  88. $address = ''; $building = '';
  89. $labelD = '';
  90. if(!empty($f->dealer_id)){
  91. $c = Company::find($f->company_id);
  92. $labelD = $c->name;
  93. }else{
  94. $labelD = "";
  95. }
  96. if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
  97. if($f->type_application == 'R'){
  98. $name = $f->Subscriber->name;
  99. $contact_no = $f->Subscriber->phone1;
  100. $building = $f->Subscriber->building_name;
  101. if($f->Subscriber->street != ''){
  102. $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  103. }else {
  104. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  105. }
  106. }else if($f->type_application == 'B'){
  107. $name = $f->Subscriber->company_name;
  108. $contact_no = $f->Subscriber->company_num;
  109. $building = $f->Subscriber->street;
  110. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  111. }
  112. $woD = '-'; $woId = 'none';
  113. if(!empty($f->WorkOrder)){
  114. $woId = $f->WorkOrder->wo;
  115. if(!empty($f->WorkOrder->Docket)){
  116. $woD = $f->WorkOrder->Docket->end_job;
  117. // array_push($result,array(
  118. // 'type_application' => $f->type_application,
  119. // "type_service" => $f->type_service,
  120. // "customer_name"=> $name,
  121. // "contact_no"=> $contact_no,
  122. // "unit_no"=>$f->Subscriber->unit_no,
  123. // "building"=>$building,
  124. // "street"=>$address,
  125. // "submitted_date" => $f->created_at->toDateTimeString(),
  126. // "package_contract" => $f->PackageDetail->contract,
  127. // "package_name" => $f->PackageDetail->name,
  128. // 'dealer' => $labelD,
  129. // 'wo' => $woId,
  130. // 'activated_date' => $woD,
  131. // ));
  132. }
  133. }
  134. array_push($result,array(
  135. 'type_application' => $f->type_application,
  136. "type_service" => $f->type_service,
  137. "customer_name"=> $name,
  138. "contact_no"=> $contact_no,
  139. "unit_no"=>$f->Subscriber->unit_no,
  140. "building"=>$building,
  141. "street"=>$address,
  142. "submitted_date" => $f->created_at->toDateTimeString(),
  143. "package_contract" => $f->PackageDetail->contract,
  144. "package_name" => $f->PackageDetail->name,
  145. 'dealer' => $labelD,
  146. 'wo' => $woId,
  147. 'activated_date' => $woD,
  148. ));
  149. }
  150. }
  151. }
  152. // return json_encode(count($result));
  153. return json_encode($result);
  154. }
  155. /***********************************
  156. /* Form Deleted by Company
  157. ***********************************/
  158. public function get_deleted_by_company($company_id)
  159. {
  160. $data = Form::with('PackageDetail', 'Subscriber')->withTrashed()->where('company_id', $company_id)->get();
  161. return $this->sendResponse($data, 'Form deleted by specific company');
  162. }
  163. }