{% load i18n %} {% load ifsetting %}

{% trans 'There are no budgets' %}

{% ifsetting OIPA_SYNC_ENABLED %} tag.iati_budgets_disabled = (data.iati_data.link_info.oipa_fields.indexOf("B") != -1); {% endifsetting %}
var tag = this; tag.toFixed = function(value){ if (!value){return ''} return tag.focus ? parseFloat(value).toFixed(2) : value.toLocaleString('en-US',{useGrouping:true, minimumFractionDigits:2}) } function getTotal() { return _.sumBy(tag.parent.budgets, 'value'); } function setTotal() { tag.total = tag.formatMoney(getTotal()); } tag.formatMoney = function(value, currency_id){return tag.focus ? value : stores.budgetStore.formatMoney(value, currency_id)} tag.shouldUpdate = function (data) { return !data ? false : tag.refs.total.value !== data.total || data.disabled !== tag.disabled; }; tag.setBudgets = function () { tag.update({ total: tag.formatMoney(getTotal()) }); }; tag.on('before-mount', setTotal); tag.on('before-update', setTotal);
var tag = this; tag.focus = false; {% ifsetting OIPA_SYNC_ENABLED %} tag.iati_budgets_disabled = (data.iati_data.link_info.oipa_fields.indexOf("B") != -1); {% else %} tag.iati_budgets_disabled = false; {% endifsetting %} tag.onfocus = function(){ tag.update({focus: true})} tag.onblur = function(){ tag.update({focus: false});} tag.onclick = function(){ /* Added for testing, to trigger a 'change' event so selenium can see what happens */ var value = _.toNumber(tag.refs.quarterly.value); var valid = _.isNumber(value); if (value > 0 && valid){ tag.onchange() } } function setInitial(){ tag.initial = _.clone(_(tag.opts.budgets).find({ quarter: tag.opts.quarter })); if (!tag.initial){return} tag.hasCurrencyWarning = _.has(tag.initial, 'currency_id') && tag.initial.currency_id !== stores.activityStore.activity.default_currency.code if (tag.hasCurrencyWarning) {tag.currencyWarning = stores.budgetStore.formatMoney(tag.initial.value, tag.initial.currency_id)} } function getTotal() { var budget = _(tag.opts.budgets).find({ quarter: tag.opts.quarter }); if (budget) { tag.budget = budget; tag.outOfRange = false; return budget.value; } tag.budget = {}; tag.outOfRange = true; return null; } tag.showInput = function(){tag.update({})} function setTotal() { tag.total = getTotal(); } tag.shouldUpdate = function (data) { return !data ? false : tag.refs.quarterly.value !== data.total || data.disabled !== tag.disabled || data.focus != tag.focus; }; tag.setBudgets = function () { tag.update({ total: getTotal() }); }; tag.onchange = function () { var value = _.toNumber(tag.refs.quarterly.value); var valid = _.isNumber(value); if (valid) { tag.parent.trigger('setQuarterly', tag.opts, value); } tag.setBudgets(); }; tag.serializeAmounts = function () { tag.update(); return { quarter: tag.opts.quarter, amount: stores.budgetStore.unformatMoney(tag.refs.quarterly.value) }; }; tag.formatMoney = function(value, currency_id){return tag.focus ? value : stores.budgetStore.formatMoney(value, currency_id)} tag.on('before-mount', setTotal); tag.on('before-mount', setInitial); tag.on('before-update', setTotal);
var tag = this; tag.focus = false; {% ifsetting OIPA_SYNC_ENABLED %} tag.iati_budgets_disabled = (data.iati_data.link_info.oipa_fields.indexOf("B") != -1); {% else %} tag.iati_budgets_disabled = false; {% endifsetting %} tag.toFixed = function(value){ if (!value) { return '' } return tag.focus ? parseFloat(value).toFixed(2) : value.toLocaleString('en-US',{useGrouping:true, minimumFractionDigits:2}) } tag.onfocus = function(){tag.update({focus: true})} tag.onblur = function(){tag.update({focus: false})} function getTotal() { return _(tag.opts.budgets).filter(function (t) { return Math.floor(t.quarter / 10) === tag.opts.year; }).sumBy('value'); } function setTotal() { tag.total = tag.formatMoney(getTotal()); } tag.shouldUpdate = function (data) { return !data ? false : tag.refs.annual.value !== data.total; }; function setDisabled() { tag.disabled = true; } tag.on('before-mount', setTotal); tag.on('before-mount', setDisabled); tag.on('before-update', setTotal); tag.setBudgets = function () { tag.update({ total: tag.formatMoney(getTotal()) }); }; tag.onchange = function () { var value = _.toNumber(tag.refs.annual.value); var valid = _.isNumber(value); if (valid) { tag.parent.trigger('setAnnual', tag.opts, value); }; tag.setBudgets(); }; tag.formatMoney = function(value, currency_id){return tag.focus ? value : stores.budgetStore.formatMoney(value, currency_id)}

