Пример #1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            NotaVenta notaVenta = await db.NotaVentas.FindAsync(id);

            db.NotaVentas.Remove(notaVenta);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <ActionResult> Edit([Bind(Include = "fecha,nombre,nit,total,notaVentaID,clienteID,vendedorID,cuotainicial,cantidadcouta,formapago")] NotaVenta notaVenta)
        {
            if (ModelState.IsValid)
            {
                db.Entry(notaVenta).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.clienteID  = new SelectList(db.clientes, "clienteID", "nombre", notaVenta.clienteID);
            ViewBag.vendedorID = new SelectList(db.Usuarios, "UsuarioID", "UsuarioNombre", notaVenta.vendedorID);
            return(View(notaVenta));
        }
Пример #3
0
        // GET: NotaVentas/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NotaVenta notaVenta = await db.NotaVentas.FindAsync(id);

            if (notaVenta == null)
            {
                return(HttpNotFound());
            }
            return(View(notaVenta));
        }
Пример #4
0
        // GET: NotaVentas/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NotaVenta notaVenta = await db.NotaVentas.FindAsync(id);

            if (notaVenta == null)
            {
                return(HttpNotFound());
            }
            ViewBag.clienteID  = new SelectList(db.clientes, "clienteID", "nombre", notaVenta.clienteID);
            ViewBag.vendedorID = new SelectList(db.Usuarios, "UsuarioID", "UsuarioNombre", notaVenta.vendedorID);
            return(View(notaVenta));
        }
Пример #5
0
        public async Task <ActionResult> Create(NotaVenta notaVenta, string list)
        {
            try
            {
                int i = db.NotaVentas.Count() + 1;
                notaVenta.notaVentaID = i;
                db.NotaVentas.Add(notaVenta);
                await db.SaveChangesAsync();

                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
                List <DetalleVenta> nota = js.Deserialize <List <DetalleVenta> >(list);
                foreach (var item in nota)
                {
                    int nt = db.DetalleVentas.Count();
                    item.detalleVentaID = nt + 1;
                    item.notaVentaID    = i;
                    db.DetalleVentas.Add(item);
                    await db.SaveChangesAsync();
                }
                if (notaVenta.formapago.Value)
                {
                    double   totalc = notaVenta.total.Value - notaVenta.cuotainicial.Value;
                    double   monto  = totalc / notaVenta.cantidadcouta.Value;
                    int      p      = db.planPagoes.Count() + 1;
                    planPago pl     = new planPago
                    {
                        planPagoID  = p,
                        totalVenta  = Convert.ToInt32(totalc),
                        ncuotas     = notaVenta.cantidadcouta,
                        fecha       = notaVenta.fecha,
                        monto       = Convert.ToInt32(monto),
                        notaVentaID = i
                    };
                    db.planPagoes.Add(pl);
                    await db.SaveChangesAsync();

                    int total = pl.totalVenta.Value;
                    int mon   = pl.monto.Value;

                    for (int j = 0; j < notaVenta.cantidadcouta; j++)
                    {
                        int      co = db.cuotas.Count() + 1;
                        DateTime dt = notaVenta.fecha.Value;
                        cuota    c  = new cuota()
                        {
                            cuotasID   = co,
                            saldo      = total - mon,
                            haber      = mon,
                            debe       = 0,
                            fecha      = dt.AddDays(30),
                            planPagoID = p,
                            pagado     = 0
                        };

                        db.cuotas.Add(c);
                        await db.SaveChangesAsync();
                    }
                }

                mensaje.Clear();
                mensaje.Add(Util.mensaje(Util.OK, Util.OKMENSAJE));
                return(Json(mensaje));
            }
            catch (Exception ex)
            {
                mensaje.Clear();
                mensaje.Add(Util.mensaje(Util.ERROR, ex.Message));
                return(Json(mensaje));
            }
        }
Пример #6
0
 public async void DeleteNV()
 {
     await NotaVenta.DeleteNvAsync(Conn);
 }
