{extends file="admin-layout.tpl"}

{block name="main-content"}
<div class="clearfix">
    <ul class="breadcrumb pull-left">
        <li>
            <a href="{url path='/admin/home'}">{intl l="Home"}</a>
        </li>
        <li>
            <a href="{url path='/admin/modules'}">{intl l="Modules"}</a>
        </li>
        <li>
            <a href="{url path='/admin/module/PayPal'}">{intl l="PayPal"}</a>
        </li>
        <li>
            <a href="{url path='/admin/module/paypal/configure/planified'}">{intl l="Planified payment" d="paypal.bo.default"}</a>
        </li>
    </ul>
</div>
<div class="row">
    <div class="col-md-12">
        <div class="general-block-decorator">

            {include file="paypal/menu/menu.html" selectedMenu="planifiedPayment"}

            <div class="tab-content">
                <!-- Countries managing tab -->
                <div class="tab-pane active form-container">
                    <div class="row">
                        <div class="col-md-12 general-block-decorator">
                            <h3>
                                <span class="label label-primary">1</span>
                                {intl l="Planified payment configuration" d="paypal.bo.default"}
                            </h3>

                            <div class="col-md-12 alert alert-info">
                                <div class="col-md-8">
                                    <h4 class="text-uppercase">
                                        <span class="glyphicon glyphicon-info-sign"></span>&nbsp;{intl l="Help" d="paypal.bo.default"}&nbsp;:
                                    </h4>
                                    <div class="tips">
                                        {intl l="This feature uses PayPal's Billing Plan and Agreement. It allows debiting a client recursively directly from PayPal." d="paypal.bo.default"}
                                        <br />{intl l="These planned payments will appear in step 4 of the purchase tunnel when selecting the payment method." d="paypal.bo.default"}
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="tips__img">
                                        <img src="{image file='assets/paypal_agreement.jpeg' source="PayPal"}" alt="Payment configuration" class="img-responsive" />
                                    </div>
                                </div>
                            </div>

                            <div class="form-container">
                                <div class="row">
                                    <div class="col-md-12">
                                        <table class="table table-striped table-condensed">
                                            <caption class="clearfix">
                                                {intl l="List of planified payments" d="paypal.bo.default"}
                                                <span class="pull-right">
                                                  <button class="btn btn-primary" title="{intl l='Add a planified payment' d='paypal.bo.default'}" href="#creation_dialog" data-toggle="modal">
                                                      <span class="glyphicon glyphicon-plus-sign"></span> {intl l='Add a planified payment' d='paypal.bo.default'}
                                                  </button>
                                                </span>
                                            </caption>

                                            <thead>
                                            <tr>
                                                <th>
                                                    {intl l='Title' d="paypal.bo.default"}
                                                </th>

                                                <th>
                                                    {intl l='Details' d="paypal.bo.default"}
                                                </th>

                                                <th class="actions"></th>
                                            </tr>
                                            </thead>

                                            <tbody>
                                            {loop name="paypal_planified_payment" type="paypal_planified_payment" backend_context=true order=$order}
                                            <tr>
                                                <td>
                                                    <strong>{$planifiedPayment->getTitle()}&nbsp;;</strong><br />
                                                    {$planifiedPayment->getDescription()}
                                                </td>

                                                <td>
                                                    <strong>{intl l='Frequency interval' d="paypal.bo.default"}&nbsp;:&nbsp;</strong>{$planifiedPayment->getFrequencyInterval()}<br />
                                                    <strong>{intl l='Frequency' d="paypal.bo.default"}&nbsp;:&nbsp;</strong>{$planifiedPayment->getFrequency()}<br />
                                                    <strong>{intl l='Cycle' d="paypal.bo.default"}&nbsp;:&nbsp;</strong>{$planifiedPayment->getCycle()}<br />
                                                    <strong>{intl l='Min amount' d="paypal.bo.default"}&nbsp;:&nbsp;</strong>{if $planifiedPayment->getMinAmount() > 0}{format_money number=$planifiedPayment->getMinAmount()}{else}{intl l='None' d="paypal.bo.default"}{/if}<br />
                                                    <strong>{intl l='Max amount' d="paypal.bo.default"}&nbsp;:&nbsp;</strong>{if $planifiedPayment->getMaxAmount() > 0}{format_money number=$planifiedPayment->getMaxAmount()}{else}{intl l='None' d="paypal.bo.default"}{/if}<br />
                                                </td>

                                                <td class="actions">
                                                    <div class="btn-group btn-group-sm" >

                                                        <a class="btn btn-primary" title="{intl l='Edit this planified payment' d='paypal.bo.default'}" href="{url path="/admin/module/paypal/configure/planified/%id" id=$planifiedPayment->getId()}">
                                                        <span class="glyphicon glyphicon-edit"></span>
                                                        </a>

                                                        <a class="btn btn-danger planified-payment-delete" title="{intl l='Delete this planified payment' d='paypal.bo.default'}" href="#delete_dialog" data-id="{$planifiedPayment->getId()}" data-toggle="modal">
                                                            <span class="glyphicon glyphicon-trash"></span>
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                            {/loop}
                                            {elseloop rel="paypal_planified_payment"}
                                            <tr>
                                                <td colspan="100">
                                                    <div class="alert alert-info">
                                                        {intl l="No planified payment has been created yet. Click the + button to create one." d="paypal.bo.default"}
                                                    </div>
                                                </td>
                                            </tr>
                                            {/elseloop}
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

    {* Adding a new planified payment *}
    {form name="paypal_planified_payment_create_form"}
    
        {* Capture the dialog body, to pass it to the generic dialog *}
        {capture "creation_dialog"}
            {form_hidden_fields}

            {include file = "paypal/form/create-or-update-planified-payment-form.html"}

            {render_form_field field="success_url" value={url path='/admin/module/paypal/configure/planified'}}
        {/capture}

        {include
            file = "includes/generic-create-dialog.html"

            dialog_id    = "creation_dialog"
            dialog_title = {intl l="Create a new planified payment" d="paypal.bo.default"}
            dialog_body  = {$smarty.capture.creation_dialog nofilter}

            dialog_ok_label     = {intl l="Create this planified payment" d="paypal.bo.default"}

            form_action        = {url path='/admin/module/paypal/configure/planified/create'}
            form_enctype       = {form_enctype}
            form_error_message = $form_error_message
        }
    {/form}

    {* Delete confirmation dialog *}
    {capture "delete_dialog"}
        <input type="hidden" name="planifiedPaymentId" id="planifiedPaymentId" value="" />
    {/capture}

    {include
        file = "includes/generic-confirm-dialog.html"

        dialog_id       = "delete_dialog"
        dialog_title    = {intl l="Delete planified payment" d="paypal.bo.default"}
        dialog_message  = {intl l="Do you really want to delete this planified payment ?" d="paypal.bo.default"}

        form_action         = {token_url path='/admin/module/paypal/configure/planified/create/delete'}
        form_content        = {$smarty.capture.delete_dialog nofilter}
    }
{/block}

{block name="javascript-initialization"}
<script>
    $(function() {
        // Set proper planified ID in delete from
        $('a.planified-payment-delete').click(function(ev) {
            $('#planifiedPaymentId').val($(this).data('id'));
        });
    });
</script>
{/block}