dbread.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. '''
  2. Created on Jun 21, 2018 @author: levente.marton
  3. '''
  4. import os
  5. import re
  6. import datetime
  7. from dataclasses import dataclass
  8. import shutil
  9. import pandas as pd
  10. from pypxlib import Table
  11. from .db_to_df import Dbtodf
  12. @dataclass
  13. class Company:
  14. name: str
  15. vat_code: str
  16. reg_number: str
  17. address: str
  18. location: str
  19. county: str
  20. shortname: str
  21. obs: str
  22. adm: str
  23. admp: str
  24. admcnp: str
  25. mail: str = None
  26. price: int = None
  27. @dataclass
  28. class Account:
  29. clasa: str
  30. simbol: str
  31. denumire: str
  32. soldid: str = None
  33. soldic: str = None
  34. precedentd: str = None
  35. precedentc: str = None
  36. curentd: str = None
  37. curentc: str = None
  38. def soldf(self, type_):
  39. if type_ == 'd':
  40. return round((self.soldid + self.precedentd + self.curentd) -
  41. (self.soldic + self.precedentc + self.curentc))
  42. elif type_ == 'c':
  43. return round((self.soldic + self.precedentc + self.curentc) -
  44. (self.soldid + self.precedentd + self.curentd))
  45. class WinMentor(object):
  46. '''
  47. Class to read winmentor database
  48. '''
  49. def __init__(self, winment_path=os.getenv('WINMENT', 'c:/winment/data/').replace('\\', '/')):
  50. '''
  51. Constructor
  52. '''
  53. self.winment_path = winment_path
  54. @property
  55. def get_winment_path(self):
  56. return self.winment_path
  57. @get_winment_path.setter
  58. def set_winment_path(self, value):
  59. # self.value = value
  60. self.winment_path = value
  61. return self.winment_path
  62. def update_copy(self, db_file) -> str:
  63. '''returns the updated version of a .db file
  64. :param db_file is a .db from winmentor'''
  65. # self._to_file = db_file
  66. _, file_name = os.path.split(db_file)
  67. dir_list = db_file.split('/')
  68. # !!NOTE: if path is ?/winment/data/ then this must be 3 & 5
  69. # if is ?/winment/winment/data/ then 4 & 6
  70. dir_to_file = dir_list[4]
  71. if len(dir_list) != 6:
  72. os.makedirs(os.path.join('cash', dir_to_file), exist_ok=True)
  73. cashed_copy_mtime = -1
  74. if os.path.isfile(os.path.join('./cash/', dir_to_file, file_name)):
  75. cashed_copy_mtime = os.stat(os.path.join('./cash/', dir_to_file, file_name)).st_mtime
  76. if os.stat(db_file).st_mtime != cashed_copy_mtime:
  77. shutil.copy2(db_file, os.path.join('./cash', dir_to_file))
  78. return(os.path.join('./cash/', dir_to_file, file_name))
  79. else:
  80. os.makedirs('cash', exist_ok=True)
  81. cashed_copy_mtime = -1
  82. if os.path.isfile('./cash/' + file_name):
  83. cashed_copy_mtime = os.stat('./cash/' + file_name).st_mtime
  84. if os.stat(db_file).st_mtime != cashed_copy_mtime:
  85. shutil.copy2(db_file, './cash')
  86. return('./cash/' + file_name)
  87. def make_list(self, db_file, headers) -> list:
  88. '''returns a list of lists with elements from a given db file
  89. :param db_file is .db file from winmentor
  90. :param headers are the fields of the specified db file'''
  91. file_name = self.update_copy(db_file)
  92. with Table(file_name) as table:
  93. m_list = []
  94. for row in table:
  95. item = []
  96. for header in headers:
  97. element = row[header]
  98. if type(element) == datetime.date:
  99. if element < datetime.date(1999, 1, 1):
  100. element = ''
  101. item.append(element)
  102. m_list.append(item)
  103. return m_list
  104. def make_sal_list(self, file_1, file_2) -> list:
  105. '''returns list with all_ employees in current month
  106. :param file_1 is npers.db from shortname
  107. :param file_2 is likisal.db shortname/current_month'''
  108. file_name1 = self.update_copy(self.winment_path + file_1)
  109. file_name2 = self.update_copy(self.winment_path + file_2)
  110. with Table(file_name1) as perss, Table(file_name2) as sals:
  111. empl_all = []
  112. # for field in perss.fields:
  113. for sal in sals:
  114. for pers in perss:
  115. # print(pers)
  116. if pers.Cod == sal.Cod:
  117. empl = []
  118. empl.append(pers.Cod)
  119. empl.append(f'{pers.Nume} {pers.Prenume}')
  120. empl.append(pers.DataAngF.strftime('%d-%m-%Y'))
  121. empl.append(sal.VenitBrut)
  122. empl.append(sal.SalRealizat)
  123. empl.append(sal.CO)
  124. empl.append(round(sal.SalOra, 2))
  125. empl.append(sal.ContribAngajat)
  126. empl.append(round(sal.ContribAngajator, 2))
  127. empl.append(sal.VenitNet)
  128. empl.append(sal.Impozit)
  129. empl.append(sal.SalarNet)
  130. empl.append(sal.OreLucrate)
  131. empl.append(sal.ZileLuk)
  132. empl.append(sal.ZileCO)
  133. empl_all.append(empl)
  134. return empl_all
  135. def gen_firms(self, db_file, headers) -> list:
  136. '''generates company list from firme.db file
  137. :param db_file is firme.db from winment/data folder'''
  138. file_db = self.update_copy(self.winment_path + db_file)
  139. with Table(file_db) as table:
  140. for row in table:
  141. yield [row[header] for header in headers]
  142. def firmlist(self, headers, db_file='/firme.db', ban=None) -> list:
  143. '''returns company list from firme.db file
  144. :param db_file is firme.db from winment/data folder
  145. :param list headers is the fields from firme.db file
  146. :param list|str ban companies excluded from list'''
  147. comp_list = []
  148. for a_company in self.gen_firms(db_file, headers):
  149. company = Company(
  150. name=a_company[0],
  151. vat_code=a_company[1],
  152. reg_number=a_company[2],
  153. address=a_company[3],
  154. location=a_company[4],
  155. county=a_company[5],
  156. shortname=a_company[6],
  157. adm=a_company[7],
  158. admp=a_company[8],
  159. admcnp=a_company[9],
  160. obs=a_company[10])
  161. comp_list.append(company)
  162. if ban:
  163. if type(ban) is list:
  164. for r in comp_list:
  165. for company_shortname in ban:
  166. if company_shortname == r.shortname:
  167. comp_list.remove(r)
  168. else:
  169. for r in comp_list:
  170. if r == ban:
  171. comp_list.remove(r)
  172. return comp_list
  173. def filtered_firmlist(self, headers, db_file='/firme.db', ban=None) -> list:
  174. '''generates company list from firme.db file
  175. :param db_file is firme.db from winment/data folder
  176. :param list headers is the fields from firme.db file
  177. :param list|str ban companies excluded from list'''
  178. headers = headers or ['Denumire', 'CF', 'J', 'Adresa', 'Oras', 'Judet', 'Prescurtat', 'Admin', 'AdminP', 'RCNP', 'Obs']
  179. if ban:
  180. if type(ban) is list:
  181. for a_company in self.gen_firms(db_file, headers):
  182. company = Company(
  183. name=a_company[0],
  184. vat_code=a_company[1],
  185. reg_number=a_company[2],
  186. address=a_company[3],
  187. location=a_company[4],
  188. county=a_company[5],
  189. shortname=a_company[6],
  190. adm=a_company[7],
  191. admp=a_company[8],
  192. admcnp=a_company[9],
  193. obs=a_company[10])
  194. if a_company[6] not in ban:
  195. yield [company.name, company.vat_code, company.reg_number,
  196. company.address, company.location, company.county,
  197. company.shortname, company.adm, company.admp,
  198. company.admcnp, company.obs]
  199. else:
  200. for a_company in self.gen_firms(db_file, headers):
  201. company = Company(
  202. name=a_company[0],
  203. vat_code=a_company[1],
  204. reg_number=a_company[2],
  205. address=a_company[3],
  206. location=a_company[4],
  207. county=a_company[5],
  208. shortname=a_company[6],
  209. adm=a_company[7],
  210. admp=a_company[8],
  211. admcnp=a_company[9],
  212. obs=a_company[10])
  213. yield [company.name, company.vat_code, company.reg_number,
  214. company.address, company.location, company.county,
  215. company.shortname, company.adm, company.admp,
  216. company.admcnp, company.obs]
  217. def get_last_month(self, short_name) -> str:
  218. '''returns last month of a company in format YYYY_MM
  219. :param str short_name is the company shortname'''
  220. short_name = self.winment_path + short_name
  221. month_folders = [f for f in os.listdir(short_name) if re.match(r'[0-9_]+$', f)]
  222. month_folders.reverse()
  223. return month_folders[0]
  224. def get_bank_accounts(self, short_name, db_file='/nbanca.db'):
  225. #.......................................................................
  226. # TO DO: put an all_ parameter to yield all_ accounts or
  227. # just one,
  228. # make a named tuple with bank accounts.
  229. #.......................................................................
  230. headers = ['Codbanca', 'Denumire', 'NrCont']
  231. headers2 = ['COD', 'DENUMIRE']
  232. short_name = self.winment_path + short_name
  233. nbanks = self.update_copy(short_name + '/nbanci.db')
  234. file_db = self.update_copy(short_name + db_file)
  235. bank_codes = {}
  236. with Table(file_db) as table, Table(nbanks) as nbanks:
  237. # tables = zip(table, nbanks)
  238. for bank in nbanks:
  239. data = [bank[header] for header in headers2]
  240. bdict = {data[i]: data[i + 1] for i in range(0, len(data), 2)}
  241. bank_codes.update(bdict)
  242. for row in table:
  243. if row.NrCont:
  244. bank_account = [row[header] for header in headers]
  245. bank_account.append(bank_codes[bank_account[0]])
  246. if bank_account[2].startswith(' '):
  247. yield bank_account
  248. def save_oblig(self, short_name):
  249. #.......................................................................
  250. # TO DO
  251. # add moneda and curs
  252. #.......................................................................
  253. df_dicts = self.get_oblig(short_name)
  254. # create dfs from dicts
  255. df_parts = pd.DataFrame(df_dicts[1])
  256. df_conts = pd.DataFrame(df_dicts[2])
  257. df_oblig = pd.DataFrame(df_dicts[0])
  258. df_obligf = pd.DataFrame(df_dicts[3])
  259. df_mons = pd.DataFrame(df_dicts[4])
  260. df_obligf = df_obligf.rename(columns={'TipTranz': 'TipDoc'})
  261. # join oblig<>part<>cont with left join
  262. df_oblig = pd.merge(df_oblig, df_parts, how='left', left_on='Part', right_on='Cod')
  263. df_oblig.drop(columns=['Part', 'Cod'], inplace=True)
  264. df_oblig = pd.merge(df_oblig, df_conts, how='left', left_on='Cont', right_on='Cod')
  265. df_oblig.drop(columns=['Cont', 'Cod'], inplace=True)
  266. df_oblig = pd.merge(df_oblig, df_mons, how='left', left_on='Moneda', right_on='Cod')
  267. df_oblig.drop(columns=['Moneda', 'Cod'], inplace=True)
  268. df_oblig.drop(columns=['TipDoc'], inplace=True)
  269. # join obligf<>party<>cont
  270. try:
  271. df_obligf = pd.merge(df_obligf, df_parts, how='left', left_on='Part', right_on='Cod')
  272. df_obligf.drop(columns=['Part', 'Cod'], inplace=True)
  273. df_obligf = pd.merge(df_obligf, df_conts, how='left', left_on='Cont', right_on='Cod')
  274. df_obligf.drop(columns=['Cont', 'Cod'], inplace=True)
  275. df_obligf = pd.merge(df_obligf, df_mons, how='left', left_on='Moneda', right_on='Cod')
  276. df_obligf.drop(columns=['Moneda', 'Cod'], inplace=True)
  277. df_obligf.drop(columns=['TipDoc'], inplace=True)
  278. df_obligall = pd.concat([df_oblig, df_obligf])
  279. except KeyError as exc_:
  280. df_obligall = df_oblig
  281. options = ['581', '455', '455.01', '167', '666']
  282. suppliers = ['401', '404', '409', '409.01', '409.02', '409.04']
  283. clients = ['411', '411.01', '419', '472']
  284. df_obligall['TipPartener'] = df_obligall.apply(lambda row: self.part_type(row), axis=1)
  285. df_obligall['RestRon'] = df_obligall['Rest'] * df_obligall['Curs']
  286. mask = (~df_obligall['Simbol_x'].isin(options)) & (df_obligall['Rest'] != 0)
  287. df_obligsp = df_obligall.loc[mask & (df_obligall['Simbol_x'].isin(suppliers))]
  288. df_obligcl = df_obligall.loc[mask & (df_obligall['Simbol_x'].isin(clients))]
  289. print(df_obligall.head(10))
  290. writer = pd.ExcelWriter(
  291. 'obligatii.xlsx',
  292. engine='xlsxwriter')
  293. df_obligsp.to_excel(writer, sheet_name='Furnizori', index=False)
  294. df_obligcl.to_excel(writer, sheet_name='Clienti', index=False)
  295. workbook = writer.book
  296. num_format = workbook.add_format()
  297. num_format.set_num_format('#,##0.00')
  298. sh = workbook.get_worksheet_by_name('Furnizori')
  299. sh.freeze_panes(1, 0)
  300. sh.autofilter('A1:N500')
  301. sh.set_column('E:F', 12, cell_format=num_format)
  302. sh.set_column('L:L', 12, cell_format=num_format)
  303. sh.set_column('D:D', 10)
  304. sh.set_column('G:G', 30)
  305. sh2 = workbook.get_worksheet_by_name('Clienti')
  306. sh2.freeze_panes(1, 0)
  307. sh2.autofilter('A1:N500')
  308. sh2.set_column('E:F', 12, cell_format=num_format)
  309. sh2.set_column('L:L', 12, cell_format=num_format)
  310. sh2.set_column('D:D', 10)
  311. sh2.set_column('G:G', 30)
  312. writer._save()
  313. # writer.close()
  314. def part_type(self, row):
  315. suppliers = ['401', '403', '404', '408']
  316. adv_suppliers = ['409', '409.01', '409.02', '409.03', '409.04']
  317. clients = ['411', '411.01', '418']
  318. adv_clients = ['419', '419.01', '419.02', '472', '472.01']
  319. if row.loc['Simbol_x'] in suppliers:
  320. return 'Furnizor'
  321. elif row.loc['Simbol_x'] in adv_suppliers:
  322. return 'avans furnizor'
  323. elif row.loc['Simbol_x'] in clients:
  324. return 'Client'
  325. elif row.loc['Simbol_x'] in adv_clients:
  326. return 'Avans client'
  327. def get_oblig(self, short_name, db_file='/ObligPI.DB'):
  328. firm_list = self.filtered_firmlist(None)
  329. oblig_headers = ['Part', 'TipDoc', 'Cont', 'Doc', 'Moneda', 'Curs', 'NrDoc', 'DataDoc', 'Valoare', 'Rest']
  330. obligf_headers = ['Part', 'TipTranz', 'Cont', 'Doc', 'Moneda', 'Curs', 'NrDoc', 'DataDoc', 'Valoare', 'Rest']
  331. nparts_headres = ['Cod', 'Denumire', 'CodFiscal']
  332. cont_headers = ['Cod', 'Simbol']
  333. mon_headers = ['Cod', 'Simbol']
  334. for firm in firm_list:
  335. if firm[6] == short_name:
  336. short_path = self.winment_path + short_name
  337. # update files
  338. nparts_db = self.update_copy(short_path + '/NPART.DB')
  339. mons_db = self.update_copy(short_path + '/NMONEDE.DB')
  340. oblig_db = self.update_copy(short_path + '/' + self.get_last_month(short_name) + db_file)
  341. obligf_db = self.update_copy(short_path + '/' + self.get_last_month(short_name) + '/ObligF.DB')
  342. conts_db = self.update_copy(short_path + '/' + self.get_last_month(short_name) + '/NCONT.DB')
  343. # convert dbs to dfs
  344. dbtodf_oblig = Dbtodf(oblig_db, *oblig_headers)
  345. dbtodf_parts = Dbtodf(nparts_db, *nparts_headres)
  346. dbtodf_conts = Dbtodf(conts_db, *cont_headers)
  347. dbtodf_obligf = Dbtodf(obligf_db, *obligf_headers)
  348. dbtodf_mons = Dbtodf(mons_db, *mon_headers)
  349. # actual converting
  350. oblig_dict = dbtodf_oblig.convert_oblig()
  351. obligf_dict = dbtodf_obligf.convert_obligf()
  352. parts_dict = dbtodf_parts.convert_parts()
  353. conts_dict = dbtodf_conts.convert_cont()
  354. mons_dict = dbtodf_mons.convert_mon()
  355. return (oblig_dict, parts_dict, conts_dict, obligf_dict, mons_dict)
  356. def corp_list(self, name=None):
  357. '''returns company list from actual shortnames from winmwnt/data folder
  358. '''
  359. dir_list = [f.name for f in os.scandir(self.winment_path) if f.is_dir() and '@' not in f.name]
  360. if name:
  361. if type(name) is list:
  362. for r in name:
  363. dir_list.remove(r)
  364. else:
  365. dir_list.remove(name)
  366. return dir_list
  367. def verif_corp(self, file_='/firme.db', ban=None):
  368. headers = ['Denumire', 'CF', 'J', 'Adresa', 'Oras', 'Judet', 'Prescurtat', 'Obs']
  369. corplist = self.make_list(self.winment_path + file_, headers) # dbRead.make_list(m_path + '/FIRME.DB', headers)
  370. if ban:
  371. if type(ban) is list:
  372. for r in corplist:
  373. for i in ban:
  374. if i == r[6]:
  375. corplist.remove(r)
  376. else:
  377. for r in corplist:
  378. if r == ban:
  379. corplist.remove(r)
  380. return corplist
  381. def verif_cont(self, file_) -> list:
  382. '''returns an account with its values from the balance
  383. :param file_ is shortname/ncont.db'''
  384. accounts = []
  385. headers = ['Clasa', 'Simbol', 'Denumire', 'SoldID', 'SoldIC', 'PrecedentD', 'PrecedentC', 'CurentD', 'CurentC']
  386. accountlist = self.make_list(self.winment_path + file_, headers) # + lunaCurenta
  387. for elem in accountlist:
  388. account = Account(clasa=elem[0],
  389. simbol=elem[1],
  390. denumire=elem[2],
  391. soldid=elem[3],
  392. soldic=elem[4],
  393. precedentd=elem[5],
  394. precedentc=elem[6],
  395. curentd=elem[7],
  396. curentc=elem[8])
  397. accounts.append(account)
  398. return accountlist
  399. def an_inc(self, account_list, boolind, ind2, ind3):
  400. '''returns the annual turnover in given year
  401. :param int boolind:account class number
  402. :param int ind2, ind3:debit or credit position in balance
  403. (6-rulaj curent debit, 8-rulaj cumulat debit, index starting from 0)'''
  404. tt = 0
  405. for account in account_list:
  406. # n = len(account[boolind]) == 3 and account[boolind] != '...' and int(account[boolind]) > 700 and int(account[boolind]) < 760
  407. n = account[boolind] == 7
  408. can = account[1][:2] != '76'
  409. # print(account[1][:2])
  410. if n and can:
  411. tt += int(account[ind2]) + int(account[ind3])
  412. return tt
  413. def divid(self, account_list, account='457') -> int:
  414. '''returns dividends/year
  415. :param account_list is account from ncont.db'''
  416. div_ = 0
  417. for acc in account_list:
  418. if acc[1][:3] == account:
  419. div_ += acc[8] + acc[6]
  420. return round(div_)
  421. def divid_current(self, account_list, account='457') -> int:
  422. '''returns dividends from current month
  423. :param account_list is account from ncont.db'''
  424. div_ = 0
  425. for acc in account_list:
  426. if acc[1][:3] == account:
  427. div_ += acc[8]
  428. return round(div_)
  429. def divid_intermed(self, account_list, account='463') -> int:
  430. '''returns dividends from current result/year
  431. :param account_list is account from ncont.db'''
  432. div_ = 0
  433. for acc in account_list:
  434. if acc[1][:3] == account:
  435. div_ += acc[7] + acc[5]
  436. return round(div_)
  437. def divid_inter_current(self, account_list, account='463') -> int:
  438. '''returns dividends from current results in the current month
  439. :param account_list is account from ncont.db'''
  440. div_ = 0
  441. for acc in account_list:
  442. if acc[1][:3] == account:
  443. div_ += acc[7]
  444. return round(div_)
  445. def spons(self, account_list, account='658.02') -> int:
  446. '''returns sponsored money/year
  447. :param account_list is account from ncont.db'''
  448. spons_ = 0
  449. for acc in account_list:
  450. if acc[1] == account:
  451. spons_ += acc[8] + acc[6]
  452. return round(spons_)
  453. def result(self, account_list, boolind, ind2, ind3) -> int: # account='121'
  454. '''returns the final result in given year
  455. :param int boolind:account class number
  456. :param int ind2, ind3:debit or credit position in balance
  457. (6-rulaj curent debit, 8-rulaj cumulat debit, index starting from 0)'''
  458. res_minus = res_plus = 0
  459. for r_minus in account_list:
  460. p = r_minus[boolind] == 6
  461. if p:
  462. res_minus += int(r_minus[ind2]) + int(r_minus[ind3])
  463. for r_plus in account_list:
  464. i = r_plus[boolind] == 7
  465. if i:
  466. res_plus += int(r_plus[ind2]) + int(r_plus[ind3])
  467. return res_plus - res_minus
  468. def ins_payable(self, account_list, account='431') -> int:
  469. '''returns insurences payable in current month
  470. :param account_list is account from ncont.db'''
  471. ins = 0
  472. for acc in account_list:
  473. p = acc[1][:3] == account
  474. if p:
  475. ins += acc[8]
  476. return round(ins)
  477. def CAS_payable(self, account_list, accounts=('431.02', '431.05')) -> int:
  478. '''returns CAS payable in current month
  479. :param account_list is account from ncont.db'''
  480. CAS = 0
  481. acc_1, acc_2 = accounts
  482. for acc in account_list:
  483. p = acc[1] == acc_1
  484. d = acc[1] == acc_2
  485. if p: CAS += acc[8]
  486. if d: CAS += acc[8]
  487. return round(CAS)
  488. def CASS_payable(self, account_list, accounts=('431.04', '431.06')) -> int:
  489. '''returns CASS payable in current month
  490. :param account_list is account from ncont.db'''
  491. CASS = 0
  492. acc_1, acc_2 = accounts
  493. for acc in account_list:
  494. p = acc[1] == acc_1
  495. d = acc[1] == acc_2
  496. if p: CASS += acc[8]
  497. if d: CASS += acc[8]
  498. return round(CASS)
  499. def sal_tax_payable(self, account_list, account='431.44') -> int:
  500. '''returns salary tax payable in current month
  501. :param account_list is account from ncont.db'''
  502. tax = 0
  503. for acc in account_list:
  504. p = acc[1] == account
  505. if p:
  506. tax += acc[8]
  507. return round(tax)
  508. def cam_payable(self, account_list, account='436') -> int:
  509. '''returns CAM payable in current month
  510. :param account_list is account from ncont.db'''
  511. cam = 0
  512. for acc in account_list:
  513. p = acc[1][:3] == account
  514. if p:
  515. cam += acc[8]
  516. return round(cam)
  517. def vat_payable(self, account_list, accounts=('442.03', '442.04')) -> int:
  518. '''returns VAT payable in current month
  519. :param account_list is account from ncont.db'''
  520. tt = 0
  521. acc_1, acc_2 = accounts
  522. for acc in account_list:
  523. p = acc[1] == acc_1
  524. d = acc[1] == acc_2
  525. if p:
  526. tt += acc[8]
  527. elif d:
  528. tt -= acc[7] + acc[8]
  529. return round(tt)
  530. def vat_final(self, acc_list, accounts=('442.03', '442.04')) -> int:
  531. '''returns VAT final payable in current month
  532. :param account_list is account from ncont.db'''
  533. tt = 0
  534. acc_1, acc_2 = accounts
  535. for acc in acc_list:
  536. account = Account(clasa=acc[0],
  537. simbol=acc[1],
  538. denumire=acc[2],
  539. soldid=acc[3],
  540. soldic=acc[4],
  541. precedentd=acc[5],
  542. precedentc=acc[6],
  543. curentd=acc[7],
  544. curentc=acc[8])
  545. payable = account.simbol == acc_1
  546. deductible = account.simbol == acc_2
  547. if payable:
  548. tt += account.soldf('c')
  549. elif deductible:
  550. tt -= account.soldf('d')
  551. return round(tt)
  552. def tax_payable(self, account_list, account='441') -> int:
  553. '''returns income TAX payable in current month
  554. :param account_list is account from ncont.db'''
  555. tax = 0
  556. for acc in account_list:
  557. p = acc[1][:3] == account
  558. if p:
  559. tax += acc[8]
  560. return round(tax)
  561. def div_tax_payable(self, acc_list, accounts='446.07') -> int:
  562. '''returns dividend TAX payable in current month
  563. :param account_list is account from ncont.db'''
  564. tt = 0
  565. # acc_1, acc_2 = accounts
  566. for acc in acc_list:
  567. account = Account(clasa=acc[0],
  568. simbol=acc[1],
  569. denumire=acc[2],
  570. soldid=acc[3],
  571. soldic=acc[4],
  572. precedentd=acc[5],
  573. precedentc=acc[6],
  574. curentd=acc[7],
  575. curentc=acc[8])
  576. payable = account.simbol == accounts
  577. # deductible = account.simbol == acc_2
  578. if payable:
  579. tt += account.curentc
  580. # elif deductible:
  581. # tt -= account.soldf('d')
  582. return round(tt)
  583. def advance_final(self, acc_list, accounts='542') -> int:
  584. '''returns final dvances/year
  585. :param account_list is account from ncont.db'''
  586. tt = 0
  587. # acc_1, acc_2 = accounts
  588. for acc in acc_list:
  589. account = Account(clasa=acc[0],
  590. simbol=acc[1],
  591. denumire=acc[2],
  592. soldid=acc[3],
  593. soldic=acc[4],
  594. precedentd=acc[5],
  595. precedentc=acc[6],
  596. curentd=acc[7],
  597. curentc=acc[8])
  598. payable = account.simbol[:3] == accounts
  599. # deductible = account.simbol == acc_2
  600. if payable:
  601. tt += account.soldf('d')
  602. # elif deductible:
  603. # tt -= account.soldf('d')
  604. return round(tt)
  605. def deb_div(self, acc_list, accounts='461') -> int:
  606. '''returns advances transfered to deb. diversi/year
  607. :param account_list is account from ncont.db'''
  608. tt = 0
  609. # acc_1, acc_2 = accounts
  610. for acc in acc_list:
  611. account = Account(clasa=acc[0],
  612. simbol=acc[1],
  613. denumire=acc[2],
  614. soldid=acc[3],
  615. soldic=acc[4],
  616. precedentd=acc[5],
  617. precedentc=acc[6],
  618. curentd=acc[7],
  619. curentc=acc[8])
  620. payable = account.simbol[:3] == accounts
  621. # deductible = account.simbol == acc_2
  622. if payable:
  623. tt += account.soldf('d')
  624. # elif deductible:
  625. # tt -= account.soldf('d')
  626. return round(tt)
  627. def credit_final(self, acc_list, accounts='455') -> int:
  628. '''returns credited ammount/year
  629. :param account_list is account from ncont.db'''
  630. tt = 0
  631. # acc_1, acc_2 = accounts
  632. for acc in acc_list:
  633. account = Account(clasa=acc[0],
  634. simbol=acc[1],
  635. denumire=acc[2],
  636. soldid=acc[3],
  637. soldic=acc[4],
  638. precedentd=acc[5],
  639. precedentc=acc[6],
  640. curentd=acc[7],
  641. curentc=acc[8])
  642. payable = account.simbol[:3] == accounts
  643. # deductible = account.simbol == acc_2
  644. if payable:
  645. tt += account.soldf('d')
  646. # elif deductible:
  647. # tt -= account.soldf('d')
  648. return round(tt)
  649. if __name__ == '__main__':
  650. mentor = WinMentor()
  651. # accounts = list(mentor.get_bank_accounts('WEBS'))
  652. # account_num = [n for n in accounts[1] if n.startswith(' ')]
  653. for account in mentor.get_bank_accounts('WEBS'):
  654. # if account[2].startswith(' '):
  655. print(account)