<?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"];
			 $two_month_rental_amount = 0.00;
             $utility_amount = 0.00;
             //get rental_rate start
             $sqlTenant = "select rental_rate 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"];
            $twoMonthRental = $rental_rate*2;
            $utility = $rental_rate;
            //get rental_rate 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


            // ALL DEPOSIT INFO START
            //CHECK DEPOSIT BILL INFO BASED ON TENANT ID
            // 1. table: deposit_bills 
            $deposit_paymentStatus = "";
            $readonly_depositbills = "readonly = 'readonly'";

             $sqlDepositBill = "select * from deposit_bills where tenant_id = $tenant_id";
            $runDepositBill = mysqli_query($link, $sqlDepositBill);
             if($runDepositBill === FALSE){
                 die(mysqli_error($link));
             }
             $countRowDepositBills = mysqli_num_rows($runDepositBill);
             if($countRowDepositBills > 0){
                $resultDepositBill = mysqli_fetch_array($runDepositBill);
                $depositBill_id = $resultDepositBill["id"];
                 " two_month_rental_amount::".  $two_month_rental_amount = $resultDepositBill["two_month_rental_amount"];
                $two_month_rental_due = $resultDepositBill["two_month_rental_due"];
                $utility_amount = $resultDepositBill["utility_amount"];
                $utility_due = $resultDepositBill["utility_due"];
                $paymentStatus = $resultDepositBill["payment_status"];
                
                $twoMonthRental_due = 0.00;
                $utility_amount_due = 0.00;

                $sqlDepositPayment = "SELECT sum(two_months_amount_paid) as totalPaid2Months, sum(utility_amount_paid) as totalPaidUtility from deposit_payments where deposit_bill_id = $depositBill_id";
                $runDepositPayment = mysqli_query($link, $sqlDepositPayment);
                if($runDepositPayment === FALSE){
                    die(mysqli_error($link));
                }
                $countPaymentRow = mysqli_num_rows($runDepositPayment);
                if($countPaymentRow > 0){
                    $resultDepositPayment = mysqli_fetch_array($runDepositPayment);
                    $two_months_amount_paid = $resultDepositPayment["totalPaid2Months"];
                    $utility_amount_paid = $resultDepositPayment["totalPaidUtility"];
                }
                else if($countPaymentRow == 0){
                    $sqlDepositPayment = "SELECT sum(two_month_rental) as totalPaid2Months, sum(utilities) as totalPaidUtility from deposits where tenant_id = $tenant_id";
                    $runDepositPayment = mysqli_query($link, $sqlDepositPayment);
                    if($runDepositPayment === FALSE){
                        die(mysqli_error($link));
                    }
                    $countPaymentRow = mysqli_num_rows($runDepositPayment);
                    if($countPaymentRow > 0){
                        $resultDepositPayment = mysqli_fetch_array($runDepositPayment);
                        $two_months_amount_paid = $resultDepositPayment["totalPaid2Months"];
                        $utility_amount_paid = $resultDepositPayment["totalPaidUtility"];
						
                    }
                    else if($countPaymentRow == 0){
                        $two_months_amount_paid = "0.00";
                        $utility_amount_paid = "0.00";
						$two_month_rental_amount = "0.00";
                        $utility_amount = "0.00";
                    // $deposit_paymentStatus = "Unpaid";
                    }
                }
             }
             else if($countRowDepositBills == 0){
                 $two_month_rental_amount = 0.00;
                 $utility_amount = 0.00;
                 $two_months_amount_paid = 0.00;
                 $utility_amount_paid = 0.00;
                 $two_months_amount_due = 0.00;
                 $utility_amount_due = 0.00;

                //set readonly
                
			 if($depositBill_id == "" || $two_month_rental_amount == 0.00 ||  $utility_amount = 0.00){
                     "READONLY::". $readonly_depositbills = "" . " onchange= 'twoMonthRentalAmount()'";
                }
             }
             //kiraan balance deposit: total billing - total payment
			 $totalBillingAmountDeposit = $two_month_rental_amount + $utility_amount;
			 $totalPaymentAmountDeposit = $two_months_amount_paid +  $utility_amount_paid;
			 $totalBalanceOutstandingDeposit =  $totalBillingAmountDeposit - $totalPaymentAmountDeposit;
			 
			 
			 if($totalBillingAmountDeposit == $totalPaymentAmountDeposit && $totalPaymentAmountDeposit != 0.00)
				$deposit_paymentStatus = "Paid";
			 else if($totalBillingAmountDeposit > $totalPaymentAmountDeposit && $totalPaymentAmountDeposit != 0.00)
				$deposit_paymentStatus = "Partial";
			 else if($totalBillingAmountDeposit > 0.00 && $totalPaymentAmountDeposit == 0.00)
				$deposit_paymentStatus = "Unpaid";
			
             $depositBillOther_ID = "";
             $readonly_otherbills = "readonly = 'readonly'";

             $sqlDepositOtherBill = "select * from deposit_bill_other_receipts where tenant_id = $tenant_id";
            $runDepositOtherBill = mysqli_query($link, $sqlDepositOtherBill);
             if($runDepositOtherBill === FALSE){
                 die(mysqli_error($link));
             }
             $countOtherBillsRow = mysqli_num_rows($runDepositOtherBill);
             if($countOtherBillsRow > 0){
                $resultDepositOtherBill = mysqli_fetch_array($runDepositOtherBill);
                $depositBillOther_ID = $resultDepositOtherBill["id"];
                $stamping_charges_amount = $resultDepositOtherBill["stamping_charges_amount"];
                $stamping_charges_due = $resultDepositOtherBill["stamping_charges_due"];
                $sst_charges_amount = $resultDepositOtherBill["sst_charges_amount"];
                $sst_charges_due = $resultDepositOtherBill["sst_charges_due"];
                $yp_charges_amount = $resultDepositOtherBill["yp_charges_amount"];
                $yp_charges_due = $resultDepositOtherBill["yp_charges_due"];
                $paymentStatusOtherBills = $resultDepositOtherBill["payment_status"];
                $yp_charges_paid = "0.00";
                $sst_charges_paid = "0.00";
                $stamping_charges_paid = "0.00";
                
                 $sqlDepositOthersPayment = "SELECT sum(stamping_paid) as totalStampingPaid, sum(sst_paid) as totalSSTPaid, sum(yp_paid) as totalYPPaid from deposit_payment_other_receipts where deposit_bill_other_id  = $depositBillOther_ID";
                $runDepositOthersPayment = mysqli_query($link, $sqlDepositOthersPayment);
                if($runDepositOthersPayment === FALSE){
                    die(mysqli_error($link));
                }
                $countOthersPaymentRow = mysqli_num_rows($runDepositOthersPayment);
                if($countOthersPaymentRow > 0){
                    $resultDepositOthersPayment = mysqli_fetch_array($runDepositOthersPayment);
                    $stamping_charges_paid = $resultDepositOthersPayment["totalStampingPaid"];
                    $sst_charges_paid = $resultDepositOthersPayment["totalSSTPaid"];
                    $yp_charges_paid = $resultDepositOthersPayment["totalYPPaid"];
                    if( ($stamping_paid == $stamping_charges_amount) && ($sst_paid == $sst_charges_amount) && ($yp_paid == $yp_charges_amount)){
                        $paymentStatusOtherBills = "Paid";
                    }
                    else if(($stamping_paid < $stamping_charges_amount && $stamping_paid != 0.00 ) && ($sst_paid < $sst_charges_amount && $sst_paid != 0.00 ) && ($yp_paid == $yp_charges_amount && $yp_paid != 0.00)){
                        $deposit_paymentStatus = "Partial";
                    }
                }
                else if($countOthersPaymentRow == 0){
                    $stamping_paid = "0.00";
                    $sst_paid = "0.00";
                    $yp_paid = "0.00";
                    $paymentStatusOtherBills = "Unpaid";
                }
            }
            else {
                $yp_charges_amount = 0.00;
                $sst_charges_amount = 0.00;
                $stamping_charges_amount = 0.00;
                $yp_charges_paid = 0.00;
                $sst_charges_paid = 0.00;
                $stamping_charges_paid = 0.00;
                $yp_charges_due = 0.00;
                $sst_charges_due = 0.00;
                $stamping_charges_due = 0.00;

                //set readonly
                
                if($depositBillOther_ID == ""){
                    $readonly_otherbills = "";
                }
            }
            $totalBillingAmount = $two_month_rental_amount + $utility_amount + $yp_charges_amount + $sst_charges_amount + $stamping_charges_amount;
            $totalAmountPaid = $two_months_amount_paid + $utility_amount_paid + $yp_charges_paid + $sst_charges_paid + $stamping_charges_paid;
            $totalAmountDue = $two_month_rental_due + $utility_due + $yp_charges_due + $sst_charges_due +  $stamping_charges_due;

            
            // ALL DEPOSIT INFO END
			?>
			
            
            <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-md-12" >
                                <div class="card">
                                 <form action="depositPayNowController.php" method="post">
                                    <div class="card-header ">
										<table width="100%">
											<tr>
												<td>
													<h5 class="m-0 font-weight-bold text-primary">
														DEPOSIT PAYMENT
													</h5>
												</td>
												<td>
													<label for="inline-checkbox1" class="form-check-label " style="float:right">
														<input type="checkbox" id="chkBox_fullpayment" name="chkBox_fullpayment" value="option1" class="form-check-input" onclick="makeFullPayment()">MAKE FULL PAYMENT
													</label>
												</td>
											</tr>
										</table>
                                    </div>
                                    <div class="card-body card-block">
                                        <table class="table table-bordered table-hover table-sm" id="dataTable" width="70%" cellspacing="0" style="font-size: 12px">
                                            <thead>
                                                <tr>
                                                    <th scope="col">INFO</th>
                                                    <th scope="col">BILLING INFO</th>
                                                    <th scope="col">AMOUNT PAID </th>
                                                    <th scope="col">PAY NOW</th>
                                                    <th scope="col">BALANCE</th>
                                                    <th scope="col">STATUS</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td>
                                                        Two Month Rental (RM) 
                                                    </td>
                                                    <td>
                                                        <input type="number" id="two_month_rental_amount"  name="two_month_rental_amount" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $two_month_rental_amount?>" <?php echo $readonly_depositbills ?>>
                                                    </td>
                                                    <td>
                                                        
                                                        <input type="number" id="two_months_amount_paid"  name="two_months_amount_paid" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $two_months_amount_paid?>" readonly="readonly">
                                                    </td>
                                                    <td>
                                                        <input type="number" id="twoMonthRental_payNow"  name="twoMonthRental_payNow" step="0.01" min="0.00" max='<?php echo $two_month_rental_due?>'  class="form-control" required="" onchange="twoMonthRentalDue()" placeholder="0.00" style="text-align: right;" value="0.00" <?php if($two_month_rental_amount == $two_months_amount_paid) echo $readonly_depositbills?> >
                                                    </td>
                                                    <td>
                                                        <input type="number" id="twoMonthRental_due"  name="twoMonthRental_due" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $two_month_rental_due?>" readonly="readonly">
                                                    </td>
                                                    <td rowspan="2">
                                                        <input type="text" id="deposit_paymentStatus"  name="deposit_paymentStatus"  class="form-control" required=""   style="text-align: right;" value="<?php echo ucfirst($deposit_paymentStatus)?>" readonly="readonly">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                       Utilities Fee (RM) 
                                                    </td>
                                                    <td>
                                                       
                                                        <input type="number" id="utility_amount"  name="utility_amount" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $utility_amount?>" <?php echo $readonly_depositbills ?>>
                                                   
                                                    </td>
                                                    <td>
                                                        
                                                        <input type="number" id="utility_amount_paid"  name="utility_amount_paid" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $utility_amount_paid?>" readonly="readonly">
                                                   
                                                    </td>
                                                    <td>
                                                        <input type="number" id="utility_payNow"  name="utility_payNow" step="0.01"  class="form-control" required="" onchange="utilityDue()" placeholder="0.00" style="text-align: right;" value="0.00" <?php if($utility_amount == $utility_amount_paid) echo $readonly_depositbills?> >
                                                    </td>
                                                    <td>
                                                        <input type="number" id="utility_due"  name="utility_due" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $utility_due ?>" readonly="readonly">
                                                    </td>
                                                    
                                                </tr>
                                                <tr>
                                                    <td>
                                                       Yuran Pelbagai (RM) 
                                                    </td>
                                                    <td>
                                                       
                                                        <input type="number" id="yp_charges_amount"  name="yp_charges_amount" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $yp_charges_amount?>" <?php echo $readonly_otherbills ?>>
                                                   
                                                    </td>
                                                    <td>
                                                        
                                                        <input type="number" id="yp_charges_paid"  name="yp_charges_paid" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $yp_charges_paid?>" readonly="readonly">
                                                   
                                                    </td>
                                                    <td>
                                                        <input type="number" id="yp_charges_payNow"  name="yp_charges_payNow" step="0.01"  class="form-control" required="" onchange="ypDue(<?php echo $sst_percent_view/100 ?>)" placeholder="0.00" style="text-align: right;" value="0.00" <?php if($yp_charges_amount == $yp_charges_paid) echo $readonly_otherbills?> >
                                                    </td>
                                                    <td>
                                                        <input type="number" id="yp_charges_due"  name="yp_charges_due" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $yp_charges_due ?>"  readonly="readonly">
                                                    </td>
                                                    <td rowspan="3">
                                                        <input type="text" id="paymentStatusOtherBills"  name="paymentStatusOtherBills"  class="form-control" required=""   style="text-align: right;" value="<?php echo ucfirst($paymentStatusOtherBills)?>" readonly="readonly">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                       SST Charges <?php echo $sst_percent_view?>% from Yuran Pelbagai (RM) 
                                                    </td>
                                                    <td>
                                                       
                                                        <input type="number" id="sst_charges_amount"  name="sst_charges_amount" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $sst_charges_amount?>" <?php echo $readonly_otherbills ?>>
                                                   
                                                    </td>
                                                    <td>
                                                        <input type="number" id="sst_charges_paid"  name="sst_charges_paid" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $sst_charges_paid?>" readonly="readonly">
                                                    </td>
                                                    <td>
                                                        <input type="number" id="sst_charges_payNow"  name="sst_charges_payNow" step="0.01"  class="form-control" required="" onchange="sstChargeDue()" placeholder="0.00" style="text-align: right;" value="0.00"  <?php if($sst_charges_amount == $sst_charges_paid) echo $readonly_otherbills?> >
                                                    </td>
                                                    <td>
                                                        <input type="number" id="sst_charges_due"  name="sst_charges_due" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $sst_charges_due ?>" readonly="readonly">
                                                    </td>
                                                    
                                                </tr>
                                                <tr>
                                                    <td>
                                                       Stamping Charges (RM) 
                                                    </td>
                                                    <td>
                                                        <input type="number" id="stamping_charges_amount"  name="stamping_charges_amount" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $stamping_charges_amount?>" <?php echo $readonly_otherbills ?>>
                                                   </td>
                                                    <td>
                                                        <input type="number" id="stamping_charges_paid"  name="stamping_charges_paid" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $stamping_charges_paid?>" readonly="readonly">
                                                   </td>
                                                    <td>
                                                        <input type="number" id="stamping_charges_payNow"  name="stamping_charges_payNow" step="0.01"  class="form-control" required="" onchange="stampingChargeDue()" placeholder="0.00" style="text-align: right;" value="0.00"  <?php if($sst_charges_amount == $sst_charges_paid) echo $readonly_otherbills?>  >
                                                    </td>
                                                    <td>
                                                        <input type="number" id="stamping_charges_due"  name="stamping_charges_due" step="0.01"  class="form-control" required=""  placeholder="0.00" style="text-align: right;" value="<?php echo $stamping_charges_due ?>" readonly="readonly">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                      <b> TOTAL (RM) </b>
                                                    </td>
                                                    <td>
                                                        <input type="TEXT" id="total_charges_amount"  name="total_charges_amount" step="0.01"  class="form-control" required=""   style="text-align: right;" value="<?php echo number_format($totalBillingAmount,2)?>" readonly="readonly">
                                                   </td>
                                                    <td>
                                                        <input type="TEXT" id="total_charges_paid"  name="total_charges_paid" step="0.01"  class="form-control" required=""  style="text-align: right;" value="<?php echo number_format($totalAmountPaid,2)?>" readonly="readonly">
                                                   </td>
                                                    <td>
                                                        <input type="TEXT" id="total_charges_payNow"  name="total_charges_payNow" step="0.01"  class="form-control" required=""   style="text-align: right;" value="0.00" readonly="readonly">
                                                    </td>
                                                    <td>
                                                        <input type="text" id="total_charges_due"  name="total_charges_due" step="0.01"  class="form-control" required=""   style="text-align: right;" value="<?php echo number_format($totalAmountDue,2); ?>" readonly="readonly">
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="6"> 
                                                        <input type="hidden" name="deposit_bill_id" value="<?php echo $depositBill_id ?>"/>
                                                        <input type="hidden" name="deposit_bill_other_id" value="<?php echo $depositBillOther_ID ?>"/>
                                                        <input type="hidden" name="tenant_id" value="<?php echo $_GET["tenant_id"] ?>"/>
                                                        <button type="submit" id="submitBtn" class="btn btn-outline-success btn-sm" style="float:right" >Submit</button> &nbsp;&nbsp;&nbsp;
                                                        <button type="reset" style="float:right" class="btn btn-outline-warning btn-sm">Reset</button>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        
                                        </table>
                                    </form>
                                </div>
                                <div class="card-footer ">
                                    <h5 class="m-0  text-primary">
                                    <?PHP include "footer.php";?>
                                        
                                    </h5>
                                </div>
                            </div>
                        </div>
                        
                       
                        
                    </div>
                </div>
            </div>
            <!-- END MAIN CONTENT-->
            <!-- END PAGE CONTAINER-->
        <!-- </div> -->
		
    </div>
    <?PHP include "footerLink.php";?>
