<?php include "headerLink.php"?>
<!DOCTYPE html>
<html lang="en">


<body class="animsition">
    <div class="page-wrapper">
       

        <!-- PAGE CONTAINER-->
        <!--<div class="page-container">-->
            <!-- HEADER DESKTOP-->
			
            <!-- END HEADER DESKTOP-->
			
			
			
			<!-- MAIN CONTENT-->
			<?php
			date_default_timezone_set("Asia/Kuala_Lumpur");
             $tenant_id = $_GET["tenant_id"];
            //get date start rental and rental_rate start
            $sqlTenant = "select rental_rate, start_date from tenants where id = $tenant_id ";
            $runTenant = mysqli_query($link, $sqlTenant);
            if($runTenant === FALSE){
               die(mysqli_error($link));
            }
            $resultTenant = mysqli_fetch_array($runTenant);
            $rental_rate = $resultTenant["rental_rate"];
            $startDate = trim($resultTenant["start_date"]);
             $startDateMonthYear = "0";
            IF($startDate == "0000-00-00 00:00:00"){
                  // "START DATE 1:::: ". $startDate;
                  $startDateFormat = "0";
            }
            else if($startDate != null || $startDate != "" || $startDate != "0000-00-00 00:00:00"){
                $startDateFormat = date("d/m/Y",strtotime($startDate));
                $startDateMonthYear = date("m/Y",strtotime($startDate));
            }
            else{
                $startDateFormat = "0";
            }
            $twoMonthRental = $rental_rate*2;
            $utility = $rental_rate;
            //get start rental date end


            //get yuran pelbagai start
             $sqlYuranPelbagai = "select id, yp_charges from yuran_pelbagais where location_id = " . $_SESSION["location_id"];
            $runYuranPelbagai = mysqli_query($link, $sqlYuranPelbagai);
            if($runYuranPelbagai === FALSE){
                die(mysqli_error($link));
            }
            $resultYuranPelbagai = mysqli_fetch_array($runYuranPelbagai);
            $yuranPelbagai_id = $resultYuranPelbagai["id"];
            $yuranPelbagai = $resultYuranPelbagai["yp_charges"];
            //get yuran pelbagai end

             //get sst charges start
             $sqlSST = "select id, sst_percent from sst where sst_status = 'enable'";
             $runSST = mysqli_query($link, $sqlSST);
             if($runSST === FALSE){
                 die(mysqli_error($link));
             }
             $resultSST = mysqli_fetch_array($runSST);
			$sst_percent = $resultSST["sst_percent"] ;
			$sst_id = $resultSST["id"];

            $sst_percent_view = $sst_percent * 100;
            $sst_charges = $sst_percent * $yuranPelbagai;
            //get sst charges end
            //SST QUERY
            $sqlSST_list = "select * from sst ";
            $runSST_list = mysqli_query($link, $sqlSST_list);
            if($runSST_list === FALSE){
                die(mysqli_error($link));
            }
            
            //SST QUERY END

            // ALL DEPOSIT INFO START
            //CHECK DEPOSIT INFO BASED ON TENANT ID
            $sqlDepositPayment = "select ";
            // ALL DEPOSIT INFO END

            $sqlDepositBills = "select * from deposit_bills where tenant_id = $tenant_id";
			$runDepositBills = mysqli_query($link, $sqlDepositBills);
			if($runDepositBills === FALSE){
				die(mysqli_error($link));
			}
			$countDepositBillsExist = mysqli_num_rows($runDepositBills);
			if($countDepositBillsExist > 0){
				$resultDepositBills = mysqli_fetch_assoc($runDepositBills);
				$twoMonthRentalAmount = $resultDepositBills["two_month_rental_amount"];
				$utilityAmount = $resultDepositBills["utility_amount"];
				$deposit_bill_id = $resultDepositBills["id"];
			}
			
			
			echo $sqlDepositBillsOthersReceipt = "select * from deposit_bill_other_receipts where tenant_id = $tenant_id";
			$runDepositBillsOthersReceipt = mysqli_query($link, $sqlDepositBillsOthersReceipt);
			if($runDepositBillsOthersReceipt === FALSE){
				die(mysqli_error($link));
			}
			$countDepositBillsOthersReceiptExist = mysqli_num_rows($runDepositBillsOthersReceipt);
			
			if($countDepositBillsOthersReceiptExist > 0 ){
				$resultDepositBillsOthersReceipt = mysqli_fetch_assoc($runDepositBillsOthersReceipt);
				$stamping_charges_amount = $resultDepositBillsOthersReceipt["stamping_charges_amount"];
				$sst_charges_amount = $resultDepositBillsOthersReceipt["sst_charges_amount"];
				$yp_charges_amount = $resultDepositBillsOthersReceipt["yp_charges_amount"];
				$deposit_other_receipt_id = $resultDepositBillsOthersReceipt["id"];
			}
			$totalBillingFromDB = $twoMonthRentalAmount + $utilityAmount + $stamping_charges_amount + $sst_charges_amount + $yp_charges_amount;
			if($yp_charges_amount == "" || $yp_charges_amount == null){
				$yp_charges_amount = 0.00;
			}
			if($sst_charges_amount == "" || $sst_charges_amount == null){
				$sst_charges_amount = 0.00;
			}
			if($stamping_charges_amount == "" || $stamping_charges_amount == null){
				$stamping_charges_amount = 0.00;
			}
			?>
			
            
            <div class="main-content"  >
                <div class="section__content section__content--p30" >
                    <div class="container-fluid" >
                        <!-- menu show on page after selected - start -->
                        
						<!-- menu show on page after selected - end -->
						<div class="row" >
                            <div class="col col-md-12" >
                                <div class="card">
                                 <form action="depositUpdateBillController.php" method="post" id="depositBill" onsubmit="validateBillForm()" >
                                    <div class="card-header ">
                                        <input type="hidden" name="tenant_id" value="<?php echo $tenant_id?>">
                                        <input type="hidden" name="deposit_bill_id" value="<?php echo $deposit_bill_id?>">
                                        <input type="hidden" name="deposit_other_receipt_id" value="<?php echo $deposit_other_receipt_id?>">
                                        <div class="form-check">
                                            <div class="checkbox">
                                                <label for="checkbox1" class="form-check-label ">
                                                    <input type="checkbox" id="checkbox1" name="checkbox1" value="option1" class="form-check-input" CHECKED onclick="return false">
                                                    <B>PLEASE TICK CHECKBOX BELOW TO CREATE BILL BEFORE CLICK SUBMIT BUTTON</B>
                                                </label>
                                            </div>
                                        </div>    
                                        
                                    </div>
                                    <div class="card-header">
                                        <h5 class="m-0 font-weight-bold text-primary">
                                            DEPOSIT BILL
                                            <span style="float: right">
                                                <input type="checkbox" id="checkboxDepositBill" name="checkboxDepositBill" value="option1" class="form-check-input" onclick="createDepositBill(<?php echo $twoMonthRental?>,<?php echo $utility?>)" >
                                            </span>
                                        </h5>
                                    </div>
                                    <div class="card-body card-block">
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label class=" form-control-label">Billing for 2 Month (RM) </label>
                                            </div>
                                            <div class="col col-md-6" >
                                               <input type="number" id="twoMonthRental"  name="twoMonthRental" step="0.01"  class="form-control" required="required"   placeholder="0.00" style="text-align: right;" value="<?php echo $twoMonthRentalAmount?>" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label class=" form-control-label">Billing for Utility (RM)</label>
                                            </div>
                                            <div class="col col-md-6" >
                                                <input type="number" id="utility"  name="utility" step="0.01"  class="form-control" required="required"  placeholder="0.00" style="text-align: right;" value="<?php echo $utilityAmount?>" readonly="readonly">
                                            </div>
                                        </div>
                                    </DIV>
                                    <div class="card-header ">
                                        <h5 class="m-0 font-weight-bold text-primary">
                                            OTHERS BILL 
                                            <span style="float: right">
											<?php if($yp_charges_amount != 0.00 && $sst_charges_amount != 0.00){?>
                                            <input type="checkbox" id="checkboxOtherBill" name="checkboxOtherBill" value="option1" class="form-check-input"   onclick="createOthersBill_1(<?php echo $yp_charges_amount?>,<?php echo $sst_charges_amount?>,<?php echo $stamping_charges_amount?>)">
											<?php } else {?>
											<input type="checkbox" id="checkboxOtherBill" name="checkboxOtherBill" value="option1" class="form-check-input"   onclick="createOthersBill_2(<?php echo $yuranPelbagai?>,<?php echo $sst_charges?>)">
											<?php } ?>
                                            </span>
                                        </h5>
                                    </div>
                                    <div class="card-body card-block">
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label class=" form-control-label">Billing for Stamping Charges (RM)</label>
                                            </div>
                                            <div class="col col-md-6" >
                                                <input type="number" id="stampingCharges"  name="stampingCharges" step="0.01"  class="form-control" required="required"  onchange ="totalBilling_addStampingCharges(this)" placeholder="0.00" style="text-align: right;" readonly="readonly" value="<?php echo ($stamping_charges_amount != "" || $stamping_charges_amount != 0.00) ? $stamping_charges_amount : "0.00" ?>">
                                            </div>
                                        </div>
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label class=" form-control-label">Billing for Yuran Pelbagai (RM)</label>
                                            </div>
                                            <div class="col col-md-6" >
                                                <input type="number" id="yuranPelbagai"  name="yuranPelbagai" step="0.01"  class="form-control" required="required"  placeholder="0.00" style="text-align: right;" value="<?php echo ($yp_charges_amount != "" || $yp_charges_amount != 0.00) ? $yp_charges_amount : "0.00" ?>" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label for="sstPercent" class=" form-control-label">SST Charges</label>
                                            </div>
                                            <div class="col col-md-6">
                                                <select name="sstPercent" id="sstPercent" class="form-control-sm form-control" onsubmit="sstChanges()" disabled>
                                                    
                                                    <option value="">Please select</option>
                                                    <?php 
                                                       while($resultSST_list = mysqli_fetch_array($runSST_list)){
                                                            ?>
                                                            <option value="<?php echo $resultSST_list['sst_percent']?>" <?php echo $resultSST_list["sst_status"] == "enable" ? "selected" : "";?>><?php echo $resultSST_list['sst_percent']*100?>%</option>
                                                            <!-- <option value="<?php echo $resultSST_list['sst_percent']?>" ><?php echo $resultSST_list['sst_percent']*100?>%</option> -->
                                                            <?php
                                                       }
                                                    ?>
                                                    
                                                </select>
                                            </div>
                                        </div>
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <!-- <label class=" form-control-label"> SST Charges <?php echo $sst_percent_view?>% from Yuran Pelbagai (RM) </label> -->
                                                <label class=" form-control-label"> SST Charges <span id="sst_percent_view"> <?php echo $sst_percent_view?></span>% from Yuran Pelbagai (RM) </label>
                                            </div>
                                            <div class="col col-md-6" >
                                                <input type="number" id="sstCharges"  name="sstCharges" step="0.01"  class="form-control" required="required"  placeholder="0.00" style="text-align: right;" value="<?php echo ($sst_charges_amount != "" || $sst_charges_amount != 0.00) ? $sst_charges_amount : "0.00" ?>" readonly="readonly">
                                            </div>
                                        </div>
                                    </div>

                                    <!--<div class="card-header ">
                                        <h5 class="m-0 font-weight-bold text-primary">
                                            1st MONTH RENTAL BILL
                                            <span style="float: right">
                                            <input type="checkbox" id="checkboxFirstMonthRental" name="checkboxFirstMonthRental" value="option1" class="form-check-input" onclick="createFirstMonthRentalBill('<?php echo $startDateFormat?>',<?php echo $rental_rate?>,'<?php echo $startDateMonthYear?>')" >
                                            </span>
                                        </h5>
                                    </div>
                                    
                                    <div class="card-body card-block" disabled >
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label class=" form-control-label">START RENT</label>
                                            </div>
                                            <div class="col col-md-6" >
                                                <input type="text" id="startRent"  name="startRent" step="0.01" onchange='updateMonthYear();'  class="form-control" required="required"  placeholder="" style="text-align: right;" value="dd/mm/yyyy" readonly="readonly">
                                            </div>
                                            <div class="invalid-feedback">
                                                Please select a valid state.
                                            </div>
                                        </div>
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label class=" form-control-label">Amount for 1st Month Rental (RM) </label>
                                            </div>
                                            <div class="col col-md-6" >
                                                <input type="number" id="firstMonthRental"  name="firstMonthRental" step="0.01"  onchange="totalBilling_firstMonthRental(this)" class="form-control" required="required"  placeholder="0.00" style="text-align: right;" value="0.00" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label class=" form-control-label">Month/Year</label>
                                            </div>
                                            <div class="col col-md-6" >
                                                <input type="text" id="firstMonthYear"  name="firstMonthYear"   class="form-control" required="required"  placeholder="" style="text-align: right;" value="mm/yyyy" readonly="readonly">
                                            </div>
                                        </div>
                                    </DIV>-->
                                    <div class="card-header">
                                        <h5 class="m-0 font-weight-bold text-primary">
                                            TOTAL
                                        </h5>
                                    </div>
                                    <div class="card-body card-block">
                                        <div class="row" valign="middle">
                                            <div class="col col-md-6">
                                                <label class=" form-control-label">Total Billing (RM) </label>
                                            </div>
                                            <div class="col col-md-6" >
                                               <input type="number" id="totalBilling"  name="totalBilling" step="0.01"  class="form-control" required="required"  placeholder="0.00" style="text-align: right;" value="<?php echo number_format($totalBillingFromDB,2) ?>" readonly="readonly">
                                            </div>
                                        </div>
                                        
                                    </DIV>
                                 

                                    <div class="card-footer">
                                         
                                        <button type="submit" id="submitBtn" class="btn btn-outline-success btn-sm" style="float:right"  >Submit</button>
                                        <button type="reset" style="float:right" class="btn btn-outline-warning btn-sm">Reset</button>
                                    </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        
                        <?PHP include "footer.php";?>
                        
                    </div>
                </div>
            </div>
            <!-- END MAIN CONTENT-->
            <!-- END PAGE CONTAINER-->
        </div>
		
    <!--</div>-->
    <?PHP include "footerLink.php";?>
