<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            
            <li><a href="Archive.php?do=report">الارشيف</a></li>
            <li class="active">عرض</li>
        </ol>
        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">عرض</h3>
            </div>
            <div class="panel-body"> 
               <form class="form-inline hidden-print" action="Archive.php?do=report" method="post">
                    <div style="display: flex; align-items: center; justify-content: flex-start; gap: 15px; flex-wrap: wrap; background-color: #f9f9f9; padding: 10px; border-radius: 5px; border: 1px solid #eee;">
           
             <div style="display: flex; align-items: center; gap: 5px;">
                <label style="font-weight: bold; white-space: nowrap; margin: 0;">العضو (المقاول):</label>
                <select id="member_id" class="form-control" style="width: 220px; height: 34px;">
                    <option value="">كل الأعضاء</option>
                    {foreach $allMembers as $m}
                        <option value="{$m.id}" {if $smarty.get.member_id == $m.id}selected{/if}>
                            {$m.member_name}
                        </option>
                    {/foreach}
                </select>
            </div>

            <div style="display: flex; align-items: center; gap: 5px;">
                <label style="font-weight: bold; white-space: nowrap; margin: 0;">من:</label>
                <input type="date" id="from_date" class="form-control" style="width: 170px; height: 34px;" value="{$smarty.get.from_date}">
            </div>

            <div style="display: flex; align-items: center; gap: 5px;">
                <label style="font-weight: bold; white-space: nowrap; margin: 0;">إلى:</label>
                <input type="date" id="to_date" class="form-control" style="width: 170px; height: 34px;" value="{$smarty.get.to_date}">
            </div>

            <div style="display: flex; gap: 5px;">
                <button type="button" onclick="filterArchive()" class="btn btn-primary" style="height: 34px; padding: 6px 12px;">
                    <i class="fa fa-filter"></i> عرض النتائج
                </button>
                
                <a href="Archive.php?do=report" class="btn btn-default" style="height: 34px; padding: 6px 12px; text-decoration: none;">
                    إظهار الكل
                </a>
            </div>
            
        </div>
                </form>
<table class="table table-bordered" style="margin-top:20px;" id="example">
    <thead>
        <tr class="bg-primary">
            <th>رقم المناقصة</th>
            <th>الاسم</th>
            <th>الجهة</th>
            <th>الحالة</th>
            <th>تاريخ الاضافة</th>
            <th>تفاصيل</th>
        </tr>
    </thead>
    <tbody>
        {foreach $allTenders as $row}
        <tr>
            <td>{$row.id}</td>
            <td>{$row.name}</td>
            <td>{$row.the_issuing_entity}</td>
            <td>
                                {if $row.status eq "process"}جاري البت فيها
                                {elseif $row.status eq "avilable"}يمكن التقدم لها
                                {elseif $row.status eq "done"}تم اصدار امر التوريد لها
                                {elseif $row.status eq "paused"}تم ايقاف العملية
                                {elseif $row.status eq "canceled"}تم الغاء العملية
                                {elseif $row.status eq "-1" or $row.status eq ""} 
                                {/if}
                            </td>
            <td>{$row.sys_date}</td>
            <td><a href="Archive.php?do=view&id={$row.id}" class="btn btn-xs btn-info">تفاصيل</a></td>
        </tr>
        {/foreach}
    </tbody>
</table>

{literal}
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
    $('#spbutton').live('click', function (e) {
        if (!$('#spbutton').hasClass("processing")) {
            $('#spbutton').addClass("processing");
            var myForm = document.getElementById("spform");
            var SS = Spry.Widget.Form.validate(myForm);
            if (SS == true) {
                myForm.submit();
            } else {
                $('#spbutton').removeClass("processing");
            }
        }
    });
$(document).ready(function() {
    $('#nature').on('change', function() {
        if ($(this).val() === 'other') {
            $('#other_input_container').show();
        } else {
            $('#other_input_container').hide(); 
            $('#other_nature').val(''); 
        }
    });
});
$(document).ready(function(){
    $('#name').on('change', function() {
        let sideValue = $(this).find(':selected').data('side');
        if (sideValue) {
                $('#side').val(sideValue);
            } else {
                $('#side').val(''); 
            }
        });
});



    $(document).ready(function () {
        $('#example').dataTable({
            "aaSorting": [[ 0, "desc" ]],
            "scrollX":true,
            "bPaginate": false,
            "bStateSave": false,
            "sDom": 'TCR<"clear">lfrtip',
            "oTableTools": {
                "aButtons": [
                    "copy",
                    "print",
                    {
                        "sExtends": "collection",
                        "sButtonText": "حفظ",
                        "aButtons": ["csv", "xls"]
                    }
                ]
            }
        });
    });
function filterArchive() {
    var from = document.getElementById('from_date').value;
    var to = document.getElementById('to_date').value;
    var member = document.getElementById('member_id').value;

    var url = "Archive.php?do=report"; 

    if (from && to) {
        url += "&from_date=" + from + "&to_date=" + to;
    }
    if (member) {
        url += "&member_id=" + member;
    }
    
    window.location.href = url;
}

</script>
{/literal}