[{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>


[{*
### PREPARATION FOR BOOTSTRAP 5 Migration ###

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
*}]

<div class="jumbotron">
    <h1 class="display-4">[{ oxmultilang ident="YS_GIFTCERT_LOG_TITLE" }]</h1>
    <div class="row">
        <div class="col-6">
            <p class="lead">Statistik</p>
            <div class="ml-3">
                <strong>[{ oxmultilang ident="YS_GIFTCERT_LOG_COUNT_OF_GIFTCERTS" }]</strong> [{$oView->getGiftcertCount()}]<br>
                <strong>[{ oxmultilang ident="YS_GIFTCERT_LOG_SUMMARY" }]</strong> [{oxprice price=$oView->getGiftcertSummary()}]<br>
                <strong>[{ oxmultilang ident="YS_GIFTCERT_LOG_OPEN_CREDITS" }]</strong> [{oxprice price=$oView->getGiftcertOpenCredits()}]
            </div>
        </div>
        <div class="col-6">
            <p class="lead">Export</p>
            <div class="ml-3">
                <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">
                    <a class="" href="#" onclick="this.closest('form').submit()"><i class="fa fa-download"></i> [{ oxmultilang ident="YS_GIFTCERT_LOG_CSV_EXPORT" }]</a>
                </form>
            </div>
            <div class="ml-3">
                <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">
                    <a class="" href="#" onclick="this.closest('form').submit()"><i class="fa fa-download"></i> [{ oxmultilang ident="YS_GIFTCERT_LOG_CSV_USED_EXPORT" }]</a>
                </form>
            </div>
            <div class="ml-3">
                <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">
                    <a class="" href="#" onclick="this.closest('form').submit()"><i class="fa fa-download"></i> [{ oxmultilang ident="YS_GIFTCERT_LOG_CSV_USER_EXPORT" }]</a>
                </form>
            </div>
        </div>
    </div>
    <hr class="my-4">
    <div class="d-flex flex-row mb-3 align-items-center">
        <div class="p-2 bd-highlight">
            <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#addGiftCertModal"><i class="fas fa-plus-circle"></i> Neuer Gutschein</a>
        </div>
        <div class="p-2 ml-auto ">
            <div class="form-group">
                <div class="custom-control custom-switch">
                    <form name="toggle-onlyWithValue" id="toggle-onlyWithValue"  action="[{ $oViewConf->getSelfLink() }]" method="post">
                        [{assign var="listFilter" value=$oView->getFilters()}]
                        [{$oViewConf->getHiddenSid()}]
                        <input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
                        <input type="hidden" name="fnc" value="updateFilter">
                        <input type="checkbox" class="custom-control-input" id="onlywithValue" [{if $listFilter.onlyWithValue}]checked[{/if}]>
                        <label class="custom-control-label" for="onlywithValue">Nur Gutscheine mit Restwert</label>
                    </form>
                </div>
            </div>
        </div>
        <div class="p-2">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    [{if $oView->getPage() > 0}]
                        <li class="page-item"><a class="page-link" href="[{ $oViewConf->getSelfLink() }]cl=[{$oViewConf->getActiveClassName()}]&page=[{$oView->getPage()-1}]" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
                    [{/if}]
                    <li class="page-item"><a class="page-link" href="#">[{$oView->getPage()+1}] / [{$oView->getGiftcertListSize()/100|ceil}]</a></li>
                    [{if $oView->getPage()+1 < $oView->getGiftcertListSize()/100|ceil}]
                        <li class="page-item"><a class="page-link" href="[{ $oViewConf->getSelfLink() }]cl=[{$oViewConf->getActiveClassName()}]&page=[{$oView->getPage()+1}]" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
                    [{/if}]
                </ul>
            </nav>
        </div>
[{*        <div class="p-2">*}
{*            <div class="dropdown">*}
{*                <button class="btn btn-light dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">*}
{*                    Anzahl <span id="numberPerPage"></span>*}
{*                </button>*}
{*                <div class="dropdown-menu">*}
{*                    <a class="dropdown-item" href="#">25</a>*}
{*                    <a class="dropdown-item" href="#">50</a>*}
{*                    <a class="dropdown-item" href="#">100</a>*}
{*                </div>*}
{*            </div>*}
{*        </div>*}]
    </div>

</div>

<div id="ys_giftcerts_successbox" class="alert alert-success">
    <span class="message">[{oxmultilang ident="YS_REDEEM_GIFTCERT_MODAL_SUCCESS"}]</span>
    <form name="giftcert-new-certs-export" id="giftcert-new-certs-export"  action="[{ $oViewConf->getSelfLink() }]" method="post">
        [{$oViewConf->getHiddenSid()}]
        <input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
        <input type="hidden" name="fnc" value="exportGeneratedGiftcerts">
        <a class="" href="#" onclick="this.closest('form').submit()"><i class="fa fa-download"></i> [{ oxmultilang ident="YS_GIFTCERT_LOG_CSV_EXPORT_GENERATED" }]</a>
    </form>
</div>


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




<table class="table table-sm giftcerts table-striped">
    <thead class="thead-dark">
    <tr>
        <th scope="col">Gutscheincode</th>
        <th scope="col">Gekauft</th>
        <th scope="col">Ursprünglicher Wert</th>
        <th scope="col">Restwert</th>
        <th scope="col">Aktionen</th>
    </tr>
    </thead>
    <tbody>
        [{foreach from=$oView->getGiftcertList() item="giftcert"}]
        <tr class="[{if $giftcert->paymentStatus() == 3}] table-danger [{/if}][{if $giftcert->paymentStatus() == 4}] table-warning [{/if}]">
            <th class="align-middle" scope="row">[{$giftcert->ysgiftcert__ysgiftcertnr->value}]</th>
            <td class="align-middle">[{if $giftcert->ysgiftcert__ysdatepurchased->value == "0000-00-00 00:00:00"}]-[{else}][{$giftcert->ysgiftcert__ysdatepurchased->value|date_format:"%d.%m.%Y %H:%M"}][{/if}]</td>
            <td class="align-middle">[{oxprice price=$giftcert->ysgiftcert__ysinitialdiscount->value}]</td>
            <td class="align-middle">[{oxprice price=$giftcert->ysgiftcert__ysrestdiscount->value}]</td>
            <td class="align-middle">
                <span class="ys_giftcertlog_action mr-3 btn btn-secondary showLog" data-tooltip="tooltip" data-placement="bottom" data-toggle="modal" data-target="#additionalInfoModal"
                                      title="[{oxmultilang ident="YS_GIFTCERTLOG_MORE_INFO_TOOLTIP"}]">
                    <i class="fas fa-info"></i>
                </span>

                <span class="ys_giftcertlog_action mr-3 btn showRedeemForm [{if $giftcert->ysgiftcert__ysrestdiscount->value > 0}]btn-primary[{else}]btn-light[{/if}]"
                      data-tooltip="tooltip"
                      data-placement="bottom"
                      data-toggle="modal"
                      data-target="#redeemModal"
                      data-giftcertcode="[{$giftcert->ysgiftcert__ysgiftcertnr->value}]"
                      data-giftcertvalue="[{$giftcert->ysgiftcert__ysrestdiscount->value|replace:'.':','}]"
                      title="[{oxmultilang ident="YS_GIFTCERTLOG_REDEEM_ACTION_TOOLTIP"}]">
                    <i class="fas fa-donate"></i>
                </span>

                <span class="ys_giftcertlog_action btn btn-danger ml-3 showDeleteForm"
                      data-tooltip="tooltip"
                      data-placement="bottom"
                      data-toggle="modal"
                      data-target="#deleteModal"
                      data-giftcertcodedelete="[{$giftcert->ysgiftcert__ysgiftcertnr->value}]"
                      title="[{oxmultilang ident="YS_GIFTCERTLOG_DELETE_TOOLTIP"}]">
                    <i class="fas fa-trash"></i>
                </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>
            </td>
        </tr>
        [{/foreach}]
    </tbody>
</table>


<!-- 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="giftcertcodedelete">[{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>