<?php
include("../../packages/require.php");
include("controller/controller_po.php");
$curpage = "po";
$page_name = "index.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?=$title['po'];?></title>
    <?php include($global['root']."packages/head.php");?>
    <style type="text/css">
        .more-button > a {
            display: none;
        }
        .table-striped th {
            text-transform: uppercase !important;
        }
        .nav-tnp a{    
            text-transform: uppercase !important;
        }
        .multiple-region-box .select2 {
            width: 100% !important;
        }
    </style>
</head>
<body class="<?=$global['body-css'];?>">
    <div class="wrapper">

        <?php include($global['root']."section/header.php");?>
      
        <?php include($global['root']."section/sidebar.php");?>

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                  <h1>
                    Module Purchase Order
                    <small>Track all your purchase order here</small>
                  </h1>
                  <ol class="breadcrumb">
                        <li><a href="<?=$path['dashboard'];?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">Purchase Order</li>
                  </ol>
            </section>
            <input type="hidden" value="<?=$O_status;?>" id="ship-status">
            <input type="hidden" value="" id="list-pick">
            <input type="hidden" value="" id="start-date">
            <input type="hidden" value="" id="end-date">
            <input type="hidden" id="redir-url" value="<?=$path['po'];?>" >
            <input type="hidden" id="acs-region" value="<?=$acsp_admin_region;?>" >
            <input type="hidden" id="region-admin" value="<?=$_SESSION['admin_region'];?>" >
            <input type="hidden" id="acsg-pic" value="<?=$acsg_show_pic;?>" >
            <input type="hidden" id="acs-hide-amount" value="<?=$acsp_hide_amount;?>" >

            <!-- Main content -->
            <section class="content">
                <!-- Default box -->
                <div class="box">
                    <div class="box-header with-border">
                        <div class="row">
                            <div class="col-sm-4">
                                <h3 class="box-title full-xs xs-down10">
                                    Purchase Order List
                                </h3>
                            </div>
                            <div class="col-sm-8">
                                <div class="head-btn text-right">
                                    <a href="javascript:void(0);" id="btn-clear" class="btn btn-default full-xs xs-down10" style="display: none;">
                                        <i class="fa fa-times"></i> Clear Filter
                                    </a>
                                    <?php if($acsp_export == 1){ ?>
                                    <a href="#modal-export" data-toggle="modal" data-target="#modal-export" class="btn bg-maroon full-xs xs-down10">
                                        <i class="fa fa-download"></i> Export Purchase Order
                                    </a>
                                    <?php } ?>
                                    <?php if($acsp_create == 1){ ?>
                                    <a href="<?=$path['po-create'];?>" class="btn btn-success full-xs xs-down10">
                                        <i class="fa fa-plus"></i> Create Purchase Order
                                    </a>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-body">
                        <ul class="nav nav-tabs nav-justified nav-tnp" role="tablist">
                            <li class="active">
                                <a href="#tab-open" id="trig-open" role="tab" data-toggle="tab" onclick="openData('open')">
                                    Open
                                    <span id="ltotal-open" class="pull-right badge bg-orange" style="position: relative;top: 2px;">0</span>
                                </a>
                            </li>
                            <li>
                                <a href="#tab-prepared" id="trig-prepared" role="tab" data-toggle="tab" onclick="openData('prepared')">
                                    Prepared
                                    <span id="ltotal-prepared" class="pull-right badge bg-orange" style="position: relative;top: 2px;">0</span>
                                </a>
                            </li>
                            <li>
                                <a href="#tab-progress" id="trig-progress" role="tab" data-toggle="tab" onclick="openData('progress')">
                                    In Progress
                                    <span id="ltotal-progress" class="pull-right badge bg-orange" style="position: relative;top: 2px;">0</span>
                                </a>
                            </li>
                            <li>
                                <a href="#tab-complete" id="trig-complete" role="tab" data-toggle="tab" onclick="openData('complete')">
                                    Completed
                                    <span id="ltotal-complete" class="pull-right badge bg-orange" style="position: relative;top: 2px;">0</span>
                                </a>
                            </li>
                            <li>
                                <a href="#tab-cancel" id="trig-cancel" role="tab" data-toggle="tab" onclick="openData('cancel')">
                                    Canceled
                                    <span id="ltotal-cancel" class="pull-right badge bg-orange" style="position: relative;top: 2px;">0</span>
                                </a>
                            </li>
                        </ul>
                        <div class="body-total" style="margin:20px 0 10px 0;">
                            <div class="row">
                                <div class="col-sm-3 col-xs-12">
                                    <div class="input-group down1">
                                        <span class="input-group-addon"><i class="fa fa-sort"></i></span>
                                        <select class="form-control input-sort" name="courier" id="sort-select">
                                            <option value="old">Oldest Purchase Order</option>
                                            <option value="new">Newest Purchase Order</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-3 col-xs-12 text-right">
                                    <div class="input-group down1">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" class="form-control" placeholder="Filter Date" id="date-filter">
                                    </div>
                                </div>
                                <div class="col-sm-3 col-xs-12">
                                    <div class="input-group down1">
                                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                        <input type="text" name="q" class="form-control" id="search-input" placeholder="PO ID / PO No / Product / Client / Sub Client...">
                                    </div>
                                </div> 
                                <div class="col-sm-3 col-xs-12 <?php if($acsp_admin_region == 1){?>hide<?php } ?>">
                                    <div class="input-group down1">
                                        <span class="input-group-addon"><i class="fa fa-filter"></i></span>
                                        <select class="form-control input-sort" name="region" id="region-select">
                                            <option value="">All Region</option>
                                            <?php foreach($data_region as $region){ ?>
                                            <option value="<?=$region['region_id'];?>"><?=ucfirst($region['region_title']);?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="tab-open">
                                <div class="body-content">
                                    <div class="table-responsive table-click">
                                        <table class="table table-striped table-bordered table-middle table-hover">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">No.</th>
                                                    <th class="text-center">Action</th>
                                                    <th class="text-center">PO ID</th>
                                                    <th class="text-center">Purchase Order No</th>
                                                    <th class="text-center">Product</th>
                                                    <th class="text-center">Client Name</th>
                                                    <th class="text-center">Sub Client</th>
                                                    <th class="text-center">Region</th>
                                                    <th class="text-center">PIC</th>
                                                    <?php if($acsp_hide_amount != 1){ ?>
                                                    <th class="text-center">Total Amount</th>
                                                    <?php } ?>
                                                    <th class="text-center">Document Date</th>
                                                </tr>
                                            </thead>
                                            <tbody id="tlist-open"></tbody>
                                            <tbody id="tloader-open">
                                                <tr style="background-color: #ffffff !important;">
                                                    <td colspan="15">
                                                        <div class="loader-image">
                                                            <img src="<?=$global['absolute-url'].'img/load.gif';?>" align="icon">
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="more-button">
                                        <input type="hidden" id="tpage-open" value="1">
                                        <a href="javascript:void(0);" id="tmore-open" onclick="moreData('open')" class="btn btn-default">Load More</a>
                                    </div>
                                </div>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="tab-progress">
                                <div class="body-content">
                                    <div class="table-responsive table-click">
                                        <table class="table table-striped table-bordered table-middle table-hover">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">No.</th>
                                                    <th class="text-center">Action</th>
                                                    <th class="text-center">PO ID</th>
                                                    <th class="text-center">Purchase Order No</th>
                                                    <th class="text-center">Product</th>
                                                    <th class="text-center">Client Name</th>
                                                    <th class="text-center">Sub Client</th>
                                                    <th class="text-center">Region</th> 
                                                    <th class="text-center">PIC</th>
                                                    <?php if($acsp_hide_amount != 1){ ?>
                                                    <th class="text-center">Total Amount</th>
                                                    <?php } ?>
                                                    <th class="text-center">Invoice No</th>
                                                    <!-- <th class="text-center">Paid</th> -->
                                                    <th class="text-center">Document Status</th>
                                                </tr>
                                            </thead>
                                            <tbody id="tlist-progress"></tbody>
                                            <tbody id="tloader-progress">
                                                <tr style="background-color: #ffffff !important;">
                                                    <td colspan="15">
                                                        <div class="loader-image">
                                                            <img src="<?=$global['absolute-url'].'img/load.gif';?>" align="icon">
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="more-button">
                                        <input type="hidden" id="tpage-progress" value="1">
                                        <a href="javascript:void(0);" id="tmore-progress" onclick="moreData('progress')" class="btn btn-default">Load More</a>
                                    </div>
                                </div>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="tab-prepared">
                                <div class="body-content">
                                    <div class="table-responsive table-click">
                                        <table class="table table-striped table-bordered table-middle table-hover">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">No.</th>
                                                    <th class="text-center">Action</th>
                                                    <th class="text-center">PO ID</th>
                                                    <th class="text-center">Purchase Order No</th>
                                                    <th class="text-center">Product</th>
                                                    <th class="text-center">Client Name</th>
                                                    <th class="text-center">Sub Client</th>
                                                    <th class="text-center">Region</th>
                                                    <th class="text-center">PIC</th>
                                                    <?php if($acsp_hide_amount != 1){ ?>
                                                    <th class="text-center">Total Amount</th>
                                                    <?php } ?>
                                                    <!-- <th class="text-center">Invoice No</th> -->
                                                    <!-- <th class="text-center">Paid</th> -->
                                                    <th class="text-center">Document Date</th>
                                                </tr>
                                            </thead>
                                            <tbody id="tlist-prepared"></tbody>
                                            <tbody id="tloader-prepared">
                                                <tr style="background-color: #ffffff !important;">
                                                    <td colspan="15">
                                                        <div class="loader-image">
                                                            <img src="<?=$global['absolute-url'].'img/load.gif';?>" align="icon">
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="more-button">
                                        <input type="hidden" id="tpage-prepared" value="1">
                                        <a href="javascript:void(0);" id="tmore-prepared" onclick="moreData('prepared')" class="btn btn-default">Load More</a>
                                    </div>
                                </div>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="tab-complete">
                                <div class="body-content">
                                    <div class="table-responsive table-click">
                                        <table class="table table-striped table-bordered table-middle table-hover">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">No.</th>
                                                    <th class="text-center">Action</th>
                                                    <th class="text-center">PO ID</th>
                                                    <th class="text-center">Purchase Order No</th>
                                                    <th class="text-center">Product</th>
                                                    <th class="text-center">Client Name</th>
                                                    <th class="text-center">Sub Client</th>
                                                    <th class="text-center">Region</th>
                                                    <th class="text-center">PIC</th>
                                                    <?php if($acsp_hide_amount != 1){ ?>
                                                    <th class="text-center">Total Amount</th>
                                                    <?php } ?>
                                                    <th class="text-center">Invoice No</th>
                                                    <th class="text-center">Paid</th>
                                                    <th class="text-center">Document Status</th>
                                                </tr>
                                            </thead>
                                            <tbody id="tlist-complete"></tbody>
                                            <tbody id="tloader-complete">
                                                <tr style="background-color: #ffffff !important;">
                                                    <td colspan="15">
                                                        <div class="loader-image">
                                                            <img src="<?=$global['absolute-url'].'img/load.gif';?>" align="icon">
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="more-button">
                                        <input type="hidden" id="tpage-complete" value="1">
                                        <a href="javascript:void(0);" id="tmore-complete" onclick="moreData('complete')" class="btn btn-default">Load More</a>
                                    </div>
                                </div>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="tab-cancel">
                                <div class="body-content">
                                    <div class="table-responsive table-click">
                                        <table class="table table-striped table-bordered table-middle table-hover">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">No.</th>
                                                    <th class="text-center">Action</th>
                                                    <th class="text-center">PO ID</th>
                                                    <th class="text-center">Purchase Order No</th>
                                                    <th class="text-center">Product</th>
                                                    <th class="text-center">Client Name</th>
                                                    <th class="text-center">Sub Client</th>
                                                    <th class="text-center">Region</th>
                                                    <th class="text-center">PIC</th>
                                                    <?php if($acsp_hide_amount != 1){ ?>
                                                    <th class="text-center">Total Amount</th>
                                                    <?php } ?>
                                                    <th class="text-center">Document Date</th>
                                                </tr>
                                            </thead>
                                            <tbody id="tlist-cancel"></tbody>
                                            <tbody id="tloader-cancel">
                                                <tr style="background-color: #ffffff !important;">
                                                    <td colspan="15">
                                                        <div class="loader-image">
                                                            <img src="<?=$global['absolute-url'].'img/load.gif';?>" align="icon">
                                                        </div>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="more-button">
                                        <input type="hidden" id="tpage-cancel" value="1">
                                        <a href="javascript:void(0);" id="tmore-cancel" onclick="moreData('cancel')" class="btn btn-default">Load More</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                </div>
            </section>
            <!-- /.content -->
        </div>
        <!-- /.content-wrapper -->

        <?php include($global['root']."section/footer.php");?>

    </div>
    <!-- ./wrapper -->
    <input type="hidden" id="redir-detail" value="<?=$path['po-detail'];?>" >

    <?php include($global['root']."packages/footer.php");?>

    
    <?php if(is_array($vmessage)){ ?>
    <div id="modal-alert" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog madd-dialog malert-size" role="document">
            <div class="modal-content madd-content">
                <div class="modal-header madd-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    Alert Message
                </div>
                <div class="modal-body madd-body">
                    <div class="malert-list">
                        <?php $c=0; foreach($vmessage as $vm){ ?>
                        <?php if($valert[$c] != "success"){ ?>
                        <div class="malert-text malert-failed"><?=$vm;?></div>
                        <?php } else { ?>
                        <div class="malert-text malert-ok"><?=$vm;?></div>
                        <?php } ?>
                        <?php $c++; } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php } ?>
    <div id="modal-export" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
        <div class="modal-dialog mde-dialog modal-sm" role="document">
            <div class="modal-content mde-content">
                <form id="form-export" action="<?=$path['po-export'];?>" enctype="multipart/form-data" method="post" target="_blank">
                <div class="modal-body mde-body">
                    <div class="mimp-header">
                        Export Purchase Order
                    </div>
                    <div class="form-group">
                        <label for="input-exstatus">PO Status</label>
                        <select id="input-exstatus" class="form-control" name="exstatus">
                            <option value="all">All Status</option>
                            <option value="open">Open</option>
                            <option value="prepared">Prepared</option>
                            <option value="progress">In Progress</option>
                            <option value="complete">Complete</option>
                            <option value="cancel">Cancel</option>
                        </select>
                        <div id="error-exstatus" class="error-text"></div>
                    </div>
                    <div class="form-group">
                        <label for="input-exregion">Region</label>
                        <div class="multiple-region-box">
                        <select class="form-control input-sort multiple-region" name="exregion[]" id="input-exregion">
                            <option value="all">All Region</option>
                            <?php foreach($data_region as $region){ ?>
                            <option value="<?=$region['region_id'];?>"><?=ucfirst($region['region_title']);?></option>
                            <?php } ?>
                        </select>
                        </div>
                        <div id="error-exregion" class="error-text"></div>
                    </div>
                    <div class="form-group">
                        <label for="input-exdate">Date Range</label>
                        <div class="input-group down1">
                            <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                            </div>
                            <input type="text" class="form-control" placeholder="Export Date" id="input-exdate">
                        </div>
                        <div id="error-exdate" class="error-text"></div>
                    </div>
                    <div class="form-group">
                        <input type="hidden" id="start-exdate" value="" name="startDate">
                        <input type="hidden" id="end-exdate" value="" name="endDate">
                        <input type="hidden" id="export-url" value="<?=$path['po-export'];?>">
                        <button type="submit" id="submit-export" class="btn bg-maroon btn-block">Export Data</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function() {
            <?php if(is_array($vmessage)){ $total_message = count($vmessage);?>
            <?php 
            if($total_message < 3){
            $c=0; 
            foreach($vmessage as $vm){ 
                if($c > 0){ $time =  5000 + ($c*1000); } else { $time = 5000; } 
            ?>
                var alertText = "<?=$vm;?>";
                <?php if($valert[$c] != "success"){ ?>
                errorAlertTimer(alertText,<?=$time;?>);// error alert
                <?php } else { ?>
                successAlertTimer(alertText,<?=$time;?>);// success alert
                <?php } ?>
            <?php $c++;} } else { ?>
            $("#modal-alert").modal('show');
            <?php } } ?>
            
        });
    </script>

    <script src="<?=$global['absolute-url'];?>module/po/js/index.js?<?=mt_rand(10,1000);?>"></script>

</body>
</html>