Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/inikoo/aiku into main
Browse files Browse the repository at this point in the history
  • Loading branch information
itzArtha committed Feb 19, 2025
2 parents 9132fe2 + b3cf9c1 commit 5226540
Show file tree
Hide file tree
Showing 31 changed files with 1,242 additions and 574 deletions.
25 changes: 12 additions & 13 deletions app/Actions/Accounting/PaymentAccount/HydratePaymentAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@

namespace App\Actions\Accounting\PaymentAccount;

use App\Actions\HydrateModel;
use App\Actions\Accounting\PaymentAccount\Hydrators\PaymentAccountHydratePAS;
use App\Actions\Accounting\PaymentAccount\Hydrators\PaymentAccountHydratePayments;
use App\Actions\Traits\Hydrators\WithHydrateCommand;
use App\Models\Accounting\PaymentAccount;
use Illuminate\Support\Collection;

class HydratePaymentAccount extends HydrateModel
class HydratePaymentAccount
{
public string $commandSignature = 'hydrate:payment_account {slugs?*} {--o|org=*} {--g|group=*} ';

public function handle(PaymentAccount $paymentAccount): void
{
PaymentAccountHydratePayments::run($paymentAccount);
}
use WithHydrateCommand;

public string $commandSignature = 'hydrate:payment_accounts {organisations?*} {--S|shop= shop slug} {--s|slug=} ';

protected function getModel(string $slug): PaymentAccount
public function __construct()
{
return PaymentAccount::where('slug', $slug)->first();
$this->model = PaymentAccount::class;
}

protected function getAllModels(): Collection
public function handle(PaymentAccount $paymentAccount): void
{
return PaymentAccount::withTrashed()->get();
PaymentAccountHydratePayments::run($paymentAccount);
PaymentAccountHydratePAS::run($paymentAccount);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ public function handle(PaymentAccount $paymentAccount): void
$stats,
$this->getEnumStats(
model: 'pas',
field: 'state',
field: 'payment_account_shop.state',
enum: PaymentAccountShopStateEnum::class,
models: PaymentAccountShop::class,
where: function ($q) use ($paymentAccount) {
$q->where('payment_account_id', $paymentAccount->id);
}
},
fieldStatsLabel: 'state'
)
);

Expand Down
50 changes: 27 additions & 23 deletions app/Actions/Accounting/PaymentAccount/UI/IndexPaymentAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Closure;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Inertia\Inertia;
use Inertia\Response;
Expand All @@ -36,6 +37,13 @@ class IndexPaymentAccounts extends OrgAction

public function handle(Group|Shop|Organisation|OrgPaymentServiceProvider $parent, $prefix = null): LengthAwarePaginator
{
$organisation = null;
if ($parent instanceof Organisation) {
$organisation = $parent;
} elseif (!$parent instanceof Group) {
$organisation = $parent->organisation;
}

$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereStartWith('payment_accounts.code', $value)
Expand All @@ -59,18 +67,10 @@ public function handle(Group|Shop|Organisation|OrgPaymentServiceProvider $parent
$queryBuilder->where('payment_accounts.group_id', $parent->id);
}

/*
foreach ($this->elementGroups as $key => $elementGroup) {
$queryBuilder->whereElementGroup(
key: $key,
allowedElements: array_keys($elementGroup['elements']),
engine: $elementGroup['engine'],
prefix: $prefix
);
}
*/

$queryBuilder->leftjoin('organisations', 'payment_accounts.organisation_id', 'organisations.id');
return $queryBuilder

$queryBuilder
->defaultSort('payment_accounts.code')
->select([
'payment_accounts.id as id',
Expand All @@ -82,14 +82,16 @@ public function handle(Group|Shop|Organisation|OrgPaymentServiceProvider $parent
'payment_service_providers.slug as payment_service_provider_slug',
'payment_service_providers.name as payment_service_provider_name',
'payment_service_providers.code as payment_service_provider_code',
'organisations.name as organisation_name',
'organisations.slug as organisation_slug',
'payment_account_stats.number_pas_state_active'
])
->leftJoin('payment_account_shop', 'payment_account_shop.payment_account_id', 'payment_accounts.id')
->leftJoin('payment_account_stats', 'payment_accounts.id', 'payment_account_stats.payment_account_id')
'payment_account_stats.number_pas_state_active',
'org_amount_successfully_paid'
]);
if ($organisation) {
$queryBuilder->addSelect(DB::raw("'{$organisation->currency->code}' AS org_currency_code"));
}

