@@ -11,8 +11,14 @@ import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { money } from '@/types/procurement';
|
||||
import type { CostCenter, Requisition } from '@/types/procurement';
|
||||
import { CatalogueSearch } from '@/components/requisition-catalogue';
|
||||
import type { CatalogueOptions } from '@/components/requisition-catalogue';
|
||||
|
||||
type Line = {
|
||||
source_line_id: string;
|
||||
catalogue_entry_id: string;
|
||||
catalogue_version: string;
|
||||
catalogue_code: string;
|
||||
key: string;
|
||||
description: string;
|
||||
category: string;
|
||||
@@ -26,7 +32,11 @@ type Line = {
|
||||
production_area: string;
|
||||
downtime_started_at: string;
|
||||
};
|
||||
const emptyLine = (): Line => ({
|
||||
const emptyLine = (taxRate: string): Line => ({
|
||||
source_line_id: '',
|
||||
catalogue_entry_id: '',
|
||||
catalogue_version: '',
|
||||
catalogue_code: '',
|
||||
key: crypto.randomUUID(),
|
||||
description: '',
|
||||
category: '',
|
||||
@@ -34,7 +44,7 @@ const emptyLine = (): Line => ({
|
||||
quantity: '1',
|
||||
unit: 'un',
|
||||
unit_price: '',
|
||||
tax_rate: '0',
|
||||
tax_rate: taxRate,
|
||||
equipment_id: '',
|
||||
spare_part_id: '',
|
||||
production_area: '',
|
||||
@@ -76,12 +86,16 @@ export default function RequisitionForm({
|
||||
equipment = [],
|
||||
spareParts = [],
|
||||
stockItems = [],
|
||||
defaultTaxRate = '16.00',
|
||||
catalogue,
|
||||
}: {
|
||||
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 }[];
|
||||
defaultTaxRate?: string;
|
||||
catalogue?: CatalogueOptions;
|
||||
}) {
|
||||
const form = useForm({
|
||||
cost_center_id: requisition ? String(requisition.cost_center_id) : '',
|
||||
@@ -89,6 +103,14 @@ export default function RequisitionForm({
|
||||
needed_by: requisition?.needed_by ?? '',
|
||||
justification: requisition?.justification ?? '',
|
||||
items: requisition?.items.map((i) => ({
|
||||
source_line_id: i.id ? String(i.id) : '',
|
||||
catalogue_entry_id: i.catalogue_entry_id
|
||||
? String(i.catalogue_entry_id)
|
||||
: '',
|
||||
catalogue_version: i.catalogue_snapshot
|
||||
? String(i.catalogue_snapshot.version)
|
||||
: '',
|
||||
catalogue_code: i.catalogue_snapshot?.code ?? '',
|
||||
key: String(i.id),
|
||||
description: i.description,
|
||||
category: i.category,
|
||||
@@ -101,7 +123,7 @@ export default function RequisitionForm({
|
||||
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()],
|
||||
})) ?? [emptyLine(defaultTaxRate)],
|
||||
});
|
||||
const changeLine = (index: number, field: keyof Line, value: string) =>
|
||||
form.setData(
|
||||
@@ -242,6 +264,9 @@ export default function RequisitionForm({
|
||||
description="Preços em MZN. Indique a taxa de IVA aplicável; o valor inicial de 0% deve ser revisto por Finanças."
|
||||
>
|
||||
<div className="space-y-5">
|
||||
{catalogue?.ready && (
|
||||
<CatalogueSearch data={catalogue} />
|
||||
)}
|
||||
{form.data.items.map((line, index) => (
|
||||
<fieldset
|
||||
className="rounded-lg border bg-muted/20 p-4"
|
||||
@@ -251,6 +276,121 @@ export default function RequisitionForm({
|
||||
LINHA {index + 1}
|
||||
</legend>
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{catalogue?.ready && (
|
||||
<label className="space-y-2 sm:col-span-3">
|
||||
Fonte do artigo
|
||||
<select
|
||||
className={controlClass}
|
||||
value={
|
||||
line.catalogue_entry_id
|
||||
? `${line.catalogue_entry_id}:${line.catalogue_version}`
|
||||
: ''
|
||||
}
|
||||
onChange={(event) => {
|
||||
const entry =
|
||||
catalogue.items.find(
|
||||
(item) =>
|
||||
`${item.id}:${item.version}` ===
|
||||
event.target
|
||||
.value,
|
||||
);
|
||||
form.setData(
|
||||
'items',
|
||||
form.data.items.map(
|
||||
(item, i) =>
|
||||
i === index
|
||||
? entry
|
||||
? {
|
||||
...item,
|
||||
catalogue_entry_id:
|
||||
String(
|
||||
entry.id,
|
||||
),
|
||||
catalogue_version:
|
||||
String(
|
||||
entry.version,
|
||||
),
|
||||
catalogue_code:
|
||||
entry.code,
|
||||
description:
|
||||
entry.description,
|
||||
category:
|
||||
entry.category,
|
||||
unit: entry.unit,
|
||||
purchase_type:
|
||||
entry.purchase_type,
|
||||
}
|
||||
: {
|
||||
...item,
|
||||
catalogue_entry_id:
|
||||
'',
|
||||
catalogue_version:
|
||||
'',
|
||||
catalogue_code:
|
||||
'',
|
||||
}
|
||||
: item,
|
||||
),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
Preenchimento livre
|
||||
</option>
|
||||
{line.catalogue_entry_id &&
|
||||
!catalogue.items.some(
|
||||
(item) =>
|
||||
String(
|
||||
item.id,
|
||||
) ===
|
||||
line.catalogue_entry_id &&
|
||||
String(
|
||||
item.version,
|
||||
) ===
|
||||
line.catalogue_version,
|
||||
) && (
|
||||
<option
|
||||
value={`${line.catalogue_entry_id}:${line.catalogue_version}`}
|
||||
>
|
||||
{
|
||||
line.catalogue_code
|
||||
}{' '}
|
||||
· versão
|
||||
preservada{' '}
|
||||
{
|
||||
line.catalogue_version
|
||||
}
|
||||
</option>
|
||||
)}
|
||||
{catalogue.items.map(
|
||||
(entry) => (
|
||||
<option
|
||||
key={`${entry.id}:${entry.version}`}
|
||||
value={`${entry.id}:${entry.version}`}
|
||||
>
|
||||
{entry.code} ·{' '}
|
||||
{
|
||||
entry.description
|
||||
}{' '}
|
||||
· v
|
||||
{entry.version}
|
||||
</option>
|
||||
),
|
||||
)}
|
||||
</select>
|
||||
{line.catalogue_entry_id && (
|
||||
<p className="text-sm">
|
||||
Fonte{' '}
|
||||
{line.catalogue_code} ·
|
||||
versão utilizada{' '}
|
||||
{line.catalogue_version}
|
||||
. Escolha preenchimento
|
||||
livre para descrever uma
|
||||
necessidade diferente.
|
||||
</p>
|
||||
)}
|
||||
</label>
|
||||
)}
|
||||
{lineFields.map(
|
||||
({ key, label, ...attributes }) => (
|
||||
<div
|
||||
@@ -265,6 +405,14 @@ export default function RequisitionForm({
|
||||
<Input
|
||||
id={`${key}-${line.key}`}
|
||||
{...attributes}
|
||||
readOnly={
|
||||
!!line.catalogue_entry_id &&
|
||||
[
|
||||
'description',
|
||||
'category',
|
||||
'unit',
|
||||
].includes(key)
|
||||
}
|
||||
required
|
||||
value={line[key]}
|
||||
onChange={(e) =>
|
||||
@@ -286,6 +434,9 @@ export default function RequisitionForm({
|
||||
id={`type-${line.key}`}
|
||||
className={controlClass}
|
||||
value={line.purchase_type}
|
||||
disabled={
|
||||
!!line.catalogue_entry_id
|
||||
}
|
||||
onChange={(e) =>
|
||||
changeLine(
|
||||
index,
|
||||
@@ -500,7 +651,7 @@ export default function RequisitionForm({
|
||||
onClick={() =>
|
||||
form.setData('items', [
|
||||
...form.data.items,
|
||||
emptyLine(),
|
||||
emptyLine(defaultTaxRate),
|
||||
])
|
||||
}
|
||||
>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Check, Circle, Pencil, Send } from 'lucide-react';
|
||||
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
|
||||
import type { ComparisonPolicy } from '@/components/comparison-policy-summary';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
@@ -33,8 +35,10 @@ export default function Show({
|
||||
conflictBlocked,
|
||||
audit,
|
||||
technical,
|
||||
comparisonPolicy,
|
||||
}: {
|
||||
requisition: Requisition;
|
||||
comparisonPolicy: ComparisonPolicy;
|
||||
canEdit: boolean;
|
||||
canDecide: boolean;
|
||||
conflictBlocked: boolean;
|
||||
@@ -81,6 +85,9 @@ export default function Show({
|
||||
}
|
||||
/>
|
||||
<FormErrors errors={submission.errors} />
|
||||
<Panel title="Regra de comparação deste processo">
|
||||
<ComparisonPolicySummary policy={comparisonPolicy} />
|
||||
</Panel>
|
||||
{r.items.some((i) => i.purchase_type === 'equipment') && (
|
||||
<Panel title="Validação técnica do equipamento">
|
||||
<p className="mb-4 text-sm">
|
||||
|
||||
Reference in New Issue
Block a user