diff --git a/src/Components/Reportes/RptCorresponsalesTraficos.tsx b/src/Components/Reportes/RptCorresponsalesTraficos.tsx index 0d892c1..ff1227c 100644 --- a/src/Components/Reportes/RptCorresponsalesTraficos.tsx +++ b/src/Components/Reportes/RptCorresponsalesTraficos.tsx @@ -286,7 +286,6 @@ export default function RptCorresponsalesTraficos(props: IProps) { .then((response) => { setData(response.data) setFilteredData(response.data) - console.log(response.data) }) .catch((e: Error) => { setHeader('Error') diff --git a/src/Components/ReportesClientes/ReporteSemanalNewel.tsx b/src/Components/ReportesClientes/ReporteSemanalNewel.tsx new file mode 100644 index 0000000..2f0b722 --- /dev/null +++ b/src/Components/ReportesClientes/ReporteSemanalNewel.tsx @@ -0,0 +1,203 @@ +import React, {FC, useRef, useState} from "react"; +import { Button, Card, Col, Form, Row } from "react-bootstrap"; +import { MdCloudDownload, MdCloudUpload, MdDelete, MdDeleteForever } from "react-icons/md"; +import * as XLSX from 'xlsx' +import CTrafDataService from '../../Services/Corresponsalias/Corresponsales.Trafico.Services' +import { MsgInformativo } from "../Utils/Toast/msgInformativo"; +import { FaRegFileExcel } from "react-icons/fa"; +import IReporteSemanalNewell from "../../Interfaces/ReportesClientes/IReporteSemanalNewell"; + +export const ReporteSemanalNewell: React.FC<{}> = () => { + + const [Inicio, setInicio] = useState(currentDate(-7)) + const [Fin, setFin] = useState(currentDate(0)) + const hiddenFileInputRef = useRef(null); + const [show, setShowMsg] = useState(false) + const [header, setHeader] = useState('') + const [msg, setMsg] = useState('') + const [msgColor, setMsgColor] = useState('primary') + const [File, setFile] = useState(); + + function currentDate(days: number): string { + var today = new Date() + today.setDate(today.getDate() + days) + var dd = String(today.getDate()).padStart(2, '0') + var mm = String(today.getMonth() + 1).padStart(2, '0') + var yyyy = today.getFullYear() + return yyyy + '-' + mm + '-' + dd + } + + const readFile = () => { + if (!File) return; + + var ext = File!.name.substr(File!.name.lastIndexOf('.') + 1) + + if (!(ext === 'xls') && !(ext === 'xlsx')) { + setHeader('Error') + setMsg('Seleccione un archivo valido.') + setShowMsg(true) + return; + } + + const fileReader = new FileReader(); + fileReader.readAsArrayBuffer(File); + + fileReader.onload = async (e: any) => { + let encabezadosTemp = [//Se crean los encabezados temporales que se usaran mas adelante. + [ + 'aduana','patente','pedimento','fechaDeEntrada', 'fechaDePago', + 'valorComercialMxn','valorComercialDlls','valorAduana','clave','iva', + 'dta','prv','lgi','factura','tc','proveedor','taxId','producto', + 'gc', 'contenedor', 'cuentaDeGastos', 'razon', 'maniobras' + ] + ] + const bufferArray = e?.target.result + const oldWorkBook = XLSX.read(bufferArray, { type: "buffer" })//Se lee el archivo + const oldWorkSheetName = oldWorkBook.SheetNames[0]//se toma el nombre de la primer hoja del archivo + const oldWorkSheet = oldWorkBook.Sheets[oldWorkSheetName]//Se crea una referencia a la misma hoja + XLSX.utils.sheet_add_aoa(oldWorkSheet,encabezadosTemp,{origin:'A1'});//Se cambian los encabezados originales por los temporales para que las columnas coincidan con las propiedades del dto IReporteSemanalNewell + const rows = XLSX.utils.sheet_to_json(oldWorkSheet)//aqui es donde los renglones pasan a ser un array de objetos + //Se obtienen los datos faltantes del reporte + let newWorkBookData = await getDataByPedimento(rows); + await exportReporteSemanal(newWorkBookData); + } + } + + const getDataByPedimento = async (rows: IReporteSemanalNewell[]) => { + let data = [...rows]; + data=[]; + await Promise.all( + rows.map( async (row) => { + await CTrafDataService.GetByPedimento(row.pedimento).then((response) => { + row.gc = response.data.gc; + row.contenedor = response.data.contenedor; + row.cuentaDeGastos = response.data.cuentaDeGastos; + row.razon = response.data.razon; + row.maniobras = response.data.maniobras; + }) + data.push(row); + }) + ) + data = data.sort((a,b) => { + return +a.aduana - +b.aduana || +a.pedimento - +b.pedimento + }) + return data; + } + + const exportReporteSemanal = async (jsonData: any[]) => { + let encabezados = [ + [ + 'Aduana','Patente','Pedimento','Fecha de Entrada', 'Fecha de Pago', + 'Valor Comercial Mxn','Valor Comercial Dlls','Valor Aduana','Clave','Iva', + 'Dta','Prv','lgi','Factura','TC.','Proveedor','Tax Id','Producto', + 'GC', 'Contenedor', 'Cuenta de Gastos', 'Razon', 'Maniobras' + ] + ] + const newWorkBook = XLSX.utils.book_new() + const newWorkBookSheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet([]) + XLSX.utils.sheet_add_aoa(newWorkBookSheet, encabezados,{origin:'A1'}) + XLSX.utils.sheet_add_json(newWorkBookSheet, jsonData, { origin: 'A2', skipHeader: true }) + XLSX.utils.book_append_sheet(newWorkBook, newWorkBookSheet, 'Sheet1') + XLSX.writeFile(newWorkBook, `Reporte_Semanal-${Inicio}_${Fin}.xlsx`); + } + + return ( + <> + + + + + +

Reporte Semanal Newell

+ + + + + Inicio + setInicio(e.target.value)} + size='sm' + /> + + + + + Fin + setFin(e.target.value)} + size='sm' + /> + + + +
+ +
{hiddenFileInputRef.current?.click()}} + > + { + setFile(e.target.files[0]); + }} + /> + + { + !File ? <> + + Seleccione un archivo... + + : <> + + {File!.name} + + } + +
+
+ + + + +
+ + +
+ { + setShowMsg(false) + }} + /> + + ) +} \ No newline at end of file diff --git a/src/Interfaces/ReportesClientes/IReporteSemanalNewell.ts b/src/Interfaces/ReportesClientes/IReporteSemanalNewell.ts new file mode 100644 index 0000000..485eb62 --- /dev/null +++ b/src/Interfaces/ReportesClientes/IReporteSemanalNewell.ts @@ -0,0 +1,6 @@ +export default interface IReporteSemanalNewell{ + aduana: number; patente: number; pedimento: number; fechaDeEntrada: string|Date; fechaDePago: string|Date; + valorComercialMxn: number; valorComercialDlls: number; valorAduana: number; clave: string; iva: number; + dta: number; prv: number; lgi: number; factura: string; tc: number; proveedor: string; taxId: number; producto: string; + gc:number; contenedor: string; cuentaDeGastos: string; razon: string; maniobras: number; +} \ No newline at end of file diff --git a/src/Services/Corresponsalias/Corresponsales.Trafico.Services.ts b/src/Services/Corresponsalias/Corresponsales.Trafico.Services.ts index 847da15..f217a7a 100644 --- a/src/Services/Corresponsalias/Corresponsales.Trafico.Services.ts +++ b/src/Services/Corresponsalias/Corresponsales.Trafico.Services.ts @@ -6,11 +6,17 @@ import DTOTraficoCompleto from "../../DTO/Corresponsales/DTOTraficoCompleto"; import IRespuesta from "../../Interfaces/IRespuesta"; import ICorresponsalRectificacionHistorico from "../../Interfaces/Corresponsales/ICorresponsalRectificacionHistorico"; import DTORectificacionHistorico from "../../DTO/Corresponsales/DTORectificacionHistorico"; +import IReporteSemanalNewell from "../../Interfaces/ReportesClientes/IReporteSemanalNewell"; class Corresponsales_Trafico_DataService { GetAll(id: number) { return http.get(`/Corresponsalias/Traficos/Get?id=${id}`); } + + GetByPedimento(pedimento: number) { + return http.get(`/Corresponsalias/Traficos/GetByPedimento?pedimento=${pedimento}`); + } + Append(data: ICorresponsalTrafico) { return http.post("/Corresponsalias/Traficos/Append", data); } diff --git a/src/index.tsx b/src/index.tsx index d80515b..b2fd4bb 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -20,6 +20,7 @@ import ForgotPassword from './Components/Login/ForgotPassword' import PIN from './Components/Login/PIN' import UserControl from './Components/UserControl/UserControl' import ResetCredentials from './Components/Login/ResetCredentials' +import { ReporteSemanalNewell } from './Components/ReportesClientes/ReporteSemanalNewel' require (`./css/${process.env.REACT_APP_ENVIRONMENT}-home.css`) function PageNotFound() { @@ -71,6 +72,7 @@ root.render( /> } /> } /> + }/>