<?php
namespace Modules\Invoices\Payments\Management\TransferToCredit\Config;


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

	protected function getDefaultFormData($R)
	{
		// load plugin config
		return [
			'paymentDocType' =>		\Modules\Invoices\Payments\Management\TransferToCredit\Config::getInstance()->get('paymentDocType'),
			'impDocType' =>			\Modules\Invoices\Payments\Management\TransferToCredit\Config::getInstance()->get('impDocType'),
			'idExternalSystem' =>	\Modules\Invoices\Payments\Management\TransferToCredit\Config::getInstance()->get('idExternalSystem'),
		];

	}

	protected function processFormData(Array $R, \App\MessagesCollector $msgs)
	{
		try {
			$pluginVarsObj = \Modules\Invoices\Payments\Management\TransferToCredit\Config::getAdmin();
			$pluginVarsObj->set('paymentDocType',		$R['paymentDocType']);
			$pluginVarsObj->set('impDocType',			$R['impDocType']);
			$pluginVarsObj->set('idExternalSystem',		$R['idExternalSystem']);

			$pluginVarsObj->save();

			$msgs->addSuccess($this->lang['index']['form']['success']['save']);

			return true;
		}
		catch (\App\Config\MessageException $e) {
			$msgs->addError($e->getMessage());
		}

		return false;
	}
}

