| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?php
-
- namespace App\Http\Controllers\v3\Api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\v3\Api\BaseController;
-
- use Config;
- use File;
- use Carbon\Carbon;
-
- use App\LatestModel\Staff;
- use App\LatestModel\StaffDetail;
- use App\LatestModel\Module\Form;
- use App\LatestModel\Module\FormStatus;
- use App\LatestModel\Module\Subscriber;
- use App\LatestModel\Module\WorkOrder;
- use App\LatestModel\Module\Docket;
- use App\LatestModel\Module\PackageDetail;
- use App\LatestModel\Module\Company;
- use App\LatestModel\Module\Coverage;
- use App\LatestModel\Module\Product;
-
- class TeamController extends BaseController
- {
- /**
- * Get insataller rating
- *
- * @return json
- */
-
- public function displayInstallerRating($id){
-
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- $staff = Staff::with('StaffDetail')->where('company_id', $id)->where('roles_access','Installer')->orderBy('created_at','DESC')->withTrashed()->get();
-
- if(!empty($staff)){
- foreach($staff as $s){
- $t_rating = 0;
- $count = count(Docket::where('installer_id',$s->_id)->get());
- $docket = Docket::where('installer_id',$s->_id)->get();
- if(!empty($docket)){
- foreach($docket as $d){
- $t_rating += $d->Rating1 + $d->Rating2 + $d->Rating3;
- }
- }
-
- if($t_rating > 0){
- $t_rating = round(($t_rating/($count*15)) * 100);
- }
-
- $i++;
- array_push($nested_data, array(
- 'index' => $i,
- 'date' => date('d/m/Y H:i:a', strtotime($s->created_at)),
- 'installer_name' => $s->StaffDetail->name,
- 'total_docket' => $count,
- 'total_rating' => $t_rating.'%'
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- /**
- * Get vendor contractor
- *
- * @return json
- */
- public function getVendor($team) {
-
- $i=0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- $team = Company::where('team',$team)->orderBy('created_at','DESC')->get();
-
- if(!empty($team)){
- foreach ($team as $a) {
-
- $n1 = '';
- $reg_time = Carbon::createFromFormat('Y-m-d H:i:s', $a->created_at);
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) { $n1 = 'New/'; }
- else{ $n1 = ''; }
-
- $i++;
- array_push($nested_data, array(
- 'index' => $n1.$i,
- 'name' => $a->name,
- 'address' => $a->address,
- 'city' => $a->city,
- 'state' => $a->state,
- 'postcode' => $a->postcode,
- 'action' => $a->_id
- ));
- }
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- /**
- * Get delete vendor contractor
- *
- * @return json
- */
- public function requestDeleteVendor(Request $request)
- {
- $company = Company::where('_id',$request->id)->first();
-
- if(!empty($company)){
- $staff = Staff::with('StaffDetail')->where('company_id', $company->_id)->get();
- if(!empty($staff)){
- foreach ($staff as $key => $s) {
- $s->staffdetail()->delete();
- $s->delete();
- }
- }
- $company->delete();
- return $this->sendResponse($company, 'Successfully delete vendor');
- }else{
- return $this->sendError('Vendor not found!', '');
- }
- }
-
- /**
- * Get contractor list
- *
- * @return json
- */
- public function getStaffList($roles,$company_id)
- {
- $i = 0;
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
-
- if($company_id == 'null'){
- $staff = Staff::with('Company','StaffDetail')->where('roles_access',$roles)->orderBy('created_at', 'desc')->get();
- }else{
- if($roles == 'Sales'){
- $staff = Staff::with('Company','StaffDetail')->orderBy('created_at', 'desc')->where(function ($q) use($company_id){
- $q->where('roles_access','Sales')->where('company_id',$company_id);
- })->orWhere(function ($q) use($company_id){
- $q->where('roles_access','Dealer')->where('company_id',$company_id);
- })->get();
- }else{
- $staff = Staff::with('Company','StaffDetail')->where('roles_access',$roles)->where('company_id',$company_id)->orderBy('created_at', 'desc')->get();
- }
- }
-
- foreach ($staff as $a) {
- $n1 = '';
- $reg_time = $a->updated_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $i++;
- array_push($nested_data, array(
- 'index' => $n1.$i,
- 'user_pic' => $a->StaffDetail->user_pic,
- 'name' => $a->StaffDetail->name,
- 'ic' => $a->StaffDetail->ic,
- 'email' => $a->StaffDetail->email,
- 'phone' => $a->StaffDetail->phone,
- 'company_id' => $a->Company->name,
- 'position' => $a->StaffDetail->position,
- 'action' => $a->_id,
- 'action1' => $a->company_id,
- '_id' => $a->_id
- ));
- }
- return \DataTables::of($nested_data)->make(true);
- }
-
- /**
- * Delete contractor list
- *
- * @return json
- */
- public function requestDeleteStaff(Request $request)
- {
- $staff = Staff::with('StaffDetail')->where('_id',$request->id)->first();
-
- if(!empty($staff)){
- if(!empty($staff->StaffDetail)){
- $staff->staffdetail()->delete();
- $staff->delete();
- }
- return $this->sendResponse($staff, 'Successfully delete staff');
- }else {
- return $this->sendError('Staff not found!', '');
- }
- }
-
- }
|