예제 #1
0
        public async Task <ActionResult> closeOutreachReferal(string idperson)
        {
            try
            {
                temporal temp = db.temporals.Find(idperson);

                temp.serviceenddate = DateTime.Now;
                temp.servicestate   = "Closed";

                db.Entry(temp).State = EntityState.Modified;

                await db.SaveChangesAsync();

                return(new JsonResult
                {
                    Data = new
                    {
                        idperson = idperson,
                        servicestate = "مغلقة"
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            catch (Exception e)
            {
                return(new JsonResult {
                    Data = "error"
                });
            }
        }
예제 #2
0
        public async Task <ActionResult> EditReferal(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            temporal temporal = await db.temporals.FindAsync(id);

            if (temporal == null)
            {
                return(HttpNotFound());
            }
            var           user          = db.AspNetUsers.Find(User.Identity.GetUserId());
            List <string> serviceStates = new List <string>();

            serviceStates.Add("Pending");
            serviceStates.Add("In prgress");
            serviceStates.Add("Closed");

            List <string> referalstates = new List <string>();

            referalstates.Add("Pending");
            referalstates.Add("Approved");
            referalstates.Add("Rejected");
            referalstates.Add("OutReach");
            referalstates.Add("External");
            ViewBag.referalstate = new SelectList(referalstates, temporal.referalstate);
            ViewBag.servicestate = new SelectList(serviceStates, temporal.servicestate);

            ViewBag.referalReciver_FK = new SelectList(db.AspNetUsers.Where(u => u.AspNetRoles.Any(r => r.Name == "cmIOutReachTeam") && u.idcenter_FK == user.idcenter_FK), "Id", "UserName", temporal.referalreicver_FK);

            return(View(temporal));
        }
예제 #3
0
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            temporal temporal = await db.temporals.FindAsync(id);

            if (temporal == null)
            {
                return(HttpNotFound());
            }
            ViewBag.idcenter_FK = new SelectList(db.centers, "idcenter", "name", temporal.idcenter_FK);



            ViewBag.genderOptions      = gender;
            ViewBag.nationalityOptions = nationality;
            ViewBag.martialOptions     = martial;
            ViewBag.educationstate     = educationstate;
            ViewBag.relationtype       = relationtype;
            ViewBag.education          = education;



            return(View(temporal));
        }
예제 #4
0
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            temporal temporal = await db.temporals.FindAsync(id);

            db.temporals.Remove(temporal);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #5
0
        public async Task <ActionResult> Edit([Bind(Include = "idperson,fname,lname,fathername,mothername,birthday,birthplace,gender,nationality,martial,relationtype,onoffflag,education,educationstate,phone1,phone2,currentaddress,tempregistrationdate,idcenter_FK,formnumber,note,submittingdate,referalstate,referaldate,servicestate,servicestartdate,serviceenddate,referalreicver_FK,senderevalution,recieverevalution,outreachnote")] temporal temporal)
        {
            if (ModelState.IsValid)
            {
                temporal.servicestate    = "In prgress";
                db.Entry(temporal).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.idcenter_FK = new SelectList(db.centers, "idcenter", "name", temporal.idcenter_FK);
            return(View(temporal));
        }
예제 #6
0
        public async Task <ActionResult> Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            temporal temporal = await db.temporals.FindAsync(id);

            if (temporal == null)
            {
                return(HttpNotFound());
            }
            return(View(temporal));
        }
예제 #7
0
        public async Task <ActionResult> edit1([Bind(Include = "idperson,fname,lname,fathername,mothername,birthday,birthplace,gender,nationality,martial,relationtype,education,educationstate,phone1,phone2,currentaddress,tempregistrationdate,idcenter_FK,formnumber,note,submittingdate,referalstate,referaldate,servicestate,servicestartdate,serviceenddate,referalreicver_FK,senderevalution,recieverevalution,outreachnote,onoffflag,iduser_FK")] temporal referalperson)
        {
            if (ModelState.IsValid)
            {
                referalperson.referalstate     = "Pending";
                referalperson.servicestate     = "Pending";
                referalperson.referaldate      = DateTime.Now;
                referalperson.servicestartdate = null;
                referalperson.serviceenddate   = null;
                db.Entry(referalperson).State  = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("IndexOutReach", "referalpersons", ""));
            }

            return(View(referalperson));
        }
예제 #8
0
        public async Task <ActionResult> Create([Bind(Include = "idperson,fname,lname,fathername,mothername,birthday,birthplace,gender,nationality,martial,relationtype,onoffflag,education,educationstate,phone1,phone2,currentaddress,tempregistrationdate,idcenter_FK,formnumber,note,referalreicver_FK,senderevalution,outreachnote")] temporal temporal)
        {
            var user = db.AspNetUsers.Find(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                DateTime now = DateTime.Now;
                temporal.tempregistrationdate = now;

                temporal.iduser_FK   = User.Identity.GetUserId();
                temporal.idcenter_FK = db.AspNetUsers.SingleOrDefault(u => u.Id == temporal.iduser_FK).idcenter_FK;

                int?maxcenterform = db.temporals.Where(p => p.idcenter_FK == temporal.idcenter_FK).Max(p => p.formnumber) + 1;
                if (maxcenterform != null)
                {
                    temporal.formnumber = maxcenterform;
                }
                else
                {
                    temporal.formnumber = 1;
                }

                temporal.idperson = temporal.idcenter_FK.ToString() + temporal.formnumber.ToString();

                temporal.submittingdate = DateTime.Now;
                temporal.referalstate   = "Pending";
                temporal.servicestate   = "Pending";

                temporal.iduser_FK = User.Identity.GetUserId();

                db.temporals.Add(temporal);
                await db.SaveChangesAsync();

                // send notification for outreach
                string username = db.AspNetUsers.SingleOrDefault(u => u.Id == temporal.referalreicver_FK).UserName;
                NotificationHub.sendnotify(username, "added outreach");

                return(RedirectToAction("Index"));
            }

            ViewBag.idcenter_FK = new SelectList(db.centers, "idcenter", "name", temporal.idcenter_FK);
            return(View(temporal));
        }
        private void facturar_Click(object sender, EventArgs e)
        {
            //mostramos el detagrib
            dataGridView1.Visible = true;


            CheckForIllegalCrossThreadCalls = false;
            var formEsperar = new FormEsperar("Creando Facturas");
            var hilo        = Task.Factory.StartNew(() =>
            {
                generar.Enabled  = false;
                añadir.Enabled   = false;
                eliminar.Enabled = false;
                imprimir.Enabled = true;
                facturar.Enabled = false;
                //mostramos el detagrib
                //     dataGridView1.Visible = true;

                //cargamos los datos en el dgv.

                //**** calculamos el valor de la coluna numerador
                decimal numerofactura = 1;

                if (bd.Facturas.Any())
                {
                    // esto comprueba que las facturas corresponde a un año nuevo
                    //por lo que deberia reiniciar la numeracion de las facturas

                    // extrae el año de la ultima factuar
                    string yearfactura = (bd.Facturas.OrderByDescending(x => x.factfecha).First().factfecha.Split('/').Last());
                    // extrae el año del sistema
                    int fechaHoy = DateTime.Now.Year;

                    //compara ambos años, si el año de la factura es menor o igual al año del sistema
                    //continua con la numeracion actual, si no la reinicia.
                    if (fechaHoy <= Convert.ToInt16(yearfactura))
                    {
                        numerofactura = (bd.Facturas.OrderByDescending(x => x.factnumerofact).First().factnumerofact.Value) + 1;
                    }
                }


                List <temporal> lista = new List <temporal>();



                foreach (DataGridViewRow row in dgvTemporal.Rows)

                {
                    temporal datosapasar = new temporal();

                    datosapasar.tempnumerofactura = Convert.ToDecimal(numerofactura);
                    numerofactura++;
                    datosapasar.tempremesa           = Convert.ToString(row.Cells[0].Value);
                    datosapasar.temptipoiva          = Convert.ToDecimal(row.Cells[1].Value);
                    datosapasar.tempcod              = Convert.ToDecimal(row.Cells[2].Value);
                    datosapasar.tempfecha            = Convert.ToString(row.Cells[3].Value);
                    datosapasar.tempnombre           = Convert.ToString(row.Cells[4].Value);
                    datosapasar.tempconcepto1        = Convert.ToString(row.Cells[5].Value);
                    datosapasar.temptarifa           = Convert.ToDecimal(row.Cells[6].Value);
                    datosapasar.tempconcepto2        = Convert.ToString(row.Cells[7].Value);
                    datosapasar.temptarifa2          = Convert.ToDecimal(row.Cells[8].Value);
                    datosapasar.tempempleados        = Convert.ToDecimal(row.Cells[9].Value);
                    datosapasar.temppvempleados      = Convert.ToDecimal(row.Cells[10].Value);
                    datosapasar.templaboral          = Convert.ToDecimal(row.Cells[11].Value);
                    datosapasar.tempbase             = Convert.ToDecimal(row.Cells[12].Value);
                    datosapasar.tempiva              = Convert.ToDecimal(row.Cells[13].Value);
                    datosapasar.temptotal            = Convert.ToDecimal(row.Cells[14].Value);
                    datosapasar.temppormail          = Convert.ToBoolean(row.Cells[15].Value);
                    datosapasar.tempdoiciliado       = Convert.ToBoolean(row.Cells[16].Value);
                    datosapasar.tempcif              = Convert.ToString(row.Cells[17].Value);
                    datosapasar.tempdireccion        = Convert.ToString(row.Cells[18].Value);
                    datosapasar.templocalidad        = Convert.ToString(row.Cells[19].Value);
                    datosapasar.tempprovincia        = Convert.ToString(row.Cells[20].Value);
                    datosapasar.tempcp               = Convert.ToString(row.Cells[21].Value);
                    datosapasar.tempmail             = Convert.ToString(row.Cells[22].Value);
                    datosapasar.tempiban1            = Convert.ToString(row.Cells[23].Value);
                    datosapasar.tempiban2            = Convert.ToString(row.Cells[24].Value);
                    datosapasar.tempiban3            = Convert.ToString(row.Cells[25].Value);
                    datosapasar.tempiban4            = Convert.ToString(row.Cells[26].Value);
                    datosapasar.tempiban5            = Convert.ToString(row.Cells[27].Value);
                    datosapasar.tempiban6            = Convert.ToString(row.Cells[28].Value);
                    datosapasar.tempparadomiciliar   = Convert.ToBoolean(row.Cells[31].Value);
                    datosapasar.tempparaimprimir     = Convert.ToBoolean(row.Cells[32].Value);
                    datosapasar.tempparacontabilizar = Convert.ToBoolean(row.Cells[33].Value);



                    lista.Add(datosapasar);
                }

                dataGridView1.DataSource = lista.ToList();

                //ahora vamos a pasar los datos a la tabla de factura.

                //**** calculamos el valor de la coluna numerador
                //var ultimonumerador = bd.Facturas.OrderByDescending(x => x.factcontador).First().factcontador;


                decimal totalbaseremesa  = 0;
                decimal totalivaremesa   = 0;
                decimal totaltotalremesa = 0;
                string numeroremesa      = "";
                string fecharemesa       = "";
                int totaldocumentos      = 0;


                List <Facturas> facturasAGuardar = new List <Facturas>();

                //            List<datoslistadoreme> alistar = new List<datoslistadoreme>();

                foreach (var temp in lista)
                {
                    datoslistadoreme mylistado = new datoslistadoreme();
                    Facturas myFactura         = new Facturas();


                    myFactura.factbase1 = temp.tempbase;
                    //          mylistado.listimporte1 = temp.

                    myFactura.factnumerofact    = temp.tempnumerofactura;
                    mylistado.listnumerofactura = temp.tempnumerofactura.ToString();

                    myFactura.factremesa     = temp.tempremesa;
                    myFactura.factfecha      = temp.tempfecha;
                    myFactura.factcodcliente = temp.tempcod;
                    myFactura.factnombre     = temp.tempnombre;
                    mylistado.listnombre     = temp.tempnombre;

                    myFactura.factdireccion = temp.tempdireccion;
                    mylistado.listdireccion = temp.tempdireccion;

                    myFactura.factlocalidad = temp.templocalidad;
                    mylistado.listpoblacion = temp.templocalidad;

                    myFactura.factprovincia = temp.tempprovincia;
                    mylistado.listprovincia = temp.tempprovincia;

                    myFactura.factcp = temp.tempcp;
                    mylistado.listcp = temp.tempcp;

                    myFactura.factnif = temp.tempcif;
                    mylistado.listcif = temp.tempcif;


                    myFactura.factiban1     = temp.tempiban1;
                    myFactura.factiban2     = temp.tempiban2;
                    myFactura.factiban3     = temp.tempiban3;
                    myFactura.factiban4     = temp.tempiban4;
                    myFactura.factiban5     = temp.tempiban5;
                    myFactura.factiban6     = temp.tempiban6;
                    myFactura.factconcepto1 = temp.tempconcepto1;
                    mylistado.listconcepto1 = temp.tempconcepto1;

                    myFactura.factconcepto2 = temp.tempconcepto2;
                    mylistado.listconcepto2 = temp.tempconcepto2;

                    myFactura.factbase1    = temp.temptarifa;
                    mylistado.listimporte1 = temp.temptarifa;


                    mylistado.listbase = temp.tempbase;

                    myFactura.factconcepto2 = temp.tempconcepto2;
                    myFactura.factbase2     = temp.temptarifa2;
                    mylistado.listsuplidos  = temp.temptarifa2;

                    myFactura.factemleados     = temp.tempempleados;
                    mylistado.listnumempleados = temp.tempempleados;

                    myFactura.factprecioempleado   = temp.temppvempleados;
                    mylistado.listimporteempleados = temp.temppvempleados;

                    myFactura.factbaseempleado   = temp.templaboral;
                    mylistado.listtotalempleados = temp.templaboral;


                    myFactura.facttipoiva    = temp.temptipoiva;
                    myFactura.factimporteiva = temp.tempiva;
                    mylistado.listiva        = temp.tempiva;

                    myFactura.facttotalfactura = temp.temptotal;
                    mylistado.listtotal        = temp.temptotal;

                    myFactura.factpara_imprimir = true;
                    myFactura.factimpresa       = false;

                    if (temp.temppormail == true)
                    {
                        myFactura.factpara_imprimir = false;
                    }
                    myFactura.factpormail = temp.temppormail;
                    myFactura.factmail    = temp.tempmail;

                    myFactura.factparacontabilizar = temp.tempparacontabilizar;
                    myFactura.factcontabilizada    = false;
                    myFactura.factparadomiciliar   = temp.tempparadomiciliar;
                    myFactura.factdomiciliada      = false;

                    totalbaseremesa = totalbaseremesa + temp.tempbase;


                    totalivaremesa   = totalivaremesa + temp.tempiva;
                    totaltotalremesa = totaltotalremesa + temp.temptotal;

                    numeroremesa        = temp.tempremesa;
                    fecharemesa         = temp.tempfecha;
                    mylistado.listfecha = temp.tempfecha;


                    mylistado.listnombreemisor = bd.Propios.First().minombre;
                    // mylistado.listtotalremesa = totaltotalremesa;
                    mylistado.listnumeroremesa = numeroremesa;


                    Globales.anofactura = Convert.ToDateTime(temp.tempfecha);

                    facturasAGuardar.Add(myFactura);
                    alistar.Add(mylistado);
                }
                // pasamos los datos a la tabla facturacion y remesa
                bd.Facturas.AddRange(facturasAGuardar);
                bd.SaveChanges();


                var pasoremesa          = new Resilla();
                pasoremesa.remesanumero = numeroremesa;


                pasoremesa.remesafecha = fecharemesa;
                pasoremesa.remesatotal = Convert.ToDecimal(totaltotalremesa);
                // pasoremesa.remesaimpresa = false;
                pasoremesa.remesacontabilizada = false;



                // pasamos los datos a remesa
                bd.Resilla.Add(pasoremesa);

                //grabamos el total de la remesa en la clase a listar
                alistar.ToList().ForEach(x => x.listtotalremesa = totaltotalremesa);
                totaldocumentos = alistar.Count;
                alistar.ToList().ForEach(x => x.listtotaldocumentos = totaldocumentos);



                //ahora vamos a introducir el total de la remesa en las facturas.

                // Filtramos la tabla facuras por el numero de remesa
                var facturasfiltradas = bd.Facturas.Where(x => x.factremesa == numeroremesa);
                //Modificamos el campo
                facturasfiltradas.ToList().ForEach(f => f.facttotalremesa = totaltotalremesa);


                // Guardamos los cambios
                bd.SaveChanges();



                //desasctivamos los botones de generar, añadir y borrar
                añadir.Enabled   = false;
                generar.Enabled  = false;
                eliminar.Enabled = false;

                formEsperar.Close();
            });

            formEsperar.ShowDialog();

            hilo.Dispose();
            CheckForIllegalCrossThreadCalls = true;


            var form = new FormEsperar("Imprimiendo Facturas");

            CheckForIllegalCrossThreadCalls = false;
            var hilo2 = Task.Factory.StartNew(() =>
            {
                // cargamos la pantalla de listados de remesas
                for (int i = 0; i < alistar.Count; i++)
                {
                    Form3 nuevaForma = new Form3();
                    var dato         = alistar[i];


                    int year = Globales.anofactura.Year;


                    //nuevaForma.ExportarToPdf(dato, $"C:\\Equipo Martin\\facturas\\Nueva carpeta\\Test{i + 1}.pdf");
                    nuevaForma.ExportarToPdf(dato, $"C:\\ByMartin\\Clientes\\{dato.listnombre}\\Facturacion{year}\\Factura {dato.listnumerofactura}.pdf");
                }

                form.Close();
            });

            form.ShowDialog();

            hilo2.Dispose();
            CheckForIllegalCrossThreadCalls = true;



            // cargamos la pantalla de listados de remesas
            Form2 forma = new Form2(alistar);

            forma.Show();
        }