
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;
	}
				dosubmit(url);
	/*		
		if(chk_qty<=0){
			
			$.alert({
	        	title: 'Warning!',
    	    	content: 'Qty Produk Tidak Boleh Kosong!',
				action:	$('#pm0').focus()
			    });
				return false;
			}
			
		else if($('#ven_autoid').val()==""){
			$.alert({
	        	title: 'Warning!',
    	    	content: 'Harap Pilih Vendor!',
				action:	$('#ven_autoid').focus()
			    });
				return false;
			}
		else{

			}
				*/
}
	
function calc_cb(){
					xrow = new Number($('#row').val());
					amount = 0;
					total_pot = 0;
					total_retur = 0;
					for(i=0;i<xrow;i++){
						price = new Number( $('#pm_bprice'+i).val() );
						qty = new Number($('#qty_p'+i).val());
						qty_r = new Number($('#qty_r'+i).val());
						pot = new Number($('#potongan'+i).val());
						
						if(qty=='NaN'){qty = 0;}
						

							subtotal = price * qty;
							retur 		= qty_r * price;	
							$('#subtotal'+i).val(subtotal);
							
							amount = amount + subtotal;
							
							
							total_pot = total_pot + pot;
							total_retur = total_retur + retur;
						}
						
						$('#subtotal').val(amount);
						$('#total_pot').val(total_pot);
						$('#total_retur').val(total_retur);
		calc_gtotal_pos();
	}
	

				
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_barcode'+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_pos(){

		subtotal = new Number($('#subtotal').val());
		pot = new Number($('#total_pot').val());
		retur = new Number($('#total_retur').val());
		gtotal = (subtotal - pot - retur);

		$('#gtotal').val(gtotal);
	}


	function get_transno(){
		outlet_id = $('#outlet_autoid').val();
		query = {outlet:outlet_id,tanggal:$('#transdate').val()}
		$.post('get_transno',query,function(e){
			$('#transno').val(e);
			})
	}

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


