<?php
 namespace App\QuickReports\PivotTables; class Content { protected $rowsFields = []; protected $otherRowsKey = null; protected $otherRowsText = null; protected $colsFields = []; protected $otherColsKey = null; protected $otherColsText = null; protected $data = []; protected $rowsTotals; protected $colsTotals; protected $grandTotal; public function setRowsFields(Array $rowsFields, $otherRowsKey = null, $otherRowsText = '') { $this->rowsFields = $rowsFields; if ($otherRowsKey!==null) { $this->otherRowsKey = $otherRowsKey; $this->otherRowsText = '...'; } if (strlen($otherRowsText)) { $this->otherRowsText = $otherRowsText; } } public function resetOtherRows() { $this->otherRowsKey = null; $this->otherRowsText = null; } public function getRowsFields() { return $this->rowsFields; } public function setColsFields(Array $colsFields, $otherColsKey = null, $otherColsText = '') { $this->colsFields = $colsFields; if ($otherColsKey!==null) { $this->otherColsKey = $otherColsKey; $this->otherColsText = '...'; } if (strlen($otherColsText)) { $this->otherColsText = $otherColsText; } } public function resetOtherCols() { $this->otherColsKey = null; $this->otherColsText = null; } public function getColsFields() { return $this->colsFields; } public function setData(Array $data) { $this->data = $data; } public function setRowsTotals(Array $totals) { $this->rowsTotals = $totals; } public function setColsTotals(Array $totals) { $this->colsTotals = $totals; } public function setGrandTotal($total) { $this->grandTotal = $total; } public function getRowsTotals() { return $this->rowsTotals; } public function getColsTotals() { return $this->colsTotals; } public function getGrandTotal() { return $this->grandTotal; } public function getOtherColsKey() { return $this->otherColsKey; } public function getOtherColsText() { return $this->otherColsText; } public function getOtherRowsKey() { return $this->otherRowsKey; } public function getOtherRowsText() { return $this->otherRowsText; } public function getDataValue($row, $col) { return $this->data[$row][$col]; } public function getAllData() { return $this->data; } protected function debugPrice($price) { return \App\Utils\PriceFormat::format($price); } public function debug() { echo '<table border="1">'; echo "<tr>"; echo "<td>*</td>"; foreach($this->colsFields as $fld) { echo "<td>{$fld}</td>"; } if ($this->otherColsKey) { echo "<td>{$this->otherColsText}</td>"; } if ($this->rowsTotals) { echo "<td>TOTAL</td>"; } foreach($this->rowsFields as $rowFldCode=>$rowFldName) { echo "<tr>"; echo "<td>{$rowFldName}</td>"; foreach($this->colsFields as $colFldCode=>$colFldName) { echo "<td>"; if ($this->data[$rowFldCode][$colFldCode]) { echo $this->debugPrice($this->data[$rowFldCode][$colFldCode]); } else { echo " - "; } echo "</td>"; } if ($this->otherColsKey) { echo "<td>".$this->debugPrice($this->data[$rowFldCode][$this->otherColsKey])."</td>"; } if ($this->rowsTotals) { echo "<td>".$this->debugPrice($this->rowsTotals[$rowFldCode])."</td>"; } echo "</tr>"; } if ($this->otherRowsKey) { echo "<tr>"; echo "<td>{$this->otherRowsText}</td>"; foreach($this->colsFields as $colFldCode=>$colFldName) { echo "<td>"; if ($this->data[$this->otherRowsKey][$colFldCode]) { echo $this->debugPrice($this->data[$this->otherRowsKey][$colFldCode]); } else { echo "-"; } echo "</td>"; } if ($this->otherColsKey) { echo "<td>{$this->data[$this->otherRowsKey][$this->otherColsKey]}</td>"; } if ($this->rowsTotals) { echo "<td>".$this->debugPrice($this->rowsTotals[$this->otherRowsKey])."</td>"; } echo "</tr>"; } if ($this->colsTotals) { echo "<tr>"; echo "<td>TOTAL</td>"; foreach($this->colsFields as $colFldCode=>$colFldName) { echo "<td>".$this->debugPrice($this->colsTotals[$colFldCode])."</td>"; } if ($this->otherColsKey) { echo "<td>".$this->debugPrice($this->colsTotals[$this->otherColsKey])."</td>"; } echo "<td>".$this->debugPrice($this->grandTotal)."</td>"; echo "<tr>"; } echo "</table>"; } } 