<?php
namespace Modules\Admin\Config\Orders\Numbers;

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


	protected function getDefaultFormData($R)
	{
		$formData = [];

		$orderNumberObj = \App\Config\OrderNumber::getInstance();
		$originalConfigs = $orderNumberObj->getAll();

		$formData['criteria'] = $originalConfigs['criteria'];
		$formData['numberLength'] = $originalConfigs['numberLength'];
		$formData['prefix'] = $originalConfigs['prefix'];
		$formData['suffix'] = $originalConfigs['suffix'];

		return $formData;
	}


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

			$orderNumberObj = \App\Config\OrderNumber::getAdmin();
			// collect data for the saving
			$orderNumberObj->set('criteria', 		$R['criteria']);
			$orderNumberObj->set('numberLength', 	$R['numberLength']);
			$orderNumberObj->set('prefix', 			$R['prefix']);
			$orderNumberObj->set('suffix', 			$R['suffix']);

			// actual save
			$orderNumberObj->save();

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

		} catch (\App\Config\MessageException $e) {

			$msgs->addWarning(sprintf($this->lang['process']['messages']['error'], $e->getMessage()));

		}

	}

}