示例#1
0
        internal static JSOXLibFactory ConstructJSOXLibFActory(Entities edc, int jsoxLibindex)
        {
            JSOXLibFactory _ret = new JSOXLibFactory();

            _ret.GetJSOXLib(edc, jsoxLibindex);
            return(_ret);
        }
        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 CreateReport(SPWeb web, string webUrl, int jsoxLibItemId, NamedTraceLogger.TraceAction trace)
        {
            trace("Entering BalanceSheetContentFactory.CreateReport", 33, TraceSeverity.Verbose);
            SPFile _newFile = default(SPFile);
            BalanceSheetContent _content = default(BalanceSheetContent);

            using (Entities _edc = new Entities(webUrl))
            {
                JSOXLib _old = Element.GetAtIndex <JSOXLib>(_edc.JSOXLibrary, jsoxLibItemId);
                if (_old.JSOXLibraryReadOnly.Value)
                {
                    throw new ApplicationException("The record is read only and new report must not be created.");
                }
                _old.JSOXLibraryReadOnly = true;
                _content = DocumentsFactory.BalanceSheetContentFactory.CreateEmptyContent();
                string _documentName = Settings.RequestForBalanceSheetDocumentName(_edc, jsoxLibItemId + 1);
                _newFile = SPDocumentFactory.Prepare(web, _content, _documentName);
                _newFile.DocumentLibrary.Update();
                JSOXLibFactory             _current = JSOXLibFactory.ConstructJSOXLibFActory(_edc, _newFile.Item.ID);
                List <BalanceBatchWrapper> batches  = new List <BalanceBatchWrapper>();
                bool _validated = _current.CreateJSOXReport(_edc, _old, batches, trace);
                trace("BalanceSheetContentFactory.CreateReport SubmitChanges", 33, TraceSeverity.Verbose);
                _edc.SubmitChanges();
                _content = CreateContent(_edc, batches, _current, _documentName, !_validated);
            }
            trace("UpdateDocument " + _newFile.Name, 51, TraceSeverity.Verbose);
            _content.UpdateDocument(_newFile);
            _newFile.DocumentLibrary.Update();
            trace("Finished BalanceSheetContentFactory.CreateReport", 53, TraceSeverity.Verbose);
        }
        private static JSOContent GetJSOContent(JSOXLibFactory factory)
        {
            JSOXLib    list = factory.JSOXList;
            JSOContent _ret = new JSOContent()
            {
                BalanceDate            = list.BalanceDate.GetValueOrDefault(),
                BalanceQuantity        = list.BalanceQuantity.Round2DecimalOrDefault(),
                JSOXCustomsSummaryList = GetDisposalsList(factory.SummaryContentList),
                IntroducingDateEnd     = list.IntroducingDateEnd.GetValueOrDefault(),
                IntroducingDateStart   = list.IntroducingDateStart.GetValueOrDefault(),
                IntroducingQuantity    = list.IntroducingQuantity.Round2DecimalOrDefault(),
                OutboundDateEnd        = list.OutboundDateEnd.GetValueOrDefault(),
                OutboundDateStart      = list.OutboundDateStart.GetValueOrDefault(),
                OutboundQuantity       = list.OutboundQuantity.Round2DecimalOrDefault(),
                PreviousMonthDate      = list.PreviousMonthDate.GetValueOrDefault(),
                PreviousMonthQuantity  = list.PreviousMonthQuantity.Round2DecimalOrDefault(),
                ReassumeQuantity       = list.ReassumeQuantity.Round2DecimalOrDefault(),
                SituationDate          = list.SituationDate.GetValueOrDefault(),
                SituationQuantity      = list.SituationQuantity.Round2DecimalOrDefault()
            };

            return(_ret);
        }
        private static List <BalanceCutfillerContent> CreateBalanceCutfillerContent(Entities edc, JSOXLibFactory factory)
        {
            List <BalanceCutfillerContent> _ret = new List <BalanceCutfillerContent>();

            foreach (StockEntry _StockEntryX in from _sex in factory.JSOXList.Stock(edc).StockEntry(edc) where _sex.IPRType.Value && _sex.ProductType == ProductType.Cutfiller orderby _sex.Batch select _sex)
            {
                double _cfc = _StockEntryX.Quantity.Value / _StockEntryX.BatchIndex.FGQuantity.Value;
                foreach (Material _MaterialX in from _mtrx in edc.Material
                         let _mtrlId = _mtrx.Material2BatchIndex.Id.Value
                                       let _stoctId = _StockEntryX.BatchIndex.Id.Value
                                                      where (_mtrlId == _stoctId && _mtrx.ProductType.Value == ProductType.IPRTobacco)
                                                      select _mtrx)
                {
                    BalanceCutfillerContent _bcc = new BalanceCutfillerContent()
                    {
                        CtfBatch             = _StockEntryX.Batch,
                        CtfBatchQuantity     = _StockEntryX.BatchIndex.FGQuantity.Value.Round2Double(),
                        CtfOnStock           = _StockEntryX.Quantity.Value.Round2Double(),
                        CtfSKU               = _StockEntryX.SKU,
                        TobaccoBatch         = _MaterialX.Batch,
                        TobaccoBatchQuantity = _MaterialX.TobaccoQuantity.Value.Round2Double(),
                        TobaccoKg            = (_MaterialX.TobaccoQuantity.Value * _cfc).Round2Double(),
                        TobaccoSKU           = _MaterialX.SKU
                    };
                    _ret.Add(_bcc);
                }
            }
            return(_ret);
        }
        private static BalanceSheetContent CreateContent(Entities edc, IEnumerable <BalanceBatchWrapper> batches, JSOXLibFactory factory, string documentName, bool preliminary)
        {
            if (preliminary)
            {
                documentName += " " + "PRELIMINARY".GetLocalizedString();
            }
            JSOXLib list = factory.JSOXList;
            List <BalanceCutfillerContent> _cr  = CreateBalanceCutfillerContent(edc, factory);
            BalanceSheetContent            _ret = new BalanceSheetContent()
            {
                DocumentDate     = DateTime.Today.Date,
                DocumentNo       = documentName,
                EndDate          = list.SituationDate.GetValueOrDefault(),
                BalanceBatch     = GetBalanceBatchContent(batches),
                JSOX             = GetJSOContent(factory),
                SituationAtDate  = list.SituationDate.GetValueOrDefault(),
                StartDate        = list.PreviousMonthDate.GetValueOrDefault(),
                BalanceCutfiller = _cr.ToArray <BalanceCutfillerContent>()
            };

            return(_ret);
        }