/** * * @service affiliate_invoice read_own * @param $fields */ public function viewInvoice(Gpf_Rpc_Params $params) { $form = new Gpf_Rpc_Form($params); $payoutId = $form->getFieldValue("Id"); $payout = new Pap_Db_Payout(); $payout->setPrimaryKeyValue($payoutId); $payout->setUserId(Gpf_Session::getAuthUser()->getPapUserId()); try { $payout->loadFromData(array(Pap_Db_Table_Payouts::ID, Pap_Db_Table_Payouts::USER_ID)); $this->invoiceHtml = $payout->getInvoice(); return $this; } catch(Gpf_Exception $e) { } throw new Gpf_Exception($this->_('Cannot find invoice')); }
private function migratePayouts() { echo " Migrating payous....."; $selectBuilder = new Gpf_SqlBuilder_SelectBuilder(); $selectBuilder->select->add('sum(commission)', 'commission'); $selectBuilder->select->add('affiliateid'); $selectBuilder->select->add('accountingid'); $selectBuilder->from->add('wd_pa_transactions'); $selectBuilder->where->add('rstatus', '=', Pap3Compatibility_Migration_Pap3Constants::STATUS_APPROVED); $selectBuilder->where->add('payoutstatus', '=', Pap3Compatibility_Migration_Pap3Constants::STATUS_APPROVED); $selectBuilder->where->add('accountingid', '!=', null); $selectBuilder->groupBy->add('accountingid'); $selectBuilder->groupBy->add('affiliateid'); $count = 0; foreach($selectBuilder->getAllRowsIterator() as $record) { $obj = new Pap_Db_Payout(); $obj->setUserId($record->get('affiliateid')); $obj->set('payouthistoryid', $record->get('accountingid')); $obj->set('amount', $record->get('commission')); $obj->save(); $count++; } echo " ($count) ..... DONE<br/>"; }