<?php
/* Smarty version 4.5.3, created on 2026-05-20 20:02:11
  from '/var/www/html/billing/ui/ui/voucher.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.3',
  'unifunc' => 'content_6a0e13435d5df9_79787336',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '1c6c275356bcaa6fa1ebda2d7ea2057281403c9a' => 
    array (
      0 => '/var/www/html/billing/ui/ui/voucher.tpl',
      1 => 1768296678,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
    'file:sections/header.tpl' => 1,
    'file:pagination.tpl' => 1,
    'file:sections/footer.tpl' => 1,
  ),
),false)) {
function content_6a0e13435d5df9_79787336 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_subTemplateRender("file:sections/header.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, false);
?>

<!-- Voucher Section -->
<div class="row" style="margin-bottom: 15px;">
    <div class="col-lg-8">
        <h2 style="margin-top: 0px; margin-bottom: 15px; color: #2b3d51;"><i class="ion ion-card"></i> <?php echo Lang::T('Voucher Management');?>
</h2>
    </div>
    <div class="col-lg-4">
        <div class="btn-group btn-group-justified" role="group" style="margin-top: 2px;">
            <div class="btn-group" role="group">
                <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/add-voucher" class="btn btn-primary btn-lg" style="border-radius: 4px 0 0 4px;">
                    <i class="ion ion-android-add"></i> <?php echo Lang::T('Add Vouchers');?>

                </a>
            </div>
            <div class="btn-group" role="group">
                <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/print-voucher" target="print_voucher" class="btn btn-info btn-lg" style="border-radius: 0 4px 4px 0;">
                    <i class="ion ion-android-print"></i> <?php echo Lang::T('Print');?>

                </a>
            </div>
        </div>
    </div>
</div>

<!-- Custom CSS -->
<style>
.panel-primary {
    border-color: #2b3d51;
}
.panel-primary > .panel-heading {
    background-color: #2b3d51;
    border-color: #2b3d51;
    padding: 15px;
}
.table {
    margin-bottom: 0;
}
.table > thead > tr > th {
    background-color: #f5f5f5;
    border-bottom: 2px solid #ddd;
    padding: 12px 8px;
}
.table > tbody > tr > td {
    padding: 12px 8px;
    vertical-align: middle;
}
.btn-tag {
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
}
.btn-tag-success {
    background-color: #27ae60;
    color: white;
}
.btn-tag-danger {
    background-color: #e74c3c;
    color: white;
}
.form-control {
    height: 38px;
    border-radius: 3px;
    box-shadow: none;
    border: 1px solid #ddd;
}
.form-control:focus {
    border-color: #2b3d51;
    box-shadow: none;
}
.btn-success {
    background-color: #27ae60;
    border-color: #27ae60;
}
.btn-success:hover {
    background-color: #219a52;
    border-color: #219a52;
}
.pagination > .active > a {
    background-color: #2b3d51;
    border-color: #2b3d51;
}

/* Additional Styles */
.select2-container .select2-selection--single {
    height: 40px;
    border: 1px solid #ddd;
    border-radius: 3px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 38px;
    padding-left: 12px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 38px;
}
.custom-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
.btn-group-xs > .btn {
    padding: 4px 8px;
    font-size: 12px;
    line-height: 1.5;
    border-radius: 2px;
}
.table > tbody > tr:hover {
    background-color: #f9f9f9;
    cursor: pointer;
}
.btn-tag {
    display: inline-block;
    min-width: 80px;
    text-align: center;
}
.text-primary { color: #2196F3; }
.text-info { color: #00BCD4; }
.text-muted { color: #939da8; }
</style>

<div class="panel panel-hovered mb20 panel-primary">
    <div class="panel-heading">
        <?php if (in_array($_smarty_tpl->tpl_vars['_admin']->value['user_type'],array('SuperAdmin','Admin'))) {?>
        <div class="btn-group pull-right">
            <button id="bulk-delete" class="btn btn-danger btn-sm" disabled>
                <i class="fa fa-trash"></i> <?php echo Lang::T('Delete Selected');?>

            </button>
            <a href="javascript:void(0)" class="btn btn-danger btn-sm" 
                onclick="confirmDelete('<?php echo Lang::T('Are you sure you want to delete all used voucher codes? This action cannot be undone.');?>
', '<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/remove-used-vouchers')">
                <i class="fa fa-trash"></i> <?php echo Lang::T('Delete Used Vouchers');?>

            </a>
            <a href="javascript:void(0)" class="btn btn-warning btn-sm" 
                onclick="confirmDelete('<?php echo Lang::T('Clean up invalid or corrupt voucher entries? This action cannot be undone.');?>
', '<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/cleanup-vouchers')">
                <i class="fa fa-broom"></i> <?php echo Lang::T('Cleanup Invalid');?>

            </a>

            <!-- Bulk Action Success/Error Messages -->
            <div id="action-message" style="display: none; margin-top: 10px;" class="alert">
                <span id="message-text"></span>
            </div>
        </div>
        <?php }?>
        &nbsp;
    </div>
    <div class="panel-body" style="padding: 20px;">
        <form id="site-search" method="post" action="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/voucher/">
            <div class="row">
                <div class="col-lg-2">
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon" style="background-color: #f5f5f5; border-color: #ddd;">
                                <span class="fa fa-search"></span>
                            </div>
                            <input type="text" name="search" class="form-control" placeholder="<?php echo Lang::T('Code Voucher');?>
"
                                value="<?php echo $_smarty_tpl->tpl_vars['search']->value;?>
" style="height: 40px;">
                        </div>
                    </div>
                </div>
                <div class="col-lg-2">
                    <div class="form-group">
                        <select class="form-control select2" id="router" name="router" style="height: 40px;">
                            <option value=""><?php echo Lang::T('Location');?>
</option>
                            <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['routers']->value, 'r');
$_smarty_tpl->tpl_vars['r']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['r']->value) {
$_smarty_tpl->tpl_vars['r']->do_else = false;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['r']->value;?>
" <?php if ($_smarty_tpl->tpl_vars['router']->value == $_smarty_tpl->tpl_vars['r']->value) {?>selected<?php }?>><?php echo $_smarty_tpl->tpl_vars['r']->value;?>
</option>
                            <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                        </select>
                    </div>
                </div>
                <div class="col-lg-2">
                    <div class="form-group">
                        <select class="form-control select2" id="plan" name="plan" style="height: 40px;">
                            <option value=""><?php echo Lang::T('Plan Name');?>
</option>
                            <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['plans']->value, 'p');
$_smarty_tpl->tpl_vars['p']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['p']->value) {
$_smarty_tpl->tpl_vars['p']->do_else = false;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['p']->value['id'];?>
" <?php if ($_smarty_tpl->tpl_vars['plan']->value == $_smarty_tpl->tpl_vars['p']->value['id']) {?>selected<?php }?>><?php echo $_smarty_tpl->tpl_vars['p']->value['name_plan'];?>
</option>
                            <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                        </select>
                    </div>
                </div>
                <div class="col-lg-2">
                    <div class="form-group">
                        <select class="form-control select2" id="status" name="status" style="height: 40px;">
                            <option value="-"><?php echo Lang::T('Status');?>
</option>
                            <option value="1" <?php if ($_smarty_tpl->tpl_vars['status']->value == 1) {?>selected<?php }?>>Used</option>
                            <option value="0" <?php if ($_smarty_tpl->tpl_vars['status']->value == 0) {?>selected<?php }?>>Not Use</option>
                        </select>
                    </div>
                </div>
                <div class="col-lg-2">
                    <div class="form-group">
                        <select class="form-control select2" id="customer" name="customer" style="height: 40px;">
                            <option value=""><?php echo Lang::T('Customer');?>
</option>
                            <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['customers']->value, 'c');
