Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

MynixController.php 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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->street. ' , '.$form->Subscriber->building_name. ' , '.$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. $unit = $form->Subscriber->unit_no;
  74. }else {
  75. $unit = ' ';
  76. }
  77. if ($form->Subscriber->building_name == null) {
  78. $address = $unit . ' , ' .$form->Subscriber->street . ' , ' .$form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  79. } else {
  80. $address = $unit . ' , ' . $form->Subscriber->street . ' , ' .$form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  81. }
  82. }
  83. if($form->type_application == 'R'){
  84. $type = 'Residential';
  85. }else if($form->type_application == 'B'){
  86. $type = 'Business';
  87. }
  88. array_push($data,array(
  89. "work_order_id" => $n1.$w->wo,
  90. "type" => $type,
  91. "contractor" => $company->name,
  92. "installer" => $installer,
  93. "title" => $w->nature_work,
  94. "appoint_date_time"=>date("m/d/Y H:i", strtotime($w->dateTimeStart)),
  95. "cus_name"=> $form->Subscriber->name,
  96. "contact_person" => $form->Subscriber->name,
  97. "contact_no"=> $form->Subscriber->phone1,
  98. "technical" => $form->Subscriber->name,
  99. "address"=> $address,
  100. "status" => $w->status,
  101. ));
  102. }
  103. }
  104. return $this->sendResponse($data, 'Get Work Order List Successfully');
  105. }
  106. }
  107. public function getCustomerList(){
  108. $data = array(); $i = 1;
  109. $n1 = ''; $address = ''; $building = ''; $status = '';
  110. $curr = Carbon::now()->getTimestamp();
  111. $form_submitted = Form::with('PackageDetail','Subscriber','WorkOrder')->withTrashed()->orderBy('created_at', 'desc')->get();
  112. if(!empty($form_submitted)){
  113. foreach ($form_submitted as $key => $v) {
  114. if(!empty($v->Subscriber)){
  115. if(empty($v->WorkOrder)){
  116. $i++;
  117. $reg_time = $v->created_at;
  118. $expiry_date = $reg_time->addDays(3);
  119. $expiry_date = $expiry_date->getTimestamp();
  120. if($curr < $expiry_date) {
  121. $n1 = "New/";
  122. }else{
  123. $n1 = "";
  124. }
  125. if($v->type_application == 'R'){
  126. if($v->Subscriber->street != ''){
  127. $address = $v->Subscriber->unit_no. ' , '.$v->Subscriber->street. ' , '.$v->Subscriber->building_name. ' , '.$v->Subscriber->postcode. ' , '.$v->Subscriber->city. ' , '.$v->Subscriber->state;
  128. }else {
  129. $address = $v->Subscriber->unit_no. ' , '.$v->Subscriber->building_name. ' , '.$v->Subscriber->postcode. ' , '.$v->Subscriber->city. ' , '.$v->Subscriber->state;
  130. }
  131. }else if($v->type_application == 'B'){
  132. if ($v->Subscriber->unit_no != '') {
  133. $unit = $v->Subscriber->unit_no;
  134. } else {
  135. $unit = ' ';
  136. }
  137. if ($v->Subscriber->building_name == null) {
  138. $address = $unit . ' , ' . $v->Subscriber->street . ' , ' . $v->Subscriber->postcode . ' , ' . $v->Subscriber->city . ' , ' . $v->Subscriber->state;
  139. } else {
  140. $address = $unit . ' , ' . $v->Subscriber->street . ' , ' . $v->Subscriber->building_name . ' , ' . $v->Subscriber->postcode . ' , ' . $v->Subscriber->city . ' , ' . $v->Subscriber->state;
  141. }
  142. }
  143. }
  144. if(!empty($v->deleted_at)){
  145. $status = 'Rejected';
  146. }else if($v->status_email == 'unverified') {
  147. $status = 'New';
  148. }else if($v->status_email == 'verified') {
  149. $status = 'Accepted';
  150. }
  151. array_push($data, array(
  152. 'formT' => $n1.$i.$v->type_application,
  153. 'type' => $v->type_service,
  154. 'subscriber_id' => $v->Subscriber->subscriber_id,
  155. 'name' => $v->Subscriber->name,
  156. 'phone' => $v->Subscriber->phone1,
  157. 'email' => $v->Subscriber->email,
  158. 'address' => $address,
  159. 'postcode' => $v->Subscriber->postcode,
  160. 'city' => $v->Subscriber->city,
  161. 'status' => $status,
  162. 'date_submitted' => Carbon::parse($v->created_at)->toDateTimeString()
  163. ));
  164. }
  165. }
  166. return $this->sendResponse($data, 'Get Customer List Successfully');
  167. }else{
  168. return $this->sendError('', 'No Data Been Found!');
  169. }
  170. }
  171. public function customerStatistic(){
  172. $finalD1 = array(); $finalD2 = array(); $finalD3 = array(); $finalD4 = array();
  173. $form_submitted1 = Form::with('PackageDetail','Subscriber','WorkOrder')->withTrashed()->orderBy('created_at', 'desc')->get();
  174. if(!empty($form_submitted1)){
  175. foreach ($form_submitted1 as $key => $v) {
  176. if(!empty($v->Subscriber)){
  177. if(empty($v->WorkOrder)){
  178. $finalD1[] = $v;
  179. }
  180. }
  181. }
  182. }
  183. $form_submitted2= Form::onlyTrashed()->get();
  184. if(!empty($form_submitted2)){
  185. foreach ($form_submitted2 as $key => $v) {
  186. if(!empty($v->Subscriber)){
  187. if(empty($v->WorkOrder)){
  188. $finalD2[] = $v;
  189. }
  190. }
  191. }
  192. }
  193. $form_submitted3= Form::get();
  194. if(!empty($form_submitted3)){
  195. foreach ($form_submitted3 as $key => $v) {
  196. if(!empty($v->Subscriber)){
  197. if(empty($v->WorkOrder)){
  198. if($v->status_email == 'verified') {
  199. $finalD3[] = $v;
  200. }else if($v->status_email == 'unverified'){
  201. $finalD4[] = $v;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. $total = count($finalD1);
  208. $new = count($finalD4);
  209. $reject = count($finalD2);
  210. $accepted = count($finalD3);
  211. $data = array();
  212. $data[] = array("status" => "New", "statistic" => $new);
  213. $data[] = array("status" => "Rejected", "statistic" => $reject);
  214. $data[] = array("status" => "Accepted", "statistic" => $accepted);
  215. $data[] = array("status" => "Total", "statistic" => $total);
  216. return $this->sendResponse($data, 'Get Registration Statistic Successfully');
  217. }
  218. }