include_once("function_mobile_detect.php");
$mobile_device = isMobileDevice();
if($mobile_device)
{
header("Location: view_all_stock_mobile.php?type=".$type);
die();
}
include("config.php");
if ( $_SESSION['ZAAUID'] == 0 )
{
$_SESSION['ZAAUID'] = 0;
include("header.php");
}
else
include "header_login.php";
$mobile_device = isMobileDevice();
include("function_stock_price.php");
include("function_stock_panels.php");
include("scripts_stock_panels.php");
if($_REQUEST['cartype'])
$bodytype = $_REQUEST['cartype'];
if($_REQUEST['listview'])
$LISTVIEW = $_REQUEST['listview'];
if(!$LISTVIEW)
$LISTVIEW = 1;
$price_color_list['Original'] = '#9D9C9D;text-decoration: line-through;';
$price_color_list['Discounted'] = '#0099F4;';
$price_color_list['50%'] = '#009148;';
$price_color_list['100%'] = '#0060B9;';
$q = "SELECT payment_discount , payment_departure_days,refrence_exr_calc FROM misc_setting ";
$r = pg_query($q);
$row = pg_fetch_array($r);
$payment_discount = json_decode($row['payment_discount'] , true);
$payment_departure_days = $row['payment_departure_days']?:0;
$refrence_exr_calc = $row['refrence_exr_calc']?:0;
$dis_options = array();
$dis_options['payment_departure_days'] = $payment_departure_days;
$dis_options['payment_discount'] = $payment_discount;
$dis_options['refrence_exr_calc'] = $refrence_exr_calc;
$q = "SELECT cpfixedamountup FROM countryport WHERE cpcountry = '$ZAACOUNTRY' ";
$r = pg_query($q);
$row = pg_fetch_array($r);
$misc_options['cpfixedamountup'] = $row['cpfixedamountup'];
$sSQL = " SELECT * FROM exrate_prefrence WHERE exrate_country = 'JAMAICA' ";
$result = pg_query($db,$sSQL);
$line_ex_pref = pg_fetch_array($result, null, PGSQL_ASSOC);
$exrate_slabs_jm = json_decode($line_ex_pref['exrate_slabs'] , true);
$sSQL = " SELECT * FROM exrate_prefrence WHERE exrate_country = '$ZAACOUNTRY' ";
$result = pg_query($db,$sSQL);
if(pg_num_rows($result) == 0)
{
$sSQL = " SELECT * FROM exrate_prefrence WHERE exrate_country = 'Global' ";
$result = pg_query($db,$sSQL);
}
$line_ex_pref = pg_fetch_array($result, null, PGSQL_ASSOC);
$exrate_slabs = json_decode($line_ex_pref['exrate_slabs'] , true);
/*
$ex_query = " SELECT * from exrate WHERE exdate <= NOW() ORDER by exdate desc LIMIT 1 ";
$result = pg_query($db,$ex_query);
$line_exr = pg_fetch_array($result, null, PGSQL_ASSOC);
*/
$exr_list = getExrList();
$q = "SELECT userid, auctionsheet ,realmilage_place, realaucpoints_place, auctionsheet_place , priceuptype, priceup,priceup_slabs,stk_liner,port,country,
bidding_per , gct_per , auction_per,roadtax_per, freight_per,ff_per, recycle_per,
storage_per, thc_per,blfee_per,radiation_per,custom_label1,custom_charges1,
trans_per1 ,trans_per2 , misc_per1 ,misc_per2 , misc_per3 ,
custom_label2,custom_charges2,custom_label3 , custom_charges3 , eff_special_price , trans_setting ,
bidding_price_1 , bidding_price_2 ,bidding_price_3, bidding_price_4 , bidding_price_5,
fixed_price_1 , fixed_price_2, fixed_price_3, fixed_price_4, fixed_price_5,
bidding_per_1 , bidding_per_2, bidding_per_3, bidding_per_4, bidding_per_5,
bidding_m3_1 , bidding_m3_2, bidding_m3_3, bidding_m3_4, bidding_m3_5,
bidding_trans_1 , bidding_trans_2, bidding_trans_3, bidding_trans_4, bidding_trans_5 ,
hand_charges1,hand_charges2,hand_charges3,hand_charges4,hand_charges5,hand_charges6,hand_charges7 , show_stock_no , hide_discount_price
FROM customer WHERE userid = ".$_SESSION['ZAAUID'];
$result = pg_query($db,$q);
$line_customer = pg_fetch_array($result, null, PGSQL_ASSOC);
$cus_sel_liner = json_decode($line_customer['stk_liner'] , true);
$show_stock_no = $line_customer['show_stock_no'];
foreach($cus_sel_liner as $buy_country => $liner)
{
$qfr = "SELECT * FROM stk_freight WHERE buy_country = '".$buy_country."'
AND liner = '".$liner."' AND ship_country = '".$line_customer['country']."'
AND ship_port = '".$line_customer['port']."' ";
$result = pg_query($db, $qfr ) or die(pg_last_error());
$row = pg_fetch_array($result);
$freight_list[$buy_country] = $row;
}
if($_POST['apply_filter'])
{
$_SESSION['vash_filters'] = $_POST;
}
if($_REQUEST['rem_session'])
{
$carmaker = $_SESSION['vash_filters']['carmaker'];
$carname = $_SESSION['vash_filters']['carname'];
$global_search = $_SESSION['vash_filters']['global_search'];
$nensikiy1 = $_SESSION['vash_filters']['nensikiy1'];
$nensikim1 = $_SESSION['vash_filters']['nensikim1'];
$nensikiy2 = $_SESSION['vash_filters']['nensikiy2'];
$nensikim2 = $_SESSION['vash_filters']['nensikim2'];
$place = $_SESSION['vash_filters']['place'];
$stockno = $_SESSION['vash_filters']['stockno'];
$stockno2 = $_SESSION['vash_filters']['stockno2'];
$mileage1 = $_SESSION['vash_filters']['mileage1'];
$mileage2 = $_SESSION['vash_filters']['mileage2'];
$transmission = $_SESSION['vash_filters']['transmission'];
$color = $_SESSION['vash_filters']['color'];
$cc_from = $_SESSION['vash_filters']['cc_from'];
$cc_to = $_SESSION['vash_filters']['cc_to'];
$price_from = str_replace(',','',$_SESSION['vash_filters']['price_from']);
$price_to = str_replace(',','',$_SESSION['vash_filters']['price_to']);
$carfuel = $_SESSION['vash_filters']['carfuel'];
$drivetype = $_SESSION['vash_filters']['drivetype'];
$drivetype2 = $_SESSION['vash_filters']['drivetype2'];
$discount_tag = $_SESSION['vash_filters']['discount_tag'];
$bodytype = $_SESSION['vash_filters']['bodytype'];
$stype = $_SESSION['vash_filters']['stype'];
$currency = $_SESSION['vash_filters']['currency'];
$sort1 = $_SESSION['vash_filters']['sort1'];
$sort2 = $_SESSION['vash_filters']['sort2'];
}
if(!$currency)
$currency = 'usd';
$price_curr = 'rate'.$currency;
?>
if($_SESSION['ipcountry'] == 'JAPAN')
$supercar_sql = " AND coalesce(show_japan,'') = '1' ";
/*
elseif($_SESSION['ipcountry'] == 'UNITED ARAB EMIRATES')
$supercar_sql = " AND coalesce(country,'') != 'UNITED ARAB EMIRATES' AND place1 != 'FA' AND coalesce(exotic_super,'') != '1' ";
*/
else
$supercar_sql = "";
$pictures = 1;
$gif = 0;
if($type == 'new')
{
$title = 'New Arrival';
$class = 'midtwo';
$class2 = 'actmstwo';
$title_color = '#5EB6EF';
}
elseif($type == 'discount')
{
$title = 'Discounted';
$class = 'midsix';
$class2 = 'actmssix';
$title_color = '#B2D411';
}
elseif($type == 'offerable')
{
$title = 'Offerable Stock';
$class = 'midseven';
$class2 = 'actmsseven';
$title_color = '#D68755';
}
elseif($type == 'super')
{
$title = 'Exotic & Supercars';
$class = 'suppercarh';
$class2 = 'actms';
$gif = 0;
$title_color = '#F14D4D';
}
elseif($type == 'brand_new')
{
$title = 'Brand New';
$class = 'midthree';
$class2 = 'actmsthree';
$title_color = '#8D55E8';
}
elseif($type == 'machinery')
{
$title = 'Machinery & Others';
$class = 'midfive';
$class2 = 'actmsfive';
$title_color = '#ECAF38';
}
elseif($type == 'dutytrucks')
{
$title = 'Light & Heavy Duty Trucks';
$class = 'midfour';
$class2 = 'actmsfour';
$title_color = '#EA48AE';
}
elseif($type == 'special_offer')
{
$title = 'Special Offer';
$class = 'mideight';
$class2 = 'actms';
$gif = 0;
$title_color = '#d10f0f';
}
elseif($type == 'executive')
{
$title = 'Executive Class';
$class = 'midten';
$class2 = 'actms';
$gif = 0;
$title_color = '#8c5903';
}elseif($type == 'exotics')
{
$title = 'Exotic Class';
$class = 'midten';
$class2 = 'actms';
$gif = 0;
$title_color = '#8c5903';
}
elseif($type == 'easter')
{
$title = 'Easter Offer';
$class = 'mideight';
$class2 = 'actms';
$gif = 0;
$title_color = '#d10f0f';
}
elseif($type == 'christmas')
{
$title = 'Christmas Offer';
$class = 'mideight';
$class2 = 'actms';
$gif = 0;
$title_color = '#d10f0f';
}
elseif($type == 'lhd')
{
$title = 'Left Hand Drive';
$class = 'midtwelve';
$class2 = 'actms';
$gif = 0;
$title_color = '#ff6600';
}
elseif($type == 'commercial')
{
$title = 'Commercial Vehicles';
$class = 'mideleven';
$class2 = 'actms';
$gif = 0;
$title_color = '#bd9e69';
}
elseif($type == 'accidental')
{
$title = 'Accidental Vehicles';
$class = 'midthirteen';
$class2 = 'actms';
$gif = 0;
$title_color = '#bd9e69';
}
elseif($type == 'motorcycle')
{
$title = 'Motorcycles';
$class = 'midthirteen';
$class2 = 'actms';
$gif = 0;
$title_color = '#bd9e69';
}
elseif($type == 'kfz')
{
$title = 'Kingston Free Zone Stock';
$class = 'midthirteen';
$class2 = 'actms';
$gif = 0;
$title_color = '#bd9e69';
}
else
{
$title = 'Stock List';
$class = 'mideleven';
$class2 = 'actmstk';
$title_color = '#bd9e69';
}
$whereSQL = " AND rno < $partsstart ";
if($type != 'executive' && $type != 'machinery' && $type != 'motorcycle' && $type != 'super' && $type != 'exotics')
$whereSQL .= " AND (tenderstock.deletedate IS NULL or tenderstock.eff_deletedate > current_date OR coalesce(exotic_super,'') = '1' ) "; //AND (buytype != 'JAPAN' OR (buytype = 'JAPAN' AND coalesce(customer.country , 'JAPAN') NOT IN ('UNITED ARAB EMIRATES')))
if($type == 'new')
$whereSQL .= " AND ( tenderstock.buydate > '".date("Y-m-d" , strtotime("-120 days"))."') ";
if($type == 'discount')
$whereSQL .= " AND hotsw=1 ";
if($type == 'offerable')
$whereSQL .= " AND oasw=1 ";
if($type == 'super')
$whereSQL .= " AND rno > 71000 AND coalesce(exotic_super,'') = '1' ";
if($type == 'exotics')
$whereSQL .= " AND ( coalesce(exotic_super,'') = '1' OR ivuserid IN ( 30132 ) )";
if($type == 'brand_new')
$whereSQL .= " AND cartype = 'Brand New' ";
if($type == 'machinery')
$whereSQL .= " AND bodytype = '28' ";
if($type == 'dutytrucks')
$whereSQL .= " AND bodytype IN ('7' , '17' , '4', '3' ,'19', '20', '9' , '30', '31', '32', '33') ";
if($type == 'special_offer')
$whereSQL .= " AND (place1 = 'AU' or special_offer = '1' ) ";
/*
if($type == 'executive')
$whereSQL .= " AND executive_class = '1' "; //AND bodytype IN ('1' , '8') AND biddingprice > 2000000
*/
if($type == 'easter')
$whereSQL .= " AND (( tenderstock.discount_tag = 'Easter Sale' AND (tenderstock.deletedate IS NULL or tenderstock.eff_deletedate > current_date ) )) ";
if($type == 'christmas')
$whereSQL .= " AND (( tenderstock.discount_tag = 'Christmas Sale' AND (tenderstock.deletedate IS NULL or tenderstock.eff_deletedate > current_date ) )) ";
if($type == 'executive')
$whereSQL .= " AND (show_fake_stock = '1' OR (executive_class = '1' AND (tenderstock.deletedate IS NULL or tenderstock.eff_deletedate > current_date ) )) ";
if($type == 'motorcycle')
$whereSQL .= " AND bodytype IN ('6') ";
if($type == 'commercial')
$whereSQL .= " AND bodytype IN ('2' , '15' , '24') ";
if($type == 'lhd')
$whereSQL .= " AND drivetype = 'left' ";
if($type == 'accidental')
$whereSQL .= " AND accidentsw= '1' ";
elseif($type == 'kfz')
$whereSQL .= " AND tenderinvoice.ivuserid = 27153 AND tenderstock.deletedate is null ";
if(strpos(strtoupper($global_search) , 'ORDER') !== FALSE)
$whereSQL .= " AND ivorderdate is not null ";
elseif($global_search)
$whereSQL .= " AND upper(tenderstock.carmaker || tenderstock.carname || coalesce(bodytype,0) || coalesce(chassis,'') || nensikiy || tenderstock.color || coalesce(carmodel,'') || place1 || '-' || rno) LIKE '%".strtoupper($global_search)."%' ";
if(countphp($carmaker) > 0)
$whereSQL .= " AND carmaker IN ('".implode("','" , $carmaker)."')";
if(countphp($carname) > 0)
$whereSQL .= " AND carname IN ('".implode("','" , $carname)."')";
if(countphp($carcode) > 0)
$whereSQL .= " AND katasiki IN ('".implode("','" , $carcode)."')";
if(countphp($caryear) > 0)
$whereSQL .= " AND nensikiy IN ('".implode("','" , $caryear)."')";
if(countphp($place_list))
$whereSQL .= " AND place1 IN ('".implode("','" , $place_list)."') ";
if(countphp($transmission_list))
$whereSQL .= " AND transmission IN ('".implode("','" , $transmission_list)."') ";
if(countphp($bodytype_list))
$whereSQL .= " AND bodytype IN ('".implode("','" , $bodytype_list)."') ";
if(countphp($color_list))
$whereSQL .= " AND tenderstock.color IN ('".implode("','" , $color_list)."') ";
if(countphp($carfuel))
$whereSQL .= " AND carfuel IN ('".implode("','" , $carfuel)."') ";
if(countphp($drivetype))
$whereSQL .= " AND drivetype IN ('".implode("','" , $drivetype)."') ";
if(countphp($drivetype2))
$whereSQL .= " AND drivetype2 IN ('".implode("','" , $drivetype2)."') ";
if(countphp($discount_tag))
$whereSQL .= " AND tenderstock.discount_tag IN ('".implode("','" , $discount_tag)."') ";
if($stockno && !$stockno2)
$whereSQL .= " AND rno = '$stockno' ";
if($stockno)
$whereSQL .= " AND rno >= '$stockno' ";
if($stockno2)
$whereSQL .= " AND rno <= '$stockno2' ";
/*
if($cc_from)
$whereSQL .= " AND carcc >= '$cc_from' ";
if($cc_to)
$whereSQL .= " AND carcc <= '$cc_to' ";
*/
$cc_ranges = array();
for($i=1;$i<=5;$i++)
{
$ccfrom = $_POST['cc_from'.$i];
$ccto = $_POST['cc_to'.$i];
if($ccfrom && $ccto)
{
$cc_ranges[] = array($ccfrom,$ccto);
}
}
if(countphp($cc_ranges))
{
$cc_clause = '';
foreach($cc_ranges as $range)
{
$cc_clause .= " OR (tenderstock.carcc >= '".intval($range[0]) ."' AND tenderstock.carcc <= '".intval($range[1]) ."') ";
}
if($cc_clause)
$whereSQL .= " AND ( FALSE ".$cc_clause.") ";
}
if(countphp($sel_rec))
$whereSQL .= " AND carid IN (".implode(',',$sel_rec).") ";
if($_SESSION['ipcountry'] == 'JAPAN')
$whereSQL .= " AND coalesce(show_japan,'') = '1' ";
if($stock_status == 'arrived')
$whereSQL .= " AND tenderinvoice.ivarrivedate <= current_date ";
if($stock_status == 'shipped')
$whereSQL .= " AND tenderinvoice.ivshipdate <= current_date AND tenderinvoice.ivarrivedate > current_date ";
if($stock_status == 'waitingship')
$whereSQL .= " AND (tenderinvoice.ivshipdate is null OR tenderinvoice.ivshipdate > current_date) ";
if($supercar_sql )
$whereSQL .= " $supercar_sql ";
if($submit == 'inspected_direct')
$whereSQL .= " AND tenderinvoice.ivinsp_status = 'Pass' ";
if($submit == 'promotion_stock')
$whereSQL .= " AND tenderstock.discount_tag != '' ";
if($submit == 'kingston_stock')
$whereSQL .= " AND ivuserid = 27153 ";
$whereSQL .= " AND coalesce(hide_customer,'') != '1' ";
//print $whereSQL;
$SLISTPAGE = $page_size?:90;
$SPAGE = 1;
if ( strlen($page) > 0 )
{
$SPAGE = $page;
}
$sql = "SELECT count(rno) as cnt
FROM tenderstock
LEFT JOIN dealer_stock ON id = carid::text AND source = 'zm'
LEFT JOIN tenderinvoice ON carid=ivcarid AND ivvalid=1
LEFT JOIN customer on tenderinvoice.ivuserid = userid
WHERE true $whereSQL $supercar_sql ";
$result = pg_query($db,$sql);
if ( $line = pg_fetch_array($result, null, PGSQL_ASSOC))
{
$cartotal = $line['cnt'];
if ( $SLISTPAGE > 0 )
{
$cnt = $cartotal / $SLISTPAGE;
}
}
if($payment_discount_units || $submit == 'discounted_stock' )
$cartotal = -1;
$paging_html = getPaginationString($SPAGE , $cartotal, $SLISTPAGE , 2 , 'view_all_stock_home.php' , '?type='.$type.'&cartype='.$cartype.'&rem_session=1&page=' );
?>