public function saveCommissions(Pap_Contexts_Tracking $context) { $context->debug('Saving recurring commissions started'); $commissionType = $context->getCommissionTypeObject(); if ($commissionType == null) { $context->debug('No commission type defined. Recurring commissions saving ended'); return; } if ($commissionType->getRecurrencePresetId() == Pap_Db_CommissionType::RECURRENCE_NONE || $commissionType->getRecurrencePresetId() == null) { $context->debug('Saving recurring commissions ended - No recurring commissions defined'); return; } $tier = 1; $currentUser = $context->getUserObject(); $currentCommission = $context->getCommission($tier, Pap_Db_Table_Commissions::SUBTYPE_RECURRING); if ($currentUser == null || $currentCommission == null) { $context->debug('Saving recurring commissions ended - current user or current commission is null'); return; } $recurringCommission = new Pap_Db_RecurringCommission(); $relatedTransaction = $this->getTransaction($context); $recurringCommission->setOrderId($relatedTransaction->getOrderId()); $recurringCommission->setTransactionId($relatedTransaction->getTransactionId()); $recurringCommission->setRecurrencePresetId($commissionType->getRecurrencePresetId()); $recurringCommission->setCommissionTypeId($commissionType->getId()); $recurringCommission->setStatus($relatedTransaction->getStatus()); $recurringCommission->setLastCommissionDate($relatedTransaction->getDateInserted()); $recurringCommission->insert(); $context->debug('Recurring commission successfully saved.'); while($currentUser != null && $currentCommission != null && $tier < 100) { $rcEntry = new Pap_Db_RecurringCommissionEntry(); $rcEntry->setRecurringCommissionId($recurringCommission->getId()); $rcEntry->setUserId($currentUser->getId()); $rcEntry->setTier($tier); $rcEntry->setCommission($currentCommission->getCommission($context->getRealTotalCost())); $rcEntry->insert(); $tier++; $currentUser = $currentUser->getParentUser(); $currentCommission = $context->getCommission($tier, Pap_Db_Table_Commissions::SUBTYPE_RECURRING); } $context->debug('Saving recurring commissions ended'); $context->debug(""); }
private function approveRecurringCommission($transactionId) { $recurringCommission = new Pap_Db_RecurringCommission(); $recurringCommission->setTransactionId($transactionId); try { $recurringCommission->loadFromData(array(Pap_Db_Table_RecurringCommissions::TRANSACTION_ID)); if ($recurringCommission->getStatus() == Pap_Common_Constants::STATUS_PENDING) { $recurringCommission->setStatus(Pap_Common_Constants::STATUS_APPROVED); $recurringCommission->update(array(Pap_Db_Table_RecurringCommissions::STATUS)); Gpf_Log::debug('Recurring commission for transacton id: ' . $transactionId . ' is approved.' ); } } catch (Gpf_DbEngine_NoRowException $e) { Gpf_Log::debug('Transacton id: ' . $transactionId . ' does not have recurring commission.' ); } }