Files
shipping-portal/app/Library/helper.php
T
Martin Kiragu 9217970237 update helpers
2023-03-19 04:38:24 +03:00

50 lines
2.0 KiB
PHP

<?php
//global helpers functions here
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Models\Company;
use App\Models\CompanyModule;
use Carbon\Carbon;
/**
* Get Active companies
* TODO add extract BusinessType::IMPORTER to a $businessType parameter
* @param $inactive_start
* @param $inactive_end
* @param $active_start
* @param $active_end
* @return mixed
*/
if (!function_exists('getActiveCompanies')) {
function getActiveCompanies($inactive_start, $inactive_end, $active_start, $active_end)
{
$activeCompanies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function ($query) use ($inactive_start, $inactive_end) {
return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) {
return $query->where('drop_date', '>=', Carbon::parse($inactive_start))->where('drop_date', '<=', Carbon::parse($inactive_end)->addDay());
});
})->pluck('id');
return CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function ($query) use ($active_start, $active_end) {
return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($active_start, $active_end) {
return $query->whereDate('drop_date', '>=', Carbon::parse($active_start))->whereDate('drop_date', '<=', Carbon::parse($active_end)->addDay());
});
})->whereNotIn('id', $activeCompanies)->get();
}
}
/**
*
* Get Packing List
* TODO change all packing related query to this
* @param Company $company
* @return mixed
*/
if (!function_exists('getPackingList')) {
function getPackingList(Company $company)
{
return $company->orderPackingLists()->where('packing_lists.type', PackingListType::SHIPPING_PACKING_LIST)->get();
}
}