@@ -1,3 +1,9 @@
|
||||
import { AdministrativeLocation } from '@/components/administrative-location';
|
||||
import type {
|
||||
GeographyDescription,
|
||||
GeographyReference,
|
||||
} from '@/components/administrative-location';
|
||||
import { TerritorialFilter } from '@/components/territorial-filter';
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { InventoryNotice, InventoryPagination } from '@/components/inventory';
|
||||
import {
|
||||
@@ -18,7 +24,50 @@ import type {
|
||||
Warehouse,
|
||||
} from '@/types/inventory';
|
||||
|
||||
function WarehouseLocation({
|
||||
warehouse,
|
||||
geography,
|
||||
}: {
|
||||
warehouse: Warehouse;
|
||||
geography: GeographyDescription;
|
||||
}) {
|
||||
const form = useForm({
|
||||
geography_reference:
|
||||
geography?.reference ?? (null as GeographyReference | null),
|
||||
expected_reference: geography?.reference ?? null,
|
||||
});
|
||||
return (
|
||||
<details className="mb-4 rounded-lg border p-3">
|
||||
<summary className="cursor-pointer text-sm font-medium">
|
||||
Localização de {warehouse.code} · {warehouse.name}
|
||||
</summary>
|
||||
<form
|
||||
className="mt-4 space-y-3"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
form.post(`/stock/armazens/${warehouse.id}/localizacao`, {
|
||||
preserveScroll: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<AdministrativeLocation
|
||||
value={form.data.geography_reference}
|
||||
initial={geography}
|
||||
onChange={(value) =>
|
||||
form.setData('geography_reference', value)
|
||||
}
|
||||
/>
|
||||
<Button disabled={form.processing}>Guardar localização</Button>
|
||||
</form>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
|
||||
type Props = {
|
||||
geographyEnabled?: boolean;
|
||||
warehouseGeography?: Record<number, GeographyDescription>;
|
||||
geographyFilter?: GeographyDescription;
|
||||
items: StockItem[];
|
||||
warehouses: Warehouse[];
|
||||
balances: {
|
||||
@@ -32,7 +81,7 @@ type Props = {
|
||||
} | null;
|
||||
}[];
|
||||
movements: Page<StockMovement>;
|
||||
filters: { search?: string; warehouse_id?: number };
|
||||
filters: { search?: string; warehouse_id?: number; location?: string };
|
||||
canManage: boolean;
|
||||
};
|
||||
export default function Stock({
|
||||
@@ -42,13 +91,21 @@ export default function Stock({
|
||||
movements,
|
||||
filters,
|
||||
canManage,
|
||||
geographyEnabled = false,
|
||||
warehouseGeography = {},
|
||||
geographyFilter = null,
|
||||
}: Props) {
|
||||
const search = useForm({
|
||||
location: filters.location ?? '',
|
||||
search: filters.search ?? '',
|
||||
warehouse_id: filters.warehouse_id ? String(filters.warehouse_id) : '',
|
||||
});
|
||||
const item = useForm({ code: '', name: '', unit: '' });
|
||||
const warehouse = useForm({ code: '', name: '' });
|
||||
const warehouse = useForm({
|
||||
code: '',
|
||||
name: '',
|
||||
geography_reference: null as GeographyReference | null,
|
||||
});
|
||||
return (
|
||||
<>
|
||||
<Head title="Stock e movimentos" />
|
||||
@@ -59,6 +116,20 @@ export default function Stock({
|
||||
description="Saldo por artigo e armazém, calculado a partir de entradas, saídas, transferências e ajustes confirmados. O histórico permanece preservado."
|
||||
/>
|
||||
<InventoryNotice />
|
||||
{geographyEnabled && (
|
||||
<Panel title="Localização dos armazéns">
|
||||
<TerritorialFilter
|
||||
target="/stock"
|
||||
initial={geographyFilter}
|
||||
extra={{
|
||||
search: filters.search ?? '',
|
||||
warehouse_id: filters.warehouse_id
|
||||
? String(filters.warehouse_id)
|
||||
: '',
|
||||
}}
|
||||
/>
|
||||
</Panel>
|
||||
)}
|
||||
{canManage && (
|
||||
<Link
|
||||
className="font-semibold text-teal-700"
|
||||
@@ -282,14 +353,40 @@ export default function Stock({
|
||||
{warehouses.map((w) => (
|
||||
<p key={w.id}>
|
||||
<strong>{w.code}</strong> · {w.name}
|
||||
{warehouseGeography[w.id]?.path
|
||||
.map((node) => node.name)
|
||||
.join(' / ') && (
|
||||
<span className="block text-muted-foreground">
|
||||
Localização actual:{' '}
|
||||
{warehouseGeography[w.id]?.path
|
||||
.map((node) => node.name)
|
||||
.join(' / ')}
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
{geographyEnabled &&
|
||||
canManage &&
|
||||
warehouses.map((w) => (
|
||||
<WarehouseLocation
|
||||
key={`${w.id}:${JSON.stringify(warehouseGeography[w.id]?.reference ?? null)}`}
|
||||
warehouse={w}
|
||||
geography={warehouseGeography[w.id] ?? null}
|
||||
/>
|
||||
))}
|
||||
{canManage && (
|
||||
<form
|
||||
className="space-y-4 border-t pt-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
warehouse.transform((data) => {
|
||||
const { geography_reference, ...rest } =
|
||||
data;
|
||||
return geographyEnabled
|
||||
? { ...rest, geography_reference }
|
||||
: rest;
|
||||
});
|
||||
warehouse.post('/stock/armazens', {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => warehouse.reset(),
|
||||
@@ -297,6 +394,19 @@ export default function Stock({
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={warehouse.errors} />
|
||||
{geographyEnabled && (
|
||||
<AdministrativeLocation
|
||||
value={
|
||||
warehouse.data.geography_reference
|
||||
}
|
||||
onChange={(value) =>
|
||||
warehouse.setData(
|
||||
'geography_reference',
|
||||
value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{(['code', 'name'] as const).map((key) => (
|
||||
<div className="space-y-2" key={key}>
|
||||
<Label htmlFor={`warehouse-${key}`}>
|
||||
|
||||
@@ -265,12 +265,20 @@ export default function WarehouseRequest(props: Props) {
|
||||
description={`Estado: ${labels[p.state] ?? p.state}`}
|
||||
/>
|
||||
<div className="flex gap-4 print:hidden">
|
||||
{props.canViewReturns && <Link href={`/stock/devolucoes-internas?request_id=${r.id}`}>Conferir devolução de excedentes</Link>}
|
||||
{props.canViewReturns && (
|
||||
<Link
|
||||
href={`/stock/devolucoes-internas?request_id=${r.id}`}
|
||||
>
|
||||
Conferir devolução de excedentes
|
||||
</Link>
|
||||
)}
|
||||
<Link href="/stock/requisicoes">
|
||||
Requisições ao armazém
|
||||
</Link>
|
||||
<Button variant="outline" onClick={() => window.print()}>
|
||||
Imprimir requisição e entregas
|
||||
<Button variant="outline" asChild>
|
||||
<a href={`/stock/requisicoes/${r.id}/imprimir`}>
|
||||
Imprimir requisição e entregas
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
<Panel title="Utilização e origem">
|
||||
@@ -672,6 +680,14 @@ export default function WarehouseRequest(props: Props) {
|
||||
Documento de saída: RA-{r.id} ·
|
||||
Entrega #{event.id}
|
||||
</p>
|
||||
<a
|
||||
href={`/stock/requisicoes/${r.id}/entregas/${event.id}/imprimir`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-sm underline print:hidden"
|
||||
>
|
||||
Imprimir apenas esta entrega
|
||||
</a>
|
||||
{event.data.lines?.map((line) => (
|
||||
<p key={line.index}>
|
||||
{
|
||||
|
||||
@@ -110,6 +110,32 @@ export default function Requests(props: Props) {
|
||||
eyebrow="Armazém e activos"
|
||||
title="Requisições ao armazém"
|
||||
description="Acompanhar autorizações, reservas, entregas e recepções conforme as suas tarefas."
|
||||
action={
|
||||
props.ready ? (
|
||||
<Button variant="outline" asChild>
|
||||
<a
|
||||
href={
|
||||
'/stock/requisicoes.csv?' +
|
||||
new URLSearchParams({
|
||||
view: props.filters.view,
|
||||
state: props.filters.state,
|
||||
search: props.filters.search,
|
||||
...(props.filters.warehouse_id
|
||||
? {
|
||||
warehouse_id: String(
|
||||
props.filters
|
||||
.warehouse_id,
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
}).toString()
|
||||
}
|
||||
>
|
||||
Exportar todos os resultados (CSV)
|
||||
</a>
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
<p className="text-sm">
|
||||
Uso interno sem factura: a requisição autorizada acompanha a
|
||||
|
||||
Reference in New Issue
Block a user