database = $database; $this->db = $GLOBALS ['superGlobalDb']; $this->setConnectionVariables (); $this->createConnection (); } private function setConnectionVariables() { switch ($this->database) { // osielsko case 'preDb_d39c8b73a813a4207397148d71641909' : $this->MSSQL_HOST = "80.53.175.14:49245"; $this->MSSQL_DATABASE = "TOMBUD_PLUS_new"; $this->MSSQL_USERNAME = "sa"; $this->MSSQL_PASSWORD = "TOMbud1649"; break; } } private function createConnection() { try { $this->pdo = new \PDO ( sprintf ( "dblib:host=%s;dbname=%s", $this->MSSQL_HOST, $this->MSSQL_DATABASE ), $this->MSSQL_USERNAME, $this->MSSQL_PASSWORD ); $this->pdo->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); echo "con"; } catch ( PDOException $e ) { echo "There was a problem connecting. " . $e->getMessage (); } } public function getKody() { } public function importAccounts() { $this->db->query ( "delete from accounts" ); $this->db->query ( "delete from ecmtransactions" ); $this->db->query ( "delete from ecmtransactions_rel" ); $query = "SELECT [kh__Kontrahent].[kh_Symbol], [kh__Kontrahent].[kh_Email], [adr__Ewid].[adr_IdObiektu], [adr__Ewid].[adr_Id], [adr__Ewid].[adr_NazwaPelna], [adr__Ewid].[adr_Telefon], [adr__Ewid].[adr_Adres], [adr__Ewid].[adr_Miejscowosc], [adr__Ewid].[adr_Kod], [adr__Ewid].[adr_NIP] FROM [dbo].[adr__Ewid] inner join [TOMBUD_PLUS_new].[dbo].[kh__Kontrahent] on [kh__Kontrahent].[kh_Id]=[adr__Ewid].[adr_IdObiektu] where [adr_TypAdresu]=1 "; //and [kh_Id]='9515' $statement = $this->pdo->prepare ( $query ); $statement->execute (); $results = $statement->fetchAll ( PDO::FETCH_ASSOC ); foreach ( $results as $result ) { $a = new Account (); $a->index_dbf = iconv ( "CP1250", "UTF-8", $result ["kh_Symbol"] ); $a->name = iconv ( "CP1250", "UTF-8", $result ["adr_NazwaPelna"] ); $a->phone_office = iconv ( "CP1250", "UTF-8", $result ["adr_Telefon"] ); $a->register_address_street = iconv ( "CP1250", "UTF-8", $result ["adr_Adres"] ); $a->register_address_city = iconv ( "CP1250", "UTF-8", $result ["adr_Miejscowosc"] ); $a->register_address_postalcode = iconv ( "CP1250", "UTF-8", $result ["adr_Kod"] ); $a->to_vatid = iconv ( "CP1250", "UTF-8", $result ["adr_NIP"] ); $a->email1 = iconv ( "CP1250", "UTF-8", $result ["kh_Email"] ); $query2 = "SELECT [sl_CechaKh].[ckh_Nazwa] FROM [dbo].[kh_CechaKh] inner join [dbo].[sl_CechaKh] on [sl_CechaKh].[ckh_Id]=[kh_CechaKh].[ck_IdCecha] where [kh_CechaKh].[ck_IdKhnt]='" . $result ["adr_IdObiektu"] . "'"; $statement2 = $this->pdo->prepare ( $query2 ); $statement2->execute (); $results2 = $statement2->fetchAll ( PDO::FETCH_ASSOC ); foreach ( $results2 as $result2 ) { if ($result2 ['ckh_Nazwa'] == 'przypomnienie_SMS') { $a->allow_prevent = 1; } if ($result2 ['ckh_Nazwa'] == 'przypomnienie_E-MAIL') { $a->allow_debt_collection = 1; } } $query3 = "SELECT [tel_Numer] FROM [TOMBUD_PLUS_new].[dbo].[tel__Ewid] where [tel__Ewid].[tel_IdAdresu]='" . $result ["adr_Id"] . "'"; $statement3 = $this->pdo->prepare ( $query3 ); $statement3->execute (); $results3 = $statement3->fetchAll ( PDO::FETCH_ASSOC ); $tels = array (); foreach ( $results3 as $result3 ) { if ($result3 ['tel_Numer'] != '') { $result3 ['tel_Numer'] = str_replace ( " ", "", $result3 ['tel_Numer'] ); $result3 ['tel_Numer'] = str_replace ( "-", "", $result3 ['tel_Numer'] ); $result3 ['tel_Numer'] = str_replace ( "/", "", $result3 ['tel_Numer'] ); } $p = array (); $p ['telephone'] = $result3 ['tel_Numer']; $tels [] = $p; } $a->save (); $a->saveTelephonesList ( $tels ); $this->getTransactions ( $result ["adr_IdObiektu"], $a ); } // var_dump(iconv("CP1250","UTF-8",$results[0]["adr_Nazwa"])); } public function getTransactions($id, $a) { $query = "SELECT [nz__Finanse].[nzf_NumerPelny], [nz__Finanse].[nzf_WartoscPierwotna], [nz__Finanse].[nzf_Wartosc], [nz__Finanse].[nzf_Data], [nz__Finanse].[nzf_TerminPlatnosci], [nz__Finanse].[nzf_Id] FROM [dbo].[nz__Finanse] where [nzf_IdObiektu]='" . $id . "' and [nzf_Data] between DateAdd(DD,-60,GETDATE() ) and GETDATE()"; $statement = $this->pdo->prepare ( $query ); $statement->execute (); $results = $statement->fetchAll ( PDO::FETCH_ASSOC ); foreach ( $results as $result ) { $t = new EcmTransaction (); $t->name = iconv ( "CP1250", "UTF-8", $result ["nzf_NumerPelny"] ); if ($result ["nzf_Typ"] == '39') { $t->type = 0; $t->value = str_replace ( ".", ",", $result ["nzf_WartoscPierwotna"] ); } if ($result ["nzf_Typ"] == '18') { $t->type = 0; $t->value = str_replace ( ".", ",", $result ["nzf_Wartosc"] ); } if ($result ["nzf_Typ"] == '20') { $t->type = 0; $t->value = str_replace ( ".", ",", $result ["nzf_Wartosc"] ); } if ($result ["nzf_Typ"] == '42') { $t->type = 0; $t->value = str_replace ( ".", ",", $result ["nzf_Wartosc"] ); } if ($result ["nzf_Typ"] == '41') { $t->type = 0; $t->value = str_replace ( ".", ",", $result ["nzf_Wartosc"] ); } if ($result ["nzf_Typ"] == '17' || $result ["nzf_Typ"] == '19') { $t->type = 1; $t->value = str_replace ( ".", ",", $result ["nzf_Wartosc"] ); } if ($result ["nzf_Typ"] == '40') { $t->type = 1; $t->value = str_replace ( ".", ",", $result ["nzf_WartoscPierwotna"] ); } $t->register_date = date ( "d.m.Y", strtotime ( $result ["nzf_Data"] ) ); if ($result ["nzf_TerminPlatnosci"] != '') { $t->payment_date = date ( "d.m.Y", strtotime ( $result ["nzf_TerminPlatnosci"] ) ); } else { $t->payment_date = date ( "d.m.Y", strtotime ( $result ["nzf_Data"] ) ); } $t->parent_id = $a->id; $t->parent_name = $a->name; $t->currency_id = "PLN"; $t->parent_index = $result ["nzf_Id"]; $t->save ( true ); } $query = "SELECT [nz__Finanse].[nzf_Id] FROM [dbo].[nz__Finanse] where [nzf_IdObiektu]='" . $id . "'"; $statement = $this->pdo->prepare ( $query ); $statement->execute (); $results = $statement->fetchAll ( PDO::FETCH_ASSOC ); foreach ($results as $result){ $query2 = "SELECT [nz_FinanseSplata].[nzs_IdDlugu],[nz_FinanseSplata].[nzs_IdSplaty],[nz_FinanseSplata].[nzs_WartoscWaluta] FROM [dbo].[nz_FinanseSplata] where [nzs_IdDlugu]='" . $result['nzf_Id'] . "'"; $statement2 = $this->pdo->prepare ( $query2 ); $statement2->execute (); $results2 = $statement2->fetchAll ( PDO::FETCH_ASSOC ); foreach ($results2 as $result2){ $t = new EcmTransaction(); $t2 = new EcmTransaction(); $t->retrieve_by_string_fields (array('parent_index'=>$result2['nzs_IdDlugu'])); $t2->retrieve_by_string_fields (array('parent_index'=>$result2['nzs_IdSplaty'])); $t->createRelation($t->id,$result2['nzs_WartoscWaluta'],$t2->id); } } } } ?>