$_smarty_tpl->tpl_vars['c']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['c']->value) {
$_smarty_tpl->tpl_vars['c']->do_else = false;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['c']->value['user'];?>
" <?php if ($_smarty_tpl->tpl_vars['customer']->value == $_smarty_tpl->tpl_vars['c']->value['user']) {?>selected<?php }?>><?php echo $_smarty_tpl->tpl_vars['c']->value['user'];?>
</option>
                            <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                        </select>
                    </div>
                </div>
                <div class="col-lg-2">
                    <div class="form-group">
                        <div class="btn-group btn-group-justified" role="group">
                            <div class="btn-group" role="group">
                                <button class="btn btn-primary" type="submit" style="height: 40px;">
                                    <i class="fa fa-search"></i> <?php echo Lang::T('Search');?>

                                </button>
                            </div>
                            <div class="btn-group" role="group">
                                <a class="btn btn-default" title="Clear Search Query" href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/voucher/" style="height: 40px;">
                                    <i class="fa fa-refresh"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Sorting Dropdown -->
            <div class="row" style="padding: 5px">
                <div class="col-lg-3">
                    <select class="form-control" name="sort" id="sort">
                        <option value="id_asc" <?php if ($_smarty_tpl->tpl_vars['sort']->value == 'id_asc') {?>selected<?php }?>><?php echo Lang::T('Sort by ID Ascending');?>
</option>
                        <option value="id_desc" <?php if ($_smarty_tpl->tpl_vars['sort']->value == 'id_desc') {?>selected<?php }?>><?php echo Lang::T('Sort by ID Descending');?>
</option>
                        <option value="name_asc" <?php if ($_smarty_tpl->tpl_vars['sort']->value == 'name_asc') {?>selected<?php }?>><?php echo Lang::T('Sort by Name Ascending');?>
</option>
                        <option value="name_desc" <?php if ($_smarty_tpl->tpl_vars['sort']->value == 'name_desc') {?>selected<?php }?>><?php echo Lang::T('Sort by Name Descending');?>
</option>
                        <option value="create_date_asc" <?php if ($_smarty_tpl->tpl_vars['sort']->value == 'create_date_asc') {?>selected<?php }?>><?php echo Lang::T('Sort by Create Date Ascending');?>
</option>
                        <option value="create_date_desc" <?php if ($_smarty_tpl->tpl_vars['sort']->value == 'create_date_desc') {?>selected<?php }?>><?php echo Lang::T('Sort by Create Date Descending');?>
</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    
    <div class="table-responsive" style="margin-top: 15px;">
        <table id="datatable" class="table table-hover">
            <thead>
                <tr>
                    <th style="width: 30px;">
                        <input type="checkbox" id="select-all" class="custom-checkbox">
                    </th>
                    <th style="width: 50px;">ID</th>
                    <th><?php echo Lang::T('Type');?>
</th>
                    <th><?php echo Lang::T('Routers');?>
</th>
                    <th><?php echo Lang::T('Plan Name');?>
</th>
                    <th><?php echo Lang::T('Code Voucher');?>
</th>
                    <th style="width: 100px;"><?php echo Lang::T('Status');?>
</th>
                    <th><?php echo Lang::T('Customer');?>
</th>
                    <th><?php echo Lang::T('Create Date');?>
</th>
                    <th><?php echo Lang::T('Generated By');?>
</th>
                    <th style="width: 100px;" class="text-center"><?php echo Lang::T('Actions');?>
</th>
                </tr>
            </thead>
            <tbody>
                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['d']->value, 'ds');
