<?php
/**
 * Created by PhpStorm.
 * User: neosoft
 * Date: 27/10/14
 * Time: 11:19 AM
 */ ?>
 <link rel="stylesheet" href="http://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css"
      xmlns="http://www.w3.org/1999/html"/>

<link rel="stylesheet" href="<?php echo base_url();?>assets/js/validationEngine.jquery.css" type="text/css" />
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/cust_paginition.css" type="text/css" />
<script src="<?php echo base_url(); ?>assets/library/jquery/jquery.min.js"></script> 

<div class="layout-app">
    <div class="container"><div class="row row-app">
            <div class="col-md-12">
                <div class="col-separator col-separator-first col-unscrollable bg-none">
                    <div class="col-table">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="widget">
                                    <?php $this->load->view('admin/flashdata_admin'); ?>
                                    <div class="widget-head">
                                        <h4 class="heading">Processing Payments</h4>
                                    </div>

                                    <div class="widget-body">
                                        <form action="" method="GET" >
                                            <div class="col-md-12 selectBox">
                                                <div class="col-xs-4 col-md-2 bot-mar">
                                                    <label class="col-xs-12">From</label>
                                                    <input type="text" class="form-control date" name="from_date" value="<?php if ($arrGetData['from_date'] != "") echo date("m/d/Y", strtotime($arrGetData['from_date'])); ?>"/>
                                                </div>
                                                <div class="col-xs-4 col-md-2 bot-mar">
                                                    <label class="col-xs-12">To</label>
                                                    <input type="text" class="form-control date" name="to_date" value="<?php if ($arrGetData['to_date'] != "") echo date("m/d/Y", strtotime($arrGetData['to_date'])); ?>"/>
                                                </div>

                                                <div class="col-xs-4 col-md-2 bot-mar" style="display: none;">
                                                    <label class="col-xs-12">Mode of Payment</label>
                                                    <select class="cust_select col-xs-12" name = "payment_mode">
                                                        <option value = "">--Select--</option>
                                                        <option value = "1"
                                                            <?php if($_GET['payment_mode'] == 1) {?> selected
                                                            <?php } ?>>Cash</option>
                                                        <option value = "2" <?php if($_GET['payment_mode'] == 2) {?> selected
                                                        <?php } ?>>Cheque</option>
                                                        <option value = "3" <?php if($_GET['payment_mode'] == 3) {?> selected
                                                        <?php } ?>>Credit card</option>
                                                        <option value = "4" <?php if($_GET['payment_mode'] == 4) {?> selected
                                                        <?php } ?>>Online banking</option>
                                                        <option value = "5" <?php if($_GET['payment_mode'] == 5) {?> selected
                                                        <?php } ?>>Club Membership</option>
                                                        <option value = "6" <?php if($_GET['payment_mode'] == 6) {?> selected
                                                        <?php } ?>>Complementary</option>
                                                        <option value = "7" <?php if($_GET['payment_mode'] == 7) {?> selected
                                                        <?php } ?>>Replacement</option>
                                                        <option value = "8" <?php if($_GET['payment_mode'] == 8) {?> selected
                                                        <?php } ?>>Invoice</option>

                                                    </select>
                                                </div>
                                                <div class="col-xs-4 col-md-2 bot-mar" style="display: none;">
                                                    <label class="col-xs-12">Status</label>
                                                    <select class="cust_select col-xs-12" name = "status">
                                                        <option value = "">--Select--</option>
                                                        <option value = "1" <?php if($_GET['status'] == 1) {?> selected
                                                        <?php } ?>>Unpaid</option>
                                                        <option value = "2" <?php if($_GET['status'] == 2) {?> selected
                                                        <?php } ?>>processing</option>
                                                        <option value = "3" <?php if($_GET['status'] == 3) {?> selected
                                                        <?php } ?>>Paid</option>
                                                    </select>
                                                </div>


                                                <div class="col-xs-4 col-md-2 bot-mar">
                                                    <label class="col-xs-12">&nbsp;</label>
                                                    <div>
                                                        <button type="submit" class="btn btn-primary">Search</button>
                                                    </div>
                                                </div>
                                        </form>
                                        <div class="clearfix"></div>
                                    </div>
                                </div>
                                <table id="sys-Member-listing" class="table table-white table-vertical-center margin-none table-striped footable">
                                    <thead>
                                    <tr>
                                        <th style="width:5%;" data-class="highlight"  class="text-center">#</th>
                                        <th style="width:10%;" class="text-center">Date</th>
                                        <th style="width:15%;" class="text-center">Trnasaction Id</th>
                                        <th style="width:25%;" data-hide="phone" class="text-left">Subscriber Name</th>
                                        <th style="width:10%;" data-hide="phone" class="text-center">Magazine ID</th>
                                        <th style="width:10%;" class="text-center">Mode of Payment</th>
                                        <th style="width:10%;" class="text-right">Amount</th>
                                        <th style="width:10%;" data-hide="phone,tablet" class="text-center">Transaction Overview</th>
                                        <th style="width:10%;" data-hide="phone,tablet" class="text-center">Update Status</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    if (count($arrData) > 0) {
                                        $intCounter = 1;
                                        foreach($arrData as $data) { ?>
                                            <tr>

                                                <td class="text-center"><?php echo $intCounter ?></td>
                                                <td class="text-center" ><?php echo date('d M Y',strtotime($data['transaction_date'])); ?></td>
                                                <td class="text-center" ><?php echo $data['transaction_id']; ?></td>
                                                <td class="text-left"><a href="<?php echo base_url();?>index.php/subscriber/preview/?user_id=<?php echo base64_encode($data['subscriber_id'])?>" > <?php echo ucwords($data['subscriber_name']) ?></a></td>
                                                <td class="text-center"><?php echo $data['magezine_id'] ?></td>
                                                <td class="text-center"><?php echo ucwords($data['mode']); ?></td>
                                                <td class="text-center"><?php echo number_format($data['amount'], 2).' '.$data['name']; ?></td>
                                                <!-- <td class="text-center"><button class="btn btn-success"><?php echo $data['status']; ?></button></td> -->
                                                <td class="text-center"><a href="#editSub" data-toggle="modal" onclick="return fnGetPreview(<?php echo $data['transaction_id'];?>);"><button class="btn btn-success">Overview</button></a></td>
                                                <!-- <td class="text-center"><a href="<?php echo base_url();?>index.php/subscriber/receipt/?id=<?php echo base64_encode($data['transaction_id']); ?>" <button class="btn btn-success">Finalise</button></td>status_option -->
                                                <td class="text-center"><a href="#update_status" data-toggle="modal" onclick="return fnDisplayUpdateStatus('<?php echo base64_encode($data['transaction_id']);?>');"><button class="btn btn-success">Finalise</button></a></td>
                                            </tr>
                                            <?php $intCounter ++; } } else {?>
                                        <tr>
                                            <td class="text-center" colspan="7">Sorry, no transactions found</td>
                                        </tr>
                                    <?php } ?>

                                    </tbody>
                                </table>
                                <?php
                                if ($limit < count($arrData)) { ?>
                                    <div class="text-center innerAll border-top pagination margin-none" align = "center">
                                        <?php echo $pagination; ?>
                                    </div>
                                <?php } ?>

                            </div>
                            <!-- // END TRENDS -->


                        </div>


                    </div>

                </div>
                <div class="col-separator-h"></div>
            </div>
        </div>
    </div>
