Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/shipping-portal into development

This commit is contained in:
edmondlang
2022-03-06 10:12:42 +08:00
4 changed files with 27 additions and 15 deletions
@@ -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)
+11
View File
@@ -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
*/
@@ -3,6 +3,7 @@
<div class="col-2">
<div v-if="item.order">
<a :href="route('customer.profile', item.order.company_module.marking)">{{item.order.company_module.marking}}</a>/<a :href="route('order.show', item.order.reference)">{{item.order.reference}}</a>
<p v-if="item.receive_packing_list">{{item.receive_packing_list.transport.drop_date}}</p>
</div>
<div v-if="!item.order" class="text-danger">Unclaimed Packing List</div>
</div>
+12 -15
View File
@@ -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 '<h4>List of customers active between <span style="color: green; font-weight: bold">'.\Carbon\Carbon::parse($active_start)->format('d/m/Y'). ' - '.\Carbon\Carbon::parse($active_end)->format('d/m/Y').'</span> & inactive between <span style="color: red; font-weight: bold">'.\Carbon\Carbon::parse($inactive_start)->format('d/m/Y'). ' - '.\Carbon\Carbon::parse($inactive_end)->format('d/m/Y').'</span></h4>';
foreach ($companies as $key => $company){
$connection = $company->inviters()->withPivot('invitee_reference')->first();
$marking = $connection ? $connection->pivot->invitee_reference:'';