def fCreate_OneRevPay(pClient,pCliNum,pMonth):
#---------------------------------------------------#

    logging.debug('- Create_OneRevPay: ' + str(pMonth) + "-" + pClient + " - " + str(pCliNum))

    # new transaction
    type("n",KeyModifier.CTRL)
    myTools.waitForTransEntry()

    # switch to Transfer

    type(Key.UP)    # this is to get by a UI defect
    time.sleep(1)
    
    type("rev")
    time.sleep(1)   
    type(Key.TAB)
       
    # client
    myTools.enterClient(pClient)
        
    # date
    tranDate = str(pMonth) + "/28/" + Settings.dataYear
    type(tranDate)
    time.sleep(1)
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    revDescription = "Reverse Pay: " + pClient + " - " + tranDate + " - " + str(pCliNum)
    type(revDescription)
    type(Key.ENTER)
    time.sleep(1)
    type(Key.TAB)

    # payment list
    type(Key.END)
    time.sleep(1)
    type(Key.SPACE)                     # this marks the checkbox in 2017+ PREM, but should be innocuous in prior
    time.sleep(1)
    type("s",KeyModifier.CTRL)   

        
    # fee on reversed payment
    myTools.waitForFinChargeMsg()
    type(Key.DOWN)
    myTools.pressTAB(1)
    revFee = "19.99"
    type(revFee)
    time.sleep(1) 
    myTools.pressTAB(1)

    # fee description
    revFeeDescription = "Note: " + pClient + " - " + revFee
    type(revFeeDescription)

    # close
    time.sleep(1) 
    myTools.pressTAB(1)
    type(Key.ENTER)    
def fPayToAccount_CreateOne(pta_client,pta_month,pta_count,pta_amount):
#---------------------------------------------------#

    logging.debug('- PTA_Create: ' + str(pta_month) + "-" + pta_client + " = " + str(pta_amount))

    # new pta
    myTools.getFocus()
    type("n",KeyModifier.CTRL + KeyModifier.SHIFT)
    logging.debug('-- new')
    myTools.waitForTransEntry()
    
    # skip type
    type(Key.TAB)      
        
    # skip deposit slip
    type(Key.TAB)
    
    # client
    myTools.enterClient(pta_client)

    # account
    type(Key.END)
    type(Key.TAB)   

    # date
    pta_date = str(pta_month) + "/28/" + Settings.dataYear
    type(pta_date)
    time.sleep(1)
    type(Key.TAB)
            
    # check number
    check_num = "pta-" + str(pta_count) + "-" + str(pta_month)
    type(check_num)
    type(Key.TAB)
    time.sleep(1)        
    
    # Amount
    type(str(pta_amount))
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    type("bds-pta: " + pta_client + " - " + pta_date)
    type(Key.ENTER)
    time.sleep(1)

    # close / save
    logging.debug('-- close/save')
    type(Key.F4,KeyModifier.CTRL)
    time.sleep(1)
    type(Key.ENTER)
    time.sleep(5)
    
    if exists("you_deposited_money.png"):
        logging.debug('--- deposited msg exists')
        type("n")  
        time.sleep(1)    
def fPayment_CreateOne(pay_client,pay_month,pay_count,pay_amount):
#---------------------------------------------------#

    logging.debug('- Pay_Create: ' + str(pay_month) + "-" + pay_client + " = " + str(pay_amount))

    # new payment
    myTools.getFocus()
    type("n",KeyModifier.CTRL)
    logging.debug('-- new')
    myTools.waitForTransEntry()
    
    # type
    type(Key.TAB)
       
    # source
    type(Key.TAB)
        
    # check number
    check_num = "pay-" + str(pay_count) + "-" + str(pay_month)
    type(check_num)
    type(Key.TAB)
    time.sleep(1)        
            
    # client
    myTools.enterClient(pay_client)
        
    # date
    pay_date = str(pay_month) + "/28/" + Settings.dataYear
    type(pay_date)
    time.sleep(1)
    type(Key.TAB)
        
    # skip deposit slip
    type(Key.TAB)
            
    # Amount
    type(str(pay_amount))
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    type("bds-pay: " + pay_client + " - " + pay_date)
    type(Key.ENTER)
    time.sleep(1)

    # close / save
    logging.debug('-- close/save')
    type(Key.F4,KeyModifier.CTRL)
    time.sleep(1)
    type(Key.ENTER)
    time.sleep(5)

    myTools.checkForUnappliedAmount()
