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 6, 2025
2 parents fade7dc + a779094 commit bd6ed0c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
6 changes: 4 additions & 2 deletions app/Actions/Fulfilment/StoredItem/UI/IndexStoredItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(Group|Organisation|FulfilmentCustomer|Fulfilment $parent,
$query->where('stored_items.group_id', $parent->id);
}
})
->allowedSorts(['slug', 'state'])
->allowedSorts(['slug', 'state', 'total_quantity', 'name'])
->allowedFilters([$globalSearch, 'slug', 'state'])
->withPaginator($prefix, tableName: request()->route()->getName())
->withQueryString();
Expand Down Expand Up @@ -104,8 +104,10 @@ public function tableStructure($parent, ?array $modelOperations = null, $prefix
)
->column(key: 'state', label: '', canBeHidden: false, sortable: false, searchable: false, type: 'icon')
->column(key: 'reference', label: __('reference'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'name', label: __('name'), canBeHidden: false, sortable: true)
->column(key: 'customer_name', label: __('Customer Name'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'pallets', label: __("Pallets"), canBeHidden: false);
->column(key: 'pallets', label: __("Pallets"), canBeHidden: false)
->column(key: 'total_quantity', label: __("Quantity"), canBeHidden: false, sortable: true);
if (class_basename($parent) == 'Group') {
$table->column(key: 'organisation_name', label: __('Organisation'), canBeHidden: false, sortable: true, searchable: true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,24 @@ public function handle(): void
$this->fixPalletDeliveryRecurringBill();
$this->fixPalletDeliveryTransactionsRecurringBill();

print "palletsStartDate\n";
$this->palletsStartDate();
print "palletsEndDate\n";
$this->palletsEndDate();


print "palletsValidateStartEndDate x\n";
$this->palletsValidateStartEndDate();

$this->fixPalletReturnRecurringBill();
print "fixPalletReturnTransactionsRecurringBill\n";

$this->fixPalletReturnTransactionsRecurringBill();

print "fixNonRentalRecurringBillTransactions\n";
$this->fixNonRentalRecurringBillTransactions();


print "last fix\n";
/** @var RecurringBill $recurringBill */
foreach (RecurringBill::where('status', RecurringBillStatusEnum::CURRENT)->get() as $recurringBill) {
$transactions = $recurringBill->transactions()->get();
Expand All @@ -60,10 +71,11 @@ public function handle(): void
CalculateRecurringBillTransactionCurrencyExchangeRates::run($transaction);
}

CalculateRecurringBillTotals::make()->action($recurringBill);
CalculateRecurringBillTotals::dispatch($recurringBill);
}
}


public function palletsValidateStartEndDate(): void
{
/** @var RecurringBill $recurringBill */
Expand Down Expand Up @@ -160,19 +172,20 @@ public function palletsEndDate(): void
print 'PED: '.$transaction->id.' add end day '.$pallet->dispatched_at->format('Y-m-d')."\n";
$transaction->update(['end_date' => $pallet->dispatched_at]);
} else {
$currentEndDay = $transaction->end_date->startOfDay();
$originalStartDate = $currentEndDay;
$currentEndDay = $transaction->end_date->startOfDay();
$originalEndDate = $currentEndDay;
if ($pallet->dispatched_at->startOfDay()->ne($currentEndDay)) {
$currentEndDay = $pallet->dispatched_at->startOfDay();
}

if ($originalStartDate->ne($currentEndDay)) {
print 'PED: '.$transaction->id.' '.$originalStartDate->format('Y-m-d').' -> '.$currentEndDay->format('Y-m-d')."\n";
if ($originalEndDate->ne($currentEndDay)) {
print 'PEDx: '.$transaction->id.' '.$originalEndDate->format('Y-m-d').' -> '.$currentEndDay->format('Y-m-d')."\n";
$transaction->update(['end_date' => $pallet->dispatched_at]);
}
}
} elseif ($transaction->end_date) {
print 'PED: '.$transaction->id.' remove end day '.$transaction->end_date->format('Y-m-d')."\n";
$transaction->update(['end_date' => null]);
// print 'PED: '.$transaction->id.' remove end day '.$transaction->end_date->format('Y-m-d')."\n";
$transaction->update(['end_date' => $recurringBill->end_date]);
}
}
}
Expand Down Expand Up @@ -271,20 +284,6 @@ public function fixPalletDeliveryRecurringBill(): void
}
}

public function fixPalletReturnRecurringBill(): void
{
$palletReturns = PalletReturn::whereNull('recurring_bill_id')->get();
/** @var PalletReturn $palletReturn */
foreach ($palletReturns as $palletReturn) {
if ($receivedDate = $palletReturn->dispatched_at and $palletReturn->fulfilmentCustomer->currentRecurringBill) {
$currentRecurringBill = $palletReturn->fulfilmentCustomer->currentRecurringBill;
if ($receivedDate->isAfter($currentRecurringBill->start_date)) {
print "Fix Pallet Return CRB: $palletReturn->id\n";
$palletReturn->update(['recurring_bill_id' => $currentRecurringBill->id]);
}
}
}
}

public function getCommandSignature(): string
{
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/Fulfilment/StoredItemResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function toArray($request): array
'state_icon' => $storedItem->state->stateIcon()[$storedItem->state->value],
'quantity' => (int) $storedItem->pallets?->sum('pivot.quantity'),
'total_quantity' => $storedItem->pallets?->sum('pivot.quantity'),
'name' => $storedItem->name,
'max_quantity' => $storedItem->pallets?->sum('pivot.quantity'),

'pallets' => $storedItem->pallets->map(fn (Pallet $pallet) => [
Expand Down

0 comments on commit bd6ed0c

Please sign in to comment.