<?php
/* ARRAY DB */


// GET VENDOR //
$sql_pn = "select * from mst_vendor";
$pn_conn = $conn->query($sql_pn) or die($sql_pn);
while($pn = $pn_conn->fetch_array()){
	$_ven_autoid = $pn['ven_autoid'];
	$_ven_name[$_ven_autoid] = $pn['ven_name'];
}

// INV TRANS TYPE
$sql_pn = "select * from invtranstype";
$pn_conn = $conn->query($sql_pn) or die($sql_pn);
while($pn = $pn_conn->fetch_array()){
	$_itt_autoid = $pn['itt_autoid'];
	$_itt_desc[$_itt_autoid] = $pn['itt_desc'];
}

/*
$sqlcoa = "SELECT * FROM mst_coa";
$prop_conn = $conn->query($sqlcoa) or die($sqlcoa);
while($coa = $prop_conn->fetch_assoc()){;
	$coa_id = $coa['coa_autoid'];
	$_coa_accno[$coa_id] = $coa['coa_accno'];
	$_coa_accdesc[$coa_id] = $coa['coa_accdesc'];
}
*/

// GET OUTLET //
$sqlcoa = "SELECT * FROM mst_customer";
$prop_conn = $conn->query($sqlcoa) or die($sqlcoa);
while($coa = $prop_conn->fetch_assoc()){;
	$_outlet_id = $coa['cust_autoid'];

	$_outlet_name[$_outlet_id] = $coa['cust_name'];
}


// GET PRODUCT //
$sqld = "SELECT * FROM mst_product";
$dcond = $conn->query($sqld) or die($sqld);
while($rowd = $dcond->fetch_array()){
	$_pm_autoid = $rowd['pm_autoid'];

	$_pm_code[$_pm_autoid] = $rowd['pm_code'];
	$_pm_name[$_pm_autoid] = $rowd['pm_name'];

	$_pm_ums[$_pm_autoid] = strtoupper($rowd['pm_ums']);
	$_pm_umb[$_pm_autoid] = strtoupper($rowd['pm_umb']);				
	$_pm_convert[$_pm_autoid] = $rowd['pm_ums_convert'];
}


// GET KATEGORI //
$sqld = "SELECT * FROM mst_parttype a, mst_partclass b WHERE a.pt_autoid = b.pt_autoid";
$dcond = $conn->query($sqld) or die($sqld);
while($rowd = $dcond->fetch_array()){
	$_pt_autoid = $rowd['pt_autoid'];
	$_pc_autoid = $rowd['pc_autoid'];
	$_pt_name[$_pc_autoid] = $rowd['pt_name'];
	$_pc_name[$_pc_autoid] = $rowd['pc_name'];				
}


// GET WAREHOUSE //
$sqlwhs = "select * from warehouse ";
$dconwhs = $conn->query($sqlwhs) or die($sqlwhs);
while($rswhs = $dconwhs->fetch_assoc()){
		$whsid = $rswhs['whs_autoid'];
		$whsname[$whsid] = $rswhs['whs_name'];
		$_whs_outlet_id[$whsid] = $rswhs['outlet_autoid'];
};	


// GET OUTLET //
$sql_outlet = "select * from mst_outlet ";
$dcon_outlet = $conn->query($sql_outlet) or die($sql_outlet);
while($rsout = $dcon_outlet->fetch_assoc()){
		$outlet_id = $rsout['outlet_autoid'];
		$_outlet_name[$outlet_id] = $rsout['outlet_name'];
		$_outlet_addr[$outlet_id] = $rsout['outlet_addr'];
		$_outlet_phone[$outlet_id] = $rsout['outlet_phone'];
};	

function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }


	
$sql_access = "SELECT * FROM useraccess WHERE user_id = '$userid'";
$dcon_acs = $conn->query($sql_access) or die($sql_access);
$acs = $dcon_acs->fetch_array();
	$order_flag 	= $acs['order_flag'];
	$inv_flag 		= $acs['inv_flag'];
	$md_flag 		= $acs['md_flag'];
	$rpt_flag 		= $acs['rpt_flag'];
	$content_flag 	= $acs['content_flag'];
	$setting_flag 	= $acs['setting_flag'];
	$prc_flag 		= $acs['prc_flag'];
	$prd_flag 		= $acs['prd_flag'];
	$acc_flag 		= $acs['acc_flag'];	
	
	
	
/* INPUT FORM */

function get_input_terms($connection,$rs_value,$onchange){
	
	if($connection){
	$sql_terms = "select * from mst_terms ORDER BY terms_id";
	$terms_con = $connection->query($sql_terms) or die($sql_terms);
	$input_terms = "<select class='input w-80' name='mst_terms' id='mst_terms'> <option value=''>Select Terms</option>"; 			

	 //  create content from the loop    
		while($rs_terms = $terms_con->fetch_assoc()) {
			$terms_id = $rs_terms['terms_id'];
			if($rs_value==$terms_id){
			   $input_terms.= "<option value='".$terms_id."' selected='selected'>".$rs_terms['terms_desc']."</option>";
			}else{
				$input_terms.= "<option value='".$terms_id."'>".$rs_terms['terms_desc']."</option>";
				}
		}
		// and close the table outside the loop
		$input_terms.="</select>";
		return $input_terms;
	}
}

function get_input_disctype($rs_value){
	if($rs_value=="P"){
		$persen_selected = 'selected="selected"';
		}
	if($rs_value=="R"){
		$rp_selected = 'selected="selected"';
		}
		
	$input_disctype = '<select class="input" name="mst_disctype"  id="mst_disctype" onchange="calc_gtotal()">
							<option '.$rp_selected.' value="R">Rp.</option>
							<option '.$persen_selected.' value="P">%</option>
						</select>';
		return $input_disctype;
	}

$arr_month = array("","Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");






function toDecimal($val){
	if(!$val){$val = 0;}
	
	return round($val,2);
}

/*NOTES

invlog - log_price -> harga satuan kecil untuk central
CENTRAL - modul barang masuk -> purchase, inv transaction, produksi(ok)
OUTLET - modul brg masuk -> penerimaan REQ ORDER, inv trans, produksi
*/

?>