private function generateExportFile(Pap_Db_PayoutOption $payoutOption, $affiliateNote = '') { $header = new Gpf_Templates_Template($payoutOption->getExportHeaderTemplate(), '', Gpf_Templates_Template::FETCH_TEXT); $content = $header->getHTML(); $currency = Pap_Common_Utils_CurrencyUtils::getDefaultCurrency(); $affiliates = 0; $commissions = 0; $selectBuilder = $this->getAffiliatesToPaySelect($payoutOption->getID()); foreach ($selectBuilder->getAllRowsIterator() as $row) { $user = new Pap_Common_User(); $user->fillFromRecord($row); $payout = new Pap_Common_Payout($user, $currency, $row->get('amountRaw'),$this->generateInvoiceNumber()); $payout->setAffiliateNote($affiliateNote); $affiliates++; $commissions += $row->get('amountRaw'); $content .= $payout->getExportRow(); } $footer = new Gpf_Templates_Template($payoutOption->getExportFooterTemplate(), '', Gpf_Templates_Template::FETCH_TEXT); $footer->assign('affiliates', $affiliates); $footer->assign('commissions', round($commissions, Pap_Common_Utils_CurrencyUtils::getDefaultCurrency()->getPrecision())); $content .= $footer->getHTML(); $content = str_replace('\t', "\t", $content); $content = str_replace('\n', "\n", $content); return $content; }
public function getExportRow() { $rowTemplate = new Gpf_Templates_Template($this->payoutOption->getExportRowTemplate(), '', Gpf_Templates_Template::FETCH_TEXT); $this->assignPayoutVariablesToTemplate($rowTemplate); return $rowTemplate->getHTML(); }
/** * @return Gpf_DbEngine_Row */ protected function createEmptyRow() { $row = new Pap_Db_PayoutOption(); $row->set(Gpf_Db_Table_Accounts::ID, Gpf_Application::getInstance()->getAccountId()); $row->setName($this->_("New payout option")); $row->setStatus(Pap_Db_PayoutOption::DISABLED); $row->setOrder(1); $i = 2; while ($i < 10) { try { $row->check(); break; } catch (Gpf_DbEngine_Row_CheckException $e) { $row->setName($this->_("New payout option %s", $i)); $i++; } } return $row; }
/** * @return Pap_Db_PayoutOption */ private function createPayoutOption($id, $status, $order, $name) { $option = new Pap_Db_PayoutOption(); $option->setId($id); $option->setStatus($status); $option->setOrder($order); $option->setName($name); $option->setAccountId($this->account->getId()); return $option; }
/** * @param array $payoutOptionData */ private function processPayoutOption($payoutOptionData, $row) { $user = new Pap_Affiliates_User(); $user->setId($payoutOptionData[Pap_Db_Table_UserPayoutOptions::USERID]); try { $user->load(); $payoutOption = new Pap_Db_PayoutOption(); $payoutOption->setID($user->getPayoutOptionId()); $payoutOption->load(); $payoutField = new Gpf_Db_FormField(); $payoutField->setFormId($payoutOption->getFormId()); $payoutField->setCode($payoutOptionData[Gpf_Db_Table_FormFields::CODE]); $payoutField->loadFromData(array(Gpf_Db_Table_FormFields::FORMID, Gpf_Db_Table_FormFields::CODE)); $userPayoutOption = new Pap_Db_UserPayoutOption(); $userPayoutOption->setUserId($payoutOptionData[Pap_Db_Table_UserPayoutOptions::USERID]); $userPayoutOption->setFormFieldId($payoutField->getId()); $userPayoutOption->setValue($payoutOptionData[Pap_Db_Table_UserPayoutOptions::VALUE]); $userPayoutOption->save(); $this->incrementSuccessfulCount(); $this->logger->debug('Data from line: ' . $this->getFile()->getActualCSVLineNumber() . ' was inserted.'); } catch (Gpf_Exception $e) { $this->logError('Payout option', $row, $e); $this->appendOutputMessage($this->getSaveErrorMessage($this->getFile()->getActualCSVLineNumber(), $e->getMessage())); $this->incrementWrongCount(); } }