<?php
require("config/config.php");
if (!empty($_GET['page'])) {
    $c_page = $_GET['page'];
} else {
    $c_page = "1";
}
$search_name = $_REQUEST['search_customer_name'];
$search_code = $_REQUEST['search_customer_code'];
$vendor_from = $_REQUEST['vendor_from'];

$search_cond = "";
if (!empty($search_code)) {
    $search_cond .= " and a.code = '" . $db_cust->escape($search_code) . "'";
}

if (!empty($vendor_from)) {
    $search_cond .= " and a.vendor_from = '" . $db_cust->escape($vendor_from) . "'";
}

if (!empty($search_name)) {
    $search_cond .= " and a.name like '" . $db_cust->escape($search_name) . "%'";
}
$cnt_sql = "select count(a.vendor_id) as total_cnt from master_vendors as a where a.is_deleted = 0 " . $search_cond;
$result = $db_cust->query_first($cnt_sql);
$total_cnt = $result['total_cnt'];

$a = new Paginator_html($c_page, $total_cnt);
$a->set_Limit(RECORDS_PER_PAGE);
$a->set_Links(1);
$limit1 = $a->getRange1();
$limit2 = $a->getRange2();
$limit = $limit1 . ',' . $limit2;

$sql = "SELECT a.vendor_id,b.address_id,
                a.application_date,
                a.category,
                a.vendor_type,
                a.vendor_group,
		a.code,
		a.name,
                a.cin_number,
                a.stn_number,
		b.phone,
		b.address,
                b.address_2,
                b.address_3,
		b.city,
                b.pin,
                a.pan_number,
                b.email,
                b.country,
                b.state,
                b.website,
                a.ceo,
                b.fax,
                b.gst_type,
                b.is_sez,
                b.gst_number,
                b.address_type,
                a.contact_person,
                a.contact_designation,
                a.contact_person_email_id,
                a.contact_person_phone,
                a.created_ts,
                a.vendor_from,
                a.created_by,
                a.updated_by,
                a.updated_ts FROM master_vendors as a "
                ." inner join master_vendors_address as b on a.vendor_id = b.vendor_id where (b.address_type ='CA' || b.address_type ='RA') and a.is_deleted = 0 " . $search_cond . " ORDER BY a.created_ts desc limit $limit";
$data = $db_cust->query($sql);
?>
<div class="btn-group button">
    <a href="javascript:void(0)" class="btn tooltip_show" oldtitle="Forward" aria-describedby="ui-tooltip-20" data-original-title="Add New Record" data-placement="bottom" rel="tooltip" id="add_new_customer" onclick="add_new_customer()"><i class="icon-plus"></i></a>
    <a href="javascript:void(0)" class="delete_msg btn tooltip_show" data-tableid="dt_inbox" oldtitle="Delete" aria-describedby="ui-tooltip-21" data-original-title="Delete Record" data-placement="bottom" rel="tooltip" id="delete_customer" onclick="delete_confirm('bulk')"><i class="icon-trash"></i></a> 
