SIMITGROUP / phpjasperxml

This is a php wysiwyg report library
BSD 3-Clause "New" or "Revised" License
44 stars 45 forks source link

printWhenExpression not working fine #84

Closed lvsan closed 11 months ago

lvsan commented 2 years ago

HI ,

I have set the printWhenExpression to false which i check the heigh of the brand already = 0 when under protected function drawBand. But when i print the reports, the detail still display with height = 15. I have debug and found out the height for the brandname still = 15 under $this->output->endBand($bandname);

below is the code that still consider as original brand height when i debug.

public function endBand(string $bandname) { $pageno = $this->PageNo(); $columnno = $this->getColumnNo(); if($this->pageOffSetY>0) {
// echo "
end band $bandname have pageOffSetY $this->pageOffSetY
"; $this->lastBandEndY =$this->pageOffSetY; $this->bands[$bandname]['endY'] = $this->pageOffSetY; $this->pageOffSetY=0;

        $this->SetPage($this->getNumPages());
    }
    if(empty($this->pagecolumnoccupation[$pageno]))
    {
        $this->pagecolumnoccupation[$pageno] = [];
    }

    if(empty($this->pagecolumnoccupation[$pageno][$columnno]))
    {
        $this->pagecolumnoccupation[$pageno][$columnno]=[];
    }
echo $bandname.'-'.$this->bands[$bandname]['height']."<br>";  --> i debug here using echo.

    $this->pagecolumnoccupation[$pageno][$columnno] = $this->lastBandEndY;
}

can advise how can i set the height =0 for under this function?

thanks.

lvsan commented 2 years ago

hi,

below is the echo result.

pageHeader-8 detail_0-4 detail_1-15 detail_1-0 detail_1-15 detail_0-4 report_group_TransID_footer-9 pageFooter-10 TCPDF ERROR: Some data has already been output, can't send PDF file

kstan79 commented 2 years ago

seems u use multiple band, before I think too much, you use any of below?

  1. multiple column
  2. change the print vertical/horizontal

as far as I know, in basic condition it should support multiple detail band

lvsan commented 2 years ago

Hi,

I am not using multiple column and change the print for vertical/horizontal.

Yes, most of the time, i will using the multiple detail band. so far the multiple detail band is working, only the printWhenExpression will not working fine although it is already set the band height =0, but it is never reflected the value under "public function endBand(string $bandname)" . When I echo the brand height under this function, the height still is original value.

thanks.

lvsan commented 2 years ago

Hi,

below is the result when i debug.

image

The detail_1 should be 0 for band height cause have set printWhenExpression and the value is false.

thanks.

lvsan commented 2 years ago

Hi,

Currently, i fix the band height when printWhenExpression is false wit swap the position for the code as below:

protected function drawBand(string $bandname, mixed $callback=null)
{       
    if($this->bands[$bandname]['height']==0)
    {
        return ;
    }

    if(isset($this->bands[$bandname]['printWhenExpression']))
    {
        $banddisplayexpression = $this->bands[$bandname]['printWhenExpression'];
        $isdisplay = $this->isDisplay($banddisplayexpression);

        if(!$isdisplay)
        {
            $height=0;
            $this->bands[$bandname]['height']=0;
        }
        else
        {
            $this->bands[$bandname]['height'] = $this->bands[$bandname]['originalheight'];
        }
    }
    $height = $this->bands[$bandname]['height'];
    if($height>0)
    {    

// move the below code from above if($this->bands[$bandname]['height']==0)

            $offsets = $this->output->prepareBand($bandname,$callback);
             //$this->console($bandname);
             //$this->console($offsets);
            $offsetx=(int)$offsets['x'];
            $offsety=(int)$offsets['y'];
        foreach($this->elements[$bandname] as $uuid =>$element)
        {
            $tmp = $element;
            $isdisplayelement = true;
            $framedisplay = true;
            if(isset($element['printWhenExpression']))
            {                   
                $printWhenExpression = (string)$element['printWhenExpression'];
                $isdisplayelement = $this->isDisplay($printWhenExpression);                     
            }
            $this->elements[$bandname][$uuid]['show']=$isdisplayelement;

            //if this element is within frame, depend on frame appear or not
            if(isset($this->elements[$bandname][$uuid]['frame']))
            {
                $frameuuid =$this->elements[$bandname][$uuid]['frame'];
                $isdisplayelement = $this->elements[$bandname][$frameuuid]['show']??true;
            }

            //only match printWhenExpression will draw element
            if($isdisplayelement && $framedisplay)
            {                    
                $this->drawElement($uuid,$tmp,$offsetx,$offsety);
            }                            
        }
    }
    $this->output->endBand($bandname);       
}

Not sure does this is the correct way to solve it.

below is the sample output after the changes.

image

Thanks.

kstan79 commented 2 years ago

you may send pull request, and I will put aside at the moment. Cause i have no time to check due to this area may effect a lot, such as test multiple column, horizontal/vertical printing. Anyhow, glad you solve this problem.

lvsan commented 2 years ago

you may send pull request, and I will put aside at the moment. Cause i have no time to check due to this area may effect a lot, such as test multiple column, horizontal/vertical printing. Anyhow, glad you solve this problem.

ok noted. I will try to pull.

thanks.