Example #1
0
        /// <summary>
        /// Contains calculated data required to create IPR account
        /// </summary>
        private Disposal AddDisposal(Entities edc, DisposalEnum status, ref decimal quantity)
        {
            Linq.DisposalStatus _typeOfDisposal = Entities.GetDisposalStatus(status);
            decimal             _toDispose      = 0;

            if (status == DisposalEnum.Cartons)
            {
                _toDispose = quantity;
                quantity   = 0;
            }
            else
            {
                _toDispose = Withdraw(ref quantity, 0);
            }
            Disposal _newDisposal = new Disposal(this, _typeOfDisposal, _toDispose);

            edc.Disposal.InsertOnSubmit(_newDisposal);
            return(_newDisposal);
        }
Example #2
0
        internal void UpdateDisposals(Entities edc, NamedTraceLogger.TraceAction trace)
        {
            trace("Entering Material.UpdateDisposals", 352, TraceSeverity.Verbose);
            string _parentBatch = this.Material2BatchIndex.Batch0;

            if (this.ProductType.Value != Linq.ProductType.IPRTobacco)
            {
                return;
            }
            IEnumerable <Disposal> _allDisposals = this.Disposal(edc, true);

            foreach (Linq.DisposalEnum _kind in Enum.GetValues(typeof(Linq.DisposalEnum)))
            {
                try
                {
                    if (_kind == DisposalEnum.Tobacco || _kind == DisposalEnum.Cartons)
                    {
                        continue;
                    }
                    decimal         _toDispose       = this[_kind];
                    List <Disposal> _disposalsOfKind = _allDisposals.Where <Disposal>(x => x.DisposalStatus.Value == Entities.GetDisposalStatus(_kind)).ToList <Disposal>();
                    if (_disposalsOfKind.Count <Disposal>() > 0)
                    {
                        _toDispose      -= _disposalsOfKind.Sum <Disposal>(x => x.SettledQuantityDec);
                        _disposalsOfKind = _disposalsOfKind.Where(v => v.CustomsStatus.Value == CustomsStatus.NotStarted).ToList <Disposal>();
                        foreach (Linq.Disposal _dx in _disposalsOfKind)
                        {
                            _dx.Adjust(edc, ref _toDispose, trace);
                        }
                        if (_toDispose == 0)
                        {
                            continue;
                        }
                        if (_toDispose <= 0)
                        {
                            string _toDisposeMessage = "_toDispose < 0 and is of {3} kg: Tobacco batch: {0}, fg batch: {1}, disposal: {2}";
                            _toDisposeMessage = String.Format(_toDisposeMessage, this.Batch, _parentBatch, _kind, _toDispose);
                            trace("IPRDataConsistencyException at Material.UpdateDisposals: " + _toDisposeMessage, 380, TraceSeverity.High);
                            throw new IPRDataConsistencyException("Material.UpdateDisposals", _toDisposeMessage, null, "IPR calculation error");
                        }
                    }
                    trace(String.Format("AddDisposal {0}, batch {1}", _kind, this.Batch), 384, TraceSeverity.Verbose);
                    if (((_kind == DisposalEnum.SHMenthol) || (_kind == DisposalEnum.OverusageInKg)) && this[_kind] <= 0)
                    {
                        continue;
                    }
                    AddNewDisposals(edc, _kind, ref _toDispose);
                    if (_toDispose <= 0)
                    {
                        continue;
                    }
                    string _mssg = "Cannot find IPR account to dispose the tobacco of {3} kg: Tobacco batch: {0}, fg batch: {1}, disposal: {2}";
                    _mssg = String.Format(_mssg, this.Batch, _parentBatch, _kind, _toDispose);
                    trace("IPRDataConsistencyException at Material.UpdateDisposals: " + _mssg, 392, TraceSeverity.High);
                    throw new IPRDataConsistencyException("Material.UpdateDisposals", String.Format(_mssg, this.Batch, _parentBatch, _kind, _toDispose), null, "IPR unrecognized account");
                }
                catch (IPRDataConsistencyException _ex)
                {
                    _ex.Add2Log(edc);
                }
            }
        }