<?php
	/*
	** File: SET_DEPT_SALES
	** Description: set sales price to percentage of list price
	** Version: $Revision: 1.4 $
	** Created: 08/13/1999
	** Author: Leon Atkinson
	** Email: leon@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 1999/12/09 23:23:22 $
	** Log : $Log: SET_DEPT_SALES,v $
	** Log : Revision 1.4  1999/12/09 23:23:22  leon
	** Log : Changed ActionResults use so that it's an array instead of a
	** Log : continually-growing string.  Note the little function in standard_library
	** Log : for printing out all the action results.
	** Log :
	** Log : Revision 1.3  1999/11/13 01:20:42  leon
	** Log : More localization work.
	** Log :
	** Log : Revision 1.2  1999/08/18 22:31:51  leon
	** Log : Returning opening PHP tag to XML-friendly tag
	** Log :
	** Log : Revision 1.1  1999/08/13 18:19:59  leon
	** Log : Added interface for setting sales prices per the requirements specification.
	** Log : (See "Add promotion/discount offers").  Since admin_sales needs to use
	** Log : DepartmentSelector, I tweaked it a bit.
	** Log :
	**
	** Copyright (c) 1999 Working Dogs.  All rights reserved.
	*/

	if($UserInfo["Permission"]["Administrate"])
	{
		$Ratio = doubleval($inputPercentage)/100.00;
	
		//get list of SKUs
		$Query = "SELECT Item ";
		$Query .= "FROM department_item ";
		$Query .= "WHERE Department in (0";
		for($index = 0; $index < count($inputDepartment); $index++)
		{
			$Query .= ", $inputDepartment[$index]";
		}
		$Query .= ") ";		
		$DatabaseResult = mysql_query($Query, $DatabaseLink);
		$itemList = "0";
		while(list($item) = mysql_fetch_row($DatabaseResult))
		{
			$itemList .= ", $item";
		}
	
	
		$Query = "UPDATE sku ";
		$Query .= "SET SalePrice = ListPrice - (ListPrice * $Ratio) ";
		$Query .= "WHERE Item in ($itemList) ";
		if(!mysql_query($Query, $DatabaseLink))
		{
			$ActionResults[] =  mysql_errno() . ": " . mysql_error();
		}
		else
		{
			$ActionResults[] =  L_SETDEPTSALES_SUCCESS . $inputPercentage . "%!";
		}

	}

?>