commit14
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
FormErrors,
|
||||
@@ -24,6 +24,7 @@ type Invoice = {
|
||||
bank_state: string;
|
||||
};
|
||||
type Payment = {
|
||||
canReview: boolean;
|
||||
id: number;
|
||||
invoice_id: number;
|
||||
created_by: number;
|
||||
@@ -90,15 +91,21 @@ export default function Payments({
|
||||
invoices,
|
||||
payments,
|
||||
canManage,
|
||||
focusPaymentId = null,
|
||||
focusInvoiceId = null,
|
||||
}: {
|
||||
invoices: Invoice[];
|
||||
payments: Page<Payment>;
|
||||
canManage: boolean;
|
||||
focusPaymentId?: number | null;
|
||||
focusInvoiceId?: number | null;
|
||||
}) {
|
||||
const { auth } = usePage().props;
|
||||
const [invoiceId, setInvoiceId] = useState('');
|
||||
const [invoiceId, setInvoiceId] = useState(
|
||||
focusInvoiceId === null ? '' : String(focusInvoiceId),
|
||||
);
|
||||
const form = useForm({
|
||||
supplier_bank_detail_id: 0,
|
||||
supplier_bank_detail_id:
|
||||
invoices.find((i) => i.id === focusInvoiceId)?.bank_id ?? 0,
|
||||
amount: '',
|
||||
paid_on: '',
|
||||
external_reference: '',
|
||||
@@ -157,7 +164,15 @@ export default function Payments({
|
||||
)}
|
||||
</div>
|
||||
</Panel>
|
||||
{canManage && (
|
||||
{(focusPaymentId !== null || focusInvoiceId !== null) && (
|
||||
<Link
|
||||
href="/pagamentos"
|
||||
className="font-semibold text-teal-700"
|
||||
>
|
||||
Ver todos os registos externos
|
||||
</Link>
|
||||
)}
|
||||
{canManage && focusPaymentId === null && (
|
||||
<Panel
|
||||
title="Registar pagamento externo para conferência"
|
||||
description="Uma referência externa identifica um registo por empresa. Use a referência da operação e a evidência do pagamento; não introduza números de conta nestes campos."
|
||||
@@ -276,34 +291,31 @@ export default function Payments({
|
||||
</Panel>
|
||||
)}
|
||||
{payments.data.map((p) => (
|
||||
<Panel
|
||||
key={p.id}
|
||||
title={`Registo externo #${p.id} · ${invoices.find((i) => i.id === p.invoice_id)?.number ?? `Factura #${p.invoice_id}`}`}
|
||||
>
|
||||
<p>
|
||||
{money(p.amount_minor)} · {p.paid_on} ·{' '}
|
||||
{{
|
||||
pending: 'Pendente de conferência',
|
||||
confirmed: 'Confirmado',
|
||||
rejected: 'Conferência rejeitada',
|
||||
}[p.status] ?? p.status}
|
||||
</p>
|
||||
{p.external_reference && (
|
||||
<p className="mt-2 text-sm break-all">
|
||||
Referência: {p.external_reference}
|
||||
<div key={p.id} id={`payment-${p.id}`}>
|
||||
<Panel
|
||||
title={`Registo externo #${p.id} · ${invoices.find((i) => i.id === p.invoice_id)?.number ?? `Factura #${p.invoice_id}`}`}
|
||||
>
|
||||
<p>
|
||||
{money(p.amount_minor)} · {p.paid_on} ·{' '}
|
||||
{{
|
||||
pending: 'Pendente de conferência',
|
||||
confirmed: 'Confirmado',
|
||||
rejected: 'Conferência rejeitada',
|
||||
}[p.status] ?? p.status}
|
||||
</p>
|
||||
)}
|
||||
{p.evidence_reference && (
|
||||
<p className="text-sm break-all">
|
||||
Evidência: {p.evidence_reference}
|
||||
</p>
|
||||
)}
|
||||
{canManage &&
|
||||
p.status === 'pending' &&
|
||||
p.created_by !== auth.user?.id && (
|
||||
<Review id={p.id} />
|
||||
{p.external_reference && (
|
||||
<p className="mt-2 text-sm break-all">
|
||||
Referência: {p.external_reference}
|
||||
</p>
|
||||
)}
|
||||
</Panel>
|
||||
{p.evidence_reference && (
|
||||
<p className="text-sm break-all">
|
||||
Evidência: {p.evidence_reference}
|
||||
</p>
|
||||
)}
|
||||
{p.canReview && <Review id={p.id} />}
|
||||
</Panel>
|
||||
</div>
|
||||
))}
|
||||
<InventoryPagination page={payments} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user