{% blocktrans %}Providing budgets helps to improve aid predictability and supports better quality forward planning. Please provide a quarterly or annual budget breakdown for your {{activity_singular_lower}}.{% endblocktrans %}

{% include "editor/budget.svg" %}

{% blocktrans %}There are multiple currencies being used for this {{activity_singular_lower}} and its Budgets. On Save, all currencies will be saved in {stores.activityStore.activity.default_currency.name}.{% endblocktrans %}

{% blocktrans %}{{activity_singular}} currency{% endblocktrans %} {stores.activityStore.activity.default_currency.name}

{% blocktrans %}Providing budgets helps to improve aid predictability and supports better quality forward planning. Please provide a quarterly or annual budget breakdown for your {{activity_singular_lower}}. You can change the default currency in the default settings tab{% endblocktrans %}
{% comment %} Year {% endcomment %} Jan - Mar Apr - Jun Jul - Sept Oct - Dec {% comment %} Divider {% endcomment %} {% trans 'Annual Total' %}
{year} {% comment %} Divider {% endcomment %}
{% trans 'Total' %}
var tag = this; tag.mixin('SerializerMixin'); tag.mixin('ValidationMixin'); tag.quarters = [1, 2, 3, 4]; {% ifsetting OIPA_SYNC_ENABLED %} tag.iati_budgets_disabled = (data.iati_data.link_info.oipa_fields.indexOf("B") != -1); {% else %} tag.iati_budgets_disabled = false; {% endifsetting %} function setActivityPeriods() { var dates = _.map(stores.activityStore.activity.activity_dates, 'iso_date'); var quarter_range; function getPeriod(d) { var date; function splitDate(_d) { return _.map(_.split(_d, '-'), _.toNumber); } date = splitDate(d); return (date[0] * 10) + _.ceil(date[1] / 3); } quarter_range = _.map(dates, getPeriod); /* Append the min, max budget dates so that we're not hiding budgets */ _.extend(quarter_range, _.map(stores.budgetStore.budgets, 'quarter')) return [_.min(quarter_range), _.max(quarter_range)] } function quartersBetweenPeriods(periods) { var current = periods[0]; var quarters = [{ quarter: current }]; while (current < periods[1]) { current = current % 10 >= 4 ? ((current + 10) - (current % 10)) + 1 : current + 1; quarters.push({ quarter: current }); } return quarters; } function arrayTags(child_tag_id){ var childTags = tag.tags[child_tag_id]; if (_.isUndefined(childTags)) { return []}; return _.isArray(childTags) ? childTags : [childTags]; } function getQuarterTags() { return arrayTags('budget-quarterly-input'); } function getAnnualTags() { return arrayTags('budget-annual-input'); } function getTotalCommitTag() { return arrayTags('budget-total-commitment'); } function setDisabled(childTag) { childTag.update({ disabled: true }); } function setEnabled(childTag) { childTag.update({ disabled: false }); } tag.toggleQuarterlyInputs = function () { tag.update({ budget_toggle: 'Quarterly' }); _(getQuarterTags()).each(setEnabled); _(getAnnualTags()).each(setDisabled); }; tag.toggleAnnualInputs = function () { tag.update({ budget_toggle: 'Annual' }); _(getQuarterTags()).each(setDisabled); _(getAnnualTags()).each(setEnabled); }; tag.serializeAmounts = function () { return _.invokeMap(getQuarterTags(), 'serializeAmounts'); }; refreshData = function(){ var data = _.cloneDeep(tag.store[tag.store.el]); var activityPeriods = setActivityPeriods(); tag.budgets = quartersBetweenPeriods(activityPeriods); _.each(tag.budgets, function (period) { var periodWithData = _.find(data, { quarter: period.quarter }); if (periodWithData) { period.value = periodWithData.value; period.currency_id = periodWithData.currency_id;} }); tag.years = _.range(_.floor(activityPeriods[0] / 10), (_.floor(activityPeriods[1] / 10) + 1)); tag.toggleQuarterlyInputs(); tag.update(); _.each(getAnnualTags(), function (childTag) { childTag.setBudgets(); }); _.each(getQuarterTags(), function (childTag) { childTag.setBudgets(); }); _.each(getTotalCommitTag(), function (childTag) { childTag.setBudgets(); }); } /* commented for editor highlighting - content is required - django templates in translations for us in Javascript * * {% trans "Budgets default currency is not set" as budget_currency_warning_title %} * {% trans "A default Budget Currency setting is required in order to view and edit budgets." as budget_currency_warning_content %} * {% trans "Set Budget Currency" as budget_currency_warning_button %} */ tag.on('before-mount', refreshData) tag.on('mount', function(){ tag.store.on('budgets_restored', refreshData) stores.activityStore.on('activity_restored', refreshData) if (!tag.store.getActivity().default_currency.code) { $.confirm({ type: 'orange', theme: 'modern', icon: 'glyphicon glyphicon-warning-sign', columnClass: 'medium', title: '{{budget_currency_warning_title|escape}}', content: '{{budget_currency_warning_content|escape}}', buttons: { setDefault: { btnClass: 'btn-success', text: '{{budget_currency_warning_button|escape}}', action: function(){ window.location.hash = '#finances/general'; } } } }); } }) tag.on('before-update', function () { tag.total = _.sumBy(tag.budgets, 'value'); }); tag.on('setQuarterly', function (opts, value) { var filter = { quarter: opts.quarter }; var budget = _.find(tag.budgets, filter); if (_.isUndefined(budget)) { tag.budgets.push(filter); budget = _.find(tag.budgets, filter); } budget.value = value; _.each(getAnnualTags(), function (childTag) { childTag.setBudgets(); }); _.each(getTotalCommitTag(), function (childTag) { childTag.setBudgets(); }); }); tag.on('setAnnual', function (opts, value) { var quarters = _.filter(tag.budgets, function (budget) { return Math.floor(budget.quarter / 10) === opts.year; }); _.each(quarters, function (q) { q.value = value / quarters.length; }); _.each(getQuarterTags(), function (childTag) { if (Math.floor(childTag.opts.quarter / 10) === opts.year) { childTag.setBudgets(); } }); _.each(getTotalCommitTag(), function (childTag) { childTag.setBudgets(); }); });

