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 20, 2025
2 parents 31aab52 + 252519a commit 9369bc8
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 52 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 @@ -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
48 changes: 30 additions & 18 deletions app/Imports/SupplyChain/SupplierProductImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace App\Imports\SupplyChain;

use App\Actions\SupplyChain\SupplierProduct\StoreSupplierProduct;
use App\Actions\SupplyChain\SupplierProduct\UpdateSupplierProduct;
use App\Imports\WithImport;
use App\Models\Helpers\Upload;
use App\Models\SupplyChain\Supplier;
Expand All @@ -35,33 +36,44 @@ public function __construct(Supplier $supplier, Upload $upload)
public function storeModel($row, $uploadRecord): void
{
$sanitizedData = $this->processExcelData([$row]);
$fields =
array_merge(
array_keys(
$this->rules()
)
);

if ($sanitizedData['availability'] == 'Available') {
$validatedData = array_intersect_key($sanitizedData, array_flip(array_keys($this->rules())));

if ($validatedData['availability'] == 'Available') {
$availability = true;
} else {
$availability = false;
}

$modelData = [
'code' => $sanitizedData['suppliers_product_code'],
'name' => $sanitizedData['suppliers_unit_description'],
'code' => $validatedData['suppliers_product_code'],
'name' => $validatedData['suppliers_unit_description'],
'is_available' => $availability,
'cost' => $sanitizedData['unit_cost'],
'units_per_pack' => $sanitizedData['units_per_sko'],
'units_per_carton' => $sanitizedData['skos_per_carton'],
'cbm' => $sanitizedData['carton_cbm'],
'cost' => $validatedData['unit_cost'],
'units_per_pack' => $validatedData['units_per_sko'],
'units_per_carton' => $validatedData['skos_per_carton'],
'cbm' => $validatedData['carton_cbm'],
];

try {
StoreSupplierProduct::run(
$this->scope,
$modelData
);
$partKey = $validatedData['id_supplier_part_key'];
$existingProduct = null;
if (is_numeric($partKey)) {
$partKey = (int) $partKey;
$existingProduct = $this->scope->supplierProducts()
->where('id', $partKey)
->first();
}

$isNew = is_string($validatedData['id_supplier_part_key'])
&& strtolower($validatedData['id_supplier_part_key']) === 'new';

if ($existingProduct) {
UpdateSupplierProduct::run($existingProduct, $modelData);
} elseif ($isNew) {
StoreSupplierProduct::run($this->scope, $modelData);
} else {
throw new Exception("Part key not found");
}

$this->setRecordAsCompleted($uploadRecord);
} catch (Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function invoiceRoute(invoiceCategory: {}) {
switch (route().current()) {
case "grp.org.accounting.invoice-categories.index":
return route(
"grp.org.accounting.invoices.index",
[route().params["organisation"]])
"grp.org.accounting.invoice-categories.show.invoices.index",
[route().params["organisation"],invoiceCategory.slug])
default:
return ''
}
Expand All @@ -47,9 +47,13 @@ function invoiceRoute(invoiceCategory: {}) {
function refundRoute(invoiceCategory: {}) {
switch (route().current()) {
case "grp.org.accounting.invoice-categories.index":
return route(
"grp.org.accounting.refunds.index",
[route().params["organisation"]])
return route(
"grp.org.accounting.invoice-categories.show.invoices.index",
{
"organisation": route().params["organisation"],
"invoiceCategory": invoiceCategory.slug,
'tab': 'refunds'
})
default:
return ''
}
Expand Down
Loading

0 comments on commit 9369bc8

Please sign in to comment.