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 21, 2025
2 parents 1579f36 + 90ef682 commit 5d0dd94
Show file tree
Hide file tree
Showing 156 changed files with 3,542 additions and 1,974 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* Author: Raul Perusquia <raul@inikoo.com>
* Created: Thu, 20 Feb 2025 16:49:23 Central Indonesia Time, Sanur, Bali, Indonesia
* Copyright (c) 2025, Raul A Perusquia Flores
*/

namespace App\Actions\Accounting\Invoice;

use App\Actions\Accounting\InvoiceTransaction\StoreInvoiceTransaction;
use App\Actions\OrgAction;
use App\Models\Accounting\Invoice;
use App\Models\Fulfilment\RecurringBill;

class InvoiceRecurringBillTransactions extends OrgAction
{
public function handle(Invoice $invoice, RecurringBill $recurringBill): Invoice
{
$transactions = $recurringBill->transactions;

foreach ($transactions as $transaction) {
$data = [
'tax_category_id' => $transaction->recurringBill->tax_category_id,
'quantity' => $transaction->quantity * $transaction->temporal_quantity,
'gross_amount' => $transaction->gross_amount,
'net_amount' => $transaction->net_amount,
];
StoreInvoiceTransaction::make()->action($invoice, $transaction->historicAsset, $data);
}

return $invoice;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@ class InvoiceCategoryHydrateOrderingIntervals
use AsAction;
use WithIntervalsAggregators;

public string $jobQueue = 'orders';
public string $jobQueue = 'sales';

private InvoiceCategory $invoicecategory;
private InvoiceCategory $invoiceCategory;

public function __construct(InvoiceCategory $invoicecategory)
public function __construct(InvoiceCategory $invoiceCategory)
{
$this->invoicecategory = $invoicecategory;
$this->invoiceCategory = $invoiceCategory;
}

public function getJobMiddleware(): array
{
return [(new WithoutOverlapping($this->invoicecategory->id))->dontRelease()];
return [(new WithoutOverlapping($this->invoiceCategory->id))->dontRelease()];
}

public function handle(InvoiceCategory $invoiceCategory): void
{

$stats = [];

$queryBase = Invoice::where('invoice_category_id', $invoiceCategory->id)->where('type', InvoiceTypeEnum::INVOICE)->selectRaw('count(*) as sum_aggregate');
Expand All @@ -58,14 +57,6 @@ public function handle(InvoiceCategory $invoiceCategory): void
$invoiceCategory->orderingIntervals->update($stats);
}

public string $commandSignature = 'invoice_category:hydrate_ordering_intervals';

public function asCommand($command)
{
$f = InvoiceCategory::all();
foreach ($f as $key => $value) {
$this->handle($value);
}
}

}
2 changes: 1 addition & 1 deletion app/Actions/Analytics/GetSectionRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function parseGroupSections(string $route, $routeParameters): AikuScopedS
}

if ($routeParameters) {
return AikuScopedSection::where('code', $sectionCode)->where('model_slug', $routeParameters['group'])->first();
return AikuScopedSection::where('code', $sectionCode)->where('model_slug', group()->slug)->first();
} else {
return AikuScopedSection::where('code', $sectionCode)->first();
}
Expand Down
11 changes: 11 additions & 0 deletions app/Actions/Catalogue/Shop/Hydrators/ShopHydrateSales.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,16 @@ public function handle(Shop $shop, ?array $intervals = null, $doPreviousInterval
$shop->salesIntervals()->update($stats);
}

public string $commandSignature = 'test';