{% blocktrans %}Budgets haven't been fitted yet to quarters. You can't save them.{% endblocktrans %}

var tag = this; tag.store = stores.budgetStore; tag.mixin('SerializerMixin'); tag.mixin('TabMixin'); tag.mixin('ValidationMixin'); {% ifsetting OIPA_SYNC_ENABLED %} tag.iati_block_saving = (data.iati_data.link_info.oipa_fields.indexOf("B") != -1); {% else %} tag.iati_block_saving = false; {% endifsetting %} tag.on('before-mount', function(){ function updateMixedCurrenciesAlert(){ var currencies = _(tag.store.budgets).map('currency_id').uniq().value() if (currencies.length === 0 ){ tag.currenciesMixed = false } else if (currencies.length > 1 || currencies[0] !== stores.activityStore.activity.default_currency.code){ tag.currenciesMixed = true } else { tag.currenciesMixed = false } } updateMixedCurrenciesAlert() stores.activityStore.on('activity_updated', updateMixedCurrenciesAlert) }) function serializeAmounts() { var table = tag.tags['budget-table']; var amounts = _.invoke(table, 'serializeAmounts'); _.each(amounts, function(amount){ amount.value = _.toNumber(_.replace(amount.amount, ',', '')); _.unset(amount, 'amount'); if (!_.isNumber( amount.value)){amount.value = 0}; }); amounts = _.filter(amounts, function(a){return a.value !== 0}) return amounts; // tag.update({ amounts: amounts }); tag.store.save(tag, { url: tag.store.urls.create(), method: 'POST', data: amounts }); } tag.save = function(){ var budgets_are_quarterly = '{{ budgets_are_quarterly }}'; if (tag.has_changed() && budgets_are_quarterly === 'True' ){ return tag.store.save(tag, { url: tag.store.urls.create(), method: 'POST', data: serializeAmounts() }); } else if (budgets_are_quarterly === 'False'){ window.banner_message.show('Current budgets are not quarterly. Cannot save', 'error'); } else { window.banner_message.show(_.get(tag.store, 'messages.no_changes', 'No changes to save'), 'success'); } } tag.has_changed = function(){ // If IATI sync is enabled for budgets do NOT allow saving. if (tag.iati_block_saving) { return false; } if ('{{ budgets_are_quarterly }}' === 'False') {return false} if (tag.tags['budget-table']) { var amounts = _.filter(tag.tags['budget-table'].budgets, function(b){return _.isNumber(b.value)}) var existing_budgets = _(tag.store.budgets).map(function(i){return _.pick(i, ['value', 'quarter'])}).value() amounts = _.map(amounts, function(i){return _.pick(i, ['value', 'quarter'])}) return !_.isEqual(_.sortBy(amounts, 'quarter'), _.sortBy(existing_budgets, 'quarter')) } else { return false; } }
 {% trans 'IATI Sync active' %}