[{include file="headitem.tpl" title="YS_GIFTCERT__ADMIN_SETTINGS"|oxmultilangassign }]

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
      integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet"
      href="[{$oViewConf->getModuleUrl('ys_giftcert', 'out/css/fontawesome/css/fontawesome-all.min.css')}]">
<link rel="stylesheet" href="[{$oViewConf->getModuleUrl('ys_giftcert', 'out/css/ys_giftcert.css')}]">
<script type="text/javascript" src="[{$oViewConf->getModuleUrl('ys_giftcert', 'out/js/jquery-3.3.1.min.js')}]"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
<script type="text/javascript" src="[{$oViewConf->getModuleUrl('ys_giftcert', 'out/js/ys_giftcert.js')}]"></script>

[{*<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>*}]

<div class="ys_giftcertlog_header">
    <strong>[{ oxmultilang ident="YS_GIFTCERT_LOG_TITLE" }]</strong>
</div>
<div class="ys_giftcertlog_form ys_giftcertlog_info">
    [{ oxmultilang ident="YS_GIFTCERT_LOG_COUNT_OF_GIFTCERTS" }] [{$oView->getGiftcertCount()}]<br>
    [{ oxmultilang ident="YS_GIFTCERT_LOG_SUMMARY" }] [{oxprice price=$oView->getGiftcertSummary()}]<br>
    [{ oxmultilang ident="YS_GIFTCERT_LOG_OPEN_CREDITS" }] [{oxprice price=$oView->getGiftcertOpenCredits()}]
</div>

<div class="ys_giftcertlog_export_buttons ys_giftcertlog_form">
    <div class="ys_giftcertlog_export">
        <form name="giftcert-export" id="giftcert-export"  action="[{ $oViewConf->getSelfLink() }]" method="post">
            [{$oViewConf->getHiddenSid()}]
            <input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
            <input type="hidden" name="fnc" value="exportOpenGiftcerts">
            <input type="submit" value="[{ oxmultilang ident="YS_GIFTCERT_LOG_CSV_EXPORT" }]">
        </form>
    </div>

    <div class="ys_giftcertlog_export">
        <form name="giftcert-export" id="giftcert-export"  action="[{ $oViewConf->getSelfLink() }]" method="post">
            [{$oViewConf->getHiddenSid()}]
            <input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
            <input type="hidden" name="fnc" value="exportUsedGiftcerts">
            <input type="submit" value="[{ oxmultilang ident="YS_GIFTCERT_LOG_CSV_USED_EXPORT" }]">
        </form>
    </div>

    <div class="ys_giftcertlog_export">
        <form name="giftcert-user-export" id="giftcert-user-export"  action="[{ $oViewConf->getSelfLink() }]" method="post">
            [{$oViewConf->getHiddenSid()}]
            <input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
            <input type="hidden" name="fnc" value="exportUserGiftcerts">
            <input type="submit" value="[{ oxmultilang ident="YS_GIFTCERT_LOG_CSV_USER_EXPORT" }]">
        </form>
    </div>
</div>
<div class="clearfix"></div>

<div id="ys_giftcerts_successbox"
     class="alert alert-success">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_SUCCESS"}]
</div>

<div class="ys_giftcertlog_export_buttons ys_giftcertlog_form" style="display: none;" id="ys_giftcerts_export">
    <div class="ys_giftcertlog_export">
        <form name="giftcert-user-export" id="giftcert-user-export"  action="[{ $oViewConf->getSelfLink() }]" method="post">
            [{$oViewConf->getHiddenSid()}]
            <input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
            <input type="hidden" name="fnc" value="exportGeneratedGiftcerts">
            <input type="submit" value="[{ oxmultilang ident="YS_GIFTCERT_LOG_CSV_EXPORT_GENERATED" }]">
        </form>
    </div>
</div>

<div id="ys_giftcerts_failbox" class="alert alert-danger">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_FAILURE"}]</div>

<span class="ys_giftcertlog_action" data-toggle="tooltip" data-placement="bottom"
      title="[{oxmultilang ident="YS_GIFTCERTLOG_ADD_CERT_TOOLTIP"}]"><i class="fas fa-plus-circle fa-2x"
                                                                         data-toggle="modal"
                                                                         data-target="#addGiftCertModal"></i></span>

