Example #1
0
        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);
        }
Example #2
0
        private async Task <List <EntryData> > GetEntryData(string wStr)
        {
            var res = new List <EntryData>();

            var entryData = new EntryData();

            var container_StatusPat = @"COST U LESS, INC\.\n*\*\*.COMMERCIAL INVOICE\*\*\*.*\nContainer :\s(?<ContainerNo>\d{3}-\d{4}-\d{6}).Status : (?<Status>\w*)\n";
            var bookingPat          = @"Booking #:\n(?<BookingNo>[\w\-]*)";



            //get Regex Groups
            var entryDetailspat =
                @"(?<ItemNumber>\d{5,})\s(?<ItemDescription>[\w,<,\s,\&,\%]{1,})\s(?<Quantity>\d{1,4})\s(?<CS>\d+)\s(?<Cost>[\d,\,]+\.\d{2})\s(?<ExtCost>[\d,\,]+\.\d{2})\s(?<IF>[\d,\,]+\.\d{2})?\s?(?<ExtCIF>[\d,\,]+\.\d{2})\s(?<OriginCountry>\w{2,})\n(?<ExtItemDescription>[\w,\<,\s,\-\./]{1,})?\n?BRB.+HTS.+(?<TariffCode>\d{10})\s?%?\n?Duty\s?%\s?\:\s(?<DutyPercent>\d{1,3}\.\d{2})\s\%?\s?.+\:\s(?<DutyAmt>\d{1,3}\.\d{2})";

            var entryDetailsRegx = new Regex(entryDetailspat, RegexOptions.Compiled);



            foreach (Match m in entryDetailsRegx.Matches(wStr))
            {
                var ed = new EntryDataDetails(true)
                {
                    TrackingState = TrackingState.Added
                };
                ed.ItemNumber      = m.Groups["ItemNumber"].Value;
                ed.ItemDescription = m.Groups["ItemDescription"].Value;
                ed.Cost            = Convert.ToDouble(m.Groups["Cost"].Value);
                ed.LineNumber      = m.Index;
                ed.Quantity        = Convert.ToDouble(m.Groups["Quantity"].Value);
                ed.Units           = m.Groups["Unit"].Value;
            }

            return(res);
        }
Example #3
0
 private static async Task SaveEntryDataDetails(EntryDataDetails item)
 {
     if (item == null)
     {
         return;
     }
     using (var ctx = new EntryDataDetailsService())
     {
         await ctx.UpdateEntryDataDetails(item).ConfigureAwait(false);
     }
 }
Example #4
0
        private async Task AddExceptionAllocation(EntryDataDetails saleitm, string error)
        {
            var ssa = new AsycudaSalesAllocations()
            {
                EntryDataDetailsId = saleitm.EntryDataDetailsId,
                //EntryDataDetails = saleitm,
                Status        = error,
                TrackingState = TrackingState.Added
            };

            await SaveAllocation(ssa).ConfigureAwait(false);

            saleitm.AsycudaSalesAllocations.Add(ssa);
        }
Example #5
0
 private static void GetSubItems(List <xcuda_Item> alst, EntryDataDetails salesDetails)
 {
     using (var ctx = new SubItemsService())
     {
         alst.AddRange(
             ctx.GetSubItemsByExpressionLst(
                 new List <string>()
         {
             string.Format("ItemNumber == \"{0}\"", salesDetails.ItemNumber)
         }
                 , new List <string>()
         {
             "xcuda_Item", "xcuda_Item.EX", "xcuda_Item.AsycudaDocument"
         }).Result
             //.Where(y => y.ItemNumber == salesDetails.ItemNumber)
             .Select(x => x.xcuda_Item).ToList());
     }
 }
Example #6
0
        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;
            }
        }
Example #7
0
 private void ReturnsStepBack(List <xcuda_Item> asycudaEntries, ref int i, ref int CurrentAsycudaItemIndex, ref xcuda_Item cAsycudaItm, EntryDataDetails saleitm)
 {
     if (saleitm.Quantity < 0) // if is a return go to previous cAsycudaItem
     {
         while (cAsycudaItm.QtyAllocated == 0 && CurrentAsycudaItemIndex > 0)
         {
             CurrentAsycudaItemIndex -= 1;
             cAsycudaItm              = GetAsycudaEntries(asycudaEntries, CurrentAsycudaItemIndex);
             i = CurrentAsycudaItemIndex;
         }
     }
 }
Example #8
0
        private async Task <List <EntryData> > GetEntryData(string wStr, AsycudaDocumentSet docSet, Container container)
        {
            try
            {
                //var bookingPat = @"Booking #:  (?<BookingNo>[\w\-]*)";
                var res = new List <EntryData>();

                var containerMatch   = GetMatchFromPattern(wStr, container_StatusPat);
                var containerDateMat = GetMatchFromPattern(wStr, containerDatePat);
                var LineTotalMat     = GetAllMatchesFromPattern(wStr, LineChkPat);

                var entryData = new PurchaseOrders(true)
                {
                    TrackingState = TrackingState.Added
                };

                entryData.AsycudaDocumentSets.Add(new AsycudaDocumentSetEntryData(true)
                {
                    AsycudaDocumentSetId = docSet.AsycudaDocumentSetId,
                    EntryDataId          = entryData.EntryDataId,
                    TrackingState        = TrackingState.Added
                });


                if (containerMatch != null)
                {
                    entryData.EntryDataId = containerMatch.Groups["ContainerNo"].Value;
                    entryData.PONumber    = containerMatch.Groups["ContainerNo"].Value;
                }
                if (containerDateMat != null)
                {
                    entryData.EntryDataDate = Convert.ToDateTime(containerDateMat.Groups["ContainerDate"].Value);
                }

                if (LineTotalMat != null)
                {
                    entryData.ImportedLines = LineTotalMat.Count;
                }

                entryData.ImportedTotal = container.TotalValue;
                entryData.ContainerEntryData.Add(new ContainerEntryData()
                {
                    Container_Id  = container.Container_Id,
                    EntryDataId   = entryData.PONumber,
                    TrackingState = TrackingState.Added
                });


                //get Regex Groups

                var entryDetailsRegx = new Regex(entryDetailspat, RegexOptions.Compiled);
                //var lineChkMat = GetAllMatchesFromPattern(wStr, LineChkPat);

                var lcnt = 0;
                //var matches = entryDetailsRegx.Matches(wStr);
                //for (int i = 0; i < lineChkMat.Count; i++)
                //{

                //}
                foreach (Match m in entryDetailsRegx.Matches(wStr))
                {
                    var ed = new EntryDataDetails(true)
                    {
                        EntryDataId   = entryData.EntryDataId,
                        TrackingState = TrackingState.Added
                    };
                    lcnt += 1;
                    if (string.IsNullOrEmpty(m.Groups["ItemNumber"].Value))
                    {
                        // missing line create blank
                        ed.ItemNumber      = "Import Error";
                        ed.ItemDescription = "This line was not imported please manually create item.";
                        ed.Cost            = 0;
                        ed.LineNumber      = lcnt;
                        ed.Quantity        = 0;
                        ed.Units           = "";
                        entryData.EntryDataDetails.Add(ed);
                    }
                    else
                    {
                        ed.ItemNumber      = m.Groups["ItemNumber"].Value;
                        ed.ItemDescription = m.Groups["ItemDescription"].Value + " " +
                                             m.Groups["ExtItemDescription"].Value;
                        ed.Cost       = Convert.ToDouble(m.Groups["Cost"].Value);
                        ed.LineNumber = lcnt;
                        ed.Quantity   = Convert.ToDouble(m.Groups["Quantity"].Value);
                        ed.Units      = m.Groups["Unit"].Value;
                        entryData.EntryDataDetails.Add(ed);
                    }

                    itmList.Add(new InventoryItem(true)
                    {
                        ItemNumber  = ed.ItemNumber,
                        Description = ed.ItemDescription,
                        TariffCode  =
                            string.IsNullOrEmpty(m.Groups["TariffCode"].Value)
                                ? null
                                : m.Groups["TariffCode"].Value.Substring(0, 8)
                    });
                }

                res.Add(entryData);


                return(res);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private async Task SaveToDataBase(IEnumerable <SalesReceiptRet> trackableCollection, AsycudaDocumentSet currentAsycudaDocumentSet)
        {
            var salesReceiptRets = trackableCollection as IList <SalesReceiptRet> ?? trackableCollection.ToList();

            StatusModel.StartStatusUpdate("Importing Sales Data", salesReceiptRets.Count());
            using (var ctx = new EntryDataDSContext())
            {
                foreach (var saleReceipt in salesReceiptRets)
                {
                    StatusModel.StatusUpdate();
                    SalesReceiptRet receipt = saleReceipt;
                    var             s       = ctx.EntryData.OfType <Sales>().FirstOrDefault(x => x.EntryDataId == receipt.SalesReceiptNumber);
                    if (s == null)
                    {
                        s = new Sales(true)
                        {
                            TrackingState = TrackingState.Added
                        };
                    }

                    // RemoveExistingDbReceipts(db, saleReceipt);
                    s.INVNumber     = saleReceipt.SalesReceiptNumber;
                    s.EntryDataId   = saleReceipt.SalesReceiptNumber;
                    s.EntryDataDate = saleReceipt.TxnDate;
                    s.TaxAmount     = Convert.ToDouble(saleReceipt.TaxAmount);
                    s.AsycudaDocumentSets.Add(new AsycudaDocumentSetEntryData(true)
                    {
                        AsycudaDocumentSetId = currentAsycudaDocumentSet.AsycudaDocumentSetId,
                        EntryDataId          = s.EntryDataId,
                        TrackingState        = TrackingState.Added
                    });


                    // do details
                    if (saleReceipt.SalesReceiptItems == null)
                    {
                        continue;
                    }

                    //foreach (var ed in s.EntryDataDetails.ToList())
                    //{
                    //    s.EntryDataDetails.Remove(ed);
                    //    db.DeleteObject(ed);
                    //}

                    for (var i = 0; i < saleReceipt.SalesReceiptItems.Count(); i++)
                    {
                        var saleReceiptDetail = saleReceipt.SalesReceiptItems[i];
                        var itm = s.EntryDataDetails.FirstOrDefault(x => x.LineNumber == i);
                        if (itm == null)
                        {
                            itm = new EntryDataDetails(true)
                            {
                                EntryDataId     = s.EntryDataId,
                                ItemNumber      = saleReceiptDetail.ItemNumber,
                                ItemDescription = saleReceiptDetail.Desc1 + "|" + saleReceiptDetail.Desc2 + "|" + saleReceiptDetail.Attribute,
                                Cost            = Convert.ToSingle(saleReceiptDetail.Cost),
                                LineNumber      = i,
                                UnitWeight      = Convert.ToSingle(saleReceiptDetail.Weight),
                                Units           = saleReceiptDetail.UnitOfMeasure,
                                TrackingState   = TrackingState.Added
                            };
                        }
                        else
                        {
                            itm.ItemNumber      = saleReceiptDetail.ItemNumber;
                            itm.ItemDescription = saleReceiptDetail.Desc1 + "|" + saleReceiptDetail.Desc2 + "|" + saleReceiptDetail.Attribute;
                            itm.Cost            = Convert.ToSingle(saleReceiptDetail.Cost);
                            itm.LineNumber      = i;
                            itm.UnitWeight      = Convert.ToSingle(saleReceiptDetail.Weight);
                            itm.Units           = saleReceiptDetail.UnitOfMeasure;
                        }

                        InventoryItem inv = null;
                        using (var ictx = new InventoryDSContext())
                        {
                            inv = await ictx.InventoryItems.FindAsync(saleReceiptDetail.ItemNumber).ConfigureAwait(false);

                            if (inv == null)
                            {
                                inv = new InventoryItem(true)
                                {
                                    ItemNumber    = saleReceiptDetail.ItemNumber,
                                    Description   = GetQBSaleItemDescription(saleReceiptDetail),
                                    TrackingState = TrackingState.Added
                                };
                                ictx.ApplyChanges(inv);
                                await ictx.SaveChangesAsync().ConfigureAwait(false);
                            }
                        }
                        itm.ItemDescription = inv.Description;

                        switch (saleReceipt.SalesReceiptType)
                        {
                        case "srtReturn":
                            itm.Quantity = Convert.ToSingle(saleReceiptDetail.Qty) * -1;
                            break;

                        case "srtSales":
                            itm.Quantity = Convert.ToSingle(saleReceiptDetail.Qty);
                            break;

                        default:
                            throw new Exception("Unknown SalesType");
                            break;
                        }

                        s.EntryDataDetails.Add(itm);
                    }
                    ctx.ApplyChanges(s);
                    await ctx.SaveChangesAsync().ConfigureAwait(false);
                }
            }


            StatusModel.StopStatusUpdate();
            MessageBox.Show(@"Sale Receipt Import Complete");
        }