<?php
 refreshReportStatus('extractMainDataFromDb', 'runningMainSQL', 0); $reportCopyInfo = new \App\Reports\Db\ManageRecords\Insert($reportTable); $reportCopyInfo->setMainTable($DBTRd_customers, 'cust'); $reportCopyInfo->addJoinTable($DBTRd_corporates, 'corp', 'cust.idCorporate=corp.id', 'LEFT'); $reportCopyInfo->addJoinTable($DBTRd_users, 'addUser', 'cust.idAddUser=addUser.id', 'LEFT'); $cols = [ 'cust_id' => 'cust.id', 'cust_idRealCustomer' => 'cust.idRealCustomer', 'cust_firstNameStd' => 'cust.firstNameStd', 'cust_middleNameStd' => 'cust.middleNameStd', 'cust_lastNameStd' => 'cust.lastNameStd', 'cust_firstNameLoc' => 'cust.firstNameLoc', 'cust_middleNameLoc' => 'cust.middleNameLoc', 'cust_lastNameLoc' => 'cust.lastNameLoc', 'cust_idSegment' => 'cust.idSegment', 'cust_flag' => 'cust.flag', 'cust_titleCode' => 'cust.title', 'cust_typeCode' => 'cust.type', 'cust_idParent' => 'cust.idParent', 'cust_comments' => 'cust.comments', 'cust_locked' => 'cust.locked', 'cust_lockedComments' => 'cust.lockedComments', 'cust_remarks' => 'cust.remarks', 'cust_processedRemarks' => 'cust.processedRemarks', 'cust_idAccountManager' => 'cust.idAccountManager', 'corp_department' => 'cust.department', 'corp_idOriginal' => 'cust.idCorporate', 'cust_birthday' => 'cust.birthday', 'cust_PNC' => 'cust.PNC', 'cust_IDSeries' => 'cust.ID_series', 'cust_IDNumber' => 'cust.ID_number', 'cust_IDReleaseBy' => 'cust.ID_releaseBy', 'cust_IDReleaseDate' => 'cust.ID_releaseDate', 'cust_IDExpireDate' => 'cust.ID_expireDate', 'cust_address' => 'cust.address', 'cust_deliveryAddress' => 'cust.deliveryAddress', 'cust_zipCode' => 'cust.zipCode', 'cust_countryCode' => 'cust.countryCode', 'cust_cityId' => 'cust.cityId', 'cust_email' => 'cust.email', 'cust_telephone' => 'cust.telephone', 'cust_telephoneMobile' => 'cust.telephoneMobile', 'cust_fax' => 'cust.fax', 'bank_id' => 'cust.idBank', 'bank_idOffice' => 'cust.idBankOffice', 'bank_account' => 'cust.bankAccount', 'bank_accountingNumber' => 'cust.accountingNumber', 'cust_idAddUser' => 'cust.idAddUser', 'cust_addOfficeId' => 'addUser.idOffice', 'cust_addDeptId' => 'addUser.idDepartment', 'cust_idUpdateUser' => 'cust.idUpdateUser', 'cust_addTime' => 'cust.addTime', 'cust_lastUpdateTime' => 'cust.lastUpdateTime', 'cust_updatesCount' => 'cust.updatesCount', ]; $reportCopyInfo->setStructureColumns($cols); $reportCopyInfo->addStructureColumn("cust_addDate", "DATE_FORMAT(cust.addTime, '%Y-%m-%d')", "cust"); $reportCopyInfo->addStructureColumn("cust_duplicate", "IF(cust.idRealCustomer, 1, 0)", "cust"); $reportCopyInfo->addStructureColumn("cust_fullNameStd", "CONCAT(cust.firstNameStd, ' ', cust.lastNameStd)", "cust"); $reportCopyInfo->addStructureColumn("corp_idCorporate", "IF(corp.idRealCorporate, corp.idRealCorporate, corp.id)", "corp"); $reportCopyInfo->addStructureColumn("corp_duplicated", "IF(corp.idRealCorporate, 1, 0)", "corp"); $reportCopyInfo->addStructureColumn("cust_addUserName", "CONCAT(addUser.firstName, ' ', addUser.lastName)", "addUser"); $reportCopyInfo->setActiveColumns($availableTableColumns); if (count($reportFilters['clientType'])==1) { if ($reportFilters['clientType']['DC']) { $reportCopyInfo->addFilter('cust.idCorporate', '=', '0'); } elseif ($reportFilters['clientType']['SA'] or $reportFilters['clientType']['CC']) { $reportCopyInfo->addFilter('cust.idCorporate', '>', '0'); } } elseif (count($reportFilters['clientType'])==2) { if ($reportFilters['clientType']['CC'] and $reportFilters['clientType']['SA']) $reportCopyInfo->addFilter('cust.idCorporate', '>', '0'); } if ($reportExtraFilters['corporate']) { $reportCopyInfo->addFilter('cust.idCorporate', 'IN', $reportExtraFilters['corporate']); } if ($reportFilters['lastNameStd']) { $reportCopyInfo->addFilter('cust.lastNameStd', 'LIKE', "%".$reportFilters['lastNameStd']."%"); } if ($reportFilters['firstNameStd']) { $reportCopyInfo->addFilter('cust.firstNameStd', 'LIKE', "%".$reportFilters['firstNameStd']."%"); } if ($reportFilters['birthday']['startDate']) { $reportCopyInfo->addFilter('cust.birthday', '>=', $reportFilters['birthday']['startDate']); } if ($reportFilters['birthday']['endDate']) { $reportCopyInfo->addFilter('cust.birthday', '<=', $reportFilters['birthday']['endDate']); } if ($reportFilters['addOfficeUser']['idUser']) { $reportCopyInfo->addFilter('cust.idAddUser' , '=', $reportFilters['addOfficeUser']['idUser']); } elseif ($reportFilters['addOfficeUser']['idOffice']) { $reportCopyInfo->addFilter('addUser.idOffice' , '=', $reportFilters['addOfficeUser']['idOffice']); } $reportCopyInfo->addFilter('cust.deleted', '=', 0); $reportCopyInfo->populate(); 