View of /com_supacart/trunk/admin_files/classes/wholesaler.functions.php
Parent Directory
|
Revision Log
Revision 4 -
(download)
(annotate)
Tue Aug 4 12:46:30 2009 UTC (3 years, 9 months ago) by andphe
File size: 14006 byte(s)
Tue Aug 4 12:46:30 2009 UTC (3 years, 9 months ago) by andphe
File size: 14006 byte(s)
+ adding first set of files for version control
<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); /** * @package SupaCart * @subpackage classes * See COPYRIGHT.php for copyright notices and details. * @license GNU/GPL Version 2, see LICENSE.php * SupaCart is free software, originally derived from Virtuemart. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See /administrator/components/com_supacart/COPYRIGHT.php for copyright notices and details. * * http://www.supacart.com */ function whOrderEmail($order_id) { $dbo = new ps_DB; $q = "SELECT vendor_id FROM #__{sc}_orders "; $q .= "WHERE order_id=$order_id"; $dbo->query($q); $dbo->next_record(); $dbv = new ps_DB; $q = "SELECT vendor_name, contact_email, vendor_currency_display_style FROM #__{sc}_vendor "; $q .= "WHERE vendor_id=".$dbo->f("vendor_id"); $dbv->query($q); $dbv->next_record(); $currency_display =& vendor_currency_display_style( $dbv->f("vendor_currency_display_style") ); $whfromemail = $dbv->f("contact_email"); $whemailname = $dbv->f("vendor_name"); $whemailsubject = $dbv->f("vendor_name"); $decimal_places = $currency_display['nbdecimal']; $template = read_file( PAGEPATH."templates/wholesale/email_detail_1.php"); $whdb =& new ps_DB; $db = new ps_DB; $db_wh = new ps_DB; global $CURRENCY_DISPLAY; $whq = "SELECT #__{sc}_order_item.product_id, #__{sc}_order_item.user_info_id, #__{sc}_order_item.order_id, #__{sc}_order_item.order_item_sku, #__{sc}_order_item.order_item_name, #__{sc}_order_item.product_quantity, #__{sc}_order_item.product_item_price, #__{sc}_order_item.product_final_price, #__{sc}_order_item.product_attribute, #__{sc}_product.product_wh_id, #__{sc}_product.product_wh_use_wholesaler, #__{sc}_wholesalers.wh_active FROM #__{sc}_order_item LEFT JOIN #__{sc}_product ON #__{sc}_order_item.product_id = #__{sc}_product.product_id LEFT JOIN #__{sc}_wholesalers ON #__{sc}_product.product_wh_id = #__{sc}_wholesalers.wholesaler_id WHERE (((#__{sc}_order_item.order_id)=".$order_id.") AND ((#__{sc}_product.product_wh_use_wholesaler)=\"Y\") AND ((#__{sc}_wholesalers.wh_active)=\"Y\")) ORDER BY #__{sc}_product.product_wh_id"; $whdb->query($whq); $whID = ''; while ($whdb->next_record()) { if ($whID == '') { $whID = $whdb->f("product_wh_id"); $supply_price_total=0; $supply_quantity_total=0; $gross_supply_price_total = 0; $gross_supply_quantity_total=0; $q = "SELECT wh_discount FROM #__{sc}_wholesalers where wholesaler_id=".$whID; $db_wh->setQuery($q); $db_wh->query(); if ($db_wh->next_record()) $wh_discount = $db_wh->f("wh_discount"); } if ($whID <> $whdb->f("product_wh_id")) { whEmailOrderToWholesaler($order_id, $whID, $whMessage, $whfromemail, $whemailname, $whemailsubject, $supply_price_total, $gross_supply_price_total, $supply_quantity_total, $decimal_places); $whID = $whdb->f("product_wh_id"); $whMessage = ''; $supply_price_total=0; $supply_quantity_total=0; $gross_supply_price_total = 0; $gross_supply_quantity_total=0; $q = "SELECT wh_discount FROM #__{sc}_wholesalers where wholesaler_id=".$whID; $db_wh->setQuery($q); $db_wh->query(); if ($db_wh->next_record()) $wh_discount = $db_wh->f("wh_discount"); } $product_cell = str_replace( "{product_sku}", $whdb->f("order_item_sku"), $template ); $product_cell = str_replace( "{product_name}", $whdb->f("order_item_name"), $product_cell ); $product_cell = str_replace( "{product_qty}", $whdb->f("product_quantity"), $product_cell ); $product_cell = str_replace( "{product_attribute}", $whdb->f("product_attribute"), $product_cell ); $supply_quantity_total+=$whdb->f("product_quantity"); // NET Price $product_price= $whdb->f("product_item_price")*(100-$wh_discount)/100; $product_price_total = $product_price*$whdb->f("product_quantity"); $supply_price_total += $product_price_total; $product_cell = str_replace( "{product_price_nf}",number_format($product_price,$decimal_places), $product_cell ); $product_cell = str_replace( "{product_price}", $CURRENCY_DISPLAY->getFullValue($product_price), $product_cell ); $product_cell = str_replace( "{product_price_total_nf}",number_format($product_price_total,$decimal_places), $product_cell ); $product_cell = str_replace( "{product_price_total}",$CURRENCY_DISPLAY->getFullValue($product_price_total), $product_cell ); // Gross Price $gross_product_price= $whdb->f("product_final_price")*(100-$wh_discount)/100; $gross_product_price_total = $gross_product_price*$whdb->f("product_quantity"); $gross_supply_price_total += $gross_product_price_total; $product_cell = str_replace( "{gross_product_price_nf}",number_format($gross_product_price,$decimal_places), $product_cell ); $product_cell = str_replace( "{gross_product_price}", $CURRENCY_DISPLAY->getFullValue($gross_product_price), $product_cell ); $product_cell = str_replace( "{gross_product_price_total_nf}",number_format($gross_product_price_total,$decimal_places), $product_cell ); $product_cell = str_replace( "{gross_product_price_total}",$CURRENCY_DISPLAY->getFullValue($gross_product_price_total), $product_cell ); if (!isset($whMessage)) { $whMessage = $product_cell; } else { $whMessage .= $product_cell; } } if (!isset($whMessage)) $whMessage = ''; if ($whMessage <> '') { whEmailOrderToWholesaler($order_id, $whID, $whMessage, $whfromemail, $whemailname, $whemailsubject, $supply_price_total, $gross_supply_price_total, $supply_quantity_total, $decimal_places); } } function whEmailOrderToWholesaler($order_id, $whID, $whMessage, $whfromemail, $whemailname, $whemailsubject, $supply_price_total, $gross_supply_price_total, $supply_quantity_total, $decimal_places) { require_once(CLASSPATH.'ps_checkout.php'); global $CURRENCY_DISPLAY; $whdb1 =& new ps_DB; $whq1 = "select * from #__{sc}_order_user_info where address_type = 'ST' and order_id =".$order_id; $whdb1->query($whq1); while ($whdb1->next_record()) { $num = 1; } if (!isset($num)) $num = 0; if ($num == 0) { $whq1 = "select * from #__{sc}_order_user_info where order_id =".$order_id; } else { $whq1 = "select * from #__{sc}_order_user_info where address_type = 'ST' and order_id =".$order_id; } $whdb1->query($whq1); $whdb1->next_record(); // pick up user group details $whdbvendorlink =& new ps_DB; $whvendorlink = "select * from #__{sc}_shopper_vendor_xref where user_id =".$whdb1->f("user_id"); $whdbvendorlink->query($whvendorlink); $whdbvendorlink->next_record(); $whdbgroup =& new ps_DB; $whgroup = "select * from #__{sc}_shopper_group where shopper_group_id =".$whdbvendorlink->f("shopper_group_id"); $whdbgroup->query($whgroup); $whdbgroup->next_record(); $whdb2 =& new ps_DB; $whq2 = "SELECT customer_note, cdate, order_shipping FROM #__{sc}_orders WHERE order_id=".$order_id; $whdb2->query($whq2); $dbaccount =& new ps_DB; $q = "SELECT payment_method_id, DECODE(order_payment_number,'".ENCODE_KEY."') AS account_number, order_payment_code FROM #__{sc}_order_payment WHERE order_id='".$order_id."'"; $dbaccount->query($q); $dbaccount->next_record(); $header = read_file( PAGEPATH."templates/wholesale/email_header_1.php"); $footer = read_file( PAGEPATH."templates/wholesale/email_footer_1.php"); $header_cell = "<html>".$header; $header_cell = str_replace( "{company}", $whdb1->f("company"), $header ); $header_cell = str_replace( "{title}", $whdb1->f("title"), $header_cell ); $header_cell = str_replace( "{first_name}", $whdb1->f("first_name"), $header_cell ); $header_cell = str_replace( "{last_name}", $whdb1->f("last_name"), $header_cell ); $header_cell = str_replace( "{address_1}", $whdb1->f("address_1"), $header_cell ); $header_cell = str_replace( "{address_2}", $whdb1->f("address_2"), $header_cell ); $header_cell = str_replace( "{city}", $whdb1->f("city"), $header_cell ); $header_cell = str_replace( "{state}", $whdb1->f("state"), $header_cell ); $header_cell = str_replace( "{zip}", $whdb1->f("zip"), $header_cell ); $header_cell = str_replace( "{country}", countryName($whdb1->f("country")), $header_cell ); $header_cell = str_replace( "{phone_1}", $whdb1->f("phone_1"), $header_cell ); $header_cell = str_replace( "{email}", $whdb1->f("user_email"), $header_cell ); $header_cell = str_replace( "{order_id}", $order_id, $header_cell ); $header_cell = str_replace( "{order_date}", date("d-M-Y g:i a", $whdb2->f("cdate")), $header_cell ); $header_cell = str_replace( "{cc_number}", substr($dbaccount->f("account_number"),-4), $header_cell ); $header_cell = str_replace( "{fax}", $whdb1->f("fax"), $header_cell ); $header_cell = str_replace( "{extra_field_1}", $whdb1->f("extra_field_1"), $header_cell ); $header_cell = str_replace( "{extra_field_2}", $whdb1->f("extra_field_2"), $header_cell ); $header_cell = str_replace( "{extra_field_3}", $whdb1->f("extra_field_3"), $header_cell ); $header_cell = str_replace( "{extra_field_4}", $whdb1->f("extra_field_4"), $header_cell ); $header_cell = str_replace( "{extra_field_5}", $whdb1->f("extra_field_5"), $header_cell ); // Shopper group details $header_cell = str_replace( "{shopper_group_name}", $whdbgroup->f("shopper_group_name"), $header_cell ); $header_cell = str_replace( "{shopper_group_desc}", $whdbgroup->f("shopper_group_desc"), $header_cell ); $header_cell = str_replace( "{shopper_group_discount}", $whdbgroup->f("shopper_group_discount"), $header_cell ); // Wholesaler details $whdb3 =& new ps_DB; $whq3 = "SELECT * FROM #__{sc}_wholesalers where id=".$whID; $whdb3->query($whq3); $whdb3->next_record(); $header_cell = str_replace( "{wh_name}", $whdb3->f("wh_name"), $header_cell ); $header_cell = str_replace( "{wh_contact_lastname}", $whdb3->f("wh_contact_lastname"), $header_cell ); $header_cell = str_replace( "{wh_contact_firstname}", $whdb3->f("wh_contact_firstname"), $header_cell ); $header_cell = str_replace( "{wh_contact_phone_1}", $whdb3->f("wh_contact_phone_1"), $header_cell ); $header_cell = str_replace( "{wh_contact_fax}", $whdb3->f("wh_contact_fax"), $header_cell ); $header_cell = str_replace( "{wh_contact_email}", $whdb3->f("wh_contact_email"), $header_cell ); $header_cell = str_replace( "{wh_address_1}", $whdb3->f("wh_address_1"), $header_cell ); $header_cell = str_replace( "{wh_address_2}", $whdb3->f("wh_address_2"), $header_cell ); $header_cell = str_replace( "{wh_city}", $whdb3->f("wh_city"), $header_cell ); $header_cell = str_replace( "{wh_state}", $whdb3->f("wh_state"), $header_cell ); $header_cell = str_replace( "{wh_zip}", $whdb3->f("wh_zip"), $header_cell ); $header_cell = str_replace( "{wh_terms_of_service}", $whdb3->f("wh_terms_of_service"), $header_cell ); $header_cell = str_replace( "{wh_url}", $whdb3->f("wh_url"), $header_cell ); $header_cell = str_replace( "{wh_freeshipping}", $whdb3->f("wh_freeshipping"), $header_cell ); $header_cell = str_replace( "{wh_discount}", $whdb3->f("wh_discount"), $header_cell ); $header_cell = str_replace( "{wh_email_for_orders}", $whdb3->f("wh_email_for_orders"), $header_cell ); $footer = str_replace( "{supply_price_total_nf}", number_format($supply_price_total,$decimal_places), $footer ); $footer = str_replace( "{supply_price_total}", $CURRENCY_DISPLAY->getFullValue($supply_price_total), $footer ); $footer = str_replace( "{supply_quantity_total}", $supply_quantity_total, $footer ); $footer = str_replace( "{gross_supply_price_total_nf}", number_format($gross_supply_price_total,$decimal_places), $footer ); $footer = str_replace( "{gross_supply_price_total}", $CURRENCY_DISPLAY->getFullValue($gross_supply_price_total), $footer ); $footer = str_replace( "{shipping_nf}", number_format($whdb2->f("order_shipping"),$decimal_places), $footer ); $footer = str_replace( "{shipping}", $CURRENCY_DISPLAY->getFullValue($whdb2->f("order_shipping")), $footer ); $footer = str_replace( "{customer_note}", $whdb2->f("customer_note"), $footer ); $footer = str_replace( "{payment_method}", paymentMethod($dbaccount->f("payment_method_id")), $footer ); // Net order total $order_total = $supply_price_total + $whdb2->f("order_shipping"); $footer = str_replace( "{order_total_nf}",number_format($order_total,$decimal_places), $footer ); $footer = str_replace( "{order_total}", $CURRENCY_DISPLAY->getFullValue($order_total), $footer ); // Gross order total $gross_order_total = $gross_supply_price_total + $whdb2->f("order_shipping"); $footer = str_replace( "{gross_order_total_nf}",number_format($gross_order_total,$decimal_places), $footer ); $footer = str_replace( "{gross_order_total}", $CURRENCY_DISPLAY->getFullValue($gross_order_total), $footer ); $mailtext = $header_cell; $mailtext .= $whMessage; $mailtext .= $footer; $whq1 = "SELECT wh_orders_email from #__{sc}_wholesalers where wholesaler_id=".$whID; $whdb1->query($whq1); $whdb1->next_record(); $result = vmMail($whfromemail, $whemailname, $whdb1->f("wh_orders_email"), $whemailsubject, $mailtext, true ); } function countryName($country) { $whdb =& new ps_DB; $q = "select country_name from #__{sc}_country where country_3_code = '".$country."'"; $whdb->query($q); $whdb->next_record(); return $whdb->f("country_name"); } function paymentMethod($id) { $whdb =& new ps_DB; $q = "select payment_method_name from #__{sc}_payment_method where payment_method_id = '".$id."'"; $whdb->query($q); $whdb->next_record(); return $whdb->f("payment_method_name"); } ?>
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

