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
YudhistiraA committed Feb 20, 2025
2 parents ab11f06 + 8c9addd commit 402cb02
Show file tree
Hide file tree
Showing 26 changed files with 274 additions and 95 deletions.
47 changes: 43 additions & 4 deletions app/Actions/Accounting/Invoice/UI/IndexInvoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace App\Actions\Accounting\Invoice\UI;

use App\Actions\Accounting\Invoice\WithInvoicesSubNavigation;
use App\Actions\Accounting\InvoiceCategory\UI\ShowInvoiceCategory;
use App\Actions\Accounting\InvoiceCategory\WithInvoiceCategorySubNavigation;
use App\Actions\CRM\Customer\UI\ShowCustomer;
use App\Actions\CRM\Customer\UI\ShowCustomerClient;
use App\Actions\CRM\Customer\UI\WithCustomerSubNavigation;
Expand All @@ -25,6 +27,7 @@
use App\Http\Resources\Accounting\InvoicesResource;
use App\InertiaTable\InertiaTable;
use App\Models\Accounting\Invoice;
use App\Models\Accounting\InvoiceCategory;
use App\Models\Catalogue\Shop;
use App\Models\CRM\Customer;
use App\Models\CRM\WebUser;
Expand All @@ -48,11 +51,13 @@ class IndexInvoices extends OrgAction
use WithFulfilmentCustomerSubNavigation;
use WithCustomerSubNavigation;
use WithInvoicesSubNavigation;
use WithInvoiceCategorySubNavigation;

private Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|Shop $parent;

private Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|InvoiceCategory|Shop $parent;
private string $bucket = '';

public function handle(Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|Shop|Order $parent, $prefix = null): LengthAwarePaginator
public function handle(Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|InvoiceCategory|Shop|Order $parent, $prefix = null): LengthAwarePaginator
{

$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
Expand Down Expand Up @@ -93,6 +98,8 @@ public function handle(Group|Organisation|Fulfilment|Customer|CustomerClient|Ful
$queryBuilder->where('invoices.order_id', $parent->id);
} elseif ($parent instanceof Group) {
$queryBuilder->where('invoices.group_id', $parent->id);
} elseif ($parent instanceof InvoiceCategory) {
$queryBuilder->where('invoices.invoice_category_id', $parent->id);
} else {
abort(422);
}
Expand Down Expand Up @@ -142,7 +149,7 @@ public function handle(Group|Organisation|Fulfilment|Customer|CustomerClient|Ful
->withQueryString();
}

public function tableStructure(Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|Shop|Order $parent, $prefix = null): Closure
public function tableStructure(Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|InvoiceCategory|Shop|Order $parent, $prefix = null): Closure
{
return function (InertiaTable $table) use ($prefix, $parent) {
if ($prefix) {
Expand All @@ -163,6 +170,9 @@ public function tableStructure(Group|Organisation|Fulfilment|Customer|CustomerCl
} elseif ($parent instanceof Group) {
$stats = $parent->orderingStats;
$noResults = __("This group hasn't been invoiced");
} elseif ($parent instanceof InvoiceCategory) {
$stats = $parent->stats;
$noResults = __("This invoice category hasn't been invoiced");
} else {
$stats = $parent->salesStats;
}
Expand Down Expand Up @@ -226,6 +236,8 @@ public function authorize(ActionRequest $request): bool
);
} elseif ($this->parent instanceof Group) {
return $request->user()->authTo("group-overview");
} elseif ($this->parent instanceof InvoiceCategory) {
return $request->user()->authTo("accounting.{$this->organisation->id}.view");
}

return false;
Expand All @@ -252,6 +264,8 @@ public function htmlResponse(LengthAwarePaginator $invoices, ActionRequest $requ
$subNavigation = $this->getFulfilmentCustomerSubNavigation($this->parent, $request);
} elseif ($this->parent instanceof Shop || $this->parent instanceof Fulfilment || $this->parent instanceof Organisation) {
$subNavigation = $this->getInvoicesNavigation($this->parent);
} elseif ($this->parent instanceof InvoiceCategory) {
$subNavigation = $this->getInvoiceCategoryNavigation($this->parent);
}


Expand All @@ -274,7 +288,6 @@ public function htmlResponse(LengthAwarePaginator $invoices, ActionRequest $requ
'icon' => 'fal fa-file-invoice-dollar',
];
$afterTitle = [

'label' => __('invoices')
];
} elseif ($this->parent instanceof CustomerClient) {
Expand All @@ -299,6 +312,14 @@ public function htmlResponse(LengthAwarePaginator $invoices, ActionRequest $requ
'icon' => ['fal', 'fa-user'],
'title' => __('customer')
];
} elseif ($this->parent instanceof InvoiceCategory) {
$iconRight = null;
$model = __('Invoices');
$title = $this->parent->name;
$icon = [
'icon' => ['fal', 'fa-file-invoice-dollar'],
'title' => __('invoice category')
];
}

$routeName = $request->route()->getName();
Expand Down Expand Up @@ -443,6 +464,14 @@ public function inGroup(ActionRequest $request): LengthAwarePaginator
return $this->handle(group());
}

