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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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', $request->startDate);
  80. $start = $dateS->copy()->startOfDay();
  81. $dateE = Carbon::createFromFormat('Y-m-d', $request->endDate);
  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. if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
  105. if($f->type_application == 'R'){
  106. $name = $f->Subscriber->name;
  107. $contact_no = $f->Subscriber->phone1;
  108. $building = $f->Subscriber->building_name;
  109. if($f->Subscriber->street != ''){
  110. $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  111. }else {
  112. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  113. }
  114. }else if($f->type_application == 'B'){
  115. $name = $f->Subscriber->company_name;
  116. $contact_no = $f->Subscriber->company_num;
  117. $building = $f->Subscriber->street;
  118. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  119. }
  120. $woD = '-'; $woId = 'none'; $natureWork = ''; $doId = ''; $woRate=""; $installerId="";
  121. if(!empty($f->WorkOrder)){
  122. $woId = $f->WorkOrder->wo;
  123. $natureWork = $f->WorkOrder->nature_work;
  124. $doId = $f->WorkOrder->docket_id;
  125. if(!empty($f->WorkOrder->Docket)){
  126. $woD = $f->WorkOrder->Docket->end_job;
  127. $woRate = $f->WorkOrder->Docket->Rating1;
  128. // $installerId = $f->WordOrder->Docket->installer_id;
  129. // array_push($result,array(
  130. // 'type_application' => $f->type_application,
  131. // "type_service" => $f->type_service,
  132. // "customer_name"=> $name,
  133. // "contact_no"=> $contact_no,
  134. // "unit_no"=>$f->Subscriber->unit_no,
  135. // "building"=>$building,
  136. // "street"=>$address,
  137. // "submitted_date" => $f->created_at->toDateTimeString(),
  138. // "package_contract" => $f->PackageDetail->contract,
  139. // "package_name" => $f->PackageDetail->name,
  140. // 'dealer' => $labelD,
  141. // 'wo' => $woId,
  142. // 'activated_date' => $woD,
  143. // ));
  144. }
  145. }
  146. // array_push($result,array(
  147. // 'type_application' => $f->type_application,
  148. // "type_service" => $f->type_service,
  149. // "customer_name"=> $name,
  150. // "contact_no"=> $contact_no,
  151. // "unit_no"=>$f->Subscriber->unit_no,
  152. // "building"=>$building,
  153. // "street"=>$address,
  154. // "submitted_date" => $f->created_at->toDateTimeString(),
  155. // "package_contract" => $f->PackageDetail->contract,
  156. // "package_name" => $f->PackageDetail->name,
  157. // 'dealer' => $labelD,
  158. // 'wo' => $woId,
  159. // 'activated_date' => $woD,
  160. // ));
  161. array_push($result,array(
  162. // 'Installer' => $installerId,
  163. 'Dealer Name' => $labelD,
  164. "Customer Name"=> $name,
  165. "Contact Number"=> $contact_no,
  166. 'Completion Date' => $woD,
  167. 'Type Application' => $f->type_application,
  168. "Form Type" => $f->type_service,
  169. "Package"=> $f->PackageDetail->contract,
  170. "WO No" => $woId,
  171. "DO No" => $doId,
  172. "Service Type" => $f->PackageDetail->name,
  173. "Building"=>$building,
  174. "Rating" => $woRate,
  175. // "Claim Amount" => $amount_claim,
  176. ));
  177. }
  178. }
  179. }
  180. // return json_encode(count($result));
  181. return json_encode($result);
  182. }
  183. /***********************************
  184. /* Form Deleted by Company
  185. ***********************************/
  186. public function get_deleted_by_company($company_id)
  187. {
  188. $data = Form::with('PackageDetail', 'Subscriber')->withTrashed()->where('company_id', $company_id)->get();
  189. return $this->sendResponse($data, 'Form deleted by specific company');
  190. }
  191. /***********************************
  192. /* API to get claimed data
  193. ***********************************/
  194. public function get_data_claim(){
  195. $dateS = Carbon::createFromFormat('Y-m-d', '2019-01-01');
  196. $start = $dateS->copy()->startOfDay();
  197. $dateE = Carbon::createFromFormat('Y-m-d', '2019-12-31');
  198. $end = $dateE->copy()->endOfDay();
  199. $result = array();
  200. $data = DealerClaim::with('Subscriber','Staff')->whereBetween('created_at', array($start, $end))->get();
  201. if(count($data) > 0) {
  202. foreach($data as $f) {
  203. $name = ''; $contact_no = ''; $building = '';
  204. $labelD = ''; $service = ''; $rating = '';
  205. if(!empty($f->dealer)){
  206. $c = Company::find($f->dealer);
  207. $labelD = $c->name;
  208. }else{
  209. $labelD = "";
  210. }
  211. if(!empty($f->Subscriber)){
  212. if($f->formT == 'R'){
  213. $name = $f->Subscriber->name;
  214. $contact_no = $f->Subscriber->phone1;
  215. $building = $f->Subscriber->building_name;
  216. }else if($f->formT == 'B'){
  217. $name = $f->Subscriber->company_name;
  218. $contact_no = $f->Subscriber->company_num;
  219. $building = $f->Subscriber->street;
  220. }
  221. if(!empty($f->docket)){
  222. $docket = Docket::where('docket_id',$f->docket)->get();
  223. foreach($docket as $d) {
  224. $service = $d->nature_work;
  225. $rating = $d->Rating1;
  226. }
  227. }
  228. array_push($result,array(
  229. "Dealer Name" => $labelD,
  230. // "Installer Name" => ,
  231. // "Contractor Name" => ,
  232. "Customer Name"=> $name,
  233. "Contact Number"=> $contact_no,
  234. "Completion Date" => $f->activated_dt,
  235. "Form Type" => $f->formT,
  236. "Package"=> $f->package,
  237. "WO No" => $f->wo,
  238. "DO No" => $f->docket,
  239. "Service Type" => $service,
  240. "Building"=> $building,
  241. "Rating" => $rating,
  242. "Claim Amount" => $f->total_claim,
  243. ));
  244. }
  245. }
  246. }
  247. return json_encode($result);
  248. }
  249. }