128 lines
5.0 KiB
PHP
Executable File
128 lines
5.0 KiB
PHP
Executable File
<?
|
|
//require_once('include/write_excell/Worksheet.php');
|
|
//require_once('include/write_excell/Workbook.php');
|
|
require_once("modules/EcmDevices/ListHelper.php");
|
|
require_once('include/we/OLEwriter.php');
|
|
require_once('include/we/BIFFwriter.php');
|
|
require_once('include/we/Worksheet.php');
|
|
require_once('include/we/Workbook.php');
|
|
|
|
if($_REQUEST['disposition']=="D")
|
|
{
|
|
header('Content-type: text/html; charset=windows-1250');
|
|
header("Content-type: application/vnd.ms-excel");
|
|
header("Content-Disposition: attachment; filename=\"Products.xls\"");
|
|
header('Pragma: private');
|
|
header('Cache-control: private, must-revalidate');
|
|
$workbook = new Workbook("-");
|
|
}
|
|
else
|
|
{
|
|
$microtime=str_replace(".","",str_replace(" ","",microtime()));
|
|
$workbook = new Workbook("cache/upload/Products".$microtime.".xls");
|
|
}
|
|
|
|
$worksheet =& $workbook->add_worksheet('arkusz');
|
|
$worksheet->set_column(0, 0, 45);
|
|
$worksheet->set_column(1, 9, 15);
|
|
|
|
|
|
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name,exchange_rate_id from ecmdevices where id='".$_SESSION['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 ecmdevices_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[]="ecmdevices_ecmproducts.id!='".$key."'";
|
|
$orand=' and ';
|
|
}
|
|
elseif($_SESSION['pricebook_check'][$_SESSION['pricebook_id']][$key]=="true" && $_SESSION['pricebook_check'][$_SESSION['pricebook_id']]['all']!="true"){
|
|
$where_clauses[]="ecmdevices_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="ecmdevices_ecmproducts.id='9999999999999999' and ";
|
|
}
|
|
else $where="ecmdevices_ecmproducts.id='9999999999999999' and ";
|
|
//print $where;
|
|
$z="select
|
|
ecmdevices_ecmproducts.price as price,
|
|
ecmdevices_ecmproducts.recipient_code as recipient_code,
|
|
ecmdevices_ecmproducts.id as idp,
|
|
ecmdevices_ecmproducts.remarks_pl as remarks_pl,
|
|
ecmdevices_ecmproducts.remarks_en as remarks_en,
|
|
ecmdevices_ecmproducts.remarks_de as remarks_de,
|
|
|
|
|
|
ecmproducts.*,
|
|
if(ecmdevices_ecmproducts.price>0,(100-(100*ecmproducts.purchase_price/ecmdevices_ecmproducts.price)),0) as margin_rate,
|
|
|
|
ecmproduct_language_pl_view.ean as ean_pl,
|
|
ecmproduct_language_pl_view.short_description as short_description_pl,
|
|
ecmproduct_language_pl_view.long_description as long_description_pl,
|
|
ecmproduct_language_pl_view.remarks as default_remarks_pl,
|
|
|
|
ecmproduct_language_en_view.ean as ean_en,
|
|
ecmproduct_language_en_view.short_description as short_description_en,
|
|
ecmproduct_language_en_view.long_description as long_description_en,
|
|
ecmproduct_language_en_view.remarks as default_remarks_en,
|
|
|
|
ecmproduct_language_de_view.ean as ean_de,
|
|
ecmproduct_language_de_view.short_description as short_description_de,
|
|
ecmproduct_language_de_view.long_description as long_description_de,
|
|
ecmproduct_language_de_view.remarks as default_remarks_de
|
|
|
|
from ecmdevices_ecmproducts
|
|
|
|
left join ecmproduct_language_pl_view on ecmproduct_language_pl_view.ecmproduct_id=ecmdevices_ecmproducts.ecmproduct_id
|
|
left join ecmproduct_language_en_view on ecmproduct_language_en_view.ecmproduct_id=ecmdevices_ecmproducts.ecmproduct_id
|
|
left join ecmproduct_language_de_view on ecmproduct_language_de_view.ecmproduct_id=ecmdevices_ecmproducts.ecmproduct_id
|
|
|
|
left join ecmproducts on ecmproducts.id=ecmdevices_ecmproducts.ecmproduct_id
|
|
|
|
where ".$where." ecmdevices_ecmproducts.ecmdevice_id='".$_SESSION['pricebook_id']."' and ecmdevices_ecmproducts.deleted='0'";
|
|
if($_SESSION['pricebook_order'])$z.=" order by ".$_SESSION['pricebook_order'];
|
|
|
|
//print $z;
|
|
$result = $GLOBALS['db']->query($z);
|
|
print mysql_error();
|
|
$header =& $workbook->addformat();
|
|
$header->set_bold();
|
|
$header->set_size(12);
|
|
$header->set_color('blue');
|
|
|
|
for($i=0;$i<count($t);$i++){
|
|
if($t[$i]){
|
|
$worksheet->write_string(0,$i,dy($t[$i]),$header);
|
|
}
|
|
}
|
|
$j=1;
|
|
while($row=$GLOBALS['db']->fetchByAssoc($result)){
|
|
for($i=0;$i<count($t);$i++){
|
|
if($t[$i]){
|
|
if($c[$i]=="list_price")$worksheet->write($j,$i,dy(addExchangeRateValue($row['price'],$c[$i],$er_value)));
|
|
elseif($c[$i]=="margin_rate")$worksheet->write($j,$i,dy(number_format($row['margin_rate'],2,",",".")));
|
|
else $worksheet->write($j,$i,iconv("utf-8","windows-1250",addExchangeRateValue($row[$c[$i]],$c[$i],$er_value)));
|
|
}
|
|
}
|
|
$j++;
|
|
}
|
|
|
|
|
|
$workbook->close();
|
|
|
|
?>
|