public function getDonation() { try { if (!class_exists('Donator_Model_Donation') || !$this->__get('donation_id')) { return null; } return $this->getForeignRecordBreakNull('donation_id', Donator_Controller_Donation::getInstance()); } catch (Exception $e) { return null; } }
public function getDonationAndMemberFeeSums($period, $definition, &$fixValues, &$resultValues) { $values = array('VOR' => array(), 'JETZT' => array(), 'NACH' => array()); $fixValues = array('prev_period' => $period - 1, 'now_period' => $period, 'next_period' => $period + 1); $periods = array('VOR' => $period - 1, 'JETZT' => $period, 'NACH' => $period + 1); $result = array(); // Mitgliederbeiträge nach Beitragsgruppen: $date = new Zend_Date(); $date->setYear($period); $beginDate = $definition->getStartDate(new Zend_Date()); $endDate = $definition->getEndDate(new Zend_Date()); /*$beginDate = clone $date; $endDate = clone $date; $beginDate->setMonth(1); $beginDate->setDay(1); $endDate->setMonth(12); $endDate->setDay(31);*/ $baseOpFilter = array(); $baseDonationFilter = array(); $baseOpFilter[] = array('field' => 'payment_date', 'operator' => 'afterOrAt', 'value' => $beginDate->toString('yyyy-MM-dd')); $baseOpFilter[] = array('field' => 'payment_date', 'operator' => 'beforeOrAt', 'value' => $endDate->toString('yyyy-MM-dd')); $baseOpFilter[] = array('field' => 'state', 'operator' => 'not', 'value' => 'OPEN'); $baseDonationFilter[] = array('field' => 'donation_date', 'operator' => 'afterOrAt', 'value' => $beginDate->toString('yyyy-MM-dd')); $baseDonationFilter[] = array('field' => 'donation_date', 'operator' => 'beforeOrAt', 'value' => $endDate->toString('yyyy-MM-dd')); $baseOpFilter = new Billing_Model_OpenItemFilter($baseOpFilter, 'AND'); $baseDonationFilter = new Donator_Model_DonationFilter($baseDonationFilter, 'AND'); $feeGroups = Membership_Controller_FeeGroup::getInstance()->getAllFeeGroups('key'); $feeGroupSum = 0; $resultValues = array(); $nowSum = $previousSum = $nextSum = $totalDonationSum = 0; foreach ($feeGroups as $feeGroup) { $opFilter = null; $opFilter = clone $baseOpFilter; $opFilter->addFilter($opFilter->createFilter('fee_group_id', 'equals', $feeGroup->__get('id'), 'rc')); $innerArray = array(); $innerArray['bg_name'] = $feeGroup->__get('name'); foreach ($values as $key => $value) { $innerOpFilter = null; $innerOpFilter = clone $opFilter; switch ($key) { case 'VOR': $innerOpFilter->addFilter($innerOpFilter->createFilter('period', 'less', $period, 'rc')); $sums = Billing_Controller_OpenItem::getInstance()->getSummation($innerOpFilter); $payedSum = $sums['payed_sum']; $innerArray['previous'] = number_format($payedSum, 2, ',', '.'); $previousSum += $payedSum; break; case 'JETZT': $innerOpFilter->addFilter($innerOpFilter->createFilter('period', 'equals', $period, 'rc')); $sums = Billing_Controller_OpenItem::getInstance()->getSummation($innerOpFilter); $payedSum = $sums['payed_sum']; $innerArray['now'] = number_format($payedSum, 2, ',', '.'); $nowSum += $payedSum; break; case 'NACH': $innerOpFilter->addFilter($innerOpFilter->createFilter('period', 'greater', $period, 'rc')); $sums = Billing_Controller_OpenItem::getInstance()->getSummation($innerOpFilter); $payedSum = $sums['payed_sum']; $innerArray['next'] = number_format($payedSum, 2, ',', '.'); $nextSum += $payedSum; break; } } $donationFilter = clone $baseDonationFilter; $donationFilter->addFilter($donationFilter->createFilter('fee_group_id', 'equals', $feeGroup->__get('id'))); $donationFilter->addFilter($donationFilter->createFilter('period', 'equals', $period)); // get Donation summation $sums = Donator_Controller_Donation::getInstance()->searchCount($donationFilter); $donationSum = $sums['sum']; $innerArray['donation'] = number_format($donationSum, 2, ',', '.'); $totalDonationSum += $donationSum; $resultValues[] = $innerArray; } // Spenden verarbeiten: $SFeeGroupSum = 0; //$result['S'] = array(); /*foreach($feeGroups as $feeGroup){ $donationFilter = clone $baseDonationFilter; $donationFilter->addFilter($donationFilter->createFilter('fee_group_id','equals',$feeGroup->__get('id'))); $donationFilter->addFilter($donationFilter->createFilter('period','equals',$period)); // get Donation summation $sums = Donator_Controller_Donation::getInstance()->searchCount($donationFilter); $donationSum = $sums['sum']; $result['SPENDE'.$feeGroup->__get('key')] = number_format($payedSum,2,',','.'); $SFeeGroupSum += $donationSum; }*/ //--> // Summe auslesen für Nichtmitglieder (Filter: is_member=false) //$group = new Tinebase_Model_Filter_FilterGroup(array(),'OR'); $donationFilter = clone $baseDonationFilter; $donationFilter->addFilter($donationFilter->createFilter('is_member', 'equals', 0)); $donationFilter->addFilter($donationFilter->createFilter('period', 'equals', $period)); /*$group->addFilterGroup($donationFilter); $donationFilter2 = clone $baseDonationFilter; $donationFilter2->addFilter($donationFilter->createFilter('fee_group_id','equals','')); $donationFilter2->addFilter($donationFilter->createFilter('period','equals',$period)); $group->addFilterGroup($donationFilter);*/ $sums = Donator_Controller_Donation::getInstance()->searchCount($donationFilter); $donationSum = $sums['sum']; $totalDonationSum += $donationSum; $result['SPENDE' . 'NOMEMBER'] = number_format($donationSum, 2, ',', '.'); //<-- $resultValues[] = array('bg_name' => 'Nichtmitglieder', 'previous' => 0, 'now' => 0, 'next' => 0, 'donation' => number_format($donationSum, 2, ',', '.')); $fixValues['sum_prev'] = number_format($previousSum, 2, ',', '.'); $fixValues['sum_now'] = number_format($nowSum, 2, ',', '.'); $fixValues['sum_next'] = number_format($nextSum, 2, ',', '.'); $fixValues['sum_donation'] = number_format($totalDonationSum, 2, ',', '.'); return $resultValues; }