示例#1
0
        public LastDoc getLastDocByType(DocType type)
        {
            try
            {
                LastDoc lastDoc = null;
                switch (type)
                {
                case DocType.Boleta:
                    lastDoc = _iBdConsulta1Repository.getLastBoleta();
                    break;

                case DocType.Factura:
                    lastDoc = _iBdConsulta1Repository.getLastFactura();
                    break;

                case DocType.NotaDeCreditoBoleta:
                    lastDoc = _iBdConsulta1Repository.getLastNotaDeCreditoBoleta();
                    break;

                case DocType.NotaDeCreditoFactura:
                    lastDoc = _iBdConsulta1Repository.getLastNotaDeCreditoFactura();
                    break;
                }
                _iLogService.Debug("Last " + type.ToString());
                _iLogService.Debug(lastDoc);
                return(lastDoc);
            }
            catch (Exception ex)
            {
                _iLogService.Error(ex.Message);
            }
            return(null);
        }
示例#2
0
        public List <Document> getNextDocumentsByTypeFrom(DocType type, LastDoc lastDoc)
        {
            try
            {
                List <Document> documents = null;
                switch (type)
                {
                case DocType.Boleta:
                    documents = _iBillingRepository.getNextBoletasFrom(lastDoc);
                    break;

                case DocType.Factura:
                    documents = _iBillingRepository.getNextFacturasFrom(lastDoc);
                    break;

                case DocType.NotaDeCreditoBoleta:
                    documents = _iBillingRepository.getNextNotasDeCreditoBoletaFrom(lastDoc);
                    break;

                case DocType.NotaDeCreditoFactura:
                    documents = _iBillingRepository.getNextNotasDeCreditoFacturaFrom(lastDoc);
                    break;
                }
                _iLogService.Debug("Next " + type.ToString());
                _iLogService.Debug("Count: " + documents.Count);
                _iLogService.Debug <Document>(documents);
                return(documents);
            }
            catch (Exception ex)
            {
                _iLogService.Error(ex.Message);
            }
            return(null);
        }
