Exemplo n.º 1
0
 /**
  * the singleton pattern
  *
  * @return SoEventManager_Controller_SoEvent
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Exemplo n.º 2
0
 public function saveOpenItemMonition($recordData)
 {
     return $this->_save($recordData, Billing_Controller_OpenItemMonition::getInstance(), 'OpenItemMonition');
 }
Exemplo n.º 3
0
 public function getMonitionPositions($receiptId)
 {
     return Billing_Controller_OpenItemMonition::getInstance()->getByReceiptId($receiptId);
 }
Exemplo n.º 4
0
 public function runMonitionExport($jobId, $dueDate)
 {
     set_time_limit(0);
     error_reporting(E_ALL);
     $job = Billing_Api_BatchJobManager::getInstance()->loadBatchJob($jobId);
     Billing_Api_BatchJobManager::getInstance()->startBatchJob();
     try {
         $db = Tinebase_Core::getDb();
         $tm = Tinebase_TransactionManager::getInstance();
         $tId = $tm->startTransaction($db);
         set_time_limit(0);
         $data = $job->getData();
         $filters = $data['filters'];
         $pagination = new Tinebase_Model_Pagination();
         $contexts = array('MEMBERSHIP' => 'Beitrag', 'DONATOR' => 'Spende', 'ERP' => 'allg.');
         // get all open items (for debit)
         // grouped by debitors
         $filters[] = array('field' => 'job_id', 'operator' => 'equals', 'value' => $job->getId());
         $filter = new Billing_Model_BatchJobMonitionFilter($filters, 'AND');
         // count membership matching filters
         $batchJobMonitionIds = $this->search($filter, new Tinebase_Model_Pagination(array('sort' => 'n_family', 'dir' => 'ASC')), false, true);
         $tempFilePath = CSopen::instance()->getCustomerPath() . '/customize/data/documents/temp/';
         $hash = md5(microtime());
         $protocolBatchJobMonitionIds = array();
         $bufferMonitionIds = array();
         foreach ($batchJobMonitionIds as $batchJobMonitionId) {
             $batchJobMonition = $this->get($batchJobMonitionId);
             // keep out items which are locked
             if ($batchJobMonition->__get('monition_lock')) {
                 continue;
             }
             $usage = array();
             $contactNr = $batchJobMonition->getForeignId('contact_id');
             $batchJobMonitionItems = Billing_Controller_BatchJobMonitionItem::getInstance()->getByBatchJobMonitionId($batchJobMonitionId);
             // get last open item (grab last order, for relating monition to)
             $lastOpenItem = Billing_Controller_BatchJobMonitionItem::getInstance()->getLastOpenItem($batchJobMonitionItems);
             $orderId = $lastOpenItem->getForeignId('order_id');
             $lastReceipt = $lastOpenItem->getReceipt();
             $monition = Billing_Model_Receipt::createMonition();
             $monition->__set('order_id', $orderId);
             $lastReceipt->copyAdditionalDataTo($monition);
             $monition = Billing_Controller_Receipt::getInstance()->create($monition);
             $bufferMonitionIds[] = $monition->getId();
             $overallMonitionStage = 0;
             foreach ($batchJobMonitionItems as $batchJobMonitionItem) {
                 $openItem = $batchJobMonitionItem->getForeignRecord('open_item_id', Billing_Controller_OpenItem::getInstance());
                 $openItem->manifestNextMonitionStage();
                 $monitionStage = $openItem->__get('monition_stage');
                 $overallMonitionStage = max($overallMonitionStage, $monitionStage);
                 $openItemMonition = Billing_Model_OpenItemMonition::createFromBatchJobMonitionItem($monition, $batchJobMonitionItem);
                 $openItemMonition = Billing_Controller_OpenItemMonition::getInstance()->create($openItemMonition);
                 Billing_Controller_OpenItem::getInstance()->update($openItem);
             }
             $monition->__set('monition_level', $overallMonitionStage);
             if (Billing_Custom_Template::isToPrint($monition, Billing_Controller_Print::TYPE_MONITION, $templateId)) {
                 $monition->__set('template_id', $templateId);
             }
             Billing_Controller_Receipt::getInstance()->update($monition);
             $batchJobMonition->__set('action_state', 'DONE');
             $batchJobMonition->__set('process_datetime', Zend_Date::now());
             $batchJobMonition->__set('processed_by_user', Tinebase_Core::get(Tinebase_Core::USER)->getId());
             $this->update($batchJobMonition);
             $protocolBatchJobMonitionIds[] = $batchJobMonitionId;
         }
         $printController = Billing_Controller_Print::getInstance();
         $printController->printReceipts($bufferMonitionIds, false, null, false, false, false);
         $storage = $printController->getPrintJobStorage();
         $tempFilePath = CSopen::instance()->getCustomerPath() . '/customize/data/documents/temp/';
         $filename = $tempFilePath . md5(microtime()) . '.pdf';
         $storage->copyOut("//out/result/merge/pdf/final", $filename);
         $storage->close();
         Billing_Api_BatchJobManager::getInstance()->jobAddData('MONITION', $filename);
         Billing_Api_BatchJobManager::getInstance()->jobAddData('MonitionDownloadFilename', 'Monition-' . $job->__get('job_nr') . '.pdf');
         $tm->commitTransaction($tId);
         //Billing_Api_BatchJobManager::getInstance()->finish();
         $this->printMonitionExportPrepare($jobId, false, null, true, $protocolBatchJobMonitionIds);
         return array('state' => 'success', 'result' => null);
         //        $outputFileName = $tempFilePath . md5(serialize($job).'preparePDF'.microtime()).'.pdf';
     } catch (Exception $e) {
         echo $e->__toString();
         $tm->rollback($tId);
         Billing_Api_BatchJobManager::getInstance()->finishError($e->__toString());
         return array('state' => 'failure', 'result' => null, 'errorInfo' => array('message' => $e->getMessage(), 'trace' => $e->getTrace()));
     }
 }