def fCreate_OneFundsTransfer(pClient,pCliNum,pMonth):
#---------------------------------------------------#

    logging.debug('- Create_OneFundsTransfer: ' + str(pMonth) + "-" + pClient)

    # new transaction
    type("n",KeyModifier.CTRL)
    myTools.waitForTransEntry()

    # switch to Transfer to Funds

    type(Key.UP)    # this is to get by a UI defect
    time.sleep(1)    
    type("t")
    time.sleep(1)
    type(Key.DOWN)
    time.sleep(1)    
    type(Key.TAB)
       
    # client
    myTools.enterClient(pClient)
        
    # date
    tranDate = str(pMonth) + "/28/" + Settings.dataYear
    type(tranDate)
    time.sleep(1)
    type(Key.TAB)       
            
    # Amount
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    type(pClient + " - " + str(pCliNum) + " - " + tranDate)
    type(Key.ENTER)
    time.sleep(1)
    type(Key.TAB)

    # payment list - mark first item in list
    if (int(Settings.tsVersion) > 2016) and (Settings.tsDB == "PREM"):
        type(Key.SPACE)             # in TS2017+ PREM, this marks the check box
    else:    
        type(Key.DOWN)              # in others, this movement highlights first in list
    
    time.sleep(1)
    type(Key.TAB)

    # funds account
    type(Key.END)
    time.sleep(1)

    type("s",KeyModifier.CTRL)
    myTools.waitForTransSave()    
def fCreate_OneDiscount(pClient, pMonth, pAmount):
    # ---------------------------------------------------#

    logging.debug("- Create_OneDiscount: " + str(pMonth) + "-" + pClient + " = " + str(pAmount))

    # new transaction
    type("n", KeyModifier.CTRL)
    myTools.waitForTransEntry()

    # switch to Discount

    type(Key.UP)  # this is to get by a UI defect
    time.sleep(1)

    type("d")
    time.sleep(1)
    type(Key.TAB)

    # client
    myTools.enterClient(pClient)

    # date
    tranDate = str(pMonth) + "/28/" + Settings.dataYear
    type(tranDate)
    time.sleep(1)
    type(Key.TAB)

    # Amount
    type(str(pAmount))
    type(Key.TAB)

    # Description
    type("a", KeyModifier.CTRL)
    type("Discount: " + pClient + " - " + tranDate)
    type(Key.ENTER)
    time.sleep(1)

    # move to invoice list
    if (int(Settings.tsVersion) > 2016) and (Settings.tsDB == "PREM"):
        myTools.pressTAB(2)
    else:
        myTools.pressTAB(1)

    # move to last entry
    myTools.moveToLastTrans()
    myTools.clickApplyOne()

    # save
    type("s", KeyModifier.CTRL)
    myTools.waitForTransSave()
def fCreate_OneFundsTransfer(pClient,pCliNum,pMonth):
#---------------------------------------------------#

    logging.debug('- Create_OneFundsTransfer: ' + str(pMonth) + "-" + pClient)

    # new transaction
    type("n",KeyModifier.CTRL)
    myTools.waitForTransEntry()

    # switch to Transfer to Funds

    type(Key.UP)    # this is to get by a UI defect
    time.sleep(1)    
    type("t")
    time.sleep(1)
    type(Key.DOWN)
    time.sleep(1)    
    type(Key.TAB)
       
    # client
    myTools.enterClient(pClient)
        
    # date
    tranDate = str(pMonth) + "/28/" + Settings.dataYear
    type(tranDate)
    time.sleep(1)
    type(Key.TAB)       
            
    # Amount
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    type(pClient + " - " + str(pCliNum) + " - " + tranDate)
    type(Key.ENTER)
    time.sleep(1)
    type(Key.TAB)

    # payment list
    type(Key.DOWN)
    time.sleep(1)
    type(Key.TAB)

    # funds account
    type(Key.END)
    time.sleep(1)

    type("s",KeyModifier.CTRL)
    myTools.waitForTransSave()    
def fCreate_OneCredit(pClient, pCliNum, pMonth, pAmount):
    # ---------------------------------------------------#

    logging.debug("- Create_OneCred: " + str(pMonth) + "-" + pClient + " = " + str(pAmount))

    # new payment
    type("n", KeyModifier.CTRL)
    myTools.waitForTransEntry()

    # type = credit
    type(Key.HOME)
    myTools.pressDOWN(1)
    type(Key.TAB)
    time.sleep(1)

    # client
    myTools.enterClient(pClient)

    # date
    credDate = str(pMonth) + "/28/" + Settings.dataYear
    type(credDate)
    time.sleep(1)
    type(Key.TAB)

    # Amount
    type(str(pAmount))
    type(Key.TAB)

    # Description
    type("a", KeyModifier.CTRL)
    type(pClient + " - " + str(pCliNum) + " - " + credDate)
    type(Key.ENTER)
    time.sleep(1)

    # move to invoice list
    if (int(Settings.tsVersion) > 2016) and (Settings.tsDB == "PREM"):
        myTools.pressTAB(2)
    else:
        myTools.pressTAB(1)

    # move to last entry
    myTools.moveToLastTrans()
    myTools.clickApplyOne()

    # save
    type("s", KeyModifier.CTRL)
    myTools.checkForUnappliedAmount()
    myTools.waitForTransSave()
def fCreate_OnePayToAccount(pClient,pCliNum,pMonth,pAmount):
#---------------------------------------------------#

    logging.debug('- Create_OnePTA: ' + str(pMonth) + "-" + pClient + " = " + str(pAmount))

    # new payment
    type("n",KeyModifier.CTRL)
    myTools.waitForTransEntry()   
       
    # type (skip)
    type(Key.TAB)

    # deposit slip (skip)
    type(Key.TAB)

    # client
    myTools.enterClient(pClient)    
        
    # skip account
    myTools.pressTAB(1)

    # date
    payDate = str(pMonth) + "/28/" + Settings.dataYear
    type(payDate)
    type(Key.TAB)
    time.sleep(1)
        
    # skip check number
    type(Key.TAB)
            
    # Amount
    type(str(pAmount))
    type(Key.TAB)
    time.sleep(1)

    # Description
    type("a",KeyModifier.CTRL)
    type(pClient + " - " + str(pCliNum) + " - " + payDate)
    type(Key.ENTER)
    time.sleep(1)
    type("s",KeyModifier.CTRL)

    myTools.waitForTransSave()

    if exists("you_deposited_money.png"):
        type("n")    
        time.sleep(2) 
def fCreate_OneWriteOff(pClient,pCliNum,pMonth,pAmount):
#---------------------------------------------------#

    logging.debug('- Create_OneWO: ' + str(pMonth) + "-" + pClient + " = " + str(pAmount))

    # new writeoff
    type("n",KeyModifier.CTRL)
    myTools.waitForTransEntry()
    
    # type = writeoff    
    type(Key.HOME)
    type("w")
    type(Key.TAB)     
        
    # client
    myTools.enterClient(pClient)
        
    # date
    woDate = str(pMonth) + "/28/" + Settings.dataYear
    type(woDate)
    time.sleep(1)
    type(Key.TAB)       
            
    # Amount
    type(str(pAmount))
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    type(pClient + " - " + str(pCliNum) + " - " + woDate)
    type(Key.ENTER)
    time.sleep(1)

    # move to invoice list
    if (int(Settings.tsVersion) > 2016) and (Settings.tsDB == "PREM"):
        myTools.pressTAB(2)
    else:
        myTools.pressTAB(1)

    # move to last entry
    myTools.moveToLastTrans()
    myTools.clickApplyOne()

    # save
    type("s",KeyModifier.CTRL)
    myTools.waitForTransSave()    
def fCreate_OneDiscount(pClient,pMonth,pAmount):
#---------------------------------------------------#

    logging.debug('- Create_OneDiscount: ' + str(pMonth) + "-" + pClient + " = " + str(pAmount))

    # new transaction
    type("n",KeyModifier.CTRL)
    myTools.waitForTransEntry()

    # switch to Discount

    type(Key.UP)    # this is to get by a UI defect
    time.sleep(1)
    
    type("d")
    time.sleep(1)   
    type(Key.TAB)
       
    # client
    myTools.enterClient(pClient)
        
    # date
    tranDate = str(pMonth) + "/28/" + Settings.dataYear
    type(tranDate)
    time.sleep(1)
    type(Key.TAB)       
            
    # Amount
    type(str(pAmount))
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    type("Discount: " + pClient + " - " + tranDate)
    type(Key.ENTER)
    time.sleep(1)
    type(Key.TAB)

    # invoice list
    type(Key.DOWN,KeyModifier.CTRL)
    time.sleep(1)
    click("apply_one.png")
    time.sleep(1)    
    type("s",KeyModifier.CTRL)
    myTools.waitForTransSave()    
def fCreate_OneCredit(pClient,pCliNum,pMonth,pAmount):
#---------------------------------------------------#

    logging.debug('- Create_OneCred: ' + str(pMonth) + "-" + pClient + " = " + str(pAmount))

    # new payment
    type("n",KeyModifier.CTRL)
    myTools.waitForTransEntry()
    
    # type = credit
    type(Key.HOME)
    myTools.pressDOWN(1)
    type(Key.TAB)     
    time.sleep(1)        
        
    # client
    myTools.enterClient(pClient)
        
    # date
    credDate = str(pMonth) + "/28/" + Settings.dataYear
    type(credDate)
    time.sleep(1)
    type(Key.TAB)       
            
    # Amount
    type(str(pAmount))
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    type(pClient + " - " + str(pCliNum) + " - " + credDate)
    type(Key.ENTER)
    time.sleep(1)
    type(Key.TAB)

    # Invoice list; go to last entry
    type(Key.END, KeyModifier.CTRL)
    time.sleep(1)    
    click("apply_one_button.png")
    time.sleep(1) 

    # save
    type("s",KeyModifier.CTRL)
    myTools.checkForUnappliedAmount()
    myTools.waitForTransSave()    
