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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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', '2019-01-01');
  79. $start = $dateS->copy()->startOfDay();
  80. $dateE = Carbon::createFromFormat('Y-m-d', '2020-06-19');
  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="";
  100. // if(!empty($f->Subscriber->DealerClaim)){
  101. // $amount_claim = $f->Subscriber->DealerClaim->total_claim;
  102. // }
  103. if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
  104. if($f->type_application == 'R'){
  105. $name = $f->Subscriber->name;
  106. $contact_no = $f->Subscriber->phone1;
  107. $building = $f->Subscriber->building_name;
  108. if($f->Subscriber->street != ''){
  109. $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  110. }else {
  111. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  112. }
  113. }else if($f->type_application == 'B'){
  114. $name = $f->Subscriber->company_name;
  115. $contact_no = $f->Subscriber->company_num;
  116. $building = $f->Subscriber->street;
  117. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  118. }
  119. $woD = '-'; $woId = 'none'; $natureWork = ''; $doId = ''; $woRate=""; $installerId="";
  120. if(!empty($f->WorkOrder)){
  121. $woId = $f->WorkOrder->wo;
  122. $natureWork = $f->WorkOrder->nature_work;
  123. $doId = $f->WorkOrder->docket_id;
  124. if(!empty($f->WorkOrder->Docket)){
  125. $woD = $f->WorkOrder->Docket->end_job;
  126. $woRate = $f->WorkOrder->Docket->Rating1;
  127. // $installerId = $f->WordOrder->Docket->installer_id;
  128. // array_push($result,array(
  129. // 'type_application' => $f->type_application,
  130. // "type_service" => $f->type_service,
  131. // "customer_name"=> $name,
  132. // "contact_no"=> $contact_no,
  133. // "unit_no"=>$f->Subscriber->unit_no,
  134. // "building"=>$building,
  135. // "street"=>$address,
  136. // "submitted_date" => $f->created_at->toDateTimeString(),
  137. // "package_contract" => $f->PackageDetail->contract,
  138. // "package_name" => $f->PackageDetail->name,
  139. // 'dealer' => $labelD,
  140. // 'wo' => $woId,
  141. // 'activated_date' => $woD,
  142. // ));
  143. }
  144. }
  145. // array_push($result,array(
  146. // 'type_application' => $f->type_application,
  147. // "type_service" => $f->type_service,
  148. // "customer_name"=> $name,
  149. // "contact_no"=> $contact_no,
  150. // "unit_no"=>$f->Subscriber->unit_no,
  151. // "building"=>$building,
  152. // "street"=>$address,
  153. // "submitted_date" => $f->created_at->toDateTimeString(),
  154. // "package_contract" => $f->PackageDetail->contract,
  155. // "package_name" => $f->PackageDetail->name,
  156. // 'dealer' => $labelD,
  157. // 'wo' => $woId,
  158. // 'activated_date' => $woD,
  159. // ));
  160. array_push($result,array(
  161. // 'Installer' => $installerId,
  162. 'Dealer Name' => $labelD,
  163. "Customer Name"=> $name,
  164. "Contact Number"=> $contact_no,
  165. 'Completion Date' => $woD,
  166. 'Type Application' => $f->type_application,
  167. "Form Type" => $f->type_service,
  168. "Package"=> $f->PackageDetail->contract,
  169. "WO No" => $woId,
  170. "DO No" => $doId,
  171. "Service Type" => $f->PackageDetail->name,
  172. "Building"=>$building,
  173. "Rating" => $woRate,
  174. // "Claim Amount" => $amount_claim,
  175. ));
  176. }
  177. }
  178. }
  179. // return json_encode(count($result));
  180. return json_encode($result);
  181. }
  182. /***********************************
  183. /* Form Deleted by Company
  184. ***********************************/
  185. public function get_deleted_by_company($company_id)
  186. {
  187. $data = Form::with('PackageDetail', 'Subscriber')->withTrashed()->where('company_id', $company_id)->get();
  188. return $this->sendResponse($data, 'Form deleted by specific company');
  189. }
  190. }