SpecialDept


as of: February 14, 2013

SpecialDept modules are used to associate an arbitrary actions with open rings to a certain department or departments. The base class exposes one method:

array handle(integer $department, float $amount, array $json)

The $department parameter is the department number. Checking this parameter to make sure it matches an specific value or values is frowned upon. Doing so makes it harder for anyone else to re-use your module and the configuration of SpecialDept module mappings can effecitvely impose the same restrictions.

The $amount parameter is the amount entered.

The $json parameter is a Parser-module formatted array. You should almost always return this value. Modifying it first can be useful. Most notably setting a URL for the main_frame key will redirect POS to another page of your choosing. You may want to use a $CORE_LOCAL (i.e., session) setting here and at the destination page to avoid winding up in a loop.

The return value is a Parser-module formatted array. Hence the advice above about returning $json. That ensures the return format is correct.

Example: redirect to an extra cashier prompt to confirm an Equity sale. Note the use of $CORE_LOCAL to alternate behavior. The first time the module is called, it redirects for confirmation but the second time - after the cashier has provided confirmation - it returns $json unmodified.

class EquityWarnDept extends SpecialDept {

	function handle($deptID,$amount,$json){
		global $CORE_LOCAL;

		if ($CORE_LOCAL->get("warned") == 1 and $CORE_LOCAL->get("warnBoxType") == "warnEquity"){
			$CORE_LOCAL->set("warned",0);
			$CORE_LOCAL->set("warnBoxType","");
		}
		else {
			$CORE_LOCAL->set("warned",1);
			$CORE_LOCAL->set("warnBoxType","warnEquity");
			$CORE_LOCAL->set("boxMsg","<b>Equity Sale</b><br>please confirm<br>
				<font size=-1>[enter] to continue, [clear] to cancel</font>");
			$json['main_frame'] = MiscLib::base_url().'gui-modules/boxMsg2.php';
		}

		return $json;
	}
}