return $queryBuilder->leftJoin('payment_account_stats', 'payment_accounts.id', 'payment_account_stats.payment_account_id')
->leftJoin('payment_service_providers', 'payment_service_provider_id', 'payment_service_providers.id')
->allowedSorts(['code', 'name', 'number_payments','payment_service_provider_code','number_pas_state_active'])
->allowedSorts(['code', 'name', 'number_payments', 'payment_service_provider_code', 'number_pas_state_active', 'org_amount_successfully_paid'])
->allowedFilters([$globalSearch])
->withPaginator($prefix, tableName: request()->route()->getName())
->withQueryString();
Expand Down Expand Up @@ -137,8 +139,10 @@ public function tableStructure(Group|Shop|Organisation|OrgPaymentServiceProvider

$table->column(key: 'number_pas_state_active', label: __('shops'), canBeHidden: false, sortable: true, searchable: true);

$table->column(key: 'number_payments', label: __('payments'), canBeHidden: false, sortable: true, searchable: true)
->defaultSort('code');
$table->column(key: 'number_payments', label: __('payments'), canBeHidden: false, sortable: true, searchable: true);
$table->column(key: 'org_amount_successfully_paid', label: __('amount'), canBeHidden: false, sortable: true, searchable: true);

$table->defaultSort('code');
};
}

