{% load i18n %} {% load ifsetting %} var tag = this; tag.mixin('TabMixin'); tag.store = stores.transactionStore; tag.transactions = tag.store[tag.store.el] window.modals = { commitment: riot.mount('tab-transactions-add-commitment-modal')[0], incoming_funds: riot.mount('tab-transactions-add-incoming-funds-modal')[0], transaction: riot.mount('tab-transactions-add-transaction-modal')[0], sync_update: riot.mount('tab-iati-sync-confirm-update-modal')[0], sync_delete: riot.mount('tab-iati-sync-confirm-delete-modal')[0], update_iati_link: riot.mount('tab-iati-sync-update-link-modal')[0], } function refreshData(){ function sumValue(objects){return _(objects).map('usd_value').map(_.toNumber).sum();} function sortValue(objects){return _.sortBy(objects, function(m){return _.toNumber(m.usd_value)}).reverse();} tag.transactions = tag.store[tag.store.el] tag.commitments = sortValue(_.filter(tag.transactions, function(t){return t.transaction_type === 'C'})); tag.spent = sortValue(_.filter(tag.transactions, function(t){return t.transaction_type === 'D' || t.transaction_type === 'E'})); tag.received_funds = sortValue(_.filter(tag.transactions, function(t){return t.transaction_type === 'IF'})); tag.totals = { commitments : sumValue(tag.commitments), received_funds : sumValue(tag.received_funds), spent: sumValue(tag.spent) } var makeSyncActivitiesRequest = function(job){ var url = "{% url 'oipa_activity' %}" + data.activity.iati_identifier + '?celerize'; if (job) { url = url + '&job=' + job} var request = $.ajax({ type: 'GET', url: url, data: {'openly_id': data.activity.id}, headers: { 'X-CSRFTOKEN': window.csrf_token } }); request.done(function(res){ if (request.status == 202){ /* 2-second Loop on a "202:Accepted" return code */ return setTimeout(function(){makeSyncActivitiesRequest(res.job)}, 2000); } else { // set iati activity and transaction data from responce data.iati_data.link_info = res['link_info']; tag.update(); } }) } makeSyncActivitiesRequest(); tag.update(); }; tag.has_changed = function(){ return false }; {% ifsetting OIPA_SYNC_ENABLED %} tag.iati_commitments_disabled = (data.iati_data.link_info.oipa_fields.indexOf("C") != -1); tag.iati_disbursements_disabled = (data.iati_data.link_info.oipa_fields.indexOf("OF") != -1); tag.iati_other_disabled = (data.iati_data.link_info.oipa_fields.indexOf("IF") != -1); {% else %} tag.iati_commitments_disabled = false; tag.iati_disbursements_disabled = false; tag.iati_other_disabled = false; {% endifsetting %} tag.on('before-mount', refreshData); tag.on('mount', function(){tag.store.on(tag.store.el+'_changed', refreshData);}) tag.on('unmount', function(){tag.store.off(tag.store.el+'_changed', refreshData);}) $(document).ready(function() { $('tr th:contains("Date")').css('min-width', '82px'); var sortableTables = ['#transactions-committed-table', '#transactions-received-table', '#transactions-spent-table']; sortableTables.forEach(function(tableId) { $(tableId + ' thead th').each(function(col) { $(this).hover( function() { $(this).addClass('focus'); }, function() { $(this).removeClass('focus'); } ); $(this).click(function() { if ($(this).is('.asc')) { $(this).removeClass('asc'); $(this).addClass('desc selected'); sortOrder = -1; } else { $(this).addClass('asc selected'); $(this).removeClass('desc'); sortOrder = 1; } $(this).siblings().removeClass('asc selected'); $(this).siblings().removeClass('desc selected'); var arrData = $(tableId).find('tbody >tr:has(td)').get(); arrData.sort(function(a, b) { var val1 = $(a).children('td').eq(col).text().toUpperCase().trim(); var val2 = $(b).children('td').eq(col).text().toUpperCase().trim(); var val1_float = parseFloat(val1.slice(4, ).replace(/,/g , "" )); var val2_float = parseFloat(val2.slice(4, ).replace(/,/g , "" )); try { var val1_date = new Date(val1); var val2_date = new Date(val2); } catch(e) { var val1_date = 0; var val2_date = 0; } if (val1_float >= 0 && val2_float >= 0) { return sortOrder == 1 ? val1_float - val2_float : val2_float - val1_float; } else if (val1_date != 0 && val2_date != 0) { return sortOrder == 1 ? val1_date - val2_date : val2_date - val1_date; } else { return (val1 < val2) ? -sortOrder : (val1 > val2) ? sortOrder : 0; } }); $.each(arrData, function(index, row) { $(tableId + ' tbody').append(row); }); }); }); }); }); Total commitment {totals.commitments} Total incoming funds {totals.received_funds} Total spent {totals.spent} var tag = this; tag.totals = {}; tag.on('before-mount', function(){ _.map(tag.opts.totals, function(v, k){ tag.totals[k] = accounting.formatMoney(v, 'USD ', 0) }) }) tag.on('update', function(){ _.map(tag.opts.totals, function(v, k){ tag.totals[k] = accounting.formatMoney(v, 'USD ', 0) }) }) How much have you allocated for the project? Add a commitment transaction There are no financial commitments added to this activity Funds allocated to this activity Add another commitment this.toggle_modal = function(){window.modals.commitment.toggle()}; Did you receive funds from another donor? Add funds received from another donor There are no funds from another donor added to this activity Funds received from other donors Add another incoming fund this.toggle_modal = function(){window.modals.incoming_funds.toggle()}; How much have you spent? Add a disbursement/expenditure transaction There are no disbursements or expenditures added to this activity Financial Transactions Add another disbursement/expenditure this.toggle_modal = function(){window.modals.transaction.toggle()}; {fieldHeader(field)} {% comment %} Edit {% endcomment %} {fieldContent(parent.transaction, field)} View Edit Delete var tag = this; var fieldHeaders; var fieldContentFunctions; tag.show_edit = true; tag.show_delete = true; {% ifsetting OIPA_SYNC_ENABLED %} tag.iati_commitments_disabled = (data.iati_data.link_info.oipa_fields.indexOf("C") != -1); tag.iati_disbursements_disabled = (data.iati_data.link_info.oipa_fields.indexOf("OF") != -1); tag.iati_other_disabled = (data.iati_data.link_info.oipa_fields.indexOf("IF") != -1); {% else %} tag.iati_commitments_disabled = false; tag.iati_disbursements_disabled = false; tag.iati_other_disabled = false; {% endifsetting %} /* Pick which attributes of a transaction you would like to show */ var all_fields = ['id', 'activity', 'value', 'finance_type', 'provider_organisation', 'provider_activity', 'receiver_organisation', 'currency', 'value_date', 'transaction_date', 'transaction_type', 'aid_type', 'flow_type', 'finance_type', 'tied_status', 'iati_disabled'] tag.fields = opts.fields || all_fields; tag.use_flags = opts.use_flags || false; tag.edit = function(e){ e.item.transaction; tag.opts.editmodal.toggle(e.item.transaction); } tag.delete = function(e){ /* Raise modal */ var confirm = function(){ stores.transactionStore.delete(tag, e.item.transaction);}; var content = 'This transaction will be deleted permanently'; RiotControl.trigger('confirm-delete', { confirm: confirm, content: content }) } /* 'fieldHeader' and 'fieldContent' functions */ fieldHeaders = { activity: 'Activity', transaction_type: 'Type', finance_type: 'Finance Type', aid_type: 'Aid Type', value: 'Amount', receiver_organisation: 'Receiver', provider_organisation: 'Provider', provider_activity: 'Activity', transaction_date: 'Date', description: 'Description', usd_value: 'Amount in USD' } fieldContentFunctions = { transaction_type: function(t){ return _.find(choices.transaction_type, {code: t.transaction_type}).code}, aid_type: function(t){ return _.find(choices.aid_type, function(at){return at[0] === t.aid_type})[2]}, finance_type: function(t){ return _.find(choices.finance_type, function(ft){return ft[0] === t.finance_type})[2]}, value: function(t){ return accounting.formatMoney(t.value, t.currency ? t.currency +' ' : '', 2)}, usd_value: function(t){ return accounting.formatMoney(t.usd_value, '$', 2)}, provider_organisation: function(t){ /* This relies on magic-number indexing. It's not ideal, we ought to use JSON for organisation choices */ var code = t.provider_organisation; if (_.isNull(code)) {return 'None'} else {return _.find(choices.organisation, function(o){return o[0] === code})[3]}; }, receiver_organisation: function(t){ /* This relies on magic-number indexing. It's not ideal, we ought to use JSON for organisation choices */ var code = t.receiver_organisation; if (_.isNull(code)) {return 'None'} else {return _.find(choices.organisation, function(o){return o[0] === code})[3]}; }, provider_activity: function(t){ /* This relies on magic-number indexing. It's not ideal, we ought to use JSON for activity choices */ var code = t.provider_activity; if (_.isNull(code)) {return 'None'} else {return _.find(choices.activity, function(o){return o[0] === code})[1]} }, iati_disabled: function(t){ if (t.transaction_type == "C") { if (tag.iati_commitments_disabled) { return true } } else if (t.transaction_type == "D" || t.transaction_type == "E") { if (tag.iati_disbursements_disabled) { return true } } else if (tag.iati_other_disabled) { return true } else { return false } } }; tag.fieldHeader = function(field){ return _.get(fieldHeaders, field, field) } tag.fieldContent = function(transaction, field){return _.invoke(fieldContentFunctions, field, transaction) || _.get(transaction, field) } IATI Sync active {% include 'tags/finances/tab-transactions-modals.html' %}
Total commitment
Total incoming funds
Total spent
There are no financial commitments added to this activity
There are no funds from another donor added to this activity
There are no disbursements or expenditures added to this activity