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 7.0KB

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