diff --git a/resources/assets/v2/src/pages/accounts/index.js b/resources/assets/v2/src/pages/accounts/index.js index 5125de0e62..380fe66116 100644 --- a/resources/assets/v2/src/pages/accounts/index.js +++ b/resources/assets/v2/src/pages/accounts/index.js @@ -315,7 +315,7 @@ let index = function () { // need to find the input thing console.log('Clicked edit button for account on index #' + index + ' and field ' + fieldName); const querySelector = 'input[data-field="' + fieldName + '"][data-index="' + index + '"]'; - console.log(querySelector); + // console.log(querySelector); const newValue = document.querySelectorAll(querySelector)[0].value ?? ''; if ('' === newValue) { return; diff --git a/resources/assets/v2/src/pages/dashboard/accounts.js b/resources/assets/v2/src/pages/dashboard/accounts.js index da71e5f435..cd8c83bc7b 100644 --- a/resources/assets/v2/src/pages/dashboard/accounts.js +++ b/resources/assets/v2/src/pages/dashboard/accounts.js @@ -201,7 +201,7 @@ export default () => ({ balance.amount_formatted = formatMoney(balance.amount, balance.currency_code); return balance; }); - console.log(parent); + // console.log(parent); // get groups for account: diff --git a/resources/assets/v2/src/pages/dashboard/boxes.js b/resources/assets/v2/src/pages/dashboard/boxes.js index 911233af94..1e6e43e2ad 100644 --- a/resources/assets/v2/src/pages/dashboard/boxes.js +++ b/resources/assets/v2/src/pages/dashboard/boxes.js @@ -76,7 +76,7 @@ export default () => ({ continue; } let key = current.key; - console.log('NOT NATIVE'); + // console.log('NOT NATIVE'); if (key.startsWith('balance-in-')) { this.balanceBox.amounts.push(formatMoney(current.monetary_value, current.currency_code)); continue; diff --git a/resources/assets/v2/src/pages/dashboard/subscriptions.js b/resources/assets/v2/src/pages/dashboard/subscriptions.js index 6359ad1784..db547b9c19 100644 --- a/resources/assets/v2/src/pages/dashboard/subscriptions.js +++ b/resources/assets/v2/src/pages/dashboard/subscriptions.js @@ -44,6 +44,18 @@ function addObjectGroupInfo(data) { } } +function parsePayDates(list) { + let newList = []; + for(let i in list) { + if (list.hasOwnProperty(i)) { + let current = list[i]; + // convert to date object: + newList.push(new Date(current)); + } + } + return newList; +} + function parseBillInfo(data) { let result = { id: data.id, @@ -55,7 +67,7 @@ function parseBillInfo(data) { // paid transactions: transactions: [], // unpaid moments - pay_dates: data.attributes.pay_dates, + pay_dates: parsePayDates(data.attributes.pay_dates), paid: data.attributes.paid_dates.length > 0, }; // set variables @@ -64,6 +76,7 @@ function parseBillInfo(data) { times: data.attributes.pay_dates.length, amount: result.expected_amount }); + // console.log(result); return result; } @@ -96,6 +109,21 @@ function parsePaidTransactions(paid_dates, bill) { return result; } +function isInRange(bill) { + let start = new Date(window.store.get('start')); + let end = new Date(window.store.get('end')); + for(let i in bill.pay_dates) { + if (bill.pay_dates.hasOwnProperty(i)) { + let currentDate = bill.pay_dates[i]; + //console.log(currentDate); + if (currentDate >= start && currentDate <= end) { + return true; + } + } + } + return false; +} + function downloadSubscriptions(params) { const getter = new Get(); return getter.list(params) @@ -113,10 +141,18 @@ function downloadSubscriptions(params) { // create and update the bill. let bill = parseBillInfo(current); + + // if not yet paid, and pay_dates is not in current rage, ignore it. + if (false === bill.paid && !isInRange(bill)) { + console.warn('Bill "'+bill.name+'" is not paid and not in range, ignoring: '); + continue; + } + + bill.transactions = parsePaidTransactions(current.attributes.paid_dates, bill); subscriptionData[objectGroupId].bills.push(bill); - if (0 === current.attributes.paid_dates.length) { + if (false === bill.paid) { // bill is unpaid, count the "pay_dates" and multiply with the "amount". // since bill is unpaid, this can only be in currency amount and native currency amount. const totalAmount = current.attributes.pay_dates.length * bill.amount; @@ -132,6 +168,7 @@ function downloadSubscriptions(params) { //native_unpaid: 0, }; } + subscriptionData[objectGroupId].payment_info[bill.currency_code].unpaid += totalAmount; //subscriptionData[objectGroupId].payment_info[bill.currency_code].native_unpaid += totalNativeAmount; }