Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. if ($f->Subscriber->building_name == null) {
  55. $building = $f->Subscriber->street;
  56. $address = $f->Subscriber->postcode . ' , ' . $f->Subscriber->city . ' , ' . $f->Subscriber->state;
  57. } else {
  58. $building = $f->Subscriber->building_name;
  59. $address = $f->Subscriber->street . ' , ' . $f->Subscriber->postcode . ' , ' . $f->Subscriber->city . ' , ' . $f->Subscriber->state;
  60. }
  61. }
  62. if($f->Subscriber->city == 'Jasin'){
  63. array_push($result,array(
  64. 'type_application' => $f->type_application,
  65. "type_service" => $f->type_service,
  66. "customer_name"=> $name,
  67. "contact_no"=> $contact_no,
  68. "unit_no"=>$f->Subscriber->unit_no,
  69. "building"=>$building,
  70. "street"=>$address,
  71. "submitted_date" => $f->created_at->toDateTimeString(),
  72. 'dealer' => $labelD,
  73. ));
  74. }
  75. }
  76. }
  77. return json_encode($result);
  78. // return $this->sendResponse($result, 'Get Schedule Successfully');
  79. }else {
  80. return $this->sendError('Invalid User', 'User Not Exist!');
  81. }
  82. }
  83. public function get_data_form(Request $request){
  84. $dateS = Carbon::createFromFormat('Y-m-d', '2020-01-01');
  85. $start = $dateS->copy()->startOfDay();
  86. $dateE = Carbon::createFromFormat('Y-m-d', '2021-12-31');
  87. $end = $dateE->copy()->endOfDay();
  88. $result = array();
  89. // $data = Form::with('PackageDetail', 'Subscriber')->where('dealer_id', 'exists', false)->whereBetween('created_at', array($start, $end))->get();
  90. // $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->where('type_service', '!=', 'Rectification')->whereBetween('created_at', array($start, $end))->get();
  91. // $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->where('type_service','New')->whereBetween('created_at', array($start, $end))->get();
  92. // $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->withTrashed()->get();
  93. $data = Form::with('PackageDetail', 'Subscriber','WorkOrder')->whereBetween('created_at', array($start, $end))->get();
  94. if(count($data) > 0) {
  95. foreach($data as $f) {
  96. $name = ''; $contact_no = '';
  97. $address = ''; $building = '';
  98. $labelD = '';
  99. if(!empty($f->dealer_id)){
  100. $c = Company::find($f->company_id);
  101. if(!empty($c->name)){
  102. $labelD = $c->name;
  103. }
  104. }else{
  105. $labelD = "";
  106. }
  107. // $amount_claim="";
  108. // if(!empty($f->Subscriber->DealerClaim)){
  109. // $amount_claim = $f->Subscriber->DealerClaim->total_claim;
  110. // }
  111. $subscriber_id=''; $ic=''; $company_reg='';
  112. if(!empty($f->Subscriber) && !empty($f->PackageDetail)){
  113. if($f->type_application == 'R'){
  114. $name = $f->Subscriber->name;
  115. $ic = $f->Subscriber->ic;
  116. $subscriber_id = $f->Subscriber->subscriber_id;
  117. $contact_no = $f->Subscriber->phone1;
  118. $building = $f->Subscriber->building_name;
  119. if($f->Subscriber->street != ''){
  120. $address = $f->Subscriber->street. ' , '.$f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  121. }else {
  122. $address = $f->Subscriber->postcode. ' , '.$f->Subscriber->city. ' , '.$f->Subscriber->state;
  123. }
  124. }else if($f->type_application == 'B'){
  125. $name = $f->Subscriber->company_name;
  126. $ic = $f->Subscriber->ic;
  127. $company_reg = $f->Subscriber->company_reg;
  128. $subscriber_id = $f->Subscriber->subscriber_id;
  129. $contact_no = $f->Subscriber->company_num;
  130. if ($f->Subscriber->building_name == null) {
  131. $building = $f->Subscriber->street;
  132. $address = $f->Subscriber->postcode . ' , ' . $f->Subscriber->city . ' , ' . $f->Subscriber->state;
  133. } else {
  134. $building = $f->Subscriber->building_name;
  135. $address = $f->Subscriber->street . ' , ' . $f->Subscriber->postcode . ' , ' . $f->Subscriber->city . ' , ' . $f->Subscriber->state;
  136. }
  137. }
  138. $woD = '-'; $woId = 'none'; $natureWork = ''; $doId = ''; $woRate=""; $installer_name=""; $contractor_name="";
  139. if(!empty($f->WorkOrder)){
  140. $woId = $f->WorkOrder->wo;
  141. $natureWork = $f->WorkOrder->nature_work;
  142. $doId = $f->WorkOrder->docket_id;
  143. $installer = StaffDetail::where('_id',$f->WorkOrder->installer_id)->get();
  144. foreach($installer as $installer) {
  145. $installer_name = $installer->name;
  146. }
  147. $contractor = Company::where('_id',$f->WorkOrder->contractor_id)->get();
  148. foreach($contractor as $contractor) {
  149. $contractor_name = $contractor->name;
  150. }
  151. if(!empty($f->WorkOrder->Docket)){
  152. $woD = $f->WorkOrder->Docket->end_job;
  153. $woRate = $f->WorkOrder->Docket->Rating1;
  154. }
  155. }
  156. array_push($result,array(
  157. 'type_application' => $f->type_application,
  158. "type_service" => $f->type_service,
  159. "customer_name"=> $name,
  160. "ic" => $ic,
  161. //"company_reg" => $company_reg,
  162. "subscriber_id" => $subscriber_id,
  163. "contact_no"=> $contact_no,
  164. "unit_no"=>$f->Subscriber->unit_no,
  165. "building"=>$building,
  166. "street"=>$address,
  167. "submitted_date" => $f->created_at->toDateTimeString(),
  168. "package_contract" => $f->PackageDetail->contract,
  169. "package_name" => $f->PackageDetail->name,
  170. 'dealer' => $labelD,
  171. 'wo' => $woId,
  172. 'activated_date' => $woD,
  173. 'installer_name' => $installer_name,
  174. 'contractor_name' => $contractor_name,
  175. ));
  176. // array_push($result,array(
  177. // // 'Installer' => $installerId,
  178. // 'Dealer Name' => $labelD,
  179. // "Customer Name"=> $name,
  180. // "Contact Number"=> $contact_no,
  181. // 'Completion Date' => $woD,
  182. // 'Type Application' => $f->type_application,
  183. // "Form Type" => $f->type_service,
  184. // "Package"=> $f->PackageDetail->contract,
  185. // "WO No" => $woId,
  186. // "DO No" => $doId,
  187. // "Service Type" => $f->PackageDetail->name,
  188. // "Building"=>$building,
  189. // "Rating" => $woRate,
  190. // // "Claim Amount" => $amount_claim,
  191. // ));
  192. }
  193. }
  194. }
  195. // return json_encode(count($result));
  196. return json_encode($result);
  197. }
  198. /***********************************
  199. /* Form Deleted by Company
  200. ***********************************/
  201. public function get_deleted_by_company($company_id)
  202. {
  203. $data = Form::with('PackageDetail', 'Subscriber')->withTrashed()->where('company_id', $company_id)->get();
  204. return $this->sendResponse($data, 'Form deleted by specific company');
  205. }
  206. }