Consolida recepcoes, stock, equipamentos e identidade SGC
This commit is contained in:
@@ -21,6 +21,10 @@ type Line = {
|
||||
unit: string;
|
||||
unit_price: string;
|
||||
tax_rate: string;
|
||||
equipment_id: string;
|
||||
spare_part_id: string;
|
||||
production_area: string;
|
||||
downtime_started_at: string;
|
||||
};
|
||||
const emptyLine = (): Line => ({
|
||||
key: crypto.randomUUID(),
|
||||
@@ -31,6 +35,10 @@ const emptyLine = (): Line => ({
|
||||
unit: 'un',
|
||||
unit_price: '',
|
||||
tax_rate: '0',
|
||||
equipment_id: '',
|
||||
spare_part_id: '',
|
||||
production_area: '',
|
||||
downtime_started_at: '',
|
||||
});
|
||||
const lineFields = [
|
||||
{ key: 'description', label: 'Descrição', type: 'text', maxLength: 255 },
|
||||
@@ -65,9 +73,15 @@ const lineFields = [
|
||||
export default function RequisitionForm({
|
||||
costCenters,
|
||||
requisition,
|
||||
equipment = [],
|
||||
spareParts = [],
|
||||
stockItems = [],
|
||||
}: {
|
||||
costCenters: CostCenter[];
|
||||
requisition: Requisition | null;
|
||||
equipment?: { id: number; code: string; description: string }[];
|
||||
spareParts?: { id: number; stock_item_id: number }[];
|
||||
stockItems?: { id: number; code: string; name: string; unit: string }[];
|
||||
}) {
|
||||
const form = useForm({
|
||||
cost_center_id: requisition ? String(requisition.cost_center_id) : '',
|
||||
@@ -83,6 +97,10 @@ export default function RequisitionForm({
|
||||
unit: i.unit,
|
||||
unit_price: (i.unit_price_minor / 100).toFixed(2),
|
||||
tax_rate: String(i.tax_rate),
|
||||
equipment_id: i.equipment_id ? String(i.equipment_id) : '',
|
||||
spare_part_id: i.spare_part_id ? String(i.spare_part_id) : '',
|
||||
production_area: i.production_area ?? '',
|
||||
downtime_started_at: i.downtime_started_at?.slice(0, 16) ?? '',
|
||||
})) ?? [emptyLine()],
|
||||
});
|
||||
const changeLine = (index: number, field: keyof Line, value: string) =>
|
||||
@@ -276,6 +294,14 @@ export default function RequisitionForm({
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="equipment">
|
||||
Equipamento (emissão
|
||||
bloqueada até definição da
|
||||
regra de investimento)
|
||||
</option>
|
||||
<option value="spare_part">
|
||||
Peça sobressalente
|
||||
</option>
|
||||
<option value="consumable">
|
||||
Insumos / matéria-prima
|
||||
</option>
|
||||
@@ -286,6 +312,160 @@ export default function RequisitionForm({
|
||||
Outro
|
||||
</option>
|
||||
</select>
|
||||
{line.purchase_type ===
|
||||
'equipment' && (
|
||||
<label className="mt-3 grid gap-2 text-sm">
|
||||
Área / linha de produção
|
||||
<Input
|
||||
required
|
||||
value={
|
||||
line.production_area
|
||||
}
|
||||
onChange={(e) =>
|
||||
changeLine(
|
||||
index,
|
||||
'production_area',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
{line.purchase_type ===
|
||||
'spare_part' && (
|
||||
<div className="mt-3 grid gap-3">
|
||||
<label className="grid gap-2 text-sm">
|
||||
Equipamento do
|
||||
departamento
|
||||
<select
|
||||
required
|
||||
className={
|
||||
controlClass
|
||||
}
|
||||
value={
|
||||
line.equipment_id
|
||||
}
|
||||
onChange={(e) =>
|
||||
changeLine(
|
||||
index,
|
||||
'equipment_id',
|
||||
e.target
|
||||
.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Seleccionar
|
||||
</option>
|
||||
{equipment.map(
|
||||
(a) => (
|
||||
<option
|
||||
key={
|
||||
a.id
|
||||
}
|
||||
value={
|
||||
a.id
|
||||
}
|
||||
>
|
||||
{a.code}{' '}
|
||||
·{' '}
|
||||
{
|
||||
a.description
|
||||
}
|
||||
</option>
|
||||
),
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Peça cadastrada
|
||||
<select
|
||||
required
|
||||
className={
|
||||
controlClass
|
||||
}
|
||||
value={
|
||||
line.spare_part_id
|
||||
}
|
||||
onChange={(e) =>
|
||||
changeLine(
|
||||
index,
|
||||
'spare_part_id',
|
||||
e.target
|
||||
.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Seleccionar
|
||||
</option>
|
||||
{spareParts.map(
|
||||
(p) => (
|
||||
<option
|
||||
key={
|
||||
p.id
|
||||
}
|
||||
value={
|
||||
p.id
|
||||
}
|
||||
>
|
||||
{
|
||||
stockItems.find(
|
||||
(
|
||||
s,
|
||||
) =>
|
||||
s.id ===
|
||||
p.stock_item_id,
|
||||
)
|
||||
?.code
|
||||
}{' '}
|
||||
·{' '}
|
||||
{
|
||||
stockItems.find(
|
||||
(
|
||||
s,
|
||||
) =>
|
||||
s.id ===
|
||||
p.stock_item_id,
|
||||
)
|
||||
?.name
|
||||
}
|
||||
</option>
|
||||
),
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-2 text-sm">
|
||||
Início da paragem
|
||||
(obrigatório para peça
|
||||
crítica urgente; hora
|
||||
UTC)
|
||||
<Input
|
||||
type="datetime-local"
|
||||
value={
|
||||
line.downtime_started_at
|
||||
}
|
||||
onChange={(e) =>
|
||||
changeLine(
|
||||
index,
|
||||
'downtime_started_at',
|
||||
e.target
|
||||
.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Use a unidade do artigo.
|
||||
A associação
|
||||
peça/equipamento é
|
||||
revalidada no servidor.
|
||||
Urgência não dispensa
|
||||
três cotações ou
|
||||
aprovações.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 flex justify-end">
|
||||
|
||||
Reference in New Issue
Block a user