<?php

// /*
//  * To change this license header, choose License Headers in Project Properties.
//  * To change this template file, choose Tools | Templates
//  * and open the template in the editor.
//  */
// $servername = 'coolmansl.com';
// $username = 'coolmanlk';
// $password = 'coolman@2017';
// $port = 10060;
// $dbname = 'coolmanl_pt';


// $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);


// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// $sql = "select * from s_salma limit 1";
// $result = $conn->query("$sql");
// $row = $result->fetch();

// echo $row["SDATE"];

require_once("config.inc.php");
	require_once("DBConnector1.php");
	$db = new DBConnector();
$subtot1=0;
// 
            $sql="SELECT * FROM s_salma where  REF_NO='XCAD031968' and   (SDATE>'2021-07-01'or SDATE='2021-07-01') AND( SDATE<'2021-07-31' or SDATE='2021-07-31')and CANCELL='0'  and DEV!='A'"; 
			$result =$db->RunQuery($sql);	
			while($row = mysqli_fetch_array($result)){
			    
			     $sql1="SELECT * FROM s_invo where REF_NO='".$row['REF_NO']."'"; 
    			$result1 =$db->RunQuery($sql1);	
    			while($row1 = mysqli_fetch_array($result1)){
    			    
    			     if (($row['VAT']=="1") or ($row['VAT']=="2")){
                        $vatr=100+$row["TAX_PER"]; 
                		$PRICE=$row1["PRICE"];
                		
                		 $disFactor = (100-$row1["Print_dis1"])*(100-$row1["Print_dis2"])/10000;  
						$subtot=$PRICE*$row1["QTY"]*$disFactor;
                			  
        			} else {
        				$PRICE=$row1["PRICE"]; 
        				 $disFactor = (100-$row1["Print_dis1"])*(100-$row1["Print_dis2"])/10000; 
						$subtot=$PRICE*$row1["QTY"]*$disFactor;
        			}
    			    
    			   $subtot1=$subtot1+$subtot;
    			    
    			}
    			
    		 	// echo $subtot1.'/'.$row['GRAND_TOT'];
    			echo $row['REF_NO'].'-'.($row['GRAND_TOT']-$subtot1). '  <br>';
    			 if($subtot1 != $row['GRAND_TOT']){
			         echo $row['REF_NO'].'-'.($row['GRAND_TOT']-$subtot1). '  <br>';
			    } 
			    
			    
			}


?>