<?php
 namespace App\Reports\Sources\CorporateContracts; class PopulateInitialImport extends \App\Reports\Sources\PopulateAbstract { public function populate() :void { global $DBTRd_corporateContracts, $DBTRd_corporates, $DBTRd_users; $reportTable = $this->tableManager->getTableName(); $activeColumns = array_keys( $this->columnsManager->getStdColumns() ); $stdFilters = $this->filtersManager->getStdFilters(); $this->reportGenerationStatusUpdate('extractMainDataFromDb', 'runningMainSQL', 0); $reportCopyInfo = new \App\Reports\Db\ManageRecords\Insert($reportTable); $reportCopyInfo->setMainTable($DBTRd_corporateContracts, 'cont'); $reportCopyInfo->addJoinTable($DBTRd_corporates, 'corp', 'cont.idCorporate=corp.id', 'LEFT'); $reportCopyInfo->addJoinTable($DBTRd_users, 'user', 'cont.idResponsibleUser=user.id', 'LEFT'); $cols = [ 'cont_id' => 'cont.id', 'cont_number' => 'cont.contractNumber', 'cont_date' => 'cont.contractDate', 'cont_typeCode' => 'cont.type', 'cont_expireDate' => 'cont.expireDate', 'cont_active' => 'cont.active', 'cont_serviceCode' => 'cont.serviceCode', 'cont_content' => 'cont.content', 'cont_fileName' => 'cont.fileName', 'user_respIdUser' => 'cont.idResponsibleUser', 'user_respIdOffice' => 'user.idOffice', 'user_respIdDepartment' => 'user.idDepartment', 'corp_idOriginal' => 'cont.idCorporate', 'user_idAddUser' => 'cont.idAddUser', 'user_idUpdateUser' => 'cont.idUpdateUser', 'cont_addTime' => 'cont.addTime', 'cont_lastUpdateTime' => 'cont.lastUpdateTime', 'cont_updatesCount' => 'cont.updatesCount', ]; $reportCopyInfo->setStructureColumns($cols); $reportCopyInfo->addStructureColumn("corp_id", "IF(corp.idRealCorporate, corp.idRealCorporate, corp.id)", "corp"); $reportCopyInfo->addStructureColumn("corp_duplicated", "IF(corp.idRealCorporate, 1, 0)", "corp"); $reportCopyInfo->addStructureColumn("user_respUserName", "CONCAT(user.firstName, ' ', user.lastName)", "user"); $reportCopyInfo->setActiveColumns($activeColumns); $reportCopyInfo->addFilter('cont.deleted', '=', 0); if ($stdFilters['contractDate']['start']) { $reportCopyInfo->addFilter('cont.contractDate', '>=', $stdFilters['contractDate']['start']); } if ($stdFilters['contractDate']['end']) { $reportCopyInfo->addFilter('cont.contractDate', '<=', $stdFilters['contractDate']['end']); } if ($stdFilters['expireDate']['start']) { $reportCopyInfo->addFilter('cont.expireDate', '>=', $stdFilters['expireDate']['start']); } if ($stdFilters['expireDate']['end']) { $reportCopyInfo->addFilter('cont.expireDate', '<=', $stdFilters['expireDate']['end']); } if ($stdFilters['addDate']['start']) { $reportCopyInfo->addFilter('cont.addTime', '>=', $stdFilters['addDate']['start']." 00:00:00"); } if ($stdFilters['addDate']['end']) { $reportCopyInfo->addFilter('cont.addTime', '<=', $stdFilters['addDate']['end']." 23:59:59"); } if ($stdFilters['idUsers']) { $reportCopyInfo->addFilter('cont.idResponsibleUser' , 'IN', $stdFilters['idUsers']); } if ($stdFilters['idOffices']) { $reportCopyInfo->addFilter('user.idOffice' , 'IN', $stdFilters['idOffices']); } if ($stdFilters['idCorporates']) { $reportCopyInfo->addFilter('cont.idCorporate', 'IN', $this->filtersManager->getDuplicateEntitiesGroup('idCorporates')); } $reportCopyInfo->populate(); } } 