0 ) { IF ( (strlen($_SESSION['VAT_No'])>8 AND $_SESSION['charge_VAT']=='N' AND $_SESSION['VAT_verify']=='Y') OR strlen($_COOKIE["lichref"])>5 ) { DEFINE('VAT_Prepaid','N'); DEFINE ('Business_Cust','Y'); $VAT_rate=0; $VAT_multiplier=1; $default_rate=sprintf("%.1f",$EU_VAT[$user_country]); DEFINE('Country_VAT',$default_rate); // this is just for information purposes/reference - but does come up in info messages. } ELSEIF ($EU_VAT[$user_country]>0) { $VAT_rate=sprintf("%.1f",$EU_VAT[$user_country]); $VAT_multiplier='1.'.$EU_VAT[$user_country]; $VAT_multiplier=sprintf("%.2f",$VAT_multiplier); DEFINE('VAT_Prepaid','Y'); // this denotes its NOT VAT for UK government, it's VAT prepaid for import VAT for courier. } ELSE { $VAT_rate='20.0'; $VAT_multiplier=1.20; DEFINE('VAT_Prepaid','N'); } } ELSE // UK VAT { IF (time()>1294099140) { $VAT_rate='20.0'; $VAT_multiplier=1.20; } ELSE { $VAT_rate='20.0'; $VAT_multiplier=1.20; } // leave in case VAT rates change at any point. } $timenow=time(); $date_now=date("j M Y", $timenow); $todaysdate=date("j M Y",$timenow); $phpver=substr(phpversion(),0,1); $year=date("Y",time()); // would be better to put all of these into a global array: eg $constants['oneday'] = 86400; and then just define global $constants; (MUCH TIDIER!) $oneday=86400; //seconds $oneweek=$oneday*7; $onemonth=$oneday*30; $oneyear=$oneday*365; $threemonths=$onemonth*3; $threemonthsago=$timenow-$threemonths; $sixmonths=$onemonth*6; $sixmonthsago=$timenow-$sixmonths; $threedays=$oneday*3; $tendays=$oneday*10; $onedayago=$timenow-$oneday; $threedaysago=$timenow-$threedays; $oneweekago=$timenow-$oneweek; $tendaysago=$timenow-$tendays; $onemonthago = $timenow-$onemonth; $oneyearago=$timenow-$oneyear; $dayofweek = date("l", time()); $day=date("D",time()); $month=date("M",time()); $daynumber=date("j",time()); $hour=date("H",time()); $mins=date("i",time()); $secs=date("s",time()); $date=date("j M y ",time()); $server=substr($_SERVER['HTTP_HOST'],4); $server_ip=$_SERVER['SERVER_ADDR']; $full_script=$_SERVER['SCRIPT_FILENAME']; $cookieurl=$server; //$http_address='http://'.$_SERVER['HTTP_HOST'].'/'; // there is more of this in /tools/library/common_data.inc.php $col_name=array('medium-grey'=>'#DADADA', 'red'=>'#FFA6A6', 'orange-red'=> '#FFB9A6', 'orange'=> '#FFCEA6', 'amber'=> '#FFDDA6', 'light-amber'=> '#FDF099', 'yellow'=> '#FEFD8E', 'lime-yellow'=> '#E9FC8F', 'lime-green'=> '#B6FD86', 'green'=> '#72FF8D', 'aquamarine'=> '#7FFAB9', 'turquoise'=> '#A1FFCB', 'cyan'=> '#93FFEB', 'pale-blue'=> '#A5E0FE', 'blue'=> '#8FAFFF', 'indigo'=> '#A59CFF', 'violet'=> '#BBA5FE','mauve'=> 'CBA5FE','dark-pink'=>'#E0A8FF','pink'=>'#F9A5FE','dark-grey'=>'#A9A9A9','light-grey'=>'#F0F0F0'); $colours_array=array('medium-grey'=>'medium-grey', 'red'=>'red', 'orange-red'=> 'orange-red', 'orange'=>'orange', 'amber'=>'amber', 'light-amber'=>'light-amber', 'yellow'=>'yellow', 'lime-yellow'=>'lime-yellow', 'lime-green'=>'lime-green', 'green'=>'green', 'aquamarine'=>'aquamarine', 'turquoise'=>'turquoise', 'cyan'=>'cyan', 'pale-blue'=>'pale-blue', 'blue'=>'blue', 'indigo'=>'indigo', 'violet'=>'violet','mauve'=>'mauve','dark-pink'=>'dark-pink','pink'=>'pink','dark-grey'=>'dark-grey','light-grey'=>'light-grey'); $colours=array($col_name['medium-grey'], $col_name['medium-grey'],$col_name['red'],$col_name['medium-grey'], $col_name['orange-red'],$col_name['medium-grey'], $col_name['orange'],$col_name['medium-grey'], $col_name['amber'],$col_name['medium-grey'], $col_name['light-amber'],$col_name['medium-grey'], $col_name['yellow'],$col_name['medium-grey'], $col_name['lime-yellow'],$col_name['medium-grey'], $col_name['lime-green'],$col_name['medium-grey'], $col_name['green'],$col_name['medium-grey'], $col_name['aquamarine'],$col_name['medium-grey'], $col_name['turquoise'],$col_name['medium-grey'], $col_name['cyan'],$col_name['medium-grey'], $col_name['pale-blue'],$col_name['medium-grey'], $col_name['blue'],$col_name['medium-grey'], $col_name['indigo'],$col_name['medium-grey'], $col_name['violet'], $col_name['medium-grey'], $col_name['mauve'],$col_name['medium-grey'], $col_name['dark-pink'],$col_name['medium-grey'], $col_name['pink'],$col_name['medium-grey'], $col_name['dark-grey'],$col_name['medium-grey'], ); ?>0 AND $height>0) { if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } $width = round($width * $percentage); $iwidth=$width; $height = round($height * $percentage); $iheight=$height; return "width='$width' height='$height' xa='$height' "; } } } class product { var $itemdata; var $server; var $poundmode; function readcatdata($prodid,$array='*') // read product info for $prodid and allocate to class array $itemdata { //construct mysql query if fields selected as an array. IF (is_array($array)) { foreach($array AS $key=>$item) { IF (strlen($fieldlist)>0) { $fieldlist.=","; } $fieldlist.="$item "; } } ELSE { $fieldlist=$array; } $strQ = "SELECT $fieldlist FROM `bluecat` WHERE `id` = '".filterSQL($prodid)."' LIMIT 0,1"; $Query = mysql_query($strQ); $this->itemdata = mysql_fetch_array($Query); } function readone($masthead) // quick fix to load manufacturer if we dont know it - better structure will make this obsolete { $strQ = "SELECT * FROM `bluecat` WHERE `masthead` = '".filterSQL($masthead)."' LIMIT 0,1"; $query = mysql_query($strQ); $this->itemdata = mysql_fetch_array($query); } function incr_visits($prodid) // basic hits counter { IF ($this->itemdata['id']!=$prodid) { $this->readcatdata($prodid); } $visits=$this->itemdata["visit"]; If ($visits<1) { $visits=1; } ELSE { $visits++; } $strU = "UPDATE bluecat SET visit='".$visits."' WHERE id='".filterSQL($prodid)."' "; $update = mysql_query($strU); } function get_cost($prodid,$qty4price=1) //get cost price for given qty { IF ($this->itemdata['id']!=$prodid) { $this->readcatdata($prodid); } $cost=$this->itemdata['cost']; //can use stored packet info. //this function doesnt do much right now, but in future it is intended it will be able to take account of stock bought at different prices, and calculate average cost price, and also take into consideration any bulk price deals we can get. return $cost; } function getpriceincvat($prodid) // make inc vat price from ex vat price - for specific product { global $VAT_multiplier; IF ($this->itemdata['id']!=$prodid) { $this->readcatdata($prodid); } $price=sprintf("%.2f",$this->itemdata['pr']*$VAT_multiplier); return $price; } function add_vat_to_price($price) // make inc vat price from ex vat price - NOT for specific product - takes any input value { global $VAT_multiplier; $price=sprintf("%.2f",$price*$VAT_multiplier); return $price; } function priceincvat($prodid) // get inc vat price, and include customisation messages - for specific product { global $tradestatus, $discrate, $qty4price, $poundmode, $VAT_multiplier; IF ($this->itemdata['id']!=$prodid) { $this->readcatdata($prodid); } $storepoundmode=$poundmode; IF ($poundmode!='VIEW') {$poundmode='NO'; } $incvat = '£'.sprintf("%.2f",$this->priceexvat($prodid)*$VAT_multiplier); IF ($tradestatus=="YES") { $incvat="".$_COOKIE["blueuser"]." PRICE:
".$incvat; } $poundmode=$storepoundmode; return $incvat; } function pricebreaknew2($prodid, $userid='anon') // shows price break table (logic unchanged; locals minified) { global $VAT_multiplier, $club_test, $require_price_auth, $debug, $zzzz; $mm = 1.1; // min margin multiplier $cost = $this->get_cost($prodid, 1); $it =& $this->itemdata; // alias for brevity if ($it['manufacturer']=='Eminence' || $it['manufacturer']=='Fane') { $mm = 1.01; } // membership / status flags $isJam = (($_SESSION['JAM_Member'] ?? '')=='YES'); $st = 0; if (($_SESSION["custstatus"] ?? '')=='PU' && $userid && $userid!='anon') { $st = 1; } if (($_SESSION["custstatus"] ?? '')=='TR' && $userid && $userid!='anon') { $st = 2; } if ($it['id'] != $prodid) { $this->readcatdata($prodid); $it =& $this->itemdata; } // init $p1s=$p1e=$p2s=$p2e=$p3s=$p3e=$p4s=''; $pb1=$pb2=$pb3=$pb4=''; $jb0=$jb1=$jb2=$jb3=''; /* break 1 */ if ($it['break1']>1 && $it['break1pr']<$it['pr'] && $it['break1pr']>0 && $it['break1pr']>($it['cost']*$mm)) { $p1s = 1; $p1e = $it['break1'] - 1; $pb1 = ($p1s==$p1e) ? $p1s : ($p1s."-".$p1e); $p2s = $it['break1']; $pb2 = $p2s."+"; if ($isJam) { $VAT_multiplier = (float)$VAT_multiplier; $c0 = (float)$this->get_club_price($prodid, 1, $userid, $cost, $it['pr'], $st); $c0i = sprintf('%.2f', $c0 * $VAT_multiplier); $jb0 = "  £".$c0i.""; $c1 = (float)$this->get_club_price($prodid, $it['break1'], $userid, $cost, $it['break1pr'], $st); $c1i = sprintf('%.2f', $c1 * $VAT_multiplier); $jb1 = "  £".$c1i.""; } } else { $p1e=$p2s=$pb1=$pb2=''; } /* break 2 */ if ($it['break2']>1 && $it['break2pr']<$it['pr'] && $it['break2pr']>0 && $it['break2pr']>($it['cost']*$mm)) { $p2e = $it['break2'] - 1; $p3s = $it['break2']; $pb2 = $p2s."-".$p2e; $pb3 = $p3s."+"; if ($isJam) { $c2 = (float)$this->get_club_price($prodid, $it['break2'], $userid, $cost, $it['break2pr'], $st); $c2i = sprintf('%.2f', $c2 * $VAT_multiplier); $jb2 = "  £".$c2i.""; } } else { $p2e=$p3s=$pb3=''; } /* break 3 */ if ($it['break3']>1 && $it['break3pr']<$it['pr'] && $it['break3pr']>0 && $it['break3pr']>($it['cost']*$mm)) { $p3e = $it['break3'] - 1; $p4s = $it['break3']; $pb3 = $p3s."-".$p3e; $pb4 = $p4s."+"; if ($isJam) { $c3 = (float)$this->get_club_price($prodid, $it['break3'], $userid, $cost, $it['break3pr'], $st); $c3i = sprintf('%.2f', $c3 * $VAT_multiplier); $jb3 = "  £".$c3i.""; } } else { $p3e=$p4s=$pb4=''; } // render (same as before, classes not inline styles) $out = ''; // render as flex (qty fixed width, wraps cleanly) $out = ''; if (strlen($pb1) > 0) { $out = "
"; if (strlen($pb2)>0 && $pb2>0 && $it['break1pr']<$it['pr']) { $out .= "
".$pb2."£".sprintf('%.2f',$it['break1pr']*$VAT_multiplier)." ea.
"; $zzzz = 2; } if (strlen($pb3)>0 && $pb3>0 && $it['break2pr']<$it['break1pr']) { $out .= "
".$pb3."£".sprintf('%.2f',$it['break2pr']*$VAT_multiplier)." ea.
"; $zzzz = 3; } if (strlen($pb4)>0 && $pb4>0 && $it['break3pr']<$it['break2pr']) { $out .= "
".$pb4."£".sprintf('%.2f',$it['break3pr']*$VAT_multiplier)." ea.
"; $zzzz = 4; } $out .= "
"; } return $out; } function check_price_breaks($prodid,$qty4price=1,$userid,$costprice,$sellprice,$status) //check price breaks for given qty // fetch prices { global $club_test,$debug,$require_price_auth; //$status to be used for jam club/ pro user/ trade status? $debug.=" B: $require_price_auth ".$_SESSION['JAM_approved'].""; IF ($_SESSION['JAM_approved']!='Y' AND $require_price_auth=='YES') // club pricing to be approved by staff before its visible { $hideclub=true; $club_price=false; $status=0; } ELSE { IF ($_SESSION['JAM_Member']=='YES') { $club_price=true; $status=0; } ELSE { $club_price=false; $status=0;} } //IF ($_SESSION['JAM_Member']=='YES' OR $club_test==true) { $club_price=true; } ELSE { $club_price=false; $status=0; } IF ($_SESSION["custstatus"]=='PU' AND strlen($userid)>0 AND $userid!='anon' ) { $status=1; // pro-user pricing? } //this also checks for prices too cheap, and wont display them. Ideally should notify us about cheap prices?.... BUT may need to be able to take account of special offer bulk prices. IF ($this->itemdata['id']!=$prodid) { $this->readcatdata($prodid); } IF ( $this->itemdata['break1']>1 AND $this->itemdata['break1pr']>0 AND $this->itemdata['break1pr']>($this->itemdata['cost']*1.1) AND $this->itemdata['break1pr']<$this->itemdata['pr'] AND $qty4price>=$this->itemdata['break1']) { $price = sprintf("%.2f",$this->itemdata['break1pr']); IF ($club_price==true ) { $clubprice=$this->get_club_price($prodid,$this->itemdata['break1'],$userid,$cost_price,($this->itemdata['break1pr']*$VAT_Multiplier), $status); $price = ($clubprice<$price) ? $clubprice : $price; } } IF ( $this->itemdata['break2']>1 AND $this->itemdata['break2pr']>0 AND $this->itemdata['break2pr']>($this->itemdata['cost']*1.1) AND $this->itemdata['break2pr']<$this->itemdata['break1pr'] AND $qty4price>=$this->itemdata['break2']) { $price = sprintf("%.2f",$this->itemdata['break2pr']); IF ($club_price==true ) { $clubprice=$this->get_club_price($prodid,$this->itemdata['break2'],$userid,$cost_price,($this->itemdata['break2pr']*$VAT_Multiplier), $status); $price = ($clubprice<$price) ? $clubprice : $price; } } IF ( $this->itemdata['break3']>1 AND $this->itemdata['break3pr']>0 AND $this->itemdata['break3pr']>($this->itemdata['cost']*1.1) AND $this->itemdata['break3pr']<$this->itemdata['break2pr'] AND $qty4price>=$this->itemdata['break3']) { $price = sprintf("%.2f",$this->itemdata['break3pr']); IF ($club_price==true ) { $clubprice=$this->get_club_price($prodid,$this->itemdata['break3'],$userid,$cost_price,($this->itemdata['break3pr']*$VAT_Multiplier), $status); $price = ($clubprice<$price) ? $clubprice : $price; } } //IF ($_COOKIE['staffuser']=='Toots') { ECHO __FILE__.' '.__LINE__.' '.$price.'
'; } return $price; } function calc_margin ($cost_price,$selling_price) // get profit margin as %age { $profitgross=$selling_price-$cost_price; IF ($selling_price>0) { $margingross=sprintf("%.2f",$profitgross/$selling_price*100); return $margingross; } } function sliding_scale($margin, $minmargin, $marginrange, $maxdisc, $pricetoadjust=0) // generate club price on sliding scale { IF ($pricetoadjust<0.01) { $pricetoadjust=$this->itemdata['pr']; } $discount_per_increment=$maxdisc/$marginrange; $no_increments=$margin-$minmargin; IF($no_increments<=0) { $no_increments=0; } IF($no_increments>=$marginrange) { $no_increments=$marginrange; } $totaldiscount=$discount_per_increment*$no_increments; $club_price=sprintf("%.2f",($pricetoadjust*(100-$totaldiscount)/100)); // wont work with qty breaks return $club_price; } function new_trade_discounts($prodid,$qty4price=1,$userid='anon',$cost_price,$selling_price) // trial pricing for multi-tier - start with eminence { global $bdebug, $trade_profile, $trade_control; if (is_array($trade_profile[$this->itemdata['manufacturer']])) // we already have customer profile loaded dont repeat mysql query { $rowF=$trade_profile[$this->itemdata['manufacturer']]; } else { $strF="SELECT * FROM `blueusers_trade` WHERE `uname` = '".filterSQL($userid)."' AND `brand` = '".filterSQL($this->itemdata['manufacturer'])."' AND LENGTH(`prod_group`)<1"; $queryF=mysql_query($strF); $rowF=mysql_fetch_array($queryF); // load up customers trade price profile $trade_profile[$this->itemdata['manufacturer']]=$rowF; } if (is_array($trade_control[$this->itemdata['manufacturer']])) // we will need to expand/improve for masthead sub categories { $rowQ=$trade_control[$this->itemdata['manufacturer']]; } else { $strQ="SELECT * FROM `bluetrade_control` WHERE name = '".filterSQL($this->itemdata['manufacturer'])."' AND masthead = '".filterSQL($this->itemdata['masthead'])."' "; $queryQ=mysql_query($strQ); // load up master profile. if (mysql_num_rows($queryQ)<1) /* no result use default*/ { $strQ="SELECT * FROM `bluetrade_control` WHERE name = '".filterSQL($this->itemdata['manufacturer'])."' AND masthead = 'default' "; $queryQ=mysql_query($strQ); } $rowQ=mysql_fetch_array($queryQ); // load system settings $trade_control[$this->itemdata['manufacturer']]=$rowQ; // default tier level is set by `level` in blueusers_trade -- there is a little 'conflict' with logic in certain cirumstances - but not too bad. } if ($rowF["basic_disc"]>0) // override/identify default tier { $trd[1]=$rowF["basic_disc"]; $tier1=$trd[1]+$rowF["extra_adjust"]; $trd['extra']=$rowF["extra_adjust"]; // basic disc already has settlement discounted. if ($tier1== $rowQ["trade_discount"]) { $default_level=1; } if ($tier1== $rowQ["trade2_discount"]) { $default_level=2; } if ($tier1== $rowQ["trade3_discount"]) { $default_level=3; } } if ($rowF["allow_bulk"]=='Y' AND $default_level<=2) { $new_level=$default_level+1; $tier2=$rowQ["trade".$new_level."_discount"]; $trd[2]=$tier2-$rowF["extra_adjust"]; } if ($rowF["allow_pallet"]=='Y' AND $default_level<=3) { $new_level=$new_level+1; $tier3=$rowQ["trade".$new_level."_discount"]; $trd[3]=$tier3-$rowF["extra_adjust"]; } return $trd; } //this is called from main price calculator to populate individual prices function get_club_price($prodid,$qty4price=1,$userid='anon',$cost_price,$selling_price, $level=0) // return club (or trade) prices. { global $VAT_multiplier, $minimum_profit_margin, $debug, $sdebug; global $hideclub, $club_test, $temp_margin, $timenow; global $require_price_auth; IF ($_SESSION['JAM_Member']=='YES' OR $club_test==true) { $club_price=true; } ELSE { $club_price=false; } $hideclub='0'; IF ($userid!='anon' AND $club_price==true) // logged in - calculate club/trade price based on 'rules' { $prefix='JC'; IF ($level==0) { $prefix='JC'; } IF ($level==1) { $prefix='PU'; } IF ($level==2) { $prefix='TR'; } $margin=$this->calc_margin($cost_price,$selling_price); $temp_margin=$margin; $trademargin=0; $valid_trade=false; IF ($level==2 AND $this->itemdata['trade_pr']>0) { $trademargin=$this->calc_margin($cost_price,$this->itemdata['trade_pr']); IF ($trademargin>5 ) { $valid_trade=true; } } IF ($valid_trade OR $level==1) { //$sdebug.=" $prefix $userid
"; IF ($level==1) { $club_price = sprintf("%.2f",$this->itemdata['pro_user_pr']); $set_club_price=$this->itemdata['pro_user_pr']; //$debug.=" $prefix $userid | "; } ELSEIF ($level==2) { $club_price = sprintf("%.2f",$this->itemdata['trade_pr']); } //check pricing tier $strF="SELECT * FROM `blueusers_trade` WHERE `uname` = '".filterSQL($userid)."' AND `brand` = '".filterSQL($this->itemdata['manufacturer'])."' AND `prod_group` = '".filterSQL($this->itemdata['masthead'])."' "; // eg. for JAM Systems Amps, TuffCab paint - where a mastheading applies. $queryF=mysql_query($strF); IF (mysql_num_rows($queryF)<1) { $strF="SELECT * FROM `blueusers_trade` WHERE `uname` = '".filterSQL($userid)."' AND `brand` = '".filterSQL($this->itemdata['manufacturer'])."' AND LENGTH(`prod_group`)<1"; $queryF=mysql_query($strF); } IF (mysql_num_rows($queryF)>0) { $r=$this->itemdata; $rowF=mysql_fetch_array($queryF); $tl=$rowF["level"]; if ($tl!='Z') { IF ($r['pro_user_pr']>0 AND $tl>=0) { $club_price = sprintf("%.2f",$r['pro_user_pr']); } IF ($r['trade_pr']>0 AND $tl>=1) { $club_price = sprintf("%.2f",$r['trade_pr']); } IF ($r['trade_bulk']>0 AND ( ($qty4price>=10 AND $tl==1) or $tl>=2) ) { $club_price = sprintf("%.2f",$r['trade_bulk']); } IF ($r['trade_export']>0 AND ( ($qty4price>=10 AND $tl=2) or $tl>=3) ) { $club_price = sprintf("%.2f",$r['trade_export']); } IF ($r['exp_preorder']>0 AND ( ($qty4price>=10 AND $tl>=3) or $tl>=3) ) { $club_price = sprintf("%.2f",$r['exp_preorder']); } } } ELSE { IF ($level==1) { $club_price = sprintf("%.2f",$this->itemdata['pro_user_pr']); $set_club_price=$this->itemdata['pro_user_pr']; } ELSEIF ($level==2) { $club_price = sprintf("%.2f",$this->itemdata['trade_pr']); } } //trade_bulk //trade_export // get new } ELSEIF ( ($level==0) AND $this->itemdata['jam_club_pr']>$this->itemdata['cost'] AND (is_null($this->itemdata['jam_club_pr_expires']) OR $this->itemdata['jam_club_pr_expires']>$timenow OR $this->itemdata['jam_club_pr_expires']==0 ) ) // club price over-ride from bluecat. { $set_club_price=$this->itemdata['jam_club_pr']; // check on effect of qty breaks $club_price=$this->itemdata['jam_club_pr']; } ELSEIF ( $level==1 AND $this->itemdata['pro_user_pr']>$this->itemdata['cost'] ) // pro user price over-ride from bluecat. { $set_club_price=$this->itemdata['pro_user_pr']; // check on effect of qty breaks $club_price=$this->itemdata['pro_user_pr']; } ELSE { $usethisprice=$this->itemdata['pr']; IF ($qty4price==1) // qty =1 { $usethisprice=$this->itemdata['pr']; } ELSE // show price breaks { $usebreak=0; //check price breaks... IF ($qty4price>=$this->itemdata['break1'] AND $this->itemdata['break1pr']>0 AND $this->itemdata['break1pr']<$usethisprice) { $usethisprice=$this->itemdata['break1pr']; IF ($level==1 OR $level==2) { $usebreak=1; } } IF ($qty4price>=$this->itemdata['break2'] AND $this->itemdata['break2pr']>0 AND $this->itemdata['break2pr']<$usethisprice) { $usethisprice=$this->itemdata['break2pr']; IF ($level==1 OR $level==2) { $usebreak=2; } } IF ($qty4price>=$this->itemdata['break3'] AND $this->itemdata['break3pr']>0 AND $this->itemdata['break3pr']<$usethisprice) { $usethisprice=$this->itemdata['break3pr']; IF ($level==1 OR $level==2) { $usebreak=3; } } //not sure if this will work with standard sliding scale? } // end show price breaks //check brand pricing $strZZ="SELECT * from `brand_discount` WHERE `manufacturer` = '".filterSQL($this->itemdata['manufacturer'])."' "; // this needs to be a global variable for this class which can be used in more than one function - going to do it the wrong way for now and do a duplicate $rowZZ=mysql_fetch_array(mysql_query($strZZ)); IF ($rowZZ["JC_authorise"]=='Y') { $require_price_auth='YES'; } ELSE { $require_price_auth='NO'; } IF (strlen($rowZZ[$prefix."_disc_type"])>0 AND $rowZZ[$prefix."_disc_type"]!="Z") { //$debug.=" $prefix = ".$rowZZ[$prefix."_disc_type"]." $usethisprice | "; IF($rowZZ[$prefix."_disc_type"]=="A") { $disc=$rowZZ[$prefix."_disc_var1"]; $club_price = sprintf("%.2f",$usethisprice*(100-$disc)/100); //min margin not in operation } ELSEIF($rowZZ[$prefix."_disc_type"]=="B") { $club_price=$this->sliding_scale($margin,$rowZZ[$prefix."_min_margin"],$rowZZ[$prefix."_disc_var2"],$rowZZ[$prefix."_disc_var1"],$usethisprice); } ELSEIF($rowZZ[$prefix."_disc_type"]=="C") // this should be %age margin; { $disc=$rowZZ[$prefix."_disc_var1"]; $adjustment=1/((100-$disc)/100); $club_price = sprintf("%.2f",$this->itemdata['cost']*$adjustment); } ELSEIF($rowZZ[$prefix."_disc_type"]=="D") // this should be match cheapest competitor { $disc=$rowZZ[$prefix."_disc_var1"]; $club_price = sprintf("%.2f",$usethisprice*(100-$disc)/100); } ELSEIF($rowZZ[$prefix."_disc_type"]=="E") // no discount { $club_price = sprintf("%.2f",$usethisprice); } ELSEIF($rowZZ[$prefix."_disc_type"]=="F") // trade price - disc off RRP { $disc=$rowZZ[$prefix."_disc_var1"]; $disc2=$rowZZ["QT_disc_var".$usebreak]; $club_price = sprintf("%.2f",$this->itemdata['rrp']*(100-$disc)/100); IF ($usebreak>0) { $club_price = sprintf("%.2f",$club_price*(100-$disc2)/100); } // calc break using disc params in brand_discount. } $debug.="$club_price"; } ELSE // default club pricing... { IF ($usethisprice<0.01) { $usethisprice=$this->itemdata['pr']; } $club_price=$this->sliding_scale($margin,20,8,5,$usethisprice); //start club discount at 20%, across range of 8%, allocating 5% in increments } } } ELSE { $club_price = sprintf("%.2f",$this->itemdata['pr']); //not logged in - so get no discount } return $club_price; } // THIS IS THE MAIN PRICE CALCULATOR - returns an array of prices . function calc_ex_vat_price($prodid,$qty4price,$userid='anon',$status='0') // need prodid, quantity and userid to calculate price { global $VAT_multiplier, $minimum_profit_margin, $cd_debug, $carton_min; IF ($this->itemdata['id']!=$prodid) { $this->readcatdata($prodid); } $price_array['itemcost'] = $this->get_cost($prodid,$qty4price); $price_array['standard'] = sprintf("%.2f",$this->itemdata['pr']); $price_array['specoffer'] = $this->get_special_offer($prodid,$qty4price); // images/formatting from separate function if required // gets all prices... then has to choose what to display. $price_array['club_price'] = $this->get_club_price($prodid,$qty4price,$userid,$price_array['itemcost'],$price_array['standard'],0); $price_array['pro_user'] = $this->get_club_price($prodid,$qty4price,$userid,$price_array['itemcost'],$price_array['standard'],1); $price_array['trade_price'] = $this->get_club_price($prodid,$qty4price,$userid,$price_array['itemcost'],$price_array['standard'],2); $word_array=array("1"=>"Unit Price: ", "2"=>"Bulk Price: ", "3"=>"Pallet Rate: "); if ($this->itemdata['manufacturer']=='Eminence') { $np=$this->new_trade_discounts($prodid,$qty4price,$userid,$price_array['itemcost'],$price_array['standard']); // create the array of different possible trade prices here? if ($np[1]>0) { $price_array["tr_info"]=" TRADE PRICING:
"; $price_array["trd_1"]=$np[1]; $price_array["trd_2"]=$np[2]; $price_array["trd_3"]=$np[3]; $price_array["trd_s"]=$np['extra']; for ($counter=1; $counter<=3; $counter++) { $td[$counter]=$np[$counter]+$np['extra']; $price_array["tpr_".$counter]=$price_array['standard']*((100-$td[$counter])/100); $price_array["tpr_".$counter]=sprintf("%.2f",$price_array["tpr_".$counter]); if ($np[$counter]>0) { $price_array["tr_info"].=""; } } $price_array["tr_info"].="
".$word_array[$counter]." £".$price_array["tpr_".$counter]."+VAT (-$td[$counter]%)
NEW TRADE PRICE STRUCTURE:
"; if ($np['extra']>0) { $price_array["tr_info"].=" Your trade discount includes ".$np['extra']."% for payment with your order. "; } if ($np[2]>0) { $price_array["tr_info"].=" Bulk rate for 10 pcs one product OR over £1000 of one brand. "; } if ($np[3]>0) { $price_array["tr_info"].=" Pallet Rate minimum order £2000 of mixed product on a pallet of one brand. "; } $price_array["tr_info"].="Please email sales office for assistance if required


"; } else { //$price_array["tr_info"]=''; } } if ($this->itemdata['manufacturer']=='P-Audio' AND $userid=='POWERAUDIO') // this is generated AFTER stockcontrol is run - add to basket button needs moving to a different place. { $np=$this->new_trade_discounts($prodid,$qty4price,$userid,$price_array['itemcost'],$price_array['standard']); IF ($_COOKIE["staffuser"]=='Andyz') { if ($this->itemdata['inner_carton']>0) // and higher price tier { $price_array["tr_info"]=" P-Audio trade pricing:
To get your special trade price, this item must be ordered in cartons.

Our system will allow you to order multiples of ".$this->itemdata['inner_carton']." pcs only

"; $carton_min=$this->itemdata['inner_carton']; } else { $carton_min=1; } } } $price_array['pricebreak'] = $this->check_price_breaks($prodid,$qty4price,$userid,$price_array['itemcost'],$price_array['standard'],$status); // gets price for given qty // $price_array['del_discount'] = // $price_array['club_del_discount'] = $this->prices=$price_array; return $price_array; // returns an array of prices, and allows calling script to decidedwhat to do? } function calc_del_discount($selling_price,$prodid,$qty4price,$userid='anon',$specialoffer) { global $debug, $club_test, $fixedpricedelivery, $delivery_debug, $sdebug; $this->readcatdata($prodid); IF ($_SESSION['JAM_Member']=='YES' OR $club_test==true) { $club_price=true; } ELSE { $club_price=false; } $adjfactor2=1; $maxdiscperitem=8; IF ($userid!='anon' AND $club_price==true) // logged in - calculate club price based on 'rules' { $discount_threshold=21; // threshold at which delivery discount begins to apply for Club Members } ELSE { $discount_threshold=21; // threshold at which delivery discount begins to apply for non Club Member } if ($this->itemdata['manufacturer']=='B & C') { $manf='BandC';} else { $manf=$this->itemdata['manufacturer'];} $strZZ="SELECT * from `brand_discount` WHERE `manufacturer` = '".$manf."' "; $query=mysql_query($strZZ); $row=mysql_fetch_array($query); // this is duplicated - see club_prices $prefix='DD'; IF ($row[$prefix."_disc_type"]=="J") { IF ($row[$prefix."_disc_var1"]=='N')// allow normal system discounts { $discount_threshold=24; $adjfactor2=1; } ELSEIF ($row[$prefix."_disc_var1"]=='Y' AND $club_price==true) { $discount_threshold=20; $adjfactor2=1; } ELSEIF ($row[$prefix."_disc_var1"]=='Y') // no discount { $discount_threshold=100; $maxdiscperitem=0.01; $adjfactor2=0.01; } } ELSEIF ($row[$prefix."_disc_type"]=="L") { $discount_threshold=100; $maxdiscperitem=0.01; $adjfactor2=0.01; } ELSEIF ($row[$prefix."_disc_type"]=="M") //fixed price delivery for any qty - calc as normal- then round to fixed price if within tolerance { $cd_debug=" type M "; $fixedpricedelivery=$row[$prefix."_max_disc"]; $maxdiscperitem=5; $adjfactor2=1; } ELSEIF ($row[$prefix."_disc_type"]=="K") // amend discount amount here: http://www.bluearan.co.uk/tools/catedit/discount_control_by_brand.php // type K is most common. { $cd_debug=" type K "; $discount_threshold=$row[$prefix."_disc_var2"]; IF (is_numeric($row[$prefix."_disc_var1"])) { $adjfactor2=sprintf("%.2f",$row[$prefix."_disc_var1"]/100); } IF ($club_price==true) { $discount_threshold=$row[$prefix."_disc_var2"]-4; IF (is_numeric($row[$prefix."_disc_var1"])) { $adjfactor2=sprintf("%.2f",1.03*$row[$prefix."_disc_var1"]/100); } } IF ($row[$prefix."_max_disc"]>0 AND $row[$prefix."_max_disc"]<20) { $maxdiscperitem=$row[$prefix."_max_disc"]; } else { $maxdiscperitem=20; } } IF (substr($this->itemdata['id'],0,3)=='GRD') // reduce discounts on graded stock { $discount_threshold=99; $maxdiscperitem=0.1; } $cost_price=$this->get_cost($prodid,$qty4price); IF (($cost_price>0) AND ($cost_price<$selling_price)) { $margin=$this->calc_margin($cost_price,$selling_price); IF ($discount_threshold==100) { $discount_threshold=$margin; } $allowable_disc=$margin-$discount_threshold; //$sdebug.="allowable: $allowable_disc %
"; $adjfactor=1; //default is allow 100% of discount IF ($selling_price<1) {$adjfactor=0.1;} // allow 10% for really small items ELSEIF ($selling_price<3) {$adjfactor=0.15;} ELSEIF ($selling_price<10) {$adjfactor=0.2;} ELSEIF ($selling_price<20) {$adjfactor=0.25;} ELSEIF ($selling_price<40) {$adjfactor=0.5;} ELSEIF ($selling_price<60) {$adjfactor=0.6;} ELSEIF ($selling_price<80) {$adjfactor=0.8;} ELSEIF ($selling_price<100) {$adjfactor=0.9;} ELSEIF ($selling_price>200) {$adjfactor=1.1;} ELSEIF ($selling_price>500) {$adjfactor=1.2;} ELSEIF ($selling_price>1000) {$adjfactor=1.3;} IF ($allowable_disc2<0) {$allowable_disc=0;} //no negatives!! // $adjfactor 3... country.. // DEFINE('Location','KNOWN'); DEFINE('Country',$user_country); if ((Location=='KNOWN' OR Location=='Inferred') AND Country!='United Kingdom') { $adjfactor3=2.5; //more discount for europe -- this should help with high ticket items where we make more profit } else { $adjfactor3=1; //less discount for UK } // country was in single quotes above, and broke this, giving more discount when not logged in and stuff. $allowable_disc2=$allowable_disc*$adjfactor*$adjfactor2*$adjfactor3; // adjustment factors for low value items //$sdebug.="allowable2: $allowable_disc2 % $adjfactor $adjfactor2 $adjfactor3
"; $per_item=($selling_price*$allowable_disc2)/100; // apply %age discount //$delivery_debug.=" 1: $per_item
allowable disc $allowable_disc
F1 $adjfactor
F2 $adjfactor2
F3 $adjfactor3
"; //$debugzz=" 1: $per_item $allowable_disc $adjfactor $adjfactor2 ".Country; //If ($_COOKIE["staffuser"]=='Andy') { echo $debugzz."
"; } IF ($specialoffer>0 AND $selling_price>0) { $offerdiscount=$selling_price-$specialoffer; IF ($offerdiscount>5) { $per_item=0; } //no carriage discount on deep discounted offers ELSEIF ($offerdiscount>2.5) { $per_item=$per_item*0.5; } ELSEIF ($offerdiscount>1) { $per_item=$per_item*0.99; } } //$sdebug.=" per item: $per_item
"; IF ($per_item<0) { $per_item=0; } IF ($per_item>$maxdiscperitem AND $maxdiscperitem>0) { $per_item=$maxdiscperitem; } $totaldisc=$per_item*$qty4price; } $dimensions = explode('|', $this->itemdata['packing_info']); //separate out the sizes unset($dimensions[3]); //ditch the volumetric weight IF (max($dimensions)>100) { $totaldisc = 0; } //find highest value in array and check if its greater than 1m and remove carriage discount IF ($this->itemdata['carr_disc']=='N') { $totaldisc = 0; } //$totaldisc = 0; //$sdebug.=" total disc: ".$totaldisc."
"; return $totaldisc; } FUNCTION calc_packing_surch($qty4price) { $packing_charge = $this->itemdata['packing']; $packing_charge += ($qty4price-1)*$this->itemdata['packing_per']; RETURN $packing_charge; } function get_special_offer($prodid,$qty4price=1) //retrieve special offer prices // used in blue_type_2_new.inc.php and calc_ex_vat_price above. { global $campaign_id; IF ($this->itemdata['id']!=$prodid) { $this->readcatdata($prodid); } $totstock=$this->itemdata["stock"]; $xoffer=$this->itemdata['offer']; IF (($xoffer=='A' OR $xoffer=='D' OR $xoffer=='B' OR $xoffer=='C10' OR $xoffer=='C15') AND ($totstock<=0 AND $this->itemdata["available"]!='PACK') ) //turn off warehouse clearance and stock requirent to 0 if all out of stock - was also swtiching it off on packs. { //reqstock Function is in includes simple_functions.php IF ($xoffer=='A') { change_reqstock(0, $this->itemdata['id'], (__FILE__), (__LINE__)); } // only set stock to zero if warehouse clearance //$strQQ="UPDATE `bluecat` SET `offer` = '0' WHERE `id` = '".filterSQL($this->itemdata['id'])."' "; $update = mysql_query($strQQ); } IF ($xoffer=='B' AND (($_SESSION['JAM_Member']=='YES' AND $_SESSION["custstatus"]!='PU' AND $_SESSION["custstatus"]!='TR') OR strlen($campaign_id)>1) ) //black friday deals only for Jam Club members OR mailshots { $offerprice=sprintf("%.2f",$this->itemdata['pr_special']); } ELSEIF ($xoffer=='C10' OR $xoffer=='C15' OR $xoffer=='Z' OR $xoffer=='Y' OR $xoffer=='X' OR $xoffer=='D' OR $xoffer=='1' OR ($xoffer=='A' AND ($this->itemdata['stock']>0 )) OR ($xoffer=='A' AND ($this->itemdata['available']=='PACK' )) ) //warehouse clearance offer only allowed if stock>0 { $offerprice=sprintf("%.2f",$this->itemdata['pr_special']); } ELSE { $offerprice=0; } $this->prices['specoffer']=$offerprice; $this->prices['standard']=$this->itemdata['pr']; $makecell=$this->special_offer_cell($prodid,$qty4price); // no longer makes a cell, just allocates data. $special_test_calc=$this->itemdata['pr_special']; IF ($special_test_calc < $this->itemdata['cost'] AND $this->itemdata['cost']>0 AND $special_test_calc>0) { IF ($offerprice>0) { //$strQ="UPDATE `bluecat` SET `offer` = '', `pr_special` = '' WHERE `id` = '".filterSQL($this->itemdata['id'])."' "; } ELSE { //$strQ="UPDATE `bluecat` SET `offer` = '' WHERE `id` = '".filterSQL($this->itemdata['id'])."' "; } if (strlen($strQ)>2) { $clear=mysql_query($strQ); } // this was triggering mysql errors. IF ($this->itemdata['visible']=='Y' AND $this->itemdata['visible']=='B') { $toemail="sales@bluearan.co.uk"; $fromemail="andy_kos@bluearan.co.uk"; $subject="PRICE FIX product_class.inc.php ".$this->itemdata['id']; $email=$this->itemdata['id']; $header1="From: ".$fromemail."\n"; $header1.="Mime-Version: 1.0\n"; $header1.="Content-type: text/html;charset=utf-8\n"; $mail_status=mail($toemail,$subject,$email,$header1); } } return $offerprice; } function special_offer_cell($prodid,$qty4price=1) { global $specialofferprice, $incvat2, $exvat2, $hotdealcell, $VAT_multiplier, $hotdealinfo, $staffuser, $hotdealtable_med; global $blackfriday, $cybermonday; $totstock=$this->itemdata['stock']; $hotdealcell=''; $hotdealinfo=''; $dealtext=''; IF ($this->prices['specoffer']>0 AND $this->prices['specoffer']<$this->prices['standard']) // special offer set so create appropriate cell { $pr_incvat=sprintf("%.2f",($this->prices['standard'])*$VAT_multiplier); $incvat2 =sprintf("%.2f",($this->prices['specoffer'])*$VAT_multiplier); // $incvatcells=$this->hot_number("£".$incvat2); // image version of the price! // hotnumber functipn archived. IF ($this->itemdata['offer']=='Y' OR $this->itemdata['offer']=='1') //hot deal. { $hotdealinfo='HOT DEAL'; } IF ($this->itemdata['offer']=='C10' AND $this->check_timed_offer_valid()) //crazy 10% { $hotdealinfo='CRAZY 10'; } IF ($this->itemdata['offer']=='C15' AND $this->check_timed_offer_valid()) //crazy 15% { $hotdealinfo='CRAZY 15'; } IF ($this->itemdata['offer']=='A' OR $this->itemdata['offer']=='D' ) //warehouse clearance { $hotdealinfo='CLEARANCE'; } IF ($this->itemdata['offer']=='X' AND $this->check_timed_offer_valid() ) //xmas // this tried to do a mysql query every time. { $hotdealinfo='XMAS'; } IF ($this->itemdata['offer']=='B' AND $this->check_timed_offer_valid()) // BLACK FRIDAY OR CYBER MONDAY { // check login status for JAM club membership. if (isset($_COOKIE["blueuser"]) AND $_COOKIE["blueuser"]!='anon') // only show black deals for those logged in // make this JAM club only once tidied up. { IF ($incvat2>0) { $hotdealinfo='BLACK FRIDAY'; } ELSE { $hotdealinfo=''; } } else { $hotdealinfo=''; } } IF ($this->itemdata['offer']=='DD' ) // B Stock -- not currently a thing. { $hotdealinfo='B STOCK'; } IF ($this->itemdata['offer']=='Z' ) // Price Match { $hotdealinfo='PRICE MATCH'; $dealtext='PRICE MATCH:
'; } $priceincv=sprintf("%.2f",($this->itemdata['pr'])*$VAT_multiplier); } } function check_timed_offer_valid() { global $black_finish, $cyber_finish, $xmas_end; IF ($this->itemdata['offer']=='B') { $msg="Black Friday / Cyber Monday Offer Finished: "; $end_date=$cyber_finish; $closedeal=true; $sendemail=true;} IF ($this->itemdata['offer']=='X') { $end_date=$xmas_end; //IF ($this->itemdata['id']=='PKNXD6000') { $end_date=time()-1; } //test product IF ($this->itemdata["manufacturer"]=='PKN') { $change_deal=true; $msg="Xmas Offer Updated: "; $sendemail=true;} // change to hot deal ELSEIF ($this->itemdata["manufacturer"]=='Fane') { $change_deal=true; $check_deal=true; $msg="Xmas Offer Changed: "; $sendemail=true;} ELSE { $closedeal=true; $msg="Xmas Special Offer Finished: "; $sendemail=true;} // just close the deal } IF ($this->itemdata['offer']=='C10' OR $this->itemdata['offer']=='C15') { $msg="Crazy Deal Offer Finished: "; $end_date=1616418000; $closedeal=true; $sendemail=false;} IF (time()>$end_date AND $end_date>0 AND $closedeal==true) //close special offer deals { $strQ="UPDATE bluecat SET offer='' WHERE id='".$this->itemdata['id']."' AND LENGTH(offer)>0"; $clear=mysql_query($strQ); if (mysql_affected_rows($clear)>0 AND $sendemail) { $toemail="sales@bluearan.co.uk"; $fromemail="andy_kos@bluearan.co.uk"; $subject="$msg ".$this->itemdata['id']; $email="$msg ".$this->itemdata['id']."
in File: ".str_replace("/var/www/bluearan/","",(__FILE__))." Line: ".(__LINE__); $header1="From: ".$fromemail."\n"; $header1.="Mime-Version: 1.0\n"; $header1.="Content-type: text/html;charset=utf-8\n"; $mail_status=mail($toemail,$subject,$email,$header1); $updated=true; } } IF (time()>$end_date AND $change_deal==true) //update special offer deals { $strQ="UPDATE bluecat SET offer='Y' WHERE id='".$this->itemdata['id']."' "; $clear=mysql_query($strQ); $toemail="sales@bluearan.co.uk"; $fromemail="andy_kos@bluearan.co.uk"; $subject="$msg ".$this->itemdata['id']; IF ($check_deal) { $extra_message=" NEW Special Offer price MUST be reviewed by a member of staff

"; } $email="$extra_message $msg ".$this->itemdata['id']."
in File: ".str_replace("/var/www/bluearan/","",(__FILE__))." Line: ".(__LINE__); $header1="From: ".$fromemail."\n"; $header1.="Mime-Version: 1.0\n"; $header1.="Content-type: text/html;charset=utf-8\n"; $mail_status=mail($toemail,$subject,$email,$header1); $updated=false; } IF ($updated) { return false; } ELSE { return true; } //prevent display of deal price. } function priceexvat($prodid) // original price function, included a lot of html for special offers, etc being replace by calc_ex_vat_price // this is still needed for now, but we should try to phase it out. { global $tradestatus, $discrate, $qty4price, $poundmode, $specialofferprice, $inbasket, $specoffercode, $specialreturn; global $offerinfo, $hotdealcell, $pricenorminsert, $passmode, $VAT_multiplier, $incvat2, $priceincv, $specialofferprice2; $hotdealcell=' '; IF (isset($_COOKIE["bluewebmaster"])) { $staff_deal_link=""; } ELSE {$staff_deal_link="";} $specialofferprice=''; IF ($poundmode=="NO" OR $poundmode=='VIEW') { $poundinsert=''; } ELSE { $poundinsert='£'; } IF ($this->itemdata['id']!=$prodid) { /* IF local class data doesnt match $prodid - load new local class data */ $this->readcatdata($prodid); } $exvat = $poundinsert.sprintf("%.2f",$this->itemdata['pr']); /* Check Price Break Price START */ IF ( $this->itemdata['break1']>1 AND $this->itemdata['break1pr']>0 AND $this->itemdata['break1pr']<$this->itemdata['pr'] AND $qty4price>=$this->itemdata['break1']) { $exvat = $poundinsert.sprintf("%.2f",$this->itemdata['break1pr']); } IF ( $this->itemdata['break2']>1 AND $this->itemdata['break2pr']>0 AND $this->itemdata['break2pr']<$this->itemdata['break1pr'] AND $qty4price>=$this->itemdata['break2']) { $exvat = $poundinsert.sprintf("%.2f",$this->itemdata['break2pr']); } IF ( $this->itemdata['break3']>1 AND $this->itemdata['break3pr']>0 AND $this->itemdata['break3pr']<$this->itemdata['break2pr'] AND $qty4price>=$this->itemdata['break3']) { $exvat = $poundinsert.sprintf("%.2f",$this->itemdata['break3pr']); } /* Check Price Break Price END */ $totstock=$this->itemdata["stock"]; /* Check SPecial Offer Prices */ IF (($this->itemdata['offer']=='A' OR $this->itemdata['offer']=='D') AND ($this->itemdata['stock']<1 OR $totstock==0 )) { //Test changes to reqstock 02 Jul 2014 Function is in includes simple_functions.php line 697 change_reqstock(0, $this->itemdata['id'], (__FILE__), (__LINE__)); //turn off warehouse clearance and stock requirent to 0 if all out of stock if ( $this->itemdata['available']!='PACK') //$strQQ="UPDATE bluecat SET offer='0', reqstock='0' WHERE id='".$this->itemdata['id']."'"; $update = mysql_query($strQQ); { $strQQ="UPDATE bluecat SET offer='0' WHERE id='".$this->itemdata['id']."' AND available!='PACK' "; $update = mysql_query($strQQ); } // this was resetting packs on special offers } IF ($this->itemdata['offer']=='Z' OR $this->itemdata['offer']=='Y' OR $this->itemdata['offer']=='X' OR $this->itemdata['offer']=='D' OR $this->itemdata['offer']=='1' OR ($this->itemdata['offer']=='A' AND $this->itemdata['stock']>0 ) OR ($this->itemdata['offer']=='A' AND $this->itemdata['available']=='PACK' ) ) { $exvat2 = $poundinsert.sprintf("%.2f",$this->itemdata['pr_special']); $incvat2 =$poundinsert.sprintf("%.2f",($this->itemdata['pr_special'])*$VAT_multiplier); IF ($exvat2<$exvat) { IF ($poundmode=='VIEW') { $specialofferprice=''; $priceincv=sprintf("%.2f",($this->itemdata['pr'])*$VAT_multiplier); } ELSE { $exvat = $poundinsert.sprintf("%.2f",$this->itemdata['pr_special']); } } ELSE { $specialofferprice=""; $hotdealcell=""; $pricenorminsert=""; } } return $exvat; } } /*______________________________________________________________________________________________________________________*/ require_once($script_path."includes/product_item_class.inc.php"); require_once($script_path."includes/product_item_list_class.inc.php"); require_once($script_path."includes/product_stock_class.inc.php"); ?>'.__FILE__.' '.__LINE__.' '.$postcode.' '.$location.' $ch '.$ch.'
'; } IF (strlen($postcode)>0 AND $location=='UK') { $debug.="
START DELIVERY FUNCTION UK: "; //$debug.="LOGGED IN WITH A UK POSTCODE"; $areacode=$Delivery->Get_Area($postcode); $areacodeinfo=$Delivery->Read_Postcode($areacode); IF ($areacodeinfo!='POSTCODE INVALID') { $locations=$Delivery->Get_company_zone(); $deltt=$UK_area; //$debug.="DELIVERY_FUNCTION.inc.php $delcountry $postcode $areacode | $areacodeinfo
loc: $deltt dpd: $dpdlocation anc: $anclocation city: $citylocation

"; IF ($deltt=='UK Channel Islands') { $delcountry=$deltt; } $delcost=delivery_cost($weight,$val); } ELSE { $deltt=$areacodeinfo; } //$debug.=" $delcountry $postcode $areacode | $areacodeinfo
loc: $deltt anc: $anclocation city: $citylocation

"; $delivery['airmail']=''; } ELSEIF ($location=='EU') { $debug.="
START DELIVERY FUNCTION EU: "; //$debug.="LOGGED IN - EU"; if ($parcel_override>0) { $set_parcels=$parcel_override; // parcel_override comes from basket_delivery.inc.php which gets number of parcels from parcel manager } else { $set_parcels=1; } IF (strlen($delcountry)>0) { $country=$delcountry; $deltt=$delcountry; } $costofdel=$Delivery->Delivery_cost_Europe($weight,$set_parcels,$country); $airmailcost=$Delivery->Royal_Mail_Airmail($weight, $country); $delivery['airmail']=$cost["airmail"]; } ELSE { $debug.="
Default Function: "; $anclocation="UK"; $deltt="Mainland UK "; $citylocation="UK"; $dpdlocation='UK'; $areacode="SO14"; $delcost=delivery_cost($weight,$val); $delivery['airmail']=''; } $cost["DPD"]["2-3_Day"][$dpdlocation] = ($cost["DPD"]["2-3_Day"][$dpdlocation]>1.5) ? $cost["DPD"]["2-3_Day"][$dpdlocation] : 0; $cost['post2ndRD'] = ($cost['post2ndRD']>0.84) ? $cost['post2ndRD'] : 0; $cost["post2ndSTD"] = ($cost["post2ndSTD"]>0.84) ? $cost["post2ndSTD"] : 0; IF ($delivery['2ndSTD']<$delivery['DPD'] AND ($weight<2000) AND $val<10 AND $allow_post==true) { $delexvat=$delivery['2ndSTD']; $cheapest_method = 'Royal Mail'; } ELSEIF ( ($delivery['2ndRD']<$delivery['DPD']) AND ($weight<1500) AND $allow_post==true) { $delexvat=$delivery['2ndRD']; $cheapest_method = 'Royal Mail'; } ELSE {$delexvat=$cost["DPD"]["2-3_Day"][$dpdlocation]; $cheapest_method = 'Courier'; } //$cost["DPD"]["2-3_Day"][$dpdlocation] = ($cost["DPD"]["2-3_Day"][$dpdlocation]>1.5) ? $cost["DPD"]["2-3_Day"][$dpdlocation] : 0; //$cost['post2ndRD'] = ($cost['post2ndRD']>0.84) ? $cost['post2ndRD'] : 0; //$cost["post2ndSTD"] = ($cost["post2ndSTD"]>0.84) ? $cost["post2ndSTD"] : 0; /* I moved above 3 lines higher up, as I wasnt getting free delivery under £1.50 for DPD */ //$debug.="ZZZZ $delivery[DPD] $delexvat ZZZZZ"; IF ($_COOKIE["staffuser"]=='Andy') { //echo ""; } $cheapest_delivery=($delexvat>0.84) ? $delexvat : 0; return $cheapest_delivery; } function delivery_cost($del_weight,$del_value) { // all these numerous variables could just be put into one array couldnt they? would be tidier? maybe? global $ch; global $ch2; global $sdebug; global $delivery_debug; global $bus1post72; global $bus1post24; global $post1amount; global $post2amount; global $post2stdamount; global $specdel; global $carriagediscount; global $packingsurcharge; global $debug; global $deliverydiscount; global $deltt, $VAT_multiplier; global $cost; global $delivery_cost_price; global $anclocation, $citylocation, $dpdlocation; global $Delivery, $delivery; global $fixedpricedelivery; global $parcel_override; $cartgrams=$del_weight; //if ($_COOKIE["staffuser"]=='Andy') { echo "W: $del_weight C: $cartgrams "; } $Delivery->Royal_Mail_UK($cartgrams); // $Delivery is the class $delivery is the array of delivery prices. $sdebug.="delivery_cost: carriagediscount: ".$carriagediscount."
"; $delivery['1stRD']=$cost["post1stRD"]; $delivery['2ndRD']=($cost["post2ndRD"]>0.84) ? $cost["post2ndRD"] : 0; // these should be determined in delivery class not here - otherwise we risk having 2 sets of rules depending on how delivery functions are invoked. $delivery['2ndSTD']=($cost["post2ndSTD"]>0.84) ? $cost["post2ndSTD"] : 0; $delivery['specdel']=$cost["postspecdel"]; $delivery['specdel9am']=$cost["postspecdel9am"]; $delivery['specdelsat']=$cost["postspecdel"]+2; $Delivery->Royal_Mail_Airmail($cartgrams); $delivery['airmail']=$cost["airmail"]; //IF ($_COOKIE['staffuser']=="Toots") { ECHO $del_value.'
'; ECHO print_r($cost); ECHO print_r($delivery);} //need to recreate $ch at this point to cater for new user_reg?? What on earth is $ch? It doesn't appear to be here. //IF ($_COOKIE['staffuser']=='Toots') {ECHO __FILE__.' '.__LINE__.' '.$ch.'
'; } IF (strlen($anclocation)<1) { SWITCH ($ch) { CASE "1" : $anclocation="UK"; $dpdlocation='UK'; $deltt="Mainland UK "; $areacode="SO14"; break; CASE "2" : $anclocation="SH"; $dpdlocation='SH'; $deltt="Scottish Highlands "; $areacode="IV22"; break; CASE "7" : $anclocation="SI"; $dpdlocation='SI'; $deltt="Scottish Islands "; $areacode="ZE3"; break; CASE "4" : $anclocation="NI"; $dpdlocation='NI'; $deltt="Northern Ireland "; $areacode="BT40"; break; CASE "5" : $anclocation="CI"; $dpdlocation='CI'; $deltt="Channel Islands "; $areacode="JE2"; break; CASE "8" : $anclocation="IW"; $dpdlocation='IW'; $deltt="Isle of Wight "; $areacode="PO33"; break; default: $anclocation="UK"; $dpdlocation='UK'; $deltt="Mainland UK "; $areacode="SO14"; //$debug.="USING DEFAULTS"; } } if ($parcel_override>0) { $set_parcels=$parcel_override; // parcel_override comes from basket_delivery.inc.php which gets number of parcels from parcel manager } else { $set_parcels=1; } // IF ($_COOKIE['staffuser']=='Toots') {ECHO __FILE__.' '.__LINE__.' '.$anclocation.' '.$dpdlocation.' '.$areacode.' '.$ch.'
'; } $costofdel=$Delivery->Delivery_cost_UK($cartgrams,$set_parcels,$areacode); IF ($dpdlocation=='NI') { $carriagediscount=0; } //Due to brexit costs, remove carriage discount from NI until further notice. $delivery_cost_price=$cost; $applyUKdiscount=$carriagediscount*0.95; // reduce UK discounts slightly - that was temporary need to compete now //$carriagediscount is calculated in includes/product_class.inc.php func calc_del_discount IF ($_SESSION['custstatus']!='TR') //no carriage discounts for trade { $cost["ANC"]["2-3_Day"][$anclocation]-=$applyUKdiscount; $cost["DPD"]["2-3_Day"][$dpdlocation]-=$applyUKdiscount; $cost["ANC"]["Next_Day"][$anclocation]-=($applyUKdiscount*0.5); $cost["DPD"]["Next_Day"][$dpdlocation]-=($applyUKdiscount*0.7); } ELSE { IF($cost["ANC"]["Next_Day"]['UK']>50) {$cost["ANC"]["Next_Day"]['UK']=50;} // max £35 same as a pallet. IF($cost["DPD"]["Next_Day"]['UK']>50) {$cost["DPD"]["Next_Day"]['UK']=50;} IF($cost["DPD"]["2-3_Day"]['UK']>50) {$cost["DPD"]["2-3_Day"]['UK']=50;} IF($cost["ANC"]["2-3_Day"]['UK']>50) {$cost["ANC"]["2-3_Day"]['UK']=50;} } $cost["ANC"]["2-3_Day"][$anclocation]+=$packingsurcharge; $cost["DPD"]["2-3_Day"][$dpdlocation]+=$packingsurcharge; $cost["ANC"]["Next_Day"][$anclocation]+=$packingsurcharge; $cost["DPD"]["Next_Day"][$dpdlocation]+=$packingsurcharge; IF($cost["ANC"]["Next_Day"][$anclocation]<0) {$cost["ANC"]["Next_Day"][$anclocation]=0;} IF($cost["DPD"]["Next_Day"][$dpdlocation]<0) {$cost["DPD"]["Next_Day"][$dpdlocation]=0;} IF($cost["DPD"]["2-3_Day"][$dpdlocation]<0) {$cost["DPD"]["2-3_Day"][$dpdlocation]=0;} IF($cost["ANC"]["2-3_Day"][$anclocation]<0) {$cost["ANC"]["2-3_Day"][$anclocation]=0;} $bus1post24=$cost["DPD"]["Next_Day"][$dpdlocation]; //$bluearansurcharge=0.025; //2.5% surcharge on min carriage? $bluearandeliverymultiplier= ($_SESSION['custstatus']!='TR') ? 1+$bluearansurcharge : 1; $ANC_cheap=$cost["ANC"]["2-3_Day"][$anclocation]*$bluearandeliverymultiplier; $DPD_cheap=$cost["DPD"]["2-3_Day"][$dpdlocation]*$bluearandeliverymultiplier; $bus1post72=($cost["DPD"]["2-3_Day"][$dpdlocation]*$bluearandeliverymultiplier)+$scartsurch; IF ($DPD_cheap<$bus1post72) { $bus1post72=$DPD_cheap; } $debug.="ANC CHEAP $ANC_cheap ".$cost["ANC"]["info"].""; $debug.="DPD CHEAP $DPD_cheap "; $delivery["actualcost"]=$actualcost=$bus1post72; $ancmin=7.78; $dpdmin=4.57; IF ($fixedpricedelivery>0) // (was applied to certain products, to not give any delivery discount { $newmin=sprintf("%.2f",$fixedpricedelivery/$VAT_multiplier); $cheapmin=sprintf("%.2f",($fixedpricedelivery)/$VAT_multiplier); IF ($newmin>$ancmin) { $ancmin=$newmin; } IF ($newmin>$dpdmin) { $dpdmin=$newmin; } IF ($bus1post72<$cheapmin ) {$bus1post72=$cheapmin;} $debug.="ZZZZ $cheapmin $bus1post72 ZZZZZ"; } $delivery["ANC"]=($cost["ANC"]["Next_Day"][$anclocation])+$scartsurch; if ($delivery["ANC"]<$ancmin) { $delivery["ANC"]=$ancmin; } $delivery["DPD"]=($cost["DPD"]["Next_Day"][$dpdlocation])+$scartsurch; IF ($deltt=='UK Channel Islands') {$delivery["DPD"]=($cost["DPD"]["2-3_Day"][$dpdlocation])+$scartsurch;} //force Channel islands to be 2-3 day $no_add_parcels = ($cartgrams>0) ? (ceil($cartgrams/27500))-1 : 0; //$delivery["DPDsat"]=12.50+(4.58*$no_add_parcels); //$delivery["DPDpre12"]=10+(5*$no_add_parcels); $delivery["DPDsat"] = $cost['DPDsat']; $delivery["DPDpre12"] = $cost["DPDpre12"]; if ($delivery["DPD"]<$dpdmin) { $delivery["DPD"]=$dpdmin; // $delivery is used in basket } IF($bus1post24<($mincarriage+1) ){$bus1post24=$mincarriage+1;} IF($bus1post72<2) {$bus1post72=0;} $debug.="---Cheapest Delivery: $cheapmin $bus1post72 ---"; $delivery['standard']=$bus1post72; //$debug.="delivery_function.inc.php Carriage Discount: $carriagediscount ".$cost["ANC"]["2-3_Day"][$anclocation]."
"; } ?>2) { IF (strlen($searchword[$counter])>3) { $keywords.=$searchword[$counter]; $reversekeys=$searchword[$counter]." ".$reversekeys; IF ($counter<$wordloop AND $counter>0) { $keywords.=" "; } } } $keywords=strip_tags($keywords); $keywords=str_replace('"',"",$keywords); return $keywords; } ?>