Skip to content

Commit

Permalink
AccountsChartExcelFileCreator added
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcota committed Jun 21, 2021
1 parent 5c78f32 commit 61b39a9
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
77 changes: 77 additions & 0 deletions OfficeIntegration/Services/AccountsChartExcelFileCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* Empiria Financial *****************************************************************************************
* *
* Module : Office Integration Component : Excel Exporter *
* Assembly : FinancialAccounting.OficeIntegration.dll Pattern : Service *
* Type : ExcelExporter License : Please read LICENSE.txt file *
* *
* Summary : Main service to export accounting information to Microsoft Excel. *
* *
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/


using System;
using Empiria.FinancialAccounting.Adapters;

namespace Empiria.FinancialAccounting.OfficeIntegration {

internal class AccountsChartExcelFileCreator {

private readonly ExcelTemplateConfig _templateConfig;

public AccountsChartExcelFileCreator(ExcelTemplateConfig templateConfig) {
Assertion.AssertObject(templateConfig, "templateConfig");

_templateConfig = templateConfig;
}


internal ExcelFile CreateExcelFile(AccountsChartDto accountsChart) {
Assertion.AssertObject(accountsChart, "accountsChart");

var excelFile = new ExcelFile(_templateConfig);

excelFile.Open();

excelFile.SetCell($"A2", "Catálogo de cuentas");

FillOut(accountsChart, excelFile);

excelFile.Save();

excelFile.Close();

return excelFile;
}

#region Private methods


private void FillOut(AccountsChartDto accountsChart, ExcelFile excelFile) {
int i = 5;

foreach (var account in accountsChart.Accounts) {
excelFile.SetCell($"C{i}", account.Number);
excelFile.SetCell($"D{i}", account.Name);

if (account.Role != AccountRole.Sumaria &&
(account.Role == AccountRole.Sectorizada && accountsChart.WithSectors)) {
excelFile.SetCell($"E{i}", "*");
}
excelFile.SetCell($"F{i}", account.Sector);
excelFile.SetCell($"G{i}", account.Role.ToString());
excelFile.SetCell($"H{i}", account.Type);
excelFile.SetCell($"I{i}", account.DebtorCreditor.ToString());
excelFile.SetCell($"J{i}", account.StartDate);
i++;
}

if (!accountsChart.WithSectors) {
excelFile.RemoveColumn("F");
}
}

#endregion Private methods

} // class AccountsChartExcelFileCreator

} // namespace Empiria.FinancialAccounting.OfficeIntegration
22 changes: 20 additions & 2 deletions WebApi/AccountsChart/AccountsChartController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
* Summary : Query web API used to retrive accounts charts. *
* *
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/
using System;
using System.Web.Http;

using Empiria.WebApi;

using Empiria.FinancialAccounting.UseCases;
using Empiria.FinancialAccounting.Adapters;

using Empiria.FinancialAccounting.OfficeIntegration;
using Empiria.FinancialAccounting.OfficeIntegration.Adapters;

namespace Empiria.FinancialAccounting.WebApi {

/// <summary>Query web API used to retrive accounts charts.</summary>
public class AccountsChartController : WebApiController {

#region Web Apis


[HttpGet]
[Route("v2/financial-accounting/accounts-charts/{accountsChartUID:guid}/accounts/{accountUID:guid}")]
public SingleObjectModel GetAccount([FromUri] string accountsChartUID,
Expand Down Expand Up @@ -71,6 +72,23 @@ public CollectionModel GetAccountsChartsMasterDataList() {
}
}

[HttpPost]
[Route("v2/financial-accounting/accounts-charts/{accountsChartUID:guid}/excel")]
public SingleObjectModel GetAccountsInExcelFile([FromUri] string accountsChartUID,
[FromBody] AccountsSearchCommand searchCommand) {
base.RequireBody(searchCommand);

using (var usecases = AccountsChartUseCases.UseCaseInteractor()) {
AccountsChartDto accountsChart = usecases.SearchAccounts(accountsChartUID, searchCommand);

var excelExporter = new ExcelExporter();

ExcelFileDto excelFileDto = excelExporter.Export(accountsChart, searchCommand);

return new SingleObjectModel(base.Request, excelFileDto);
}
}


[HttpPost]
[Route("v2/financial-accounting/accounts-charts/{accountsChartUID:guid}")]
Expand Down

0 comments on commit 61b39a9

Please sign in to comment.