/**
  * Returns an singleton instance of this class
  *
  * @param object $config
  * @param object $args
  * @return
  */
 public static function getInstance($config, $args)
 {
     if (self::$instance == null) {
         self::$instance = new ServiceCompaniesPriceListManager($config, $args);
     }
     return self::$instance;
 }
 public function service()
 {
     $service_company_id = intval($_REQUEST['service_company_id']);
     if ($this->getUserLevel() === UserGroups::$SERVICE_COMPANY) {
         $requestHistoryManager = RequestHistoryManager::getInstance($this->config, $this->args);
         $customerGivenRequestRecentCountByHours = $requestHistoryManager->getCustomerGivenRequestRecentCountByHours($this->getCustomerLogin(), 24, get_class());
         if ($customerGivenRequestRecentCountByHours > intval($this->getCmsVar('company_revert_price_limit'))) {
             $jsonArr = array('status' => "err", "errText" => $this->getPhrase(557) . ' ' . intval($this->getCmsVar('company_revert_price_limit')));
             echo json_encode($jsonArr);
             return false;
         }
     }
     $serviceCompaniesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
     $ret = $serviceCompaniesPriceListManager->removeCompanyLastPrice($service_company_id);
     if ($ret > 0) {
         $jsonArr = array('status' => "ok");
         echo json_encode($jsonArr);
         return true;
     } else {
         switch ($ret) {
             case -1:
                 $errMessage = "Price doesn't exist!";
                 break;
             default:
                 $errMessage = "You can not revert the price file! You have only 1 price file on pcstore.";
                 break;
         }
         $jsonArr = array('status' => "err", "errText" => "System Error: " . $errMessage);
         echo json_encode($jsonArr);
         return false;
     }
 }
 public function load()
 {
     $serviceCompaniesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
     $serviceCompanyId = $_REQUEST['service_company_id'];
     $this->addParam("serviceCompaniesPriceListManager", $serviceCompaniesPriceListManager);
     $companiesZippedPricesByDaysNumber = $serviceCompaniesPriceListManager->getCompaniesZippedPricesByDaysNumber($serviceCompanyId);
     $groupServiceCompaniesZippedPricesByCompanyId = $this->groupCompaniesZippedPricesByCompanyId($companiesZippedPricesByDaysNumber);
     $this->addParam("groupServiceCompaniesZippedPricesByCompanyId", $groupServiceCompaniesZippedPricesByCompanyId);
 }
 public function load()
 {
     $userLevel = $this->sessionManager->getUser()->getLevel();
     $serviceCompaniesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
     $serviceCompanyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
     if ($userLevel === UserGroups::$SERVICE_COMPANY) {
         $serviceCompanyId = $this->getUserId();
         $selectedCompanyId = $serviceCompanyId;
         $serviceCompanyExtendedProfileManager = ServiceCompanyExtendedProfileManager::getInstance($this->config, $this->args);
         $dto = $serviceCompanyExtendedProfileManager->getByCompanyId($serviceCompanyId);
         if (!isset($dto)) {
             $serviceCompanyExtendedProfileManager->createDefaultExCompanyProfile($serviceCompanyId);
         }
         $dto = $serviceCompanyExtendedProfileManager->getByCompanyId($serviceCompanyId);
         list($companyEmailServerLogins, $companyEmailServersEmailsCount) = $this->getCompanyEmailServerLogins($dto);
         $this->addParam("companyEmailServerLogins", $companyEmailServerLogins);
         $this->addParam("companyEmailServersEmailsCount", $companyEmailServersEmailsCount);
         $this->addParam("companyExProfileDto", $dto);
         $dealerEmails = trim($dto->getDealerEmails());
         $this->addParam("total_price_email_recipients_count", empty($dealerEmails) ? 0 : count(explode(';', $dealerEmails)));
         array_map('unlink', glob(HTDOCS_TMP_DIR_ATTACHMENTS . "/service_companies/" . $serviceCompanyId . "/*"));
     } else {
         if ($userLevel === UserGroups::$ADMIN) {
             $allCompanies = $serviceCompanyManager->selectAll();
             $companiesIds = $serviceCompanyManager->getCompaniesIdsArray($allCompanies);
             $companiesNames = $serviceCompanyManager->getCompaniesNamesArray($allCompanies);
             if (isset($_REQUEST['selected_company'])) {
                 $selectedCompanyId = $this->secure($_REQUEST['selected_company']);
             } else {
                 $selectedCompanyId = $allCompanies[0]->getId();
             }
             $this->addParam("companiesIds", $companiesIds);
             $this->addParam("companiesNames", $companiesNames);
         }
     }
     $companyPrices = $serviceCompaniesPriceListManager->getCompanyHistoryPricesOrderByDate($selectedCompanyId, 0, 50);
     $this->addParam("company_prices", $companyPrices);
     $this->addParam("selectedCompanyId", $selectedCompanyId);
     if (isset($_REQUEST['show_send_email_to_dealers']) && $_REQUEST['show_send_email_to_dealers'] == 1) {
         $this->addParam("show_send_email_to_dealers", 1);
     }
     $emailServersManager = EmailServersManager::getInstance($this->config, $this->args);
     $allEmailServers = $emailServersManager->selectAll();
     $this->addParam("allEmailServers", $allEmailServers);
 }
