<?php
 namespace Modules\Invoices\Cashings\Management\Cancel; class Controller extends \App\Mvc\Controller\Form\PopupAbstract { protected function getDefaultFormData($R) { return $R; } protected function processFormData(array $R, \App\MessagesCollector $msgs) { $invoiceCashingEntCfg = \Entity\InvoiceCashing::loadCFG(); if (!is_array($R['id']) or !$R['id']) { $msgs->addError($this->lang['index']['msgs']['noDocsIds']); return false; } if ($invoiceCashingEntCfg['_special']['voidReasonMandatory'] and !$R['voidReason']) { $msgs->addWarning($this->lang['index']['msgs']['noVoidReason']); return false; } $OK = true; foreach ($R['id'] as $idCashingDoc) { try { \DB::startTransaction(); $cashingDocCancel = \Entity\InvoiceCashing::cancel($idCashingDoc); $cashingDocCancel->voidReason = $R['voidReason']; $cashingDocCancel->save(); \DB::commitTransaction(); $msgs->addSuccess(sprintf($this->lang['index']['msgs']['success'], $idCashingDoc)); } catch (\App\Entity\Exception $e) { \DB::rollbackTransaction(); $msgs->appendMessages($e->getMessagesCollector(), sprintf($this->lang['index']['msgs']['error'], $idCashingDoc).' %s'); $OK = false; break ; } } return $OK; } }