mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-28 00:44:04 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fe98b24a4 | |||
| 39892a0938 | |||
| 0ffe81d1cf | |||
| 5fd6e6a528 | |||
| 09ede52ecf | |||
| e5d6f3f581 | |||
| aa65b333c8 | |||
| 656c50e047 | |||
| 275157b243 | |||
| 0c9ffd2bf7 | |||
| d4dcae155d | |||
| bad8cadb3a | |||
| 3af32cc6e7 | |||
| 34bab6a45c |
@@ -36,6 +36,8 @@ use App\Models\User;
|
|||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class CreateCustomerLogic extends AbstractControllerLogic
|
class CreateCustomerLogic extends AbstractControllerLogic
|
||||||
{
|
{
|
||||||
@@ -167,6 +169,19 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
|||||||
CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject);
|
CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(app()->environment(['production'])){
|
||||||
|
// call wac webhook
|
||||||
|
$url = config('wagWebhookUrl.account_registration_url');
|
||||||
|
$payload = [
|
||||||
|
'name' => $request->input('name'),
|
||||||
|
'email' => $request->input('email'),
|
||||||
|
'phone' => $request->input('phone'),
|
||||||
|
'portal' => 'izyim'
|
||||||
|
];
|
||||||
|
$response = Http::post($url, $payload);
|
||||||
|
Log::channel('wac_webhook')->info('Register Account: ' . json_encode($response));
|
||||||
|
}
|
||||||
|
|
||||||
// $this->generateEmailVerificationAttemptProcessor->execute($user);
|
// $this->generateEmailVerificationAttemptProcessor->execute($user);
|
||||||
|
|
||||||
return $this->response($this->authenticationProcessor->execute($request));
|
return $this->response($this->authenticationProcessor->execute($request));
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use Illuminate\Http\JsonResponse;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class CreateInvoiceTransactionProcessor
|
class CreateInvoiceTransactionProcessor
|
||||||
{
|
{
|
||||||
@@ -74,6 +75,18 @@ class CreateInvoiceTransactionProcessor
|
|||||||
*/
|
*/
|
||||||
public function execute(PackingList $packingList)
|
public function execute(PackingList $packingList)
|
||||||
{
|
{
|
||||||
|
$ori_packing_list = $packingList;
|
||||||
|
// call wac webhook
|
||||||
|
$hasInvoiceCreated = Transaction::withTrashed()
|
||||||
|
->where('type', TransactionType::SHIPPING_INVOICE)
|
||||||
|
->where('owner_type', PackingList::class)
|
||||||
|
->where('owner_id', $ori_packing_list->id)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($hasInvoiceCreated) {
|
||||||
|
Log::channel('wac_webhook')->info('Regenerating Invoice for PackingList: ' . $ori_packing_list->id . '. No call wac api.');
|
||||||
|
}
|
||||||
|
|
||||||
$packing_list = PackingList::where('reference', $packingList->reference)->where('type', PackingListType::SHIPPING_PACKING_LIST)->first();
|
$packing_list = PackingList::where('reference', $packingList->reference)->where('type', PackingListType::SHIPPING_PACKING_LIST)->first();
|
||||||
|
|
||||||
$billable_packing_list = $packing_list->packingLists()->first();
|
$billable_packing_list = $packing_list->packingLists()->first();
|
||||||
@@ -238,6 +251,32 @@ class CreateInvoiceTransactionProcessor
|
|||||||
|
|
||||||
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
|
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (app()->environment('production') && !$hasInvoiceCreated) {
|
||||||
|
$order = $ori_packing_list->owner;
|
||||||
|
$companyModule = $order->companyModule;
|
||||||
|
$company = $companyModule->company;
|
||||||
|
$companyContact = $company->contacts()->first();
|
||||||
|
$employee = $companyModule->employees()->first();
|
||||||
|
|
||||||
|
$invoiceCount = Transaction::where('type', TransactionType::SHIPPING_INVOICE)
|
||||||
|
->where('receiver', $companyModule->id)
|
||||||
|
->where('status', ApprovalStatus::APPROVED)
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
'name' => $employee->name,
|
||||||
|
'email' => $employee->email,
|
||||||
|
'phone' => $companyContact->phone,
|
||||||
|
'order_reference' => $order->reference,
|
||||||
|
'portal' => 'izyim',
|
||||||
|
'invoice_count' => $invoiceCount,
|
||||||
|
];
|
||||||
|
|
||||||
|
Log::channel('wac_webhook')->info('Attempt to send wac_webhook - Invoice Created: ' . json_encode($payload));
|
||||||
|
$response = Http::post(config('wagWebhookUrl.invoice_created_url'), $payload);
|
||||||
|
Log::channel('wac_webhook')->info('Invoice Created: ' . json_encode($response));
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Wac\ControllersLogic;
|
||||||
|
|
||||||
|
use App\Classes\Exceptions\RequestValidationException;
|
||||||
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||||
|
use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject;
|
||||||
|
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
|
||||||
|
use App\Classes\Modules\HelpMenu\Standards\Rules\CanFetchHelpMenuQuestion;
|
||||||
|
use App\Classes\Modules\HelpMenu\Processors\FetchFirstQuestionQAProcessor;
|
||||||
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||||
|
use App\Http\Resources\HelpMenuQuestionResource;
|
||||||
|
use App\Models\User;
|
||||||
|
use ErrorException;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use App\Classes\Modules\Companies\Processors\AssignEmployeeProcessor;
|
||||||
|
use App\Classes\Modules\Accounts\Services\CreatesUser;
|
||||||
|
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||||
|
|
||||||
|
class RegisterExchangeEmailLogic extends AbstractControllerLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function notification(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => 'Register Exchange Email',
|
||||||
|
'message' => 'You have successfully registered an exchange email address'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var AssignEmployeeProcessor */
|
||||||
|
private $assignEmployeeProcessor;
|
||||||
|
|
||||||
|
/** @var CreatesUser */
|
||||||
|
private $createsUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RegisterEmailLogic constructor.
|
||||||
|
* @param AssignEmployeeProcessor $assignEmployeeProcessor
|
||||||
|
*/
|
||||||
|
public function __construct(AssignEmployeeProcessor $assignEmployeeProcessor, CreatesUser $createsUser)
|
||||||
|
{
|
||||||
|
$this->assignEmployeeProcessor = $assignEmployeeProcessor;
|
||||||
|
$this->createsUser = $createsUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @return JsonResponse
|
||||||
|
* @throws ErrorException
|
||||||
|
*/
|
||||||
|
public function logic(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
// Validate the request inputs
|
||||||
|
$validator = Validator::make(
|
||||||
|
$request->all(),
|
||||||
|
[
|
||||||
|
'izyim_email' => 'email|required',
|
||||||
|
'exchange_email' => 'email|required',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
throw new RequestValidationException($validator->messages()->first());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the validated emails from the request
|
||||||
|
$izyimEmail = $request->input('izyim_email');
|
||||||
|
$exchangeEmail = $request->input('exchange_email');
|
||||||
|
|
||||||
|
// Check if both emails are the same
|
||||||
|
if ($izyimEmail === $exchangeEmail) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Both emails are the same.',
|
||||||
|
'status' => 'ok',
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the exchange email already exists in the system
|
||||||
|
$existingUser = User::where('email', $exchangeEmail)->first();
|
||||||
|
if ($existingUser) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'The Exchange email already exists in the system.',
|
||||||
|
'status' => 'error',
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the izyim user
|
||||||
|
$izyimUser = User::where('email', $izyimEmail)->first();
|
||||||
|
if (!$izyimUser) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'The Izyim email not found in system.',
|
||||||
|
'status' => 'error',
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newUser = new User();
|
||||||
|
$newUser->name = $izyimUser->name;
|
||||||
|
$newUser->email = $exchangeEmail;
|
||||||
|
$newUser->password = $izyimUser->password;
|
||||||
|
$newUser->type = RoleTypes::USER;
|
||||||
|
$newUser->status = ApprovalStatus::APPROVED;
|
||||||
|
$newUser->save();
|
||||||
|
|
||||||
|
Log::channel('wac_webhook')->info('Wac created user: ' . $exchangeEmail);
|
||||||
|
|
||||||
|
$companyModule = $izyimUser->companyModule->first();
|
||||||
|
$Object = new EmploymentObject($companyModule, $newUser);
|
||||||
|
|
||||||
|
$this->assignEmployeeProcessor->execute($Object);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Exchange email registered successfully.',
|
||||||
|
'status' => 'success',
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Classes\Modules\PackingLists\Processors\FetchPackingListsFromYdPortalProcessor;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class FixMissingPackingList extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'fix-missing-packinglist';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Fix Missing Packinglist';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$start_date = '2024-05-05';
|
||||||
|
$end_date = '2024-05-05';
|
||||||
|
|
||||||
|
$start = $start_date ? Carbon::parse($start_date) : null;
|
||||||
|
$end = $end_date ? Carbon::parse($end_date) : null;
|
||||||
|
|
||||||
|
if (!$start || !$end) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(App()->make(FetchPackingListsFromYdPortalProcessor::class))->execute($start, $end);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -76,7 +76,7 @@ class SendPermitsReminderEmails extends Command
|
|||||||
protected function getEmailList(): array
|
protected function getEmailList(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'edmond.wuiming2021@gmail.com',
|
// 'edmond.wuiming2021@gmail.com',
|
||||||
'anithagurl96@gmail.com'
|
'anithagurl96@gmail.com'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,25 +40,41 @@ class ImportPermitsReminderController
|
|||||||
$row['reminder_date'] = $this->changeExcelDate($row['reminder_date']);
|
$row['reminder_date'] = $this->changeExcelDate($row['reminder_date']);
|
||||||
|
|
||||||
$validator = Validator::make($row, [
|
$validator = Validator::make($row, [
|
||||||
'model' => 'required|unique:permits_reminders,model',
|
'model' => 'required',
|
||||||
'expiry_date' => 'required|date|after_or_equal:today',
|
// 'expiry_date' => 'required|date|after_or_equal:today',
|
||||||
'reminder_date' => 'required|date|after_or_equal:today',
|
'expiry_date' => 'required|date',
|
||||||
|
// 'reminder_date' => 'required|date|after_or_equal:today',
|
||||||
|
'reminder_date' => 'required|date',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$row['status'] = 'failed';
|
$row['status'] = 'failed';
|
||||||
$row['message'] = $validator->errors()->all();
|
$row['message'] = $validator->errors()->all();
|
||||||
|
|
||||||
$returnArray[] = $row;
|
$returnArray[] = $row;
|
||||||
} else {
|
} else {
|
||||||
$row['created_at'] = Carbon::now();
|
$existingRecord = PermitsReminder::where('model', $row['model'])->first();
|
||||||
$row['updated_at'] = Carbon::now();
|
|
||||||
$successRows[] = $row;
|
if ($existingRecord) {
|
||||||
|
$existingRecord->update([
|
||||||
|
'expiry_date' => $row['expiry_date'],
|
||||||
|
'reminder_date' => $row['reminder_date'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$row['status'] = 'Updated';
|
||||||
|
$row['message'] = 'Record has been updated';
|
||||||
|
$returnArray[] = $row;
|
||||||
|
} else {
|
||||||
|
// Add to successful rows for batch insertion
|
||||||
|
$row['created_at'] = Carbon::now();
|
||||||
|
$row['updated_at'] = Carbon::now();
|
||||||
|
$successRows[] = $row;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert only if there are new successful rows
|
||||||
if (!empty($successRows)) {
|
if (!empty($successRows)) {
|
||||||
PermitsReminder::insert($successRows); // Insert only if there are successful rows
|
PermitsReminder::insert($successRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
$successCount = count($successRows);
|
$successCount = count($successRows);
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Wac;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Wac\ControllersLogic\RegisterExchangeEmailLogic;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class RegisterExchangeEmailController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param FetchQuestionQALogic $logic
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function register(Request $request, RegisterExchangeEmailLogic $logic): JsonResponse {
|
||||||
|
return $logic->execute($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -130,6 +130,11 @@ return [
|
|||||||
'path' => storage_path('logs/laravel_perfex_crm.log'),
|
'path' => storage_path('logs/laravel_perfex_crm.log'),
|
||||||
'level' => 'info',
|
'level' => 'info',
|
||||||
],
|
],
|
||||||
|
'wac_webhook' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/wac_webhook.log'),
|
||||||
|
'level' => 'info',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'account_registration_url' => 'https://wacontact.readyspace.com/rest/trigger/9fe03daf-2ace-4095-b064-601ef6d9bfe7',
|
||||||
|
'invoice_created_url' => 'https://wacontact.readyspace.com/rest/trigger/c0d38aa7-91ac-458b-8014-cf3287a636e4',
|
||||||
|
];
|
||||||
@@ -34,8 +34,6 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
|
|||||||
|
|
||||||
Route::post('/import/update-debtor/f614e339d7058904a831aad742e24d55', 'Imports\ImportUpdateDebtorController@import')->name('debtor.import');
|
Route::post('/import/update-debtor/f614e339d7058904a831aad742e24d55', 'Imports\ImportUpdateDebtorController@import')->name('debtor.import');
|
||||||
|
|
||||||
Route::post('/import/upload-permits-reminder', 'Imports\ImportPermitsReminderController@import')->name('permits_reminder.upload');
|
|
||||||
|
|
||||||
require __DIR__ . '/company.php';
|
require __DIR__ . '/company.php';
|
||||||
|
|
||||||
require __DIR__ . '/document.php';
|
require __DIR__ . '/document.php';
|
||||||
|
|||||||
@@ -12,5 +12,9 @@ Route::group(['middleware' => 'apipub', 'prefix' => 'v1', 'as' => 'apipub.'], fu
|
|||||||
Route::group(['prefix' => 'feedback', 'as' => 'feedback.', 'namespace' => 'HelpMenu'], function () {
|
Route::group(['prefix' => 'feedback', 'as' => 'feedback.', 'namespace' => 'HelpMenu'], function () {
|
||||||
Route::post('/generate', 'GenerateFeedbackUrlController@generate')->name('feedback.url.generate');
|
Route::post('/generate', 'GenerateFeedbackUrlController@generate')->name('feedback.url.generate');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::group(['prefix' => 'wac', 'as' => 'wac.', 'namespace' => 'Wac'], function () {
|
||||||
|
Route::post('/register-email', 'RegisterExchangeEmailController@register')->name('register_email');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,3 +9,5 @@ Route::group(['prefix' => 'permits-reminder', 'as' => 'permits_reminder.', 'name
|
|||||||
Route::post('/{id}/update', 'UpdatePermitsReminderController@update')->name('update');
|
Route::post('/{id}/update', 'UpdatePermitsReminderController@update')->name('update');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::post('/import/upload-permits-reminder', 'Imports\ImportPermitsReminderController@import')->name('permits_reminder.upload');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user