Example #1
0
                   </table:table-cell>
                   <table:table-cell office:value-type="string">
                     <text:p>An online map</text:p>
                   </table:table-cell>
                   <table:table-cell office:value-type="string">
                     <text:p>
                       <text:a xlink:type="simple" xlink:href="http://maps.google.com/"
                         >http://maps.google.com</text:a>
                     </text:p>
                   </table:table-cell>
                 </table:table-row>
               </table:table>
';
*/
$descr_tz = '
               111
               <text:h text:outline-level="1"> A Table (Heading 1)</text:h>
               <text:p>222</text:p>
               <text:a xlink:type="simple" xlink:href="http://www.flickr.com/services/api/">http://www.flickr.com/services/api/</text:a>
';
$act_new = array('$sbr_num' => "СБР-109-Б/О-1", '$date_act' => "12.09.2012", '$date_sbr' => "12.09.2012", '$efio' => "Резидент Республики Беларусь", '$ffio' => "Александр Сергеевич Буров", '$sum_frl' => num2strEx($sum_frl, 'рублей Российской Федерации'), '$sum_emp' => num2strEx($sum_emp, 'рублей Российской Федерации'), '$tz_descr' => $descr_tz, '$work_time' => '3 дня на этап', '$work_type' => 'Промежуточной стоимости Работы', '$work_cost' => num2strEx($work_cost, 'рублей Российской Федерации'), '$is_arb_emp' => false, '$is_arb_frl' => false, '$user_arb' => 'Заказчик', '$result_arb' => 'Результат арбитража вынес потому что не работал такой то человек');
$t = new odt2pdf('arb_frl_soglashenie.odt');
$t->convert($act_new);
$content = $t->Output(NULL, 'S');
$file = new CFile();
//$file->table = 'file_sbr';
$file->path = 'uploader/';
$file->name = basename($file->secure_tmpname($file->path, '.pdf'));
$file->size = strlen($content);
$file->putContent($file->path . $file->name, $content);
//echo strlen($t->output);
Example #2
0
 /**
  * Формирование актов и счет-фактур по данным из pskb_invoice_raw
  * Загрузка документов в сделку.
  * 
  * @param type $data  массив с данными - строка результата запроса из sbr_adm::processInvoiceData
  * @param type $error
  *
  * @return bool
  */
 public static function addInvoice($data, &$error = '')
 {
     $row = $data;
     if (!$row) {
         $error = 'Не найден аккредитив';
         return false;
     }
     if (!trim($row['addr'])) {
         $error = 'Не указан юрадрес';
         //            return false;
     }
     $sbr = sbr_meta::getInstanceLocal($row['emp_id']);
     $sbr->initFromId($row['sbr_id'], false, false, false);
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/odt2pdf.php';
     require_once dirname(__FILE__) . '/num_to_word.php';
     /*
      * Акт на сумму комиссии ВААН
      */
     $replace = array('USER_NAME' => $row['name'], 'ACT_SUM' => number_format($row['sum'], 2, ',', ''), 'NDS_SUM' => number_format($row['sum'] - $row['sum'] / 1.18, 2, ',', ''), 'NO_NDS_SUM' => number_format($row['sum'] / 1.18, 2, ',', ''), 'ACT_NUM' => intval($row['actnum']), 'DOC_NUM' => $sbr->getContractNum(), 'SUM_STR' => num2strEx(floatval($row['sum'])), 'ACT_DATE' => date('d.m.Y', strtotime($row['actdate'])));
     $tpl = 'pskb_close_act.ods';
     $pdf = new odt2pdf($tpl);
     $pdf->convert($replace);
     if (!($file = $sbr->_saveDocFile($pdf->Output(null, 'S')))) {
         $error = 'Ошибка при формировании Акта';
         return false;
     }
     $docs[] = array('file_id' => $file->id, 'status' => sbr::DOCS_STATUS_PUBL, 'access_role' => $row['is_emp'] ? sbr::DOCS_ACCESS_EMP : sbr::DOCS_ACCESS_FRL, 'owner_role' => 0, 'type' => sbr::DOCS_TYPE_PSKB_ACT);
     /*
      * Счет-фактура
      */
     $replace = array('USER_NAME' => $row['name'], 'USER_ADDR' => $row['addr'], 'USER_INN' => $row['inn'] . ($row['kpp'] ? '/' . $row['kpp'] : ''), 'INV_SUM' => number_format($row['sum'], 2, ',', ''), 'NDS_SUM' => number_format($row['sum'] - $row['sum'] / 1.18, 2, ',', ''), 'NO_NDS_SUM' => number_format($row['sum'] / 1.18, 2, ',', ''), 'INV_NUM' => intval($row['invnum']), 'DOC_NUM' => $sbr->getContractNum(), 'INV_DATE' => date('d.m.Y', strtotime($row['invdate'])));
     $tpl = 'pskb_close_invoice.ods';
     $pdf = new odt2pdf($tpl);
     $pdf->convert($replace);
     if (!($file = $sbr->_saveDocFile($pdf->Output(null, 'S')))) {
         $error = 'Ошибка при формировании счета-фактуры';
         return false;
     }
     $docs[] = array('file_id' => $file->id, 'status' => sbr::DOCS_STATUS_PUBL, 'access_role' => $row['is_emp'] ? sbr::DOCS_ACCESS_EMP : sbr::DOCS_ACCESS_FRL, 'owner_role' => 0, 'type' => sbr::DOCS_TYPE_FACTURA);
     foreach ($docs as $doc) {
         $ok = $sbr->addDocR($doc);
     }
     return true;
 }
