public static Factura entidadADato(Entidades.Factura f)
 {
     Factura nuevo = new Factura();
     nuevo.fac_ced_cliente = f.Ced_cliente;
     nuevo.fac_ced_recep = f.Ced_recep;
     nuevo.fac_fecha = f.Fecha;
     nuevo.fac_iva = Convert.ToDecimal(f.Iva);
     nuevo.fac_n_factura = f.Numero;
     nuevo.fac_subtotal = Convert.ToDecimal(f.Subtotal);
     nuevo.fac_total = Convert.ToDecimal(f.Total);
     return nuevo;
 }
 public static Entidades.Factura datoAEntidad(Factura f)
 {
     Entidades.Factura retorno = new Entidades.Factura();
     retorno.Anulada = (bool)f.fac_anulada;
     retorno.Ced_cliente = f.fac_ced_cliente;
     retorno.Ced_recep = f.fac_ced_recep;
     retorno.Fecha = (DateTime)f.fac_fecha;
     retorno.Iva = (double)f.fac_iva;
     retorno.Numero = f.fac_n_factura;
     retorno.Subtotal = (double)f.fac_subtotal;
     retorno.Total = (double)f.fac_total;
     return retorno;
 }
Example #3
0
 internal static void ActualizarFactura(Factura facturaBD)
 {
     context.Entry(facturaBD).State = EntityState.Modified;
     context.SaveChanges();
 }
Example #4
0
        public static void Generar(Factura pFactura)
        {
            string SQL = string.Empty;

            SqlConnection  objConexion = null;
            SqlCommand     objCommandDocumentoComercial = null;
            SqlCommand     objCommandFactura            = null;
            SqlCommand     objCommandItem          = null;
            SqlCommand     objCommandFacturasItems = null;
            SqlTransaction objTransaction          = null;

            try
            {
                objConexion = new SqlConnection(BaseDatos.StringConexion);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            SQL = "INSERT INTO DocumentosComerciales (Numero, Fecha, Cliente, Direccion, CondicionIVA, CondicionVenta)";
            SQL = SQL + " " + "VALUES(@Numero, @Fecha, @Cliente, @Direccion, @CondicionIVA, @CondicionVenta)";
            SQL = SQL + ";" + "SELECT SCOPE_IDENTITY()";
            objCommandDocumentoComercial = new SqlCommand(SQL, objConexion);
            SqlParameter objNumero         = new SqlParameter("@Numero", pFactura.Numero);
            SqlParameter objFecha          = new SqlParameter("@Fecha", pFactura.Fecha.Date.ToString("yyyyMMdd"));
            SqlParameter objCliente        = new SqlParameter("@Cliente", pFactura.Cliente);
            SqlParameter objDireccion      = new SqlParameter("@Direccion", pFactura.Direccion);
            SqlParameter objCondicionIVA   = new SqlParameter("@CondicionIVA", pFactura.CondicionIVA);
            SqlParameter objCondicionVenta = new SqlParameter("@CondicionVenta", pFactura.CondicionVenta);

            objCommandDocumentoComercial.Parameters.Add(objNumero);
            objCommandDocumentoComercial.Parameters.Add(objFecha);
            objCommandDocumentoComercial.Parameters.Add(objCliente);
            objCommandDocumentoComercial.Parameters.Add(objDireccion);
            objCommandDocumentoComercial.Parameters.Add(objCondicionIVA);
            objCommandDocumentoComercial.Parameters.Add(objCondicionVenta);

            SQL = "INSERT INTO Facturas (Id_DocumentoComercial, Tipo)";
            SQL = SQL + " " + "VALUES(@Id_DocumentoComercial, @Tipo)";
            SQL = SQL + ";" + "SELECT SCOPE_IDENTITY()";
            objCommandFactura = new SqlCommand(SQL, objConexion);
            SqlParameter objId_DocumentoComercial = new SqlParameter("@Id_DocumentoComercial", null);
            SqlParameter objTipo = new SqlParameter("@Tipo", pFactura.Tipo);

            objCommandFactura.Parameters.Add(objId_DocumentoComercial);
            objCommandFactura.Parameters.Add(objTipo);

            SQL            = "INSERT INTO Items (Cantidad, Descripcion, PrecioUnitario, Importe)";
            SQL            = SQL + " " + "VALUES(@Cantidad, @Descripcion, @PrecioUnitario, @Importe)";
            SQL            = SQL + ";" + "SELECT SCOPE_IDENTITY()";
            objCommandItem = new SqlCommand(SQL, objConexion);
            SqlParameter objCantidad       = new SqlParameter("@Cantidad", null);
            SqlParameter objDescripcion    = new SqlParameter("@Descripcion", null);
            SqlParameter objPrecioUnitario = new SqlParameter("@PrecioUnitario", null);
            SqlParameter objImporte        = new SqlParameter("@Importe", null);

            objCommandItem.Parameters.Add(objCantidad);
            objCommandItem.Parameters.Add(objDescripcion);
            objCommandItem.Parameters.Add(objPrecioUnitario);
            objCommandItem.Parameters.Add(objImporte);

            SQL = "INSERT INTO FacturasItems (ID_Factura, Id_Item)";
            SQL = SQL + " " + "Values(@Id_Factura, @Id_Item)";
            objCommandFacturasItems = new SqlCommand(SQL, objConexion);
            SqlParameter objId_Factura = new SqlParameter("@Id_Factura", null);
            SqlParameter objId_Item    = new SqlParameter("@Id_item", null);

            objCommandFacturasItems.Parameters.Add(objId_Factura);
            objCommandFacturasItems.Parameters.Add(objId_Item);

            try
            {
                objConexion.Open();
                objTransaction = objConexion.BeginTransaction();
                objCommandDocumentoComercial.Transaction = objTransaction;
                objCommandFactura.Transaction            = objTransaction;
                objCommandItem.Transaction          = objTransaction;
                objCommandFacturasItems.Transaction = objTransaction;

                objId_DocumentoComercial.Value = Convert.ToInt32(objCommandDocumentoComercial.ExecuteScalar());
                objId_Factura.Value            = Convert.ToInt32(objCommandFactura.ExecuteScalar());

                foreach (Item Item in pFactura.Detalle)
                {
                    objCantidad.Value       = Item.Cantidad;
                    objDescripcion.Value    = Item.Descripcion;
                    objPrecioUnitario.Value = Item.PrecioUnitario;
                    objImporte.Value        = Item.Importe;
                    objId_Item.Value        = Convert.ToInt32(objCommandItem.ExecuteScalar());
                    objCommandFacturasItems.ExecuteNonQuery();
                }
                objTransaction.Commit();
            }
            catch (Exception ex)
            {
                objTransaction.Rollback();
                throw new Exception(ex.Message);
            }
            finally
            {
                objConexion.Close();
            }
        }
		private void detach_Factura(Factura entity)
		{
			this.SendPropertyChanging();
			entity.Cliente = null;
		}
		private void attach_Factura(Factura entity)
		{
			this.SendPropertyChanging();
			entity.Cliente = this;
		}
 partial void DeleteFactura(Factura instance);
 partial void UpdateFactura(Factura instance);
 partial void InsertFactura(Factura instance);