public function asCommand($command)
{
$f = Shop::all();
foreach ($f as $fulfilment) {
$this->handle($fulfilment);
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* Author: Artha <artha@aw-advantage.com>
* Created: Thu, 20 Feb 2025 13:37:24 Central Indonesia Time, Sanur, Bali, Indonesia
* Copyright (c) 2025, Raul A Perusquia Flores
*/

namespace App\Actions\Comms\DispatchedEmail\Hydrators;

use App\Actions\Traits\WithEnumStats;
use App\Enums\Comms\EmailTrackingEvent\EmailTrackingEventTypeEnum;
use App\Models\Comms\DispatchedEmail;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Lorisleiva\Actions\Concerns\AsAction;

class DispatchedEmailHydrateEmailTracking
{
use AsAction;
use WithEnumStats;

private DispatchedEmail $dispatchedEmail;

public string $jobQueue = 'low-priority';

public function __construct(DispatchedEmail $dispatchedEmail)
{
$this->dispatchedEmail = $dispatchedEmail;
}

public function getJobMiddleware(): array
{
return [(new WithoutOverlapping($this->dispatchedEmail->id))->dontRelease()];
}


public function handle(DispatchedEmail $dispatchedEmail): void
{
$stats = [
'number_clicks' => $dispatchedEmail
->emailTrackingEvents()
->where('type', EmailTrackingEventTypeEnum::CLICKED)
->count(),
'number_reads' => $dispatchedEmail
->emailTrackingEvents()
->where('type', EmailTrackingEventTypeEnum::OPENED)
->count()
];

$dispatchedEmail->update($stats);
}
}
13 changes: 7 additions & 6 deletions app/Actions/Comms/DispatchedEmail/UI/IndexDispatchedEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function handle(Group|Mailshot|Outbox|PostRoom|Organisation|Shop $parent,
'dispatched_emails.id',
'dispatched_emails.state',
'dispatched_emails.mask_as_spam',
'dispatched_emails.number_email_tracking_events',
'email_addresses.email as email_address',
'dispatched_emails.sent_at as sent_at',
'dispatched_emails.number_reads',
Expand Down Expand Up @@ -96,7 +97,7 @@ public function handle(Group|Mailshot|Outbox|PostRoom|Organisation|Shop $parent,
$query->where('dispatched_emails.group_id', $parent->id);
}
})
->allowedSorts(['email_address', 'sent_at' ,'number_reads', 'mask_as_spam' ,'number_clicks'])
->allowedSorts(['email_address', 'number_email_tracking_events' ,'sent_at' ,'number_reads', 'mask_as_spam' ,'number_clicks'])
->allowedFilters([$globalSearch])
->withPaginator($prefix, tableName: request()->route()->getName())
->withQueryString();
Expand All @@ -114,17 +115,17 @@ public function tableStructure($parent, $prefix = null): Closure

$table
->withGlobalSearch()
->column(key: 'state', label: '', type: 'icon', canBeHidden: false)
->column(key: 'mask_as_spam', label: __('Spam'), type: 'icon', canBeHidden: false, sortable: true);
->column(key: 'state', label: '', type: 'icon', canBeHidden: false);
$table->column(key: 'email_address', label: __('Email'), canBeHidden: false, sortable: true);

$table->column(key: 'sent_at', label: __('Send Date'), canBeHidden: false, sortable: true);
$table->column(key: 'sent_at', label: __('Sent Date'), canBeHidden: false, sortable: true);
if ($parent instanceof Group) {
$table->column(key: 'organisation_name', label: __('organisation'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'shop_name', label: __('shop'), canBeHidden: false, sortable: true, searchable: true);
}
$table->column(key: 'number_reads', label: __('reads'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'number_clicks', label: __('clicks'), canBeHidden: false, sortable: true, searchable: true);
$table->column(key: 'number_email_tracking_events', label: __('events'), canBeHidden: false, sortable: true);
$table->column(key: 'number_reads', label: __('reads'), canBeHidden: false, sortable: true)
->column(key: 'number_clicks', label: __('clicks'), canBeHidden: false, sortable: true);
$table->defaultSort('-sent_at');
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function authorize(ActionRequest $request): bool
public function rules(): array
{
$rules = [
'ses_id' => ['sometimes', 'required', 'string'],
'provider_dispatch_id' => ['sometimes', 'required', 'string'],
'state' => ['sometimes', 'required', Rule::enum(DispatchedEmailStateEnum::class)]
];
if (!$this->strict) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class EmailBulkRunHydrateCumulativeDispatchedEmails

private EmailBulkRun $emailBulkRun;

public string $jobQueue = 'low-priority';

public function __construct(EmailBulkRun $emailBulkRun)
{
$this->emailBulkRun = $emailBulkRun;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class EmailBulkRunHydrateDispatchedEmails

private EmailBulkRun $emailBulkRun;

public string $jobQueue = 'low-priority';

public function __construct(EmailBulkRun $emailBulkRun)
{
$this->emailBulkRun = $emailBulkRun;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* Author: Raul Perusquia <raul@inikoo.com>
* Created: Tue, 19 Nov 2024 11:09:35 Central Indonesia Time, Sanur, Bali, Indonesia
* Copyright (c) 2024, Raul A Perusquia Flores
*/

namespace App\Actions\Comms\EmailTrackingEvent;

use App\Actions\OrgAction;
use App\Actions\Traits\Rules\WithNoStrictRules;
use App\Actions\Traits\WithActionUpdate;
use App\Models\Comms\EmailTrackingEvent;
use hisorange\BrowserDetect\Parser as Browser;
use Illuminate\Support\Arr;

class PostProcessingEmailTrackingEvent extends OrgAction
{
use WithNoStrictRules;
use WithActionUpdate;

public function handle(EmailTrackingEvent $emailTrackingEvent): EmailTrackingEvent
{
$parsedUserAgent = (new Browser())->parse(Arr::get($emailTrackingEvent->data, 'userAgent'));

$ip = Arr::get($emailTrackingEvent->data, 'ipAddress');
$device = $parsedUserAgent->deviceType();

return $this->update($emailTrackingEvent, [
'ip' => $ip,
'device' => $device,
'data' => (object) []
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace App\Actions\Comms\EmailTrackingEvent;

use App\Actions\Comms\DispatchedEmail\Hydrators\DispatchedEmailHydrateEmailTracking;
use App\Actions\OrgAction;
use App\Actions\Traits\Rules\WithNoStrictRules;
use App\Enums\Comms\EmailTrackingEvent\EmailTrackingEventTypeEnum;
Expand All @@ -27,13 +28,14 @@ public function handle(DispatchedEmail $dispatchedEmail, array $modelData): Emai
/** @var EmailTrackingEvent $emailTrackingEvent */
$emailTrackingEvent = $dispatchedEmail->emailTrackingEvents()->create($modelData);

DispatchedEmailHydrateEmailTracking::dispatch($dispatchedEmail);

return $emailTrackingEvent;
}

public function rules(): array
{
$rules = [
'provider_reference' => ['sometimes', 'nullable', 'string', 'max:64'],
'type' => ['required', Rule::enum(EmailTrackingEventTypeEnum::class)],
'data' => ['sometimes', 'array']
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class MailshotHydrateCumulativeDispatchedEmails

private Mailshot $mailshot;

public string $jobQueue = 'low-priority';

public function __construct(Mailshot $mailshot)
{
$this->mailshot = $mailshot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class MailshotHydrateDispatchedEmails

private Mailshot $mailshot;

public string $jobQueue = 'low-priority';

public function __construct(Mailshot $mailshot)
{
$this->mailshot = $mailshot;
Expand Down
3 changes: 1 addition & 2 deletions app/Actions/Comms/Notifications/GetSnsNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function asController(ServerRequestInterface $request): string
{
$message = Message::fromPsrRequest($request);
$validator = new MessageValidator();

if ($validator->isValid($message)) {
if ($message['Type'] == 'SubscriptionConfirmation') {
file_get_contents($message['SubscribeURL']);
Expand All @@ -45,7 +44,7 @@ public function asController(ServerRequestInterface $request): string
]
);

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

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class OutboxHydrateEmailBulkRuns

private Outbox $outbox;

public string $jobQueue = 'low-priority';

public function __construct(Outbox $outbox)
{
$this->outbox = $outbox;
Expand Down
Loading

0 comments on commit 5d0dd94

Please sign in to comment.