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/>";
    }