<?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($_GET['delete'])) {
    $customerId = $_GET['delete'];

    $data = array();
    $data['status'] = 'deleted';

    CustomerSetup::UpdateCustomerSetup($customerId, $data);

    header("Location: " . PROJECT_ADMIN_URL . "customer_setup.php?view");
    exit();
}


$name = "";
$location = "";
$contact = "";
$email = "";
$short_code = "";
$gst = "";
$ntn = "";
$status = "";
$category_id = "";
$status = "";
$mart = "";
$discountdisable = "";
$discount_perc = "";
$add_discount_perc = "";
$middle_man = "";
$balance = "";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include('includes/inc_head.php'); ?>
</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>Customer Setup</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" style="font-size:12px;"></i></a>
                    <div class="clearfix"></div>
                <?php }
            } ?>
            <br/>
            <?php
            if (isset($_GET['add'])) {
            if (isset($_POST) && !empty($_POST)) {
                extract($_REQUEST);
                $data['code'] = __CUSTOMER__;
                $data['name'] = $name;
                $data['location'] = $location;
                $data['contact'] = $contact;
                $data['email'] = $email;
                $data['short_code'] = $short_code;
                $data['gst'] = $gst;
                $data['ntn'] = $ntn;
                $data['status'] = $status;
                $data['is_mart'] = $mart;
                $data['is_discountdisable'] = $discountdisable;
                $data['discount_perc'] = !empty($discount_perc) ? $discount_perc : 0;
              $data['balance'] = !empty($balance) ? $balance : 0;

                $data['add_discount_perc'] = !empty($add_discount_perc) ? $add_discount_perc : 0;
               // $data['middle_man'] = $middle_man;
                $data['category_id'] = $category_id;
                $data['datetime'] = date('Y-m-d H:i:s');
                $usercheck = CustomerSetup::CheckCustomer($name, 0);
              
              
				print_r($data);
                $errors = array();
                // Validate the input

                if ((strlen($name) == 0) || (strlen($name) > 255))
                    array_push($errors, "Please enter customer name");
                if ((strlen($location) == 0))
                    array_push($errors, "Please enter location");
                if ((strlen($contact) == 0))
                    array_push($errors, "Please enter contact");
                //if ((!filter_var($email, FILTER_VALIDATE_EMAIL)) || ((strlen($email) > 50)))
                //array_push($errors, "Invalid email format");
                if ($usercheck)
                    array_push($errors, "customer name already exist");
                if ($mart == 1) {
                    if ((strlen($name) == 0) || (strlen($name) > 255)) {
                        array_push($errors, "Please enter middle name");
                    }
                }
            if (count($errors) == 0) {
                $q = CustomerSetup::AddCustomerSetup($data);

                //Ledger Add Functionality
                $dataLedger['scheem_name'] = "customer";
                $dataLedger['head'] = $q;
                $dataLedger['figure'] = 0;
                $dataLedger['datetime'] = 'NOW()';

                $led = Ledger::AddLedger($dataLedger);
                //Ledger Add Functionality

            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="customer_setup_form" novalidate="novalidate">
                        <div class="col s12">
                            <?php echo $output; ?>
                            <div class="col s8">
                                <div class="row">
                                    <span>(*) Mark Fields are mandatory</span><br/><br/>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="name" maxlength="250"
                                               name="name"
                                               value='<?php echo $name; ?>'/>
                                        <label for="name" class="control-label">Customer Name *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                                <textarea class="materialize-textarea" id="location"
                                                          name="location"><?php echo $location; ?></textarea>
                                        <label for="location" class="control-label">Location *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="contact" name="contact"
                                               value='<?php echo $contact; ?>'/>
                                        <label for="contact" class="control-label">Contact *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="email" name="email"
                                               maxlength="50"
                                               value='<?php echo $email; ?>'/>
                                        <label for="email" class="control-label">Email</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="short_code" name="short_code"
                                               maxlength="15"
                                               value='<?php echo $short_code; ?>'/>
                                        <label for="short_code" class="control-label">Short Code</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="gst" name="gst"
                                               maxlength="15"
                                               value='<?php echo $gst; ?>'/>
                                        <label for="gst" class="control-label">GST</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="ntn" name="ntn"
                                               maxlength="15"
                                               value='<?php echo $ntn; ?>'/>
                                        <label for="ntn" class="control-label">NTN</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <select class="form-control" name="discountdisable" id="discountdisable">
                                            <option value="0" <?php if ($discountdisable == '0') {
                                                echo "selected='selected'";
                                            } ?>>No
                                            </option>
                                            <option value="1" <?php if ($discountdisable == '1') {
                                                echo "selected='selected'";
                                            } ?>>Yes
                                            </option>
                                        </select>
                                        <label for="discountdisable" class="control-label">Discount Disable</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div id="discount_detail" class="input-field col s12" style="display: none;">
                                        <input class="form-control" type="text" id="discount_perc"
                                               name="discount_perc"
                                               maxlength="2"
                                               value='<?php echo $discount_perc; ?>'/>
                                        <label for="discount_perc" class="control-label">Discount Percentage</label><br>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div id="add_discount_detail" class="input-field col s12" style="display: none;">
                                        <input class="form-control" type="text" id="add_discount_perc"
                                               name="add_discount_perc"
                                               maxlength="2"
                                               value='<?php echo $add_discount_perc; ?>'/>
                                        <label for="add_discount_perc" class="control-label">Additional Discount Percentage</label><br>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <select class="form-control" name="mart" id="mart">
                                            <option value="0" <?php if ($mart == '0') {
                                                echo "selected='selected'";
                                            } ?>>No
                                            </option>
                                            <option value="1" <?php if ($mart == '1') {
                                                echo "selected='selected'";
                                            } ?>>Yes
                                            </option>
                                        </select>
                                        <label for="mart" class="control-label">Mart</label><br>
                                    </div>
                                </div>
<!--                                <div class="row margin">-->
<!--                                    <div id="mart_detail" class="input-field col s12" style="display: none;">-->
<!--                                        <input class="form-control" type="text" id="middle_man"-->
<!--                                               name="middle_man"-->
<!--                                               maxlength="255"-->
<!--                                               value='--><?php //echo $middle_man; ?><!--'/>-->
<!--                                        <label for="middle_man" class="control-label">Distributor Name</label><br>-->
<!--                                    </div>-->
<!--                                </div>-->
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <?php
                                        $filterCategory = " ORDER BY name";
                                        $qryCategory = CustomerCategorySetup::GetCustomerCategorySetupList($filterCategory);
                                        if ($qryCategory) {
                                            echo '<select id="category_id" name="category_id" class="form-control">';
                                            foreach ($qryCategory as $qery) {
                                                echo '<option value=' . $qery->id . '>' . $qery->name . '</option>';
                                            }
                                            echo '</select>';
                                        }
                                        ?>
                                        <label for="category_id" class="control-label">Category *</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="inactive" <?php if ($status == 'inactive') {
                                                echo "selected='selected'";
                                            } ?>>Inactive
                                            </option>
                                        </select>
                                        <label for="status" class="control-label">Status</label>
                                    </div>
                                </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>
                                <a href="customer_setup.php?view">
                                    <button type="button" class="btn waves-effect waves-light">Cancel</button>
                                </a>
                            </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="responsive-table display">
                        <thead>
                        <tr>
                            <th>Action</th>
                            <th>Customer Name</th>
                            <th>Category</th>
                            <th>Location</th>
                            <th>Contact</th>
                            <th>Email</th>
                            <th>Mart</th>
                            <th>Discount Disable</th>
                            <th>Discount Percentage</th>
                            <th>Additional Discount</th>
                            <th>OP Balance</th>
                            <th>Status</th>
                            <th>Date</th>
                        </tr>
                        </thead>
                        <tfoot>
                        <tr>
                            <th>Action</th>
                            <th>Customer Name</th>
                            <th>Category</th>
                            <th>Location</th>
                            <th>Contact</th>
                            <th>Email</th>
                            <th>Mart</th>
                            <th>Discount Disable</th>
                            <th>Discount Percentage</th>
                            <th>Additional Discount</th>
                            <th>OP Balance</th>
                            <th>Status</th>
                            <th>Date</th>
                        </tr>
                        </tfoot>
                        <tbody>
                        <?php
                        $qry = CustomerSetup::GetCustomerSetupList();
                        if ($qry) {
                            foreach ($qry as $qery) {
                               if ($qery->status == 'deleted') {
            continue;
        }
                                $catId = CustomerCategorySetup::GetCustomerCategorySetupById($qery->category_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>
                                      
                                      <a style="cursor:pointer;font-size: 10px;padding: 1px;" title="Delete">
                                                <span
                                                    style="width: 60px; height: 20px; border-radius: 5%; font-size: 12px; line-height: 20px;"
                                                    class="btn-warning-confirm<?= $qery->id ?> mini-stat-icon deep-orange darken-3"><i class="fa fa-arrows-alt">Delete</i></span>
                                            </a>
                                            <script>
                                                $('.btn-warning-confirm<?= $qery->id ?>').click(function () {
                                                    swal({
                                                            title: "Are you sure?",
                                                            text: "Are you sure change status to Delete?",
                                                            type: "warning",
                                                            showCancelButton: true,
                                                            confirmButtonColor: '#DD6B55',
                                                            confirmButtonText: 'Yes',
                                                            closeOnConfirm: false
                                                        },
                                                        function () {
                                                            swal("Successful!", "Your status has been Deleted!", "success");
                                                            window.location.href = 'customer_setup.php?delete=<?php echo $qery->id; ?>';
                                                        });
                                                });
                                            </script>
                                        <?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 } ?>
                                    </td>
                                    <td><?php echo ucwords($qery->name); ?></td>
                                    <td><?php echo ucwords($catId->name); ?></td>
                                    <td><?php echo ucwords($qery->location); ?></td>
                                    <td><?php echo $qery->contact; ?></td>
                                    <td><?php echo $qery->email; ?></td>
                                    <td><?= $qery->is_mart == 1 ? 'Yes' : 'No'; ?></td>
                                    <td><?= $qery->is_discountdisable == 1 ? 'Yes' : 'No'; ?></td>
                                    <td><?php echo $qery->discount_perc; ?></td>
                                    <td><?php echo $qery->add_discount_perc; ?></td>
                                    <td><?php echo $qery->balance; ?></td>
                                    <td><?= ($qery->status == 'active') ? ucwords($qery->status) : "Inactive"; ?></td>
                                    <td><?php echo $qery->datetime; ?></td>
                                </tr>
                                <?php
                            }
                        } ?>
                        </tbody>
                    </table>
                </div>
                <?php

            } // close view


            if (isset($_GET['edit']) && !empty($_POST)) {
                extract($_REQUEST);
                $id = $_GET['id'];

                $data['name'] = $name;
                $data['location'] = $location;
                $data['contact'] = $contact;
                $data['email'] = $email;
                $data['short_code'] = $short_code;
                $data['gst'] = $gst;
                $data['ntn'] = $ntn;
                $data['status'] = $status;
                $data['is_discountdisable'] = $discountdisable;
                $data['discount_perc'] = $discount_perc;
                $data['add_discount_perc'] = $add_discount_perc;
//                if(isset($middle_man)){
//                    $data['middle_man'] = $middle_man;
//                }
                $data['category_id'] = $category_id;
                $data['datetime'] = 'NOW()';
                $usercheck = CustomerSetup::CheckCustomer($name, $id);

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

                if ((strlen($name) == 0) || (strlen($name) > 255))
                    array_push($errors, "Please enter customer name");
                if ((strlen($location) == 0))
                    array_push($errors, "Please enter location");
                if ((strlen($contact) == 0))
                    array_push($errors, "Please enter contact");
                //if ((!filter_var($email, FILTER_VALIDATE_EMAIL)) || ((strlen($email) > 50)))
                //array_push($errors, "Invalid email format");

                if ($usercheck)
                    array_push($errors, "Customer name already exist");

                if (count($errors) == 0) {
                    $q = CustomerSetup::UpdateCustomerSetup($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 = CustomerSetup::GetCustomerSetupById($id);
                    $name = $qry->name;
                    $name = $qry->name;
                    $category_id = $qry->category_id;
                    $location = $qry->location;
                    $contact = $qry->contact;
                    $email = $qry->email;
                    $discountdisable = $qry->is_discountdisable;
                    $discount_perc = $qry->discount_perc;
                    $add_discount_perc = $qry->add_discount_perc;
//                    $middle_man = $qry->middle_man;
                    $is_mart = $qry->is_mart;
                    $short_code = $qry->short_code;
                    $gst = $qry->gst;
                    $ntn = $qry->ntn;
                    $status = $qry->status;

                    $custCat = CustomerCategorySetup::GetCustomerCategorySetupById($category_id);
                    $customerCategory = $custCat->name;
                }
                if ($_REQUEST['id'] && isset($_REQUEST['v'])) {
                    ?>
                    <style>
                        h4 {
                            float: left;
                            margin: 0;
                            width: 30%;
                        }

                        p {
                            float: left;
                        }

                        .activity-icon {
                            margin: 0;
                        }
                    </style>
                    <div class="row">
                        <!--  The form that will be parsed by jQuery before submit  -->
                        <div class="col s12 form-group">
                            <div class="col s8">
                                <div class="row">
                                    <div class="col s6">Customer Name:</div>
                                    <div class="col s6"><?php echo $name; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Customer Code:</div>
                                    <div class="col s6"><?php echo $code; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Location:</div>
                                    <div class="col s6"><?php echo $location; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Contact:</div>
                                    <div class="col s6"><?php echo $contact; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Email:</div>
                                    <div class="col s6"><?php echo $email; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Short Code:</div>
                                    <div class="col s6"><?php echo $short_code; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">GST:</div>
                                    <div class="col s6"><?php echo $gst; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">NTN:</div>
                                    <div class="col s6"><?php echo $ntn; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Category:</div>
                                    <div class="col s6"><?php echo $customerCategory; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Discount Disable:</div>
                                    <div class="col s6">
                                        <?php if ($discountdisable == '1') {
                                            echo "Yes";
                                        } else {
                                            echo "No";
                                        } ?>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Discount Percentage:</div>
                                    <div class="col s6"><?php echo $discount_perc; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Additional Discount Percentage:</div>
                                    <div class="col s6"><?php echo $add_discount_perc; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Status</div>
                                    <div class="col s6">
                                        <?php
                                        if ($status == 'active') {
                                            echo "Active";
                                        } else if ($status == 'inactive') {
                                            echo "Inactive";
                                        } ?>
                                    </div>
                                </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="customer_setup_form"
                              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" type="text" id="name" maxlength="250"
                                                   name="name"
                                                   value="<?php echo $name; ?>"/>
                                            <label for="name" class="control-label">Customer Name *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                                <textarea class="materialize-textarea" id="location"
                                                          name="location"><?php echo $location; ?></textarea>
                                            <label for="location" class="control-label">Location *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <input class="form-control" type="text" id="contact" name="contact"
                                                   value='<?php echo $contact; ?>'/>
                                            <label for="contact" class="control-label">Contact *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <input class="form-control" type="text" id="email" name="email"
                                                   maxlength="50"
                                                   value='<?php echo $email; ?>'/>
                                            <label for="email" class="control-label">Email </label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <input class="form-control" type="text" id="short_code" name="short_code"
                                                   maxlength="15"
                                                   value='<?php echo $short_code; ?>'/>
                                            <label for="short_code" class="control-label">Short Code</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <input class="form-control" type="text" id="gst" name="gst"
                                                   maxlength="15"
                                                   value='<?php echo $gst; ?>'/>
                                            <label for="gst" class="control-label">GST</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <input class="form-control" type="text" id="ntn" name="ntn"
                                                   maxlength="15"
                                                   value='<?php echo $ntn; ?>'/>
                                            <label for="ntn" class="control-label">NTN</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <select class="form-control" name="discountdisable" id="discountdisable">
                                                <option value="0" <?php if ($discountdisable == '0') {
                                                    echo "selected='selected'";
                                                } ?>>No
                                                </option>
                                                <option value="1" <?php if ($discountdisable == '1') {
                                                    echo "selected='selected'";
                                                } ?>>Yes
                                                </option>
                                            </select>
                                            <label for="discountdisable" class="control-label">Discount Disable</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div id="discount_detail" class="input-field col s12" style="display: none;">
                                            <input class="form-control" type="text" id="discount_perc"
                                                   name="discount_perc"
                                                   maxlength="2"
                                                   value='<?php echo $discount_perc; ?>'/>
                                            <label for="discount_perc" class="control-label">Discount
                                                Percentage</label><br>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div id="add_discount_detail" class="input-field col s12" style="display: none;">
                                            <input class="form-control" type="text" id="add_discount_perc"
                                                   name="add_discount_perc"
                                                   maxlength="2"
                                                   value='<?php echo $add_discount_perc; ?>'/>
                                            <label for="add_discount_perc" class="control-label">Additional Discount
                                                Percentage</label><br>
                                        </div>
                                    </div>
<!--                                    --><?php //if($is_mart == 1){ ?>
<!--                                        <div class="row margin">-->
<!--                                            <div class="input-field col s12">-->
<!--                                                <input class="form-control" type="text" id="middle_man"-->
<!--                                                       name="middle_man"-->
<!--                                                       maxlength="255"-->
<!--                                                       value='--><?php //echo $middle_man; ?><!--'/>-->
<!--                                                <label for="middle_man" class="control-label">Distributor Name</label><br>-->
<!--                                            </div>-->
<!--                                        </div>-->
<!--                                    --><?php //} ?>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <?php
                                            $filterCategory = " ORDER BY name";
                                            $qryCategory = CustomerCategorySetup::GetCustomerCategorySetupList($filterCategory);
                                            if ($qryCategory) {
                                                echo '<select id="category_id" name="category_id" class="form-control">';
                                                foreach ($qryCategory as $qery) {
                                                    if ($qery->id == $category_id) {
                                                        $select = "selected";
                                                    } else {
                                                        $select = "";
                                                    }
                                                    echo '<option ' . $select . ' value=' . $qery->id . '>' . $qery->name . '</option>';
                                                }
                                                echo '</select>';
                                            }
                                            ?>
                                            <label for="category_id" class="control-label">Category *</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="inactive" <?php if ($status == 'inactive') {
                                                    echo "selected='selected'";
                                                } ?>>Inactive
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </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 } ?>
                                    <a href="customer_setup.php?view">
                                        <button type="button" class="btn waves-effect waves-light">Cancel</button>
                                    </a>
                                </div>
                            </div>
                        </form>
                    </div>
                <?php } ?>
                <?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 () {
        if ($('#mart').val() == 1) {
            $('#mart_detail').show();
        } else {
            $('#mart_detail').hide();
        }
        if ($('#discountdisable').val() == 0) {
            $('#discount_detail').show();
            $('#add_discount_detail').show();
        } else {
            $('#discount_detail').hide();
            $('#add_discount_detail').hide();
        }
    });
    $('#mart').on('change', function () {
        if ($(this).val() == 1) {
            $('#mart_detail').show();
        } else {
            $('#mart_detail').hide();
        }
    });
    $('#discountdisable').on('change', function () {
        if ($(this).val() == 0) {
            $('#discount_detail').show();
            $('#add_discount_detail').show();
        } else {
            $('#discount_detail').hide();
            $('#add_discount_detail').hide();
        }
    });
</script>
<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>
</body>
</html>