Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/inikoo/aiku
Browse files Browse the repository at this point in the history
  • Loading branch information
YudhistiraA committed Feb 24, 2025
2 parents 6f55f86 + 05d7850 commit 3b5d279
Show file tree
Hide file tree
Showing 152 changed files with 6,284 additions and 2,688 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ frankenphp
frankenphp-worker.php
rr
/.rr.yaml
/maya/private/
10 changes: 9 additions & 1 deletion app/Actions/Accounting/Invoice/DeleteInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
namespace App\Actions\Accounting\Invoice;

use App\Actions\CRM\Customer\Hydrators\CustomerHydrateInvoices;
use App\Actions\OrgAction;
use App\Actions\Traits\WithActionUpdate;
use App\Models\Accounting\Invoice;

class DeleteInvoice
class DeleteInvoice extends OrgAction
{
use WithActionUpdate;

Expand All @@ -26,4 +27,11 @@ public function handle(

return $this->update($invoice, $modelData, ['data']);
}

public function action(Invoice $invoice, array $modelData): Invoice
{
$this->initialisation($invoice->organisation, $modelData);

return $this->handle($invoice, $this->validatedData);
}
}
5 changes: 5 additions & 0 deletions app/Actions/Accounting/Invoice/DestroyRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace App\Actions\Accounting\Invoice;

use App\Actions\CRM\Customer\Hydrators\CustomerHydrateInvoices;
use App\Actions\OrgAction;
use App\Models\Accounting\Invoice;
use Illuminate\Support\Facades\DB;
Expand All @@ -19,6 +20,10 @@ public function handle(Invoice $invoice, array $modelData): void
DB::transaction(function () use ($invoice) {
$invoice->invoiceTransactions()->forceDelete();
$invoice->forceDelete();

if ($invoice->customer_id) {
CustomerHydrateInvoices::dispatch($invoice->customer);
}
});
}

Expand Down
5 changes: 5 additions & 0 deletions app/Actions/Accounting/Invoice/StoreRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace App\Actions\Accounting\Invoice;

use App\Actions\CRM\Customer\Hydrators\CustomerHydrateInvoices;
use App\Actions\OrgAction;
use App\Actions\Traits\Rules\WithNoStrictRules;
use App\Actions\Traits\WithFixedAddressActions;
Expand Down Expand Up @@ -59,6 +60,10 @@ public function handle(Invoice $invoice, array $modelData): Invoice
$refund = $invoice->refunds()->create($modelData);
$refund->stats()->create();

if ($refund->customer_id) {
CustomerHydrateInvoices::dispatch($refund->customer)->delay($this->hydratorsDelay);
}

