function get_value($code) { return $this->format(smn_round(smn_add_tax($products_price, $products_tax), $this->currencies[$currency_type]['decimal_places']) * $quantity); }
} $affiliate_clickthroughs_raw = "select count(*) as count from " . TABLE_AFFILIATE_CLICKTHROUGHS . " where affiliate_id = '" . $affiliate_id . "'"; $affiliate_clickthroughs_query = smn_db_query($affiliate_clickthroughs_raw); $affiliate_clickthroughs = smn_db_fetch_array($affiliate_clickthroughs_query); $affiliate_clickthroughs = $affiliate_clickthroughs['count']; $affiliate_sales_raw = "\n\t\t\tselect count(*) as count, sum(affiliate_value) as total, sum(affiliate_payment) as payment from " . TABLE_AFFILIATE_SALES . " a \n\t\t\tleft join " . TABLE_ORDERS . " o on (a.affiliate_orders_id=o.orders_id) \n\t\t\twhere a.affiliate_id = '" . $affiliate_id . "' and o.orders_status >= " . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . " \n\t\t\t"; $affiliate_sales_query = smn_db_query($affiliate_sales_raw); $affiliate_sales = smn_db_fetch_array($affiliate_sales_query); $affiliate_transactions = $affiliate_sales['count']; if ($affiliate_clickthroughs > 0) { $affiliate_conversions = smn_round($affiliate_transactions / $affiliate_clickthroughs * 100, 2) . "%"; } else { $affiliate_conversions = "n/a"; } $affiliate_amount = $affiliate_sales['total']; if ($affiliate_transactions > 0) { $affiliate_average = smn_round($affiliate_amount / $affiliate_transactions, 2); } else { $affiliate_average = "n/a"; } $affiliate_commission = $affiliate_sales['payment']; $affiliate_values = smn_db_query("select * from " . TABLE_AFFILIATE . " where affiliate_id = '" . $affiliate_id . "'"); $affiliate = smn_db_fetch_array($affiliate_values); $affiliate_percent = 0; $affiliate_percent = $affiliate['affiliate_commission_percent']; if ($affiliate_percent < AFFILIATE_PERCENT) { $affiliate_percent = AFFILIATE_PERCENT; } ?>
} $orders_id = substr($orders_id, 0, -1) . ")"; // Set the Sales to Temp State (it may happen that an order happend while billing) $sql = "UPDATE " . TABLE_AFFILIATE_SALES . " \n set affiliate_billing_status=99 \n where affiliate_id='" . $affiliate_payment['affiliate_id'] . "' \n and affiliate_orders_id in " . $orders_id . " \n "; smn_db_query($sql); // Get Sum of payment (Could have changed since last selects); $sql = "\n SELECT sum(affiliate_payment) as affiliate_payment\n FROM " . TABLE_AFFILIATE_SALES . " \n WHERE affiliate_id='" . $affiliate_payment['affiliate_id'] . "' and affiliate_billing_status=99 \n "; $affiliate_billing_query = smn_db_query($sql); $affiliate_billing = smn_db_fetch_array($affiliate_billing_query); // Get affiliate Informations $sql = "\n SELECT a.*, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id \n from " . TABLE_AFFILIATE . " a \n left join " . TABLE_ZONES . " z on (a.affiliate_zone_id = z.zone_id) \n left join " . TABLE_COUNTRIES . " c on (a.affiliate_country_id = c.countries_id)\n WHERE affiliate_id = '" . $affiliate_payment['affiliate_id'] . "' \n "; $affiliate_query = smn_db_query($sql); $affiliate = smn_db_fetch_array($affiliate_query); // Get need tax informations for the affiliate $affiliate_tax_rate = smn_get_affiliate_tax_rate(AFFILIATE_TAX_ID, $affiliate['affiliate_country_id'], $affiliate['affiliate_zone_id']); $affiliate_tax = smn_round($affiliate_billing['affiliate_payment'] * $affiliate_tax_rate / 100, 2); // Netto-Provision $affiliate_payment_total = $affiliate_billing['affiliate_payment'] + $affiliate_tax; // Bill the order $affiliate['affiliate_state'] = smn_get_zone_code($affiliate['affiliate_country_id'], $affiliate['affiliate_zone_id'], $affiliate['affiliate_state']); $sql_data_array = array('affiliate_id' => $affiliate_payment['affiliate_id'], 'affiliate_payment' => $affiliate_billing['affiliate_payment'], 'affiliate_payment_tax' => $affiliate_tax, 'affiliate_payment_total' => $affiliate_payment_total, 'affiliate_payment_date' => 'now()', 'affiliate_payment_status' => '0', 'affiliate_firstname' => $affiliate['affiliate_firstname'], 'affiliate_lastname' => $affiliate['affiliate_lastname'], 'affiliate_street_address' => $affiliate['affiliate_street_address'], 'affiliate_suburb' => $affiliate['affiliate_suburb'], 'affiliate_city' => $affiliate['affiliate_city'], 'affiliate_country' => $affiliate['countries_name'], 'affiliate_postcode' => $affiliate['affiliate_postcode'], 'affiliate_company' => $affiliate['affiliate_company'], 'affiliate_state' => $affiliate['affiliate_state'], 'affiliate_address_format_id' => $affiliate['address_format_id']); smn_db_perform(TABLE_AFFILIATE_PAYMENT, $sql_data_array); $insert_id = smn_db_insert_id(); // Set the Sales to Final State smn_db_query("update " . TABLE_AFFILIATE_SALES . " set affiliate_payment_id = '" . $insert_id . "', affiliate_billing_status = 1, affiliate_payment_date = now() where affiliate_id = '" . $affiliate_payment['affiliate_id'] . "' and affiliate_billing_status = 99"); // Notify Affiliate if (AFFILIATE_NOTIFY_AFTER_BILLING == 'true') { $check_status_query = smn_db_query("select af.affiliate_email_address, ap.affiliate_lastname, ap.affiliate_firstname, ap.affiliate_payment_status, ap.affiliate_payment_date, ap.affiliate_payment_date from " . TABLE_AFFILIATE_PAYMENT . " ap, " . TABLE_AFFILIATE . " af where affiliate_payment_id = '" . $insert_id . "' and af.affiliate_id = ap.affiliate_id "); $check_status = smn_db_fetch_array($check_status_query); $email = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_AFFILIATE_PAYMENT_NUMBER . ' ' . $insert_id . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . smn_catalog_href_link(FILENAME_CATALOG_AFFILIATE_PAYMENT_INFO, 'payment_id=' . $insert_id, 'NONSSL') . "\n" . EMAIL_TEXT_PAYMENT_BILLED . ' ' . smn_date_long($check_status['affiliate_payment_date']) . "\n\n" . EMAIL_TEXT_NEW_PAYMENT; smn_mail($check_status['affiliate_firstname'] . ' ' . $check_status['affiliate_lastname'], $check_status['affiliate_email_address'], EMAIL_TEXT_SUBJECT, nl2br($email), STORE_OWNER, AFFILIATE_EMAIL_ADDRESS);
function collect_posts() { global $_POST, $customer_id, $currencies, $cc_id; if ($_POST['gv_redeem_code']) { // get some info from the coupon table $coupon_query = smn_db_query("select coupon_id, coupon_amount, coupon_type, coupon_minimum_order,uses_per_coupon, uses_per_user, restrict_to_products,restrict_to_categories from " . TABLE_COUPONS . " where coupon_code='" . $_POST['gv_redeem_code'] . "' and coupon_active='Y'"); $coupon_result = smn_db_fetch_array($coupon_query); if ($coupon_result['coupon_type'] != 'G') { if (smn_db_num_rows($coupon_query) == 0) { smn_redirect(smn_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . urlencode(ERROR_NO_INVALID_REDEEM_COUPON), 'NONSSL')); } $date_query = smn_db_query("select coupon_start_date from " . TABLE_COUPONS . " where coupon_start_date <= now() and coupon_code='" . $_POST['gv_redeem_code'] . "'"); if (smn_db_num_rows($date_query) == 0) { smn_redirect(smn_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . urlencode(ERROR_INVALID_STARTDATE_COUPON), 'NONSSL')); } $date_query = smn_db_query("select coupon_expire_date from " . TABLE_COUPONS . " where coupon_expire_date >= now() and coupon_code='" . $_POST['gv_redeem_code'] . "'"); if (smn_db_num_rows($date_query) == 0) { smn_redirect(smn_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . urlencode(ERROR_INVALID_FINISDATE_COUPON), 'NONSSL')); } $coupon_count = smn_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id'] . "'"); $coupon_count_customer = smn_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id'] . "' and customer_id = '" . $customer_id . "'"); if (smn_db_num_rows($coupon_count) >= $coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0) { smn_redirect(smn_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . urlencode(ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES), 'NONSSL')); } if (smn_db_num_rows($coupon_count_customer) >= $coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0) { smn_redirect(smn_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . urlencode(ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES), 'NONSSL')); } global $order, $ot_coupon, $currency; if (!smn_session_is_registered('cc_id')) { smn_session_register('cc_id'); } $cc_id = $coupon_result['coupon_id']; $coupon_amount = smn_round($ot_coupon->pre_confirmation_check($order->info['subtotal']), $currencies->currencies[$currency]['decimal_places']); // $cc_id $coupon_amount_out = $currencies->format($coupon_amount) . ' '; if ($coupon_result['coupon_minimum_order'] > 0) { $coupon_amount_out .= 'on orders greater than ' . $currencies->format($coupon_result['coupon_minimum_order']); } if (!smn_session_is_registered('cc_id')) { smn_session_register('cc_id'); } $cc_id = $coupon_result['coupon_id']; if (strlen($cc_id) > 0 && $coupon_amount == 0) { $err_msg = ERROR_REDEEMED_AMOUNT . ERROR_REDEEMED_AMOUNT_ZERO; } else { $err_msg = ERROR_REDEEMED_AMOUNT . $coupon_amount_out; } smn_redirect(smn_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . urlencode($err_msg), 'NONSSL')); } // ENDIF valid coupon code } // ENDIF code entered // v5.13a If no code entered and coupon redeem button pressed, give an alarm if ($_POST['submit_redeem_coupon_x']) { smn_redirect(smn_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . urlencode(ERROR_NO_REDEEM_CODE), 'NONSSL')); } }
echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_6) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?> </td> <td width="15%" class="dataTableContent"><?php echo $currencies->display_price($affiliate_average, ''); ?> </td> </tr> <tr> <td width="35%" align="right" class="dataTableContent"><?php echo TEXT_COMMISSION_RATE; echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_7) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?> </td> <td width="15%" class="dataTableContent"><?php echo smn_round(AFFILIATE_PERCENT, 2) . ' %'; ?> </td> <td width="35%" align="right" class="dataTableContent"><b><?php echo TEXT_COMMISSION; echo '<a href="javascript:popupWindow(\'' . (HTTP_SERVER . DIR_WS_CATALOG . FILENAME_AFFILIATE_HELP_8) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?> </b></td> <td width="15%" class="dataTableContent"><b><?php echo $currencies->display_price($affiliate_commission, ''); ?> </b></td> </tr> <tr> <td colspan="4"><?php echo smn_draw_separator();
} $affiliate_total = smn_round($affiliate_total, 2); // Check for individual commission $affiliate_percentage = 0; if (AFFILATE_INDIVIDUAL_PERCENTAGE == 'true') { $affiliate_commission_query = smn_db_query("select affiliate_commission_percent from " . TABLE_AFFILIATE . " where affiliate_id = '" . $affiliate_ref . "'"); $affiliate_commission = smn_db_fetch_array($affiliate_commission_query); $affiliate_percent = $affiliate_commission['affiliate_commission_percent']; } if ($affiliate_percent < AFFILIATE_PERCENT) { $affiliate_percent = AFFILIATE_PERCENT; } $affiliate_payment = smn_round($affiliate_total * $affiliate_percent / 100, 2); if ($HTTP_SESSION_VARS['affiliate_ref']) { $sql_data_array = array('affiliate_id' => $affiliate_ref, 'affiliate_date' => $affiliate_clientdate, 'affiliate_browser' => $affiliate_clientbrowser, 'affiliate_ipaddress' => $affiliate_clientip, 'affiliate_value' => $affiliate_total, 'affiliate_payment' => $affiliate_payment, 'affiliate_orders_id' => $insert_id, 'affiliate_clickthroughs_id' => $affiliate_clickthroughs_id, 'affiliate_percent' => $affiliate_percent, 'affiliate_salesman' => $affiliate_ref); smn_db_perform(TABLE_AFFILIATE_SALES, $sql_data_array); if (AFFILATE_USE_TIER == 'true') { $affiliate_tiers_query = smn_db_query("SELECT aa2.affiliate_id, (aa2.affiliate_rgt - aa2.affiliate_lft) as height\n FROM affiliate_affiliate AS aa1, affiliate_affiliate AS aa2\n WHERE aa1.affiliate_root = aa2.affiliate_root \n AND aa1.affiliate_lft BETWEEN aa2.affiliate_lft AND aa2.affiliate_rgt\n AND aa1.affiliate_rgt BETWEEN aa2.affiliate_lft AND aa2.affiliate_rgt\n AND aa1.affiliate_id = '" . $affiliate_ref . "'\n ORDER by height asc limit 1, " . AFFILIATE_TIER_LEVELS . " \n "); $affiliate_tier_percentage = split("[;]", AFFILIATE_TIER_PERCENTAGE); $i = 0; while ($affiliate_tiers_array = smn_db_fetch_array($affiliate_tiers_query)) { $affiliate_percent = $affiliate_tier_percentage[$i]; $affiliate_payment = smn_round($affiliate_total * $affiliate_percent / 100, 2); if ($affiliate_payment > 0) { $sql_data_array = array('affiliate_id' => $affiliate_tiers_array['affiliate_id'], 'affiliate_date' => $affiliate_clientdate, 'affiliate_browser' => $affiliate_clientbrowser, 'affiliate_ipaddress' => $affiliate_clientip, 'affiliate_value' => $affiliate_total, 'affiliate_payment' => $affiliate_payment, 'affiliate_orders_id' => $insert_id, 'affiliate_clickthroughs_id' => $affiliate_clickthroughs_id, 'affiliate_percent' => $affiliate_percent, 'affiliate_salesman' => $affiliate_ref); smn_db_perform(TABLE_AFFILIATE_SALES, $sql_data_array); } $i++; } } }
function calculate_price($products_price, $products_tax, $quantity = 1) { global $currency; return smn_round(smn_add_tax($products_price, $products_tax), $this->currencies[$currency]['decimal_places']) * $quantity; }
echo '<a href="javascript:popupWindow(\'' . smn_href_link(FILENAME_AFFILIATE_HELP_18) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?> </td> <td class="main"><?php echo $currencies->display_price(AFFILIATE_PAYMENT, ''); ?> </td> </tr> <tr> <td width="35%" align="right" class="main"><?php echo TEXT_COMMISSION_RATE; echo '<a href="javascript:popupWindow(\'' . smn_href_link(FILENAME_AFFILIATE_HELP_7) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?> </td> <td width="15%" class="main"><?php echo smn_round($affiliate_percent, 2) . '%'; ?> </td> <td width="35%" align="right" class="main"><?php echo TEXT_COMMISSION; echo '<a href="javascript:popupWindow(\'' . smn_href_link(FILENAME_AFFILIATE_HELP_8) . '\')">' . TEXT_SUMMARY_HELP . '</a>'; ?> </td> <td width="15%" class="main"><?php echo $currencies->display_price($affiliate_commission, ''); ?> Info</td> </tr> <tr> <td colspan="4"><?php echo smn_draw_separator();
function calculate_tax_deduction($amount, $od_amount, $method) { global $order; switch ($method) { case 'Standard': $ratio1 = $amount == 0 ? 0 : smn_round($od_amount / $amount, 2); $tod_amount = 0; reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $tax_rate = smn_get_tax_rate_from_desc($key); $total_net += $tax_rate * $order->info['tax_groups'][$key]; } if ($od_amount > $total_net) { $od_amount = $total_net; } reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $tax_rate = smn_get_tax_rate_from_desc($key); $net = $tax_rate * $order->info['tax_groups'][$key]; if ($net > 0) { $god_amount = $order->info['tax_groups'][$key] * $ratio1; $tod_amount += $god_amount; $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; } } $order->info['tax'] -= $tod_amount; $order->info['total'] -= $tod_amount; break; case 'Credit Note': $tax_rate = smn_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tax_desc = smn_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate; $order->info['tax_groups'][$tax_desc] -= $tod_amount; break; default: } return $tod_amount; }
if ($affiliate_impressions == 0) { $affiliate_impressions = "n/a"; } $affiliate_query = smn_db_query("select * from " . TABLE_AFFILIATE . " where affiliate_id ='" . $_GET['acID'] . "'"); $affiliate = smn_db_fetch_array($affiliate_query); $affiliate_percent = 0; $affiliate_percent = $affiliate['affiliate_commission_percent']; if ($affiliate_percent < AFFILIATE_PERCENT) { $affiliate_percent = AFFILIATE_PERCENT; } $affiliate_clickthroughs_raw = "select count(*) as count from " . TABLE_AFFILIATE_CLICKTHROUGHS . " where affiliate_id = '" . $_GET['acID'] . "'"; $affiliate_clickthroughs_query = smn_db_query($affiliate_clickthroughs_raw); $affiliate_clickthroughs = smn_db_fetch_array($affiliate_clickthroughs_query); $affiliate_clickthroughs = $affiliate_clickthroughs['count']; $affiliate_sales_raw = "\n select count(*) as count, sum(affiliate_value) as total, sum(affiliate_payment) as payment from " . TABLE_AFFILIATE_SALES . " a \n left join " . TABLE_ORDERS . " o on (a.affiliate_orders_id=o.orders_id) \n where a.affiliate_id = '" . $_GET['acID'] . "' and o.orders_status >= " . AFFILIATE_PAYMENT_ORDER_MIN_STATUS . "\n "; $affiliate_sales_query = smn_db_query($affiliate_sales_raw); $affiliate_sales = smn_db_fetch_array($affiliate_sales_query); $affiliate_transactions = $affiliate_sales['count']; if ($affiliate_clickthroughs > 0) { $affiliate_conversions = smn_round($affiliate_transactions / $affiliate_clickthroughs * 100, 2) . "%"; } else { $affiliate_conversions = "n/a"; } if ($affiliate_sales['total'] > 0) { $affiliate_average = $affiliate_sales['total'] / $affiliate_sales['count']; } else { $affiliate_average = 0; } $content_page = basename($_SERVER['PHP_SELF']); require 'templates/default/layout.php'; require DIR_WS_INCLUDES . 'application_bottom.php';