Example #1
0
        public async Task <IActionResult> Delete([FromBody] ProformaInvoice _ProformaInvoice)
        {
            ProformaInvoice _ProformaInvoiceq = new ProformaInvoice();

            try
            {
                _ProformaInvoiceq = _context.ProformaInvoice
                                    .Where(x => x.ProformaId == (Int64)_ProformaInvoice.ProformaId)
                                    .FirstOrDefault();

                _context.ProformaInvoice.Remove(_ProformaInvoiceq);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(_ProformaInvoiceq)));
        }
Example #2
0
        public async Task <ActionResult <ProformaInvoice> > Update([FromBody] ProformaInvoice _ProformaInvoice)
        {
            ProformaInvoice _ProformaInvoiceq = _ProformaInvoice;

            try
            {
                _ProformaInvoiceq = await(from c in _context.ProformaInvoice
                                          .Where(q => q.ProformaId == _ProformaInvoice.ProformaId)
                                          select c
                                          ).FirstOrDefaultAsync();

                _context.Entry(_ProformaInvoiceq).CurrentValues.SetValues((_ProformaInvoice));

                //_context.ProformaInvoice.Update(_ProformaInvoiceq);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(_ProformaInvoiceq)));
        }
Example #3
0
        public ActionResult Create(ProformaInvoice model)
        {
            try
            {
                model.OrganizationId = OrganizationId;
                model.CreatedDate    = System.DateTime.Now;
                model.CreatedBy      = UserID.ToString();
                string id = new ProformaInvoiceRepository().InsertProformaInvoice(model);
                if (id.Split('|')[0] != "0")
                {
                    TempData["success"] = "Saved successfully. Proforma Invoice No. is " + id.Split('|')[1];
                    //TempData["error"] = "";
                    return(RedirectToAction("PendingProforma", new { ProjectBased = model.isProjectBased }));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (SqlException sx)
            {
                TempData["error"] = "Some error occured while connecting to database. Please check your network connection and try again.|" + sx.Message;
            }
            catch (NullReferenceException nx)
            {
                TempData["error"] = "Some required data was missing. Please try again.|" + nx.Message;
            }
            catch (Exception ex)
            {
                TempData["error"] = "Some error occured. Please try again.|" + ex.Message;
            }
            TempData["success"] = "";


            return(View(model));
        }
Example #4
0
 public object UpdateProformaInvoiceEmailInfo(ProformaInvoice proformaInvoice)
 {
     return(_proforaInvoiceRepository.UpdateProformaInvoiceEmailInfo(proformaInvoice));
 }
Example #5
0
        public async Task <ActionResult <ProformaInvoice> > InsertWithInventory([FromBody] ProformaInvoiceDTO _ProformaInvoice)
        {
            ProformaInvoice _ProformaInvoiceq = _ProformaInvoice;


            try
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _context.ProformaInvoice.Add(_ProformaInvoiceq);
                        //await _context.SaveChangesAsync();

                        foreach (var item in _ProformaInvoice.ProformaInvoiceLine)
                        {
                            item.ProformaInvoiceId = _ProformaInvoice.ProformaId;


                            //KardexViale items2 = new KardexViale();

                            //items2 = await _context.KardexViale.Where(q => q.ProducId == item.ProductId && q.BranchId == _ProformaInvoice.BranchId).OrderByDescending(o => o.KardexDate).FirstOrDefaultAsync();

                            //KardexViale kardexViale = items2;

                            //kardexViale.QuantityOut = item.Quantity;
                            //kardexViale.QuantityEntry = 0;
                            //kardexViale.SaldoAnterior = kardexViale.Total;
                            //kardexViale.Total = kardexViale.Total - item.Quantity;
                            //kardexViale.Id = 0;
                            //kardexViale.KardexDate = DateTime.Now;
                            //kardexViale.TypeOperationId = 2;
                            //kardexViale.TypeOperationName = "Salida";
                            //kardexViale.UsuarioCreacion = _ProformaInvoice.UsuarioCreacion;
                            //kardexViale.BranchId = _ProformaInvoice.BranchId;
                            //kardexViale.TypeOfDocumentId = 1;
                            //kardexViale.TypeOfDocumentName = "Factura al Contado";
                            //kardexViale.DocumentId = item.ProformaInvoiceId;

                            _context.ProformaInvoiceLine.Add(item);
                            // _context.KardexViale.Add(kardexViale);
                        }

                        await _context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(_ProformaInvoiceq)));
        }
Example #6
0
        public static string ReplaceProformaInvoicePlaceHolder(string template, Customer customer, ProformaInvoice invoice, bool groupVisits)
        {
            double rivalsa    = 0;
            double prezPrieno = 1 - rivalsa;

            var therapist = GetTherapist();

            var pivaTxt = customer.Language == "german" ? "MwSt.-Nr: " : "Part.IVA : ";
            var cfTxt   = customer.Language == "german" ? "Steuercodex: " : "Cod.fisc.: ";

            template = template.Replace("{{ragione_sociale}}", therapist.FullName);
            template = template.Replace("{{indirizzo}}", customer.Language == "german" ? therapist.AddressDe.Replace("-", "<br>") : therapist.Address.Replace("-", "<br>"));
            template = template.Replace("{{partita_iva}}", therapist.TaxNumber);
            template = template.Replace("{{cf}}", therapist.FiscalCode);
            template = template.Replace("{{iban}}", therapist.Iban);

            template = template.Replace("{{invoice_number}}", invoice.Title);
            template = template.Replace("{{date}}", ((DateTime)invoice.Date).ToShortDateString());

            template = template.Replace("{{customer_name}}", customer.FullName);
            template = template.Replace("{{customer_address}}", $"{customer.Address?.Address_Column}");
            template = template.Replace("{{address_display}}", $"{(string.IsNullOrEmpty(customer.Address?.Address_Column) ? "none" : "inherit")}");
            template = template.Replace("{{customer_cap}}", $"{customer.Address?.Cap}");
            template = template.Replace("{{cap_display}}", $"{(string.IsNullOrEmpty(customer.Address?.Cap) ? "none" : "inherit")}");
            template = template.Replace("{{customer_city}}", $"{customer.Address?.City}");
            template = template.Replace("{{city_display}}", $"{(string.IsNullOrEmpty(customer.Address?.City) ? "none" : "inherit")}");
            template = template.Replace("{{customer_piva}}", string.IsNullOrEmpty(customer.Vat) ? "" : pivaTxt + customer.Vat);
            template = template.Replace("{{piva_display}}", $"{(string.IsNullOrEmpty(customer.Vat) ? "none" : "inherit")}");
            template = template.Replace("{{customer_cf}}", string.IsNullOrEmpty(customer.Fiscalcode) ? "" : cfTxt + customer.Fiscalcode);
            template = template.Replace("{{cf_display}}", $"{(string.IsNullOrEmpty(customer.Fiscalcode) ? "none" : "inherit")}");
            template = template.Replace("{{group_display}}", $"{(groupVisits ? "inline-block" : "none")}");

            var prestazioniHtml = @"<div style=""display: block; padding: 15px 0 15px 0px;"">";

            if (groupVisits)
            {
                var prestPriceList = new List <Tuple <string, double> >();
                foreach (var prestazioni in invoice.Visitsproformainvoiceidfkeys)
                {
                    var prestazioniHtm = "";
                    var treatments     = Helper.GetTratmensByIdS(prestazioni.Treatmentsvisitidfkeys.Select(x => x.TreatmentId).ToList(), customer.Language);
                    if (!treatments.Any())
                    {
                        treatments = Helper.GetATreatment(customer.Language);
                    }
                    foreach (var treatment in treatments)
                    {
                        prestazioniHtm += $@"<div>{treatment}</div>";
                    }

                    prestPriceList.Add(new Tuple <string, double>(prestazioniHtm, prestazioni.Price.Value));
                }

                var list = prestPriceList.Distinct();

                foreach (var el in list)
                {
                    var qt = prestPriceList.Count(pl => pl.Item1 == el.Item1);
                    prestazioniHtml += $@"<div style=""width: 350px; display:inline-block;""> {el.Item1}</div>";
                    prestazioniHtml += $@"<div style=""width: 100px; display:inline-block; text-align: right;""> {qt}</div>";
                    prestazioniHtml += $@"<div style=""width: 100px; display:inline-block; text-align: right;""> {el.Item2.ToString("#.00")} €</div>";
                    prestazioniHtml += $@"<div style=""width: 150px; text-align:right; display:inline-block;""> {(el.Item2 * qt).ToString("#.00")} €</div>";
                }
            }
            else
            {
                foreach (var prestazioni in invoice.Visitsproformainvoiceidfkeys)
                {
                    prestazioniHtml += $@"<div style=""width: 200px; display:inline-block;"">{((DateTime)prestazioni.Date).ToShortDateString()}</div>";

                    var treatments = Helper.GetTratmensByIdS(prestazioni.Treatmentsvisitidfkeys.Select(x => x.TreatmentId).ToList(), customer.Language);
                    if (!treatments.Any())
                    {
                        treatments = Helper.GetATreatment(customer.Language);
                    }
                    prestazioniHtml += $@"<div style=""display:inline-block; width: 350px; vertical-align: middle;"">";
                    foreach (var treatment in treatments)
                    {
                        prestazioniHtml += $@"<div>{treatment}</div>";
                    }
                    prestazioniHtml += $@"</div><div style=""width: 150px; text-align:right; display:inline-block;"">{(prestazioni.Price.Value * prezPrieno).ToString("#.00")} €</div>";
                }
            }

            prestazioniHtml += "</div>";
            template         = template.Replace("{{prestazioni}}", prestazioniHtml);

            var sconto       = invoice.Discount ?? 0;
            var total        = invoice.Visitsproformainvoiceidfkeys.Sum(x => x.Price * prezPrieno) - (sconto * prezPrieno);
            var bollo        = invoice.TaxStamp ? 2 : 0;
            var bolloDisplay = bollo > 0 ? "block" : "none";

            template = template.Replace("{{bollo}}", bollo.ToString());
            template = template.Replace("{{bollo_display}}", bolloDisplay.ToString());

            template = template.Replace("{{sconto}}", (sconto * -prezPrieno).ToString("#.00"));
            template = template.Replace("{{sconto_display}}", sconto > 0 ? "block" : "none");

            template = template.Replace("{{total}}", total.Value.ToString("#.00"));

            template = template.Replace("{{total_with_inps}}", (total + bollo).Value.ToString("#.00"));

            return(template);
        }
Example #7
0
        private void InvoiceCtrl_Load(object sender, EventArgs e)
        {
            bool invoiced = ProformaInvoice.Invoice != null;

            labelInviceName.Text = invoiced ? ProformaInvoice.Invoice.Title : "Non ancora fatturato";
            labelInviceDate.Text = invoiced ? $"del {((DateTime)ProformaInvoice.Invoice.Date).ToShortDateString()}" : "";

            textBoxDiscount.Text   = "0";
            labelName.Text         = ProformaInvoice.Title;
            labelProformaData.Text = $"del {((DateTime)ProformaInvoice.Date).ToShortDateString()}";

            var aVisit = ProformaInvoice.Visitsproformainvoiceidfkeys.FirstOrDefault();

            checkBoxGroup.Checked = ProformaInvoice.GroupVisits;

            if (_edit)
            {
                textBoxDiscount.ReadOnly = true;
                checkBox1.Enabled        = false;
                checkBoxPayed.Enabled    = true;

                if (invoiced)
                {
                    buttonSave.Visible = false;
                }
                else
                {
                    buttonSave.Text = "Genera Fattura";
                }
            }
            else
            {
                checkBoxPayed.Enabled = false;
            }

            if (aVisit != null)
            {
                using (var db = new Db.PhisioDB())
                {
                    var cust = db.Customers.LoadWith(e1 => e1.Address).LoadWith(e1 => e1.Pricelist).FirstOrDefault(x => x.Id == aVisit.Customer.Id);
                    aVisit.Customer = cust;
                }
                _customer = aVisit.Customer;
                labelCustomerName.Text = aVisit.Customer.FullName;
                labelFiscalCode.Text   = aVisit.Customer.Fiscalcode;
            }
            var y = 0;

            foreach (var visit in ProformaInvoice.Visitsproformainvoiceidfkeys)
            {
                Panel panelIn = new Panel();
                panelIn.Dock = DockStyle.Top;
                panel1.Controls.Add(panelIn);

                Label labelVisit = new Label();
                labelVisit.Location = new Point(0, 0);
                labelVisit.Font     = new System.Drawing.Font("Segoe UI Historic", 11.25F);
                labelVisit.Text     = $"•  {((DateTime)visit.Date).ToShortDateString()}";
                panelIn.Controls.Add(labelVisit);

                var treatments = Helper.Helper.GetTratmensByIdS(visit.Treatmentsvisitidfkeys.Select(x => x.TreatmentId).ToList(), aVisit.Customer.Language);

                if (treatments.Count == 0)
                {
                    treatments = Helper.Helper.GetATreatment(aVisit.Customer.Language);
                }


                Label lableTreatment = new Label();
                lableTreatment.Location = new Point((int)(panel1.Width * .2), 0);
                lableTreatment.AutoSize = false;
                lableTreatment.Font     = new System.Drawing.Font("Segoe UI Historic", 11.25F);
                lableTreatment.Text     = string.Join(Environment.NewLine, treatments);
                lableTreatment.Size     = new Size(panel1.Width - (int)(panel1.Width * .2) - 200, LineHeight * treatments.Count());
                lableTreatment.Padding  = new Padding(20, 0, 0, 0);
                panelIn.Controls.Add(lableTreatment);

                Label labelPrice = new Label();
                labelPrice.Location = new Point((int)(panel1.Width - 106), 0);
                labelPrice.Font     = new Font("Segoe UI Historic", 11.25F);
                labelPrice.Text     = $"{visit.Price} €";
                labelPrice.AutoSize = false;
                labelPrice.Anchor   = AnchorStyles.Top | AnchorStyles.Right;
                labelPrice.Size     = new Size(60, LineHeight * treatments.Count());
                panelIn.Controls.Add(labelPrice);

                /*
                 * Label labelPriceRivalsa = new Label();
                 * labelPriceRivalsa.Location = new Point((int)(panel1.Width - 106), 0);
                 * labelPriceRivalsa.Font = new Font("Segoe UI Historic", 11.25F);
                 * labelPriceRivalsa.Text = $"{((double)visit.Price * 1).ToString("#.00")} €";
                 * labelPriceRivalsa.AutoSize = false;
                 * labelPriceRivalsa.Size = new Size(60, LineHeight * treatments.Count());
                 * labelPriceRivalsa.Anchor = AnchorStyles.Top | AnchorStyles.Right;
                 * panelIn.Controls.Add(labelPriceRivalsa);
                 */
                panelIn.Location         = new Point(0, y);
                panelIn.Size             = new Size(panel1.Width, Math.Max(labelVisit.Height, lableTreatment.Height) + 10);
                checkBox1.Checked        = ProformaInvoice.TaxStamp;
                checkBoxContanti.Checked = ProformaInvoice.Contanti;

                y += panelIn.Height;
            }
            var total = CalculateTotal(false);

            labelRivalsaSconto.Text = "0";

            if (!ProformaInvoice.IsInitialized())
            {
                if (total > 77.47)
                {
                    checkBox1.Checked = true;
                }
                else
                {
                    checkBox1.Checked = false;
                }
            }

            labelTotal.Text = CalculateTotal(true).ToString();


            checkBoxPayed.Checked = ProformaInvoice.Payed;
            if (ProformaInvoice.Payed == true)
            {
                dateTimePickerPayed.Enabled = true;
                dateTimePickerPayed.Value   = (DateTime)ProformaInvoice.PayedDate;
                dateTimePickerPayed.Format  = DateTimePickerFormat.Short;
            }
            else
            {
                dateTimePickerPayed.Enabled      = false;
                dateTimePickerPayed.Format       = DateTimePickerFormat.Custom;
                dateTimePickerPayed.CustomFormat = " ";
            }

            _initialization = false;
        }
        public string InsertProformaInvoice(ProformaInvoice objProInvoice)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                IDbTransaction txn = connection.BeginTransaction();
                try
                {
                    var internalId = DatabaseCommonRepository.GetNewDocNo(connection, objProInvoice.OrganizationId, 6, true, txn);

                    objProInvoice.ProformaInvoiceRefNo = internalId;

                    string sql = @"
                    insert  into ProformaInvoice(ProformaInvoiceRefNo,ProformaInvoiceDate,SaleOrderId,SpecialRemarks,PaymentTerms,CreatedBy,CreatedDate,OrganizationId,isProjectBased)
                                   Values (@ProformaInvoiceRefNo,@ProformaInvoiceDate,@SaleOrderId,@SpecialRemarks,@PaymentTerms,@CreatedBy,@CreatedDate,@OrganizationId,@isProjectBased);
                    SELECT CAST(SCOPE_IDENTITY() as int) ProformaInvoiceId";



                    var id = connection.Query <int>(sql, objProInvoice, txn).Single();

                    foreach (ProformaInvoiceItem item in objProInvoice.Items)
                    {
                        item.ProformaInvoiceId = id;
                        new ProformaInvoiceItemRepository().InsertProformaInvoiceItem(item, connection, txn);
                    }

                    if (objProInvoice.isProjectBased == 1)
                    {
                        #region delete and inserting print description
                        try
                        {
                            sql = @"DELETE FROM PrintDescription WHERE SaleOrderId = " + objProInvoice.SaleOrderId;
                            connection.Execute(sql, transaction: txn);
                            sql = @"INSERT INTO PrintDescription (SaleOrderId, Description, UoM, Quantity, PriceEach, Amount, CreatedBy, CreatedDate, OrganizationId)
                                    VALUES (@SaleOrderId, @Description, @UoM, @Quantity, @PriceEach, @Amount, @CreatedBy, GETDATE(), @OrganizationId)";
                            foreach (var item in objProInvoice.PrintDescriptions)
                            {
                                if (item.Description == null)
                                {
                                    continue;
                                }
                                item.SaleOrderId    = objProInvoice.SaleOrderId;
                                item.CreatedBy      = int.Parse(objProInvoice.CreatedBy);
                                item.OrganizationId = objProInvoice.OrganizationId;
                                item.Amount         = (item.Quantity ?? 0) * item.PriceEach;
                                if (connection.Execute(sql, item, txn) <= 0)
                                {
                                    throw new Exception();
                                }
                            }
                        }
                        catch (Exception) { throw new Exception(); }
                        #endregion
                    }

                    InsertLoginHistory(dataConnection, objProInvoice.CreatedBy, "Create", "Proforma Invoice", id.ToString(), "0");
                    txn.Commit();

                    return(id + "|" + internalId);
                }
                catch (Exception)
                {
                    txn.Rollback();
                    return("0");
                }
            }
        }
        public async Task <ActionResult <ProformaInvoice> > Insert([FromBody] ProformaInvoiceDTO _ProformaInvoice)
        {
            ProformaInvoice _ProformaInvoiceq = new ProformaInvoice();

            try
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _context.ProformaInvoice.Add(_ProformaInvoice);
                        //await _context.SaveChangesAsync();

                        foreach (var item in _ProformaInvoice.ProformaInvoiceLine)
                        {
                            item.ProformaInvoiceId = _ProformaInvoice.ProformaId;
                            _context.ProformaInvoiceLine.Add(item);
                        }

                        _context.Entry(_ProformaInvoiceq).CurrentValues.SetValues((_ProformaInvoice));

                        await _context.SaveChangesAsync();

                        //   if(_ProformaInvoice.Identificador!="")
                        var calculo = await _context.InvoiceCalculation.Where(q => q.Identificador == _ProformaInvoice.Identificador).ToListAsync();

                        calculo.ForEach(q => q.ProformaInvoiceId = _ProformaInvoice.ProformaId);

                        await _context.SaveChangesAsync();


                        BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora
                        {
                            IdOperacion  = _ProformaInvoice.CustomerId,
                            DocType      = "ProformaInvoice",
                            ClaseInicial =
                                Newtonsoft.Json.JsonConvert.SerializeObject(_ProformaInvoice, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_ProformaInvoice, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            Accion              = "Insert",
                            FechaCreacion       = DateTime.Now,
                            FechaModificacion   = DateTime.Now,
                            UsuarioCreacion     = _ProformaInvoice.UsuarioCreacion,
                            UsuarioModificacion = _ProformaInvoice.UsuarioModificacion,
                            UsuarioEjecucion    = _ProformaInvoice.UsuarioModificacion,
                        });

                        await _context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
                //_ProformaInvoiceq = _ProformaInvoice;
                //_context.ProformaInvoice.Add(_ProformaInvoiceq);
                //await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(_ProformaInvoice)));
        }
        public async Task <ActionResult <ProformaInvoice> > InsertWithInventory([FromBody] ProformaInvoiceDTO _ProformaInvoice)
        {
            ProformaInvoice _ProformaInvoiceq = _ProformaInvoice;


            try
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _context.ProformaInvoice.Add(_ProformaInvoiceq);
                        //await _context.SaveChangesAsync();

                        foreach (var item in _ProformaInvoice.ProformaInvoiceLine)
                        {
                            item.ProformaInvoiceId = _ProformaInvoice.ProformaId;


                            //KardexViale items2 = new KardexViale();

                            //items2 = await _context.KardexViale.Where(q => q.ProducId == item.ProductId && q.BranchId == _ProformaInvoice.BranchId).OrderByDescending(o => o.KardexDate).FirstOrDefaultAsync();

                            //KardexViale kardexViale = items2;

                            //kardexViale.QuantityOut = item.Quantity;
                            //kardexViale.QuantityEntry = 0;
                            //kardexViale.SaldoAnterior = kardexViale.Total;
                            //kardexViale.Total = kardexViale.Total - item.Quantity;
                            //kardexViale.Id = 0;
                            //kardexViale.KardexDate = DateTime.Now;
                            //kardexViale.TypeOperationId = 2;
                            //kardexViale.TypeOperationName = "Salida";
                            //kardexViale.UsuarioCreacion = _ProformaInvoice.UsuarioCreacion;
                            //kardexViale.BranchId = _ProformaInvoice.BranchId;
                            //kardexViale.TypeOfDocumentId = 1;
                            //kardexViale.TypeOfDocumentName = "Factura al Contado";
                            //kardexViale.DocumentId = item.ProformaInvoiceId;

                            _context.ProformaInvoiceLine.Add(item);
                            // _context.KardexViale.Add(kardexViale);
                        }

                        await _context.SaveChangesAsync();


                        BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora
                        {
                            IdOperacion  = _ProformaInvoice.CustomerId,
                            DocType      = "ProformaInvoice",
                            ClaseInicial =
                                Newtonsoft.Json.JsonConvert.SerializeObject(_ProformaInvoice, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_ProformaInvoice, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            }),
                            Accion              = "Insert",
                            FechaCreacion       = DateTime.Now,
                            FechaModificacion   = DateTime.Now,
                            UsuarioCreacion     = _ProformaInvoice.UsuarioCreacion,
                            UsuarioModificacion = _ProformaInvoice.UsuarioModificacion,
                            UsuarioEjecucion    = _ProformaInvoice.UsuarioModificacion,
                        });

                        await _context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(_ProformaInvoiceq)));
        }