</body>

</html>

<script>
const chkBox_fullpayment = document.getElementById('chkBox_fullpayment');
chkBox_fullpayment.addEventListener('change', (event) => {
  if (event.currentTarget.checked) {
   // alert('chkBox_fullpayment');
    

  } else {
   // alert('not checked');
    document.getElementById("twoMonthRental_payNow").value = "0.00" ;
	document.getElementById("utility_payNow").value = "0.00"; 
	document.getElementById("yp_charges_payNow").value = "0.00" ;
	document.getElementById("sst_charges_payNow").value =  "0.00";
	document.getElementById("stamping_charges_payNow").value =  "0.00";
	document.getElementById("total_charges_payNow").value =  "0.00";
	}
  }
)
function makeFullPayment(){
	
	var twoMonthRental_due = document.getElementById("twoMonthRental_due").value;
	var utility_due = document.getElementById("utility_due").value;
	var yp_charges_due = document.getElementById("yp_charges_due").value;
	var sst_charges_due = document.getElementById("sst_charges_due").value;
	var stamping_charges_due = document.getElementById("stamping_charges_due").value;
	//alert(stamping_charges_due);
	var fullAmount_due = parseFloat(twoMonthRental_due) + parseFloat(utility_due) + parseFloat(yp_charges_due) + parseFloat(sst_charges_due) + parseFloat(stamping_charges_due);
	
	
	document.getElementById("twoMonthRental_payNow").value = twoMonthRental_due ;
	document.getElementById("utility_payNow").value = utility_due; 
	document.getElementById("yp_charges_payNow").value = yp_charges_due ;
	document.getElementById("sst_charges_payNow").value = sst_charges_due;
	document.getElementById("stamping_charges_payNow").value = stamping_charges_due;
	document.getElementById("total_charges_payNow").value = fullAmount_due.toFixed(2);
}
function twoMonthRentalDue(){
    //alert
    var two_month_rental_amount = document.getElementById("two_month_rental_amount").value;
    var two_months_amount_paid = document.getElementById("two_months_amount_paid").value;
    var twoMonthRental_payNow = document.getElementById("twoMonthRental_payNow").value;
    var twoMonthRental_due = document.getElementById("twoMonthRental_due").value;
    var utility_amount = document.getElementById("utility_amount").value;
    var utility_amount_paid = document.getElementById("utility_amount_paid").value;
    var utility_due = document.getElementById("utility_due").value;
    var utility_payNow = document.getElementById("utility_payNow").value;
    var deposit_paymentStatus = document.getElementById("deposit_paymentStatus").value;
    
    if(two_months_amount_paid == "")
    two_months_amount_paid = 0.00;
    if(utility_amount_paid == "")
    utility_amount_paid = 0.00;

	if(two_month_rental_amount == 0.00){
		document.getElementById("two_month_rental_amount").value = twoMonthRental_payNow;
		two_month_rental_amount = twoMonthRental_payNow;
	}
	if(utility_amount == 0.00){
		document.getElementById("utility_amount").value = utility_payNow;
		utility_amount = utility_payNow;
	}
    
    var updateBalance_twoMonthRental = parseFloat(two_month_rental_amount) - parseFloat(two_months_amount_paid) - parseFloat(twoMonthRental_payNow);
    var updateBalance_utility = parseFloat(utility_amount) - parseFloat(utility_amount_paid) - parseFloat(utility_payNow);
   
    var updateBalance = parseFloat(updateBalance_twoMonthRental) - parseFloat(updateBalance_utility);
    updateBalance_twoMonthRental = updateBalance_twoMonthRental.toFixed(2);
   // alert("two_month_rental_amount: " +two_month_rental_amount+"two_months_amount_paid"+two_months_amount_paid+"twoMonthRental_payNow"+ twoMonthRental_payNow);
    document.getElementById("twoMonthRental_due").value =  updateBalance_twoMonthRental;
    
    //set status unpaid/partial/paid - start
    var totalDeposit_amount = parseFloat(two_month_rental_amount) + parseFloat(utility_amount)  ;
    var totalDeposit_paid = parseFloat(two_months_amount_paid) + parseFloat(utility_amount_paid);
    var totalDeposit_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow);
    var totalDeposit_due = parseFloat(totalDeposit_amount) - parseFloat(totalDeposit_paid) - parseFloat(totalDeposit_payNow);
    
    var deposit_paymentStatus = "";
    if(totalDeposit_due == totalDeposit_amount){
        document.getElementById("deposit_paymentStatus").value = "Unpaid";
    }
    else if(totalDeposit_due < totalDeposit_amount && totalDeposit_due != 0.00){
        document.getElementById("deposit_paymentStatus").value = "Partial";
    }
    else if(totalDeposit_due == 0.00){
        document.getElementById("deposit_paymentStatus").value = "Paid";
    }
    //set status unpaid/partial/paid - end
   
    //untuk kira total (bawah sekali) - start
    var yp_charges_amount = document.getElementById("yp_charges_amount").value;
    var yp_charges_paid = document.getElementById("yp_charges_paid").value;
    var yp_charges_payNow = document.getElementById("yp_charges_payNow").value;
    var yp_charges_due = document.getElementById("yp_charges_due").value;
    
    var sst_charges_amount = document.getElementById("sst_charges_amount").value;
    var sst_charges_paid = document.getElementById("sst_charges_paid").value;
    var sst_charges_payNow = document.getElementById("sst_charges_payNow").value;
    var sst_charges_due = document.getElementById("sst_charges_due").value;

    var stamping_charges_amount = document.getElementById("stamping_charges_amount").value;
    var stamping_charges_paid = document.getElementById("stamping_charges_paid").value;
    var stamping_charges_payNow = document.getElementById("stamping_charges_payNow").value;
    var stamping_charges_due = document.getElementById("stamping_charges_due").value;

    if(yp_charges_paid == "")
    yp_charges_paid = 0.00;
    if(sst_charges_paid == "")
    sst_charges_paid = 0.00;
    if(stamping_charges_paid == "")
    stamping_charges_paid = 0.00;

    var fullAmount = parseFloat(two_month_rental_amount) + parseFloat(utility_amount) + parseFloat(yp_charges_amount) + parseFloat(sst_charges_amount) + parseFloat(stamping_charges_amount);
    var fullAmount_paid = parseFloat(two_months_amount_paid) + parseFloat(utility_amount_paid) + parseFloat(yp_charges_paid)  + parseFloat(sst_charges_paid) + parseFloat(stamping_charges_paid);
    var fullAmount_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow) + parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow) + parseFloat(stamping_charges_payNow);
    //alert("two_months_amount_paid: " + two_months_amount_paid + "utility_amount_paid: " + utility_amount_paid + "yp_charges_paid: " + yp_charges_paid + "sst_charges_paid: " + sst_charges_paid + "stamping_charges_paid: " + stamping_charges_paid);
    var totalBalance = 0.00;
    totalBalance = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow) ;
    
    //var total_charges_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow) + parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow) +  parseFloat(stamping_charges_payNow);
    fullAmount_payNow = fullAmount_payNow.toFixed(2);
    //alert("total_charges_payNow: " + fullAmount_payNow + "twoMonthRental_payNow: " + twoMonthRental_payNow + "utility_payNow: " + utility_payNow);
    document.getElementById("total_charges_payNow").value = fullAmount_payNow;

   
    var total_charges_due = parseFloat(twoMonthRental_due) + parseFloat(utility_due) + parseFloat(yp_charges_due) + parseFloat(sst_charges_due) +  parseFloat(stamping_charges_due);
    total_charges_due = total_charges_due.toFixed(2);
    var total_charges_payNow = document.getElementById("total_charges_payNow").value;
     //alert("fullAmount: " + fullAmount + "fullAmount_paid: " + fullAmount_paid + "total_charges_payNow: " + total_charges_payNow);
    var total_due = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow);
    total_due = total_due.toFixed(2);
    //alert("total_due: " + total_due);
    document.getElementById("total_charges_due").value = total_due;

}

