您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FormController.php 7.6KB

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