Categories > TinyButStrong general >

thank you, Skrol, But, the last total does not show

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Valterci
Date: 2006-10-26
Time: 16:58

thank you, Skrol, But, the last total does not show

Hi Skrol,
Its solution is excellent. But, the last total does not show. Or either, example: if I have 5 values(totals), shows 4 and 5º does not show.
It can help me?

http://www.tinybutstrong.com/forum.php?msg_id=6584
By: Skrol29
Date: 2006-10-26
Time: 17:44

Re: thank you, Skrol, But, the last total does not show

Can you send to me a snippet of you template and a var_export() of the data just before the MergeBlock() ?
By: Valterci
Date: 2006-10-26
Time: 18:09

Re: thank you, Skrol, But, the last total does not show

<table border='1' align="center" width="778px" class="bordasimples">
  <tr bgcolor="#FFFFFF">
    <td colspan="10"><div align="center"><b>C A I X A</b></div></td>
  </tr>
  <tr bgcolor="#CACACA">
    <td colspan="10"><div align="center"> ENTRADAS DE CAIXA CONSOLIDADAS DO PERÍODO DE [var.per_ini] ATÉ [var.per_fim]</div></td>
<tr><td colspan="10">[blk;block=tr;headergrp=data;ondata=f_total]</td></tr>
<tr bgcolor="#FFFFFF">
   <td  width="100"><div align="left">Data<br />[var.data_all;onformat=f_seq2;frm='dd/mm';block=td]</div></td>
    <td width="100"><div align="center"><strong>[blk_1.moeda;block=td]</strong><br>
        <span>[blk_1.valor;frm='000.000,00';block=td]</span>
      </div></td>
    <td  width="100"><div align="center"><strong>[blk_2.moeda;block=td]</strong><br>
        <span>[blk_2.valor;frm='000.000,00';block=td]</span>
      </div></td>
    <td  width="100"><div align="center"><strong>[blk_3.moeda;block=td]</strong><br>
        <span>[blk_3.valor;frm='000.000,00';block=td]</span>
      </div></td>
    <td  width="100"><div align="center"><strong>[blk_4.moeda;block=td]</strong><br>
        <span>[blk_4.valor;frm='000.000,00';block=td]</span>
      </div></td>
    <td  width="100"><div align="center"><strong>[blk_5.moeda;block=td]</strong><br>
        <span>[blk_5.valor;frm='000.000,00';block=td]</span>
      </div></td>
    <td  width="100"><div align="center"><strong>[blk_6.moeda;block=td]</strong><br>
        <span>[blk_6.valor;frm='000.000,00';block=td]</span>
      </div></td>
     <td  width="100"><div align="center"><strong>[blk_7.moeda;block=td]</strong><br>
        <span>[blk_7.valor;frm='000.000,00';block=td]</span>
      </div></td>
     <td  width="100"><div align="center"><strong>[blk_8.moeda;block=td]</strong>
        <span>[blk_8.valor;frm='000.000,00';block=td]</span>
      </div></td>
   <td  width="100"><div align="right">Total<br>
        <span><strong>[var.tot_all;onformat=f_seq;frm='000.000,00';block=td]</strong></span></div>
      [blk;block=tr;serial]</td>
  </tr>

<tr>
<td colspan="10" align="right">Total >>&nbsp;&nbsp;&nbsp;<b>[var.tot_2;frm='000.000,00';block=td]</b></td>
</tr>
</table>



my function:
-----------
function f_total($Name,&$CurrRec,$RecNum) {
  global $save_data, $tot_1, $tot_2, $tot_all, $data_all;
  if (!isset($save_data)) {
  //$tot_1 += $CurrRec['valor'];
    $save_data = '';
    $tot_all = array();
  };
   //$tot_all[] = $tot_1;
  if ($save_data!=$CurrRec['data']){
   // $tot_all[] = $tot_1;
    if (isset($tot_1)) $tot_all[] = $tot_1;
    $tot_1 = 0;
    $save_data= $CurrRec['data'];
   $data_all[] = $save_data;
   // echo $tot_all;
  };
  // Calculate totals
  $tot_1 += $CurrRec['valor'];
  $tot_2 += $CurrRec['valor'];
  // Save into the current record
// $CurrRec['tot_1'] = $tot_1;
};
function f_seq($FieldName,&$CurrVal) {
  global $tot_id, $tot_all;
  if (!isset($tot_id)) $tot_id = 0;
  $CurrVal = $tot_all[$tot_id];
  $tot_id++;
//echo $i[1];

};
function f_seq2($FieldName,&$CurrVal) {
  global $data_id,  $data_all;
  if (!isset($data_id)) $data_id = 0;
  $CurrVal = $data_all[$data_id];
  $data_id++;
//echo $i[1];
};




