<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
include("function.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");



if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage,base1,base2,DecimalBase,DecimalBase1,DecimalBase2,maxperpage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

$querylog="SELECT language from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}
	

$querylog="SELECT FI_SellingPriceAdjust as loginaccess from ".$_SESSION['dbLabel'].".ListUserDir where Usercode='".$_SESSION['useraccount']."' 	and Upper(concat(CompanyName,'_',Diryear)) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}
	
$items = json_decode($_POST['items'],true);			
	
$querylang="select language, buttonclear, save, print, find, clear, results, page from ".$_SESSION['dbLabel'].".buttons_label 
where language='$language'";


$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		//extract($rows);
		
		$buttonclear=$rows[1];
		$save=$rows[2];
		$print=$rows[3];
		$find=$rows[4];
		$clear=$rows[5];
		$results=$rows[6];
		$page=$rows[7];
		
	}

	

$existsinpurchases1 = $_GET['existsinpurchases1']; if($existsinpurchases1 == '') $existsinpurchases1 = $_POST['existsinpurchases1'];
$costMeth = $_GET['costMeth']; if($costMeth == '') $costMeth = $_POST['costMeth'];
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	//echo "$itemloaded";
if($itemloaded=='') $itemloaded=0;	
if($adjustDays =='') {
	$queryNumberDays = "select ifnull(itemcostdays,60)  from purchasesetup ";
	$resNumDays=mysql_query($queryNumberDays,$connection) or die(mysql_error());
	$rowsNumDays=mysql_fetch_array($resNumDays);
	$adjustDays=$rowsNumDays[0];
}

$sellingprice_label = array('Price','Price Local', 'Price Export', 'Price 3', 'Price 4', 'Price 5');

if( $mode == 'editItem'){
	$itemloaded=1;
	$existsinpurchases1=0;
	$sellingprice_nbr =1;
	$Item_code = $_GET['item_code'];
}
print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
		<meta name="viewport" content="width=device-width, initial-scale=1.0"> 


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">


<title>Selling Price</title>

<style type="text/css">
/* Hide HTML5 Up and Down arrows. */
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="number"] {
-moz-appearance: textfield;
}

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body >
<form name='sellingprice' method='post' enctype='multipart/form-data'>
<input type=hidden name='message' value='$message'> 
<input type=hidden name='itemloaded' value='$itemloaded'>
<input type='hidden' name='items' id='items' value='$items'>
<input type='hidden' name='loadedfromexcel' id='loadedfromexcel' value='$loadedfromexcel'>
<input type='hidden' name='existsinpurchases1' id='existsinpurchases1' value='$existsinpurchases1'>
HERE;
echo "<input type='hidden' name='items2' id='items2' value='".json_encode($items)."'>";



echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Selling Price</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";


echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='38'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' colspan = '2'>";
echo"		<button type='button' id='btnClear' name='btnClear' onclick=\"ClearPage(); return false;\" title='Clear Page'><span><span>$buttonclear</span></span></button>";
echo"		<button type='button' id='btnSave' name='btnSave' onclick=\"savePage(); return false;\" title='Save Page'><span><span>$save</span></span></button>";
echo"		<button type='button' id='btnLoad' name='btnLoad' onclick=\"loadItems(); return false;\" title='Load Items'><span><span>Load Items</span></span></button>";
echo"		<button type='button' id='btnPrint' name='btnPrint' onclick=\"printItems('0'); return false;\" title='Print'><span><span>Print</span></span></button>";
echo"		<button type='button' id='btnExcel' name='btnExcel' onclick=\"printItems('1'); return false;\" title='Print'><span><span>Excel</span></span></button>";
echo"		<button type='button' id='btnPrint' name='btnPrint1' onclick=\"printHistory('0'); return false;\" title='Print History Price'><span><span>Print History</span></span></button>";
echo"		<button type='button' id='btnPrint' name='btnExcel1' onclick=\"printHistory('1'); return false;\" title='Excel History Price'><span><span>Excel History</span></span></button>";
echo"		<button type='button' id='btnHistory' name='btnHistory' onclick=\"openWindow('history'); return false;\" title='Browse History'><span><span>Browse History</span></span></button>";
echo"		<button type='button' id='btnLExcel' name='btnLExcel' onclick=\"LoadExcel(); return false;\" title='Load From Excel'><span><span>Load from Excel</span></span></button>
			<input type='file'  name='image'    id='image' style='width:200px;' accept='file/xls'>";