<ul class="giftcerts">
    <li class="header">
        <span>Gutscheincode</span><span>Gekauft</span><span>Ursprünglicher Wert</span><span>Restwert</span><span>Aktionen</span>
    </li>
    [{foreach from=$oView->getGiftcertList() item="giftcert"}]
        <li>
            <span>[{$giftcert->ysgiftcert__ysgiftcertnr->value}]</span><span>[{if $giftcert->ysgiftcert__ysdatepurchased->value == "0000-00-00 00:00:00"}]-[{else}][{$giftcert->ysgiftcert__ysdatepurchased->value|date_format:"%d.%m.%Y %H:%M"}][{/if}]</span><span>[{oxprice price=$giftcert->ysgiftcert__ysinitialdiscount->value}]</span><span>[{oxprice price=$giftcert->ysgiftcert__ysrestdiscount->value}]</span><span>
                <span class="ys_giftcertlog_action" data-toggle="tooltip" data-placement="bottom"
                      title="[{oxmultilang ident="YS_GIFTCERTLOG_MORE_INFO_TOOLTIP"}]"><i class="fas fa-info showLog"
                                                                                          data-toggle="modal"
                                                                                          data-target="#additionalInfoModal"></i></span>
                [{if $giftcert->ysgiftcert__ysrestdiscount->value > 0}]<span class="ys_giftcertlog_action"
                                                                             data-toggle="tooltip"
                                                                             data-placement="bottom"
                                                                             title="[{oxmultilang ident="YS_GIFTCERTLOG_REDEEM_ACTION_TOOLTIP"}]">
                    <i class="fas fa-donate showRedeemForm" data-toggle="modal" data-target="#redeemModal"
                       data-giftcertcode="[{$giftcert->ysgiftcert__ysgiftcertnr->value}]"
                       data-giftcertvalue="[{$giftcert->ysgiftcert__ysrestdiscount->value|replace:'.':','}]"></i>
                    </span>[{/if}]
                <span class="ys_giftcertlog_action" data-toggle="tooltip" data-placement="bottom"
                      title="[{oxmultilang ident="YS_GIFTCERTLOG_DELETE_TOOLTIP"}]"><i class="fas fa-minus-circle showDeleteForm"
                                                                                          data-toggle="modal"
                                                                                          data-giftcertcodedelete="[{$giftcert->ysgiftcert__ysgiftcertnr->value}]"
                                                                                          data-target="#deleteModal"></i></span>
            </span>
            <div class="giftcertlogs">
                [{if $giftcert->getGiftcertLogList()|@count > 0}]
                    [{foreach from=$giftcert->getGiftcertLogList() item="giftcertlog"}]
                        <div class="giftcertlogs_entry row">
                            <div class="col-6">[{$giftcertlog->ysgiftcertlog__ysdateused->value|date_format:"%d.%m.%Y %H:%M"}]</div>
                            <div class="col-6">
                                BestNr. [{$oView->getOrderStringById($giftcertlog->ysgiftcertlog__ysorderid->value)}]</div>
                            <div class="col-6">
                                <b>Eingelöst: [{oxprice price=$giftcertlog->ysgiftcertlog__ysamountused->value}]</b>
                            </div>
                            <div class="col-6">
                                Kundennr. [{$oView->getCustomerStringById($giftcertlog->ysgiftcertlog__ysuserid->value)}]</div>
                        </div>
                    [{/foreach}]
                [{else}]
                    <div class="giftcertlogs_entry row">
                        <div class="col-12">
                            [{oxmultilang ident="YS_GIFTCERTLOG_NOT_REDEEMED_YET"}]
                        </div>
                    </div>
                [{/if}]
                <div class="giftcertlogs_entry_sum row">
                    <div class="col-12"><b>Restwert: [{oxprice price=$giftcert->ysgiftcert__ysrestdiscount->value}]</b>
                    </div>
                </div>
            </div>
        </li>
    [{/foreach}]
</ul>


