示例#1
0
        // POST: Invoices/Delete/5

        //Eliminar factura

        public void DeleteConfirmed(int id)
        {
            Invoice invoice = db.Invoice.Find(id);

            //Actualizando el Detalle
            ProjectDetails pd = db.ProjectDetails.Find(invoice.InvoiceProjectDetails.First().ProjectDetailsSpecialist.projectDetailsId);

            pd.totalInvoiced = pd.totalInvoiced - invoice.amount;
            pd.toInvoice     = pd.totalContracted - pd.totalInvoiced;
            //Actualizar Proyecto
            pd.ProjSup.Project.totalnvoiced = decimal.Parse((pd.totalInvoiced - invoice.amount).ToString());
            pd.ProjSup.Project.toInvoiced   = decimal.Parse((pd.totalContracted - pd.totalInvoiced).ToString());
            //Actualizar Estado del SUplemento

            Supplement s         = pd.ProjSup.Supplement;
            double     facturado = s.ProjSup.Sum(z => z.ProjectDetails.Sum(ss => ss.totalInvoiced));

            if (Math.Abs(facturado - decimal.ToDouble(s.amount)) < 0.1)
            {
                foreach (var state in s.StateCSupplement)
                {
                    state.state = false;
                }
                StateC           terminado        = db.StateC.Find(10);
                StateCSupplement stateCSupplement = new StateCSupplement
                {
                    stateCId    = terminado.stateCId,
                    Supplement  = s,
                    date        = DateTime.Now,
                    description = "Maximo de facturacion alcanzada",
                    state       = true
                };
                db.StateCSupplement.Add(stateCSupplement);
            }
            else
            {
                if (s.StateCSupplement.First(a => a.state).stateCId == 10)
                {
                    foreach (var state in s.StateCSupplement)
                    {
                        state.state = false;
                    }
                    StateC           iniciado         = db.StateC.Find(5);
                    StateCSupplement stateCSupplement = new StateCSupplement
                    {
                        stateCId    = iniciado.stateCId,
                        Supplement  = s,
                        date        = DateTime.Now,
                        description = "Estado cambiado dinamicamente x Ediacion de Facturas",
                        state       = true
                    };
                    db.StateCSupplement.Add(stateCSupplement);
                }
            }

            db.InvoiceProjectDetails.RemoveRange(invoice.InvoiceProjectDetails);
            db.InvoiceStateSet.RemoveRange(invoice.InvoiceStateSet);
            db.Invoice.Remove(invoice);
            db.SaveChanges();
        }
示例#2
0
        public ActionResult DeleteConfirmed(int id, bool idclient, int stateC, DateTime dateState, string descriptionState)
        {
            Supplement supplement = db.Supplement.Find(id);
            //int contractId = supplement.contractId;
            //List<ClientSupplement> listClientS =
            //                db.ClientSupplement.Where(c => c.supplementId == supplement.supplementId).ToList();
            //if (listClientS.Any())
            //{
            //    int count = listClientS.Count;
            //    for (int i = 0; i < count; i++)
            //    {
            //        db.ClientSupplement.Remove(listClientS[i]);
            //    }
            //}
            //List<StateCSupplement> listStateCSupplements =
            //                db.StateCSupplement.Where(s => s.supplementId == supplement.supplementId).ToList();
            //if (listStateCSupplements.Any())
            //{
            //    int count = listStateCSupplements.Count;
            //    for (int i = 0; i < count; i++)
            //    {
            //        db.StateCSupplement.Remove(listStateCSupplements[i]);
            //    }
            //}
            List <StateCSupplement> stateCSupplement =
                db.StateCSupplement.Where(st => st.supplementId == supplement.supplementId).ToList();
            bool found = false;

            foreach (StateCSupplement stateCs in stateCSupplement)
            {
                if (stateCs.stateCId == stateC)
                {
                    found               = true;
                    stateCs.state       = true;
                    stateCs.date        = dateState;
                    stateCs.description = descriptionState;
                }
                else
                {
                    stateCs.state = false;
                }
            }
            if (!found)
            {
                StateCSupplement _stateCSupplement = new StateCSupplement
                {
                    stateCId    = stateC,
                    Supplement  = supplement,
                    date        = dateState,
                    description = descriptionState,
                    state       = true
                };
                db.StateCSupplement.Add(_stateCSupplement);
            }


            db.SaveChanges();
            return(RedirectToAction("Index", new { id = supplement.contractId, idclient = idclient }));
        }
