public void RegistrarPreventa(ConfirmarPreventa CP)
        {
            Caja C = new Caja();

            C.idCaja         = 0;
            C.idConcepto     = CP.idConcepto;
            C.Monto          = CP.Monto;
            C.TipoMovimiento = CP.TipoMovimiento == null ? "I":(string)CP.TipoMovimiento.ToString();
            C.UsuarioAlta    = 1;
            C.Descripcion    = CP.Descripcion;
            C.FechaAlta      = DateTime.Today;
            C.Estado         = "A";
            this.db.Caja.Add(C);
            this.save();

            foreach (PreventasAPagar PAP in CP.PreVentaDetalle)
            {
                Venta _v = this.db.Venta.Where(v1 => v1.idVenta == PAP.idVenta).FirstOrDefault();

                if (_v != null)
                {
                    if (_v.Total <= CP.Monto)
                    {
                        MedioPago mp = this.db.MedioPago.Where(mp1 => mp1.Descripcion == "Efectivo").FirstOrDefault();

                        if (mp != null)
                        {
                            _v.idMedioPago     = mp.idMedioPago;
                            db.Entry(_v).State = EntityState.Modified;
                            this.save();
                        }
                        CP.Monto = (decimal)CP.Monto - (decimal)_v.Total;
                    }
                    else
                    {
                        if (CP.Monto > 0)
                        {
                            _v.MontoPagado     = CP.Monto;
                            db.Entry(_v).State = EntityState.Modified;
                            this.save();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public HttpResponseMessage PostPreVenta([FromBody] ConfirmarPreventa cp)
        {
            HttpResponseMessage response;

            try
            {
                VentaService service = (VentaService) new VentaService().setDatabase(db);

                service.RegistrarPreventa(cp);


                response = this.getSuccessResponse(cp);
            }
            catch (Exception e)
            {
                response = this.getErrorResponse(e);
            }
            return(response);
        }