</body>

</html>
<!-- end document-->

<script>



const checkboxDepositBill = document.getElementById('checkboxDepositBill')

checkboxDepositBill.addEventListener('change', (event) => {
  if (event.currentTarget.checked) {
    alert('checkboxDepositBill');
    

  } else {
    alert('not checked');
    var twoMonthRental = document.getElementById("twoMonthRental").value = 0.00;
    var utility = document.getElementById("utility").value = 0.00;
    var stampingCharges = document.getElementById("stampingCharges").value;
    var yuranPelbagai = document.getElementById("yuranPelbagai").value;
    var sstCharges = document.getElementById("sstCharges").value;
    //var firstMonthRental = document.getElementById("firstMonthRental").value;
    twoMonthRental = twoMonthRental.toFixed(2);
    utility = utility.toFixed(2);
    stampingCharges = Number(stampingCharges);
    yuranPelbagai = Number(yuranPelbagai);
    sstCharges = Number(sstCharges);
    //firstMonthRental = Number(firstMonthRental);
   // alert(twoMonthRental);
   // alert(utility);
    updateTotalBilling = parseFloat(twoMonthRental) + parseFloat(utility) +  stampingCharges + yuranPelbagai + sstCharges;
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;
    document.getElementById("twoMonthRental").value =  twoMonthRental;
    document.getElementById("utility").value =  utility;

    document.getElementById("twoMonthRental").readOnly = true;
    document.getElementById("utility").readOnly = true;
}
  }
)

//checkboxOtherBill
const checkboxOtherBill = document.getElementById('checkboxOtherBill')

checkboxOtherBill.addEventListener('change', (event) => {
  if (event.currentTarget.checked) {
   // alert('checkboxOtherBill');
    

  } else {
   // alert('not checked');
    var twoMonthRental = document.getElementById("twoMonthRental").value;
    var utility = document.getElementById("utility").value;
    //var firstMonthRental = document.getElementById("firstMonthRental").value;
    var stampingCharges = document.getElementById("stampingCharges").value = 0.00;
    var yuranPelbagai = document.getElementById("yuranPelbagai").value = 0.00;
    var sstPercent = document.getElementById("sstPercent").value = "";
    var sstCharges = document.getElementById("sstCharges").value = 0.00;
    twoMonthRental = Number(twoMonthRental);
    utility = Number(utility);
    //firstMonthRental = Number(firstMonthRental);
    stampingCharges = stampingCharges.toFixed(2);
    yuranPelbagai = yuranPelbagai.toFixed(2);
    sstCharges = sstCharges.toFixed(2);
    //alert("twoMonthRental:" + twoMonthRental);
    //alert("utility:" + utility);
    //alert(stampingCharges);
    //alert(yuranPelbagai);
    //alert(sstCharges);
    updateTotalBilling = twoMonthRental + utility +  parseFloat(stampingCharges) + parseFloat(yuranPelbagai) +  parseFloat(sstCharges) ;
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;
    document.getElementById("stampingCharges").value =  stampingCharges;
    document.getElementById("yuranPelbagai").value =  yuranPelbagai;
    document.getElementById("sstCharges").value =  sstCharges;

    document.getElementById("stampingCharges").readOnly = true;
    document.getElementById("yuranPelbagai").readOnly = true;
    document.getElementById("sstCharges").readOnly = true;
    document.getElementById("sstPercent").disabled = true;
}
  }
)

//checkboxFirstMonthRental
/* const checkboxFirstMonthRental = document.getElementById('checkboxFirstMonthRental')

checkboxFirstMonthRental.addEventListener('change', (event) => {
  if (event.currentTarget.checked) {
   // alert('checkboxFirstMonthRental');
    

  } else {
  //  alert('not checked');
    var twoMonthRental = document.getElementById("twoMonthRental").value;
    var utility = document.getElementById("utility").value;
    var firstMonthRental = document.getElementById("firstMonthRental").value = 0.00;
    var stampingCharges = document.getElementById("stampingCharges").value;
    var yuranPelbagai = document.getElementById("yuranPelbagai").value;
    var sstCharges = document.getElementById("sstCharges").value;
    
    twoMonthRental = Number(twoMonthRental);
    utility = Number(utility);
    stampingCharges = Number(stampingCharges);
    yuranPelbagai = Number(yuranPelbagai);
    sstCharges = Number(sstCharges);
    firstMonthRental = firstMonthRental.toFixed(2);

    //alert("twoMonthRental:" + twoMonthRental);
    //alert("utility:" + utility);
    //alert(stampingCharges);
    //alert(yuranPelbagai);
    //alert(sstCharges);
    //alert("firstMonthRental:" +  firstMonthRental);
    updateTotalBilling = twoMonthRental + utility +  stampingCharges + yuranPelbagai + sstCharges +  parseFloat(firstMonthRental) ;
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;
    document.getElementById("firstMonthRental").value =  firstMonthRental;

    document.getElementById("startRent").readOnly = true;
    document.getElementById("firstMonthRental").readOnly = true;
    document.getElementById("firstMonthYear").readOnly = true;

    document.getElementById("startRent").type = "text";
    document.getElementById("startRent").value = "dd/mm/yyyy";
    document.getElementById("firstMonthYear").value = "mm/yyyy";
}
  }
) */

