<?php 
define('DOCUMENT_ROOT_CLASS','../../');
define('DOCUMENT_ROOT_INC_FOLDER','inc/');
$filepath = realpath(dirname(__FILE__));
require "../../inc/header.php";
$msg = Session::get('msg');
Session::set("msg", NULL);
$serviceData = $commonFunctions->getRowData('invty_srvs_details'," WHERE id = '".@$_GET['service_id']."' ");
?>

    <!-- Page-Title -->
    <div class="row">
        <div class="col-sm-12">
            <div class="page-title-box">
                <div class="row">
                    <div class="col form-row">
                    	<div class="col-sm-9">
                            <h4 class="page-title"><?php echo @$serviceData['label'];?></h4>
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="javascript:void(0);">Products & Services</a></li>
                                <li class="breadcrumb-item"><a href="javascript:void(0);">Services</a></li>
                                <li class="breadcrumb-item"><a href="javascript:void(0);">Services Details</a></li>
                            </ol>
                        </div>
                        <div class="col-sm-3">
                            <a href="services.php?state=edit&service_id=<?php echo $serviceData['id'];?>">
                            	<button type="button" class="btn btn-sm btn-outline-primary">Edit</button>
                            </a>
                            <a href="services.php?state=copy&service_id=<?php echo $serviceData['id'];?>">
                            	<button type="button"class="btn btn-sm btn-outline-dark">Duplicate</button>
                            </a>
                            <a href="services.php?state=list"><button type="button" class="btn btn-sm btn-outline-secondary clear_form">Back to Services List</button></a>
                            <!-- <button type="button" class="btn btn-sm btn-outline-danger">Delete</button> -->
                        </div>
                    </div><!--end col-->
                </div><!--end row-->                                                              
            </div><!--end page-title-box-->
        </div><!--end col-->
    </div><!--end row-->
    <!-- end page title end breadcrumb -->

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <div class="dastone-profile">
                        <div class="row">
                            <div class="col-lg-3 align-self-center mb-lg-0">
                                <div class="dastone-profile-main">
                                    <div class="dastone-profile_user-detail">
                                        <img src="../../uploads/product-services/service-images/<?php echo @$serviceData['service_image'];?>" width="80px">                                              
                                    </div>
                                </div>                                                
                            </div><!--end col-->
                            <div class="col-lg-4 align-self-center mb-lg-0">
                                <div class="dastone-profile-main">
                                    <div class="dastone-profile_user-detail">
                                        <?php 
                                        $barcode_type = $commonFunctions->getname($serviceData['barcode_type'],'sys_erp_adm_barcode_type','label','id');
                                        ?>
                                        <div id="barcodeTarget" class="barcodeTarget"></div>
										<canvas id="canvasTarget" width="150" height="150"></canvas>
                                    </div>
                                </div>                                                
                            </div><!--end col-->
                            <div class="col-lg-5 align-self-center mb-lg-0">
                                <div class="dastone-profile-main">
                                    <div class="dastone-profile_user-detail">
                                    	<b><?php echo @$serviceData['label'];?></b><br>
                                    </div>
                                </div>                                                
                            </div><!--end col-->

                        </div><!--end row-->
                    </div><!--end f_profile-->                                                                                
                </div><!--end card-body-->          
            </div> <!--end card-->    
        </div><!--end col-->
    </div><!--end row-->
    <div class="pb-4">
        <ul class="nav-border nav nav-pills mb-0" id="pills-tab" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" id="product_details_tab" data-toggle="pill" href="#product_details">Services Details</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="purchase_details_tab" data-toggle="pill" href="#purchase_details">Purchase Details</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="related_invoice_tab" data-toggle="pill" href="#related_invoice">Related Invoice</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="statistics_tab" data-toggle="pill" href="#statistics">Statistics</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="note_tab" data-toggle="pill" href="#note">Note</a>
            </li>
        </ul>        
    </div><!--end card-body-->
    <style type="text/css">
    	label.form-control1 {display: block;}
    	label.label-title {font-weight: 600;}
    </style>
    <div class="row">
        <div class="col-12">
            <div class="tab-content" id="pills-tabContent">
                <div class="tab-pane fade show active" id="product_details" role="tabpanel" aria-labelledby="product_details_tab">
                	<div class="card">
                		<div class="card-body">
                			<div class="form-row">
                				<div class="col-md-6">
	                        		<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline" style="border-collapse: collapse; border-spacing: 0px; width: 100%;" role="grid" aria-describedby="datatable-buttons_info">
                                    	<thead>
                                        	<tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Label / Services Name</td>
	                                            <td style=""><?php echo @$serviceData['label'];?></td>
	                                        </tr>
                                    	</thead>
                                    	<tbody>
                                    		<tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Reference Number</td>
	                                            <td style=""><?php echo @$serviceData['reference_number'];?></td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Barcode Value</td>
	                                            <td style=""><?php echo @$serviceData['barcode_value'];?></td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Barcode Type</td>
	                                            <td style=""><?php
			                                    $barcodeArr = $commonFunctions->getData('sys_erp_adm_barcode_type',' WHERE active = 1 ');
			                                    foreach ($barcodeArr as $row) { ?>
			                                        <?php echo (@$serviceData['barcode_type'] == $row['id'])?$row['label']:"";?>
			                                    <?php } ?></td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Nature</td>
	                                            <td style="">
	                                            	<?php echo (@$serviceData['nature'] == 0)?"Raw Material":"";?>
	                                    			<?php echo (@$serviceData['nature'] == 1)?"Manufactured Product":"";?>
	                                            </td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Tags / Categories</td>
	                                            <td style="">
	                                            	<?php $TagData = $commonFunctions->getData('invty_svs_tag',''); ?>
	                                    
				                                    <?php foreach ($TagData as $rw) { ?>
				                                        <?php if(@$serviceData['tag_id'] == $rw['id']){
					                                        if($rw['parent_id'] > 0){
					                                            echo $commonFunctions->getName($rw['parent_id'],'crm_cust_tag','label','id')." >> ";           
					                                        }
					                                        echo $rw['label']; 
					                                    } ?>
				                                    <?php } ?>
	                                            </td>
	                                        </tr>

	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Warehouse</td>
	                                            <td style="">
	                                            	<?php $warehouseData = $commonFunctions->getData('invty_wrhus',' WHERE status = 0 '); ?>
				                                    <?php foreach ($warehouseData as $rw) { ?>
				                                        <?php echo (@$serviceData['default_warehouse_id'] == $rw['id'])?$rw['short_name_location']:"";?>
				                                    <?php } ?>
	                                            </td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Use Lot / Serial Number</td>
	                                            <td style="">
	                                            	<?php echo (@$serviceData['lot_serial_status'] == 0)?"No ( Lot / Serial not Used )":"";?><?php echo (@$serviceData['lot_serial_status'] == 1)?"Yes ( Lot / Serial Required )":"";?>
	                                            </td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="">Note (not visible on Invoices, Proposals...)</td>
	                                            <td style="">	
				                                    <?php echo @$serviceData['note'];?>
	                                            </td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="">Selling Type</td>
	                                            <td style="">	
				                                    <?php echo (@$serviceData['selling_type'] == 0)?"Fixed Amount":"";?><?php echo (@$serviceData['selling_type'] == 1)?"Recurring Amount":"";?>
	                                            </td>
	                                        </tr>
                                    	</tbody>
                                    </table>
                                </div>
                                <div class="col-md-6">
	                        		<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline" style="border-collapse: collapse; border-spacing: 0px; width: 100%;" role="grid" aria-describedby="datatable-buttons_info">
                                    	<thead>
                                        	<tr role="row" class="even">
	                                            <td tabindex="0" class="sorting_1">Sales Status</td>
	                                            <td style=""><?php echo (@$serviceData['sales_status'] == 1)?"For Sale":"";?><?php echo (!empty($serviceData) and @$serviceData['sales_status'] == 0)?"Not For Sale":"";?></td>
	                                        </tr>
	                                    </thead>
	                                    <tbody>
	                                        <tr role="row" class="odd">
	                                            <td tabindex="0" class="">Purchase Status</td>
	                                            <td style="">
	                                            	<?php echo (@$serviceData['purchase_status'] == 1)?"For Purchase":"";?>
	                                    			<?php echo (!empty($serviceData) and @$serviceData['purchase_status'] == 0)?"Not For Purchase":"";?>
	                                            </td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="">Selling Price</td>
	                                            <td style="">	
				                                    <div style="display: flex;">
					                                    <label style="width:70%" class="form-control1">
					                                    	<?php echo (empty(@$serviceData['price']))?0:@$serviceData['price'];?>
					                                    </label>
					                                    <label class="form-control1" style="width:30%">
					                                        <?php echo (@$serviceData['nature'] == "HT")?"Net of TAX":"";?>
					                                        <?php echo (@$serviceData['nature'] == "TTC")?"Inc. TAX":"";?>
					                                    </label>
					                                </div>
	                                            </td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="">Stock Limit for Alert</td>
	                                            <td style="">	
				                                    <?php echo (empty(@$serviceData['stock_limit_alert']))?0:@$serviceData['stock_limit_alert'];?>
	                                            </td>
	                                        </tr>
	                                        <tr role="row" class="even">
	                                            <td tabindex="0" class="">Desired Optimal Stock</td>
	                                            <td style="">	
				                                    <?php echo (empty(@$serviceData['desired_optimal_stock']))?0:@$serviceData['desired_optimal_stock'];?>
	                                            </td>
	                                        </tr>
	                                       <tr role="row" class="even">
	                                            <td tabindex="0" class="">Duration</td>
	                                            <td style="">	
				                                    <div style="display: flex;">   
					                                    <label type="text" class="form-control1" style="width:70%">
					                                    	<?php echo @$serviceData['duration'];?>
					                                    </label>
					                                    <label class="form-control1" style="width:30%">
					                                        <?php echo (@$serviceData['nature'] == "i")?"I":"";?><?php echo (@$serviceData['nature'] == "h")?"H":"";?><?php echo (@$serviceData['nature'] == "d")?"D":"";?><?php echo (@$serviceData['nature'] == "w")?"W":"";?><?php echo (@$serviceData['nature'] == "m")?"M":"";?><?php echo (@$serviceData['nature'] == "y")?"Y":"";?>
					                                    </label>
					                                </div>
	                                            </td>
	                                        </tr>
	                                        
                                    	</tbody>
                                    </table>
                                </div>
                			</div>
	                    </div>
                	</div>
                </div>
                <div class="tab-pane" id="purchase_details" role="tabpanel" aria-labelledby="purchase_details_tab">
                    <div class="card">
                		<div class="card-body">
                        	Purchase Details
                    	</div><!--end row-->    
                    </div>
                </div>
                <div class="tab-pane" id="related_invoice" role="tabpanel" aria-labelledby="related_invoice_tab">
                    <div class="card">
                		<div class="card-body">
                        	Related Invoice
                    	</div><!--end row-->    
                    </div> <!--end row-->
				</div>
                <div class="tab-pane" id="statistics" role="tabpanel" aria-labelledby="statistics_tab">
                    <div class="card">
                		<div class="card-body">
                        	Statistics
                    	</div><!--end row-->    
                    </div>
                </div>
                <div class="tab-pane" id="note" role="tabpanel" aria-labelledby="note_tab">
                    <div class="card">
                		<div class="card-body">
                        	<div class="form-row">
                        		<div class="col-md-12 position-relative form-group">
                        			<?php echo @$serviceData['description'];?>
                        		</div>
                        	</div>
                        </div>
                    </div><!--end row-->
                </div>
            </div>
        </div>
    </div>


    <!-- end page content -->