function utilityDue(){
    //alert
    var two_month_rental_amount = document.getElementById("two_month_rental_amount").value;
    var two_months_amount_paid = document.getElementById("two_months_amount_paid").value;
    var twoMonthRental_payNow = document.getElementById("twoMonthRental_payNow").value;
    var twoMonthRental_due = document.getElementById("twoMonthRental_due").value;
    var utility_amount = document.getElementById("utility_amount").value;
    var utility_amount_paid = document.getElementById("utility_amount_paid").value;
    var utility_payNow = document.getElementById("utility_payNow").value;
    var utility_due = document.getElementById("utility_due").value;

    if(two_months_amount_paid == "")
    two_months_amount_paid = 0.00;
    if(utility_amount_paid == "")
    utility_amount_paid = 0.00;
	
	if(two_month_rental_amount == 0.00){
		document.getElementById("two_month_rental_amount").value = twoMonthRental_payNow;
		two_month_rental_amount = twoMonthRental_payNow;
	}
	if(utility_amount == 0.00){
		document.getElementById("utility_amount").value = utility_payNow;
		utility_amount = utility_payNow;
	}

    var updateBalance_twoMonthRental = parseFloat(two_month_rental_amount) - parseFloat(two_months_amount_paid) - parseFloat(twoMonthRental_payNow);
    var updateBalance_utility = parseFloat(utility_amount) - parseFloat(utility_amount_paid) - parseFloat(utility_payNow);
   
    var updateBalance = parseFloat(updateBalance_twoMonthRental) - parseFloat(updateBalance_utility);
    updateBalance_utility = updateBalance_utility.toFixed(2);
   // alert("two_month_rental_amount: " +two_month_rental_amount+"two_months_amount_paid"+two_months_amount_paid+"twoMonthRental_payNow"+ twoMonthRental_payNow);
    document.getElementById("utility_due").value =  updateBalance_utility;


    //set status unpaid/partial/paid - start
    var totalDeposit_amount = parseFloat(two_month_rental_amount) + parseFloat(utility_amount)  ;
    var totalDeposit_paid = parseFloat(two_months_amount_paid) + parseFloat(utility_amount_paid);
    var totalDeposit_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow);
    var totalDeposit_due = parseFloat(totalDeposit_amount) - parseFloat(totalDeposit_paid) - parseFloat(totalDeposit_payNow);
    
    var deposit_paymentStatus = "";
    if(totalDeposit_due == totalDeposit_amount){
        document.getElementById("deposit_paymentStatus").value = "Unpaid";
    }
    else if(totalDeposit_due < totalDeposit_amount && totalDeposit_due != 0.00){
        document.getElementById("deposit_paymentStatus").value = "Partial";
    }
    else if(totalDeposit_due == 0.00){
        document.getElementById("deposit_paymentStatus").value = "Paid";
    }
    //set status unpaid/partial/paid - end
   
    //untuk kira total (bawah sekali) - start
    var yp_charges_amount = document.getElementById("yp_charges_amount").value;
    var yp_charges_paid = document.getElementById("yp_charges_paid").value;
    var yp_charges_payNow = document.getElementById("yp_charges_payNow").value;
    var yp_charges_due = document.getElementById("yp_charges_due").value;
    
    var sst_charges_amount = document.getElementById("sst_charges_amount").value;
    var sst_charges_paid = document.getElementById("sst_charges_paid").value;
    var sst_charges_payNow = document.getElementById("sst_charges_payNow").value;
    var sst_charges_due = document.getElementById("sst_charges_due").value;

    var stamping_charges_amount = document.getElementById("stamping_charges_amount").value;
    var stamping_charges_paid = document.getElementById("stamping_charges_paid").value;
    var stamping_charges_payNow = document.getElementById("stamping_charges_payNow").value;
    var stamping_charges_due = document.getElementById("stamping_charges_due").value;

    if(yp_charges_paid == "")
    yp_charges_paid = 0.00;
    if(sst_charges_paid == "")
    sst_charges_paid = 0.00;
    if(stamping_charges_paid == "")
    stamping_charges_paid = 0.00;

    var fullAmount = parseFloat(two_month_rental_amount) + parseFloat(utility_amount) + parseFloat(yp_charges_amount) + parseFloat(sst_charges_amount) + parseFloat(stamping_charges_amount);
    var fullAmount_paid = parseFloat(two_months_amount_paid) + parseFloat(utility_amount_paid) + parseFloat(yp_charges_paid)  + parseFloat(sst_charges_paid) + parseFloat(stamping_charges_paid);
    var fullAmount_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow) + parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow) + parseFloat(stamping_charges_payNow);
    //alert("two_months_amount_paid: " + two_months_amount_paid + "utility_amount_paid: " + utility_amount_paid + "yp_charges_paid: " + yp_charges_paid + "sst_charges_paid: " + sst_charges_paid + "stamping_charges_paid: " + stamping_charges_paid);
    var totalBalance = 0.00;
    totalBalance = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow) ;
    
    //var total_charges_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow) + parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow) +  parseFloat(stamping_charges_payNow);
    fullAmount_payNow = fullAmount_payNow.toFixed(2);
    //alert("total_charges_payNow: " + fullAmount_payNow + "twoMonthRental_payNow: " + twoMonthRental_payNow + "utility_payNow: " + utility_payNow);
    document.getElementById("total_charges_payNow").value = fullAmount_payNow;

   
    var total_charges_due = parseFloat(twoMonthRental_due) + parseFloat(utility_due) + parseFloat(yp_charges_due) + parseFloat(sst_charges_due) +  parseFloat(stamping_charges_due);
    total_charges_due = total_charges_due.toFixed(2);
    var total_charges_payNow = document.getElementById("total_charges_payNow").value;
     //alert("fullAmount: " + fullAmount + "fullAmount_paid: " + fullAmount_paid + "total_charges_payNow: " + total_charges_payNow);
    var total_due = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow);
    total_due = total_due.toFixed(2);
    //alert("total_due: " + total_due);
    document.getElementById("total_charges_due").value = total_due;
    //set status unpaid/partial/paid - end


    
}
function ypDue(sst_percent_view){

    var two_month_rental_amount = document.getElementById("two_month_rental_amount").value;
    var two_months_amount_paid = document.getElementById("two_months_amount_paid").value;
    var twoMonthRental_payNow = document.getElementById("twoMonthRental_payNow").value;
    var twoMonthRental_due = document.getElementById("twoMonthRental_due").value;
    var utility_amount = document.getElementById("utility_amount").value;
    var utility_amount_paid = document.getElementById("utility_amount_paid").value;
    var utility_payNow = document.getElementById("utility_payNow").value;
    var utility_due = document.getElementById("utility_due").value;

    var yp_charges_amount = document.getElementById("yp_charges_amount").value;
    var yp_charges_paid = document.getElementById("yp_charges_paid").value;
    var yp_charges_payNow = document.getElementById("yp_charges_payNow").value;
    var yp_charges_due = document.getElementById("yp_charges_due").value;
    
     var sst_charges_amount = document.getElementById("sst_charges_amount").value;
     var sst_charges_paid = document.getElementById("sst_charges_paid").value;
     var sst_charges_payNow = document.getElementById("sst_charges_payNow").value;
     var sst_charges_due = document.getElementById("sst_charges_due").value;

     var stamping_charges_amount = document.getElementById("stamping_charges_amount").value;
     var stamping_charges_paid = document.getElementById("stamping_charges_paid").value;
     var stamping_charges_payNow = document.getElementById("stamping_charges_payNow").value;
     var stamping_charges_due = document.getElementById("stamping_charges_due").value;
    
    var paymentStatusOtherBills = document.getElementById("paymentStatusOtherBills").value;

    if(two_months_amount_paid == "")
    two_months_amount_paid = 0.00;
    if(utility_amount_paid == "")
    utility_amount_paid = 0.00;
    if(yp_charges_paid == "")
    yp_charges_paid = 0.00;
    if(sst_charges_paid == "")
    sst_charges_paid = 0.00;
    if(stamping_charges_paid == "")
    stamping_charges_paid = 0.00;

    var updateBalance_yp = 0.00;
	if(yp_charges_amount == 0.00){
		document.getElementById("yp_charges_amount").value = yp_charges_payNow;
		yp_charges_amount = yp_charges_payNow;
	}
	if(sst_charges_amount == 0.00){
		//kira sst charges based on ypDue
		sst_charges_amount = sst_percent_view * yp_charges_amount;
		sst_charges_amount = sst_charges_amount.toFixed(2);
		document.getElementById("sst_charges_amount").value = sst_charges_amount;
		//sst_charges_amount = sst_charges_payNow;
	}
	if(stamping_charges_amount == 0.00){
		document.getElementById("stamping_charges_amount").value = stamping_charges_payNow;
		stamping_charges_amount = stamping_charges_payNow;
	}	
    updateBalance_yp = parseFloat(yp_charges_amount) - parseFloat(yp_charges_paid) - parseFloat(yp_charges_payNow);
    updateBalance_yp = updateBalance_yp.toFixed(2);

    document.getElementById("yp_charges_due").value = updateBalance_yp;

    //update status payment - check payment balance
    
     var fullAmount = parseFloat(yp_charges_amount)+ parseFloat(sst_charges_amount)+ parseFloat(stamping_charges_amount);
     var fullAmount_paid = parseFloat(yp_charges_paid)+ parseFloat(sst_charges_paid)+ parseFloat(stamping_charges_paid);
     var fullAmount_payNow = parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow)+ parseFloat(stamping_charges_payNow);
     var fullAmount_due = parseFloat(yp_charges_due) + parseFloat(sst_charges_due)+ parseFloat(stamping_charges_due);

    
     

    //alert("UNPAID FULL AMOUNT: "+fullAmount);
    
    var totalBalance = 0.00;
   
    totalBalance = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow) ;
    totalBalance = totalBalance.toFixed(2);
    //var deposit_paymentStatus = "Unpaid";
    if(totalBalance == fullAmount){
        //alert("2 UNPAID FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = paymentStatusOtherBills;
    }
    else if(totalBalance < fullAmount && totalBalance != 0.00){
        //alert(" PARTIAL FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = "Partial";
    }
    else if(totalBalance == 0.00){
        //alert("PAID FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = "Paid";
    }
    var fullAmount = parseFloat(two_month_rental_amount) + parseFloat(utility_amount) + parseFloat(yp_charges_amount) + parseFloat(sst_charges_amount) + parseFloat(stamping_charges_amount);
    var fullAmount_paid = parseFloat(two_months_amount_paid) + parseFloat(utility_amount_paid) + parseFloat(yp_charges_paid)  + parseFloat(sst_charges_paid) + parseFloat(stamping_charges_paid);
    var fullAmount_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow) + parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow) + parseFloat(stamping_charges_payNow);
    
    fullAmount_payNow = fullAmount_payNow.toFixed(2);
     
    document.getElementById("total_charges_payNow").value = fullAmount_payNow;
    //alert("fullAmount= "+fullAmount+" fullAmount_paid= " + fullAmount_paid + " fullAmount_payNow= " + fullAmount_payNow);
    var totalBalance = 0.00;
    totalBalance = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow) ;
    totalBalance = totalBalance.toFixed(2);


    document.getElementById("total_charges_due").value = totalBalance;
}

function sstChargeDue(){

    var two_month_rental_amount = document.getElementById("two_month_rental_amount").value;
    var two_months_amount_paid = document.getElementById("two_months_amount_paid").value;
    var twoMonthRental_payNow = document.getElementById("twoMonthRental_payNow").value;
    var twoMonthRental_due = document.getElementById("twoMonthRental_due").value;
    var utility_amount = document.getElementById("utility_amount").value;
    var utility_amount_paid = document.getElementById("utility_amount_paid").value;
    var utility_payNow = document.getElementById("utility_payNow").value;
    var utility_due = document.getElementById("utility_due").value;

    var yp_charges_amount = document.getElementById("yp_charges_amount").value;
    var yp_charges_paid = document.getElementById("yp_charges_paid").value;
    var yp_charges_payNow = document.getElementById("yp_charges_payNow").value;
    var yp_charges_due = document.getElementById("yp_charges_due").value;
    
    var sst_charges_amount = document.getElementById("sst_charges_amount").value;
    var sst_charges_paid = document.getElementById("sst_charges_paid").value;
    var sst_charges_payNow = document.getElementById("sst_charges_payNow").value;
    var sst_charges_due = document.getElementById("sst_charges_due").value;

    var stamping_charges_amount = document.getElementById("stamping_charges_amount").value;
    var stamping_charges_paid = document.getElementById("stamping_charges_paid").value;
    var stamping_charges_payNow = document.getElementById("stamping_charges_payNow").value;
    var stamping_charges_due = document.getElementById("stamping_charges_due").value;
    
    var paymentStatusOtherBills = document.getElementById("paymentStatusOtherBills").value;

    if(two_months_amount_paid == "")
    two_months_amount_paid = 0.00;
    if(utility_amount_paid == "")
    utility_amount_paid = 0.00;
    if(yp_charges_paid == "")
    yp_charges_paid = 0.00;
    if(sst_charges_paid == "")
    sst_charges_paid = 0.00;
    if(stamping_charges_paid == "")
    stamping_charges_paid = 0.00;

    //alert("sst_charges_amount= "+sst_charges_amount+" sst_charges_paid= " + sst_charges_paid + " sst_charges_payNow= " + sst_charges_payNow);
   

    var updateBalance_sst = 0.00;
	
	if(yp_charges_amount == 0.00){
		document.getElementById("yp_charges_amount").value = yp_charges_payNow;
		yp_charges_amount = yp_charges_payNow;
	}
	if(sst_charges_amount == 0.00){
		document.getElementById("sst_charges_amount").value = sst_charges_payNow;
		sst_charges_amount = sst_charges_payNow;
	}
	if(stamping_charges_amount == 0.00){
		document.getElementById("stamping_charges_amount").value = stamping_charges_payNow;
		stamping_charges_amount = stamping_charges_payNow;
	}	
	
    updateBalance_sst = parseFloat(sst_charges_amount) - parseFloat(sst_charges_paid) - parseFloat(sst_charges_payNow);
    updateBalance_sst = updateBalance_sst.toFixed(2);
   
    document.getElementById("sst_charges_due").value = updateBalance_sst;

    //update status payment - check payment balance
    
     var fullAmount = parseFloat(yp_charges_amount)+ parseFloat(sst_charges_amount)+ parseFloat(stamping_charges_amount);
     var fullAmount_paid = parseFloat(yp_charges_paid)+ parseFloat(sst_charges_paid)+ parseFloat(stamping_charges_paid);
     var fullAmount_payNow = parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow)+ parseFloat(stamping_charges_payNow);
    //alert("UNPAID FULL AMOUNT: "+fullAmount);
    
    var totalBalance = 0.00;
   
    totalBalance = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow) ;
    totalBalance = totalBalance.toFixed(2);
    //var deposit_paymentStatus = "Unpaid";
    if(totalBalance == fullAmount){
      //  alert("2 UNPAID FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = paymentStatusOtherBills;
    }
    else if(totalBalance < fullAmount && totalBalance != 0.00){
      //  alert(" PARTIAL FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = "Partial";
    }
    else if(totalBalance == 0.00){
       // alert("PAID FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = "Paid";
    }
    var fullAmount = parseFloat(two_month_rental_amount) + parseFloat(utility_amount) + parseFloat(yp_charges_amount) + parseFloat(sst_charges_amount) + parseFloat(stamping_charges_amount);
    var fullAmount_paid = parseFloat(two_months_amount_paid) + parseFloat(utility_amount_paid) + parseFloat(yp_charges_paid)  + parseFloat(sst_charges_paid) + parseFloat(stamping_charges_paid);
    var fullAmount_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow) + parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow) + parseFloat(stamping_charges_payNow);
    
    fullAmount_payNow = fullAmount_payNow.toFixed(2);
     
    document.getElementById("total_charges_payNow").value = fullAmount_payNow;
    
    var totalBalance = 0.00;
    totalBalance = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow) ;
    totalBalance = totalBalance.toFixed(2);
    document.getElementById("total_charges_due").value = totalBalance;
}

