552 lines
27 KiB
PHP
552 lines
27 KiB
PHP
<?php
|
|
|
|
namespace export_sracka;
|
|
|
|
use Query\Operator;
|
|
use XBase\Record;
|
|
use XBase\WritableTable;
|
|
|
|
global $cfg, $dbcfg;
|
|
|
|
$cfg['Order']['Status']['dispatch'][0] = 'čeká na odeslání';
|
|
$cfg['Order']['Status']['dispatch'][1] = 'částečně odesláno';
|
|
$cfg['Order']['Status']['dispatch'][2] = 'odesláno';
|
|
|
|
if (!findRight('EXPRT')) {
|
|
redirect('launch.php?s=error.php&id=1');
|
|
}
|
|
|
|
date_default_timezone_set('Europe/Prague');
|
|
|
|
$type = getVal('type');
|
|
$format = getVal('format');
|
|
$dateTo = getVal('dateTo');
|
|
$dateFrom = getVal('dateFrom');
|
|
$data = getVal('data');
|
|
$what = $data['what'];
|
|
$dateFromC = getVal('dateFromC');
|
|
$dateToC = getVal('dateToC');
|
|
$where = 'file';
|
|
|
|
function formatString2CSV($str, $format)
|
|
{
|
|
if ($format == 'csv') {
|
|
$str = str_replace('"', '""', $str);
|
|
$str = preg_replace("/\r?\n/i", ' ', $str);
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
$userAgent = 'MOZILLA';
|
|
|
|
$mime_type['file'] = ($userAgent == 'IE' || $userAgent == 'OPERA')
|
|
? 'application/octetstream'
|
|
: 'application/octet-stream';
|
|
$mime_type['excel'] = 'application/x-msexcel';
|
|
$mime_type['csv'] = 'text/comma-separated-values';
|
|
$mime_type['dbf'] = 'application/dbase';
|
|
$mime_type['overview'] = 'text/html';
|
|
|
|
$filename['excel'] = 'export.xls';
|
|
$filename['csv'] = 'export.csv';
|
|
$filename['dbf'] = 'export.dbf';
|
|
$filename['overview'] = 'export.html';
|
|
|
|
$file = '';
|
|
|
|
// ##############################################################
|
|
|
|
/*
|
|
* ======================================================================
|
|
* EXPORT OBJEDNAVEK
|
|
* ======================================================================
|
|
*/
|
|
|
|
if ($type == 'orders') {
|
|
$filename['excel'] = 'objednavky_'.date('Y-m-d_H-i-s').'.xls';
|
|
$filename['csv'] = 'objednavky_'.date('Y-m-d_H-i-s').'.csv';
|
|
$filename['dbf'] = 'objednavky_'.date('Y-m-d_H-i-s').'.dbf';
|
|
$filename['overview'] = 'objednavky_'.date('Y-m-d_H-i-s').'.html';
|
|
|
|
$var['fields'] = " id, id_user, order_no,
|
|
status, status_payed, status_dispatch, status_storno, total_price,
|
|
invoice_name, invoice_surname, invoice_firm, invoice_ico, invoice_dic,
|
|
invoice_street, invoice_city, invoice_zip, invoice_country, invoice_phone, invoice_email,
|
|
delivery_name, delivery_surname, delivery_firm, delivery_street, delivery_city,
|
|
delivery_zip, delivery_country, delivery_type, delivery_complete,
|
|
note_user, note_admin, date_handle,
|
|
DATE_FORMAT(date_created, '".$dbcfg['date_format'].' '.$dbcfg['time_format']."') AS datec,
|
|
DATE_FORMAT(date_accept, '".$dbcfg['date_format'].' '.$dbcfg['time_format']."') AS datea,
|
|
DATE_FORMAT(date_handle, '".$dbcfg['date_format'].' '.$dbcfg['time_format']."') AS dateh,
|
|
COALESCE(date_handle, date_accept, NOW()) + INTERVAL {$dbcfg->shop_due_days} DAY AS date_due,
|
|
flags
|
|
";
|
|
$var['from'] = ' '.getTableName('orders').' AS o ';
|
|
$var['where'] = ' 1 ';
|
|
$var['orderField'] = 'o.id';
|
|
$var['orderDir'] = 'ASC';
|
|
$var['order'] = ' ORDER BY '.$var['orderField'].' '.$var['orderDir'];
|
|
|
|
if (findModule('currencies')) {
|
|
$var['fields'] = str_replace('total_price', 'total_price, total_price*currency_rate as total_price_czk, currency, currency_rate', $var['fields']);
|
|
}
|
|
|
|
// -----------------------------------------------------------------
|
|
function prepdate($date)
|
|
{
|
|
if (empty($date)) {
|
|
return '';
|
|
}
|
|
|
|
$date = new \DateTime($date);
|
|
|
|
return $date->format('Y-m-d');
|
|
}
|
|
|
|
$var['where'] .= ' AND o.id IN ('.(!empty($orderIds) ? join(',', $orderIds) : '0').')';
|
|
|
|
$encode = function ($str) {
|
|
return iconv('utf-8', getVal('coding', null, 'utf-8').'//TRANSLIT', $str);
|
|
};
|
|
|
|
// -----------------------------------------------------------------
|
|
|
|
$var['query'] = 'SELECT '.$var['fields'].' FROM '.$var['from'].' WHERE '.$var['where'].' '.$var['order'];
|
|
|
|
// Invoice mass printing
|
|
if ($format == 'invoice') {
|
|
$where = 'screen';
|
|
|
|
$var['fields'] = 'id';
|
|
$SQL = sqlQuery('SELECT '.$var['fields'].' FROM '.$var['from'].' WHERE '.$var['where'].' '.$var['order']);
|
|
|
|
$file = '<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="stylesheet" href="//www.w3.org/StyleSheets/Core/Steely" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<form action="launch.php?s=printCenter.php&type=order&set=order" method="POST" target="_blank" >';
|
|
|
|
while (($row = sqlFetchAssoc($SQL)) !== false) {
|
|
$file .= "<input type='hidden' name='IDs[]' value='{$row['id']}' />";
|
|
}
|
|
|
|
$file .= '<input type="submit" value="vygenerovat faktury"></form></body></html>';
|
|
}
|
|
|
|
if ($format == 'overview') {
|
|
$where = 'screen';
|
|
}
|
|
|
|
$SQL = sqlQuery($var['query']);
|
|
|
|
if (sqlNumRows($SQL) > 0) {
|
|
if ($format == 'dbf' || $format == 'overview') {
|
|
$vats = sqlFetchAll(sqlQuery('SELECT DISTINCT COALESCE(tax, 0) vat FROM '.$var['from'].' LEFT JOIN order_items oi ON oi.id_order=o.id WHERE '.$var['where'].' ORDER BY vat'), 'vat');
|
|
$vats = array_map(function ($x) {
|
|
return \DecimalConstants::zero();
|
|
}, $vats);
|
|
|
|
$sumTaxes = $vats;
|
|
|
|
if ($format == 'overview') {
|
|
$file = '<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="stylesheet" href="http://www.w3.org/StyleSheets/Core/Steely" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<style>
|
|
th {
|
|
text-align: center;
|
|
}
|
|
.right {
|
|
text-align: right;
|
|
}
|
|
td {
|
|
padding-right: 21px;
|
|
}
|
|
</style>
|
|
<table cellpadding="2">
|
|
<thead>
|
|
<th>číslo dokladu</th>
|
|
<th>datum vystavení</th>
|
|
<th>jmeno a přijmení</th>
|
|
';
|
|
foreach ($sumTaxes as $vat => $sum) {
|
|
$file .= "<th>základ dph {$vat}%</th>
|
|
<th>dph {$vat}%</th>";
|
|
}
|
|
|
|
$file .= '<th>celková částka</th>
|
|
<th>stav</th>
|
|
<th>poznámka</th>
|
|
</thead>
|
|
<tbody>';
|
|
}
|
|
|
|
if ($format == 'dbf') {
|
|
if ($where == 'file') {
|
|
header('Content-type: '.$mime_type[$format]);
|
|
header('Content-Disposition: attachment; filename="'.$filename[$format].'"');
|
|
header('Expires: 0');
|
|
header('Pragma: no-cache');
|
|
}
|
|
|
|
$oldErr = error_reporting(0);
|
|
|
|
/* sample data */
|
|
$fields = [
|
|
['DATUM_VYST', Record::DBFFIELD_TYPE_DATE], // datum vystavení
|
|
['DATUM_SPL', Record::DBFFIELD_TYPE_DATE], // prázdné
|
|
['DOKLAD_1', Record::DBFFIELD_TYPE_CHAR, 12], // aby tam bylo fčíslo objednávky např. f11521
|
|
['TYP_ZAP', Record::DBFFIELD_TYPE_CHAR, 1], // hodnota P
|
|
['ZNAK_UCT', Record::DBFFIELD_TYPE_CHAR, 5], // prázdné
|
|
['SYMBOLY', Record::DBFFIELD_TYPE_CHAR, 20], // včísloobjednávky např. v11521
|
|
['PAR_ZNAK', Record::DBFFIELD_TYPE_CHAR, 12], // to samé jako DOKLAD_1 např. f11521
|
|
['BANK_UCET', Record::DBFFIELD_TYPE_CHAR, 44], // prázdné
|
|
['SPEC_SYMB', Record::DBFFIELD_TYPE_CHAR, 10], // prázdné
|
|
['POPIS_TEXT', Record::DBFFIELD_TYPE_CHAR, 30], // libovolný text - např. prodej eshop-objednávka 11521
|
|
['DRUH_UCT', Record::DBFFIELD_TYPE_CHAR, 5], // hodnota PZ
|
|
['MENA', Record::DBFFIELD_TYPE_CHAR, 3], // buď Kč nebo EUR
|
|
['CELKEM_KC', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // celková částka dokladu včetně DPH v Kč
|
|
['CELKEMCIZI', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // celková částka dokladu v EUR - prodej na Slovensko?
|
|
['KURZ', Record::DBFFIELD_TYPE_FLOATING, 5, 3], // kurz pro přepočet
|
|
['DATUM_DPH', Record::DBFFIELD_TYPE_DATE], // datum DPH = datum vystavení
|
|
['TYP_DPH', Record::DBFFIELD_TYPE_CHAR, 5], // hodnota U
|
|
['ZAKL_DPH_Z', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // Částka bez daně v základní sazbě
|
|
['DPH_Z', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // Daň s azba 21 %
|
|
['ZAKL_DPH_S', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // Částka bez daně ve snížené sazbě
|
|
['DPH_S', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // Daň s azba 15 %
|
|
['TYPMIMODPH', Record::DBFFIELD_TYPE_CHAR, 1], // prázdné
|
|
['CASTKAMIMO', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // prázdné
|
|
['STREDISKO', Record::DBFFIELD_TYPE_CHAR, 5], // PRÁZDNÉ
|
|
['vykon', Record::DBFFIELD_TYPE_CHAR, 5], // prázdné
|
|
['zakazka', Record::DBFFIELD_TYPE_CHAR, 5], // prázdné
|
|
['POZNAMKA', Record::DBFFIELD_TYPE_CHAR, 150], // sem naimportovat jméno a příjmění a město kupujícího JAN NOVAK TURNOV
|
|
['FIRMA', Record::DBFFIELD_TYPE_CHAR, 30], // Firma
|
|
['JMENO', Record::DBFFIELD_TYPE_CHAR, 30], // Jmeno
|
|
['PRIJMENI', Record::DBFFIELD_TYPE_CHAR, 30], // Prijmeni
|
|
['ICO', Record::DBFFIELD_TYPE_CHAR, 15], // ICO
|
|
['DIC', Record::DBFFIELD_TYPE_CHAR, 20], // DIC
|
|
|
|
['ZAKAZNIK', Record::DBFFIELD_TYPE_CHAR, 80], // Prijmeni nebo firma
|
|
['ULICE', Record::DBFFIELD_TYPE_CHAR, 50], // Adresa
|
|
['MESTO', Record::DBFFIELD_TYPE_CHAR, 30], // Adresa
|
|
['PSC', Record::DBFFIELD_TYPE_CHAR, 10], // Adresa
|
|
['ZEME', Record::DBFFIELD_TYPE_CHAR, 30], // Adresa
|
|
|
|
['STAV', Record::DBFFIELD_TYPE_CHAR, 10], // STORNO/PRODEJ
|
|
['DATUM_SPLAT', Record::DBFFIELD_TYPE_DATE], // datum splatnosti
|
|
['SAZBA_DPH_Z', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // sazba DPH - zakladni
|
|
['SAZBA_DPH_S', Record::DBFFIELD_TYPE_FLOATING, 8, 2], // sazba DPH - snizena
|
|
];
|
|
|
|
/* create a new table */
|
|
$tableNew = WritableTable::create($cfg['Path']['data'].'export.dbf', $fields);
|
|
}
|
|
|
|
$sumPrice = \DecimalConstants::zero();
|
|
|
|
while (($row = sqlFetchAssoc($SQL)) !== false) {
|
|
$taxes = $vats;
|
|
|
|
if ($row['status_storno']) {
|
|
$row['total_price_czk'] = 0;
|
|
$row['total_price'] = 0;
|
|
} else {
|
|
// Get vats
|
|
$query = "SELECT oi.tax, SUM(oi.total_price) price
|
|
FROM order_items oi
|
|
JOIN orders o ON o.id = oi.id_order
|
|
WHERE oi.id_order={$row['id']}
|
|
GROUP BY oi.tax";
|
|
|
|
if (findModule('currencies')) {
|
|
$query = str_replace('total_price', 'total_price*o.currency_rate', $query);
|
|
}
|
|
|
|
$i_SQL = sqlQuery($query);
|
|
|
|
foreach ($i_SQL as $i_row) {
|
|
$tax = strval($i_row['tax']);
|
|
$price = toDecimal($i_row['price']);
|
|
$taxes[$tax] = $price;
|
|
if (!isset($sumTaxes[$tax])) {
|
|
$sumTaxes[$tax] = \DecimalConstants::zero();
|
|
}
|
|
$sumTaxes[$tax] = $sumTaxes[$tax]->add($price);
|
|
}
|
|
$sumPrice = $sumPrice->add(toDecimal($row['total_price']));
|
|
}
|
|
|
|
if ($format == 'overview') {
|
|
$note = '';
|
|
if ($row['status_storno']) {
|
|
$note = 'STORNO';
|
|
}
|
|
$file .= "<tr>
|
|
<td>{$row['order_no']}</td>
|
|
<td>{$row['dateh']}</td>
|
|
<td>{$row['invoice_name']} {$row['invoice_surname']}, {$row['invoice_city']}</td>";
|
|
|
|
foreach ($taxes as $vat => $sum) {
|
|
$file .= "<td class='right'>".number_format($taxes[$vat]->asFloat(), 2, ',', '')."</td>
|
|
<td class='right'>".number_format($taxes[$vat]->mul(toDecimal($vat / 100))->asFloat(), 2, ',', '').'</td>';
|
|
}
|
|
|
|
$file .= "<td class='right'>".number_format($row['total_price'], 2, ',', '').'</td>
|
|
<td>'.$cfg['Order']['Status']['global'][$row['status']]."</td>
|
|
<td>{$note}</td>
|
|
</tr>";
|
|
}
|
|
|
|
if ($format == 'dbf') {
|
|
$r = $tableNew->appendRecord();
|
|
|
|
$total_price = roundPrice($row['total_price_czk']);
|
|
|
|
$vatsFormDB = sqlQueryBuilder()
|
|
->select('vat, is_default')
|
|
->from('vats')
|
|
->where(Operator::equals(['id_country' => $row['invoice_country'] ?: 'CZ']))
|
|
->orderBy('vat', 'DESC')
|
|
->execute()
|
|
->fetchAll();
|
|
|
|
$dph_z = 0;
|
|
foreach ($vatsFormDB as $vatRow) {
|
|
if ($vatRow['is_default'] == 'Y') {
|
|
$dph_z = $vatRow['vat'];
|
|
break;
|
|
}
|
|
}
|
|
$dph_s = $vatsFormDB[1]['vat'] ?? 0;
|
|
|
|
if (!isset($taxes[$dph_z])) {
|
|
$taxes[$dph_z] = \DecimalConstants::zero();
|
|
}
|
|
if (!isset($taxes[$dph_s])) {
|
|
$taxes[$dph_s] = \DecimalConstants::zero();
|
|
}
|
|
if (!isset($taxes[0])) {
|
|
$taxes[0] = \DecimalConstants::zero();
|
|
}
|
|
|
|
$r->setObjectByName('DATUM_VYST', strtotime($row['date_handle'])); // datum vystavení
|
|
// $r->setObjectByName("DATUM_SPL", $row['DBFFIELD_TYPE_DATE']); //prázdné
|
|
$r->setObjectByName('DOKLAD_1', $row['order_no']); // aby tam bylo fčíslo objednávky např. f11521
|
|
$r->setObjectByName('TYP_ZAP', 'P'); // hodnota P
|
|
$r->setObjectByName('ZNAK_UCT', ''); // prázdné
|
|
$r->setObjectByName('SYMBOLY', $row['id']); // včísloobjednávky např. v11521
|
|
$r->setObjectByName('PAR_ZNAK', $row['order_no']); // to samé jako DOKLAD_1 např. f11521
|
|
$r->setObjectByName('BANK_UCET', ''); // prázdné
|
|
$r->setObjectByName('SPEC_SYMB', ''); // prázdné
|
|
$r->setObjectByName('POPIS_TEXT', $encode('Objednávka: '.$row['id'])); // libovolný text - např. prodej eshop-objednávka 11521
|
|
$r->setObjectByName('DRUH_UCT', 'PZ'); // hodnota PZ
|
|
$r->setObjectByName('MENA', $row['currency']); // buď Kč nebo EUR
|
|
$r->setObjectByName('CELKEM_KC', $total_price->printFloatValue(2)); // celková částka dokladu včetně DPH v Kč
|
|
$r->setObjectByName('CELKEMCIZI', ($row['currency'] == 'CZK') ? 0 : toDecimal($row['total_price'])->printFloatValue(2)); // celková částka dokladu v EUR - prodej na Slovensko?
|
|
$r->setObjectByName('KURZ', $row['currency_rate']); // kurz pro přepočet
|
|
$r->setObjectByName('DATUM_DPH', strtotime($row['date_handle'])); // datum DPH = datum vystavení
|
|
$r->setObjectByName('TYP_DPH', 'U'); // hodnota U
|
|
$r->setObjectByName('ZAKL_DPH_Z', $taxes[$dph_z]->printFloatValue(2)); // Částka bez daně v základní sazbě
|
|
$r->setObjectByName('DPH_Z', $taxes[$dph_z]->mul(toDecimal($dph_z / 100))->printFloatValue(2)); // Daň sazba 21 %
|
|
$r->setObjectByName('ZAKL_DPH_S', $taxes[$dph_s]->printFloatValue(2)); // Částka bez daně ve snížené sazbě
|
|
$r->setObjectByName('DPH_S', $taxes[$dph_s]->mul(toDecimal($dph_z / 100))->printFloatValue(2)); // Částka bez daně ve snížené sazbě
|
|
$r->setObjectByName('TYPMIMODPH', ''); // prázdné
|
|
$r->setObjectByName('CASTKAMIMO', $taxes['0']->printFloatValue(2)); // prázdné
|
|
$r->setObjectByName('STREDISKO', ''); // PRÁZDNÉ
|
|
$r->setObjectByName('vykon', ''); // prázdné
|
|
$r->setObjectByName('zakazka', ''); // prázdné
|
|
$r->setObjectByName('POZNAMKA', $encode("{$row['invoice_name']} {$row['invoice_surname']}, {$row['invoice_city']}")); // sem naimportovat jméno a příjmění a město kupujícího JAN NOVAK TURNOV
|
|
$r->setObjectByName('FIRMA', $encode($row['invoice_firm'])); // Firma
|
|
$r->setObjectByName('JMENO', $encode($row['invoice_name'])); // Jmeno
|
|
$r->setObjectByName('PRIJMENI', $encode($row['invoice_surname'])); // Prijmeni
|
|
|
|
$r->setObjectByName('ICO', $row['invoice_ico']); // ICO
|
|
$r->setObjectByName('DIC', $row['invoice_dic']); // DIC
|
|
|
|
$r->setObjectByName('ZAKAZNIK', $encode($row['invoice_firm'] ? $row['invoice_firm'] : "{$row['invoice_name']} {$row['invoice_surname']}")); // Prijmeni nebo firma
|
|
$r->setObjectByName('ULICE', $encode($row['invoice_street']));
|
|
$r->setObjectByName('MESTO', $encode($row['invoice_city']));
|
|
$r->setObjectByName('PSC', $row['invoice_zip']);
|
|
$r->setObjectByName('ZEME', $encode($row['invoice_country']));
|
|
|
|
$r->setObjectByName('STAV', $row['status_storno'] ? 'STORNO' : 'PRODEJ'); // STORNO/PRODEJ
|
|
$r->setObjectByName('DATUM_SPLAT', strtotime($row['date_due']));
|
|
$r->setObjectByName('SAZBA_DPH_Z', $dph_z);
|
|
$r->setObjectByName('SAZBA_DPH_S', $dph_s);
|
|
$tableNew->writeRecord();
|
|
}
|
|
}
|
|
|
|
if ($format == 'overview') {
|
|
$file .= '<tr><td> </td></tr>
|
|
<thead>
|
|
<th></th>
|
|
<th></th>
|
|
<th></th>';
|
|
foreach ($sumTaxes as $tax => $sum) {
|
|
$file .= "
|
|
<th>zaklad dph {$tax}%</th>
|
|
<th>dph {$tax}%</th>
|
|
";
|
|
}
|
|
|
|
$file .= '
|
|
<th>celková částka</th>
|
|
<th></th>
|
|
<th></th>
|
|
</thead>
|
|
<tr>
|
|
<td/><td/><td><b>CELKEM:</b></td>
|
|
';
|
|
foreach ($sumTaxes as $tax => $sum) {
|
|
$file .= " <td class='right'><b>".number_format($sum->asFloat(), 2, ',', '')."</b></td>
|
|
<td class='right'><b>".number_format($sum->mul(toDecimal($tax / 100))->asFloat(), 2, ',', '').'</b></td>
|
|
';
|
|
}
|
|
|
|
$file .= "<td class='right'><b>".number_format($sumPrice->asFloat(), 2, ',', '').'</b></td>
|
|
<tr>
|
|
</tbody>
|
|
</table>
|
|
</body>
|
|
</html>';
|
|
}
|
|
|
|
if ($format == 'dbf') {
|
|
/* close the table */
|
|
$tableNew->close();
|
|
|
|
error_reporting($oldErr);
|
|
|
|
readfile($cfg['Path']['data'].'export.dbf');
|
|
exit;
|
|
}
|
|
} elseif ($format == 'csv') {
|
|
$file = '"Kód";"Stav objednávky";"Stav zaplacení";"Stav expedice";"Stav storna";"Datum objednávky";'.
|
|
'"Datum přijetí";"Datum vyřízení";"Počet položek";"Cena ('.$dbcfg['currency'].')";'.
|
|
'"Jméno";"Příjmení";"Firma";"Email";"Telefon";"Ulice";"Město";"PSČ";"Země";"IČO";"DIČ";'.
|
|
'"Doruč.jméno";"Doruč.příjmení";"Doruč.firma";"Doruč.ulice";"Doruč.město";"Doruč.PSČ";"Doruč.země";'.
|
|
'"Doručit jen kompletně";"Pozn.pro zákazníka";"Pozn.pro obchodníka";"Příznaky"'."\r\n\r\n";
|
|
$rowtpl = '"{O_NO}";"{STATUS}";"{STATUS_PAYED}";"{STATUS_DISPATCH}";"{STATUS_STORNO}";'.
|
|
'"{DATE_CREATED}";"{DATE_ACCEPT}";"{DATE_HANDLE}";"{ITEMS}";"{PRICE}";"{INV_NAME}";"{INV_SURNAME}";'.
|
|
'"{INV_FIRM}";"{INV_EMAIL}";"{INV_PHONE}";"{INV_STREET}";"{INV_CITY}";"{INV_ZIP}";"{INV_COUNTRY}";'.
|
|
'"{INV_ICO}";"{INV_DIC}";"{DEL_NAME}";"{DEL_SURNAME}";"{DEL_FIRM}";"{DEL_STREET}";"{DEL_CITY}";'.
|
|
'"{DEL_ZIP}";"{DEL_COUNTRY}";"{DEL_COMPLETE}";"{NOTE_ADMIN}";"{NOTE_USER}";"{FLAGS}"'."\r\n";
|
|
}
|
|
|
|
if ($format == 'csv') {
|
|
while ($row = sqlFetchArray($SQL)) {
|
|
// kontrola delky zpracovani skriptu
|
|
controlTimeLimit();
|
|
|
|
$order = new \Order();
|
|
$order->createFromDB($row['id']);
|
|
$order->fetchItems();
|
|
|
|
$i_row = ['items' => count($order->items)];
|
|
|
|
$rowtpl_t = $rowtpl;
|
|
|
|
$rowtpl_t = str_replace('{O_NO}', $row['order_no'], $rowtpl_t);
|
|
$rowtpl_t = str_replace('{ITEMS}', $i_row['items'], $rowtpl_t);
|
|
if (findModule('currencies')) {
|
|
$rowtpl_t = str_replace('.', ',', str_replace('{PRICE}', number_format($row['total_price'], 2, '.', ''), $rowtpl_t));
|
|
$rowtpl_t = str_replace('{MENA}', $row['currency'], $rowtpl_t);
|
|
$rowtpl_t = str_replace('{KURZ}', $row['currency_rate'], $rowtpl_t);
|
|
$rowtpl_t = str_replace('.', ',', str_replace('{PRICE_CZK}', number_format($row['total_price_czk'], 2, '.', ''), $rowtpl_t));
|
|
} else {
|
|
$rowtpl_t = str_replace('.', ',', str_replace('{PRICE}', number_format($row['total_price'], 2, '.', ''), $rowtpl_t));
|
|
}
|
|
if (findModule(\Modules::PRODUCTS, \Modules::SUB_WEIGHT)) {
|
|
$order = new \Order();
|
|
$order->createFromDB($row['id']);
|
|
$rowtpl_t = str_replace('{O_WEIGHT}', $order->getTotalWeight(), $rowtpl_t);
|
|
}
|
|
$rowtpl_t = str_replace('{STATUS}', formatString2CSV($cfg['Order']['Status']['global'][$row['status']], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{STATUS_PAYED}', formatString2CSV($cfg['Order']['Status']['payed'][$row['status_payed']], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{STATUS_DISPATCH}', formatString2CSV($cfg['Order']['Status']['dispatch'][$row['status_dispatch']], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{STATUS_STORNO}', formatString2CSV($cfg['Order']['Status']['storno'][$row['status_storno']], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DATE_CREATED}', $row['datec'], $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DATE_ACCEPT}', $row['datea'], $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DATE_HANDLE}', $row['dateh'], $rowtpl_t);
|
|
|
|
$rowtpl_t = str_replace('{DEL_COMPLETE}', ($row['delivery_complete'] == 'Y') ? 'Ano' : 'Ne', $rowtpl_t);
|
|
|
|
$rowtpl_t = str_replace('{INV_NAME}', formatString2CSV($row['invoice_name'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_SURNAME}', formatString2CSV($row['invoice_surname'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_FIRM}', formatString2CSV($row['invoice_firm'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_EMAIL}', formatString2CSV($row['invoice_email'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_PHONE}', formatString2CSV($row['invoice_phone'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_STREET}', formatString2CSV($row['invoice_street'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_CITY}', formatString2CSV($row['invoice_city'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_ZIP}', formatString2CSV($row['invoice_zip'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_COUNTRY}', formatString2CSV($row['invoice_country'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_ICO}', formatString2CSV($row['invoice_ico'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{INV_DIC}', formatString2CSV($row['invoice_dic'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DEL_NAME}', formatString2CSV($row['delivery_name'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DEL_SURNAME}', formatString2CSV($row['delivery_surname'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DEL_FIRM}', formatString2CSV($row['delivery_firm'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DEL_STREET}', formatString2CSV($row['delivery_street'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DEL_CITY}', formatString2CSV($row['delivery_city'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DEL_ZIP}', formatString2CSV($row['delivery_zip'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{DEL_COUNTRY}', formatString2CSV($row['delivery_country'], $format), $rowtpl_t);
|
|
|
|
$rowtpl_t = str_replace('{NOTE_ADMIN}', formatString2CSV($row['note_admin'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{NOTE_USER}', formatString2CSV($row['note_user'], $format), $rowtpl_t);
|
|
$rowtpl_t = str_replace('{FLAGS}', $row['flags'], $rowtpl_t);
|
|
|
|
$deliveryType = explode('-', $row['delivery_type']);
|
|
|
|
$rowtpl_t = str_replace('{DELIVERY}', $deliveryType[1] ?? '', $rowtpl_t);
|
|
$rowtpl_t = str_replace('{PAYMENT}', $deliveryType[0] ?? '', $rowtpl_t);
|
|
|
|
$file .= $rowtpl_t;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// kontrola delky zpracovani skriptu
|
|
controlTimeLimit();
|
|
|
|
// ###########################
|
|
// KAM EXPORTOVAT
|
|
|
|
// ============================================
|
|
if ($where == 'screen') {
|
|
if ($format == 'csv') {
|
|
header('Content-type: '.$mime_type['csv']);
|
|
// vytisknout
|
|
echo $file;
|
|
} else {
|
|
echo $file;
|
|
}
|
|
} elseif // ============================================
|
|
($where == 'file'
|
|
) {
|
|
header('Content-type: '.$mime_type['file']);
|
|
if ($userAgent == 'IE') {
|
|
header('Content-Disposition: attachment; filename="'.$filename[$format].'"');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
header('Pragma: public');
|
|
} else {
|
|
header('Content-Disposition: attachment; filename="'.$filename[$format].'"');
|
|
header('Expires: 0');
|
|
header('Pragma: no-cache');
|
|
}
|
|
// vytisknout
|
|
echo $file;
|
|
}
|
|
|
|
//
|
|
// ###########################
|
|
|
|
// ##############################################################
|