示例#1
0
 public function bookPayments($payments)
 {
     //throw new Zend_Exception('Temporarily disabled');
     foreach ($payments as $payment) {
         if ($payment->hasAdditionalItem('donation')) {
             $donationData = $payment->getAdditionalItem('donation');
         } else {
             $donationData = null;
         }
         if ($payment->hasMultipleOpenItems()) {
             $additionalData = $payment->getAdditionalData();
             if ($payment->hasAdditionalItem('openItems')) {
                 $data = $payment->getAdditionalItem('openItems');
                 $donationData = $payment->getAdditionalItem('donation');
                 $payment->flatten();
                 $paymentRecord = $payment->toArray();
                 $paymentRecord['amount'] = $paymentRecord['payment_amount'];
                 Billing_Controller_OpenItem::getInstance()->payOpenItems($data, $paymentRecord, $donationData);
             }
         } else {
             $pExtract = clone $payment;
             $pExtract->flatten();
             $paymentRecord = $pExtract->toArray();
             $paymentO = Billing_Controller_Payment::getInstance()->getEmptyPayment();
             if (array_key_exists('id', $paymentRecord)) {
                 unset($paymentRecord['id']);
             }
             $paymentO->setFromArray($paymentRecord);
             $paymentO->__set('amount', $payment->__get('payment_amount'));
             $openItem = $payment->getForeignRecordBreakNull('op_id', Billing_Controller_OpenItem::getInstance());
             if ($openItem) {
                 if ($payment->__get('overpay') == 'DONATION' && !$payment->__get('is_return_debit') && $donationData) {
                     $opAmount = abs((double) $openItem->__get('open_sum'));
                     $pAmount = abs((double) $payment->__get('payment_amount'));
                     if ($pAmount > $opAmount) {
                         $donationAmount = $pAmount - $opAmount;
                         $payment2 = clone $paymentO;
                         $payment2->__set('id', null);
                         $payment2->__set('amount', $donationAmount);
                         $payment2->__set('erp_context_id', 'DONATOR');
                         $payment2 = Billing_Controller_Payment::getInstance()->create($payment2);
                         $paymentDebitor = $payment2->getForeignRecord('debitor_id', Billing_Controller_Debitor::getInstance());
                         $contactId = $paymentDebitor->getForeignId('contact_id');
                         if ($donationData) {
                             $campaignId = $donationData['campaign'];
                         } else {
                             $campaign = Donator_Controller_Campaign::getInstance()->getDefaultCampaign();
                             $campaignId = $campaign->getId();
                         }
                         $usage = 'Spende Adress-Nr: ' . $paymentDebitor->__get('debitor_nr');
                         $date = $payment->__get('payment_date');
                         $donation = Donator_Controller_FundMaster::getInstance()->donateByContactId($contactId, $donationAmount, $campaignId, $date, $usage, $payment2);
                         $paymentO->__set('amount', $pAmount - $donationAmount);
                     }
                 }
                 // in case of overpay
                 if ($paymentO->__get('amount') != 0) {
                     $paymentO = Billing_Controller_Payment::getInstance()->create($paymentO);
                     Billing_Controller_OpenItem::getInstance()->payOpenItem($openItem->getId(), $paymentO, abs((double) $openItem->__get('open_sum')));
                 }
             } else {
                 // can be donation or prepay of member fee
                 if ($payment->__get('is_return_debit')) {
                     $paymentO = Billing_Controller_Payment::getInstance()->create($paymentO);
                     // prepay member fee
                 } elseif ($payment->__get('overpay') == 'PREPAYMEMBERFEE') {
                     // do nothing else, payment is stored with context membership
                     // so balance is positive
                     $paymentO->__set('erp_context_id', 'MEMBERSHIP');
                     $paymentO = Billing_Controller_Payment::getInstance()->create($paymentO);
                 } else {
                     // donation
                     $paymentO->__set('erp_context_id', 'DONATOR');
                     //$paymentO = Billing_Controller_Payment::getInstance()->create($paymentO);
                     $donationData = $payment->getAdditionalItem('donation');
                     $donationAmount = abs((double) $payment->__get('payment_amount'));
                     $payment2 = clone $paymentO;
                     $payment2->__set('id', null);
                     $payment2->__set('amount', $donationAmount);
                     $payment2->__set('erp_context_id', 'DONATOR');
                     $payment2 = Billing_Controller_Payment::getInstance()->create($payment2);
                     $paymentDebitor = $payment2->getForeignRecord('debitor_id', Billing_Controller_Debitor::getInstance());
                     $contactId = $paymentDebitor->getForeignId('contact_id');
                     if ($donationData) {
                         $campaignId = $donationData['campaign'];
                     } else {
                         $campaign = Donator_Controller_Campaign::getInstance()->getDefaultCampaign();
                         $campaignId = $campaign->getId();
                     }
                     $usage = 'Spende Adress-Nr: ' . $paymentDebitor->__get('debitor_nr');
                     $date = $payment->__get('payment_date');
                     $donation = Donator_Controller_FundMaster::getInstance()->donateByContactId($contactId, $donationAmount, $campaignId, $date, $usage, $payment2);
                 }
             }
         }
     }
 }
示例#2
0
 /**
  * 
  * get donation_amount sums collected by campaigns
  */
 public function getCreateDonationData()
 {
     try {
         if (!class_exists('Donator_Model_Donation')) {
             return null;
         }
         $hasDon = false;
         $aResult = array();
         $receiptPositions = Billing_Controller_ReceiptPosition::getInstance()->getPositionsByReceiptId($this->getId());
         foreach ($receiptPositions as $rp) {
             $article = $rp->getForeignRecordBreakNull('article_id', Billing_Controller_Article::getInstance());
             if ($article && $article->createsDonation()) {
                 $donationAmount = $article->__get('donation_amount') * $rp->__get('amount');
                 $campaign = $article->getForeignRecordBreakNull('donation_campaign_id', Donator_Controller_Campaign::getInstance());
                 if ($donationAmount != 0 && $campaign) {
                     $hasDon = true;
                     if (!array_key_exists($campaign->getId(), $aResult)) {
                         $aResult[$campaign->getId()] = $donationAmount;
                     } else {
                         $aResult[$campaign->getId()] += $donationAmount;
                     }
                 }
             }
         }
         if (!$hasDon) {
             return null;
         }
         return $aResult;
     } catch (Exception $e) {
         return null;
     }
 }