Example #3
0
                   </table:table-cell>
                   <table:table-cell office:value-type="string">
                     <text:p>An online map</text:p>
                   </table:table-cell>
                   <table:table-cell office:value-type="string">
                     <text:p>
                       <text:a xlink:type="simple" xlink:href="http://maps.google.com/"
                         >http://maps.google.com</text:a>
                     </text:p>
                   </table:table-cell>
                 </table:table-row>
               </table:table>
';
*/
$descr_tz = '
               111
               <text:h text:outline-level="1"> A Table (Heading 1)</text:h>
               <text:p>222</text:p>
               <text:a xlink:type="simple" xlink:href="http://www.flickr.com/services/api/">http://www.flickr.com/services/api/</text:a>
';
$act_new = array('$sbr_num' => 'СБР-109-Б/О-1', '$date_act' => '12.09.2012', '$date_sbr' => '12.09.2012', '$efio' => 'Резидент Республики Беларусь', '$ffio' => 'Александр Сергеевич Буров', '$sum_frl' => num2strEx($sum_frl, 'рублей Российской Федерации'), '$sum_emp' => num2strEx($sum_emp, 'рублей Российской Федерации'), '$tz_descr' => $descr_tz, '$work_time' => '3 дня на этап', '$work_type' => 'Промежуточной стоимости Работы', '$work_cost' => num2strEx($work_cost, 'рублей Российской Федерации'), '$is_arb_emp' => false, '$is_arb_frl' => false, '$user_arb' => 'Заказчик', '$result_arb' => 'Результат арбитража вынес потому что не работал такой то человек');
$t = new odt2pdf('arb_frl_soglashenie.odt');
$t->convert($act_new);
$content = $t->Output(null, 'S');
$file = new CFile();
//$file->table = 'file_sbr';
$file->path = 'uploader/';
$file->name = basename($file->secure_tmpname($file->path, '.pdf'));
$file->size = strlen($content);
$file->putContent($file->path . $file->name, $content);
//echo strlen($t->output);
Example #4
0
 /**
  * Генерирует PDF-документ на основании XML-файла.
  *
  * @param string $file          Файл для обработки
  * @param mixed $replacements   массив для подстановки значений
  * @return FPDF сформированный документ PDF или FALSE в случае неудачи
  */
 public static function xml2pdf($file, $replacements = false)
 {
     // Новая обработка PDF
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/odt2pdf.php';
     $tpl = basename($file, ".xml") . ".odt";
     $t = new odt2pdf($tpl);
     $t->convert($replacements);
     return $t;
     /**
      * @deprecated
      */
     if (!file_exists($file)) {
         return false;
     }
     require_once dirname(__FILE__) . '/fpdf/fpdf.php';
     define('FPDF_FONTPATH', dirname(__FILE__) . '/fpdf/font/');
     if (is_array($replacements)) {
         foreach ($replacements as &$val) {
             $val = htmlspecialchars_decode($val, ENT_QUOTES);
         }
     }
     $replacements['$tab'] = '    ';
     $xml = new DOMDocument('1.0', 'windows-1251');
     $xml->load($file);
     $pdf = new FPDF();
     // Загружаем шрифты
     $pdf->AddFont('ArialMT', '', 'c9bb7ceca00657d007d343f4e34b71a8_arial.php');
     $pdf->AddFont('Arial-BoldMT', '', '9cb9fc616ba50d7ecc7b816984f2ffda_arialbd.php');
     $pdf->AddFont('TimesNewRomanPSMT', '', '5f37f1915715e014ee2254b95c0b6cab_times.php');
     $pdf->AddFont('TimesNewRomanPS-BoldMT', '', 'e07f6c05a47ebec50a80f29789c7f1f6_timesbd.php');
     /*
             Загружаем XML-документ и читаем из него основные параметры лоя итогового PDF-документа
     */
     $root = $xml->documentElement;
     $title = $root->getAttribute('title') ? iconv('windows-1251', 'utf-8', $root->getAttribute('title')) : '';
     // заголовок документа
     $author = $root->getAttribute('author');
     // автор
     $margin_left = $root->getAttribute('margin-left') ? $root->getAttribute('margin-left') : 20;
     // отступ слева
     $margin_right = $root->getAttribute('margin-right') ? $root->getAttribute('margin-right') : 20;
     // отступ справа
     $margin_top = $root->getAttribute('margin-top') ? $root->getAttribute('margin-top') : 20;
     // отступ сверху
     $font_name = $root->getAttribute('font-name') ? $root->getAttribute('font-name') : 'ArialMT';
     // дефолтный шрифт (имя)
     $font_size = (int) $root->getAttribute('font-size') ? (int) $root->getAttribute('font-size') : 10;
     // дефолтный шрифт (размер)
     $text_width = (int) $root->getAttribute('width') ? (int) $root->getAttribute('width') : 170;
     // ширина печатной области документа
     $paragraph_indent = (int) $root->getAttribute('paragraph-indent') ? (int) $root->getAttribute('paragraph-indent') : 0;
     // отступ между параграфами
     $printable = $pdf->h - $margin_top - 20;
     $pdf->SetTitle($title, true);
     $pdf->SetAuthor($author);
     $pdf->SetLeftMargin($margin_left);
     $pdf->SetRightMargin($margin_right);
     $pdf->SetTopMargin($margin_top);
     $pdf->AddPage();
     $pdf->SetFont($font_name, '', $font_size);
     $pdf->SetX($margin_left);
     $locates = array();
     // разбор XML-документа
     $xpath = new DOMXPath($xml);
     $scale = $xpath->query('/document/page/*');
     if ($scale->length) {
         $footer = $xpath->query('//footer');
         $footer = $footer->length ? $footer->item(0) : NULL;
         $no_brake = $xpath->query('//nobreak');
         $no_brake = $no_brake->length ? TRUE : FALSE;
         // если есть теги <nobreak>, то расставляем разрывы страниц руками
         if ($no_brake) {
             $pdf->SetAutoPageBreak(false);
         }
         $last_y = 0;
         $pages = array();
         foreach ($scale as $node) {
             $last_y = intval($pdf->y);
             if ($node->tagName == 'nobreak' && $node->getAttribute('start')) {
                 $max_h = $last_y;
                 $loc_offset = 0;
                 foreach ($xpath->query('//cell|locate[(following::nobreak)]') as $i => $nd) {
                     if ($nd->tagName == 'nobreak' && $node->getAttribute('end')) {
                         break;
                     }
                     $_h = $nd->getAttribute('height');
                     if ($i > 0 && !$loc_offset) {
                         $_h = 0;
                     }
                     $max_h += intval($_h);
                     $loc_offset = $nd->getAttribute('x_offset');
                 }
                 $max_h += $last_y;
                 if ($max_h > $printable) {
                     if ($footer) {
                         $pdf->SetY(-20);
                         $pdf->SetFont($font_name, '', 9);
                         $pdf->Cell(0, 10, self::prepareNodeText($footer), 0, 0, 'C');
                         $pages[] = $pdf->PageNo();
                     }
                     $pdf->AddPage();
                 }
             }
             if ($no_brake && $pdf->y > $printable) {
                 if ($footer && !in_array($pdf->PageNo(), $pages)) {
                     $pdf->SetY(-20);
                     $pdf->SetFont($font_name, '', 9);
                     $pdf->Cell(0, 10, self::prepareNodeText($footer), 0, 0, 'C');
                     $pages[] = $pdf->PageNo();
                 }
                 $pdf->AddPage();
             }
             if (!(int) $node->getAttribute('keep-pos')) {
                 $pdf->SetX($margin_left);
             }
             // сброс позиции по X-оси если <node keep-pos="0" или не задан
             if ((int) $node->getAttribute('offset-left')) {
                 $pdf->SetX((int) $node->getAttribute('offset-left') + $margin_left);
             }
             if ($node->tagName == 'text') {
                 // вывод строки
                 if ($node->getAttribute('font-name')) {
                     $font_name = $node->getAttribute('font-name');
                 }
                 if ((int) $node->getAttribute('font-size')) {
                     $font_size = (int) $node->getAttribute('font-size');
                 }
                 $align = $node->getAttribute('align') ? strtoupper($node->getAttribute('align')) : 'C';
                 $width = (int) $node->getAttribute('width') ? (int) $node->getAttribute('width') : $text_width;
                 $height = (int) $node->getAttribute('height') ? (int) $node->getAttribute('height') : 5;
                 $border = $node->getAttribute('border') ? strtoupper($node->getAttribute('border')) : 0;
                 $text = self::prepareNodeText($node, $replacements);
                 if (!($color = $node->getAttribute('color'))) {
                     $color = '000000';
                 }
                 $pdf->SetTextColor(hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));
                 $pdf->SetFont($font_name, '', $font_size);
                 $skip_empty = (int) $node->getAttribute('skip-empty') ? (int) $node->getAttribute('skip-empty') : 0;
                 if ((int) $skip_empty) {
                     if (!trim($text)) {
                         continue;
                     }
                 }
                 $pdf->Cell($width, $height, trim($text), $border, 1, $align);
             } elseif ($node->tagName == 'paragraph') {
                 // выводит многострочный текстовый блок, можно указывать тип выравнивания текста (L, J, R, C)
                 if (($show_if = $node->getAttribute('show-if')) && !$replacements[$show_if]) {
                     continue;
                 }
                 if ($node->getAttribute('font-name')) {
                     $font_name = $node->getAttribute('font-name');
                 }
                 if ((int) $node->getAttribute('font-size')) {
                     $font_size = (int) $node->getAttribute('font-size');
                 }
                 $align = $node->getAttribute('align') ? strtoupper($node->getAttribute('align')) : 'J';
                 $width = (int) $node->getAttribute('width') ? (int) $node->getAttribute('width') : $text_width;
                 $height = (int) $node->getAttribute('height') ? (int) $node->getAttribute('height') : 5;
                 $border = $node->getAttribute('border') ? strtoupper($node->getAttribute('border')) : 0;
                 $keep_text_wrap = (int) $node->getAttribute('keep-text-wrap') ? (int) $node->getAttribute('keep-text-wrap') : 0;
                 $text = self::prepareNodeText($node, $replacements, $keep_text_wrap);
                 if (!($color = $node->getAttribute('color'))) {
                     $color = '000000';
                 }
                 $pdf->SetTextColor(hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));
                 $pdf->SetFont($font_name, '', $font_size);
                 $skip_empty = (int) $node->getAttribute('skip-empty') ? (int) $node->getAttribute('skip-empty') : 0;
                 if ((int) $skip_empty) {
                     if (!trim($text)) {
                         continue;
                     }
                 }
                 $pdf->MultiCell($width, $height, $text, $border, $align);
                 if ($paragraph_indent) {
                     $pdf->Ln($paragraph_indent);
                 }
             } elseif ($node->tagName == 'ln') {
                 // перевод строки
                 $height = (int) $node->getAttribute('height') ? (int) $node->getAttribute('height') : 5;
                 $pdf->Ln($height);
             } elseif ($node->tagName == 'cell') {
                 // рисует ячейку
                 if ($node->getAttribute('font-name')) {
                     $font_name = $node->getAttribute('font-name');
                 }
                 if ((int) $node->getAttribute('font-size')) {
                     $font_size = (int) $node->getAttribute('font-size');
                 }
                 $align = $node->getAttribute('align') ? strtoupper($node->getAttribute('align')) : 'J';
                 $width = (int) $node->getAttribute('width') ? (int) $node->getAttribute('width') : $text_width;
                 $height = (int) $node->getAttribute('height') ? (int) $node->getAttribute('height') : 5;
                 $border = $node->getAttribute('border') != '' ? (int) $node->getAttribute('border') : 1;
                 $keep_text_wrap = (int) $node->getAttribute('keep-text-wrap') ? (int) $node->getAttribute('keep-text-wrap') : 0;
                 $text = self::prepareNodeText($node, $replacements, $keep_text_wrap);
                 if (!($color = $node->getAttribute('color'))) {
                     $color = '000000';
                 }
                 $pdf->SetTextColor(hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));
                 $pdf->SetFont($font_name, '', $font_size);
                 $pdf->Cell($width, $height, $text, $border, 0, $align);
             } elseif ($node->tagName == 'locate') {
                 // перемещает указатель в определенную позицию в документе
                 $x = $node->getAttribute('x') ? $node->getAttribute('x') : 0;
                 $y = $node->getAttribute('y') ? $node->getAttribute('y') : 0;
                 $x_offset = (int) $node->getAttribute('x_offset') ? (int) $node->getAttribute('x_offset') : 0;
                 $y_offset = (int) $node->getAttribute('y_offset') ? (int) $node->getAttribute('y_offset') : 0;
                 if (strpos($x, '@') !== false) {
                     $x = $locates['x'][$x] + $x_offset;
                 }
                 if (strpos($y, '@') !== false) {
                     $y = $locates['y'][$y] + $y_offset;
                 }
                 if (!$x) {
                     $x = $pdf->GetX() + $x_offset;
                 }
                 if (!$y) {
                     $y = $pdf->GetY() + $y_offset;
                 }
                 $pdf->SetXY($x, $y);
             } elseif ($node->tagName == 'fix-locate') {
                 // перемещает указатель в определенную позицию в документе
                 if ($x = $node->getAttribute('x')) {
                     $locates['x'][$x] = $pdf->GetX();
                 }
                 if ($y = $node->getAttribute('y')) {
                     $locates['y'][$y] = $pdf->GetY();
                 }
             } elseif ($node->tagName == 'line') {
                 // рисует простую горизонтальную линию
                 $x = (int) $node->getAttribute('x') ? (int) $node->getAttribute('x') : $margin_left;
                 $y = (int) $node->getAttribute('y') ? (int) $node->getAttribute('y') : $margin_top;
                 $len = (int) $node->getAttribute('len') ? (int) $node->getAttribute('len') : $text_width;
                 if ($x) {
                     $pdf->setX($x);
                 }
                 if ($y) {
                     $pdf->setY($y);
                 }
                 $pdf->Cell($len, 0, '', 1);
             } elseif ($node->tagName == 'newpage') {
                 //новая страница и перевод указателя на нее
                 $pdf->AddPage();
             }
         }
     }
     return $pdf;
 }
