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;
30 my $cui = new Curses::UI( -color_support => 1 );
36 { -label => 'Issues ^I', -value => \&issues },
37 { -label => 'Returns ^R', -value => \&returns },
38 { -label => 'Exit ^Q', -value => \&exit_dialog }
42 -label => 'Parameters',
44 { -label => 'Branch', -value => \&changebranch },
45 { -label => 'Printer', -value => \&changeprinter }
82 my $texteditor = $win1->add( "text", "TextEditor",
84 "This is the first cut of a \ncirculations system using Curses::UI\n"
85 . "Use the menus (or the keyboard\nshortcuts) to choose issues or \nreturns"
88 $cui->set_binding( sub { $menu->focus() }, "\cX" );
89 $cui->set_binding( \&exit_dialog, "\cQ" );
90 $cui->set_binding( \&issues, "\cI" );
91 $cui->set_binding( \&returns, "\cR" );
99 my $return = $cui->dialog(
100 -message => "Do you really want to quit?",
101 -title => "Are you sure???",
102 -buttons => [ 'yes', 'no' ],
110 my $barcode = $cui->question(
112 -question => 'Barcode'
117 my ( $returned, $messages, $iteminformation, $borrower ) =
118 returnbook( $barcode, $branch );
119 if ( $borrower && $borrower->{'borrowernumber'} ) {
121 getpatroninformation( \%env, $borrower->{'borrowernumber'}, 0 );
122 $win1->delete('borrowerdata');
123 my $borrowerdata = $win1->add(
124 'borrowerdata', 'TextViewer',
125 -text => "Cardnumber: $borrower->{'cardnumber'}\n"
126 . "Name: $borrower->{'title'} $borrower->{'firstname'} $borrower->{'surname'}\n"
130 $borrowerdata->focus();
133 $cui->error( -message => 'That item isnt on loan' );
140 # this routine does the actual issuing
145 # the librarian can overide system issue date, need to fetch values from them
150 $win1->delete('text');
152 # get a cardnumber or a name
153 my $cardnumber = $cui->question(
155 -question => 'Cardnumber'
158 # search for that borrower
159 my ( $count, $borrowers ) =
160 BornameSearch( \%env, $cardnumber, 'cardnumber', 'web' );
161 my @borrowers = @$borrowers;
162 if ( $#borrowers == -1 ) {
163 $cui->error( -message =>
164 'No borrowers match that name or cardnumber please try again.' );
166 elsif ( $#borrowers == 0 ) {
167 $borrowernumber = $borrowers[0]->{'borrowernumber'};
170 $borrowerlist = \@borrowers;
173 if ($borrowernumber) {
175 # if we have one single borrower, we can start issuing
176 doissues( $borrowernumber, \%env, $year, $month, $day );
178 elsif ($borrowerlist) {
180 # choose from a list then start issuing
183 foreach my $bor (@$borrowerlist) {
184 push @borrowernumbers, $bor->{'borrowernumber'};
185 $borrowernames{ $bor->{'borrowernumber'} } =
186 "$bor->{'cardnumber'} $bor->{'firstname'} $bor->{surname}";
188 $win1->delete('mypopupbox');
189 my $popupbox = $win1->add(
190 'mypopupbox', 'Popupmenu',
191 -values => [@borrowernumbers],
192 -labels => \%borrowernames,
193 -onchange => \&dolistissues,
204 my $borrowernumber = $list->get();
205 doissues($borrowernumber);
209 my ( $borrowernumber, $env, $year, $month, $day ) = @_;
212 my $borrower = getpatroninformation( $env, $borrowernumber, 0 );
213 $win1->delete('borrowerdata');
214 my $borrowerdata = $win1->add( 'borrowerdata', 'TextViewer',
215 -text => "Cardnumber: $borrower->{'cardnumber'}\n"
216 . "Name: $borrower->{'title'} $borrower->{'firstname'} $borrower->{'surname'}"
219 $borrowerdata->focus();
221 $win3->delete('pastissues');
222 my $issueslist = getissues($borrower);
224 foreach my $it ( keys %$issueslist ) {
226 $issueslist->{$it}->{'barcode'}
227 . " $issueslist->{$it}->{'title'} $issueslist->{$it}->{'date_due'}\n";
232 $win3->add( 'pastissues', 'TextViewer', -text => $oldissues, );
233 $pastissues->focus();
235 $win2->delete('currentissues');
237 $win2->add( 'currentissues', 'TextViewer',
238 -text => "Todays issues go here", );
239 $currentissues->focus();
241 # go into a loop issuing until a blank barcode is given
242 while ( my $barcode = $cui->question( -question => 'Barcode' ) ) {
245 my ( $error, $question ) =
246 canbookbeissued( $env, $borrower, $barcode, $year, $month, $day );
249 foreach my $impossible ( keys %$error ) {
250 $cui->error( -message => $impossible );
255 # no point asking confirmation questions if we cant issue
256 foreach my $needsconfirmation ( keys %$question ) {
258 $issueconfirmed = $cui->dialog(
260 "$needsconfirmation $question->{$needsconfirmation} Issue anyway?",
261 -title => "Confirmation",
262 -buttons => [ 'yes', 'no' ],
268 if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
269 issuebook( $env, $borrower, $barcode, $datedue );
270 $issues .= "$barcode";
271 $win2->delete('currentissues');
273 $win2->add( 'currentissues', 'TextViewer', -text => $issues, );
280 my $printconfirm = $cui->dialog(
281 -message => "Print a slip for this borrower?",
282 -title => "Print Slip",
283 -buttons => [ 'yes', 'no' ],
287 printslip( $env, $borrowernumber );
292 my $dbh = C4::Context->dbh();
293 my $sth = $dbh->prepare('SELECT * FROM branches');
296 while ( my $data = $sth->fetchrow_hashref() ) {
297 push @branches, $data->{'branchcode'};
300 $win1->delete('text');
301 $win1->delete('mypopupbox');
302 my $popupbox = $win1->add(
303 'mypopupbox', 'Popupmenu',
304 -values => [@branches],
305 -onchange => \&setbranch,
311 my $dbh = C4::Context->dbh();
312 my $sth = $dbh->prepare('SELECT * FROM printers');
315 while ( my $data = $sth->fetchrow_hashref() ) {
316 push @printers, $data->{'printqueue'};
319 $win1->delete('text');
320 $win1->delete('mypopupbox');
321 my $popupbox = $win1->add(
322 'mypopupbox', 'Popupmenu',
323 -values => [@printers],
324 -onchange => \&setprinter,
332 my $branch = $list->get();
333 $env{'branch'} = $branch;
338 my $printer = $list->get();
339 $env{'printer'} = $printer;