Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TeamController.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace App\Http\Controllers\v3\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\v3\Api\BaseController;
  5. use Config;
  6. use File;
  7. use Carbon\Carbon;
  8. use App\LatestModel\Staff;
  9. use App\LatestModel\StaffDetail;
  10. use App\LatestModel\Module\Form;
  11. use App\LatestModel\Module\FormStatus;
  12. use App\LatestModel\Module\Subscriber;
  13. use App\LatestModel\Module\WorkOrder;
  14. use App\LatestModel\Module\Docket;
  15. use App\LatestModel\Module\PackageDetail;
  16. use App\LatestModel\Module\Company;
  17. use App\LatestModel\Module\Coverage;
  18. use App\LatestModel\Module\Product;
  19. class TeamController extends BaseController
  20. {
  21. /**
  22. * Get insataller rating
  23. *
  24. * @return json
  25. */
  26. public function displayInstallerRating($id){
  27. $i = 0;
  28. $curr = Carbon::now()->getTimestamp();
  29. $nested_data = array();
  30. $staff = Staff::with('StaffDetail')->where('company_id', $id)->where('roles_access','Installer')->orderBy('created_at','DESC')->withTrashed()->get();
  31. if(!empty($staff)){
  32. foreach($staff as $s){
  33. $t_rating = 0;
  34. $count = count(Docket::where('installer_id',$s->_id)->get());
  35. $docket = Docket::where('installer_id',$s->_id)->get();
  36. if(!empty($docket)){
  37. foreach($docket as $d){
  38. $t_rating += $d->Rating1 + $d->Rating2 + $d->Rating3;
  39. }
  40. }
  41. if($t_rating > 0){
  42. $t_rating = round(($t_rating/($count*15)) * 100);
  43. }
  44. $i++;
  45. array_push($nested_data, array(
  46. 'index' => $i,
  47. 'date' => date('d/m/Y H:i:a', strtotime($s->created_at)),
  48. 'installer_name' => $s->StaffDetail->name,
  49. 'total_docket' => $count,
  50. 'total_rating' => $t_rating.'%'
  51. ));
  52. }
  53. }
  54. return \DataTables::of($nested_data)->make(true);
  55. }
  56. /**
  57. * Get vendor contractor
  58. *
  59. * @return json
  60. */
  61. public function getVendor($team) {
  62. $i=0;
  63. $curr = Carbon::now()->getTimestamp();
  64. $nested_data = array();
  65. $team = Company::where('team',$team)->orderBy('created_at','DESC')->get();
  66. if(!empty($team)){
  67. foreach ($team as $a) {
  68. $n1 = '';
  69. $reg_time = Carbon::createFromFormat('Y-m-d H:i:s', $a->created_at);
  70. $expiry_date = $reg_time->addDays(3);
  71. $expiry_date = $expiry_date->getTimestamp();
  72. if($curr < $expiry_date) { $n1 = 'New/'; }
  73. else{ $n1 = ''; }
  74. $i++;
  75. array_push($nested_data, array(
  76. 'index' => $n1.$i,
  77. 'name' => $a->name,
  78. 'address' => $a->address,
  79. 'city' => $a->city,
  80. 'state' => $a->state,
  81. 'postcode' => $a->postcode,
  82. 'action' => $a->_id
  83. ));
  84. }
  85. }
  86. return \DataTables::of($nested_data)->make(true);
  87. }
  88. /**
  89. * Get delete vendor contractor
  90. *
  91. * @return json
  92. */
  93. public function requestDeleteVendor(Request $request)
  94. {
  95. $company = Company::where('_id',$request->id)->first();
  96. if(!empty($company)){
  97. $staff = Staff::with('StaffDetail')->where('company_id', $company->_id)->get();
  98. if(!empty($staff)){
  99. foreach ($staff as $key => $s) {
  100. $s->staffdetail()->delete();
  101. $s->delete();
  102. }
  103. }
  104. $company->delete();
  105. return $this->sendResponse($company, 'Successfully delete vendor');
  106. }else{
  107. return $this->sendError('Vendor not found!', '');
  108. }
  109. }
  110. /**
  111. * Get contractor list
  112. *
  113. * @return json
  114. */
  115. public function getStaffList($roles,$company_id)
  116. {
  117. $i = 0;
  118. $curr = Carbon::now()->getTimestamp();
  119. $nested_data = array();
  120. if($company_id == 'null'){
  121. $staff = Staff::with('Company','StaffDetail')->where('roles_access',$roles)->orderBy('created_at', 'desc')->get();
  122. }else{
  123. if($roles == 'Sales'){
  124. $staff = Staff::with('Company','StaffDetail')->orderBy('created_at', 'desc')->where(function ($q) use($company_id){
  125. $q->where('roles_access','Sales')->where('company_id',$company_id);
  126. })->orWhere(function ($q) use($company_id){
  127. $q->where('roles_access','Dealer')->where('company_id',$company_id);
  128. })->get();
  129. }else{
  130. $staff = Staff::with('Company','StaffDetail')->where('roles_access',$roles)->where('company_id',$company_id)->orderBy('created_at', 'desc')->get();
  131. }
  132. }
  133. foreach ($staff as $a) {
  134. $n1 = '';
  135. $reg_time = $a->updated_at;
  136. $expiry_date = $reg_time->addDays(3);
  137. $expiry_date = $expiry_date->getTimestamp();
  138. if($curr < $expiry_date) {
  139. $n1 = "New/";
  140. }
  141. $i++;
  142. array_push($nested_data, array(
  143. 'index' => $n1.$i,
  144. 'user_pic' => $a->StaffDetail->user_pic,
  145. 'name' => $a->StaffDetail->name,
  146. 'ic' => $a->StaffDetail->ic,
  147. 'email' => $a->StaffDetail->email,
  148. 'phone' => $a->StaffDetail->phone,
  149. 'company_id' => $a->Company->name,
  150. 'position' => $a->StaffDetail->position,
  151. 'action' => $a->_id,
  152. 'action1' => $a->company_id,
  153. '_id' => $a->_id
  154. ));
  155. }
  156. return \DataTables::of($nested_data)->make(true);
  157. }
  158. /**
  159. * Delete contractor list
  160. *
  161. * @return json
  162. */
  163. public function requestDeleteStaff(Request $request)
  164. {
  165. $staff = Staff::with('StaffDetail')->where('_id',$request->id)->first();
  166. if(!empty($staff)){
  167. if(!empty($staff->StaffDetail)){
  168. $staff->staffdetail()->delete();
  169. $staff->delete();
  170. }
  171. return $this->sendResponse($staff, 'Successfully delete staff');
  172. }else {
  173. return $this->sendError('Staff not found!', '');
  174. }
  175. }
  176. }