feature/pedimentos-csv-validations
This commit is contained in:
@@ -476,11 +476,18 @@ export const api = {
|
||||
|
||||
// CSV import for Pedimentos (pedimentos/imports)
|
||||
pedimentosImports: {
|
||||
upload: (file: File, companyId: number) => {
|
||||
upload: (
|
||||
file: File,
|
||||
companyId: number,
|
||||
params?: { actualizar?: boolean; dateFormat?: string }
|
||||
) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const search = new URLSearchParams({ company_id: String(companyId) });
|
||||
if (params?.actualizar !== undefined) search.set('actualizar', String(!!params.actualizar));
|
||||
if (params?.dateFormat != null) search.set('dateFormat', params.dateFormat);
|
||||
return fetchApi(
|
||||
`/v1/a76/pedimentos/imports/upload?company_id=${companyId}`,
|
||||
`/v1/a76/pedimentos/imports/upload?${search.toString()}`,
|
||||
{ method: 'POST', body: formData }
|
||||
);
|
||||
},
|
||||
|
||||
@@ -665,9 +665,9 @@
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<!-- ID del Cliente -->
|
||||
<!-- ID del Cliente (opcional) -->
|
||||
<div class="space-y-2">
|
||||
<Label for="client_id">Cliente <span class="text-red-500">*</span></Label>
|
||||
<Label for="client_id">Cliente</Label>
|
||||
<Select.Root
|
||||
type="single"
|
||||
value={String(formData.client_id ?? '')}
|
||||
|
||||
@@ -221,7 +221,14 @@
|
||||
|
||||
if (usePedimentosImport) {
|
||||
try {
|
||||
const res = await api.pedimentosImports.upload(file, companyId);
|
||||
const catalogosSettings = allSettings['catalogos'] || {};
|
||||
const actualizar = catalogosSettings['mode'] === 'update';
|
||||
const dateFormat =
|
||||
globalSettings['dateFormat'] ?? catalogosSettings['dateFormat'] ?? globalCsvParams.find((p) => p.name === 'dateFormat')?.defaultValue ?? 'dd/mm/yyyy';
|
||||
const res = await api.pedimentosImports.upload(file, companyId, {
|
||||
actualizar,
|
||||
dateFormat
|
||||
});
|
||||
if (res.data?.job_id) {
|
||||
currentJobId = res.data.job_id;
|
||||
pollStatus();
|
||||
@@ -516,11 +523,12 @@
|
||||
const skippedFk = res.data?.skipped_missing_fk || 0;
|
||||
const skippedDup = res.data?.skipped_duplicate || 0;
|
||||
const totalSkipped = skippedInvalid + skippedFk + skippedDup;
|
||||
const backendMessage = res.data?.message;
|
||||
|
||||
if (inserted === 0) {
|
||||
toast.error(`No se insertaron registros. ${totalSkipped} fueron rechazados.`);
|
||||
toast.error(backendMessage || `No se insertaron registros. ${totalSkipped} fueron rechazados.`);
|
||||
} else {
|
||||
toast.warning(`Solo se insertaron ${inserted} de ${inserted + totalSkipped} registros.`);
|
||||
toast.warning(backendMessage || `Solo se insertaron ${inserted} de ${inserted + totalSkipped} registros.`);
|
||||
}
|
||||
isUploading = false;
|
||||
} else if (res.data?.status === 'finished') {
|
||||
|
||||
@@ -408,14 +408,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Validar campos requeridos para creación
|
||||
// Validar campos requeridos para creación (client_id es opcional)
|
||||
if (data.isCreate && generalFormData) {
|
||||
const requiredFields = {
|
||||
const requiredFields: Record<string, string> = {
|
||||
year: 'Año',
|
||||
customs_office: 'Aduana',
|
||||
license: 'Patente',
|
||||
pedimento_number: 'Número de Pedimento',
|
||||
client_id: 'ID del Cliente',
|
||||
pedimento_code: 'Clave',
|
||||
regime: 'Régimen'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user