Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use C4::Context;
- my $dbh = C4::Context->dbh;
- my $prefix = 24572;
- my $prefix2 = 34572;
- while (my $inp = <STDIN>){
- chomp $inp; ###get rid of trailing \n
- my ($itembarcode,$patronbarcode,$datedue,$dateout) = split(/\,/, $inp);
- $newbarcode = upcycle_barcode($patronbarcode, $prefix);
- $newitembarcode = upcycle_barcode2($itembarcode, $prefix2);
- my $sth = $dbh->prepare("SELECT borrowernumber from borrowers WHERE cardnumber = ?");
- $sth->execute($patronbarcode);
- my $sth2 = $dbh->prepare("SELECT itemnumber from items WHERE barcode = ?");
- $sth2->execute($newbarcode);
- my $borrower=$sth->fetchrow_hashref;
- my $item = $sth2->fetchrow_hashref;
- # my $sth3 = $dbh->prepare("INSERT into issues (borrowernumber, itemnumber, date_due, issuedate, branchcode) value (?, ?, ?, ?, ?)");
- # $sth3->execute($borrower->{'borrowernumber'},$item->{'itemnumber'},$datedue,$dateout,'TROY');
- # my $sth4 = $dbh->prepare("UPDATE items SET onloan = ? WHERE itemnumber = ?");
- # $sth4->execute($datedue,$item->{'itemnumber'});
- print "$newbarcode, We should be seeting that man.... \n";
- }
- sub upcycle_barcode {
- my $patronbarcode = shift;
- my $prefix = shift;
- $prefix = $prefix * 100000000;
- my $newbarcode = $prefix + $patronbarcode;
- my $checkdigit = &calculate_check_digit($newbarcode);
- $newbarcode .= $checkdigit;
- return $newbarcode;
- }
- sub calculate_check_digit {
- my $incoming = shift();
- my @number = split(//, $incoming);
- my $total = 0;
- for ($i = 0; $i < @number; $i++){
- $value = $number[$i];
- if ($i%2 == 0){
- $value = $value*2;
- if ($value >= 10){
- $value = $value - 9;
- }
- }
- $total += $value;
- }
- $total = $total % 10;
- if ($total == 0) {
- return 0;
- } else {
- return 10 - $total;
- }
- }
- sub upcycle_barcode2 {
- my $itembarcode = shift;
- my $prefix2 = shift;
- $prefix2 = $prefix2 * 100000000;
- my $newitembarcode = $prefix2 + $itembarcode;
- my $checkdigit = &calculate_check_digit($newitembarcode);
- $newbarcode .= $checkdigit;
- return $newitembarcode;
- }
- sub calculate_check_digit {
- my $incoming = shift();
- my @number = split(//, $incoming);
- my $total = 0;
- for ($i = 0; $i < @number; $i++){
- $value = $number[$i];
- if ($i%2 == 0){
- $value = $value*2;
- if ($value >= 10){
- $value = $value - 9;
- }
- }
- $total += $value;
- }
- $total = $total % 10;
- if ($total == 0) {
- return 0;
- } else {
- return 10 - $total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement