;statement_details;
Company Name
ClientID
RetainerID
TOPP Plan
Total Cost
Balance Paid
'; function retainer_statement($retainerid) { require('inc/fpdf.php'); class PDF extends FPDF { function fancytable($header,$data,$w) { if ($header != '') { //Colors, line width and bold font $this->SetFillColor(204,204,204); $this->SetTextColor(0); $this->SetDrawColor(0); $this->SetLineWidth(.3); $this->SetFont('Arial','B',10); for($i=0;$iCell($w[$i],7,$header[$i],1,0,'C',1); $this->Ln(); } //Color and font restoration $this->SetFillColor(241,241,241); $this->SetTextColor(0); $this->SetFont('Arial','','7'); //Data $fill=0; foreach($data as $row) { if (strlen($row[0]) < 35) { $this->Cell($w[0],6,$row[0],'LR',0,'C',$fill); } else { $this->Y=$this->getY(); $this->X=$this->getX(); $this->Cell($w[0],3,substr($row[0],0,35),'LR',0,'C',$fill); $this->ln(); $this->setX($this->X); $this->Cell($w[0],3,substr($row[0],35,35),'LR',0,'C',$fill); $this->setY($this->Y); $this->setX($this->X+$w[0]); } if (strlen($row[1]) < 65) { $this->Cell($w[1],6,$row[1],'LR',0,'C',$fill); } else { $this->Y=$this->getY(); $this->X=$this->getX(); $this->Cell($w[1],3,substr($row[1],0,65),'LR',0,'C',$fill); $this->ln(); $this->setX($this->X); $this->Cell($w[1],3,substr($row[1],65,65),'LR',0,'C',$fill); $this->setY($this->Y); $this->setX($this->X+$w[1]); } for ($i=2; $i < count($w); $i++) { $this->Cell($w[$i],6,$row[$i],'LR',0,'C',$fill); } $this->Ln(); $fill=!$fill; } $this->Cell(array_sum($w),0,'','T'); } } $pdf=new PDF(); include('inc/dbconnect.php'); $sql="select * from clients,topp where topp.retainerid='$retainerid' and clients.clientid = topp.clientid"; $result=mysql_query($sql) or die(mysql_error()); $topp_data=mysql_fetch_object($result); $pdf->AddPage(); $pdf->Image('inc/title.jpg',10,10,40); $pdf->SetFont('Arial','B',20); $pdf->setXY(95,10); $pdf->MultiCell(0,8,"T.O.P.P Level ".$topp_data->serviceplan." ".$topp_data->requiredvisits." Plan\nRetainer Statement"); $pdf->setXY(10,50); $pdf->setFont('Arial','B',12); $pdf->MultiCell(0,1,$topp_data->companyname); $pdf->setXY(160,50); $pdf->MultiCell(0,1,'Date: '.date('M d,Y')); $pdf->setXY(10,80); $w=array(50,56,42,40); $columns=array('Previous Retainer Balance','Payment to Increase Retainer','Total Labour Used','New Retainer Balance'); if ($topp_data->totalpaid == '') { $topp_data->totalpaid='0.00'; } if ($topp_data->totalused == '') { $topp_data->totalused='0.00'; } if ($topp_data->total <= $topp_data->totalpaid) { if ($topp_data->total-$topp_data->totalpaid < 0) { $topp_data->increase='0.00'; } else { $topp_data->increase=$topp_data->total-$topp_data->totalpaid; } } else { $topp_data->increase=$topp_data->monthlypayments; } $topp_summary=array( array('$ '.$topp_data->totalpaid, '$ '.$topp_data->increase, '$ '.$topp_data->totalused, '$ '.number_format($topp_data->totalpaid-$topp_data->totalused+$topp_data->increase,2) ) ); $pdf->fancytable($columns,$topp_summary,$w); $invoice_workorder=array(); $sql="select * from topp_invoices,invoices where topp_invoices.retainerid='".$topp_data->retainerid."' and invoices.invoiceid=topp_invoices.invoiceid order by invoices.invoiceid"; $result=mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) != 0) { while ($row = mysql_fetch_object($result)) { $sql2="select * from labour where workorderid='".$row->workorderid."'"; $result2=mysql_query($sql2) or die(mysql_error()); while ( $row2 = mysql_fetch_object($result2) ) { $invoice_workorder[]=array($row->invoiced_date, $row2->desc . " - Workorder - " . $row->workorderid, '$ '.number_format($row2->unitprice*$row2->quantity+($row2->unitprice*$row2->quantity*0.07),2) ); } $sql2="select * from inventory where workorderid='".$row->workorderid."'"; $result2=mysql_query($sql2); while ($row2=mysql_fetch_object($result2)) { $invoice_workorder[]=array($row->invoiceid, $row2->description, '$ '.number_format($row2->selling_price*1+($row2->selling_price*1*0.07),2)); } } } else { $invoice_workorder[]=array('','No Transactions Have been Processed','$ 0.00'); } while (count($invoice_workorder) <= 22) { $invoice_workorder[]=array(); } $pdf->Y=$pdf->getY(); $pdf->setXY(10,$pdf->Y+10); $w=array(50,98,40); $columns=array('Tranaction Date','Transaction Description','Amount'); $pdf->fancytable($columns,$invoice_workorder,$w); $w=array(50,56,42,40); $columns=array('Retainer Payment Due Date','Retainer Montly Payments','Retainer Amount Owing','Amount Paid *'); $topp_data->owing=($topp_data->total-$topp_data->totalpaid); if ($topp_data->owing <= 0) { $topp_data->owing='Paid in full'; } $topp_data->duedate=strtotime('now'); while (date('d',$topp_data->duedate) < date('d',strtotime($topp_data->dateopened))) { $topp_data->duedate=strtotime('+1 day',$topp_data->duedate); } $retainer_summary=array( array( date('m/d/Y',$topp_data->duedate), '$ '.$topp_data->monthlypayments, '$ '.$topp_data->owing, '$ '.$topp_data->totalpaid ) ); $pdf->Y=$pdf->getY(); $pdf->setXY(9,$pdf->Y+10); $pdf->SetFont('Arial','',10); $pdf->MultiCell(0,4,'All Prices include GST'); $pdf->fancytable($columns,$retainer_summary,$w); $pdf->output(); } ?>