<?php
    
        include'connection.php';
        
        $dataAirtel =getRechByData('Airtel','My_API','My_API2');
		$dataIdea =getRechByData('Idea','My_API','My_API2');
		$dataVoda =getRechByData('Vodafone','My_API','My_API2');
		$dataJio =getRechByData('Reliance Jio','My_API','My_API2');
		$dataBsnlTopup =getRechByData('BSNL_Topup','My_API','My_API2');
		$dataBsnlSpe =getRechByData('BSNL_Special','My_API','My_API2');
		$dataOzzy =getRechByData('ALL','Ozzy_Api','Ozzy_Api');
		$dataAmbika =getRechByData('ALL','Ambika_Api','Ambika_Api');
		$dataDizi =getRechByData('ALL','Dizi_Kwik','Dizi_Kwik');
		
		$dataAirtel_RO =getRechByData('Airtel_RO','My_API','My_API2');
		$dataVi_RO =getRechByData('Vi_RO','My_API','My_API2');
		
		$AdminBal=getBal(1111);
		
		$queryMd="SELECT * FROM masterdis";
		$resultMd=mysqli_query($con,$queryMd);
		$rowMd=mysqli_num_rows($resultMd);
		$totalMdBal=0;
		while($mdData=mysqli_fetch_array($resultMd))
		{
		    $MdBal=$mdData['Balance'];
		    $totalMdBal=$totalMdBal+$MdBal;
		}
		
		$querydis="SELECT * FROM distributer";
		$resultdis=mysqli_query($con,$querydis);
		$rowdis=mysqli_num_rows($resultdis);
		$DiswalletBal=0;
		while($disData=mysqli_fetch_array($resultdis))
		{
		    $totalDisBal=$disData['Balance'];
		    $DiswalletBal=$DiswalletBal+$totalDisBal;
		}
		
		$query1="SELECT * FROM retailer";
		$result1=mysqli_query($con,$query1);
		$row1=mysqli_num_rows($result1);
		$RetWalletBal=0;
	    while($row11=mysqli_fetch_array($result1))
		{
		    $retalrBal=$row11['Balance'];
		    $RetWalletBal=$RetWalletBal+$retalrBal;
		}
		
		$quMLM="SELECT * FROM MLM_Users";
		$reMLM=mysqli_query($con,$quMLM);
		$rowMLM=mysqli_num_rows($reMLM);
		$mlmWalletBal=0;
	    while($dataMLM=mysqli_fetch_array($reMLM))
		{
		    $mlmWalletBal=$mlmWalletBal+$dataMLM['Balance'];
		}
		
		$query4="SELECT * FROM commwallet WHERE Active='0'";
	    $result4=mysqli_query($con,$query4);
	    $Commission=0;
	    while($row4=mysqli_fetch_array($result4))
	    {
		    $data4=$row4['Balance'];
	        $Commission=$Commission+$data4;
	    }
	    
		$totalUserWalletBal=$totalMdBal+$DiswalletBal+$RetWalletBal+$mlmWalletBal+$Commission;
		$totalWalletBal=$AdminBal+$totalUserWalletBal;
		
		
		$TotalAirtelBal=getLB('Airtel');
        $ActualAirtelBal=$TotalAirtelBal*100/103;
    
	    $TotalIdeaBal=getLB('Idea'); 
        $ActualIdeaBal=$TotalIdeaBal*100/104;
        
        $TotalVodaBal=getLB('Vodafone');
        $ActualVodaBal=$TotalVodaBal*100/104;
        
        $TotalJioBal=getLB('Reliance Jio');
        $ActualJioBal=$TotalJioBal*100/105;
        
        $TotalBSNLBal=getLB('BSNL Topup');
        $ActualBSNLBal=$TotalBSNLBal*100/106;
        
        $OzzyBal=floor(getOzzyBal());
        $DiziBal=floor(getDiziBal());
        $AmbikaBal=floor(getAmbikaBal());
        $ppApiBal=0;
        
	    $TotalApiBal=$ActualJioBal+$ActualVodaBal+$ActualAirtelBal+$OzzyBal+$DiziBal+$ppApiBal+$ActualIdeaBal+$ActualBSNLBal+$AmbikaBal;
	    $Managebal=$totalWalletBal-$TotalApiBal;
	    $BenefitBal=floor(2000000-$Managebal);
	    $RestBal=$Managebal-2000000;
	    
	    $AllBankBal=0;
        $quBank="SELECT * FROM bank";
	    $reBank=mysqli_query($con,$quBank);
	    while($dataBank=mysqli_fetch_array($reBank))
	    {
	        $TotalBankBal=0;
		    $AllBank=$dataBank['Bankname'];
		    $BankId=$dataBank['Id'];
		
		    $quGetBankBal="select * from Bank_Account_Txn where Bank_Id='$BankId'";
		    $reGetBankBal=mysqli_query($con,$quGetBankBal);
		    while($dataGetBankBal=mysqli_fetch_array($reGetBankBal))
		    {
		        $Txn=$dataGetBankBal['Txn'];
		        $TotalBankBal=$TotalBankBal+$Txn;
		    }
		    
		    $AllBankBal=$AllBankBal+$TotalBankBal;
	    }
	    
	    $TotalBizBal=$TotalApiBal+$RestBal+$AllBankBal;
        $BizDiff=floor($TotalBizBal-$totalUserWalletBal);
?>