public async Task <IActionResult> Save([FromBody] Common.Ac_Mtr_Agreement_Product_Info_Detail model) { try { var message = new Message(); message.BusinessLogic = configuration.GetValue <string>("AppSettings:BusinessLogic:Ac_Mtr_Agreement_Product_Info_Detail"); message.Operation = Operation.Save; message.Connection = configuration.GetValue <string>("ConnectionStrings:MEXPRESS_AC"); message.MessageInfo = model.SerializeObject(); using (var businessLgic = new ServiceManager()) { var result = await businessLgic.DoWork(message); if (result.Status == Status.Failed) { return(BadRequest(result.Result)); } var resultModel = result.DeSerializeObject <Common.Ac_Mtr_Agreement_Product_Info_Detail>(); return(Ok(resultModel)); } } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> List([FromBody] Common.Ac_Mtr_Agreement_Product_Info_Detail model) { try { var message = new Message(); message.BusinessLogic = configuration.GetValue <string>("AppSettings:BusinessLogic:Ac_Mtr_Agreement_Product_Info_Detail"); message.Operation = Operation.List; message.Connection = configuration.GetValue <string>("ConnectionStrings:MEXPRESS_AC"); message.MessageInfo = model.SerializeObject(); using (var businessLgic = new ServiceManager()) { var result = await businessLgic.DoWork(message); if (result.Status == Status.Failed) { return(BadRequest(result.Result)); } var list = result.DeSerializeObject <IEnumerable <Common.Ac_Mtr_Agreement_Product_Info_Detail> >(); // var dataSuccess = new // { // Data = list, // MessageResult = Backend.Common.Enum.Status.Success, // Message = string.Empty, // RegisterType = string.Empty // }; return(Ok(list)); } } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> CreatePdf([FromBody] Common.Ac_Mtr_Agreement_Product_Info_Detail model) { try { var message = new Message(); message.BusinessLogic = configuration.GetValue <string>("AppSettings:BusinessLogic:Ac_Mtr_Agreement_Product_Info_Detail"); message.Operation = Operation.List; message.Connection = configuration.GetValue <string>("ConnectionStrings:MEXPRESS_AC"); message.MessageInfo = model.SerializeObject(); using (var businessLgic = new ServiceManager()) { var result = await businessLgic.DoWork(message); if (result.Status == Status.Failed) { return(BadRequest(result.Result)); } var list = result.DeSerializeObject <IEnumerable <Common.Ac_Mtr_Agreement_Product_Info_Detail> >(); String output = ""; output = string.Format("{0}{1}", configuration.GetValue <string>("Files:RutaDestinoReporteAcuerdos"), "Informe_General_Acuerdo" + "_" + list.First().Name_Agree + ".pdf"); FileStream fs = new FileStream(output, FileMode.Create); Document document = new Document(iTextSharp.text.PageSize.A2, 20f, 20f, 0f, 40f); //30f, 20f, 0f, 40f PdfWriter pw = PdfWriter.GetInstance(document, fs); pw.PageEvent = new HeaderFooter(); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); Font fontVariedInformation = new Font(bf, 16, 0, BaseColor.BLACK); Font fontTextTittle = new Font(bf, 24, 1, new BaseColor(0, 173, 239)); Font fontTextColumnHeader = new Font(bf, 14, 1, BaseColor.WHITE); Font fontTextTable = new Font(bf, 12, 0, BaseColor.BLACK); //Tabla para insertar espacios en blanco PdfPTable pdfTableBlack = new PdfPTable(1); pdfTableBlack.DefaultCell.Border = 0; pdfTableBlack.WidthPercentage = 100f; pdfTableBlack.AddCell(new Phrase(" ")); // Insertar imagen en el documento: string imageURL = @"C:\inetpub\wwwroot\Archivos\Acuerdos\Reportes\Recursos\Header_Mexpress.png"; iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(imageURL); // Reescalar imagen: // png.ScaleToFit(1587f, 200f); //1587f, 270f // Agregar espacio antes de la imagen: png.SpacingBefore = 0f; //10f; // Agregar espacio despues de la imagen: png.SpacingAfter = 0f; //Alineacion de la imagen: png.Alignment = Element.ALIGN_CENTER; document.Open(); document.Add(png); document.Add(pdfTableBlack); //Tabla para insertar informacion varia del reporte: PdfPTable pdfTableVariedInformation = new PdfPTable(1); pdfTableVariedInformation.DefaultCell.Border = 0; pdfTableVariedInformation.WidthPercentage = 100f; pdfTableVariedInformation.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; PdfPCell cellInfo1 = new PdfPCell(new Paragraph("Nombre del acuerdo: " + list.First().Name_Agree, fontVariedInformation)); cellInfo1.Border = 0; cellInfo1.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo1); PdfPCell cellInfo2 = new PdfPCell(new Paragraph("Tipo de acuerdo: " + list.First().Agreement_Type_Name, fontVariedInformation)); cellInfo2.Border = 0; cellInfo2.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo2); PdfPCell cellInfo3 = new PdfPCell(new Paragraph("Proveedor: " + list.First().Provider_Name, fontVariedInformation)); cellInfo3.Border = 0; cellInfo3.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo3); PdfPCell cellInfo4 = new PdfPCell(new Paragraph("Fecha inicial del acuerdo: " + list.First().Date_Start, fontVariedInformation)); cellInfo4.Border = 0; cellInfo4.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo4); PdfPCell cellInfo5 = new PdfPCell(new Paragraph("Fecha de finalización del acuerdo: " + list.First().Date_Finish, fontVariedInformation)); cellInfo5.Border = 0; cellInfo5.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo5); PdfPCell cellInfo6 = new PdfPCell(new Paragraph("Correo: " + list.First().Email, fontVariedInformation)); cellInfo6.Border = 0; cellInfo6.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo6); PdfPCell cellInfo7 = new PdfPCell(new Paragraph("Monto máximo: " + list.First().String_Max_Amount, fontVariedInformation)); cellInfo7.Border = 0; cellInfo7.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo7); PdfPCell cellInfo8 = new PdfPCell(new Paragraph("Recuperado colones: " + list.First().String_Total_Recovery, fontVariedInformation)); cellInfo8.Border = 0; cellInfo8.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo8); PdfPCell cellInfo9 = new PdfPCell(new Paragraph("Recuperado dólares: " + list.First().String_Total_Recovery_Dollars, fontVariedInformation)); cellInfo9.Border = 0; cellInfo9.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo9); PdfPCell cellInfo10 = new PdfPCell(new Paragraph("Cuenta contable: " + list.First().Accounting_Account, fontVariedInformation)); cellInfo10.Border = 0; cellInfo10.ExtraParagraphSpace = 10; pdfTableVariedInformation.AddCell(cellInfo10); document.Add(pdfTableVariedInformation); document.Add(pdfTableBlack); //Tabla para insertar titulo del reporte: PdfPTable pdfTableTittle = new PdfPTable(1); pdfTableTittle.DefaultCell.Border = 0; pdfTableTittle.WidthPercentage = 100f; pdfTableTittle.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; Chunk cnkTittle = new Chunk("Lista de productos del acuerdo", fontTextTittle); cnkTittle.Font.Size = 16; pdfTableTittle.AddCell(new Phrase(cnkTittle)); document.Add(pdfTableTittle); document.Add(pdfTableBlack); //Tabla para mostrar la informacion de los productos del acuerdo PdfPTable table = new PdfPTable(11); table.WidthPercentage = 100f; //Creacion de la tabla string[] oddArray = new string[] { "Código", "Nombre artículo", "Tienda de venta", "Nombre vendedor", "Cliente", "Tipo de factura", "Nº Factura", "Serie", "Cantidad", "Costo", "Fecha de venta" }; foreach (string val in oddArray) { PdfPCell cell = new PdfPCell(); cell = new PdfPCell(new Paragraph(val, fontTextColumnHeader)); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = new BaseColor(31, 136, 176); table.AddCell(cell); } foreach (var item in list) { PdfPCell cell = new PdfPCell(); cell = new PdfPCell(new Paragraph(item.Product_Id, fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Product_Name, fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Name_Store, fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Name_Vendor, fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Client_Name, fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Name_Document, fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Bill_Id.ToString(), fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Product_Serie, fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Product_Quantity.ToString(), fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Product_Cost.ToString(), fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Paragraph(item.Date_Invoice.ToString(), fontTextTable)); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); } document.Add(table); document.Close(); var Url_Attachment = output.Replace(configuration.GetValue <string>("Files:FilePathReplace"), configuration.GetValue <string>("Files:FilePathDownload")); fs.Close(); return(Ok(Url_Attachment)); } } catch (Exception ex) { var exception = ex; var error = "Debe cerrar el pdf anterior antes de poder generar el siguiente"; return(BadRequest(error)); } }