def fCreate_OnePayment(pClient,pCliNum,pMonth,pAmount):
#---------------------------------------------------#

    logging.debug('- Create_OnePay: ' + str(pMonth) + "-" + pClient + " = " + str(pAmount))

    # build a list of clients for which you will clear apply details
    transferClients = ["East.Bridgewater","North.Adams","West.Boylston"]
    transferFundsClients = ["East.Brookfield","North.Andover","West.Bridgewater"]
    refundClients = ["Harvard","Harwich","Hatfield","Haverhill","Hawley"]   
    clearClients = transferClients + transferFundsClients + refundClients

    # new payment
    type("n",KeyModifier.CTRL)
    myTools.waitForTransEntry()
       
    # type
    type(Key.TAB)
       
    # source
    myTools.pressDOWN(pMonth-1)
    type(Key.TAB)
    time.sleep(1)
        
    # check number; only available in month 1
    if pMonth == 1:
        type(str(pCliNum))
        type(Key.TAB)
        time.sleep(1)
            
    # skip card options
    if pMonth in (3,4,5,6,7,8):
        type(Key.TAB)
            
    # client
    myTools.enterClient(pClient)
        
    # date
    payDate = str(pMonth) + "/28/" + Settings.dataYear
    type(payDate)
    time.sleep(1)
    type(Key.TAB)
        
    # skip deposit slip
    if pMonth in (1,2):
        type(Key.TAB)
            
    # Amount
    type(str(pAmount))
    type(Key.TAB)
        
    # Description
    type("a",KeyModifier.CTRL)
    type(pClient + " - " + str(pCliNum) + " - " + payDate)
    type(Key.ENTER)
    time.sleep(1)

    # save
    type("s",KeyModifier.CTRL)
    myTools.checkForUnappliedAmount()
    myTools.waitForTransSave()    

    imgClearApplies = "clear_applies.png"
    imgRemainingAmount = "apply_remaining_to_future.png"       

    # clear applies and mark future invoice (this is for transfers in other scripts)
    if pClient in clearClients:
        logging.debug("==> CLEAR APPLIED")        
        click(imgClearApplies)
        time.sleep(1)
        click(imgRemainingAmount)
        time.sleep(1)
        # save
        type("s",KeyModifier.CTRL)       
        myTools.checkForUnappliedAmount()
        myTools.waitForTransSave()    
def fCreate_SpecCredits(pMonth):
#---------------------------------------------------#

    myTools.sectionStartTimeStamp("specialCredits" + str(pMonth))
    logging.debug('Create_SpecCredits: ' + str(pMonth))

    if int(Settings.tsVersion) < 2017:
        logging.debug('- SKIP until 2017')
        return       

    myTools.getFocus()

    # list of invoices; one for each month
    invList = ["12400","12600","13100","13330","13830","14210","14370","14850","15200","15460","15960","16240"]

    # open a/r tran list
    logging.debug('- open a/r list')    
    type("t",KeyModifier.CTRL)
    myTools.waitForTransList()

    # go to invoice
    type('g',KeyModifier.CTRL + KeyModifier.SHIFT)
    time.sleep(1)
    myTools.pressTAB(2)
    invNum = invList[pMonth-1]
    logging.debug('- look for: ' + invNum)
    type(invNum)
    type(Key.ENTER)
    time.sleep(1)

    # open it
    type(Key.ENTER)
    myTools.waitForTransEntry()

    # apply a new special credit
    click("apply_new.png")
    myTools.pressDOWN(5)    
    type(Key.ENTER)
    time.sleep(1)

    # type
    type(Key.TAB)

    # client
    type(Key.TAB)
        
    # date
    tranDate = str(pMonth) + "/28/" + Settings.dataYear
    type(tranDate)
    time.sleep(1)
    type(Key.TAB)       
            
    # Description
    type(Key.END)
    type(" - " + tranDate)
    time.sleep(1)
    myTools.pressTAB(2)

    # Fees
    feeAmount = 5 + pMonth/float(100)
    type(str(feeAmount))
    time.sleep(1)    
    type(Key.TAB)

    # Costs
    costAmount = 4 + pMonth/float(100)
    type(str(costAmount))
    time.sleep(1)    
    type(Key.TAB)

    # Interest
    interestAmount = 3 + pMonth/float(100)
    type(str(interestAmount))
    time.sleep(1)    

    #save
    type("s",KeyModifier.CTRL)
    myTools.checkForUnappliedAmount()
    myTools.waitForTransSave()    

    # close
    type(Key.F4,KeyModifier.CTRL)
    time.sleep(1)
    type(Key.F4,KeyModifier.CTRL)
    
    myTools.sectionEndTimeStamp()
    myTools.checkProcesses()