@php
/**
* The job's products, managed as units of work inside the one job.
*
* One invoice is one job. A sale of three products is still one job and one
* invoice, so nothing here creates or splits jobs: it arranges the products
* of THIS job so each can be run, dated, owned and costed on its own, or
* compiled with the ones it is genuinely made alongside — or, where one
* product is really several pieces of work (three flags, three designs),
* split into pieces that each carry their own state, artwork and notes.
*/
$statusMeta = [
'pending' => ['label' => __('Not started'), 'color' => 'slate', 'icon' => 'clock', 'bar' => 'bg-slate-300'],
'in_production' => ['label' => __('In production'), 'color' => 'sky', 'icon' => 'cog-6-tooth', 'bar' => 'bg-sky-500'],
'on_hold' => ['label' => __('On hold'), 'color' => 'amber', 'icon' => 'stop', 'bar' => 'bg-amber-500'],
'done' => ['label' => __('Done'), 'color' => 'emerald', 'icon' => 'check-circle', 'bar' => 'bg-emerald-500'],
];
$initials = function (?string $name): string {
$words = preg_split('/\s+/', trim((string) $name)) ?: [];
return strtoupper(\Illuminate\Support\Str::substr($words[0] ?? '?', 0, 1) . (isset($words[1]) ? \Illuminate\Support\Str::substr($words[1], 0, 1) : '')) ?: '?';
};
$selectedCount = count($selected);
@endphp
{{-- ============ ROLL-UP STRIP ============ --}}
@php
$tiles = [
['label' => __('Products'), 'value' => $roll['total'], 'icon' => 'cube', 'tone' => 'indigo', 'tag' => trans_choice('{1} one unit of work|[2,*] :count units of work', $roll['total'], ['count' => $roll['total']])],
['label' => __('In production'), 'value' => $roll['in_production'], 'icon' => 'cog-6-tooth', 'tone' => 'sky', 'tag' => __('being made now')],
['label' => __('Finished'), 'value' => $roll['done'].' / '.$roll['total'], 'icon' => 'check-circle', 'tone' => $roll['all_done'] ? 'emerald' : 'slate', 'tag' => $roll['all_done'] ? __('all products done') : __('still open')],
['label' => __('Real progress'), 'value' => $roll['progress'].'%', 'icon' => 'chart-bar', 'tone' => 'violet', 'tag' => __('weighted by sale value')],
];
// A hybrid job splits its work, so the board says how much of it left.
if ($isHybrid) {
$tiles[] = ['label' => __('Outsourced'), 'value' => $roll['outsourced'].' / '.$roll['total'], 'icon' => 'truck', 'tone' => $roll['outsourced'] > 0 ? 'rose' : 'slate', 'tag' => $roll['outsourced'] > 0 ? __('made by a partner') : __('all in-house so far')];
}
$tileChip = [
'indigo' => 'bg-indigo-50 text-indigo-600',
'sky' => 'bg-sky-50 text-sky-600',
'violet' => 'bg-violet-50 text-violet-600',
'emerald' => 'bg-emerald-50 text-emerald-600',
'rose' => 'bg-rose-50 text-rose-600',
'slate' => 'bg-slate-100 text-slate-500',
];
@endphp
{{ $selectedCount > 0
? trans_choice('{1} :count product selected|[2,*] :count products selected', $selectedCount, ['count' => $selectedCount])
: __('Tick the products you make together to compile them into one unit.') }}
@foreach ($groups as $group)
@if (! $group['is_split'])
{{-- A product that is one piece of work: its own card, as it
has always been. --}}
@php $unit = $group['units'][0]; $compact = false; @endphp
@include('livewire.jobs.partials.product-unit-card')
@else
{{-- A product made in several pieces.
The pieces are cards in their own right — a piece IS a
unit of work — but they sit on the product's own surface
rather than on the page, so the board reads as "this
product, made in three" instead of five loose things.
The tinted well behind them is what does that work: the
cards float on it, and the eye reads the boundary of the
group before it reads the cards inside. --}}
@php
$groupTone = $group['revenue'] <= 0
? 'slate'
: ($group['margin'] >= 30 ? 'emerald' : ($group['margin'] >= 10 ? 'amber' : 'rose'));
$groupPill = [
'emerald' => 'bg-emerald-50 text-emerald-700 ring-emerald-200',
'amber' => 'bg-amber-50 text-amber-700 ring-amber-200',
'rose' => 'bg-rose-50 text-rose-700 ring-rose-200',
'slate' => 'bg-slate-100 text-slate-500 ring-slate-200',
][$groupTone];
@endphp
{{-- The product itself: one sale, one roll-up. --}}
@endif
{{-- ============ FILES ON ONE PRODUCT ============ --}}
{{ __('Files for :product', ['product' => $filesLabel]) }}
{{ __('Artwork, references and print-ready files for this piece of work. They stay with it, so whoever picks it up is looking at the right drawing, and they show on the job’s Files tab too.') }}
@endif
{{ __('Done') }}
{{-- ============ SPLIT INTO PIECES MODAL ============ --}}
{{ __('Pieces of :product', ['product' => $splitProductName]) }}
{{ __('Three flags with three different designs are three pieces of work: each is drawn, approved and finished on its own. Give each piece a name and say how many of the quantity sold it covers.') }}
{{ __('The invoice does not change. It still reads :product — :qty, for the same money; the pieces only say how it is made, and each one carries its own artwork, costs, notes and margin.', [
'product' => $splitProductName,
'qty' => rtrim(rtrim(number_format($splitLineQty, 2), '0'), '.'),
]) }}
{{ __('These products are made together, so from here they are scheduled, assigned and finished as one. Costs stay tagged to each product, so the profit of each is still visible.') }}