コード例 #1
0
        private static void MarkInvoiceAsMigrated(int invoiceId)
        {
            using (var renteco = new RentecoEntities())
            {
                var documentId     = Convert.ToDouble(invoiceId);
                var currentInvoice = renteco.FAC_FACTURAS.FirstOrDefault(x => x.FAC_Numero == documentId);
                if (currentInvoice != null)
                {
                    try
                    {
                        currentInvoice.MigradaSAP = MigratedFlag;

                        renteco.SaveChanges();
                        logger.Info("Factura #{0} Migrada a SAP Correctamente", invoiceId);
                    }
                    catch (Exception ex)
                    {
                        logger.Error("Problema marcando como migrada la factura #{0} {1}", invoiceId, ex.Message);
                    }
                }
                else
                {
                    logger.Error("Factura #{0} No fue posible marcarla como migrada, no se encontro", invoiceId);
                }
            }
        }
コード例 #2
0
        private static void MarkCreditNoteAsMigrated(int creditNoteId)
        {
            using (var renteco = new RentecoEntities())
            {
                var documentId        = Convert.ToDouble(creditNoteId);
                var currentCreditNote = renteco.CXC_RECIBOS.FirstOrDefault(x => x.CXC_Recibo.Equals(documentId));
                if (currentCreditNote != null)
                {
                    try
                    {
                        currentCreditNote.MigradaSAP = MigratedFlag == 1;

                        renteco.SaveChanges();
                        logger.Info("Nota de Credito #{0} Migrada a SAP Correctamente", creditNoteId);
                    }
                    catch (Exception ex)
                    {
                        logger.Error("Problema marcando como migrada la Nota de Credito #{0} - {1}", creditNoteId, ex.Message);
                    }
                }
                else
                {
                    logger.Error("Nota de Credito #{0} No fue posible marcarla como migrada, no se encontro", creditNoteId);
                }
            }
        }
コード例 #3
0
        private void LoadPendingCreditNotes()
        {
            var creditNotes = new List <CustomerInvoice>();
            var headers     = new List <SAP_CreditNoteMaster>();
            var details     = new List <SAP_CreditNoteDetail>();

            logger.Info("Cargando Notas de Credito");
            using (var renteco = new RentecoEntities())
            {
                headers = renteco.SAP_CreditNoteMaster.ToList();
                details = renteco.SAP_CreditNoteDetail.ToList();
            }

            foreach (var header in headers)
            {
                var customerInvoice = new CustomerInvoice
                {
                    SellerCode      = header.SlpCode == null ? 0 : (int)header.SlpCode,
                    DiscountPercent = header.DiscountPercent,
                    DocumentId      = (int)header.DocNum,
                    InvoiceType     = header.DocType,
                    DocumentType    = header.TipoDocumento,
                    CustomerCode    = header.CardCode,

                    Comments     = header.Comments,
                    PostingDate  = header.DocDate, // Fecha Contabilizacion
                    DueDate      = header.DocDate, // Fecha Vencimiento
                    DocumentDate = header.TaxDate, // Fecha Documento
                    DocCurrency  = header.DocCurrency,
                    NumAtCard    = header.NumAtCard.ToString(CultureInfo.InvariantCulture),
                    HandWritten  = header.HandWritten == "tYES",
                    ManualNumber = header.ManualNumber == "tYES"
                };

                // Invoice Details
                var invoiceDetails = details.Where(x => x.RecordKey.Equals(header.DocNum)).ToList();

                customerInvoice.ItemDetails = new List <ItemDetail>();
                foreach (var invoiceDetail in invoiceDetails)
                {
                    customerInvoice.ItemDetails.Add(new ItemDetail
                    {
                        TaxLiable       = false,
                        ItemCode        = "A9999999",
                        TaxCode         = invoiceDetail.TaxCode,
                        Currency        = invoiceDetail.Currency,
                        Quantity        = 1,
                        WarehouseCode   = 16,
                        Price           = invoiceDetail.LineTotal == null ? 0 : Convert.ToDecimal(invoiceDetail.LineTotal.Value),
                        DiscountPercent = invoiceDetail.DiscountPercent
                    });
                }

                creditNotes.Add(customerInvoice);
            }

            SavePendingCreditNotes(creditNotes);
        }
コード例 #4
0
        private void LoadPendingInvoices()
        {
            var invoces = new List <CustomerInvoice>();
            var headers = new List <SAP_LoadInvoiceMaster>();
            var details = new List <SAP_LoadInvoiceDetail>();

            logger.Info("Cargando Facturas");
            using (var renteco = new RentecoEntities())
            {
                headers = renteco.SAP_LoadInvoiceMaster.ToList();
                details = renteco.SAP_LoadInvoiceDetail.ToList();
            }

            foreach (var header in headers)
            {
                var customerInvoice = new CustomerInvoice
                {
                    SellerCode      = header.SalesPersonCode == null ? 0 : (int)header.SalesPersonCode,
                    DiscountPercent = header.DiscountPercent,
                    DocumentId      = (int)header.DocNum,
                    InvoiceType     = header.DocType,
                    DocumentType    = header.U_SCG_TipoDocumento,
                    CustomerCode    = header.CardCode,

                    Comments     = header.Comments,
                    PostingDate  = header.DocDate,
                    DueDate      = header.DocDueDate ?? DateTime.Today,
                    DocumentDate = header.TaxDate,
                    DocCurrency  = header.DocCurrency,
                    NumAtCard    = header.NumAtCard.ToString(CultureInfo.InvariantCulture),
                    HandWritten  = header.HandWritten == "tYES",
                    ManualNumber = header.ManualNumber == "tYES"
                };

                // Invoice Details
                var invoiceDetails = details.Where(x => x.RecordKey.Equals(header.DocNum)).ToList();

                customerInvoice.ItemDetails = new List <ItemDetail>();
                foreach (var invoiceDetail in invoiceDetails)
                {
                    string itemCode;
                    // Item code detection
                    switch (invoiceDetail.AccountCode)
                    {
                    case "_SYS00000000300":
                        itemCode = "A9999999";
                        break;

                    case "_SYS00000000304":
                        itemCode = "A9999998";
                        break;

                    case "_SYS00000000324":
                        itemCode = "A9999997";
                        break;

                    default:
                        itemCode = "A9999999";
                        break;
                    }


                    customerInvoice.ItemDetails.Add(new ItemDetail
                    {
                        TaxLiable       = false,
                        ItemCode        = itemCode,
                        TaxCode         = invoiceDetail.TaxCode,
                        Currency        = invoiceDetail.Currency,
                        Quantity        = 1,
                        WarehouseCode   = 16,
                        Price           = invoiceDetail.LineTotal == null? 0 : Convert.ToDecimal(invoiceDetail.LineTotal.Value),
                        DiscountPercent = invoiceDetail.DiscountPercent
                    });
                }

                invoces.Add(customerInvoice);
            }

            SavePendingInvoices(invoces);


            Task.Run(() => LoadPendingCreditNotes());
        }