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
KirinZero0 committed Feb 24, 2025
2 parents bd14e79 + 28e1db2 commit 05d7850
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 61 deletions.
10 changes: 5 additions & 5 deletions app/Actions/HumanResources/Employee/StoreEmployee.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function handle(Organisation|Workplace $parent, array $modelData): Employ
$organisation = $parent;
}

if(Arr::get($modelData, 'contact_address')) {
if (Arr::get($modelData, 'contact_address')) {
$contactAddressData = Arr::get($modelData, 'contact_address', []);
Arr::forget($modelData, 'contact_address');
}
Expand All @@ -75,11 +75,11 @@ public function handle(Organisation|Workplace $parent, array $modelData): Employ
$employee = $parent->employees()->create($modelData);
$employee->stats()->create();

if($contactAddressData){
if ($contactAddressData) {
$employee = $this->addAddressToModelFromArray(
model: $employee,
addressData: $contactAddressData,
);
model: $employee,
addressData: $contactAddressData,
);
$employee->refresh();
}

Expand Down
1 change: 0 additions & 1 deletion app/Actions/HumanResources/Employee/UI/CreateEmployee.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

class CreateEmployee extends OrgAction
{

public function handle(Organisation $organisation, ActionRequest $request): Response
{
return Inertia::render(
Expand Down
28 changes: 14 additions & 14 deletions app/Actions/Inventory/Location/DownloadLocations.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* author Arya Permana - Kirin
* created on 24-02-2025-13h-09m
Expand All @@ -9,31 +10,30 @@
namespace App\Actions\Inventory\Location;

use App\Actions\OrgAction;
use App\Events\FileDownloadProgress;
use App\Models\Inventory\Warehouse;
use App\Models\Inventory\WarehouseArea;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsController;
use Lorisleiva\Actions\Concerns\WithAttributes;
use App\Models\Inventory\Location;
use App\Models\SysAdmin\Organisation;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Facades\Excel;

class DownloadLocations extends OrgAction
class DownloadLocations extends OrgAction
{
public function handle(Warehouse $warehouse, array $modelData)
public function handle(Warehouse $warehouse, array $modelData): void
{
$fileName = 'locations_warehouse_' . $warehouse->id . '.xlsx';
return Excel::download(new LocationsExport($warehouse, $modelData), $fileName);

Excel::queue(new LocationsExport($warehouse, $modelData), 'public/'.$fileName)->chain([
function () use ($warehouse, $fileName) {
broadcast(new FileDownloadProgress($warehouse->id, 100, $fileName));
}
]);
}

public function asController(Organisation $organisation, Warehouse $warehouse, ActionRequest $request)
public function asController(Organisation $organisation, Warehouse $warehouse, ActionRequest $request): void
{
$this->initialisationFromWarehouse($warehouse, $request);
$columns = explode(',', $request->query('columns', ''));
return $this->handle($warehouse, $columns);

$this->handle($warehouse, $columns);
}
}
}
48 changes: 24 additions & 24 deletions app/Actions/Inventory/Location/LocationsExport.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
<?php
/*
* author Arya Permana - Kirin
* created on 24-02-2025-13h-07m
* github: https://github.com/KirinZero0
* copyright 2025
*/

namespace App\Actions\Inventory\Location;

use App\Actions\OrgAction;
use App\Models\Inventory\Warehouse;
use App\Models\Inventory\WarehouseArea;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsController;
use Lorisleiva\Actions\Concerns\WithAttributes;
use App\Models\Inventory\Location;
use App\Models\SysAdmin\Organisation;
use App\Models\Inventory\Warehouse;
use App\Events\FileDownloadProgress;
use Illuminate\Contracts\Queue\ShouldQueue;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class LocationsExport implements FromQuery, WithMapping, WithHeadings
class LocationsExport implements FromQuery, WithMapping, WithHeadings, ShouldQueue
{
use Exportable;

private Warehouse $warehouse;
private array $columns;

public int $processed = 0;
public int $totalCount = 0;

public function __construct(Warehouse $warehouse, array $columns)
{
$this->warehouse = $warehouse;
$this->columns = $columns;
}


public function map($row): array
{
return collect($this->columns)->map(fn($column) => $row->{$column})->toArray();
{
$this->processed++;

$progress = $this->totalCount > 0
? ($this->processed / $this->totalCount) * 100
: 100;

broadcast(new FileDownloadProgress($this->warehouse->id, (int) $progress));

return collect($this->columns)->map(fn ($col) => $row->{$col} ?? '')->toArray();
}

public function headings(): array
{
return array_map(fn($col) => str_replace('_', ' ', ucfirst($col)), $this->columns);
return array_map(fn ($col) => str_replace('_', ' ', ucfirst($col)), $this->columns);
}

public function query()
{
return Location::query()->where('warehouse_id', $this->warehouse->id);
$query = Location::query()->where('warehouse_id', $this->warehouse->id);
$this->totalCount = $query->count();

return $query;
}
}
}
14 changes: 7 additions & 7 deletions app/Actions/Inventory/Location/UI/IndexLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ public function htmlResponse(LengthAwarePaginator $locations, ActionRequest $req
$container = null;
$export = [];
$columns = collect([
'code',
'status',
'stock_value',
'stock_commercial_value',
'max_weight',
'max_volume',
'code',
'status',
'stock_value',
'stock_commercial_value',
'max_weight',
'max_volume',
'barcode'
])->map(fn($col) => [
])->map(fn ($col) => [
'label' => __(str_replace('_', ' ', ucfirst($col))), // Convert _ to space and capitalize first letter
'value' => $col
])->toArray();
Expand Down
45 changes: 45 additions & 0 deletions app/Events/FileDownloadProgress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class FileDownloadProgress
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
public int $userId;
public int $progress;
public string|null $fileName;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($userId, $progress, $fileName = null)
{
$this->userId = $userId;
$this->progress = $progress;
$this->fileName = $fileName;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn(): Channel|PrivateChannel|array
{
return new PrivateChannel('grp.download-progress.' . $this->userId);
}

public function broadcastAs(): string
{
return 'FileDownloadProgress';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class () extends Migration {
/**
* Run the migrations.
*
Expand Down
4 changes: 4 additions & 0 deletions routes/channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
return $userID === $user->id;
});

Broadcast::channel('grp.download-progress.{userID}', function (User $user, int $userID) {
return $userID === $user->id;
});

Broadcast::channel('grp.{groupID}.general', function (User $user, int $groupID) {
return $user->group_id === $groupID;
});
Expand Down
1 change: 0 additions & 1 deletion routes/grp/web/models/inventory/warehouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

use App\Actions\Fulfilment\Pallet\UpdatePalletLocation;
use App\Actions\Inventory\Location\DownloadLocations;
use App\Actions\Inventory\Location\ImportLocation;
use App\Actions\Inventory\Location\StoreLocation;
use App\Actions\Inventory\Warehouse\UpdateWarehouse;
Expand Down
11 changes: 4 additions & 7 deletions tests/Feature/AikuSections/OrderingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
use App\Actions\Dropshipping\CustomerClient\UpdateCustomerClient;
use App\Actions\Ordering\Adjustment\StoreAdjustment;
use App\Actions\Ordering\Adjustment\UpdateAdjustment;
use App\Actions\Ordering\Order\DeleteOrder;
use App\Actions\Ordering\Order\Search\ReindexOrdersSearch;
use App\Actions\Ordering\Order\SendOrderToWarehouse;
use App\Actions\Ordering\Order\StoreOrder;
use App\Actions\Ordering\Order\UpdateOrder;
use App\Actions\Ordering\Order\UpdateOrderStateToSubmitted;
use App\Actions\Ordering\Order\UpdateStateToCreatingOrder;
use App\Actions\Ordering\Order\UpdateStateToFinalizedOrder;
use App\Actions\Ordering\Order\UpdateStateToHandlingOrder;
use App\Actions\Ordering\Order\UpdateStateToPackedOrder;
Expand Down Expand Up @@ -70,7 +68,6 @@
use App\Models\Ordering\ShippingZoneSchema;
use App\Models\Ordering\Transaction;
use Carbon\Carbon;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Facades\Date;
use Inertia\Testing\AssertableInertia;

Expand Down Expand Up @@ -347,7 +344,7 @@
$order->refresh();
expect($deliveryNote)->toBeInstanceOf(DeliveryNote::class)
->and($order->state)->toEqual(OrderStateEnum::IN_WAREHOUSE);

return $order;
})->depends('update order state to submitted');

Expand All @@ -356,7 +353,7 @@
$order->refresh();
expect($order)->toBeInstanceOf(Order::class)
->and($order->state)->toEqual(OrderStateEnum::HANDLING);

return $order;
})->depends('update order state to in warehouse');

Expand All @@ -365,7 +362,7 @@
$order->refresh();
expect($order)->toBeInstanceOf(Order::class)
->and($order->state)->toEqual(OrderStateEnum::PACKED);

return $order;
})->depends('update order state to Handling');

Expand All @@ -374,7 +371,7 @@
$order->refresh();
expect($order)->toBeInstanceOf(Order::class)
->and($order->state)->toEqual(OrderStateEnum::FINALISED);

return $order;
})->depends('update order state to Handling');

Expand Down

0 comments on commit 05d7850

Please sign in to comment.