function stampingChargeDue(){


    var two_month_rental_amount = document.getElementById("two_month_rental_amount").value;
    var two_months_amount_paid = document.getElementById("two_months_amount_paid").value;
    var twoMonthRental_payNow = document.getElementById("twoMonthRental_payNow").value;
    var twoMonthRental_due = document.getElementById("twoMonthRental_due").value;
    var utility_amount = document.getElementById("utility_amount").value;
    var utility_amount_paid = document.getElementById("utility_amount_paid").value;
    var utility_payNow = document.getElementById("utility_payNow").value;
    var utility_due = document.getElementById("utility_due").value;

    var yp_charges_amount = document.getElementById("yp_charges_amount").value;
    var yp_charges_paid = document.getElementById("yp_charges_paid").value;
    var yp_charges_payNow = document.getElementById("yp_charges_payNow").value;
    var yp_charges_due = document.getElementById("yp_charges_due").value;
    
    var sst_charges_amount = document.getElementById("sst_charges_amount").value;
    var sst_charges_paid = document.getElementById("sst_charges_paid").value;
    var sst_charges_payNow = document.getElementById("sst_charges_payNow").value;
    var sst_charges_due = document.getElementById("sst_charges_due").value;

    var stamping_charges_amount = document.getElementById("stamping_charges_amount").value;
    var stamping_charges_paid = document.getElementById("stamping_charges_paid").value;
    var stamping_charges_payNow = document.getElementById("stamping_charges_payNow").value;
    var stamping_charges_due = document.getElementById("stamping_charges_due").value;
    
    var paymentStatusOtherBills = document.getElementById("paymentStatusOtherBills").value;

    if(two_months_amount_paid == "")
    two_months_amount_paid = 0.00;
    if(utility_amount_paid == "")
    utility_amount_paid = 0.00;
    if(yp_charges_paid == "")
    yp_charges_paid = 0.00;
    if(sst_charges_paid == "")
    sst_charges_paid = 0.00;
    if(stamping_charges_paid == "")
    stamping_charges_paid = 0.00;

    if(stamping_charges_payNow > 0.00 && stamping_charges_amount == 0.00){
        document.getElementById("stamping_charges_amount").value = stamping_charges_payNow;
        stamping_charges_amount = stamping_charges_payNow;
    }

   // alert("stamping_charges_amount= "+stamping_charges_amount+" stamping_charges_paid= " + stamping_charges_paid + " stamping_charges_payNow= " + stamping_charges_payNow);
    
    var updateBalance_stamping = 0.00;
	
	if(yp_charges_amount == 0.00){
		document.getElementById("yp_charges_amount").value = yp_charges_payNow;
		yp_charges_amount = yp_charges_payNow;
	}
	if(sst_charges_amount == 0.00){
		document.getElementById("sst_charges_amount").value = sst_charges_payNow;
		sst_charges_amount = sst_charges_payNow;
	}
	if(stamping_charges_amount == 0.00){
		document.getElementById("stamping_charges_amount").value = stamping_charges_payNow;
		stamping_charges_amount = stamping_charges_payNow;
	}	
	
    updateBalance_stamping = parseFloat(stamping_charges_amount) - parseFloat(stamping_charges_paid) - parseFloat(stamping_charges_payNow);
    updateBalance_stamping = updateBalance_stamping.toFixed(2);
   
    document.getElementById("stamping_charges_due").value = updateBalance_stamping;
   

    //update status payment - check payment balance
    
    var fullAmount = parseFloat(yp_charges_amount)+ parseFloat(sst_charges_amount)+ parseFloat(stamping_charges_amount);
    var fullAmount_paid = parseFloat(yp_charges_paid)+ parseFloat(sst_charges_paid)+ parseFloat(stamping_charges_paid);
    var fullAmount_payNow = parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow)+ parseFloat(stamping_charges_payNow);
    
    
    var totalBalance = 0.00;
   
    totalBalance = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow) ;
    totalBalance = totalBalance.toFixed(2);
    //var deposit_paymentStatus = "Unpaid";
    if(totalBalance == fullAmount){
       // alert("2 UNPAID FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = paymentStatusOtherBills;
    }
    else if(totalBalance < fullAmount && totalBalance != 0.00){
       // alert(" PARTIAL FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = "Partial";
    }
    else if(totalBalance == 0.00){
      //  alert("PAID FULL AMOUNT: "+fullAmount);
        document.getElementById("paymentStatusOtherBills").value = "Paid";
    }
    var fullAmount = parseFloat(two_month_rental_amount) + parseFloat(utility_amount) + parseFloat(yp_charges_amount) + parseFloat(sst_charges_amount) + parseFloat(stamping_charges_amount);
    var fullAmount_paid = parseFloat(two_months_amount_paid) + parseFloat(utility_amount_paid) + parseFloat(yp_charges_paid)  + parseFloat(sst_charges_paid) + parseFloat(stamping_charges_paid);
    var fullAmount_payNow = parseFloat(twoMonthRental_payNow) + parseFloat(utility_payNow) + parseFloat(yp_charges_payNow) + parseFloat(sst_charges_payNow) + parseFloat(stamping_charges_payNow);
    
    fullAmount = fullAmount.toFixed(2);
    fullAmount_payNow = fullAmount_payNow.toFixed(2);
     
    document.getElementById("total_charges_payNow").value = fullAmount_payNow;
    document.getElementById("total_charges_amount").value = fullAmount;
    
    var totalBalance = 0.00;
    totalBalance = parseFloat(fullAmount) - parseFloat(fullAmount_paid) - parseFloat(fullAmount_payNow) ;
    
    totalBalance = totalBalance.toFixed(2);
  //  alert("totalBalance: "+totalBalance );
    document.getElementById("total_charges_due").value = totalBalance;
}



</script>
<!-- end document-->