Example #1
0
        public void Crear_Factura(int iddetalle, int idcliente, int idproducto, int idestado, string fecha,
            string numero, string projDetailsSpecialistId, string montos)
        {
            List<int> ids = Convert(projDetailsSpecialistId);
            List<double> montosv = ConvertMontos(montos);

            DateTime f = DateTime.Parse(fecha);
            double montof = montosv.Sum();
            Invoice i = new Invoice();

            i.Client = db.Client.Find(idcliente);
            i.Product = db.Product.Find(idproducto);
            i.invoiceNum = numero;
            i.amount = montof;
            i.date = f;
            db.Invoice.Add(i);

            InvoiceStateSet issSet = new InvoiceStateSet
            {
                Invoice = i,
                State1 = db.State.Find(idestado),
                date = fecha,
                description = db.State.Find(idestado).name
            };
            db.InvoiceStateSet.Add(issSet);

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

            }
            //Restando del Detalle
            ProjectDetails pd = db.ProjectDetails.Find(iddetalle);
            pd.totalInvoiced = pd.totalInvoiced + montof;
            pd.toInvoice = pd.totalContracted - pd.totalInvoiced;
            //Atualizando proyecto
            pd.ProjSup.Project.totalnvoiced = decimal.Parse((pd.totalInvoiced + montof).ToString());
            pd.ProjSup.Project.toInvoiced = decimal.Parse((pd.totalContracted - pd.totalInvoiced).ToString());
            db.SaveChanges();
        }
Example #2
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();
        }