View | Details | Raw Unified | Return to bug 2975
Collapse All | Expand All

(-)a/offline_circ/process_koc.pl (-132 / +134 lines)
Lines 43-55 my $FILE_VERSION = '1.0'; Link Here
43
43
44
our $query = CGI->new;
44
our $query = CGI->new;
45
45
46
my ($template, $loggedinuser, $cookie)
46
my ($template, $loggedinuser, $cookie) = get_template_and_user({
47
  = get_template_and_user( { template_name => "offline_circ/process_koc.tmpl",
47
    template_name => "offline_circ/process_koc.tmpl",
48
				query => $query,
48
    query => $query,
49
				type => "intranet",
49
    type => "intranet",
50
				authnotrequired => 0,
50
    authnotrequired => 0,
51
				 flagsrequired   => { circulate => "circulate_remaining_permissions" },
51
     flagsrequired   => { circulate => "circulate_remaining_permissions" },
52
				});
52
});
53
53
54
54
55
my $fileID=$query->param('uploadedfileid');
55
my $fileID=$query->param('uploadedfileid');
Lines 71-78 if ($completedJobID) { Link Here
71
    my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID);
71
    my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID);
72
    my $fh = $uploaded_file->fh();
72
    my $fh = $uploaded_file->fh();
73
    my @input_lines = <$fh>;
73
    my @input_lines = <$fh>;
74
  
74
75
    my $filename = $uploaded_file->name(); 
75
    my $filename = $uploaded_file->name();
76
    my $job = undef;
76
    my $job = undef;