示例#3
0
        public ActionResult Edit([Bind(Include = "supplementId,number,name,contractId,amount,nom1,nom2,signedClient,productId,serviceId,signedProvider,comitteNumber,comitteDate,expirationDate")] Supplement supplement, int stateC, System.DateTime dateState, string descriptionState, string jsonClient, bool idclient)
        {
            if (ModelState.IsValid)
            {
                List <StateCSupplement> stateCSupplement =
                    db.StateCSupplement.Where(st => st.supplementId == supplement.supplementId).ToList();
                bool found = false;
                foreach (StateCSupplement stateCs in stateCSupplement)
                {
                    if (stateCs.stateCId == stateC)
                    {
                        found               = true;
                        stateCs.state       = true;
                        stateCs.date        = dateState;
                        stateCs.description = descriptionState;
                    }
                    else
                    {
                        stateCs.state = false;
                    }
                }
                if (!found)
                {
                    StateCSupplement _stateCSupplement = new StateCSupplement
                    {
                        stateCId    = stateC,
                        Supplement  = supplement,
                        date        = dateState,
                        description = descriptionState,
                        state       = true
                    };
                    db.StateCSupplement.Add(_stateCSupplement);
                }

                db.Entry(supplement).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = supplement.contractId, idclient = idclient }));
            }
            ViewBag.contractId    = new SelectList(db.Contract, "contractId", "number", supplement.contractId);
            ViewBag.productId     = new SelectList(db.Product, "productId", "name", supplement.productId);
            ViewBag.serviceId     = new SelectList(db.Service, "serviceId", "name", supplement.serviceId);
            ViewBag.idclientValue = idclient;
            return(View(supplement));
        }
示例#4
0
        public ActionResult CreateAlter(Int32 iddet, Int32 idclien, Int32 idprod)
        {
            ViewBag.clientId  = db.Client.Find(idclien);
            ViewBag.productId = db.Product.Find(idprod);
            ProjectDetails pd = db.ProjectDetails.Find(iddet);

            ViewBag.ammount = pd.toInvoice;
            ViewBag.state   = db.State.Where(p => p.type == "f" && p.name == "Propuesta").ToList()[0];
            ICollection <ProjectDetailsSpecialist> spec =
                db.ProjectDetailsSpecialist.Include(a => a.ProjSpecialist.Specialist)
                .Where(p => p.projectDetailsId == iddet)
                .ToList();


            StateCSupplement stateCSupplement = db.StateCSupplement.Where(st => st.supplementId == pd.ProjSup.supplementId && st.state).ToList().First();

            if (stateCSupplement.stateCId == 6 || stateCSupplement.stateCId == 7)
            {
                ViewBag.error += "Esta fase esta en un suplemento cancelado o detenido no se pueden realizar cambios.";
            }

            if (pd.toInvoice == 0)
            {
                ViewBag.error += " Esta fase ya se ha facturado por completo.";
            }
            if (spec.Count == 0)
            {
                ViewBag.error += "Esta fase no puede ser facturada. No tiene especialistas asignados";
            }


            else
            {
                ViewBag.spec = spec;
            }


            return(View());
        }
