diff --git a/app/Http/Resources/PackingListResource.php b/app/Http/Resources/PackingListResource.php
index 38c568e7..82065b18 100644
--- a/app/Http/Resources/PackingListResource.php
+++ b/app/Http/Resources/PackingListResource.php
@@ -2,8 +2,10 @@
namespace App\Http\Resources;
+use App\Classes\ValueObjects\Constants\PackingListType;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Models\Order;
+use App\Models\PackingList;
use Illuminate\Http\Resources\Json\JsonResource;
class PackingListResource extends JsonResource
@@ -26,6 +28,7 @@ class PackingListResource extends JsonResource
'status' => $this->status,
'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())),
'packages' => PackageResource::collection($packages),
$this->mergeWhen($this->owner instanceof Order, [
'order' => New OrderResource($this->owner)
diff --git a/app/Models/CompanyModule.php b/app/Models/CompanyModule.php
index b0058389..180d8286 100644
--- a/app/Models/CompanyModule.php
+++ b/app/Models/CompanyModule.php
@@ -21,6 +21,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use PhpParser\Node\Expr\AssignOp\Mod;
+use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
+use Staudenmeir\EloquentHasManyDeep\HasRelationships;
/**
* Class CompanyModule
@@ -32,6 +34,7 @@ use PhpParser\Node\Expr\AssignOp\Mod;
*/
class CompanyModule extends AbstractModel implements Addressable, Documentable, Contactable, ContainerOwner, Packable
{
+ use HasRelationships;
use SoftDeletes;
protected $table = 'company_modules';
@@ -70,6 +73,14 @@ class CompanyModule extends AbstractModel implements Addressable, Documentable,
return $this->morphMany(PackingList::class, 'owner');
}
+ /**
+ * @return hasManyDeep
+ */
+ public function orderPackingLists(): hasManyDeep
+ {
+ return $this->hasManyDeep(PackingList::class, [Order::class], ['company_module_id', ['owner_type', 'owner_id']], ['id', null]);
+ }
+
/**
* @return belongsToMany
*/
diff --git a/resources/assets/vue/components/containers/elements/PackingListComponent.vue b/resources/assets/vue/components/containers/elements/PackingListComponent.vue
index d1b37139..078fd100 100644
--- a/resources/assets/vue/components/containers/elements/PackingListComponent.vue
+++ b/resources/assets/vue/components/containers/elements/PackingListComponent.vue
@@ -3,6 +3,7 @@
diff --git a/routes/web.php b/routes/web.php
index cb0db698..4c3077fe 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -239,23 +239,20 @@ Route::get('/settings', function () {
return view('pages.settings');
})->name('settings');
-Route::get('/customers/active/{active_start}/{active_end}/{?inactive_start}/{?inactive_end}', function ($active_start, $active_end, $inactive_start, $inactive_end) {
- $companies = CompanyModule::where('type', \App\Classes\ValueObjects\Constants\BusinessType::IMPORTER)->whereHas('orders', function($query) use($active_start, $active_end, $inactive_start, $inactive_end){
- return $query->whereHas('packingLists', function($query) use($active_start, $active_end){
- return $query->where('type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function($query) use($active_start, $active_end){
- return $query->whereHas('schedules', function($query) use($active_start, $active_end){
- return $query->where('eta', '>=', \Carbon\Carbon::parse($active_start))->where('eta', '<=', \Carbon\Carbon::parse($active_end)->addDay());
- });
- });
- })->whereDoesntHave('packingLists', function($query) use($inactive_start, $inactive_end){
- return $query->where('type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function($query) use($inactive_start, $inactive_end){
- return $query->whereDoesntHave('schedules', function($query) use($inactive_start, $inactive_end){
- return $query->where('eta', '>=', \Carbon\Carbon::parse($inactive_start))->where('eta', '<=', \Carbon\Carbon::parse($inactive_end)->addDay());
- });
- });
+Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{inactive_end?}', function ($active_start, $active_end, $inactive_start=null, $inactive_end=null) {
+ $activeCompanies = CompanyModule::where('type', \App\Classes\ValueObjects\Constants\BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($inactive_start, $inactive_end) {
+ return $query->where('packing_lists.type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) {
+ return $query->where('drop_date', '>=', \Carbon\Carbon::parse($inactive_start))->where('drop_date', '<=', \Carbon\Carbon::parse($inactive_end)->addDay());
});
- })->get();
+ })->pluck('id');
+ $companies = CompanyModule::where('type', \App\Classes\ValueObjects\Constants\BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($active_start, $active_end) {
+ return $query->where('packing_lists.type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($active_start, $active_end) {
+ return $query->whereDate('drop_date', '>=', \Carbon\Carbon::parse($active_start))->whereDate('drop_date', '<=', \Carbon\Carbon::parse($active_end)->addDay());
+ });
+ })->whereNotIn('id', $activeCompanies)->get();
+
+ echo 'List of customers active between '.\Carbon\Carbon::parse($active_start)->format('d/m/Y'). ' - '.\Carbon\Carbon::parse($active_end)->format('d/m/Y').' & inactive between '.\Carbon\Carbon::parse($inactive_start)->format('d/m/Y'). ' - '.\Carbon\Carbon::parse($inactive_end)->format('d/m/Y').'
';
foreach ($companies as $key => $company){
$connection = $company->inviters()->withPivot('invitee_reference')->first();
$marking = $connection ? $connection->pivot->invitee_reference:'';