public async Task <ActionResult> VerSaldo([FromBody] int Codigo)
        {
            string      valorrespuesta = "";
            KardexViale _KardexVialeP  = new KardexViale();
            string      baseadress     = config.Value.urlbase;
            HttpClient  _client        = new HttpClient();

            _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
            var result = await _client.GetAsync(baseadress + "api/KardexViale/GetKardexByProductId/" + Codigo + "/" + Convert.ToInt32(HttpContext.Session.GetString("BranchId")));

            if (result.IsSuccessStatusCode)
            {
                valorrespuesta = await(result.Content.ReadAsStringAsync());
                _KardexVialeP  = JsonConvert.DeserializeObject <KardexViale>(valorrespuesta);
                if (_KardexVialeP == null)
                {
                    int Total = 0;
                    return(Ok(Total));
                }
                else
                {
                    return(Ok(_KardexVialeP.Total));
                }
            }
            else
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> Save([FromBody] KardexViale _CompanyInfoS)
        {
            try
            {
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                _CompanyInfoS.SaldoAnterior   = _CompanyInfoS.Total;
                _CompanyInfoS.Total           = _CompanyInfoS.Total + _CompanyInfoS.QuantityEntry;
                _CompanyInfoS.QuantityOut     = 0;
                _CompanyInfoS.KardexDate      = DateTime.Now;
                _CompanyInfoS.BranchId        = Convert.ToInt32(HttpContext.Session.GetString("BranchId"));
                _CompanyInfoS.UsuarioCreacion = HttpContext.Session.GetString("user");

                var result = await _client.PostAsJsonAsync(baseadress + "api/KardexViale/Insert", _CompanyInfoS);

                string valorrespuesta = "";
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta = await(result.Content.ReadAsStringAsync());
                    _CompanyInfoS  = JsonConvert.DeserializeObject <KardexViale>(valorrespuesta);
                    return(RedirectToAction("Menu", "CompanyInfo"));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error{ex.Message}"));
            }
            return(Ok(_CompanyInfoS));
        }
Example #3
0
        public async Task <ActionResult <ProformaInvoice> > Insert(ProformaInvoice _ProformaInvoice)
        {
            try
            {
                string valorrespuesta3 = "";
                // TODO: Add insert logic here
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                _ProformaInvoice.UsuarioCreacion     = HttpContext.Session.GetString("user");
                _ProformaInvoice.UsuarioModificacion = HttpContext.Session.GetString("user");
                var result = await _client.PostAsJsonAsync(baseadress + "api/ProformaInvoice/InsertWithInventory", _ProformaInvoice);

                string valorrespuesta = "";
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta   = await(result.Content.ReadAsStringAsync());
                    _ProformaInvoice = JsonConvert.DeserializeObject <ProformaInvoice>(valorrespuesta);

                    foreach (var item in _ProformaInvoice.ProformaInvoiceLine)
                    {
                        KardexViale kardexViale = new KardexViale();

                        var result3 = await _client.GetAsync(baseadress + "api/KardexViale/GetKardexByProductId/" + item.ProductId + "/" + Convert.ToInt32(HttpContext.Session.GetString("BranchId")));

                        if (result3.IsSuccessStatusCode)
                        {
                            valorrespuesta3                = await(result3.Content.ReadAsStringAsync());
                            kardexViale                    = JsonConvert.DeserializeObject <KardexViale>(valorrespuesta3);
                            kardexViale.QuantityOut        = item.Quantity;
                            kardexViale.QuantityEntry      = 0;
                            kardexViale.SaldoAnterior      = kardexViale.Total;
                            kardexViale.Total              = kardexViale.Total - item.Quantity;
                            kardexViale.Id                 = 0;
                            kardexViale.KardexDate         = DateTime.Now;
                            kardexViale.TypeOperationId    = 2;
                            kardexViale.TypeOperationName  = "Salida";
                            kardexViale.UsuarioCreacion    = HttpContext.Session.GetString("user");
                            kardexViale.BranchId           = Convert.ToInt32(HttpContext.Session.GetString("BranchId"));
                            kardexViale.TypeOfDocumentId   = 1;
                            kardexViale.TypeOfDocumentName = "Factura al Contado";
                            kardexViale.DocumentId         = _ProformaInvoice.ProformaId;
                            result3 = await _client.PostAsJsonAsync(baseadress + "api/KardexViale/Insert", kardexViale);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error{ex.Message}"));
            }
            return(Ok(_ProformaInvoice));
            // return new ObjectResult(new DataSourceResult { Data = new[] { _ProformaInvoice }, Total = 1 });
        }
        public async Task <ActionResult <InventoryTransfer> > Update(Int64 id, InventoryTransfer _Contrato)
        {
            try
            {
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));

                var result = await _client.PutAsJsonAsync(baseadress + "api/InventoryTransfer/Update", _Contrato);

                string valorrespuesta = "";
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta = await(result.Content.ReadAsStringAsync());
                    _Contrato      = JsonConvert.DeserializeObject <InventoryTransfer>(valorrespuesta);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error{ex.Message}"));
            }
            if (_Contrato.EstadoId == 8)
            {
                foreach (var item in _Contrato.InventoryTransferLines)
                {
                    KardexViale _KardexVialeP = new KardexViale();
                    string      baseadress    = config.Value.urlbase;
                    HttpClient  _client       = new HttpClient();
                    _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                    var result = await _client.GetAsync(baseadress + "api/KardexViale/GetKardexByProductId/" + item.ProductId + "/" + Convert.ToInt32(HttpContext.Session.GetString("BranchId")));

                    if (result.IsSuccessStatusCode)
                    {
                        string valorrespuesta = await(result.Content.ReadAsStringAsync());
                        _KardexVialeP                    = JsonConvert.DeserializeObject <KardexViale>(valorrespuesta);
                        _KardexVialeP.QuantityOut        = item.QtyStock;
                        _KardexVialeP.QuantityEntry      = 0;
                        _KardexVialeP.SaldoAnterior      = _KardexVialeP.Total;
                        _KardexVialeP.Total              = _KardexVialeP.Total - item.QtyStock;
                        _KardexVialeP.Id                 = 0;
                        _KardexVialeP.KardexDate         = DateTime.Now;
                        _KardexVialeP.TypeOperationId    = 2;
                        _KardexVialeP.TypeOperationName  = "Salida";
                        _KardexVialeP.UsuarioCreacion    = HttpContext.Session.GetString("user");
                        _KardexVialeP.TypeOfDocumentId   = 2;
                        _KardexVialeP.TypeOfDocumentName = "Transferencia de Inventario";
                        _KardexVialeP.DocumentId         = _Contrato.Id;
                        result = await _client.PostAsJsonAsync(baseadress + "api/KardexViale/Insert", _KardexVialeP);
                    }
                }
            }
            HttpContext.Session.SetString("listadoproductos", "");
            return(Ok(_Contrato));
        }
Example #5
0
        public async Task <IActionResult> GetKardexByProductId(int Id, int BranchId)
        {
            KardexViale Items = new KardexViale();

            try
            {
                Items = await _context.KardexViale.Where(q => q.ProducId == Id && q.BranchId == BranchId).OrderByDescending(o => o.KardexDate).FirstOrDefaultAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(await Task.Run(() => Ok(Items)));
        }
Example #6
0
        public async Task <ActionResult <KardexViale> > Insert([FromBody] KardexViale payload)
        {
            KardexViale KardexViale = payload;

            try
            {
                _context.KardexViale.Add(KardexViale);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(await Task.Run(() => Ok(KardexViale)));
        }
Example #7
0
        public async Task <ActionResult <PurchaseOrder> > Update([FromBody] PurchaseOrder _PurchaseOrder)
        {
            PurchaseOrder _PurchaseOrderq = _PurchaseOrder;

            try
            {
                _PurchaseOrderq = await _context.PurchaseOrder.Where(w => w.Id == _PurchaseOrder.Id).Include(b => b.Branch).FirstOrDefaultAsync();

                _context.Entry(_PurchaseOrderq).CurrentValues.SetValues((_PurchaseOrder));



                if (_PurchaseOrderq.EstadoId == 6)
                {
                    List <PurchaseOrderLine> purchaseOrderLines = await _context.PurchaseOrderLine.Where(w => w.PurchaseOrderId == _PurchaseOrderq.Id).ToListAsync();

                    foreach (var item in  purchaseOrderLines)
                    {
                        KardexViale kardexMax = await _context.KardexViale.Where(w => w.BranchId == _PurchaseOrderq.BranchId && w.ProducId == item.ProductId).OrderByDescending(d => d.KardexDate).FirstOrDefaultAsync();

                        KardexViale nuevokardex = new KardexViale();
                        if (kardexMax != null)
                        {
                            nuevokardex = new KardexViale {
                                BranchId           = Convert.ToInt64(_PurchaseOrderq.BranchId),
                                BranchName         = _PurchaseOrderq.Branch.BranchName,
                                KardexDate         = DateTime.Now,
                                ProducId           = item.ProductId == null?0:Convert.ToInt64(item.ProductId),
                                ProductName        = kardexMax.ProductName,
                                DocumentId         = _PurchaseOrderq.Id,
                                SaldoAnterior      = kardexMax.Total,
                                TypeOfDocumentId   = 5,
                                TypeOfDocumentName = "Orden de Compra",
                                TypeOperationId    = 1,
                                TypeOperationName  = "Entrada",
                                QuantityEntry      = Convert.ToDouble(item.QtyReceived),
                                QuantityOut        = 0,
                                Total            = Convert.ToDouble(kardexMax.Total + item.QtyReceived),
                                MinimumExistance = 1,
                                UsuarioCreacion  = _PurchaseOrderq.UsuarioModificacion,
                                WareHouseId      = 1,
                                WareHouseName    = " "
                            };
                        }
                        else
                        {
                            nuevokardex = new KardexViale
                            {
                                BranchId           = Convert.ToInt64(_PurchaseOrderq.BranchId),
                                BranchName         = _PurchaseOrderq.Branch.BranchName,
                                KardexDate         = DateTime.Now,
                                ProducId           = item.ProductId == null ? 0 : Convert.ToInt64(item.ProductId),
                                ProductName        = item.ProductDescription,
                                DocumentId         = _PurchaseOrderq.Id,
                                SaldoAnterior      = 0,
                                TypeOfDocumentId   = 5,
                                TypeOfDocumentName = "Orden de Compra",
                                TypeOperationId    = 1,
                                TypeOperationName  = "Entrada",
                                QuantityEntry      = Convert.ToDouble(item.QtyReceived),
                                QuantityOut        = 0,
                                Total            = Convert.ToDouble(item.QtyReceived),
                                MinimumExistance = 1,
                                UsuarioCreacion  = _PurchaseOrderq.UsuarioModificacion,
                                WareHouseId      = 1,
                                WareHouseName    = " "
                            };
                        }
                        _context.KardexViale.Add(nuevokardex);
                    }
                    await _context.SaveChangesAsync();
                }

                //_context.PurchaseOrder.Update(_PurchaseOrderq);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(await Task.Run(() => Ok(_PurchaseOrderq)));
        }
        public async Task <ActionResult <InventoryTransfer> > SaveInventoryTransfer([FromBody] InventoryTransferDTO _ContratoP)
        {
            string            valorrespuesta = "";
            InventoryTransfer _Contrato      = _ContratoP;

            foreach (var item in _Contrato.InventoryTransferLines)
            {
                if (item.CantidadRecibida == 0)
                {
                    item.CantidadRecibida = item.QtyStock;
                }
            }
            if (_ContratoP.EstadoId == 10)
            {
                foreach (var item in _Contrato.InventoryTransferLines)
                {
                    KardexViale _KardexVialeP = new KardexViale();
                    string      baseadress    = config.Value.urlbase;
                    HttpClient  _client       = new HttpClient();
                    _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                    var result = await _client.GetAsync(baseadress + "api/KardexViale/GetKardexByProductId/" + item.ProductId + "/" + Convert.ToInt32(HttpContext.Session.GetString("BranchId")));

                    if (result.IsSuccessStatusCode)
                    {
                        valorrespuesta = await(result.Content.ReadAsStringAsync());
                        _KardexVialeP  = JsonConvert.DeserializeObject <KardexViale>(valorrespuesta);
                        _KardexVialeP.QuantityEntry      = item.CantidadRecibida;
                        _KardexVialeP.QuantityOut        = 0;
                        _KardexVialeP.SaldoAnterior      = _KardexVialeP.Total;
                        _KardexVialeP.Total              = _KardexVialeP.Total + item.CantidadRecibida;
                        _KardexVialeP.Id                 = 0;
                        _KardexVialeP.KardexDate         = DateTime.Now;
                        _KardexVialeP.TypeOperationId    = 1;
                        _KardexVialeP.TypeOperationName  = "Entrada";
                        _KardexVialeP.UsuarioCreacion    = HttpContext.Session.GetString("user");
                        _KardexVialeP.TypeOfDocumentId   = 2;
                        _KardexVialeP.TypeOfDocumentName = "Transferencia de Inventario";
                        _KardexVialeP.DocumentId         = _ContratoP.Id;
                        result = await _client.PostAsJsonAsync(baseadress + "api/KardexViale/Insert", _KardexVialeP);
                    }
                }
            }
            try
            {
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                var result = await _client.GetAsync(baseadress + "api/InventoryTransfer/GetInventoryTransferById/" + _Contrato.Id);

                _Contrato.FechaModificacion   = DateTime.Now;
                _Contrato.UsuarioModificacion = HttpContext.Session.GetString("user");
                _Contrato.FechaCreacion       = DateTime.Now;
                _Contrato.UsuarioCreacion     = HttpContext.Session.GetString("user");
                //_Contrato.SourceBranchId = Convert.ToInt32(HttpContext.Session.GetString("BranchId"));
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta = await(result.Content.ReadAsStringAsync());
                    _Contrato      = JsonConvert.DeserializeObject <InventoryTransfer>(valorrespuesta);
                }

                if (_Contrato == null)
                {
                    _Contrato = new Models.InventoryTransfer();
                }

                if (_ContratoP.Id == 0)
                {
                    _ContratoP.FechaCreacion   = DateTime.Now;
                    _ContratoP.UsuarioCreacion = HttpContext.Session.GetString("user");
                    _ContratoP.SourceBranchId  = Convert.ToInt32(HttpContext.Session.GetString("BranchId"));
                    var insertresult = await Insert(_ContratoP);
                }
                else
                {
                    _ContratoP.FechaModificacion   = DateTime.Now;
                    _ContratoP.UsuarioModificacion = HttpContext.Session.GetString("user");
                    var updateresult = await Update(_Contrato.Id, _ContratoP);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                throw ex;
            }

            return(Json(_Contrato));
        }