Report stock usage and value, add material cost to profitability, document phase 5

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 17:24:07 +02:00
co-authored by Claude Sonnet 5.5
parent 38b8075a9c
commit 3207d0064a
34 changed files with 1145 additions and 24 deletions
@@ -0,0 +1,47 @@
<?php
namespace App\Modules\Reports\Infrastructure\Adapters;
use App\Modules\Inventory\Application\Contracts\StockReportQueries;
use App\Modules\Machines\Application\Contracts\MachineQueries;
use App\Modules\Reports\Application\Contracts\ReportStock;
use App\Modules\Reports\Domain\ValueObjects\ReportPeriod;
/**
* Stock for reports through the Inventory and Machines modules.
*/
class StockForReports implements ReportStock
{
public function __construct(
private StockReportQueries $stock,
private MachineQueries $machines,
) {}
public function usage(ReportPeriod $period): array
{
return $this->stock->usage($period->from, $period->to);
}
public function valueOn(string $day): array
{
return $this->stock->valueOn($day);
}
public function materialCostsByJob(ReportPeriod $period): array
{
return $this->stock->materialCostsByJob($period->from, $period->to);
}
public function machineNames(array $ids): array
{
$names = [];
foreach ($this->machines->machines(includeInactive: true) as $machine) {
if (in_array($machine->id, $ids, true)) {
$names[$machine->id] = $machine->name;
}
}
return $names;
}
}
@@ -3,6 +3,7 @@
namespace App\Modules\Reports\Infrastructure\Providers;
use App\Models\User;
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Reports\Application\Contracts\ReportCatalog;
use App\Modules\Reports\Application\Contracts\ReportExpenses;
use App\Modules\Reports\Application\Contracts\ReportHours;
@@ -10,6 +11,7 @@ use App\Modules\Reports\Application\Contracts\ReportJobs;
use App\Modules\Reports\Application\Contracts\ReportPeople;
use App\Modules\Reports\Application\Contracts\ReportRevenue;
use App\Modules\Reports\Application\Contracts\ReportSales;
use App\Modules\Reports\Application\Contracts\ReportStock;
use App\Modules\Reports\Infrastructure\Adapters\CatalogForReports;
use App\Modules\Reports\Infrastructure\Adapters\ExpensesForReports;
use App\Modules\Reports\Infrastructure\Adapters\HoursForReports;
@@ -17,6 +19,7 @@ use App\Modules\Reports\Infrastructure\Adapters\JobsForReports;
use App\Modules\Reports\Infrastructure\Adapters\PeopleForReports;
use App\Modules\Reports\Infrastructure\Adapters\RevenueForReports;
use App\Modules\Reports\Infrastructure\Adapters\SalesForReports;
use App\Modules\Reports\Infrastructure\Adapters\StockForReports;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
@@ -37,6 +40,7 @@ class ReportsServiceProvider extends ServiceProvider
ReportCatalog::class => CatalogForReports::class,
ReportPeople::class => PeopleForReports::class,
ReportSales::class => SalesForReports::class,
ReportStock::class => StockForReports::class,
ReportExpenses::class => ExpensesForReports::class,
ReportRevenue::class => RevenueForReports::class,
];
@@ -52,6 +56,8 @@ class ReportsServiceProvider extends ServiceProvider
}
// Reports are for admin and management (spec 2.4).
Gate::define('reports.stock', fn (User $user): bool => $user->role->seesAllMoney() && app(CatalogQueries::class)->stockServiceUnitIds() !== []);
Gate::define('reports.view', fn (User $user): bool => $user->role->seesAllMoney());
}
}