
function validation(url){
	xrow = new Number($('#row').val());
	chk_qty = 0;
				
				
						
	for(i=0;i<xrow;i++){
		qty = new Number($('#qty'+i).val());
		chk_qty  = chk_qty + qty;
	}
		
		if(chk_qty<=0){
			
			$.alert({
	        	title: 'Warning!',
    	    	content: 'Qty Produk Tidak Boleh Kosong!',
				action:	$('#pm0').focus()
			    });
				return false;
			}
			
		else if($('#supp_name').val()==""){
			$.alert({
	        	title: 'Warning!',
    	    	content: 'Nama Tidak Boleh Kosong!',
				action:	$('#supp_name').focus()
			    });
				return false;
			}
		else{
			dosubmit(url);
			}
				
}
	
function calc_cb(){
					xrow = new Number($('#row').val());
					amount = 0;
					for(i=0;i<xrow;i++){
						price = new Number( $('#pm_bprice'+i).val() );
						qty = new Number($('#qty'+i).val());
						disc = 0;
						pm_disctype = "P";
						
						if(qty=='NaN'){qty = 0;}
						
							if(pm_disctype=="P"){
								nett_price = price - (price * disc/100);
								}
							else{
								nett_price = price - disc;
								}
							subtotal = nett_price * qty;
							
							$('#nett_price'+i).val(nett_price);
							$('#subtotal'+i).val(subtotal);
							amount = amount + subtotal;
						}
						$('#subtotal').val(amount);
		calc_gtotal();
	}
	

				
function pm_auto_complete(i){
	

		$("#pm"+i).autocomplete('getproduct.php', {
		width: 450,
		matchContains: true,
		selectFirst: false
		});
		
			$("#pm"+i).result(function(event, data, formatted) {
				$("#pm_autoid"+i).val(data[1]);
				$("#pm_bprice"+i).val(data[3]);
			});
}

function get_ums(i){
	query = {
			pm_autoid:$('#pm_autoid'+i).val(),
			row:i
			}
			
		$.post('get_ums',query,function(e){
				$("#pm_ums"+i).html(e);
			})
	}

function add_detailrow(){

			xrow = new Number($('#row').val());
			
			query = {id:1,row:xrow}			
			
			nextrow = xrow + 1;
			
			$.post('getnewrow',query,function(data){
					$("#jt_table").last().append(data);
					$('#row').val(nextrow);
					$('#pm'+xrow).focus();
				})
}		
			
function chk_field(i){
			
				pm_autoid 	= new Number($('#pm_autoid'+i).val());
				qty 		= new Number($('#qty'+i).val());
				
				row = $('#row').val();
				curr  = new Number(i);
				
				if(curr+1==row){
					if(pm_autoid + qty > 0){
						add_detailrow();
					}
				}
	}


// MATH GRAND TOTAL TRANSACTION //
function calc_gtotal(){
	subtotal = new Number($('#subtotal').val());

	}


$().ready(function(e) {
	$('#transdate').datepicker({
    	format: 'dd/mm/yyyy',
	   	startDate: '-3d'
	});	
});

function getdate(id){
		$('#'+id).datepicker({
    			format: 'dd/mm/yyyy',
	    		startDate: '-3d'
			});			
	}