my sql:
--------
$sql =" SELECT "
." cxa_origem.descricao as origem, "
." cxa_tipo.descricao as tipo, "
." cxa_moeda.descricao as moeda, "
." SUM(cxa_caixa.valor) as valor, "
." cxa_caixa.data as data"
." FROM cxa_caixa "
." INNER JOIN cxa_origem ON cxa_caixa.id_origem=cxa_origem.id "
." INNER JOIN cxa_moeda ON cxa_caixa.id_moeda=cxa_moeda.id "
." INNER JOIN cxa_tipo ON cxa_caixa.id_tipo=cxa_tipo.id "
." WHERE cxa_caixa.data>='".datform_my($per_ini)."'"
." AND cxa_caixa.data<='".datform_my($per_fim)."'"
." GROUP BY data,cxa_moeda.descricao"
." ORDER BY data DESC,moeda";


By: Valterci
Date: 2006-10-26
Time: 18:18

Re: thank you, Skrol, But, the last total does not show

is this show:


C A I X A
ENTRADAS DE CAIXA CONSOLIDADAS DO PERÍODO DE 22/10/2006 ATÉ 28/10/2006

Data
26/10 Dinheiro
33,73  Visa
35,00 




  Total
68,73   --- THIS OK

Data
25/10 Cheque a Vista
19,90  Credicard
71,85  Dinheiro
239,08  Não definida
49,15  RedeShop
2,99  Visa
75,00  VisaEletron
48,90  
Total
506,87   --- THIS OK

Data
24/10 Cheque Pré
58,49  Dinheiro
214,09  Não definida
47,80  RedeShop
19,30  Visa
9,90 

  Total
349,58  --- THIS OK

Data
23/10 Dinheiro
223,99  Não definida
65,95  Visa
65,50  VisaEletron
8,90 
 
  Total   ??????   .......... THIS LINE IS THE PROBLEM......(THE LAST LINE)

Total >>   1.289,52  --- THIS OK
By: Valterci
Date: 2006-10-26
Time: 18:39

Re: thank you, Skrol, But, the last total does not show

I its that the problem is here in the function, the last line is being rejected, however I do not obtain to find the solution.

It can help me?

function f_total($Name,&$CurrRec,$RecNum) {
  global $save_data, $tot_1, $tot_2, $tot_all, $data_all, $data_fim;
  if (!isset($save_data)) {

    $save_data = '';
    $tot_all = array();
  };
  .................................
  if ($save_data!=$CurrRec['data']){    ///......in de last line $CurrRec['data'] not change...

    if (isset($tot_1)) $tot_all[] = $tot_1;
    $tot_1 = 0;
    $save_data= $CurrRec['data'];
   $data_all[] = $save_data;
  };
  ................................

// Calculate totals
  $tot_1 += $CurrRec['valor'];
  $tot_2 += $CurrRec['valor'];
};
By: Valterci
Date: 2006-10-27
Time: 12:46

Re: thank you, Skrol, But, the last total does not show

Hi Skrol

Help me.
By: Skrol29
Date: 2006-10-27
Time: 13:15

Re: thank you, Skrol, But, the last total does not show

Hi Valteci,

Thank you for providing your snippet, it helps to reproduce the problem.
As you guess I do what I can, with my own job obligations and personal time. I'm sorry if it doesn't go as fast I you wish.
Your problem is more a algorithmic problem than a TBS problem now.

If you add
if (isset($tot_1)) $tot_all[] = $tot_1;
just after the $TBS->MergeBlock('blk',...)
then it should run correctly. The last total was not saved in the global array because f_total() saves totals only when a new group is identified.

It should be ok now, but take care that the algorithm will not be available if a group of date is displayed on several rows.

By the way, I'm studying a plug-in to display data by a pivot table. Which is closed to what you're trying to do.
By: Valterci
Date: 2006-10-27
Time: 13:44

Re: thank you, Skrol, But, the last total does not show

Thank you Skrol, this solution is ok.