<?php
 namespace App\GenDocument\SpecialObject; class ReservationCumulativeOffer extends TableAbstract { private $totals=[]; protected function table_populateRows() { $rows = []; $totals = []; $idx=0; $allowedServiceCodesBulk = explode(",", $this->settings['filterServices']); $allowedServiceCodes = []; foreach($allowedServiceCodesBulk as $serviceCode){ $serviceCode = trim($serviceCode); if ($serviceCode) { $allowedServiceCodes[$serviceCode] = $serviceCode; } } if ($this->extraParams['servicesList']) { $selectedServicesList = $this->extraParams['servicesList']; } else { $selectedServicesList = array_keys(\Entity\Order::select($this->idPivot)->servicesList); } $servicesList = []; foreach ( \Entity\Order::select($this->idPivot)->sortedServicesSegmentsFinal as $serviceComponent) { if ( !in_array($serviceComponent['idService'], $servicesList) and in_array($serviceComponent['idService'], $selectedServicesList) ) { $servicesList[] = $serviceComponent['idService']; } } foreach($servicesList as $idServ) { $serv = \Entity\Service::select($idServ); if ($serv->statusOp!='OK') continue; if ($allowedServiceCodes && !$allowedServiceCodes[$serv->serviceCode]){ continue; } $idx++; $off = $serv->chosenOffer; $row = []; $row['currentNumber'] = ['content'=>$idx]; $row['service'] = ['content'=>$serv->service]; $row['destination'] = ['content'=>$serv->chosenOffer->destinationCity->name]; if ($serv->chosenOffer->destinationCountry->name) { $row['destination']['content'] .= " ({$serv->chosenOffer->destinationCountry->name})"; } $psgs=[]; foreach($serv->idCustomersList as $idCust) { $psgs[]=\Entity\Customer::select($idCust)->name; } $row['passengers'] = ['content'=>implode(', ', $psgs)]; $row['ticketNumber'] = ['content'=>implode(', ', $serv->passengersTicketsList)]; $row['extResId'] = ['content'=>$serv->chosenOffer->externalSystemReservationId]; $row['extResDate'] = ['content' => $serv->chosenOffer->externalSystemReservationDate, 'type' => 'date']; $row['supplier'] = ['content'=>$serv->chosenOffer->supplier->alias]; $row['supplierService'] = ['content'=>$off->relevantProductName]; $row['startDate'] = ['content'=> $serv->chosenOffer->startDate, 'type' => 'date']; $row['endDate'] = ['content'=> $serv->chosenOffer->endDate, 'type' => 'date']; $servAttr=[]; if ($serv->categoryReadable) $servAttr[]=$serv->categoryReadable; if ($serv->productTypeReadable) $servAttr[]=$serv->productTypeReadable; if ($serv->multiplierReadable) $servAttr[]=$serv->multiplierReadable; $row['serviceAttributes']= ['content'=>implode(', ', $servAttr)]; $row['serviceCategory']= ['content'=>$serv->categoryReadable]; $row['serviceProductType']= ['content'=>$serv->productTypeReadable]; $row['serviceMultiplier']= ['content'=>$serv->multiplierReadable]; $row['serviceSource']= ['content'=>$serv->serviceSourceReadable]; $row['priceSupplierPrice']= ['content'=>round($off->supplierWorkValue+$off->supplierWorkVat, 2), 'type'=>'price']; $row['priceCommission']= ['content'=>round($off->commissionWorkValue+$off->commissionWorkVat, 2), 'type'=>'price']; $row['priceServicePrice']= ['content'=>round($off->supplierWorkValue+$off->supplierWorkVat+$off->commissionWorkValue+$off->commissionWorkVat, 2), 'type'=>'price']; $row['priceDiscount']= ['content'=>round(-$off->discountWorkValue-$off->discountWorkVat, 2), 'type'=>'price']; $row['priceServiceFee']= ['content'=>round($off->serviceFeeWorkValue+$off->serviceFeeWorkVat, 2), 'type'=>'price']; $row['priceTax']= ['content'=>round($off->taxWorkValue+$off->taxWorkVat, 2), 'type'=>'price']; $row['priceTotal']= ['content'=>round($off->offerWorkTotal, 2), 'type'=>'price']; $row['currency']= ['content'=>$off->totalCurrency]; $row['priceTotalDefCurr']= ['content'=>round($off->offerTotalDefCurr, 2), 'type'=>'price']; $row['priceTotalWorkCurr']= ['content'=>round($off->offerTotalWorkCurr, 2), 'type'=>'price']; $totals['priceTotalDefCurr']+=round($off->offerTotalDefCurr, 2); $totals['priceTotalWorkCurr']+=round($off->offerTotalWorkCurr, 2); $rows[]=$row; } $this->totals = $totals; $this->tableRows = $rows; } protected function render_table_addTableFoot() { if (!$this->settings['showTotals']) return; $finalRow = new \DTMControl_table_tr(); foreach($this->tableColumns as $col=>$nothing) { if ($col=='priceTotalDefCurr' or $col=='priceTotalWorkCurr') { $cellContent=$this->totals[$col]; } else { $cellContent=''; } $finalRow->add_td( [ 'fontFamily'=>$this->settings['totalsFont'], 'style_bold'=>(bool)$this->settings['totalsTextStyle']['bold'], 'style_italic'=>(bool)$this->settings['totalsTextStyle']['italic'], 'style_underline'=>(bool)$this->settings['totalsTextStyle']['underline'], 'fontSize'=>$this->settings['totalsFontSize'], 'color'=>$this->settings['totalsTextColor'], 'backgroundColor'=>$this->settings['totalsBackgroundColor'], 'text'=>$cellContent, 'colspan'=>1, 'align'=>"right" ] ); } $this->table->add_tr($finalRow); } } 