<?php
namespace Modules\Admin\Config\Gds\Worldspan;

class Controller extends \App\Mvc\Controller\Form\WindowAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\Controller\Form\WindowAbstract::getDefaultFormData()
	 */
	protected function getDefaultFormData($R)
	{
		return [
			'ignoreSupplierOnDocuments' => 				unserialize((string)\App\Worldspan\Config::getInstance()->get("ignoreSupplierOnDocuments")),
			'importCurrency' => 						\App\Worldspan\Config::getInstance()->get("importCurrency"),
			"importServiceFeeForService" => 			\App\Worldspan\Config::getInstance()->get("importServiceFeeForService"),
			"importServiceFeeForServiceCurrency" => 	\App\Worldspan\Config::getInstance()->get("importServiceFeeForServiceCurrency"),
			"importDiscountForService" => 				\App\Worldspan\Config::getInstance()->get("importDiscountForService"),
			"importDiscountForServiceCurrency" => 		\App\Worldspan\Config::getInstance()->get("importDiscountForServiceCurrency"),

		];
	}

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\Controller\Form\WindowAbstract::processFormData()
	 */
	protected function processFormData(Array $R, \App\MessagesCollector $msgs)
	{
		\App\Worldspan\Config::getAdmin()->setAll([
			"ignoreSupplierOnDocuments" => 				serialize(array_filter((array)$R['ignoreSupplierOnDocuments'])),
			"importCurrency" => 						$R['importCurrency'],
			"importServiceFeeForService" => 			$R['importServiceFeeForService'],
			"importServiceFeeForServiceCurrency" => 	$R['importServiceFeeForServiceCurrency'],
			"importDiscountForService" => 				$R['importDiscountForService'],
			"importDiscountForServiceCurrency" => 		$R['importDiscountForServiceCurrency'],
		]);
		\App\Worldspan\Config::getAdmin()->save();

		$msgs->addSuccess($this->lang['index']['saveOk']);

		return true;
	}
}
