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.

MynixController.php 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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\Staff;
  8. use App\Model\StaffDetail;
  9. use App\Model\Docket;
  10. use App\Model\WorkOrder;
  11. use App\Model\Company;
  12. Use App\Model\Form;
  13. Use App\Model\PackageDetail;
  14. Use App\Model\Subscriber;
  15. Use Hash;
  16. use Carbon\Carbon;
  17. use Crypt;
  18. use File;
  19. use Mail;
  20. class MynixController extends BaseController
  21. {
  22. public function workOrderStatistics(){
  23. $pc = count(WorkOrder::where('status','Pending Contractor')->get());
  24. $pi = count(WorkOrder::where('status','Pending Installer')->get());
  25. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
  26. $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
  27. $rs = count(WorkOrder::where('status','Reschedule')->get());
  28. $ss = count(WorkOrder::where('status','Suspend')->get());
  29. $cm = count(WorkOrder::where('status','Completed')->get());
  30. $data = array();
  31. $data[] = array("status" => "Pending Contractor", "statistic" => $pc);
  32. $data[] = array("status" => "Pending Installer", "statistic" => $pi);
  33. $data[] = array("status" => "Pending Non Prelaid", "statistic" => $pp);
  34. $data[] = array("status" => "Success Non Prelaid", "statistic" => $sp);
  35. $data[] = array("status" => "Reschedule", "statistic" => $rs);
  36. $data[] = array("status" => "Suspend", "statistic" => $ss);
  37. $data[] = array("status" => "Completed", "statistic" => $cm);
  38. return $this->sendResponse($data, 'Get Statistic Successfully');
  39. }
  40. public function workOrderList(){
  41. $data = array();
  42. $installer = ''; $type = ''; $n1 = '';
  43. $curr = Carbon::now()->getTimestamp();
  44. $work_order = WorkOrder::orderBy('created_at', 'desc')->get();
  45. if(!empty($work_order)){
  46. foreach ($work_order as $key => $w) {
  47. $reg_time = $w->created_at;
  48. $expiry_date = $reg_time->addDays(3);
  49. $expiry_date = $expiry_date->getTimestamp();
  50. if($curr < $expiry_date) {
  51. $n1 = "New/";
  52. }else{
  53. $n1 = "";
  54. }
  55. $form = Form::with('PackageDetail','Subscriber')->first();
  56. if(!empty($form)){
  57. $company = Company::where('_id',$w->contractor_id)->first();
  58. $staff = Staff::with('StaffDetail')->where('_id',$w->installer_id)->first();
  59. if(!empty($staff)){
  60. $installer = $staff->StaffDetail->name;
  61. }else{
  62. $installer = '';
  63. }
  64. $address = '';
  65. if($form->type_application == 'R'){
  66. if($form->Subscriber->street != ''){
  67. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  68. }else {
  69. $address = $form->Subscriber->unit_no. ' , '.$form->Subscriber->building_name. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  70. }
  71. }else if($form->type_application == 'B'){
  72. if($form->Subscriber->unit_no != ''){
  73. $address = $form->Subscriber->unit_no. ', '.$form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  74. }else {
  75. $address = $form->Subscriber->company_name. ', '.$form->Subscriber->street. ' , '.$form->Subscriber->postcode. ' , '.$form->Subscriber->city. ' , '.$form->Subscriber->state;
  76. }
  77. }
  78. if($form->type_application == 'R'){
  79. $type = 'Residential';
  80. }else if($form->type_application == 'B'){
  81. $type = 'Business';
  82. }
  83. array_push($data,array(
  84. "work_order_id" => $n1.$w->wo,
  85. "type" => $type,
  86. "contractor" => $company->name,
  87. "installer" => $installer,
  88. "title" => $w->nature_work,
  89. "appoint_date_time"=>date("m/d/Y H:i", strtotime($w->dateTimeStart)),
  90. "cus_name"=> $form->Subscriber->name,
  91. "contact_person" => $form->Subscriber->name,
  92. "contact_no"=> $form->Subscriber->phone1,
  93. "technical" => $form->Subscriber->name,
  94. "address"=> $address,
  95. "status" => $w->status,
  96. ));
  97. }
  98. }
  99. return $this->sendResponse($data, 'Get Work Order List Successfully');
  100. }
  101. }
  102. public function getCustomerList(){
  103. $data = array(); $i = 1;
  104. $n1 = ''; $address = ''; $building = ''; $status = '';
  105. $curr = Carbon::now()->getTimestamp();
  106. $form_submitted = Form::with('PackageDetail','Subscriber','WorkOrder')->withTrashed()->orderBy('created_at', 'desc')->get();
  107. if(!empty($form_submitted)){
  108. foreach ($form_submitted as $key => $v) {
  109. if(!empty($v->Subscriber)){
  110. if(empty($v->WorkOrder)){
  111. $i++;
  112. $reg_time = $v->created_at;
  113. $expiry_date = $reg_time->addDays(3);
  114. $expiry_date = $expiry_date->getTimestamp();
  115. if($curr < $expiry_date) {
  116. $n1 = "New/";
  117. }else{
  118. $n1 = "";
  119. }
  120. if($v->type_application == 'R'){
  121. if($v->Subscriber->street != ''){
  122. $address = $v->Subscriber->unit_no. ' , '.$v->Subscriber->building_name. ' , '.$v->Subscriber->street. ' , '.$v->Subscriber->postcode. ' , '.$v->Subscriber->city. ' , '.$v->Subscriber->state;
  123. $building = $v->Subscriber->building_name;
  124. }else {
  125. $address = $v->Subscriber->unit_no. ' , '.$v->Subscriber->building_name. ' , '.$v->Subscriber->postcode. ' , '.$v->Subscriber->city. ' , '.$v->Subscriber->state;
  126. $building = $v->Subscriber->building_name;
  127. }
  128. }else if($v->type_application == 'B'){
  129. if($v->Subscriber->unit_no != ''){
  130. $address = $v->Subscriber->unit_no. ', '.$v->Subscriber->company_name. ', '.$v->Subscriber->street. ' , '.$v->Subscriber->postcode. ' , '.$v->Subscriber->city. ' , '.$v->Subscriber->state;
  131. $building = $v->Subscriber->company_name;
  132. }else {
  133. $address = $v->Subscriber->company_name. ', '.$v->Subscriber->street. ' , '.$v->Subscriber->postcode. ' , '.$v->Subscriber->city. ' , '.$v->Subscriber->state;
  134. $building = $v->Subscriber->company_name;
  135. }
  136. }
  137. }
  138. if(!empty($v->deleted_at)){
  139. $status = 'Rejected';
  140. }else if($v->status_email == 'unverified') {
  141. $status = 'New';
  142. }else if($v->status_email == 'verified') {
  143. $status = 'Accepted';
  144. }
  145. array_push($data, array(
  146. 'formT' => $n1.$i.$v->type_application,
  147. 'type' => $v->type_service,
  148. 'subscriber_id' => $v->Subscriber->subscriber_id,
  149. 'name' => $v->Subscriber->name,
  150. 'phone' => $v->Subscriber->phone1,
  151. 'email' => $v->Subscriber->email,
  152. 'address' => $address,
  153. 'postcode' => $v->Subscriber->postcode,
  154. 'city' => $v->Subscriber->city,
  155. 'status' => $status,
  156. 'date_submitted' => Carbon::parse($v->created_at)->toDateTimeString()
  157. ));
  158. }
  159. }
  160. return $this->sendResponse($data, 'Get Customer List Successfully');
  161. }else{
  162. return $this->sendError('', 'No Data Been Found!');
  163. }
  164. }
  165. public function customerStatistic(){
  166. $finalD1 = array(); $finalD2 = array(); $finalD3 = array(); $finalD4 = array();
  167. $form_submitted1 = Form::with('PackageDetail','Subscriber','WorkOrder')->withTrashed()->orderBy('created_at', 'desc')->get();
  168. if(!empty($form_submitted1)){
  169. foreach ($form_submitted1 as $key => $v) {
  170. if(!empty($v->Subscriber)){
  171. if(empty($v->WorkOrder)){
  172. $finalD1[] = $v;
  173. }
  174. }
  175. }
  176. }
  177. $form_submitted2= Form::onlyTrashed()->get();
  178. if(!empty($form_submitted2)){
  179. foreach ($form_submitted2 as $key => $v) {
  180. if(!empty($v->Subscriber)){
  181. if(empty($v->WorkOrder)){
  182. $finalD2[] = $v;
  183. }
  184. }
  185. }
  186. }
  187. $form_submitted3= Form::get();
  188. if(!empty($form_submitted3)){
  189. foreach ($form_submitted3 as $key => $v) {
  190. if(!empty($v->Subscriber)){
  191. if(empty($v->WorkOrder)){
  192. if($v->status_email == 'verified') {
  193. $finalD3[] = $v;
  194. }else if($v->status_email == 'unverified'){
  195. $finalD4[] = $v;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. $total = count($finalD1);
  202. $new = count($finalD4);
  203. $reject = count($finalD2);
  204. $accepted = count($finalD3);
  205. $data = array();
  206. $data[] = array("status" => "New", "statistic" => $new);
  207. $data[] = array("status" => "Rejected", "statistic" => $reject);
  208. $data[] = array("status" => "Accepted", "statistic" => $accepted);
  209. $data[] = array("status" => "Total", "statistic" => $total);
  210. return $this->sendResponse($data, 'Get Registration Statistic Successfully');
  211. }
  212. }