public function postProcess()
 {
     if (Tools::isSubmit('submitCloseClaim')) {
         $id_mf_claim = (int) Tools::getValue('id_mf_claim');
         if (!$id_mf_claim || !Validate::isUnsignedId($id_mf_claim)) {
             $this->errors[] = $this->l('The claim is no longer valid.');
         } else {
             $claim = new MediafinanzClaim($id_mf_claim);
             if (!Validate::isLoadedObject($claim)) {
                 $this->errors[] = $this->l('The Claim cannot be found');
             } else {
                 try {
                     $res = $this->module->closeClaim($claim->file_number);
                     if ($res) {
                         $this->confirmations[] = $this->l('The Claim has been closed');
                     } else {
                         $this->errors[] = $this->l('The Claim has not been closed');
                     }
                 } catch (Exception $e) {
                     $this->errors[] = $this->l('The Claim has not been closed');
                     $this->errors[] = $e->getMessage();
                     Mediafinanz::logToFile($e->getMessage(), 'general');
                 }
             }
         }
     }
     if (Tools::isSubmit('submitBookDirectPayment')) {
         $id_mf_claim = (int) Tools::getValue('id_mf_claim');
         $amount = str_replace(',', '.', Tools::getValue('paidAmount'));
         if (!$id_mf_claim || !Validate::isUnsignedId($id_mf_claim)) {
             $this->errors[] = $this->l('The Claim is no longer valid.');
         } else {
             $claim = new MediafinanzClaim($id_mf_claim);
             if (!Validate::isLoadedObject($claim)) {
                 $this->errors[] = $this->l('The Claim cannot be found');
             } elseif (!Validate::isDate(Tools::getValue('dateOfPayment'))) {
                 $this->errors[] = $this->l('The date of payment is invalid');
             } elseif (!Validate::isPrice($amount)) {
                 $this->errors[] = $this->l('The paid amount is invalid.');
             } else {
                 try {
                     $direct_payment = array('dateOfPayment' => Tools::getValue('dateOfPayment'), 'paidAmount' => $amount);
                     $res = $this->module->bookDirectPayment($claim->file_number, $direct_payment);
                     if ($res) {
                         $this->confirmations[] = $this->l('Direct payment has been booked');
                     } else {
                         $this->errors[] = $this->l('Direct payment has not been booked');
                     }
                 } catch (Exception $e) {
                     $this->errors[] = $this->l('Direct payment has not been booked');
                     $this->errors[] = $e->getMessage();
                     Mediafinanz::logToFile($e->getMessage(), 'general');
                 }
             }
         }
     }
     if (Tools::isSubmit('submitMessage')) {
         $id_mf_claim = (int) Tools::getValue('id_mf_claim');
         $msg_text = Tools::getValue('message');
         if (!$id_mf_claim || !Validate::isUnsignedId($id_mf_claim)) {
             $this->errors[] = $this->l('The claim is no longer valid.');
         } elseif (empty($msg_text)) {
             $this->errors[] = $this->l('The message cannot be blank.');
         } elseif (!Validate::isMessage($msg_text)) {
             $this->errors[] = $this->l('This message is invalid (HTML is not allowed).');
         }
         if (!count($this->errors)) {
             $claim = new MediafinanzClaim($id_mf_claim);
             if (Validate::isLoadedObject($claim)) {
                 try {
                     $res = $this->module->sendMessage($claim->file_number, $msg_text);
                     if (!$res) {
                         $this->errors[] = $this->l('The Message has not been sent');
                     } else {
                         $this->confirmations[] = $this->l('The Message has been sent');
                     }
                 } catch (Exception $e) {
                     $this->errors[] = $this->l('The Message has not been sent');
                     $this->errors[] = $e->getMessage();
                     Mediafinanz::logToFile($e->getMessage(), 'general');
                 }
             } else {
                 $this->errors[] = $this->l('The Claim not found');
             }
         }
     }
     /*if (Tools::isSubmit('update_claims_statuses'))
     		{*/
     if ($this->display == '') {
         try {
             $this->module->updateClaimsStatuses();
         } catch (Exception $e) {
             $this->_errors[] = $e->getMessage();
             Mediafinanz::logToFile($e->getMessage(), 'general');
         }
     }
     //}
     if (Tools::isSubmit('submitCreateClaims')) {
         $order_ids = Tools::getValue('order_list');
         $claim = Tools::getValue('claim');
         $debtor = Tools::getValue('debtor');
         $list = Db::getInstance()->executeS('SELECT a.`id_order`, a.`id_shop` FROM `' . _DB_PREFIX_ . 'orders` a LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_order` = a.`id_order` AND o.`id_shop` = a.`id_shop`) LEFT JOIN ' . _DB_PREFIX_ . 'mf_claims c ON a.`id_order`=c.`id_order` AND c.`sandbox`=' . (int) Configuration::get('MEDIAFINANZ_SANDBOX') . ' WHERE c.`id_order` IS NULL AND a.`id_order` IN (' . implode(', ', array_map('intval', $order_ids)) . ')' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'a', 'shop'));
         foreach ($list as $row) {
             $id = $row['id_order'];
             $debtor_to = array('id' => $debtor[$id]['id'], 'address' => $debtor[$id]['address'], 'firstname' => $debtor[$id]['firstname'], 'lastname' => $debtor[$id]['lastname'], 'company' => $debtor[$id]['company'], 'co' => '', 'street' => $debtor[$id]['street'], 'postcode' => $debtor[$id]['postcode'], 'city' => $debtor[$id]['city'], 'country' => $debtor[$id]['country'], 'telephone1' => $debtor[$id]['telephone1'], 'telephone2' => $debtor[$id]['telephone2'], 'email' => $debtor[$id]['email']);
             $claim_to = array('invoice' => $claim[$id]['invoice'], 'type' => $claim[$id]['type'], 'reason' => $claim[$id]['reason'], 'originalValue' => $claim[$id]['originalvalue'], 'overdueFees' => $claim[$id]['overduefees'], 'dateOfOrigin' => $claim[$id]['dateoforigin'], 'dateOfLastReminder' => $claim[$id]['dateoflastreminder'], 'note' => $claim[$id]['note']);
             try {
                 $result = $this->module->newClaim($claim_to, $debtor_to);
                 if (!empty($result->fileNumber)) {
                     $mf = new MediafinanzClaim();
                     $mf->id_order = $claim[$id]['invoice'];
                     $mf->file_number = $result->fileNumber;
                     $mf->firstname = $debtor[$id]['firstname'];
                     $mf->lastname = $debtor[$id]['lastname'];
                     $mf->id_shop = $row['id_shop'];
                     $mf->sandbox = (int) Configuration::get('MEDIAFINANZ_SANDBOX');
                     $mf->add();
                     $claim_status = $this->module->getClaimStatus($result->fileNumber, $row['id_shop']);
                     if ($mf->status_code != $claim_status->statusCode) {
                         $mf->status_code = $claim_status->statusCode;
                         $mf->status_text = $claim_status->statusText;
                         if (isset($claim_status->statusDetails)) {
                             $mf->status_details = $claim_status->statusDetails;
                         } else {
                             $mf->status_details = '';
                         }
                         $mf->date_change = date('Y-m-d H:i:s');
                         $mf->save();
                     }
                     //change state
                     $this->module->changeOrderState($claim[$id]['invoice'], Configuration::get('PS_OS_MF_INKASSO'));
                 } else {
                     foreach ($result->errorList as $error_msg) {
                         $this->errors[] = $this->l('Order') . ' - ' . $row['id_order'] . ': ' . $error_msg;
                     }
                 }
             } catch (Exception $e) {
                 $this->errors[] = $this->l('Order') . ' - ' . $row['id_order'] . ': ' . $e->getMessage();
                 Mediafinanz::logToFile($this->l('Order') . ' - ' . $row['id_order'] . ': ' . $e->getMessage(), 'general');
             }
         }
     }
     parent::postProcess();
 }