<?php
 namespace App\GenDocument\SpecialObject; class InvoiceVatDetails extends TableAbstract { protected function table_populateRows() { global $CFG; $invoiceRows=\Entity\Invoice::select($this->idPivot)->rowsList; $invoiceCurrency=\Entity\Invoice::select($this->idPivot)->currency; $invoiceDate=\Entity\Invoice::select($this->idPivot)->invoiceDate; $groupedVat=[]; foreach($invoiceRows as $thisRow) { $k=$thisRow['vatText']; $groupedVat[$k]['vatQuota'] = $thisRow['vatText']; $groupedVat[$k]['value'] += $thisRow['pricePrintValue']; $groupedVat[$k]['vat'] += $thisRow['vatPrintValue']; $groupedVat[$k]['totalAmount'] += $thisRow['pricePrintValue']+$thisRow['vatPrintValue']; if ($this->tableColumns['vatBase']) { $groupedVat[$k]['vatBase'] += \Entity\InvoiceRow::select($thisRow['id'])->vatBasePrintValue; } } $rows=[]; foreach($groupedVat as $vatDetails) { $valInDefCurr=\App\CurrencyExchange\Rates::getInstance($invoiceDate)->convert($vatDetails['value'], $invoiceCurrency, $CFG['currencies']['defaultCurrency']); $vatInDefCurr=\App\CurrencyExchange\Rates::getInstance($invoiceDate)->convert($vatDetails['vat'], $invoiceCurrency, $CFG['currencies']['defaultCurrency']); $ttlInDefCurr=\App\CurrencyExchange\Rates::getInstance($invoiceDate)->convert($vatDetails['totalAmount'], $invoiceCurrency, $CFG['currencies']['defaultCurrency']); $replacements = [ '%invoiceVatDetails_vatQuota%' => $vatDetails['vatQuota'], ]; $vatDetails['prefix'] = str_replace(array_keys($replacements), array_values($replacements), $this->settings['column_prefixValue']); $vatColValue = $vatDetails['vat']; $vatBaseColValue = $vatDetails['vatBase']; $vatDefCurrColValue = $vatInDefCurr; $vatColType = 'price'; if ($this->settings['options_zeroVatBlank']['blank'] && $vatDetails['vat']==0) { $vatColValue = ''; $vatBaseColValue = ''; $vatDefCurrColValue = ''; $vatColType = 'string'; } $row = [ 'prefix' => ['content'=>$vatDetails['prefix'], 'type'=>'string'], 'vatQuota' => ['content'=>$vatDetails['vatQuota'], 'type'=>'price'], 'value' => ['content'=>$vatDetails['value'], 'type'=>'price'], 'vatBase' => ['content'=>$vatBaseColValue, 'type'=>$vatColType], 'vat' => ['content'=>$vatColValue, 'type'=>$vatColType], 'totalAmount' => ['content'=>$vatDetails['totalAmount'], 'type'=>'price'], 'valueInDefCurrency' => ['content'=>$valInDefCurr, 'type'=>'price'], 'vatInDefCurrency' => ['content'=>$vatDefCurrColValue, 'type'=>$vatColType], 'totalAmountInDefCurrency'=>['content'=>$ttlInDefCurr, 'type'=>'price'], ]; $rows[]=$row; } $this->tableRows=$rows; } protected function render_table_setTableBorderAttributes() { parent::render_table_setTableBorderAttributes(); if($this->settings['column_prefixBorders']=='none') { foreach($this->table->children as $tr) { foreach($tr->children as $tdIndex=>$td) { if($tdIndex==0) { $td->setAttribute('border_color', '#FFFFFF'); } } } } } } 