private void CalculateBalance(FinancialReport document) { if (document.ClosureDate != null) { CalculateReportBalanceResponse response = this.mapper.CalculateReportBalance(document.Id.Value); document.IncomeAmount = response.IncomeAmount; document.OutcomeAmount = response.OutcomeAmount; if (!document.SkipFurtherReportRecalculation) { this.RecalculateFurtherReports(document); } } else if (document.IsNew) { //sprawdzamy czy to pierwszy raport czy juz jakeis byly bool exists = this.mapper.CheckReportExistence(document.FinancialRegisterId); if (exists)//policz raport otwarcia { decimal initialBalance = this.mapper.CalculateReportInitialBalance(document.FinancialRegisterId); document.InitialBalance = initialBalance; }//w przeciwnym przypadku wpisz to co wklepal uzytkownik } }
private void RecalculateFurtherReports(FinancialReport document) { XDocument getNextFinancialReportsIdResult = this.mapper.GetNextFinancialReportsId(document.Id.Value); Dictionary <Guid, string> nextReportsIdDict = this.ConsumeGetNextFinancialReportsIdResult(getNextFinancialReportsIdResult); FinancialReport previousReport = document; foreach (Guid id in nextReportsIdDict.Keys) { FinancialReport ptrReport = (FinancialReport)this.coordinator.LoadBusinessObject(BusinessObjectType.FinancialReport, id); decimal prvInitialBalance = ptrReport.InitialBalance; ptrReport.InitialBalance = previousReport.InitialBalance + previousReport.IncomeAmount.Value + previousReport.OutcomeAmount.Value; //Jeśli raport jest zaksięgowany a zmienił się jego bilans to rzucamy wyjątek if (prvInitialBalance != ptrReport.InitialBalance && nextReportsIdDict.ContainsKey(ptrReport.Id.Value) && nextReportsIdDict[ptrReport.Id.Value] != null && nextReportsIdDict[ptrReport.Id.Value] != ExportToAccountingStatus.Unexported) { throw new ClientException(ClientExceptionId.BookedFinancialReportRecalculationForbidden); } ptrReport.SkipFurtherReportRecalculation = true; document.AddRelatedObject(ptrReport); previousReport = ptrReport; } }
static void FinancialReportExample() { Pages page = null; FinancialReport report = new FinancialReport(); page = report.CreateDocument("Products"); }
private void ValidateDuringTransaction(FinancialReport document) { FinancialReport alternate = document.AlternateVersion as FinancialReport; //Nie można ponownie otworzyć zaksięgowanego raportu finansowego if (alternate != null && alternate.IsClosed && !document.IsClosed) { string objectExportedStatus = this.mapper.GetFinancialReportStatusById(document.Id.Value); if ((objectExportedStatus ?? ExportToAccountingStatus.Unexported) != ExportToAccountingStatus.Unexported) { throw new ClientException(ClientExceptionId.BookedFinancialReportReopeningForbidden); } } Guid?openedReportId = this.mapper.GetOpenedFinancialReportId(document.FinancialRegisterId); if (openedReportId != null && !SessionManager.VolatileElements.SavedInThisTransaction(openedReportId.Value)) { throw new ClientException(ClientExceptionId.OpenedFinancialReportAlreadyExists); } GetFinancialReportValidationDatesResponse response = this.mapper.GetFinancialReportValidationDates(document.FinancialRegisterId, document.CreationDate, document.Id.Value, document.IsNew); if (document.ClosureDate != null) { //sprawdzamy czy data zamkniecia jest < od daty otwarcia kolejnego raportu if (response.NextFinancialReportOpeningDate != null && document.ClosureDate.Value >= response.NextFinancialReportOpeningDate.Value) { throw new ClientException(ClientExceptionId.FinancialReportCloseError); } if (response.GreatestIssueDateOnFinancialDocument != null && document.ClosureDate.Value < response.GreatestIssueDateOnFinancialDocument.Value) { throw new ClientException(ClientExceptionId.FinancialReportCloseError3); } if (document.ClosureDate.Value <= document.CreationDate) { throw new ClientException(ClientExceptionId.FinancialReportCloseError4); } } if (response.PreviousFinancialReportClosureDate != null && document.IssueDate < response.PreviousFinancialReportClosureDate.Value) { throw new ClientException(ClientExceptionId.FinancialReportCloseError2); } }
/// <summary> /// Демо паттерна "Декоратор". /// Паттерн Декоратор динамически наделяет объект новыми возможностями и является гибкой /// альтернативой субклассированию в области расширения функциональности. /// </summary> public void DemoDecorator() { // Здесь происходит расширение класса FinancialReport дополнительной функциональностью в виде FinancialDailyReport var dailyReport = new FinancialReport(new FinancialDailyReport()); dailyReport.ApplyStyles(); // Здесь происходит расширение класса FinancialReport дополнительной функциональностью в виде FinancialDailyReportWithCharts var dailyReportWithCharts = new FinancialReport(new FinancialDailyReportWithCharts()); dailyReportWithCharts.ApplyStyles(); // Здесь происходит декорирование объекта FinancialDailyReport функциональностью из FinancialReport и PurchaseReport IReport newDailyReport = new FinancialDailyReport(); newDailyReport = new FinancialReport(newDailyReport); newDailyReport = new PurchaseReport(newDailyReport); newDailyReport.ApplyStyles(); }
public static void CreateFinancialReportToFinancialRegister(XElement source, FinancialReport destination) { Guid registerId = new Guid(source.Element("financialRegisterId").Value); FinancialRegister register = DictionaryMapper.Instance.GetFinancialRegister(registerId); destination.Number.NumberSettingId = register.FinancialReportNumberSettingId; destination.FinancialRegisterId = registerId; DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>(); bool exists = mapper.CheckReportExistence(registerId); if (!exists) { destination.IsFirstReport = true; destination.InitialBalance = 0; } else { destination.InitialBalance = mapper.CalculateReportInitialBalance(registerId); } }
public void BridgeTest() { // Bridge 就是把一組概念相同的名詞(報表),與一組概念相同的實作(匯出)橋接在一起的橋接模式 // given 兩種匯出實作 var excelExporter = new ExcelExporter(); var pdfExporter = new PDFExporter(); // given 午餐報表對應不同的實作 var lunchPdfReport = new LunchReport(pdfExporter); var lunchExcelReport = new LunchReport(excelExporter); // given 財務報表對應不同的實作 var financialPdfReport = new FinancialReport(pdfExporter); var financialExcelReport = new FinancialReport(excelExporter); // then assert 不同報表對應不同實作的結果 Assert.AreEqual("午餐明細.pdf: 午餐明細資料", lunchPdfReport.Export("午餐明細")); Assert.AreEqual("午餐明細.excel: 午餐明細資料", lunchExcelReport.Export("午餐明細")); Assert.AreEqual("財金報表.pdf: 財金報表資料", financialPdfReport.Export("財金報表")); Assert.AreEqual("財金報表.excel: 財金報表資料", financialExcelReport.Export("財金報表")); }
private void ExecuteLogic(FinancialReport document) { FinancialReport alternate = document.AlternateVersion as FinancialReport; if (alternate == null) //new report { document.CreatingUser = Contractor.CreateEmptyContractor(SessionManager.User.UserId); //document.CreationDate = SessionManager.VolatileElements.CurrentDateTime; } else { if (alternate.IsClosed == false && document.IsClosed == true) { document.ClosingUser = Contractor.CreateEmptyContractor(SessionManager.User.UserId); //document.ClosureDate = SessionManager.VolatileElements.CurrentDateTime; } else if (alternate.IsClosed == true && document.IsClosed == false) { document.OpeningUser = Contractor.CreateEmptyContractor(SessionManager.User.UserId); document.OpeningDate = SessionManager.VolatileElements.CurrentDateTime; } } }
public void ReturnsFalse_WhenInputIsInvalid(string input) => FinancialReport.TryParseNextReportDate(input, out var _).Should().BeFalse();
public void ReturnsTrue_WhenInputIsValid(string input) { FinancialReport.TryParseNextReportDate(input, out var result).Should().BeTrue(); result.Should().Be(_expectedResult); }
private static void GenerateFinancialDocumentToPayment(Payment payment, CommercialDocument document) { DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>(); using (DocumentCoordinator coordinator = new DocumentCoordinator(false, false)) { PaymentMethod paymentMethod = DictionaryMapper.Instance.GetPaymentMethod(payment.PaymentMethodId.Value); Guid branchId = SessionManager.User.BranchId; if (DictionaryMapper.Instance.IsPaymentMethodSupportedByRegister(paymentMethod.Id.Value, branchId)) { FinancialRegister register = DictionaryMapper.Instance.GetFinancialRegisterForSpecifiedPaymentMethod(paymentMethod.Id.Value, branchId, payment.PaymentCurrencyId); if (register == null) { throw new ClientException(ClientExceptionId.UnableToIssueFinancialDocument3); } FinancialDirection direction = FinancialDocumentFactory.GetFinancialDirectionForPayment(document, payment); Guid?reportId = mapper.GetOpenedFinancialReportId(register.Id.Value); if (reportId == null) { throw new ClientException(ClientExceptionId.UnableToIssueDocumentToClosedFinancialReport); } FinancialDocument financialDoc = new FinancialDocument(); financialDoc.RelatedCommercialDocument = document; coordinator.TrySaveProfileIdAttribute(financialDoc); if (direction == FinancialDirection.Income) { financialDoc.DocumentTypeId = register.IncomeDocumentTypeId; financialDoc.Number.NumberSettingId = register.IncomeNumberSettingId; } else { financialDoc.DocumentTypeId = register.OutcomeDocumentTypeId; financialDoc.Number.NumberSettingId = register.OutcomeNumberSettingId; } financialDoc.Contractor = payment.Contractor; financialDoc.ContractorAddressId = payment.ContractorAddressId; FinancialReport report = new FinancialReport(); report.Id = reportId; report.FinancialRegisterId = register.Id.Value; financialDoc.FinancialReport = report; financialDoc.DocumentStatus = DocumentStatus.Committed; DuplicableAttributeFactory.DuplicateAttributes(document, financialDoc); Payment pt = financialDoc.Payments.CreateNew(); pt.Amount = Math.Abs(payment.Amount); pt.ExchangeRate = financialDoc.ExchangeRate = document.ExchangeRate; pt.ExchangeScale = financialDoc.ExchangeScale = document.ExchangeScale; pt.ExchangeDate = financialDoc.ExchangeDate = document.ExchangeDate; financialDoc.Amount = pt.Amount; financialDoc.DocumentCurrencyId = payment.PaymentCurrencyId; PaymentSettlement settlement = pt.Settlements.CreateNew(); settlement.IsAutoGenerated = true; settlement.RelatedPayment = payment; settlement.Amount = pt.Amount; document.AddRelatedObject(financialDoc); } } }
public void ReturnsTrue_WhenInputIsValid(string input, decimal expected) { FinancialReport.TryParseEPS(input, out var result).Should().BeTrue(); result.Should().Be(expected); }
public XDocument SaveBusinessObject(FinancialReport document) { DictionaryMapper.Instance.CheckForChanges(); //validate document.Validate(); //load alternate version if (!document.IsNew) { IBusinessObject alternateBusinessObject = this.mapper.LoadBusinessObject(document.BOType, document.Id.Value); document.SetAlternateVersion(alternateBusinessObject); } this.ExecuteLogic(document); //update status document.UpdateStatus(true); if (document.AlternateVersion != null) { document.AlternateVersion.UpdateStatus(false); } SqlConnectionManager.Instance.BeginTransaction(); try { DictionaryMapper.Instance.CheckForChanges(); this.mapper.CheckBusinessObjectVersion(document); DocumentLogicHelper.AssignNumber(document, this.mapper); this.ValidateDuringTransaction(document); this.CalculateBalance(document); //Make operations list XDocument operations = XDocument.Parse("<root/>"); document.SaveChanges(operations); if (document.AlternateVersion != null) { document.AlternateVersion.SaveChanges(operations); } if (operations.Root.HasElements) { this.mapper.ExecuteOperations(operations); this.mapper.CreateCommunicationXml(document); this.mapper.UpdateDictionaryIndex(document); } Coordinator.LogSaveBusinessObjectOperation(); document.SaveRelatedObjects(); XDocument returnXml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture, "<root><id>{0}</id></root>", document.Id.ToUpperString())); if (this.coordinator.CanCommitTransaction) { if (!ConfigurationMapper.Instance.ForceRollbackTransaction) { SqlConnectionManager.Instance.CommitTransaction(); } else { SqlConnectionManager.Instance.RollbackTransaction(); } } return(returnXml); } catch (SqlException sqle) { RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:67"); Coordinator.ProcessSqlException(sqle, document.BOType, this.coordinator.CanCommitTransaction); throw; } catch (Exception) { RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:68"); if (this.coordinator.CanCommitTransaction) { SqlConnectionManager.Instance.RollbackTransaction(); } throw; } }
public void ReturnsTrue_WhenInputIsValid(string input, int expected) { FinancialReport.TryParseMonthsInReport(input, out var result).Should().BeTrue(); result.Should().Be(expected); }
private static HashSet<FinancialReport> GenerateReportData( List<string> vendors, Dictionary<string, decimal> vendorsIncomes, Dictionary<string, decimal> vendorsExpenses, Dictionary<string, decimal> vendorsTaxes) { var vendorsReport = new HashSet<FinancialReport>(); foreach (var vendor in vendors) { var incomes = vendorsIncomes.FirstOrDefault(v => v.Key == vendor); var expenses = vendorsExpenses.FirstOrDefault(v => v.Key == vendor); var taxes = vendorsTaxes.FirstOrDefault(v => v.Key == vendor); var vendorReport = new FinancialReport { Vendor = vendor, Incomes = incomes.Value, Expenses = expenses.Value, TotalTaxes = taxes.Value }; vendorsReport.Add(vendorReport); } return vendorsReport; }