private static async Task SaveSubItem(SubItems subitm) { if (subitm == null) { return; } using (var ctx = new SubItemsService()) { await ctx.UpdateSubItems(subitm).ConfigureAwait(false); } }
private double GetAsycudaItmQtyToAllocate(xcuda_Item cAsycudaItm, EntryDataDetails saleitm, out SubItems subitm) { double asycudaItmQtyToAllocate; if (cAsycudaItm.SubItems.Any()) { subitm = cAsycudaItm.SubItems.FirstOrDefault(x => x.ItemNumber == saleitm.ItemNumber); if (subitm != null) { asycudaItmQtyToAllocate = subitm.Quantity - subitm.QtyAllocated; if (Convert.ToDouble(asycudaItmQtyToAllocate) > (Convert.ToDouble(cAsycudaItm.ItemQuantity) - cAsycudaItm.QtyAllocated)) { asycudaItmQtyToAllocate = cAsycudaItm.ItemQuantity - cAsycudaItm.QtyAllocated; } } else { asycudaItmQtyToAllocate = 0; } } else { asycudaItmQtyToAllocate = cAsycudaItm.ItemQuantity - cAsycudaItm.QtyAllocated; subitm = null; } return(asycudaItmQtyToAllocate); }
private async Task <double> AllocateSaleItem(xcuda_Item cAsycudaItm, EntryDataDetails saleitm, double saleitmQtyToallocate, SubItems subitm) { try { var dfp = ((Sales)saleitm.Sales).DutyFreePaid; // allocate Sale item var ssa = new AsycudaSalesAllocations { EntryDataDetailsId = saleitm.EntryDataDetailsId, PreviousItem_Id = cAsycudaItm.Item_Id, QtyAllocated = 0, TrackingState = TrackingState.Added }; if (cAsycudaItm.QtyAllocated >= 0 && saleitmQtyToallocate != 0 && cAsycudaItm.QtyAllocated <= Convert.ToDouble(cAsycudaItm.ItemQuantity)) { if (saleitmQtyToallocate > 0) { if (subitm != null) { subitm.QtyAllocated = subitm.QtyAllocated + saleitmQtyToallocate; } if (dfp == "Duty Free") { cAsycudaItm.DFQtyAllocated += saleitmQtyToallocate; } else { cAsycudaItm.DPQtyAllocated += saleitmQtyToallocate; } if (BaseDataModel.Instance.CurrentApplicationSettings.AllowEntryDoNotAllocate == "Visible") { SetPreviousItemXbond(ssa, cAsycudaItm, dfp, saleitmQtyToallocate); } saleitm.QtyAllocated += saleitmQtyToallocate; ssa.QtyAllocated += saleitmQtyToallocate; saleitmQtyToallocate -= saleitmQtyToallocate; } else { // returns double mqty = 0; if ((Convert.ToDouble(cAsycudaItm.QtyAllocated) == 0)) { if (dfp == "Duty Free") { cAsycudaItm.DFQtyAllocated = cAsycudaItm.ItemQuantity; } else { cAsycudaItm.DPQtyAllocated = cAsycudaItm.ItemQuantity; } if (BaseDataModel.Instance.CurrentApplicationSettings.AllowEntryDoNotAllocate == "Visible") { SetPreviousItemXbond(ssa, cAsycudaItm, dfp, saleitmQtyToallocate); } } if ((cAsycudaItm.QtyAllocated > Convert.ToDouble(saleitmQtyToallocate * -1))) { mqty = saleitmQtyToallocate * -1; } else { if (cAsycudaItm.QtyAllocated == 0) { mqty = cAsycudaItm.ItemQuantity; } else { mqty = cAsycudaItm.QtyAllocated; } //mqty = Convert.ToDouble(saleitmQtyToallocate * -1); } if (cAsycudaItm.QtyAllocated != 0) { if (subitm != null) { subitm.QtyAllocated = subitm.QtyAllocated - mqty; } if (dfp == "Duty Free") { cAsycudaItm.DFQtyAllocated -= mqty; } else { cAsycudaItm.DPQtyAllocated -= mqty; } if (BaseDataModel.Instance.CurrentApplicationSettings.AllowEntryDoNotAllocate == "Visible") { SetPreviousItemXbond(ssa, cAsycudaItm, dfp, -mqty); } saleitmQtyToallocate += mqty; saleitm.QtyAllocated -= mqty; ///saleitm.QtyAllocated + System.Convert.ToDouble(saleitmQtyToallocate); ssa.QtyAllocated -= mqty; //Convert.ToDouble(saleitmQtyToallocate); } } } //saleitm.AsycudaSalesAllocations = new ObservableCollection<AsycudaSalesAllocations>(saleitm.AsycudaSalesAllocations){ssa}; await SaveAllocation(ssa).ConfigureAwait(false); if (subitm != null) { await SaveSubItem(subitm).ConfigureAwait(false); } await SaveXcuda_Item(cAsycudaItm).ConfigureAwait(false); await SaveEntryDataDetails(saleitm).ConfigureAwait(false); // saleitm.AsycudaSalesAllocations.Add(ssa); return(saleitmQtyToallocate); } catch (Exception) { throw; } }
private async Task AllocateSalestoAsycudaByItemNumber(List <EntryDataDetails> saleslst, List <xcuda_Item> asycudaEntries) { try { if (asycudaEntries == null || !asycudaEntries.Any()) { foreach (var item in saleslst) { if (item.AsycudaSalesAllocations.FirstOrDefault(x => x.Status == "No Asycuda Entries Found") == null) { await AddExceptionAllocation(item, "No Asycuda Entries Found").ConfigureAwait(false); } } // continue; return; } var CurrentAsycudaItemIndex = 0; var CurrentSalesItemIndex = 0; var cAsycudaItm = GetAsycudaEntries(asycudaEntries, CurrentAsycudaItemIndex); while (cAsycudaItm.QtyAllocated == Convert.ToDouble(cAsycudaItm.ItemQuantity)) { if (CurrentAsycudaItemIndex + 1 < asycudaEntries.Count()) { CurrentAsycudaItemIndex += 1; cAsycudaItm = GetAsycudaEntries(asycudaEntries, CurrentAsycudaItemIndex); } else { break; } } var saleitm = GetSaleEntries(saleslst, CurrentSalesItemIndex); // AllocatePreviousItems(cAsycudaItm); // foreach (var saleitm in saleslst) for (var s = CurrentSalesItemIndex; s < saleslst.Count(); s++) { StatusModel.Refresh(); //if (saleitm.QtyAllocated == null) saleitm.QtyAllocated = 0; if (CurrentSalesItemIndex != s) { CurrentSalesItemIndex = s; saleitm = GetSaleEntries(saleslst, CurrentSalesItemIndex); } foreach (var allo in saleitm.AsycudaSalesAllocations.ToList()) { await AllocationsModel.Instance.ClearAllocation(allo).ConfigureAwait(false); saleitm.AsycudaSalesAllocations.Remove(allo); } //saleitm.AsycudaSalesAllocations.Clear(); var saleitmQtyToallocate = saleitm.Quantity - saleitm.QtyAllocated; SubItems subitm = null; for (var i = CurrentAsycudaItemIndex; i < asycudaEntries.Count(); i++) { // reset in event earlier dat if (CurrentAsycudaItemIndex != i) { CurrentAsycudaItemIndex = i; cAsycudaItm = GetAsycudaEntries(asycudaEntries, CurrentAsycudaItemIndex); } ReturnsStepBack(asycudaEntries, ref i, ref CurrentAsycudaItemIndex, ref cAsycudaItm, saleitm); if ((cAsycudaItm.AsycudaDocument.EffectiveRegistrationDate == null ? cAsycudaItm.AsycudaDocument.RegistrationDate : cAsycudaItm.AsycudaDocument.EffectiveRegistrationDate) > saleitm.Sales.EntryDataDate) { await AddExceptionAllocation(saleitm, "Early Sales").ConfigureAwait(false); break; } var asycudaItmQtyToAllocate = GetAsycudaItmQtyToAllocate(cAsycudaItm, saleitm, out subitm); if (asycudaItmQtyToAllocate == 0 && saleitmQtyToallocate > 0) { continue; } if ((asycudaItmQtyToAllocate) >= (saleitmQtyToallocate)) { var ramt = await AllocateSaleItem(cAsycudaItm, saleitm, saleitmQtyToallocate, subitm).ConfigureAwait(false); saleitmQtyToallocate = ramt; if (ramt == 0) { break; } if (i == 0 && saleitmQtyToallocate < 0) { break; } ReturnsStepBack(asycudaEntries, ref i, ref CurrentAsycudaItemIndex, ref cAsycudaItm, saleitm); } else { if (asycudaItmQtyToAllocate != 0) { var ramt = await AllocateSaleItem(cAsycudaItm, saleitm, asycudaItmQtyToAllocate, subitm).ConfigureAwait(false); saleitmQtyToallocate -= asycudaItmQtyToAllocate; if (saleitmQtyToallocate < 0) { throw new ApplicationException("saleitmQtyToallocate < 0 check this out"); } } else { await AddExceptionAllocation(saleitm, "Out of Stock").ConfigureAwait(false); } } } if (saleitmQtyToallocate > 0 && saleitm.AsycudaSalesAllocations.Any() == false)// { await AddExceptionAllocation(saleitm, "Insufficent Quantities").ConfigureAwait(false); } } } catch (Exception e) { throw e; } }