Пример #1
0
 public static function getAllPayments($periods)
 {
     $payments = array();
     $grandtotal = 0;
     $i = 0;
     $userpromos = array();
     $current_user = '';
     foreach ($periods as $key => $period) {
         $promoObject = new PAP_Model_Promotion();
         $allpromos = $promoObject->getPromotionsByDates($period->getFrom(), $period->getTo(), null);
         $countpromos = count($allpromos);
         foreach ($allpromos as $promo) {
             $i += 1;
             if (!($current_user == $promo['user_id'] || $current_user == '')) {
                 if (isset($userpromos)) {
                     $payment = array();
                     $payment['user_id'] = $current_user;
                     $payment['charge_id'] = $key;
                     $payment['periodo'] = $period->getCode();
                     $payment['desde'] = $period->getFrom();
                     $payment['hasta'] = $period->getTo();
                     $total = PAP_Model_Payment::getPeriodsRecords($period, $userpromos, $promoscost);
                     $payment['costos'] = $promoscost;
                     $payment['total'] = $total;
                     $payments[] = $payment;
                     $grandtotal += $total;
                 }
                 $userpromos = array();
                 $total = 0;
             }
             $userpromos[] = $promo;
             $current_user = $promo['user_id'];
             if ($countpromos == $i) {
                 //proceso ultima promoción.
                 $payment = array();
                 $payment['user_id'] = $current_user;
                 $payment['charge_id'] = $key;
                 $payment['periodo'] = $period->getCode();
                 $payment['desde'] = $period->getFrom();
                 $payment['hasta'] = $period->getTo();
                 $total = PAP_Model_Payment::getPeriodsRecords($period, $userpromos, $promoscost);
                 $payment['costos'] = $promoscost;
                 $payment['total'] = $total;
                 $payments[] = $payment;
                 $grandtotal += $total;
             }
         }
     }
     return $payments;
 }