public function inInvoiceCategory(Organisation $organisation, InvoiceCategory $invoiceCategory, ActionRequest $request): LengthAwarePaginator
{
$this->parent = $invoiceCategory;
$this->initialisation($invoiceCategory->organisation, $request)->withTab(InvoicesTabsEnum::values());

return $this->handle($invoiceCategory, InvoicesTabsEnum::INVOICES->value);
}

/** @noinspection PhpUnusedParameterInspection */
public function inFulfilmentCustomer(Organisation $organisation, Fulfilment $fulfilment, FulfilmentCustomer $fulfilmentCustomer, ActionRequest $request): LengthAwarePaginator
{
Expand Down Expand Up @@ -616,6 +645,16 @@ public function getBreadcrumbs(string $routeName, array $routeParameters): array
]
)
),
'grp.org.accounting.invoice-categories.show.invoices.index' =>
array_merge(
ShowInvoiceCategory::make()->getBreadcrumbs($this->parent, $routeName, $routeParameters),
$headCrumb(
[
'name' => $routeName,
'parameters' => $routeParameters
],
)
),

'grp.overview.ordering.invoices.index' =>
array_merge(
Expand Down
14 changes: 11 additions & 3 deletions app/Actions/Accounting/Invoice/UI/IndexRefunds.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use App\Http\Resources\Accounting\InvoicesResource;
use App\InertiaTable\InertiaTable;
use App\Models\Accounting\Invoice;
use App\Models\Accounting\InvoiceCategory;
use App\Models\Catalogue\Shop;
use App\Models\CRM\Customer;
use App\Models\Dropshipping\CustomerClient;
Expand All @@ -46,10 +47,10 @@ class IndexRefunds extends OrgAction
use WithCustomerSubNavigation;
use WithInvoicesSubNavigation;

private Invoice|Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|Shop $parent;
private Invoice|Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|InvoiceCategory|Shop $parent;
private string $bucket;

public function handle(Invoice|Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|Shop|Order $parent, $prefix = null): LengthAwarePaginator
public function handle(Invoice|Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|InvoiceCategory|Shop|Order $parent, $prefix = null): LengthAwarePaginator
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
Expand Down Expand Up @@ -84,6 +85,8 @@ public function handle(Invoice|Group|Organisation|Fulfilment|Customer|CustomerCl
$queryBuilder->where('invoices.group_id', $parent->id);
} elseif ($parent instanceof Invoice) {
$queryBuilder->where('invoices.invoice_id', $parent->id);
} elseif ($parent instanceof InvoiceCategory) {
$queryBuilder->where('invoices.invoice_category_id', $parent->id);
} else {
abort(422);
}
Expand Down Expand Up @@ -133,7 +136,7 @@ public function handle(Invoice|Group|Organisation|Fulfilment|Customer|CustomerCl
->withQueryString();
}

public function tableStructure(Invoice|Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|Shop|Order $parent, $prefix = null): Closure
public function tableStructure(Invoice|Group|Organisation|Fulfilment|Customer|CustomerClient|FulfilmentCustomer|InvoiceCategory|Shop|Order $parent, $prefix = null): Closure
{
return function (InertiaTable $table) use ($prefix, $parent) {
if ($prefix) {
Expand All @@ -156,6 +159,9 @@ public function tableStructure(Invoice|Group|Organisation|Fulfilment|Customer|Cu
} elseif ($parent instanceof Group) {
$stats = $parent->orderingStats;
$noResults = __("This group hasn't been invoiced");
} elseif ($parent instanceof InvoiceCategory) {
$stats = $parent->stats;
$noResults = __("This invoice category hasn't been invoiced");
} else {
$stats = $parent->salesStats;
}
Expand Down Expand Up @@ -220,6 +226,8 @@ public function authorize(ActionRequest $request): bool
return $request->user()->authTo("fulfilment-shop.{$this->fulfilment->id}.view");
} elseif ($this->parent instanceof Group) {
return $request->user()->authTo("group-overview");
} elseif ($this->parent instanceof InvoiceCategory) {
return $request->user()->authTo("accounting.{$this->organisation->id}.view");
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function handle(Organisation $parent, $prefix = null): LengthAwarePaginat
'invoice_category_stats.number_invoices_type_invoice as number_type_invoices',
'invoice_category_stats.number_invoices_type_refund as number_type_refunds',
])
->allowedSorts(['name', 'state', 'number_type_invoices', 'amount', 'number_type_refunds'])
->allowedSorts(['name', 'id' ,'state', 'number_type_invoices', 'amount', 'number_type_refunds'])
->allowedFilters([$globalSearch])
->withPaginator($prefix, tableName: request()->route()->getName())
->withQueryString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function htmlResponse(InvoiceCategory $invoiceCategory, ActionRequest $re
'subNavigation' => $this->getInvoiceCategoryNavigation($invoiceCategory),
'model' => __('Invoice Category'),
'icon' => [
'icon' => ['fal', 'fa-money-check-alt'],
'icon' => ['fal', 'fa-sitemap'],
'title' => __('invoice category')
],
'title' => $invoiceCategory->name,
Expand Down Expand Up @@ -144,6 +144,26 @@ public function getBreadcrumbs(InvoiceCategory $invoiceCategory, string $routeNa
$suffix
),
),
'grp.org.accounting.invoice-categories.show.invoices.index' => array_merge(
ShowAccountingDashboard::make()->getBreadcrumbs(
'grp.org.accounting.dashboard',
Arr::only($routeParameters, ['organisation'])
),
$headCrumb(
$invoiceCategory,
[
'index' => [
'name' => 'grp.org.accounting.invoice-categories.index',
'parameters' => Arr::only($routeParameters, ['organisation'])
],
'model' => [
'name' => 'grp.org.accounting.invoice-categories.show',
'parameters' => Arr::only($routeParameters, ['organisation', 'invoiceCategory'])
]
],
$suffix
),
),
default => []
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ protected function getInvoiceCategoryNavigation(InvoiceCategory $invoiceCategory
],
],
],
[
"label" => __('Invoices'),
"route" => [
"name" => 'grp.org.accounting.invoice-categories.show.invoices.index',
"parameters" => [
'organisation' => $invoiceCategory->organisation->slug,
'invoiceCategory' => $invoiceCategory->slug
],
],
'leftIcon' => [
'icon' => ['fal', 'fa-file-invoice-dollar'],
'tooltip' => __('Invoices')
]
],

