<?php
include("../../classes/manager.class.php");
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
$m = new Manager();
$output = '';
if (!isset($_SESSION['sess_userid'])) {
    header("Location: " . PROJECT_ADMIN_URL);
    exit();
}


if (isset($_POST) && !empty($_GET['delete'])) {
    BankTransactionSetup::DeleteBankTransactionSetup($_GET['delete']);
    header("Location: " . PROJECT_ADMIN_URL . "transaction/bank_transaction.php?view");
    exit();
}




$bank_account_number = "";
$status = "";
$type = "";
$payment_type = "";
$cheque_number = "";
$cheque_bank = "";
$online_bank = "";
$particulars = "";
$statement_bank_id = "";
$amount = "";
$current_date = date('d-m-Y');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include('../includes/inc_head.php'); ?>
    <script>
        $(function () {
            $('#datepicker').pickadate({
                format: 'dd-mm-yyyy',
                selectMonths: true,
            });
        });
    </script>
</head>
<body>
<!-- Start Page Loading -->
<div id="loader-wrapper">
    <div id="loader"></div>
    <div class="loader-section section-left"></div>
    <div class="loader-section section-right"></div>
</div>
<!-- End Page Loading -->
<div id="container">
    <?php include('../includes/inc_top.php'); ?>
    <div class="row">
        <div class="col s12 m12">
            <div class="">
                <h3>Bank Transaction</h3>
            </div>
            <hr>
            <?php if ($_SESSION['sess_role'] == 'VEC') {
                if (isset($_GET['view'])) { ?>
                    <a class="btn waves-effect waves-light" style="float:right;margin-left:5px;" href="?add">Add<i class="mdi-content-add-box"></i></a>
                    <a class="btn waves-effect waves-light" style="float:right;margin-left:5px;" href="reportbanktransaction.php">Report<i class="mdi-content-add-box"></i></a>
                    <div class="clearfix"></div>
                <?php }
            } ?>
            <br/>
            <?php
            if (isset($_GET['add'])) {
            if (isset($_POST) && !empty($_POST)) {
                extract($_REQUEST);
                $data['particulars'] = $particulars;
                $data['statement_bank_id'] = $statement_bank_id;
                $data['type'] = $type;
                $data['payment_type'] = $payment_type;
                $data['cheque_number'] = $cheque_number;
                $data['cheque_bank'] = $cheque_bank;
                $data['online_bank'] = $online_bank;
                $data['amount'] = $amount;
                $data['status'] = $status;
                $data['create_date'] = date('Y-m-d H:i:s', strtotime(date('H:i:s'), strtotime($create_date)));

                $errors = array();
                // Validate the input

                if ((strlen($particulars) == 0) || (strlen($particulars) > 255))
                    array_push($errors, "Please enter particulars");
                if ((strlen($amount) == 0))
                    array_push($errors, "Please enter amount");

            if (count($errors) == 0) {
                $q = BankTransactionSetup::AddBankTransactionSetup($data);

            if ($q) {
                $output = '';
                //header("Location: ?view&sucess"); ?>
                <script>window.location.href = '?view&sucess'</script>
            <?php
            echo "<div id='card-alert' class='card green lighten-5'>
                      <div class='card-content green-text'>
                        <p>SUCCESS : <strong>Attention! </strong>Submitted!</p>
                      </div>
                      <button type='button' class='close green-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
            } else {
                $output = '';
                echo "<div id='card-alert' class='card orange lighten-5'>
                      <div class='card-content orange-text'>
                        <p>WARNING : <strong>Attention! </strong>Some error occurred!</p>
                      </div>
                      <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
            }
            } else {
                //Prepare errors for output
                foreach ($errors as $val) {
                    $output .= "<div id='card-alert' class='card orange lighten-5'>
                      <div class='card-content orange-text'>
                        <p>WARNING : <strong>Attention! </strong>$val</p>
                      </div>
                      <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
                }
            }
            }
            ?>
                <div class="row">
                    <form action="" method="post" id="bank_setup_form" novalidate="novalidate">
                        <div class="col s12">
                            <?php echo $output; ?>
                            <div class="row">
                                <span>(*) Mark Fields are mandatory</span><br/><br/>
                            </div>
                            <div class="col m6 s12">
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" required type="text" id="datepicker"
                                               name="create_date"
                                               placeholder="<?= date('01-01-Y') ?>"
                                               value='<?= !empty($create_date) ? $create_date : $current_date; ?>'/><br/>
                                        <label for="invoice_date" class="control-label">Date *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <?php
                                        $bankfilter = " WHERE status = 'active' ORDER BY bank_name";
                                        $banks = StatementBankSetup::GetBankSetupList($bankfilter);
                                        ?>
                                        <select class="form-control" required id="statement_bank_id"
                                                name="statement_bank_id">
                                            <?php
                                            foreach ($banks AS $banksRow) {
                                                $selected = $banksRow->id == $statement_bank_id ? "selected" : "";
                                                echo '<option ' . $selected . ' value="' . $banksRow->id . '">' . $banksRow->bank_name . ' - ' . $banksRow->bank_account_number . '</option>';
                                            }
                                            ?>
                                        </select>
                                        <label for="customer_name" class="control-label">Bank Account *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input type="text" name="particulars" id="particulars" maxlength="250"
                                               class="form-control"
                                               value='<?php echo $particulars; ?>'>
                                        <label for="name" class="center-align">Particulars *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="amount"
                                               maxlength="30"
                                               name="amount"
                                               value='<?php echo $amount; ?>'/>
                                        <label for="bank_account_number" class="center-align">Amount *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div id="status" class="input-field col s12">
                                        <select class="form-control" name="type">
                                            <option value="debit" <?php if ($type == 'debit') {
                                                echo "selected='selected'";
                                            } ?>>Debit
                                            </option>
                                            <option value="credit" <?php if ($type == 'credit') {
                                                echo "selected='selected'";
                                            } ?>>Credit
                                            </option>
                                        </select>
                                        <label for="status" class="center-align">Type</label>
                                    </div>
                                    <br/>
                                </div>
                                <div class="row margin">
                                    <div id="status" class="input-field col s12">
                                        <select class="form-control" name="payment_type" id="payment_type">
                                            <option value="cash" <?php if ($payment_type == 'cash') {
                                                echo "selected='selected'";
                                            } ?>>Cash
                                            </option>
                                            <option value="cheque" <?php if ($payment_type == 'cheque') {
                                                echo "selected='selected'";
                                            } ?>>Cheque
                                            </option>
                                            <option value="online" <?php if ($payment_type == 'online') {
                                                echo "selected='selected'";
                                            } ?>>Online
                                            </option>
                                        </select>
                                        <label for="status" class="center-align">Payment Type</label>
                                    </div>
                                    <br/>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12" id="cheque_number_row">
                                        <input class="form-control" type="text" id="cheque_number"
                                               name="cheque_number"
                                               value='<?php echo $cheque_number; ?>'/>
                                        <label for="cheque_number" class="center-align">Cheque Number</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12" id="cheque_bank_row">
                                        <input class="form-control" type="text" id="cheque_bank"
                                               name="cheque_bank"
                                               value='<?php echo $cheque_bank; ?>'/>
                                        <label for="cheque_bank" class="center-align">Cheque Bank Name</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12" id="online_bank_row">
                                        <input class="form-control" type="text" id="online_bank"
                                               name="online_bank"
                                               value='<?php echo $online_bank; ?>'/>
                                        <label for="online_bank" class="center-align">Online Bank Name</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div id="status" class="input-field col s12">
                                        <select class="form-control" name="status">
                                            <option value="active" <?php if ($status == 'active') {
                                                echo "selected='selected'";
                                            } ?>>Active
                                            </option>
                                            <option value="cancel" <?php if ($status == 'cancel') {
                                                echo "selected='selected'";
                                            } ?>>Cancel
                                            </option>
                                        </select>
                                        <label for="status" class="center-align">Status</label>
                                    </div>
                                    <br/>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <div class="row margin">
                            <div class="input-field col s12">
                                <button id="btnsubmit" type="submit" class="btn waves-effect waves-light">Submit
                                </button>
                                <button type="button" class="btn waves-effect waves-light"
                                        onclick="location.href='bank_transaction.php?view'">Cancel
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <?php
            } // add close

            if (isset($_GET['view'])) {

                ?>
                <?php if (isset($_GET['sucess'])) { ?>
                    <div id='card-alert' class='card green lighten-5'>
                        <div class='card-content green-text'>
                            <p>Successfully updated!</p>
                        </div>
                        <button type='button' class='close green-text' data-dismiss='alert' aria-label='Close'>
                            <span aria-hidden='true'>x</span>
                        </button>
                    </div>
                <?php } ?>
                <?php if (isset($_GET['error'])) { ?>
                    <div id='card-alert' class='card orange lighten-5'>
                        <div class='card-content orange-text'>
                            <p>WARNING : <strong>Attention! </strong>Error occurred!</p>
                        </div>
                        <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                            <span aria-hidden='true'>x</span>
                        </button>
                    </div>
                <?php } ?>
                <div class="table-datatables">
                    <table id="data-table-simple" class="bordered responsive-table table dataTable">
                        <thead>
                        <tr>
                            <th>Action</th>
                            <th>Bank Name</th>
                            <th>Particulars</th>
                            <th>Payment Type</th>
                            <th>Amount</th>
                            <th>Type</th>
                            <th>Status</th>
                            <th>Date</th>
                        </tr>
                        </thead>
                        <tfoot>
                        <tr>
                            <th>Action</th>
                            <th>Bank Name</th>
                            <th>Particulars</th>
                            <th>Payment Type</th>
                            <th>Amount</th>
                            <th>Type</th>
                            <th>Status</th>
                            <th>Date</th>
                        </tr>
                        </tfoot>
                        <tbody>
                        <?php
              			$filter = " ORDER BY create_date DESC";
                        $qry = BankTransactionSetup::GetBankTransactionSetupList($filter);
                        if ($qry) {
                            foreach ($qry as $qery) {
                                $bankStatement = StatementBankSetup::GetBankSetupById($qery->statement_bank_id);
                                ?>
                                <tr>
                                    <td>
                                        <?php
                                        if ($_SESSION['sess_role'] == 'VEC' || $_SESSION['sess_role'] == 'VE') {
                                            ?>
                                            <a href='?edit&id=<?php echo $qery->id; ?>&v' title="View">
                                                    <span
                                                        style="width: 20px; height: 20px; font-size: 12px; line-height: 20px;"
                                                        class="mini-stat-icon pink"><i
                                                            class="mdi-action-description"></i></span>
                                            </a>
                                            <a href="?edit&id=<?php echo $qery->id; ?>" title="Edit">
                                                    <span
                                                        style="width: 20px; height: 20px; font-size: 12px; line-height: 20px;"
                                                        class="mini-stat-icon orange"><i
                                                            class="mdi-image-edit"></i></span>
                                            </a>
                                        <?php } else { ?>
                                            <a href="?edit&id=<?php echo $qery->id; ?>&v" title="View">
                                                    <span
                                                        style="width: 20px; height: 20px; font-size: 12px; line-height: 20px;"
                                                        class="mini-stat-icon pink"><i
                                                            class="mdi-action-description"></i></span>
                                            </a>
                                         <?php } ?>
                                              <a href="?view&delete=<?= $qery->id ?>" title="Delete" onclick="return confirm('Delete this record?');">
                                            <span style="width: 20px; height: 20px; font-size: 12px; line-height: 20px;"
                                                  class="mini-stat-icon red">
                                                <i class="mdi-action-delete"></i>
                                            </span>
                                            </a>
                                                                            </td>
                                    <td><?php echo ucwords($bankStatement->bank_name); ?></td>
                                    <td><?php echo $qery->particulars; ?></td>
                                    <td><?php
                                        if ($qery->payment_type == 'cash') {
                                            echo "Cash";
                                        } else if ($qery->payment_type == 'cheque') {
                                            echo "Cheque";
                                        } else if ($qery->payment_type == 'online') {
                                            echo "Online";
                                        } ?></td>
                                    <td><?php echo $qery->amount; ?></td>
                                    <td><?= ($qery->type == 'debit') ? ucwords($qery->type) : "Credit"; ?></td>
                                    <td><?= ($qery->status == 'active') ? ucwords($qery->status) : "Inactive"; ?></td>
                                    <td><?php echo $qery->create_date; ?></td>
                                </tr>
                                <?php
                            }
                        } ?>
                        </tbody>
                    </table>
                </div>
                <?php

            } // close view


            if (isset($_GET['edit']) && !empty($_POST)) {
                extract($_REQUEST);
                $id = $_GET['id'];
                $data['particulars'] = $particulars;
                $data['statement_bank_id'] = $statement_bank_id;
                $data['type'] = $type;
                $data['payment_type'] = $payment_type;
                $data['cheque_number'] = $cheque_number;
                $data['cheque_bank'] = $cheque_bank;
                $data['online_bank'] = $online_bank;
                $data['amount'] = $amount;
                $data['status'] = $status;
                $data['create_date'] = date('Y-m-d H:i:s', strtotime(date('H:i:s'), strtotime($create_date)));

                $errors = array();
                // Validate the input

                if ((strlen($particulars) == 0) || (strlen($particulars) > 255))
                    array_push($errors, "Please enter particulars");
                if ((strlen($amount) == 0))
                    array_push($errors, "Please enter amount");

                if (count($errors) == 0) {
                    $q = BankTransactionSetup::UpdateBankTransactionSetup($id, $data);

                    if ($q) {
                        $output = '';
                        //header("Location: ?view&sucess"); ?>
                        <script>window.location.href = '?view&sucess'</script>
                        <?php
                        echo "<div id='card-alert' class='card green lighten-5'>
                      <div class='card-content green-text'>
                        <p>SUCCESS : <strong>Attention! </strong>Submitted!</p>
                      </div>
                      <button type='button' class='close green-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
                    } else {
                        $output = '';
                        echo "<div id='card-alert' class='card orange lighten-5'>
                      <div class='card-content orange-text'>
                        <p>WARNING : <strong>Attention! </strong>Some error occurred!</p>
                      </div>
                      <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
                    }
                } else {
                    //Prepare errors for output
                    foreach ($errors as $val) {
                        $output .= "<div id='card-alert' class='card orange lighten-5'>
                      <div class='card-content orange-text'>
                        <p>WARNING : <strong>Attention! </strong>$val</p>
                      </div>
                      <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
                    }
                }
            }
            if (isset($_GET['edit'])) {
            $id = $_GET['id'];
            if (empty($_POST)) {
                $qry = BankTransactionSetup::GetBankTransactionSetupById($id);
                $particulars = $qry->particulars;
                $statement_bank_id = $qry->statement_bank_id;
                $amount = $qry->amount;
                $type = $qry->type;
                $payment_type = $qry->payment_type;
                $cheque_number = $qry->cheque_number;
                $cheque_bank = $qry->cheque_bank;
                $online_bank = $qry->online_bank;
                $status = $qry->status;
                $bankStatement = StatementBankSetup::GetBankSetupById($statement_bank_id);
            }
            if ($_REQUEST['id'] && isset($_REQUEST['v'])) {
                ?>
                <div class="row">
                    <!--  The form that will be parsed by jQuery before submit  -->
                    <div class="col s12">
                        <div class="col s8">
                            <div class="row">
                                <div class="col s6">Bank Name:</div>
                                <span class="col s6"><?php echo $bankStatement->bank_name; ?></span>
                            </div>
                            <div class="row">
                                <div class="col s6">Particulars:</div>
                                <span class="col s6"><?php echo $particulars; ?></span>
                            </div>
                            <div class="row">
                                <div class="col s6">Amount:</div>
                                <span class="col s6"><?php echo $amount; ?></span>
                            </div>
                            <div class="row">
                                <div class="col s6">Type</div>

                                <span class="col s6">
                                    <?php
                                    if ($type == 'debit') {
                                        echo "Debit";
                                    } else if ($type == 'credit') {
                                        echo "Credit";
                                    } ?>
                                </span>
                            </div>
                            <div class="row">
                                <div class="col s6">Payment Type</div>

                                <span class="col s6">
                                    <?php
                                    if ($payment_type == 'cash') {
                                        echo "Cash";
                                    } else if ($payment_type == 'cheque') {
                                        echo "Cheque";
                                    } else if ($payment_type == 'online') {
                                        echo "Online";
                                    } ?>
                                </span>
                            </div>
                            <?php
                            if ($payment_type == 'cheque') { ?>
                                <div class="row">
                                    <div class="col s6">Cheque Number</div>
                                    <span class="col s6"><?php echo $cheque_number; ?></span>
                                </div>
                                <div class="row">
                                    <div class="col s6">Cheque Bank Name</div>
                                    <span class="col s6"><?php echo $cheque_bank; ?></span>
                                </div>
                            <?php } else if ($payment_type == 'online') { ?>
                                <div class="row">
                                    <div class="col s6">Online Bank Name</div>
                                    <span class="col s6"><?php echo $online_bank; ?></span>
                                </div>
                            <?php } ?>
                            <div class="row">
                                <div class="col s6">Status</div>

                                <span class="col s6">
                                    <?php
                                    if ($status == 'active') {
                                        echo "Active";
                                    } else if ($status == 'cancel') {
                                        echo "Cancel";
                                    } ?>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
            <?php } else {
                ?>
                <div class="row">
                    <!--  The form that will be parsed by jQuery before submit  -->
                    <form action="?edit&id=<?php echo $id ?>" method="post" id="bank_setup_form"
                          name="bank_transaction"
                          novalidate="novalidate">
                        <div class="col s12">
                            <div class="col s8">
                                <div class="row">
                                    <?php echo $output; ?>
                                </div>
                                <div class="row margin">
                                    <span>(*) Mark Fields are mandatory</span><br/><br/>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" required type="text" id="datepicker"
                                               name="create_date"
                                               placeholder="<?= date('01-01-Y') ?>"
                                               value='<?= !empty($create_date) ? $create_date : $current_date; ?>'/><br/>
                                        <label for="invoice_date" class="control-label">Date *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <?php
                                        $bankfilter = " WHERE status = 'active' ORDER BY bank_name";
                                        $banks = StatementBankSetup::GetBankSetupList($bankfilter);
                                        ?>
                                        <select class="form-control" required id="statement_bank_id"
                                                name="statement_bank_id">
                                            <?php
                                            foreach ($banks AS $banksRow) {
                                                $selected = $banksRow->id == $statement_bank_id ? "selected" : "";
                                                echo '<option ' . $selected . ' value="' . $banksRow->id . '">' . $banksRow->bank_name . ' - ' . $banksRow->bank_account_number . '</option>';
                                            }
                                            ?>
                                        </select>
                                        <label for="customer_name" class="control-label">Bank Account *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="particulars" maxlength="250"
                                               name="particulars"
                                               value="<?php echo $particulars; ?>"/>
                                        <label for="particulars" class="control-label">Particulars *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="amount"
                                               maxlength="30"
                                               name="amount"
                                               value="<?php echo $amount; ?>"/>
                                        <label for="amount" class="control-label">Amount
                                            *</label><br/>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <label class="control-label">Type</label><br>
                                        <select class="form-control" name="type">
                                            <option value="debit" <?php if ($type == 'debit') {
                                                echo "selected='selected'";
                                            } ?>>Debit
                                            </option>
                                            <option value="credit" <?php if ($type == 'credit') {
                                                echo "selected='selected'";
                                            } ?>>Credit
                                            </option>
                                        </select>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div id="status" class="input-field col s12">
                                        <select class="form-control" name="payment_type" id="payment_type">
                                            <option value="cash" <?php if ($payment_type == 'cash') {
                                                echo "selected='selected'";
                                            } ?>>Cash
                                            </option>
                                            <option value="cheque" <?php if ($payment_type == 'cheque') {
                                                echo "selected='selected'";
                                            } ?>>Cheque
                                            </option>
                                            <option value="online" <?php if ($payment_type == 'online') {
                                                echo "selected='selected'";
                                            } ?>>Online
                                            </option>
                                        </select>
                                        <label for="status" class="center-align">Payment Type</label>
                                    </div>
                                    <br/>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12" id="cheque_number_row">
                                        <input class="form-control" type="text" id="cheque_number"
                                               name="cheque_number"
                                               value='<?php echo $cheque_number; ?>'/>
                                        <label for="cheque_number" class="center-align">Cheque Number</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12" id="cheque_bank_row">
                                        <input class="form-control" type="text" id="cheque_bank"
                                               name="cheque_bank"
                                               value='<?php echo $cheque_bank; ?>'/>
                                        <label for="cheque_bank" class="center-align">Cheque Bank Name</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12" id="online_bank_row">
                                        <input class="form-control" type="text" id="online_bank"
                                               name="online_bank"
                                               value='<?php echo $online_bank; ?>'/>
                                        <label for="online_bank" class="center-align">Online Bank Name</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div id="status" class="input-field col s12">
                                        <label class="control-label">Status</label><br>
                                        <select class="form-control" name="status">
                                            <option value="active" <?php if ($status == 'active') {
                                                echo "selected='selected'";
                                            } ?>>Active
                                            </option>
                                            <option value="cancel" <?php if ($status == 'cancel') {
                                                echo "selected='selected'";
                                            } ?>>Cancel
                                            </option>
                                        </select>
                                    </div>
                                    <br/>
                                </div>
                                <div class="clearfix"></div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <?php if ($_SESSION['sess_role'] == 'VE' || $_SESSION['sess_role'] == 'VEC') { ?>
                                            <button id="btnsubmit" type="submit" class="btn waves-effect waves-light">
                                                Submit
                                            </button>
                                        <?php } ?>
                                        <button type="button" class="btn waves-effect waves-light"
                                                onclick="location.href='bank_transaction.php?view'">
                                            Cancel
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            <?php } ?>
        </div>
        <?php
        } ?>
    </div>
