note highlights, Notes Emails, client edit

This commit is contained in:
Kwesi Banson
2023-03-06 15:14:53 +00:00
parent ad0dd6a6e1
commit a8301660fc
9 changed files with 735 additions and 129 deletions

View File

@@ -8,6 +8,7 @@ use Session;
use Illuminate\Support\Arr;
use App\Jobs\SendNewUssdClientEmail;
use App\Jobs\SendUssdClientActiveEmail;
use App\Jobs\SendNewNotesEmailAlert;
class ClientsController extends Controller
@@ -236,10 +237,18 @@ class ClientsController extends Controller
'auth_user_id' => $auth_user['id'],
'client_id' => $request->client_id
];
if ($request->has('highlight')) {
$notes_arr['highlight'] = 'YES';
}
//todo : send emails
//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'];
}
@@ -262,16 +271,29 @@ class ClientsController extends Controller
$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);
if ($showclient->status == 'Live') {
$status_bg = "info";
}
elseif ($showclient->status == 'Prospective') {
$status_bg = "warning";
}
else{
$status_bg = "danger";
}
//dd($showclient->sender_ids);
$data = [
'page_title' => 'Show Client',
'page_title' => 'Client Profile',
'showclient' => $showclient,
'show_services' => $show_services,
'service_type' => $service_type,
'service_type_names' => $service_type_names,
'show_notes' => $show_notes
'show_notes' => $show_notes,
'status_bg' => $status_bg
];
return view('client.show', $data);
@@ -307,19 +329,40 @@ class ClientsController extends Controller
{
$client = Models\Client::find($id);
$service_type = Models\Service::pluck('name', 'id');
// $payment_type = Models\PaymentType::pluck('name', 'id');
$countries = Models\Country::pluck('en_short_name','en_short_name');
$countries = Models\Country::pluck('en_short_name','alpha_2_code');
$payment_type = [1 => 'Prepaid', 2 => 'Postpaid']; // Models\PaymentType::pluck('name', 'id')->toArray();
$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'); //
// dd($currency);
$auth_users = Models\Account::pluck('name', 'id');
// dump(array_flatten($client->client_services));
$company_types = ['A2P Supplier' => 'A2P Supplier', 'A2P Consumer' => 'A2P Consumer', 'Hybrid' => 'Hybrid'];
$auth_users = Models\Account::pluck('name', 'id');
// dd($client->sender_ids);
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,
@@ -327,7 +370,14 @@ class ClientsController extends Controller
'payment_type' => $payment_type,
'status' => $status,
'auth_users' => $auth_users,
'currency' => $currency
'currency' => $currency,
'page_title' => 'Update Client Details',
'connections_arr' => $connections,
'status_bg' => $status_bg,
'sender_ids' => $sender_ids,
'company_types' => $company_types,
'old_sender_ids' => $old_sender_ids,
'contract_types' => $contract_types
];
// dd($service_type->toArray());
return view('client.edit', $data);
@@ -342,21 +392,24 @@ class ClientsController extends Controller
*/
public function update(Request $request, $id)
{
//Todo : work on the services and the sender IDs
$request->validate([
'name' => 'required',
// 'email' => 'required|email',
// 'services' => 'required',
'email' => 'required|email',
'country' => 'required',
'status' => 'required',
// 'payment_mode' => 'required',
'currency' => 'required',
'auth_user_id' => 'required'
]);
$client_update = Models\Client::find($id);
//dump($request->status);
//dump(($request->sender_ids) ? json_encode($request->sender_ids) : "");
//dd($request->all());
$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;
@@ -365,6 +418,15 @@ class ClientsController extends Controller
$client_update->notes = $request->notes;
$client_update->skype_name = $request->skype_name;
$client_update->linkedin_name = $request->linkedin_name;
$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->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->created_by = session('current_user.id');
$client_update->last_modified_by = session('current_user.id');
@@ -395,7 +457,7 @@ class ClientsController extends Controller
Session::flash('success_message', 'Client successfully Updated');
return redirect(url('clients'));
return redirect(url('clients', $id));
}
/**

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Jobs;
use App\Models;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Mail\Mailer;
class SendNewNotesEmailAlert implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $note;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Models\ClientNote $note)
{
$this->note = $note;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(Mailer $mailer)
{
$note = $this->note;
$emails = ['samuel@click-mobile.com'];
//$note_body = $note->notes_body;
$data = [
'client' => $note->client_info->name,
'created_by' => $note->created_by_info->name,
'services' => $note->services,
'notes_body' => $note->notes_body
];
$mailer->send('emails.new-notes', $data, function ($message) use ($data, $emails) {
$message->from('support@click-mobile.com', 'Click Mobile ERP');
$message->to($emails)->subject('New Notes');
});
}
}