Esempio n. 1
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()));
     }
 }
Esempio n. 2
0
 /**
  * 
  * Create monition to an order
  * @param unknown_type $orderId
  * @param unknown_type $invoiceId
  */
 public function createMonition($orderId, $invoiceId)
 {
     $rcptController = Billing_Controller_Receipt::getInstance();
     // load invoice (same as get with type check on invoice)
     $invoice = $rcptController->getInvoice($invoiceId);
     $positions = $rcptController->getOrderPositions($invoice->getId());
     $monition = Billing_Model_Receipt::createMonition();
     $monition->__set('order_id', $orderId);
     $monition->__set('monition_fee', 0);
     $monition->__set('invoice_nr', $invoice->__get('invoice_nr'));
     $rcptController->create($monition);
     $rPosController = Billing_Controller_ReceiptPosition::getInstance();
     $rPosController->addOrderPositions($monition, $positions);
     $monition = $rcptController->get($monition->getId());
     return array('success' => true, 'result' => $monition->toArray());
 }