function render_pdf()
 {
     // start the PDF object
     $template_pdf = new template_engine_latex();
     // load template
     $template_pdf->prepare_load_template("templates/latex/report_incomestatement.tex");
     /*
     	Fetch data + define fields
     */
     // company logo
     $template_pdf->prepare_add_file("company_logo", "png", "COMPANY_LOGO", 0);
     // mode
     $template_pdf->prepare_add_field("mode", $this->mode);
     // dates
     $template_pdf->prepare_add_field("date_start", time_format_humandate($this->date_start));
     $template_pdf->prepare_add_field("date_end", time_format_humandate($this->date_end));
     $template_pdf->prepare_add_field("date_created", time_format_humandate());
     // totals
     $template_pdf->prepare_add_field("amount_total_income", $this->data_totals["income"]);
     $template_pdf->prepare_add_field("amount_total_expense", $this->data_totals["expense"]);
     $template_pdf->prepare_add_field("amount_total_final", $this->data_totals["final"]);
     // income data
     $structure_main = NULL;
     foreach ($this->data_income as $itemdata) {
         $structure = array();
         $structure["name_chart"] = $itemdata["code_chart"] . " -- " . $itemdata["description"];
         $structure["amount"] = format_money($itemdata["amount"]);
         $structure_main[] = $structure;
     }
     $template_pdf->prepare_add_array("table_income", $structure_main);
     // income data
     $structure_main = NULL;
     foreach ($this->data_expense as $itemdata) {
         $structure = array();
         $structure["name_chart"] = $itemdata["code_chart"] . " -- " . $itemdata["description"];
         $structure["amount"] = format_money($itemdata["amount"]);
         $structure_main[] = $structure;
     }
     $template_pdf->prepare_add_array("table_expense", $structure_main);
     /*
     	Output PDF
     */
     // perform string escaping for latex
     $template_pdf->prepare_escape_fields();
     // fill template
     $template_pdf->prepare_filltemplate();
     // generate PDF output
     $template_pdf->generate_pdf();
     // display PDF
     print $template_pdf->output;
     //		foreach ($template_pdf->processed as $line)
     //		{
     //			print $line;
     //		}
 }