// [
// "number" => $numberUnpaid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function handle(Group|Mailshot|Outbox|PostRoom|Organisation|Shop $parent,
{
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
$query->orWhereWith('dispatched_emails.email_address', $value);
$query->orWhereWith('email_addresses.email', $value);
});
});

Expand Down Expand Up @@ -96,7 +96,7 @@ public function handle(Group|Mailshot|Outbox|PostRoom|Organisation|Shop $parent,
$query->where('dispatched_emails.group_id', $parent->id);
}
})
->allowedSorts(['dispatched_emails.state', 'sent_at' ,'dispatched_emails.number_reads', 'mask_as_spam' ,'dispatched_emails.number_clicks'])
->allowedSorts(['email_address', 'sent_at' ,'number_reads', 'mask_as_spam' ,'number_clicks'])
->allowedFilters([$globalSearch])
->withPaginator($prefix, tableName: request()->route()->getName())
->withQueryString();
Expand Down
7 changes: 4 additions & 3 deletions app/Actions/Comms/Notifications/GetSnsNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
use Aws\Sns\Message;
use Aws\Sns\MessageValidator;
use Illuminate\Support\Arr;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;

class GetSnsNotification
{
use AsAction;

public function asController(): string
public function asController(ActionRequest $request): string
{
$message = Message::fromRawPostData();
$message = new Message($request->all());
$validator = new MessageValidator();

if ($validator->isValid($message)) {
Expand All @@ -44,7 +45,7 @@ public function asController(): string
]
);

ProcessSesNotification::dispatch($sesNotification);
// ProcessSesNotification::dispatch($sesNotification);

}
}
Expand Down
8 changes: 4 additions & 4 deletions app/Actions/Comms/Outbox/UI/ShowOutbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ public function htmlResponse(Outbox $outbox, ActionRequest $request): Response
: Inertia::lazy(fn () => GetOutboxShowcase::run($outbox)),