示例#3
0
        public void rubJob()
        {
            var docTypes = Enum.GetValues(typeof(DocType));

            List <IFSRegister> IFSRegisters = new List <IFSRegister>();
            List <Document>    documents    = new List <Document>();
            List <Auditory>    auditories   = new List <Auditory>();

            foreach (DocType docType in docTypes) // Factura, Boleta, NC-Factura, NC-Boleta
            {
                #region "Lectura de Documentos"
                LastDoc lastDoc = _IBdMostService.getLastDocByType(docType);
                // ↑ Obtenemos el último documento en TransDocumento
                documents = _IBdMostService.getNextDocumentsByTypeFrom(docType, lastDoc);
                // ↑ Obtenemos TODOS los documentos del N4, posteriores al último documento
                #endregion

                #region "¿Hay nuevos documentos?"
                if (!(documents.Count > 0))
                {
                    continue;
                }
                // ↑ Si no hay documentos, analizamos el siguiente tipo de documento
                #endregion

                #region "Obtiene H, I, P"
                List <LineH> Hlines = _IBdMostService.getLineHByTypeFor(docType, documents);
                List <LineI> ILines = _IBdMostService.getLineIByTypeFor(docType, documents);
                List <LineP> PLines = _IBdMostService.getLinePByTypeFor(docType, documents);
                #endregion

                #region "Escritura en CSV"
                IFSRegisters.AddRange(Hlines.Select(this._IMappingService.MapLineHToIFSFile).ToList <IFSRegister>());
                IFSRegisters.AddRange(ILines.Select(this._IMappingService.MapLineIToIFSFile).ToList <IFSRegister>());
                IFSRegisters.AddRange(PLines.Select(this._IMappingService.MapLinePToIFSFile).ToList <IFSRegister>());
                auditories.AddRange(Hlines.Select((h) => { return(this._IMappingService.MapLineHToAuditory(OriginType.Most, docType, h)); }));
                IFSRegisters = IFSRegisters.OrderBy(R => R.sorterB).ThenBy(R => R.sorterA).ToList <IFSRegister>();
                OperationResult result = _IIFSService.writeIFSRegistersByOriginType(OriginType.Most, docType, IFSRegisters);
                // ↑ Agrega las líneas al CSV creado (si no existe el archivo, lo crea)
                #endregion

                #region "Escritura en BD"
                _IBdMostService.saveLinesH(Hlines);             // ← TRAMA_IFS_H
                _IBdMostService.saveLinesI(ILines);             // ← TRAMA_IFS_I
                _IBdMostService.saveLinesP(PLines);             // ← TRAMA_IFS_P
                auditories = auditories.Select((a) =>
                {
                    a.des_fil = result[IFSKeys.FILE].ToString();
                    return(a);
                }).ToList <Auditory>();                   // ↑

                _IBdMostService.saveAuditory(auditories); // ← TransDocumento
                #endregion

                #region "Limpia Lista"
                IFSRegisters.Clear(); auditories.Clear();     // ← Limpia listas de la fecha
                #endregion
            }
        }
 public List <Document> getNextFacturasFrom(LastDoc lastDoc)
 {
     try
     {
         return(this.getNextDocumentsFrom(lastDoc, "[ifsDocsMost].[get_next_facturas_from]"));
     }
     catch (Exception ex)
     {
         _iLogService.Error(ex.Message);
     }
     return(null);
 }
 public List <Document> getNextNotasDeCreditoBoletaFrom(LastDoc lastDoc)
 {
     try
     {
         return(this.getNextDocumentsFrom(lastDoc, "[ifsDocsMost].[get_next_notas_credito_boleta_from]"));
     }
     catch (Exception ex)
     {
         _iLogService.Error(ex.Message);
     }
     return(null);
 }
 private List <Document> getNextDocumentsFrom(LastDoc lastDoc, string SPName)
 {
     try
     {
         List <Document> documents = new List <Document>();
         this.addInParameter("@nro_doc", lastDoc.ultimo_nro_doc);
         var result = this.executeSPWithResults(SPName);
         foreach (DataRow row in result.Rows)
         {
             documents.Add(new Document()
             {
                 final_nbr      = row["final_nbr"].ToString(),
                 finalized_date = DateTime.Parse(row["finalized_date"].ToString())
             });
         }
         return(documents);
     }
     catch (Exception ex)
     {
         _iLogService.Error(ex.Message);
     }
     return(null);
 }
