mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-28 00:43:58 +00:00
E-Invoice - Fix problem reported by Sin Yee when PO can be edited
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Bookings\Services\FetchesBooking;
|
||||
use App\Classes\Modules\Bookings\Services\UpdatesBookingFixedAmount;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Http\Resources\BookingResource;
|
||||
use App\Models\Booking;
|
||||
@@ -32,15 +33,21 @@ class UpdateBookingAmountWithPOLogic extends AbstractControllerLogic
|
||||
/** @var UpdatesBookingFixedAmount */
|
||||
private $updatesBookingFixedAmount;
|
||||
|
||||
/** @var CalculatesBookingOutstanding */
|
||||
private $calculatesBookingOutstanding;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateBookingAmountWithPOLogic constructor.
|
||||
* @param FetchesBooking $fetchesBooking
|
||||
* @param UpdatesBookingFixedAmount $updatesBookingFixedAmount
|
||||
* @param CalculatesBookingOutstanding $calculatesBookingOutstanding
|
||||
*/
|
||||
public function __construct(FetchesBooking $fetchesBooking, UpdatesBookingFixedAmount $updatesBookingFixedAmount)
|
||||
public function __construct(FetchesBooking $fetchesBooking, UpdatesBookingFixedAmount $updatesBookingFixedAmount, CalculatesBookingOutstanding $calculatesBookingOutstanding)
|
||||
{
|
||||
$this->fetchesBooking = $fetchesBooking;
|
||||
$this->updatesBookingFixedAmount = $updatesBookingFixedAmount;
|
||||
$this->calculatesBookingOutstanding = $calculatesBookingOutstanding;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,8 +61,13 @@ class UpdateBookingAmountWithPOLogic extends AbstractControllerLogic
|
||||
{
|
||||
/** @var Booking $booking */
|
||||
$booking = $this->fetchesBooking->execute(['id' => $request->route('id') ?? $id]);
|
||||
$outstandingAmount = $this->calculatesBookingOutstanding->execute($booking);
|
||||
$bookingAttribute = $booking->attributesKVP()->where('key', "BOOKING_AMOUNT_UPDATE")->first();
|
||||
|
||||
if(!($outstandingAmount > 0 && $bookingAttribute)){
|
||||
throw new MalformedRequestException('Purchase Order at this point can only be edited after editing the booking amount');
|
||||
}
|
||||
|
||||
if($bookingAttribute){
|
||||
$total = collect($request->input('products'))->sum(function($product){
|
||||
return $product['quantity'] * floatval(str_replace(',', '', $product['unit_price']));
|
||||
|
||||
@@ -236,7 +236,7 @@
|
||||
},
|
||||
created() {
|
||||
this.products = this.data.purchase_order ? this.data.purchase_order.details : [];
|
||||
this.submitted = this.data.purchase_order ? this.data.purchase_order.status === 1 || this.data.purchase_order.status === 2: false;
|
||||
this.submitted = this.data.purchase_order ? true : false; // this.submitted = this.data.purchase_order ? this.data.purchase_order.status === 1 || this.data.purchase_order.status === 2: false;
|
||||
},
|
||||
computed: {
|
||||
productTotal(){
|
||||
@@ -248,17 +248,23 @@
|
||||
}, 0);
|
||||
},
|
||||
allowPOEditing() {
|
||||
//Condition 1
|
||||
const noPaymentsMade = Math.round((this.data.paid_amount + Number.EPSILON) * 100) / 100 === 0;
|
||||
const noPendingVerifications = this.data.payment_history.every(payment => payment.status !== 1);
|
||||
const noPaymentPendingVerifications = this.data.payment_history.every(payment => payment.status !== 1);
|
||||
|
||||
return noPaymentsMade && noPendingVerifications;
|
||||
//Condition 2
|
||||
const paymentsMade = Math.round((this.data.paid_amount + Number.EPSILON) * 100) / 100 > 0;
|
||||
const outstandingAmount = Math.round((this.data.outstanding_amount + Number.EPSILON) * 100) / 100 > 0;
|
||||
const allPaymentApproved = this.data.payment_history.every(payment => payment.status === 2);
|
||||
|
||||
return (noPaymentsMade && noPaymentPendingVerifications) || (paymentsMade && outstandingAmount && allPaymentApproved);
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'data': function () {
|
||||
if (this.data && this.data.purchase_order && this.data.purchase_order.details) {
|
||||
this.products = this.data.purchase_order.details;
|
||||
this.submitted = this.data.purchase_order ? this.data.purchase_order.status === 1 || this.data.purchase_order.status === 2: false;
|
||||
this.submitted = this.data.purchase_order ? true : false; // this.submitted = this.data.purchase_order ? this.data.purchase_order.status === 1 || this.data.purchase_order.status === 2: false;
|
||||
} else {
|
||||
this.products = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user