File: /var/www/html/fieldsblaze-heroku/app/Http/Controllers/APICollectionController.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\Collection;
use App\Models\PaymentType;
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;
use App\Http\Controllers\APICommonController;
class APICollectionController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $userLib;
protected $dateFormat = 'dd-mm-yyyy';
protected $APICommonController;
public function __construct(UserLib $userLib, APICommonController $APICommonController)
{
$this->userLib = $userLib;
$this->APICommonController = $APICommonController;
}
//User Registration
public function createCollection(Request $request) {
//TODO What is device_token
$data = $request->json()->all();
$CollectionId = $this->userLib->useridGenrator();
$CreatedDate = date('Y-m-d H:i:s',time());
$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);
}
if(!$data['CustomerId'])
{
$response = [
'success' => false,
'ResponseMessage' => "Customer Id Required",
'ResponseCode' => "302",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
$data['CollectionNo'] = "COL-".time().'-'.rand();
$data['CollectionId'] = $CollectionId;
// $data['CollectionDate'] = $CreatedDate;
$data['Updated_at'] = $CreatedDate;
$data['Created_at'] = $CreatedDate;
$data['Created_by'] = $UserId;
$data['Updated_by'] = $UserId;
$data['AssignTo'] = $UserId;
$collection_insert = Collection::insert($data);
if($collection_insert)
{
$AmountPaid = isset($data['AmountPaid']) ? $data['AmountPaid'] : '';
$CollectionDate = isset($data['CollectionDate']) ? $data['CollectionDate'] : '';
$CollectionType = isset($data['CollectionType']) ? $data['CollectionType'] : '';
$CustomerId = isset($data['CustomerId']) ? $data['CustomerId'] : '';
$Description = isset($data['Description']) ? $data['Description'] : '';
$OrderId = isset($data['OrderId']) ? $data['OrderId'] : '';
$PaymentType = isset($data['PaymentType']) ? $data['PaymentType'] : '';
$ReferenceNo = isset($data['ReferenceNo']) ? $data['ReferenceNo'] : '';
$Status = isset($data['Status']) ? $data['Status'] : '';
$Updated_by = isset($data['Updated_by']) ? $data['Updated_by'] : '';
$CollectionNo = isset($data['CollectionNo']) ? $data['CollectionNo'] : '';
$IsDeleted = '0';
// $Created_by = isset($data['Created_by']) ? $data['Created_by'] : '';
$CollectionQuery = "insert into salesforce.Collection__c (Collection_Id__c,Amount_Paid__c,CollectionDate__c,CollectionType__c,Customer_Id__c,Description__c,Order_Id__c,Payment_Type__c,ReferenceNo__c,IsDeleted,Status__c,Updated_by__c, collection_no__c, Updated_at__c,Name) values ('$CollectionId','$AmountPaid','$CollectionDate','$CollectionType','$CustomerId','$Description','$OrderId','$PaymentType','$ReferenceNo','$IsDeleted','$Status','$Updated_by', '$CollectionNo', '$CreatedDate','$CollectionNo')";
DB::connection('pgsql')->insert($CollectionQuery);
$CollectionDetails = Collection::where('CollectionId', '=', $CollectionId)->get()->first();
if ($CollectionDetails->CustomerId) {
$Customer = Customer::where('CustomerId', '=', $CollectionDetails->CustomerId)->get()->first();
$CustomerCode = $Customer->CustomerCode;
$CustomerName = $Customer->CustomerName;
$CollectionDetails->CustomerName = $CustomerName;
}
$response = [
'Success' => true,
'ResponseMessage' => "Colletion has been created",
'ResponseCode' => "200",
'Collection' => $CollectionDetails,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
'CollectionQuery' => $CollectionQuery
];
return response()->json($response);
}
else
{
$response = [
'Success' => false,
'ResponseMessage' => "Invalid data",
'ResponseCode' => "204",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//User Registration
public function updateCollection(Request $request) {
//TODO What is device_token
$data = $request->json()->all();
$CollectionId = $this->userLib->useridGenrator();
$CreatedDate = date('Y-m-d H:i:s',time());
$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);
}
if(!$data['CustomerId'])
{
$response = [
'success' => false,
'ResponseMessage' => "Customer Id Required",
'ResponseCode' => "302",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
$CollectionId = $data['CollectionId'];
// $data['CollectionDate'] = $CreatedDate;
$data['Updated_at'] = $CreatedDate;
$data['Updated_by'] = $UserId;
$data['AssignTo'] = $UserId;
unset($data['CollectionId']);
$collection_insert = Collection::where('CollectionId', '=', $CollectionId)->update($data);
if($collection_insert)
{
$AmountPaid = isset($data['AmountPaid']) ? $data['AmountPaid'] : '';
$CollectionDate = isset($data['CollectionDate']) ? $data['CollectionDate'] : '';
$CollectionType = isset($data['CollectionType']) ? $data['CollectionType'] : '';
$CustomerId = isset($data['CustomerId']) ? $data['CustomerId'] : '';
$Description = isset($data['Description']) ? $data['Description'] : '';
$OrderId = isset($data['OrderId']) ? $data['OrderId'] : '';
$PaymentType = isset($data['PaymentType']) ? $data['PaymentType'] : '';
$ReferenceNo = isset($data['ReferenceNo']) ? $data['ReferenceNo'] : '';
$Updated_by = isset($data['Updated_by']) ? $data['Updated_by'] : '';
$CollectionQuery = "update salesforce.Collection__c set Amount_Paid__c='$AmountPaid',CollectionDate__c='$CollectionDate',CollectionType__c='$CollectionType',Customer_Id__c='$CustomerId',Description__c='$Description',Order_Id__c='$OrderId',Payment_Type__c='$PaymentType',ReferenceNo__c='$ReferenceNo',Updated_by__c='$Updated_by', Updated_at__c = '$CreatedDate' where Collection_Id__c='$CollectionId'";
DB::connection('pgsql')->update($CollectionQuery);
$CollectionDetails = Collection::where('CollectionId', '=', $CollectionId)->get()->first();
if ($CollectionDetails->CustomerId) {
$Customer = Customer::where('CustomerId', '=', $CollectionDetails->CustomerId)->get()->first();
$CustomerCode = $Customer->CustomerCode;
$CustomerName = $Customer->CustomerName;
$CollectionDetails->CustomerName = $CustomerName;
}
$response = [
'Success' => true,
'ResponseMessage' => "Colletion has been updated",
'ResponseCode' => "200",
'Collection' => $CollectionDetails,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
'CollectionQuery' => $CollectionQuery
];
return response()->json($response);
}
else
{
$response = [
'Success' => false,
'ResponseMessage' => "Invalid data",
'ResponseCode' => "204",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//Upload collection image
public function uploadCollectionfiles(Request $request) {
//TODO What is device_token
// $data = $request->json()->all();
$CreatedDate = date('Y-m-d H:i:s',time());
$CollectionId = $request->input('CollectionId');
$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);
}
$data = array();
$data['Updated_by'] = session('UserId');;
$data['Updated_at'] = $CreatedDate;
// if ($request->hasFile('PaymentFile1'))
// {
// $imageName = $this->userLib->useridGenrator();
// $file = $request->file('PaymentFile1');
// $extension = $file->getClientOriginalExtension();
// $newFileName = $imageName.'-'.time() . '.' . $extension;
// Storage::putFileAs(
// 'public/collection', $file, $newFileName
// );
// $path = Storage::url('collection/'.$newFileName);
// $data['PaymentFile1'] = $path;
// }
$imageName1 = $this->userLib->useridGenrator();
if ($request->hasFile('PaymentFile1'))
{
$path1 = '';
$file1 = $request->file('PaymentFile1');
$extension = $file1->getClientOriginalExtension();
$newFileName1 = $imageName1 . '-' . time() . '.' . $extension;
Storage::putFileAs(
'public/collection',
$file1,
$newFileName1
);
$destinationPath = 'collection';
$isUploaded = $file1->move($destinationPath,$newFileName1);
$uploadedFileURL1 = '';
if($isUploaded)
{
$path1 = 'collection/' . $newFileName1;
$ThumbnailUrl = $path1;
//File Upload Service as s3
$sourceFileURL = env('APP_URL').'/'.$path1;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://172.105.42.62/s3-file-server/api-upload.php',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('file_url' => $sourceFileURL),
CURLOPT_HTTPHEADER => array(
'Cookie: private_content_version=3f7abce738dd8b52d0dcb8653bfe8e93; mage-messages=%5B%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%2C%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%2C%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%5D'
),
));
$response = curl_exec($curl);
curl_close($curl);
$uploadedFile = json_decode($response,true);
$uploadedFileURL1 = isset($uploadedFile['url']) ? $uploadedFile['url'] : '';
}
$data['PaymentFile1'] = $uploadedFileURL1;
}
// if ($request->hasFile('PaymentFile2'))
// {
// $imageName2 = $this->userLib->useridGenrator();
// $file2 = $request->file('PaymentFile2');
// $extension2 = $file2->getClientOriginalExtension();
// $newFileName2 = $imageName2.'-'.time() . '.' . $extension2;
// Storage::putFileAs(
// 'public/collection', $file2, $newFileName2
// );
// $path2 = Storage::url('collection/'.$newFileName2);
// $data['PaymentFile2'] = $path2;
// }
$imageName2 = $this->userLib->useridGenrator();
if ($request->hasFile('PaymentFile2'))
{
$path2 = '';
$file2 = $request->file('PaymentFile2');
$extension = $file2->getClientOriginalExtension();
$newFileName2 = $imageName2 . '-' . time() . '.' . $extension;
Storage::putFileAs(
'public/collection',
$file2,
$newFileName2
);
$destinationPath = 'collection';
$isUploaded = $file2->move($destinationPath,$newFileName2);
$uploadedFileURL2='';
if($isUploaded)
{
$path2 = 'collection/' . $newFileName2;
$ThumbnailUrl = $path2;
//File Upload Service
$sourceFileURL = env('APP_URL').'/'.$path2;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://172.105.42.62/s3-file-server/api-upload.php',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('file_url' => $sourceFileURL),
CURLOPT_HTTPHEADER => array(
'Cookie: private_content_version=3f7abce738dd8b52d0dcb8653bfe8e93; mage-messages=%5B%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%2C%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%2C%7B%22type%22%3A%22error%22%2C%22text%22%3A%22Invalid%20Form%20Key.%20Please%20refresh%20the%20page.%22%7D%5D'
),
));
$response = curl_exec($curl);
curl_close($curl);
$uploadedFile = json_decode($response,true);
$uploadedFileURL2 = isset($uploadedFile['url']) ? $uploadedFile['url'] : '';
}
$data['PaymentFile2'] = $uploadedFileURL2;
}
$collection_update = Collection::where('CollectionId', $CollectionId)->update($data);
if($collection_update)
{
$CollectionDetails = Collection::where('CollectionId', $CollectionId)->get()->first();
if ($CollectionDetails->CustomerId) {
$Customer = Customer::where('CustomerId', '=', $CollectionDetails->CustomerId)->get()->first();
$CustomerCode = $Customer->CustomerCode;
$CustomerName = $Customer->CustomerName;
$CollectionDetails->CustomerName = $CustomerName;
}
$response = [
'success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'ApiVersion' => env('APP_VERSION'),
'ApiUrl' => env('APP_URL'),
'Collection'=>$CollectionDetails,
];
return response()->json($response);
}
else
{
$response = [
'Success' => false,
'ResponseMessage' => "Invalid data",
'ResponseCode' => "202",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//collectionPaymentType
public function collectionPaymentType(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);
}
$Paymenttypes = PaymentType::select('*')
->where('Status', '=', 1)
->orderBy('PaymentTypeName', 'asc')
->get();
if ($Paymenttypes->count() > 0)
{
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'AuthToken' => $AuthToken,
'Paymenttypes' => $Paymenttypes,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
else
{
// fail
$response = [
'Success' => false,
'ResponseMessage' => "Collections does not exist",
'ResponseCode' => "201",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//customerCllectionList
public function customerCllectionList(Request $request, $CustomerId='')
{
$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);
}
if(!$CustomerId)
{
$response = [
'success' => false,
'ResponseMessage' => "Please provide CustomerId",
'ResponseCode' => "203",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $CollectionId)
->where('CustomerId', $CustomerId)
->where('IsDeleted', '=', 0)
->orderBy('id', 'desc')
->get();
if ($Collections->count() > 0)
{
foreach ($Collections as $key => $ColletionValue)
{
$CustomerId = $ColletionValue->CustomerId;
$CreatedFormatedDate = $ColletionValue->Created_at;
$CreatedFormatedDate = date("j M Y",strtotime($CreatedFormatedDate));
$ColletionValue->CreatedFormatedDate = $CreatedFormatedDate;
$custmer = Customer::where('CustomerId', $CustomerId)->get();
if ($custmer->count() > 0)
{ //email is not exist
$custmer = $custmer->first();
$CustomerName = $custmer->CustomerName;
}
$ColletionValue['CustomerName'] = $CustomerName;
}
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'AuthToken' => $AuthToken,
'Collections' => $Collections,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
else
{
// fail
$response = [
'Success' => false,
'ResponseMessage' => "Collections does not exist",
'ResponseCode' => "201",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//getOrderDetails
public function collectionList(Request $request, $SearchText ='')
{
$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);
}
$TeamList = $this->APICommonController->getManagerTeamList($UserId);
if($TeamList && $SearchText)
{
array_push($TeamList, $UserId);
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $SearchText)
->where('IsDeleted', '=', 0)
->whereIn('AssignTo', $TeamList)
->orderBy('id', 'desc')
->get();
}
else
{
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $SearchText)
->where('IsDeleted', '=', 0)
->where('AssignTo', '=', $UserId)
->orderBy('id', 'desc')
->get();
}
if ($Collections->count() > 0)
{
foreach ($Collections as $key => $ColletionValue)
{
$CustomerId = $ColletionValue->CustomerId;
$CreatedFormatedDate = $ColletionValue->Created_at;
$CreatedFormatedDate = date("j M Y",strtotime($CreatedFormatedDate));
$ColletionValue->CreatedFormatedDate = $CreatedFormatedDate;
$CustomerName = '';
$custmer = Customer::where('CustomerId', $CustomerId)->get();
if ($custmer->count() > 0)
{ //email is not exist
$custmer = $custmer->first();
$CustomerName = $custmer->CustomerName;
}
$ColletionValue['CustomerName'] = $CustomerName;
}
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'AuthToken' => $AuthToken,
'Collections' => $Collections,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
else
{
// fail
$response = [
'Success' => false,
'ResponseMessage' => "Collections does not exist",
'ResponseCode' => "201",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//getOrderDetails
public function collectionListFilter(Request $request, $filter='')
{
$data = $request->json()->all();
$UserId = $request->header('UserId');
$AuthToken = $request->header('AuthToken');
$TeamList = '';
//check auth token
if($this->userLib->tokenChecker($request) == FALSE)
{
$response = [
'success' => false,
'error_message' => "Authentication Failed",
'error_code' => "301",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
$today = date('Y-m-d',time());
//DB::enableQueryLog();
if(strtoupper($filter)==strtoupper('Today'))
{
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $CollectionId)
->where('IsDeleted', '=', 0)
->where('Created_by', '=', $UserId)
->where('Created_at', 'like', '%'.$today.'%')
->orderBy('id', 'desc')
->get();
}
else if(strtoupper($filter)==strtoupper('UpComing'))
{
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $CollectionId)
->where('IsDeleted', '=', 0)
->where('Created_by', '=', $UserId)
->where('Created_at', '>', $today)
->orderBy('id', 'desc')
->get();
}
else if(strtoupper($filter)==strtoupper('Past'))
{
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $CollectionId)
->where('IsDeleted', '=', 0)
->where('Created_by', '=', $UserId)
->where('Created_at', '<', $today)
->orderBy('id', 'desc')
->get();
}
else if(strtoupper($filter)==strtoupper('team'))
{
$TeamList = $this->APICommonController->getManagerTeamList($UserId);
if($TeamList)
{
// array_push($TeamList, $UserId);
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $CollectionId)
->where('IsDeleted', '=', 0)
->whereIn('Created_by', $TeamList)
->orderBy('id', 'desc')
->get();
}
}
else
{
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $CollectionId)
->where('IsDeleted', '=', 0)
->where('Created_by', '=', $UserId)
->orderBy('id', 'desc')
->get();
}
if ($Collections->count() > 0)
{
foreach ($Collections as $key => $ColletionValue)
{
$CustomerId = $ColletionValue->CustomerId;
$CreatedFormatedDate = $ColletionValue->Created_at;
$CreatedFormatedDate = date("j M Y",strtotime($CreatedFormatedDate));
$ColletionValue->CreatedFormatedDate = $CreatedFormatedDate;
$CustomerName = '';
$custmer = Customer::where('CustomerId', $CustomerId)->get();
if ($custmer->count() > 0)
{ //email is not exist
$custmer = $custmer->first();
$CustomerName = $custmer->CustomerName;
}
$ColletionValue['CustomerName'] = $CustomerName;
}
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'AuthToken' => $AuthToken,
'Collections' => $Collections,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
'TeamList'=>$TeamList
];
return response()->json($response);
}
else
{
// fail
$response = [
'Success' => false,
'ResponseMessage' => "Collections does not exist",
'ResponseCode' => "201",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//getOrderStatusList
public function getOrderStatusList(Request $request, $CustomerId='') {
$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);
}
$OrderStatus = OrderStatus::select('*')
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get();
if ($OrderStatus->count() > 0)
{
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'AuthToken' => $AuthToken,
'OrderStatus' => $OrderStatus,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
else
{
// fail
$response = [
'Success' => false,
'ResponseMessage' => "OrderStatus does not exist",
'ResponseCode' => "201",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
//getOrderStatusList
public function getCollectionDetails(Request $request, $CollectionId='') {
$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);
}
$Collections = Collection::select('*')
->where('CollectionId', '=', $CollectionId)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get();
if ($Collections->count() > 0)
{
$CollectionData = $Collections->first();
$OrderId = $CollectionData->OrderId;
if ($CollectionData->CustomerId) {
$Customer = Customer::where('CustomerId', '=', $CollectionData->CustomerId)->get()->first();
$CustomerCode = $Customer->CustomerCode;
$CustomerName = $Customer->CustomerName;
$CollectionData->CustomerName = $CustomerName;
}
if ($CollectionData->PaymentType) {
$pt = PaymentType::where('PaymentTypeId', '=', $CollectionData->PaymentType)->get()->first();
$PaymentTypeName = $pt->PaymentTypeName;
$CollectionData->PaymentTypeName = $PaymentTypeName;
}
if ($CollectionData->OrderId) {
$Order = Order::where('OrderId', '=', $CollectionData->OrderId)->get()->first();
$OrderNo = isset($Order->OrderNo) ? $Order->OrderNo : '';
$CollectionData->OrderNo = $OrderNo;
}
$CreatedFormatedDate = $CollectionData->Created_at;
$CreatedFormatedDate = date("j M Y",strtotime($CreatedFormatedDate));
$CollectionData->CreatedFormatedDate = $CreatedFormatedDate;
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'AuthToken' => $AuthToken,
'Collection' => $CollectionData,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
else
{
// fail
$response = [
'Success' => false,
'ResponseMessage' => "Collection does not exist",
'ResponseCode' => "201",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}
function count_digit($number) {
return strlen($number);
}
function divider($number_of_digits)
{
$tens="1";
if($number_of_digits>8)
return 10000000;
while(($number_of_digits-1)>0)
{
$tens.="0";
$number_of_digits--;
}
return $tens;
}
//collectionListSearchText
public function collectionListSearchText(Request $request, $SearchText ='')
{
$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);
}
$TeamList = $this->APICommonController->getManagerTeamList($UserId);
array_push($TeamList, $UserId);
if($SearchText)
{
//DB::enableQueryLog(); // Enable query log
$Customers = Customer::select('*')
->where('CustomerName', 'iLIKE', '%'.$SearchText.'%')
->where('IsDeleted', '=', 0)
->whereIn('AssignTo', $TeamList)
->orderBy('id', 'desc')
->get();
//dd(DB::getQueryLog()); // Show results of log
$CustomerIds = array();
if($Customers->count() > 0)
{ //email is exist
foreach ($Customers as $key => $CValue)
{
$CustomerId = $CValue['CustomerId'];
$CustomerIds[] = $CustomerId;
}
}
$CustomerIds2 = implode(',',$CustomerIds);
// print_r($CustomerIds);
// DB::enableQueryLog(); // Enable query log
$Collections = Collection::select('*')
->where('IsDeleted', '=', 0)
->whereIn('Created_by', $TeamList)
->whereIn('CustomerId', $CustomerIds)
// ->orWhere('CollectionType', 'iLIKE', '%'.$SearchText.'%')
->orderBy('id', 'desc')
->get();
//dd(DB::getQueryLog()); // Show results of log
}
else
{
$Collections = Collection::select('*')
// ->where('CollectionId', 'like', $SearchText)
->where('IsDeleted', '=', 0)
->whereIn('Created_by', $TeamList)
->orderBy('id', 'desc')
->get();
}
if ($Collections->count() > 0)
{
foreach ($Collections as $key => $ColletionValue)
{
$CustomerId = $ColletionValue->CustomerId;
$CreatedFormatedDate = $ColletionValue->Created_at;
$CreatedFormatedDate = date("j M Y",strtotime($CreatedFormatedDate));
$ColletionValue->CreatedFormatedDate = $CreatedFormatedDate;
$CustomerName = '';
$custmer = Customer::where('CustomerId', $CustomerId)->get();
if ($custmer->count() > 0)
{ //email is not exist
$custmer = $custmer->first();
$CustomerName = $custmer->CustomerName;
}
$ColletionValue['CustomerName'] = $CustomerName;
}
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'UserId' => $UserId,
'AuthToken' => $AuthToken,
'Collections' => $Collections,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
'TeamList'=>$TeamList
];
return response()->json($response);
}
else
{
// fail
$response = [
'Success' => false,
'ResponseMessage' => "Collections does not exist",
'ResponseCode' => "201",
'ApiVersion' => env('APP_VERSION'),
'TeamList'=>$TeamList
];
return response()->json($response);
}
}
}