</div>
<?php if ($total_cnt > 0) { ?>
    <input type="hidden" id="hid_delele_ids" name="hid_delele_ids" value="" /> 
    <input type="hidden" id="hid_paging_params" name="hid_paging_params" value="vendor_from=<?php echo $vendor_from; ?>&search_customer_name=<?php echo $search_name; ?>&search_customer_code=<?php echo $search_code; ?>" />         
    <div class="tables">
        <div class="row-fluid">
            <div class="span12">
                <div class="row-fluid sepH_c">
                    <div style="width:100%;">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th class="table_checkbox sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 12px; " aria-label=""><input type="checkbox" data-tableid="dt_inbox" class="select_msgs" name="select_all" id="select_all" onclick="select_all()"></th>
                                    <th style="width:25%;">Customer Details</th>
                                    <th style="width:10%;">Vendor Type</th>
                                    <th style="width:21%;">Customer Contact Details</th>
                                    <th style="width:10%;">Added By</th>
                                    <th style="width:15%;">Created On</th>
                                    <th class="last">Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                while ($record = $db_cust->fetch_array($data)) {
                                    ?>
                                    <tr>
                                        <td class="nohref "  width="4%"><input type="checkbox" class="select_msg" name="id[]" id="id" value="<?php echo $record['vendor_id'] ?>" /></td>
                                        <td width="25%"><span><b><?php echo $record['name'] ?></b></span> |
                                            <span>Group:</span><span><?php 
                                            if ($record['vendor_group'] == "NONMEM"){ 
                                                echo 'Non Member'; 
                                            }else if($record['vendor_group'] == "MEMBER"){ 
                                               echo "MEMBER"; 
                                            }else{
                                                echo 'Non Member Foreign'; 
                                            } 
                                                ?>
                                            </span> |
                                            <span>Code:</span><span><?php echo $record['code'] ?></span> |
                                            <span>Application Date:</span><span><?php echo $record['application_date'] ?></span> |
                                            <span>Category:</span><span><?php echo $record['category'] ?></span> |
                                            <span>GSTIN:</span><span><?php if(!empty($record['gst_number'])){ echo $record['gst_number'];} else { echo 'N/A'; } ?></span> |
                                            <span>GST Type:</span><span><?php if(!empty($record['gst_number'])) { if($record['gst_type']==1){echo 'Custom';} else { echo 'Life Time'; } } else { echo "-"; } ?></span> |
                                            <span>PAN:</span><span><?php echo $record['pan_number'] ?></span> |
                                            <span>CIN:</span><span><?php echo $record['cin_number'] ?></span> |
                                            <span>STN:</span><span><?php echo $record['stn_number'] ?></span> |
                                            <span>Is SEZ:</span><span><?php if($record['is_sez']==1){echo ' Yes';} else { echo ' No'; } ?></span>
                                        </td>
                                        <td width="10%">
                                            <?php if($record['vendor_type']=="M") { echo "<span class='label label-success'>Member</span>"; } else { echo "<span class='label label-danger' style='background-color: #da4f49;'>Customer</span>"; } ; ?>
                                        </td>
                                        <td  width="21%">
                                            <span>Address Type:</span><span><?php echo " ".$record['address_type'] ?></span> |
                                            <span>Contact Name:</span><span><?php echo $record['name'] ?></span> |
                                            <span>Address:</span><span><?php echo $record['address'] . " " . $record['address_2'] . " " . $record['address_3'] . " " . $record['city'] . " " . $record['state'] . " " . $record['country']; ?>
                                            </span>|
                                            <span>Phone:</span><span><?php echo $record['phone'] . "," . $record['contact_person_phone']; ?></span> |
                                            <span>Website:</span><span><?php echo $record['website'] ?></span> 
                                        </td>
                                        <td><?php if ($record['vendor_from'] == 1) {
                                echo 'IMTEX';
                            } else if ($record['vendor_from'] == 2) {
                                echo 'BIEC Billing';
                            } else if ($record['vendor_from'] == 3) {
                                echo 'MTX';
                            } else if ($record['vendor_from'] == 4) {
                                echo 'MEMBER';
                            } else if ($record['vendor_from'] == 5) {
                                echo 'PMS';
                            } ?></td>
                                        <td><?php echo $record['created_ts'] ?></td>
                                        <td class="last" width="20%"> 
                                            <?php if($record['vendor_from'] == 1 || $record['vendor_from'] == 2 || $record['vendor_from'] == 3) { ?>
                                            <a href="javascript:void(0)" onclick="edit_vendor(<?php echo $record['vendor_id'] ?>)" class="sepV_a tooltip_show" data-original-title="Edit Permission" data-placement="bottom" rel="tooltip"><i class="icon-pencil"></i></a>
                                            <a href="javascript:void(0)" class="tooltip_show" onclick="delete_confirm('single',<?php echo $record['vendor_id'] ?>)"  data-original-title="Delete Record" data-placement="bottom" rel="tooltip"><i class="icon-trash"></i></a>
                                            <?php } ?>
                                        </td>
                                    </tr>      
    <?php } ?> 
                            </tbody>
                        </table>
                    </div>
                    <div class="list_pagination">
                        <div class="row">
                            <div class="span6">
                                <div class="dataTables_info" id="dt_inbox_info">Showing  <?php echo $a->getFirstOf(); ?> to <?php echo $a->getSecondOf(); ?> of <?php echo $a->getTotalItems(); ?> entries</div>
                            </div>
                            <div class="span6">
                                <div class="dataTables_paginate paging_bootstrap pagination">
    <?php
    $current_page = basename($_SERVER['SCRIPT_NAME']);
    echo $prev = $a->previousNext($current_page);
    ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php } else { ?>

    <div id="alltasksWrapper" style="margin-top:20px;">
        <div class="minHeight">
            <div id="blankSlate" class="blankSlate">
                <h3>No Records Found</h3>
            </div>
        </div>
    </div>
<?php } $db_cust->close(); ?>

