internal void AdjustTobaccoQuantity(ref decimal totalQuantity, NamedTraceLogger.TraceAction trace) { trace("Entering Material.AdjustTobaccoQuantity", 135, TraceSeverity.Verbose); decimal _available = Accounts2Dispose.Sum(y => y.TobaccoNotAllocatedDec) + Disposed; if (Math.Abs(_available - TobaccoQuantityDec) > Settings.MinimalOveruse) { return; } totalQuantity += _available - TobaccoQuantityDec; decimal _startingTobaccoQuantity = this.TobaccoQuantityDec; this.TobaccoQuantityDec = _available; Warnning _warnning = null; if (Accounts2Dispose.Count > 0) { string _tmpl = "Adjusted TobaccoQuantity of material: batch {0} IPR: {1}"; _warnning = new Warnning(String.Format(_tmpl, this.Batch, String.Concat(Accounts2Dispose.Select <IPR, string>(x => x.DocumentNo).ToArray <string>())), false); } else { string _tmpl = "Cleared TobaccoQuantity of {0}kg for the material: batch {1} because no account to adjust found."; _warnning = new Warnning(String.Format(_tmpl, _startingTobaccoQuantity, this.Batch), false); } trace("Wanning at Material.AdjustTobaccoQuantity: " + _warnning.Message, 135, TraceSeverity.Monitorable); }
internal IPR.Balance Update(Entities edc, NamedTraceLogger.TraceAction trace) { trace("Entering BalanceIPR.Update", 453, TraceSeverity.Verbose); if (this.IPRIndex == null) { throw new ArgumentNullException("IPRIndex", "IPRIndex for Balance IPR cannot be null"); } IPR.Balance _balnce = new IPR.Balance(edc, this.IPRIndex, trace); DustCSNotStarted = _balnce[IPR.ValueKey.DustCSNotStarted]; DustCSStarted = _balnce[IPR.ValueKey.DustCSStarted]; IPRBook = _balnce[IPR.ValueKey.IPRBook]; OveruseCSNotStarted = _balnce[IPR.ValueKey.OveruseCSNotStarted]; OveruseCSStarted = _balnce[IPR.ValueKey.OveruseCSStarted]; PureTobaccoCSNotStarted = _balnce[IPR.ValueKey.PureTobaccoCSNotStarted]; PureTobaccoCSStarted = _balnce[IPR.ValueKey.PureTobaccoCSStarted]; SHMentholCSNotStarted = _balnce[IPR.ValueKey.SHMentholCSNotStarted]; SHMentholCSStarted = _balnce[IPR.ValueKey.SHMentholCSStarted]; SHWasteOveruseCSNotStarted = _balnce[IPR.ValueKey.SHWasteOveruseCSNotStarted]; TobaccoAvailable = _balnce[IPR.ValueKey.TobaccoAvailable]; TobaccoCSFinished = _balnce[IPR.ValueKey.TobaccoCSFinished]; TobaccoEnteredIntoIPR = _balnce[IPR.ValueKey.TobaccoEnteredIntoIPR]; TobaccoInFGCSNotStarted = _balnce[IPR.ValueKey.TobaccoInFGCSNotStarted]; TobaccoInFGCSStarted = _balnce[IPR.ValueKey.TobaccoInFGCSStarted]; TobaccoToBeUsedInTheProduction = _balnce[IPR.ValueKey.TobaccoToBeUsedInTheProduction]; TobaccoUsedInTheProduction = _balnce[IPR.ValueKey.TobaccoUsedInTheProduction]; WasteCSNotStarted = _balnce[IPR.ValueKey.WasteCSNotStarted]; WasteCSStarted = _balnce[IPR.ValueKey.WasteCSStarted]; TobaccoStarted = _balnce[IPR.ValueKey.TobaccoStarted]; Balance = this.IPRIndex.TobaccoNotAllocated - _balnce[IPR.ValueKey.TobaccoToBeUsedInTheProduction]; Title = String.Format("{0}/{1}", this.Batch, this.DocumentNo); return(_balnce); }
/// <summary> /// Clear through customs according procedure 4051. /// </summary> /// <param name="entities">The entities.</param> /// <param name="good">The good description form.</param> /// <param name="trace">The trace action.</param> /// <exception cref="InputDataValidationException">SAD Required Documents;clear through customs fatal error; true</exception> private static void IPRClearThroughCustoms(Entities entities, SADGood good, NamedTraceLogger.TraceAction trace) { foreach (Clearence _clearance in GetClearanceIds(entities, good, Settings.GetParameter(entities, SettingsEntry.RequiredDocumentFinishedGoodExportConsignmentPattern))) { _clearance.FinishClearingThroughCustoms(entities, good, trace); } }
private void UpdateNotStartedDisposals(Entities edc, NamedTraceLogger.TraceAction trace) { trace("Entering SummaryContentInfo.UpdateNotStartedDisposals", 192, TraceSeverity.Verbose); foreach (Material _materialX in this.Values) { _materialX.UpdateDisposals(edc, trace); } }
/// <summary> /// Clears through customs. /// </summary> /// <param name="entities">The entities.</param> /// <param name="trace">The trace action.</param> public void FinishClearingThroughCustoms(Entities entities, NamedTraceLogger.TraceAction trace) { trace("Entering Clearence.FinishClearingThroughCustoms", 47, TraceSeverity.Verbose); SADDocumentType sadDocument = Clearence2SadGoodID.SADDocumentIndex; DocumentNo = sadDocument.DocumentNumber; ReferenceNumber = sadDocument.ReferenceNumber; SPStatus = true; foreach (Disposal _disposal in this.Disposal(entities)) { _disposal.FinishClearingThroughCustoms(entities, Clearence2SadGoodID, trace); } UpdateTitle(entities); }
internal void FinishClearThroughCustoms(Entities entities, NamedTraceLogger.TraceAction traceEvent) { traceEvent("Starting Clearence.FinishClearThroughCustoms", 74, TraceSeverity.Verbose); SADDocumentType _sadDocument = Clearence2SadGoodID.SADDocumentIndex; DocumentNo = _sadDocument.DocumentNumber; ReferenceNumber = _sadDocument.ReferenceNumber; SPStatus = true; foreach (CustomsWarehouseDisposal _cwdx in this.CustomsWarehouseDisposal(entities, false)) { _cwdx.FinishClearThroughCustoms(entities, Clearence2SadGoodID, traceEvent); } UpdateTitle(entities, traceEvent); traceEvent("Finished Clearence.FinishClearThroughCustoms", 82, TraceSeverity.Verbose); }
internal void FinishClearThroughCustoms(Entities edc, SADGood sadGood, NamedTraceLogger.TraceAction traceEvent) { traceEvent("Starting CustomsWarehouseDisposal.FinishClearThroughCustoms for sadGood:" + sadGood.Title, 100, TraceSeverity.Verbose); if (this.CustomsStatus.Value == Linq.CustomsStatus.Finished) { return; } try { List <CustomsWarehouseDisposal> _Finished = (from _dsp in this.CWL_CWDisposal2CustomsWarehouseID.CustomsWarehouseDisposal(edc, false) where _dsp.CustomsStatus.Value == Linq.CustomsStatus.Finished select _dsp).ToList <CustomsWarehouseDisposal>(); if (_Finished.Count <CustomsWarehouseDisposal>() == 0) { this.SPNo = 1; } else { this.SPNo = _Finished.Max <CustomsWarehouseDisposal>(dspsl => dspsl.SPNo.Value) + 1; } AssignSADGood(edc, sadGood, traceEvent); decimal _balance = CalculateRemainingQuantity(); if (_balance == 0) { this.CW_RemainingPackage = 0; this.CW_RemainingTobaccoValue = 0; this.ClearingType = Linq.ClearingType.TotalWindingUp; } else { double _value = _Finished.Sum <CustomsWarehouseDisposal>(x => x.TobaccoValue.Value); double _pckgs = _Finished.Sum <CustomsWarehouseDisposal>(x => x.CW_PackageToClear.Value); this.CW_RemainingPackage = this.CWL_CWDisposal2CustomsWarehouseID.CW_PackageUnits - _pckgs - this.CW_PackageToClear; this.CW_RemainingTobaccoValue = this.CWL_CWDisposal2CustomsWarehouseID.Value - _value - this.TobaccoValue; this.ClearingType = Linq.ClearingType.PartialWindingUp; } CheckCNConsistency(traceEvent); this.CustomsStatus = Linq.CustomsStatus.Finished; } catch (Exception ex) { traceEvent("Exception at CustomsWarehouseDisposal.FinishClearThroughCustoms for sadGood:" + ex.Message, 133, TraceSeverity.High); throw; } traceEvent("Finished CustomsWarehouseDisposal.FinishClearThroughCustoms", 136, TraceSeverity.Verbose); }
internal void RecalculateClearedRecords(Entities edc, NamedTraceLogger.TraceAction trace) { trace("Entering IPR.RecalculateClearedRecords", 453, TraceSeverity.Verbose); if (this.AccountClosed.Value) { trace("ApplicationException at IPR.RecalculateClearedRecords - closed account", 455, TraceSeverity.High); throw new ApplicationException("IPR.RecalculateClearedRecords cannot be executed for closed account"); } IEnumerable <Disposal> _2Calculate = this.Disposals(edc, trace); _2Calculate = (from _dx in _2Calculate where _dx.CustomsStatus.Value == Linq.CustomsStatus.Finished orderby _dx.SPNo.Value ascending select _dx).ToList <Disposal>(); this.AccountBalance = this.NetMass; foreach (Disposal _dx in _2Calculate) { _dx.CalculateRemainingQuantity(); } }
/// <summary> /// Return all Disposals associated with this item. /// </summary> /// <param name="edc">The <see cref="Entities" /> object.</param> /// <param name="trace">The trace action.</param> /// <returns>All Disposals associated with this item</returns> public IEnumerable <Disposal> Disposals(Entities edc, NamedTraceLogger.TraceAction trace) { if (!this.Id.HasValue) { trace("IPR.Disposals - ArgumentOutOfRangeException: Reverse lookup cannot be evaluated for new entities.", 147, TraceSeverity.High); throw new ArgumentOutOfRangeException("IPR.Id", "Reverse lookup cannot be evaluated for new entities."); } if (m_Disposals == null) { trace("IPR.Disposals reverse lookup calculation.", 151, TraceSeverity.Verbose); m_Disposals = from _dsx in edc.Disposal let _idx = _dsx.Disposal2IPRIndex.Id.Value where _idx == this.Id.Value select _dsx; trace(String.Format("IPR.Disposals found reverse lookups {0}.", m_Disposals.Count()), 157, TraceSeverity.Verbose); } return(m_Disposals); }
/// <summary> /// Updates the title. /// </summary> /// <param name="entities">The auto-generated <see cref="Microsoft.SharePoint.Linq.DataContext"/> object.</param> public void UpdateTitle(Entities entities, NamedTraceLogger.TraceAction traceEvent) { string _quantity = String.Empty; //IQueryable<CustomsWarehouseDisposal> _Dspsls = from _Dspx in entities.CustomsWarehouseDisposal where _Dspx == this.Id select {ssss = _d.s } //if ( this.Disposal.Any() ) // _quantity = this.Disposal.Sum<Disposal>( x => x.SettledQuantity.Value ).ToString( "F2" ); //else // _quantity = " --- "; traceEvent("Starting Clearence.UpdateTitle", 57, TraceSeverity.Verbose); string _ClearanceTitleFormat = Settings.GetParameter(entities, SettingsEntry.ClearanceTitleFormatCW); Title = String.Format(_ClearanceTitleFormat, this.ProcedureCode, //0 ClearenceProcedure.GetValueOrDefault(Linq.ClearenceProcedure.Invalid).Convert2String(), //1 ReferenceNumber.NotAvailable(), //2 Id.GetValueOrDefault(-999)); //3 traceEvent("Finished Clearence.UpdateTitle; new Title: " + Title, 66, TraceSeverity.Verbose); }
internal void FinishClearingThroughCustoms(Entities edc, SADGood sadGood, NamedTraceLogger.TraceAction trace) { string _at = "starting"; if (this.CustomsStatus.Value == Linq.CustomsStatus.Finished) { return; } try { _at = "Disposal _lastOne"; IEnumerable <Disposal> _lastOne = from _dsp in this.Disposal2IPRIndex.Disposals(edc, trace) where _dsp.CustomsStatus.Value == Linq.CustomsStatus.Finished select _dsp; if (_lastOne.Count <Disposal>() == 0) { this.SPNo = 1; } else { this.SPNo = _lastOne.Max <Disposal>(dspsl => dspsl.SPNo.Value) + 1; } decimal _balance = CalculateRemainingQuantity(); if (_balance == 0) { this.ClearingType = Linq.ClearingType.TotalWindingUp; } else { this.ClearingType = Linq.ClearingType.PartialWindingUp; } AssignSADGood(edc, sadGood); this.CustomsStatus = Linq.CustomsStatus.Finished; } catch (Exception _ex) { string _template = "Cannot finish Export of disposal {0} {1} because of internal error: {2} at: {3}"; _template = String.Format(_template, this.Title, this.Id.Value, _ex.Message, _at); trace("Exception at Disposal.FinishClearingThroughCustoms", 181, TraceSeverity.High); throw GenericStateMachineEngine.ActionResult.Exception(_ex, _template); } }
private void TraceRecalculationDiff(string name, NamedTraceLogger.TraceAction trace, double dif, Action <double> correct) { TraceSeverity _severity = TraceSeverity.Verbose; if (Math.Abs(dif) > 10) { _severity = TraceSeverity.High; } else if (Math.Abs(dif) > 1) { _severity = TraceSeverity.Monitorable; } string _msg = String.Format("Correction {3} value = {0} for IPR: {1} {2}", dif.Round2Decimals(), this.Title, _severity == TraceSeverity.High ? "has not been applied because is out of range" : "has been applied", name); trace(_msg, 513, _severity); if (_severity != TraceSeverity.High) { correct(dif); } }
internal void RecalculateLastStarted(Entities edc, Linq.Disposal disposal, NamedTraceLogger.TraceAction trace) { IEnumerable <Disposal> _ds = Disposals(edc, trace); if (this.TobaccoNotAllocatedDec != 0 || _ds.Where(x => x.SettledQuantityDec > 0 && x.CustomsStatus == CustomsStatus.NotStarted).Any()) { return; } trace("Starting IPR.RecalculateLastStarted", 52, TraceSeverity.Verbose); //DutyPerSettledAmount double _dif = this.Duty.Value - (from _dec in _ds where _dec.DutyPerSettledAmount.HasValue select _dec.DutyPerSettledAmount.Value).Sum <double>(itm => itm); TraceRecalculationDiff("DutyPerSettledAmount", trace, _dif, correction => disposal.DutyPerSettledAmount = (disposal.DutyPerSettledAmount.Value + correction).Round2Decimals()); //VATPerSettledAmount _dif = this.VAT.Value - (from _dec in _ds where _dec.VATPerSettledAmount.HasValue select _dec.VATPerSettledAmount.Value).Sum <double>(itm => itm); TraceRecalculationDiff("VATPerSettledAmount", trace, _dif, correction => disposal.VATPerSettledAmount = (disposal.VATPerSettledAmount.Value + correction).Round2Decimals()); //VATPerSettledAmount _dif = this.Value.Value - (from _dec in _ds where _dec.TobaccoValue.HasValue select _dec.TobaccoValue.Value).Sum <double>(itm => itm); TraceRecalculationDiff("TobaccoValue", trace, _dif, correction => disposal.TobaccoValue = (disposal.TobaccoValue.Value + correction).Round2Decimals()); //DutyAndVAT disposal.DutyAndVAT = (disposal.DutyPerSettledAmount + disposal.VATPerSettledAmount).Value.Round2Decimals(); }
private void AssignSADGood(Entities edc, SADGood sadGood, NamedTraceLogger.TraceAction traceEvent) { traceEvent("Starting CustomsWarehouseDisposal.AssignSADGood", 167, TraceSeverity.Verbose); this.SADDate = sadGood.SADDocumentIndex.CustomsDebtDate; this.SADDocumentNo = sadGood.SADDocumentIndex.DocumentNumber; //TODO check consistency and generate warning. this.CustomsProcedure = sadGood.SPProcedure; if (this.TobaccoValue != sadGood.TotalAmountInvoiced) { string _msg = "Total Amount Invoiced value is not equal as requested to clear through customs"; traceEvent("Finishing CustomsWarehouseDisposal.AssignSADGood: " + _msg, 167, TraceSeverity.High); throw new ArgumentOutOfRangeException("TotalAmountInvoiced", _msg); } decimal _vat = 0; decimal _duties = 0; foreach (SADDuties _sdc in sadGood.SADDuties(edc, false)) { switch (Settings.DutyKind(_sdc.DutyType)) { case Settings.DutyKindEnum.VAT: _vat += _sdc.Amount.DecimalValue(); break; case Settings.DutyKindEnum.Duty: _duties += _sdc.Amount.DecimalValue(); break; case Settings.DutyKindEnum.ExciseDuty: throw new NotImplementedException(); } } this.DutyPerSettledAmount = _duties.DoubleValue(); this.VATPerSettledAmount = _vat.DoubleValue(); this.DutyAndVAT = (_vat + _duties).DoubleValue(); traceEvent("Finishing CustomsWarehouseDisposal.AssignSADGood", 167, TraceSeverity.Verbose); }
internal void UpdateExportedDisposals(Entities edc, NamedTraceLogger.TraceAction trace) { trace("Entering InvoiceContent.UpdateExportedDisposals", 48, TraceSeverity.Verbose); IEnumerable <IGrouping <int, Disposal> > _dspslsGroups = from _dsx in this.Disposal(edc) let _midx = _dsx.Disposal2MaterialIndex.Id.Value group _dsx by _midx; foreach (IGrouping <int, Disposal> _gx in _dspslsGroups) { Disposal _dsp = _gx.FirstOrDefault <Disposal>(); if (_dsp == null) { continue; } Material _mtrl = _dsp.Disposal2MaterialIndex; decimal _2Add = _mtrl.CalculatedQuantity(this) - _gx.Sum <Disposal>(v => v.SettledQuantityDec); //TODO it could cause that the closed IPR accounts will have account balance != 0 //TODO if current settled quantity < previous value it could also cause that old account will have holes that makes them difficult to be closed. IEnumerable <Disposal> _sorted = from _dx in _gx orderby _dx.SettledQuantityDec ascending select _dx; foreach (Disposal _dx in _sorted) { _dx.Adjust(edc, ref _2Add, trace); if (_2Add <= 0) { break; } } if (_2Add <= 0) { continue; } _mtrl.AddNewDisposals(edc, DisposalEnum.TobaccoInCigaretess, ref _2Add, this, trace); } }
internal static void UpdateReport(SPListItem listItem, string WebUrl, int jsoxLibItemId, NamedTraceLogger.TraceAction trace) { trace("Entering BalanceSheetContentFactory.UpdateReport", 62, TraceSeverity.Verbose); BalanceSheetContent _content = null; using (Entities _edc = new Entities(WebUrl)) { JSOXLibFactory _jsoxLibFactory = JSOXLibFactory.ConstructJSOXLibFActory(_edc, jsoxLibItemId); if (_jsoxLibFactory.JSOXLibraryReadOnly) { string _msg = "The record is read only and the report must not be updated."; trace("ApplicationException at BalanceSheetContentFactory.UpdateReport: " + _msg, 70, TraceSeverity.Monitorable); throw new ApplicationException(_msg); } List <BalanceBatchWrapper> batches = new List <BalanceBatchWrapper>(); bool _validated = _jsoxLibFactory.UpdateBalanceReport(_edc, batches, trace); string _documentName = Settings.RequestForBalanceSheetDocumentName(_edc, _jsoxLibFactory.Id); _content = DocumentsFactory.BalanceSheetContentFactory.CreateContent(_edc, batches, _jsoxLibFactory, _documentName, !_validated); _jsoxLibFactory.JSOXLibraryReadOnly = true; _edc.SubmitChanges(); } _content.UpdateDocument(listItem.File); listItem.ParentList.Update(); trace("Finished BalanceSheetContentFactory.UpdateReport", 82, TraceSeverity.Verbose); }
internal static void DeclarationProcessing(string webUrl, int sadDocumentTypeId, CustomsDocument.DocumentType documentType, ref string comments, List <Warnning> warnings, NamedTraceLogger.TraceAction trace) { trace("Entering ClearenceHelpers.DeclarationProcessing", 40, TraceSeverity.Verbose); comments = "Clearance association error"; switch (documentType) { case CustomsDocument.DocumentType.SAD: case CustomsDocument.DocumentType.PZC: SADPZCProcessing(webUrl, documentType, sadDocumentTypeId, ref comments, warnings, trace); break; case CustomsDocument.DocumentType.IE529: IE529Processing(webUrl, sadDocumentTypeId, ref comments, trace); break; case CustomsDocument.DocumentType.CLNE: CLNEProcessing(webUrl, sadDocumentTypeId, ref comments, warnings, trace); break; }//switch (_documentType }
internal void Analyze(Entities edc, Batch parent, Material.Ratios materialRatios, bool newBatch, NamedTraceLogger.TraceAction trace) { trace("Entering SummaryContentInfo.Analyze", 120, TraceSeverity.Verbose); this.ReplaceMaterials(edc, parent, materialRatios, newBatch, trace); List <Material> _tobacco = this.Values.Where <Material>(x => x.ProductType.Value == ProductType.IPRTobacco || x.ProductType.Value == ProductType.Tobacco).ToList <Material>(); List <Material> _IPTobacco = _tobacco.Where <Material>(x => x.ProductType.Value == ProductType.IPRTobacco).ToList <Material>(); if (this.Product.ProductType.Value == ProductType.Cigarette && this.BatchStatus == Linq.BatchStatus.Final) { foreach (Material _mx in _IPTobacco) { _mx.AdjustTobaccoQuantity(ref myTotalTobacco, trace); } } this.GetOverusage(parent.UsageMax.Value, parent.UsageMin.Value); if (this.BatchStatus == Linq.BatchStatus.Progress) { return; } foreach (Material _mx in _IPTobacco) { _mx.CalculateOveruse(edc, materialRatios, CalculatedOveruse); } this.AdjustOveruse(materialRatios, _IPTobacco); foreach (Material _mx in _tobacco) { _mx.CalculateCompensationComponents(materialRatios); AccumulatedDisposalsAnalysis.Accumutate(_mx); } foreach (InvoiceContent _ix in parent.InvoiceContent(edc, newBatch)) { _ix.UpdateExportedDisposals(edc, trace); } this.UpdateNotStartedDisposals(edc, trace); }
private void ReplaceMaterials(Entities entities, Batch parent, Material.Ratios materialRatios, bool newBatch, NamedTraceLogger.TraceAction trace) { trace("Entering SummaryContentInfo.ReplaceMaterials", 159, TraceSeverity.Verbose); if (Product == null) { trace("IPRDataConsistencyException at Entering SummaryContentInfo.ReplaceMaterials: Summary content info has unassigned Product property", 162, TraceSeverity.High); throw new IPRDataConsistencyException("SummaryContentInfo.ReplaceMaterials", "Summary content info has unassigned Product property", null, "Wrong batch - product is unrecognized."); } try { List <Material> _newMaterialList = new List <Material>(); List <Material> _oldMaterialList = new List <Material>(); List <Material> _copyThis = new List <Material>(); _copyThis.AddRange(this.Values); Dictionary <string, Material> _parentsMaterials = parent.Material(entities, newBatch).ToDictionary <Material, string>(x => x.GetKey()); foreach (Material _materialX in _copyThis) { _materialX.ReplaceByExistingOne(_oldMaterialList, _newMaterialList, _parentsMaterials, parent); } if (_newMaterialList.Count > 0) { entities.Material.InsertAllOnSubmit(_newMaterialList); } foreach (Material _omx in _oldMaterialList) { this.Remove(_omx.GetKey()); this.Add(_omx.GetKey(), _omx); } } catch (Exception _ex) { trace("IPRDataConsistencyException at Entering SummaryContentInfo.ReplaceMaterials: " + _ex.Message, 184, TraceSeverity.High); throw new IPRDataConsistencyException("SummaryContentInfo.ReplaceMaterials", _ex.Message, _ex, "Disposal processing error"); } }
internal static BalanceBatchWrapper Create(Entities edc, IGrouping <string, IPR> iprGroups, JSOXLib parent, StockDictionary.BalanceStock balanceStock, NamedTraceLogger.TraceAction trace) { trace("Entering BalanceBatch.Create", 34, TraceSeverity.Verbose); BalanceBatchWrapper _ret; try { IPR _firsTIPR = iprGroups.FirstOrDefault <IPR>(); BalanceBatch _newBB = new BalanceBatch() { Archival = false, Balance2JSOXLibraryIndex = parent, Batch = iprGroups.Key, Title = "creating", SKU = _firsTIPR == null ? "NA" : _firsTIPR.SKU, }; edc.BalanceBatch.InsertOnSubmit(_newBB); List <BalanceIPR> _is = new List <BalanceIPR>(); _newBB.Update(edc, iprGroups, balanceStock, _is, trace); _ret = new BalanceBatchWrapper() { iprCollection = _is.ToArray <BalanceIPR>(), batch = _newBB }; } catch (CAS.SharePoint.ApplicationError) { throw; } catch (Exception ex) { trace("ApplicationError at BalanceBatch.Create", 58, TraceSeverity.High); throw new SharePoint.ApplicationError("BalanceBatch.Create", "Body", ex.Message, ex); } trace("Finished BalanceBatch.Create", 61, TraceSeverity.Verbose); return(_ret); }
internal void Update(Entities edc, IGrouping <string, IPR> grouping, StockDictionary.BalanceStock balanceStock, List <BalanceIPR> iprCollection, NamedTraceLogger.TraceAction trace) { trace("Entering BalanceBatch.Update", 66, TraceSeverity.Verbose); if (grouping == null) { throw new ArgumentNullException("grouping", "grouping at BalanceBatch.Update is null."); } if (balanceStock == null) { throw new ArgumentNullException("balanceStock", "balanceStock at BalanceBatch.Update is null."); } try { Dictionary <string, IPR> _iprDictionary = grouping.ToDictionary(x => x.DocumentNo); List <string> _processed = new List <string>(); BalanceTotals _totals = new BalanceTotals(); trace("BalanceBatch.Update at BalanceIPR", 70, TraceSeverity.Verbose); foreach (BalanceIPR _balanceIPRx in this.BalanceIPR(edc)) { if (_iprDictionary.ContainsKey(_balanceIPRx.DocumentNo)) { IPR.Balance _new = _balanceIPRx.Update(edc, trace); _totals.Add(_new); iprCollection.Add(_balanceIPRx); } else { edc.BalanceIPR.DeleteOnSubmit(_balanceIPRx); } _processed.Add(_balanceIPRx.DocumentNo); } foreach (string _dcn in _processed) { _iprDictionary.Remove(_dcn); } trace("BalanceBatch.Update at BalanceIPR.Create", 55, TraceSeverity.Verbose); foreach (IPR _iprx in _iprDictionary.Values) { IPR.Balance _newBipr = Linq.BalanceIPR.Create(edc, _iprx, this, this.Balance2JSOXLibraryIndex, iprCollection, trace); _totals.Add(_newBipr); } trace("BalanceBatch.Update at update this.", 90, TraceSeverity.Verbose); this.DustCSNotStarted = _totals[IPR.ValueKey.DustCSNotStarted]; this.DustCSStarted = _totals[IPR.ValueKey.DustCSStarted]; this.IPRBook = _totals[IPR.ValueKey.IPRBook]; this.OveruseCSNotStarted = _totals[IPR.ValueKey.OveruseCSNotStarted]; this.OveruseCSStarted = _totals[IPR.ValueKey.OveruseCSStarted]; this.PureTobaccoCSNotStarted = _totals[IPR.ValueKey.PureTobaccoCSNotStarted]; this.PureTobaccoCSStarted = _totals[IPR.ValueKey.PureTobaccoCSStarted]; this.SHMentholCSNotStarted = _totals[IPR.ValueKey.SHMentholCSNotStarted]; this.SHMentholCSStarted = _totals[IPR.ValueKey.SHMentholCSStarted]; this.SHWasteOveruseCSNotStarted = _totals[IPR.ValueKey.SHWasteOveruseCSNotStarted]; this.TobaccoAvailable = _totals[IPR.ValueKey.TobaccoAvailable]; this.TobaccoCSFinished = _totals[IPR.ValueKey.TobaccoCSFinished]; this.TobaccoEnteredIntoIPR = _totals[IPR.ValueKey.TobaccoEnteredIntoIPR]; this.TobaccoInFGCSNotStarted = _totals[IPR.ValueKey.TobaccoInFGCSNotStarted]; this.TobaccoInFGCSStarted = _totals[IPR.ValueKey.TobaccoInFGCSStarted]; this.TobaccoToBeUsedInTheProduction = _totals[IPR.ValueKey.TobaccoToBeUsedInTheProduction]; this.TobaccoUsedInTheProduction = _totals[IPR.ValueKey.TobaccoUsedInTheProduction]; this.WasteCSNotStarted = _totals[IPR.ValueKey.WasteCSNotStarted]; this.WasteCSStarted = _totals[IPR.ValueKey.WasteCSStarted]; this.TobaccoStarted = _totals[IPR.ValueKey.TobaccoStarted]; // balanceStock.CalculateBalance(_totals.Base[IPR.ValueKey.TobaccoInFGCSNotStarted], _totals.Base[IPR.ValueKey.TobaccoAvailable]); this.Balance = balanceStock[StockDictionary.StockValueKey.Balance]; this.TobaccoInCigarettesProduction = balanceStock[StockDictionary.StockValueKey.TobaccoInCigarettesProduction]; this.TobaccoInCigarettesWarehouse = balanceStock[StockDictionary.StockValueKey.TobaccoInCigarettesWarehouse]; this.TobaccoInCutfillerWarehouse = balanceStock[StockDictionary.StockValueKey.TobaccoInCutfillerWarehouse]; this.TobaccoInWarehouse = balanceStock[StockDictionary.StockValueKey.TobaccoInWarehouse]; } catch (Exception ex) { trace("Exception at BalanceBatch.Update: " + ex.Message, 128, TraceSeverity.High); throw new SharePoint.ApplicationError("BalanceBatch.Update", "Body", ex.Message, ex); } trace("Finished BalanceBatch.Update", 131, TraceSeverity.Verbose); }
/// <summary> /// Creates the clearance. /// </summary> /// <param name="entities">The entities.</param> /// <param name="procedure">The procedure.</param> /// <param name="procedureCode">The procedure code.</param> /// <returns></returns> public static Clearence CreataClearence(Entities entities, string procedure, ClearenceProcedure procedureCode, NamedTraceLogger.TraceAction traceEvent) { Clearence _newClearence = CreateClearance(procedure, procedureCode); entities.Clearence.InsertOnSubmit(_newClearence); _newClearence.UpdateTitle(entities, traceEvent); entities.SubmitChanges(); _newClearence.UpdateTitle(entities, traceEvent); return(_newClearence); }
/// <summary> /// Updates the balance report. /// </summary> /// <param name="edc">The <see cref="Entities" /> representing data model.</param> /// <param name="getOutboundQuantity">Delegate to get outbound quantity.</param> /// <param name="batches">The batches.</param> /// <param name="trace">The trace action.</param> /// <returns><c>true</c> if the stock is valid (consistent), <c>false</c> otherwise.</returns> internal bool UpdateBalanceReport(Entities edc, GetOutboundQuantity getOutboundQuantity, List <BalanceBatchWrapper> batches, NamedTraceLogger.TraceAction trace) { trace("Entering JSOXLib.UpdateBalanceReport", 43, TraceSeverity.Verbose); bool _validated = false; StockDictionary _balanceStock = new StockDictionary(); Dictionary <string, IGrouping <string, IPR> > _accountGroups = Linq.IPR.GetAllOpen4JSOXGroups(edc).ToDictionary(x => x.Key); Linq.StockLib _stock = Stock(edc); if (_stock != null) { _validated = _stock.Validate(edc, _accountGroups, _stock); _stock.GetInventory(edc, _balanceStock); _stock.Stock2JSOXLibraryIndex = this; } else { ActivityLogCT.WriteEntry(edc, "Balance report", "Cannot find stock report - only preliminary report will be created"); } List <string> _processed = new List <string>(); IEnumerable <BalanceBatch> _existingBatches = this.BalanceBatch(edc); foreach (BalanceBatch _bbx in _existingBatches) { if (_accountGroups.ContainsKey(_bbx.Batch)) { List <BalanceIPR> _is = new List <BalanceIPR>(); _bbx.Update(edc, _accountGroups[_bbx.Batch], _balanceStock.GetOrDefault(_bbx.Batch), _is, trace); batches.Add(new BalanceBatchWrapper() { batch = _bbx, iprCollection = _is.ToArray <BalanceIPR>() }); } else { edc.BalanceBatch.DeleteOnSubmit(_bbx); } _processed.Add(_bbx.Batch); } foreach (string _btchx in _processed) { _accountGroups.Remove(_btchx); } foreach (var _grpx in _accountGroups) { batches.Add(Linq.BalanceBatch.Create(edc, _grpx.Value, this, _balanceStock.GetOrDefault(_grpx.Key), trace)); } //Introducing DateTime _thisIntroducingDateStart = LinqIPRExtensions.DateTimeMaxValue; DateTime _thisIntroducingDateEnd = LinqIPRExtensions.DateTimeMinValue; decimal _introducingQuantity = Linq.IPR.GetIntroducingData(edc, this, out _thisIntroducingDateStart, out _thisIntroducingDateEnd); this.IntroducingDateStart = _thisIntroducingDateStart; this.IntroducingDateEnd = _thisIntroducingDateEnd; this.IntroducingQuantity = Convert.ToDouble(_introducingQuantity); //Outbound DateTime _thisOutboundDateEnd = LinqIPRExtensions.DateTimeMinValue; DateTime _thisOutboundDateStart = LinqIPRExtensions.DateTimeMaxValue; decimal _outQuantity = getOutboundQuantity(edc, this, out _thisOutboundDateStart, out _thisOutboundDateEnd); this.OutboundQuantity = _outQuantity.Convert2Double2Decimals(); this.OutboundDateEnd = _thisOutboundDateEnd; this.OutboundDateStart = _thisOutboundDateStart; //Balance decimal _thisBalanceQuantity = Convert.ToDecimal(this.PreviousMonthQuantity) + _introducingQuantity - _outQuantity; this.BalanceQuantity = _thisBalanceQuantity.Convert2Double2Decimals(); //Situation at decimal _thisSituationQuantity = batches.Select <BalanceBatchWrapper, BalanceBatch>(x => x.batch).Sum <BalanceBatch>(x => x.IPRBookDecimal); this.SituationQuantity = Convert.ToDouble(_thisSituationQuantity); //Reassign this.ReassumeQuantity = (_thisBalanceQuantity - _thisSituationQuantity).Convert2Double2Decimals(); return(_validated); }
private static void SADPZCProcessing(string webUrl, CustomsDocument.DocumentType messageType, int sadDocumentTypeId, ref string comments, List <Warnning> warnings, NamedTraceLogger.TraceAction trace) { trace("Entering ClearenceHelpers.SADPZCProcessing", 71, TraceSeverity.Verbose); List <CommonClearanceData> _tasksList = new List <CommonClearanceData>(); using (Entities entities = new Entities(webUrl)) { SADDocumentType sad = Element.GetAtIndex <SADDocumentType>(entities.SADDocument, sadDocumentTypeId); foreach (SADGood _sgx in sad.SADGood(entities)) { switch (_sgx.SPProcedure.RequestedProcedure()) { case CustomsProcedureCodes.FreeCirculation: if (messageType == CustomsDocument.DocumentType.SAD) { comments = "Document added"; continue; } if (_sgx.SPProcedure.PreviousProcedure() == CustomsProcedureCodes.CustomsWarehousingProcedure) { _tasksList.Add(CWPrepareClearance(entities, _sgx)); //Procedure 4071 } else if (_sgx.SPProcedure.PreviousProcedure() == CustomsProcedureCodes.InwardProcessing) { IPRClearThroughCustoms(entities, _sgx, trace); //Procedure 4051 } else { string _msg = string.Format("Unexpected previous procedure code {1} for the {0} message", messageType, _sgx.SPProcedure.PreviousProcedure()); trace("IPRDataConsistencyException at ClearenceHelpers.SADPZCProcessing: ", 140, TraceSeverity.Verbose); throw new IPRDataConsistencyException("SADPZCProcessing.FreeCirculation", _msg, null, c_wrongProcedure); } break; case CustomsProcedureCodes.InwardProcessing: { if (messageType == CustomsDocument.DocumentType.SAD) { comments = "Document added"; continue; } if (_sgx.SPProcedure.PreviousProcedure() == CustomsProcedureCodes.CustomsWarehousingProcedure) { _tasksList.Add(CWPrepareClearance(entities, _sgx)); //Procedure 5171 } // Procedure 5100 or 5171 Clearence _newClearance = Clearence.CreataClearance(entities, "InwardProcessing", ClearenceProcedure._5171, _sgx); CreateIPRAccount(entities, _newClearance, CustomsDocument.DocumentType.PZC, out comments, warnings, trace); break; } case CustomsProcedureCodes.CustomsWarehousingProcedure: Clearence _newWarehousinClearance = Clearence.CreataClearance(entities, "CustomsWarehousingProcedure", ClearenceProcedure._7100, _sgx); if (messageType == CustomsDocument.DocumentType.PZC) { comments = "CW account creation error"; CWAccountData _accountData = new CWAccountData(_newWarehousinClearance.Id.Value); _accountData.GetAccountData(entities, _newWarehousinClearance, ImportXMLCommon.Convert2MessageType(CustomsDocument.DocumentType.SAD), warnings, trace); _tasksList.Add(_accountData); } else { comments = "Document added"; } break; case CustomsProcedureCodes.NoProcedure: case CustomsProcedureCodes.ReExport: default: throw new IPRDataConsistencyException("SADPZCProcessing.RequestedProcedure", string.Format("Unexpected procedure code for the {0} message", messageType), null, c_wrongProcedure); } //switch ( _sgx.Procedure.RequestedProcedure() ) } //foreach ( SADGood _sgx in sad.SADGood ) entities.SubmitChanges(); } //using ( Entities entities foreach (CommonClearanceData _accountData in _tasksList) { if (_accountData is CWAccountData) { CreateCWAccount((CWAccountData)_accountData, webUrl, out comments); } else if (_accountData is CWClearanceData) { CWClearThroughCustoms((CWClearanceData)_accountData, webUrl, out comments); } } }
private void CheckCNConsistency(NamedTraceLogger.TraceAction traceEvent) { traceEvent("Starting CustomsWarehouseDisposal.CheckCNConsistency but it is not implemented.", 163, TraceSeverity.Verbose); //TODO CheckCNCosistency NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="AccountData" /> class. /// </summary> /// <param name="edc">The <see cref="Entities" /> object.</param> /// <param name="clearance">The clearance.</param> /// <param name="messageType">Type of the customs message.</param> /// <param name="warnings">The list of warnings.</param> /// <param name="trace">The trace.</param> public override void GetAccountData(Entities edc, Clearence clearance, Customs.Account.CommonAccountData.MessageType messageType, List <Warnning> warnings, NamedTraceLogger.TraceAction trace) { base.GetAccountData(edc, clearance, messageType, warnings, trace); Value = clearance.Clearence2SadGoodID.TotalAmountInvoiced.GetValueOrDefault(0); UnitPrice = Value / NetMass; AnalizeDutyAndVAT(edc, clearance.Clearence2SadGoodID); }
private void Create(NamedTraceLogger.TraceAction trace) { CurrentClearance = Clearence.CreateClearance(m_DataContextManagement.DataContext, m_SelectGroupRadioButtonList.SelectedValue, SelectedClearenceProcedure, trace); Update(); Response.Redirect(Request.RawUrl); }
private static void CLNEProcessing(string webUrl, int sadDocumentTypeId, ref string comments, List <Warnning> warnings, NamedTraceLogger.TraceAction trace) { trace("Entering ClearenceHelpers.CLNEProcessing", 71, TraceSeverity.Verbose); List <CWAccountData> _tasksList = new List <CWAccountData>(); using (Entities _entities = new Entities(webUrl)) { SADDocumentType _sad = Element.GetAtIndex <SADDocumentType>(_entities.SADDocument, sadDocumentTypeId); IQueryable <Clearence> _clrncs = Clearence.GetClearence(_entities, _sad.ReferenceNumber); if ((from _cx in _clrncs where _cx.Clearence2SadGoodID == null select _cx).Any <Clearence>()) { string _error = String.Format("SAD with reference number: {0} must be imported first", _sad.ReferenceNumber); throw new InputDataValidationException("CLNE message cannot be processed before SAD", "DeclarationProcessing", _error, true); } foreach (Clearence _cx in _clrncs) { _cx.DocumentNo = _sad.DocumentNumber; switch (_cx.ClearenceProcedure.Value.RequestedProcedure()) { case CustomsProcedureCodes.FreeCirculation: _cx.FinishClearingThroughCustoms(_entities, trace); break; case CustomsProcedureCodes.InwardProcessing: CreateIPRAccount(_entities, _cx, CustomsDocument.DocumentType.SAD, out comments, warnings, trace); break; case CustomsProcedureCodes.CustomsWarehousingProcedure: throw new NotImplementedException("CLNEProcessing - CustomsWarehousingProcedure"); //TODO http://casas:11227/sites/awt/Lists/RequirementsList/_cts/Requirements/displayifs.aspx?List=e1cf335a //comments = "CW account creation error"; //CWAccountData _accountData = new CWAccountData(_cx.Id.Value); //_accountData.GetAccountData(_entities, _cx, ImportXMLCommon.Convert2MessageType(CustomsDocument.DocumentType.SAD), progressChange); //CreateCWAccount(_accountData, webUrl, out comments); //break; case CustomsProcedureCodes.ReExport: case CustomsProcedureCodes.NoProcedure: default: throw new IPRDataConsistencyException("CLNEProcessing", "Unexpected procedure code for CLNE message", null, c_wrongProcedure); } } _entities.SubmitChanges(); } trace("ClearenceHelpers.CLNEProcessing at CreateCWAccount", 109, TraceSeverity.Verbose); foreach (CWAccountData _accountData in _tasksList) { CreateCWAccount(_accountData, webUrl, out comments); } }
private static void IE529Processing(string webUrl, int sadDocumentTypeId, ref string comments, NamedTraceLogger.TraceAction trace) { comments = "Reexport of goods failed"; trace("Entering ClearenceHelpers.IE529Processing", 61, TraceSeverity.Verbose); using (Entities _entities = new Entities(webUrl)) { SADDocumentType _sad = Element.GetAtIndex <SADDocumentType>(_entities.SADDocument, sadDocumentTypeId); foreach (SADGood _gdx in _sad.SADGood(_entities)) { IPRClearThroughCustoms(_entities, _gdx, trace); } comments = "Reexport of goods"; trace("ClearenceHelpers.IE529Processing SubmitChanges", 61, TraceSeverity.Verbose); _entities.SubmitChanges(); } }
/// <summary> /// Creates the IPR account. /// </summary> /// <param name="entities">The entities.</param> /// <param name="clearance">The clearance.</param> /// <param name="messageType">Type of the _message.</param> /// <param name="comments">The _comments.</param> /// <param name="warnings">The list of warnings.</param> /// <param name="trace">The trace action.</param> private static void CreateIPRAccount(Entities entities, Clearence clearance, CustomsDocument.DocumentType messageType, out string comments, List <Warnning> warnings, NamedTraceLogger.TraceAction trace) { trace("Entering ClearenceHelpers.CreateIPRAccount", 169, TraceSeverity.Verbose); comments = "IPR account creation error"; string _referenceNumber = String.Empty; SADDocumentType declaration = clearance.Clearence2SadGoodID.SADDocumentIndex; _referenceNumber = declaration.ReferenceNumber; if (WebsiteModel.Linq.IPR.RecordExist(entities, clearance.DocumentNo)) { string _msg = "IPR record with the same SAD document number: {0} exist"; _msg = String.Format(_msg, clearance.DocumentNo); trace("Exception at ClearenceHelpers.CreateIPRAccount: " + _msg, 199, TraceSeverity.Verbose); throw GenericStateMachineEngine.ActionResult.NotValidated(_msg); } comments = "Inconsistent or incomplete data to create IPR account"; IPRAccountData _iprdata = new IPRAccountData(clearance.Id.Value); _iprdata.GetAccountData(entities, clearance, ImportXMLCommon.Convert2MessageType(messageType), warnings, trace); comments = "Consent lookup filed"; IPRClass _ipr = new IPRClass(entities, _iprdata, clearance, declaration); entities.IPR.InsertOnSubmit(_ipr); clearance.SPStatus = true; trace("ClearenceHelpers.CreateIPRAccount at SubmitChanges", 209, TraceSeverity.Verbose); entities.SubmitChanges(); _ipr.UpdateTitle(); comments = "IPR account created"; trace("ClearenceHelpers.Create - IPRAccount comments", 213, TraceSeverity.Verbose); }