echo"   </td></tr>";
echo"	</table>";
echo"</td></tr>";

echo"<tr><td id='content-body'>";
echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<col width=65%>";

echo"   <tr bgcolor='#F7F7F7'><td valign='top'>";	 

	  
echo"  
        <table border='0' style='table-layout:fixed' align='left' valign='top'>
		<col width=120px><col width=180px><col width=120px><col width=180px><col width=120px><col width=180px>
		 ";
if($existsinpurchases1 == 1) $checkedExistInPurchase = 'checked';
else  $checkedExistInPurchase = '';
echo"<tr bgcolor='#F7F7F7' height='25'>
           <td valign='center' align='left' ><span class='style1'>Group Code</span></td>
           <td valign='center' align='left' ><input type='text' name='group_code' id='group_code' value='$group_code' style='width:120px;'>
				<img src='img/btnopen.jpg' width15px height=15px onmouseover=\"style.cursor='hand'\" onclick=\"openWindow('group');\">
		   </td>
           <td valign='center' align='left' ><span class='style1'>Subgroup Code</span></td>
           <td valign='center' align='left' ><input type='text' name='subgroup_code' id='subgroup_code' value='$subgroup_code' style='width:120px;'>
				<img src='img/btnopen.jpg' width15px height=15px onmouseover=\"style.cursor='hand'\" onclick=\"openWindow('subgroup');\">
		   </td>
		   <td valign='center' align='left' ><span class='style1'>Category Code</span></td>
           <td valign='center' align='left' ><input type='text' name='category_code' id='category_code' value='$category_code' style='width:120px;'>
				<img src='img/btnopen.jpg' width15px height=15px onmouseover=\"style.cursor='hand'\" onclick=\"openWindow('category');\">
		   </td>
		   <td><input type='checkbox' id='existsinpurchases' name='existsinpurchases' $checkedExistInPurchase><span class='style1'>Exists In Purcahses</span></td>
	 </tr>";

echo "<tr bgcolor='#F7F7F7' height='25'>
		<td><span class='style1'>Selling Price</span></td>	
		<td><select name='sellingprice_nbr' id='sellingprice_nbr'  style='width:120px;' >
			<option value='' ".($sellingprice_nbr=='1'?'selected':'')."></option>
			<option value='1' ".($sellingprice_nbr=='1'?'selected':'').">$sellingprice_label[1]</option>
			<option value='2' ".($sellingprice_nbr=='2'?'selected':'').">$sellingprice_label[2]</option>
			<option value='3' ".($sellingprice_nbr=='3'?'selected':'').">$sellingprice_label[3]</option>
			<option value='4' ".($sellingprice_nbr=='4'?'selected':'').">$sellingprice_label[4]</option>
			<option value='5' ".($sellingprice_nbr=='5'?'selected':'').">$sellingprice_label[5]</option>
		</select></td>
		<td><span class='style1'>Percentage</span></td>	
		<td><input type='number' name='def_per' id='def_per' value='$def_per' style='width:120px;' onkeyup=\"setNewVal(this.id);\"  max=100 min=-100></td>
		<td><span class='style1'>Value</span></td>	
		<td><input type='number' name='def_val' id='def_val' value='$def_val' style='width:120px;' onkeyup=\"setNewVal(this.id);\" max=100 min=-100></td>
	</tr>";
	
