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

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