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

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