Files
click-erp/app/Http/Controllers/ClientsController.php
2023-04-17 20:25:52 +00:00

898 lines
34 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models;
use Session;
use Illuminate\Support\Arr;
use App\Jobs\SendNewUssdClientEmail;
use App\Jobs\SendUssdClientActiveEmail;
use App\Jobs\SendNewNotesEmailAlert;
class ClientsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$client_arr = new Models\Client;
$client_arr = $client_arr->with('auth_user_info','country_info', 'created_by_info')->orderBy('name', 'ASC')->paginate(10);
//dd($client_arr);
$data = [
'page_title' => 'Clients',
'client_arr' => $client_arr,
'current_user' => session('current_user')
];
// dd($data);
return view('client.index-tabulator', $data);
}
public function indexBak(){
$client_arr = new Models\Client;
$client_arr = $client_arr->with('auth_user_info','country_info', 'created_by_info')->orderBy('name', 'ASC')->paginate(10);
$data = [
'page_title' => 'Clients',
'current_user' => session('current_user')
];
return view('client.index-rawjs', $data);
}
public function getClientJson(Request $request)
{
/*
$client_arr = new Models\Client;
$client_arr = $client_arr->with('auth_user_info','country_info', 'created_by_info', 'modified_by_info')->orderBy('name', 'ASC')->paginate(20);
dump($request->all());
$client_arr = $client_arr->with('auth_user_info','country_info', 'created_by_info', 'modified_by_info')
->orderBy('name', 'ASC')->paginate(20);
}
*/
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->select('clients.id', 'clients.name', 'clients.status', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy')
->orderBy('name', 'ASC')
->paginate(15);
if($request->has('keyword')){ // != ''
$keyword = $request->keyword;
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->select('clients.id','clients.name', 'clients.status', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy')
->whereRaw("clients.name like '%$keyword%' or clients.status like '%$keyword%' OR clients.country like '%$keyword%' OR aumngr.name like '%$keyword%' OR aumodify.name like '%$keyword%'")
->orderBy('name', 'ASC')
->paginate(15);
}
return response()->json($client_arr);
}
public function getClientJsonRawJs(Request $request){
#$client_arr = new Models\Client;
#$client_arr = $client_arr->with('auth_user_info','country_info', 'created_by_info', 'modified_by_info')->orderBy('name', 'ASC')->paginate(20);
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->select('clients.id', 'clients.name', 'clients.status', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy')
->paginate(10);
if($request->has('keyword')){ // != ''
$keyword = $request->keyword;
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->select('clients.id','clients.name', 'clients.status', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy')
->whereRaw("clients.name like '%$keyword%' or clients.status like '%$keyword%' OR clients.country like '%$keyword%' OR aumngr.name like '%$keyword%' OR aumodify.name like '%$keyword%'")
->paginate(10);
}
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.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$countries = Models\Country::pluck('en_short_name','en_short_name');
$service_type = Models\Service::pluck('name', 'name');
$payment_type = Models\PaymentType::pluck('name', 'id');
$auth_users = Models\Account::pluck('name', 'id');
$status = ['Live' => 'Live', 'inactive' => 'Inactive', 'Prospective' => 'Prospective'];
$currency = Models\Currency::pluck('name','name');
$company_types = ['Aggregator/Supplier' => 'Aggregator/Supplier', 'Enterprise' => 'Enterprise', 'Hybrid' => 'Hybrid'];
$industries = Models\Industry::orderBy('name', 'ASC')->pluck('name', 'name');
// $industries = Models\Industry::pluck('name', 'name')->orderBy('name', 'ASC');
$data = [
'page_title' => 'Create Client',
'countries' => $countries,
'service_type' => $service_type,
'status' => $status,
'currency' => $currency,
'auth_users' => $auth_users,
'payment_type' => $payment_type,
'company_types' => $company_types,
'industries' => $industries
];
return view('client.create', $data);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required|unique:clients,name',
'email' => 'required|email',
'services' => 'required',
'country' => 'required',
'status' => 'required',
'payment_mode' => 'required',
'currency' => 'required',
'company_type' => 'required',
'industry' => 'required',
'auth_user_id' => 'required', // account manager
]);
$client_arr = [
'name' => $request->name,
'email' => $request->email,
'country' => $request->country,
'status' => $request->status,
'pay_mode' => $request->payment_mode,
'currency' => $request->currency,
'auth_user_id' => $request->auth_user_id, // account manager
'created_by' => session('current_user.id'),
'last_modified_by' => session('current_user.id')
];
if ($request->has('notes')) {
$client_arr['notes'] = $request->notes;
}
if ($request->has('services')) {
$client_arr['services'] = json_encode($request->services);
}
if ($request->has('phone')) {
$client_arr['phone'] = $request->phone;
}
if ($request->has('skype_name')) {
$client_arr['skype_name'] = $request->skype_name;
}
if ($request->has('linkedin_name')) {
$client_arr['linkedin_name'] = $request->linkedin_name;
}
if ($request->has('contact_person')) {
$client_arr['contact_person'] = $request->contact_person;
}
$result = Models\Client::create($client_arr);
if (in_array('3', $request->services)) {
\Log::info('ussd client detected');
$ussd_client_payment_arr = [
'client_id' => $result->id,
'last_modified_by_id' => session('current_user.id')
];
$retval = Models\UssdClientPayment::create($ussd_client_payment_arr);
//TODO send an email to jim/priscilla about new USSD client,
#dispatch(new SendNewUssdClientEmail($result));
}
#save services this has been moved to the main client table
//$retval = $this->store_services($request->services, $result->id);
Session::flash('success_message', 'Client successfully added');
return redirect(url('clients'));
}
public function notesStore(Request $request)
{
$request->validate([
'client_id' => 'required',
'notes_body' => 'required'
]);
$auth_user = session('current_user');
// dd($request->all());
//'email' => 'unique:users,email_address'
$notes_arr = [
'notes_body' => $request->notes_body,
'services' => implode(',', $request->services),
'auth_user_id' => $auth_user['id'],
'client_id' => $request->client_id
];
if ($request->has('highlight')) {
$notes_arr['highlight'] = 'YES';
}
//dd($notes_arr);
$result = Models\ClientNote::create($notes_arr);
$notes = Models\ClientNote::with('client_info', 'created_by_info')->find($result->id);
//todo : send emails
dispatch(new SendNewNotesEmailAlert($notes));
if ($result) {
$data = ['code' => 1, 'msg' => 'Notes successfully added'];
}
else{
$data = ['code' => 3, 'msg' => 'Your request could not be handled at this time'];
}
return response()->json($data, 200);
}
public function financeStore(Request $request)
{
$request->validate([
'client_id' => 'required',
'services' => 'required',
'invoice_number' => 'required',
'invoice_amount' => 'required',
'invoice_date' => 'required',
'invoice_status' => 'required'
]);
$auth_user = session('current_user');
// dd($request->all());
//'email' => 'unique:users,email_address'
$finance_arr = [
'invoice_number' => $request->invoice_number,
'invoice_amount' => $request->invoice_amount,
'invoice_date' => $request->invoice_date,
'invoice_status' => $request->invoice_status,
'services' => implode(',', $request->services),
'user_id' => $auth_user['id'],
'client_id' => $request->client_id
];
if ($request->has('remarks')) {
$finance_arr['remarks'] = $request->remarks;
}
$result = Models\ClientPayment::create($finance_arr);
#$payments = Models\ClientPayment::with('client_info', 'created_by_info')->find($result->id);
if ($result) {
$data = ['code' => 1, 'msg' => 'Payment Details successfully added'];
}
else{
$data = ['code' => 3, 'msg' => 'Your request could not be handled at this time'];
}
return response()->json($data, 200);
}
public function shortcodeStore(Request $request)
{
$request->validate([
'client_id' => 'required',
'network' => 'required',
'shortcode' => 'required',
'code_type' => 'required',
'toll_free' => 'required',
'status' => 'required',
'remarks' => 'required',
'launch_date' => 'required'
]);
$auth_user = session('current_user');
$shortcode_arr = [
'name' => $request->name,
'client_id' => $request->client_id,
'network' => $request->network,
'shortcode' => $request->shortcode,
'code_type' => $request->code_type,
'toll_free' => $request->toll_free,
'last_updaed_by' => $auth_user['id'],
'launch_date' => $request->launch_date,
'status' => $request->status
];
if ($request->has('remarks')) {
$shortcode_arr['remarks'] = $request->remarks;
}
$result = Models\ClientShortCode::create($shortcode_arr);
if ($result) {
$data = ['code' => 1, 'msg' => 'ShortCode Details successfully added'];
}
else{
$data = ['code' => 3, 'msg' => 'Your request could not be handled at this time'];
}
return response()->json($data, 200);
}
public function financeUpdate(Request $request)
{
$request->validate([
'payment_id' => 'required',
'client_id' => 'required',
'services' => 'required',
'invoice_number' => 'required',
'invoice_amount' => 'required',
'invoice_date' => 'required',
'invoice_status' => 'required'
]);
$auth_user = session('current_user');
$payment = Models\ClientPayment::findOrFail($request->payment_id);
$payment->invoice_number = $request->invoice_number;
$payment->invoice_amount = $request->invoice_amount;
$payment->invoice_date = $request->invoice_date;
$payment->invoice_status = $request->invoice_status;
$payment->services = implode(',', $request->services);
$result = $payment->save();
//'email' => 'unique:users,email_address'
/*
$finance_arr = [
'invoice_number' => $request->invoice_number,
'invoice_amount' => $request->invoice_amount,
'invoice_date' => $request->invoice_date,
'invoice_status' => $request->invoice_status,
'services' => implode(',', $request->services),
'user_id' => $auth_user['id'],
'client_id' => $request->client_id
];
if ($request->has('remarks')) {
$finance_arr['remarks'] = $request->remarks;
}
*/
#$payments = Models\ClientPayment::with('client_info', 'created_by_info')->find($result->id);
if ($result) {
$data = ['code' => 1, 'msg' => 'Payment Details successfully updated'];
}
else{
$data = ['code' => 3, 'msg' => 'Your request could not be handled at this time'];
}
return response()->json($data, 200);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($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');
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
];
return view('client.show', $data);
}
public function showservices($id)
{
$show_services = Models\ClientCategory::where('client_id', $id)->get();
dd($show_services);
$data = [
'page_title' => 'Show Services',
'show_services' => $show_services
];
return view('client.services', $data);
}
public function editservice($id)
{
$payment = Models\ClientCategory::find($id);
$data = [
'page_title' => 'Show Services',
'service' => $service
];
return view('client.service-edit', $data);
}
public function getPayment($id)
{
$payment = Models\ClientPayment::find($id);
if ($payment) {
$services_arr = explode(',', $payment->services);
return response()->json([ 'code' => 1, 'result' => $payment, 'services_arr' => $services_arr]);
}
else{
return response()->json([ 'code' => 3, 'msg' => 'Request could not be handled at this time']);
}
}
public function getShortCodes(){
//$auth_users = Models\SystemUser::pluck('name', 'id');
$voice_codes = Models\ClientShortCode::with('client_info', 'client_info', 'update_info')->where('code_type', 'voice')->get();
$sms_codes = Models\ClientShortCode::with('client_info','client_info', 'update_info')->where('code_type', 'sms')->get();
$ussd_codes = Models\ClientShortCode::with('client_info', 'client_info', 'update_info')->where('code_type', 'ussd')->get();
//dd($voice_codes);
// dump($sms_codes[0]->last_updaed_by);
// dd($auth_users[$sms_codes[0]->last_updaed_by]);
$codes = Models\ClientShortCode::with('update_info')->get();
$data = [
'page_title' => 'Client Short Codes',
'voice_codes' => $voice_codes,
'sms_codes' => $sms_codes,
'ussd_codes' => $ussd_codes,
];
return view('client.shortcodes', $data);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$client = Models\Client::find($id);
$service_type = Models\Service::pluck('name', 'name');
$countries = Models\Country::pluck('en_short_name','en_short_name');
$payment_type = ['Prepaid' => 'Prepaid', 'Postpaid' => 'Postpaid']; // Models\PaymentType::pluck('name', 'id')->toArray();
$status = ['Live' => 'Live', 'inactive' => 'Inactive', 'Prospective' => 'Prospective'];
$currency = Models\Currency::pluck('name', 'name'); //
$company_types = ['Aggregator/Supplier' => 'Aggregator/Supplier', 'Enterprise' => 'Enterprise', 'Hybrid' => 'Hybrid'];
$auth_users = Models\Account::pluck('name', 'id');
$industries = Models\Industry::orderBy('name', 'ASC')->pluck('name', 'name');
$message_types_arr = ['International' => 'International', 'Local' => 'Local'];
$how_we_got_clients_arr = ['Event : (GCCM) etc' => 'Event : (GCCM) etc', 'Referral' => 'Referral', 'Word of Mouth' => 'Word of Mouth', 'Marketing' => 'Marketing', 'Other' => 'Other'];
// 'current_services' => json_decode($client->services, true);
if ($client->support_emails) {
$support_emails = json_decode($client->support_emails, true);
$support_emails = array_combine($support_emails, $support_emails);
$old_support_emails = json_decode($client->support_emails, true);
}
else{
$support_emails = [];
$old_support_emails = [];
}
if ($client->rate_emails) {
$rate_emails = json_decode($client->rate_emails, true);
$rate_emails = array_combine($rate_emails, $rate_emails);
$old_rate_emails = json_decode($client->rate_emails, true);
}
else{
$rate_emails = [];
$old_rate_emails = [];
}
if ($client->support_phones) {
$support_phones = json_decode($client->support_phones, true);
$support_phones = array_combine($support_phones, $support_phones);
$old_support_phones = json_decode($client->support_phones, true);
}
else{
$support_phones = [];
$old_support_phones = [];
}
if ($client->support_skype) {
$support_skype_arr = json_decode($client->support_skype, true);
$support_skype_arr = array_combine($support_skype_arr, $support_skype_arr);
$old_support_skype_arr = json_decode($client->support_skype, true);
}
else{
$support_skype_arr = [];
$old_support_skype_arr = [];
}
if ($client->finance_email) {
$finance_emails = json_decode($client->finance_email, true);
$finance_emails = array_combine($finance_emails, $finance_emails);
$old_finance_emails = json_decode($client->finance_email, true);
}
else{
$finance_emails = [];
$old_finance_emails = [];
}
if ($client->sender_ids) {
$sender_ids = json_decode($client->sender_ids, true);
$sender_ids = array_combine($sender_ids, $sender_ids);
$old_sender_ids = json_decode($client->sender_ids, true);
}
else{
$sender_ids = ['click' => 'click'];
$old_sender_ids = [];
}
if ($client->status == 'Live') {
$status_bg = "info";
}
elseif ($client->status == 'Prospective') {
$status_bg = "warning";
}
else{
$status_bg = "danger";
}
$contract_types = ['bilateral' => 'bilateral', 'unilateral' => 'unilateral'];
$connections = ['SMPP' => 'SMPP', 'HTTP' => 'HTTP'];
$data = [
'client' => $client,
'countries' => $countries,
'service_type' => $service_type->toArray(),
'payment_type' => $payment_type,
'status' => $status,
'auth_users' => $auth_users,
'currency' => $currency,
'page_title' => 'Update Client Details',
'connections_arr' => $connections,
'status_bg' => $status_bg,
'sender_ids' => $sender_ids,
'finance_emails' => $finance_emails,
'support_emails' => $support_emails,
'rate_emails' => $rate_emails,
'support_skype_arr' => $support_skype_arr,
'support_phones' => $support_phones,
'old_finance_emails' => $old_finance_emails,
'old_rate_emails' => $old_rate_emails,
'old_support_emails' => $old_support_emails,
'old_support_skype_arr' => $old_support_skype_arr,
'old_support_phones' => $old_support_phones,
'company_types' => $company_types,
'old_sender_ids' => $old_sender_ids,
'contract_types' => $contract_types,
'message_types_arr' => $message_types_arr,
'industries' => $industries,
'how_we_got_clients_arr' => $how_we_got_clients_arr,
'current_services' => json_decode($client->services, true)
];
return view('client.edit', $data);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//Todo : work on the services and the sender IDs
$request->validate([
'name' => 'required',
'email' => 'required|email',
'country' => 'required',
'status' => 'required',
'currency' => 'required',
'auth_user_id' => 'required'
]);
$client_update = Models\Client::find($id);
// dd($request->support_emails);
$client_update->name = $request->name;
$client_update->email = $request->email;
$client_update->phone = $request->phone ?? "";
$client_update->contact_person = $request->contact_person;
$client_update->status = $request->status;
$client_update->pay_mode = $request->payment_mode;
$client_update->country = $request->country;
$client_update->currency = $request->currency;
$client_update->notes = $request->notes;
$client_update->industry = $request->industry;
$client_update->skype_name = $request->skype_name ?? "";
$client_update->linkedin_name = $request->linkedin_name ?? "";
$client_update->smpp_username = $request->smpp_username ?? "";
$client_update->company_type = $request->company_type ?? "";
$client_update->auth_user_id = $request->auth_user_id ?? "";
$client_update->contract_type = $request->contract_type ?? "";
$client_update->contract_validity = $request->contract_validity ?? "";
$client_update->contract_auto_renew = $request->contract_auto_renew ?? "";
//$client_update->smpp_details = $request->smpp_details ?? "";
$client_update->sender_ids = ($request->sender_ids) ? json_encode($request->sender_ids) : "";
$client_update->connections = ($request->connections) ? json_encode($request->connections) : "";
$client_update->services = ($request->services) ? json_encode($request->services) : "";
$client_update->message_types = ($request->message_types) ? json_encode($request->message_types) : "";
$client_update->finance_email = ($request->finance_email) ? json_encode($request->finance_email) : "";
$client_update->support_emails = ($request->support_emails) ? json_encode($request->support_emails) : "";
$client_update->rate_emails = ($request->rate_emails) ? json_encode($request->rate_emails) : "";
$client_update->support_phones = ($request->support_phones) ? json_encode($request->support_phones) : "";
$client_update->support_skype = ($request->support_skype) ? json_encode($request->support_skype) : "";
if ($request->has('how_we_got_client')) {
if ($request->how_we_got_client == 'Other') {
$client_update->how_we_got_client = $request->how_we_got_client_other ?? "";
}
else{
$client_update->how_we_got_client = $request->how_we_got_client ?? "";
}
}
$client_update->created_by = session('current_user.id');
$client_update->last_modified_by = session('current_user.id');
$result = $client_update->save();
$client = Models\Client::find($id);
/*
if (in_array('3', $request->services)) {
if ($request->status == 'active' && $client_update->status !== 'active') {
\log::info('ussd client active detected');
#dispatch(new SendUssdClientActiveEmail($client));
}
}
if (in_array('3', $request->services)) {
\Log::info('ussd client detected');
$ussd_client_payment_arr = [
'client_id' => $client_update->id,
'last_modified_by_id' => session('current_user.id')
];
$retval = Models\UssdClientPayment::create($ussd_client_payment_arr);
//TODO send an email to jim/priscilla about new USSD client,
#dispatch(new SendNewUssdClientEmail($client_update));
}
$retval = $this->update_services($request->services, $client_update->id);
*/
Session::flash('success_message', 'Client successfully Updated');
return redirect(url('clients', $id));
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$result = Models\Client::destroy($id);
if (request()->ajax()) {
$result_arr = ['code' => 1];
return response()->json($result_arr);
}
Session::flash('success_message', 'Client successfully deleted!');
return redirect(route('client.index'));
}
public function store_services($services_arr, $client_id){
foreach ($services_arr as $id) {
$client_arr = [
'client_id' => $client_id,
'category_id' => $id
];
$result = Models\ClientCategory::create($client_arr);
}
return true;
}
public function update_services($services_arr, $client_id){
// remove and add will think of a better approach later
$result = Models\ClientCategory::where('client_id', $client_id)->delete();
foreach ($services_arr as $id) {
$client_arr = [
'client_id' => $client_id,
'category_id' => $id
];
$result = Models\ClientCategory::create($client_arr);
}
return true;
}
public function get_filter_ids($filter, $keyword)
{
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;
}
}
}