Exemple #2
0
 function render_table_pdf($template = NULL)
 {
     log_debug("table", "Executing render_table_pdf()");
     if (!$template) {
         $template = "amberphplib_table_default.tex";
     }
     // calculate all the totals and prepare processed values
     if (!isset($this->data_render)) {
         $this->render_table_prepare();
     }
     // start the PDF object
     $template_pdf = new template_engine_latex();
     // load template
     $template_pdf->prepare_load_template("templates/latex/{$template}");
     /*
     	Generate PDF Template
     */
     log_write("debug", "table", "Generating custom PDF template latex...");
     // init values
     $output_tabledata = array();
     // fetch the number of columns so we can draw the latex table
     $col_num = count($this->columns);
     // work out the number columns with the totals
     $col_num_with_total = $col_num;
     if ($this->total_rows) {
         $col_num_with_total++;
     }
     // fetch column widths (float of percent of one)
     $col_width = 0.9 / $col_num_with_total;
     $output_tabledata[] = '\\noindent \\begin{longtable}{';
     for ($i = 0; $i < $col_num_with_total; $i++) {
         $output_tabledata[] = '>{\\centering}p{' . $col_width . '\\columnwidth}';
     }
     $output_tabledata[] = '}\\cline{1-' . $col_num_with_total . '}';
     // define column headers
     for ($i = 0; $i < $col_num; $i++) {
         $output_tabledata[] = '\\textbf{' . $this->render_columns[$this->columns[$i]] . '}';
         if ($i != $col_num - 1) {
             $output_tabledata[] = " & ";
         }
     }
     // add header for total
     if ($this->total_rows) {
         $output_tabledata[] = ' & \\textbf{Total} ';
     }
     $output_tabledata[] = '\\endfirsthead \\cline{1-' . $col_num_with_total . '}';
     // table foreach loop
     $output_tabledata[] = '%% foreach table\\_data';
     $line = "";
     $line .= '%% ';
     for ($i = 0; $i < $col_num; $i++) {
         $line .= '(column\\_' . $i . ')';
         if ($i != $col_num - 1) {
             $line .= " & ";
         }
     }
     if ($this->total_rows) {
         $line .= ' & (column\\_total) ';
     }
     $line .= '\\tabularnewline';
     $output_tabledata[] = $line;
     $output_tabledata[] = '%% end';
     // display totals for columns (if required)
     if ($this->total_columns) {
         $output_tabledata[] = '\\cline{1-' . $col_num_with_total . '}';
         $line = "";
         for ($i = 0; $i < $col_num; $i++) {
             $line .= '(column\\_total\\_' . $i . ')';
             if ($i != $col_num - 1) {
                 $line .= " & ";
             }
         }
         if ($this->total_rows) {
             $line .= ' & (column\\_total\\_total) ';
         }
         $line .= '\\tabularnewline';
         $output_tabledata[] = $line;
     }
     // end data table
     $output_tabledata[] = '\\cline{1-' . $col_num_with_total . '}';
     $output_tabledata[] = '\\end{longtable}';
     /*
     	Write changes to PDF template in memory
     */
     log_write("debug", "table", "Writing custom PDF template in memory");
     $template_new = array();
     foreach ($template_pdf->template as $line_orig) {
         if ($line_orig == "%% TABLE_DATA\n") {
             foreach ($output_tabledata as $line_new) {
                 $template_new[] = $line_new . "\n";
             }
         } else {
             $template_new[] = $line_orig;
         }
     }
     // overwrite memory version with processed version
     $template_pdf->template = $template_new;
     unset($template_new);
     /*
     	Fill Template
     */
     // company logo
     $template_pdf->prepare_add_file("company_logo", "png", "COMPANY_LOGO", 0);
     // table name
     $template_pdf->prepare_add_field("table_name", lang_trans($this->tablename));
     // table options
     $structure_main = NULL;
     // add date created option
     $structure = array();
     $structure["option_name"] = lang_trans("date_created");
     $structure["option_value"] = time_format_humandate();
     $structure_main[] = $structure;
     foreach (array_keys($this->filter) as $filtername) {
         $structure = array();
         $structure["option_name"] = lang_trans($filtername);
         switch ($this->filter[$filtername]["type"]) {
             case "date":
                 $structure["option_value"] = time_format_humandate($this->filter[$filtername]["defaultvalue"]);
                 break;
             case "timestamp":
                 $structure["option_value"] = time_format_humandate($this->filter[$filtername]["defaultvalue"]);
                 break;
             default:
                 // for all other types of filters, just display raw
                 if ($this->filter[$filtername]["defaultvalue"]) {
                     $structure["option_value"] = $this->filter[$filtername]["defaultvalue"];
                 } else {
                     $structure["option_value"] = "---";
                 }
                 break;
         }
         $structure_main[] = $structure;
     }
     $template_pdf->prepare_add_array("table_options", $structure_main);
     // main table data rows
     $structure_main = NULL;
     for ($i = 0; $i < $this->data_num_rows; $i++) {
         $structure = array();
         // add data for all selected columns
         for ($j = 0; $j < count($this->columns); $j++) {
             $structure["column_{$j}"] = $this->data_render[$i]["" . $this->columns[$j] . ""];
         }
         // optional: row totals column
         if ($this->total_rows) {
             $structure["column_total"] = $this->data_render[$i]["total"];
         }
         $structure_main[] = $structure;
     }
     $template_pdf->prepare_add_array("table_data", $structure_main);
     // totals
     if ($this->total_columns) {
         for ($j = 0; $j < count($this->columns); $j++) {
             $column = $this->columns[$j];
             if (in_array($column, $this->total_columns)) {
                 $template_pdf->prepare_add_field('column_total_' . $j, $this->data_render["total"][$column]);
             } else {
                 $template_pdf->prepare_add_field('column_total_' . $j, "");
             }
         }
         // optional: totals for rows
         if ($this->total_rows) {
             $template_pdf->prepare_add_field('column_total_total', $this->data_render["total"]["total"]);
         }
         print "\n";
     }
     /*
     	Output PDF
     */
     // perform string escaping for latex
     $template_pdf->prepare_escape_fields();
     // fill template
     $template_pdf->prepare_filltemplate();
     // generate PDF output
     $template_pdf->generate_pdf();
     // display PDF
     print $template_pdf->output;
     //		print_r($template_pdf->template);
     //		print_r($template_pdf->processed);
     //		print_r($template_pdf->data_array);
 }
 function render_pdf()
 {
     // start the PDF object
     $template_pdf = new template_engine_latex();
     // load template
     $template_pdf->prepare_load_template("templates/latex/report_balancesheet.tex");
     /*
     	Fill in template fields
     */
     // company logo
     $template_pdf->prepare_add_file("company_logo", "png", "COMPANY_LOGO", 0);
     // mode
     $template_pdf->prepare_add_field("mode", $this->mode);
     // dates
     $template_pdf->prepare_add_field("date_end", time_format_humandate($this->date_end));
     $template_pdf->prepare_add_field("date_created", time_format_humandate());
     // totals
     $template_pdf->prepare_add_field("amount_total_current_earnings", $this->data_totals["current_earnings"]);
     $template_pdf->prepare_add_field("amount_total_assets", $this->data_totals["assets"]);
     $template_pdf->prepare_add_field("amount_total_liabilities", $this->data_totals["liabilities"]);
     $template_pdf->prepare_add_field("amount_total_equity", $this->data_totals["equity"]);
     $template_pdf->prepare_add_field("amount_total_liabilities_and_equity", $this->data_totals["liabilities_and_equity"]);
     // asset data
     $structure_main = NULL;
     foreach ($this->data_assets as $itemdata) {
         $structure = array();
         $structure["name_chart"] = $itemdata["code_chart"] . " -- " . $itemdata["description"];
         $structure["amount"] = format_money($itemdata["amount"]);
         $structure_main[] = $structure;
     }
     $template_pdf->prepare_add_array("table_assets", $structure_main);
     // liabilities data
     $structure_main = NULL;
     foreach ($this->data_liabilities as $itemdata) {
         $structure = array();
         $structure["name_chart"] = $itemdata["code_chart"] . " -- " . $itemdata["description"];
         $structure["amount"] = format_money($itemdata["amount"]);
         $structure_main[] = $structure;
     }
     $template_pdf->prepare_add_array("table_liabilities", $structure_main);
     // equity data
     $structure_main = NULL;
     foreach ($this->data_equity as $itemdata) {
         $structure = array();
         $structure["name_chart"] = $itemdata["code_chart"] . " -- " . $itemdata["description"];
         $structure["amount"] = format_money($itemdata["amount"]);
         $structure_main[] = $structure;
     }
     $template_pdf->prepare_add_array("table_equity", $structure_main);
     /*
     	Output PDF
     */
     // perform string escaping for latex
     $template_pdf->prepare_escape_fields();
     // fill template
     $template_pdf->prepare_filltemplate();
     // generate PDF output
     $template_pdf->generate_pdf();
     // display PDF
     print $template_pdf->output;
     //		foreach ($template_pdf->processed as $line)
     //		{
     //			print $line;
     //		}
 }
 function render_pdf()
 {
     // prepare table data
     $this->obj_table->render_table_prepare();
     // start the PDF object
     $template_pdf = new template_engine_latex();
     // load template
     $template_pdf->prepare_load_template("templates/latex/report_trialbalance.tex");
     /*
     	Fetch data + define fields
     */
     // company logo
     $template_pdf->prepare_add_file("company_logo", "png", "COMPANY_LOGO", 0);
     // dates
     $template_pdf->prepare_add_field("date_start", time_format_humandate($this->date_start));
     $template_pdf->prepare_add_field("date_end", time_format_humandate($this->date_end));
     $template_pdf->prepare_add_field("date_created", time_format_humandate());
     // totals
     $template_pdf->prepare_add_field("amount_total_credit", $this->obj_table->data_render["total"]["credit"]);
     $template_pdf->prepare_add_field("amount_total_debit", $this->obj_table->data_render["total"]["debit"]);
     // table rows
     $structure_main = NULL;
     for ($i = 0; $i < $this->obj_table->data_num_rows; $i++) {
         $structure = array();
         $structure["code_chart"] = $this->obj_table->data_render[$i]["code_chart"];
         $structure["description"] = $this->obj_table->data_render[$i]["description"];
         $structure["chart_type"] = $this->obj_table->data_render[$i]["chart_type"];
         $structure["credit"] = $this->obj_table->data_render[$i]["credit"];
         $structure["debit"] = $this->obj_table->data_render[$i]["debit"];
         $structure["balance"] = $this->obj_table->data_render[$i]["total"];
         $structure_main[] = $structure;
     }
     $template_pdf->prepare_add_array("table_data", $structure_main);
     /*
     	Output PDF
     */
     // perform string escaping for latex
     $template_pdf->prepare_escape_fields();
     // fill template
     $template_pdf->prepare_filltemplate();
     // generate PDF output
     $template_pdf->generate_pdf();
     // display PDF
     print $template_pdf->output;
 }