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


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

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

	}

	protected function processFormData(Array $R, \App\MessagesCollector $msgs)
	{
		try {
			$pluginVarsObj = \Modules\Invoices\Cashings\Management\TransferToCredit\Config::getAdmin();
			$pluginVarsObj->set('cashingDocType',		$R['cashingDocType']);
			$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;
	}
}

