<?
include getenv("DOCUMENT_ROOT")."/include/session_include.php";

//$func->checkAdmin("index.php");

$d_uid = trim($_POST["duid"]);

//echo "[$d_uid]";exit;

if ($mode == "") {
		$mode = "update";
		$btnName = "UPDATE";
		$admTag = "DISABLED";
}

if($d_uid == "") {
		$msg = "Invaild data. Please try again. [Err - d_uid / RECEIPT NOTE POPUP]";
		$func -> modalMsg ($msg, 1);
		exit();
} else {
	
		// Get Information
		$query = "SELECT * FROM tbl_daily WHERE d_uid = '".$d_uid."' LIMIT 1 ";
		$result=$jdb->fQuery($query, "fetch query error");
		//	echo"$query";

		for($i=0; $i<sizeof($result); $i++)
		{
			//list($key, $value) = each($result);
			foreach ( (Array) $result as $key => $value )			
				$$key = $value;
		}

		$d_paynoteSTR = str_replace("\\", "", $d_paynote);

}

?>



      <div class="modal-header">
        <h4 class="modal-title">ACCOUNTING NOTE</h4>
        <button type="button" class="btn" data-bs-dismiss="modal" aria-label="Close" style="color:#fff;"><i class="bi bi-x"></i></button>
      </div>
      <div class="modal-body">

				<FORM NAME=receiptNoteInfo id=receiptNoteInfo METHOD=POST >
			    	<input type=hidden name=actionStr value="RECEIPTNOTE">
			    	<input type=hidden name=actionPage value="">
			    	<input type=hidden name=d_uid id=d_uid value="<?=$d_uid?>">
						<input type=hidden name=mode id=mode value="update">

          <table class="tb-info-box">
            <tr>
              <td class="td-title-info">Note</td>
              <td class="td-text-info">
                <textarea id="d_paynote" class="textarea" name="d_paynote" rows="4" cols="20"><?=htmlspecialchars($d_paynoteSTR, ENT_QUOTES)?></textarea>
              </td>
            </tr>
          </table>
          <br>
          <div class="text-center grid-layout-col-2">
          	<button type="submit" id="buttonADD" class="btn-sub">SAVE</button>
            <button type="button" class="btn-gray" data-bs-dismiss="modal">CLOSE</button>
          </div>
        </FORM>
      </div>



<div class="modal fade" id="myModalPopup" tabindex="-1" role="dialog" aria-labelledby="myModalPopup"  style="opacity: 0.5; padding-right: 0px !important;">
  <div class="modal-dialog modal-dialog-centered modal-xl" role="document">
      <div class="modal-content" style="background-color:#2A9B56 !important; max-width:260px; margin: 0 auto;">
        <div class="myModalPopup-body" style="text-align: center; border-radius: 5px; max-height:60px;	font-size:18px; background-color:#2A9B56; color: #FFFFFF; font-weight: bold;padding:0.5em 1em; ">

        </div>     	
      </div>
  </div>
</div>



<script>

$(document).ready(function(){

	  $("#receiptNoteInfo").validate({
	    // Specify validation rules
	    /*ignore: ".ignore",
	    rules: {
	      d_quantity: {
	        required: true,
	        //minlength: 6,
	      },
	      d_payamount: {
	        required: "#d_paystatuspaid:checked",
	        //minlength: 6,
	      }, 	      
	    },
	    messages: {
					d_quantity: {
							required: "Please input Oil Quantity",
							//minlength: "Minimum of 6 characters.",
					},
					d_payamount: {
							required: "Please input Cash Amount",
							//minlength: "Minimum of 6 characters.",
					},						
	    },
	    */
	    errorElement : 'div',


		  submitHandler: function(form) {
		  	
		  	var $inputs = $(form).find("input, select, button, textarea");
		  	var serializedData = $(form).serialize();
		  	
		 							//e.preventDefault();
				         	/*
				         	var d_mode = $('#mode').val();				         	
									var d_uid = $('#d_uid').val();
									var d_visitdate = $('#d_visitdate').val();
									var d_driveruid = $('#d_driveruid').val();
									var d_customeruid = $('#d_customeruid').val();
									var d_quantity = $('#d_quantity').val();
									var d_sludge = $('#d_sludge').val();
									var d_payamount = $('#d_payamount').val();
									var d_paystatus = $('#d_paystatus').val();
									var d_note = $('#d_note').val();
				         	alert(d_mode); */

					        $.ajax({  
					             url:"/lib/receiptNote_lib_process.php",  
					             method:"POST",  
					             data: serializedData,
					             
					             /*
					             data:{d_mode:d_mode, d_uid:d_uid, d_visitdate:d_visitdate, d_driveruid:d_driveruid, 
					             			d_customeruid:d_customeruid, d_quantity:d_quantity, d_sludge:d_sludge, 
					             			d_payamount:d_payamount, d_paystatus:d_paystatus, d_note:d_note	},
					             */
					             //beforeSend:function(){  
					             //     $('#submitid').val("Updating");  
					             //},  
					             success:function(response){  
					                  //$('#addcartformid')[0].reset();  
					                  //For debugging
					                  //$('.rt_debugging').html(response);
					                  //alert(response);
					                  if (response) {
																$('.myModalPopup-body').html("Saved Successfully.");
																$('.myModalPopup-body').css('background-color', '#2A9B56');
																$('#myModalcustomerShortInfo').modal('hide');
																
							                  $('#myModalPopup').modal('show'); 
														    setTimeout(function () {
														        //$('#myModalcustomerShortInfo').modal('hide');
														        $('#myModalPopup').modal('hide'); 
														        parent.location.reload();
														    }, 1000);                  
					                  } else {
																$('.myModalPopup-body').html("Failed. Please Try again.");
																$('.myModalPopup-body').css('background-color', '#FF8205');
																
							                  $('#myModalPopup').modal('show'); 
														    setTimeout(function () {
														        $('#myModalPopup').modal('hide'); 
														    }, 1500); 
					                  }
					                  
					                  //$('#myModalAdminInfo').modal('hide');
					                  //$('.cart-item-no').html(response);  

					             }  
					        });  

			}		



	});
  
});
</script>


<style>
.error{
	color: red;
	font-weight: 200;
	margin-left: 0em;
}		
</style>