/[informatika.old]/print/izvjestaj.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /print/izvjestaj.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Thu Apr 27 10:57:11 2000 UTC (24 years ago) by dpavlin
Branch: MAIN
Changes since 1.1: +10 -0 lines
File MIME type: text/plain
podr¹ka za debug

1 dpavlin 1.1 #!/usr/local/bin/perl -w
2    
3     use strict;
4    
5 dpavlin 1.2 my $debug=1;
6    
7 dpavlin 1.1 use DBI;
8     use POSIX qw(strftime);
9    
10 dpavlin 1.2 print STDERR "Debug mod: output je u /tmp/debug*\n" if ($debug);
11    
12 dpavlin 1.1 my $currdate = strftime "%d.%m.%Y %H:%M:%S", localtime;
13    
14     my $html_file=$currdate;
15     $html_file=~s/ /_/g;
16     $html_file="izvjestaji/$html_file.html";
17    
18 dpavlin 1.2 if (! $debug) {
19 dpavlin 1.1 open(HTML,"> $html_file") || die "html: $!";
20     open(MAIL,"|/usr/lib/sendmail biljana.gombar\@pliva.hr,izvjestaji\@support.pliva.hr") || die "sendmail: $!";
21 dpavlin 1.2 } else {
22     open(HTML,"> /tmp/debug$$.html") || die "html: $!";
23     open(MAIL,"> /tmp/debug$$.mail") || die "sendmail: $!";
24     }
25 dpavlin 1.1
26     print HTML '
27     <html>
28     <title>Danas otvoreni raèuni</title>
29     <body bgcolor="#ffffff">
30     <h1>Danas otvoreni raèuni</h1>
31     ';
32    
33     print MAIL 'From: PlivaNet Core Support Team <pcst@pliva.hr>
34     Subject: otvoreni raèuni za e-mail
35    
36     ';
37    
38     my $dbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr;
39     $dbh->do("set datestyle = 'german'") || die $dbh->errstr();
40    
41     my $sth = $dbh->prepare("select id from last_print order by id desc limit 1,1");
42     $sth->execute() || die $sth->errstr();
43     my ($print_from_id) = $sth->fetchrow_array();
44    
45     $sth = $dbh->prepare("select osoba_id,max(status_tip_id) from status
46     where osoba_id > $print_from_id
47     group by osoba_id
48     ") || die $dbh->errstr();
49     $sth->execute() || die $sth->errstr();
50    
51     my @osoba_id_za_print;
52    
53     while (my ($osoba_id,$status_tip_id) = $sth->fetchrow_array() ) {
54     if ($status_tip_id == 5) { # print
55     push @osoba_id_za_print,$osoba_id;
56     }
57     }
58    
59     print MAIL "Otvorenih raèuna: ",$#osoba_id_za_print+1,"
60     Datum i vrijeme generiranja izvje¹taja: $currdate
61    
62     Izvje¹taj se nalazi i na
63     http://support.pliva.hr/$html_file
64     (npr. za ispis na ¹tampaèu)
65    
66     ";
67     print HTML "Otvorenih raèuna: ",$#osoba_id_za_print+1,"
68     <br>Datum i vrijeme generiranja izvje¹taja: $currdate<p>";
69    
70     $sth = $dbh->prepare("
71     select osobe.id,ime,prezime,tel,lokacije.naziv,
72     org_jed.naziv,org_pod_jed.pod_naziv,
73     lok_racunala,objekt,kat,soba,z_rac
74     from osobe
75     where osobe.id in (".join(",",@osoba_id_za_print).")
76     and lokacija_id=lokacije.id and org_jed_id=org_jed.id
77     and org_pod_jed_id=org_pod_jed.pod_id
78     order by lokacije.naziv,org_jed.naziv
79     ") || die $dbh->errstr();
80     $sth->execute() || die $sth->errstr();
81    
82     my $rbr=1;
83    
84     printf MAIL ("%3s %4s %-20s %4s %-30s %-20s\n","rbr","id","ime i prezime","tel","lokacija","org.jed");
85     print HTML '<table border=1>
86     <tr bgcolor="#e0e0f0"><th>rbr</th><th>id</th><th>ime i prezime</th><th>tel</th><th>lokacija</th><th>org.jed</th></tr>
87     ';
88    
89     while (my @arr = $sth->fetchrow_array() ) {
90     printf MAIL ("%3s %4s %-20s %4s %-30s %-20s\n",$rbr,$arr[0],"$arr[1] $arr[2]",$arr[3],$arr[4],"$arr[5] $arr[6]");
91     print HTML "<tr><td>$rbr</td><td>$arr[0]</td><td>$arr[1] $arr[2]</td><td>$arr[3]</td><td>$arr[4]</td><td>$arr[5]<br>$arr[6]</td></tr>\n";
92     $rbr++;
93     }
94    
95     $sth->finish;
96    
97     print HTML '
98     </table>
99     </body>
100     ';
101    
102     close(HTML);
103     close(MAIL);
104 dpavlin 1.2

  ViewVC Help
Powered by ViewVC 1.1.26