Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- error_reporting(E_ALL);
- ini_set('display_errors', TRUE);
- ini_set('display_startup_errors', TRUE);
- define("SM_SAFE_MODE", true);
- define("NOT_CHECK_PERMISSIONS",true);
- define("NO_AGENT_CHECK", true);
- define("NO_AGENT_STATISTIC", true);
- define("STOP_STATISTICS", true);
- require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
- require_once $_SERVER["DOCUMENT_ROOT"] . '/local/lib/dompdf/autoload.inc.php';
- use Dompdf\Dompdf;
- use Dompdf\Options;
- global $USER;
- $USER->GetID();
- if($_GET["user_id"] == $USER->GetID()) {
- CModule::IncludeModule("iblock");
- $arSelect = array("ID", "IBLOCK_ID", "NAME", "PROPERTY_OPERATIONS", "PROPERTY_TOTAL_ACCRUED", "PROPERTY_TOTAL_SUM", "PROPERTY_TOTAL_WITHHELD", "PROPERTY_TOTAL_COMPLETED");
- $arFilter = array("IBLOCK_ID" => \Bitrix\Main\Config\Option::get('main', 'IBLOCK_PAY_LIST'), "ID" => $_GET["element_id"], "ACTIVE" => "Y");
- $res = CIBlockElement::GetList(array(), $arFilter, false, array("nPageSize" => 1), $arSelect);
- while ($ob = $res->GetNextElement()) {
- $arFields = $ob->GetFields();
- $ddd = json_decode($arFields["~PROPERTY_OPERATIONS_VALUE"]);
- $docName = $arFields["NAME"];
- $prop1 = $arFields["PROPERTY_TOTAL_ACCRUED_VALUE"];
- $prop2 = $arFields["PROPERTY_TOTAL_SUM_VALUE"];
- $prop3 = $arFields["PROPERTY_TOTAL_WITHHELD_VALUE"];
- $prop4 = $arFields["PROPERTY_TOTAL_COMPLETED_VALUE"];
- }
- $arAllData = array();
- foreach ((array)$ddd as $data):
- $data = (array)$data;
- $date = new DateTime($data["StartDate"]);
- $StartDate = $date->format('d.m.Y');
- $date = new DateTime($data["RegistrationData"]);
- $EndDate = $date->format('d.m.Y');
- $arAllData[$data["Group"]] .= "<tr><td>" . $data["Type"] . " (" . $StartDate . "-" . $EndDate . ") - " . $data["Amount"] . "</td></tr>";
- endforeach;
- define("DOMPDF_ENABLE_REMOTE", true);
- $pdf_table_style = '<style>
- body {
- font-family: DejaVu Sans
- }
- table.products{
- border-collapse: collapse;
- width: 100%;
- margin: 0 auto;
- }
- table.products td{
- border: 1px solid;
- font-size: 12px;
- padding: 3px;
- }
- table.products td b{
- font-size: 15px;
- }
- table.products td span{
- font-size: 14px;
- }
- table.products th{
- padding: 5px;
- border: 1px solid;
- font-weight: bold;
- font-size: 12px;
- }
- h1{
- text-align: center;
- }
- </style>';
- $pdf_table = '<!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv = "Content-Type" content = "text/html; charset = utf-8" />
- ' . $pdf_table_style . '
- <title></title>
- </head>
- <body>
- <img src="http://' . $_SERVER['HTTP_HOST'] . '/local/download.jpg">
- <h1>' . $docName . '</h1>
- <table cellpadding="0" cellspacing="0" class="products">
- <colgroup><col></colgroup>
- <tbody>
- <tr>
- <td>
- <b>1. Начислено:</b>
- </td>
- </tr>
- ' . $arAllData["Начислено"] . '
- <tr>
- <td>
- <span>ИТОГО НАЧИСЛЕНО: ' . $prop1 . '</span>
- </td>
- </tr>
- <tr>
- <td>
- <b>2. Доходы в натуральной Форме:</b>
- </td>
- </tr>
- ' . $arAllData["Справочно"] . '
- <tr>
- <td>
- <span>ИТОГО ДОХОДОВ В НАТУРАЛЬНОЙ ФОРМЕ: ' . $prop2 . '</span>
- </td>
- </tr>
- <tr>
- <td>
- <b>3. Удержано:</b>
- </td>
- </tr>
- ' . $arAllData["Удержано"] . '
- <tr>
- <td>
- <span>ИТОГО Удержано: ' . $prop3 . '</span>
- </td>
- </tr>
- <tr>
- <td>
- <b>4. Выплачено:</b>
- </td>
- </tr>
- ' . $arAllData["Выплачено"] . '
- <tr>
- <td>
- <span>ИТОГО Выплачено: ' . $prop4 . '</span>
- </td>
- </tr>
- </tbody>
- </table>';
- $pdf_table .= '</body></html></table>';
- //echo $pdf_table;
- //exit();
- $options = new Options();
- $options->set('isRemoteEnabled', true);
- $dompdf = new Dompdf($options);
- $dompdf->set_option('isHtml5ParserEnabled', true);
- $dompdf->set_option('isRemoteEnabled', true);
- $dompdf->loadHtml($pdf_table);
- $dompdf->render();
- $file = $dompdf->output();
- $file_to_save = $_SERVER["DOCUMENT_ROOT"] . '/upload/file.pdf';
- //save the pdf file on the server
- file_put_contents($file_to_save, $file);
- //print the pdf file to the screen for saving
- header('Content-type: application/pdf');
- header('Content-Disposition: inline; filename="file.pdf"');
- header('Content-Transfer-Encoding: binary');
- header('Content-Length: ' . filesize($file_to_save));
- header('Accept-Ranges: bytes');
- readfile($file_to_save);
- $temp = tmpfile();
- fwrite($temp, $file);
- fseek($temp, 0);
- $metaDatas = stream_get_meta_data($temp);
- echo "<pre>";
- print_r($metaDatas);
- echo "</pre>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement