private static async Task SaveDocumentCT(DocumentCT cdoc) { try { if (cdoc != null && cdoc.DocumentItems.Any() == true) { if (cdoc.Document.xcuda_Valuation == null) { cdoc.Document.xcuda_Valuation = new xcuda_Valuation() { ASYCUDA_Id = cdoc.Document.ASYCUDA_Id, TrackingState = TrackingState.Added } } ; if (cdoc.Document.xcuda_Valuation.xcuda_Weight == null) { cdoc.Document.xcuda_Valuation.xcuda_Weight = new xcuda_Weight() { Valuation_Id = cdoc.Document.xcuda_Valuation.ASYCUDA_Id, TrackingState = TrackingState.Added } } ; cdoc.Document.xcuda_Valuation.xcuda_Weight.Gross_weight = cdoc.DocumentItems.Select(x => x.xcuda_PreviousItem).Sum(x => x.Net_weight); await BaseDataModel.Instance.SaveDocumentCT(cdoc).ConfigureAwait(false); } } catch (Exception) { throw; } }
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(); }
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(); }
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; } }
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; } }
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(); }
private static void AttachCustomProcedure(DocumentCT cdoc, Customs_Procedure cp) { if (cp == null) { throw new ApplicationException("Default Export Template not configured properly!"); } else { cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Customs_ProcedureId = cp.Customs_ProcedureId; cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Customs_Procedure = cp; cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Document_TypeId = cp.Document_TypeId; cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Document_Type = cp.Document_Type; } }
private void InsertEntryIdintoRefNum(DocumentCT cdoc, string entryDataId) { try { if (BaseDataModel.Instance.CurrentApplicationSettings.InvoicePerEntry == true) { cdoc.Document.xcuda_Declarant.Number = entryDataId; } } catch (Exception) { throw; } }
public async Task SaveDocumentCT(AsycudaDocument entity) { var ct = new DocumentCT(); ct.Document = await WaterNut.DataSpace.BaseDataModel.Instance.GetDocument(entity.ASYCUDA_Id, new List <string>() { "xcuda_ASYCUDA_ExtendedProperties", "xcuda_Identification", "xcuda_Valuation.xcuda_Gs_Invoice", "xcuda_Declarant", "xcuda_General_information.xcuda_Country", "xcuda_Property" }).ConfigureAwait(false); using (var ctx = new xcuda_ItemService()) { var res = (await ctx.Getxcuda_ItemByASYCUDA_Id(entity.ASYCUDA_Id.ToString(), new List <string>() { "xcuda_Previous_doc" }).ConfigureAwait(false)); if (res != null) { ct.DocumentItems = res.ToList(); } } // bl foreach (var itm in ct.DocumentItems.Where(x => x.xcuda_Previous_doc.Summary_declaration != entity.BLNumber)) { itm.xcuda_Previous_doc.StartTracking(); itm.xcuda_Previous_doc.Summary_declaration = entity.BLNumber; } ct.Document.xcuda_Identification.StartTracking(); ct.Document.xcuda_Identification.Manifest_reference_number = entity.Manifest_reference_number; ct.Document.xcuda_Valuation.xcuda_Gs_Invoice.StartTracking(); ct.Document.xcuda_Valuation.xcuda_Gs_Invoice.Currency_code = entity.Currency_code; ct.Document.xcuda_Valuation.xcuda_Gs_Invoice.Currency_rate = entity.Currency_rate.GetValueOrDefault(); ct.Document.xcuda_ASYCUDA_ExtendedProperties.StartTracking(); ct.Document.xcuda_ASYCUDA_ExtendedProperties.Description = entity.Description; ct.Document.xcuda_ASYCUDA_ExtendedProperties.Document_TypeId = entity.Document_TypeId; ct.Document.xcuda_ASYCUDA_ExtendedProperties.Customs_ProcedureId = entity.Customs_ProcedureId; ct.Document.xcuda_Declarant.StartTracking(); ct.Document.xcuda_Declarant.Number = string.Format("{0}-F{1}", entity.ReferenceNumber, ct.Document.xcuda_ASYCUDA_ExtendedProperties.FileNumber); ct.Document.xcuda_General_information.xcuda_Country.StartTracking(); ct.Document.xcuda_General_information.xcuda_Country.Country_first_destination = entity.Country_first_destination; await WaterNut.DataSpace.BaseDataModel.Instance.SaveDocumentCT(ct).ConfigureAwait(false); }
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; } }
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 CreateIncompOPS(string filterExpression, AsycudaDocumentSet docSet) { if (docSet == null) { throw new ApplicationException("Please Select a Asycuda Document Set before proceding"); } var cdoc = new DocumentCT(); cdoc.Document = BaseDataModel.Instance.CreateNewAsycudaDocument(docSet); StatusModel.Timer("Getting Data ..."); var itmcount = cdoc.DocumentItems.Count(); var slst = await AllocationsModel.Instance.GetAsycudaSalesAllocations(filterExpression).ConfigureAwait(false); 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; } IncompOpsIntializeCdoc(cdoc, dt, docSet); var cslst = slst.Where(x => x.EntryDataDetails.Quantity > 0) .Select(x => x.EntryDataDetails).Distinct(); StatusModel.StartStatusUpdate("Creating Incomplete Allocation OPS entries", cslst.Count()); foreach (var pod in cslst) { StatusModel.StatusUpdate(); var el = new AllocationsModel.AlloEntryLineData() { ItemNumber = pod.ItemNumber, ItemDescription = pod.ItemDescription, Cost = pod.Cost, TariffCode = pod.EntryDataDetailsEx.TariffCode, Quantity = pod.Quantity - pod.QtyAllocated, EntryDataDetails = new List <IEntryDataDetail>() { pod } }; var itm = BaseDataModel.Instance.CreateItemFromEntryDataDetail(el, cdoc); // SwitchToMyDB(mydb, itm); cdoc.DocumentItems.Add(itm); // pod.PreviousDocumentItem = itm; itmcount += 1; if (itmcount % BaseDataModel.Instance.CurrentApplicationSettings.MaxEntryLines == 0) { //dup new file cdoc = new DocumentCT(); cdoc.Document = BaseDataModel.Instance.CreateNewAsycudaDocument(docSet); IncompOpsIntializeCdoc(cdoc, dt, docSet); } } if (cdoc.DocumentItems.Count == 0) { cdoc = null; } await BaseDataModel.Instance.SaveDocumentCT(cdoc).ConfigureAwait(false); StatusModel.StopStatusUpdate(); }
private xcuda_Item CreateIM9Line(AsycudaDocumentItemIM9 ditm, int itmcount, DocumentCT cdoc) { try { var itm = new xcuda_Item(true) { ItemNumber = ditm.ItemNumber, ItemQuantity = Convert.ToDouble(ditm.ItemQuantity - ditm.PiQuantity), xcuda_PreviousItem = new xcuda_PreviousItem(true) { TrackingState = TrackingState.Added, Hs_code = ditm.TariffCode, Commodity_code = "00", Current_item_number = (itmcount + 1).ToString(), // piggy back the previous item count Previous_item_number = ditm.LineNumber.ToString(), Previous_Packages_number = ditm.Number_of_packages.ToString(), Suplementary_Quantity = Convert.ToDouble(ditm.ItemQuantity - ditm.PiQuantity), Preveious_suplementary_quantity = Convert.ToDouble(ditm.ItemQuantity), Prev_net_weight = ditm.Net_weight, //////////////////////////todo/////////////////////////// Net_weight = ditm.Net_weight - ditm.PiWeight, Goods_origin = ditm.Country_of_origin_code, Previous_value = Convert.ToDouble((ditm.Total_CIF_itm / ditm.ItemQuantity)), Current_value = Convert.ToDouble((ditm.Total_CIF_itm) / ditm.ItemQuantity), Prev_reg_ser = "C", Prev_reg_nbr = ditm.CNumber, Prev_reg_dat = ditm.RegistrationDate.Year.ToString(), Prev_reg_cuo = ditm.Customs_clearance_office_code ?? "GDSGO", }, ASYCUDA_Id = cdoc.Document.ASYCUDA_Id, TrackingState = TrackingState.Added }; var pitm = itm.xcuda_PreviousItem; pitm.xcuda_Item = itm; if (ditm.Number_of_packages != 0) { if (itm.xcuda_Packages.FirstOrDefault() == null) { itm.xcuda_Packages.Add(new xcuda_Packages(true) { TrackingState = TrackingState.Added }); } itm.xcuda_Packages.FirstOrDefault().Number_of_packages = ditm.Number_of_packages; } itm.xcuda_Goods_description.Commercial_Description = ditm.Commercial_Description; if (cdoc.Document.xcuda_General_information != null) { itm.xcuda_Goods_description.Country_of_origin_code = cdoc.Document.xcuda_General_information.xcuda_Country.Country_first_destination; } itm.xcuda_Tarification.Item_price = Convert.ToSingle(ditm.Item_price / ditm.ItemQuantity) * itm.ItemQuantity; itm.xcuda_Tarification.xcuda_HScode.Commodity_code = pitm.Hs_code; itm.xcuda_Tarification.xcuda_HScode.Precision_1 = pitm.Commodity_code; itm.xcuda_Tarification.xcuda_HScode.InventoryItems = BaseDataModel.Instance.GetInventoryItem(x => x.ItemNumber == ditm.ItemNumber); itm.xcuda_Goods_description.Country_of_origin_code = pitm.Goods_origin; itm.xcuda_Previous_doc.Summary_declaration = String.Format("{0} {1} C {2} art. {3}", pitm.Prev_reg_cuo, pitm.Prev_reg_dat, pitm.Prev_reg_nbr, pitm.Previous_item_number); itm.xcuda_Valuation_item.xcuda_Weight_itm = new xcuda_Weight_itm(true) { TrackingState = TrackingState.Added }; itm.xcuda_Valuation_item.xcuda_Weight_itm.Gross_weight_itm = pitm.Net_weight; itm.xcuda_Valuation_item.xcuda_Weight_itm.Net_weight_itm = pitm.Net_weight; // adjusting because not using real statistical value when calculating itm.xcuda_Valuation_item.xcuda_Item_Invoice.Amount_foreign_currency = Convert.ToDouble(Math.Round((pitm.Current_value * pitm.Suplementary_Quantity), 2)); itm.xcuda_Valuation_item.xcuda_Item_Invoice.Amount_national_currency = Convert.ToDouble(Math.Round(pitm.Current_value * pitm.Suplementary_Quantity, 2)); itm.xcuda_Valuation_item.xcuda_Item_Invoice.Currency_code = "XCD"; itm.xcuda_Valuation_item.xcuda_Item_Invoice.Currency_rate = 1; itm.xcuda_Valuation_item.Total_CIF_itm = Convert.ToSingle(Math.Round((pitm.Current_value * pitm.Suplementary_Quantity), 4)); itm.xcuda_Valuation_item.Statistical_value = Convert.ToSingle(Math.Round((pitm.Current_value * pitm.Suplementary_Quantity), 4)); if (itmcount == 0) //cdoc.DocumentItems.Select(x => x.xcuda_PreviousItem).Count() == 1 || { pitm.Packages_number = "1"; //(i.Packages.Number_of_packages).ToString(); pitm.Previous_Packages_number = pitm.Previous_item_number == "1" ? "1" : "0"; } else { if (pitm.Packages_number == null) { pitm.Packages_number = (0).ToString(CultureInfo.InvariantCulture); pitm.Previous_Packages_number = (0).ToString(CultureInfo.InvariantCulture); } } //if (ditm.xcuda_Supplementary_unit.Count > 1) //{ // var sup = ditm.xcuda_Supplementary_unit[1]; itm.xcuda_Tarification.Unordered_xcuda_Supplementary_unit.Add(new xcuda_Supplementary_unit(true) { Suppplementary_unit_code = ditm.Suppplementary_unit_code, Suppplementary_unit_quantity = ditm.ItemQuantity, TrackingState = TrackingState.Added }); //} itm.ImportComplete = true; return(itm); } catch (Exception) { throw; } }
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); }
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); } }
private void Ex9Bucket(AllocationsModel.MyPodData mypod, string dfp, DocumentCT cdoc) { // prevent over draw down of pqty == quantity allocated try { var eld = mypod.EntlnData; var previousItem = mypod.EntlnData.PreviousDocumentItem as xcuda_Item; if (previousItem == null) { return; } var PdfpAllocated = (dfp == "Duty Free" ? previousItem.DFQtyAllocated : previousItem.DPQtyAllocated); var pAllocated = previousItem.DFQtyAllocated + previousItem.DPQtyAllocated; if (previousItem.QtyAllocated == 0) { if (dfp == "Duty Free") { previousItem.DFQtyAllocated = 0; } else { previousItem.DPQtyAllocated = 0; } } if (previousItem.xcuda_PreviousItems.Any() == false) { return; } var pqty = previousItem.xcuda_PreviousItems.Where(x => x.xcuda_Item.AsycudaDocument.CNumber != null && x.DutyFreePaid == dfp).Sum(xx => xx.Suplementary_Quantity); var apqty = previousItem.xcuda_PreviousItems.Where(x => x.xcuda_Item.AsycudaDocument.CNumber != null).Sum(xx => xx.Suplementary_Quantity); if (previousItem.QtyAllocated == 0) { return; } if (pqty != 0 && previousItem.xcuda_PreviousItems.Sum(x => x.Suplementary_Quantity) == previousItem.ItemQuantity) { pqty = Convert.ToDouble(previousItem.xcuda_PreviousItems.Sum(x => x.Suplementary_Quantity)); } if (pqty == 0 && (eld.Quantity > (previousItem.ItemQuantity - previousItem.xcuda_PreviousItems.Sum(x => x.Suplementary_Quantity)))) { pqty = Convert.ToDouble(previousItem.xcuda_PreviousItems.Sum(x => x.Suplementary_Quantity)); } if (previousItem.ItemQuantity == apqty) { mypod.Allocations.Clear(); eld.EntryDataDetails.Clear(); eld.Quantity = 0; return; } if (PdfpAllocated - (apqty + Convert.ToDouble(eld.Quantity)) < 0) { var qty = PdfpAllocated - (apqty); var lst = eld.EntryDataDetails.OrderBy(x => (x as EntryDataDetails).Sales.EntryDataDate).ToList(); var aqty = PdfpAllocated; var lqty = lst.Sum(x => x.QtyAllocated); while (qty < lqty) { if (lst.Any() == false) { break; } lqty -= lst.ElementAt(0).QtyAllocated; //if (aqty < qty) //{ //} var entlst = mypod.Allocations.Where(x => x.EntryDataDetails.EntryDataDetailsId == lst.ElementAt(0).EntryDataDetailsId).ToList(); foreach (var item in entlst) { mypod.Allocations.Remove(item); } eld.EntryDataDetails.Remove(lst.ElementAt(0)); lst.RemoveAt(0); } eld.Quantity = qty; } } catch (Exception Ex) { throw; } }
public bool CreateEx9EntryAsync(dynamic mypod, DocumentCT cdoc, int itmcount, string dfp, bool applyEX9Bucket) { try { if (applyEX9Bucket == true) { Ex9Bucket(mypod, dfp, cdoc); } mypod.EntlnData.Quantity = Math.Round(mypod.EntlnData.Quantity, 2); if (mypod.EntlnData.Quantity <= 0) { return(false); } global::DocumentItemDS.Business.Entities.xcuda_PreviousItem pitm = CreatePreviousItem(mypod.EntlnData, itmcount, dfp); if (pitm.Net_weight < 0.01) { foreach (AsycudaSalesAllocations item in mypod.Allocations) { item.Status = "Net Weight < 0.01"; } return(false); } //cdoc.Document.xcuda_PreviousItem.Add(pitm); pitm.ASYCUDA_Id = cdoc.Document.ASYCUDA_Id; global::DocumentItemDS.Business.Entities.xcuda_Item itm = BaseDataModel.Instance.CreateItemFromEntryDataDetail(mypod.EntlnData, cdoc); itm.xcuda_ASYCUDA = cdoc.Document; //TODO:Refactor this dup code if (mypod.Allocations != null) { var itmcnt = 0; foreach ( var allo in (mypod.Allocations as List <AsycudaSalesAllocations>))//.Distinct() { itm.xBondAllocations.Add(new xBondAllocations() { AllocationId = allo.AllocationId, xcuda_Item = itm, TrackingState = TrackingState.Added }); itmcnt = AddFreeText(itmcnt, itm, allo.EntryDataDetails.EntryDataId); } } //return true; itm.xcuda_PreviousItem = pitm; pitm.xcuda_Item = itm; // cdoc.Document.xcuda_PreviousItem.Add(pitm); //pitm.xcuda_ASYCUDA = cdoc; // pitm.PreviousDocumentItem = itm; itm.xcuda_Tarification.xcuda_HScode.Commodity_code = pitm.Hs_code; itm.xcuda_Goods_description.Country_of_origin_code = pitm.Goods_origin; itm.xcuda_Previous_doc.Summary_declaration = String.Format("{0} {1} C {2} art. {3}", pitm.Prev_reg_cuo, pitm.Prev_reg_dat, pitm.Prev_reg_nbr, pitm.Previous_item_number); itm.xcuda_Valuation_item.xcuda_Weight_itm = new xcuda_Weight_itm() { TrackingState = TrackingState.Added }; itm.xcuda_Valuation_item.xcuda_Weight_itm.Gross_weight_itm = pitm.Net_weight; itm.xcuda_Valuation_item.xcuda_Weight_itm.Net_weight_itm = pitm.Net_weight; // adjusting because not using real statistical value when calculating itm.xcuda_Valuation_item.xcuda_Item_Invoice.Amount_foreign_currency = Convert.ToDouble(Math.Round((pitm.Current_value * pitm.Suplementary_Quantity), 2)); itm.xcuda_Valuation_item.xcuda_Item_Invoice.Amount_national_currency = Convert.ToDouble(Math.Round(pitm.Current_value * pitm.Suplementary_Quantity, 2)); itm.xcuda_Valuation_item.xcuda_Item_Invoice.Currency_code = "XCD"; itm.xcuda_Valuation_item.xcuda_Item_Invoice.Currency_rate = 1; if (cdoc.DocumentItems.Select(x => x.xcuda_PreviousItem).Count() == 1 || itmcount == 0) { pitm.Packages_number = "1"; //(i.Packages.Number_of_packages).ToString(); pitm.Previous_Packages_number = pitm.Previous_item_number == "1" ? "1" : "0"; } else { pitm.Packages_number = (0).ToString(CultureInfo.InvariantCulture); pitm.Previous_Packages_number = (0).ToString(CultureInfo.InvariantCulture); } return(true); } catch (Exception Ex) { throw; } }
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(); }
public async Task CreateOversOps(IEnumerable <OversShortEX> selOS, AsycudaDocumentSet docSet) { 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 == "Over")).ToList(); if (!slstSource.Any()) { StatusModel.StopStatusUpdate(); return; } var slst = (from s in slstSource group s by new { s.ItemNumber, s.ItemDescription, s.InventoryItem.TariffCode, s.Cost, s.InventoryItem } into g select new { EntlnData = new BaseDataModel.EntryLineData() { ItemNumber = g.Key.ItemNumber, ItemDescription = g.Key.ItemDescription, TariffCode = g.Key.TariffCode, Cost = Convert.ToDouble(g.Key.Cost), InventoryItem = g.Key.InventoryItem, Quantity = Convert.ToDouble(g.Sum(x => x.OversQuantity)), EntryDataDetails = new List <IEntryDataDetail>() } }).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"); } DocumentCT cdoc = await BaseDataModel.Instance.CreateDocumentCt(docSet).ConfigureAwait(false); int itmcount = 0; Document_Type dt = BaseDataModel.Instance.Document_Types.FirstOrDefault(x => x.DisplayName == "IM7"); if (dt == null) { StatusModel.StopStatusUpdate(); throw new ApplicationException(string.Format("Null Document Type for '{0}' Contact your Network Administrator", "IM7")); } dt.DefaultCustoms_Procedure = BaseDataModel.Instance.Customs_Procedures .FirstOrDefault(x => x.DisplayName.Contains("OPP") && x.Document_TypeId == dt.Document_TypeId); if (dt.DefaultCustoms_Procedure == null) { StatusModel.StopStatusUpdate(); throw new ApplicationException(string.Format("Null Customs Procedure for '{0}' Contact your Network Administrator", "OPP")); } CreateOPSClass.Instance.OPSIntializeCdoc(cdoc, dt, docSet); cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Customs_Procedure = dt.DefaultCustoms_Procedure; StatusModel.StartStatusUpdate("Creating Opening Stock Entries", slst.Count()); foreach (var pod in slst) { StatusModel.StatusUpdate(); xcuda_Item itm = BaseDataModel.Instance.CreateItemFromEntryDataDetail(pod.EntlnData, cdoc); if (itm != null) { itmcount += 1; } if (itmcount % BaseDataModel.Instance.CurrentApplicationSettings.MaxEntryLines == 0) { await BaseDataModel.Instance.SaveDocumentCT(cdoc).ConfigureAwait(false); cdoc = await BaseDataModel.Instance.CreateDocumentCt(docSet).ConfigureAwait(false); CreateOPSClass.Instance.OPSIntializeCdoc(cdoc, dt, docSet); cdoc.Document.xcuda_ASYCUDA_ExtendedProperties.Customs_Procedure = dt.DefaultCustoms_Procedure; } } if (cdoc.DocumentItems.Count == 0) { await BaseDataModel.Instance.DeleteAsycudaDocument(cdoc.Document).ConfigureAwait(false); } }