ddek pisze:
Można by podzielić się tym przerobionym skryptem i podpowiedzieć w skróie jak to powiązać z Inteligo bo płatności masowych to w Inteligo nie ma więc jak u Ciebie działa na subkontach czy jako zgaduj zgadula z 1 konta ??
Akurat z 3 subkont, ale na zasadzie zgaduj zgadula:) Fakt ze brak opisu, wiec mam nadzieje ze autor sie nie obrazi jak opisze w kilku slowach co i jak u siebie odpalam. W lms.ini oczywiscie zamieszczamy sekcje:
[cashimport_inteligo] id='12345678' ;# login do inteligo pass='abcdef' ;# hasło account='111111111111' ;# nr konta -ostatnie 12 cyfr ;#wyciag_r='strftime "%Y", localtime(time-86400);# rok wyciągu ;#wyciag_m='strftime "%m", localtime(time-86400);# m-c wyciągu ;#wyciag_d='strftime "%d", localtime(time-86400);# d-n wyciągu ;trans_type='CREDIT' ;# ;history_dir='/var/lms/cashimport' ;# folder do zapisu kopi wyciągów
Skrypt odpalamy z crona najbezpieczniej raz dziennie. Sciaga on historie operacji z danego dnia i wrzuca dane do bazy dancyh. Dane widzimy w Finanse->import.
To chyba tyle:) Z przerobek skryptu, ktore w moim systemie dzialaja jest ustawienie kodowania na UTF-8 (takie mam kodowanie bazy) i zamiana znakow "" na znaki "/" (panie na poczcie niemilosiernie naduzywaja tego znaku przepisujac numeracje faktur). W nieprzerobionej wersji skrypt sie wykladal przy probie zapisu takich danych do bazy.
Co do celnosci "strzalow" to w naszym przypadku (ok 500 klientow) przelewy automatycznie sa dopisywane w ok 80%. Przy pozostalych trzeba z listy wybrac samemu klienta. 90% tych niecelnych strzalow to przelewy z poczty. Tam w tytule przelewu mile panie podaja najczesciej "kasa" i to co im sie w danej chwili zechce - nieraz id klienta, nieraz tylko rok - zalezy czy kawka im stygnie czy nie...
U nas akurat calym fakturowaniem itp zajmuje sie oddzielny program ksiegowy wiec wplat w lms'ie uzywamy tylko do "nekania" klientow nieplacacych na czas. Tak wiec nie zalezy nam na idealnym dzialaniu skryptu. Jezeli jakas wplata zaginie lub zostanie naliczona podwojnei to pod koniec miesiaca zostanie to wychwycone przy porownaniu danych z systemow.
pozdrawiam; Andrzej Banach
!DSPAM:47dad61741922048516912!
#!/usr/bin/perl -Tw # # LMS version 1.8.1 Shyla _ moded by ReYu # # (C) 2001-2006 LMS Developers # # Please, see the doc/AUTHORS for more information about authors! # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License Version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. # # $Id: lms-cashimport-Inteligo,v 1.1.2.2 2006/01/16 09:35:17 reyu Exp $
use strict; use DBI; use Config::IniFiles; use Getopt::Long; use HTTP::Cookies; use HTTP::Request::Common qw(POST GET); use Crypt::SSLeay; use LWP::UserAgent; use POSIX; use POSIX qw(mktime strftime); use HTML::TokeParser; use Time::Local; use vars qw($configfile $quiet $help $version); use Digest::MD5; use Text::Iconv;
my $_version = '1.8.1 Shyla moded by ReYu';
my %options = ( "--config-file|C=s" => $configfile, "--quiet|q" => $quiet, "--help|h" => $help, "--version|v" => $version, );
Getopt::Long::config("no_ignore_case"); GetOptions(%options);
if($help) { print STDERR <<EOF; lms-cashimport-inteligo, version $_version (C) 2001-2006 LMS Developers & ReYu
-C, --config-file=/etc/lms/lms.ini alternate config file (default: /etc/lms/lms.ini); -h, --help print this help and exit; -v, --version print version info and exit; -q, --quiet suppress any output, except errors;
EOF exit 0; }
if($version) { print STDERR <<EOF; lms-cashimport-inteligo, version $_version (C) 2001-2006 LMS Developers & ReYu
EOF exit 0; }
if(!$configfile) { $configfile = "/etc/lms/lms.ini"; }
if(!$quiet) { print STDOUT "lms-cashimport-inteligo, version $_version\n"; print STDOUT "(C) 2001-2006 LMS Developers & ReYu\n"; print STDOUT "Using file $configfile as config.\n"; }
if(! -r $configfile) { print STDERR "Fatal error: Unable to read configuration file $configfile, exiting.\n"; exit 1; }
my $ini = new Config::IniFiles -file => $configfile; print @Config::IniFiles::errors;
my $dbtype = $ini->val('database', 'type') || 'mysql'; my $dbhost = $ini->val('database', 'host') || 'localhost'; my $dbuser = $ini->val('database', 'user') || 'root'; my $dbpasswd = $ini->val('database', 'password') || ''; my $dbname = $ini->val('database', 'database') || 'lms';
my $login_i = $ini->val('cashimport_inteligo', 'id') || '12345678'; my $passwd_i = $ini->val('cashimport_inteligo', 'pass') || 'abcdef'; my $accounts = $ini->val('cashimport_inteligo', 'account') || '111111111111'; my $time_y = $ini->val('cashimport_inteligo', 'wyciag_r') || strftime "%Y", localtime(time-86400); my $time_m = $ini->val('cashimport_inteligo', 'wyciag_m') || strftime "%m", localtime(time-86400); my $time_d = $ini->val('cashimport_inteligo', 'wyciag_d') || strftime "%d", localtime(time-86400); my $trans_type = $ini->val('cashimport_inteligo', 'trans_type') || 'CREDIT'; my $file_out_dir = $ini->val('cashimport_inteligo', 'history_dir') || '/var/lms/cashimport';
my $dbase; my $time_d_t = 1; if($dbtype eq "mysql") { $dbase = DBI->connect("DBI:mysql:database=$dbname;host=$dbhost","$dbuser","$dbpasswd", { RaiseError => 1 }); } elsif($dbtype eq "postgres") { $dbase = DBI->connect("DBI:Pg:dbname=$dbname;host=$dbhost","$dbuser","$dbpasswd", { RaiseError => 1 }); } else { print STDERR "Fatal error: unsupported database type: $dbtype, exiting.\n"; exit 1; }
# Definicja Agenta http my $sd =''; my $cookie_jar = HTTP::Cookies->new; my $ua = new LWP::UserAgent; $ua->timeout(30); $ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4'); $ua->env_proxy();
# Wchodzimy na stronê my $get = new HTTP::Request(GET => 'https://secure.inteligo.com.pl/'); my $res = $ua->request($get); if ($res->content =~ /Przepraszamy/ ){ print "ERROR: System chwilowo niedostêpny", "\n"; exit 1; } if ($res->content =~ /Identyfikator/ ){ my $p = HTML::TokeParser->new($res->content); while ( my $token1 = $p->get_tag("input")){ if (my $ur = $token1->[1]{name} =~ /sd/){ my $url = $token1->[1]{name} || "-"; my $url2 = $token1->[1]{value} || "-"; $sd = $url2; } } } print "Logujemy do Serwisu ... \t"; my $post = POST 'https://secure.inteligo.com.pl/', [ sd => $sd, form_name => "login", btn_ok => "", menu => "", cif => $login_i, password => $passwd_i, btn_ok => "", ]; my $res1 = $ua->request($post); if ($res1->content =~ /Stan Twoich/ ){ print "Jestesmy zalogowani", "\n"; my $p = HTML::TokeParser->new($res1->content); while ( my $token1 = $p->get_tag("input")){ if (my $ur = $token1->[1]{name} eq "sd"){ my $url = $token1->[1]{name} || "-"; my $url2 = $token1->[1]{value} || "-"; $sd = $url2; } } } print "Przechodzimy do historii ...\t"; my $post1 = POST 'https://secure.inteligo.com.pl/web', [ sd => $sd, section => "mojerachunki", return_point => "1", form_name => "accounts", menu => "history", button => "", ]; $res = $ua->request($post1); if ($res->content =~ /Historia rachunku/ ){ print "Strona Historii Rachunku \n"; my $p1 = HTML::TokeParser->new($res->content); while ( my $token2 = $p1->get_tag("input")){ if (my $ur = $token2->[1]{name} eq "sd"){ my $url = $token2->[1]{name} || "-"; my $url2 = $token2->[1]{value} || "-"; $sd = $url2; } } } my @account = split (' ', $accounts); for (my $x=0;$x<scalar(@account);$x++){ my $konto = $account[$x];
print "Zmieniamy filtr historii....\t"; if ($time_d >1){ my $time_d_t =$time_d-1; }else{ $time_d_t =$time_d; } my $post2 = POST 'https://secure.inteligo.com.pl/web', [ sd => $sd, section => "mojerachunki", return_point => "1", form_name => "history", menu => "", button => "filter", selected_acc => $konto, beg_date_y => $time_y, beg_date_m => $time_m, beg_date_d => $time_d, # 1,#$time_d_t, end_date_y => $time_y, end_date_m => $time_m, end_date_d => $time_d, sel_tx_filter_type => $trans_type, amount_min => '', amount_max => '', export_type => 'CSV', ]; $res = $ua->request($post2); if ($res->content =~ /Historia rachunku/ ){ print "Zmieniono filtr \n"; my $p1 = HTML::TokeParser->new($res->content); while (my $token2 = $p1->get_tag("input")){ if (my $ur = $token2->[1]{name} eq "sd"){ my $url = $token2->[1]{name} || "-"; my $url2 = $token2->[1]{value} || "-"; $sd = $url2; } } } print "Pobieramy plik historii....\t"; my $post3 = POST 'https://secure.inteligo.com.pl/web', [ sd => $sd, section => "mojerachunki", return_point => "1", form_name => "history", menu => "", button => "export_list", selected_acc => $konto, beg_date_y => $time_y, beg_date_m => $time_m, beg_date_d => $time_d, end_date_y => $time_y, end_date_m => $time_m, end_date_d => $time_d, sel_tx_filter_type => $trans_type, amount_min => "", amount_max => "", export_type => "CSV", ]; $res = $ua->request($post3); my $post4 = 'https://secure.inteligo.com.pl' . $res->header('Location'); $post4 =GET $post4; $res =$ua->request($post4); print "Pobrano plik\n"; my @dana = split("\n", $res->content); my $file_name = $file_out_dir."/". $konto ."_". time(); if ($file_out_dir){ open (DOUT,">$file_name"); my $y = scalar(@dana) - 1 ; print DOUT "Ilo¶æ pozycji : ". $y ."\n" }
for (my $x=1;$x<scalar(@dana);$x++){ my $line = $dana[$x]; $line =~ s/"//g; #" $line =~ s/'//g; #' my $converter = Text::Iconv->new("ISO-8859-2","UTF-8"); $line = $converter->convert($line);
my @linia = split(",",$line); my @da = split('-',$linia[2]);
$linia[2] = mktime(0,0,0,$da[2],$da[1]-1, $da[0]-1900); $linia[4] =~ s/[^0-9.]//g; #$linia[8] = $converter->convert($linia[8]) || " "; #$linia[9] = $converter->convert($linia[9]) || " "; #$linia[10] = $converter->convert($linia[10]) || " "; #$linia[11] = $converter->convert($linia[11]) || " "; #$linia[12] = $converter->convert($linia[12]) || " "; $linia[8] = $linia[8] || " "; $linia[9] = $linia[9] || " "; $linia[10] = $linia[10] || " "; $linia[11] = $linia[11] || " "; $linia[12] = $linia[12] || " "; $linia[8] =~ s/.//g; $linia[9] =~ s/.//g; $linia[10] =~ s/.//g; $linia[11] =~ s/.//g; $linia[12] =~ s/.//g; $linia[9] =~ s{\}{/}g; $linia[10] =~ s{\}{/}g; $linia[11] =~ s{\}{/}g; $linia[12] =~ s{\}{/}g;
if ($file_out_dir){ print DOUT $line ."\n"; } my $date = $linia[2]; my $customer = $linia[8]; my $description = $linia[9] ." ". $linia[10] ." ". $linia[11] ." ". $linia[12]; my $value = $linia[4]; my $customerid = '0'; if ($description =~ m/SALDO/i){ my $customerid_t = $description; $customerid_t =~ s/.+SALDO//gi; $customerid_t =~ s/[^0-9 ]//g; $customerid_t =~ s/^\s+//; $customerid_t =~ s/[ ].*//; $customerid_t =~ s/\s+$//; $customerid = $customerid_t; } #if ($customerid == '0'){ #if ($description =~ m/KLIENT/i){ # my $customerid_t = $description; # $customerid_t =~ s/.+KLIENT//gi; # $customerid_t =~ s/[^0-9 ]//g; # $customerid_t =~ s/^\s+//; # $customerid_t =~ s/[ ].*//; # $customerid_t =~ s/\s+$//; # $customerid = $customerid_t; #}} if($customerid == '0'){ @da = split(" ", $linia[8]); $da[1] = $da[1] || " "; my $sdbq = $dbase->prepare("SELECT id FROM customers WHERE UPPER(lastname)=UPPER('$da[0]') and UPPER(name)=UPPER('$da[1]')"); $sdbq->execute; my $id = '0'; if (my $row = $sdbq->fetchrow_hashref()){ $customerid = $row->{'id'}; }else { my $sdbq = $dbase->prepare("SELECT id FROM customers WHERE UPPER(lastname)=UPPER('$da[1]') and UPPER(name)=UPPER('$da[0]')"); $sdbq->execute; if (my $row = $sdbq->fetchrow_hashref()){ $customerid = $row->{'id'}; } } } my $hash = $konto.$linia[0]; my $sdbq = $dbase->prepare("SELECT id FROM cashimport WHERE hash = '$hash'"); $sdbq->execute(); my $row = $sdbq->fetchrow_hashref(); if ($row->{'id'}) { print "ERROR: Hash exists, ignoring $customer \n"; } else { my $sdbq = $dbase->prepare("INSERT INTO cashimport ( Date , Value , Customer , Description , CustomerId , Hash ) VALUES ('$date', '$value', '$customer', '$description', '$customerid', '$hash');"); $sdbq->execute(); print $date ." ".$value." ".$customerid ." ". $hash ."\n"; } } close DOUT; } exit 1; print "ERROR: Nieznany b³±d"; exit 1;
!DSPAM:47dad61741922048516912!