J'ai un ensemble de tables classées par leur source par exemple: "Client", "Stock", "Floorstock". Ils ressemblent à ceci:Comment ajouter des totaux FPDF à la dernière rangée de tables?
contiennent chacune des listes de prix, qui doivent être ajoutés et s'élevaient sur la dernière ligne des tables.
Je vais avoir des problèmes reliant un tableau des « totaux » à « tableaux » tableau - en particulier l'affichage de chaque total à la fin de chaque tableau
Jusqu'à présent, les totaux de chaque tableau sont produits dans une autre fonction, où sourceTotals
est un tableau d'instance:
public function setSourceTotalsArray($data)
{
$this->sourceTotals = $data["source_totals"];
return $this->sourceTotals;
}
ce retourne un tableau qui ressemble à ceci:
array(4) { ["Floorstock"]=> int(0) ["Stock"]=> int(0) ["Client"]=> float(32.18) }
Voici où je définis mon $pdf
objet:
if($_SERVER["REQUEST_METHOD"] == "POST"){
$data = json_decode($_POST["printData"],true);
$pdf = new PDF();
// Column headings
$month = $pdf->getMonth($data['month']);
$year = $data['year'];
$pdf->SetFont('Arial','',10);
$pdf->AddPage();
$pdf>title(array('month'=>$month,'year'=>$year,'showroom'=>ucfirst($data['showroom_name'])));
$pdf->tableBody($data);
if(!empty($data["order_detail"])){
$customerOrders = array();
$stockOrders = array();
$floorstockOrders = array();
$otherOrders = array();
foreach($data["order_detail"] as $o){
switch($o["orderSource"]){
case 'Client':
$customerOrders[] = $o;
break;
case 'Stock':
$stockOrders[] = $o;
break;
case 'Floorstock':
$floorstockOrders[] = $o;
break;
default:
$otherOrders[] = $o;
break;
}
}
if (!empty($customerOrders)) {
$pdf->orderDetail($customerOrders, $data['currency'], 'Client');
}
if (!empty($stockOrders)) {
$pdf->orderDetail($stockOrders, $data['currency'], 'Stock');
}
if (!empty($floorstockOrders)) {
$pdf->orderDetail($floorstockOrders, $data['currency'], 'Floor Stock');
}
if (!empty($otherOrders)) {
$pdf->orderDetail($otherOrders, $data['currency'], 'Client');
}
}
$pdf->Output();
La fonction orderDetail
est ce que les structures du tableau dans l'objet $pdf
afin que la table a des cellules qui correspondent au nom de la colonne correcte:
function orderDetail($data,$currencyShortCode, $type){
$this->orderType = $type;
list($currencySymbol, $w_symbol, $cellHight) = $this->getOrderDetailHeader($currencyShortCode, $type);
foreach ($data as $d){
$commaValue = $this->addComma((float)$d['value']);
$this->Cell(15,$cellHight,$d['order_no'],'LTB',0,'L');
$this->Cell(20,$cellHight,substr($d['customer'],0,13),'TB',0,'L');
$this->Cell(20,$cellHight,substr($d['company'],0,13),'TB',0,'L');
$this->Cell(20,$cellHight,substr($d['ref'],0,13),'TB',0,'L');
$this->Cell(2,$cellHight,'','TB',0,'R');
$this->Cell($w_symbol,$cellHight,$currencySymbol,'TB',0,'R');
$this->Cell(16-$w_symbol,$cellHight,$commaValue,'TB',0,'R');
$this->Cell(2,$cellHight,'','TB',0,'R');
$this->Cell(10,$cellHight,$d['cat'],'TB',0,'L');
$this->Cell(84,$cellHight,$d['description'],'RTB',0,'L');
$this->Ln($cellHight);
}
//BOTTOM TOTAL
$this->Cell(13,$cellHight,'TOTAL','LRTB',0,'L');
$this->Cell(22,$cellHight,'','TB',0,'L');
$this->Cell(20,$cellHight,'','TB',0,'L');
$this->Cell(20,$cellHight,'','TB',0,'L');
$this->Cell(4,$cellHight,$currencySymbol,'TB',0,'R');
$this->Cell(14,$cellHight,$this->setSourceTotalsArray($data),'TB',0,'R'); //HERE
$this->Cell(2,$cellHight,'','TB',0,'R');
$this->Cell(10,$cellHight,'','TB',0,'L');
$this->Cell(84,$cellHight,'','RTB',0,'L');
}
Je ne suis pas sûr de savoir comment pour passer setSourceTotalsArray
en orderDetail
, car ma tentative actuelle ne renvoie que null
.