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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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= DealerClaim::where('wo',$f->WorkOrder->wo)->get();
  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';
  117. if(!empty($f->WorkOrder)){
  118. $woId = $f->WorkOrder->wo;
  119. if(!empty($f->WorkOrder->Docket)){
  120. $woD = $f->WorkOrder->Docket->end_job;
  121. // array_push($result,array(
  122. // 'type_application' => $f->type_application,
  123. // "type_service" => $f->type_service,
  124. // "customer_name"=> $name,
  125. // "contact_no"=> $contact_no,
  126. // "unit_no"=>$f->Subscriber->unit_no,
  127. // "building"=>$building,
  128. // "street"=>$address,
  129. // "submitted_date" => $f->created_at->toDateTimeString(),
  130. // "package_contract" => $f->PackageDetail->contract,
  131. // "package_name" => $f->PackageDetail->name,
  132. // 'dealer' => $labelD,
  133. // 'wo' => $woId,
  134. // 'activated_date' => $woD,
  135. // ));
  136. }
  137. }
  138. // array_push($result,array(
  139. // 'type_application' => $f->type_application,
  140. // "type_service" => $f->type_service,
  141. // "customer_name"=> $name,
  142. // "contact_no"=> $contact_no,
  143. // "unit_no"=>$f->Subscriber->unit_no,
  144. // "building"=>$building,
  145. // "street"=>$address,
  146. // "submitted_date" => $f->created_at->toDateTimeString(),
  147. // "package_contract" => $f->PackageDetail->contract,
  148. // "package_name" => $f->PackageDetail->name,
  149. // 'dealer' => $labelD,
  150. // 'wo' => $woId,
  151. // 'activated_date' => $woD,
  152. // ));
  153. array_push($result,array(
  154. 'Dealer Name' => $labelD,
  155. "Customer Name"=> $name,
  156. 'Completion Date' => $woD,
  157. "Form Type" => $f->type_service,
  158. "Package"=> $f->PackageDetail->contract,
  159. "WO No" => $woId,
  160. "DO No" => $f->WorkOrder->docket_id,
  161. "Service Type" => $f->WorkOrder->nature_work,
  162. "Building"=>$building,
  163. "Rating" => $f->WorkOrder->Docket->Rating1,
  164. "Claim Amount" => $amount_claim,
  165. ));
  166. }
  167. }
  168. }
  169. // return json_encode(count($result));
  170. return json_encode($result);
  171. }
  172. /***********************************
  173. /* Form Deleted by Company
  174. ***********************************/
  175. public function get_deleted_by_company($company_id)
  176. {
  177. $data = Form::with('PackageDetail', 'Subscriber')->withTrashed()->where('company_id', $company_id)->get();
  178. return $this->sendResponse($data, 'Form deleted by specific company');
  179. }
  180. }