echo "<tr bgcolor='#F7F7F7' height='25'>
		<td><span class='style1'>Item Code</span></td>	
		<td>
			<input type='text' name='Item_code' id='Item_code' value='$Item_code' style='width:120px;'>
			<img src='img/btnopen.jpg' width15px height=15px onmouseover=\"style.cursor='hand'\" onclick=\"openWindow('Items');\">
		</td>
		<td><span class='style1'>Cost Method</span></td>";	
		echo "<td>";

		if($costMeth =='') $costMeth = 'Last Pur Price';
		if($costMeth !='') { if ($costMeth == 'Highest Cost') $selected1 = 'Selected'; else $selected1 = '';}
		if($costMeth !='') { if ($costMeth == 'Average Cost') $selected2 = 'Selected'; else $selected2 = '';}
		if($costMeth !='') { if ($costMeth == 'Last Pur Price') $selected3 = 'Selected'; else $selected3 = '';}

		echo"<select id='costMeth' name='costMeth'>";
			echo"<option val='Highest Cost' $selected1>Highest Cost</option>";
			echo"<option val='Average Cost' $selected2>Average Cost</option>";
			echo"<option val='Last Pur Price' $selected3>Last Pur Price</option>";
		echo"</select>";
		echo "</td>	";
		echo "<td><span class='style1'>Days</span></td>	
		<td><input type='number' id='adjustDays' name='adjustDays'  value ='$adjustDays' style='width:120px;'/></td>	

	</tr>";
	
	
echo"</table></td></tr><tr>";

echo"<td  valign='top'>";


if($sellingprice_nbr == '') $sellingprice_nbr = 0;

echo"<table style='width:1050px;' border='0' cellspacing=0>
	 
	 <tr><td  valign='top' colspan=3 id='' style='width:1050px;'>
	 <table style='width:1050px;' border='0' cellspacing=0>
	 <col width=150>
	 <col width=200>
	 <col width=90>
	 <col width=90>  
	 <col width=90>
	 <col width=90>
	 <col width=150>
	 <col width=90>
	 <col width=150>
	<tr height='30px' style='background-color:darkgray;'>
	<td align='left'><span class='style1'><b>Item Code</b></td>
	<td align='left'><span class='style1'><b>Item Description</b></td>
	<td align='left'><span class='style1'><b>Currency</b></td>
	<td align='center'><span class='style1'><b>Percentage</b></td>
	<td align='center'><span class='style1'><b>Value</b></td>
	<td align='center'><span class='style1'><b>Hist. cost</b></td>
	<td align='center'><span class='style1'><b>Selling ".$sellingprice_label[$sellingprice_nbr]."</b></td>
	<td align='center'><span class='style1'><b>New Cost</b></td>
	<td align='center'><span class='style1'><b>New Selling ".$sellingprice_label[$sellingprice_nbr]."</b></td>
	</tr></table></td></tr>";
		$queryload = "select Item_Code, Item_Description, items.currency_code, Item_SellingPrice$sellingprice_nbr, category.Category_Price$sellingprice_nbr as catPrice$sellingprice_nbr
			from items
			left join grouping on grouping.group_code = items.group_code
			left join subgroup on subgroup.subgroup_code = items.subgroup_code
			left join category on category.category_code = items.category_code
			where ifnull(sale_group,0) = 1 and if('$group_code'='',1=1, items.group_code = '$group_code')
			and if('$subgroup_code'='',1=1, items.subgroup_code = '$subgroup_code') and if('$category_code'='',1=1, items.category_code = '$category_code')
			and if('$Item_code'='',1=1, items.item_code = '$Item_code')";
			
		if($existsinpurchases1 == 1){
			$queryload .= " and (";
			$queryload .= " items.item_code in (select distinct item_code from purchasesdt where Purchase_Date >= DATE_ADD(now(),INTERVAL - $adjustDays day))";
			$queryload .= " Or ";
			$queryload .= " items.item_code in (select distinct item_code from adjustmentdt where adjustment_Date >= DATE_ADD(now(),INTERVAL - $adjustDays day))";
			$queryload .= ")";
			
		}	
		  $queryload .= "order by item_code"; 
$i=0;
 echo "<tr><td  valign='top' colspan=3 id='' style='width:1050px;'><div style='overflow-x:hidden;overflow-y:scroll;width:100%;height:400px;'>
	 <table style='width:1050px;' border='0' cellspacing=0>
	 <col width=200>
	 <col width=280>
	 <col width=90>
	 <col width=90>  
	 <col width=90>
	 <col width=90>
	 <col width=150>
	 <col width=90>
	 <col width=150>";
	// echo"<BR>".$queryload."<BR>";