Example #5
0
 /**
  * Генерация файла по шаблону ODT
  * и затем конвертация в PDF
  * 
  * @return boolean|\CFile
  */
 public function generate()
 {
     $pdf = new odt2pdf($this->template);
     $pdf->setFolder(ABS_PATH . $this->template_path);
     $pdf->convert($this->data);
     $content = $pdf->output(NULL, 'S');
     $len = strlen($content);
     if (!$len) {
         return false;
     }
     $file = new CFile();
     $file->path = $this->getFilePath();
     $file->table = $this->file_table;
     $file->size = $len;
     $file->src_id = $this->file_src_id;
     $file->name = basename($file->secure_tmpname($file->path, '.pdf'));
     $file->original_name = change_q_x($this->file_original_name);
     if (!$file->putContent($file->path . $file->name, $content)) {
         return false;
     }
     Events::trigger('generate_file', $file);
     return $file;
 }
Example #6
0
 /**
  * НЕ ИСПОЛЬЗОВАТЬ - УСТАРЕЛ СМ generateInvoice2.
  * 
  * Генерация счета
  *
  * @todo: может перенести генерацию в очереди?
  * @todo: но тогда нужно организовать обратную связь.
  * 
  * @param type $user_info
  *
  * @return bool|\CFile
  */
 public function generateInvoice($user_info)
 {
     extract($this->options);
     $file = new CFile();
     $file_path = $this->getFilePath();
     $reserve_id = @$this->data['reserve_id'];
     if (!$file_path || !$reserve_id || empty($this->data)) {
         return false;
     }
     $data = $this->getCheckByReserveId($reserve_id);
     if (isset($data['payed_date']) && !empty($data['payed_date'])) {
         return false;
     }
     if (isset($data['check_file_id']) && $data['check_file_id'] > 0) {
         $file->Delete($data['check_file_id']);
     }
     if (!$data) {
         $data = array();
     }
     $this->data = array_merge($data, $this->data, $user_info);
     $data = $this->data;
     $bill_num = sprintf($bill_num_format, $data['reserve_id']);
     $data['bill_num'] = $bill_num;
     $data['date'] = date_text($data['date'], 'd');
     $data['price_txt'] = num2str(intval($data['price']));
     $data['price'] = number_format($data['price'], 2, ',', '');
     $data['title'] = sprintf($check_title, $bill_num);
     foreach ($data as $key => $value) {
         $data['$' . $key] = $value;
         unset($data[$key]);
     }
     $pdf = new odt2pdf($invoice_template);
     $pdf->setFolder(ABS_PATH . $templates_path);
     $pdf->convert($data);
     $content = $pdf->output(null, 'S');
     $len = strlen($content);
     if (!$len) {
         return false;
     }
     $file->path = $file_path;
     $file->table = $table_files;
     $file->size = $len;
     $file->src_id = $src_id;
     $file->name = basename($file->secure_tmpname($file->path, '.pdf'));
     $file->original_name = change_q_x(sprintf($check_org_filename, $bill_num));
     if (!$file->putContent($file->path . $file->name, $content)) {
         return false;
     }
     $this->data['check_file_id'] = $file->id;
     return $this->addCheck() ? $file : false;
 }