public bool DeleteShippingInstruction(ShippingInstruction shippingInstruction) { if (shippingInstruction == null) return false; _unitOfWork.ShippingInstructionRepository.Delete(shippingInstruction); _unitOfWork.Save(); return true; }
public APIResponse <ShippingInstruction> PostShippingInstruction([FromBody] ShippingInstruction ShippingInstruction) { Func <ServiceResponse <ShippingInstruction> > f = delegate { return(this._cs.CreateShippingInstruction(ShippingInstruction)); }; return(this.CastToAPIResponse(f)); }
public bool DeleteShippingInstruction(ShippingInstruction shippingInstruction) { if (shippingInstruction == null) { return(false); } _unitOfWork.ShippingInstructionRepository.Delete(shippingInstruction); _unitOfWork.Save(); return(true); }
public ServiceResponse <bool> DeleteShippingInstruction(ShippingInstruction c) { Func <bool> f = delegate { var ShippingInstruction_result = this._APIContext.ShippingInstructions.Remove(c); _APIContext.SaveChanges(); return(true); }; return(this.Execute(f)); }
public APIResponse <bool> DeleteShippingInstruction([FromRoute] long id) { Func <ServiceResponse <bool> > f = delegate { var c = new ShippingInstruction { Id = id }; return(this._cs.DeleteShippingInstruction(c)); }; return(this.CastToAPIResponse(f)); }
public int GetShippingInstruction(string siNumber) { var sINumber = _unitOfWork.ShippingInstructionRepository.FindBy(m => m.Value == siNumber).FirstOrDefault(); if (sINumber == null) { var shippingInstruction = new ShippingInstruction(); shippingInstruction.Value = siNumber; _unitOfWork.ShippingInstructionRepository.Add(shippingInstruction); _unitOfWork.Save(); return(shippingInstruction.ShippingInstructionID); } return(sINumber.ShippingInstructionID); }
public ShippingInstruction GetSiNumber(string siNumber) { var oldSiNumber = _unitOfWork.ShippingInstructionRepository.FindBy(m => m.Value == siNumber).SingleOrDefault(); if (oldSiNumber == null) { var shippingInstruction = new ShippingInstruction() { Value = siNumber }; _unitOfWork.ShippingInstructionRepository.Add(shippingInstruction); _unitOfWork.Save(); return(_unitOfWork.ShippingInstructionRepository.FindBy(m => m.Value == siNumber).SingleOrDefault()); } return(oldSiNumber); }
public ServiceResponse <ShippingInstruction> UpdateShippingInstruction(ShippingInstruction c) { c.PrintToken = c.PrintToken = Guid.NewGuid().ToString(); Func <ShippingInstruction> f = delegate { var si = _APIContext.ShippingInstructions.Where(col => col.Id == c.Id).Include(i => i.ShippingInstructionDetails).SingleOrDefault(); foreach (var item in si.ShippingInstructionDetails) { _APIContext.Entry(item).State = EntityState.Deleted; } foreach (var SIDetail in c.ShippingInstructionDetails) { if (SIDetail.Id != 0) { var DetailInDb = si.ShippingInstructionDetails.Single(e => e.Id == SIDetail.Id); _APIContext.Entry(DetailInDb).CurrentValues.SetValues(SIDetail); _APIContext.Entry(DetailInDb).State = EntityState.Modified; } else { SIDetail.Servicio = null; si.ShippingInstructionDetails.Add(SIDetail); } } _APIContext.Entry(si).CurrentValues.SetValues(c); _APIContext.Entry(si).State = EntityState.Modified; _APIContext.SaveChanges(); return(c); }; return(this.Execute(f)); }
/// <summary> /// Gets the SI number id With create. /// </summary> /// <param name="SiNumber">The si number.</param> /// <returns></returns> public ShippingInstruction GetSINumberIdWithCreate(string SiNumber) { var instruction = _unitOfWork.ShippingInstructionRepository.FindBy(t => t.Value.ToUpper() == SiNumber.ToUpper()). SingleOrDefault(); if (instruction != null) { return(instruction); } else { ShippingInstruction newInstruction = new ShippingInstruction() { Value = SiNumber.ToUpperInvariant() }; _unitOfWork.ShippingInstructionRepository.Add(newInstruction); _unitOfWork.Save(); return(newInstruction); } }
/// <summary> /// Gets the balance In Units for non-food items. /// </summary> /// <param name="hubID">The hub ID.</param> /// <param name="commodityId">The commodity id.</param> /// <param name="shippingInstructionID">The shipping instruction ID.</param> /// <returns></returns> public SIBalance GetBalanceInUnit(int hubID, int commodityId, int shippingInstructionID) { SIBalance siBalance = new SIBalance(); siBalance.Commodity = _unitOfWork.CommodityRepository.FindById(commodityId).Name; siBalance.SINumberID = shippingInstructionID; ProjectCode projectCode = GetProjectCodeForSI(hubID, commodityId, shippingInstructionID); siBalance.ProjectCodeID = projectCode.ProjectCodeID; siBalance.Project = projectCode.Value; ShippingInstruction si = _unitOfWork.ShippingInstructionRepository.FindById(shippingInstructionID); var availableBalance = (from v in si.Transactions where v.LedgerID == Cats.Models.Ledger.Constants.GOODS_ON_HAND_UNCOMMITED && commodityId == v.ParentCommodityID select v.QuantityInUnit).DefaultIfEmpty().Sum(); var firstOrDefaultans = si.Transactions.FirstOrDefault(); if (firstOrDefaultans != null) { siBalance.Program = firstOrDefaultans.Program.Name; } siBalance.AvailableBalance = availableBalance; siBalance.SINumber = si.Value; // convert the amount which is in Quintals to ... MT siBalance.CommitedToFDP = (from v in si.DispatchAllocations where v.IsClosed == false && v.CommodityID == commodityId select v.AmountInUnit).DefaultIfEmpty().Sum(); //select v.Amount / 10).DefaultIfEmpty().Sum(); var utilGetDispatchedAllocationFromSiResult = _unitOfWork.ReportRepository.util_GetDispatchedAllocationFromSI(hubID, shippingInstructionID).FirstOrDefault(); if (utilGetDispatchedAllocationFromSiResult != null) { if (utilGetDispatchedAllocationFromSiResult.QuantityInUnit != null) { siBalance.CommitedToFDP -= utilGetDispatchedAllocationFromSiResult.QuantityInUnit.Value; } } siBalance.CommitedToOthers = (from v in si.OtherDispatchAllocations where v.IsClosed == false && v.CommodityID == commodityId select v.QuantityInUnit).DefaultIfEmpty().Sum(); decimal ReaminingExpectedReceipts = 0; //TODO:After Implementing ReceiptAllocationService please return here //var rAll = repository.ReceiptAllocation.FindBySINumber(siBalance.SINumber) // .Where( // p => // { // if (p.Commodity.ParentID == null) // return p.CommodityID == commodityId; // else // return p.Commodity.ParentID == commodityId; // } // ) // .Where(q => q.IsClosed == false); //foreach (var receiptAllocation in rAll) //{ // decimal Qunt = 0; // if (receiptAllocation.QuantityInUnit != null) // Qunt = receiptAllocation.QuantityInUnit.Value; // ReaminingExpectedReceipts = ReaminingExpectedReceipts + // (Qunt // - // repository.ReceiptAllocation.GetReceivedAlreadyInUnit(receiptAllocation)); //} siBalance.ReaminingExpectedReceipts = ReaminingExpectedReceipts; siBalance.Dispatchable = siBalance.AvailableBalance - (siBalance.CommitedToFDP + siBalance.CommitedToOthers) + ReaminingExpectedReceipts; siBalance.TotalDispatchable = siBalance.AvailableBalance - (siBalance.CommitedToFDP + siBalance.CommitedToOthers); return(siBalance); }
public APIResponse <ShippingInstruction> PutShippingInstruction([FromRoute] string id, [FromBody] ShippingInstruction ShippingInstruction) { Func <ServiceResponse <ShippingInstruction> > f = delegate { return(this._cs.UpdateShippingInstruction(ShippingInstruction)); }; return(this.CastToAPIResponse(f)); }
public List <SIBalance> GetSIBalanceForCommodityInUnit(int hubId, int CommodityId) { var list = (from RA in _unitOfWork.ReceiptAllocationRepository.Get() where (RA.IsClosed == false && RA.HubID == hubId) && (RA.Commodity.ParentID == CommodityId || RA.CommodityID == CommodityId) group RA by new { RA.SINumber, RA.ProjectNumber, RA.Commodity, RA.Program } into si select new SIBalance { AvailableBalance = 0, CommitedToFDP = 0, CommitedToOthers = 0, Commodity = si.Key.Commodity.Name, Dispatchable = si.Sum(p => p.QuantityInUnit ?? 0), // { // if (p.QuantityInUnit == null) //return 0; // return p.QuantityInUnit.Value; // }), SINumber = si.Key.SINumber, Program = si.Key.Program.Name, Project = si.Key.ProjectNumber, ProjectCodeID = 0, ReaminingExpectedReceipts = si.Sum(p => p.QuantityInUnit ?? 0), // { // if (p.QuantityInUnit == null) //return 0; // return p.QuantityInUnit.Value; // }), TotalDispatchable = 0, //si.Sum(p => p.QuantityInMT), }).ToList(); foreach (var siBalance in list) { var sis = _ShippingInstructionService.GetShipingInstructionId(siBalance.SINumber); //siBalance.ReaminingExpectedReceipts = totalSumForComm; //decimal totalSumForComm = (from rAll in db.ReceiptAllocations // where rAll.IsClosed == false && rAll.SINumber == siBalance.SINumber // && rAll.CommodityID == CommodityId || // rAll.Commodity.ParentID == CommodityId // select rAll.QuantityInMT).Sum(); //siBalance.ReaminingExpectedReceipts = totalSumForComm; if (sis != 0) { int commodityId = _unitOfWork.CommodityRepository.FindById(CommodityId).ParentID ?? CommodityId; ShippingInstruction si = _unitOfWork.ShippingInstructionRepository.FindById(sis); // convert the amount which is in Quintals to ... MT siBalance.CommitedToFDP = (from v in si.DispatchAllocations where v.IsClosed == false && v.CommodityID == commodityId select v.AmountInUnit).DefaultIfEmpty().Sum(); var utilGetDispatchedAllocationFromSiResult = _unitOfWork.ReportRepository.util_GetDispatchedAllocationFromSI(hubId, sis).FirstOrDefault(); if (utilGetDispatchedAllocationFromSiResult != null) { if (utilGetDispatchedAllocationFromSiResult.QuantityInUnit != null) { siBalance.CommitedToFDP -= utilGetDispatchedAllocationFromSiResult.QuantityInUnit.Value; } } siBalance.CommitedToOthers = (from v in si.OtherDispatchAllocations where v.IsClosed == false && v.CommodityID == commodityId select v.QuantityInUnit).DefaultIfEmpty().Sum(); //sum up all the Expected reamining quantities //siBalance.ReaminingExpectedReceipts = siBalance.ReaminingExpectedReceipts; siBalance.Dispatchable = siBalance.AvailableBalance - (siBalance.CommitedToFDP + siBalance.CommitedToOthers) + siBalance.ReaminingExpectedReceipts; //TODO if(siBalance.CommitedToFDP + siBalance.CommitedToOthers == 0 )//set total to 0 if ((siBalance.CommitedToFDP + siBalance.CommitedToOthers) == 0) { siBalance.TotalDispatchable = 0; } else { siBalance.TotalDispatchable = siBalance.AvailableBalance - (siBalance.CommitedToFDP + siBalance.CommitedToOthers); } } } return(list); //return null; }
public ServiceResponse <ShippingInstruction> CreateShippingInstruction(ShippingInstruction c) { Func <ShippingInstruction> f = delegate { long max = 1; try { max = this._APIContext.ShippingInstructions.Where(si => si.Fecha.Year == DateTime.Now.Year).Count(); } catch (System.Exception) { max = 1; //throw; } if (max == 0) { string tempID = DateTime.Now.Year.ToString().Substring(2, 2) + max.ToString("0000"); c.Id = long.Parse(tempID); } else { max = max + 1; string tempID = DateTime.Now.Year.ToString().Substring(2, 2) + max.ToString("0000"); c.Id = long.Parse(tempID); } var ShippingInstruction_result = this._APIContext.ShippingInstructions.Find(c.Id); if (ShippingInstruction_result != null) { throw new Exception("ShippingInstruction ya existe"); } else { c.Cliente = null; c.Agente = null; c.Consignatario = null; c.Shipper = null; c.PuertoDeDespacho = null; c.PuertoDeDescarga = null; // c.DestinoFinal = null; c.Region = null; c.Carrier = null; c.Usuario = null; c.Commodity = null; c.PrintToken = Guid.NewGuid().ToString(); if (c.LugarDeCarga == "") { c.LugarDeCarga = " "; } ; if (c.Comentarios == "") { c.Comentarios = " "; } ; if (c.Nominacion == "") { c.Nominacion = " "; } ; foreach (var item in c.ShippingInstructionDetails) { item.Servicio = null; } _APIContext.ShippingInstructions.Add(c); _APIContext.SaveChanges(); return(c); } }; return(this.Execute(f)); }
public bool EditShippingInstruction(ShippingInstruction shippingInstruction) { _unitOfWork.ShippingInstructionRepository.Edit(shippingInstruction); _unitOfWork.Save(); return(true); }
public bool EditShippingInstruction(ShippingInstruction shippingInstruction) { _unitOfWork.ShippingInstructionRepository.Edit(shippingInstruction); _unitOfWork.Save(); return true; }
/// <summary> /// Gets the balance. /// </summary> /// <param name="hubID">The hub ID.</param> /// <param name="commodityId">The commodity id.</param> /// <param name="shippingInstructionID">The shipping instruction ID.</param> /// <returns></returns> public SIBalance GetBalance(int hubID, int commodityId, int shippingInstructionID) { SIBalance siBalance = new SIBalance(); siBalance.Commodity = _unitOfWork.CommodityRepository.FindById(commodityId).Name; siBalance.SINumberID = shippingInstructionID; ProjectCode projectCode = GetProjectCodeForSI(hubID, commodityId, shippingInstructionID); siBalance.ProjectCodeID = projectCode.ProjectCodeID; siBalance.Project = projectCode.Value; ShippingInstruction si = _unitOfWork.ShippingInstructionRepository.FindById(shippingInstructionID); var availableBalance = (from v in si.Transactions where v.LedgerID == Cats.Models.Ledger.Constants.GOODS_ON_HAND_UNCOMMITED && commodityId == v.ParentCommodityID select v.QuantityInMT).DefaultIfEmpty().Sum(); var firstOrDefaultans = si.Transactions.FirstOrDefault(); if (firstOrDefaultans != null) { siBalance.Program = firstOrDefaultans.Program.Name; } siBalance.AvailableBalance = availableBalance; siBalance.SINumber = si.Value; // convert the amount which is in Quintals to ... MT siBalance.CommitedToFDP = (from v in si.DispatchAllocations where v.IsClosed == false && v.CommodityID == commodityId select v.Amount / 10).DefaultIfEmpty().Sum(); var utilGetDispatchedAllocationFromSiResult = _unitOfWork.ReportRepository.util_GetDispatchedAllocationFromSI(hubID, shippingInstructionID).FirstOrDefault(); if (utilGetDispatchedAllocationFromSiResult != null) { if (utilGetDispatchedAllocationFromSiResult.Quantity != null) { siBalance.CommitedToFDP -= utilGetDispatchedAllocationFromSiResult.Quantity.Value; } } siBalance.CommitedToOthers = (from v in si.OtherDispatchAllocations where v.IsClosed == false && v.CommodityID == commodityId select v.QuantityInMT).DefaultIfEmpty().Sum(); decimal ReaminingExpectedReceipts = 0; var allocation = _unitOfWork.ReceiptAllocationRepository.FindBy(r => r.SINumber == siBalance.SINumber).ToList(); var rAll = allocation .Where( p => { if (p.Commodity.ParentID == null) { return(p.CommodityID == commodityId); } else { return(p.Commodity.ParentID == commodityId); } } ) .Where(q => q.IsClosed == false); foreach (var receiptAllocation in rAll) { ReaminingExpectedReceipts = ReaminingExpectedReceipts + (receiptAllocation.QuantityInMT - GetReceivedAlready(receiptAllocation)); } siBalance.ReaminingExpectedReceipts = ReaminingExpectedReceipts; decimal newVariable = (siBalance.CommitedToFDP + siBalance.CommitedToOthers); siBalance.Dispatchable = siBalance.AvailableBalance - newVariable + ReaminingExpectedReceipts; if (newVariable > 0) { siBalance.TotalDispatchable = siBalance.AvailableBalance - (siBalance.CommitedToFDP + siBalance.CommitedToOthers); } else { siBalance.TotalDispatchable = siBalance.AvailableBalance; } return(siBalance); }
/// <summary> /// Gets the SI number id With create. /// </summary> /// <param name="SiNumber">The si number.</param> /// <returns></returns> public ShippingInstruction GetSINumberIdWithCreate(string SiNumber) { var instruction = _unitOfWork.ShippingInstructionRepository.FindBy(t => t.Value.ToUpper() == SiNumber.ToUpper()). SingleOrDefault(); if (instruction != null) { return instruction; } else { ShippingInstruction newInstruction = new ShippingInstruction() { Value = SiNumber.ToUpperInvariant() }; _unitOfWork.ShippingInstructionRepository.Add(newInstruction); _unitOfWork.Save(); return newInstruction; } }