示例#5
0
 public int IsSupDetoCanc(Int32?idsup, int?proysupid, int?iddet)
 {
     if (iddet != null)
     {
         ProjectDetails   ed = db.ProjectDetails.Find(iddet);
         StateCSupplement stateCSupplement =
             db.StateCSupplement.Where(st => st.supplementId == ed.ProjSup.supplementId && st.state)
             .ToList()
             .First();
         if (stateCSupplement.stateCId == 6 || stateCSupplement.stateCId == 7)
         {
             return(1);
         }
         return(0);
     }
     if (proysupid != null)
     {
         ProjSup          pSup             = db.ProjSup.Find(proysupid);
         StateCSupplement stateCSupplement =
             db.StateCSupplement.Where(st => st.supplementId == pSup.supplementId && st.state).ToList().First();
         if (stateCSupplement.stateCId == 6 || stateCSupplement.stateCId == 7)
         {
             return(1);
         }
         return(0);
     }
     else
     {
         StateCSupplement stateCSupplement =
             db.StateCSupplement.Where(st => st.supplementId == idsup && st.state).ToList().First();
         if (stateCSupplement.stateCId == 6 || stateCSupplement.stateCId == 7)
         {
             return(1);
         }
         return(0);
     }
 }
示例#6
0
        public void Editar_Factura(int?idfact, int?iddet, string projDetailsSpecialistId, string montos, string oldm)
        {
            List <int>    ids      = Convert(projDetailsSpecialistId);
            List <double> montosv  = ConvertMontos(montos);
            Invoice       i        = db.Invoice.Find(idfact);
            double        montoant = i.amount;

            db.InvoiceProjectDetails.RemoveRange(i.InvoiceProjectDetails);


            for (int j = 0; j < ids.Count; j++)
            {
                InvoiceProjectDetails ipd = new InvoiceProjectDetails();
                ipd.projDetailsSpecialistId = ids[j];
                ipd.amount  = montosv[j];
                ipd.Invoice = i;
                i.InvoiceProjectDetails.Add(ipd);
            }
            double montof = montosv.Sum();

            i.amount = montof;
            //Actualizando el Detalle
            ProjectDetails pd = db.ProjectDetails.Find(iddet);

            pd.totalInvoiced = pd.totalInvoiced + montof - montoant;
            pd.toInvoice     = pd.totalContracted - pd.totalInvoiced;
            //Actualizar Proyecto
            pd.ProjSup.Project.totalnvoiced = decimal.Parse((pd.totalInvoiced + montof - montoant).ToString());
            pd.ProjSup.Project.toInvoiced   = decimal.Parse((pd.totalContracted - pd.totalInvoiced).ToString());
            //Actualizar Estado del SUplemento

            Supplement s         = pd.ProjSup.Supplement;
            double     facturado = s.ProjSup.Sum(z => z.ProjectDetails.Sum(ss => ss.totalInvoiced));

            if (Math.Abs(facturado - decimal.ToDouble(s.amount)) < 0.1)
            {
                foreach (var state in s.StateCSupplement)
                {
                    state.state = false;
                }
                StateC           terminado        = db.StateC.Find(10);
                StateCSupplement stateCSupplement = new StateCSupplement
                {
                    stateCId    = terminado.stateCId,
                    Supplement  = s,
                    date        = DateTime.Now,
                    description = "Maximo de facturacion alcanzada",
                    state       = true
                };
                db.StateCSupplement.Add(stateCSupplement);
            }
            else
            {
                if (s.StateCSupplement.First(a => a.state).stateCId == 10)
                {
                    foreach (var state in s.StateCSupplement)
                    {
                        state.state = false;
                    }
                    StateC           iniciado         = db.StateC.Find(5);
                    StateCSupplement stateCSupplement = new StateCSupplement
                    {
                        stateCId    = iniciado.stateCId,
                        Supplement  = s,
                        date        = DateTime.Now,
                        description = "Estado cambiado dinamicamente x Ediacion de Facturas",
                        state       = true
                    };
                    db.StateCSupplement.Add(stateCSupplement);
                }
            }

            /////////////////////////
            db.SaveChanges();
        }