Пример #7
0
        public async Task <List <int> > InsertNv(List <Detalle> detalles)
        {
            BilingTypes = await BilingType.GetBilinTypesAsync();

            int        c       = 0;
            float      porcent = 0;
            TextInfo   ti      = CultureInfo.CurrentCulture.TextInfo;
            int        resultInsertNV;
            int        lastF  = 0;
            List <int> folios = new List <int>();

            foreach (Detalle item in detalles)
            {
                AuxCsv a = FileSii.GetAuxCvsFromFile(item); // INFORMATION UPDATE FROM CSV FILE.
                if (a != null)
                {
                    string name = ti.ToTitleCase(a.Name.ToLower());
                    item.Instruction.ParticipantDebtor.BusinessName      = name;
                    item.Instruction.ParticipantDebtor.DteReceptionEmail = a.Email;
                    item.Instruction.ParticipantDebtor.Name = item.Instruction.ParticipantDebtor.Name.ToUpper();
                }
                else
                {
                    StringLogging.AppendLine($"{item.Instruction.Id}\tUpdate email\t\tError in CSV file.");
                    continue;
                }
                Auxiliar aux = await Auxiliar.GetAuxiliarAsync(item.Instruction, Conn);

                Comuna comunaobj;
                if (aux == null) // INSERT NEW AUX.
                {
                    comunaobj = await Comuna.GetComunaFromInput(item, Conn, true);

                    aux = await Auxiliar.InsertAuxiliarAsync(item.Instruction, Conn, comunaobj);

                    if (aux != null)
                    {
                        StringLogging.AppendLine($"{item.Instruction.Id}\tAuxiliar Insert:\tOk: {item.Instruction.ParticipantDebtor.Rut} / {aux.DirAux} / {aux.ComAux}");
                    }
                    else
                    {
                        StringLogging.AppendLine($"{item.Instruction.Id}\tAuxiliar Error:\t {item.Instruction.ParticipantDebtor.Rut}");
                    }
                }
                else // UPDATE ALL AUX FROM LIST.
                {
                    if (aux.ComAux == null)
                    {
                        comunaobj = await Comuna.GetComunaFromInput(item, Conn, false);
                    }
                    else
                    {
                        comunaobj = new Comuna {
                            ComCod = aux.ComAux
                        };
                    }
                    if (await aux.UpdateAuxiliarAsync(item.Instruction, Conn, comunaobj) == 0)
                    {
                        StringLogging.AppendLine($"{item.Instruction.Id}\tAuxiliar Update:\tError Sql: {item.Instruction.ParticipantDebtor.Rut}");
                        continue;
                    }
                }
                // INSERT THE NV.
                lastF = await NotaVenta.GetLastNv(Conn);

                string prod = BilingTypes.FirstOrDefault(x => x.Id == item.Instruction.PaymentMatrix.BillingWindow.BillingType).DescriptionPrefix;
                resultInsertNV = await NotaVenta.InsertNvAsync(item.Instruction, lastF, prod, Conn);

                if (resultInsertNV == 0)
                {
                    StringLogging.AppendLine($"{item.Instruction.Id}\tInsert NV:\tError Sql");
                }
                else if (resultInsertNV == 1) // SUCCESS INSERT.
                {
                    if (item.Instruction.ParticipantNew == null)
                    {
                        StringLogging.AppendLine($"{item.Nro}-{item.Instruction.Id}\tInsert NV:\tF°: {lastF}");
                    }
                    else
                    {
                        StringLogging.AppendLine($"{item.Instruction.Id}\tInsert NV:\tF°: {lastF}  *Change RUT {item.Instruction.ParticipantDebtor.Rut} by {item.Instruction.ParticipantNew.Rut}");
                    }
                    folios.Add(lastF);
                }
                c++;
                porcent = (float)(100 * c) / detalles.Count;
                await ReportProgress(porcent, $"Inserting NV, wait please...   ({c}/{detalles.Count})  F°: {lastF})");
            }
            return(folios);
        }