return $refund;
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Accounting/Invoice/UI/IndexRefunds.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function authorize(ActionRequest $request): bool
if ($this->parent instanceof Organisation) {
return $request->user()->authTo("accounting.{$this->organisation->id}.view");
} elseif ($this->parent instanceof Customer or $this->parent instanceof CustomerClient) {
return $request->user()->authTo("crm.{$this->organisation->id}.view");
return $request->user()->authTo("crm.{$this->shop->id}.view");
} elseif ($this->parent instanceof Shop) {
return $request->user()->authTo("orders.{$this->shop->id}.view");
} elseif ($this->parent instanceof FulfilmentCustomer or $this->parent instanceof Fulfilment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ class GetOrgPaymentServiceProviderShowcase

public function handle(OrgPaymentServiceProvider $orgPaymentServiceProvider): array
{
// dd($orgPaymentServiceProvider);
return [
[

]
'type' => $orgPaymentServiceProvider->type,
'slug' => $orgPaymentServiceProvider->slug,
'code' => $orgPaymentServiceProvider->code,
'created_at' => $orgPaymentServiceProvider->created_at,
'payment_service_provider' => $orgPaymentServiceProvider->paymentServiceProvider,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public function tableStructure($prefix = null): Closure
$table
->withGlobalSearch()
->defaultSort('code')
->column(key: 'adoption', label: '')
->column(key: 'adoption', label: '', type: 'icon')
->column(key: 'logo', label: '')

->column(key: 'code', label: __('code'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'name', label: __('Name'), canBeHidden: false, sortable: true, searchable: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,89 @@

use App\Actions\Accounting\PaymentAccount\Hydrators\PaymentAccountHydratePAS;
use App\Actions\OrgAction;
use App\Actions\Traits\Rules\WithNoStrictRules;
use App\Enums\Accounting\PaymentAccountShop\PaymentAccountShopStateEnum;
use App\Models\Accounting\PaymentAccount;
use App\Models\Accounting\PaymentAccountShop;
use App\Models\Catalogue\Shop;
use Illuminate\Support\Arr;
use Illuminate\Validation\Rule;
use Lorisleiva\Actions\ActionRequest;

class StorePaymentAccountShop extends OrgAction
{
use WithNoStrictRules;

public function handle(PaymentAccount $paymentAccount, Shop $shop, array $modelData): PaymentAccountShop
{
data_set($modelData, 'shop_id', $shop->id);
data_set($modelData, 'type', $paymentAccount->type);

data_set($modelData, 'currency_id', $shop->currency_id, overwrite: false);

$paymentAccountShop = $paymentAccount->paymentAccountShops()->create($modelData);
if (Arr::has($modelData, 'state') && $modelData['state'] == PaymentAccountShopStateEnum::ACTIVE) {
data_set($modelData, 'activated_at', now(), overwrite: false);
data_set($modelData, 'last_activated_at', now(), overwrite: false);
}

PaymentAccountHydratePAS::dispatch($paymentAccount);
/** @var PaymentAccountShop $paymentAccountShop */
$paymentAccountShop = $paymentAccount->paymentAccountShops()->create($modelData);
PaymentAccountHydratePAS::dispatch($paymentAccount)->delay($this->hydratorsDelay);

return $paymentAccountShop;
}

public function rules(): array
{
return [
'state' => [
$rules = [
'state' => [
'required',
Rule::enum(PaymentAccountShopStateEnum::class)
],
'currency_id' => [
'currency_id' => [
'sometimes',
'required',
Rule::Exists('currencies', 'id')
]
],
'show_in_checkout' => ['sometimes', 'boolean'],
'checkout_display_position' => ['sometimes', 'numeric'],
'data' => ['sometimes', 'array']
];

if (!$this->strict) {
$rules = $this->noStrictStoreRules($rules);
$rules['activated_at'] = ['sometimes', 'date'];
$rules['last_activated_at'] = ['sometimes', 'date'];
}

return $rules;
}

public function prepareForValidation(): void
{
if ($this->has('checkout_display_position')) {
$checkoutDisplayPosition = $this->shop->paymentAccountShops()->max('checkout_display_position') + 10;
$this->set('checkout_display_position', $checkoutDisplayPosition);
}
}

public function asController(PaymentAccount $paymentAccount, Shop $shop, ActionRequest $request): PaymentAccountShop
{
$this->initialisation($paymentAccount->organisation, $request);
$this->initialisationFromShop($shop, $request);

return $this->handle($paymentAccount, $shop, $this->validateAttributes());
}

public function action(PaymentAccount $paymentAccount, Shop $shop, array $modelData): PaymentAccountShop
public function action(PaymentAccount $paymentAccount, Shop $shop, array $modelData, int $hydratorsDelay = 0, bool $strict = true, $audit = true): PaymentAccountShop
{
$this->asAction = true;
$this->initialisation($paymentAccount->organisation, $modelData);
if (!$audit) {
PaymentAccountShop::disableAuditing();
}
$this->asAction = true;
$this->strict = $strict;
$this->hydratorsDelay = $hydratorsDelay;

$this->initialisationFromShop($shop, $modelData);

return $this->handle($paymentAccount, $shop, $this->validateAttributes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use App\Actions\Accounting\PaymentAccount\Hydrators\PaymentAccountHydratePAS;
use App\Actions\OrgAction;
use App\Actions\Traits\Rules\WithNoStrictRules;
use App\Actions\Traits\WithActionUpdate;
use App\Enums\Accounting\PaymentAccountShop\PaymentAccountShopStateEnum;
use App\Models\Accounting\PaymentAccountShop;
Expand All @@ -20,30 +21,41 @@
class UpdatePaymentAccountShop extends OrgAction
{
use WithActionUpdate;
use WithNoStrictRules;

public function handle(PaymentAccountShop $paymentAccountShop, array $modelData): PaymentAccountShop
{
$paymentAccountShop = $this->update($paymentAccountShop, $modelData);


if ($paymentAccountShop->wasChanged('state')) {
PaymentAccountHydratePAS::dispatch($paymentAccountShop->paymentAccount);
PaymentAccountHydratePAS::dispatch($paymentAccountShop->paymentAccount)->delay($this->hydratorsDelay);
}

return $paymentAccountShop;
}

public function rules(): array
{
return [
'state' => [
$rules = [
'state' => [
'sometimes',
Rule::enum(PaymentAccountShopStateEnum::class)
],
'currency_id' => [
'sometimes',
'required',
Rule::Exists('currencies', 'id')
]
'show_in_checkout' => ['sometimes', 'boolean'],
'checkout_display_position' => ['sometimes', 'numeric'],
'data' => ['sometimes', 'array']
];


if (!$this->strict) {
$rules = $this->noStrictUpdateRules($rules);
$rules['currency_id'] = ['sometimes', 'required', Rule::Exists('currencies', 'id')];
$rules['activated_at'] = ['sometimes', 'date'];
$rules['last_activated_at'] = ['sometimes', 'date'];
}

return $rules;
}

public function asController(PaymentAccountShop $paymentAccountShop, ActionRequest $request): PaymentAccountShop
Expand All @@ -53,9 +65,13 @@ public function asController(PaymentAccountShop $paymentAccountShop, ActionReque
return $this->handle($paymentAccountShop, $this->validateAttributes());
}

public function action(PaymentAccountShop $paymentAccountShop, array $modelData): PaymentAccountShop
public function action(PaymentAccountShop $paymentAccountShop, array $modelData, int $hydratorsDelay = 0, bool $strict = true, bool $audit = true): PaymentAccountShop
{
$this->asAction = true;
$this->strict = $strict;
if (!$audit) {
PaymentAccountShop::disableAuditing();
}
$this->hydratorsDelay = $hydratorsDelay;
$this->initialisation($paymentAccountShop->paymentAccount->organisation, $modelData);

return $this->handle($paymentAccountShop, $this->validateAttributes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace App\Actions\CRM\BackInStockReminder\UI;

use App\Actions\OrgAction;
use App\Actions\Traits\Authorisations\WithCRMAuthorisation;
use App\Http\Resources\CRM\CustomerBackInStockRemindersResource;
use App\InertiaTable\InertiaTable;
use App\Models\CRM\BackInStockReminder;
Expand All @@ -18,19 +19,18 @@
use Closure;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Lorisleiva\Actions\ActionRequest;
use Spatie\QueryBuilder\AllowedFilter;

class IndexCustomerBackInStockReminders extends OrgAction
{
private Customer $parent;
use WithCRMAuthorisation;

public function handle(Customer $parent, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->whereStartWith('products.code', $value)
->orWhereAnyWordStartWith('products.name', 'ILIKE', $value);
->orWhereAnyWordStartWith('products.name', $value);
});
});

Expand Down Expand Up @@ -75,10 +75,7 @@ public function tableStructure(Customer $parent, $prefix = null): Closure
}


$stats = $parent->stats;
$noResults = __("Customer has no reminders");


$table
->withGlobalSearch()
->withEmptyState(
Expand All @@ -93,13 +90,6 @@ public function tableStructure(Customer $parent, $prefix = null): Closure
};
}

public function authorize(ActionRequest $request): bool
{

$this->canEdit = $request->user()->authTo("crm.{$this->shop->id}.view");

return $request->user()->authTo("crm.{$this->organisation->id}.view");
}

public function jsonResponse(LengthAwarePaginator $reminders): AnonymousResourceCollection
{
Expand Down
11 changes: 4 additions & 7 deletions app/Actions/CRM/Customer/UI/CreateCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

/*
* Author: Raul Perusquia <raul@inikoo.com>
* Created: Tue, 20 Jun 2023 20:32:25 Malaysia Time, Pantai Lembeng, Bali, Id
* Created: Tue, 20 Jun 2023 20:32:25 Malaysia Time, Pantai Lembeng, Bali, Indonesia
* Copyright (c) 2023, Raul A Perusquia Flores
*/

namespace App\Actions\CRM\Customer\UI;

use App\Actions\Helpers\Country\UI\GetAddressData;
use App\Actions\OrgAction;
use App\Actions\Traits\Authorisations\WithCRMAuthorisation;
use App\Http\Resources\Helpers\AddressFormFieldsResource;
use App\Models\Catalogue\Shop;
use App\Models\Helpers\Address;
Expand All @@ -20,6 +21,8 @@

class CreateCustomer extends OrgAction
{
use WithCRMAuthorisation;

public function handle(Shop $shop, ActionRequest $request): Response
{
return Inertia::render(
Expand Down Expand Up @@ -97,12 +100,6 @@ public function handle(Shop $shop, ActionRequest $request): Response
);
}

public function authorize(ActionRequest $request): bool
{
return $request->user()->authTo("crm.{$this->shop->id}.edit");
}


public function asController(Organisation $organisation, Shop $shop, ActionRequest $request): Response
{
$this->initialisationFromShop($shop, $request);
Expand Down
Loading

0 comments on commit 3b5d279

Please sign in to comment.