示例#7
0
        public void runJob()
        {
            // var originTypes = Enum.GetValues(typeof(OriginType));
            var docTypes = Enum.GetValues(typeof(DocType));

            foreach (DocType docType in docTypes) // Factura, Boleta, NC-Factura, NC-Boleta
            // foreach (DocType docType in new DocType[]{DocType.Factura})
            {
                List <IFSRegister> IFSRegisters = new List <IFSRegister>();
                List <Document>    documents    = new List <Document>();
                List <Auditory>    auditories   = new List <Auditory>();

                #region "Zona de Lectura de Documentos"
                LastDoc lastDoc = _IBdConsulta1Service.getLastDocByType(docType);
                // ↑ Obtenemos el último documento en TransDocumento

                List <Document> totalDocuments = _IBillingService.getNextDocumentsByTypeFrom(docType, lastDoc);
                // ↑ Obtenemos TODOS los documentos del N4, posteriores al último documento
                #endregion

                List <DateTime> dates = totalDocuments.DistinctBy(d => d.finalized_date).Select(d => d.finalized_date).ToList <DateTime>();
                // ↑ Obtenemos las diferentes fechas de los documentos obtenidos (porque cada fecha tiene su tipo de cambio)

                foreach (DateTime date in dates)
                // ↑ Iteramos por cada fecha distinta de la lista de documentos
                {
                    _ILogService.Info(date.ToString("dd/MM/yyyy"));
                    // ↑ Escribe en el log
                    documents = totalDocuments.Where(d => d.finalized_date == date).ToList <Document>();

                    if (documents.Count > 0)
                    {
                        // Obtemos el tipo de cambio del día
                        CurrentExchange current_exchange = _IBillingService.getExchangeForDate(date);

                        List <LineH>        Hlines        = _IBillingService.getLineHByTypeFor(docType, documents, current_exchange);
                        List <LineOperator> linesOperator = _IN4Service.getLineOperatorsFor(Hlines);
                        List <OtherPayer>   otherPayers   = _IBillingService.getOtherPayersFor(
                            _IBdSolicitudServicioService.getRucAgenteByTypeFor(docType,
                                                                               Hlines.Where(h => h.other_payer == IFSKeys.PENDING_DATA).ToList <LineH>())
                            );
                        foreach (LineH lineH in Hlines)
                        {
                            lineH.creators_reference = linesOperator.Where(l => l.draft == lineH.draft_nbr)
                                                       .DefaultIfEmpty(new LineOperator()
                            {
                                draft = lineH.draft_nbr, line_operator = lineH.creators_reference
                            })
                                                       .First().line_operator;
                            lineH.other_payer = otherPayers.Where(p => p.invoice_no == lineH.invoice_no)
                                                .DefaultIfEmpty(new OtherPayer()
                            {
                                invoice_no = lineH.invoice_no, other_payer = lineH.other_payer
                            })
                                                .First().other_payer;
                        }

                        List <LineI> ILines = _IBillingService.getLineIByTypeFor(docType, documents, current_exchange);
                        List <LineP> PLines = _IBillingService.getLinePByTypeFor(docType, documents, current_exchange);
                        List <CodeA> codesA = _IBdConsulta1Service.getCodeAByTypeFor(docType, PLines);
                        foreach (LineP lineP in PLines)
                        {
                            lineP.code_a = codesA.Where(c => c.invoice_no == lineP.invoice_no)
                                           .DefaultIfEmpty(new CodeA()
                            {
                                invoice_no = lineP.invoice_no, code_a = lineP.code_a
                            })
                                           .First().code_a;
                        }

                        #region "Zona de Mapeo"
                        IFSRegisters.AddRange(Hlines.Select(this._IMappingService.MapLineHToIFSFile).ToList <IFSRegister>());

                        IFSRegisters.AddRange(ILines.Select(this._IMappingService.MapLineIToIFSFile).ToList <IFSRegister>());

                        IFSRegisters.AddRange(PLines.Select(this._IMappingService.MapLinePToIFSFile).ToList <IFSRegister>());

                        auditories.AddRange(Hlines.Select((h) => { return(this._IMappingService.MapLineHToAuditory(OriginType.N4, docType, h)); }));
                        #endregion

                        /* <GrabarBD> → Grabar en BD las líneas H, I y P */
                        _IBdConsulta1Service.saveLinesH(Hlines);        // TRAMA_IFS_H
                        _IBdConsulta1Service.saveLinesI(ILines);        // TRAMA_IFS_I
                        _IBdConsulta1Service.saveLinesP(PLines);        // TRAMA_IFS_P
                        /* </GrabarBD> */

                        IFSRegisters = IFSRegisters.OrderBy(R => R.sorterB).ThenBy(R => R.sorterA).ToList <IFSRegister>();

                        OperationResult result = _IIFSService.writeIFSRegistersByOriginType(OriginType.N4, docType, IFSRegisters);

                        auditories = auditories.Select((a) =>
                        {
                            a.des_fil = result[IFSKeys.FILE].ToString();
                            return(a);
                        }).ToList <Auditory>();                        // ↑

                        _IBdConsulta1Service.saveAuditory(auditories); // TransDocumento

                        IFSRegisters.Clear();
                        auditories.Clear();
                    }
                }
            }
        }