<?php

namespace Modules\Admin\Config\SupplierInvoices\General;

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


	protected function getDefaultFormData($R)
	{
		$formData['unblocking'] = \App\Config\DocumentsUnblocking::getInstance()->get('supplierInvoice');
		return $formData;
	}


	protected function processFormData(Array $R, \App\MessagesCollector $msgs)
	{

		$formData = [
			'unblocking' => [
				'unblockEnabled'	=> (bool) $R['unblocking']['unblockEnabled'],
				'unblockAllowedFor'	=> ((bool) $R['unblocking']['unblockEnabled'] ? $R['unblocking']['unblockAllowedFor'] : 0)
			]
		];

		try {
			// setting up the unblock documents
			\App\Config\DocumentsUnblocking::getAdmin()->setSupplierInvoice($formData['unblocking']);
			\App\Config\DocumentsUnblocking::getAdmin()->save();

			$msgs->addSuccess($this->lang['unblocking']['process']['messages']['success']);

		} catch (\App\Config\MessageException $e) {
			$msgs->addWarning(sprintf($this->lang['process']['messages']['error'], $e->getMessage()));
		}
	}

}