$resload = mysql_query($queryload,$connection);
while($rowload = mysql_fetch_array($resload)){	
	
	if(($loadedfromexcel == 1 && in_array($rowload[0],array_keys($items))) || $loadedfromexcel == 0){
		
		$defper = 'def_per'.$i;
		if($$defper == '') $$defper = $def_per;
		
		$defval = 'def_val'.$i;
		if($$defval == '') $$defval = $def_val;
		
		
		if($rowload[3]!= 0){ 
			if($$defper != '') 
				$newprice = round($rowload[3]+($$defper*$rowload[3]/100),$DecimalBase);
			else if($$defval != '')
				$newprice = round($rowload[3] + $$defval,$DecimalBase);
			
		}
		else  $newprice = 0;
		
		//if loaded from excel
		if($loadedfromexcel == 1 && in_array($rowload[0],array_keys($items))){
			$newprice = $items[$rowload[0]]['newprice'];
			$$defval = round($newprice - $rowload[3],$DecimalBase);
		}

		
		// get item date from history or from item creation date 
		
		$query_item_dateModified  = "select IFNULL(datemodified,0) as lastDateModified  from sellingpricehistory left join items on items.item_id = sellingpricehistory.item_id where item_code ='".$rowload[0]."' order by datemodified desc limit 1";
		$result_item_dateModified = mysql_query($query_item_dateModified, $connection);
		$row_item_dateModified    = mysql_fetch_array($result_item_dateModified);
		extract($row_item_dateModified);
		
		
		$query_lastdatePurchased  = "select ifnull(Item_LastDatePurchase,0) as lastdatePurchased from items where item_code = '".$rowload[0]."'";
		$result_lastdatePurchased = mysql_query($query_lastdatePurchased, $connection);
		$row_lastdatePurchased    = mysql_fetch_array($result_lastdatePurchased);
		extract($row_lastdatePurchased);
		
		if($lastDateModified = '' && $lastdatePurchased == '' || $lastdatePurchased == 0) $ItemCostPrice = round(0,$DecimalBase);
		else{
			$query_selectCostPrice  = "select round(MeanCostCur('$rowload[0]', now(), 1, '$base1', '$base1'),$DecimalBase) as ItemCostPrice from dual";
			$result_selectCostPrice = mysql_query($query_selectCostPrice, $connection);
			$row_selectCostPrice    = mysql_fetch_array($result_selectCostPrice);
			extract($row_selectCostPrice);
		}

		if ($costMeth == 'Average Cost'){
			// get item date from history or from item creation date 
			$query_selectCostPriceNew  = "select round(MeanCostCur('$rowload[0]', now(), 1, '$base1', '$base1'),$DecimalBase) as ItemCostPriceNew from dual";
			$result_selectCostPriceNew = mysql_query($query_selectCostPriceNew, $connection);
			$row_selectCostPriceNew    = mysql_fetch_array($result_selectCostPriceNew);
			extract($row_selectCostPriceNew); 
		}

		if ($costMeth == 'Highest Cost'){
			// get item date from history or from item creation date 
			$query_selectCostPriceNew  = "select Item_LastPricePurchase as ItemCostPriceNew from items where item_code = '$rowload[0]' ";
			$result_selectCostPriceNew = mysql_query($query_selectCostPriceNew, $connection);
			$row_selectCostPriceNew    = mysql_fetch_array($result_selectCostPriceNew);
			extract($row_selectCostPriceNew); 
		} 
		
		if ($costMeth == 'Last Pur Price'){
			// get item date from history or from item creation date 
			$query_selectCostPriceNew  = "select purchasedt_price as ItemCostPriceNew  from purchasesdt where item_code = '$rowload[0]' order by purchase_date desc  limit 1 ";
			$result_selectCostPriceNew = mysql_query($query_selectCostPriceNew, $connection);
			$row_selectCostPriceNew    = mysql_fetch_array($result_selectCostPriceNew);
			extract($row_selectCostPriceNew); 
		} 
		
		if($$defper == '' || $$defper == 0 ) $$defper = $rowload[4];
		 
		$newprice = round(($ItemCostPriceNew + ($ItemCostPriceNew * ($rowload[4]/100)))/10,0)*10;
		echo "<tr height='25px' >
				<td align='left'><span class='style1'>$rowload[0]</td>
				<td align='left'><span class='style1'>$rowload[1]</td>
				<td align='center'><span class='style1'>$rowload[2]</td>
				<td align='center'><input type='number' name='$defper' id='$defper' value='".$$defper."' onkeyup=\"changePrice(this.id,'$i','$DecimalBase');\" style='width:80px;' ></td>
				<td align='center'><input type='number' name='$defval' id='$defval' value='".$$defval."' onkeyup=\"changePrice(this.id,'$i','$DecimalBase');\" style='width:80px;' ></td>
				<td align='center'><input type='number' name='oldCost$i' id ='oldcost$i' readonly value ='$ItemCostPrice' style='width:80;border:none;text-align-last:center;' readonly='' ></td>
				<td align='center'><input type='number' name='sellingPrice$i' id='sellingPrice$i' value='$rowload[3]' style='width:120px;border:none;text-align-last:center;'readonly ></td>
				<td align='center'><input type='number' name='newcost$i' id ='newcost$i'  value='$ItemCostPriceNew' style='width:80;border:none;text-align-last:center;' readonly='' ></td>
				<td align='center'><input type='number' name='newsellingPrice$i' id='newsellingPrice$i' value='".$newprice."' style='width:120px;border:none;text-align-last:center;' onkeyup=\"changePriceVal('$i','$DecimalBase');\" ></td>
			</tr>";
		$i++;	
	}
}
echo"<input type='hidden' name='totalitems' id='totalitems' value='$i'></table></div></td></tr>";		
echo"<tr height='50px'><td id='' colspan='2'><table width=100% border='0'><tr><td align='center' width=50%>";
		
	
		echo"</td><td  align='center'>";
		
		
		echo"</td></tr><tr>
					<td id='' style='width:1050px;height:20px;' colspan='6'></td>
				</tr></table></td></tr>";
			


