Compare commits

...

11 Commits

Author SHA1 Message Date
Aqqil Azman 9c4c472a40 fix wrong decimal round off 2024-08-01 09:37:22 +08:00
Aqqil Azman a67afdc0ff changed decimal points to 2 2024-08-01 09:34:14 +08:00
edmondlang b30cdaba84 fix export/aging-list, it has duplicated rows due to unnecessary joins 2024-07-26 00:58:49 +08:00
Dillon Ngo 9ac0ca45be Merge branch 'dillon/46.14-data-patch' into 'master'
Data patch for storage invoice

See merge request CIEFWorldwideSdnBhd/shipping-portal!235
2024-07-22 23:07:16 +00:00
Dillon Ngo 3fe98b24a4 Data patch for storage invoice 2024-07-23 07:06:34 +08:00
Dillon Ngo 7e7e43ee9c Merge branch 'dillon/46.14-data-patch' into 'master'
Data patch for storage invoice

See merge request CIEFWorldwideSdnBhd/shipping-portal!234
2024-07-22 23:00:09 +00:00
Dillon Ngo 39892a0938 Data patch for storage invoice 2024-07-23 06:58:10 +08:00
edmondlang 0ffe81d1cf update call wac webhook 2024-07-19 00:35:38 +08:00
edmondlang 5fd6e6a528 update call wac webhook 2024-07-19 00:28:51 +08:00
edmondlang 09ede52ecf update call wac webhook 2024-07-18 23:59:23 +08:00
edmondlang e5d6f3f581 wac webhook 2024-07-18 23:11:04 +08:00
8 changed files with 201 additions and 6 deletions
@@ -169,16 +169,17 @@ class CreateCustomerLogic extends AbstractControllerLogic
CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject);
}
if(!app()->environment(['production'])){
if(app()->environment(['production'])){
// call wac webhook
$url = 'https://wacontact.readyspace.com/rest/trigger/9fe03daf-2ace-4095-b064-601ef6d9bfe7';
$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(json_encode($response));
Log::channel('wac_webhook')->info('Register Account: ' . json_encode($response));
}
// $this->generateEmailVerificationAttemptProcessor->execute($user);
@@ -24,8 +24,8 @@ class ExportsAgingList implements WithHeadings, WithHeadingRow, WithMapping, Sho
{
$this->filters = [
"has_invoice_status_in" => [2],
"packing_list_ordered_by_invoice_date" => true,
"with_aging_column" => true
// "packing_list_ordered_by_invoice_date" => true,
// "with_aging_column" => true
];
}
@@ -156,7 +156,7 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
$detail->quantity,
$detail->price,
floatval($detail->tax_percentage) > 0 ? 'SV-6' : '',
floatval($detail->tax_percentage) > 0 ? $detail->amount : '0',
floatval($detail->tax_percentage) > 0 ? number_format($detail->amount, 2) : '0.00',
$detail->tax_percentage,
];
@@ -34,6 +34,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
use Illuminate\Support\Facades\Http;
class CreateInvoiceTransactionProcessor
{
@@ -74,6 +75,18 @@ class CreateInvoiceTransactionProcessor
*/
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();
$billable_packing_list = $packing_list->packingLists()->first();
@@ -238,6 +251,32 @@ class CreateInvoiceTransactionProcessor
$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;
}
@@ -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,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);
}
}
+6
View File
@@ -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',
];
+4
View File
@@ -12,5 +12,9 @@ Route::group(['middleware' => 'apipub', 'prefix' => 'v1', 'as' => 'apipub.'], fu
Route::group(['prefix' => 'feedback', 'as' => 'feedback.', 'namespace' => 'HelpMenu'], function () {
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');
});
});
});