示例#1
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);
     }
 }
示例#2
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));
        }