Expand Down Expand Up @@ -237,8 +241,8 @@ public function htmlResponse(LengthAwarePaginator $paymentAccounts, ActionReques


],
'shops_list' => ShopResource::collection($shops),
'data' => PaymentAccountsResource::collection($paymentAccounts)
'shops_list' => ShopResource::collection($shops),
'data' => PaymentAccountsResource::collection($paymentAccounts)


]
Expand Down Expand Up @@ -302,7 +306,7 @@ public function getBreadcrumbs(string $routeName, array $routeParameters): array
ShowGroupOverviewHub::make()->getBreadcrumbs(),
$headCrumb(
[
'name' => $routeName,
'name' => $routeName,
'parameters' => $routeParameters
]
)
Expand Down
97 changes: 79 additions & 18 deletions app/Actions/Fulfilment/PalletReturn/UI/IndexPalletReturns.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function authorize(ActionRequest $request): bool
public function asController(Organisation $organisation, Fulfilment $fulfilment, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $fulfilment;
$this->restriction = 'all';
$this->initialisationFromFulfilment($fulfilment, $request)->withTab(PalletReturnsTabsEnum::values());

return $this->handle($fulfilment, PalletReturnsTabsEnum::RETURNS->value);
Expand All @@ -82,6 +83,15 @@ public function inFulfilmentConfirmed(Organisation $organisation, Fulfilment $fu
return $this->handle($fulfilment, PalletReturnsTabsEnum::RETURNS->value);
}

public function inFulfilmentNew(Organisation $organisation, Fulfilment $fulfilment, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $fulfilment;
$this->restriction = 'new';
$this->initialisationFromFulfilment($fulfilment, $request)->withTab(PalletReturnsTabsEnum::values());

return $this->handle($fulfilment, PalletReturnsTabsEnum::RETURNS->value);
}

public function inFulfilmentPicking(Organisation $organisation, Fulfilment $fulfilment, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $fulfilment;
Expand All @@ -100,10 +110,29 @@ public function inFulfilmentPicked(Organisation $organisation, Fulfilment $fulfi
return $this->handle($fulfilment, PalletReturnsTabsEnum::RETURNS->value);
}

public function inFulfilmentDispatched(Organisation $organisation, Fulfilment $fulfilment, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $fulfilment;
$this->restriction = 'dispatched';
$this->initialisationFromFulfilment($fulfilment, $request)->withTab(PalletReturnsTabsEnum::values());

return $this->handle($fulfilment, PalletReturnsTabsEnum::RETURNS->value);
}

public function inFulfilmentCancelled(Organisation $organisation, Fulfilment $fulfilment, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $fulfilment;
$this->restriction = 'cancelled';
$this->initialisationFromFulfilment($fulfilment, $request)->withTab(PalletReturnsTabsEnum::values());

return $this->handle($fulfilment, PalletReturnsTabsEnum::RETURNS->value);
}

/** @noinspection PhpUnusedParameterInspection */
public function inFulfilmentCustomer(Organisation $organisation, Fulfilment $fulfilment, FulfilmentCustomer $fulfilmentCustomer, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $fulfilmentCustomer;
$this->restriction = 'all';
$this->initialisationFromFulfilment($fulfilment, $request)->withTab(PalletReturnsTabsEnum::values());

return $this->handle($fulfilmentCustomer, PalletReturnsTabsEnum::RETURNS->value);
Expand All @@ -113,6 +142,7 @@ public function inFulfilmentCustomer(Organisation $organisation, Fulfilment $ful
public function inWarehouse(Organisation $organisation, Warehouse $warehouse, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $warehouse;
$this->restriction = 'all';
$this->initialisationFromWarehouse($warehouse, $request)->withTab(PalletReturnsTabsEnum::values());

return $this->handle($warehouse, PalletReturnsTabsEnum::RETURNS->value);
Expand Down Expand Up @@ -168,23 +198,37 @@ public function inWarehouseDispatched(Organisation $organisation, Warehouse $war

return $this->handle($warehouse, PalletReturnsTabsEnum::RETURNS->value);
}
/** @noinspection PhpUnusedParameterInspection */
public function inWarehouseCancelled(Organisation $organisation, Warehouse $warehouse, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $warehouse;
$this->restriction = 'cancelled';
$this->initialisationFromWarehouse($warehouse, $request)->withTab(PalletReturnsTabsEnum::values());

return $this->handle($warehouse, PalletReturnsTabsEnum::RETURNS->value);
}

protected function getElementGroups(Organisation|FulfilmentCustomer|Fulfilment|Warehouse|PalletDelivery|PalletReturn|RecurringBill $parent): array
{
$allowedStates = PalletReturnStateEnum::labels(forElements: true);
$countStates = PalletReturnStateEnum::count($parent, forElements: true);

if ($this->restriction === 'new') {
$allowedStates = array_filter($allowedStates, fn($key) => in_array($key, ['in_process', 'submitted', 'confirmed']), ARRAY_FILTER_USE_KEY);
$countStates = array_filter($countStates, fn($key) => in_array($key, ['in_process', 'submitted', 'confirmed']), ARRAY_FILTER_USE_KEY);
} elseif ($this->parent instanceof Warehouse && $this->restriction === 'all') {
$allowedStates = array_filter($allowedStates, fn($key) => !in_array($key, ['in_process', 'submitted']), ARRAY_FILTER_USE_KEY);
$countStates = array_filter($countStates, fn($key) => !in_array($key, ['in_process', 'submitted']), ARRAY_FILTER_USE_KEY);
}

return [
'state' => [
'label' => __('State'),
'elements' => array_merge_recursive(
PalletReturnStateEnum::labels(forElements: true),
PalletReturnStateEnum::count($parent, forElements: true)
),

'elements' => array_merge_recursive($allowedStates, $countStates),
'engine' => function ($query, $elements) {
$query->whereIn('pallet_returns.state', $elements);
}
],


];
}

Expand Down Expand Up @@ -219,14 +263,16 @@ public function handle(Fulfilment|Warehouse|FulfilmentCustomer|RecurringBill $pa
if ($this->type) {
$queryBuilder->where('type', $this->type);
}

foreach ($this->getElementGroups($parent) as $key => $elementGroup) {
$queryBuilder->whereElementGroup(
key: $key,
allowedElements: array_keys($elementGroup['elements']),
engine: $elementGroup['engine'],
prefix: $prefix
);

if($this->restriction == 'all' || $this->restriction == 'new') {
foreach ($this->getElementGroups($parent) as $key => $elementGroup) {
$queryBuilder->whereElementGroup(
key: $key,
allowedElements: array_keys($elementGroup['elements']),
engine: $elementGroup['engine'],
prefix: $prefix
);
}
}

if ($this->restriction) {
Expand All @@ -243,6 +289,15 @@ public function handle(Fulfilment|Warehouse|FulfilmentCustomer|RecurringBill $pa
case 'picked':
$queryBuilder->where('state', PalletReturnStateEnum::PICKED);
break;
case 'dispatched':
$queryBuilder->where('state', PalletReturnStateEnum::DISPATCHED);
break;
case 'cancelled':
$queryBuilder->where('state', PalletReturnStateEnum::CANCEL);
break;
case 'new':
$queryBuilder->whereIn('state', [PalletReturnStateEnum::CONFIRMED, PalletReturnStateEnum::SUBMITTED, PalletReturnStateEnum::IN_PROCESS]);
break;
case 'handling':
$queryBuilder->whereIn(
'state',
Expand All @@ -264,15 +319,16 @@ public function handle(Fulfilment|Warehouse|FulfilmentCustomer|RecurringBill $pa
->withQueryString();
}

public function tableStructure(Fulfilment|Warehouse|FulfilmentCustomer|RecurringBill $parent, ?array $modelOperations = null, $prefix = null): Closure
public function tableStructure(Fulfilment|Warehouse|FulfilmentCustomer|RecurringBill $parent, ?array $modelOperations = null, $prefix = null, string $restriction = 'all'): Closure
{
return function (InertiaTable $table) use ($parent, $modelOperations, $prefix) {
return function (InertiaTable $table) use ($parent, $modelOperations, $prefix, $restriction) {
if ($prefix) {
$table
->name($prefix)
->pageName($prefix.'Page');
}

if($restriction == 'all' || $this->parent instanceof Fulfilment && $restriction == 'new')
foreach ($this->getElementGroups($parent) as $key => $elementGroup) {
$table->elementGroup(
key: $key,
Expand Down Expand Up @@ -426,7 +482,7 @@ public function htmlResponse(LengthAwarePaginator $returns, ActionRequest $reque
: Inertia::lazy(fn () => PalletReturnItemUploadsResource::collection(IndexPalletReturnItemUploads::run($this->parent, PalletReturnsTabsEnum::UPLOADS->value))),

]
)->table($this->tableStructure(parent: $this->parent, prefix: PalletReturnsTabsEnum::RETURNS->value))
)->table($this->tableStructure(parent: $this->parent, prefix: PalletReturnsTabsEnum::RETURNS->value, restriction: $this->restriction))
->table(IndexPalletReturnItemUploads::make()->tableStructure(prefix: PalletReturnsTabsEnum::UPLOADS->value));
}

Expand All @@ -449,6 +505,8 @@ public function getBreadcrumbs(string $routeName, array $routeParameters): array
'grp.org.warehouses.show.dispatching.pallet-returns.index',
'grp.org.warehouses.show.dispatching.pallet-returns.confirmed.index',
'grp.org.warehouses.show.dispatching.pallet-returns.picking.index',
'grp.org.warehouses.show.dispatching.pallet-returns.dispatched.index',
'grp.org.warehouses.show.dispatching.pallet-returns.cancelled.index',
'grp.org.warehouses.show.dispatching.pallet-returns.picked.index' => array_merge(
ShowWarehouse::make()->getBreadcrumbs(
$routeParameters
Expand All @@ -475,6 +533,9 @@ public function getBreadcrumbs(string $routeName, array $routeParameters): array
'grp.org.fulfilments.show.operations.pallet-returns.index',
'grp.org.fulfilments.show.operations.pallet-returns.confirmed.index',
'grp.org.fulfilments.show.operations.pallet-returns.picking.index',
'grp.org.fulfilments.show.operations.pallet-returns.dispatched.index',
'grp.org.fulfilments.show.operations.pallet-returns.cancelled.index',
'grp.org.fulfilments.show.operations.pallet-returns.new.index',
'grp.org.fulfilments.show.operations.pallet-returns.picked.index' => array_merge(
ShowFulfilment::make()->getBreadcrumbs(
$routeParameters
Expand Down
Loading

0 comments on commit 5226540

Please sign in to comment.