Files
2024-04-27 09:23:34 +02:00

65 lines
2.5 KiB
PHP

<?php
//ini_set('display_errors',1);
$date = "2013-11";
$fp2 = fopen('generatorfifi.php', 'w');
fwrite($fp2, "<?php\ninclude 'PDFMerger.php';\n\$pdf = new PDFMerger;\n\$pdf");
$db = $GLOBALS['db'];
$res = $db->query("SELECT id FROM ecminvoiceoutolds WHERE register_date like '2014-02%'");
//$res = $db->query("SELECT id, document_no, total, subtotal FROM ecminvoiceoutolds WHERE id='5a5074e6-689c-375c-07f4-529edd341c10'");
$b=0;
require_once("modules/EcmInvoiceOutOlds/EcmInvoiceOutOld.php");
while ($row = $db->fetchByAssoc($res)) {
$i = new EcmInvoiceOutOld();
$i->retrieve($row['id']);
echo 'bb';
if(file_exists('pdftmp2/'.$i->createPdfFileName())) { $b++; echo 'istnieje<br>'; } else {
//echo $i->createPdfFileName.' null<br>';
echo 'aa<br>'.$row['id'].'<br>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://192.168.1.131/crm/index.php?action=Authenticate&module=Users&return_module=Users&return_action=Login&user_name=db&user_password=rudemodz&login_theme=Sugar&login_language=en_us');
//curl_setopt($ch, CURLOPT_POSTFIELDS,'user_name=db&user_password='.$pass.'');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
$page = curl_exec($ch);
$up='https://192.168.1.131/crm/index.php?module=EcmInvoiceOutOlds&action=previewPDF&type=&to_pdf=1&record='.$row['id'].'';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $up);
//echo $i.': '.$row['id'].'<br>';
$page = curl_exec($ch);
$fp = fopen('pdftmp2/'.$i->createPdfFileName().'', 'w');
fwrite($fp, $page);
$s="->addPDF('pdftmp/".$i->createPdfFileName()."', 'all')\n";
//$b=microtime();
fwrite($fp2, $s);
fclose($fp);
//repair in db
//$db->query("UPDATE ecminvoiceoutolds SET total=$total, subtotal=$subtotal WHERE id='".$row['id']."'");
//echo "UPDATE ecminvoiceoutolds SET total=$total, subtotal=$subtotal WHERE id='".$row['id']."'<br>";
// $db->query("UPDATE ecmpayments_ecminvoiceoutolds SET total=$total WHERE ecminvoiceoutold_id='".$row['id']."'");
//unset($i);
}
}
/*
$s="->merge('file', 'pdftmp/asd".date("h:y");
$s.=".pdf');";
fwrite($fp2, $s);
fclose($fp2);
echo 'Zrobione!';
*/
echo $b;
?>