Ejemplo n.º 1
0
        public ActionResult generarEdoCta(NominaXCDCModel model)
        {
            if (sesion == null)
            {
                sesion = SessionDB.start(Request, Response, false, db);
            }
            Debug.WriteLine("controller NominaXCDC");

            try
            {
                if (model.insertaEntregaContratosXEsquemaPago())
                {
                    Log.write(this, "Calculo Nomina: Insertar entrega de contratos", LOG.EDICION, "SQL:" + model.sql, sesion);

                    //if (model.calculaEstadocuentaXEsquemaPago())
                    if (model.calculaEstadocuentaXRegistroNomina(sesion.nickName))
                    {
                        Log.write(this, "Calculo Nomina: Cálculo estado de cuenta", LOG.EDICION, "SQL:" + model.sql, sesion);
                        return(Json(new { msg = Notification.Succes("Se ha generado la entrega de contratos y se han realizado los cálculos para el estado de cuenta.") }));
                    }
                    else
                    {
                        Log.write(this, "Calculo Nomina: Cálculo estado de cuenta", LOG.EDICION, "SQL:" + model.sql + ", IdPersona: " + model.PersonaID, sesion);
                        return(Json(new { msg = Notification.Error("Se ha realizado el registro de entrega de contratos, pero el cálculo de estado de cuenta no se generó. IdPersona: " + model.PersonaID) }));
                    }
                }
                else
                {
                    Log.write(this, "Calculo Nomina: Insertar entrega de contratos", LOG.EDICION, "SQL:" + model.sql, sesion);
                    return(Json(new { msg = Notification.Error("Hubo un error al generar la entrega de contratos") }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { msg = Notification.Error(e.Message) }));
            }
        }
        //#EXPORT EXCEL
        public void ExportExcel(string periodo = "", string nivel = "", string opcionPago = "", string campusVPDI = "")
        {
            NominaXCDCModel model = new NominaXCDCModel();

            if (sesion == null)
            {
                sesion = SessionDB.start(Request, Response, false, db);
            }

            try
            {
                System.Data.DataTable tbl = new System.Data.DataTable();
                tbl.Columns.Add("Periodo", typeof(string));
                tbl.Columns.Add("Contrato", typeof(string));
                tbl.Columns.Add("ID", typeof(string));
                tbl.Columns.Add("Nombre(s)", typeof(string));
                tbl.Columns.Add("Apellidos", typeof(string));
                tbl.Columns.Add("Origen", typeof(string));
                tbl.Columns.Add("Tipo de pago", typeof(string));
                tbl.Columns.Add("Centro de costos", typeof(string));
                tbl.Columns.Add("Importe", typeof(string));
                tbl.Columns.Add("Sede", typeof(string));

                var sql = " PERIODO = '" + periodo + "'";

                if (opcionPago != "" && opcionPago != null)
                {
                    switch (opcionPago)
                    {
                    case "A":
                        opcionPago = "ADI";
                        break;

                    case "H":
                        opcionPago = "HDI";
                        break;

                    default:
                        opcionPago = "-X1";     //No existe está opción de pago
                        break;
                    }
                }

                if (opcionPago != "" && opcionPago != null)
                {
                    sql += " AND CVE_TIPODEPAGO = '" + opcionPago + "'";
                }

                sql += " AND CVE_SEDE = '" + campusVPDI + "'";

                ResultSet res = db.getTable("SELECT * FROM QNominaXCDC WHERE " + sql + " ORDER BY IDSIU");

                while (res.Next())
                {
                    // Here we add five DataRows.
                    tbl.Rows.Add(res.Get("PERIODO"), res.Get("CONTRATO"), res.Get("IDSIU")
                                 , res.Get("NOMBRES"), res.Get("APELLIDOS"), res.Get("ORIGEN"), res.Get("TIPODEPAGO")
                                 , res.Get("CENTRODECOSOTOS"), res.Get("MONTOAPAGAR"), res.Get("CVE_SEDE"));
                }

                using (ExcelPackage pck = new ExcelPackage())
                {
                    //Create the worksheet
                    ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Nomina por centro de costos");

                    //Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
                    ws.Cells["A1"].LoadFromDataTable(tbl, true);
                    ws.Cells["A1:K1"].AutoFitColumns();

                    //Format the header for column 1-3
                    using (ExcelRange rng = ws.Cells["A1:K1"])
                    {
                        rng.Style.Font.Bold        = true;
                        rng.Style.Fill.PatternType = ExcelFillStyle.Solid;                      //Set Pattern for the background to Solid
                        rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));  //Set color to dark blue
                        rng.Style.Font.Color.SetColor(Color.White);
                    }

                    //Example how to Format Column 1 as numeric
                    using (ExcelRange col = ws.Cells[2, 1, 2 + tbl.Rows.Count, 1])
                    {
                        col.Style.Numberformat.Format = "#,##0.00";
                        col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
                    }

                    //Write it back to the client
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.AddHeader("content-disposition", "attachment;  filename=ImportarNominaXCDC.xlsx");
                    Response.BinaryWrite(pck.GetAsByteArray());
                }
                Log.write(this, "Start", LOG.CONSULTA, "Exporta nomina por centro de costos", sesion);
            }
            catch (Exception e)
            {
                ViewBag.Notification = Notification.Error(e.Message);
                Log.write(this, "Start", LOG.ERROR, "Exporta nomina por centro de costos" + e.Message, sesion);
            }
        }