示例#7
0
        public ActionResult Create([Bind(Include = "supplementId,number,name,contractId,amount,nom1,nom2,signedClient,productId,serviceId,signedProvider,comitteNumber,comitteDate,expirationDate")] Supplement supplement, int stateC, System.DateTime dateState, string descriptionState, string jsonClient, int contractId, bool idclient)
        {
            if (ModelState.IsValid)
            {
                supplement.nom1 = "tmpvalue";
                supplement.nom2 = "tmpvalue";
                StateCSupplement _stateCSupplement = new StateCSupplement
                {
                    stateCId    = stateC,
                    Supplement  = supplement,
                    date        = dateState,
                    description = descriptionState,
                    state       = true
                };
                db.StateCSupplement.Add(_stateCSupplement);

                List <string> stringData  = SetJson(jsonClient);
                decimal       amountValue = 0;
                if (stringData.Any())
                {
                    for (int i = 0; i < stringData.Count(); i += 3)
                    {
                        int id = int.Parse(stringData.ElementAt(i));

                        string   newAmount = stringData.ElementAt(i + 1);
                        string[] newValue  = newAmount.Split('.');
                        decimal  endValue  = 0;
                        if (newValue.Count() == 2)
                        {
                            decimal decens  = decimal.Parse(newValue[0]);
                            decimal centens = decimal.Parse(newValue[1]);
                            endValue = decens + (centens / 100);
                        }
                        else
                        {
                            endValue = decimal.Parse(newAmount);
                        }
                        string idproy = stringData.ElementAt(i + 2);



                        ClientSupplement clientSupplement = new ClientSupplement
                        {
                            clientId   = id,
                            Supplement = supplement,
                            amount     = endValue
                        };
                        amountValue += endValue;
                        if (clientSupplement != null)
                        {
                            db.ClientSupplement.Add(clientSupplement);
                        }
                        //creando los proyectos
                        Client client = db.Client.First(c => c.clientId == id);
                        if (client != null)
                        {
                            if (idproy != "*")
                            {
                                Project p       = db.Project.Find(int.Parse(idproy));
                                ProjSup projSup = new ProjSup
                                {
                                    Project    = p,
                                    Supplement = supplement,
                                    amount     = endValue
                                };
                                p.totalContracted += endValue;
                                p.toInvoiced      += endValue;
                                db.ProjSup.Add(projSup);
                            }
                            else
                            {
                                State   c       = db.State.Find(3);
                                Project project = new Project
                                {
                                    name            = supplement.number + " - " + client.name,
                                    clientId        = id,
                                    productId       = supplement.productId,
                                    advancePercent  = 0,
                                    totalContracted = endValue,
                                    toInvoiced      = endValue
                                };

                                db.Project.Add(project);
                                ProjectState ps = new ProjectState
                                {
                                    State1      = c,
                                    date        = DateTime.Now,
                                    description = "Proyecto creado automaticamente al crear Sumpelento",
                                    state       = true,
                                    Project     = project
                                };

                                db.ProjectState.Add(ps);
                                ProjSup projSup = new ProjSup
                                {
                                    Project    = project,
                                    Supplement = supplement,
                                    amount     = endValue
                                };
                                db.ProjSup.Add(projSup);
                            }
                        }
                    }
                }

                supplement.amount     = amountValue;
                supplement.contractId = contractId;

                db.Supplement.Add(supplement);
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = supplement.contractId, idclient = idclient }));
            }

            ViewBag.contractId = contractId;
            ViewBag.productId  = new SelectList(db.Product, "productId", "name", supplement.productId);
            ViewBag.serviceId  = new SelectList(db.Service, "serviceId", "name", supplement.serviceId);
            ViewBag.stateC     = db.StateC.Where(s => s.type == "Suplemento");
            Contract contract = db.Contract.First(c => c.contractId == contractId);

            ViewBag.clientFather  = db.Client.First(fa => fa.clientId == contract.clientId);
            ViewBag.clients       = db.Client.Where(cl => cl.fatherId == contract.clientId).ToList();
            ViewBag.idclientValue = idclient;
            return(View(supplement));
        }