179 lines
4.9 KiB
PHP
179 lines
4.9 KiB
PHP
<?php
|
|
if ($_REQUEST ['date']) {
|
|
$date = $_REQUEST ['date'];
|
|
} else {
|
|
$date = new DateTime ();
|
|
$date->modify ( "-1 month" );
|
|
$date = $date->format ( "01.m.Y" );
|
|
}
|
|
|
|
$dokumenty = $_REQUEST['documents'];
|
|
if ($_REQUEST ['date'] != "") {
|
|
|
|
$array=[];
|
|
foreach ($dokumenty as $dokument){
|
|
echo $dokument;
|
|
if($dokument=='fs'){
|
|
$invoiceCreator = new InvoiceCreator ( $_REQUEST ['date'] );
|
|
|
|
$array2 = $invoiceCreator->getInvoices ();
|
|
|
|
$array = array_merge ( $array, $array2 );
|
|
}
|
|
if($dokument=='fz-all'){
|
|
$purchaseCreator = new PurchaseCreator ( $_REQUEST ['date'] );
|
|
|
|
$array2 = $purchaseCreator->getPurchases ("all");
|
|
|
|
$array = array_merge ( $array, $array2 );
|
|
}
|
|
if($dokument=='fz-new'){
|
|
$purchaseCreator = new PurchaseCreator ( $_REQUEST ['date'] );
|
|
|
|
$array2 = $purchaseCreator->getPurchases ("new");
|
|
|
|
$array = array_merge ( $array, $array2 );
|
|
}
|
|
if($dokument=='pz'){
|
|
$purchaseCreator = new PzCreator ( $_REQUEST ['date'] );
|
|
|
|
$array2 = $purchaseCreator->getDocuments();
|
|
|
|
$array = array_merge ( $array, $array2 );
|
|
}
|
|
if($dokument=='wz'){
|
|
$purchaseCreator = new WzCreator ( $_REQUEST ['date'] );
|
|
|
|
$array2 = $purchaseCreator->getDocuments();
|
|
|
|
$array = array_merge ( $array, $array2 );
|
|
}
|
|
if($dokument=='rw'){
|
|
$purchaseCreator = new RwCreator ( $_REQUEST ['date'] );
|
|
|
|
$array2 = $purchaseCreator->getDocuments();
|
|
|
|
$array = array_merge ( $array, $array2 );
|
|
}
|
|
|
|
if($dokument=='pw'){
|
|
$purchaseCreator = new PwCreator ( $_REQUEST ['date'] );
|
|
|
|
$array2 = $purchaseCreator->getDocuments();
|
|
|
|
$array = array_merge ( $array, $array2 );
|
|
}
|
|
|
|
if($dokument=='mm'){
|
|
$purchaseCreator = new MmCreator ( $_REQUEST ['date'] );
|
|
|
|
$array2 = $purchaseCreator->getDocuments();
|
|
|
|
$array = array_merge ( $array, $array2 );
|
|
}
|
|
}
|
|
|
|
|
|
$delimiter = ',';
|
|
unlink( 'eksport.epp');
|
|
if (count ( $array ) > 0) {
|
|
|
|
$fp = fopen ( 'eksport.epp', 'w' );
|
|
fwriteEncoding ( $fp, "[INFO]\r\n" );
|
|
fwriteEncoding ( $fp, '"1.05.4",0,1250,"Subiekt GT","GT","SubTest","Firma przykładowa systemu InsERT GT","Wrocław","54-445","Bławatkowa 25/3","111-111-11-11","MAG","Główny","Magazyn główny",,1,20170101000000,20170331000000,"Kowalski Jan",20170804155934,"Polska","PL",,0' . "\r\n\r\n" );
|
|
foreach ( $array as $element ) {
|
|
fwriteEncoding ( $fp, "[NAGLOWEK]\r\n" );
|
|
|
|
$arrayElement = ( array ) $element;
|
|
|
|
unset ( $arrayElement ['pozycjeObiekt'] );
|
|
|
|
fwriteArray ( $fp, $arrayElement, $delimiter );
|
|
fwriteEncoding ( $fp, "\r\n" );
|
|
|
|
$pozycje = $element->getPozycjeObiekt ();
|
|
|
|
if (count ( $pozycje ) > 0) {
|
|
fwriteEncoding ( $fp, "[ZAWARTOSC]\r\n" );
|
|
foreach ( $pozycje as $pozycja ) {
|
|
|
|
fwriteArray ( $fp, ( array ) $pozycja, $delimiter );
|
|
}
|
|
fwriteEncoding ( $fp, "\r\n" );
|
|
} else {
|
|
fwriteEncoding ( $fp, "[ZAWARTOSC]\r\n" );
|
|
fwriteEncoding ( $fp, "\r\n" );
|
|
}
|
|
}
|
|
|
|
fwriteEncoding ( $fp, "[NAGLOWEK]\r\n" );
|
|
fwriteEncoding ( $fp, "\"KONTRAHENCI\"\r\n\r\n" );
|
|
|
|
fwriteEncoding ( $fp, "[ZAWARTOSC]\r\n" );
|
|
foreach ( $invoiceCreator->kontrahenci as $pozycja ) {
|
|
|
|
fwriteArray ( $fp, ( array ) $pozycja, $delimiter );
|
|
}
|
|
/*
|
|
foreach ( $purchaseCreator->kontrahenci as $pozycja ) {
|
|
|
|
fwriteArray ( $fp, ( array ) $pozycja, $delimiter );
|
|
}*/
|
|
fwriteEncoding ( $fp, "\r\n" );
|
|
}
|
|
|
|
|
|
$quoted = sprintf('"%s"', addcslashes(basename('eksport.epp'), '"\\'));
|
|
$size = filesize('eksport.epp');
|
|
header('Content-Description: File Transfer');
|
|
header('Content-Type: application/octet-stream');
|
|
header('Content-Disposition: attachment; filename=' . $quoted);
|
|
header('Content-Transfer-Encoding: binary');
|
|
header('Connection: Keep-Alive');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
header('Pragma: public');
|
|
header('Content-Length: ' . $size);
|
|
ob_clean();
|
|
flush();
|
|
readfile('eksport.epp'); //Absolute URL
|
|
exit();
|
|
|
|
|
|
} else {
|
|
$smarty = new Sugar_Smarty ();
|
|
$smarty->assign ( 'dateFormat', $Calendar_daFormat = str_replace ( "d", "%d", str_replace ( "m", "%m", str_replace ( "Y", "%Y", $GLOBALS ['timedate']->get_date_format () ) ) ) );
|
|
$smarty->assign ( "date", $date );
|
|
echo $smarty->fetch ( "modules/EcmReports/RewizorGT/form.tpl.html" );
|
|
}
|
|
|
|
function fwriteEncoding($fp,$text){
|
|
//cp1250
|
|
return fwrite($fp, iconv('UTF-8//TRANSLIT',"Windows-1250//TRANSLIT",$text));
|
|
|
|
}
|
|
|
|
function fwriteArray($fp, $array, $delimiter) {
|
|
$string = "";
|
|
|
|
$i = 0;
|
|
$len = count ( $array );
|
|
foreach ( $array as $key => $value ) {
|
|
if ($i == $len - 1) {
|
|
$string .= addEnclosure ( $value ) . "\r\n";
|
|
} else {
|
|
$string .= addEnclosure ( $value ) . $delimiter;
|
|
}
|
|
// …
|
|
$i ++;
|
|
}
|
|
fwriteEncoding ( $fp, $string );
|
|
}
|
|
function addEnclosure($value) {
|
|
if (is_string ( $value )) {
|
|
return '"' . $value . '"';
|
|
} else {
|
|
return $value;
|
|
}
|
|
}
|
|
?>
|