<!-- Redeem Modal -->
<div class="modal fade" id="redeemModal" tabindex="-1" role="dialog" aria-labelledby="redeemModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"
                    id="redeemModalLabel">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_TITLE"}]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form>
                    [{$oViewConf->getHiddenSid()}]
                    <input type="hidden" class="giftcertcode" name="giftcertcode" value="">
                    <div class="form-group">
                        <label for="modalRedeemValue">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_GIFTCERTID_LABEL"}]</label>
                        <input type="text" readonly class="form-control-plaintext giftcertcode" id="giftcertcode"
                               value="">
                    </div>
                    [{if $oView->canBeRedeemedPartly()}]
                        <div class="form-group modalRedeemValueGroup">
                            <label for="modalRedeemValue">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_VALUE_LABEL"}]</label>
                            <input type="text" class="form-control" id="modalRedeemValue">
                        </div>
                    [{/if}]
                    [{if $oView->shouldRedeemToPool()}]
                        <div class="alert alert-warning">[{oxmultilang ident="YS_REDDEM_GIFTCERT_MODAL_TO_POOL_WARNING"}]</div>
                    [{/if}]
                    [{if $oView->canBeRedeemedPartly()}]
                        <div class="form-group">
                            <div class="custom-control custom-switch">
                                <input type="checkbox" class="custom-control-input" id="customSwitch1">
                                <label class="custom-control-label"
                                       for="customSwitch1">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_FULLY_REDEEM"}]</label>
                            </div>
                        </div>
                    [{/if}]
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary"
                        data-dismiss="modal">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_CANCEL"}]</button>
                <button type="button"
                        class="btn btn-primary">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_SUBMIT"}]</button>
            </div>
        </div>
    </div>
</div>


<!-- Additional Info Modal -->
<div class="modal fade" id="additionalInfoModal" tabindex="-1" role="dialog" aria-labelledby="additionalInfoModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"
                    id="additionalInfoModalLabel">[{oxmultilang ident="YS_REDEEM_GIFTCERT_REDEEMED_MODAL_TITLE"}]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary"
                        data-dismiss="modal">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_CANCEL"}]</button>
            </div>
        </div>
    </div>
</div>

<!-- Delete Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"
                    id="deleteModalLabel">[{oxmultilang ident="YS_DELETE_GIFTCERT_MODAL_TITLE"}]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form>
                    [{$oViewConf->getHiddenSid()}]
                    <input type="hidden" class="giftcertcodedelete" name="giftcertcodedelete" value="">
                    <div class="form-group">
                        <label for="modalRedeemValue">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_GIFTCERTID_LABEL"}]</label>
                        <input type="text" readonly class="form-control-plaintext giftcertcodedelete" id="giftcertcodedelete"
                               value="">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary"
                        data-dismiss="modal">[{oxmultilang ident="YS_ADD_GIFTCERT_MODAL_CANCEL"}]</button>
                <button type="button"
                        class="btn btn-danger">[{oxmultilang ident="YS_DELETE_GIFTCERT_MODAL_SUBMIT"}]</button>
            </div>
        </div>
    </div>
</div>

<!-- Add gift certificate manually modal-->
<div class="modal fade" id="addGiftCertModal" tabindex="-1" role="dialog" aria-labelledby="addGiftCertModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"
                    id="addGiftCertModalLabel">[{oxmultilang ident="YS_ADD_GIFTCERT_MODAL_TITLE"}]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form>
                    [{$oViewConf->getHiddenSid()}]

                    <div class="form-group">
                        <label for="modalAddValue">[{oxmultilang ident="YS_ADD_GIFTCERT_MODAL_VALUE_LABEL"}]</label>
                        <input type="number" step="0.01" class="form-control" id="modalAddValue">
                    </div>
                    <div class="form-group">
                        <label for="modalAddQuantity">[{oxmultilang ident="YS_ADD_GIFTCERT_MODAL_QUANTITY_LABEL"}]</label>
                        <input type="number" value="1" step="1" class="form-control" id="modalAddQuantity">
                    </div>
                    <div class="form-group">
                        <label for="modalAddDate">[{oxmultilang ident="YS_ADD_GIFTCERT_MODAL_DATE_LABEL"}]</label>
                        <input type="datetime-local" class="form-control" value="[{$smarty.now|date_format:"%Y-%m-%d"}]T00:00"  id="modalAddDate">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary"
                        data-dismiss="modal">[{oxmultilang ident="YS_ADD_GIFTCERT_MODAL_CANCEL"}]</button>
                <button type="button"
                        class="btn btn-primary">[{oxmultilang ident="YS_ADD_GIFTCERT_MODAL_SUBMIT"}]</button>
            </div>
        </div>
    </div>
</div>