</div>
</div>
</div>
</div>
<?php include('../includes/inc_footer.php'); ?>

<?php include('../includes/inc_js.php'); ?>
<script type="application/javascript">
    $(document).ready(function () {
        var fewSeconds = 2;
        $('#btnsubmit').click(function () {
            // Ajax request
            var btn = $(this);
            btn.hide();
            setTimeout(function () {
                btn.show();
            }, fewSeconds * 1000);
        });
    });
</script>
<script type="text/javascript">
    /*Show entries on click hide*/
    $(document).ready(function () {
        $('#payment_type').material_select();
        <?php if(isset($_GET['edit']) && $payment_type == 'cheque'){?>
        $('#online_bank_row').hide();
        $('#online_bank').hide();
        $('#online_bank').attr('required', false);
        $('#online_bank').attr('disabled', true);
        $('#online_bank').rules('add', {
            required: false
        });

        $('#cheque_number_row').show();
        $('#cheque_number').show();
        $('#cheque_number').attr('required', true);
        $('#cheque_number').attr('disabled', false);
        $('#cheque_number').rules('add', {
            required: true,
            messages: {
                required: "<span class='label label-warning val_mes'>Please enter cheque number</span>"
            }
        });

        $('#cheque_bank_row').show();
        $('#cheque_bank').show();
        $('#cheque_bank').attr('required', true);
        $('#cheque_bank').attr('disabled', false);
        $('#cheque_bank').rules('add', {
            required: true,
            messages: {
                required: "<span class='label label-warning val_mes'>Please enter bank name</span>"
            }
        });

    <?php }else if(isset($_GET['edit']) && $payment_type == 'online'){?>
        $('#cheque_bank_row').hide();
        $('#cheque_bank').hide();
        $('#cheque_bank').attr('required', false);
        $('#cheque_bank').attr('disabled', true);
        $('#cheque_bank').rules('add', {
            required: false
        });

        $('#cheque_number_row').hide();
        $('#cheque_number').hide();
        $('#cheque_number').attr('required', false);
        $('#cheque_number').attr('disabled', true);
        $('#cheque_number').rules('add', {
            required: false
        });

        $('#online_bank_row').show();
        $('#online_bank').show();
        $('#online_bank').attr('required', true);
        $('#online_bank').attr('disabled', false);
        $('#online_bank').rules('add', {
            required: true,
            messages: {
                required: "<span class='label label-warning val_mes'>Please enter bank name</span>"
            }
        });
    <?php }else if(isset($_GET['edit']) && ($payment_type == 'cash' || $payment_type == '')){ ?>
        $('#cheque_bank_row').hide();
        $('#cheque_bank').hide();
        $('#cheque_bank').attr('required', false);
        $('#cheque_bank').attr('disabled', true);
        $('#cheque_bank').rules('add', {
            required: false
        });

        $('#cheque_number_row').hide();
        $('#cheque_number').hide();
        $('#cheque_number').attr('required', false);
        $('#cheque_number').attr('disabled', true);
        $('#cheque_number').rules('add', {
            required: false
        });

        $('#online_bank_row').hide();
        $('#online_bank').hide();
        $('#online_bank').attr('required', false);
        $('#online_bank').attr('disabled', true);
        $('#online_bank').rules('add', {
            required: false
        });
    <?php }else if($payment_type == ''){?>
        $('#cheque_bank_row').hide();
        $('#cheque_bank').hide();
        $('#cheque_bank').attr('required', false);
        $('#cheque_bank').attr('disabled', true);
        $('#cheque_bank').rules('add', {
            required: false
        });

        $('#cheque_number_row').hide();
        $('#cheque_number').hide();
        $('#cheque_number').attr('required', false);
        $('#cheque_number').attr('disabled', true);
        $('#cheque_number').rules('add', {
            required: false
        });

        $('#online_bank_row').hide();
        $('#online_bank').hide();
        $('#online_bank').attr('required', false);
        $('#online_bank').attr('disabled', true);
        $('#online_bank').rules('add', {
            required: false
        });
    <?php }?>
    });
    $(document).ready(function () {
        $(".dropdown-content.select-dropdown li").on("click", function () {
            var that = this;
            setTimeout(function () {
                if ($(that).parent().hasClass('active')) {
                    $(that).parent().removeClass('active');
                    $(that).parent().hide();
                }
            }, 100);
        });
        $('#payment_type').on('change', function () {
            if($(this).val() == 'cheque') {
                $('#online_bank_row').hide();
                $('#online_bank').hide();
                $('#online_bank').attr('required', false);
                $('#online_bank').attr('disabled', true);
                $('#online_bank').rules('add', {
                    required: false
                });

                $('#cheque_number_row').show();
                $('#cheque_number').show();
                $('#cheque_number').attr('required', true);
                $('#cheque_number').attr('disabled', false);
                $('#cheque_number').rules('add', {
                    required: true,
                    messages: {
                        required: "<span class='label label-warning val_mes'>Please enter cheque number</span>"
                    }
                });

                $('#cheque_bank_row').show();
                $('#cheque_bank').show();
                $('#cheque_bank').attr('required', true);
                $('#cheque_bank').attr('disabled', false);
                $('#cheque_bank').rules('add', {
                    required: true,
                    messages: {
                        required: "<span class='label label-warning val_mes'>Please enter bank name</span>"
                    }
                });
            } else if($(this).val() == 'online'){
                $('#cheque_bank_row').hide();
                $('#cheque_bank').hide();
                $('#cheque_bank').attr('required', false);
                $('#cheque_bank').attr('disabled', true);
                $('#cheque_bank').rules('add', {
                    required: false
                });

                $('#cheque_number_row').hide();
                $('#cheque_number').hide();
                $('#cheque_number').attr('required', false);
                $('#cheque_number').attr('disabled', true);
                $('#cheque_number').rules('add', {
                    required: false
                });

                $('#online_bank_row').show();
                $('#online_bank').show();
                $('#online_bank').attr('required', true);
                $('#online_bank').attr('disabled', false);
                $('#online_bank').rules('add', {
                    required: true,
                    messages: {
                        required: "<span class='label label-warning val_mes'>Please enter bank name</span>"
                    }
                });
            } else{
                $('#cheque_bank_row').hide();
                $('#cheque_bank').hide();
                $('#cheque_bank').attr('required', false);
                $('#cheque_bank').attr('disabled', true);
                $('#cheque_bank').rules('add', {
                    required: false
                });

                $('#cheque_number_row').hide();
                $('#cheque_number').hide();
                $('#cheque_number').attr('required', false);
                $('#cheque_number').attr('disabled', true);
                $('#cheque_number').rules('add', {
                    required: false
                });

                $('#online_bank_row').hide();
                $('#online_bank').hide();
                $('#online_bank').attr('required', false);
                $('#online_bank').attr('disabled', true);
                $('#online_bank').rules('add', {
                    required: false
                });
            }
        });
    });
</script>
</body>
</html>