Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1.  
  2. ---Script-----
  3.  
  4.  
  5. #!/usr/bin/perl
  6.  
  7. # I hacked this together one night when I accidently billed customers 2
  8. times in a row due to a date
  9. # change I had done to bill 1 customer in the rear by a few days.
  10.  
  11. # Brian Walters <brian@mylinuxisp.com>
  12.  
  13. # Don't ask for support, this was done to get me out of hot water it may
  14. not work in all cases, it might not
  15. # work in your case particularly. Use at your own risk!!!!
  16.  
  17. use strict;
  18. use DBI;
  19.  
  20.  
  21. my $database = "freeside";
  22. my $user = "root";
  23. my $password = "";
  24.  
  25. # I like things like db handles to be global, it's just me.
  26. my $dbh;
  27.  
  28.  
  29. sub delete_cc_trans {
  30. # I'm not checking for the existence. If there's no transaction
  31. nothing is going to happen
  32.  
  33. my ($invoicenum) = @_;
  34. $dbh->do("delete from cust_pay_batch where invnum=$invoicenum");
  35.  
  36. }
  37.  
  38.  
  39. sub clear_bill_dates {
  40. # I have to clear the next bill date and possibly the setup date if
  41. it was billed too
  42.  
  43. my ($invoicenum) = @_;
  44. my ($pkgnum,$recur,$setup,$sqlstring);
  45.  
  46.  
  47. my $sth = $dbh->prepare("select pkgnum, recur, setup from
  48. cust_bill_pkg where invnum=$invoicenum");
  49.  
  50. $sth->execute;
  51.  
  52. my $ary_ref = $sth->fetch;
  53.  
  54. while ($ary_ref) {
  55. $pkgnum = $$ary_ref[0];
  56. $recur = $$ary_ref[1];
  57. $setup = $$ary_ref[2];
  58.  
  59. # we have to make sure we don't get the sales tax entry
  60. if ($pkgnum!=0) {
  61.  
  62. $sqlstring = "UPDATE cust_pkg SET ";
  63.  
  64. if ($setup > 0) {
  65. $sqlstring = $sqlstring . "setup=0,";
  66. }
  67. $sqlstring = $sqlstring . "bill=0";
  68.  
  69. $sqlstring = $sqlstring . " WHERE pkgnum=$pkgnum";
  70. $dbh->do($sqlstring);
  71. }
  72. $ary_ref = $sth->fetch;
  73. }
  74.  
  75. }
  76.  
  77. sub clear_invoice {
  78. # I have to clear the next bill date and possibly the setup date if
  79. it was billed too
  80.  
  81. my ($invoicenum) = @_;
  82.  
  83. # If you actually want to delete the invoice completely!
  84. $dbh->do("delete from cust_bill_pkg where invnum=$invoicenum");
  85. $dbh->do("delete from cust_bill where invnum=$invoicenum");
  86.  
  87. # If you simply want to void it but keep a record.
  88. # $dbh->do("update cust_bill_pkg SET recur=0,setup=0 where
  89. invnum=$invoicenum");
  90. # $dbh->do("update cust_bill SET charged=0, owed=0 where
  91. invnum=$invoicenum");
  92.  
  93. }
  94.  
  95.  
  96. # MAIN CODE
  97.  
  98.  
  99. # This line should probably be rewritten if you plan to run the script
  100. from another host.
  101. $dbh = DBI->connect("DBI:mysql:$database", $user, $password)
  102. or die "Can't connect to $database: $DBI::errstr\n";
  103.  
  104. my $invoicenum = $ARGV[0];
  105.  
  106.  
  107. # ___VERY___ limited argument checking
  108. $invoicenum>0 or die "Bad invoice number!!\n";
  109.  
  110.  
  111. print "Deleting invoice number $invoicenum\n";
  112.  
  113. delete_cc_trans ($invoicenum);
  114. clear_bill_dates ($invoicenum);
  115. clear_invoice ($invoicenum);
  116.  
  117. $dbh->disconnect;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement