Exemplo n.º 1
0
        public async Task ProcessDroppedFile(string fileName, string fileType, AsycudaDocumentSet docSet,
                                             bool overWriteExisting)
        {
            try
            {
                //get the text
                var wStr = ExtractTextFromFile(fileName);

                var container = await ConfigureContainer(wStr, docSet).ConfigureAwait(false);

                var elst = await GetEntryData(wStr, docSet, container).ConfigureAwait(false);

                await ConfigureDocSet(wStr, docSet).ConfigureAwait(false);

                await ImportInventory(elst).ConfigureAwait(false);

                var flst = FixExistingEntryData(elst);

                await SaveEntryData(flst).ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        private async Task SaveCSV(string droppedFilePath, string fileType, AsycudaDocumentSet docSet, bool overWriteExisting)
        {
            try
            {
                var lines = File.ReadAllLines(droppedFilePath);
                // identify header
                var headerline = lines.FirstOrDefault();

                var csvType = GetFileType(headerline);


                if (headerline != null)
                {
                    var headings = headerline.CsvSplit();


                    if (fileType == "SI")
                    {
                        await SaveCsvSubItems.Instance.ExtractSubItems(fileType, lines, headings, csvType).ConfigureAwait(false);

                        return;
                    }

                    if (await SaveCsvEntryData.Instance.ExtractEntryData(fileType, lines, headings, csvType, docSet, overWriteExisting).ConfigureAwait(false))
                    {
                        return;
                    }
                }
            }
            catch (Exception Ex)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task ProcessDroppedFile(string fileName, string fileType, AsycudaDocumentSet docSet, bool overWriteExisting)
        {
            //get the text
            var wStr = Core.Common.PDF2TXT.Pdf2Txt.Instance.ExtractTextFromPdf(fileName);

            var elst = await GetEntryData(wStr).ConfigureAwait(false);

            await ImportInventory(elst).ConfigureAwait(false);

            var flst       = FixExistingEntryData(elst);
            var exceptions = new ConcurrentQueue <Exception>();

            flst.AsParallel(new ParallelLinqOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }).ForAll(itm =>
            {
                try
                {
                    using (var ctx = new EntryDataDSContext())
                    {
                        ctx.ApplyChanges(itm);
                        ctx.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Enqueue(ex);
                }
            });
            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }
        }
Exemplo n.º 4
0
        public void AddDutyFreePaidtoRef(DocumentCT cdoc, string dfp, AsycudaDocumentSet docSet)
        {
            try
            {
                switch (dfp)
                {
                case "Duty Free":

                    cdoc.Document.xcuda_Declarant.Number = docSet.Declarant_Reference_Number
                                                           + "-F" +     //+ "-DF"
                                                           cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.FileNumber
                                                           .ToString();
                    break;

                case "Duty Paid":
                    cdoc.Document.xcuda_Declarant.Number = docSet.Declarant_Reference_Number
                                                           + "-P" +    // + "-DP"
                                                           cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.FileNumber
                                                           .ToString();
                    break;

                default:
                    break;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 5
0
 void UpdateDocSet(AsycudaDocumentSet dset, DocInfo docInfo = null)
 {
     if (docInfo != null)
     {
         dset.Declarant_Reference_Number = docInfo.DeclarantReferenceNumber;
         dset.Customs_ProcedureId        = docInfo.Customs_ProcedureId;
         if (docInfo.Description != null)
         {
             dset.Description = docInfo.Description;
         }
         if (docInfo.Currency_Code != null)
         {
             dset.Currency_Code = docInfo.Currency_Code;
         }
         dset.Document_TypeId = docInfo.Document_TypeId;
         dset.Exchange_Rate   = docInfo.Exchange_Rate;
         if (docInfo.Country_of_origin_code != null)
         {
             dset.Country_of_origin_code = docInfo.Country_of_origin_code;
         }
         if (docInfo.ManifestNumber != null)
         {
             dset.Manifest_Number = docInfo.ManifestNumber;
         }
         if (docInfo.BlNumber != null)
         {
             dset.BLNumber = docInfo.BlNumber;
         }
         // dset.TotalGrossWeight = docInfo.TotalGrossWeight;
     }
 }
Exemplo n.º 6
0
 public void OPSIntializeCdoc(DocumentCT cdoc, Document_Type dt, AsycudaDocumentSet ads)
 {
     BaseDataModel.Instance.IntCdoc(cdoc, dt, ads);
     cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.AutoUpdate  = false;
     cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Description = "Existing Opening Stock Entries";
     cdoc.Document.xcuda_Declarant.Number = cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.AsycudaDocumentSet.Declarant_Reference_Number + "-OPS" + "-F" + cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.FileNumber.ToString();
 }
Exemplo n.º 7
0
        public async Task SaveAsycudaDocument(AsycudaDocumentSet docSet, DocInfo docInfo)
        {
            if (docSet != null)
            {
                if (docSet.Declarant_Reference_Number == "Search Results")
                {
                    return;
                    //  SaveSearchResults();
                }

                UpdateDocSet(docSet, docInfo);
                foreach (var cdoc in docSet.Documents.Where(x => x.xcuda_ASYCUDA_ExtendedProperties.AutoUpdate == true))
                {
                    cdoc.SetupProperties();

                    BaseDataModel.Instance.IntCdoc(cdoc, docSet.Document_Type, docSet);
                }
            }
            else
            {
                //Create New AsycudaDocumentset
                docSet = await CreateNewAsycudaDocumentSet().ConfigureAwait(false);
            }


            using (var ctx = new AsycudaDocumentSetService())
            {
                await ctx.UpdateAsycudaDocumentSet(docSet).ConfigureAwait(false);
            }
        }
 private void IncompOpsIntializeCdoc(DocumentCT cdoc, Document_Type dt, AsycudaDocumentSet ads)
 {
     BaseDataModel.Instance.IntCdoc(cdoc, dt, ads);
     cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.AutoUpdate  = false;
     cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Description = "Incomplete Allocations Opening Stock Entries";
     cdoc.Document.xcuda_Declarant.Number = cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.AsycudaDocumentSet.Declarant_Reference_Number + "-INCOPS" + "-F" + cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.FileNumber.ToString();
 }
Exemplo n.º 9
0
        private async Task ConfigureDocSet(string wStr, AsycudaDocumentSet docSet)
        {
            try
            {
                var casesTotalMat  = GetMatchFromPattern(wStr, CasesTotalPat);
                var weightTotalMat = GetMatchFromPattern(wStr, WeightTotalsPat);

                if (weightTotalMat != null)
                {
                    docSet.TotalWeight = Convert.ToDouble(weightTotalMat.Groups["TotalKGS"].Value);
                }

                if (casesTotalMat != null)
                {
                    docSet.TotalPackages = int.Parse(casesTotalMat.Groups["CasesTotal"].Value, NumberStyles.AllowThousands);
                }



                await DocumentDS.DataModels.BaseDataModel.Instance.SaveAsycudaDocumentSet(docSet).ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 10
0
        public void Ex9InitializeCdoc(Document_Type dt, string dfp, DocumentCT cdoc, AsycudaDocumentSet ads)
        {
            try
            {
                cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.AutoUpdate = false;
                BaseDataModel.Instance.IntCdoc(cdoc, dt, ads);

                switch (dfp)
                {
                case "Duty Free":
                    var Exp = BaseDataModel.Instance.ExportTemplates.FirstOrDefault(y => y.Description.ToUpper() == "EX9".ToUpper());
                    if (Exp.Customs_Procedure == null || string.IsNullOrEmpty(Exp.Customs_Procedure))
                    {
                        throw new ApplicationException("Export Template default Customs Procedures not Configured!");
                    }
                    cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Description = "Duty Free Entries";
                    var df =
                        BaseDataModel.Instance.Customs_Procedures.AsEnumerable()
                        .FirstOrDefault(
                            x =>
                            x.DisplayName ==
                            ((Exp == null || string.IsNullOrEmpty(Exp.Customs_Procedure))
                                            ? "9070-000"
                                            : Exp.Customs_Procedure));

                    AttachCustomProcedure(cdoc, df);

                    break;

                case "Duty Paid":
                    var Exp1 = BaseDataModel.Instance.ExportTemplates.FirstOrDefault(y => y.Description == "IM4");
                    if (Exp1.Customs_Procedure == null || string.IsNullOrEmpty(Exp1.Customs_Procedure))
                    {
                        throw new ApplicationException("Export Template default Customs Procedures not Configured!");
                    }
                    cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Description = "Duty Paid Entries";
                    var dp =
                        BaseDataModel.Instance.Customs_Procedures.AsEnumerable()
                        .FirstOrDefault(
                            x =>
                            x.DisplayName ==
                            ((Exp1 == null || string.IsNullOrEmpty(Exp1.Customs_Procedure))
                                            ? "4070-000"
                                            : Exp1.Customs_Procedure));
                    AttachCustomProcedure(cdoc, dp);
                    break;

                default:
                    break;
                }

                AllocationsModel.Instance.AddDutyFreePaidtoRef(cdoc, dfp, ads);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 11
0
        public async Task SaveAsycudaDocumentSetEx(AsycudaDocumentSetEx asycudaDocumentSetEx)
        {
            var docset = new AsycudaDocumentSet();

            asycudaDocumentSetEx.ModifiedProperties = null;
            docset.InjectFrom(asycudaDocumentSetEx);

            await WaterNut.DataSpace.DocumentDS.DataModels.BaseDataModel.Instance.SaveAsycudaDocumentSet(docset).ConfigureAwait(false);
        }
Exemplo n.º 12
0
        public async Task CreateErrorOPS(string filterExpression, AsycudaDocumentSet docSet)
        {
            var cdoc = new DocumentCT();

            cdoc.Document = BaseDataModel.Instance.CreateNewAsycudaDocument(docSet);

            StatusModel.Timer("Getting Data ...");

            var itmcount = 0;
            var slst     = await GetErrOPSData(filterExpression).ConfigureAwait(false);


            Document_Type dt;

            if (GetDocumentType(out dt))
            {
                return;
            }

            ErrOpsIntializeCdoc(cdoc, dt, docSet);

            StatusModel.StartStatusUpdate("Creating Error OPS entries", slst.Count());


            var cslst = AllocationEntryLine(slst);


            foreach (var pod in cslst)
            {
                StatusModel.StatusUpdate();

                BaseDataModel.Instance.CreateItemFromEntryDataDetail(pod, cdoc);


                itmcount += 1;
                if (itmcount % BaseDataModel.Instance.CurrentApplicationSettings.MaxEntryLines == 0)
                {
                    await BaseDataModel.Instance.SaveDocumentCT(cdoc).ConfigureAwait(false);

                    //dup new file
                    cdoc          = new DocumentCT();
                    cdoc.Document = BaseDataModel.Instance.CreateNewAsycudaDocument(docSet);

                    ErrOpsIntializeCdoc(cdoc, dt, docSet);
                }
            }
            if (cdoc.DocumentItems.Count == 0)
            {
                cdoc = null;
            }

            await BaseDataModel.Instance.SaveDocumentCT(cdoc).ConfigureAwait(false);

            StatusModel.StopStatusUpdate();
        }
Exemplo n.º 13
0
 public async Task SaveAsycudaDocumentSet(AsycudaDocumentSet i)
 {
     if (i == null)
     {
         return;
     }
     using (var ctx = new AsycudaDocumentSetService())
     {
         await ctx.UpdateAsycudaDocumentSet(i).ConfigureAwait(false);
     }
 }
Exemplo n.º 14
0
 public async Task SaveAsycudaDocumentSet(AsycudaDocumentSet i)
 {
     if (i == null)
     {
         return;
     }
     using (var ctx = new AsycudaDocumentSetService())
     {
         await ctx.UpdateAsycudaDocumentSet(i).ConfigureAwait(false);
     }
     await DataSpace.BaseDataModel.Instance.CalculateDocumentSetFreight(i.AsycudaDocumentSetId).ConfigureAwait(false);
 }
Exemplo n.º 15
0
        internal async Task CleanLines(AsycudaDocumentSet docSet, IEnumerable <int> lst, bool perIM7)
        {
            try
            {
                var alst = await GetSelectedLinesIM9Data(lst).ConfigureAwait(false);

                await CreateIM9Entries(docSet, perIM7, alst).ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 16
0
        internal async Task CleanEntries(AsycudaDocumentSet docSet, IEnumerable <int> lst, bool PerIM7)
        {
            //get document items where itemquantity > pi quantity
            try
            {
                var alst = await GetSelectedIM9Data(lst).ConfigureAwait(false);

                await CreateIM9Entries(docSet, PerIM7, alst).ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 17
0
        private async Task <DocumentCT> SaveAndCreateIM9Doc(AsycudaDocumentSet docSet, DocumentCT cdoc)
        {
            int itmcount;

            if (cdoc != null && cdoc.Document != null && cdoc.DocumentItems.Any())
            {
                await BaseDataModel.Instance.SaveDocumentCT(cdoc).ConfigureAwait(false);

                itmcount = 0;
            }


            var Exp = BaseDataModel.Instance.ExportTemplates.FirstOrDefault(y => y.Description.ToUpper() == "IM9".ToUpper());

            if (Exp.Customs_Procedure == null || string.IsNullOrEmpty(Exp.Customs_Procedure))
            {
                throw new ApplicationException("Export Template default Customs Procedures not Configured for IM9!");
            }

            var dt = BaseDataModel.Instance.Document_Types.AsEnumerable().FirstOrDefault(x => x.DisplayName == "IM9");

            if (dt == null)
            {
                dt = docSet.Document_Type;
            }
            cdoc = await BaseDataModel.Instance.CreateDocumentCt(docSet).ConfigureAwait(false);

            cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.AutoUpdate = false;
            BaseDataModel.Instance.IntCdoc(cdoc, dt, docSet);

            //cdoc.Document.xcuda_Identification.xcuda_Type.Declaration_gen_procedure_code = "9";
            //cdoc.Document.xcuda_Identification.xcuda_Type.Type_of_declaration = "IM";
            cdoc.Document.xcuda_Valuation.xcuda_Gs_Invoice.Currency_code = "XCD";


            cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Description = "IM9 Entries";
            var df =
                BaseDataModel.Instance.Customs_Procedures.AsEnumerable()
                .FirstOrDefault(
                    x =>
                    x.DisplayName ==
                    ((Exp == null || string.IsNullOrEmpty(Exp.Customs_Procedure))
                                ? "9370-EXB"
                                : Exp.Customs_Procedure) && x.Document_TypeId == dt.Document_TypeId);

            BaseDataModel.Instance.AttachCustomProcedure(cdoc, df);
            return(cdoc);
        }
Exemplo n.º 18
0
        internal async Task CleanBond(AsycudaDocumentSet docSet, bool PerIM7)
        {
            //get document items where itemquantity > pi quantity
            try
            {
                var alst = await GetAllIM9Data().ConfigureAwait(false);

                var grp = alst.GroupBy(x => x.CNumber);
                foreach (var item in grp)
                {
                    await CreateIM9Entries(docSet, PerIM7, item).ConfigureAwait(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 19
0
        private async Task <int> InitializeDocumentCT(int itmcount, string prevEntryId, AllocationsModel.MyPodData mypod,
                                                      DocumentCT cdoc, AsycudaDocumentSet docSet, string prevIM7, AllocationsModel.AllocationDataBlock monthyear, Document_Type dt,
                                                      string dfp)
        {
            try
            {
                if (MaxLineCount(itmcount) ||
                    InvoicePerEntry(prevEntryId, mypod) ||
                    (cdoc.Document == null || itmcount == 0) ||
                    IsPerIM7(prevIM7, monthyear))
                {
                    if (itmcount != 0)
                    {
                        if (cdoc.Document != null)
                        {
                            await SaveDocumentCT(cdoc).ConfigureAwait(false);

                            //}
                            //else
                            //{
                            cdoc = await BaseDataModel.Instance.CreateDocumentCt(docSet).ConfigureAwait(true);
                        }
                    }
                    Ex9InitializeCdoc(dt, dfp, cdoc, docSet);
                    if (PerIM7 == true)
                    {
                        cdoc.Document.xcuda_Declarant.Number =
                            cdoc.Document.xcuda_Declarant.Number.Replace(
                                docSet.Declarant_Reference_Number,
                                docSet.Declarant_Reference_Number + "-" +
                                monthyear.CNumber);
                    }
                    InsertEntryIdintoRefNum(cdoc, mypod.EntlnData.EntryDataDetails[0].EntryDataId);

                    itmcount = 0;
                }
                return(itmcount);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 20
0
        //private void SaveSearchResults()
        //{
        //    //foreach (var item in AsycudaDocumentSummaryListModel._asycudaDocuments.ToList())
        //    //{
        //    //   Document_Type doc = db.Document_Type.FirstOrDefault();

        //    //    doc.LoadAllChild();

        //    //    Document_Type ndoc = Common.EntityClone<Document_Type>(doc);

        //    //    DetachAll(doc, true);
        //    //    //Clear Entity Values of New Object

        //    //    ndoc.ClearEntityReference(true);
        //    //    //detach the Load empbasic from Context

        //    //    ndoc.AsycudaDocumentSet.Clear();

        //    //    //Add new Clone Object and save it DB
        //    //    db.Document_Type.AddObject(ndoc);

        //    //    //xcuda_ASYCUDA doc = db.xcuda_ASYCUDA.Where(x => x.ASYCUDA_Id == item.ASYCUDA_Id).FirstOrDefault();

        //    //    //doc.LoadAllChild();

        //    //    //xcuda_ASYCUDA ndoc = Common.EntityClone<xcuda_ASYCUDA>(doc);

        //    //    //DetachAll(doc,true);
        //    //    ////Clear Entity Values of New Object

        //    //    //ndoc.ClearEntityReference(true);
        //    //    ////detach the Load empbasic from Context


        //    //    ////Add new Clone Object and save it DB
        //    //    //db.xcuda_ASYCUDA.AddObject(ndoc);
        //    //    //ndoc.xcuda_ASYCUDA_ExtendedProperties.AsycudaDocumentSet = BaseDataModel.Instance.CurrentAsycudaDocumentSet;
        //    //    SaveDatabase();
        //    //}

        //}



        //private AsycudaDocumentSet CreateNewAsycudaDocumentSet()
        //{
        //   return CreateNewAsycudaDocumentSet(db);
        //}
        async Task <AsycudaDocumentSet> CreateNewAsycudaDocumentSet()
        {
            using (var ctx = new AsycudaDocumentSetService())
            {
                //var dset = (await ctx.AsycudaDocumentSets().ConfigureAwait(false)).FirstOrDefault(ads => ads.Declarant_Reference_Number == docInfo.DeclarantReferenceNumber);
                //if (dset == null)
                //{
                var dset = new AsycudaDocumentSet()
                {
                    TrackingState = TrackingState.Added
                };
                // dset = await ctx.CreateAsycudaDocumentSet(dset).ConfigureAwait(false);
                //  UpdateDocSet(dset);
                await ctx.UpdateAsycudaDocumentSet(dset).ConfigureAwait(false);

                //}
                return(dset);
            }
        }
Exemplo n.º 21
0
        private async Task CreateIM9Entries(AsycudaDocumentSet docSet, bool PerIM7, IEnumerable <AsycudaDocumentItemIM9> alst)
        {
            var elst = alst.OrderByDescending(x => x.RegistrationDate).GroupBy(x => x.AsycudaDocumentId);

            var itmcount = 0;

            DocumentCT cdoc = null;

            foreach (var entry in elst)
            {
                if (PerIM7)
                {
                    cdoc = await SaveAndCreateIM9Doc(docSet, cdoc).ConfigureAwait(false);
                }

                //create new document
                foreach (
                    var ditm in
                    entry.OrderByDescending(x => x.RegistrationDate).ThenBy(x => x.LineNumber))
                //.Where(x => x.CNumber == "24985" && x.LineNumber == 5)
                {
                    if (CreateEx9Class.Instance.MaxLineCount(itmcount) || itmcount == 0)
                    {
                        cdoc = await SaveAndCreateIM9Doc(docSet, cdoc).ConfigureAwait(false);
                    }

                    if (itmcount == 0)
                    {
                        cdoc.Document.xcuda_General_information.xcuda_Country.xcuda_Export.Export_country_code =
                            ditm.Country_of_origin_code;
                        cdoc.Document.xcuda_General_information.xcuda_Country.xcuda_Destination.Destination_country_code
                            = "GD";
                    }
                    var itm = CreateIM9Line(ditm, itmcount, cdoc);

                    cdoc.DocumentItems.Add(itm);
                    itmcount += 1;
                }
            }
            await SaveAndCreateIM9Doc(docSet, cdoc).ConfigureAwait(false);
        }
        public async Task WalkSalesReceiptQueryRs(IMsgSetResponse responseMsgSet, AsycudaDocumentSet currentAsycudaDocumentSet)
        {
            if (responseMsgSet == null)
            {
                return;
            }

            var responseList = responseMsgSet.ResponseList;

            if (responseList == null)
            {
                return;
            }

            //if we sent only one request, there is only one response, we'll walk the list for this sample
            for (var i = 0; i < responseList.Count; i++)
            {
                var response = responseList.GetAt(i);
                //check the status code of the response, 0=ok, >0 is warning
                if (response.StatusCode >= 0)
                {
                    //the request-specific response is in the details, make sure we have some
                    if (response.Detail != null)
                    {
                        //make sure the response is the type we're expecting
                        var responseType = (ENResponseType)response.Type.GetValue();
                        if (responseType == ENResponseType.rtSalesReceiptQueryRs)
                        {
                            //upcast to more specific type here, this is safe because we checked with response.Type check above
                            var SalesReceiptRet = (ISalesReceiptRetList)response.Detail;
                            await SaveToDataBase(WalkSalesReceiptRet(SalesReceiptRet), currentAsycudaDocumentSet).ConfigureAwait(false);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(response.StatusMessage);
                }
            }
        }
Exemplo n.º 23
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;
            }
        }
Exemplo n.º 24
0
        public async Task CreateShortsEx9(IEnumerable <OversShortEX> selos, AsycudaDocumentSet docSet, bool BreakOnMonthYear, bool ApplyEX9Bucket)
        {
            if (docSet == null)
            {
                throw new ApplicationException("Please Select a Asycuda Document Set before proceding");
            }



            if (selos.Any() == false)
            {
                throw new ApplicationException("Please Select Overs/Shorts before proceding");
            }

            StatusModel.Timer("Getting Data...");

            var slstSource =
                selos.SelectMany(x => x.OverShortDetailsEXes.Where(y => y.Type == "Short")).ToList();

            if (!slstSource.Any())
            {
                return;
            }
            IEnumerable <EXWDataBlock> slst;

            if (BreakOnMonthYear)
            {
                slst = (from s in slstSource
                        group s by new { MonthYear = s.OversShortEX.InvoiceDate.ToString("MMM-yy") }
                        into g
                        select new EXWDataBlock()
                {
                    MonthYear = g.Key.MonthYear,
                    DutyFreePaid = "DutyFree",
                    OverShortDetailsEX = g.ToList(),
                }).ToList();
            }
            else
            {
                slst = (from s in slstSource
                        group s by new { MonthYear = "NoMTY" }
                        into g
                        select new EXWDataBlock
                {
                    MonthYear = g.Key.MonthYear,
                    DutyFreePaid = "DutyFree",
                    OverShortDetailsEX = g.ToList(),
                }).ToList();
            }

            if (!slst.Any())
            {
                StatusModel.StopStatusUpdate();
                throw new ApplicationException(
                          "No OPS Allocations found! If you just deleted Entries, Please Allocate Sales then continue Else Contact your Network Administrator");
            }

            var dfp = "Duty Free";


            Document_Type dt = CreateDocumentType();

            if (dt == null)
            {
                return;
            }

            DocumentCT cdoc = await BaseDataModel.Instance.CreateDocumentCt(docSet).ConfigureAwait(false);

            CreateEx9Class.Instance.Ex9InitializeCdoc(dt, dfp, cdoc, docSet);

            cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Customs_Procedure = dt.DefaultCustoms_Procedure;

            int itmcount = 0;

            StatusModel.StartStatusUpdate("Creating Shorts EXW Entries", slst.Count());

            foreach (EXWDataBlock monthyear in slst)
            {
                var elst = PrepareShortsEXWData(monthyear);

                foreach (var pod in elst)
                {
                    StatusModel.StatusUpdate();

                    if (CreateEx9Class.Instance.CreateEx9EntryAsync(pod, cdoc, itmcount, dfp, ApplyEX9Bucket))
                    {
                        StatusModel.StatusUpdate();

                        itmcount += 1;
                    }

                    if (itmcount % BaseDataModel.Instance.CurrentApplicationSettings.MaxEntryLines == 0)
                    {
                        await BaseDataModel.Instance.SaveDocumentCT(cdoc).ConfigureAwait(false);
                    }
                    //dup new file
                    cdoc = await BaseDataModel.Instance.CreateDocumentCt(docSet).ConfigureAwait(false);

                    CreateEx9Class.Instance.Ex9InitializeCdoc(dt, dfp, cdoc, docSet);
                    cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Customs_Procedure = dt.DefaultCustoms_Procedure;
                    if (cdoc.Document != null)
                    {
                        cdoc.Document.xcuda_Valuation = new xcuda_Valuation();
                        cdoc.Document.xcuda_Valuation.xcuda_Weight = new xcuda_Weight();
                        cdoc.Document.xcuda_Valuation.xcuda_Weight.Gross_weight =
                            cdoc.Document.xcuda_PreviousItem.Sum(x => x.Net_weight);
                    }
                }
            }
            if (cdoc.DocumentItems.Count == 0)
            {
                await BaseDataModel.Instance.DeleteAsycudaDocument(cdoc.Document).ConfigureAwait(false);
            }
        }
Exemplo n.º 25
0
        private async Task <Container> ConfigureContainer(string wStr, AsycudaDocumentSet docSet)
        {
            try
            {
                var cnt = new Container()
                {
                    TrackingState = TrackingState.Added
                };
                var invoiceTotalMat      = GetMatchFromPattern(wStr, InvoiceTotalPat);
                var palletTotalMat       = GetMatchFromPattern(wStr, palletTotalPat);
                var containerIdentityMat = GetMatchFromPattern(wStr, containerIdentityPat);
                var shipDateSealMat      = GetMatchFromPattern(wStr, shipDateSealPat);
                var WeightTotalsMat      = GetMatchFromPattern(wStr, WeightTotalsPat);
                var cubicPat             = GetMatchFromPattern(wStr, cubicMeasurementsPat);


                if (containerIdentityPat != null)
                {
                    var cid = containerIdentityMat.Groups["ContainerIdentity"].Value;
                    using (var ctx = new ContainerService())
                    {
                        var res =
                            await
                            ctx.GetContainersByExpression(string.Format("Container_Identity == \"{0}\"", cid),
                                                          new List <string>()
                        {
                            "ContainerAsycudaDocumentSets"
                        })
                            .ConfigureAwait(false);

                        if (res.FirstOrDefault() != null)
                        {
                            cnt = res.FirstOrDefault();
                            cnt.StartTracking();
                        }
                    }
                    cnt.Container_identity = cid;
                    cnt.DeliveryDate       = Convert.ToDateTime(containerIdentityMat.Groups["DeliveryDate"].Value);
                }


                if (invoiceTotalMat != null)
                {
                    cnt.TotalValue = Convert.ToDouble(invoiceTotalMat.Groups["InvoiceTotal"].Value);
                }

                if (palletTotalPat != null)
                {
                    cnt.Packages_number = palletTotalMat.Groups["PalletTotal"].Value;
                    using (var ctx = new PackageTypesService())
                    {
                        var pklst =
                            await
                            ctx.GetPackageTypesByExpression("PackageDescription == \"Pallet\"")
                            .ConfigureAwait(false);

                        cnt.Packages_type = pklst.FirstOrDefault().PackageType;
                    }
                }
                if (shipDateSealMat != null)
                {
                    cnt.ShipDate = Convert.ToDateTime(shipDateSealMat.Groups["ShipDate"].Value);
                    cnt.Seal     = shipDateSealMat.Groups["Seal"].Value;
                }
                if (WeightTotalsMat != null)
                {
                    cnt.Gross_weight    = Convert.ToDouble(WeightTotalsMat.Groups["TotalKGS"].Value);
                    cnt.Packages_weight = Convert.ToDouble(WeightTotalsMat.Groups["TotalKGS"].Value);
                }

                cnt.Goods_description = "Food Stuff";

                if (cubicPat != null)
                {
                    var m3 = Convert.ToDouble(cubicPat.Groups["CubicMeters"].Value);
                    cnt.Container_type = m3 > 34 ? "40RG" : "20RG";
                }

                if (!cnt.ContainerAsycudaDocumentSets.Any(x => x.AsycudaDocumentSetId == docSet.AsycudaDocumentSetId))
                {
                    cnt.ContainerAsycudaDocumentSets.Add(new ContainerAsycudaDocumentSet()
                    {
                        AsycudaDocumentSetId = docSet.AsycudaDocumentSetId,
                        Container            = cnt,
                        TrackingState        = TrackingState.Added
                    });
                }

                using (var ctx = new ContainerService())
                {
                    cnt = await ctx.UpdateContainer(cnt).ConfigureAwait(false);
                }

                return(cnt);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 26
0
        public async Task CreateOPS(string filterExpression, AsycudaDocumentSet docSet)
        {
            if (docSet == null)
            {
                throw new ApplicationException("Please Select a Asycuda Document Set before proceding");
            }

            StatusModel.Timer("Getting Data...");

            var slstSource = await AllocationsModel.Instance.GetAsycudaSalesAllocations(filterExpression).ConfigureAwait(false);



            var slst = from s in slstSource.Where(p => p.PreviousDocumentItem != null &&
                                                  p.PreviousDocumentItem.AsycudaDocument.IsManuallyAssessed == true)
                       group s by new
            {
                s.EntryDataDetails.ItemNumber,
                s.EntryDataDetails.ItemDescription,
                s.EntryDataDetails.EntryDataDetailsEx.TariffCode,
                s.EntryDataDetails.Cost,
            }
            into g
                select new
            {
                Allocations = g.ToList(),
                EntlnData   = new AllocationsModel.AlloEntryLineData
                {
                    ItemNumber       = g.Key.ItemNumber,
                    ItemDescription  = g.Key.ItemDescription,
                    TariffCode       = g.Key.TariffCode,
                    Cost             = g.Key.Cost,
                    Quantity         = g.Sum(x => x.EntryDataDetails.Quantity),
                    EntryDataDetails = g.Select(x => x.EntryDataDetails as IEntryDataDetail).ToList()
                }
            };

            if (!slst.Any())
            {
                throw new ApplicationException(
                          "No OPS Allocations found! If you just deleted Entries, Please Allocate Sales then continue Else Contact your Network Administrator");
                StatusModel.StopStatusUpdate();
                return;
            }

            var cdoc = new DocumentCT();

            cdoc.Document = BaseDataModel.Instance.CreateNewAsycudaDocument(docSet);



            var itmcount = cdoc.DocumentItems.Count();

            var dt = BaseDataModel.Instance.Document_Types.AsEnumerable().FirstOrDefault(x => x.DisplayName == "IM7");

            if (dt == null)
            {
                throw new ApplicationException(string.Format("Null Document Type for '{0}' Contact your Network Administrator", "IM7"));
                return;
            }

            dt.DefaultCustoms_Procedure =
                BaseDataModel.Instance.Customs_Procedures.AsEnumerable()
                .FirstOrDefault(x => x.DisplayName.Contains("OPS") && x.Document_TypeId == dt.Document_TypeId);

            if (dt.DefaultCustoms_Procedure == null)
            {
                throw new ApplicationException(string.Format("Null Customs Procedure for '{0}' Contact your Network Administrator", "OPS"));
                return;
            }

            OPSIntializeCdoc(cdoc, dt, docSet);

            StatusModel.StartStatusUpdate("Creating Opening Stock Entries", slst.Count());


            foreach (var pod in slst)
            {
                StatusModel.StatusUpdate();

                var itm = BaseDataModel.Instance.CreateItemFromEntryDataDetail(pod.EntlnData, cdoc);

                cdoc.DocumentItems.Add(itm);
                foreach (var allo in pod.Allocations)
                {
                    allo.PreviousItem_Id = itm.Item_Id;
                }



                itmcount += 1;
                if (itmcount % BaseDataModel.Instance.CurrentApplicationSettings.MaxEntryLines == 0)
                {
                    //dup new file
                    cdoc          = new DocumentCT();
                    cdoc.Document = BaseDataModel.Instance.CreateNewAsycudaDocument(docSet);

                    OPSIntializeCdoc(cdoc, dt, docSet);
                }
            }
            if (cdoc.DocumentItems.Count == 0)
            {
                cdoc = null;
            }

            StatusModel.Timer("Saving to Database...");

            await BaseDataModel.Instance.SaveDocumentCT(cdoc).ConfigureAwait(false);

            StatusModel.StopStatusUpdate();
        }
        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");
        }
Exemplo n.º 28
0
        public static async Task DownloadQbData(DateTime startDate, DateTime endDate, AsycudaDocumentSet currentAsycudaDocumentSet, bool ImportSales, bool ImportInventory)
        {
            StatusModel.Timer("Connecting to QuickBooks");

            var sessionBegun   = false;
            var connectionOpen = false;
            QBPOSSessionManager sessionManager = null;

            //try
            //{
            // get qbpos filename
            var qbposfile = "";

            //Create the session Manager object
            sessionManager = new QBPOSSessionManager();
            sessionManager.OpenConnection("1", "Insight's Asycuda Toolkit");
            short          majorVersion;
            short          minorVersion;
            ENReleaseLevel releaseLevel;
            short          releaseNumber;

            // sessionManager.GetVersion(out majorVersion, out minorVersion, out releaseLevel, out releaseNumber);



            connectionOpen = true;
            sessionManager.BeginSession(qbposfile);
            sessionBegun = true;

            try
            {
                if (ImportInventory)
                {
                    var ItemInventoryRequestMsgSet = sessionManager.CreateMsgSetRequest(3, 0);
                    ItemInventoryRequestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
                    var    inventoryVM    = new ItemInventoryViewModel();
                    int    increment      = 1000;
                    int    toItemNumber   = 0;
                    int    fromItemNumber = 0;
                    string errstring      = null;

                    while (errstring == null)
                    {
                        toItemNumber += increment;
                        ItemInventoryRequestMsgSet.ClearRequests();
                        inventoryVM.BuildItemInventoryQueryRq(ItemInventoryRequestMsgSet, fromItemNumber, toItemNumber);
                        fromItemNumber = toItemNumber;
                        ItemInventoryRequestMsgSet.Verify(out errstring);

                        IMsgSetResponse ItemInventoryResponseMsgSet = null;
                        ItemInventoryResponseMsgSet = sessionManager.DoRequests(ItemInventoryRequestMsgSet);
                        var responseStatus = new Tuple <string>(null);
                        if (ItemInventoryResponseMsgSet != null)
                        {
                            responseStatus = await inventoryVM.WalkItemInventoryQueryRs(ItemInventoryResponseMsgSet).ConfigureAwait(false);
                        }

                        if (errstring != null || responseStatus.Item1 == "0")
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }



            if (ImportSales)
            {
                StatusModel.Timer("Getting Data Request");
                var SalesReceiptRequestMsgSet = sessionManager.CreateMsgSetRequest(3, 0);
                SalesReceiptRequestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
                var SalesReceiptVM = new SalesReceiptViewModel();
                SalesReceiptVM.BuildSalesReceiptQueryRq(SalesReceiptRequestMsgSet, startDate, endDate);
                IMsgSetResponse SalesReceiptResponseMsgSet = null;

                SalesReceiptResponseMsgSet = sessionManager.DoRequests(SalesReceiptRequestMsgSet);

                if (SalesReceiptResponseMsgSet != null)
                {
                    await SalesReceiptVM.WalkSalesReceiptQueryRs(SalesReceiptResponseMsgSet, currentAsycudaDocumentSet).ConfigureAwait(false);
                }
            }



            //End the session and close the connection to QuickBooks
            sessionManager.EndSession();
            sessionBegun = false;
            sessionManager.CloseConnection();
            connectionOpen = false;



            StatusModel.StopStatusUpdate();
        }
Exemplo n.º 29
0
 public static async Task AddDocToEntry(List <EntryDataEx> lst, AsycudaDocumentSet docSet)
 {
     await BaseDataModel.Instance.AddToEntry(lst, docSet).ConfigureAwait(false);
 }
Exemplo n.º 30
0
 internal async Task ProcessDroppedFile(string droppedFilePath, string fileType, AsycudaDocumentSet docSet, bool overWriteExisting)
 {
     try
     {
         await SaveCSV(droppedFilePath, fileType, docSet, overWriteExisting).ConfigureAwait(false);
     }
     catch (Exception Ex)
     {
         throw new ApplicationException(string.Format("Problem importing File '{0}'. - Error: {1}", droppedFilePath, Ex.Message));
     }
 }