Advertisement
Guest User

Untitled

a guest
Mar 11th, 2020
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 88.04 KB | None | 0 0
  1. '*********************************************************************************************************
  2. 'VALIDATION FUNCTIONS (CASE FUNCTIONS,FUNCTIONS TO CREATE ERROR SHEET AND GENERATE UPLOAD)
  3. '*********************************************************************************************************
  4.  
  5. Public Sub createErrorSheet()
  6. 'Start Here
  7. thisComponent.CurrentController.Frame.ContainerWindow.Enable= false
  8.  
  9. Dim sectionName As String
  10. Dim sectionDesc As String
  11. Dim fieldName As String
  12. Dim previousSectionName As String
  13. Dim row As Long
  14. Dim column As Long
  15. Dim errorFound As Boolean
  16. errorFound = False
  17. ' Get the Error Sheet and clear its content
  18. Dim errorSheet as object
  19. errorSheet = ThisComponent.Sheets.getByName("Errors")
  20. errorSheet.Unprotect (Pwd)
  21. errorSheet.clearContents( _
  22. com.sun.star.sheet.CellFlags.VALUE _
  23. +com.sun.star.sheet.CellFlags.STRING _
  24. +com.sun.star.sheet.CellFlags.DATETIME _
  25. +com.sun.star.sheet.CellFlags.FORMULA)
  26. Dim srNo As Integer
  27. Dim startIndex As Integer
  28. startIndex = 1
  29. Dim errInd As Integer
  30. Dim errDesc As String
  31. EMPTYCELLTYPE = com.sun.star.table.CellContentType.EMPTY
  32. Dim validationSheet as object
  33. validationSheet = ThisComponent.Sheets.getByName("Validations")
  34. validationSheet.UnProtect (Pwd)
  35. 'With validationSheet
  36. 'With Worksheets.Item(4)
  37. Dim rangeName as String, mandatFlag as String, validityCheck as Boolean
  38.  
  39. 'Added By Janhavi on 23 Jan 2012
  40. errInd = 1
  41.  
  42. call MacroRunning()
  43. oProgressBarModel.setPropertyValue( "ProgressValue", 10 )
  44. labelModel.Label="Please wait while data is being read and validated..."
  45. For row = 1 To 65535
  46. If(validationSheet.getCellByPosition(0,row).getType() = EMPTYCELLTYPE) Then
  47. Exit For
  48. End If
  49. sectionName = validationSheet.getCellByPosition(0,row).String
  50. sectionDesc = validationSheet.getCellByPosition(14,row).String
  51. If Trim(previousSectionName) = "" Then
  52. previousSectionName = sectionName
  53. End If
  54.  
  55.  
  56. If row = 1 Or UCase(sectionName) <> UCase(previousSectionName) Then
  57. 'Added By Janhavi on 23 Jan 2012
  58. 'Define Header of Error Sheet
  59.  
  60. previousSectionName = sectionName
  61.  
  62. If (row-1) =0 then
  63. 'errorSheet.getCellByPosition(0, errInd - 2).CharWeight = com.sun.star.awt.FontWeight.BOLD
  64. errorSheet.getCellByPosition(0,0).String = "Sr. No."
  65. errorSheet.getCellByPosition(1,0).String = "Section Name"
  66. errorSheet.getCellByPosition(2,0).String = "Field"
  67. errorSheet.getCellByPosition(3,0).String = "Error Description"
  68. errorSheet.getCellByPosition(4,0).String = "Reference Cell"
  69. End If
  70. 'End Janhavi on 23 Jan 2012
  71. End If
  72. 'mandatFlag = validationSheet.getCellByPosition(3, row).String
  73. rangeName = validationSheet.getCellByPosition(2, row).String
  74. Dim startRowNum as Long , endRowNum as Long, startColumnNum as Long , endcolumnNum as Long
  75. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  76. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  77. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  78. startColumnNum = oRange.getReferredCells().getRangeAddress().StartColumn
  79. endcolumnNum = oRange.getReferredCells().getRangeAddress().EndColumn
  80. 'Added by Janhavi on 17.02.2012
  81. Dim singleCellRng as String
  82.  
  83. If (startRowNum = endRowNum and startColumnNum = endColumnNum) then
  84. REM this is a single cell validate against the rule in same rows
  85. fieldName = validationSheet.getCellByPosition(1, row).String
  86. For column = 3 To 256 Step 2
  87. validationFunctionCell = validationSheet.getCellByPosition(column, row)
  88. ' if the cell is empty break current for loop and goto next row
  89. If(validationFunctionCell.getType() = EMPTYCELLTYPE) Then
  90. Exit For
  91. Else
  92. validationFunctionInt = validationFunctionCell.String
  93. errDesc = validationSheet.getCellByPosition(column+1, row).String
  94. validityCheck = True
  95. cell = oRange.getReferredCells().getCellByPosition(0,0)
  96. cellValue = cell.String
  97. Select Case validationFunctionInt
  98. Case "0" 'isMandatory
  99. validityCheck = isMandatory(cellValue)
  100. Case "1" 'TestAlphanumeric
  101. validityCheck = TestAlphanumeric(cellValue)
  102. Case "2" 'TestPIN
  103. validityCheck = TestPIN(cellValue)
  104. Case "3" 'TestNumber
  105. validityCheck = TestNumber(cellValue)
  106. Case "4" 'validateCurrencyFormat
  107. validityCheck = validateCurrencyFormat(cellValue)
  108. Case "5" 'TestDate
  109. validityCheck = ValidateDate(cellValue)
  110. Case "6" 'TestDateBtwnRtnPeriod
  111. If(cellValue="") then
  112. validityCheck =True
  113. else
  114. validityCheck = TestDateBtwnRtnPeriod(cellValue)
  115. End IF
  116.  
  117. Case "7" 'TestAlphabetOnly
  118. validityCheck = TestAlphabet(cellValue)
  119. Case "8" 'TestAlphabetWithSpaceOnly
  120. validityCheck = TestAlphabetWithSpace(cellValue)
  121. case "9"
  122. validityCheck = TestAlphabetNumSpl(cellValue)
  123. Case "10"
  124. If(cellValue="") then
  125. validityCheck =True
  126. else
  127. validityCheck = checkFutureDate(cellValue)
  128. End If
  129. Case "11"
  130. validityCheck = checkDuplicateTaxPyrPIN(cellValue)
  131. Case "12" 'check amount is greater than Zero or not
  132. if (validateCurrencyFormat(cellValue)) then
  133. if CDbl(cellValue)>0 then
  134. validityCheck=True
  135. else
  136. validityCheck=false
  137. End If
  138. Else
  139. validityCheck=false
  140. End If
  141. Case "15"
  142. validityCheck = CompareSumValue()
  143. 'CompareSumValue
  144. Case "20" 'RelevantDateCheck
  145. If(cellValue="") then
  146. validityCheck =True
  147. else
  148. validityCheck = RelevantDateCheck(cellValue)
  149. End IF
  150. Case "37" 'lessCompareTotals
  151. validityCheck = lessCompareTotals(rangeName,cell.value)
  152. Case "40" 'checkDateOfDeposit
  153. validityCheck = checkDateOfDeposit(cellValue)
  154. Case "41" 'checkDateOfDepositSelfAssess
  155. validityCheck = checkDateOfDepositSelfAssess(cellValue)
  156. Case "42" 'prnEntriesBothSch
  157. validityCheck = prnEntriesBothSch()
  158. Case "43" 'prnEntriesSelfAssess
  159. validityCheck = prnEntriesSelfAssess()
  160. Case "44" 'advPaymentGreaterThanLiability
  161. validityCheck = advPaymentGreaterThanLiability()
  162. Case "45" 'selfPaymentGreaterThanLiability
  163. validityCheck = selfPaymentGreaterThanLiability()
  164. Case "61" 'TestAlphabetNumNoSpl
  165. validityCheck = TestAlphabetNumNoSpl(cellValue)
  166. Case "62" 'TestAlphabetNumSpaceDot
  167. validityCheck = TestAlphabetNumSpaceDot(cellValue)
  168. Case "64" 'TestPRN
  169. validityCheck = TestPRN(cellValue)
  170. Case Else
  171. ina = ina + 1
  172. End Select
  173. If validityCheck = False Then
  174. srNo = srNo + 1
  175.  
  176. 'Updated by janhavi on 23 Jan 2012
  177. 'errInd= printErrorStack(errInd, startRowNum, fieldName, errDesc, startIndex, rangeName)
  178. 'errInd = printErrorStack(errInd,sectionName, fieldName,errDesc,startRowNum,srNo, rangeName)
  179.  
  180. 'Added by Janhavi on 17.02.2012
  181. singleCellRng= ColumnNumberToString(INT(cell.getRangeAddress().startcolumn))& (cell.getRangeAddress().startrow +1)
  182. errInd = printErrorStack(errInd,sectionName, fieldName, errDesc,singleCellRng , srNo, rangeName,sectionDesc)
  183. 'Changes by Maulika end ColumnNumberToString(INT(columnName))&(startRowNum + multriEntryRowNum + 1)
  184.  
  185. 'errInd = errInd + 1
  186. errorFound = True
  187. End If
  188. End If
  189. Next
  190. Else
  191.  
  192. Rem This is Multi-Entry field validate according to the range specified
  193. startMEVR = validationSheet.getCellByPosition(3, row).value - 1
  194. endMEVR = validationSheet.getCellByPosition(4, row).value - 1
  195. For multriEntryRowNum = 0 to endRowNum - startRowNum
  196. REM Check whether any column contains data
  197. REM for current multi-entry row using multriEntryRowNum, startColNum and endColNum
  198. REM If any column contains data then run the validationrules according to the range
  199.  
  200. doValidation = False
  201. For multiEntryColNum = startColumnNum to endColumnNum
  202. curCell = oRange.getReferredCells().getCellByPosition(multiEntryColNum,multriEntryRowNum)
  203. 'Added by Janhavi for skiping cells with formulas on 7th Dec 2011
  204. If(curCell.getType() <> EMPTYCELLTYPE And InStr(curCell.FormulaLocal, "=")=0) Then
  205. ' If(curCell.getType() <> EMPTYCELLTYPE ) Then
  206. doValidation = True
  207. Exit For
  208. End If
  209. Next 'multiEntryColNum
  210. If (doValidation) Then
  211. Rem Do the validation for the row start from startmultyentryvalidationrow to endmultyentryvalidationrow
  212. For eachCellValidationRow = startMEVR to endMEVR
  213. fieldName = validationSheet.getCellByPosition(1, eachCellValidationRow).String
  214. columnName = validationSheet.getCellByPosition(2, eachCellValidationRow).String
  215. oCells=oRange.getReferredCells().getCellByPosition(columnName,multriEntryRowNum)
  216. CellProtStruc = oCells.CellProtection
  217. If CellProtStruc.isLocked = False then
  218.  
  219. For column = 3 To 256 Step 2
  220. validationFunctionCell = validationSheet.getCellByPosition(column, eachCellValidationRow)
  221. ' if the cell is empty break current for loop and goto next row
  222. If(validationFunctionCell.getType() = EMPTYCELLTYPE) Then
  223. Exit For
  224. Else
  225. validationFunctionInt = validationFunctionCell.String
  226. errDesc = validationSheet.getCellByPosition(column+1, eachCellValidationRow).String
  227. validityCheck = True
  228. ' TODO change tge multriEntryColNum with the value related to C column value of Validations
  229. cellValue = oRange.getReferredCells().getCellByPosition(columnName,multriEntryRowNum).String
  230. 'Arjun - Added For Relevant Invoice Date and Number
  231. nextCellValueStr= oRange.getReferredCells().getCellByPosition(1,multriEntryRowNum).String
  232. multiCell = oRange.getReferredCells().getCellByPosition(columnName,multriEntryRowNum).CellAddress
  233.  
  234. Select Case validationFunctionInt
  235. Case "0" 'isMandatory
  236. validityCheck = isMandatory(cellValue)
  237. Case "1" 'TestAlphanumeric
  238. validityCheck = TestAlphanumeric(cellValue)
  239. Case "2" 'TestPIN
  240. validityCheck = TestPIN(cellValue)
  241.  
  242. Case "3" 'TestNumber
  243. validityCheck = TestNumber(cellValue)
  244. Case "4" 'TestCurrencyFormat
  245. validityCheck = validateCurrencyFormat(cellValue)
  246. Case "5" 'TestDate
  247. validityCheck = ValidateDate(cellValue)
  248. Case "6" 'TestDateBtwnRtnPeriod
  249. If(cellValue="") then
  250. validityCheck =True
  251. else
  252. validityCheck = TestDateBtwnRtnPeriod(cellValue)
  253. End IF
  254. Case "7" 'TestAlphabetOnly
  255. validityCheck = TestAlphabet(cellValue)
  256. Case "8" 'TestAlphabetWithSpaceOnly
  257. validityCheck = TestAlphabetWithSpace(cellValue)
  258. Case "9"
  259. validityCheck = TestAlphabetNumSpl(cellValue)
  260. Case "10"
  261. validityCheck = checkFutureDate(cellValue)
  262. Case "11"
  263. validityCheck = checkDuplicateTaxPyrPIN(cellValue)
  264. Case "12" 'check amount is greater than Zero or not
  265. if (validateCurrencyFormat(cellValue)) then
  266. if CDbl(cellValue)>0 then
  267. validityCheck=True
  268. else
  269. validityCheck=false
  270. End If
  271. Else
  272. validityCheck=false
  273. End If
  274. Case "15"
  275. validityCheck = CompareSumValue()
  276. Case "20" 'RelevantDateCheck
  277. If(cellValue="") then
  278. validityCheck =True
  279. else
  280. validityCheck = RelevantDateCheck(cellValue)
  281. End IF
  282. Case "37" 'lessCompareTotals
  283. validityCheck = lessCompareTotals(rangeName,cell.value)
  284. Case "40" 'checkDateOfDeposit
  285. validityCheck = checkDateOfDeposit(cellValue)
  286. Case "41" 'checkDateOfDepositSelfAssess
  287. validityCheck = checkDateOfDepositSelfAssess(cellValue)
  288. Case "42" 'prnEntriesBothSch
  289. validityCheck = prnEntriesBothSch()
  290. Case "43" 'prnEntriesSelfAssess
  291. validityCheck = prnEntriesSelfAssess()
  292. Case "44" 'advPaymentGreaterThanLiability
  293. validityCheck = advPaymentGreaterThanLiability()
  294. Case "45" 'selfPaymentGreaterThanLiability
  295. validityCheck = selfPaymentGreaterThanLiability()
  296. Case "61" 'TestAlphabetNumNoSpl
  297. validityCheck = TestAlphabetNumNoSpl(cellValue)
  298. Case "62" 'TestAlphabetNumSpaceDot
  299. validityCheck = TestAlphabetNumSpaceDot(cellValue)
  300. Case "63" 'checkRelevantInvNoDate
  301. validityCheck = checkRelevantInvNoDate(rangeName)
  302. Case "64" 'TestPRN
  303. validityCheck = TestPRN(cellValue)
  304. Case Else
  305. ina = ina + 1
  306. End Select
  307.  
  308.  
  309. 'Check For Condtional Mandatory
  310. If validityCheck = False Then
  311. srNo = srNo + 1
  312. 'Updated by janhavi on 23 Jan 2012
  313. ' errInd = printErrorStack(errInd, startRowNum + multriEntryRowNum , fieldName, errDesc, startIndex, rangeName)
  314. '' errInd = printErrorStack(errInd,sectionName, fieldName,errDesc,startRowNum + multriEntryRowNum,srNo, rangeName)
  315. 'Changes by Maulika start
  316. errInd = printErrorStack(errInd,sectionName, fieldName, errDesc, ColumnNumberToString(INT(columnName))&(startRowNum + multriEntryRowNum + 1) , srNo, rangeName,sectionDesc)
  317. 'changes by Maulika end
  318. 'errInd = errInd + 1
  319. errorFound = True
  320. End If
  321. End If
  322. Next 'column
  323. End If
  324.  
  325. Next 'eachCellValidation
  326. End If
  327. Next 'multriEntryRowNum
  328. End If
  329. Next
  330.  
  331. oProgressBarModel.setPropertyValue( "ProgressValue", 100 )
  332.  
  333. errorSheet.protect (Pwd)
  334. validationSheet.Protect (Pwd)
  335. If errorFound Then
  336. MsgBox "Error Found in the sheet"
  337. oSheet = ThisComponent.Sheets.getByName("Errors")
  338. ThisComponent.CurrentController.setActiveSheet(oSheet)
  339.  
  340. Else
  341. Call RunSheetUploadDlg
  342. If (allow=true) then
  343. Call fillUploadSheet
  344. 'MsgBox "Sheets are ready to be uploaded."
  345. ' msg1 = MsgBox(msg, vbQuestion + vbYesNo, "Generate Upload File")
  346. ' If msg1 = vbYes Then
  347. ' Generate_upload
  348. generate_ods_file
  349. End If
  350. ' End If
  351. End If
  352. 'Call createErrorSheetForList(errInd, srNo)
  353. thisComponent.CurrentController.Frame.ContainerWindow.Enable= True
  354. End Sub
  355.  
  356. Public Function CheckOtherValidations(rangeName As String, row as Long, Optional colName As String) As Boolean
  357. CheckOtherValidations = True
  358. End Function
  359. 'PREVIOUS METHOD
  360. 'Public Function printErrorStack(errline_index As Integer, col_no As Double, field As String, error As String, start_index As Integer, rangeName As String) As Integer
  361. ' Dim Doc As Object
  362. ' Dim SheetError As Object
  363. ' Dim CellError As Object
  364. ' Doc = ThisComponent
  365. ' SheetError = Doc.Sheets.getByName("Errors")
  366. ' CellError = SheetError.getCellByPosition(0,errline_index)
  367. ' CellError.String = errline_index - start_index
  368. ' CellError = SheetError.getCellByPosition(1,errline_index)
  369. ' CellError.String = col_no + 1
  370. ' CellError = SheetError.getCellByPosition(2,errline_index)
  371. ' CellError.String = field
  372. ' CellError = SheetError.getCellByPosition(3,errline_index)
  373. ' CellError.String = error
  374. 'CellError = SheetError.getCellByPosition(4,errline_index)
  375. 'CellError.String = rangeName
  376. ' printErrorStack = errline_index + 1
  377. 'ERR_COUNT = ERR_COUNT + 1
  378. 'End Function
  379.  
  380. 'UPDATED METHOD TO PRINT ERROR STACK IN ERROR SHEET. Updated By Janhavi 23 Jan 2012
  381. 'Public Function printErrorStack(errline_index As Integer,sectionName as String, field As String, error As String, col_no As Double, srNo As Integer, rangeName As String) As Integer
  382. ' Dim Doc As Object
  383. ' Dim SheetError As Object
  384. ' Dim CellError As Object
  385. ' Doc = ThisComponent
  386. ' SheetError = Doc.Sheets.getByName("Errors")
  387. ' CellError = SheetError.getCellByPosition(0,errline_index)
  388. ' CellError.String = srNo
  389. ' CellError = SheetError.getCellByPosition(1,errline_index)
  390. ' CellError.String = sectionName
  391. ' CellError = SheetError.getCellByPosition(2,errline_index)
  392. ' CellError.String = field
  393. ' CellError = SheetError.getCellByPosition(3,errline_index)
  394. ' CellError.String = error
  395. ' CellError = SheetError.getCellByPosition(4,errline_index)
  396. ' CellError.String = col_no + 1
  397.  
  398. 'CellError = SheetError.getCellByPosition(4,errline_index)
  399. 'CellError.String = rangeName
  400. ' printErrorStack = errline_index + 1
  401. 'ERR_COUNT = ERR_COUNT + 1
  402. 'End Function
  403.  
  404. REM changed by maulika for Hyperlinks
  405. Public Function printErrorStack(errline_index As Integer,sectionName as String, field As String, error As String, col_no As String, srNo As Integer, rangeName As String, optional sectionDesc As String) As Integer
  406. Dim Doc As Object
  407. Dim SheetError As Object
  408. Dim CellError As Object
  409. Doc = ThisComponent
  410. SheetError = Doc.Sheets.getByName("Errors")
  411. CellError = SheetError.getCellByPosition(0,errline_index)
  412. CellError.String = srNo
  413. CellError = SheetError.getCellByPosition(1,errline_index)
  414. CellError.String = sectionDesc 'Section Description added by Sandeep Thaker
  415. ' CellError.CharColor = RGB(0,0,0)
  416. CellError.CharUnderline = 0
  417. CellError = SheetError.getCellByPosition(2,errline_index)
  418. CellError.String = field
  419. ' CellError.CharColor = RGB(0,0,255)
  420. CellError.CharUnderline = 1
  421. CellError.FormulaLocal="=HYPERLINK(CONCATENATE(""#"";"""+ sectionName +""";""!"";"""+col_no+""");"""+field+""")"
  422.  
  423.  
  424. CellError = SheetError.getCellByPosition(3,errline_index)
  425. CellError.String = error
  426. CellError = SheetError.getCellByPosition(4,errline_index)
  427. CellError.String = col_no
  428. 'CellError = SheetError.getCellByPosition(4,errline_index)
  429. 'CellError.String = rangeName
  430. printErrorStack = errline_index + 1
  431. 'ERR_COUNT = ERR_COUNT + 1
  432. End Function
  433. REM end of changes by maulika
  434.  
  435. '**************************************************************
  436. ' VALIDATION CASES FUNCTIONS
  437. '**************************************************************
  438. 'Case 0 isMandatory
  439. 'Case 1 TestAlphanumeric
  440. 'Case 2 TestPIN
  441. 'Case 3 TestNumber
  442. 'Case 4 validateCurrencyFormat
  443. 'Case 5 TestDate
  444. 'Case 6 TestDateBtwnRtnPeriod
  445. 'Case 7 TestAlphabet
  446. 'Case 8 TestAlphabetWithSpace
  447. 'Case 9 TestAlphabetNumSpl
  448. 'Case10
  449. 'Case 11 checkDuplicateTaxPyrPIN
  450. Public Function isMandatory(lstr_check As String) As Boolean
  451. isMandatory = True
  452. If Trim(lstr_check) = "" Then
  453. isMandatory = False
  454. End If
  455. 'sheetName = value.Worksheet.Name
  456. End Function
  457.  
  458. Public Function TestAlphanumeric(lstr_check As String) As Boolean
  459. 'allowed characters A to Z, a to z, 0 To 9 And Blank
  460. Dim i As Integer
  461. Dim ia As Integer
  462. Dim ina As Integer
  463. Dim stlen As Integer
  464. stlen = Len(lstr_check)
  465. ia = 0
  466. TestAlphanumeric = True
  467. For i = 1 To stlen
  468. Select Case (Mid(lstr_check, i, 1))
  469. Case "A" To "Z" 'A to Z
  470. ia = ia + 1
  471. Case "a" To "z" 'a to z
  472. ia = ia + 1
  473. ' Case " " ' Blank
  474. ' ia = ia + 1
  475. Case "0" To "9" '0 to 9
  476. ia = ia + 1
  477. ' Case "," ',
  478. ' ia = ia + 1
  479. ' Case "." '.
  480. ' ia = ia + 1
  481. ' Case "/"
  482. ' ia = ia + 1
  483. ' Case "-"
  484. ' ia = ia + 1
  485. Case Else
  486. TestAlphanumeric = False
  487. Exit Function
  488. End Select
  489. Next i
  490. End Function
  491.  
  492. Public Function TestPIN(lstr_check As String) As Boolean
  493. 'allowed characters A to Z, a to z And Blank
  494. Dim i As Integer
  495. Dim ia As Integer
  496. Dim ina As Integer
  497. Dim stlen As Integer
  498. Dim ascChr As Integer
  499. stlen = Len(lstr_check)
  500. ia = 0
  501. TestPIN = True
  502. If(stlen <> 11) Then
  503. 'ina = 1
  504. TestPIN = False
  505. If (stlen =0 ) Then
  506. TestPIN = True
  507. End If
  508. Exit Function
  509.  
  510. Else
  511. For i = 1 To 11
  512. curChar = (Mid(lstr_check, i, 1))
  513. If i = 1 And (curChar <> "A" and curChar <> "a" and curChar <> "P" and curChar <> "p") Then
  514. 'ina = 1
  515. TestPIN = False
  516. Exit Function
  517. ElseIf i > 1 and i < 11 Then
  518. Select Case curChar
  519. Case "0" To "9" 'A to Z
  520. ia = ia + 1
  521. Case Else
  522. 'ina = 1
  523. TestPIN = False
  524. Exit Function
  525. End Select
  526. ElseIf i = 11 Then
  527. Select Case curChar
  528. Case "A" To "Z" 'A to Z
  529. ia = ia + 1
  530. Case "a" To "z" 'A to Z
  531. ia = ia + 1
  532. Case Else
  533. TestPIN = False
  534. Exit Function
  535. End Select
  536. End If
  537. Next i
  538. End If
  539. End Function
  540.  
  541.  
  542. Public Function TestNumber(lstr_check As String) As Boolean
  543. 'allowed characters 0 to 9 and .
  544. Dim i As Integer
  545. Dim ia As Integer
  546. 'Dim ina As Integer
  547. Dim stlen As Integer
  548.  
  549. stlen = Len(lstr_check)
  550. ia = 0
  551. 'ina = 0
  552. TestNumber = True
  553. For i = 1 To stlen
  554. Select Case (Mid(lstr_check, i, 1))
  555. Case "0" To "9" '0 to 9
  556. ia = ia + 1
  557. Case Else
  558. 'ina = ina + 1
  559. TestNumber = False
  560. Exit Function
  561. End Select
  562. Next i
  563. End Function
  564.  
  565. 'validateCurrencyFormat
  566. Public Function validateCurrencyFormat(lstr_check As String) As Boolean
  567. 'allowed characters 0 to 9 and .
  568. Dim i As Integer
  569. Dim ia As Integer
  570. Dim ina As Integer
  571. Dim stlen As Integer
  572. Dim dotCount As Integer
  573. stlen = Len(lstr_check)
  574. ia = 0
  575. ina = 0
  576. validateCurrencyFormat = True
  577. For i = 1 To stlen
  578. Select Case (Mid(lstr_check, i, 1))
  579. Case "-"
  580. ia = ia + 1
  581. Case ","
  582. ia = ia + 1
  583. Case "."
  584. ia = ia + 1
  585. dotCount = dotCount + 1
  586. Case "0" To "9" '0 to 9
  587. ia = ia + 1
  588. Case Else
  589. ina = ina + 1
  590. validateCurrencyFormat = False
  591. Exit Function
  592. End Select
  593. Next i
  594. If dotCount > 1 Then
  595. validateCurrencyFormat = False
  596. End If
  597. End Function
  598. Public Function TestDate(strDate As String) As Boolean
  599. Dim strMonth As String
  600. Dim strDay As String
  601. Dim strYear As String
  602. Dim validDay As Boolean
  603. Dim validMonth As Boolean
  604. Dim validYear As Boolean
  605. validDay = False
  606. validMonth = False
  607. validYear = False
  608. Dim validFormat As Boolean
  609. Dim i As Integer
  610. Dim Length As Integer
  611. Dim temp As String
  612. Dim index1 As Integer
  613. Dim index2 As Integer
  614. Dim flag As Integer
  615.  
  616. TestDate = False
  617.  
  618. If IsDate(strDate) = True Then
  619. Length = Len(strDate)
  620. flag = 0
  621.  
  622. If (Length > 10) Then
  623. validFormat = False
  624. Else
  625.  
  626. validFormat = True
  627. For i = 1 To Length
  628. If (Mid(strDate, i, 1) = "/") Then
  629. flag = flag + 1
  630.  
  631. If (flag = 1) Then
  632. index1 = i
  633. End If
  634. If (flag = 2) Then
  635. index2 = i
  636. End If
  637.  
  638. End If
  639. Next i
  640. If (index1 > 0 And index2 > 0) Then
  641. strDay = Mid(strDate, 1, index1 - 1)
  642. If (Len(strDay) > 2) Then
  643. validDay = False
  644. Else
  645. If IsNumeric(strDay) = True Then
  646. If Val(strDay) > 32 Then
  647. validDay = False
  648. Else
  649. validDay = True
  650. End If
  651. Else
  652. validDay = True
  653. End If
  654. End If
  655.  
  656.  
  657. strMonth = Mid(strDate, index1 + 1, (index2 - index1) - 1)
  658. If (Len(strMonth) > 2) Then
  659. validDay = False
  660. Else
  661. If IsNumeric(strMonth) = True Then
  662. If Val(strMonth) > 12 Then
  663. validMonth = False
  664. Else
  665. validMonth = True
  666. End If
  667. Else
  668. validMonth = True
  669. End If
  670. End If
  671.  
  672. strYear = Mid(strDate, index2 + 1, Len(strDate))
  673. If (Len(strYear) > 4) Then
  674. validYear = False
  675. Else
  676.  
  677. If IsNumeric(strYear) = True Then
  678. validYear = True
  679. Else
  680. validYear = False
  681. End If
  682. End If
  683. End If
  684. End If
  685. If (validFormat = False Or validDay = False Or validMonth = False Or validYear = False) Then
  686. If Length=0 then
  687. TestDate = True
  688. Else
  689. TestDate = False
  690. End If
  691. Else
  692.  
  693. TestDate = True
  694. End If
  695. End If
  696.  
  697. End Function
  698.  
  699. Function ValidateDate(EnteredDate As String) As Boolean
  700. ValidateDate = True
  701. Dim i as Integer
  702. Dim enDate as Integer
  703. Dim enMonth as Integer
  704. Dim enYear as Integer
  705. if Len(Trim(EnteredDate))=0 then
  706. ValidateDate = True
  707. Exit Function
  708. End If
  709. if Len(Trim(EnteredDate)) <> 10 and Len(Trim(EnteredDate)) <> 0 then
  710. ValidateDate = False
  711. EXIT FUNCTION
  712. else
  713. for i= 1 to Len(EnteredDate)
  714. curChar = (Mid(EnteredDate, i, 1))
  715. if i = 3 or i = 6 then
  716. Select Case (curChar)
  717. Case "/"
  718. Case Else
  719. ValidateDate = False
  720. EXIT FUNCTION
  721. end select
  722. else
  723. Select Case (curChar)
  724. Case "0" To "9"
  725. Case Else
  726. ValidateDate = False
  727. EXIT FUNCTION
  728. end select
  729. end if
  730. Next i
  731. end if
  732. enDate = Int((Mid(EnteredDate, 1, 2)))
  733. enMonth = Int((Mid(EnteredDate, 4, 2)))
  734. enYear = Int((Mid(EnteredDate, 7,4)))
  735. 'Added By Arjun to avoid 00/00/0000
  736. if enDate=0 or enMonth=0 or enYear=0 then
  737. ValidateDate = False
  738. EXIT FUNCTION
  739. End if
  740. yearMod = INT(enYear / 4)
  741. if (yearMod * 4) <> enYear then
  742.  
  743. if enMonth > 12 then
  744. ValidateDate = False
  745. EXIT FUNCTION
  746. else
  747. if enMonth <> 2 then
  748. if enMonth = 1 or enMonth = 3 or enMonth = 5 or enMonth= 7 or enMonth = 8 or enmonth = 10 or enmonth = 12 then
  749. if enDate > 31 then
  750. ValidateDate = False
  751. EXIT FUNCTION
  752. end if
  753. else
  754. if enDate > 30 then
  755. ValidateDate = False
  756. EXIT FUNCTION
  757. end if
  758. end if
  759. else
  760. if enDate > 28 then
  761. ValidateDate = False
  762. EXIT FUNCTION
  763. end if
  764. end if
  765. end if
  766. else
  767. if enMonth > 12 then
  768. ValidateDate = False
  769. else
  770. if enMonth <> 2 then
  771. if enMonth = 1 or enMonth = 3 or enMonth = 5 or enMonth= 7 or enMonth = 8 or enmonth = 10 or enmonth = 12 then
  772. if enDate > 31 then
  773. ValidateDate = False
  774. EXIT FUNCTION
  775. end if
  776. else
  777. if enDate > 30 then
  778. ValidateDate = False
  779. EXIT FUNCTION
  780. end if
  781. end if
  782. else
  783. if enDate > 29 then
  784. ValidateDate = False
  785. EXIT FUNCTION
  786. end if
  787. end if
  788. end if
  789. end if
  790.  
  791. end Function
  792.  
  793.  
  794. Public Function TestDateBtwnRtnPeriod1(ByVal value As String) As Boolean
  795. Dim mm As Integer
  796. Dim yr As Integer
  797. Dim startDate As String
  798. Dim endDate As String
  799. Dim sheet As Object
  800. Dim startMon as Integer
  801. Dim endMon as Integer
  802. Dim currMon as Integer
  803.  
  804. Dim startDt as Object
  805. Dim endDt as Object
  806. Dim currDt as Object
  807.  
  808.  
  809. startDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdFrom").string
  810. endDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdTo").string
  811. startDt= Split( startDate,"/")
  812. endDt= Split( endDate,"/")
  813. currDt= Split( value,"/")
  814.  
  815. If ValidateDate(value) = True And ValidateDate(startDate) = True And ValidateDate(endDate) = True Then
  816. If currDt(2)=startDt(2) then
  817. If currDt(1)>=startDt(1) and currDt(1)<=endDt(1) then
  818. TestDateBtwnRtnPeriod1 = True
  819. Else
  820. TestDateBtwnRtnPeriod1 = False
  821. End If
  822. Else
  823. TestDateBtwnRtnPeriod1 = False
  824. End If
  825. Else
  826. TestDateBtwnRtnPeriod1 = False
  827. End If
  828. End Function
  829.  
  830. Public Function TestDateBtwnRtnPeriod(ByVal value As String) As Boolean
  831. Dim mm As Integer
  832. Dim yr As Integer
  833. Dim startDate As String
  834. Dim endDate As String
  835. Dim sheet As Object
  836. Dim startMon as Integer
  837. Dim endMon as Integer
  838. Dim currMon as Integer
  839.  
  840. Dim startDt as Object
  841. Dim endDt as Object
  842. Dim currDt as Object
  843.  
  844.  
  845. unprotectsheet("A_Basic_Info")
  846. '->Arjun
  847. if(ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdTo").string<>"")then
  848. startDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdFrom").string
  849. endDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdTo").string
  850.  
  851. startDt= Split( startDate,"/")
  852. endDt= Split( endDate,"/")
  853. currDt= Split( value,"/")
  854.  
  855. If ValidateDate(value) = True And ValidateDate(startDate) = True And ValidateDate(endDate) = True Then
  856. If lessThnEqualToReturnYr(value,INT(endDt(2)),INT(endDt(1)),INT(endDt(0))) and greaterThnEqualToReturnYr(value,INT(startDt(2)),INT(startDt(1)),INT(startDt(0))) then
  857. TestDateBtwnRtnPeriod = True
  858. Else
  859. TestDateBtwnRtnPeriod = False
  860. End If
  861. Else
  862. TestDateBtwnRtnPeriod = False
  863. End If
  864. Else
  865. TestDateBtwnRtnPeriod = True
  866. End If
  867. protectsheet("A_Basic_Info")
  868. End Function
  869.  
  870. 'Arjun
  871. Public Function lessThnEqualToReturnYr(ByVal value As String,ByVal year as Integer,ByVal month as Integer,ByVal day as Integer) As Boolean
  872. Dim mm As Integer
  873. Dim yr As Integer
  874. Dim dd as Integer
  875. Dim strDate As Object
  876. Dim currDate as Object
  877. Dim returnDate As Date
  878.  
  879. returnDate = DateSerial(year, month, day)
  880.  
  881. If(Len(Trim(value))=0) then
  882. lessThnEqualToReturnYr=True
  883. Exit function
  884. End If
  885. if ValidateDate(value) then
  886. strDate= Split(value, "/")
  887. dd= INT(strDate(0))
  888. mm= INT(strDate(1))
  889. yr= INT(strDate(2))
  890.  
  891. currDate= Split( Format(returnDate, "dd/mm/yyyy"),"/")
  892. 'If yr = Format(Now(), "yyyy") Then
  893. If yr= INT(currDate(2)) then
  894. Dim mon as Integer
  895. Dim dayD as Integer
  896. mon= INT(currDate(1))
  897. dayD = INT(currDate(0))
  898. If mm < mon Then
  899. lessThnEqualToReturnYr = True
  900. ElseIf mm=mon then
  901. If dd<=dayD then
  902. lessThnEqualToReturnYr = True
  903. Else
  904. lessThnEqualToReturnYr = False
  905. End If
  906. Else
  907. lessThnEqualToReturnYr = False
  908. End If
  909.  
  910. ElseIf yr < currDate(2) And mm <= 12 Then
  911. lessThnEqualToReturnYr = True
  912. Else
  913. lessThnEqualToReturnYr = False
  914. End If
  915. End If
  916. End Function
  917.  
  918.  
  919. 'Arjun
  920. Public Function greaterThnEqualToReturnYr(ByVal value As String,ByVal year as Integer,ByVal month as Integer,ByVal day as Integer) As Boolean
  921. Dim mm As Integer
  922. Dim yr As Integer
  923. Dim dd as Integer
  924. Dim strDate As Object
  925. Dim currDate as Object
  926. Dim returnDate As Date
  927.  
  928. returnDate = DateSerial(year, month, day)
  929.  
  930. If(Len(Trim(value))=0) then
  931. greaterThnEqualToReturnYr=True
  932. Exit function
  933. End If
  934. if ValidateDate(value) then
  935. strDate= Split(value, "/")
  936. dd= INT(strDate(0))
  937. mm= INT(strDate(1))
  938. yr= INT(strDate(2))
  939.  
  940. currDate= Split( Format(returnDate, "dd/mm/yyyy"),"/")
  941. 'If yr = Format(Now(), "yyyy") Then
  942. If yr= INT(currDate(2)) then
  943. Dim mon as Integer
  944. Dim dayD as Integer
  945. mon= INT(currDate(1))
  946. dayD = INT(currDate(0))
  947. If mm < mon Then
  948. greaterThnEqualToReturnYr = False
  949. ElseIf mm=mon then
  950. If dd<dayD then
  951. greaterThnEqualToReturnYr = False
  952. Else
  953. greaterThnEqualToReturnYr = True
  954. End If
  955. Else
  956. greaterThnEqualToReturnYr = True
  957. End If
  958.  
  959. ElseIf yr < currDate(2) And mm <= 12 Then
  960. greaterThnEqualToReturnYr = False
  961. Else
  962. greaterThnEqualToReturnYr = True
  963. End If
  964. End If
  965. End Function
  966.  
  967. Public Function TestAlphabet(lstr_check As String) As Boolean
  968. 'allowed characters A to Z, a to z And Blank
  969. Dim i As Integer
  970. Dim ia As Integer
  971. Dim ina As Integer
  972. Dim stlen As Integer
  973.  
  974. stlen = Len(lstr_check)
  975. ia = 0
  976. ina = 0
  977. For i = 1 To stlen
  978. Select Case (Mid(lstr_check, i, 1))
  979. Case "A" To "Z" 'A to Z
  980. ia = ia + 1
  981. Case "a" To "z" 'a to z
  982. ia = ia + 1
  983. Case Else
  984. ina = ina + 1
  985. End Select
  986. Next i
  987. If ina = 0 Then
  988. TestAlphabet = True
  989. Else
  990. TestAlphabet = False
  991. End If
  992.  
  993. End Function
  994.  
  995.  
  996. Public Function TestAlphabetWithSpace(lstr_check As String) As Boolean
  997. 'allowed characters A to Z, a to z And Blank
  998. Dim i As Integer
  999. Dim ia As Integer
  1000. Dim ina As Integer
  1001. Dim stlen As Integer
  1002.  
  1003. stlen = Len(lstr_check)
  1004. ia = 0
  1005. ina = 0
  1006. For i = 1 To stlen
  1007. Select Case (Mid(lstr_check, i, 1))
  1008. Case "A" To "Z" 'A to Z
  1009. ia = ia + 1
  1010. Case "a" To "z" 'a to z
  1011. ia = ia + 1
  1012. Case " " ' Blank
  1013. ia = ia + 1
  1014. Case Else
  1015. ina = ina + 1
  1016. End Select
  1017. Next i
  1018. If ina = 0 Then
  1019. TestAlphabetWithSpace = True
  1020. Else
  1021. TestAlphabetWithSpace = False
  1022. End If
  1023.  
  1024. End Function
  1025.  
  1026.  
  1027. Public Function TestAlphabetNumSpl(lstr_check As String) As Boolean
  1028. 'allowed characters A to Z, a to z And Blank
  1029. Dim i As Integer
  1030. Dim ia As Integer
  1031. Dim ina As Integer
  1032. Dim stlen As Integer
  1033.  
  1034. stlen = Len(lstr_check)
  1035. ia = 0
  1036. ina = 0
  1037. For i = 1 To stlen
  1038. Select Case (Mid(lstr_check, i, 1))
  1039. Case "A" To "Z" 'A to Z
  1040. ia = ia + 1
  1041. Case "a" To "z" 'a to z
  1042. ia = ia + 1
  1043. Case "0" To "9" '0 to 9
  1044. ia = ia + 1
  1045. Case " ", ",", ".", "-", "/","'",":","&", "(", ")", "`", "$", "%", "}", "$", "}", "{" , "!", "|" ,"#", ";", "\" ', "[", "]" ' Blank
  1046. ia = ia + 1
  1047. Case Else
  1048. ina = ina + 1
  1049. End Select
  1050. Next i
  1051. If ina = 0 Then
  1052. TestAlphabetNumSpl = True
  1053. Else
  1054. TestAlphabetNumSpl = False
  1055. End If
  1056.  
  1057. End Function
  1058.  
  1059.  
  1060. Public Function checkFutureDate(ByVal value As String) As Boolean
  1061. Dim mm As Integer
  1062. Dim yr As Integer
  1063. Dim dd as Integer
  1064. Dim strDate As Object
  1065. Dim currDate as Object
  1066. 'mm = Format(CDate(Trim(value)), "MM")
  1067. 'yr = Format(CDate(Trim(value)), "yyyy")
  1068. 'dd = Format(CDate(Trim(value)), "dd")
  1069. If(Len(Trim(value))=0) then
  1070. checkFutureDate=True
  1071. Exit function
  1072. End If
  1073. if ValidateDate(value) then
  1074. strDate= Split(value, "/")
  1075. dd= INT(strDate(0))
  1076. mm= INT(strDate(1))
  1077. yr= INT(strDate(2))
  1078.  
  1079. currDate= Split( Format(Now(), "dd/mm/yyyy"),"/")
  1080. 'If yr = Format(Now(), "yyyy") Then
  1081. If yr= INT(currDate(2)) then
  1082. Dim mon as Integer
  1083. Dim dayD as Integer
  1084. mon= INT(currDate(1))
  1085. dayD = INT(currDate(0))
  1086. If mm < mon Then
  1087. checkFutureDate = True
  1088. ElseIf mm=mon then
  1089. If dd<=dayD then
  1090. checkFutureDate = True
  1091. Else
  1092. checkFutureDate = False
  1093. End If
  1094. Else
  1095. checkFutureDate = False
  1096. End If
  1097.  
  1098. ElseIf yr < currDate(2) And mm <= 12 Then
  1099. checkFutureDate = True
  1100. Else
  1101. checkFutureDate = False
  1102. End If
  1103. End If
  1104. End Function
  1105.  
  1106. 'Arjun
  1107. Public Function specificYearBeforeDate(ByVal value As String,ByVal yearGap as Integer,ByVal dd as String) As String
  1108. Dim currDt as Object
  1109. Dim newDt as String
  1110. Dim intYear
  1111. 'Dim a
  1112. 'a = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
  1113.  
  1114. If value<>"" Then
  1115. currDt= Split(value,"/")
  1116. 'Day
  1117. newDt=dd & "/"
  1118. 'Month
  1119. if currDt(1)="01" then
  1120. newDt=newDt & "02"
  1121. ElseIf currDt(1)="02" then
  1122. newDt=newDt & "03"
  1123. ElseIf currDt(1)="03" then
  1124. newDt=newDt & "04"
  1125. ElseIf currDt(1)="04" then
  1126. newDt=newDt & "05"
  1127. ElseIf currDt(1)="05" then
  1128. newDt=newDt & "06"
  1129. ElseIf currDt(1)="06" then
  1130. newDt=newDt & "07"
  1131. ElseIf currDt(1)="07" then
  1132. newDt=newDt & "08"
  1133. ElseIf currDt(1)="08" then
  1134. newDt=newDt & "09"
  1135. ElseIf currDt(1)="09" then
  1136. newDt=newDt & "10"
  1137. ElseIf currDt(1)="10" then
  1138. newDt=newDt & "11"
  1139. ElseIf currDt(1)="11" then
  1140. newDt=newDt & "12"
  1141. ElseIf currDt(1)="12" then
  1142. newDt=newDt & "01"
  1143. End If
  1144. 'Year
  1145. intYear=INT(currDt(2))
  1146. intYear=intYear-yearGap
  1147. newDt=newDt & "/" & Cstr(intYear)
  1148. 'msgbox newDt
  1149. specificYearBeforeDate=newDt
  1150. End If
  1151.  
  1152. End Function
  1153.  
  1154. Public function checkDuplicateTaxPyrPIN(ByVal value As String) As Boolean
  1155.  
  1156. Dim PINNo As String
  1157. Dim sheet as Object
  1158. sheet=ThisComponent.sheets.getByName("A_Basic_Info")
  1159. PINNo = sheet.getCellrangeByName("SecA.TaxPayerPIN").String
  1160. If (TestPIN(lstr_check) And TestPIN(PINNo)) Then
  1161. If lstr_check = PINNo And lstr_check <> "" And PINNo <> "" Then
  1162. checkDuplicateTaxPyrPIN = False
  1163. Else
  1164. checkDuplicateTaxPyrPIN = True
  1165. End If
  1166. Else
  1167. checkDuplicateTaxPyrPIN = False
  1168. End If
  1169.  
  1170. End Function
  1171.  
  1172. 'EXTRA FUNCTIONS
  1173. Public Function isTodaysDate(ByVal value As String) As Boolean
  1174.  
  1175. Dim sheetName As String
  1176. value = Format(CDate(Trim(value)), "dd/MM/yyyy")
  1177. If Trim(value) <> "" And Trim(value) <> Format(Now(), "dd/MM/yyyy") Then
  1178. isTodaysDate = False
  1179. Else
  1180. isTodaysDate = True
  1181. End If
  1182. End Function
  1183.  
  1184. sub generate_ods_file()
  1185.  
  1186. ThisComponent.Store
  1187. REM source document
  1188. Dim sURL$, sLinkSheetName$
  1189. sURL = thisComponent.getURL()
  1190. 'sLinkSheetName = thisComponent.Sheets.getByIndex(thisComponent.Sheets.count-1).getName()
  1191.  
  1192. '********************************************************
  1193. 'Code added by janhavi on 28.02.2012 for Amendment
  1194. if ThisComponent.getSheets().hasByName("Amendment") Then
  1195. sLinkSheetName = thisComponent.Sheets.getByIndex(thisComponent.Sheets.count-2).getName()
  1196. Else
  1197. sLinkSheetName = thisComponent.Sheets.getByIndex(thisComponent.Sheets.count-1).getName()
  1198. End If
  1199. '********************************************************
  1200.  
  1201.  
  1202. 'Msgbox sURL
  1203. REM target document
  1204. Dim doc, sheets, sName$, pos%
  1205. doc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_default",0, Array())
  1206. sheets = doc.getSheets()
  1207. ' sName = getUniqueName(sheets, "Copied")
  1208. sName = getUniqueName(sheets, "Sheet1")
  1209. pos = 0
  1210.  
  1211. REM new sheet
  1212. Dim sh
  1213. sheets.insertNewByName(sName, pos)
  1214. sh = sheets.getByName(sName)
  1215.  
  1216. REM link the new sheet
  1217. sh.link(sURL, sLinkSheetName, "calc8", "", com.sun.star.sheet.SheetLinkMode.VALUE)
  1218. REM break link
  1219. sh.setLinkMode(com.sun.star.sheet.SheetLinkMode.NONE)
  1220.  
  1221. REM
  1222. sheets.removeByName("Sheet2")
  1223. sheets.removeByName("Sheet3")
  1224. REM
  1225. Dim cFile,cURL,oColumn,oCell,FilePicker,FPtype(0),FileN
  1226. oCell = Nothing
  1227. GlobalScope.BasicLibraries.LoadLibrary("Tools")
  1228. FileN=GetFileNameWithoutExtension(sURL,"/")
  1229. 'FileN=GetFileNameWithoutExtension(sURL)
  1230. 'msgbox "With Path : "+FileN
  1231.  
  1232.  
  1233. '=======================
  1234. ' Added By Sandeep Thaker
  1235. '==========================
  1236. Dim currDate As String
  1237. Dim currTime As String
  1238. Dim TaxPayerPIN As String
  1239.  
  1240. currDate=Day(Now) & "-" & Month(Now) & "-" & Year(Now)
  1241. currTime=Hour(Now) & "-" & Minute(Now) & "-" & Second(Now)
  1242.  
  1243. TaxPayerPIN = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.TaxPayerPIN").string
  1244.  
  1245. FileN = currDate + "_" +currTime+ "_" + TaxPayerPIN + "_VAT.ods" 'Modified by Sandeep Thaker
  1246.  
  1247. '=======================
  1248. ' End of Added By Sandeep Thaker
  1249. '==========================
  1250.  
  1251. 'cFile = "F:\MyCalc_upload" ' Windows
  1252. 'cURL = ConvertToURL( cFile + "_upload.ods" )
  1253. cURL = FileN
  1254.  
  1255.  
  1256.  
  1257. 'cFile = "F:\MyCalc_upload" ' Windows
  1258. 'cURL = ConvertToURL( cFile + "_upload.ods" )
  1259. cURL = FileN
  1260. sh = sheets.getByName(sName)
  1261.  
  1262. For i=1 to 25
  1263. If i=10 Then
  1264. i = i+1
  1265. End IF
  1266. oColumn = sh.getColumns.getByIndex( i )
  1267. oColumn.setPropertyValue("IsVisible", true)
  1268.  
  1269. Next
  1270. sh.CharColor = RGB(0,0,0)
  1271. oColumns = sh.getColumns()
  1272. ' Get a specific column.
  1273. oColumn = oColumns.getByName( "A" )
  1274. ' Change width of column.
  1275. oColumn.Width = 0 ' 0 cm
  1276.  
  1277. 'oCell = sh.getCellRangeByName("B1")
  1278. 'oCell.CharColor = RGB(0,0,0)
  1279.  
  1280. 'oCell.setString("This sheet have hidden data please do not try to alter this file.")
  1281. oCell = sh.getCellRangeByName("A3")
  1282. oCell.setString("VAT_RET")
  1283. sh.Protect(Pwd)
  1284. oCell = sh.getCellRangeByName("C1")
  1285. 'doc.storeAsURL( cURL, Array() )
  1286. 'doc.Protect(Pwd)
  1287. oDocFrame = doc.getCurrentController().getFrame()
  1288. oDispatchHelper = createUnoService( "com.sun.star.frame.DispatchHelper" )
  1289. ' oDispatchHelper.executeDispatch( oDocFrame, ".uno:SaveAs", "", 0, Array() )
  1290. doc.Protect(Pwd)
  1291.  
  1292. cURL = ConvertFromUrl(fSaveFile(FileN,doc)) ' Modified By Sandeep Thaker
  1293.  
  1294. doc.close(True)
  1295. if cURL <> "" then
  1296. a5 = split(ConvertFromUrl(cURL),"\")
  1297. Dim destFileName as String
  1298. destFileName = a5(Ubound(a5))
  1299. dim makeNewFolderPath as String
  1300. makeNewFolderPath = ""
  1301. for i = Lbound(a5) to UBound(a5) - 1
  1302. if i = Lbound(a5) then
  1303. makeNewFolderPath = a5(i)
  1304. else
  1305. makeNewFolderPath = makeNewFolderPath + "\" + a5(i)
  1306. end if
  1307. next i
  1308. tod = NOW()
  1309. tod = (Mid(tod, 1, 10))
  1310. tod = join(split(tod, "/"), "-")
  1311. makeNewFolderPath = makeNewFolderPath + "\"
  1312. a4 = split(a5(Ubound(a5)),".")
  1313. zipPath = makeNewFolderPath + a4(0) + ".zip"
  1314. PutZipContent(ConvertToUrl(zipPath),destFileName,cURL, True)
  1315. Dim s As String
  1316. s = ConvertFromUrl(cURL)
  1317. Kill s
  1318. MsgBox "The zip file containing the sheet to be uploaded is saved at :"+ ConvertFromUrl(zipPath) '"File Saved at: "+ ConvertFromUrl(cURL) + " and
  1319. end if
  1320.  
  1321. end sub
  1322.  
  1323. Function getUniqueName(oContainer,sName$)
  1324. Dim i%,sNew$
  1325. sNew = sName
  1326. Do while oContainer.hasByName(sNew)
  1327. oContainer.removeByName(sNew)
  1328. 'i = i +1
  1329. 'sNew = sName &"_"& i
  1330. loop
  1331. getUniqueName = sNew
  1332. End Function
  1333.  
  1334.  
  1335. 'ENDED BY JANHAVI ON 23.11.2011
  1336.  
  1337. Public Sub fillUploadSheet()
  1338. Dim sheetCount As Integer, i As Integer, rowCount As Integer
  1339. Dim finalSheet As String, propValuePair As String
  1340.  
  1341. Dim PROP_SEP As String
  1342. PROP_SEP = "@P_@"
  1343. Dim CLASS_SEP As String
  1344. CLASS_SEP = "#C_@"
  1345. Dim VALUE_SEP As String
  1346. VALUE_SEP = "%V_@"
  1347. Dim MAIN_PROP_START As String
  1348. MAIN_PROP_START = "#"
  1349. Dim LIST_PROP_START As String
  1350. LIST_PROP_START = "@L_@"
  1351.  
  1352. Dim LIST_PROP_SEP As String
  1353. LIST_PROP_SEP = "@PL@"
  1354. Dim LIST_SEP As String
  1355. LIST_SEP = "@L_@"
  1356. Dim LIST_VALUE_SEP As String
  1357. LIST_VALUE_SEP = "%VL@"
  1358.  
  1359.  
  1360.  
  1361. Dim tempString As String, cellName As String
  1362. Dim row As Long, column As Long, LastColumn As Long, LastRow As Long
  1363. Dim currentWorkSheet As Object
  1364. Dim cellRange As Object
  1365. Dim nameCell As Object
  1366. Dim str1 As String, str2 As String, str3 As String, str4 As String
  1367. sheetCount = ThisComponent.Sheets.Count
  1368.  
  1369. 'Arjun
  1370. Dim cellCounter as Long
  1371. Dim listNameAppendFlag as Boolean
  1372. listNameAppendFlag = False
  1373. cellCounter=0
  1374.  
  1375. If (sheetCount > 0) Then
  1376. '*************************************************
  1377. 'Code added for amendment by Janhavi on 28.02.2012
  1378.  
  1379. if ThisComponent.getSheets().hasByName("Amendment") Then
  1380. sheet1 = ThisComponent.Sheets.getByIndex(sheetCount - 2)
  1381. Else
  1382. sheet1 = ThisComponent.Sheets.getByIndex(sheetCount - 1)
  1383. End If
  1384.  
  1385. '*************************************************
  1386.  
  1387. ' sheet1 = ThisComponent.Sheets.getByIndex(sheetCount - 1)
  1388. ThisComponent.CurrentController.setActiveSheet(sheet1)
  1389. sheet1.Unprotect(Pwd)
  1390. finalSheet = sheet1.Name
  1391. sheet1.getCellByPosition(0,0).String = ""
  1392. For i = 0 To 255
  1393. If sheet1.getCellByPosition(i,1).String<>"" then
  1394. sheet1.getCellByPosition(i,1).String=""
  1395. End If
  1396. Next
  1397. allRangeNames = ThisComponent.NamedRanges.getElementNames()
  1398. Dim firstRowValue as String, secondRowValue As String
  1399. firstRowValue = ""
  1400. secondRowValue = ""
  1401. Dim validationSheet as object
  1402. validationSheet = ThisComponent.Sheets.getByName("Validations")
  1403. For i = 1 To 65535
  1404. If(validationSheet.getCellByPosition(0,i).getType() = EMPTYCELLTYPE) Then
  1405. Exit For
  1406. End If
  1407. dim ccell as object
  1408. ccell = validationSheet.getCellByPosition(3,i)
  1409. If(validationSheet.getCellByPosition(3,i).String = "") Then
  1410. Goto Continue
  1411. End If
  1412. rangeName = validationSheet.getCellByPosition(2, i).String
  1413. Dim startRowNum as Long , endRowNum as Long, startColumnNum as Long , endcolumnNum as Long
  1414. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  1415. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  1416. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  1417. startColumnNum = oRange.getReferredCells().getRangeAddress().StartColumn
  1418. endcolumnNum = oRange.getReferredCells().getRangeAddress().EndColumn
  1419.  
  1420. If (startRowNum = endRowNum and startColumnNum = endColumnNum) then
  1421. cell = oRange.getReferredCells().getCellByPosition(0,0)
  1422. cellValue = cell.value
  1423. if(cellValue = 0) then
  1424. cellValue = cell.String
  1425. End If
  1426. If Trim(firstRowValue) = "" Then
  1427. firstRowValue = firstRowValue & rangeName & VALUE_SEP & cellValue
  1428. Else
  1429. firstRowValue = firstRowValue & PROP_SEP & rangeName & VALUE_SEP & cellValue
  1430. End If
  1431. Else
  1432. If Trim(secondRowValue) = "" Then
  1433. secondRowValue = rangeName
  1434. Else
  1435. secondRowValue = secondRowValue & LIST_SEP & rangeName
  1436. End If
  1437.  
  1438. For multriEntryRowNum = 0 to endRowNum - startRowNum
  1439. REM Check whether any column contains data
  1440. REM for current multi-entry row using multriEntryRowNum, startColNum and endColNum
  1441. REM If any column contains data then run the validationrules according to the range
  1442.  
  1443. 'Arjun
  1444. If listNameAppendFlag = True Then
  1445. If Trim(secondRowValue) = "" Then
  1446. secondRowValue = rangeName
  1447. Else
  1448. secondRowValue = secondRowValue & LIST_SEP & rangeName
  1449. End If
  1450. listNameAppendFlag = False
  1451. End If
  1452.  
  1453. doValidation = False
  1454. For multiEntryColNum = startColumnNum to endColumnNum
  1455. Dim referredCells as object
  1456. referredCells = oRange.getReferredCells()
  1457. curCell = oRange.getReferredCells().getCellByPosition(multiEntryColNum,multriEntryRowNum)
  1458. If(curCell.getType() <> EMPTYCELLTYPE) Then
  1459. Dim formulaLng as Long
  1460. formulaLng = 3
  1461. If(curCell.getType() = formulaLng and curCell.String = "" and curCell.value = 0) Then
  1462.  
  1463. else
  1464. doValidation = True
  1465. Exit For
  1466. End If
  1467. End If
  1468. Next 'multiEntryColNum
  1469.  
  1470. If (doValidation) Then
  1471. Rem Do the validation for the row start from startmultyentryvalidationrow to endmultyentryvalidationrow
  1472. For multiEntryColNum = startColumnNum to endColumnNum
  1473. curCell = oRange.getReferredCells().getCellByPosition(multiEntryColNum,multriEntryRowNum)
  1474. cellValue = curCell.value
  1475. if(cellValue = 0) then
  1476. cellValue = curCell.String
  1477. End If
  1478. If multiEntryColNum = startColumnNum Then
  1479. secondRowValue = secondRowValue & LIST_PROP_SEP
  1480. End If
  1481. If multiEntryColNum = endColumnNum Then
  1482. secondRowValue = secondRowValue & cellValue
  1483.  
  1484. sheet1.getCellByPosition(cellCounter,1).String=secondRowValue
  1485.  
  1486. If Len(secondRowValue) > 12000 And Len(secondRowValue) < 16000 Then
  1487. cellCounter=cellCounter+1
  1488. secondRowValue=""
  1489. listNameAppendFlag = True
  1490. End If
  1491.  
  1492. Else
  1493. secondRowValue = secondRowValue & cellValue & LIST_VALUE_SEP
  1494. End If
  1495. Next 'multiEntryColNum
  1496. End If
  1497. Next multriEntryRowNum
  1498. End If
  1499. Continue:
  1500. Next i
  1501. End If
  1502. sheet1.unprotect(Pwd)
  1503. sheet1.getCellByPosition(0,0).String = firstRowValue
  1504. 'sheet1.getCellByPosition(0,1).String = secondRowValue
  1505. 'For generating hash codes.
  1506. oDocScriptProvider = ThisComponent.getScriptProvider()
  1507. oScriptHash = oDocScriptProvider.getScript("vnd.sun.star.script:Encrypt.SHA.js?language=JavaScript&location=document")
  1508.  
  1509. sheet1.getCellByPosition(0,3).String = oScriptHash.invoke(Array(sheet1.getCellByPosition(0,0).String), Array(), Array())
  1510.  
  1511. For i = 0 To 255
  1512. If sheet1.getCellByPosition(i,1).String<>"" then
  1513. sheet1.getCellByPosition(i,4).String=oScriptHash.invoke(Array(sheet1.getCellByPosition(i,1).String), Array(), Array())
  1514. End If
  1515. Next
  1516. sheet1.protect(Pwd)
  1517. End Sub
  1518.  
  1519.  
  1520. Function calc_SUBSTITUTE(vRange) As String
  1521.  
  1522. ' The first argument to callFunction() is the Calc Function Name
  1523. ' The 2nd argument is the parameters of that function as an array
  1524. FuncAcc = createunoservice("com.sun.star.sheet.FunctionAccess")
  1525. aArgs = array(vRange,",","")
  1526. calc_SUBSTITUTE = FuncAcc.callFunction("SUBSTITUTE", aArgs)
  1527.  
  1528. End Function
  1529.  
  1530. 'Function fSaveFile() as String
  1531. ' 'Set the Dialog Arguments to a Template for FILESAVE
  1532. ' sFilePickerArgs = Array(com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION )
  1533.  
  1534. 'register the Service for Filepicker
  1535. ' oFilePicker = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" )
  1536.  
  1537. 'Pass some arguments to it
  1538. ' With oFilePicker
  1539. ' .Initialize( sFilePickerArgs() )
  1540. ' .setDisplayDirectory( "C:/" )
  1541. ' .appendFilter("CSV Files (.csv)", "*.csv" )
  1542. ' .setTitle( "Save As ..." )
  1543. ' End With
  1544.  
  1545. 'If the savepath is selected return the complete path and display it in an messagebox
  1546. ' If oFilePicker.execute() Then
  1547. ' sFiles = oFilePicker.getFiles()
  1548. ' fSaveFile = sFiles(0)
  1549. ' End If
  1550.  
  1551. ' Close the Dialog
  1552. ' oFilePicker.Dispose()'
  1553. 'End Function
  1554.  
  1555.  
  1556. '=========================================
  1557. 'Default Name in Dialog box for saving file
  1558. 'Added by Sandeep Thaker
  1559. '==========================================
  1560. Function fSaveFile(fileName as String,doc as Object) as String
  1561. 'Set the Dialog Arguments to a Template for FILESAVE
  1562.  
  1563. sFilePickerArgs = Array(com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION )
  1564.  
  1565. 'register the Service for Filepicker
  1566. oFilePicker = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" )
  1567.  
  1568. 'Pass some arguments to it
  1569. With oFilePicker
  1570. .Initialize( sFilePickerArgs() )
  1571.  
  1572. .appendFilter("ODS Files (.ods)", "*.ods" )
  1573. .setTitle( "Save As ..." )
  1574. .setDefaultName(fileName)
  1575. End With
  1576.  
  1577. 'If the savepath is selected return the complete path and display it in an messagebox
  1578. If oFilePicker.execute() Then
  1579. sFiles = oFilePicker.getFiles()
  1580. fSaveFile = sFiles(0)
  1581. doc.storeToURL( fSaveFile, Array() )
  1582. End If
  1583.  
  1584. ' Close the Dialog
  1585. oFilePicker.Dispose()
  1586.  
  1587. End Function
  1588. '==============================================
  1589. 'End of Added by Sandeep Thaker
  1590. '==============================================
  1591.  
  1592.  
  1593. '*************NOT USED/EXRTA FUNCTIONS*********************************************
  1594. Public Sub Generate_upload()
  1595. On Error GoTo Errorhandle
  1596.  
  1597. Dim sURL$, sLinkSheetName$
  1598. sURL = thisComponent.getURL()
  1599. GlobalScope.BasicLibraries.LoadLibrary("Tools")
  1600. FileN=GetFileNameWithoutExtension(sURL)
  1601. FileN = fSaveFile() '"file:///D:/KRA Work/Excel/VAT Returns_up.csv"
  1602. ' cURL = FileN
  1603.  
  1604. ' doc.storeAsURL( cURL, Array() )
  1605. ' MsgBox "File Saved at: "+ ConvertFromUrl(cURL)
  1606. Dim oSFA As Object, oOutStream as Object, oOutText as Object
  1607. Dim sFilePath as String
  1608. oSFA = createUNOService ("com.sun.star.ucb.SimpleFileAccess")
  1609. sFilePath = FileN '"C:\basefile.txt"
  1610. If oSFA.exists(sFilePath) Then
  1611. oSFA.kill(sFilePath) 'if file exists, delete it
  1612. End If
  1613. sheetCount = ThisComponent.Sheets.Count
  1614.  
  1615. If (sheetCount > 0) Then
  1616. sheet1 = ThisComponent.Sheets.getByIndex(sheetCount - 1)
  1617. firstRowValue = sheet1.getCellByPosition(0,0).String
  1618. secondRowValue = sheet1.getCellByPosition(0,1).String
  1619. End If
  1620.  
  1621. oOutStream = oSFA.openFileWrite(sFilePath)
  1622. oOutText = createUNOService ("com.sun.star.io.TextOutputStream")
  1623. oOutText.setOutputStream(oOutStream)
  1624.  
  1625. oOutText.WriteString(firstRowValue)
  1626. oOutText.WriteString(chr(13))
  1627. oOutText.WriteString(secondRowValue)
  1628. oOutText.WriteString(chr(13))
  1629. oOutText.WriteString(DigestStrToHexStr(firstRowValue + secondRowValue))
  1630. oOutText.closeOutput()
  1631. MsgBox ("No Error Found,Upload file is saved : """ + ConvertFromUrl(sFilePath) + """.")
  1632.  
  1633. Exit Sub
  1634.  
  1635. Errorhandle:
  1636. MsgBox ("Modifications Are Not Saved,Upload File Not Generated") '& Err.Description)
  1637. Exit Sub
  1638. Resume
  1639. End Sub
  1640.  
  1641. Public Function validateExpoFormat(lstr_check As String) As Boolean
  1642. 'allowed characters 0 to 9 and .
  1643. Dim i As Integer
  1644. Dim ia As Integer
  1645. Dim ina As Integer
  1646. Dim stlen As Integer
  1647. Dim dotCount As Integer
  1648. Dim expCount as Integer
  1649. Dim plusCount as Integer
  1650.  
  1651. stlen = Len(lstr_check)
  1652. ia = 0
  1653. ina = 0
  1654. validateExpoFormat = True
  1655. For i = 1 To stlen
  1656. Select Case (Mid(lstr_check, i, 1))
  1657. Case "-"
  1658. ia = ia + 1
  1659. Case ","
  1660. ia = ia + 1
  1661. Case "."
  1662. ia = ia + 1
  1663. dotCount = dotCount + 1
  1664. Case "E"
  1665. ia = ia + 1
  1666. expCount = expCount + 1
  1667. Case "+"
  1668. ia = ia + 1
  1669. plusCount = plusCount + 1
  1670. Case "0" To "9" '0 to 9
  1671. ia = ia + 1
  1672. Case Else
  1673. ina = ina + 1
  1674. validateExpoFormat = False
  1675. Exit Function
  1676. End Select
  1677. Next i
  1678. If dotCount > 1 or expCount>1 or plusCount>1 Then
  1679. validateExpoFormat = False
  1680. End If
  1681. End Function
  1682.  
  1683. Public Function CompareSumValue() As Boolean
  1684. unprotectsheet("O_VAT_Due")
  1685. unprotectsheet("M_Sales_N_Purchases")
  1686.  
  1687. Dim value as Double
  1688. Dim value1 as Double
  1689. Dim sum1 as Double
  1690. Dim sum2 as Double
  1691.  
  1692. value = ThisComponent.Sheets.getByName("O_VAT_Due").getCellrangeByName("TaxDue.TotalVatPurCharged").value
  1693. value1 = ThisComponent.Sheets.getByName("O_VAT_Due").getCellrangeByName("TaxDue.AmountVatClaimableListTO").value
  1694. sum1 = ThisComponent.Sheets.getByName("O_VAT_Due").getCellrangeByName("SecD.InputVatExemptSup").value
  1695. sum2 = ThisComponent.Sheets.getByName("O_VAT_Due").getCellrangeByName("SecD.InputVatTaxbleExemptSup").value
  1696. If (Cdbl(format(value,"#,##0.00"))+Cdbl(format(value1,"#,##0.00")))=0 and (Cdbl(format(sum1,"#,##0.00"))+Cdbl(format(sum2,"#,##0.00")))=0 then
  1697. CompareSumValue=True
  1698. Else
  1699. If (Cdbl(format(value,"#,##0.00"))+Cdbl(format(value1,"#,##0.00")))>=0 Then
  1700. If (Cdbl(format(value,"#,##0.00"))+Cdbl(format(value1,"#,##0.00")))<=(Cdbl(format(sum1,"#,##0.00"))+Cdbl(format(sum2,"#,##0.00"))) Then
  1701. CompareSumValue=False
  1702. Else
  1703. CompareSumValue=True
  1704. End If
  1705. Else
  1706. CompareSumValue=True
  1707. End If
  1708. End If
  1709. protectsheet("M_Sales_N_Purchases")
  1710. protectsheet("O_VAT_Due")
  1711. End Function
  1712.  
  1713.  
  1714. Sub resetForAmendment()
  1715. Call resetOnUsageToggle("Sch5.InputTaxPurchDtlsGRList","F_General_Rated_Purchases_Dtls")
  1716. Call resetOnUsageToggle("Sch6.InputTaxPurchDtlsORList","G_Other_Rated_Purchases_Dtls")
  1717. Call resetOnUsageToggle("Sch7.InputTaxPurchDtlsExemptList","H_Zero_Rated_Purchases_Dtls")
  1718. Call resetOnUsageToggle("Sch8.InputTaxPurchDtlsExemptList","I_Exempted_Purchases_Dtls")
  1719. Call resetOnUsageToggleExemption("Sch3.ZeroRateSalesDtlsList","D_Zero_Rated_Sales_Dtls")
  1720. 'Call resetPRNNumber("Sch10.VATPaidDtlsList","K_VAT_Payment_Credits")
  1721. 'Call resetPRNNumber("Sch10.VATSelfAssPaidDtlsList","K_VAT_Payment_Credits")
  1722. 'Call resetPRNNumberSpecial("Sch10.ClaimableServiceImportedList","J_VAT_Imported_Services_Dtls")
  1723. Call resetTaxableValues("Sch1.GeneralRateSalesDtlsList","B_General_Rated_Sales_Dtls")
  1724. Call resetTaxableValues("Sch2.OtherRateSalesDtlsList","C_Other_Rated_Sales_Dtls")
  1725. Call resetTaxableValuesNew("Sch5.InputTaxPurchDtlsGRList","F_General_Rated_Purchases_Dtls")
  1726. Call resetTaxableValuesNew("Sch6.InputTaxPurchDtlsORList","G_Other_Rated_Purchases_Dtls")
  1727. Call resetTaxSingleCellCheck()
  1728. 'Disable 21 and 22 on Amendment
  1729. unprotectsheet("O_VAT_Due")
  1730. if ThisComponent.getSheets().hasByName("Amendment") Then
  1731.  
  1732. sheet=ThisComponent.sheets.getByName("O_VAT_Due")
  1733. oCells = ThisComponent.Sheets.getByName("O_VAT_Due").getCellRangeByName("SecD.CrdtBroughtFrwd")
  1734. CellProtStruc = oCells.CellProtection
  1735.  
  1736. If CellProtStruc.isLocked = False then
  1737. Special_Protect_Range("O_VAT_Due","SecD.CrdtBroughtFrwd")
  1738. End If
  1739.  
  1740. oCells = ThisComponent.Sheets.getByName("O_VAT_Due").getCellRangeByName("SecD.AddRefundClaimPaid")
  1741. CellProtStruc = oCells.CellProtection
  1742.  
  1743. If CellProtStruc.isLocked = False then
  1744. 'Special_Protect_Range("O_VAT_Due","SecD.AddRefundClaimPaid")
  1745. End If
  1746. Else
  1747. sheet=ThisComponent.sheets.getByName("O_VAT_Due")
  1748. oCells = ThisComponent.Sheets.getByName("O_VAT_Due").getCellRangeByName("SecD.CrdtBroughtFrwd")
  1749. CellProtStruc = oCells.CellProtection
  1750.  
  1751. If CellProtStruc.isLocked = True then
  1752. Special_Unprotect_Range("O_VAT_Due","SecD.CrdtBroughtFrwd")
  1753. End If
  1754.  
  1755. oCells = ThisComponent.Sheets.getByName("O_VAT_Due").getCellRangeByName("SecD.AddRefundClaimPaid")
  1756. CellProtStruc = oCells.CellProtection
  1757.  
  1758. If CellProtStruc.isLocked = True then
  1759. 'Special_Unprotect_Range("O_VAT_Due","SecD.AddRefundClaimPaid")
  1760. End If
  1761. End If
  1762. protectsheet("O_VAT_Due")
  1763. End Sub
  1764.  
  1765. sub resetPRNNumber(rangeName as String,sheetName as String)
  1766.  
  1767. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  1768. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  1769. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  1770. sheet=ThisComponent.sheets.getByName(sheetName)
  1771. oColRange = sheet.getCellrangeByName("A"&(startRowNum+1)&":A"&(endRowNum+1))
  1772.  
  1773. Dim prnNo as String
  1774. Dim prnNoObject as Object
  1775. '***
  1776. for i = startRowNum to endRowNum
  1777. row=i
  1778. prnNoObject=sheet.getCellrangeByName("A"&(row+1)&":A"&(row+1))
  1779. prnNo= sheet.getCellrangeByName("A"&(row+1)&":A"&(row+1)).string
  1780. sheet.getCellrangeByName("A"&(row+1)&":A"&(row+1)).string=Cstr(Format(prnNo,0))
  1781. Next
  1782.  
  1783. end Sub
  1784.  
  1785. sub resetPRNNumberSpecial(rangeName as String,sheetName as String)
  1786.  
  1787. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  1788. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  1789. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  1790. sheet=ThisComponent.sheets.getByName(sheetName)
  1791. oColRange = sheet.getCellrangeByName("F"&(startRowNum+1)&":F"&(endRowNum+1))
  1792.  
  1793. Dim prnNo as String
  1794. Dim prnNoObject as Object
  1795. '***
  1796. for i = startRowNum to endRowNum
  1797. row=i
  1798. prnNoObject=sheet.getCellrangeByName("F"&(row+1)&":F"&(row+1))
  1799. prnNo= sheet.getCellrangeByName("F"&(row+1)&":F"&(row+1)).string
  1800. sheet.getCellrangeByName("F"&(row+1)&":F"&(row+1)).string=Cstr(Format(prnNo,0))
  1801. Next
  1802.  
  1803. end Sub
  1804.  
  1805. sub resetTaxableValues(rangeName as String,sheetName as String)
  1806.  
  1807. Dim startRowNum as Long , endRowNum as Long, startColumnNum as Long , endcolumnNum as Long
  1808. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  1809. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  1810. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  1811. sheet=oRange.getReferredCells().getRangeAddress().sheet
  1812.  
  1813. Unprotectsheet(sheetName)
  1814. Dim usage as String
  1815. Dim msgStr As String
  1816. Dim currRange as Object
  1817. Dim row As Long
  1818. Dim tempValue as Double
  1819. Dim tempValueString as String
  1820. sheet=ThisComponent.sheets.getByName(sheetName)
  1821.  
  1822. for i = startRowNum to endRowNum
  1823. row=i
  1824. taxableValue=sheet.getCellrangeByName("H"&(row+1)&":H"&(row+1)).value
  1825. '************
  1826. If taxableValue<0 then
  1827. tempValueString=sheet.getCellrangeByName("I"&(row+1)&":I"&(row+1)).string
  1828. Unprotect_Range(sheetName,"I" & (row+1) & ":I" & (row+1))
  1829. sheet.getCellrangeByName("I"&(row+1)&":I"&(row+1)).value=tempValueString
  1830. tempValueString=sheet.getCellrangeByName("J"&(row+1)&":J"&(row+1)).string
  1831. Unprotect_Range(sheetName,"J" & (row+1) & ":J" & (row+1))
  1832. sheet.getCellrangeByName("J"&(row+1)&":J"&(row+1)).string=tempValueString
  1833. Else
  1834. sheet.getCellrangeByName("I"&(row+1)&":I"&(row+1)).string=""
  1835. Protect_Range(sheetName,"I" & (row+1) & ":I" & (row+1))
  1836. sheet.getCellrangeByName("J"&(row+1)&":J"&(row+1)).string=""
  1837. Protect_Range(sheetName,"J" & (row+1) & ":J" & (row+1))
  1838. End If
  1839. '************
  1840. Next
  1841. protectsheet(sheetName)
  1842. end Sub
  1843.  
  1844. sub resetTaxableValuesNew(rangeName as String,sheetName as String)
  1845.  
  1846. Dim startRowNum as Long , endRowNum as Long, startColumnNum as Long , endcolumnNum as Long
  1847. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  1848. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  1849. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  1850. sheet=oRange.getReferredCells().getRangeAddress().sheet
  1851.  
  1852. Unprotectsheet(sheetName)
  1853. Dim usage as String
  1854. Dim msgStr As String
  1855. Dim currRange as Object
  1856. Dim row As Long
  1857. Dim tempValue as Double
  1858. Dim tempValueString as String
  1859.  
  1860. sheet=ThisComponent.sheets.getByName(sheetName)
  1861.  
  1862. for i = startRowNum to endRowNum
  1863. row=i
  1864. taxableValue=sheet.getCellrangeByName("H"&(row+1)&":H"&(row+1)).value
  1865. '************
  1866. If taxableValue<0 then
  1867. tempValueString=sheet.getCellrangeByName("J"&(row+1)&":J"&(row+1)).string
  1868. Unprotect_Range(sheetName,"J" & (row+1) & ":J" & (row+1))
  1869. sheet.getCellrangeByName("J"&(row+1)&":J"&(row+1)).value=tempValueString
  1870. tempValueString=sheet.getCellrangeByName("K"&(row+1)&":K"&(row+1)).string
  1871. Unprotect_Range(sheetName,"K" & (row+1) & ":K" & (row+1))
  1872. sheet.getCellrangeByName("K"&(row+1)&":K"&(row+1)).string=tempValueString
  1873. Else
  1874. sheet.getCellrangeByName("J"&(row+1)&":J"&(row+1)).string=""
  1875. Protect_Range(sheetName,"J" & (row+1) & ":J" & (row+1))
  1876. sheet.getCellrangeByName("K"&(row+1)&":K"&(row+1)).string=""
  1877. Protect_Range(sheetName,"K" & (row+1) & ":K" & (row+1))
  1878. End If
  1879. '************
  1880. Next
  1881. protectsheet(sheetName)
  1882. end Sub
  1883.  
  1884. sub resetOnUsageToggle(rangeName as String,sheetName as String)
  1885.  
  1886. Dim startRowNum as Long , endRowNum as Long, startColumnNum as Long , endcolumnNum as Long
  1887. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  1888. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  1889. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  1890. sheet=oRange.getReferredCells().getRangeAddress().sheet
  1891.  
  1892. Unprotectsheet(sheetName)
  1893. Dim usage as String
  1894. Dim msgStr As String
  1895. Dim currRange as Object
  1896. Dim row As Long
  1897. Dim tempValue as String
  1898.  
  1899. sheet=ThisComponent.sheets.getByName(sheetName)
  1900.  
  1901. for i = startRowNum to endRowNum
  1902. row=i
  1903. selectedPurchaserCode=sheet.getCellrangeByName("A"&(row+1)&":A"&(row+1)).string
  1904. '************
  1905. If selectedPurchaserCode <> "" Then
  1906.  
  1907. 'disable Exemption Certificate Number in case "Exempt"
  1908. If selectedPurchaserCode = "Import" Then
  1909. sheet.getCellrangeByName("L"&(row+1)&":L"&(row+1)).string="Import"
  1910. sheet.getCellrangeByName("B"&(row+1)&":B"&(row+1)).string=""
  1911. Protect_Range(sheetName,"B" & (row+1) & ":B" & (row+1))
  1912. tempValue=sheet.getCellrangeByName("G"&(row+1)&":G"&(row+1)).string
  1913. Unprotect_Range(sheetName,"G" & (row+1) & ":G" & (row+1))
  1914. sheet.getCellrangeByName("G"&(row+1)&":G"&(row+1)).string=tempValue
  1915. ElseIf selectedPurchaserCode = "Local" Then
  1916. sheet.getCellrangeByName("L"&(row+1)&":L"&(row+1)).string="Local"
  1917. tempValue=sheet.getCellrangeByName("B"&(row+1)&":B"&(row+1)).string
  1918. Unprotect_Range(sheetName,"B" & (row+1) & ":B" & (row+1))
  1919. sheet.getCellrangeByName("B"&(row+1)&":B"&(row+1)).string=tempValue
  1920. sheet.getCellrangeByName("G"&(row+1)&":G"&(row+1)).string=""
  1921. Protect_Range(sheetName,"G" & (row+1) & ":G" & (row+1))
  1922. End If
  1923. Else
  1924. sheet.getCellrangeByName("L"&(row+1)&":L"&(row+1)).string=""
  1925. tempValue=sheet.getCellrangeByName("B"&(row+1)&":B"&(row+1)).string
  1926. Unprotect_Range(sheetName,"B" & (row+1) & ":B" & (row+1))
  1927. sheet.getCellrangeByName("B"&(row+1)&":B"&(row+1)).string=tempValue
  1928. sheet.getCellrangeByName("G"&(row+1)&":G"&(row+1)).string=""
  1929. Protect_Range(sheetName,"G" & (row+1) & ":G" & (row+1))
  1930. End If
  1931. '************
  1932. Next
  1933. protectsheet(sheetName)
  1934. end Sub
  1935.  
  1936. Sub resetTaxSingleCellCheck()
  1937. unprotectsheet("M_Sales_N_Purchases")
  1938. unprotectsheet("O_VAT_Due")
  1939. Dim sheet as Object
  1940. Dim msgStr As String
  1941. Dim salesExemptValue as Double
  1942. Dim tempValue as Double
  1943. Dim taxableSalesGen as Double
  1944. Dim taxableSalesOther as Double
  1945. Dim taxableSales as Double
  1946.  
  1947. sheet=ThisComponent.sheets.getByName("M_Sales_N_Purchases")
  1948. salesExemptValue= sheet.getCellrangeByName("Sales.ExemptSalesDtlsTO").value
  1949. taxableSalesGen=sheet.getCellrangeByName("Sales.GeneralRateSalesDtlsTO").value
  1950. taxableSalesOther=sheet.getCellrangeByName("Sales.OtherRateSalesDtlsTO").value
  1951. taxableSales=sheet.getCellrangeByName("Sales.ZeroRateSalesSecASecBTO").value
  1952.  
  1953. If salesExemptValue>0 and (taxableSalesGen>0 or taxableSalesOther>0 or taxableSales>0) then
  1954. sheet=ThisComponent.sheets.getByName("O_VAT_Due")
  1955. 'enable
  1956. tempValue=sheet.getCellrangeByName("SecD.InputVatExemptSup").value
  1957. Unprotect_Range("O_VAT_Due","SecD.InputVatExemptSup")
  1958. sheet.getCellrangeByName("SecD.InputVatExemptSup").value=tempValue
  1959. tempValue=sheet.getCellrangeByName("SecD.InputVatTaxbleExemptSup").value
  1960. Unprotect_Range("O_VAT_Due","SecD.InputVatTaxbleExemptSup")
  1961. sheet.getCellrangeByName("SecD.InputVatTaxbleExemptSup").value=tempValue
  1962. Else
  1963. sheet=ThisComponent.sheets.getByName("O_VAT_Due")
  1964. 'disable
  1965. sheet.getCellrangeByName("SecD.InputVatExemptSup").string=""
  1966. Protect_Range("O_VAT_Due","SecD.InputVatExemptSup")
  1967. sheet.getCellrangeByName("SecD.InputVatTaxbleExemptSup").string=""
  1968. Protect_Range("O_VAT_Due","SecD.InputVatTaxbleExemptSup")
  1969. End If
  1970.  
  1971.  
  1972. protectsheet("O_VAT_Due")
  1973. protectsheet("M_Sales_N_Purchases")
  1974. Call EnableDisableBasedOnBAndC()
  1975. End Sub
  1976.  
  1977.  
  1978. Public Function RelevantDateCheck(ByVal value As String) As Boolean
  1979.  
  1980. Dim startDate As String
  1981. Dim endDate As String
  1982. Dim sheet As Object
  1983.  
  1984. Dim date1 as Object
  1985. Dim date2 as Object
  1986. Dim dd1 as Integer
  1987. Dim mm1 as Integer
  1988. Dim yy1 as Integer
  1989. Dim dd2 as Integer
  1990. Dim mm2 as Integer
  1991. Dim yy2 as Integer
  1992.  
  1993.  
  1994. startDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdFrom").string
  1995. endDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdTo").string
  1996.  
  1997. date1= Split(value, "/")
  1998. dd1= INT(date1(0))
  1999. mm1= INT(date1(1))
  2000. yy1= INT(date1(2))
  2001.  
  2002. date2= Split(endDate, "/")
  2003. dd2= INT(date2(0))
  2004. mm2= INT(date2(1))
  2005. yy2= INT(date2(2))
  2006.  
  2007. If checkGrtrThnDate(Cstr(Format(DateSerial(yy2-1, mm2, dd2),"dd/mm/yyyy")),dateVal)=False Then
  2008. RelevantDateCheck = False
  2009. ElseIf checkFutureDate(value)=False or checkGrtrThnDate(value,endDate)=False then
  2010. RelevantDateCheck = False
  2011. Else
  2012. RelevantDateCheck = True
  2013. End If
  2014.  
  2015. End Function
  2016.  
  2017.  
  2018. Public Function lessCompareTotals(totalRangeName As String,cellValue As Double) As Boolean
  2019. 'unprotect all sheets
  2020. for i=0 to ThisComponent.Sheets.Count - 1
  2021. ActiveSheet = ThisComponent.sheets.getByIndex(i)
  2022. ActiveSheet.unprotect(Pwd)
  2023. next i
  2024.  
  2025. Dim sheetCompareName as String
  2026. Dim CompareRangeName as String
  2027.  
  2028. 'get rangeNames
  2029. if(totalRangeName="SecD.AddRefundClaimPaid")then
  2030. sheetCompareName="O_VAT_Due"
  2031. CompareRangeName="SecD.CrdtBroughtFrwd"
  2032. elseif(totalRangeName="")then
  2033. sheetCompareName=""
  2034. CompareRangeName=""
  2035. elseif(totalRangeName="")then
  2036. sheetCompareName=""
  2037. CompareRangeName=""
  2038. End If
  2039.  
  2040. Dim value1 as Double
  2041. Dim value2 as Double
  2042. value1 = cellValue
  2043. value2 = ThisComponent.Sheets.getByName(sheetCompareName).getCellrangeByName(CompareRangeName).value
  2044.  
  2045. If Cdbl(format(value1,"#,##0.00"))>Cdbl(format(value2,"#,##0.00")) then
  2046. lessCompareTotals=False
  2047. Else
  2048. lessCompareTotals=True
  2049. End If
  2050.  
  2051. 'protect all sheets
  2052. for i=0 to ThisComponent.Sheets.Count - 1
  2053. ActiveSheet = ThisComponent.sheets.getByIndex(i)
  2054. ActiveSheet.protect (Pwd)
  2055. next i
  2056.  
  2057. errorSheet = ThisComponent.Sheets.getByName("Errors")
  2058. errorSheet.Unprotect (Pwd)
  2059.  
  2060. validationSheet = ThisComponent.Sheets.getByName("Validations")
  2061. validationSheet.UnProtect (Pwd)
  2062.  
  2063. End Function
  2064.  
  2065. Public Function checkGrtrThnDate(ByVal dateFrom As String,ByVal dateTo as String) As Boolean
  2066. Dim mm As Integer
  2067. Dim yr As Integer
  2068. Dim dd as Integer
  2069. Dim strDate As Object
  2070. Dim currDate as Object
  2071. 'mm = Format(CDate(Trim(value)), "MM")
  2072. 'yr = Format(CDate(Trim(value)), "yyyy")
  2073. 'dd = Format(CDate(Trim(value)), "dd")
  2074. If(Len(Trim(dateFrom))=0) then
  2075. checkGrtrThnDate=True
  2076. Exit function
  2077. End If
  2078. If(Len(Trim(dateTo))=0) then
  2079. checkGrtrThnDate=True
  2080. Exit function
  2081. End If
  2082. if ValidateDate(dateFrom) then
  2083. strDate= Split(dateFrom, "/")
  2084. dd= INT(strDate(0))
  2085. mm= INT(strDate(1))
  2086. yr= INT(strDate(2))
  2087.  
  2088. currDate= Split(dateTo,"/")
  2089. 'If yr = Format(Now(), "yyyy") Then
  2090. If yr= INT(currDate(2)) then
  2091. Dim mon as Integer
  2092. Dim dayD as Integer
  2093. mon= INT(currDate(1))
  2094. dayD = INT(currDate(0))
  2095. If mm < mon Then
  2096. checkGrtrThnDate = True
  2097. ElseIf mm=mon then
  2098. If dd<=dayD then
  2099. checkGrtrThnDate = True
  2100. Else
  2101. checkGrtrThnDate = False
  2102. End If
  2103. Else
  2104. checkGrtrThnDate = False
  2105. End If
  2106.  
  2107. ElseIf yr < currDate(2) And mm <= 12 Then
  2108. checkGrtrThnDate = True
  2109. Else
  2110. checkGrtrThnDate = False
  2111. End If
  2112. End If
  2113. End Function
  2114.  
  2115.  
  2116.  
  2117. Public Function checkGrtrThnDateForInvoiceDate(ByVal rtnPrdTo As String,ByVal invoiceDate as String) As Boolean
  2118. Dim mmRtnTo As Integer
  2119. Dim yrRtnTo As Integer
  2120. Dim ddRtnTo as Integer
  2121. Dim strDate As Object
  2122. Dim currDate as Object
  2123.  
  2124. Dim mmInvDt As Integer
  2125. Dim yrInvDt As Integer
  2126. Dim ddInvDt As Integer
  2127.  
  2128. Dim tempMonth As Integer
  2129.  
  2130. If(Len(Trim(rtnPrdTo))=0) then
  2131. checkGrtrThnDateForInvoiceDate=True
  2132. Exit function
  2133. End If
  2134. If(Len(Trim(invoiceDate))=0) then
  2135. checkGrtrThnDateForInvoiceDate=True
  2136. Exit function
  2137. End If
  2138. if ValidateDate(rtnPrdTo) then
  2139. strDate= Split(rtnPrdTo, "/")
  2140.  
  2141. ddRtnTo= INT(strDate(0))
  2142. mmRtnTo= INT(strDate(1))
  2143. yrRtnTo= INT(strDate(2))
  2144.  
  2145. if ValidateDate(invoiceDate) then
  2146. currDate= Split(invoiceDate,"/")
  2147.  
  2148. ddInvDt= INT(currDate(0))
  2149. mmInvDt= INT(currDate(1))
  2150. yrInvDt= INT(currDate(2))
  2151.  
  2152. 'year of invoice date and rtnPrdTo is same then ...
  2153. If yrRtnTo= yrInvDt then
  2154.  
  2155. if mmInvDt=mmRtnTo then
  2156. checkGrtrThnDateForInvoiceDate = True
  2157. elseif mmInvDt<mmRtnTo and (mmRtnTo-mmInvDt)<=6 Then
  2158. checkGrtrThnDateForInvoiceDate = True
  2159. Else
  2160. checkGrtrThnDateForInvoiceDate = False
  2161. End If
  2162. 'if Year of invoice Date and rtnPrdTo is different
  2163.  
  2164. elseIf yrInvDt<yrRtnTo then
  2165. tempMonth=mmRtnTo+6
  2166. if mmInvDt>mmRtnTo and tempMonth<=mmInvDt then
  2167. checkGrtrThnDateForInvoiceDate = True
  2168. Else
  2169. checkGrtrThnDateForInvoiceDate = False
  2170. END if
  2171.  
  2172. else
  2173. checkGrtrThnDateForInvoiceDate = True
  2174. End If
  2175. End If
  2176. End If
  2177. End Function
  2178.  
  2179.  
  2180. Public Function specificDateBeforeYears(ByVal value As String,ByVal yearGap as Integer) As String
  2181. Dim currDt as Object
  2182. Dim newDt as String
  2183. Dim intYear
  2184. 'Dim a
  2185. 'a = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
  2186.  
  2187. If value<>"" Then
  2188. currDt= Split(value,"/")
  2189. 'Day & Month
  2190. newDt=currDt(0)& "/" & currDt(1)
  2191. 'Year
  2192. intYear=INT(currDt(2))
  2193. intYear=intYear-yearGap
  2194. newDt=newDt & "/" & Cstr(intYear)
  2195. 'msgbox newDt
  2196. specificDateBeforeYears=newDt
  2197. End If
  2198.  
  2199. End Function
  2200.  
  2201. Public Function checkDateOfDeposit(ByVal value As String) As Boolean
  2202. Dim startDate as String
  2203. Dim endDate as String
  2204.  
  2205. checkDateOfDeposit = True
  2206.  
  2207. unprotectsheet("A_Basic_Info")
  2208. '->Arjun
  2209. if(ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdFrom").string<>"" and ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdTo").string<>"")then
  2210. startDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdFrom").string
  2211. endDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdTo").string
  2212. If value<>"" then
  2213. If ValidateDate(value) then
  2214. If checkGrtrThnDate(value,endDate)=False then
  2215. checkDateOfDeposit = False
  2216. End If
  2217. Else
  2218. checkDateOfDeposit = False
  2219. End If
  2220. End If
  2221. Else
  2222. checkDateOfDeposit = True
  2223. End If
  2224. protectsheet("A_Basic_Info")
  2225. End Function
  2226.  
  2227. Public Function TestAlphabetNumNoSpl(lstr_check As String) As Boolean
  2228. 'allowed characters A to Z, a to z And Blank
  2229. Dim i As Integer
  2230. Dim ia As Integer
  2231. Dim ina As Integer
  2232. Dim stlen As Integer
  2233.  
  2234. stlen = Len(lstr_check)
  2235. ia = 0
  2236. ina = 0
  2237. For i = 1 To stlen
  2238. Select Case (Mid(lstr_check, i, 1))
  2239. Case "A" To "Z" 'A to Z
  2240. ia = ia + 1
  2241. Case "a" To "z" 'a to z
  2242. ia = ia + 1
  2243. Case "0" To "9" '0 to 9
  2244. ia = ia + 1
  2245. Case Else
  2246. ina = ina + 1
  2247. End Select
  2248. Next i
  2249. If ina = 0 Then
  2250. TestAlphabetNumNoSpl = True
  2251. Else
  2252. TestAlphabetNumNoSpl = False
  2253. End If
  2254.  
  2255. End Function
  2256.  
  2257. sub resetOnUsageToggleExemption(rangeName as String,sheetName as String)
  2258.  
  2259. Dim startRowNum as Long , endRowNum as Long, startColumnNum as Long , endcolumnNum as Long
  2260. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  2261. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  2262. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  2263. sheet=oRange.getReferredCells().getRangeAddress().sheet
  2264.  
  2265. Unprotectsheet(sheetName)
  2266. Dim usage as String
  2267. Dim msgStr As String
  2268. Dim currRange as Object
  2269. Dim row As Long
  2270. Dim tempValue as String
  2271.  
  2272. sheet=ThisComponent.sheets.getByName(sheetName)
  2273.  
  2274. for i = startRowNum to endRowNum
  2275. row=i
  2276. selectedPurchaserCode=sheet.getCellrangeByName("A"&(row+1)&":A"&(row+1)).string
  2277. '************
  2278. If selectedPurchaserCode <> "" Then
  2279.  
  2280. 'disable Exemption Certificate Number in case "Exempt"
  2281. If selectedPurchaserCode = "Local" Then
  2282. sheet.getCellrangeByName("K"&(row+1)&":K"&(row+1)).string="Import"
  2283. sheet.getCellrangeByName("I"&(row+1)&":I"&(row+1)).string=""
  2284. Protect_Range(sheetName,"I" & (row+1) & ":I" & (row+1))
  2285. ElseIf selectedPurchaserCode = "Exemption" Then
  2286. sheet.getCellrangeByName("K"&(row+1)&":K"&(row+1)).string="Exempt"
  2287. tempValue=sheet.getCellrangeByName("I"&(row+1)&":I"&(row+1)).string
  2288. Unprotect_Range(sheetName,"I" & (row+1) & ":I" & (row+1))
  2289. sheet.getCellrangeByName("I"&(row+1)&":I"&(row+1)).string=tempValue
  2290. End If
  2291. Else
  2292. sheet.getCellrangeByName("K"&(row+1)&":K"&(row+1)).string=""
  2293. sheet.getCellrangeByName("I"&(row+1)&":I"&(row+1)).string=""
  2294. Protect_Range(sheetName,"I" & (row+1) & ":I" & (row+1))
  2295. End If
  2296. '************
  2297. Next
  2298. protectsheet(sheetName)
  2299. end Sub
  2300.  
  2301. Public Function TestAlphabetNumSpaceDot(lstr_check As String) As Boolean
  2302. 'allowed characters A to Z, a to z And Blank
  2303. Dim i As Integer
  2304. Dim ia As Integer
  2305. Dim ina As Integer
  2306. Dim stlen As Integer
  2307.  
  2308. stlen = Len(lstr_check)
  2309. ia = 0
  2310. ina = 0
  2311. For i = 1 To stlen
  2312. Select Case (Mid(lstr_check, i, 1))
  2313. Case "A" To "Z" 'A to Z
  2314. ia = ia + 1
  2315. Case "a" To "z" 'a to z
  2316. ia = ia + 1
  2317. Case "0" To "9" '0 to 9
  2318. ia = ia + 1
  2319. Case " ", "." ', ".", "-", "/",":" '";", "-", "#", "+", "*", "/", "=", "@", "$", "&", "%" , "(", ")" ,">", "<" ' Blank
  2320. ia = ia + 1
  2321. Case Else
  2322. ina = ina + 1
  2323. End Select
  2324. Next i
  2325. If ina = 0 Then
  2326. TestAlphabetNumSpaceDot = True
  2327. Else
  2328. TestAlphabetNumSpaceDot = False
  2329. End If
  2330.  
  2331. End Function
  2332.  
  2333. Function PutZipContent( sZipURL As String, sContentName As String, sInputURL As String, Optional bCompress As Boolean )
  2334. Dim oZipPkg As Object, oSFA As Object
  2335. Dim oContentStream As Object, oZipFolder As Object
  2336. oZipPkg = CreateUnoService("com.sun.star.packages.Package")
  2337. oZipPkg.initialize(array(sZipURL))
  2338. oZipFolder = oZipPkg.getByHierarchicalName("/")
  2339. oContentStream = oZipPkg.createInstanceWithArguments(array(false))
  2340. oSFA = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
  2341. If oSFA.exists(sInputURL) Then
  2342. oContentStream.setInputStream(oSFA.openFileRead(sInputURL))
  2343.  
  2344. If IsMissing(bCompress) Then bCompress = True
  2345. oContentStream.setPropertyValue("Compressed", bCompress)
  2346. If NOT oZipFolder.hasByName(sContentName) Then
  2347. oZipFolder.insertByName(sContentName,oContentStream)
  2348. Else
  2349. oZipFolder.replaceByName(sContentName,oContentStream)
  2350. End If
  2351. oZipPkg.commitChanges()
  2352. End If
  2353. End Function
  2354.  
  2355. Sub checkRelevantInvNoDate(rangeName as String)as Boolean
  2356.  
  2357. checkRelevantInvNoDate=True
  2358.  
  2359. Dim startRowNum as Long , endRowNum as Long, startColumnNum as Long , endcolumnNum as Long
  2360. Dim startRowNumInternal as Long , endRowNumInternal as Long, startColumnNumInternal as Long , endcolumnNumInternal as Long
  2361. Dim sheetName as String
  2362. Dim revInvNumCol as String
  2363. Dim revInvDateCol as String
  2364. Dim revInvNum as String
  2365. Dim revInvDate as String
  2366. Dim invNum as String
  2367. Dim invDate as String
  2368. Dim mainPinCol as String
  2369. Dim mainPin as String
  2370. Dim internalPin as String
  2371. Dim taxableValue as Double
  2372. Dim taxableValueCol as String
  2373. Dim exists as Boolean
  2374.  
  2375. exists=False
  2376.  
  2377. If rangeName="Sch1.GeneralRateSalesDtlsList" Then
  2378. sheetName="B_General_Rated_Sales_Dtls"
  2379. revInvNumCol="I"
  2380. revInvDateCol="J"
  2381. mainPinCol="A"
  2382. taxableValueCol="G"
  2383. ElseIf rangeName="Sch2.OtherRateSalesDtlsList" Then
  2384. sheetName="C_Other_Rated_Sales_Dtls"
  2385. revInvNumCol="I"
  2386. revInvDateCol="J"
  2387. mainPinCol="A"
  2388. taxableValueCol="G"
  2389. ElseIf rangeName="Sch5.InputTaxPurchDtlsGRList" Then
  2390. sheetName="F_General_Rated_Purchases_Dtls"
  2391. revInvNumCol="J"
  2392. revInvDateCol="K"
  2393. mainPinCol="B"
  2394. taxableValueCol="H"
  2395. ElseIf rangeName="Sch6.InputTaxPurchDtlsORList" Then
  2396. sheetName="G_Other_Rated_Purchases_Dtls"
  2397. revInvNumCol="J"
  2398. revInvDateCol="K"
  2399. mainPinCol="B"
  2400. taxableValueCol="H"
  2401. Else
  2402. sheetName=""
  2403. revInvNumCol=""
  2404. revInvDateCol=""
  2405. mainPinCol=""
  2406. taxableValueCol=""
  2407. End If
  2408.  
  2409. If sheetName<>"" and revInvNumCol<>"" and revInvDateCol<>"" and mainPinCol<>"" and taxableValueCol<>"" then
  2410.  
  2411. oRange = ThisComponent.NamedRanges.getByName(rangeName)
  2412. startRowNum = oRange.getReferredCells().getRangeAddress().StartRow
  2413. endRowNum = oRange.getReferredCells().getRangeAddress().EndRow
  2414. startRowNumInternal = oRange.getReferredCells().getRangeAddress().StartRow
  2415. endRowNumInternal = oRange.getReferredCells().getRangeAddress().EndRow
  2416. sheet=ThisComponent.sheets.getByName(sheetName)
  2417.  
  2418. for i=startRowNum to endRowNum
  2419.  
  2420. revInvNum=sheet.getCellrangeByName(revInvNumCol &(i+1)&":"& revInvNumCol &(i+1)).string
  2421. revInvDate=sheet.getCellrangeByName(revInvDateCol &(i+1)&":"& revInvDateCol &(i+1)).string
  2422. mainPin=sheet.getCellrangeByName(mainPinCol &(i+1)&":"& mainPinCol &(i+1)).string
  2423.  
  2424. exists=False
  2425.  
  2426. If revInvNum<>"" and revInvDate<>"" then
  2427. If (ValidateDate(revInvDate) = True) Then
  2428. If TestDateBtwnRtnPeriod(revInvDate)=True then
  2429.  
  2430. for j=startRowNumInternal to endRowNumInternal
  2431.  
  2432. invNum=sheet.getCellrangeByName("E"&(j+1)&":E"&(j+1)).string
  2433. invDate=sheet.getCellrangeByName("D"&(j+1)&":D"&(j+1)).string
  2434. internalPin=sheet.getCellrangeByName(mainPinCol &(j+1)&":"& mainPinCol &(j+1)).string
  2435. taxableValue=sheet.getCellrangeByName(taxableValueCol &(j+1)&":"& taxableValueCol &(j+1)).value
  2436.  
  2437. if revInvNum=invNum and revInvDate=invDate and mainPin=internalPin and taxableValue>=0 then
  2438. exists=True
  2439. End If
  2440. Next j
  2441.  
  2442. If exists=False then
  2443. checkRelevantInvNoDate=False
  2444. Exit For
  2445. End If
  2446. End If
  2447. End If
  2448. End If
  2449. Next i
  2450. End If
  2451. End Sub
  2452.  
  2453. Public Function checkDateOfDepositSelfAssess(ByVal value As String) As Boolean
  2454. Dim startDate as String
  2455.  
  2456. checkDateOfDepositSelfAssess = True
  2457.  
  2458. unprotectsheet("A_Basic_Info")
  2459. '->Arjun
  2460. if(ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdFrom").string<>"" and ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdTo").string<>"")then
  2461. startDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdFrom").string
  2462. endDate = ThisComponent.Sheets.getByName("A_Basic_Info").getCellrangeByName("SecA.RtnPdTo").string
  2463. If value<>"" then
  2464. If ValidateDate(value) then
  2465. If checkFutureDate(value) = False Then
  2466. checkDateOfDepositSelfAssess = False
  2467. ElseIf checkGrtrThnNotEqlDate(endDate,value)=False then
  2468. checkDateOfDepositSelfAssess = False
  2469. End If
  2470. Else
  2471. checkDateOfDepositSelfAssess = False
  2472. End If
  2473. End If
  2474. Else
  2475. checkDateOfDepositSelfAssess = True
  2476. End If
  2477. protectsheet("A_Basic_Info")
  2478. End Function
  2479.  
  2480. Sub prnEntriesBothSch() as Boolean
  2481. Dim taxDue as Double
  2482. Dim prnAdvPmt as Double
  2483. Dim prnTotal as Double
  2484.  
  2485. prnEntriesBothSch=True
  2486.  
  2487. taxDue=ThisComponent.Sheets.getByName("O_VAT_Due").getCellrangeByName("SecD.TotalVatPyble").value
  2488. prnAdvPmt=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATPaidDtlsTO").value
  2489. prnTotal=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATAdvcSelfAssPaidDtlsTO").value
  2490. prnSelfAssess=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATSelfAssPaidDtlsTO").value
  2491.  
  2492. If (Cdbl(format(taxDue,"#,##0.00")))<=0 and (Cdbl(format(prnTotal,"#,##0.00")))>0 then
  2493. prnEntriesBothSch=False
  2494. End If
  2495. End Sub
  2496.  
  2497. Sub prnEntriesSelfAssess() as Boolean
  2498. Dim taxDue as Double
  2499. Dim prnAdvPmt as Double
  2500. Dim prnTotal as Double
  2501. Dim prnSelfAssess as Double
  2502.  
  2503. prnEntriesSelfAssess=True
  2504.  
  2505. taxDue=ThisComponent.Sheets.getByName("O_VAT_Due").getCellrangeByName("SecD.TotalVatPyble").value
  2506. prnAdvPmt=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATPaidDtlsTO").value
  2507. prnTotal=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATAdvcSelfAssPaidDtlsTO").value
  2508. prnSelfAssess=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATSelfAssPaidDtlsTO").value
  2509.  
  2510. If (Cdbl(format(prnSelfAssess,"#,##0.00")))>0 and (Cdbl(format(prnAdvPmt,"#,##0.00")))>0 then
  2511. If (Cdbl(format(taxDue,"#,##0.00")))<=(Cdbl(format(prnSelfAssess,"#,##0.00"))) and (Cdbl(format(prnAdvPmt,"#,##0.00")))>0 then
  2512. prnEntriesSelfAssess=False
  2513. ElseIf (Cdbl(format(taxDue,"#,##0.00")))<(Cdbl(format(prnSelfAssess,"#,##0.00")))+(Cdbl(format(prnAdvPmt,"#,##0.00"))) and (Cdbl(format(prnAdvPmt,"#,##0.00")))>0 then
  2514. prnEntriesSelfAssess=False
  2515. End If
  2516. End If
  2517. End Sub
  2518.  
  2519. Sub advPaymentGreaterThanLiability() as Boolean
  2520. Dim taxDue as Double
  2521. Dim prnAdvPmt as Double
  2522. Dim prnTotal as Double
  2523. Dim prnSelfAssess as Double
  2524.  
  2525. advPaymentGreaterThanLiability=True
  2526.  
  2527. taxDue=ThisComponent.Sheets.getByName("O_VAT_Due").getCellrangeByName("SecD.TotalVatPyble").value
  2528. prnAdvPmt=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATPaidDtlsTO").value
  2529. prnTotal=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATAdvcSelfAssPaidDtlsTO").value
  2530. prnSelfAssess=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATSelfAssPaidDtlsTO").value
  2531.  
  2532. If (Cdbl(format(taxDue,"#,##0.00")))>0 then
  2533. If (Cdbl(format(prnSelfAssess,"#,##0.00")))<=0 then
  2534. If (Cdbl(format(taxDue,"#,##0.00")))<(Cdbl(format(prnAdvPmt,"#,##0.00"))) then
  2535. advPaymentGreaterThanLiability=False
  2536. End If
  2537. End If
  2538. End If
  2539. End Sub
  2540.  
  2541. Sub selfPaymentGreaterThanLiability() as Boolean
  2542. Dim taxDue as Double
  2543. Dim prnAdvPmt as Double
  2544. Dim prnTotal as Double
  2545. Dim prnSelfAssess as Double
  2546.  
  2547. selfPaymentGreaterThanLiability=True
  2548.  
  2549. taxDue=ThisComponent.Sheets.getByName("O_VAT_Due").getCellrangeByName("SecD.TotalVatPyble").value
  2550. prnAdvPmt=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATPaidDtlsTO").value
  2551. prnTotal=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATAdvcSelfAssPaidDtlsTO").value
  2552. prnSelfAssess=ThisComponent.Sheets.getByName("K_VAT_Payment_Credits").getCellrangeByName("Sch10.VATSelfAssPaidDtlsTO").value
  2553.  
  2554. If (Cdbl(format(taxDue,"#,##0.00")))>0 then
  2555. If (Cdbl(format(prnAdvPmt,"#,##0.00")))<=0 then
  2556. If (Cdbl(format(taxDue,"#,##0.00")))<(Cdbl(format(prnSelfAssess,"#,##0.00"))) then
  2557. selfPaymentGreaterThanLiability=False
  2558. End If
  2559. End If
  2560. End If
  2561. End Sub
  2562.  
  2563. Public Function checkGrtrThnNotEqlDate(ByVal dateFrom As String,ByVal dateTo as String) As Boolean
  2564. Dim mm As Integer
  2565. Dim yr As Integer
  2566. Dim dd as Integer
  2567. Dim strDate As Object
  2568. Dim currDate as Object
  2569. 'mm = Format(CDate(Trim(value)), "MM")
  2570. 'yr = Format(CDate(Trim(value)), "yyyy")
  2571. 'dd = Format(CDate(Trim(value)), "dd")
  2572. If(Len(Trim(dateFrom))=0) then
  2573. checkGrtrThnNotEqlDate=True
  2574. Exit function
  2575. End If
  2576. If(Len(Trim(dateTo))=0) then
  2577. checkGrtrThnNotEqlDate=True
  2578. Exit function
  2579. End If
  2580. if ValidateDate(dateFrom) then
  2581. strDate= Split(dateFrom, "/")
  2582. dd= INT(strDate(0))
  2583. mm= INT(strDate(1))
  2584. yr= INT(strDate(2))
  2585.  
  2586. currDate= Split(dateTo,"/")
  2587. 'If yr = Format(Now(), "yyyy") Then
  2588. If yr= INT(currDate(2)) then
  2589. Dim mon as Integer
  2590. Dim dayD as Integer
  2591. mon= INT(currDate(1))
  2592. dayD = INT(currDate(0))
  2593. If mm < mon Then
  2594. checkGrtrThnNotEqlDate = True
  2595. ElseIf mm=mon then
  2596. If dd<dayD then
  2597. checkGrtrThnNotEqlDate = True
  2598. Else
  2599. checkGrtrThnNotEqlDate = False
  2600. End If
  2601. Else
  2602. checkGrtrThnNotEqlDate = False
  2603. End If
  2604.  
  2605. ElseIf yr < currDate(2) And mm <= 12 Then
  2606. checkGrtrThnNotEqlDate = True
  2607. Else
  2608. checkGrtrThnNotEqlDate = False
  2609. End If
  2610. End If
  2611. End Function
  2612.  
  2613. Public Function TestPRN(lstr_check As String) As Boolean
  2614. 'allowed characters A to Z, a to z And Blank
  2615. Dim i As Integer
  2616. Dim ia As Integer
  2617. Dim ina As Integer
  2618. Dim stlen As Integer
  2619. Dim count As Integer
  2620.  
  2621. stlen = Len(lstr_check)
  2622. ia = 0
  2623. ina = 0
  2624. count = 0
  2625. For i = 1 To stlen
  2626. Select Case (Mid(lstr_check, i, 1))
  2627. Case "0" To "9" '0 to 9
  2628. ia = ia + 1
  2629. Case "-" ' Hypen
  2630. count=count+1
  2631. ia = ia + 1
  2632. Case Else
  2633. ina = ina + 1
  2634. End Select
  2635. Next i
  2636. If ina = 0 Then
  2637. TestPRN = True
  2638. Else
  2639. TestPRN = False
  2640. End If
  2641.  
  2642. 'Single Hypen
  2643. 'If count>1 Then
  2644. ' TestPRN = False
  2645. 'End If
  2646. 'For checking whether all characters in PRN are 0.
  2647. ia=0
  2648. For i = 1 To stlen
  2649. Select Case (Mid(lstr_check, i, 1))
  2650. Case "0" '0
  2651. ia = ia + 1
  2652. Case Else
  2653. ina = ina + 1
  2654. End Select
  2655. Next i
  2656. If stlen <> 0 then
  2657. If ia = stlen then
  2658. TestPRN = False
  2659. End If
  2660. End If
  2661. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement