<?xml version="1.0" encoding="UTF-8"?>

<templates xml:space="preserve">

<div t-name="reconciliation" class="o_reconciliation">
    <div class="o_form_view">
        <div class="o_form_sheet_bg">
            <div class="o_form_sheet"/>
        </div>
    </div>
</div>

<t t-name="reconciliation.statement">
    <div t-if="widget._initialState.valuemax">
        <div>
            <t t-if="widget._initialState.bank_statement_id">
                <h1 class="statement_name editable" title="Click to Rename" />
            </t>
            <t t-else="">
                <h1 class="statement_name" />
            </t>
            <h1 class="statement_name_edition" style="display: none;"/>
            <div class="progress progress-striped">
                <div class="progress-text">
                    <span class="valuenow"><t t-esc="widget._initialState.valuenow"/></span> / <span class="valuemax"><t t-esc="widget._initialState.valuemax"/></span>
                </div>
                <div aria-valuemin="0" t-att-aria-valuenow="widget._initialState.valuenow" class="progress-bar" role="progressbar" style="width: 0%;" t-att-aria-valuemax="widget._initialState.valuemax"></div>
            </div>
            <div class="notification_area"/>
        </div>
        <div class="o_reconciliation_lines"/>
        <div t-if="widget._initialState.valuemax &gt; widget._initialState.defaultDisplayQty">
            <button class="btn btn-secondary js_load_more">Load more</button>
        </div>
    </div>
    <div t-else="" class="o_view_noreconciliation">
        <p>Nothing to do!</p>
        <p>This page displays all the bank transactions that are to be reconciled and provides with a neat interface to do so.</p>
    </div>
</t>

<t t-name="reconciliation.manual.statement" t-extend="reconciliation.statement">
    <t t-jquery="div:first" t-operation="attributes">
        <attribute name="class">o_manual_statement</attribute>
    </t>
    <t t-jquery=".o_view_noreconciliation p" t-operation="replace"></t>
    <t t-jquery=".o_view_noreconciliation" t-operation="append">
        <p><b>Good Job!</b> There is nothing to reconcile.</p>
        <p>All invoices and payments have been matched, your accounts' balances are clean.</p>
    </t>
</t>

<div t-name="reconciliation.done" class="done_message">
    <h2>Congrats, you're all done!</h2>
    <p>You reconciled <strong><t t-esc="number"/></strong> transactions in <strong><t t-esc="duration"/></strong>.
        <t t-if="number > 1">
            <br/>That's on average <t t-esc="timePerTransaction"/> seconds per transaction.
        </t>
    </p>
    <t t-if="context &amp;&amp; context.active_model">
        <p t-if="context['active_model'] === 'account.journal' || context['active_model'] === 'account.bank.statement'" class="actions_buttons">
            <t t-if="context.journal_id">
                <button class="button_back_to_statement btn btn-secondary" t-att-data_journal_id='context.journal_id'>Go to bank statement(s)</button>
            </t>
            <t t-if="context['active_model'] === 'account.bank.statement'">
                <button class="button_close_statement btn btn-primary" style="display: inline-block;">Close statement</button>
            </t>
        </p>
    </t>
</div>

<t t-name="reconciliation.line">
    <t t-set="state" t-value="widget._initialState"/>
    <div class="o_reconciliation_line" t-att-data-mode="state.mode">
        <table class="accounting_view">
            <caption style="caption-side: top;">
                <div class="float-right o_buttons">
                    <button t-attf-class="o_validate btn btn-secondary #{!state.balance.type ? '' : 'd-none'}">Validate</button>
                    <button t-attf-class="o_reconcile btn btn-primary #{state.balance.type &gt; 0 ? '' : 'd-none'}">Reconcile</button>
                    <span t-attf-class="o_no_valid text-danger #{state.balance.type &lt; 0 ? '' : 'd-none'}">Select a partner or choose a counterpart</span>
                </div>
            </caption>
            <thead>
                <tr>
                    <td class="cell_action"><span class="toggle_match fa fa-cog" aria-label="Settings" role="img" title="Settings"></span></td>
                    <td class="cell_account_code"><t t-esc="state.st_line.account_code"/></td>
                    <td class="cell_due_date"><t t-esc="state.st_line.date"/></td>
                    <td class="cell_label"><t t-if="state.st_line.name" t-esc="state.st_line.name"/> <t t-if="state.st_line.amount_currency_str"> (<t t-esc="state.st_line.amount_currency_str"/>)</t></td>
                    <td class="cell_left"><t t-if="state.st_line.amount &gt; 0"><t t-raw="state.st_line.amount_str"/></t></td>
                    <td class="cell_right"><t t-if="state.st_line.amount &lt; 0"><t t-raw="state.st_line.amount_str"/></t></td>
                    <td class="cell_info_popover"></td>
                </tr>
            </thead>
            <tbody>
                <t t-foreach="state.reconciliation_proposition" t-as="line"><t t-call="reconciliation.line.mv_line"/></t>
            </tbody>
            <tfoot>
                <t t-call="reconciliation.line.balance"/>
            </tfoot>
        </table>
        <div class="match">
            <t t-call="reconciliation.line.match"/>
        </div>
        <div class="create"></div>
    </div>