echo"</tr></table></td></tr>";	
echo"</tr></table></td></tr>";	
	 
			 
		  

print <<< HERE
       </td>
      </tr>  <tr height='30'><td align='center' id='content-bottom' ></td></tr>
	  </table>
HERE;


print <<<HERE
</form>

<script>
function setNewVal(idVal){
	if (idVal == 'def_per'){
		document.getElementById('def_val').value='';
	} else if (idVal == 'def_val'){
		document.getElementById('def_per').value='';
	}
	
}
function changePriceVal(index,dec){
	let newSellingPrice = document.getElementById('newsellingPrice'+index).value;
	let sellingPrice = document.getElementById('sellingPrice'+index).value;
	let def_val = parseFloat(newSellingPrice) - parseFloat(sellingPrice);
	
	document.getElementById('def_val'+index).value = def_val.toFixed(dec);
}

function changePrice(idVal, index,dec){
	let newPrice = 0;
	let def_per = document.getElementById('def_per'+index).value;
	let def_val = document.getElementById('def_val'+index).value;
	let sellingPrice = document.getElementById('newcost'+index).value;
	if(def_per == '') def_per = 0;
	if(def_val == '') def_val = 0;
	if(sellingPrice == '') sellingPrice = 0;
	def_per 	= parseFloat(def_per);
	def_val 	= parseFloat(def_val);
	sellingPrice = parseFloat(sellingPrice);
		
	if (idVal == 'def_per'+index){
		document.getElementById('def_val'+index).value='';
		if(sellingPrice != 0)
		newPrice = parseFloat(sellingPrice + (def_per*sellingPrice/100));
		else newPrice = 0;
	} else if (idVal == 'def_val'+index){
		document.getElementById('def_per'+index).value='';
		if(sellingPrice != 0)
		newPrice = parseFloat(sellingPrice + def_val);
		else newPrice = 0;
	}
	
	document.getElementById('newsellingPrice'+index).value = newPrice.toFixed(0);
}

