diff --git a/app/Classes/General/Eloquent/Filters/DoesNotHaveTransactionType.php b/app/Classes/General/Eloquent/Filters/DoesNotHaveTransactionType.php
index 3568ac3b..486819bf 100644
--- a/app/Classes/General/Eloquent/Filters/DoesNotHaveTransactionType.php
+++ b/app/Classes/General/Eloquent/Filters/DoesNotHaveTransactionType.php
@@ -2,6 +2,7 @@
namespace App\Classes\General\Eloquent\Filters;
+use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
class DoesNotHaveTransactionType implements Filter
@@ -15,6 +16,8 @@ class DoesNotHaveTransactionType implements Filter
{
return $builder->whereDoesntHave('transactions', function (Builder $query) use($value) {
$query->where('type', $value);
+ })->whereHas('containers', function ($query){
+ return $query->whereDate('loading_date', '>=', Carbon::parse('08-08-2022'));
});
}
}
\ No newline at end of file
diff --git a/app/Classes/General/Eloquent/Filters/SegmentIdIn.php b/app/Classes/General/Eloquent/Filters/SegmentIdIn.php
new file mode 100644
index 00000000..de66a61f
--- /dev/null
+++ b/app/Classes/General/Eloquent/Filters/SegmentIdIn.php
@@ -0,0 +1,20 @@
+whereIn('segment_id', $value);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Classes/Modules/Companies/Services/AssignsCompanyToSegment.php b/app/Classes/Modules/Companies/Services/AssignsCompanyToSegment.php
index 81b6e964..9c54d401 100644
--- a/app/Classes/Modules/Companies/Services/AssignsCompanyToSegment.php
+++ b/app/Classes/Modules/Companies/Services/AssignsCompanyToSegment.php
@@ -4,6 +4,7 @@ namespace App\Classes\Modules\Companies\Services;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
+use App\Classes\ValueObjects\Constants\BusinessType;
use App\Models\Company;
use App\Models\Segment;
use Illuminate\Database\QueryException;
@@ -19,8 +20,9 @@ class AssignsCompanyToSegment extends AbstractUpdateRecord
public function execute(Company $company, Segment $segment)
{
try {
-
- $company->segments()->attach($segment);
+ $companyModule = $company->companyModules()->where('type', BusinessType::IMPORTER)->first();
+ $connection = $companyModule->connections()->where('inviter_reference', 'CIEF');
+ $connection->segments()->attach($segment);
return $company;
diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php
index 50b6165f..dd64c5e9 100644
--- a/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php
+++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateShippingInvoiceTransactionLogic.php
@@ -6,6 +6,8 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\Modules\SegmentConstants\Services\FetchesSegmentConstant;
+use App\Classes\Modules\Segments\Services\ListsConstants;
+use App\Classes\Modules\Segments\Services\ListsSegments;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
@@ -24,7 +26,9 @@ use App\Classes\ValueObjects\Constants\PackageType;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Classes\ValueObjects\Constants\TransactionDetailType;
+use App\Http\Resources\PackingListResource;
use App\Models\Document;
+use App\Models\PackingList;
use App\Models\Transaction;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
@@ -36,7 +40,6 @@ use Meneses\LaravelMpdf\Facades\LaravelMpdf;
class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
{
-
/**
* @return array
*/
@@ -53,6 +56,9 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
/** @var FetchesSegmentConstant */
private $fetchesSegmentConstant;
+ /** @var ListsConstants */
+ private $listsConstants;
+
/** @var GeneratesTransactionBillNumber */
private $generatesTransactionBillNumber;
@@ -67,20 +73,24 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
/** @var CreatesFiles */
private $createsFile;
-
- public function __construct(
- FetchesPackingList $fetchesPackingList,
- FetchesSegmentConstant $fetchesSegmentConstant,
- GeneratesTransactionBillNumber $generatesTransactionBillNumber,
- CreatesTransaction $createsTransaction,
- CreatesTransactionDetail $createsTransactionDetail,
- CreatesDocument $createsDocument,
- CreatesFiles $createsFile
- )
- {
+
+ /**
+ * CreateShippingInvoiceTransactionLogic constructor.
+ * @param FetchesPackingList $fetchesPackingList
+ * @param FetchesSegmentConstant $fetchesSegmentConstant
+ * @param ListsConstants $listsConstants
+ * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
+ * @param CreatesTransaction $createsTransaction
+ * @param CreatesTransactionDetail $createsTransactionDetail
+ * @param CreatesDocument $createsDocument
+ * @param CreatesFiles $createsFile
+ */
+ public function __construct(FetchesPackingList $fetchesPackingList, FetchesSegmentConstant $fetchesSegmentConstant, ListsConstants $listsConstants, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CreatesTransactionDetail $createsTransactionDetail, CreatesDocument $createsDocument, CreatesFiles $createsFile)
+ {
$this->fetchesPackingList = $fetchesPackingList;
$this->fetchesSegmentConstant = $fetchesSegmentConstant;
+ $this->listsConstants = $listsConstants;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createsTransaction = $createsTransaction;
$this->createsTransactionDetail = $createsTransactionDetail;
@@ -88,6 +98,7 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$this->createsFile = $createsFile;
}
+
public function logic(Request $request) : JsonResponse
{
$packing_list = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]);
@@ -100,22 +111,33 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity);
});
+ $minimum_charges = ($cbm + $over_weight_cbm) < 0.3 ? (0.3 - ($cbm + $over_weight_cbm)) : 0;
+
$order = $packing_list->owner;
$address = $order->addresses()->first();
+ $segments = $order->companyModule->connections->first()->segments->pluck('id');
+
+ $segment_price = 0;
$base_price_constant = $this->fetchesSegmentConstant->execute(['segment_id' => 1, 'reference' => SegmentConstants::BASE_PRICE]);
+
+ if(count($segments)){
+ $segment_price_constants = $this->listsConstants->execute(['segment_id_in' => $segments, 'reference' => SegmentConstants::CUSTOM_PRICE]);
+ $segment_price_constant = $segment_price_constants->sortBy(function ($constant){
+ return $constant->value[0];
+ })->first();
+ $segment_price = $segment_price_constant->value[0];
+
+ }
+
$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 = '';
- $base_price = $this->getConstantByKey($base_price_constant, date('Y-m-d'));
-
+ $packing_list_drop_date = Carbon::parse(PackingList::where('reference', $packing_list->reference)->where('type', 1)->first()->transports->first()->drop_date)->format('Y-m-d');
+ $base_price = $this->getConstantByKey($base_price_constant, $packing_list_drop_date);
$warehouseId = $order->orderRoles()->where('role_id', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->company_module_id;
$selected_warehouse_rate = $this->getConstantByKey($warehouse_rate_constant, $warehouseId);
$warehouse_rate = is_object($selected_warehouse_rate) ? $selected_warehouse_rate->amount : 0;
@@ -128,12 +150,15 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$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_select == '' ? 0 : $state_rate_constant[$state_select];
+ $state_rate = $state_select == '' ? 0 : $state_rate_constant['center'] + ($state_select === 'outstation' ? $state_rate_constant['outstation'] : 0);
+
+ $price_cbm = $base_price + $segment_price + $warehouse_rate + $state_rate;
- $price_cbm = $base_price + $warehouse_rate + $state_rate;
$total_cbm = $price_cbm * ($cbm + $over_weight_cbm);
- $billNumber = $this->generatesTransactionBillNumber->execute('SHIP-');
+
+
+ $billNumber = $this->generatesTransactionBillNumber->execute('SI-');
$object = new TransactionObject(
$billNumber,
@@ -158,7 +183,7 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$object_detail = new TransactionDetailObject(
'SHIPPING_FEE',
- TransactionDetailType::SHIPPING_FEE,
+ TransactionDetailType::SHIPPING_FEE.'
'.round($packing_list->packages->sum('quantity'), 3).' CTNS - '.$cbm.' CBM',
$cbm,
$price_cbm
);
@@ -176,7 +201,7 @@ class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
}
- return $this->response([]);
+ return $this->resourceResponse(new PackingListResource($packing_list));
}
function getConstantByKey($segmentConstantObject, $key) {
diff --git a/app/Classes/ValueObjects/Constants/TransactionDetailType.php b/app/Classes/ValueObjects/Constants/TransactionDetailType.php
index b3e1541c..aa9e835c 100644
--- a/app/Classes/ValueObjects/Constants/TransactionDetailType.php
+++ b/app/Classes/ValueObjects/Constants/TransactionDetailType.php
@@ -4,9 +4,9 @@ namespace App\Classes\ValueObjects\Constants;
final class TransactionDetailType {
- public const SHIPPING_FEE = 'Shipping Fee';
+ public const SHIPPING_FEE = 'X1 Freight Service Charge';
- public const OVER_WEIGHT_CHARGES = 'Over weight charges';
+ public const OVER_WEIGHT_CHARGES = 'Overweight Charges';
public const CUSTOM_CHARGES = 'Custom charges';
}
diff --git a/app/Http/Controllers/Companies/AssignCompanyConnectionToConnectionSegmentController.php b/app/Http/Controllers/Companies/AssignCompanyConnectionToConnectionSegmentController.php
index fab9e692..e22c554f 100644
--- a/app/Http/Controllers/Companies/AssignCompanyConnectionToConnectionSegmentController.php
+++ b/app/Http/Controllers/Companies/AssignCompanyConnectionToConnectionSegmentController.php
@@ -10,7 +10,7 @@ class AssignCompanyConnectionToConnectionSegmentController
{
/**
* @param Request $request
- * @param AssignCompanyToSegmentLogic $logic
+ * @param AssignCompanyConnectionToConnectionSegmentLogic $logic
* @return JsonResponse
*/
public function assign(Request $request, AssignCompanyConnectionToConnectionSegmentLogic $logic): JsonResponse {
diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php
index 8e27ab73..899a9405 100644
--- a/app/Http/Resources/CompanyResource.php
+++ b/app/Http/Resources/CompanyResource.php
@@ -27,6 +27,7 @@ class CompanyResource extends JsonResource
'type' => (int) $this->type,
'business_type' => (int) $this->business_type,
'status' => (int) $this->status,
+ 'segments' => SegmentResource::collection($companyModule->connections()->first()->segments),
'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())),
'employee' => new UserResource($companyModule->employees()->first()),
'company_module' => new CompanyModuleResource($companyModule),
diff --git a/app/Http/Resources/OrderResource.php b/app/Http/Resources/OrderResource.php
index d2c72930..d25ecce9 100644
--- a/app/Http/Resources/OrderResource.php
+++ b/app/Http/Resources/OrderResource.php
@@ -29,23 +29,23 @@ class OrderResource extends JsonResource
'warehouse' => new CompanyModuleResource($this->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee),
'address' => new AddressResource($this->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first()),
'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()),
- 'parcels' => $this->whenLoaded('packingLists', function() {
- return [
- 'origin_warehouse_packages' => PackingListResource::collection(
- $this->originWarehousePackages()->get()
- ),
- 'in_transit_packages' => PackingListResource::collection(
- $this->inTransitPackages()->get()
- ),
- 'destination_warehouse_packages' => PackingListResource::collection(
- $this->destinationWarehousePackages()->get()
- ),
- 'delivered_packages' => PackingListResource::collection(
- $this->deliveredPackages()->get()
- ),
- 'received_packages' => PackingListResource::collection($this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('packages')->get()),
- ];
- }),
+// 'parcels' => $this->whenLoaded('packingLists', function() {
+// return [
+// 'origin_warehouse_packages' => PackingListResource::collection(
+// $this->originWarehousePackages()->get()
+// ),
+// 'in_transit_packages' => PackingListResource::collection(
+// $this->inTransitPackages()->get()
+// ),
+// 'destination_warehouse_packages' => PackingListResource::collection(
+// $this->destinationWarehousePackages()->get()
+// ),
+// 'delivered_packages' => PackingListResource::collection(
+// $this->deliveredPackages()->get()
+// ),
+// 'received_packages' => PackingListResource::collection($this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('packages')->get()),
+// ];
+// }),
'remarks' => RemarkResource::collection($this->remarks),
'created_at' => $this->created_at->format('d-m-Y')
];
diff --git a/app/Http/Resources/PackingListResource.php b/app/Http/Resources/PackingListResource.php
index 5256e3de..2c9463e8 100644
--- a/app/Http/Resources/PackingListResource.php
+++ b/app/Http/Resources/PackingListResource.php
@@ -2,11 +2,13 @@
namespace App\Http\Resources;
+use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Models\Order;
use App\Models\PackingList;
+use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
class PackingListResource extends JsonResource
@@ -27,14 +29,17 @@ class PackingListResource extends JsonResource
'claimant_id' => $this->claimant_id,
'reference' => $this->reference,
'status' => $this->status,
- 'transport' => new TransportResource($this->transports()->first()),
+// 'transport' => new TransportResource($this->transports()->first()),
'type' => $this->type,
- 'receive_packing_list' => $this->when($this->type === PackingListType::SHIPPING_PACKING_LIST, new PackingListResource(PackingList::where('reference', $this->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first())),
+// 'receive_packing_list' => $this->when($this->type === PackingListType::SHIPPING_PACKING_LIST, new PackingListResource(PackingList::where('reference', $this->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first())),
'packages' => PackageResource::collection($packages),
$this->mergeWhen($this->owner instanceof Order, [
'order' => New OrderResource($this->owner)
]),
- 'shippng_transaction' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->first()),
+ 'shippng_transaction' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first()),
+ 'suspended_invoice' => new TransactionResource($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first()),
+ // 'suspended_invoices' => TransactionResource::collection($this->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->get()),
+ 'loading_days_ago' => $this->containers()->first()->loading_date->diffForHumans()
];
}
}
diff --git a/database/seeders/SegmentsTableSeeder.php b/database/seeders/SegmentsTableSeeder.php
index 72545884..807441c7 100644
--- a/database/seeders/SegmentsTableSeeder.php
+++ b/database/seeders/SegmentsTableSeeder.php
@@ -15,12 +15,7 @@ class SegmentsTableSeeder extends Seeder
'id' => 1,
'company_module_id' => 1,
'name' => 'Default Segment',
- ],
- [
- 'id' => 2,
- 'company_module_id' => 2,
- 'name' => 'Normal Member',
- ],
+ ]
]
);
}
diff --git a/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue b/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue
index 512fa04d..8b0b6625 100644
--- a/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue
+++ b/resources/assets/vue/components/companies/elements/CustomerProfileComponent.vue
@@ -30,6 +30,32 @@
+
{{item.receive_packing_list.transport.drop_date}}
+{{item.loading_days_ago}}
Container Reference
-Due Date