$_smarty_tpl->tpl_vars['ds']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['ds']->value) {
$_smarty_tpl->tpl_vars['ds']->do_else = false;
?>
                <tr <?php if ($_smarty_tpl->tpl_vars['ds']->value['status'] == '1') {?>style="background-color: #fff5f5;"<?php }?>>
                    <td>
                        <input type="checkbox" class="voucher-checkbox custom-checkbox" value="<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
">
                    </td>
                    <td><strong><?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
</strong></td>
                    <td><span class="text-muted"><?php echo $_smarty_tpl->tpl_vars['ds']->value['type'];?>
</span></td>
                    <td><?php echo $_smarty_tpl->tpl_vars['ds']->value['routers'];?>
</td>
                    <td><strong><?php echo $_smarty_tpl->tpl_vars['ds']->value['name_plan'];?>
</strong></td>
                    <td><code style="background: #f8f9fa; color: #333; padding: 4px 8px;"><?php echo $_smarty_tpl->tpl_vars['ds']->value['code'];?>
</code></td>
                    <td>
                        <?php if ($_smarty_tpl->tpl_vars['ds']->value['status'] == '0') {?>
                            <span class="btn-tag btn-tag-success"><i class="fa fa-check-circle"></i> Active</span>
                        <?php } else { ?>
                            <span class="btn-tag btn-tag-danger"><i class="fa fa-times-circle"></i> Used</span>
                        <?php }?>
                    </td>
                    <td>
                        <?php if ($_smarty_tpl->tpl_vars['ds']->value['user'] == '0') {?>
                            <span class="text-muted">-</span>
                        <?php } else { ?>
                            <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
customers/viewu/<?php echo $_smarty_tpl->tpl_vars['ds']->value['user'];?>
" class="text-primary">
                                <i class="fa fa-user"></i> <?php echo $_smarty_tpl->tpl_vars['ds']->value['user'];?>

                            </a>
                        <?php }?>
                    </td>
                    <td><?php if ($_smarty_tpl->tpl_vars['ds']->value['create_date']) {
echo Lang::dateTimeFormat($_smarty_tpl->tpl_vars['ds']->value['create_date']);
}?></td>
                    <td>
                        <?php if ($_smarty_tpl->tpl_vars['ds']->value['generated_by']) {?>
                            <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
settings/users-view/<?php echo $_smarty_tpl->tpl_vars['ds']->value['generated_by'];?>
" class="text-info">
                                <i class="fa fa-user-circle"></i> <?php echo $_smarty_tpl->tpl_vars['admins']->value[$_smarty_tpl->tpl_vars['ds']->value['generated_by']];?>

                            </a>
                        <?php } else { ?>
                            <span class="text-muted">-</span>
                        <?php }?>
                    </td>
                    <td class="text-center">
                        <div class="btn-group">
                            <?php if ($_smarty_tpl->tpl_vars['ds']->value['status'] != '1') {?>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/voucher-view/<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
" class="btn btn-xs btn-primary" data-toggle="tooltip" data-placement="top" title="<?php echo Lang::T('View');?>
">
                                    <i class="fa fa-eye"></i>
                                </a>
                            <?php }?>
                            <?php if (in_array($_smarty_tpl->tpl_vars['_admin']->value['user_type'],array('SuperAdmin','Admin'))) {?>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/voucher-delete/<?php echo $_smarty_tpl->tpl_vars['ds']->value['id'];?>
" class="btn btn-xs btn-danger" onclick="return ask(this, '<?php echo Lang::T('Delete');?>
?')" data-toggle="tooltip" data-placement="top" title="<?php echo Lang::T('Delete');?>
">
                                    <i class="fa fa-trash"></i>
                                </a>
                            <?php }?>
                        </div>
                    </td>
                </tr>
                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
            </tbody>
        </table>
        </div>
    </div>

    <?php $_smarty_tpl->_subTemplateRender("file:pagination.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, false);
?>
</div>

<input type="hidden" id="_csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrf_token']->value;?>
">

<?php echo '<script'; ?>
>
function confirmDelete(message, url) {
    if (confirm(message)) {
        window.location.href = url;
    }
}

function showMessage(message, type) {
    const messageDiv = document.getElementById('action-message');
    const messageText = document.getElementById('message-text');
    messageDiv.className = 'alert alert-' + type;
    messageText.textContent = message;
    messageDiv.style.display = 'block';
    setTimeout(() => {
        messageDiv.style.display = 'none';
    }, 5000);
}

document.addEventListener('DOMContentLoaded', function() {
    const bulkDeleteBtn = document.getElementById('bulk-delete');
    const checkboxes = document.querySelectorAll('.voucher-checkbox');
    
    // Enable/disable bulk delete button based on selections
    function updateBulkDeleteButton() {
        const checkedBoxes = document.querySelectorAll('.voucher-checkbox:checked');
        bulkDeleteBtn.disabled = checkedBoxes.length === 0;
    }

    // Handle select all checkbox
    document.getElementById('select-all').addEventListener('change', function() {
        checkboxes.forEach(checkbox => {
            checkbox.checked = this.checked;
        });
        updateBulkDeleteButton();
    });

    // Handle individual checkboxes
    checkboxes.forEach(checkbox => {
        checkbox.addEventListener('change', updateBulkDeleteButton);
    });

    // Handle bulk delete
    bulkDeleteBtn.addEventListener('click', function() {
        const checkedBoxes = document.querySelectorAll('.voucher-checkbox:checked');
        if(checkedBoxes.length > 0) {
            if(confirm('Are you sure you want to delete the selected ' + checkedBoxes.length + ' vouchers? This action cannot be undone.')) {
                // Collect selected IDs
                const ids = Array.from(checkedBoxes).map(checkbox => checkbox.value);
                
                // Create form data
                const formData = new FormData();
                formData.append('ids', ids.join(','));
                formData.append('_csrf_token', document.getElementById('_csrf_token').value);
                
                // Send to backend
                fetch('<?php echo $_smarty_tpl->tpl_vars['_url']->value;?>
plan/voucher-bulk-delete/', {
                    method: 'POST',
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest'
                    },
                    body: formData
                })
                .then(response => response.json())
                .then(data => {
                    if(data.success) {
                        showMessage('Successfully deleted ' + checkedBoxes.length + ' vouchers.', 'success');
                        setTimeout(() => {
                            location.reload();
                        }, 1000);
                    } else {
                        showMessage('Error deleting vouchers: ' + (data.message || 'Unknown error'), 'danger');
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    showMessage('Error deleting vouchers. Please try again.', 'danger');
                });
            }
        }
    });
});
<?php echo '</script'; ?>
>

<?php $_smarty_tpl->_subTemplateRender("file:sections/footer.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, false);
}
}
