taxesgsheet.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. '''
  2. Created on 21 Jan 2023 @author: vnc-console
  3. '''
  4. import gspread
  5. from gspread.client import BackoffClient
  6. from winmentor import WinMentor
  7. from beautiful_date import * # @UnusedWildImport
  8. g_sheet = '17ZympS8FjiCqsGbkKz1CPN_7NKdV_idXmYs61Mdxnsc'
  9. # g_sheet = '1G4l7Klb34Nu1h7lBNvA-q4FB5WlQmtoxS3xLFM5XEVw' # HUN
  10. gc = gspread.service_account(filename='../Pygsheet-4a83fcaf2282.json', client_factory=BackoffClient)
  11. # print(gc.list_spreadsheet_files())
  12. gsh = gc.open_by_key(g_sheet)
  13. sh1 = gsh.worksheet('ROU')
  14. # sh1 = gsh.worksheet('HUN') # HUN
  15. exclude = ['ABRON',
  16. 'ASCOMVEL',
  17. 'ASDONAT',
  18. 'ASPRO',
  19. 'ASIONAG',
  20. 'ASIVP',
  21. 'ALPHA',
  22. 'ASOBS',
  23. 'BANXI',
  24. 'BREIS',
  25. 'COMELECT',
  26. 'ECOPROT',
  27. 'EVEREST',
  28. 'FLAUR',
  29. 'GBZPFA',
  30. 'JOART',
  31. 'LUXWIN',
  32. 'MATILAND',
  33. 'MOCAN',
  34. 'SCOM',
  35. 'TERHOV'
  36. 'UNION',
  37. 'RECYC']
  38. head = ['Denumire', 'CF', 'J', 'Adresa', 'Oras', 'Judet', 'Prescurtat', 'Admin', 'AdminP', 'RCNP', 'Obs']
  39. mentor = WinMentor()
  40. office = list(mentor.filtered_firmlist(headers=head, ban=exclude)) # generator
  41. date = (D.today() - 1 * months).strftime('%m_%Y')
  42. mentor_date = (D.today() - 1 * months).strftime('%Y_%m')
  43. print(f'period should be "{date}"', end='\n' * 2)
  44. col_NAME = sh1.col_values(2)[2:]
  45. col_TAX = sh1.col_values(19)[2:]
  46. col_PER = sh1.col_values(3)[2:]
  47. col_CHKM = sh1.col_values(23)[2:]
  48. cond_range = zip(col_NAME, col_TAX, col_PER, col_CHKM)
  49. def main(month_=None):
  50. for name, tax, period, mail in cond_range:
  51. for company in office:
  52. condition = name == company[0] and tax == '.00' and period == date and mail == '1'
  53. if condition:
  54. if month_:
  55. if month_ >= mentor.get_last_month(company[6]):
  56. current_month = mentor.get_last_month(company[6])
  57. else:
  58. current_month = month_
  59. else:
  60. current_month = mentor.get_last_month(company[6])
  61. if current_month == mentor_date:
  62. account = mentor.verif_cont(company[6] + '/' + current_month + './NCONT.DB')
  63. print(f'...processing-->>{name}')
  64. cell = sh1.find(f'{name}_{date}', in_column=1)
  65. # Update cells
  66. sh1.update_cell(cell.row, 7, mentor.vat_payable(account))
  67. print('writing VAT')
  68. sh1.update_cell(cell.row, 9, mentor.vat_final(account))
  69. print('writing VAT total')
  70. contrs = [mentor.CAS_payable(account),
  71. mentor.CASS_payable(account),
  72. mentor.sal_tax_payable(account)]
  73. contr = sum(contrs)
  74. sh1.update_cell(cell.row, 11, contr)
  75. print('writing contributions')
  76. sh1.update_cell(cell.row, 12, mentor.cam_payable(account))
  77. print('writing CAM')
  78. sh1.update_cell(cell.row, 15, mentor.tax_payable(account))
  79. print('writing income tax')
  80. sh1.update_cell(cell.row, 18, mentor.div_tax_payable(account))
  81. print('writing dividend tax')
  82. sh1.update_cell(cell.row, 20, mentor.an_inc(account, 0, 6, 8))
  83. print('writing turnover')
  84. sh1.update_cell(cell.row, 21, mentor.result(account, 0, 6, 8))
  85. print('writing result', end='\n' * 2)
  86. if __name__ == '__main__':
  87. main(month_='2023_01')