</t>

<t t-name="reconciliation.manual.line" t-extend="reconciliation.line">
    <t t-jquery=".o_buttons" t-operation="replace">
        <div class="float-right o_buttons">
            <button t-attf-class="o_validate btn btn-secondary #{!state.balance.type ? '' : 'd-none'}">Reconcile</button>
            <button t-attf-class="o_reconcile btn btn-primary #{state.balance.type &gt; 0 ? '' : 'd-none'}">Reconcile</button>
            <button t-attf-class="o_no_valid btn btn-secondary #{state.balance.type &lt; 0 ? '' : 'd-none'}">Skip</button>
        </div>
    </t>
    <t t-jquery=".accounting_view tbody" t-operation="append">
        <t t-if='!_.filter(state.reconciliation_proposition, {"display": true}).length'>
            <t t-set="line" t-value='{}'/>
            <t t-call="reconciliation.line.mv_line"/>
        </t>
    </t>
    <t t-jquery=".accounting_view thead tr" t-operation="replace">
        <tr>
            <td class="cell_action"><span class="toggle_match fa fa-cog" aria-label="Settings" role="img" title="Settings"></span></td>
            <td colspan="3"><span/><span t-if="state.last_time_entries_checked">Last Reconciliation: <t t-esc="state.last_time_entries_checked"/></span></td>
            <td colspan="2"><t t-esc="state.st_line.account_code"/></td>
            <td class="cell_info_popover"></td>
        </tr>
    </t>
</t>

<t t-name="reconciliation.line.balance">
    <tr t-if="state.balance.amount_currency &amp;&amp; !(state.reconciliation_proposition[0] || {}).partial_reconcile">
        <td class="cell_action"><span role="img" class="toggle_create fa fa-play" aria-label="Run" title="Run"></span></td>
        <td class="cell_account_code"><t t-esc="state.balance.account_code"/></td>
        <td class="cell_due_date"></td>
        <td class="cell_label"><t t-if="state.st_line.partner_id">Open balance</t><t t-else="">Choose counterpart or Create Write-off</t></td>
        <td class="cell_left"><t t-if="state.balance.amount_currency &lt; 0"><span role="img" t-if="state.balance.amount_currency_str" t-attf-class="o_multi_currency o_multi_currency_color_#{state.balance.currency_id%8} line_info_button fa fa-money" t-att-data-content="state.balance.amount_currency_str" t-att-aria-label="state.balance.amount_currency_str" t-att-title="state.balance.amount_currency_str"/><t t-raw="state.balance.amount_str"/></t></td>
        <td class="cell_right"><t t-if="state.balance.amount_currency &gt; 0"><span role="img" t-if="state.balance.amount_currency_str" t-attf-class="o_multi_currency o_multi_currency_color_#{state.balance.currency_id%8} line_info_button fa fa-money" t-att-data-content="state.balance.amount_currency_str" t-att-aria-label="state.balance.amount_currency_str" t-att-title="state.balance.amount_currency_str"/><t t-raw="state.balance.amount_str"/></t></td>
        <td class="cell_info_popover"></td>
    </tr>
</t>


<div t-name="reconciliation.line.match">
    <div class="match_controls">
        <input class="filter" placeholder="Filter..." type="text" value=""/>
    </div>
    <table>
        <tbody>
        </tbody>
    </table>
    <div class="load-more text-center">
        <a href="#">Load more... (<span></span> remaining)</a>
    </div>
</div>


<div t-name="reconciliation.line.create">
    <div class="quick_add">
        <div class="btn-group o_reconcile_models" t-if="state.reconcileModels">
            <t t-foreach="state.reconcileModels" t-as="reconcileModel">
                <button class="btn btn-primary"
                        t-if="reconcileModel.rule_type === 'writeoff_button' &amp;&amp; (reconcileModel.match_journal_ids.length == 0 || reconcileModel.match_journal_ids.includes(state.st_line.journal_id))"
                        t-att-data-reconcile-model-id="reconcileModel.id">
                    <t t-esc="reconcileModel.name"/>
                </button>
            </t>
            <p t-if="!state.reconcileModels.length" style="color: #bbb;">To speed up reconciliation, define <a style="cursor: pointer;" class="reconcile_model_create">reconciliation models</a>.</p>
        </div>
        <div class="dropdown float-right">
            <a data-toggle="dropdown" href="#"><span class="fa fa-cog" role="img" aria-label="Settings"/></a>
            <div class="dropdown-menu dropdown-menu-right" role="menu" aria-label="Presets config">
                <a role="menuitem" class="dropdown-item reconcile_model_create" href="#">Create model</a>
                <a role="menuitem" class="dropdown-item reconcile_model_edit" href="#">Modify models</a>
            </div>
        </div>
    </div>
    <table class="float-left">
        <tr class="create_account_id">
            <td class="o_td_label">Account</td>
            <td class="o_td_field"></td>
        </tr>
        <tr class="create_tax_id">
            <td class="o_td_label">Tax</td>
            <td class="o_td_field"></td>
        </tr>
        <tr class="create_analytic_account_id" groups="analytic.group_analytic_accounting">
            <td class="o_td_label">Analytic Acc.</td>
            <td class="o_td_field"></td>
        </tr>
        <tr class="create_analytic_tag_ids" groups="analytic.group_analytic_tags">
            <td class="o_td_label">Analytic Tags.</td>
            <td class="o_td_field"></td>
        </tr>
    </table>
    <table class="float-right">
        <tbody>
            <tr class="create_journal_id" style="display: none;">
                <td class="o_td_label">Journal</td>
                <td class="o_td_field"></td>
            </tr>
            <tr class="create_label">
                <td class="o_td_label">Label</td>
                <td class="o_td_field"></td>
            </tr>
            <tr class="create_amount">
                <td class="o_td_label">Amount</td>
                <td class="o_td_field"></td>
            </tr>
            <tr class="create_force_tax_included d-none">
                <td class="o_td_label">Tax Included in Price</td>
                <td class="o_td_field"></td>
            </tr>
        </tbody>
    </table>
    <div class="add_line_container">
        <a class="add_line" t-att-style="!state.balance.amout ? 'display: none;' : null"><i class="fa fa-plus-circle"/> Save and New</a>
    </div>
</div>


<t t-name="reconciliation.line.mv_line.triangle">
    <t t-if="line.display_triangle">
        <t t-if="line.partial_reconcile">
            <span t-att-class="'do_partial_reconcile_'+(!line.partial_reconcile)+' line_info_button fa fa-exclamation-triangle'"
                  data-content="Undo the partial reconciliation."/>
        </t>
        <t t-else="">
            <span t-att-class="'do_partial_reconcile_'+(!line.partial_reconcile)+' line_info_button fa fa-exclamation-triangle'"
                  data-content="This move's amount is higher than the transaction's amount. Click to register a partial payment and keep the payment balance open."/>
        </t>
    </t>
</t>


<t t-name="reconciliation.line.mv_line">
    <tr t-if="line.display !== false" t-attf-class="mv_line #{line.already_paid ? ' already_reconciled' : ''} #{line.__invalid ? 'invalid' : ''} #{line.is_tax ? 'is_tax' : ''}" t-att-data-line-id="line.id" t-att-data-selected="selected">
        <td class="cell_action"><span class="fa fa-add-remove" role="img" aria-label="Set" title="Set"/></td>
        <td class="cell_account_code"><t t-esc="line.account_code"/></td>
        <td class="cell_due_date">
            <t t-if="typeof(line.id) != 'number'">
                <span class="badge badge-secondary">New</span>
            </t>
            <t t-else="" t-esc="line.date_maturity === false ? line.date : line.date_maturity"/>
        </td>
        <td class="cell_label">
            <t t-if="line.partner_id &amp;&amp; line.partner_id !== state.st_line.partner_id">
                <t t-if="line.partner_name.length">
                    <t t-esc="line.partner_name"/>:
                </t>
            </t>
            <t t-esc="line.label || line.name"/>
            <t t-if="line.ref &amp;&amp; line.ref.length"> : </t>
            <t t-esc="line.ref"/>
        </td>
        <td class="cell_left">
            <t t-if="line.amount &lt; 0">
                <t t-call="reconciliation.line.mv_line.triangle"/>
                <span t-if="line.amount_currency_str"
                      t-attf-class="o_multi_currency o_multi_currency_color_#{line.currency_id%8} line_info_button fa fa-money"
                      t-att-data-content="line.amount_currency_str"/>
                <t t-raw="line.partial_reconcile ? line.write_off_amount_str : line.amount_str"/>
            </t>
        </td>
        <td class="cell_right">
            <t t-if="line.amount &gt; 0">
                <t t-call="reconciliation.line.mv_line.triangle"/>
                <span t-if="line.amount_currency_str"
                      t-attf-class="o_multi_currency o_multi_currency_color_#{line.currency_id%8} line_info_button fa fa-money"
                      t-att-data-content="line.amount_currency_str"/>
                <t t-raw="line.partial_reconcile ? line.write_off_amount_str : line.amount_str"/>
            </t>
        </td>
        <td class="cell_info_popover"></td>
    </tr>
</t>


<t t-name="reconciliation.line.mv_line.details">
    <table class='details'>
        <tr t-if="line.account_code"><td>Account</td><td><t t-esc="line.account_code"/> <t t-esc="line.account_name"/></td></tr>
        <tr><td>Journal</td><td><t t-esc="line.journal_id[1]"/></td></tr>
        <tr><td>Label</td><td><t t-esc="line.label"/></td></tr>
        <tr t-if="line.ref"><td>Ref</td><td><t t-esc="line.ref"/></td></tr>
        <tr t-if="line.partner_id"><td>Partner</td><td><t t-esc="line.partner_name"/></td></tr>
        <tr><td>Date</td><td><t t-esc="line.date"/></td></tr>
        <tr><td>Due Date</td><td><t t-esc="line.date_maturity === false ? line.date : line.date_maturity"/></td></tr>
        <tr><td>Amount</td><td><t t-raw="line.total_amount_str"/><t t-if="line.total_amount_currency_str"> (<t t-esc="line.total_amount_currency_str"/>)</t></td></tr>
        <tr t-if="line.is_partially_reconciled"><td>Residual</td><td>
            <t t-raw="line.amount_str"/><t t-if="line.amount_currency_str"> (<t t-esc="line.amount_currency_str"/>)</t>
        </td></tr>
        <tr class="one_line_info" t-if='line.already_paid'>
            <td colspan="2">This payment is registered but not reconciled.</td>
        </tr>
    </table>
</t>


<t t-name="reconciliation.line.statement_line.details">
    <table class='details'>
        <tr><td>Date</td><td><t t-esc="state.st_line.date"/></td></tr>
        <tr t-if="state.st_line.partner_name"><td>Partner</td><td><t t-esc="state.st_line.partner_name"/></td></tr>
        <tr t-if="state.st_line.ref"><td>Transaction</td><td><t t-esc="state.st_line.ref"/></td></tr>
        <tr><td>Description</td><td><t t-esc="state.st_line.name"/></td></tr>
        <tr><td>Amount</td><td><t t-raw="state.st_line.amount_str"/><t t-if="state.st_line.amount_currency_str"> (<t t-esc="state.st_line.amount_currency_str"/>)</t></td></tr>
        <tr><td>Account</td><td><t t-esc="state.st_line.account_code"/> <t t-esc="state.st_line.account_name"/></td></tr>
        <tr t-if="state.st_line.note"><td>Note</td><td style="white-space: pre;"><t t-esc="state.st_line.note"/></td></tr>
    </table>
</t>


<t t-name="reconciliation.notification.reconciled">
    <t t-if="details !== undefined">
        <a rel="do_action" href="#" aria-label="External link" title="External link"
            t-att-data-action_name="details.name"
            t-att-data-model="details.model"
            t-att-data-ids="details.ids">
            <t t-esc="nb_reconciled_lines"/>
            statement lines
        </a>
        have been reconciled automatically.
    </t>
</t>


<t t-name="reconciliation.notification.default">
    <t t-esc="message"/>
    <t t-if="details !== undefined">
        <a class="fa fa-external-link" rel="do_action" href="#" aria-label="External link" title="External link"
            t-att-data-action_name="details.name"
            t-att-data-model="details.model"
            t-att-data-ids="details.ids">
        </a>
    </t>
</t>


<t t-name="reconciliation.notification">
    <div t-att-class="'notification alert-dismissible alert alert-' + type" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span title="Close" class="fa fa-times"></span></button>
        <t t-if="template">
            <t t-call="{{template}}"/>
        </t>
        <t t-else="">
            <t t-call="reconciliation.notification.default"/>
        </t>
    </div>
</t>

</templates>
