public function reportAction()
 {
     if ($this->getRequest()->isPost()) {
         $sSessionId = $this->params()->fromPost('session_id');
         $oOrderPayment = $this->getOrderPaymentTable()->getRow(array('session_id' => $sSessionId));
         $sLocationKey = $oOrderPayment->location_key;
         $oPayU = new \Shop\PayU($sLocationKey);
         if ($oPayU->getResponse((array) $this->getRequest()->getPost())) {
             $oPaymentStatusData = new \ArrayObject($oPayU->getPaymentStatus());
             $oOrderPayment = $this->getOrderPaymentTable()->getRow(array('session_id' => $oPaymentStatusData->offsetGet('session_id')));
             if ($oOrderPayment) {
                 try {
                     $this->getOrderPaymentTable()->beginTransaction();
                     $oOrderPaymentEntity = new OrderPaymentEntity();
                     $oResponseEntity = new ResponseEntity();
                     $oUserEntity = new UserEntity();
                     $oUserStd = new \stdClass();
                     $oMail = new \Application\Mail($this->getServiceLocator());
                     $aBorrowerFine = array();
                     $aExpirationItem = array();
                     $nUserId = $oOrderPayment->user_id;
                     if ($nUserId) {
                         $oUserParam = $this->getUserParamTable()->getRow(array('user_id' => $nUserId));
                         foreach ($oUserParam as $sKey => $mValue) {
                             if (in_array($sKey, array('user_id'))) {
                                 continue;
                             }
                             if (in_array($sKey, array('id'))) {
                                 $sKey = 'user_param_id';
                             }
                             $oUserStd->{$sKey} = $mValue;
                         }
                         foreach ($oOrderPayment as $sKey => $mValue) {
                             if (in_array($sKey, array('user_id', 'first_name', 'last_name', 'e-mail address'))) {
                                 continue;
                             }
                             if (in_array($sKey, array('id'))) {
                                 $sKey = 'order_payment_id';
                             }
                             if (in_array($sKey, array('amount'))) {
                                 $sKey = 'user_amount';
                                 $mValue = (int) $mValue / 100;
                             }
                             $oUserStd->{$sKey} = $mValue;
                         }
                         $nTime = time();
                         $oUserStd->issue_user_date = date('d.m.Y, H:i:s', $nTime);
                         $nPaymentStatus = $oPaymentStatusData->offsetGet('status');
                         $sPaymentStatus = $this->translatePaymentStatusAction($nPaymentStatus);
                         $oOrderPaymentData = new \ArrayObject(array('id' => $oOrderPayment->id, 'payment_status' => $nPaymentStatus, 'user_payment_status' => $sPaymentStatus, 'last_update_payment_status_date' => $nTime));
                         $this->getOrderPaymentTable()->editRow($oOrderPaymentEntity->setOptions($oOrderPaymentData, array('id', 'payment_status', 'user_payment_status', 'last_update_payment_status_date')));
                         if ($nPaymentStatus == '1') {
                             //nowa
                             $oMail->fillMessage('sendPayUReport1', $oUserStd);
                         } else {
                             if ($nPaymentStatus == '2') {
                                 //anulowana
                                 $oMail->fillMessage('sendPayUReport2', $oUserStd);
                             } else {
                                 if ($nPaymentStatus == '3') {
                                     //odrzucona
                                     $oMail->fillMessage('sendPayUReport3', $oUserStd);
                                 } else {
                                     if ($nPaymentStatus == '4') {
                                         //rozpoczęta
                                         $oMail->fillMessage('sendPayUReport4', $oUserStd);
                                     } else {
                                         if ($nPaymentStatus == '5') {
                                             //oczekuje na odbiór
                                             $oMail->fillMessage('sendPayUReport5', $oUserStd);
                                         } else {
                                             if ($nPaymentStatus == '7') {
                                                 //odrzucona
                                                 $oMail->fillMessage('sendPayUReport7', $oUserStd);
                                             } else {
                                                 if ($nPaymentStatus == '99') {
                                                     //zakończona
                                                     if (!$this->getOrderPaymentTable()->getRow(array('id' => $oOrderPayment->id))->end) {
                                                         $oOrderPaymentHistory = $this->getOrderPaymentHistoryTable()->getAll(array('filter' => array('order_payment_id' => $oOrderPayment->id)));
                                                         if ($oOrderPaymentHistory) {
                                                             foreach ($oOrderPaymentHistory as $aValue) {
                                                                 $nItemId = $aValue->item_id;
                                                                 $oItem = $this->getItemTable()->getRow(array('id' => $nItemId));
                                                                 if ($oItem->name === 'expiration_item') {
                                                                     $aExpirationItem[] = array('fine_id' => $oItem->fine_id, 'fine_sequence' => $oItem->fine_sequence, 'doc_number' => $oItem->doc_number, 'item_sequence' => $oItem->item_sequence, 'price_net' => $oItem->price_net / 100, 'price_gross' => $oItem->price_gross / 100, 'location_key' => $oItem->item_location_key);
                                                                 } else {
                                                                     if ($oItem->name === 'borrower_fine') {
                                                                         $aBorrowerFine[] = array('fine_id' => $oItem->fine_id, 'fine_sequence' => $oItem->fine_sequence, 'doc_number' => $oItem->doc_number, 'item_sequence' => $oItem->item_sequence, 'price_net' => $oItem->price_net / 100, 'price_gross' => $oItem->price_gross / 100, 'location_key' => $oItem->item_location_key);
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                         $sBorrowerHash = $oUserParam->borrower_hash;
                                                         if ($sBorrowerHash) {
                                                             //$oPushBullet = new \Shop\PushBullet();
                                                             //$oPushBullet->pushNote('*****@*****.**', 'Kara w PW przed usunięciem', 'Kara w PW przed usunięciem');
                                                             $oXServer = new XServer();
                                                             $oXServer->deleteExpirationItem($sBorrowerHash, $aExpirationItem);
                                                             $oXServer->deleteBorrowerFine($sBorrowerHash, $aBorrowerFine);
                                                             $oOrderPaymentData = new \ArrayObject(array('id' => $oOrderPayment->id, 'date_end' => time(), 'end' => 1));
                                                             $oUserData = new \ArrayObject(array('id' => $nUserId, 'active' => 1));
                                                             $this->getOrderPaymentTable()->editRow($oOrderPaymentEntity->setOptions($oOrderPaymentData, array('id', 'date_end', 'end')));
                                                             $this->getUserTable()->changeActive($oUserEntity->setOptions($oUserData));
                                                             $oMail->fillMessage('sendPayUReport99', $oUserStd);
                                                             //$oPushBullet->pushNote('*****@*****.**', 'Kara w PW została usunięta', 'Kara w PW została usunięta');
                                                             //$oPushBullet->pushNote('*****@*****.**', 'Kara w WAT została usunięta', 'Kara w WAT została usunięta');
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         $oPaymentStatusData->offsetSet('order_payment_id', $oOrderPayment->id);
                         $oPaymentStatusData->offsetSet('date', time());
                         $this->getResponseTable()->addRow($oResponseEntity->setOptions($oPaymentStatusData));
                         $this->getOrderPaymentTable()->commit();
                     }
                 } catch (\Exception $e) {
                     //$oPushBullet = new \Shop\PushBullet();
                     //$oPushBullet->pushNote('*****@*****.**', 'Kara w WAT - wystąpił błąd', 'Kara w WAT - wystąpił błąd' . $e->getLine());
                     $this->getOrderPaymentTable()->rollBack();
                 }
             }
         }
     }
     echo 'OK';
     exit;
 }