72 lines
3.1 KiB
PHP
72 lines
3.1 KiB
PHP
<?
|
|
require_once("modules/EcmPrices/ListHelper.php");
|
|
|
|
header("Content-Type: application/vnd.ms-excel");
|
|
header("Content-Disposition: attachment; filename=Products.xls");
|
|
header("Pragma: no-cache");
|
|
header("Expires: 0");
|
|
|
|
|
|
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name,exchange_rate_id from ecmprices where id='".$_COOKIE['pricebook_id']."'"));
|
|
$name=$r['name'];
|
|
$exchange_rate_id=$r['exchange_rate_id'];
|
|
|
|
require_once('modules/Currencies/Currency.php');
|
|
$currency = new Currency();
|
|
$currency->retrieve($exchange_rate_id);
|
|
$er_value=$currency->conversion_rate;
|
|
|
|
$result = $GLOBALS['db']->query("select * from ecmprices_customview where id='".$_COOKIE['customview_id']."'");
|
|
$row=$GLOBALS['db']->fetchByAssoc($result);
|
|
$c=explode("||",$row['columns']);
|
|
$t=explode("||",$row['titles']);
|
|
|
|
$where="";
|
|
if(count($_SESSION['pricebook_check'][$_SESSION['pricebook_id']])>0)
|
|
{
|
|
foreach($_SESSION['pricebook_check'][$_SESSION['pricebook_id']] as $key=>$value){
|
|
if($_SESSION['pricebook_check'][$_SESSION['pricebook_id']][$key]!="true" && $_SESSION['pricebook_check'][$_SESSION['pricebook_id']]['all']=="true"){
|
|
$where_clauses[]="ecmprices_ecmproducts.id!='".$key."'";
|
|
$orand=' and ';
|
|
}
|
|
elseif($_SESSION['pricebook_check'][$_SESSION['pricebook_id']][$key]=="true" && $_SESSION['pricebook_check'][$_SESSION['pricebook_id']]['all']!="true"){
|
|
$where_clauses[]="ecmprices_ecmproducts.id='".$key."'";
|
|
$orand=' or ';
|
|
}
|
|
}
|
|
if(count($where_clauses)>0)$where="(".implode($orand,$where_clauses).") and ";
|
|
elseif($_SESSION['pricebook_check'][$_SESSION['pricebook_id']]['all']!="true" && count($where_clauses)==0)$where="ecmprices_ecmproducts.id='9999999999999999' and ";
|
|
}
|
|
else $where="ecmprices_ecmproducts.id='9999999999999999' and ";
|
|
$z="select ecmprices_ecmproducts.price as price,ecmprices_ecmproducts.recipient_code as recipient_code,ecmprices_ecmproducts.id as idp,ecmproducts.*,
|
|
if(ecmprices_ecmproducts.price>0,(100-(100*ecmproducts.purchase_price/ecmprices_ecmproducts.price)),0) as margin_rate from ecmprices_ecmproducts left join ecmproducts on ecmproducts.id=ecmprices_ecmproducts.ecmproduct_id where ".$where."ecmprices_ecmproducts.ecmprice_id='".$_COOKIE['pricebook_id']."' and ecmprices_ecmproducts.deleted='0'";
|
|
if($_SESSION['pricebook_order'])$z.=" order by ".$_SESSION['pricebook_order'];
|
|
$result = $GLOBALS['db']->query($z);
|
|
|
|
$ca="abcdefghijklmnopqrstuvwxyz";
|
|
$html='';
|
|
$html.='<table border="1">';
|
|
$html.='<tr>';
|
|
for($i=0;$i<count($t);$i++){
|
|
if($t[$i]){
|
|
|
|
$html.='<th><b>'.iconv("utf-8","cp1250",$t[$i]).'</b></th>';
|
|
}
|
|
}
|
|
$html.='</tr>';
|
|
$j=1;
|
|
while($row=$GLOBALS['db']->fetchByAssoc($result)){
|
|
$html.='<tr>';
|
|
for($i=0;$i<count($t);$i++){
|
|
if($t[$i]){
|
|
if($c[$i]=="list_price")$html.='<td>'.iconv("utf-8","cp1250",addExchangeRateValue($row['price'],$c[$i],$er_value)).'</td>';
|
|
elseif($c[$i]=="margin_rate")$html.='<td>'.number_format($row['margin_rate'],2,",",".").'</td>';
|
|
else $html.='<td>'.iconv("utf-8","cp1250",addExchangeRateValue($row[$c[$i]],$c[$i],$er_value)).'</td>';
|
|
}
|
|
}
|
|
$html.='</tr>';
|
|
$j++;
|
|
}
|
|
$html.='</table>';
|
|
echo $html;
|
|
?>
|