public cCoyPath, nTransTax1, nTransTax2, nTradeTax1, nTradeTax2, cIntInvRef, cExtInvRef, nAdjTransTax1, nAdjTranTax2, nTolerance set console off set safety off ************************************************* * Set Tolerance before transactions are changed * ************************************************* nTolerance = 999999.05 cCoyPath = [c:\sybiz\vision\home\matrix32\sample] cCoyPath = getdir(cCoyPath) cd [&cCoyPath] set alternate to [Tax_Rounding_Fix.log] additive if not file("system.dbf") messagebox("This is not a Vision Company Folder",0,"GST Fix") return endif =LogEntry([Invoice Date ] + [ Internal Ref ] + [ External Ref ] + [ Variance ] + [ Trade Tax1 ] + [ Trade Tax 2 ] + [ Trans Tax 1 ] + [ Trans Tax 2 ] ) =LogEntry([------------ ] + [ ------------------ ] + [ ------------------ ] + [ -------------------- ] + [ -------------------- ] + [ -------------------- ] + [ -------------------- ] + [ -------------------- ]) =LogEntry("Note: Tolerance set to " + alltrim(str(nTolerance,12,6)) + " cents. Variances beyond this will be ignored.") use trans in 0 shared use trade in 0 shared select trans scan for trantype = 7 and ledgerno = 3 cCustId = AccountId nTransTax1 = TaxAmount1 nTransTax2 = TaxAmount2 cIntInvRef = Internref cExtInvRef = Externref select Trade sum TaxAmount1 to nTradeTax1 for IntInvRef = cIntInvRef and ExtInvRef = cExtInvRef and Account2 = cCustId nTradeTax1 = nTradeTax1 * trans.Exchange sum TaxAmount2 to nTradeTax2 for IntInvRef = cIntInvRef and ExtInvRef = cExtInvRef and Account2 = cCustId nTradeTax2 = nTradeTax2 * trans.Exchange nVariance = nTransTax1 + nTransTax2 + round(nTradeTax1,2) + round(nTradeTax2,2) *messagebox(nVariance,0,"nVariance") *messagebox(nTolerance,0,"nTolerance") * Only make the adjustment for minor variances if (abs(nVariance) > 0) and (abs(nVariance) <= nTolerance) =LogEntry(padr(dtoc(Trans.TranDate),12) + " " + cIntInvRef + cExtInvRef + str(nVariance,20,6) + str(nTradeTax1,20,6) + str(nTradeTax2,20,6) + str(nTransTax1,20,6) + str(nTransTax2,20,6)) select Trade * Now rewrite any tax in trade that has more than 2 digits nAdjTransTax1 = 0 nAdjTransTax2 = 0 scan for intinvref = cIntInvRef and ExtInvRef = cExtInvRef nAdjTradeTax1 = round(TaxAmount1,2) if nAdjTradeTax1 != TaxAmount1 =LogEntry(padr(dtoc(Trans.TranDate),12) + " " + cIntInvRef + cExtInvRef + " Replaced Trade Tax 1: " + str(Trade.TaxAmount1,20,6) + " with " + str(nAdjTradeTax1,20,6)) replace TaxAmount1 with nAdjTradeTax1 endif nAdjTradeTax2 = round(TaxAmount2,2) if nAdjTradeTax2 != TaxAmount2 =LogEntry(padr(dtoc(Trans.TranDate),12) + " " + cIntInvRef + cExtInvRef + " Replaced Trade Tax 2: " + str(Trade.TaxAmount2,20,6) + " with " + str(nAdjTradeTax2,20,6)) replace TaxAmount2 with nAdjTradeTax2 endif nAdjTransTax1 = nAdjTransTax1 + TaxAmount1 nAdjTransTax2 = nAdjTransTax2 + TaxAmount2 endscan select Trans nAdjTransTax1 = nAdjTransTax1 * -1 && Change sign nAdjTransTax2 = nAdjTransTax2 * -1 && Change sign if TaxAmount1 != nAdjTransTax1 =LogEntry(padr(dtoc(Trans.TranDate),12) + " " + cIntInvRef + cExtInvRef + " Replaced Trans Tax 1: " + str(TaxAmount1,20,6) + " with " + str(nAdjTransTax1,20,6)) replace Trans.TaxAmount1 with nAdjTransTax1 endif if TaxAmount2 != nAdjTransTax2 =LogEntry(padr(dtoc(Trans.TranDate),12) + " " + cIntInvRef + cExtInvRef + " Replaced Trans Tax 2: " + str(Trans.TaxAmount2,20,6) + " with " + str(nAdjTransTax2,20,6)) replace Trans.TaxAmount2 with nAdjTransTax2 endif * Check OSitem flag if (TaxAmount1 + TaxAmount2 + Amount1 + Amount2 + Amount4 + Amount5) = 0 and OSITEM = .T. replace OSITEM with .F. =LogEntry(padr(dtoc(Trans.TranDate),12) + " " + cIntInvRef + cExtInvRef + " Set OSITEM to *FALSE*") endif endif endscan set alternate to !notepad Tax_Rounding_Fix.log ************************ *** Common Functions *** ************************ function LogEntry parameters tnMsg set alternate on set console on cMsg = dtoc(date())+ " " + time() + " " + tnMsg ? cMsg set alternate off set console off return