<?php require "../../inc/footer.php"; ?>
<script type="text/javascript" src="https://www.jqueryscript.net/demo/Simple-jQuery-Based-Barcode-Generator-Barcode/jquery-barcode.js"></script>
<script type="text/javascript">
    
  	function generateBarcode(){
	    var value = "<?php echo strtolower(@$serviceData['barcode_value']); ?>";
	    var btype = "<?php echo strtolower(@$barcode_type); ?>";
	    var renderer = "css";
    	var quietZone = false;
	    
	    var settings = {
	      	output:renderer,
	      	bgColor: "#FFFFFF",
	      	color: "#000000",
	      	barWidth: "2",
	     	barHeight: "50",
	      	moduleSize: "5",
	      	posX: "10",
	      	posY: "20",
	      	addQuietZone: "1"
	    };
    	if (renderer == 'canvas'){
      		clearCanvas();
	      	$("#barcodeTarget").hide();
	      	$("#canvasTarget").show().barcode(value, btype, settings);
    	} else {
      		$("#canvasTarget").hide();
      		$("#barcodeTarget").html("").show().barcode(value, btype, settings);
    	}
  	}
      
  	function showConfig1D(){
	    $('.config .barcode1D').show();
	    $('.config .barcode2D').hide();
  	}
  
  	function showConfig2D(){
	    $('.config .barcode1D').hide();
	    $('.config .barcode2D').show();
  	}
  
  	function clearCanvas(){
	    var canvas = $('#canvasTarget').get(0);
	    var ctx = canvas.getContext('2d');
	    ctx.lineWidth = 1;
	    ctx.lineCap = 'butt';
	    ctx.fillStyle = '#FFFFFF';
	    ctx.strokeStyle  = '#000000';
	    ctx.clearRect (0, 0, canvas.width, canvas.height);
	    ctx.strokeRect (0, 0, canvas.width, canvas.height);
  	}
  
  	$(function(){
    	generateBarcode();
  	});

</script>