77
77
78
    if ($runinbackground) {
78
    if ($runinbackground) {
Lines 110-134 if ($completedJobID) { Link Here
110
        # if we get here, we're a child that has detached
110
        # if we get here, we're a child that has detached
111
        # itself from Apache
111
        # itself from Apache
112
112
113
    }     
113
    }
114
114
115
    my $header_line = shift @input_lines;
115
    my $header_line = shift @input_lines;
116
    my $file_info   = parse_header_line($header_line);
116
    my $file_info   = parse_header_line($header_line);
117
    if ($file_info->{'Version'} ne $FILE_VERSION) {
117
    if ($file_info->{'Version'} ne $FILE_VERSION) {
118
      push( @output, { message => 1,
118
        push @output, {
119
      ERROR_file_version => 1,
119
            message => 1,
120
      upload_version => $file_info->{'Version'},
120
            ERROR_file_version => 1,
121
      current_version => $FILE_VERSION
121
            upload_version => $file_info->{'Version'},
122
      } );
122
            current_version => $FILE_VERSION
123
        };
123
    }
124
    }
124
    
125
125
    
126
    my $i = 0;
126
    my $i = 0;
127
    foreach  my $line (@input_lines)  {
127
    foreach  my $line (@input_lines)  {
128
    
129
        $i++;
128
        $i++;
130
        my $command_line = parse_command_line($line);
129
        my $command_line = parse_command_line($line);
131
        
130
132
        # map command names in the file to subroutine names
131
        # map command names in the file to subroutine names
133
        my %dispatch_table = (
132
        my %dispatch_table = (
134
            issue     => \&kocIssueItem,
133
            issue     => \&kocIssueItem,
Lines 193-199 sub parse_command_line { Link Here
193
    my $command_line = shift;
192
    my $command_line = shift;
194
    chomp($command_line);
193
    chomp($command_line);
195
    $command_line =~ s/\r//g;
194
    $command_line =~ s/\r//g;
196
    
195
197
    my ( $timestamp, $command, @args ) = split( /\t/, $command_line );
196
    my ( $timestamp, $command, @args ) = split( /\t/, $command_line );
198
    my ( $date,      $time,    $id )   = split( /\s/, $timestamp );
197
    my ( $date,      $time,    $id )   = split( /\s/, $timestamp );
199
198
Lines 239-363 sub arguments_for_command { Link Here
239
}
238
}
240
239
241
sub kocIssueItem {
240
sub kocIssueItem {
242
  my $circ = shift;
241
    my $circ = shift;
243
242
244
  $circ->{ 'barcode' } = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter'));
243
    $circ->{ 'barcode' } = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter'));
245
  my $branchcode = C4::Context->userenv->{branch};
244
    my $branchcode = C4::Context->userenv->{branch};
246
  my $borrower = GetMember( 'cardnumber'=>$circ->{ 'cardnumber' } );
245
    my $borrower = GetMember( 'cardnumber'=>$circ->{ 'cardnumber' } );
247
  my $item = GetBiblioFromItemNumber( undef, $circ->{ 'barcode' } );
246
    my $item = GetBiblioFromItemNumber( undef, $circ->{ 'barcode' } );
248
  my $issue = GetItemIssue( $item->{'itemnumber'} );
247
    my $issue = GetItemIssue( $item->{'itemnumber'} );
249
248
250
  if ( $issue->{ 'date_due' } ) { ## Item is currently checked out to another person.
249
    if ( $issue->{ 'date_due' } ) { ## Item is currently checked out to another person.
251
#warn "Item Currently Issued.";
250
        #warn "Item Currently Issued.";
252
    my $issue = GetOpenIssue( $item->{'itemnumber'} );
251
        my $issue = GetOpenIssue( $item->{'itemnumber'} );
253
    
252
254
    if ( $issue->{'borrowernumber'} eq $borrower->{'borrowernumber'} ) { ## Issued to this person already, renew it.
253
        if ( $issue->{'borrowernumber'} eq $borrower->{'borrowernumber'} ) { ## Issued to this person already, renew it.
255
#warn "Item issued to this member already, renewing.";
254
            #warn "Item issued to this member already, renewing.";
256
    
255
257
    C4::Circulation::AddRenewal(
256
            C4::Circulation::AddRenewal(
258
        $issue->{'borrowernumber'},    # borrowernumber
257
                $issue->{'borrowernumber'},    # borrowernumber
259
        $item->{'itemnumber'},         # itemnumber
258
                $item->{'itemnumber'},         # itemnumber
260
        undef,                         # branch
259
                undef,                         # branch
261
        undef,                         # datedue - let AddRenewal calculate it automatically
260
                undef,                         # datedue - let AddRenewal calculate it automatically
262
        $circ->{'date'},               # issuedate
261
                $circ->{'date'},               # issuedate
263
    ) unless ($DEBUG);
262
            ) unless ($DEBUG);
264
263
265
      push( @output, { renew => 1,
264
            push @output, {
266
    title => $item->{ 'title' },
265
                renew => 1,
267
    biblionumber => $item->{'biblionumber'},
266
                title => $item->{ 'title' },
268
    barcode => $item->{ 'barcode' },
267
                biblionumber => $item->{'biblionumber'},
269
    firstname => $borrower->{ 'firstname' },
268
                barcode => $item->{ 'barcode' },
270
    surname => $borrower->{ 'surname' },
269
                firstname => $borrower->{ 'firstname' },
271
    borrowernumber => $borrower->{'borrowernumber'},
270
                surname => $borrower->{ 'surname' },
272
    cardnumber => $borrower->{'cardnumber'},
271
                borrowernumber => $borrower->{'borrowernumber'},
273
    datetime => $circ->{ 'datetime' }
272
                cardnumber => $borrower->{'cardnumber'},
274
    } );
273
                datetime => $circ->{ 'datetime' }
274
            };
275
275
276
    } else {
276
        } else {
277
#warn "Item issued to a different member.";
277
            #warn "Item issued to a different member.";
278
#warn "Date of previous issue: $issue->{'issuedate'}";
278
            #warn "Date of previous issue: $issue->{'issuedate'}";
279
#warn "Date of this issue: $circ->{'date'}";
279
            #warn "Date of this issue: $circ->{'date'}";
280
      my ( $i_y, $i_m, $i_d ) = split( /-/, $issue->{'issuedate'} );
280
            my ( $i_y, $i_m, $i_d ) = split( /-/, $issue->{'issuedate'} );
281
      my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
281
            my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
282
      
282
283
      if ( Date_to_Days( $i_y, $i_m, $i_d ) < Date_to_Days( $c_y, $c_m, $c_d ) ) { ## Current issue to a different persion is older than this issue, return and issue.
283
            if ( Date_to_Days( $i_y, $i_m, $i_d ) < Date_to_Days( $c_y, $c_m, $c_d ) ) { ## Current issue to a different persion is older than this issue, return and issue.
284
                C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
285
                push @output, {
286
                    issue => 1,
287
                    title => $item->{ 'title' },
288
                    biblionumber => $item->{'biblionumber'},
289
                    barcode => $item->{ 'barcode' },
290
                    firstname => $borrower->{ 'firstname' },
291
                    surname => $borrower->{ 'surname' },
292
                    borrowernumber => $borrower->{'borrowernumber'},
293
                    cardnumber => $borrower->{'cardnumber'},
294
                    datetime => $circ->{ 'datetime' }
295
                };
296
297
            } else { ## Current issue is *newer* than this issue, write a 'returned' issue, as the item is most likely in the hands of someone else now.
298
                #warn "Current issue to another member is newer. Doing nothing";
299
                ## This situation should only happen of the Offline Circ data is *really* old.
300
                ## FIXME: write line to old_issues and statistics
301
            }
302
        }
303
    } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
284
        C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
304
        C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
285
        push( @output, { issue => 1,
305
        push @output, {
286
    title => $item->{ 'title' },
306
            issue => 1,
287
    biblionumber => $item->{'biblionumber'},
307
            title => $item->{ 'title' },
288
    barcode => $item->{ 'barcode' },
308
            biblionumber => $item->{'biblionumber'},
289
    firstname => $borrower->{ 'firstname' },
309
            barcode => $item->{ 'barcode' },
290
    surname => $borrower->{ 'surname' },
310
            firstname => $borrower->{ 'firstname' },
291
    borrowernumber => $borrower->{'borrowernumber'},
311
            surname => $borrower->{ 'surname' },
292
    cardnumber => $borrower->{'cardnumber'},
312
            borrowernumber => $borrower->{'borrowernumber'},
293
    datetime => $circ->{ 'datetime' }
313
            cardnumber => $borrower->{'cardnumber'},
294
    } );
314
            datetime =>$circ->{ 'datetime' }
295
315
        };
296
      } else { ## Current issue is *newer* than this issue, write a 'returned' issue, as the item is most likely in the hands of someone else now.
297
#warn "Current issue to another member is newer. Doing nothing";
298
        ## This situation should only happen of the Offline Circ data is *really* old.
299
        ## FIXME: write line to old_issues and statistics
300
      }
301
    
302
    }
316
    }
303
  } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
304
      C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
305
    push( @output, { issue => 1,
306
    title => $item->{ 'title' },
307
    biblionumber => $item->{'biblionumber'},
308
    barcode => $item->{ 'barcode' },
309
    firstname => $borrower->{ 'firstname' },
310
    surname => $borrower->{ 'surname' },
311
    borrowernumber => $borrower->{'borrowernumber'},
312
    cardnumber => $borrower->{'cardnumber'},
313
    datetime =>$circ->{ 'datetime' }
314
    } );
315
	 }  
316
}
317
}
317
318
318
sub kocReturnItem {
319
sub kocReturnItem {
319
  my ( $circ ) = @_;
320
    my ( $circ ) = @_;
320
  $circ->{'barcode'} = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter'));
321
    $circ->{'barcode'} = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter'));
321
  my $item = GetBiblioFromItemNumber( undef, $circ->{ 'barcode' } );
322
    my $item = GetBiblioFromItemNumber( undef, $circ->{ 'barcode' } );
322
  #warn( Data::Dumper->Dump( [ $circ, $item ], [ qw( circ item ) ] ) );
323
    #warn( Data::Dumper->Dump( [ $circ, $item ], [ qw( circ item ) ] ) );
323
  my $borrowernumber = _get_borrowernumber_from_barcode( $circ->{'barcode'} );
324
    my $borrowernumber = _get_borrowernumber_from_barcode( $circ->{'barcode'} );
324
  if ( $borrowernumber ) {
325
    if ( $borrowernumber ) {
325
  my $borrower = GetMember( 'borrowernumber' =>$borrowernumber );
326
        my $borrower = GetMember( 'borrowernumber' =>$borrowernumber );
326
    C4::Circulation::MarkIssueReturned( $borrowernumber,
327
        C4::Circulation::MarkIssueReturned(
327
                                      $item->{'itemnumber'},
328
            $borrowernumber,
328
                                      undef,
329
            $item->{'itemnumber'},
329
                                      $circ->{'date'} );
330
            undef,
330
  
331
            $circ->{'date'}
331
  push( @output, { return => 1,
332
        );
332
    title => $item->{ 'title' },
333
    biblionumber => $item->{'biblionumber'},
334
    barcode => $item->{ 'barcode' },
335
    borrowernumber => $borrower->{'borrowernumber'},
336
    firstname => $borrower->{'firstname'},
337
    surname => $borrower->{'surname'},
338
    cardnumber => $borrower->{'cardnumber'},
339
    datetime => $circ->{ 'datetime' }
340
    } ); 
341
  } else {
342
    push( @output, { ERROR_no_borrower_from_item => 1,
343
    badbarcode => $circ->{'barcode'}
344
    } );
345
  
346
  }
347
333
334
        push @output, {
335
            return => 1,
336
            title => $item->{ 'title' },
337
            biblionumber => $item->{'biblionumber'},
338
            barcode => $item->{ 'barcode' },
339
            borrowernumber => $borrower->{'borrowernumber'},
340
            firstname => $borrower->{'firstname'},
341
            surname => $borrower->{'surname'},
342
            cardnumber => $borrower->{'cardnumber'},
343
            datetime => $circ->{ 'datetime' }
344
        };
345
    } else {
346
        push @output, {
347
            ERROR_no_borrower_from_item => 1,
348
            badbarcode => $circ->{'barcode'}
349
        };
350
    }
348
}
351
}
349
352
350
sub kocMakePayment {
353
sub kocMakePayment {
351
  my ( $circ ) = @_;
354
    my ( $circ ) = @_;
352
  my $borrower = GetMember( 'cardnumber'=>$circ->{ 'cardnumber' } );
355
    my $borrower = GetMember( 'cardnumber'=>$circ->{ 'cardnumber' } );
353
  recordpayment( $borrower->{'borrowernumber'}, $circ->{'amount'} );
356
    recordpayment( $borrower->{'borrowernumber'}, $circ->{'amount'} );
354
  push( @output, { payment => 1,
357
    push @output, {
355
    amount => $circ->{'amount'},
358
        payment => 1,
356
    firstname => $borrower->{'firstname'},
359
        amount => $circ->{'amount'},
357
    surname => $borrower->{'surname'},
360
        firstname => $borrower->{'firstname'},
358
    cardnumber => $circ->{'cardnumber'},
361
        surname => $borrower->{'surname'},
359
    borrower => $borrower->{'borrowernumber'}
362
        cardnumber => $circ->{'cardnumber'},
360
    } );
363
        borrower => $borrower->{'borrowernumber'}
364
    };
361
}
365
}
362
366
363
=head2 _get_borrowernumber_from_barcode
367
=head2 _get_borrowernumber_from_barcode
Lines 375-383 sub _get_borrowernumber_from_barcode { Link Here
375
379
376
    my $item = GetBiblioFromItemNumber( undef, $barcode );
380
    my $item = GetBiblioFromItemNumber( undef, $barcode );
377
    return unless $item->{'itemnumber'};
381
    return unless $item->{'itemnumber'};
378
    
382
379
    my $issue = C4::Circulation::GetItemIssue( $item->{'itemnumber'} );
383
    my $issue = C4::Circulation::GetItemIssue( $item->{'itemnumber'} );
380
    return unless $issue->{'borrowernumber'};
384
    return unless $issue->{'borrowernumber'};
381
    return $issue->{'borrowernumber'};
385
    return $issue->{'borrowernumber'};
382
    
383
}
386
}
384
- 

Return to bug 2975