/** * Генерация файла по шаблону 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; }
/** * НЕ ИСПОЛЬЗОВАТЬ - УСТАРЕЛ СМ 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; }