File: /var/www/html/fieldsblaze-heroku/app/Http/Controllers/APICommonController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
use DB;
use App\Library\UserLib;
use App\Models\User;
use App\Models\Product;
use App\Models\Customer;
use App\Models\PriceBookEntry;
use App\Models\Order;
use App\Models\OrderItems;
use App\Models\OrderStatus;
use App\Models\Countries;
use App\Models\PaymentType;
use App\Models\Contact;
use App\Models\Visits;
use App\Models\VisitCustomer;
use App\Models\BeatPlan;
use App\Models\Performance;
use App\Models\Collection;
use App\Models\Attendance;
use App\Models\Notes;
use App\Models\Leave;
use App\Models\Stocks;
use App\Models\Announcement;
use App\Models\UserProfile;
use App\Models\Expense;
use App\Models\ExpenseType;
use App\Models\ExpenseTypeTravel;
use App\Models\SalesArea;
use App\Models\SalesTerritory;
use App\Models\TermsConditions;
use App\Models\CompanyProfile;
use App\Models\CompanyBankDetail;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;
class APICommonController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $userLib;
protected $dateFormat = 'dd-mm-yyyy';
protected $TeamList;
public function __construct(UserLib $userLib)
{
$this->userLib = $userLib;
}
public function getManagerTeamList($ManagerId='') {
//Check Memeber is exist or not
$users = User::select('UserId', 'FirstName', 'LastName', 'Email','Mobile', 'ManagerId', 'ProfileId')
->where('ManagerId',$ManagerId)
->get();
if ($users->count() > 0)
{ //email is exist
foreach ($users as $key => $UValue)
{
$UserId = $UValue['UserId'];
$FirstName = $UValue['FirstName'];
$LastName = $UValue['LastName'];
$ManagerId = $UValue['ManagerId'];
$this->TeamList[] = $UserId;
//echo 'UserId - '.$UserId .'('.$FirstName.') '.', ManagerId - '.$ManagerId."\n";
$this->getManagerTeamList($UserId);
}
}
return $responseData = $this->TeamList;
//return response()->json($responseData);
}
//getUserAccessCheck
public function getUserAccessCheck(Request $request, $ProfileId='', $ModuleId='') {
$data = $request->json()->all();
$UserId = $request->header('UserId');
$AuthToken = $request->header('AuthToken');
if($this->userLib->tokenChecker($request) == FALSE)
{
$response = [
'success' => false,
'ResponseMessage' => "Authentication Failed",
'ResponseCode' => "301",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
if(!$ProfileId)
{
$response = [
'success' => false,
'ResponseMessage' => "ProfileId Required",
'ResponseCode' => "203",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
if(!$ModuleId)
{
$response = [
'success' => false,
'ResponseMessage' => "ModuleId Required",
'ResponseCode' => "203",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
$ManagerName = '';
$UserProfileData = array();
$UserProfiles = UserProfile::select('ModuleId','ModuleName', 'W', 'R', 'U','D','Mobile','Created_at','Updated_at')
->where('ModuleId', $ModuleId)
->where('ProfileId', $ProfileId)
->OrderBy('ModuleName','Asc')->get();
if ($UserProfiles->count() > 0)
{ //user is exist
$UserProfileData = $UserProfiles->first();
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'ModulesDetails' => $UserProfileData,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
else
{
$response = [
'Success' => true,
'ResponseMessage' => "ModuleId not found",
'ResponseCode' => "201",
'UserId' => $UserId,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//getVisitsDetails
public function checkAuthToken(Request $request, $VisitId='') {
$data = $request->json()->all();
$UserId = $request->header('UserId');
$AuthToken = $request->header('AuthToken');
//check auth token
if($this->userLib->tokenChecker($request) == TRUE)
{
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'AuthToken' => $AuthToken,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
else
{
$response = [
'success' => false,
'ResponseMessage' => "Authentication Failed",
'ResponseCode' => "301",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
### All Customer
public function getCustomerList(Request $request, $Created_by =''){
$data = $request->json()->all();
$UserId = $request->header('UserId');
$AuthToken = $request->header('AuthToken');
//check auth token
if($this->userLib->tokenChecker($request) == FALSE)
{
$response = [
'success' => false,
'ResponseMessage' => "Authentication Failed",
'ResponseCode' => "301",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
$Created_by = $UserId;
//Get cutomer list
$Customers = Customer::select('tbl_customer.*', 'tbl_price_book.PriceBookName', 'tbl_user.FirstName as Updated_by_name', 'tbl_user.FirstName as Created_by_name')
->leftJoin('tbl_user', 'tbl_customer.Created_by', '=', 'tbl_user.UserId')
->leftJoin('tbl_price_book', 'tbl_customer.PriceBookId', '=', 'tbl_price_book.PriceBookId')
->where('tbl_customer.IsDeleted', '=', '0')
->where('tbl_customer.Status', '=', '1')
->where('tbl_customer.Created_by', '=', $Created_by)
->get();
$CutomerCount = $Customers->count();
//End cutomer list
//Get order list
$Order = Order::select('*')
->where('Created_by', 'like', $Created_by)
->where('IsDeleted', '=', 0)
->where('Status', '=', 1)
->orderBy('id', 'desc')
->get();
$Order = Customer::select('tbl_order.*')
->leftJoin('tbl_order', 'tbl_customer.CustomerId', '=', 'tbl_order.CustomerId')
->where('tbl_customer.IsDeleted', '=', '0')
->where('tbl_order.IsDeleted', '=', '0')
->where('tbl_order.Created_by',$Created_by)
->orderBy('tbl_order.id', 'desc')
->get();
$OrderCount = $Order->count();
//End of order list
//Get Collections list
$Collections = Collection::select('*')
->where('Created_by', 'like', $Created_by)
->where('IsDeleted', '=', 0)
->where('Status', '=', 1)
->orderBy('id', 'desc')
->get();
$CollectionsCount = $Collections->count();
//End of Collections list
//Start Attendance list
$Attendance = Attendance::select('*')
->where('Created_by',$Created_by)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get();
$AttendanceCount = $Attendance->count();
//End of Attendance list
//Start Leave list
$Leave = Leave::select('*')
->where('Created_by',$Created_by)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->orderBy('id', 'DESC')
->get();
$LeaveCount = $Leave->count();
//End Leave list
//Start Notes list
$Notes = Notes::select('*')
->where('Created_by',$Created_by)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get();
$NotesCount = $Notes->count();
//End Notes list
//Start Expenses list
$Expenses = Expense::select('*')
->where('Created_by',$Created_by)
->where('IsDeleted', '=', 0)
->orderBy('id', 'desc')
->get();
$ExpensesCount = $Expenses->count();
//End Expenses list
//Start BeatPlan list
$BeatPlans = BeatPlan::select('*')
->where('Created_by',$Created_by)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->orderBy('id', 'DESC')
->get();
$BeatPlansCount = $BeatPlans->count();
//End BeatPlan list
//Start Expenses list
$Visits = Visits::select('*')
->where('Created_by',$Created_by)
->where('IsDeleted', '=', 0)
->where('Status', '=', '1')
->orderBy('id', 'DESC')
->get();
$VisitsCount = $Visits->count();
//End Expenses list
//Start Stocks list
$Stocks = Stocks::select('*')
->where('Created_by',$Created_by)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get();
$StocksCount = $Stocks->count();
//End Stocks list
//Start Announcements list
$Announcements = Announcement::select('*')
->where('Created_by',$Created_by)
->where('Status', '=', '1')
->where('IsDeleted', '=', '0')
->get();
$AnnouncementsCount = $Announcements->count();
//End Announcements list
//Start Performance list
$Performances = Performance::select('*')
->where('Created_by',$Created_by)
->where('Status', '=', '1')
->where('IsDeleted', '=', '0')
->get();
$PerformancesCount = $Performances->count();
//End Performance list
$DashboardCounter = array(
'CutomerCount' => $CutomerCount,
'OrderCount' => $OrderCount,
'CollectionsCount' => $CollectionsCount,
'AttendanceCount' => $AttendanceCount,
'LeaveCount' => $LeaveCount,
'NotesCount' => $NotesCount,
'ExpensesCount' => $ExpensesCount,
'BeatPlansCount' => $BeatPlansCount,
'VisitsCount' => $VisitsCount,
'StocksCount' => $StocksCount,
'AnnouncementsCount' => $AnnouncementsCount,
'PerformancesCount' => $PerformancesCount,
);
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'AuthToken' => $AuthToken,
'DashboardCounter' => $DashboardCounter,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
//getSignUpTermCondition
public function getSignUpTermCondition(Request $request, $CrmId='') {
$data = $request->json()->all();
$UserId = $request->header('UserId');
$AuthToken = $request->header('AuthToken');
if($CrmId)
{
$TermsConditions = TermsConditions::select('*')
->where('CrmId',$CrmId)
->where('TermsId','bN7yWYznvyLyAc214BruueLMbsMQMbrPBBCxS')
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get()->first();
}
else
{
$TermsConditions = TermsConditions::select('*')
->where('TermsId','bN7yWYznvyLyAc214BruueLMbsMQMbrPBBCxS')
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get()->first();
}
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'SignupTermsCondition' => $TermsConditions,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
public function getTime()
{
$date = date('d-m-Y H:i:s',time());
echo "Date = ".$date;
}
### All Company Profile List
public function getCompanyProfileList(Request $request){
$data = $request->json()->all();
$UserId = $request->header('UserId');
$AuthToken = $request->header('AuthToken');
//check auth token
if($this->userLib->tokenChecker($request) == FALSE)
{
$response = [
'success' => false,
'ResponseMessage' => "Authentication Failed",
'ResponseCode' => "301",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
//Get CompanyProfile list
$getCompanyProfile = CompanyProfile::select('tbl_company_profile.*', 'tbl_countries.country_name as CountryName')
->leftJoin('tbl_countries', 'tbl_company_profile.Country', '=', 'tbl_countries.id')
// ->where('IsDeleted', '=', '0')
// ->where('Status', '=', '1')
->get();
//Get CompanyBankDetail list
$getCompanyBankDetail = CompanyBankDetail::select('tbl_company_bank_detail.*')
->where('IsDeleted', '=', '0')
->where('Status', '=', '1')
->orderBy('id', 'desc')
->get();
$CompanyProfile = array(
'CompanyDetail' => $getCompanyProfile,
'BankDetail' => $getCompanyBankDetail,
);
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'AuthToken' => $AuthToken,
'CompanyProfile' => $CompanyProfile,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}