billing fix up

This commit is contained in:
omair saleh
2022-09-20 06:43:54 +08:00
parent 968ff5c02a
commit d8b41cbe55
9 changed files with 82 additions and 18 deletions
@@ -23,7 +23,7 @@ class CreatesBillplzBill
try{
// config('billplz.maybank')
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->post(config('billplz.base_url').'/api/v3/bills', [
'collection_id' => $wallet ? config('billplz.wallet_collection_id') : config('billplz.collection_id'),
'collection_id' => config('billplz.collection_id'),
'name' => $name,
'email' => $email,
'description' => $description,
@@ -35,7 +35,7 @@ class CreatesBillplzBill
'reference_2_label' => 'Bill Number',
'reference_2' => $billNumber
]);
dd($response);
if($response->successful()){
$data = $response->json();
@@ -90,7 +90,7 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic
$request->input('bank_code'),
true
);
dd($billPlzBill);
$payment_reference = $billPlzBill->id;
}
else {
@@ -16,6 +16,7 @@ use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
@@ -92,6 +93,7 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
public function logic(Request $request) : JsonResponse
{
$packing_list = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]);
$packing_list = PackingList::where('reference', $packing_list->reference)->where('type', PackingListType::SHIPPING_PACKING_LIST)->first();
$cbm = $packing_list->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum(function($package) {
return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity);
@@ -102,6 +104,8 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
});
$order = $packing_list->owner;
$companyModule = $order->companyModule;
$connection = $companyModule->connections()->first();
$address = $order->addresses()->first();
$base_price_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::BASE_PRICE]);
@@ -110,13 +114,22 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$center_postcode_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::CENTER_POSTCODE]);
$outstation_postcode_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::OUTSTATION_POSTCODE]);
$noMinimumCharge = $connection->segments()->where('segments.id', 4)->first();
$base_price = 0;
$warehouse_rate = 0;
$state_rate = 0;
$minimum_cbm = 0.3;
$segment_price = 0;
$state_select = '';
$segment_price = $connection->segments()->whereHas('constants')->get()->map(function($segment){
return (float) $segment->constants()->first()->value[0];
})->sort()->first();
$segment_price = $segment_price ? $segment_price : 0;
$packing_list_drop_date = Carbon::parse(PackingList::where('reference', $packing_list->reference)->where('type', 1)->first()->transports->first()->drop_date)->format('d/m/Y');
$base_price = $this->getConstantByKey($base_price_constant, $packing_list_drop_date);
$base_price = $this->getConstantByKey($base_price_constant, Carbon::parse($packing_list_drop_date)->format('Y-m-d'));
$warehouseId = $order->orderRoles()->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->company_module_id;
$selected_warehouse_rate = $this->getConstantByKey($warehouse_rate_constant, $warehouseId);
@@ -132,8 +145,40 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$state_rate_constant = (array)$state_rate_constant;
$state_rate = $state_select == '' ? 0 : $state_rate_constant[$state_select];
$price_cbm = $base_price + $warehouse_rate + $state_rate;
$total_cbm = $price_cbm * ($cbm + $over_weight_cbm);
$container = $packing_list->containers()->first();
$containerPackingLists = collect();
$hasMinimumCharge = null;
foreach ($container->packingLists as $packingList){
if($packingList->owner->companyModule->id !== $companyModule->id) continue;
$containerPackingLists->push($packingList);
if(!$hasMinimumCharge) {
$hasMinimumCharge = $packingList->transactions()->whereHas('transactionDetails', function ($query){
$query->where('reference', 'MIN_CBM_CHARGES');
})->first();
}
}
$totalContainerCbm = $containerPackingLists->sum(function($packingList){
return $packingList->packages->where('type', '!=', PackageType::OVER_WEIGHT)->sum(function($package) {
return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity);
});
});
$minimum_charge = round($minimum_cbm - $totalContainerCbm, '2');
$minimum_charge = $minimum_charge < 0 ? 0 : $minimum_charge;
$minimum_charge = $noMinimumCharge ? 0 : $minimum_charge;
if($hasMinimumCharge) {
$minimum_charge = 0;
}
$price_cbm = $base_price + $segment_price + $warehouse_rate + $state_rate;
$total_cbm = $price_cbm * ($cbm + $minimum_charge + $over_weight_cbm);
$billNumber = $this->generatesTransactionBillNumber->execute('SHIP-');
@@ -166,7 +211,7 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
);
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
if ($over_weight_cbm > 0) {
$object_detail = new TransactionDetailObject(
'OVER_WEIGHT_CHARGES',
@@ -178,6 +223,17 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
}
if ($minimum_charge > 0) {
$object_detail = new TransactionDetailObject(
'MIN_CBM_CHARGES',
TransactionDetailType::MIN_CBM_CHARGES,
$minimum_charge,
$price_cbm
);
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
}
return $this->response([]);
}
@@ -185,6 +241,7 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
if ($segmentConstantObject) {
$base_rate = (array) $segmentConstantObject->value;
$base_rate = array_key_exists($key, $base_rate) === true ? $base_rate[$key] : 0;
return $base_rate;
}
}
@@ -85,7 +85,7 @@ class UpdateShippingInvoiceTransactionLogic extends AbstractControllerLogic
{
$invoice_transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
$old_transaction_details = $invoice_transaction->transactionDetails->whereNotIn('reference', ['SHIPPING_FEE', 'OVER_WEIGHT_CHARGES'])->pluck('id')->toArray();
$old_transaction_details = $invoice_transaction->transactionDetails->whereNotIn('reference', ['SHIPPING_FEE', 'OVER_WEIGHT_CHARGES', 'MIN_CBM_CHARGES'])->pluck('id')->toArray();
$new_transaction_details = collect($request->input('transaction_details'));
@@ -104,7 +104,7 @@ class UpdateShippingInvoiceTransactionLogic extends AbstractControllerLogic
foreach($new_transaction_details as $transaction_detail){
$transaction_detail = (object) $transaction_detail;
if(!in_array($transaction_detail->reference, ['SHIPPING_FEE', 'OVER_WHEIGHT_CHARGES'])){
if(!in_array($transaction_detail->reference, ['SHIPPING_FEE', 'OVER_WEIGHT_CHARGES', 'MIN_CBM_CHARGES'])){
$object_detail = new TransactionDetailObject(
'CUSTOM_CHARGES',
isset($transaction_detail->name) ? $transaction_detail->name : TransactionDetailType::CUSTOM_CHARGES,
@@ -117,8 +117,6 @@ class UpdateShippingInvoiceTransactionLogic extends AbstractControllerLogic
}else{
$new_transaction_detail = $this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
}
$total_cbm += $new_transaction_detail->amount;
}
}
@@ -129,8 +127,8 @@ class UpdateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$invoice_transaction->issuer,
1,
PaymentMethodType::CASH,
$total_cbm,
$total_cbm,
$invoice_transaction->transactionDetails()->sum('amount'),
$invoice_transaction->transactionDetails()->sum('amount'),
1,
1,
0,
@@ -8,5 +8,7 @@ final class TransactionDetailType {
public const OVER_WEIGHT_CHARGES = 'Overweight Charges';
public const MIN_CBM_CHARGES = 'Overweight Charges';
public const CUSTOM_CHARGES = 'Custom charges';
}
+3
View File
@@ -13,9 +13,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Transaction extends AbstractModel implements Documentable, Transactionable, Remarkable
{
use SoftDeletes;
protected $table = 'transactions';
public function owner(): morphTo
@@ -46,7 +46,7 @@
<i class="fa fa-times muted m-l-10 pointer requestModal" data-type="detachSegment" ></i>
</div>
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="detachSegment">
<detach-segment-form-component :data="segment" :company_id="item.id" section="customerProfileSection"></detach-segment-form-component>
<detach-segment-form-component :data="segment" :company_id="item.id" :connection="item.company_module.connections[0].id" section="customerProfileSection"></detach-segment-form-component>
</modal-component>
</div>
</div>
@@ -12,7 +12,7 @@
<div class="row m-b-20">
<div class="col">
<h3 class="all-caps">Are you Sure?</h3>
<div class="fs-11">Are you sure you want to detach custom from <span class="bold">{{this.item.name}}</span> segment?</div>
<div class="fs-11">Are you sure you want to detach customer from <span class="bold">{{this.item.name}}</span> segment?</div>
</div>
</div>
<div class="row">
@@ -20,7 +20,7 @@
<div class="btn btn-sm btn-success btn-block b-rad-none" data-dismiss="modal">Cancel</div>
</div>
<div class="col p-l-5">
<div class="btn btn-sm btn-danger btn-block b-rad-none" @click="submit(route('api.company.segment.detach', company_id, item.id), 'delete', 'customerProfileSection', true, true)">Remove Segment</div>
<div class="btn btn-sm btn-danger btn-block b-rad-none" @click="submit(route('api.company.connection.detach', company_id, connection, item.id), 'delete', 'customerProfileSection', true, true)">Remove Segment</div>
</div>
</div>
</div>
@@ -36,6 +36,10 @@
company_id: {
required: true,
type: Number
},
connection: {
required: true,
type: Number
}
},
@@ -21,12 +21,12 @@
<p class="m-b-0 small muted">Total</p>
<p class="m-b-0 bold text-success">{{currency}} {{(Math.round((productTotal + Number.EPSILON) * 100) / 100).toFixed(2)}}</p>
</div>
<div class="col-auto" :class="{ 'invisible': ['SHIPPING_FEE', 'OVER_WEIGHT_CHARGES'].includes(product.reference) }">
<div class="col-auto" :class="{ 'invisible': ['SHIPPING_FEE', 'OVER_WEIGHT_CHARGES', 'MIN_CBM_CHARGES'].includes(product.reference) }">
<div @click="isEdit = !isEdit" class="pointer">
<i class="fa fa-pencil" />
</div>
</div>
<div class="col-auto" :class="{ 'invisible': ['SHIPPING_FEE', 'OVER_WEIGHT_CHARGES'].includes(product.reference) }">
<div class="col-auto" :class="{ 'invisible': ['SHIPPING_FEE', 'OVER_WEIGHT_CHARGES', 'MIN_CBM_CHARGES'].includes(product.reference) }">
<div @click="$emit('remove')" class="pointer">
<i class="fa fa-close" />
</div>