<?php
include('db_connection.php');

$Mainclass=new DB_Controller();

$Order_Id=base64_decode($_REQUEST['o']);
$result=$Mainclass->Fetch_individual_data('gold_billing_order_master',"making_discount_percent,stone_discount_percent,diamond_discount_percent,solitaire_discount_percent","Order_No='".$Order_Id."'");
$sum_condition = "Order_No='".$Order_Id."'";
$sum_making_charge=$Mainclass->get_sum_field("gold_billing_order_details","total_making_charge",$sum_condition);
$sum_stone=$Mainclass->get_sum_field("gold_billing_order_details","stone_price",$sum_condition);
$sum_diamond=$Mainclass->get_sum_field("gold_billing_order_details","diamond_price",$sum_condition);
$sum_solitaire=$Mainclass->get_sum_field("gold_billing_order_details","solitaire_price",$sum_condition);
$sum_making_charge=$Mainclass->get_sum_field("gold_billing_order_details","total_making_charge",$sum_condition);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet">

<script type="text/javascript" src="files/bower_components/jquery/js/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

<style type="text/css">

body{

margin:0px;

padding:0px;

font-family: quicksand, sans-serif !important;

}



.wrapper{

float:left;

width:100%;

height:auto;

}



.header_div{

float:left;

width:100%;

height:auto;

padding: 0px 0% 15px;

border-bottom: 1px solid #e9ecef;

font-size:20px;

color:#000000;

text-transform:uppercase;

}



.body_maindiv{

float:left;

width:100%;

height:auto;

padding:5% 0%;

}



.heading_maindiv{

float:left;

width:100%;

height:auto;

text-align:left;

font-size:15px;

color:#000000;

padding-bottom:6px;

}

.discount_div{
float:left;
width:60%;
margin-right:5%;
text-align:left;
font-size:16px;
color:#000;
font-weight:600;
}

.form_div{
float:left;
width:25%;    
}



.dropdown_div{

display: block;

    width: 95%;

    height: 28px;

    padding: 2px 2%;

    background-color: #fff;

    border: 1px solid #ccc;

    border-radius: 4px;

    box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);

    transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;

	    font-size: 14px;

    border-radius: 2px;

    border: 1px solid #ccc;

	outline:0px;

}

.table_header {

    background-color: #263544;

    text-align: center;

    color: #FFFFFF;

    font-size: 13px;

    padding: 4px 0px;

}



.table_body {

    background-color: #e7eef6;

    text-align: center;

    color: #000000;

    font-size: 13px;

    padding: 4px 0px;

}



.btn{

float:right;

border-radius: 2px;

text-transform: capitalize;

font-size: 15px;

padding: 10px 19px;

text-align:center;

color:#FFFFFF;

background-color:#4099ff;

border:0;

cursor:pointer;

	

}



</style>



</head>



<body>

<div class="wrapper">

<div class="header_div">Dealer Discount</div>

<div class="body_maindiv">


<input type="hidden" name="order" id="order" value="<?php echo $Order_Id ?>">


<div class="heading_maindiv" style="margin-bottom:5px;">
    
    <div class="discount_div">Making Charge Value - <?php echo $sum_making_charge ?> /- </div>
    
    <div class="form_div">
      <select class="dropdown_div" id="making_charge_percent">
          <option >0%</option>
  <?php for ($i = 1; $i <= 20; $i++) : ?>
    <option value="<?= $i ?>" <?php if($result['making_discount_percent']==$i) echo "selected"; ?>><?= $i ?>%</option>
  <?php endfor; ?>
      </select>  
        
        
    </div>





</div>

<div class="heading_maindiv" style="margin-bottom:5px;">
    
    <div class="discount_div">Stone Value - <?php echo $sum_stone ?> /- </div>
    
    <div class="form_div">
      <select class="dropdown_div" id="stone_percent">
          <option >0%</option>
  <?php for ($i = 1; $i <= 20; $i++) : ?>
    <option value="<?= $i ?>" <?php if($result['stone_discount_percent']==$i) echo "selected"; ?>><?= $i ?>%</option>
  <?php endfor; ?>
      </select>  
        
        
    </div>