예제 #5
0
 public function load()
 {
     $this->setDescriptionTagValue('Companies that are registered in pcstore.am and their products are listed.');
     $this->setTitleTagValue('Pcstore Company List');
     $this->setKeywordsTagValue('Companies that are registered in pcstore.am and their products are listed.');
     $companyManager = CompanyManager::getInstance($this->config, $this->args);
     $serviceCompanyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
     $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
     $serviceCompaniesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
     $show_only_last_hours_values = array(0, 10, 24, 72, 168);
     $ph_all = $this->getPhrase(461);
     $ph_last = $this->getPhrase(456);
     $ph_hours = $this->getPhrase(455);
     $ph_days = $this->getPhrase(459);
     $ph_week = $this->getPhrase(460);
     $ph_updated = $this->getPhrase(457);
     $show_only_last_hours_names_phrase_ids_array = array(461, "`456` 10 `455` `457`", "`456` 24 `455` `457`", "`456` 3 `459` `457`", "`456` `460` `457`");
     $show_only_last_hours_names = array($ph_all, $ph_last . ' 10 ' . $ph_hours . ' ' . $ph_updated, $ph_last . ' 24 ' . $ph_hours . ' ' . $ph_updated, $ph_last . ' 3 ' . $ph_days . ' ' . $ph_updated, $ph_last . ' ' . $ph_week . ' ' . $ph_updated);
     $show_only_last_hours_selected = 0;
     if (isset($_REQUEST['show_only_last_hours_selected'])) {
         $show_only_last_hours_selected = intval($_REQUEST['show_only_last_hours_selected']);
     }
     $this->addParam("show_only_last_hours_values", $show_only_last_hours_values);
     $this->addParam("show_only_last_hours_names", $show_only_last_hours_names);
     $this->addParam("show_only_last_hours_names_phrase_ids_array", $show_only_last_hours_names_phrase_ids_array);
     $this->addParam("show_only_last_hours_selected", $show_only_last_hours_selected);
     $searchText = "";
     if (isset($_REQUEST['search_text'])) {
         $searchText = $this->secure($_REQUEST['search_text']);
     }
     $this->addParam("search_text", $searchText);
     $userLevel = $this->getUserLevel();
     $userId = $this->getUserId();
     $companiesList = array();
     $allServiceCompaniesWithBranches = $serviceCompanyManager->getAllServiceCompaniesWithBranches();
     foreach ($allServiceCompaniesWithBranches as $serviceCompanyDto) {
         $serviceCompanyDto->setShowPrice(1);
     }
     if ($userLevel == UserGroups::$USER) {
         $serviceCompanyDealersManager = ServiceCompanyDealersManager::getInstance($this->config, $this->args);
         $userserviceCompaniesIdsArray = $serviceCompanyDealersManager->getUserCompaniesIdsArray($userId);
         foreach ($allServiceCompaniesWithBranches as $serviceCompanyDto) {
             if (in_array($serviceCompanyDto->getId(), $userserviceCompaniesIdsArray)) {
                 $serviceCompanyDto->setShowPrice(1);
             } else {
                 $serviceCompanyDto->setShowPrice(0);
             }
         }
     }
     if ($userLevel == UserGroups::$COMPANY || $userLevel == UserGroups::$SERVICE_COMPANY) {
         $companiesList = $companyManager->getAllCompaniesByPriceHours($show_only_last_hours_selected, $searchText);
     }
     if ($userLevel == UserGroups::$USER) {
         $companiesList = $companyManager->getUserCompaniesJoindWithFullInfo($userId, $show_only_last_hours_selected, $searchText);
     }
     if ($userLevel == UserGroups::$ADMIN) {
         $companiesList = $companyManager->getAllCompaniesByPriceHours($show_only_last_hours_selected, $searchText, true, true);
     }
     $this->addParam('allCompanies', $companiesList);
     $this->addParam('allServiceCompanies', $allServiceCompaniesWithBranches);
     $allNonHiddenCompanies = $companyManager->getAllCompanies();
     $this->addParam('allNonHiddenCompanies', $allNonHiddenCompanies);
     $this->addParam('allCompaniesDtosToArray', json_encode(AbstractDto::dtosToArray($companiesList, array("id" => "id", "name" => "name", "rating" => "rating"))));
     $this->addParam('allServiceCompaniesDtosToArray', json_encode(AbstractDto::dtosToArray($allServiceCompaniesWithBranches, array("id" => "id", "name" => "name"))));
     // $this->addParam('userLevel', $userLevel);
     // $this->addParam('userGroupsUser', UserGroups::$USER);
     $companyBranchesManager = CompanyBranchesManager::getInstance($this->config, $this->args);
     $serviceCompanyBranchesManager = ServiceCompanyBranchesManager::getInstance($this->config, $this->args);
     $cids = $this->getCompanyIdsArray($companiesList);
     $scids = $this->getCompanyIdsArray($allServiceCompaniesWithBranches);
     $companiesBranchesDtos = $companyBranchesManager->getCompaniesBranches($cids);
     $serviceCompaniesBranchesDtos = $serviceCompanyBranchesManager->getServiceCompaniesBranches($scids);
     $this->addParam('allCompaniesBranchesDtosToArray', json_encode(AbstractDto::dtosToArray($companiesBranchesDtos)));
     $this->addParam('allServiceCompaniesBranchesDtosToArray', json_encode(AbstractDto::dtosToArray($serviceCompaniesBranchesDtos)));
     $this->addParam("companiesPriceListManager", $companiesPriceListManager);
     $this->addParam("serviceCompaniesPriceListManager", $serviceCompaniesPriceListManager);
     $companiesZippedPricesByDaysNumber = $companiesPriceListManager->getCompaniesZippedPricesByDaysNumber($cids, 360);
     $serviceCompaniesZippedPricesByDaysNumber = $serviceCompaniesPriceListManager->getCompaniesZippedPricesByDaysNumber($cids, 360);
     $groupCompaniesZippedPricesByCompanyId = $this->groupCompaniesZippedPricesByCompanyId($companiesZippedPricesByDaysNumber);
     $groupServiceCompaniesZippedPricesByCompanyId = $this->groupServiceCompaniesZippedPricesByCompanyId($serviceCompaniesZippedPricesByDaysNumber);
     $this->addParam("groupCompaniesZippedPricesByCompanyId", $groupCompaniesZippedPricesByCompanyId);
     $this->addParam("groupServiceCompaniesZippedPricesByCompanyId", $groupServiceCompaniesZippedPricesByCompanyId);
 }
 public function checkIfSamePriceAlreadyExists($companyId, $tmp_name)
 {
     $serviceCompaniesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
     $companyLastPrices = $serviceCompaniesPriceListManager->getCompanyLastPrices($companyId);
     $uploadedFileContentMd5 = md5_file($tmp_name);
     $duplicatedUpload = false;
     foreach ($companyLastPrices as $companyLastPrice) {
         $lastPriceContentMd5 = md5_file($serviceCompaniesPriceListManager->getPricePath($companyLastPrice));
         if ($uploadedFileContentMd5 === $lastPriceContentMd5) {
             $duplicatedUpload = true;
             break;
         }
     }
     return $duplicatedUpload;
 }
