<?php echo $header; ?>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<?php echo $column_left; ?>
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
     
      <h1><?php echo $heading_title; ?></h1>
 
    </div>
  </div> 
  <div class="container-fluid">


    <?php if ($error_warning) { ?>
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>

    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list"></i> </h3>
      </div>
      <div class="panel-body">

	<?php
	
	if($product_price_change){
		
		$text_a  = "";
		$category_list   = $product_price_change['category_list'];
		$prices          = $product_price_change['price'];
		$specials        = $product_price_change['special'];
		$cleans          = $product_price_change['clean'];

		if(!empty($prices)){
			$products  = $prices ;
		}else{
			$products  = $specials ;
		}
		
		echo "<br>Kategoriler<br>";
		 
		foreach($category_list as $category){
			
			echo "<br><a  target='_blank' href='index.php?route=catalog/category/edit&token=".$token."&category_id=$category'>$category</a>";
			
		}
		


		if(!empty($cleans)){

			echo '<hr style="margin-top: 9px; margin-bottom: -5px;">';
			
			echo "<br>Ürünler<br>";
			
			foreach($cleans as $clean){
				
				echo "<br><a target='_blank' href='index.php?route=catalog/product/edit&token=".$token."&product_id=".$clean."'>".$clean."</a>";
				
			}
  
			echo '<br>';
			echo '<br>Ürünler deki indirimler temizlenmiştir.';
  
			}
  


		if(!empty($products)){

			echo '<hr style="margin-top: 9px; margin-bottom: -5px;">';
			
			echo "<br>Ürünler<br>";
			
			foreach($products as $product){
				
				echo "<br><a target='_blank' href='index.php?route=catalog/product/edit&token=".$token."&product_id=".$product['product_id']."'>".$product['product_id']."</a>";
				
			}
			}

		echo '<hr style="margin-top: 9px; margin-bottom: -5px;">';
		
		
		$normal_price    = $product_price_change['normal_price'];
		if($normal_price){
			$text_a = "<br>$normal_price TL olarak fiyat güncellenmiştir. ";
		}
		
		
		$percent_price   = $product_price_change['percent_price'];
		if($percent_price){
			$text_a = "<br>%$percent_price ürün fiyatı üzerinden  eklenmiştir. ";
		}
		
		
		$normal_spacial  = $product_price_change['normal_spacial'];
		
		if($normal_spacial){
			$text_a = "<br>$normal_spacial TL indirimli fiyatı eklenmiştir. ";
		}
		
		
		$percent_spacial = $product_price_change['percent_spacial'];
		
		if($percent_spacial){
			$text_a = "<br>Ürün fiyatından %$percent_spacial tutarında indirim  eklenmiştir. ";
		}
		
		
		
		echo $text_a;
	}
	
	?>


      </div>
    </div>
 




    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list"></i> </h3>
      </div>
      <div class="panel-body">



<div class="col-lg-12" id="cat_list">

<form action="<?php echo $action; ?>" method="post"  id="form-category" class="form-horizontal">


<span style="width: 100%;
display: block;
height: 400px;
overflow-x: hidden;
background: beige;
padding: 19px 29px;">
<?php

if(count($NewCategories) > 0 && is_array($NewCategories)){
	
	foreach($NewCategories as $category){
		
 
                        echo '
                        <input type="checkbox"  id="cat'.$category["category_id"].'" o
                        data-parent="'.$category["category_id"].'" name="cat_list[]" value="'.$category["category_id"].'">
							<label style="margin-left:10px;" for="cat'.$category["category_id"].'">
								'.$category["name"].'
							</label>
						<br>
                        ';
		
		if(count($category['children']) > 0 && is_array($category['children'])){
			
				foreach($category['children'] as $categoryChildren){
					
                        echo '
                            <input style="margin-left:20px;" 
							type="checkbox" id="cat'.$categoryChildren["category_id"].'" name="cat_list[]" value="'.$categoryChildren["category_id"].'">
                            <label style="margin-left:10px;" for="cat'.$categoryChildren["category_id"].'">
								'.$categoryChildren["name"].'
                            </label>
							<br>
                        ';

						if(count($categoryChildren['children']) > 0 && is_array($categoryChildren['children'])){

							foreach($categoryChildren['children'] as $categoryChildrenChild){
								echo '
								<input style="margin-left:40px;" 
								type="checkbox" id="cat'.$categoryChildrenChild["category_id"].'"  name="cat_list[]" value="'.$categoryChildrenChild["category_id"].'">
									<label style="margin-left:10px;"  for="cat'.$categoryChildrenChild["category_id"].'">
										'.$categoryChildrenChild["name"].' 
									</label>
								<br>';

							}

						}
		
		
				}
			
		}
		
		
	}
	
}



?>
</span>
	<?php if(isset($attributes)) { ?>
		<div class="form-group">
			<label for="attribute">Özellik</label>
			<select class="attribute" name="attribute[]" style="width:100%;" multiple="multiple">
                 <?php 
                    if($attributes){
                        foreach($attributes as $attribute){
                          if(in_array($attribute['attribute_id'],$filter_attribute)){
                               echo '<option selected value="'.$attribute['attribute_id'].'">'.$attribute['name'].'</option>';
                           }else{
                               echo '<option value="'.$attribute['attribute_id'].'">'.$attribute['name'].'</option>';
                           }
                        }
                    }
                 ?>
            </select>
		</div>
	<?php } ?>


    <div class="form-group row">
	 <h3 >KDV Hesaplama</h3>
		<div class="col-md-4">
			<label for="with_tax">KDV DAHİL FİYAT</label>
			<input type="text" class="form-control" name="with_tax" id="with_tax"  placeholder="Rakam Giriniz">
			
		</div>
		
		<div class="col-md-4">
			<label for="tax">KDV SEÇ</label>
				<select name="tax" id="tax" class="form-control">
					<option selected value="08">KDV %8</option>
					<option value="18">KDV %18</option>
					
				</select>
		</div>
		
		<div class="col-md-4">
			<label for="without_tax">KDV HARİÇ FİYAT</label>
			<input type="text" class="form-control" name="without_tax" id="without_tax"  placeholder="Rakam Giriniz">
			
		</div>
		
    </div>

<script>

 
$( "#with_tax" ).change(function() {
 
	with_tax_value  = Number($("#with_tax").val());
	tax_value       = Number($("#tax").val());
	
  $.ajax({
        url: "index.php?route=catalog/cost_change_by_category/tax&token=<?=$token;?>",
        type: "post",
        data: {'price_value': with_tax_value , 'tax_value':tax_value , 'tax_type':'with_tax'} ,
        success: function (response) {

           console.log(response);
		  $( "#without_tax" ).val(response.value);
		  
        },
        error: function(jqXHR, textStatus, errorThrown) {
           console.log(textStatus, errorThrown);
        }
    });
 
 
});


$( "#without_tax" ).change(function() {
 
 	without_tax_value  = Number($("#without_tax").val());
	tax_value          = Number($("#tax").val());
	
 
  $.ajax({
        url: "index.php?route=catalog/cost_change_by_category/tax&token=<?=$token;?>",
        type: "post",
        data: {'price_value': without_tax_value , 'tax_value':tax_value ,  'tax_type':'without_tax'} ,
        success: function (response) {

           console.log(response);
		  $( "#with_tax" ).val(response.value);
		  
        },
        error: function(jqXHR, textStatus, errorThrown) {
           console.log(textStatus, errorThrown);
        }
    });
	

 
});

</script>



    <div class="form-group">
        <label for="InputPrice">Normal Fiyatı Güncelle <span><b>(+/-) Belirtiniz</b></span></label>
        <input type="text" class="form-control" name="normal_price" id="InputPrice"  placeholder="Rakam Giriniz">
        <small style="color:red;">Sistem fiyata kdv eklediği için fiyatlar KDV hariç fiyat giriniz.(+/-) Belirtilmez ise bu değer fiyat olarak güncellenir</small>
       <small style="color:red;">Küsüratlı değerlerde nokta giriniz.</small>
    </div>

    <div class="form-group">
        <label for="InputPrice">Yüzde olarak Fiyatı Güncelle <span><b>(+/-) Belirtiniz</b></span></label>
        <input type="text" class="form-control" name="percent_price" id="InputPrice"  placeholder="Rakam Giriniz">
        <small>Sistem fiyata kdv eklediği için fiyatlar KDV hariç fiyat giriniz.</small>
    </div>


    <div class="form-group">
        <label for="InputPrice">Normal İndirimli Fiyat </label>
        <input type="text" class="form-control" name="normal_spacial" id="InputPrice"  placeholder="Rakam Giriniz">
        <small>Sistem fiyata kdv eklediği için fiyatlar KDV hariç fiyat giriniz.</small>
    </div>

    <div class="form-group">
        <label for="InputPrice">Yüzde İndirimli Fiyat </label>
        <input type="text" class="form-control" name="percent_spacial" id="InputPrice"  placeholder="Rakam Giriniz">
        <small>Sistem fiyata kdv eklediği için fiyatlar KDV hariç fiyat giriniz.</small>
    </div>

	<div class="form-group">
	<label for="InputClean">İndirimleri Temizle   <small style="color:red;">Burayı tıkladığınızda ilgili ürünlerdeki indirimleri temizler.</small> </label>
	<input type="checkbox" id="InputClean" class="form-control" name="clean_spacial" >
  
</div>



       <div class="form-group">
            <button style="width:100%;" type="submit" class="btn btn-primary">Gönder</button>
       </div>
</form>

 
  </div>   
	   
 
	
 

      </div>
    </div>
  </div>
</div>

<script>

function catSelect (id,category_id) {

 if ($('#cat'+category_id+'').is(':checked')) {
	 
	$('#cat'+category_id+'').prop('checked', false);
	 
  }else{
	  
	$('#cat'+category_id+'').prop('checked', true);
	 
  }

var parent = 'parent';

if(id == 0){
var parent = 'parent';	
}

if(id == 1){
var parent = 'child';	
}


var cats = $("[data-"+parent+"='" + category_id + "']").each(function( index,value ) {
	 	 
 if ($(this).is(':checked')) {
	 
	 $(this).prop('checked', false); 
	 
  }else{
	  
	 $(this).prop('checked', true);
	 
  }

});


}

   
$(document).ready(function() {
    $('.attribute').select2();
});

</script>
 
<?php echo $footer; ?>