Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. use C4::Context;
  4. my $dbh = C4::Context->dbh;
  5.  
  6. my $prefix = 24572;
  7. my $prefix2 = 34572;
  8.  
  9. while (my $inp = <STDIN>){
  10. chomp $inp; ###get rid of trailing \n
  11. my ($itembarcode,$patronbarcode,$datedue,$dateout) = split(/\,/, $inp);
  12.  
  13. $newbarcode = upcycle_barcode($patronbarcode, $prefix);
  14. $newitembarcode = upcycle_barcode2($itembarcode, $prefix2);
  15.  
  16. my $sth = $dbh->prepare("SELECT borrowernumber from borrowers WHERE cardnumber = ?");
  17. $sth->execute($patronbarcode);
  18.  
  19. my $sth2 = $dbh->prepare("SELECT itemnumber from items WHERE barcode = ?");
  20. $sth2->execute($newbarcode);
  21.  
  22. my $borrower=$sth->fetchrow_hashref;
  23. my $item = $sth2->fetchrow_hashref;
  24.  
  25. # my $sth3 = $dbh->prepare("INSERT into issues (borrowernumber, itemnumber, date_due, issuedate, branchcode) value (?, ?, ?, ?, ?)");
  26. # $sth3->execute($borrower->{'borrowernumber'},$item->{'itemnumber'},$datedue,$dateout,'TROY');
  27.  
  28. # my $sth4 = $dbh->prepare("UPDATE items SET onloan = ? WHERE itemnumber = ?");
  29. # $sth4->execute($datedue,$item->{'itemnumber'});
  30.  
  31. print "$newbarcode, We should be seeting that man.... \n";
  32. }
  33.  
  34. sub upcycle_barcode {
  35. my $patronbarcode = shift;
  36. my $prefix = shift;
  37. $prefix = $prefix * 100000000;
  38. my $newbarcode = $prefix + $patronbarcode;
  39. my $checkdigit = &calculate_check_digit($newbarcode);
  40. $newbarcode .= $checkdigit;
  41. return $newbarcode;
  42. }
  43.  
  44.  
  45. sub calculate_check_digit {
  46. my $incoming = shift();
  47. my @number = split(//, $incoming);
  48. my $total = 0;
  49. for ($i = 0; $i < @number; $i++){
  50. $value = $number[$i];
  51. if ($i%2 == 0){
  52. $value = $value*2;
  53. if ($value >= 10){
  54. $value = $value - 9;
  55. }
  56. }
  57. $total += $value;
  58. }
  59. $total = $total % 10;
  60. if ($total == 0) {
  61. return 0;
  62. } else {
  63. return 10 - $total;
  64. }
  65. }
  66.  
  67. sub upcycle_barcode2 {
  68. my $itembarcode = shift;
  69. my $prefix2 = shift;
  70. $prefix2 = $prefix2 * 100000000;
  71. my $newitembarcode = $prefix2 + $itembarcode;
  72. my $checkdigit = &calculate_check_digit($newitembarcode);
  73. $newbarcode .= $checkdigit;
  74. return $newitembarcode;
  75. }
  76.  
  77.  
  78. sub calculate_check_digit {
  79. my $incoming = shift();
  80. my @number = split(//, $incoming);
  81. my $total = 0;
  82. for ($i = 0; $i < @number; $i++){
  83. $value = $number[$i];
  84. if ($i%2 == 0){
  85. $value = $value*2;
  86. if ($value >= 10){
  87. $value = $value - 9;
  88. }
  89. }
  90. $total += $value;
  91. }
  92. $total = $total % 10;
  93. if ($total == 0) {
  94. return 0;
  95. } else {
  96. return 10 - $total;
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement