/**
  * @author Okan CIRAN
  * @ info_firm_keys tablosuna yeni bir kayıt oluşturur.  !!
  * @version v 1.0  17/03/2016
  * @return array
  * @throws \PDOException
  */
 public function insert($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         //  $pdo->beginTransaction();
         $CountryCode = NULL;
         $CountryCodeValue = 'TR';
         if (isset($params['country_id']) && $params['country_id'] != "") {
             $CountryCode = SysCountrys::getCountryCode(array('country_id' => $params['country_id']));
             if (\Utill\Dal\Helper::haveRecord($CountryCode)) {
                 $CountryCodeValue = $CountryCode['resultSet'][0]['country_code'];
             }
         }
         $sql = "\n                INSERT INTO info_firm_keys(   \n                        firm_id,\n                        network_key,\n                        machines_folder, \n                        logos_folder, \n                        products_folder, \n                        members_folder, \n                        others_folder,\n                        folder_name\n                       )\n                VALUES (\n                        :firm_id, \n                        CONCAT('" . $CountryCodeValue . "',ostim_id_generator()),\n                        'Machines',\n                        'Logos',\n                        'Products',\n                        'Members',\n                        'Others',\n                        'x'\n                                              )  ";
         $statement = $pdo->prepare($sql);
         $statement->bindValue(':firm_id', $params['firm_id'], \PDO::PARAM_STR);
         //  echo debugPDO($sql, $params);
         $result = $statement->execute();
         $insertID = $pdo->lastInsertId('info_firm_keys_id_seq');
         $errorInfo = $statement->errorInfo();
         InfoFirmKeys::setFirmPrivateKey(array('id' => $insertID));
         if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
             throw new \PDOException($errorInfo[0]);
         }
         //  $pdo->commit();
         return array("found" => true, "errorInfo" => $errorInfo, "lastInsertId" => $insertID);
     } catch (\PDOException $e) {
         // $pdo->rollback();
         return array("found" => false, "errorInfo" => $e->getMessage());
     }
 }
 /** 
  * @author Okan CIRAN
  * @ userin yaptığı aktif kayıt bilgisini info_firm_profile tablosundan döndürür !!
  * @version v 1.0  09.02.2016
  * @param array | null $args
  * @return array
  * @throws \PDOException
  */
 public function fillFirmFullVerbal($params = array())
 {
     try {
         $pdo = $this->slimApp->getServiceManager()->get('pgConnectFactory');
         $getFirmId = -1;
         $getFirm = InfoFirmProfile::getFirmIdsForNetworkKey(array('network_key' => $params['network_key']));
         if (\Utill\Dal\Helper::haveRecord($getFirm)) {
             $getFirmId = $getFirm['resultSet'][0]['firm_id'];
             $endOfId = $this->getFirmEndOfId(array('firm_id' => $getFirmId));
             if (\Utill\Dal\Helper::haveRecord($endOfId)) {
                 $languageId = NULL;
                 $languageIdValue = 647;
                 if (isset($params['language_code']) && $params['language_code'] != "") {
                     $languageId = SysLanguage::getLanguageId(array('language_code' => $params['language_code']));
                     if (\Utill\Dal\Helper::haveRecord($languageId)) {
                         $languageIdValue = $languageId['resultSet'][0]['id'];
                     }
                 }
                 $CPKValue = NULL;
                 $CPK = InfoFirmKeys::getCPK(array('network_key' => $params['network_key']));
                 if (\Utill\Dal\Helper::haveRecord($CPK)) {
                     $CPKValue = $CPK['resultSet'][0]['cpk'];
                 }
                 $sql = "\n                SELECT \n                    ifv.id,                    \n                    a.profile_public,                     \n                    a.s_date, \n                    a.c_date,                     \n                    COALESCE(NULLIF(COALESCE(NULLIF(ax.firm_name, ''), a.firm_name_eng), ''), a.firm_name) AS firm_name,\n                    a.firm_name_eng,\n\t\t    COALESCE(NULLIF(COALESCE(NULLIF(ax.firm_name_short, ''), a.firm_name_short_eng), ''), a.firm_name_short) AS firm_name_short,\n\t\t    a.firm_name_short_eng,\n\t\t    a.web_address,\n                    a.country_id,                   \n\t\t    COALESCE(NULLIF(cox.name, ''), co.name_eng) AS country_name,\n\t\t    co.name_eng AS country_name_eng,\n                    COALESCE(NULLIF(ifvx.about, ''), ifv.about_eng) AS about,\n                    ifv.about_eng,\n                    COALESCE(NULLIF(ifvx.verbal1_title, ''), ifv.verbal1_title_eng) AS verbal1_title,\n                    ifv.verbal1_title_eng,\n                    COALESCE(NULLIF(ifvx.verbal1, ''), ifv.verbal1_eng) AS verbal1,\n                    ifv.verbal1_eng,\n                    COALESCE(NULLIF(ifvx.verbal2_title, ''), ifv.verbal2_title_eng) AS verbal2_title,\n                    ifv.verbal2_title_eng,\n                    COALESCE(NULLIF(ifvx.verbal2, ''), ifv.verbal2_eng) AS verbal2,\n                    ifv.verbal2_eng,\n                    COALESCE(NULLIF(ifvx.verbal3_title, ''), ifv.verbal3_title_eng) AS verbal3_title,\n                    ifv.verbal3_title_eng,\n                    COALESCE(NULLIF(ifvx.verbal3, ''), ifv.verbal3_eng) AS verbal3,\n                    ifv.verbal3_eng,\n                    a.duns_number,                    \n                    a.tax_office, \n                    a.tax_no, \n                    a.foundation_yearx,\n                    a.act_parent_id,\n                    COALESCE(NULLIF(lx.id, NULL), 385) AS language_id,\n\t\t    COALESCE(NULLIF(lx.language, ''), 'en') AS language_name,                    \n                    a.operation_type_id,                   \n                    COALESCE(NULLIF(opx.operation_name, ''), op.operation_name_eng) AS operation_name,\n                    op.operation_name_eng,\n                    a.active,                \n                    COALESCE(NULLIF(sd16x.description, ''), sd16.description_eng) AS state_active,    \n                    a.deleted,                  \n                    COALESCE(NULLIF(sd15x.description, ''), sd15.description_eng) AS state_deleted,    \n                    a.op_user_id,\n                    u.username,                    \n                    a.auth_allow_id,                    \n                    COALESCE(NULLIF(sd13x.description, ''), sd13.description_eng) AS auth_alow,    \n                    a.cons_allow_id,                   \n                    COALESCE(NULLIF(sd14x.description, ''), sd14.description_eng) AS cons_allow,    \n                    a.language_parent_id,  \n                    ifk.network_key,                  \n                    CASE COALESCE(NULLIF(a.logo, ''),'-') \n                        WHEN '-' THEN CONCAT(COALESCE(NULLIF(concat(sps.folder_road,'/'), '/'),''),sps.logos_folder,'/' ,COALESCE(NULLIF(a.logo, ''),'image_not_found.png'))\n                        ELSE CONCAT(ifk.folder_name ,'/',ifk.logos_folder,'/' ,COALESCE(NULLIF(a.logo, ''),'image_not_found.png')) END AS logo,\n                    a.place_point,\n                    '" . $CPKValue . "' AS cpk\n                FROM info_firm_profile a  \n                INNER JOIN sys_project_settings sps ON sps.op_project_id = 1 AND sps.active =0 AND sps.deleted =0  \n                INNER JOIN info_firm_keys ifk ON ifk.firm_id =  a.act_parent_id \n                INNER JOIN sys_language l ON l.id = a.language_id AND l.deleted =0 AND l.active =0 \n                LEFT JOIN sys_language lx ON lx.id = " . intval($languageIdValue) . " AND l.deleted =0 AND l.active =0 \n\t\tLEFT JOIN info_firm_profile ax ON (ax.id = a.id OR ax.language_parent_id = a.id) AND ax.language_id = lx.id AND ax.active =0 AND ax.deleted =0\n\t\tLEFT JOIN info_firm_verbal ifv ON ifv.firm_id = ifk.firm_id AND ifv.deleted = 0 AND ifv.active =0 AND ifv.language_parent_id=0  \n\t\tLEFT JOIN info_firm_verbal ifvx ON (ifvx.id = ifv.id OR ifvx.language_parent_id = ifv.id) AND ifvx.deleted = 0 AND ifvx.active =0 AND ifvx.language_id = lx.id \n                INNER JOIN sys_operation_types op ON op.id = a.operation_type_id AND op.language_id = a.language_id AND op.deleted =0 AND op.active =0\n\t\tLEFT JOIN sys_operation_types opx ON (opx.id = op.id OR opx.language_parent_id = op.id) AND opx.language_id = lx.id AND opx.deleted =0 AND opx.active =0\n                INNER JOIN sys_specific_definitions sd13 ON sd13.main_group = 13 AND sd13.language_id = a.language_id AND a.auth_allow_id = sd13.first_group AND sd13.deleted =0 AND sd13.active =0\n                LEFT JOIN sys_specific_definitions sd13x ON (sd13x.id = sd13.id OR sd13.language_parent_id = sd13.id) AND sd13x.language_id = lx.id AND sd13x.deleted =0 AND sd13x.active =0\n                INNER JOIN sys_specific_definitions sd14 ON sd14.main_group = 14 AND sd14.language_id = a.language_id AND a.cons_allow_id = sd14.first_group AND sd14.deleted =0 AND sd14.active =0\n                LEFT JOIN sys_specific_definitions sd14x ON (sd14x.id = sd14.id OR sd14.language_parent_id = sd14.id) AND sd14x.language_id = lx.id AND sd14x.deleted =0 AND sd14x.active =0\n                INNER JOIN sys_specific_definitions sd15 ON sd15.main_group = 15 AND sd15.first_group= a.deleted AND sd15.language_id = a.language_id AND sd15.deleted =0 AND sd15.active =0 \n                LEFT JOIN sys_specific_definitions sd15x ON (sd15x.id = sd15.id OR sd15.language_parent_id = sd15.id) AND sd15x.language_id = lx.id AND sd15x.deleted =0 AND sd15x.active =0\n                INNER JOIN sys_specific_definitions sd16 ON sd16.main_group = 16 AND sd16.first_group= a.active AND sd16.language_id = a.language_id AND sd16.deleted = 0 AND sd16.active = 0\n                LEFT JOIN sys_specific_definitions sd16x ON (sd16x.id = sd16.id OR sd16.language_parent_id = sd16.id) AND sd16x.language_id = lx.id AND sd16x.deleted =0 AND sd16x.active =0\n                \n                INNER JOIN info_users u ON u.id = a.op_user_id                                      \n                INNER JOIN sys_countrys co ON co.id = a.country_id AND co.deleted = 0 AND co.active = 0 AND co.language_id = a.language_id\n                LEFT JOIN sys_countrys cox ON (cox.id = a.country_id OR cox.language_parent_id = a.country_id) AND cox.deleted = 0 AND cox.active = 0 AND cox.language_id = lx.id\t\t\n                WHERE    \n                    a.id = " . $endOfId['resultSet'][0]['firm_id'] . "                 \n                ";
                 $statement = $pdo->prepare($sql);
                 //    echo debugPDO($sql, $params);
                 $statement->execute();
                 $result = $statement->fetchAll(\PDO::FETCH_ASSOC);
                 $errorInfo = $statement->errorInfo();
                 if ($errorInfo[0] != "00000" && $errorInfo[1] != NULL && $errorInfo[2] != NULL) {
                     throw new \PDOException($errorInfo[0]);
                 }
                 return array("found" => true, "errorInfo" => $errorInfo, "resultSet" => $result);
             } else {
                 $errorInfo = '23502';
                 // 23502  user_id not_null_violation
                 $errorInfoColumn = 'firm_id';
                 return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
             }
         } else {
             $errorInfo = '23502';
             // 23502  user_id not_null_violation
             $errorInfoColumn = 'network_key';
             return array("found" => false, "errorInfo" => $errorInfo, "resultSet" => '', "errorInfoColumn" => $errorInfoColumn);
         }
     } catch (\PDOException $e) {
         //$debugSQLParams = $statement->debugDumpParams();
         return array("found" => false, "errorInfo" => $e->getMessage());
     }
 }