예제 #7
0
 public function service()
 {
     //todo check if user have access to given company
     $customer = $this->sessionManager->getUser();
     $userLevel = $customer->getLevel();
     $userId = $customer->getId();
     $companyManager = CompanyManager::getInstance($this->config, $this->args);
     $serviceCompanyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
     if ($this->args[0] == "last_price") {
         $companyId = $this->args[1];
         if ($userLevel == UserGroups::$USER) {
             $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $companyDealersManager->getByCompanyIdAndUserId($userId, $companyId);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $companyManager->selectByPK($companyId);
         assert($company);
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             if (count($companyLastPrices) === 1) {
                 $pricePath = DATA_DIR . "/companies_prices/" . $companyId . '/' . $companyLastPrices[0]->getFileName() . '.' . $companyLastPrices[0]->getFileExt();
                 if (file_exists($pricePath)) {
                     $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $companyLastPrices[0]->getFileName());
                 } else {
                     echo "file not exists!";
                 }
             } else {
                 $filesPaths = array();
                 foreach ($companyLastPrices as $key => $clp) {
                     $fileName = $clp->getFileName() . '.' . $clp->getFileExt();
                     $filesPaths[] = array(DATA_DIR . "/companies_prices/" . $company->getId() . '/' . $fileName, $company->getShortName() . '_' . ($key + 1) . '_' . $fileName);
                 }
                 $uid = uniqid();
                 $this->createZip($filesPaths, DATA_DIR . "/temp/" . $uid . '.zip');
                 $companiesPriceListManager->downloadFile(DATA_DIR . "/temp/" . $uid . '.zip', $company->getShortName() . '_price');
                 unlink(DATA_DIR . "/temp/" . $uid . '.zip');
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "service_last_price") {
         $companyId = $this->args[1];
         if ($userLevel == UserGroups::$USER) {
             $serviceCompanyDealersManager = ServiceCompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $serviceCompanyDealersManager->getByCompanyIdAndUserId($userId, $companyId);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $serviceCompanyManager->selectByPK($companyId);
         assert($company);
         $companiesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             if (count($companyLastPrices) === 1) {
                 $pricePath = DATA_DIR . "/service_companies_prices/" . $companyId . '/' . $companyLastPrices[0]->getFileName() . '.' . $companyLastPrices[0]->getFileExt();
                 if (file_exists($pricePath)) {
                     $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $companyLastPrices[0]->getFileName());
                 } else {
                     echo "file not exists!";
                 }
             } else {
                 $filesPaths = array();
                 foreach ($companyLastPrices as $key => $clp) {
                     $fileName = $clp->getFileName() . '.' . $clp->getFileExt();
                     $filesPaths[] = array(DATA_DIR . "/service_companies_prices/" . $company->getId() . '/' . $fileName, $company->getShortName() . '_' . ($key + 1) . '_' . $fileName);
                 }
                 $uid = uniqid();
                 $this->createZip($filesPaths, DATA_DIR . "/temp/" . $uid . '.zip');
                 $companiesPriceListManager->downloadFile(DATA_DIR . "/temp/" . $uid . '.zip', $company->getShortName() . '_price');
                 unlink(DATA_DIR . "/temp/" . $uid . '.zip');
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "zipped_price") {
         $zippedPriceId = $this->args[1];
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $price = $companiesPriceListManager->selectByPK($zippedPriceId);
         $company_id = $price->getCompanyId();
         if ($userLevel == UserGroups::$USER) {
             $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $companyDealersManager->getByCompanyIdAndUserId($userId, $company_id);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $companyManager->selectByPK($company_id);
         assert($company);
         if ($price) {
             $pricePath = DATA_DIR . "/companies_prices/" . $price->getCompanyId() . '/' . $price->getFileName() . '.' . $price->getFileExt();
             if (file_exists($pricePath)) {
                 $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $price->getFileName());
             } else {
                 echo "file not exists!";
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "zipped_price_unzipped") {
         $zippedPriceId = $this->args[1];
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $price = $companiesPriceListManager->selectByPK($zippedPriceId);
         $company_id = $price->getCompanyId();
         if ($userLevel == UserGroups::$USER) {
             $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $companyDealersManager->getByCompanyIdAndUserId($userId, $company_id);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $companyManager->selectByPK($company_id);
         assert($company);
         if ($price) {
             $pricePath = DATA_DIR . "/companies_prices/" . $price->getCompanyId() . '/' . $price->getFileName() . '.' . $price->getFileExt();
             if (file_exists($pricePath)) {
                 $unzipPriceFile = $companiesPriceListManager->unzipFile($pricePath);
                 if (count($unzipPriceFile) === 1) {
                     $companiesPriceListManager->downloadFile($unzipPriceFile[0], $company->getShortName() . "_" . $price->getFileName());
                 } else {
                     $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $price->getFileName());
                 }
             } else {
                 echo "file not exists!";
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "service_zipped_price_unzipped") {
         $zippedPriceId = $this->args[1];
         $companiesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
         $price = $companiesPriceListManager->selectByPK($zippedPriceId);
         $company_id = $price->getServiceCompanyId();
         if ($userLevel == UserGroups::$USER) {
             $serviceCompanyDealersManager = ServiceCompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $serviceCompanyDealersManager->getByCompanyIdAndUserId($userId, $company_id);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $serviceCompanyManager->selectByPK($company_id);
         assert($company);
         if ($price) {
             $pricePath = DATA_DIR . "/service_companies_prices/" . $price->getServiceCompanyId() . '/' . $price->getFileName() . '.' . $price->getFileExt();
             if (file_exists($pricePath)) {
                 $unzipPriceFile = $companiesPriceListManager->unzipFile($pricePath);
                 if (count($unzipPriceFile) === 1) {
                     $companiesPriceListManager->downloadFile($unzipPriceFile[0], $company->getShortName() . "_" . $price->getFileName());
                 } else {
                     $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $price->getFileName());
                 }
             } else {
                 echo "file not exists!";
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "all_zipped_prices") {
         $companiesList = array();
         if ($userLevel == UserGroups::$COMPANY) {
             $companiesList = $companyManager->getAllCompaniesByPriceHours();
         }
         if ($userLevel == UserGroups::$USER) {
             $companiesList = $companyManager->getUserCompaniesJoindWithFullInfo($userId);
         }
         if ($userLevel == UserGroups::$ADMIN) {
             $companiesList = $companyManager->getAllCompaniesByPriceHours(0, "", true, true);
         }
         $filesPaths = array();
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         foreach ($companiesList as $company) {
             $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($company->getId());
             foreach ($companyLastPrices as $key => $companyLastPrice) {
                 $fileName = $companyLastPrice->getFileName() . '.' . $companyLastPrice->getFileExt();
                 $filesPaths[] = array(DATA_DIR . "/companies_prices/" . $company->getId() . '/' . $fileName, $company->getShortName() . '_' . $fileName . '_' . ($key + 1));
             }
         }
         $uid = uniqid();
         $this->createZip($filesPaths, DATA_DIR . "/temp/" . $uid . '.zip');
         $companiesPriceListManager->downloadFile(DATA_DIR . "/temp/" . $uid . '.zip', 'all');
         unlink(DATA_DIR . "/temp/" . $uid . '.zip');
     }
 }
 private function sendEmailToDealersEmails($companyExProfiledto, $byMandrill = false)
 {
     $dealerEmailsText = $companyExProfiledto->getDealerEmails();
     $dealerEmailsArray = explode(';', $dealerEmailsText);
     $subject = $companyExProfiledto->getPriceEmailSubject();
     $body = stripslashes($companyExProfiledto->getPriceEmailBody());
     $fromEmail = $companyExProfiledto->getFromEmail();
     $companyName = $this->getCustomer()->getName();
     $isServiceCompany = $this->getUserLevel() == UserGroups::$SERVICE_COMPANY;
     $priceFiles = array();
     if ($isServiceCompany) {
         $companiesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyId = $companyExProfiledto->getServiceCompanyId();
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             foreach ($companyLastPrices as $key => $clp) {
                 $priceFiles[] = DATA_DIR . "/service_companies_prices/" . $companyId . '/' . $clp->getFileName() . '.' . $clp->getFileExt();
             }
         }
         $tmpSubdirectoryName = 'service_companies';
     } else {
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyId = $companyExProfiledto->getCompanyId();
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             foreach ($companyLastPrices as $key => $clp) {
                 $priceFiles[] = DATA_DIR . "/companies_prices/" . $companyId . '/' . $clp->getFileName() . '.' . $clp->getFileExt();
             }
         }
         $tmpSubdirectoryName = 'companies';
     }
     $allEmailFileAttachments = array();
     foreach ($priceFiles as $key => $priceFile) {
         $pfnParts = explode('.', $priceFile);
         $priceFileExtention = end($pfnParts);
         if (file_exists($priceFile)) {
             $postfix = "";
             if ($key > 0) {
                 $postfix = '_' . ($key + 1);
             }
             $allEmailFileAttachments[$companyName . ' Pricelist' . $postfix . '.' . $priceFileExtention] = $priceFile;
         }
     }
     $additionalAttachedFiles = array();
     $dir = HTDOCS_TMP_DIR_ATTACHMENTS . '/' . $tmpSubdirectoryName . '/' . $companyId . '/';
     if (is_dir($dir)) {
         $additionalAttachedFiles = scandir($dir);
     }
     foreach ($additionalAttachedFiles as $file) {
         $fileFullPath = $dir . $file;
         if (is_file($fileFullPath)) {
             $path_parts = pathinfo($fileFullPath);
             $basename = $path_parts['basename'];
             $fileDisplayName = substr($basename, strpos($basename, '_') + 1);
             $allEmailFileAttachments[$fileDisplayName] = $fileFullPath;
         }
     }
     if ($byMandrill == true) {
         $mandrillEmailSenderManager = new MandrillEmailSenderManager($this->getCmsVar("mandrill_api_key"));
         $body .= '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>';
         $body .= '<p style="font-size:10px"><a href="*|UNSUB:http://pcstore.am/unsub/' . ($isServiceCompany ? 'sc' : 's') . '/' . $companyId . '|*">Click here to unsubscribe.</a></p>';
         $res = $mandrillEmailSenderManager->sendHtmlEmail($dealerEmailsArray, $subject, $body, $fromEmail, $companyName, $allEmailFileAttachments, ($isServiceCompany ? 'service_company' : 'company') . '_' . $companyId);
         $sentSuccess = is_array($res);
     } else {
         $emailSenderManager = new EmailSenderManager('gmail');
         $res = $emailSenderManager->sendBulkEmailWithAttachmentsUsingPcstoreEmails($dealerEmailsArray, $subject, $body, array(), $allEmailFileAttachments, $fromEmail, $companyName);
         $sentSuccess = $res === true;
     }
     if ($sentSuccess !== true) {
         return $res;
     } else {
         $companyPriceEmailHistoryManager = CompanyPriceEmailHistoryManager::getInstance($this->config, $this->args);
         $companyPriceEmailHistoryManager->addRow($companyId, $isServiceCompany ? "service_company" : "company", $fromEmail, $dealerEmailsArray, $body, $subject, array_keys($allEmailFileAttachments));
     }
     return true;
 }