'created by Ajay on 30Mar2021
Sub Main ()

if msgbox("This report is to reset all billnos with 1(sale/Pur/BR/BP)" & vbcrlf & "do you want to continue?" , vbquestion + vbyesno + vbdefaultbutton2,"Confirm") = vbno then exit sub

With MetaScript
   
   set rs = .sumrs("Select * from series", .getdatafile)   
   do while not rs.eof
      if msgbox ("Do you want to reset numbers for " & rs.fields("Description") & "   -  " & rs.fields("Cashprefix") & "  -   " & rs.fields("Creditprefix"), vbquestion + vbyesno , "Reset " & rs.fields("Description")) = vbyes then
         
         cp = inputbox("Enter Cash Prefix","Cash Prefix",rs.fields("CashPrefix"))
         crp = inputbox("Enter Credit Prefix","Credit Prefix",rs.fields("CreditPrefix"))
         
         if msgbox("Do you want to update " & rs.fields("Description") & "." & vbcrlf & vbcrlf & "Change " & rs.fields("Cashprefix") & " -> " & cp & vbcrlf & vbcrlf & "Change " & rs.fields("creditprefix") & " -> " & crp & vbcrlf & vbcrlf & "Please confirm", vbquestion + vbyesno,"Updating " & rs.fields("Description") )= vbyes then
            
            if rs.fields("CashPrefix") = cp then
               .exec "Update Ph set Billno=billno +'*' from salehead as ph, licence as l where ph.billdate between fromyear and toyear and cashcredit=0 and ph.saletype=" & rs.fields("Serieskey"), .getdatafile
            end if
            if rs.fields("CreditPrefix") = crp then
               .exec "Update Ph set Billno=billno +'*' from salehead as ph, licence as l where ph.billdate between fromyear and toyear and cashcredit=1 and ph.saletype=" & rs.fields("Serieskey"), .getdatafile
            end if
            
            .exec "Update series set cashprefix = '" & cp & "' , creditprefix = '" & crp & "', cashserialnumber=0, creditserialnumber=0 where serieskey = " & rs.fields("Serieskey"), .getdatafile
            
         end if
      end if
      if not rs.eof then rs.movenext
   loop 
   .exec "Update Ph set Billno=billno +'*' from salehead as ph, licence as l where ph.billdate between fromyear and toyear and ph.saletype>800", .getdatafile
   .exec "Update Ph set Billno=billno +'*' from Purchasehead as ph, licence as l where ph.billdate between fromyear and toyear and transferout>800", .getdatafile
   
   if msgbox("Do you want to Reset Purchases/PRs from 1 " & vbcrlf & vbcrlf & "Please confirm", vbquestion + vbyesno,"Updating  Purchase")  = vbyes then
      .exec "Update billnos set PurchaseGenNo = 0, PurchaseReturn =0 ", .getdatafile
      .exec "Update Ph set Billno=billno +'*' from purchasehead as ph, licence as l where ph.billdate between fromyear and toyear ", .getdatafile
      .exec "Update accpost set Billno=billno +'*' where  billtype in ('PI','PR') ", .getdatafile
   end if         
   
   if msgbox("Do you want to Reset Bill Receipts from 1 " & vbcrlf & vbcrlf & "Please confirm", vbquestion + vbyesno,"Updating  Bill Receipts  BR/CO")  = vbyes then
      .exec "Update billnos set BRNumber = 0, CONumber =0 ", .getdatafile
      .exec "Update Ph set Billno=billno +'*' from Receipthead as ph, licence as l where ph.billdate between fromyear and toyear ", .getdatafile
      .exec "Update accpost set Billno=billno +'*' where billtype in ('BR','CO') ", .getdatafile
   end if         
   
   if msgbox("Do you want to Reset Bill Payments from 1 " & vbcrlf & vbcrlf & "Please confirm", vbquestion + vbyesno,"Updating  Bill Payments (BP)")  = vbyes then
      .exec "Update billnos set BPNumber = 0, CONumber =0 ", .getdatafile
      .exec "Update Ph set Billno=billno +'*' from paymenthead as ph, licence as l where ph.billdate between fromyear and toyear ", .getdatafile
      .exec "Update accpost set Billno=billno +'*' where billtype in ('BP') ", .getdatafile
   end if         
   
   .exec "update billnos set SaleDCNo=0,    PurchaseDCNo =0, PurchaseReturn=0, SaleReturn =0, SRCNNo=0   ", .getdatafile
   msgbox "Numbering Updated Successfully." ,vbinformation,"PharmaPulse"
   
End With
End Sub




