Annotation of /com_supacart/trunk/admin_files/classes/wholesaler.functions.php
Parent Directory
|
Revision Log
Revision 4 - (view) (download)
| 1 : | andphe | 4 | <?php |
| 2 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 3 : | /** | ||
| 4 : | * @package SupaCart | ||
| 5 : | * @subpackage classes | ||
| 6 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 7 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 8 : | * SupaCart is free software, originally derived from Virtuemart. This version may have been modified pursuant | ||
| 9 : | * to the GNU General Public License, and as distributed it includes or | ||
| 10 : | * is derivative of works licensed under the GNU General Public License or | ||
| 11 : | * other free or open source software licenses. | ||
| 12 : | * See /administrator/components/com_supacart/COPYRIGHT.php for copyright notices and details. | ||
| 13 : | * | ||
| 14 : | * http://www.supacart.com | ||
| 15 : | */ | ||
| 16 : | function whOrderEmail($order_id) { | ||
| 17 : | |||
| 18 : | $dbo = new ps_DB; | ||
| 19 : | $q = "SELECT vendor_id FROM #__{sc}_orders "; | ||
| 20 : | $q .= "WHERE order_id=$order_id"; | ||
| 21 : | $dbo->query($q); | ||
| 22 : | $dbo->next_record(); | ||
| 23 : | |||
| 24 : | $dbv = new ps_DB; | ||
| 25 : | $q = "SELECT vendor_name, contact_email, vendor_currency_display_style FROM #__{sc}_vendor "; | ||
| 26 : | $q .= "WHERE vendor_id=".$dbo->f("vendor_id"); | ||
| 27 : | $dbv->query($q); | ||
| 28 : | $dbv->next_record(); | ||
| 29 : | |||
| 30 : | $currency_display =& vendor_currency_display_style( $dbv->f("vendor_currency_display_style") ); | ||
| 31 : | |||
| 32 : | $whfromemail = $dbv->f("contact_email"); | ||
| 33 : | $whemailname = $dbv->f("vendor_name"); | ||
| 34 : | $whemailsubject = $dbv->f("vendor_name"); | ||
| 35 : | $decimal_places = $currency_display['nbdecimal']; | ||
| 36 : | |||
| 37 : | $template = read_file( PAGEPATH."templates/wholesale/email_detail_1.php"); | ||
| 38 : | |||
| 39 : | $whdb =& new ps_DB; | ||
| 40 : | |||
| 41 : | $db = new ps_DB; | ||
| 42 : | $db_wh = new ps_DB; | ||
| 43 : | global $CURRENCY_DISPLAY; | ||
| 44 : | |||
| 45 : | $whq = "SELECT | ||
| 46 : | #__{sc}_order_item.product_id, | ||
| 47 : | #__{sc}_order_item.user_info_id, | ||
| 48 : | #__{sc}_order_item.order_id, | ||
| 49 : | #__{sc}_order_item.order_item_sku, | ||
| 50 : | #__{sc}_order_item.order_item_name, | ||
| 51 : | #__{sc}_order_item.product_quantity, | ||
| 52 : | #__{sc}_order_item.product_item_price, | ||
| 53 : | #__{sc}_order_item.product_final_price, | ||
| 54 : | #__{sc}_order_item.product_attribute, | ||
| 55 : | #__{sc}_product.product_wh_id, | ||
| 56 : | #__{sc}_product.product_wh_use_wholesaler, | ||
| 57 : | #__{sc}_wholesalers.wh_active | ||
| 58 : | FROM #__{sc}_order_item LEFT JOIN #__{sc}_product ON #__{sc}_order_item.product_id = #__{sc}_product.product_id | ||
| 59 : | LEFT JOIN #__{sc}_wholesalers ON #__{sc}_product.product_wh_id = #__{sc}_wholesalers.wholesaler_id | ||
| 60 : | WHERE (((#__{sc}_order_item.order_id)=".$order_id.") AND ((#__{sc}_product.product_wh_use_wholesaler)=\"Y\") AND ((#__{sc}_wholesalers.wh_active)=\"Y\")) | ||
| 61 : | ORDER BY #__{sc}_product.product_wh_id"; | ||
| 62 : | |||
| 63 : | $whdb->query($whq); | ||
| 64 : | $whID = ''; | ||
| 65 : | |||
| 66 : | while ($whdb->next_record()) { | ||
| 67 : | |||
| 68 : | if ($whID == '') { | ||
| 69 : | $whID = $whdb->f("product_wh_id"); | ||
| 70 : | |||
| 71 : | $supply_price_total=0; | ||
| 72 : | $supply_quantity_total=0; | ||
| 73 : | $gross_supply_price_total = 0; | ||
| 74 : | $gross_supply_quantity_total=0; | ||
| 75 : | $q = "SELECT wh_discount FROM #__{sc}_wholesalers where wholesaler_id=".$whID; | ||
| 76 : | $db_wh->setQuery($q); $db_wh->query(); | ||
| 77 : | if ($db_wh->next_record()) $wh_discount = $db_wh->f("wh_discount"); | ||
| 78 : | } | ||
| 79 : | |||
| 80 : | if ($whID <> $whdb->f("product_wh_id")) { | ||
| 81 : | whEmailOrderToWholesaler($order_id, $whID, $whMessage, $whfromemail, $whemailname, $whemailsubject, $supply_price_total, $gross_supply_price_total, $supply_quantity_total, $decimal_places); | ||
| 82 : | $whID = $whdb->f("product_wh_id"); | ||
| 83 : | $whMessage = ''; | ||
| 84 : | |||
| 85 : | $supply_price_total=0; | ||
| 86 : | $supply_quantity_total=0; | ||
| 87 : | $gross_supply_price_total = 0; | ||
| 88 : | $gross_supply_quantity_total=0; | ||
| 89 : | $q = "SELECT wh_discount FROM #__{sc}_wholesalers where wholesaler_id=".$whID; | ||
| 90 : | $db_wh->setQuery($q); $db_wh->query(); | ||
| 91 : | if ($db_wh->next_record()) $wh_discount = $db_wh->f("wh_discount"); | ||
| 92 : | } | ||
| 93 : | |||
| 94 : | $product_cell = str_replace( "{product_sku}", $whdb->f("order_item_sku"), $template ); | ||
| 95 : | $product_cell = str_replace( "{product_name}", $whdb->f("order_item_name"), $product_cell ); | ||
| 96 : | $product_cell = str_replace( "{product_qty}", $whdb->f("product_quantity"), $product_cell ); | ||
| 97 : | $product_cell = str_replace( "{product_attribute}", $whdb->f("product_attribute"), $product_cell ); | ||
| 98 : | |||
| 99 : | $supply_quantity_total+=$whdb->f("product_quantity"); | ||
| 100 : | |||
| 101 : | // NET Price | ||
| 102 : | $product_price= $whdb->f("product_item_price")*(100-$wh_discount)/100; | ||
| 103 : | $product_price_total = $product_price*$whdb->f("product_quantity"); | ||
| 104 : | $supply_price_total += $product_price_total; | ||
| 105 : | $product_cell = str_replace( "{product_price_nf}",number_format($product_price,$decimal_places), $product_cell ); | ||
| 106 : | $product_cell = str_replace( "{product_price}", $CURRENCY_DISPLAY->getFullValue($product_price), $product_cell ); | ||
| 107 : | $product_cell = str_replace( "{product_price_total_nf}",number_format($product_price_total,$decimal_places), $product_cell ); | ||
| 108 : | $product_cell = str_replace( "{product_price_total}",$CURRENCY_DISPLAY->getFullValue($product_price_total), $product_cell ); | ||
| 109 : | |||
| 110 : | // Gross Price | ||
| 111 : | $gross_product_price= $whdb->f("product_final_price")*(100-$wh_discount)/100; | ||
| 112 : | $gross_product_price_total = $gross_product_price*$whdb->f("product_quantity"); | ||
| 113 : | $gross_supply_price_total += $gross_product_price_total; | ||
| 114 : | $product_cell = str_replace( "{gross_product_price_nf}",number_format($gross_product_price,$decimal_places), $product_cell ); | ||
| 115 : | $product_cell = str_replace( "{gross_product_price}", $CURRENCY_DISPLAY->getFullValue($gross_product_price), $product_cell ); | ||
| 116 : | $product_cell = str_replace( "{gross_product_price_total_nf}",number_format($gross_product_price_total,$decimal_places), $product_cell ); | ||
| 117 : | $product_cell = str_replace( "{gross_product_price_total}",$CURRENCY_DISPLAY->getFullValue($gross_product_price_total), $product_cell ); | ||
| 118 : | |||
| 119 : | if (!isset($whMessage)) { | ||
| 120 : | $whMessage = $product_cell; | ||
| 121 : | } else { | ||
| 122 : | $whMessage .= $product_cell; | ||
| 123 : | } | ||
| 124 : | } | ||
| 125 : | |||
| 126 : | if (!isset($whMessage)) $whMessage = ''; | ||
| 127 : | if ($whMessage <> '') { | ||
| 128 : | whEmailOrderToWholesaler($order_id, $whID, $whMessage, $whfromemail, $whemailname, $whemailsubject, $supply_price_total, $gross_supply_price_total, $supply_quantity_total, $decimal_places); | ||
| 129 : | } | ||
| 130 : | |||
| 131 : | } | ||
| 132 : | |||
| 133 : | function whEmailOrderToWholesaler($order_id, $whID, $whMessage, $whfromemail, $whemailname, $whemailsubject, $supply_price_total, $gross_supply_price_total, $supply_quantity_total, $decimal_places) { | ||
| 134 : | |||
| 135 : | require_once(CLASSPATH.'ps_checkout.php'); | ||
| 136 : | |||
| 137 : | global $CURRENCY_DISPLAY; | ||
| 138 : | $whdb1 =& new ps_DB; | ||
| 139 : | |||
| 140 : | $whq1 = "select * from #__{sc}_order_user_info where address_type = 'ST' and order_id =".$order_id; | ||
| 141 : | $whdb1->query($whq1); | ||
| 142 : | while ($whdb1->next_record()) { | ||
| 143 : | $num = 1; | ||
| 144 : | } | ||
| 145 : | |||
| 146 : | if (!isset($num)) $num = 0; | ||
| 147 : | |||
| 148 : | if ($num == 0) { | ||
| 149 : | $whq1 = "select * from #__{sc}_order_user_info where order_id =".$order_id; | ||
| 150 : | } else { | ||
| 151 : | $whq1 = "select * from #__{sc}_order_user_info where address_type = 'ST' and order_id =".$order_id; | ||
| 152 : | } | ||
| 153 : | |||
| 154 : | $whdb1->query($whq1); | ||
| 155 : | $whdb1->next_record(); | ||
| 156 : | |||
| 157 : | // pick up user group details | ||
| 158 : | $whdbvendorlink =& new ps_DB; | ||
| 159 : | $whvendorlink = "select * from #__{sc}_shopper_vendor_xref where user_id =".$whdb1->f("user_id"); | ||
| 160 : | $whdbvendorlink->query($whvendorlink); | ||
| 161 : | $whdbvendorlink->next_record(); | ||
| 162 : | |||
| 163 : | $whdbgroup =& new ps_DB; | ||
| 164 : | $whgroup = "select * from #__{sc}_shopper_group where shopper_group_id =".$whdbvendorlink->f("shopper_group_id"); | ||
| 165 : | $whdbgroup->query($whgroup); | ||
| 166 : | $whdbgroup->next_record(); | ||
| 167 : | |||
| 168 : | $whdb2 =& new ps_DB; | ||
| 169 : | $whq2 = "SELECT customer_note, cdate, order_shipping FROM #__{sc}_orders WHERE order_id=".$order_id; | ||
| 170 : | |||
| 171 : | $whdb2->query($whq2); | ||
| 172 : | |||
| 173 : | $dbaccount =& new ps_DB; | ||
| 174 : | $q = "SELECT payment_method_id, DECODE(order_payment_number,'".ENCODE_KEY."') | ||
| 175 : | AS account_number, order_payment_code FROM #__{sc}_order_payment | ||
| 176 : | WHERE order_id='".$order_id."'"; | ||
| 177 : | $dbaccount->query($q); | ||
| 178 : | $dbaccount->next_record(); | ||
| 179 : | |||
| 180 : | $header = read_file( PAGEPATH."templates/wholesale/email_header_1.php"); | ||
| 181 : | $footer = read_file( PAGEPATH."templates/wholesale/email_footer_1.php"); | ||
| 182 : | |||
| 183 : | $header_cell = "<html>".$header; | ||
| 184 : | $header_cell = str_replace( "{company}", $whdb1->f("company"), $header ); | ||
| 185 : | $header_cell = str_replace( "{title}", $whdb1->f("title"), $header_cell ); | ||
| 186 : | $header_cell = str_replace( "{first_name}", $whdb1->f("first_name"), $header_cell ); | ||
| 187 : | $header_cell = str_replace( "{last_name}", $whdb1->f("last_name"), $header_cell ); | ||
| 188 : | $header_cell = str_replace( "{address_1}", $whdb1->f("address_1"), $header_cell ); | ||
| 189 : | $header_cell = str_replace( "{address_2}", $whdb1->f("address_2"), $header_cell ); | ||
| 190 : | $header_cell = str_replace( "{city}", $whdb1->f("city"), $header_cell ); | ||
| 191 : | $header_cell = str_replace( "{state}", $whdb1->f("state"), $header_cell ); | ||
| 192 : | $header_cell = str_replace( "{zip}", $whdb1->f("zip"), $header_cell ); | ||
| 193 : | $header_cell = str_replace( "{country}", countryName($whdb1->f("country")), $header_cell ); | ||
| 194 : | $header_cell = str_replace( "{phone_1}", $whdb1->f("phone_1"), $header_cell ); | ||
| 195 : | $header_cell = str_replace( "{email}", $whdb1->f("user_email"), $header_cell ); | ||
| 196 : | $header_cell = str_replace( "{order_id}", $order_id, $header_cell ); | ||
| 197 : | $header_cell = str_replace( "{order_date}", date("d-M-Y g:i a", $whdb2->f("cdate")), $header_cell ); | ||
| 198 : | $header_cell = str_replace( "{cc_number}", substr($dbaccount->f("account_number"),-4), $header_cell ); | ||
| 199 : | $header_cell = str_replace( "{fax}", $whdb1->f("fax"), $header_cell ); | ||
| 200 : | $header_cell = str_replace( "{extra_field_1}", $whdb1->f("extra_field_1"), $header_cell ); | ||
| 201 : | $header_cell = str_replace( "{extra_field_2}", $whdb1->f("extra_field_2"), $header_cell ); | ||
| 202 : | $header_cell = str_replace( "{extra_field_3}", $whdb1->f("extra_field_3"), $header_cell ); | ||
| 203 : | $header_cell = str_replace( "{extra_field_4}", $whdb1->f("extra_field_4"), $header_cell ); | ||
| 204 : | $header_cell = str_replace( "{extra_field_5}", $whdb1->f("extra_field_5"), $header_cell ); | ||
| 205 : | |||
| 206 : | // Shopper group details | ||
| 207 : | $header_cell = str_replace( "{shopper_group_name}", $whdbgroup->f("shopper_group_name"), $header_cell ); | ||
| 208 : | $header_cell = str_replace( "{shopper_group_desc}", $whdbgroup->f("shopper_group_desc"), $header_cell ); | ||
| 209 : | $header_cell = str_replace( "{shopper_group_discount}", $whdbgroup->f("shopper_group_discount"), $header_cell ); | ||
| 210 : | |||
| 211 : | // Wholesaler details | ||
| 212 : | $whdb3 =& new ps_DB; | ||
| 213 : | $whq3 = "SELECT * FROM #__{sc}_wholesalers where id=".$whID; | ||
| 214 : | $whdb3->query($whq3); | ||
| 215 : | $whdb3->next_record(); | ||
| 216 : | $header_cell = str_replace( "{wh_name}", $whdb3->f("wh_name"), $header_cell ); | ||
| 217 : | $header_cell = str_replace( "{wh_contact_lastname}", $whdb3->f("wh_contact_lastname"), $header_cell ); | ||
| 218 : | $header_cell = str_replace( "{wh_contact_firstname}", $whdb3->f("wh_contact_firstname"), $header_cell ); | ||
| 219 : | $header_cell = str_replace( "{wh_contact_phone_1}", $whdb3->f("wh_contact_phone_1"), $header_cell ); | ||
| 220 : | $header_cell = str_replace( "{wh_contact_fax}", $whdb3->f("wh_contact_fax"), $header_cell ); | ||
| 221 : | $header_cell = str_replace( "{wh_contact_email}", $whdb3->f("wh_contact_email"), $header_cell ); | ||
| 222 : | $header_cell = str_replace( "{wh_address_1}", $whdb3->f("wh_address_1"), $header_cell ); | ||
| 223 : | $header_cell = str_replace( "{wh_address_2}", $whdb3->f("wh_address_2"), $header_cell ); | ||
| 224 : | $header_cell = str_replace( "{wh_city}", $whdb3->f("wh_city"), $header_cell ); | ||
| 225 : | $header_cell = str_replace( "{wh_state}", $whdb3->f("wh_state"), $header_cell ); | ||
| 226 : | $header_cell = str_replace( "{wh_zip}", $whdb3->f("wh_zip"), $header_cell ); | ||
| 227 : | $header_cell = str_replace( "{wh_terms_of_service}", $whdb3->f("wh_terms_of_service"), $header_cell ); | ||
| 228 : | $header_cell = str_replace( "{wh_url}", $whdb3->f("wh_url"), $header_cell ); | ||
| 229 : | $header_cell = str_replace( "{wh_freeshipping}", $whdb3->f("wh_freeshipping"), $header_cell ); | ||
| 230 : | $header_cell = str_replace( "{wh_discount}", $whdb3->f("wh_discount"), $header_cell ); | ||
| 231 : | $header_cell = str_replace( "{wh_email_for_orders}", $whdb3->f("wh_email_for_orders"), $header_cell ); | ||
| 232 : | |||
| 233 : | $footer = str_replace( "{supply_price_total_nf}", number_format($supply_price_total,$decimal_places), $footer ); | ||
| 234 : | $footer = str_replace( "{supply_price_total}", $CURRENCY_DISPLAY->getFullValue($supply_price_total), $footer ); | ||
| 235 : | $footer = str_replace( "{supply_quantity_total}", $supply_quantity_total, $footer ); | ||
| 236 : | $footer = str_replace( "{gross_supply_price_total_nf}", number_format($gross_supply_price_total,$decimal_places), $footer ); | ||
| 237 : | $footer = str_replace( "{gross_supply_price_total}", $CURRENCY_DISPLAY->getFullValue($gross_supply_price_total), $footer ); | ||
| 238 : | $footer = str_replace( "{shipping_nf}", number_format($whdb2->f("order_shipping"),$decimal_places), $footer ); | ||
| 239 : | $footer = str_replace( "{shipping}", $CURRENCY_DISPLAY->getFullValue($whdb2->f("order_shipping")), $footer ); | ||
| 240 : | $footer = str_replace( "{customer_note}", $whdb2->f("customer_note"), $footer ); | ||
| 241 : | |||
| 242 : | $footer = str_replace( "{payment_method}", paymentMethod($dbaccount->f("payment_method_id")), $footer ); | ||
| 243 : | |||
| 244 : | // Net order total | ||
| 245 : | $order_total = $supply_price_total + $whdb2->f("order_shipping"); | ||
| 246 : | $footer = str_replace( "{order_total_nf}",number_format($order_total,$decimal_places), $footer ); | ||
| 247 : | $footer = str_replace( "{order_total}", $CURRENCY_DISPLAY->getFullValue($order_total), $footer ); | ||
| 248 : | |||
| 249 : | // Gross order total | ||
| 250 : | $gross_order_total = $gross_supply_price_total + $whdb2->f("order_shipping"); | ||
| 251 : | $footer = str_replace( "{gross_order_total_nf}",number_format($gross_order_total,$decimal_places), $footer ); | ||
| 252 : | $footer = str_replace( "{gross_order_total}", $CURRENCY_DISPLAY->getFullValue($gross_order_total), $footer ); | ||
| 253 : | |||
| 254 : | $mailtext = $header_cell; | ||
| 255 : | $mailtext .= $whMessage; | ||
| 256 : | $mailtext .= $footer; | ||
| 257 : | |||
| 258 : | $whq1 = "SELECT wh_orders_email from #__{sc}_wholesalers where wholesaler_id=".$whID; | ||
| 259 : | |||
| 260 : | $whdb1->query($whq1); | ||
| 261 : | |||
| 262 : | $whdb1->next_record(); | ||
| 263 : | |||
| 264 : | $result = vmMail($whfromemail, $whemailname, $whdb1->f("wh_orders_email"), $whemailsubject, $mailtext, true ); | ||
| 265 : | |||
| 266 : | } | ||
| 267 : | |||
| 268 : | function countryName($country) { | ||
| 269 : | |||
| 270 : | $whdb =& new ps_DB; | ||
| 271 : | |||
| 272 : | $q = "select country_name from #__{sc}_country where country_3_code = '".$country."'"; | ||
| 273 : | |||
| 274 : | $whdb->query($q); | ||
| 275 : | $whdb->next_record(); | ||
| 276 : | |||
| 277 : | return $whdb->f("country_name"); | ||
| 278 : | |||
| 279 : | } | ||
| 280 : | |||
| 281 : | function paymentMethod($id) { | ||
| 282 : | |||
| 283 : | $whdb =& new ps_DB; | ||
| 284 : | |||
| 285 : | $q = "select payment_method_name from #__{sc}_payment_method where payment_method_id = '".$id."'"; | ||
| 286 : | |||
| 287 : | $whdb->query($q); | ||
| 288 : | $whdb->next_record(); | ||
| 289 : | |||
| 290 : | return $whdb->f("payment_method_name"); | ||
| 291 : | |||
| 292 : | } | ||
| 293 : | |||
| 294 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