</div>
</div>

<div class="modal fade" id="editSub">
    <div class="modal-dialog">
        <div class="modal-content" id="tran_preview">

        </div>
    </div>
</div>
<div class="modal fade" id="update_status">
    <div class="modal-dialog">
        <div class="modal-content" id="status_option">

        </div>
    </div>
</div>
<script src="<?php echo base_url();?>assets/js/main.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/plugins/forms_elements_multiselect/js/jquery.multi-select.js?v=v2.0.0-rc1&sv=v0.0.1.2"></script>
<script src="<?php echo base_url();?>assets/plugins/forms_elements_bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_bootstrap-select/bootstrap-select.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_bootstrap-select/bootstrap-select.init.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_fuelux-radio/fuelux-radio.init.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_multiselect/multiselect.init.js?v=v2.0.0-rc1&sv=v0.0.1.2"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validationEngine-en.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validationEngine.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>assets/js/subscriber.js"></script>
<script src="<?php echo base_url(); ?>assets/js/data-table-jquery.js"></script>
<script type="application/javascript">
    $('#sys-Member-listing').DataTable({"autoWidth": false,"iDisplayLength": 50,"bPaginate": false});
    function fnGetPreview(intTransactionId)
    {
        $.ajax({
            url:"<?php echo base_url();?>index.php/users/transaction_preview",
            'type' : 'GET',
            'data' : {
                'transaction_id' :intTransactionId
            },
            success:function(result){
                $("#tran_preview").html(result);
            }
        });
    }

    function fnDisplayUpdateStatus(intTransactionId)
    {
        $("#status_option").html('');
        var new_html =  '<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'+
                        '<h3 class="modal-title">Transaction Details</h3></div><div class="widget-body innerAll inner-2x"><h5 align="center">Update Status of transaction</h5><br>'+
                        '<div id="append_proceed_option"><div style="float: left"> <a href="<?php echo base_url();?>index.php/subscriber/update_payment_method/?id='+intTransactionId +'" title="Update Payment details"><button class="btn btn-danger">Reprocess</button></a></div>'+
                        '<div style="float: right"><a href="<?php echo base_url();?>index.php/subscriber/receipt/?id='+intTransactionId +'" title="Confirm and proceed"><button class="btn btn-success">Proceed</button></a></div></div>' +
                        '<div style="clear: both"></div></div>';
        $("#status_option").html(new_html);
    }
</script>