E-Invoice - New request to allow user to change of mind when filling up einvoice info form to opt out when they already opt in for e-invoice

This commit is contained in:
Dillon Ngo
2025-07-02 00:09:38 +08:00
parent c7fd52e65f
commit e53fb80ee3
6 changed files with 108 additions and 8 deletions
@@ -0,0 +1,62 @@
<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\UpdatesCompanyEInvoiceRequest;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\DataTransferObjects\EInvoiceRequestDTO;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateCompanyEInvoiceRequestChangeLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Updated EInvoice Request',
'message' => 'You have successfully updated company E-Invoice request'
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var UpdatesCompanyEInvoiceRequest */
private $updatesCompanyEInvoiceRequest;
/**
* UpdateCompanyEInvoiceRequestChangeLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param UpdatesCompanyEInvoiceRequest $updatesCompanyEInvoiceRequest
*/
public function __construct(FetchesCompany $fetchesCompany, UpdatesCompanyEInvoiceRequest $updatesCompanyEInvoiceRequest)
{
$this->fetchesCompany = $fetchesCompany;
$this->updatesCompanyEInvoiceRequest = $updatesCompanyEInvoiceRequest;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function logic(Request $request) : JsonResponse
{
$dto = new EInvoiceRequestDTO($request->all());
$company = $this->fetchesCompany->execute(['id' => $dto->companyId]);
if($company->e_invoice === 1){
$this->updatesCompanyEInvoiceRequest->execute($company, $dto->eInvoiceRequest);
}
return $this->response([]);
}
}
@@ -17,13 +17,18 @@ class UpdatesCompanyEInvoiceRequest extends AbstractUpdateRecord
*/
public function execute(Company $model, bool $eInvoice)
{
if (is_null($model->e_invoice_requested_at)) {
if($eInvoice){
$model->e_invoice_requested_at = now();
if($eInvoice){
if (is_null($model->e_invoice_requested_at)) {
if($eInvoice){
$model->e_invoice_requested_at = now();
}
}
$model->e_invoice = 1;
}
else{
$model->e_invoice_requested_at = null;
$model->e_invoice = 0;
}
$model->e_invoice = $eInvoice;
return $this->handler($model);
}
}
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Companies;
use App\Classes\Modules\Companies\ControllersLogic\UpdateCompanyEInvoiceInfoLogic;
use App\Classes\Modules\Companies\ControllersLogic\UpdateCompanyEInvoiceRequestLogic;
use App\Classes\Modules\Companies\ControllersLogic\UpdateCompanyEInvoiceRequestChangeLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -18,7 +19,7 @@ class UpdateCompanyEInvoiceInfoController
return $logic->execute($request);
}
/**
/**
* @param Request $request
* @param UpdateCompanyEInvoiceRequestLogic $logic
* @return JsonResponse
@@ -26,4 +27,13 @@ class UpdateCompanyEInvoiceInfoController
public function updateRequest(Request $request, UpdateCompanyEInvoiceRequestLogic $logic): JsonResponse {
return $logic->execute($request);
}
/**
* @param Request $request
* @param UpdateCompanyEInvoiceRequestChangeLogic $logic
* @return JsonResponse
*/
public function updateChangeOfMindRequest(Request $request, UpdateCompanyEInvoiceRequestChangeLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -80,6 +80,18 @@
</div>
</div>
</div>
<div class="row">
<div class="col text-right">
<a
id="e-invoice-request-link"
href="javascript:void(0);"
class="fs-12 text-complete text-underline pointer"
@click="updateChangeOfMind()"
>
I don't need now
</a>
</div>
</div>
</div>
</div>
<div class="row" v-if="step === 2">
@@ -251,6 +263,10 @@
successHandler(response){
this.$emit('eInvoiceInfoUpdated', response.payload.data);
this.closeModal();
},
updateChangeOfMind(){
this.$emit('eInvoiceChangeOfMindRequest');
this.closeModal();
}
},
mixins: [ModalFormHandler],
@@ -166,7 +166,7 @@
:company-id="data.company.id"
:company-type="data.company.type"
v-on:eInvoiceInfoUpdated="updatedEInvoiceInfo($event)"
v-on:close="createAddress = !createAddress">
v-on:eInvoiceChangeOfMindRequest="changeOfMindEInvoiceRequest()">
</e-invoice-info-form-component>
</modal-component>
<!-- E-Invoice - end -->
@@ -724,6 +724,9 @@
$('#confirm-booking-modal').modal('show');
}
}
else if(section === this.section + 'ChangeOfMind'){
this.$store.dispatch('reloadList', {'name': "bookingDetailSection"});
}
else if(section === this.section + 'ValidateVoucher'){
if(!response.payload.data){
this.voucherValidated = false;
@@ -756,7 +759,6 @@
}
else{
this.checkTransferRule();
// this.checkEInvoiceRule();
}
},
cancelQuotation(){
@@ -836,6 +838,10 @@
if(!choice){
this.showModalEInvoiceRequest = true;
}
},
changeOfMindEInvoiceRequest(){
this.parameters.e_invoice_request = false;
this.submit((this.route('api.company.einvoice.request.change')), 'post', this.section + 'ChangeOfMind', true, true);
}
//E-Invoice - Ends
},
+1
View File
@@ -43,4 +43,5 @@ Route::group(['prefix' => 'company', 'as' => 'company.', 'namespace' => 'Compani
Route::get('/e-invoice/info/{id}', [FetchCompanyEInvoiceInfoController::class, 'fetch'])->name('einvoice.info');
Route::post('/e-invoice/info/update', [UpdateCompanyEInvoiceInfoController::class, 'updateInfo'])->name('einvoice.info.update');
Route::post('/e-invoice/request/update', [UpdateCompanyEInvoiceInfoController::class, 'updateRequest'])->name('einvoice.request.update');
Route::post('/e-invoice/request/update/changeofmind', [UpdateCompanyEInvoiceInfoController::class, 'updateChangeOfMindRequest'])->name('einvoice.request.change');
});