Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
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 });
        }
Ejemplo n.º 5
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();
        }