function sstChanges(){
    var x = document.getElementById("sstPercent").value;
    document.getElementById("sst_percent_view").innerHTML =  + x * 100;

    var sstCharges = 0.00;
    var yuranPelbagai = document.getElementById("yuranPelbagai").value ;
    if(yuranPelbagai > 0){
        sstCharges = parseFloat(yuranPelbagai) * x;
    }
    document.getElementById("sstCharges").value = sstCharges.toFixed(2);

    var twoMonthRental = document.getElementById("twoMonthRental").value;
    var utility = document.getElementById("utility").value;
    //var firstMonthRental = document.getElementById("firstMonthRental").value = 0.00;
    var stampingCharges = document.getElementById("stampingCharges").value;
    var yuranPelbagai = document.getElementById("yuranPelbagai").value;
    
    twoMonthRental = Number(twoMonthRental);
    utility = Number(utility);
    stampingCharges = Number(stampingCharges);
    yuranPelbagai = Number(yuranPelbagai);
    //sstCharges = Number(sstCharges);
    //firstMonthRental = Number(firstMonthRental);



    updateTotalBilling = twoMonthRental + utility +  stampingCharges + yuranPelbagai +  parseFloat(sstCharges) ;
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;
}

var updateTotalBilling = 0.00;
function totalBilling_addStampingCharges(){
    var stampingCharges = document.getElementById("stampingCharges").value;
   // alert(stampingCharges);

    updateTotalBilling =  parseFloat(updateTotalBilling) + parseFloat(stampingCharges);
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;
}
/* function totalBilling_firstMonthRental(){
   
    var firstMonthRental = document.getElementById("firstMonthRental").value;
    var twoMonthRental = document.getElementById("twoMonthRental").value ;
    var utility = document.getElementById("utility").value ;
    var stampingCharges = document.getElementById("stampingCharges").value;
    var yuranPelbagai =  document.getElementById("yuranPelbagai").value;
    var sstCharges = document.getElementById("sstCharges").value;


  //  alert(firstMonthRental);

    updateTotalBilling = parseFloat(twoMonthRental) + parseFloat(utility) +  parseFloat(stampingCharges) + parseFloat(yuranPelbagai) +  parseFloat(sstCharges) +  parseFloat(firstMonthRental) ;
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;

    
} */
function createDepositBill(twoMonthRental,utility){
    
    var  js_twoMonthRental = twoMonthRental.toFixed(2);
    var  js_utility = utility.toFixed(2);
    //var  js_totalBilling = js_twoMonthRental + js_utility;
	
	
    var stampingCharges = document.getElementById("stampingCharges").value;
    var yuranPelbagai = document.getElementById("yuranPelbagai").value;
    var sstCharges =  document.getElementById("sstCharges").value;
    //var firstMonthRental =  document.getElementById("firstMonthRental").value;
	
	if(stampingCharges == "" ){
		stampingCharges =0.00;
	}
	if(yuranPelbagai == "" ){
		yuranPelbagai =0.00;
	}
	if(sstCharges == "" ){
		sstCharges =0.00;
	}
	
     alert("js_twoMonthRental: " + js_twoMonthRental);
     alert("js_utility: " + js_utility);
     alert("stampingCharges: " + stampingCharges);
     alert("yuranPelbagai: " + yuranPelbagai);
     alert("sstCharges: " + sstCharges);
    // alert("FIRSTMONTH RENTAL: " + firstMonthRental);
    updateTotalBilling = parseFloat(js_twoMonthRental) + parseFloat(js_utility) +  parseFloat(stampingCharges) + parseFloat(yuranPelbagai) +  parseFloat(sstCharges) ;
     alert("updateTotalBilling: " +updateTotalBilling);
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;
	

    document.getElementById("twoMonthRental").value =  js_twoMonthRental;
    document.getElementById("utility").value = js_utility;

}
function createOthersBill_1(yuranPelbagai,sstCharges,stampingCharges){
   alert("yuranPelbagai11: "+yuranPelbagai);
    var  yuranPelbagai = yuranPelbagai.toFixed(2);
    var  sstCharges = sstCharges.toFixed(2);
    var  stampingCharges = stampingCharges.toFixed(2);
	
	if(yuranPelbagai == ""){
		yuranPelbagai = 0.00;
	}
	if(sstCharges == ""){
		sstCharges = 0.00;
	}
	if(stampingCharges == ""){
		stampingCharges = 0.00;
	}

    var twoMonthRental = document.getElementById("twoMonthRental").value ;
    var utility = document.getElementById("utility").value ;
    var stampingCharges = document.getElementById("stampingCharges").value;
    //var firstMonthRental =  document.getElementById("firstMonthRental").value;

    document.getElementById("stampingCharges").readOnly = false;
    document.getElementById("sstPercent").disabled = false;
    document.getElementById("yuranPelbagai").value =  yuranPelbagai;
    document.getElementById("sstCharges").value = sstCharges;
    // document.getElementById("sstPercent").value = sst_percent_view;
    // document.getElementById("sstPercent").setAttribute('selected','selected')
    document.getElementById("totalBilling").value =  parseFloat(updateTotalBilling);

    updateTotalBilling = parseFloat(twoMonthRental) + parseFloat(utility) +  parseFloat(stampingCharges) + parseFloat(yuranPelbagai) +  parseFloat(sstCharges);
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;
}
function createOthersBill_2(yuranPelbagai,sstCharges){
   
    var  yuranPelbagai = yuranPelbagai.toFixed(2);
    var  sstCharges = sstCharges.toFixed(2);
	var stampingCharges = document.getElementById("stampingCharges").value;
	
	if(yuranPelbagai == ""){
		yuranPelbagai = 0.00;
	}
	if(sstCharges == ""){
		sstCharges = 0.00;
	}
	
	alert("yuranPelbagai22: "+yuranPelbagai);
    var twoMonthRental = document.getElementById("twoMonthRental").value ;
    var utility = document.getElementById("utility").value ;
    //var firstMonthRental =  document.getElementById("firstMonthRental").value;

    document.getElementById("stampingCharges").readOnly = false;
    document.getElementById("sstPercent").disabled = false;
    document.getElementById("yuranPelbagai").value =  yuranPelbagai;
    document.getElementById("sstCharges").value = sstCharges;
    // document.getElementById("sstPercent").value = sst_percent_view;
    // document.getElementById("sstPercent").setAttribute('selected','selected')
    document.getElementById("totalBilling").value =  parseFloat(updateTotalBilling);

    updateTotalBilling = parseFloat(twoMonthRental) + parseFloat(utility) +  parseFloat(stampingCharges) + parseFloat(yuranPelbagai) +  parseFloat(sstCharges)  ;
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;
}
/* function createFirstMonthRentalBill(startRent, firstMonthRental,firstMonthYear){
   // alert(startRent);
    var  firstMonthRental = firstMonthRental.toFixed(2);

    var twoMonthRental = document.getElementById("twoMonthRental").value ;
    var utility = document.getElementById("utility").value ;
    var stampingCharges = document.getElementById("stampingCharges").value;
    var yuranPelbagai =  document.getElementById("yuranPelbagai").value;
    var sstCharges = document.getElementById("sstCharges").value;

    if(startRent == "0" ){
        document.getElementById("startRent").type = "date";
    }
    else{
        document.getElementById("startRent").value =  startRent;
   }
   if(firstMonthYear == "0" ){
        document.getElementById("firstMonthYear").value = "mm/yyyy";
    }
    else{
        document.getElementById("firstMonthYear").value =  firstMonthYear;
   }
   //alert("firstMonthYear:" + firstMonthYear);
    document.getElementById("startRent").readOnly = false;
    document.getElementById("firstMonthRental").readOnly = false;
    document.getElementById("firstMonthYear").readOnly = false;
    document.getElementById("firstMonthRental").value =  firstMonthRental;

    updateTotalBilling = parseFloat(twoMonthRental) + parseFloat(utility) +  parseFloat(stampingCharges) + parseFloat(yuranPelbagai) +  parseFloat(sstCharges) +  parseFloat(firstMonthRental) ;
    updateTotalBilling = updateTotalBilling.toFixed(2);
    document.getElementById("totalBilling").value =  updateTotalBilling;

} */
function validateBillForm(){
    //var startRent = document.getElementById("startRent");
    var stampingCharges = document.getElementById("stampingCharges");
    var firstMonthYear = document.getElementById("firstMonthYear");
    let depositBill = document.getElementById("depositBill");
   // let element = document.getElementsByClassName('form-control')[0];
   // ALERT();
   /* if(startRent.value == "" || startRent.value == null){
    document.getElementById("startRent").className += " is-invalid";
   } */
   if(stampingCharges.value == "" || stampingCharges.value == null){
    document.getElementById("stampingCharges").className += " is-invalid";
   }
   if(firstMonthYear.value == "" || firstMonthYear.value == null){
    document.getElementById("firstMonthYear").className += " is-invalid";
   }
   else{
    depositBill.submit();
   }
    
}
/* function updateMonthYear(){
    var startRent = document.getElementById("startRent").value;
    var firstMonthYear = document.getElementById("firstMonthYear");
    var day_startRent = startRent.split("-"); //dalam array 0->[2024],1->[02],2->[06]
    // var day = day_startRent[2];
    // if(day<15){
    //     alert(day);
    // }
    const startRentConst= new Date(startRent);
    //let day = startRentConst.getDay();
    let month = startRentConst.getMonth() + 1;
    let year = startRentConst.getFullYear();
    //document.getElementById("firstMonthYear").value = month + "/" + year;
    firstMonthYear.value = month + "/" + year;
    //alert(day);
    
} */

</script>