<!-- File: src/Template/Articles/index.ctp -->
<div id="page-wrapper">
    <div class="header">
        <h1 class="page-header">

        </h1>
        <ol class="breadcrumb">
            <li><a href="#">Books</a></li>
            <li class="active">Cash Book</li>
        </ol>

    </div>
    <div id="page-inner">



        <div class="row">
            <div class="col-md-12">
                <!--   Kitchen Sink -->
                <div class="panel panel-default">
                    <div class="panel-heading d-flex justify-content-center">
                        Cash Book
                    </div>
                    <div class="panel-body">
                        <div class="app-title">

                            <?php if (isset($_SESSION['mem_add']) && $_SESSION['mem_add'] != "") { ?>
                                <div class="alert alert-success">
                                    <strong><?php echo $_SESSION['mem_add']; ?></strong>
                                </div>
                            <?php $_SESSION['mem_add'] = "";
                            } ?>
                        </div>
                        <form method="post" action="<?php echo base_url(); ?>index.php/Demand/cash_book" id="member_add_" enctype='multipart/form-data'>
                            <div class="row">
                                <div class="col-sm-3">
                                    <div>
                                        Date
                                    </div>
                                    <input type="date" name="added_on" id="added_on_id" value="<?php echo date("Y/m/d"); ?>" onchange="disable_month_year();" class="form-control mt-2">
                                </div>
                                <div class="col-sm-3">
                                    <div>Month</div>
                                    <select name="month" id="month_id" class="form-control mt-2">
                                        <option value="">Select Month</option>
                                        <option value="January">January</option>
                                        <option value="February">February</option>
                                        <option value="March">March</option>
                                        <option value="April">April</option>
                                        <option value="May">May</option>
                                        <option value="June">June</option>
                                        <option value="July">July</option>
                                        <option value="August">August</option>
                                        <option value="September">September</option>
                                        <option value="October">October</option>
                                        <option value="November">November</option>
                                        <option value="December">December</option>
                                    </select>
                                </div>
                                <div class="col-sm-2">Year
                                    <?php $y = date('Y'); ?>
                                    <select name="year" id="year_id" class="form-control">
                                        <option value="">Select Year</option>
                                        <?php for ($j = $y; $j >= 2019; $j--) { ?>
                                            <option <?php if ($j == $y) {
                                                        echo "";
                                                    } ?> value="<?php echo $j; ?>"><?php echo $j; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                                <div class="col-sm-2 mt-4"><button type="submit" class="btn btn-primary">Submit</button></div>
                        </form>
                    </div>
                    <br>
                    <br>

                    <?php $sno = 0;
                    $member_ft = 0; ?>

                    <?php if (isset($members) && count($members) > 0) { ?>
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="tile">
                                    <div class="tile-body">
                                        <table id="table_id" class="table table-striped table-bordered table-responsive" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">Particulars</th>
                                                    <th class="text-center">Cash</th>
                                                    <th class="text-center">Adjustment</th>
                                                    <th class="text-center">Total</th>
                                                    <th class="text-center">Particulars</th>
                                                    <th class="text-center">Cash</th>
                                                    <th class="text-center">Adjustment</th>
                                                    <th class="text-center">Total</th>
                                                </tr>
                                            </thead>
                                            <!-- Here's where we iterate through our $articles query object, printing out article info -->
                                            <tbody>
                                                <tr>
                                                    <td class="text-center">Share</td>
                                                    <td class="text-center"><?php echo $share_amt_tot; ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot_; ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot + $share_amt_tot_; ?></td>
                                                    <td class="text-center"><?php if ($share_amt_tot_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot; ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot_; ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot + $share_amt_tot_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">E. Fees</td>
                                                    <td class="text-center"><?php echo $ent_fees_tot; ?></td>
                                                    <td class="text-center"><?php echo $ent_fees_tot_; ?></td>
                                                    <td class="text-center"><?php echo $ent_fees_tot + $ent_fees_tot_; ?></td>
                                                    <td class="text-center"><?php if ($ent_fees_tot_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $ent_fees_tot; ?></td>
                                                    <td class="text-center"><?php echo $ent_fees_tot_; ?></td>
                                                    <td class="text-center"><?php echo $ent_fees_tot + $ent_fees_tot_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">Thrift</td>
                                                    <td class="text-center"><?php echo $tot_td; ?></td>
                                                    <td class="text-center"><?php echo $tot_td_; ?></td>
                                                    <td class="text-center"><?php echo $tot_td + $tot_td_; ?></td>
                                                    <td class="text-center"><?php if ($tot_td_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $tot_td; ?></td>
                                                    <td class="text-center"><?php echo $tot_td_; ?></td>
                                                    <td class="text-center"><?php echo $tot_td + $tot_td_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">Principal</td>
                                                    <td class="text-center"><?php echo $tot_loan_pri; ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_pri_; ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_pri + $tot_loan_pri_; ?></td>
                                                    <td class="text-center"><?php if ($tot_loan_pri_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_pri; ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_pri_; ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_pri + $tot_loan_pri_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">Interest</td>
                                                    <td class="text-center"><?php echo $tot_loan_int; ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_int_; ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_int + $tot_loan_int_; ?></td>
                                                    <td class="text-center"><?php if ($tot_loan_int_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_int; ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_int_; ?></td>
                                                    <td class="text-center"><?php echo $tot_loan_int + $tot_loan_int_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">FL. Pri</td>
                                                    <td class="text-center"><?php echo $tot_f_pri; ?></td>
                                                    <td class="text-center"><?php echo $tot_f_pri_; ?></td>
                                                    <td class="text-center"><?php echo $tot_f_pri + $tot_f_pri_; ?></td>
                                                    <td class="text-center"><?php if ($tot_f_pri_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $tot_f_pri; ?></td>
                                                    <td class="text-center"><?php echo $tot_f_pri_; ?></td>
                                                    <td class="text-center"><?php echo $tot_f_pri + $tot_f_pri_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">FL. Int</td>
                                                    <td class="text-center"><?php echo $tot_f_int; ?></td>
                                                    <td class="text-center"><?php echo $tot_f_int_; ?></td>
                                                    <td class="text-center"><?php echo $tot_f_int + $tot_f_int_; ?></td>
                                                    <td class="text-center"><?php if ($tot_f_int_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $tot_f_int; ?></td>
                                                    <td class="text-center"><?php echo $tot_f_int_; ?></td>
                                                    <td class="text-center"><?php echo $tot_f_int + $tot_f_int_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">Insurance</td>
                                                    <td class="text-center"><?php echo $tot_insurance; ?></td>
                                                    <td class="text-center"><?php echo $tot_insurance_; ?></td>
                                                    <td class="text-center"><?php echo $tot_insurance + $tot_insurance_; ?></td>
                                                    <td class="text-center"><?php if ($tot_insurance_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $tot_insurance; ?></td>
                                                    <td class="text-center"><?php echo $tot_insurance_; ?></td>
                                                    <td class="text-center"><?php echo $tot_insurance + $tot_insurance_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">Others</td>
                                                    <td class="text-center"><?php echo $tot_others; ?></td>
                                                    <td class="text-center"><?php echo $tot_others_; ?></td>
                                                    <td class="text-center"><?php echo $tot_others + $tot_others_; ?></td>
                                                    <td class="text-center"><?php if ($tot_others_ > 0) {
                                                                                echo "As per Bank Entry Cheque no. or Transaction id : " . implode(",", $tansaction_id);
                                                                            } ?></td>
                                                    <td class="text-center"><?php echo $tot_others; ?></td>
                                                    <td class="text-center"><?php echo $tot_others_; ?></td>
                                                    <td class="text-center"><?php echo $tot_others + $tot_others_; ?></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">Extra Input</td>
                                                    <td class="text-center"></td>
                                                    <td class="text-center"></td>
                                                    <td class="text-center"></td>
                                                    <td class="text-center"></td>
                                                    <td class="text-center"></td>
                                                    <td class="text-center"></td>
                                                    <td class="text-center"></td>
                                                </tr>
                                                <tr>
                                                    <td class="text-center">Total</td>
                                                    <td class="text-center"><?php echo $share_amt_tot + $ent_fees_tot + $tot_td + $tot_others + $tot_insurance + $tot_loan_pri + $tot_loan_int + $tot_f_pri + $tot_f_int; ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot_ + $ent_fees_tot_ + $tot_td_ + $tot_others_ + $tot_insurance_ + $tot_loan_pri_ + $tot_loan_int_ + $tot_f_pri_ + $tot_f_int_; ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot + $ent_fees_tot + $tot_td + $tot_others + $tot_insurance + $tot_loan_pri + $tot_loan_int + $tot_f_pri + $tot_f_int + $share_amt_tot_ + $ent_fees_tot_ + $tot_td_ + $tot_others_ + $tot_insurance_ + $tot_loan_pri_ + $tot_loan_int_ + $tot_f_pri_ + $tot_f_int_; ?></td>
                                                    <td class="text-center"></td>
                                                    <td class="text-center"><?php echo $share_amt_tot + $ent_fees_tot + $tot_td + $tot_others + $tot_insurance + $tot_loan_pri + $tot_loan_int + $tot_f_pri + $tot_f_int; ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot_ + $ent_fees_tot_ + $tot_td_ + $tot_others_ + $tot_insurance_ + $tot_loan_pri_ + $tot_loan_int_ + $tot_f_pri_ + $tot_f_int_; ?></td>
                                                    <td class="text-center"><?php echo $share_amt_tot + $ent_fees_tot + $tot_td + $tot_others + $tot_insurance + $tot_loan_pri + $tot_loan_int + $tot_f_pri + $tot_f_int + $share_amt_tot_ + $ent_fees_tot_ + $tot_td_ + $tot_others_ + $tot_insurance_ + $tot_loan_pri_ + $tot_loan_int_ + $tot_f_pri_ + $tot_f_int_; ?></td>
                                                </tr>
                                            </tbody>
                                        </table>

                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php } ?>
                </div>


            </div>
        </div>

        <script>
            function disable_month_year() {
                var added_on = $("#added_on_id").val();
                if (added_on != "") {
                    $("#month_id").val("");
                    $("#year_id").val("");
                    $('#month_id').prop('disabled', 'disabled');
                    $('#year_id').prop('disabled', 'disabled');
                } else {
                    $('#month_id').prop('disabled', false);
                    $('#year_id').prop('disabled', false);
                }
            }

            function editpodate(id) {
                $("#edit_" + id).hide();
                $("#save_" + id).show();
                $("#divpo_" + id).hide();
                $("#input_" + id).show();
            }

            function savepodate(id) {
                var paid_on = $("#paid_on_date_" + id).val();
                if (paid_on != "") {
                    $.ajax({
                        type: 'POST',
                        url: "<?php echo base_url() ?>index.php/Demand/savepodate",
                        data: {
                            id: id,
                            paid_on: paid_on
                        },
                        dataType: 'html',
                        success: function(data) {
                            alert("Paid date updated successfully");
                            $("#edit_" + id).show();
                            $("#save_" + id).hide();
                            $("#divpo_" + id).show();
                            $("#input_" + id).hide();
                            $("#divpo_" + id).html(paid_on);
                        }
                    });
                } else {
                    alert("Paid date should be filled out");
                }
            }

            $(document).ready(function() {
                $('.alert').fadeOut(3000);
                $('.datePicker')
                    .datepicker({
                        format: 'dd-mm-yyyy'
                    })
                    .on('changeDate', function(e) {
                        // Revalidate the date field
                        // $('#eventForm').formValidation('revalidateField', 'date');
                    });


                // $('#eventForm').formValidation({
                //     framework: 'bootstrap',
                //     icon: {
                //         valid: 'glyphicon glyphicon-ok',
                //         invalid: 'glyphicon glyphicon-remove',
                //         validating: 'glyphicon glyphicon-refresh'
                //     },
                //     fields: {
                //         name: {
                //             validators: {
                //                 notEmpty: {
                //                     message: 'The name is required'
                //                 }
                //             }
                //         },
                //         date: {
                //             validators: {
                //                 notEmpty: {
                //                     message: 'The date is required'
                //                 },
                //                 date: {
                //                     format: 'MM/DD/YYYY',
                //                     message: 'The date is not a valid'
                //                 }
                //             }
                //         }
                //     }
                // });
            });
        </script>