mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-24 15:05:09 +00:00
refactor functions: getConstantByKey, checkPostcodeExistInConstant
This commit is contained in:
@@ -24,4 +24,31 @@ class Helper
|
||||
return array_slice(get_class_methods($className), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $segmentConstantObject
|
||||
* @param string $key
|
||||
* @return integer
|
||||
*/
|
||||
static 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $segmentConstantObject
|
||||
* @param string $postcode
|
||||
* @return boolean
|
||||
*/
|
||||
static function checkPostcodeExistInConstant($segmentConstantObject, $postcode) {
|
||||
$segmentConstantObject = $segmentConstantObject->value;
|
||||
if (!empty($segmentConstantObject)) {
|
||||
return in_array($postcode, $segmentConstantObject);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+6
-22
@@ -32,6 +32,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Meneses\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\General\Helper;
|
||||
|
||||
class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -114,19 +115,19 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
$state_rate = 0;
|
||||
$state_select = '';
|
||||
|
||||
$base_price = $this->getConstantByKey($base_price_constant, date('Y-m-d'));
|
||||
$base_price = Helper::getConstantByKey($base_price_constant, date('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);
|
||||
$selected_warehouse_rate = Helper::getConstantByKey($warehouse_rate_constant, $warehouseId);
|
||||
$warehouse_rate = is_object($selected_warehouse_rate) ? $selected_warehouse_rate->amount : 0;
|
||||
|
||||
$stateId = $address->state_id;
|
||||
$state_rate_constant = $this->getConstantByKey($state_rate_constant, $stateId);
|
||||
$state_rate_constant = Helper::getConstantByKey($state_rate_constant, $stateId);
|
||||
|
||||
// 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' : '' ;
|
||||
Helper::checkPostcodeExistInConstant($center_postcode_constant, $postcode) === true ? $state_select = 'center' : '' ;
|
||||
Helper::checkPostcodeExistInConstant($outstation_postcode_constant, $postcode) === true ? $state_select = 'outstation' : '' ;
|
||||
$state_rate_constant = (array)$state_rate_constant;
|
||||
$state_rate = $state_select == '' ? 0 : $state_rate_constant[$state_select];
|
||||
|
||||
@@ -194,21 +195,4 @@ 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) {
|
||||
$segmentConstantObject = $segmentConstantObject->value;
|
||||
if (!empty($segmentConstantObject)) {
|
||||
return in_array($postcode, $segmentConstantObject);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-21
@@ -10,6 +10,7 @@ use App\Models\District;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\General\Helper;
|
||||
|
||||
class ShippingEstimationCalculatorLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -49,14 +50,14 @@ class ShippingEstimationCalculatorLogic extends AbstractControllerLogic
|
||||
$state_rate_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::STATE_RATE]);
|
||||
$outstation_postcode_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::OUTSTATION_POSTCODE]);
|
||||
|
||||
$base_price = $this->getConstantByKey($base_price_constant, date('Y-m-d'));
|
||||
$selected_warehouse_rate = $this->getConstantByKey($warehouse_rate_constant, $request->input('warehouse_id'));
|
||||
$base_price = Helper::getConstantByKey($base_price_constant, date('Y-m-d'));
|
||||
$selected_warehouse_rate = Helper::getConstantByKey($warehouse_rate_constant, $request->input('warehouse_id'));
|
||||
$warehouse_rate = is_object($selected_warehouse_rate) ? $selected_warehouse_rate->amount : 0;
|
||||
|
||||
$district = District::where('postcode','LIKE','%'.$request->input('postcode').'%')->first();
|
||||
$state_rate_constant = $this->getConstantByKey($state_rate_constant, $district->state_id);
|
||||
$state_rate_constant = Helper::getConstantByKey($state_rate_constant, $district->state_id);
|
||||
|
||||
$this->checkPostcodeExistInConstant($outstation_postcode_constant, $request->input('postcode')) === true ? $state_select = 'outstation' : '' ;
|
||||
Helper::checkPostcodeExistInConstant($outstation_postcode_constant, $request->input('postcode')) === true ? $state_select = 'outstation' : '' ;
|
||||
$state_rate_constant = (array)$state_rate_constant;
|
||||
$state_rate = $state_select == '' ? 0 : $state_rate_constant[$state_select];
|
||||
|
||||
@@ -69,21 +70,4 @@ class ShippingEstimationCalculatorLogic extends AbstractControllerLogic
|
||||
]);
|
||||
}
|
||||
|
||||
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) {
|
||||
$segmentConstantObject = $segmentConstantObject->value;
|
||||
if (!empty($segmentConstantObject)) {
|
||||
return in_array($postcode, $segmentConstantObject);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user