|
|
@ -8,6 +8,7 @@ using Microsoft.VisualBasic; |
|
|
|
using MyFirstAPI.Interfaces; |
|
|
|
using MyFirstAPI.Interfaces; |
|
|
|
using MyFirstAPI.Models; |
|
|
|
using MyFirstAPI.Models; |
|
|
|
using System.ComponentModel; |
|
|
|
using System.ComponentModel; |
|
|
|
|
|
|
|
using System.Security.Cryptography.X509Certificates; |
|
|
|
|
|
|
|
|
|
|
|
namespace MyFirstAPI.Repositorio |
|
|
|
namespace MyFirstAPI.Repositorio |
|
|
|
{ |
|
|
|
{ |
|
|
@ -44,7 +45,7 @@ namespace MyFirstAPI.Repositorio |
|
|
|
/// METODO POST PARA ENVIAR DATOS EN DETALLES |
|
|
|
/// METODO POST PARA ENVIAR DATOS EN DETALLES |
|
|
|
public async Task Create (Detalles deta) |
|
|
|
public async Task Create (Detalles deta) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Detalles D = new Detalles(); |
|
|
|
//Detalles D = new Detalles(); |
|
|
|
var ProcedimientoalmacenadoInser = "SpInsert"; |
|
|
|
var ProcedimientoalmacenadoInser = "SpInsert"; |
|
|
|
using (var connection = new SqlConnection(cn.CadenaSQL())) |
|
|
|
using (var connection = new SqlConnection(cn.CadenaSQL())) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -58,54 +59,105 @@ namespace MyFirstAPI.Repositorio |
|
|
|
Cantidad = deta.Cantidad, |
|
|
|
Cantidad = deta.Cantidad, |
|
|
|
Precio = deta.Precio |
|
|
|
Precio = deta.Precio |
|
|
|
}, commandType: CommandType.StoredProcedure); |
|
|
|
}, commandType: CommandType.StoredProcedure); |
|
|
|
//var sql = @"insert into Detalles( IdFactura , Nfactura , ArticuloNumber , Articulo , Cantidad, Precio) |
|
|
|
|
|
|
|
// values ( @Idfactura , @Nfactura, @ArticuloNumber, @Articulo, @Cantidad, @Precio) |
|
|
|
|
|
|
|
// update Detalles set TotalId = Cantidad * Precio from factura where IdFactura = Idf |
|
|
|
|
|
|
|
// update FACTURA set Subtotal =(SELECT IIF(SUM(TotalId) IS NULL,0,SUM(TotalId) ) from Detalles where IdFactura = idf ) |
|
|
|
|
|
|
|
// update FACTURA set Total = ( SELECT IIF(SUM(TotalId) IS NULL ,0,SUM(TotalId + TotalID * 0.15 )) FROM Detalles WHERE IdFactura = Idf ) "; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// METODO PARA ENVIAR FACTURA |
|
|
|
|
|
|
|
|
|
|
|
public async Task CreateF(Factura fac) |
|
|
|
public async Task CreateF(Factura fac) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Factura F = new Factura(); |
|
|
|
|
|
|
|
var ProcedimientoAlmacenadoInserFactura = "SpInsertarFactura"; |
|
|
|
var ProcedimientoAlmacenadoInserFactura = "SpInsertarFactura"; |
|
|
|
using (var connection = new SqlConnection(cn.CadenaSQL())) |
|
|
|
using (var connection = new SqlConnection(cn.CadenaSQL())) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var Factura = await connection.ExecuteAsync(ProcedimientoAlmacenadoInserFactura, |
|
|
|
var Factura = await connection.ExecuteAsync(ProcedimientoAlmacenadoInserFactura, |
|
|
|
new |
|
|
|
new |
|
|
|
{ |
|
|
|
{ |
|
|
|
Id = F.Idf, |
|
|
|
Fecha = fac.Fecha, |
|
|
|
Fecha = F.Fecha, |
|
|
|
NumberFactura = fac.NumberFactura, |
|
|
|
NumberFactura = F.NumberFactura, |
|
|
|
MetodoPago = fac.Metodopago, |
|
|
|
MetodoPago = F.Metodopago, |
|
|
|
Dirrecion = fac.Dirreccion, |
|
|
|
Dirrecion = F.Dirreccion, |
|
|
|
Empresa = fac.Empresa, |
|
|
|
Empresa = F.Empresa, |
|
|
|
Subtotal = fac.Subtotal, |
|
|
|
Subtotal = F.Subtotal, |
|
|
|
Total = fac.Total, |
|
|
|
Total = F.Total, |
|
|
|
|
|
|
|
Activo = F.Activo, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, commandType: CommandType.StoredProcedure); |
|
|
|
}, commandType: CommandType.StoredProcedure); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class DateTimeConverter : JsonConverter<DateTime> |
|
|
|
|
|
|
|
{ |
|
|
|
//METODO PARA ACTUALIZAR DETALLES |
|
|
|
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
|
|
|
|
|
|
|
|
|
|
|
public async Task UPDATED (Detalles deta) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var ProcedimientoAlmacenadoUpdate = "SpUpdateDetalles"; |
|
|
|
|
|
|
|
using (var connection = new SqlConnection(cn.CadenaSQL())) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var Detalles = await connection.ExecuteAsync(ProcedimientoAlmacenadoUpdate, new |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Idfactura = deta.IdFactura, |
|
|
|
|
|
|
|
Nfactura = deta.Nfactura, |
|
|
|
|
|
|
|
ArticuloNumber = deta.ArticuloNumber, |
|
|
|
|
|
|
|
Articulo = deta.Articulo, |
|
|
|
|
|
|
|
Cantidad = deta.Cantidad, |
|
|
|
|
|
|
|
Precio = deta.Precio, |
|
|
|
|
|
|
|
Total =deta.TotalId |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, commandType: CommandType.StoredProcedure); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Metodo Para Actualizar Factura |
|
|
|
|
|
|
|
public async Task UpdateF (Factura fac) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// You should do some fool proof parsing here |
|
|
|
var ProcedimientoAlmacendadoUpdateF = "SpUpdateFactura"; |
|
|
|
var s = reader.GetString(); |
|
|
|
using (var connection = new SqlConnection(cn.CadenaSQL())) |
|
|
|
s = s.Replace("/Date(", "").Replace(")/", ""); |
|
|
|
{ |
|
|
|
long epoch = Convert.ToInt64(s); |
|
|
|
var Factura = await connection.ExecuteAsync(ProcedimientoAlmacendadoUpdateF, |
|
|
|
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(epoch); |
|
|
|
new |
|
|
|
return dateTimeOffset.UtcDateTime; |
|
|
|
{ |
|
|
|
|
|
|
|
Fecha = fac.Fecha, |
|
|
|
|
|
|
|
NumberFactura = fac.NumberFactura, |
|
|
|
|
|
|
|
MetodoPago = fac.Metodopago, |
|
|
|
|
|
|
|
Dirrecion = fac.Dirreccion, |
|
|
|
|
|
|
|
Empresa = fac.Empresa, |
|
|
|
|
|
|
|
Subtotal = fac.Subtotal, |
|
|
|
|
|
|
|
TotalF = fac.Total |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, commandType: CommandType.StoredProcedure); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// METODO PARA ELIMINAR DETALLES |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task Delete (int id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Do some conversion here |
|
|
|
|
|
|
|
|
|
|
|
var ProcedimientoAlmacenadoDelete = "SpEliminarDetalles"; |
|
|
|
|
|
|
|
using (var connection = new SqlConnection(cn.CadenaSQL())) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var detalles = await connection.ExecuteAsync(ProcedimientoAlmacenadoDelete , |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new { ArticuloNumber = id }, |
|
|
|
|
|
|
|
commandType: CommandType.StoredProcedure); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|