PDF from view with own template

juergen_mueller

DaDaBIK Guru
I tried to create a PDF from a view using an own template. My view contains a number SELECT statements from other tables than the main one.

When I try to use an own PDF template, it does not show any records (dadabik_field MYFIELD dadabik_field), just things like logo and labels I created.

I guess it's not possible (yet) to create PDFs in such an environment.

However, the non-template PDF works as expected but does not really fits my needs.

Best,
Juergen
 

eugenio

Administrator
Staff member
Hello Juergen,
PDF templates do work with Views, a view is seen by DaDaBIK as any other table, so I guess the reason the records are not displayed is something else. Could you give more details?

Best,
 

juergen_mueller

DaDaBIK Guru
Hi Eugenio

The following is the code I use for the view. I started to create a PDF template containing the fields from this view (see second code). The PDF remains empty (apart from the labels and header).
Code:
select `transactions`.`year` AS `Jahr`,round(sum(`transactions`.`expense`) + (select sum(`water`.`garden_water_total`) from `water` where `water`.`year` = 2023),2) AS `Betriebskosten`,(select `flats`.`share` from `flats` where `flats`.`user_id` = 4) AS `Anteil`,(select `flats`.`flat` from `flats` where `flats`.`user_id` = 4) AS `Wohnung`,round((select `flats`.`share` from `flats` where `flats`.`user_id` = 4) * (sum(`transactions`.`expense`) + (select sum(`water`.`garden_water_total`) from `water` where `water`.`year` = 2023)),2) AS `Betrag`,round((select sum(`transactions`.`income`) from `transactions` where `transactions`.`user_id` = 4 and `transactions`.`cost_center_id` = 1),2) AS `Einzahlung`,round((select sum(`transactions`.`income`) from `transactions` where `transactions`.`user_id` = 4 and `transactions`.`cost_center_id` = 1) - (select `flats`.`share` from `flats` where `flats`.`user_id` = 4) * (sum(`transactions`.`expense`) + (select sum(`water`.`garden_water_total`) from `water` where `water`.`year` = 2023)) - (select sum(`water`.`gardenwater_wgeg_eur`) from `water` where `water`.`year` = 2023),2) AS `Differenz` from `transactions` where `transactions`.`cost_center_id` = 1 and `transactions`.`year` = 2023

PDF template:

Code:
<!-- DaDaBIK Template -->

<h1>Abrechnung</h1>
<div class="date"><?php echo 'Berlin, den: '.date('d.m.Y'); ?></div><br>

<table>
<tr><td>Jahr:</td><td>dadabik_field year dadabik_field</td></tr>
<tr><td>Aufwand:</td><td>dadabik_field expense dadabik_field</td></tr>
<tr><td>Anteil:</td><td>dadabik_field share dadabik_field</td></tr>
</table>

</body>
</html>

Maybe I should work with INNER JOINS instead?

Best,

Juergen
 

eugenio

Administrator
Staff member
I think you are not using the correct field names, for example you should use Jahr (because in the view is defined as Jahr) and not year.

Best,
 
Top