<commit_before>import m from 'mithril';
import _ from 'underscore';
import h from '../h';
import contributionVM from '../vms/contribution-vm';
import ownerMessageContent from '../c/owner-message-content';
import modalBox from '../c/modal-box';
import userVM from '../vms/user-vm';
import rewardReceiver from './reward-receiver';

const I18nScope = _.partial(h.i18nScope, 'payment.state');
const contributionScope = _.partial(h.i18nScope, 'users.contribution_row');

const userContributedBox = {
    controller: function(args) {
        const displayModal = h.toggleProp(false, true),
            toggleDelivery = (projectId, contribution) => {
                userVM.toggleDelivery(projectId, contribution).then(() => {
                    const lastStatus = contribution.reward_sent_at ? 'delivered' : 'undelivered';
                    contribution.delivery_status = contribution.delivery_status === 'received' ? lastStatus : 'received'; // so we don't have to reload the page
                });
            };

        return {
            toggleAnonymous: userVM.toggleAnonymous,
            displayModal,
            contribution: args.contribution,
            toggleDelivery
        };
    },
    view: function(ctrl) {
        const contribution = ctrl.contribution,
            contactModalC = [ownerMessageContent, m.prop({
                id: contribution.project_user_id,
                name: contribution.project_owner_name,
                project_id: contribution.project_id
            })],
            finishedAt = contribution.survey && contribution.survey.finished_at,
            answeredAt = contribution.survey_answered_at;

        return (!_.isEmpty(contribution) ? m('div',
            (ctrl.displayModal() ? m.component(modalBox, {
                displayModal: ctrl.displayModal,
                content: contactModalC
            }) : ''), [
                m('.card.w-row', [
                    m('.u-marginbottom-20.w-col.w-col-3', [
                        m('.u-marginbottom-10.w-row', [
                            m('.u-marginbottom-10.w-col.w-col-4',
                                m(`a.w-inline-block[href='/${contribution.permalink}']`,
                                    m(`img.thumb-project.u-radius[alt='${contribution.project_name}'][src='${contribution.project_image}'][width='50']`)
                                )
                            ),
                            m('.w-col.w-col-8',
                                m('.fontsize-small.fontweight-semibold.lineheight-tight',
                                    m(`a.link-hidden[href='/${contribution.permalink}']`,
                                        contribution.project_name
                                    )
                                )
                            )
                        ]),
                        m("a.btn.btn-edit.btn-inline.btn-small.w-button[href='javascript:void(0);']", {
                            onclick: () => {
                                ctrl.displayModal.toggle();
                            }
                        },
                            window.I18n.t('contact_author', contributionScope())
                        )
                    ]),
                    m('.u-marginbottom-20.w-col.w-col-3', [
                        m('.fontsize-base.fontweight-semibold.lineheight-looser',
                            `R$ ${contribution.value}`
                        ),
                        m('.w-embed',
                            m('div', [
                                m('.w-hidden-main.w-hidden-medium.fontsize-smallest.fontweight-semibold',
                                    window.I18n.t('status', contributionScope())
                                ),
                                m('.fontsize-smaller.fontweight-semibold', [
                                    m('.lineheight-tighter'),
                                    m(`span.fa.fa-circle.fontsize-smallest.${contribution.state === 'paid' ? 'text-success' : contribution.state === 'pending' ? 'text-waiting' : 'text-error'}`,
                                        m.trust('&nbsp;')
                                    ),
                                    window.I18n.t(`${contribution.payment_method.toLowerCase()}.${contribution.state}`, I18nScope({
                                        date: h.momentify(contribution[`${contribution.state}_at`])
                                    }))
                                ]),
                                m('.fontsize-smallest',
                                    (contribution.installments > 1 ? (`${contribution.installments} x R$ ${contribution.installment_value} `) : ''),
                                    (contribution.payment_method === 'BoletoBancario' ? 'Boleto Bancário' : 'Cartão de Crédito')
                                ),
                                (contributionVM.canShowReceipt(contribution) ?
                                    m(`a.alt-link.u-margintop-10[href='/projects/${contribution.project_id}/contributions/${contribution.contribution_id}/receipt'][target='__blank']`,
                                        window.I18n.t('show_receipt', contributionScope())
                                    ) : ''),

                                (contribution.gateway_data && contributionVM.canShowSlip(contribution) ?
                                    m(`a.alt-link.u-margintop-10[href='${contribution.gateway_data.boleto_url}'][target='__blank']`,
                                        window.I18n.t('print_slip', contributionScope())
                                    ) : ''),

                                (contribution.gateway_data && contributionVM.canGenerateSlip(contribution) ?
                                    m(`a.alt-link.u-margintop-10[href='/projects/${contribution.project_id}/contributions/${contribution.contribution_id}/second_slip'][target='__blank']`,
                                        window.I18n.t('slip_copy', contributionScope())
                                    ) : ''),
                                m('.w-checkbox.fontsize-smallest.fontcolor-secondary.u-margintop-10', [
                                    m(`input.w-checkbox-input[id='anonymous'][name='anonymous'][type='checkbox']${contribution.anonymous ? '[checked=\'checked\']' : ''}[value='1']`, {
                                        onclick: () => ctrl.toggleAnonymous(contribution.project_id, contribution)
                                    }),
                                    m('label.w-form-label',
                                        window.I18n.t('anonymous', contributionScope())
                                    )
                                ])
                            ])
                        )
                    ]),
                    m('.u-marginbottom-20.w-col.w-col-3', [
                        (contribution.reward_id ? [m('.fontsize-smallest.fontweight-semibold',
                            contribution.reward_title
                        ), m('p.fontcolor-secondary.fontsize-smallest', m.trust(h.simpleFormat(
                            `${contribution.reward_description.substring(0, 90)} (...)`<commit_msg>should show user total payment with installments more than 1 because the installment taxes #158377826<commit_after>import m from 'mithril';
import _ from 'underscore';
import h from '../h';
import contributionVM from '../vms/contribution-vm';
import ownerMessageContent from '../c/owner-message-content';
import modalBox from '../c/modal-box';
import userVM from '../vms/user-vm';
import rewardReceiver from './reward-receiver';
import paymentVM from '../vms/payment-vm';

const I18nScope = _.partial(h.i18nScope, 'payment.state');
const contributionScope = _.partial(h.i18nScope, 'users.contribution_row');

const userContributedBox = {
    controller: function(args) {
        const displayModal = h.toggleProp(false, true),
            toggleDelivery = (projectId, contribution) => {
                userVM.toggleDelivery(projectId, contribution).then(() => {
                    const lastStatus = contribution.reward_sent_at ? 'delivered' : 'undelivered';
                    contribution.delivery_status = contribution.delivery_status === 'received' ? lastStatus : 'received'; // so we don't have to reload the page
                });
            },
            installmentTotalAmount = m.prop(Number.parseFloat(args.contribution.installments_total_amount).toFixed(2));

        return {
            toggleAnonymous: userVM.toggleAnonymous,
            displayModal,
            contribution: args.contribution,
            toggleDelivery,
            installmentTotalAmount
        };
    },
    view: function(ctrl) {
        const contribution = ctrl.contribution,
            contactModalC = [ownerMessageContent, m.prop({
                id: contribution.project_user_id,
                name: contribution.project_owner_name,
                project_id: contribution.project_id
            })],
            finishedAt = contribution.survey && contribution.survey.finished_at,
            answeredAt = contribution.survey_answered_at;

            console.log('contribution', contribution);

        return (!_.isEmpty(contribution) ? m('div',
            (ctrl.displayModal() ? m.component(modalBox, {
                displayModal: ctrl.displayModal,
                content: contactModalC
            }) : ''), [
                m('.card.w-row', [
                    m('.u-marginbottom-20.w-col.w-col-3', [
                        m('.u-marginbottom-10.w-row', [
                            m('.u-marginbottom-10.w-col.w-col-4',
                                m(`a.w-inline-block[href='/${contribution.permalink}']`,
                                    m(`img.thumb-project.u-radius[alt='${contribution.project_name}'][src='${contribution.project_image}'][width='50']`)
                                )
                            ),
                            m('.w-col.w-col-8',
                                m('.fontsize-small.fontweight-semibold.lineheight-tight',
                                    m(`a.link-hidden[href='/${contribution.permalink}']`,
                                        contribution.project_name
                                    )
                                )
                            )
                        ]),
                        m("a.btn.btn-edit.btn-inline.btn-small.w-button[href='javascript:void(0);']", {
                            onclick: () => {
                                ctrl.displayModal.toggle();
                            }
                        },
                            window.I18n.t('contact_author', contributionScope())
                        )
                    ]),
                    m('.u-marginbottom-20.w-col.w-col-3', [
                        m('.fontsize-base.fontweight-semibold.lineheight-looser',
                            `R$ ${contribution.value}`
                        ),
                        m('.w-embed',
                            m('div', [
                                m('.w-hidden-main.w-hidden-medium.fontsize-smallest.fontweight-semibold',
                                    window.I18n.t('status', contributionScope())
                                ),
                                m('.fontsize-smaller.fontweight-semibold', [
                                    m('.lineheight-tighter'),
                                    m(`span.fa.fa-circle.fontsize-smallest.${contribution.state === 'paid' ? 'text-success' : contribution.state === 'pending' ? 'text-waiting' : 'text-error'}`,
                                        m.trust('&nbsp;')
                                    ),
                                    window.I18n.t(`${contribution.payment_method.toLowerCase()}.${contribution.state}`, I18nScope({
                                        date: h.momentify(contribution[`${contribution.state}_at`])
                                    }))
                                ]),
                                m('.fontsize-smallest',
                                    (contribution.installments > 1 ? (`${contribution.installments} x R$ ${ Number.parseFloat(contribution.installment_value).toFixed(2) } `) : ''),
                                    (contribution.payment_method === 'BoletoBancario' ? 'Boleto Bancário' : 'Cartão de Crédito')
                                ),
                                (
                                    contribution.installments > 1 ? 
                                        m(".fontsize-smallest.fontweight-semibold.u-marginbottom-10", 
                                            I18n.t('total_amount', contributionScope({
                                                total_amount: ctrl.installmentTotalAmount()
                                            }))
                                        ) : ''
                                ),
                                (contributionVM.canShowReceipt(contribution) ?
                                    m(`a.alt-link.u-margintop-10[href='/projects/${contribution.project_id}/contributions/${contribution.contribution_id}/receipt'][target='__blank']`,
                                        window.I18n.t('show_receipt', contributionScope())
                                    ) : ''),

                                (contribution.gateway_data && contributionVM.canShowSlip(contribution) ?
                                    m(`a.alt-link.u-margintop-10[href='${contribution.gateway_data.boleto_url}'][target='__blank']`,
                                        window.I18n.t('print_slip', contributionScope())
                                    ) : ''),

                                (contribution.gateway_data && contributionVM.canGenerateSlip(contribution) ?
                                    m(`a.alt-link.u-margintop-10[href='/projects/${contribution.project_id}/contributions/${contribution.contribution_id}/second_slip'][target='__blank']`,
                                        window.I18n.t('slip_copy', contributionScope())
                                    ) : ''),
                                m('.w-checkbox.fontsize-smallest.fontcolor-secondary.u-margintop-10', [
                                    m(`input.w-checkbox-input[id='anonymous'][name='anonymous'][type='checkbox']${contribution.anonymous ? '[checked=\'checked\']' : ''}[value='1']`, {
                                        onclick: () => ctrl.toggleAnonymous(contribution.project_id, contribution)
                                    }),
                                    m('label.w-form-label',
                                        window.I18n.t('anonymous', contributionScope())
                                    )
                                ])
                            ])
                        )
                    ]),
                    m('.u-marginbottom-20.w-col.w-col-3', [
                        (contribution.reward_id ? [m('.fontsize-smallest.fontweight-semibold',
                            contribution.reward_title
                        ), m('p.fontcolor-secondary.fontsize-smallest', m.trust(h.simpleFormat(
                            `${contribution.reward_description.substring(0, 90)} (...)`
{'fraction_non_alphanumeric': 0.12460753532182103, 'fraction_numerical': 0.00804552590266876, 'mean_word_length': 1.2254730713245998, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 68, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5276926', 'n_tokens_mistral': 3907, 'n_tokens_neox': 3621, 'n_words': 408}