/**
  * Get the data being exported
  *
  * @access public
  * @since 1.0
  * @return array $data Data for Export
  */
 public function get_data()
 {
     $args = array('status' => 'unpaid', 'date' => !empty($this->date) ? $this->date : '', 'number' => -1);
     // Final data to be exported
     $data = array();
     // The affiliates that have earnings to be paid
     $affiliates = array();
     // The list of referrals that are possibly getting marked as paid
     $to_maybe_pay = array();
     // Retrieve the referrals from the database
     $referrals = affiliate_wp()->referrals->get_referrals($args);
     // The minimum payout amount
     $minimum = !empty($_POST['minimum']) ? sanitize_text_field(affwp_sanitize_amount($_POST['minimum'])) : 0;
     if ($referrals) {
         foreach ($referrals as $referral) {
             if (in_array($referral->affiliate_id, $affiliates)) {
                 // Add the amount to an affiliate that already has a referral in the export
                 $amount = $data[$referral->affiliate_id]['amount'] + $referral->amount;
                 $data[$referral->affiliate_id]['amount'] = $amount;
             } else {
                 $email = affwp_get_affiliate_email($referral->affiliate_id);
                 $data[$referral->affiliate_id] = array('email' => $email, 'amount' => $referral->amount, 'currency' => !empty($referral->currency) ? $referral->currency : affwp_get_currency());
                 $affiliates[] = $referral->affiliate_id;
             }
             // Add the referral to the list of referrals to maybe payout
             if (!array_key_exists($referral->affiliate_id, $to_maybe_pay)) {
                 $to_maybe_pay[$referral->affiliate_id] = array();
             }
             $to_maybe_pay[$referral->affiliate_id][] = $referral->referral_id;
         }
         // Now determine which affiliates are above the minimum payout amount
         if ($minimum > 0) {
             foreach ($data as $affiliate_id => $payout) {
                 if ($payout['amount'] < $minimum) {
                     unset($data[$affiliate_id]);
                     unset($to_maybe_pay[$affiliate_id]);
                 }
             }
         }
         // We now know which referrals should be marked as paid
         foreach ($to_maybe_pay as $referral_list) {
             foreach ($referral_list as $referral_id) {
                 affwp_set_referral_status($referral_id, 'paid');
             }
         }
     }
     $data = apply_filters('affwp_export_get_data', $data);
     $data = apply_filters('affwp_export_get_data_' . $this->export_type, $data);
     return $data;
 }
/**
 * Retrieves an array of allowed affiliate rate types
 *
 * @since 1.1
 * @return array
 */
function affwp_get_affiliate_rate_types()
{
    // Allowed types
    $types = array('percentage' => __('Percentage (%)', 'affiliate-wp'), 'flat' => sprintf(__('Flat %s', 'affiliate-wp'), affwp_get_currency()));
    return apply_filters('affwp_get_affiliate_rate_types', $types);
}
Ejemplo n.º 3
0
/**
 * Set the number of decimal places per currency
 *
 * @since 1.4.2
 * @param int $decimals Number of decimal places
 * @return int $decimals
*/
function affwp_currency_decimal_filter($decimals = 2)
{
    global $affwp_options;
    $currency = affwp_get_currency();
    switch ($currency) {
        case 'RIAL':
        case 'JPY':
        case 'TWD':
        case 'KRW':
            $decimals = 0;
            break;
    }
    return $decimals;
}
Ejemplo n.º 4
0
 /**
  * Get default column values
  *
  * @access  public
  * @since   1.0
  */
 public function get_column_defaults()
 {
     return array('affiliate_id' => 0, 'date' => date('Y-m-d H:i:s'), 'currency' => affwp_get_currency());
 }