OutboxTabsEnum::MAILSHOTS->value => $this->tab == OutboxTabsEnum::MAILSHOTS->value ?
fn () => MailshotResource::collection(IndexMailshots::run($outbox))
: Inertia::lazy(fn () => MailshotResource::collection(IndexMailshots::run($outbox))),
fn () => MailshotResource::collection(IndexMailshots::run($outbox, OutboxTabsEnum::MAILSHOTS->value))
: Inertia::lazy(fn () => MailshotResource::collection(IndexMailshots::run($outbox, OutboxTabsEnum::MAILSHOTS->value))),

OutboxTabsEnum::DISPATCHED_EMAILS->value => $this->tab == OutboxTabsEnum::DISPATCHED_EMAILS->value ?
fn () => DispatchedEmailResource::collection(IndexDispatchedEmails::run($outbox))
: Inertia::lazy(fn () => DispatchedEmailResource::collection(IndexDispatchedEmails::run($outbox))),
fn () => DispatchedEmailResource::collection(IndexDispatchedEmails::run($outbox, OutboxTabsEnum::DISPATCHED_EMAILS->value))
: Inertia::lazy(fn () => DispatchedEmailResource::collection(IndexDispatchedEmails::run($outbox, OutboxTabsEnum::DISPATCHED_EMAILS->value))),

// OutboxTabsEnum::EMAIL_BULK_RUNS->value => $this->tab == OutboxTabsEnum::EMAIL_BULK_RUNS->value ?
// fn () => EmailBulkRunsResource::collection(IndexEmailBulkRuns::run($outbox))
Expand Down
38 changes: 22 additions & 16 deletions app/Actions/Comms/SesNotification/ProcessSesNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace App\Actions\Comms\SesNotification;

use App\Actions\Comms\DispatchedEmail\UpdateDispatchedEmail;
use App\Actions\Comms\EmailTrackingEvent\StoreEmailTrackingEvent;
use App\Actions\CRM\Prospect\UpdateProspectEmailClicked;
use App\Actions\CRM\Prospect\UpdateProspectEmailHardBounced;
use App\Actions\CRM\Prospect\UpdateProspectEmailOpened;
Expand Down Expand Up @@ -161,22 +162,27 @@ public function handle(SesNotification $sesNotification): ?array

break;
case 'Click':
$type = DispatchedEmailEventTypeEnum::CLICK;
$date = Arr::get($sesNotification->data, 'click.timestamp');
$data = Arr::only($sesNotification->data['click'], ['ipAddress', 'userAgent', 'link', 'linkTags']);

if ($dispatchedEmail->recipient_type == 'Prospect') {
UpdateProspectEmailClicked::run($dispatchedEmail->recipient, new Carbon($date));
}

UpdateDispatchedEmail::run(
$dispatchedEmail,
[
'state' => DispatchedEmailStateEnum::CLICKED,
'date' => $date,
'is_clicked' => true
]
);
StoreEmailTrackingEvent::make()->action($dispatchedEmail, [
'provider_reference' => $sesNotification->message_id
]);
/* $type = DispatchedEmailEventTypeEnum::CLICK;
$date = Arr::get($sesNotification->data, 'click.timestamp');
$data = Arr::only($sesNotification->data['click'], ['ipAddress', 'userAgent', 'link', 'linkTags']);
if ($dispatchedEmail->recipient_type == 'Prospect') {
UpdateProspectEmailClicked::run($dispatchedEmail->recipient, new Carbon($date));
}*/

// Create storetracking event and call hydrators

/* UpdateDispatchedEmail::run(
$dispatchedEmail,
[
'state' => DispatchedEmailStateEnum::CLICKED,
'date' => $date,
'is_clicked' => true
]
);*/

break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle(PalletDelivery $palletDelivery, $prefix = null): LengthAw
'pallets.pallet_delivery_id',
'pallets.pallet_return_id',
'locations.slug as location_slug',
'locations.slug as location_code',
'locations.code as location_code',
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ public function handle(PalletReturn $palletReturn, $prefix = null): LengthAwareP
});

if ($palletReturn->state !== PalletReturnStateEnum::DISPATCHED) {
$query->where('pallets.status', '!=', PalletStatusEnum::RETURNED);
$query->whereNotIn('pallets.status', [
PalletStatusEnum::RETURNED,
PalletStatusEnum::IN_PROCESS,
PalletStatusEnum::RECEIVING,
PalletStatusEnum::NOT_RECEIVED
]);
} elseif ($palletReturn->state === PalletReturnStateEnum::IN_PROCESS) {
$query->where('pallets.status', PalletStatusEnum::STORING);
}
Expand Down
Loading

0 comments on commit 402cb02

Please sign in to comment.