5 # Copyright 2005 Katipo Communications
7 # This file is part of Koha.
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
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.
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
23 use lib '/usr/local/koha/intranet/modules';
25 use C4::Circulation::Circ2;
29 my $cui = new Curses::UI( -color_support => 1 );
35 { -label => 'Issues ^I', -value => \&issues },
36 { -label => 'Returns ^R', -value => \&returns },
37 { -label => 'Exit ^Q', -value => \&exit_dialog }
74 my $texteditor = $win1->add( "text", "TextEditor",
76 "This is the first cut of a \ncirculations system using Curses::UI\n"
77 . "Use the menus (or the keyboard\nshortcuts) to choose issues or \nreturns"
80 $cui->set_binding( sub { $menu->focus() }, "\cX" );
81 $cui->set_binding( \&exit_dialog, "\cQ" );
82 $cui->set_binding( \&issues, "\cI" );
83 $cui->set_binding( \&returns, "\cR" );
89 my $return = $cui->dialog(
90 -message => "Do you really want to quit?",
91 -title => "Are you sure???",
92 -buttons => [ 'yes', 'no' ],
100 my $barcode = $cui->question(
102 -question => 'Barcode'
107 my ( $returned, $messages, $iteminformation, $borrower ) =
108 returnbook( $barcode, $branch );
109 if ( $borrower && $borrower->{'borrowernumber'} ) {
111 getpatroninformation( \%env, $borrower->{'borrowernumber'}, 0 );
112 $win1->delete('borrowerdata');
113 my $borrowerdata = $win1->add(
114 'borrowerdata', 'TextViewer',
115 -text => "Cardnumber: $borrower->{'cardnumber'}\n"
116 . "Name: $borrower->{'title'} $borrower->{'firstname'} $borrower->{'surname'}\n"
120 $borrowerdata->focus();
123 $cui->error( -message => 'That item isnt on loan' );
130 # this routine does the actual issuing
136 # the librarian can overide system issue date, need to fetch values from them
141 $win1->delete('text');
143 # get a cardnumber or a name
144 my $cardnumber = $cui->question(
146 -question => 'Cardnumber'
149 # search for that borrower
150 my ( $count, $borrowers ) =
151 BornameSearch( \%env, $cardnumber, 'cardnumber', 'web' );
152 my @borrowers = @$borrowers;
153 if ( $#borrowers == -1 ) {
154 $cui->error( -message =>
155 'No borrowers match that name or cardnumber please try again.' );
157 elsif ( $#borrowers == 0 ) {
158 $borrowernumber = $borrowers[0]->{'borrowernumber'};
161 $borrowerlist = \@borrowers;
164 if ($borrowernumber) {
166 # if we have one single borrower, we can start issuing
167 doissues( $borrowernumber, \%env, $year, $month, $day );
169 elsif ($borrowerlist) {
171 # choose from a list then start issuing
174 foreach my $bor (@$borrowerlist) {
175 push @borrowernumbers, $bor->{'borrowernumber'};
176 $borrowernames{ $bor->{'borrowernumber'} } =
177 "$bor->{'cardnumber'} $bor->{'firstname'} $bor->{surname}";
179 $win1->delete('mypopupbox');
180 my $popupbox = $win1->add(
181 'mypopupbox', 'Popupmenu',
182 -values => [@borrowernumbers],
183 -labels => \%borrowernames,
184 -onchange => \&dolistissues,
188 $borrowernumber = $popupbox->get();
189 if ($borrowernumber) {
190 doissues( $borrowernumber, \%env, $year, $month, $day );
199 my $borrowernumber = $list->get();
200 doissues($borrowernumber);
204 my ( $borrowernumber, $env, $year, $month, $day ) = @_;
207 my $borrower = getpatroninformation( $env, $borrowernumber, 0 );
208 $win1->delete('borrowerdata');
209 my $borrowerdata = $win1->add( 'borrowerdata', 'TextViewer',
210 -text => "Cardnumber: $borrower->{'cardnumber'}\n"
211 . "Name: $borrower->{'title'} $borrower->{'firstname'} $borrower->{'surname'}"
214 $borrowerdata->focus();
216 $win3->delete('pastissues');
217 my $issueslist = getissues($borrower);
219 foreach my $it ( keys %$issueslist ) {
221 $issueslist->{$it}->{'barcode'}
222 . " $issueslist->{$it}->{'title'} $issueslist->{$it}->{'date_due'}\n";
227 $win3->add( 'pastissues', 'TextViewer', -text => $oldissues, );
228 $pastissues->focus();
230 $win2->delete('currentissues');
232 $win2->add( 'currentissues', 'TextViewer',
233 -text => "Todays issues go here", );
234 $currentissues->focus();
236 # go into a loop issuing until a blank barcode is given
237 while ( my $barcode = $cui->question( -question => 'Barcode' ) ) {
240 my ( $error, $question ) =
241 canbookbeissued( $env, $borrower, $barcode, $year, $month, $day );
244 foreach my $impossible ( keys %$error ) {
245 $cui->error( -message => $impossible );
250 # no point asking confirmation questions if we cant issue
251 foreach my $needsconfirmation ( keys %$question ) {
253 $issueconfirmed = $cui->dialog(
255 "$needsconfirmation $question->{$needsconfirmation} Issue anyway?",
256 -title => "Confirmation",
257 -buttons => [ 'yes', 'no' ],
263 if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
264 issuebook( $env, $borrower, $barcode, $datedue );
265 $issues .= "$barcode";
266 $win2->delete('currentissues');
268 $win2->add( 'currentissues', 'TextViewer', -text => $issues, );
275 my $printconfirm = $cui->dialog(
276 -message => "Print a slip for this borrower?",
277 -title => "Print Slip",
278 -buttons => [ 'yes', 'no' ],
282 printslip( $env, $borrowernumber );