File: /var/www/html/fieldsblaze-heroku/app/Http/Controllers/APINoteController.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\Notes;
use DateTime;
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 APINoteController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $userLib;
protected $dateFormat = 'dd-mm-yyyy';
public function __construct(UserLib $userLib)
{
$this->userLib = $userLib;
}
//createVisits
public function createNote(Request $request) {
//TODO What is device_token
$data = $request->json()->all();
$NoteId = $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);
}
$cvdata = array();
$cvdata['NoteNo'] = "Note-" . time() . '-' . rand();
$cvdata['NoteId'] = $NoteId;
$cvdata['UserId'] = $UserId;
$cvdata['NoteTitle'] = $data['NoteTitle'];
$cvdata['NoteDescription'] = $data['NoteDescription'];
$cvdata['Status'] = '1';
$cvdata['IsDeleted'] = '0';
$cvdata['Updated_at'] = $CreatedDate;
$cvdata['Created_at'] = $CreatedDate;
$cvdata['Created_by'] = $UserId;
$cvdata['Updated_by'] = $UserId;
unset($cvdata['id']);
$NoteInsert = Notes::insert($cvdata);
$Note = Notes::select('*')
->where('NoteId',$NoteId)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get()->first();
$response = [
'Success' => true,
'ResponseMessage' => "Note has been added",
'ResponseCode' => "200",
'Note' => $Note,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
//createVisits
public function updateNote(Request $request) {
//TODO What is device_token
$data = $request->json()->all();
$NoteId = $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);
}
$cvdata = array();
$NoteId = $data['NoteId'];
unset($data['NoteId']);
$cvdata['UserId'] = $UserId;
$cvdata['NoteTitle'] = $data['NoteTitle'];
$cvdata['NoteDescription'] = $data['NoteDescription'];
$cvdata['Status'] = $data['Status'];
$cvdata['IsDeleted'] = $data['IsDeleted'];
$cvdata['Updated_at'] = $CreatedDate;
$cvdata['Updated_by'] = $UserId;
$update = Notes::where('NoteId',$NoteId)->update($cvdata);
$Note = Notes::select('*')
->where('NoteId',$NoteId)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get()->first();
$response = [
'Success' => true,
'ResponseMessage' => "Note has been added",
'ResponseCode' => "200",
'Note' => $Note,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
//getNote List
public function getNoteList(Request $request, $NoteId='') {
$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);
}
$Notes = Notes::select('*')
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->where('Created_by', '=', $UserId)
->orderBy('id', 'desc')
->get();
foreach ($Notes as $key => $NotesValue)
{
$CustomerId = $NotesValue->CustomerId;
$NotesValue->CustomerName='';
$CreatedFormatedDate = $NotesValue->Created_at;
$CreatedFormatedDate = date("j M Y",strtotime($CreatedFormatedDate));
$NotesValue->CreatedFormatedDate = $CreatedFormatedDate;
}
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'Notes' => $Notes,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
//getVisitsDetails
public function getNoteDetails(Request $request, $NoteId='') {
$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($NoteId == '')
{
$response = [
'success' => false,
'ResponseMessage' => "Please provide NoteId",
'ResponseCode' => "305",
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
$Note = Notes::select('*')
->where('NoteId',$NoteId)
->where('Status', '=', '1')
->where('IsDeleted', '=', 0)
->get()->first();
$CreatedFormatedDate = $Note->Created_at;
$CreatedFormatedDate = date("j M Y",strtotime($CreatedFormatedDate));
$Note->CreatedFormatedDate = $CreatedFormatedDate;
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'Note' => $Note,
'ApiUrl' => env('APP_URL'),
'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;
}
//getNote List
public function getNoteListSearch(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);
}
if($SearchText)
{
$Notes = Notes::select('*')
->where('IsDeleted', '0')
->where('Created_by', '=', $UserId)
->Where('NoteTitle', 'iLIKE', '%'.$SearchText.'%')
->orderBy('id', 'desc')
->get();
}
else
{
$Notes = Notes::select('*')
->where('IsDeleted','0')
->where('Created_by', '=', $UserId)
//->orWhere('NoteTitle', 'like', '%'.$SearchText.'%')
->orderBy('id', 'desc')
->get();
}
foreach ($Notes as $key => $NotesValue)
{
$CustomerId = $NotesValue->CustomerId;
$NotesValue->CustomerName='';
$CreatedFormatedDate = $NotesValue->Created_at;
$CreatedFormatedDate = date("j M Y",strtotime($CreatedFormatedDate));
$NotesValue->CreatedFormatedDate = $CreatedFormatedDate;
}
$response = [
'Success' => true,
'ResponseMessage' => "Success",
'ResponseCode' => "200",
'Notes' => $Notes,
'ApiUrl' => env('APP_URL'),
'ApiVersion' => env('APP_VERSION'),
];
return response()->json($response);
}
}