</div>

<div class="heading_maindiv" style="margin-bottom:5px;">
    
    <div class="discount_div">Diamond Value - <?php echo $sum_diamond ?> /- </div>
    
    <div class="form_div">
      <select class="dropdown_div" id="diamond_percent">
          <option >0%</option>
  <?php for ($i = 0; $i <= 20; $i++) : ?>
    <option value="<?= $i ?>" <?php if($result['diamond_discount_percent']==$i) echo "selected"; ?>><?= $i ?>%</option>
  <?php endfor; ?>
      </select>  
        
        
    </div>





</div>

<div class="heading_maindiv" style="margin-bottom:5px;">
    
    <div class="discount_div">Solitaire Value - <?php echo $sum_solitaire ?> /- </div>
    
    <div class="form_div">
      <select class="dropdown_div" id="solitaire_percent">
          <option >0%</option>
  <?php for ($i = 1; $i <= 20; $i++) : ?>
    <option value="<?= $i ?>" <?php if($result['solitaire_discount_percent']==$i) echo "selected"; ?>><?= $i ?>%</option>
  <?php endfor; ?>
      </select>  
        
        
    </div>




</div>



<div class="heading_maindiv" style="text-align:center; color:#FF0000;"><span id="vou_err"></span></div>

<div class="heading_maindiv">

<input name="submit11" type="button" value="Apply" class="btn" style="width:100%;background: #017471;border: none;"  onclick="add_discount()" />

</div>



<div class="heading_maindiv">

<input name="submit11" type="button" value="Cancel" class="btn" style="width:100%;background: #FF1515;border: none;"  onclick="cancel_dealer_discount()" />

</div>






</div>

</div>

<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script type="text/javascript">
  


function add_discount(){


var order = $('#order').val();
var making_charge_percent = $('#making_charge_percent').val();
var stone_percent = $('#stone_percent').val();
var diamond_percent = $('#diamond_percent').val();
var solitaire_percent = $('#solitaire_percent').val();

if(making_charge_percent=="" || stone_percent=="" || diamond_percent=="" || solitaire_percent==""){

$('#vou_err').html('Please specify the discount percentage.');

return false;

}

else{

$('#vou_err').html('');


$.ajax({
url:'ajax-dealer-discount.php',
type:'POST',
data:{making_charge_percent:making_charge_percent,stone_percent:stone_percent,diamond_percent:diamond_percent,solitaire_percent:solitaire_percent,order:order},
success:function(f){


$.ajax({
url:'ajax_get_gold_discounts.php',
type:'POST',
data:{Order:order},
success:function(f){


Swal.fire({
icon: 'success',
title: 'Success',
text: 'Discount has been successfully applied.',
width: '450px',
showConfirmButton:false,
timer:2000,
}).then(function() {
window.parent.location.href='billing.php?o='+btoa(order);
});


}
});



}
});



}



}





function reject_discount(){


var order = $('#order').val();
var making_charge_percent = "0";
var stone_percent = "0";
var diamond_percent = "0";
var solitaire_percent = "0";

if(making_charge_percent=="" || stone_percent=="" || diamond_percent=="" || solitaire_percent==""){

$('#vou_err').html('Please specify the discount percentage.');

return false;

}

else{

$('#vou_err').html('');


$.ajax({
url:'ajax-dealer-discount.php',
type:'POST',
data:{making_charge_percent:making_charge_percent,stone_percent:stone_percent,diamond_percent:diamond_percent,solitaire_percent:solitaire_percent,order:order},
success:function(f){

Swal.fire({
icon: 'success',
title: 'Success',
text: 'Discount has been successfully applied.',
width: '450px',
showConfirmButton:false,
timer:2000,
}).then(function() {
window.parent.location.href='billing.php?o='+btoa(order);
});


}
});



}



}


function cancel_dealer_discount(){

var order = $('#order').val();

window.parent.location.href='billing.php?o='+btoa(order);

}



</script>

</body>

</html>