Merge branch 'container-payment-ui' of https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal into development

This commit is contained in:
edmondlang
2022-05-07 16:28:40 +08:00
5 changed files with 114 additions and 141 deletions
@@ -21,10 +21,12 @@ use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\PackageType;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Classes\ValueObjects\Constants\TransactionDetailType;
use App\Models\Document;
use App\Models\Transaction;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
@@ -98,57 +100,35 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity);
});
$order = $packing_list->owner()->first();
$order = $packing_list->owner;
$address = $order->addresses()->first();
$base_price_constant = $this->fetchesSegmentConstant->execute(['id' => 1]);
$warehouse_rate_constant = $this->fetchesSegmentConstant->execute(['id' => 2]);
$state_rate_constant = $this->fetchesSegmentConstant->execute(['id' => 3]);
$center_postcode_constant = $this->fetchesSegmentConstant->execute(['id' => 4]);
$outstation_postcode_constant = $this->fetchesSegmentConstant->execute(['id' => 5]);
$base_price_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::BASE_PRICE]);
$warehouse_rate_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::WAREHOUSE_RATE]);
$state_rate_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::STATE_RATE]);
$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]);
$base_price = 0;
$warehouse_rate = 0;
$state_rate = 0;
$state_select = [];
$with_out = false;
$state_select = '';
if ($base_price_constant) {
$base_price = $base_price_constant->value->price;
}
$base_price = $this->getConstantByKey($base_price_constant, date('Y-m-d'));
dd($base_price);
if ($warehouse_rate_constant) {
$package_warehouse = $order->OrderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->reference;
foreach ($warehouse_rate_constant->value->config as $key_warehouse => $row_warehouse) {
if ($row_warehouse->warehouse_name == $package_warehouse) {
$warehouse_rate = $row_warehouse->rate;
}
}
}
$warehouseId = $order->orderRoles()->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->company_module_id;
$warehouse_rate = $this->getConstantByKey($warehouse_rate_constant, $warehouseId)->amount;
if ($state_rate_constant) {
foreach ($state_rate_constant->value->config as $key_state => $row_state) {
if ($row_state->status_id == $address->state_id) {
$state_select = $row_state;
}
}
}
$stateId = $address->state_id;
$state_rate_constant = $this->getConstantByKey($state_rate_constant, $stateId);
if ($outstation_postcode_constant) {
foreach ($outstation_postcode_constant->value as $key_out => $row_out) {
if($row_out == $address->postcode) {
$with_out = true;
}
}
}
if (!empty($state_select)) {
$state_rate = $state_select->rate;
if ($with_out) {
$state_rate = $state_select->rate + $state_select->outstation_rate;
}
}
// get $state_rate
$postcode = $address->postcode;
$this->checkPostcodeExistInConstant($center_postcode_constant, $postcode) === true ? $state_select = 'center' : '' ;
$this->checkPostcodeExistInConstant($outstation_postcode_constant, $postcode) === true ? $state_select = 'outstation' : '' ;
$state_rate_constant = (array)$state_rate_constant;
$state_rate = $state_rate_constant[$state_select];
$price_cbm = $base_price + $warehouse_rate + $state_rate;
$total_cbm = $price_cbm * ($cbm + $over_weight_cbm);
@@ -213,4 +193,20 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
return $this->response([]);
}
function getConstantByKey($segmentConstantObject, $key) {
if ($segmentConstantObject) {
$base_rate = (array) $segmentConstantObject->value;
$base_rate = array_key_exists($key, $base_rate) === true ? $base_rate[$key] : 0;
return $base_rate;
}
}
function checkPostcodeExistInConstant($segmentConstantObject, $postcode) {
if ($segmentConstantObject) {
$segmentConstantObject = $segmentConstantObject->value;
return in_array($postcode, $segmentConstantObject);
}
}
}
+3
View File
@@ -1,8 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class SegmentCompany extends AbstractModel
{
use SoftDeletes;
protected $table = 'segment_companies';
}
+2
View File
@@ -15,6 +15,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
*/
class SegmentConstant extends AbstractModel
{
use SoftDeletes;
protected $table = 'segment_constants';
public function getDetailAttribute($value)
@@ -19,8 +19,8 @@ class SegmentConstantsTableSeeder extends Seeder
'segment_id' => 1,
'reference' => SegmentConstants::BASE_PRICE,
'value' => json_encode([
'id'=> 1,
'price' => 500,
'2022-05-01'=> '0.00',
'2022-05-02'=> '0.00',
]),
],
[
@@ -28,21 +28,12 @@ class SegmentConstantsTableSeeder extends Seeder
'segment_id' => 1,
'reference' => SegmentConstants::WAREHOUSE_RATE,
'value' => json_encode([
'id'=> 1,
'config' => [
[
'warehouse_name' => WarehouseReferences::VT_GUANG_ZHOU,
'rate' => 10
],
[
'warehouse_name' => WarehouseReferences::YD_GUANG_ZHOU,
'rate' => 10
],
[
'warehouse_name' => WarehouseReferences::VT_YIWU,
'rate' => 10
],
]
'7' =>[
'amount' => '0.00',
],
'6' =>[
'amount' => '0.00',
],
]),
],
[
@@ -50,88 +41,69 @@ class SegmentConstantsTableSeeder extends Seeder
'segment_id' => 1,
'reference' => SegmentConstants::STATE_RATE,
'value' => json_encode([
'id'=> 1,
'config' => [
[
'status_id' => 1,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 2,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 3,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 4,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 5,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 6,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 7,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 8,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 9,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 10,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 11,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 12,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 13,
'rate' => 20,
'outstation_rate' => 2
],
[
'status_id' => 14,
'rate' => 20,
'outstation_rate' => 2
],
[
'status_id' => 15,
'rate' => 10,
'outstation_rate' => 2
],
[
'status_id' => 16,
'rate' => 10,
'outstation_rate' => 2
]
'1' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'2' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'3' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'4' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'5' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'6' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'7' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'8' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'9' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'10' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'11' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'12' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'13' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'14' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'15' =>[
'center' => '10.00',
'outstation' => '2.00'
],
'16' =>[
'center' => '10.00',
'outstation' => '2.00'
]
]),
],
@@ -40,7 +40,7 @@
<div v-if="!item.order" class="text-danger">Unclaimed</div>
</div>
</div>
<div class="row hide" v-if="false">
<div class="row">
<div class="col">
<div v-if="!item.shippng_transaction">
<div class="btn btn-xs btn-primary pointer" @click="generateInvoice()">Generate Invoice</div>