Skip to content

Commit

Permalink
balance_sheet end point updated. balance sheet done.
Browse files Browse the repository at this point in the history
  • Loading branch information
HelderAntunes committed Dec 9, 2017
1 parent 423f3b7 commit d152066
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 44 deletions.
24 changes: 24 additions & 0 deletions proto/server/public/javascript/balance_sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ var updateData = function($scope, $http){

var balanceSheetCallback = function($scope, $http, balanceSheet) {
console.log(balanceSheet);

var currAssets = balanceSheet.assets.curr;
var nonCurrAssets = balanceSheet.assets.nonCurr;
$scope.cashAndBankDeposits = currAssets.cashAndBankDeposits;
$scope.inventory = currAssets.inventory;
$scope.clients = currAssets.clients;
$scope.stateAndOtherPubEntAssets = currAssets.stateAndOtherPubEntAssets;
$scope.otherCurrAssets = currAssets.otherCurrAssets;
$scope.totalCurrAssets = currAssets.totalCurrAssets;
$scope.shareholders_partners = nonCurrAssets.shareholders_partners;
$scope.tangibleFixedAssets = nonCurrAssets.tangibleFixedAssets;
$scope.otherNonCurrAssets = nonCurrAssets.otherNonCurrAssets;
$scope.totalNonCurrAssets = nonCurrAssets.totalNonCurrAssets;

var liabilities = balanceSheet.liabilities;
$scope.suppliers = liabilities.suppliers;
$scope.customerDownPayment = liabilities.customerDownPayment;
$scope.stateAndOtherPubEntAssetsLiabilities = liabilities.stateAndOtherPubEntAssetsLiabilities;
$scope.otherLiabilities = liabilities.otherLiabilities;
$scope.totalLiabilities = liabilities.value;

$scope.assets = balanceSheet.assets.value;
$scope.liabilities = balanceSheet.liabilities.value;
$scope.equity = balanceSheet.equity.value;
}

var getMonthName = function(index) {
Expand Down
2 changes: 1 addition & 1 deletion proto/server/public/javascript/income_statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ app.controller('income_statement_controller', function($scope, $http) {
//init vars
var today = new Date();

var url_string = window.location.href
var url_string = window.location.href;
var url = new URL(url_string);

$scope.chosenYear = url.searchParams.get("year");
Expand Down
49 changes: 11 additions & 38 deletions proto/server/templates/balance_sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ <h3>[[equity | euro]]</h3>
</thead>
<tbody>
<tr>
<td>Property</td>
<td>[[property | euro]]</td>
<td>Tangible fixed assets</td>
<td>[[tangibleFixedAssets | euro]]</td>
</tr>
<tr>
<td>Other Debtors and Creditors</td>
<td>[[otherDebtorsAndCreditors | euro]]</td>
<td>Shareholders / partners</td>
<td>[[shareholders_partners | euro]]</td>
</tr>
<tr>
<td>Other non current assets</td>
Expand All @@ -109,7 +109,7 @@ <h3>[[equity | euro]]</h3>
<table class="table table-striped">
<thead>
<tr>
<th>Current Liabilities</th>
<th>Liabilities</th>
<th>[[dateTable]]</th>
</tr>
</thead>
Expand All @@ -119,47 +119,20 @@ <h3>[[equity | euro]]</h3>
<td>[[suppliers | euro]]</td>
</tr>
<tr>
<td>Customer Advance</td>
<td>[[customerAdvance | euro]]</td>
<td>Customer Down Payment</td>
<td>[[customerDownPayment | euro]]</td>
</tr>
<tr>
<td>State and other public entities</td>
<td>[[stateAndOtherPubEntAssetsLiabilities | euro]]</td>
</tr>
<tr>
<td>Other bills to pay</td>
<td>[[otherBillsToPay | euro]]</td>
<td>Other liabilities</td>
<td>[[otherLiabilities | euro]]</td>
</tr>
<tr>
<td>Total current liablities</td>
<td>[[totalCurrLiabilities | euro]]</td>
</tr>
</tbody>
</table>
<hr/>
<table class="table table-striped">
<thead>
<tr>
<th>Non Current Liabilities</th>
<th>[[dateTable]]</th>
</tr>
</thead>
<tbody>
<tr>
<td>Provisions</td>
<td>[[provisions | euro]]</td>
</tr>
<tr>
<td>Long-term debt</td>
<td>[[customerAdvance | euro]]</td>
</tr>
<tr>
<td>Other non current liabilities</td>
<td>[[otherNonCurrentLiabilities | euro]]</td>
</tr>
<tr>
<td>Total non current liablities</td>
<td>[[totalNonCurrLiabilities | euro]]</td>
<td>Total liablities</td>
<td>[[totalLiabilities | euro]]</td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 2 additions & 0 deletions proto/server/templates/finances.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ <h3>[[equity | euro]]</h3>

</div>

<hr/>

</div>

<script src="../javascript/main.js"></script>
Expand Down
97 changes: 92 additions & 5 deletions proto/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,32 @@ function calcCumulativeBalancetes(transactions, accounts, year, month) {
return balancetes;
}

// based on http://www.dfk.pt/snc/balanco.htm
function calcBalanco(balancete) {
var balanco = {
'assets':{
'assets': {
'accounts': [],
'value': 0,
'curr': {
'cashAndBankDeposits': 0,
'inventory': 0,
'clients': 0,
'stateAndOtherPubEntAssets': 0,
'otherCurrAssets': 0
},
'nonCurr': {
'shareholders_partners': 0,
'tangibleFixedAssets': 0,
'otherNonCurrAssets': 0,
}
},
'liabilities': {
'accounts': [],
'value': 0,
'suppliers': 0,
'stateAndOtherPubEntAssetsLiabilities': 0,
'otherLiabilities': 0,
'customerDownPayment': 0,
},
'equity': {
'accounts': [],
Expand All @@ -235,8 +252,13 @@ function calcBalanco(balancete) {
balancete[i].AccountID[0] === '6' ||
balancete[i].AccountID[0] === '7' ||
balancete[i].AccountID[0] === '8' ||
balancete[i].AccountID[0] === '9')
balancete[i].AccountID[0] === '9') {
if (balancete[i].AccountID === "219") {
balanco.assets.accounts.push(balancete[i]);
balanco.liabilities.accounts.push(balancete[i]);
}
continue;
}

balancete[i].ClosingDebitBalance = balancete[i].OpeningDebitBalance + balancete[i].DebtMovements;
balancete[i].ClosingCreditBalance = balancete[i].OpeningCreditBalance + balancete[i].CreditMovements;
Expand All @@ -245,17 +267,82 @@ function calcBalanco(balancete) {
balancete[i].ClosingDebitBalance = balancete[i].ClosingDebitBalance - balancete[i].ClosingCreditBalance;
balancete[i].ClosingCreditBalance = 0;
balanco.assets.accounts.push(balancete[i])
balanco.assets.value += balancete[i].ClosingDebitBalance;
}
else {
balancete[i].ClosingCreditBalance = balancete[i].ClosingCreditBalance - balancete[i].ClosingDebitBalance;
balancete[i].ClosingDebitBalance = 0;
balanco.liabilities.accounts.push(balancete[i]);
balanco.liabilities.value += balancete[i].ClosingCreditBalance;
}
}
balanco.equity.value = balanco.assets.value - balanco.liabilities.value;

for (var i = 0; i < balanco.assets.accounts.length; i++) {
var account = balanco.assets.accounts[i];
var id = account.AccountID;

// Current Assets
if (id === "11" || id === "12" || id == "13") {
balanco.assets.curr.cashAndBankDeposits += account.ClosingDebitBalance - account.ClosingCreditBalance;
}
else if (id === "32" || id === "33" || id === "34" || id === "35" || id === "36" || id == "39") { // 32/3/4/5/6/9
balanco.assets.curr.inventory += account.ClosingDebitBalance;
}
else if (id === "21") {
balanco.assets.curr.clients += account.ClosingDebitBalance;
}
else if (id === "219") {
balanco.assets.curr.clients -= - account.ClosingCreditBalance;
}
else if (id === "24") {
if (account.ClosingDebitBalance > account.ClosingCreditBalance)
balanco.assets.curr.stateAndOtherPubEntAssets += account.ClosingDebitBalance;
}
else {
balanco.assets.curr.otherCurrAssets += 0;
}

// Non current assets
if (id === "26") {
balanco.assets.nonCurr.shareholders_partners += account.ClosingDebitBalance;
}
else if (id === "43") {
balanco.assets.nonCurr.tangibleFixedAssets += account.ClosingDebitBalance;
}
else {
balanco.assets.nonCurr.otherNonCurrAssets += 0;
}
}
balanco.assets.curr.totalCurrAssets = balanco.assets.curr.cashAndBankDeposits
+ balanco.assets.curr.inventory
+ balanco.assets.curr.clients
+ balanco.assets.curr.stateAndOtherPubEntAssets
+ balanco.assets.curr.otherCurrAssets;
balanco.assets.nonCurr.totalNonCurrAssets = balanco.assets.nonCurr.shareholders_partners
+ balanco.assets.nonCurr.tangibleFixedAssets
+ balanco.assets.nonCurr.otherNonCurrAssets;
balanco.assets.value = balanco.assets.curr.totalCurrAssets + balanco.assets.nonCurr.totalNonCurrAssets;

for (var i = 0; i < balanco.liabilities.accounts.length; i++) {
var account = balanco.liabilities.accounts[i];
var id = account.AccountID;

// liabilities
if (id === "22") {
balanco.liabilities.suppliers += account.ClosingCreditBalance;
}
else if (id === "219") {
balanco.liabilities.customerDownPayment += account.ClosingCreditBalance;
}
else if (id == "24") {
balanco.liabilities.stateAndOtherPubEntAssetsLiabilities += account.ClosingCreditBalance;
}
else {
balanco.liabilities.otherLiabilities += 0;
}
}
balanco.liabilities.value = balanco.liabilities.suppliers + balanco.liabilities.customerDownPayment +
balanco.liabilities.stateAndOtherPubEntAssetsLiabilities + balanco.liabilities.otherLiabilities;
balanco.equity.value = balanco.assets.value - balanco.liabilities.value;
console.log(balanco);
return balanco;
}

Expand Down

0 comments on commit d152066

Please sign in to comment.