function openWindow(winName){
	let strName = '';
	if(winName=='group')
		strName= 'List_Grouping.php?str=16';
	else if(winName=='subgroup')
		strName= 'List_SubGroup.php?str=11';
	else if(winName=='category')
		strName= 'List_Categories.php?str=9';
	else if(winName=='history')
		strName= 'Form_BrowseSellingPrice.php';
	else if(winName=='Items')
		strName= 'list_SorItems.php?frm=22&ItemType=All';
	
	window.open(strName,winName, 'width=1000px,height=600px');
}

function LoadExcel(){
	if(document.sellingprice.image.value == ''){
		alert('No File was uploaded!');
		return 0;
	} else if(document.sellingprice.sellingprice_nbr.value == ''){
		alert('No Selling Price was selected!');
		return 0;
	} else {
		document.sellingprice.action = 'Form_SellingPrice_Actions.php?mode=importExcel';
		document.sellingprice.submit();
		
	}
}
function loadItems(){
	if(document.getElementById('existsinpurchases').checked == 1){ 
		document.sellingprice.existsinpurchases1.value=1;
	}else{ 
		document.sellingprice.existsinpurchases1.value=0;
	}
	document.sellingprice.itemloaded.value=1;
	document.sellingprice.submit();
}

function ClearPage(){
	document.sellingprice.group_code.value 			= '';
	document.sellingprice.subgroup_code.value 		= '';
	document.sellingprice.category_code.value 		= '';
	document.sellingprice.sellingprice_nbr.value 	= '';
	document.sellingprice.def_per.value 			= '';
	document.sellingprice.itemloaded.value 			= '';
	document.sellingprice.message.value 			= '';
	document.sellingprice.items.value 				= '';
	document.sellingprice.items2.value 				= '';
	document.sellingprice.loadedfromexcel.value 	= '';
	document.sellingprice.action = 'Form_SellingPrice.php';
	document.sellingprice.submit();
}

function printItems(exp){
	let str = '';
	let sellingprice_nbr = document.sellingprice.sellingprice_nbr.value;
	let group_code = document.sellingprice.group_code.value;
	let subgroup_code = document.sellingprice.subgroup_code.value;
	let category_code = document.sellingprice.category_code.value;
	
	if(sellingprice_nbr == ''){
		alert('No Selling Price was Selected!');
		document.sellingprice.sellingprice_nbr.focus();
	} else {
		if(exp == 1) str = 'Exp_SellingPrice.php';
		else str = 'Form_SellingPricepreview.php';
		
		str = str+'?sellingprice_nbr='+sellingprice_nbr+'&group_code='+group_code+'&subgroup_code='+subgroup_code+'&category_code='+category_code;   
		window.open(str);
	}
	
} 

function printHistory(exp){
	let str = '';
	let sellingprice_nbr = document.sellingprice.sellingprice_nbr.value;
	let group_code = document.sellingprice.group_code.value;
	let subgroup_code = document.sellingprice.subgroup_code.value;
	let category_code = document.sellingprice.category_code.value;
	
	if(sellingprice_nbr == ''){
		alert('No Selling Price was Selected!');
		document.sellingprice.sellingprice_nbr.focus();
	} else {
		if(exp == 1) str = 'Exp_SellingPriceHistoryPreview.php';
		else str = 'Rep_SellingPriceHistoryPreview.php';
		
		str = str+'?sellingprice_nbr='+sellingprice_nbr+'&group_code='+group_code+'&subgroup_code='+subgroup_code+'&category_code='+category_code;   
		window.open(str);
	}
	
}

function savePage(){
	if(confirm('are you sure you want to update prices ?')==true){
		let alertVal = 1;
	
	if ((document.sellingprice.totalitems.value != 0 && document.sellingprice.itemloaded.value == 1) || 
			(document.sellingprice.totalitems.value != 0 && document.sellingprice.loadedfromexcel.value == 1) )
		alertVal = 0;	
			
	if ( alertVal == 1) {
		alert('No Item Was Loaded!');
		return 0;		
	} else {
		document.sellingprice.action = 'Form_SellingPrice_Actions.php?mode=changePrice';
		document.sellingprice.submit();		
	}
	}
	
}




</script>
</body>

HERE;

?>