Just changed the intro text
[koha.git] / koha-curses / circ.pl
1 #!/usr/bin/perl -w
2
3 # $Id$
4
5 # Copyright 2005 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use lib '/usr/local/koha/intranet/modules';
24 use Curses::UI;
25 use C4::Circulation::Circ2;
26 use C4::Search;
27
28 my $cui = new Curses::UI( -color_support => 1 );
29
30 my @menu = (
31     {
32         -label   => 'File',
33         -submenu => [
34             { -label => 'Issues   ^I', -value => \&issues },
35             { -label => 'Returns  ^R', -value => \&returns },
36             { -label => 'Exit     ^Q', -value => \&exit_dialog }
37         ]
38     },
39 );
40
41 my $menu = $cui->add(
42     'menu', 'Menubar',
43     -menu => \@menu,
44     -fg   => "blue",
45 );
46
47 my $win1 = $cui->add(
48     'win1', 'Window',
49     -border => 1,
50     -y      => 1,
51     -bfg    => 'red',
52     -width  => 40,
53 );
54
55 my $win2 = $cui->add(
56     'win2', 'Window',
57     -border => 1,
58     -y      => 1,
59     -x      => 40,
60     -height => 10,
61     -bfg    => 'red',
62 );
63
64 my $win3 = $cui->add(
65     'win3', 'Window',
66     -border => 1,
67     -y      => 11,
68     -x      => 40,
69     -height => 10,
70     -bfg    => 'red',
71 );
72
73 my $texteditor =
74   $win1->add( "text", "TextEditor",
75     -text => "This is the first cut of a \ncirculations system using Curses::UI\n".
76   "Use the menus (or the keyboard\nshortcuts) to choose issues or \nreturns");
77
78 $cui->set_binding( sub { $menu->focus() }, "\cX" );
79 $cui->set_binding( \&exit_dialog, "\cQ" );
80 $cui->set_binding( \&issues,      "\cI" );
81 $cui->set_binding( \&returns,     "\cR" );
82
83 $texteditor->focus();
84 $cui->mainloop();
85
86 sub exit_dialog() {
87     my $return = $cui->dialog(
88         -message => "Do you really want to quit?",
89         -title   => "Are you sure???",
90         -buttons => [ 'yes', 'no' ],
91
92     );
93
94     exit(0) if $return;
95 }
96
97 sub returns {
98     my $barcode = $cui->question(
99         -title    => 'Returns',
100         -question => 'Barcode'
101     );
102     my $branch = 'MAIN';
103     my %env;
104     if ($barcode) {
105         my ( $returned, $messages, $iteminformation, $borrower ) =
106           returnbook( $barcode, $branch );
107         if ( $borrower && $borrower->{'borrowernumber'} ) {
108             $borrower =
109               getpatroninformation( \%env, $borrower->{'borrowernumber'}, 0 );
110             $win1->delete('borrowerdata');
111             my $borrowerdata = $win1->add( 'borrowerdata', 'TextViewer',
112                 -text => "Cardnumber: $borrower->{'cardnumber'}\n"
113                   . "Name: $borrower->{'title'} $borrower->{'firstname'} $borrower->{'surname'}"
114             );
115
116             $borrowerdata->focus();
117         }
118         else {
119             $cui->error( -message => 'That item isnt on loan' );
120         }
121     }
122 }
123
124 sub issues {
125
126     # this routine does the actual issuing
127
128     my %env;
129     my $borrowernumber;
130     my $borrowerlist;
131
132    # the librarian can overide system issue date, need to fetch values from them
133     my $year;
134     my $month;
135     my $day;
136     my $datedue;
137
138     $win1->delete('text');
139
140     # get a cardnumber or a name
141     my $cardnumber = $cui->question(
142         -title    => 'Issues',
143         -question => 'Cardnumber'
144     );
145
146     # search for that borrower
147     my ( $count, $borrowers ) =
148       BornameSearch( \%env, $cardnumber, 'cardnumber', 'web' );
149     my @borrowers = @$borrowers;
150     if ( $#borrowers == -1 ) {
151         $cui->error( -message =>
152               'No borrowers match that name or cardnumber please try again.' );
153     }
154     elsif ( $#borrowers == 0 ) {
155         $borrowernumber = $borrowers[0]->{'borrowernumber'};
156     }
157     else {
158         $borrowerlist = \@borrowers;
159     }
160
161     if ($borrowernumber) {
162
163         # if we have one single borrower, we can start issuing
164         my $borrower = getpatroninformation( \%env, $borrowernumber, 0 );
165         $win1->delete('borrowerdata');
166         my $borrowerdata = $win1->add( 'borrowerdata', 'TextViewer',
167             -text => "Cardnumber: $borrower->{'cardnumber'}\n"
168               . "Name: $borrower->{'title'} $borrower->{'firstname'} $borrower->{'surname'}"
169         );
170
171         $borrowerdata->focus();
172
173         $win3->delete('pastissues');
174         my $issueslist = getissues($borrower);
175         my $oldissues;
176         foreach my $it ( keys %$issueslist ) {
177             $oldissues .=
178               $issueslist->{$it}->{'barcode'}
179               . " $issueslist->{$it}->{'title'} $issueslist->{$it}->{'date_due'}\n";
180
181         }
182
183         my $pastissues =
184           $win3->add( 'pastissues', 'TextViewer', -text => $oldissues, );
185         $pastissues->focus();
186
187         $win2->delete('currentissues');
188         my $currentissues =
189           $win2->add( 'currentissues', 'TextViewer',
190             -text => "Todays issues go here", );
191         $currentissues->focus();
192
193         # go into a loop issuing until a blank barcode is given
194         while ( my $barcode = $cui->question( -question => 'Barcode' ) ) {
195             my $issueconfirmed;
196             my ( $error, $question ) =
197               canbookbeissued( \%env, $borrower, $barcode, $year, $month,
198                 $day );
199             my $noerror    = 1;
200             my $noquestion = 1;
201             foreach my $impossible ( keys %$error ) {
202                 $cui->error( -message => $impossible );
203                 $noerror = 0;
204             }
205
206             foreach my $needsconfirmation ( keys %$question ) {
207                 $noquestion     = 0;
208                 $issueconfirmed = $cui->dialog(
209                     -message => $needsconfirmation,
210                     -title   => "Confirmation",
211                     -buttons => [ 'yes', 'no' ],
212
213                 );
214
215             }
216             if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
217                 issuebook( \%env, $borrower, $barcode, $datedue );
218             }
219
220         }
221
222     }
223     elsif ($borrowerlist) {
224         my $listbox = $win1->add(
225             'mylistbox',
226             'Listbox',
227             -values => [ 1, 2, 3 ],
228             -labels => {
229                 1 => 'One',
230                 2 => 'Two',
231                 3 => 'Three'
232             },
233             -radio => 1,
234         );
235
236         $listbox->focus();
237         my $selected = $listbox->get();
238     }
239     else {
240     }
241 }