taxesgsheet.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. '''
  2. Created on 21 Jan 2023 @author: vnc-console
  3. '''
  4. import gspread
  5. from gspread import BackOffHTTPClient
  6. from winmentor import WinMentor
  7. import beautiful_date as bd # type: ignore
  8. g_sheet = '17ZympS8FjiCqsGbkKz1CPN_7NKdV_idXmYs61Mdxnsc'
  9. # g_sheet = '1G4l7Klb34Nu1h7lBNvA-q4FB5WlQmtoxS3xLFM5XEVw' # HUN
  10. gc = gspread.service_account(filename='../Pygsheet-4a83fcaf2282.json', http_client=BackOffHTTPClient)
  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 = (bd.D.today() - 1 * bd.months).strftime('%m_%Y')
  42. mentor_date = (bd.D.today() - 1 * bd.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. other_tax = mentor.div_tax_payable(account) + mentor.other_tax_payable(account)
  81. sh1.update_cell(cell.row, 18, other_tax)
  82. print('writing dividend tax')
  83. sh1.update_cell(cell.row, 20, mentor.an_inc(account, 0, 6, 8))
  84. print('writing turnover')
  85. sh1.update_cell(cell.row, 21, mentor.result(account, 0, 6, 8))
  86. print('writing result', end='\n' * 2)
  87. if __name__ == '__main__':
  88. main(month_=mentor_date)