staff, mno, clients, bug fixes
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Support\Arr;
|
||||
use App\Jobs\SendNewUssdClientEmail;
|
||||
use App\Jobs\SendUssdClientActiveEmail;
|
||||
use App\Jobs\SendNewNotesEmailAlert;
|
||||
use App\Http\Requests;
|
||||
|
||||
|
||||
class ClientsController extends Controller
|
||||
@@ -22,7 +23,7 @@ class ClientsController extends Controller
|
||||
{
|
||||
|
||||
$client_arr = new Models\Client;
|
||||
$client_arr = $client_arr->with('auth_user_info','country_info', 'created_by_info')->orderBy('name', 'ASC')->paginate(10);
|
||||
$client_arr = $client_arr->with('auth_user_info','country_info', 'created_by_info')->orderBy('name', 'ASC')->paginate(15);
|
||||
//dd($client_arr);
|
||||
$data = [
|
||||
'page_title' => 'Clients',
|
||||
@@ -93,48 +94,7 @@ class ClientsController extends Controller
|
||||
}
|
||||
return response()->json($client_arr);
|
||||
}
|
||||
public function indexOriginal()
|
||||
{
|
||||
|
||||
$client_arr = new Models\Client;
|
||||
$table_columns = \DB::select(\DB::raw("show full columns from clients"));
|
||||
$exclude_arr = [
|
||||
'updated_at', 'id', 'auth_user_id', 'pay_mode', 'type', 'created_at', 'currency'
|
||||
];
|
||||
$columns = [];
|
||||
$queries = [];
|
||||
foreach ($table_columns as $key) {
|
||||
$columns[$key->Field] = $key->Field;
|
||||
}
|
||||
foreach ($columns as $col) {
|
||||
if (request('filter') == $col) {
|
||||
$filter = request('filter');
|
||||
$keyword = request('keyword');
|
||||
$table_arr = ['staff_id', 'pay_mode'];
|
||||
// dump($col);
|
||||
// dump(in_array($col, $table_arr));
|
||||
if (in_array($col, $table_arr)) {
|
||||
$key = $this->get_filter_ids($filter, $keyword);
|
||||
if (!empty($key)) {
|
||||
$keyword = $key;
|
||||
}
|
||||
}
|
||||
$client_arr = $client_arr->where($col, 'like', '%'.$keyword.'%');
|
||||
$queries[$col] = request('keyword');
|
||||
}
|
||||
}
|
||||
|
||||
$client_arr = $client_arr->with('payment_type_info', 'service_info', 'auth_user_info', 'created_by_info')->orderBy('name', 'ASC')->paginate(10)->appends($queries);
|
||||
$columns = Arr::except($columns, $exclude_arr);
|
||||
$columns['pay_mode'] = 'Payment Mode';
|
||||
$data = [
|
||||
'page_title' => 'Clients',
|
||||
'columns' => $columns,
|
||||
'client_arr' => $client_arr,
|
||||
'current_user' => session('current_user')
|
||||
];
|
||||
return view('client.index', $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
@@ -243,8 +203,6 @@ class ClientsController extends Controller
|
||||
'notes_body' => 'required'
|
||||
]);
|
||||
$auth_user = session('current_user');
|
||||
|
||||
// dd($request->all());
|
||||
//'email' => 'unique:users,email_address'
|
||||
$notes_arr = [
|
||||
'notes_body' => $request->notes_body,
|
||||
@@ -278,14 +236,13 @@ class ClientsController extends Controller
|
||||
'client_id' => 'required',
|
||||
'services' => 'required',
|
||||
'invoice_number' => 'required',
|
||||
'invoice_amount' => 'required',
|
||||
'invoice_amount' => 'required|numeric',
|
||||
'invoice_date' => 'required',
|
||||
'invoice_status' => 'required'
|
||||
]);
|
||||
$auth_user = session('current_user');
|
||||
|
||||
// dd($request->all());
|
||||
//'email' => 'unique:users,email_address'
|
||||
//dd($request->all());
|
||||
$finance_arr = [
|
||||
'invoice_number' => $request->invoice_number,
|
||||
'invoice_amount' => $request->invoice_amount,
|
||||
@@ -323,11 +280,15 @@ class ClientsController extends Controller
|
||||
'launch_date' => 'required'
|
||||
]);
|
||||
$auth_user = session('current_user');
|
||||
|
||||
$network = Models\NetworkOps::find($request->network);
|
||||
// dump($network);
|
||||
// dd($request->all());
|
||||
|
||||
$shortcode_arr = [
|
||||
'name' => $request->name,
|
||||
'client_id' => $request->client_id,
|
||||
'network' => $request->network,
|
||||
'network' => $network->name,
|
||||
'country' => $network->country,
|
||||
'shortcode' => $request->shortcode,
|
||||
'code_type' => $request->code_type,
|
||||
'toll_free' => $request->toll_free,
|
||||
@@ -356,7 +317,7 @@ class ClientsController extends Controller
|
||||
'client_id' => 'required',
|
||||
'services' => 'required',
|
||||
'invoice_number' => 'required',
|
||||
'invoice_amount' => 'required',
|
||||
'invoice_amount' => 'required|numeric',
|
||||
'invoice_date' => 'required',
|
||||
'invoice_status' => 'required'
|
||||
]);
|
||||
@@ -395,7 +356,6 @@ class ClientsController extends Controller
|
||||
}
|
||||
return response()->json($data, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
@@ -417,8 +377,98 @@ class ClientsController extends Controller
|
||||
$ussd_codes = Models\ClientShortCode::where('client_id', $id)->where('code_type', 'ussd')->get();
|
||||
$recent_payments = Models\ClientPayment::where('client_id', $id)->orderBy('id', 'DESC')->get();
|
||||
$countries = Models\Country::pluck('en_short_name','en_short_name');
|
||||
$networks = Models\NetworkOps::pluck('name', 'name');
|
||||
$networks = Models\NetworkOps::pluck('name', 'id');
|
||||
|
||||
$showdocuments = Models\ClientFile::where('client_id', $id)->get();
|
||||
if ($showclient->status == 'Live') {
|
||||
$status_bg = "info";
|
||||
}
|
||||
elseif ($showclient->status == 'Prospective') {
|
||||
$status_bg = "warning";
|
||||
}
|
||||
else{
|
||||
$status_bg = "danger";
|
||||
}
|
||||
|
||||
$renewal_due = 'N/A';
|
||||
$highlight_colour = 'none';
|
||||
//review this later
|
||||
if ($showclient->contract_validity == null || $showclient->contract_validity == '') {
|
||||
$renewal_due = "N/A";
|
||||
}
|
||||
else{
|
||||
$current_date = date_create(date('Y-m-d'));
|
||||
|
||||
$expiry_date = date_create($showclient->contract_validity);
|
||||
|
||||
$diff = date_diff($current_date, $expiry_date);
|
||||
|
||||
$polar = $diff->format("%R");
|
||||
|
||||
$months = $diff->format("%m");
|
||||
|
||||
$days = $diff->format("%a");
|
||||
if ($days < 31) {
|
||||
if ($polar == '-') {
|
||||
$highlight_colour = 'warning';
|
||||
$renewal_due = "Contract expired $days days(s) ago";
|
||||
}
|
||||
else{
|
||||
$renewal_due = "In $days day(s)" ;
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
if ($polar == '-') {
|
||||
$highlight_colour = 'warning';
|
||||
$renewal_due = "Contract expired $months month(s) ago";
|
||||
|
||||
}
|
||||
else{
|
||||
$renewal_due = "In $months months";
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'page_title' => 'Client Profile',
|
||||
'showclient' => $showclient,
|
||||
'show_services' => $show_services,
|
||||
'service_type' => $service_type,
|
||||
'service_type_names' => $service_type_names,
|
||||
'show_notes' => $show_notes,
|
||||
'status_bg' => $status_bg,
|
||||
'voice_codes' => $voice_codes,
|
||||
'sms_codes' => $sms_codes,
|
||||
'ussd_codes' => $ussd_codes,
|
||||
'countries' => $countries,
|
||||
'networks' => $networks,
|
||||
'renewal_due' => $renewal_due,
|
||||
'recent_payments' => $recent_payments,
|
||||
'highlight_colour' => $highlight_colour,
|
||||
'showdocuments' => $showdocuments
|
||||
];
|
||||
|
||||
return view('client.show', $data);
|
||||
}
|
||||
public function showReadonly($id)
|
||||
{
|
||||
//with('short_code_info')->
|
||||
$showclient = Models\Client::with('service_info', 'country_info', 'auth_user_info', 'short_code_info')->find($id);
|
||||
$service_type = Models\Service::pluck('name', 'id');
|
||||
$service_type_names = Models\Service::pluck('name', 'name');
|
||||
$show_services = Models\ClientCategory::where('client_id', $id)->get();
|
||||
|
||||
//->where('highlight', 'NO')
|
||||
$show_notes = Models\ClientNote::with('created_by_info', 'client_info')->where('client_id', $id)->orderBy('id', 'DESC')->get()->take(20);
|
||||
$voice_codes = Models\ClientShortCode::where('client_id', $id)->where('code_type', 'voice')->get();
|
||||
$sms_codes = Models\ClientShortCode::where('client_id', $id)->where('code_type', 'sms')->get();
|
||||
$ussd_codes = Models\ClientShortCode::where('client_id', $id)->where('code_type', 'ussd')->get();
|
||||
$recent_payments = Models\ClientPayment::where('client_id', $id)->orderBy('id', 'DESC')->get();
|
||||
$countries = Models\Country::pluck('en_short_name','en_short_name');
|
||||
$networks = Models\NetworkOps::pluck('name', 'name');
|
||||
$all_shortcodes = Models\ClientShortCode::with('client_info', 'client_info', 'update_info')->where('client_id', $id)->orderBy('code_type', 'ASC')->get();
|
||||
$showdocuments = Models\ClientFile::where('client_id', $id)->get();
|
||||
|
||||
if ($showclient->status == 'Live') {
|
||||
$status_bg = "info";
|
||||
}
|
||||
@@ -485,9 +535,11 @@ class ClientsController extends Controller
|
||||
'networks' => $networks,
|
||||
'renewal_due' => $renewal_due,
|
||||
'recent_payments' => $recent_payments,
|
||||
'highlight_colour' => $highlight_colour
|
||||
'highlight_colour' => $highlight_colour,
|
||||
'all_shortcodes' => $all_shortcodes,
|
||||
'showdocuments' => $showdocuments
|
||||
];
|
||||
return view('client.show', $data);
|
||||
return view('client.show-readonly', $data);
|
||||
}
|
||||
public function showservices($id)
|
||||
{
|
||||
@@ -560,7 +612,7 @@ class ClientsController extends Controller
|
||||
$status = ['Live' => 'Live', 'inactive' => 'Inactive', 'Prospective' => 'Prospective'];
|
||||
$currency = Models\Currency::pluck('name', 'name'); //
|
||||
|
||||
$company_types = ['Aggregator/Supplier' => 'Aggregator/Supplier', 'Enterprise' => 'Enterprise', 'Hybrid' => 'Hybrid'];
|
||||
$company_types = ['Aggregator/Supplier' => 'Aggregator/Supplier', 'Enterprise' => 'Enterprise'];
|
||||
$auth_users = Models\Account::pluck('name', 'id');
|
||||
$industries = Models\Industry::orderBy('name', 'ASC')->pluck('name', 'name');
|
||||
$message_types_arr = ['International' => 'International', 'Local' => 'Local'];
|
||||
@@ -642,7 +694,7 @@ class ClientsController extends Controller
|
||||
$status_bg = "danger";
|
||||
}
|
||||
|
||||
$contract_types = ['bilateral' => 'bilateral', 'unilateral' => 'unilateral'];
|
||||
$contract_types = ['Bilateral' => 'Bilateral', 'Unilateral' => 'Unilateral'];
|
||||
$connections = ['SMPP' => 'SMPP', 'HTTP' => 'HTTP'];
|
||||
|
||||
|
||||
@@ -689,9 +741,10 @@ class ClientsController extends Controller
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Requests\UpdateClientRequest $request, $id)
|
||||
{
|
||||
//Todo : work on the services and the sender IDs
|
||||
/*
|
||||
$request->validate([
|
||||
'name' => 'required',
|
||||
'email' => 'required|email',
|
||||
@@ -700,9 +753,53 @@ class ClientsController extends Controller
|
||||
'currency' => 'required',
|
||||
'auth_user_id' => 'required'
|
||||
]);
|
||||
*/
|
||||
$client_update = Models\Client::find($id);
|
||||
|
||||
// dd($request->support_emails);
|
||||
if ($request->has('document_one') && $request->has('document_one_name')) {
|
||||
if ($request->file('document_one')->isValid()) {
|
||||
$filename = "erp_" . time() . str_random(6) . "." . $request->document_one->extension();
|
||||
$request->document_one->storeAs('client_files', $filename, 'public');
|
||||
$document_arr['file_path'] = $filename;
|
||||
$client_update->name = $request->name;
|
||||
|
||||
$document_arr['file_extension'] = $request->document_one->extension();
|
||||
$document_arr['file_reff'] = time() . uniqid();
|
||||
$document_arr['name'] = $request->document_one_name;
|
||||
$document_arr['created_by'] = session('current_user.id');
|
||||
$document_arr['client_id'] = $id;
|
||||
$result = Models\ClientFile::create($document_arr);
|
||||
}
|
||||
}
|
||||
if ($request->has('document_two') && $request->has('document_two_name')) {
|
||||
if ($request->file('document_two')->isValid()) {
|
||||
$filename = "erp_" . time() . str_random(6) . "." . $request->document_two->extension();
|
||||
$request->document_two->storeAs('client_files', $filename, 'public');
|
||||
$document_arr['file_path'] = $filename;
|
||||
$client_update->name = $request->name;
|
||||
|
||||
$document_arr['file_extension'] = $request->document_two->extension();
|
||||
$document_arr['file_reff'] = time() . uniqid();
|
||||
$document_arr['name'] = $request->document_two_name;
|
||||
$document_arr['created_by'] = session('current_user.id');
|
||||
$document_arr['client_id'] = $id;
|
||||
$result = Models\ClientFile::create($document_arr);
|
||||
}
|
||||
}
|
||||
if ($request->has('document_three') && $request->has('document_three_name')) {
|
||||
if ($request->file('document_three')->isValid()) {
|
||||
$filename = "erp_" . time() . str_random(6) . "." . $request->document_three->extension();
|
||||
$request->document_three->storeAs('client_files', $filename, 'public');
|
||||
$document_arr['file_path'] = $filename;
|
||||
$client_update->name = $request->name;
|
||||
|
||||
$document_arr['file_extension'] = $request->document_three->extension();
|
||||
$document_arr['file_reff'] = time() . uniqid();
|
||||
$document_arr['name'] = $request->document_three_name;
|
||||
$document_arr['created_by'] = session('current_user.id');
|
||||
$document_arr['client_id'] = $id;
|
||||
$result = Models\ClientFile::create($document_arr);
|
||||
}
|
||||
}
|
||||
|
||||
$client_update->name = $request->name;
|
||||
$client_update->email = $request->email;
|
||||
@@ -772,9 +869,6 @@ class ClientsController extends Controller
|
||||
}
|
||||
$retval = $this->update_services($request->services, $client_update->id);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Session::flash('success_message', 'Client successfully Updated');
|
||||
return redirect(url('clients', $id));
|
||||
}
|
||||
@@ -819,79 +913,54 @@ class ClientsController extends Controller
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function get_filter_ids($filter, $keyword)
|
||||
public function storeFiles(AddFilesRequest $request)
|
||||
{
|
||||
switch ($filter) {
|
||||
case 'status':
|
||||
$id = Models\Client::where('status', 'like', "%$keyword%")->get(['id']);
|
||||
if ($id->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
$step = json_decode($id);
|
||||
$the_id = $step[0]->id;
|
||||
return (count($step) > 0 ) ? $step[0]->id : "";
|
||||
break;
|
||||
case 'type':
|
||||
$id = Models\Client::where('type', 'like', "%$keyword%")->get(['id']);
|
||||
if ($id->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
$step = json_decode($id);
|
||||
$the_id = $step[0]->id;
|
||||
return (count($step) > 0 ) ? $step[0]->id : "";
|
||||
break;
|
||||
case 'country':
|
||||
$id = Models\Country::where('alpha_2_code', 'like', "%$keyword%")->orWhere('alpha_3_code', 'like', "%$keyword%")->orWhere('en_short_name', 'like', "%$keyword%")->get(['id']);
|
||||
if ($id->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
$step = json_decode($id);
|
||||
$the_id = $step[0]->id;
|
||||
return (count($step) > 0 ) ? $step[0]->id : "";
|
||||
break;
|
||||
case 'currency':
|
||||
$id = Models\Client::where('currency', 'like', "%$keyword%")->get(['id']);
|
||||
if ($id->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
$step = json_decode($id);
|
||||
$the_id = $step[0]->id;
|
||||
return (count($step) > 0 ) ? $step[0]->id : "";
|
||||
break;
|
||||
case 'auth_user_id':
|
||||
$id = Models\SystemUser::where('name', 'like', "%$keyword%")->get(['id']);
|
||||
if ($id->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
$step = json_decode($id);
|
||||
$the_id = $step[0]->id;
|
||||
return (count($step) > 0 ) ? $step[0]->id : "";
|
||||
break;
|
||||
case 'name':
|
||||
// $this->log_query();
|
||||
$id = Models\Client::where('name', 'like', "%$keyword%")->get(['id']);
|
||||
if ($id->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
$step = json_decode($id);
|
||||
return (count($step) > 0 ) ? $step[0]->id : "";
|
||||
break;
|
||||
case 'pay_mode':
|
||||
// $this->log_query();
|
||||
$id = Models\PaymentType::where('name', 'like', "%$keyword%")->get(['id']);
|
||||
if ($id->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
$step = json_decode($id);
|
||||
return (count($step) > 0 ) ? $step[0]->id : "";
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
break;
|
||||
$document_arr = $request->except('document');
|
||||
if ($request->hasFile('document')) {
|
||||
if ($request->file('document')->isValid()) {
|
||||
$filename = "erp_" . time() . "." . $request->document->extension();
|
||||
$request->document->storeAs('client_files', $filename, 'public');
|
||||
$document_arr['document'] = json_encode([$filename]);
|
||||
}
|
||||
}
|
||||
$document_arr['file_extension'] = $request->document->extension();
|
||||
$document_arr['file_reff'] = time() . uniqid();
|
||||
$document_arr['last_modified_by'] = session('current_user.id');
|
||||
|
||||
$result = Models\ClientFile::create($document_arr);
|
||||
|
||||
if ($result) {
|
||||
$data = ['code' => 1, 'msg' => 'Document successfully uploaded'];
|
||||
}
|
||||
else{
|
||||
$data = ['code' => 3, 'msg' => 'Your request could not be handled at this time'];
|
||||
}
|
||||
return response()->json($data, 200);
|
||||
|
||||
}
|
||||
public function getClientFile($id)
|
||||
{
|
||||
$client_file = Models\ClientFile::with('client_info')->findOrFail($id);
|
||||
//PDF file is stored under project/public/download/info.pdf
|
||||
$file = public_path('documents/client_files/') . $client_file->file_path;
|
||||
|
||||
$headers = []; //['Content-Type: application/pdf'];
|
||||
$filename = $client_file->client_info->name . "_" . $client_file->name;
|
||||
$filename = $this->cleanStr($filename);
|
||||
$filename = $filename . "." . $client_file->file_extension;
|
||||
|
||||
// $filename = str_replace(' ', '_', $filename);
|
||||
return \Response::download($file, $filename, $headers);
|
||||
}
|
||||
public function cleanStr($string){
|
||||
// Replaces all spaces with hyphens.
|
||||
$string = str_replace(' ', '-', $string);
|
||||
|
||||
// Removes special chars.
|
||||
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string);
|
||||
// Replaces multiple hyphens with single one.
|
||||
$string = preg_replace('/-+/', '_', $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user