dbread.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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_obligf = df_obligf.rename(columns={'TipTranz': 'TipDoc'})
  260. # join oblig<>part<>cont with left join
  261. df_oblig = pd.merge(df_oblig, df_parts, how='left', left_on='Part', right_on='Cod')
  262. df_oblig.drop(columns=['Part', 'Cod'], inplace=True)
  263. df_oblig = pd.merge(df_oblig, df_conts, how='left', left_on='Cont', right_on='Cod')
  264. df_oblig.drop(columns=['Cont', 'Cod'], inplace=True)
  265. # join obligf<>party<>cont
  266. try:
  267. df_obligf = pd.merge(df_obligf, df_parts, how='left', left_on='Part', right_on='Cod')
  268. df_obligf.drop(columns=['Part', 'Cod'], inplace=True)
  269. df_obligf = pd.merge(df_obligf, df_conts, how='left', left_on='Cont', right_on='Cod')
  270. df_obligf.drop(columns=['Cont', 'Cod'], inplace=True)
  271. df_obligall = pd.concat([df_oblig, df_obligf])
  272. except KeyError as exc_:
  273. df_obligall = df_oblig
  274. options = ['581', '455', '455.01', '167', '666']
  275. df_obligall = df_obligall.loc[(~df_obligall['Simbol'].isin(options)) & (df_obligall['Rest'] != 0)]
  276. print(df_obligall.head(10))
  277. df_obligall.to_excel('obligatii.xlsx')
  278. def get_oblig(self, short_name, db_file='/ObligPI.DB'):
  279. firm_list = self.filtered_firmlist(None)
  280. oblig_headers = ['Part', 'TipDoc', 'Cont', 'Doc', 'NrDoc', 'DataDoc', 'Valoare', 'Rest']
  281. obligf_headers = ['Part', 'TipTranz', 'Cont', 'Doc', 'NrDoc', 'DataDoc', 'Valoare', 'Rest']
  282. nparts_headres = ['Cod', 'Denumire', 'CodFiscal']
  283. cont_headers = ['Cod', 'Simbol']
  284. for firm in firm_list:
  285. if firm[6] == short_name:
  286. short_path = self.winment_path + short_name
  287. # update files
  288. nparts_db = self.update_copy(short_path + '/NPART.DB')
  289. oblig_db = self.update_copy(short_path + '/' + self.get_last_month(short_name) + db_file)
  290. obligf_db = self.update_copy(short_path + '/' + self.get_last_month(short_name) + '/ObligF.DB')
  291. conts_db = self.update_copy(short_path + '/' + self.get_last_month(short_name) + '/NCONT.DB')
  292. # convert dbs to dfs
  293. dbtodf_oblig = Dbtodf(oblig_db, *oblig_headers)
  294. dbtodf_parts = Dbtodf(nparts_db, *nparts_headres)
  295. dbtodf_conts = Dbtodf(conts_db, *cont_headers)
  296. dbtodf_obligf =Dbtodf(obligf_db, *obligf_headers)
  297. # actual converting
  298. oblig_dict = dbtodf_oblig.convert_oblig()
  299. obligf_dict = dbtodf_obligf.convert_obligf()
  300. parts_dict = dbtodf_parts.convert_parts()
  301. conts_dict = dbtodf_conts.convert_cont()
  302. return (oblig_dict, parts_dict, conts_dict, obligf_dict)
  303. def corp_list(self, name=None):
  304. '''returns company list from actual shortnames from winmwnt/data folder
  305. '''
  306. dir_list = [f.name for f in os.scandir(self.winment_path) if f.is_dir() and '@' not in f.name]
  307. if name:
  308. if type(name) is list:
  309. for r in name:
  310. dir_list.remove(r)
  311. else:
  312. dir_list.remove(name)
  313. return dir_list
  314. def verif_corp(self, file_='/firme.db', ban=None):
  315. headers = ['Denumire', 'CF', 'J', 'Adresa', 'Oras', 'Judet', 'Prescurtat', 'Obs']
  316. corplist = self.make_list(self.winment_path + file_, headers) # dbRead.make_list(m_path + '/FIRME.DB', headers)
  317. if ban:
  318. if type(ban) is list:
  319. for r in corplist:
  320. for i in ban:
  321. if i == r[6]:
  322. corplist.remove(r)
  323. else:
  324. for r in corplist:
  325. if r == ban:
  326. corplist.remove(r)
  327. return corplist
  328. def verif_cont(self, file_) -> list:
  329. '''returns an account with its values from the balance
  330. :param file_ is shortname/ncont.db'''
  331. accounts = []
  332. headers = ['Clasa', 'Simbol', 'Denumire', 'SoldID', 'SoldIC', 'PrecedentD', 'PrecedentC', 'CurentD', 'CurentC']
  333. accountlist = self.make_list(self.winment_path + file_, headers) # + lunaCurenta
  334. for elem in accountlist:
  335. account = Account(clasa=elem[0],
  336. simbol=elem[1],
  337. denumire=elem[2],
  338. soldid=elem[3],
  339. soldic=elem[4],
  340. precedentd=elem[5],
  341. precedentc=elem[6],
  342. curentd=elem[7],
  343. curentc=elem[8])
  344. accounts.append(account)
  345. return accountlist
  346. def an_inc(self, account_list, boolind, ind2, ind3):
  347. '''returns the annual turnover in given year
  348. :param int boolind:account class number
  349. :param int ind2, ind3:debit or credit position in balance
  350. (6-rulaj curent debit, 8-rulaj cumulat debit, index starting from 0)'''
  351. tt = 0
  352. for account in account_list:
  353. # n = len(account[boolind]) == 3 and account[boolind] != '...' and int(account[boolind]) > 700 and int(account[boolind]) < 760
  354. n = account[boolind] == 7
  355. can = account[1][:2] != '76'
  356. # print(account[1][:2])
  357. if n and can:
  358. tt += int(account[ind2]) + int(account[ind3])
  359. return tt
  360. def divid(self, account_list, account='457') -> int:
  361. '''returns dividends/year
  362. :param account_list is account from ncont.db'''
  363. div_ = 0
  364. for acc in account_list:
  365. if acc[1][:3] == account:
  366. div_ += acc[8] + acc[6]
  367. return round(div_)
  368. def divid_current(self, account_list, account='457') -> int:
  369. '''returns dividends from current month
  370. :param account_list is account from ncont.db'''
  371. div_ = 0
  372. for acc in account_list:
  373. if acc[1][:3] == account:
  374. div_ += acc[8]
  375. return round(div_)
  376. def divid_intermed(self, account_list, account='463') -> int:
  377. '''returns dividends from current result/year
  378. :param account_list is account from ncont.db'''
  379. div_ = 0
  380. for acc in account_list:
  381. if acc[1][:3] == account:
  382. div_ += acc[7] + acc[5]
  383. return round(div_)
  384. def divid_inter_current(self, account_list, account='463') -> int:
  385. '''returns dividends from current results in the current month
  386. :param account_list is account from ncont.db'''
  387. div_ = 0
  388. for acc in account_list:
  389. if acc[1][:3] == account:
  390. div_ += acc[7]
  391. return round(div_)
  392. def spons(self, account_list, account='658.02') -> int:
  393. '''returns sponsored money/year
  394. :param account_list is account from ncont.db'''
  395. spons_ = 0
  396. for acc in account_list:
  397. if acc[1] == account:
  398. spons_ += acc[8] + acc[6]
  399. return round(spons_)
  400. def result(self, account_list, boolind, ind2, ind3) -> int: # account='121'
  401. '''returns the final result in given year
  402. :param int boolind:account class number
  403. :param int ind2, ind3:debit or credit position in balance
  404. (6-rulaj curent debit, 8-rulaj cumulat debit, index starting from 0)'''
  405. res_minus = res_plus = 0
  406. for r_minus in account_list:
  407. p = r_minus[boolind] == 6
  408. if p:
  409. res_minus += int(r_minus[ind2]) + int(r_minus[ind3])
  410. for r_plus in account_list:
  411. i = r_plus[boolind] == 7
  412. if i:
  413. res_plus += int(r_plus[ind2]) + int(r_plus[ind3])
  414. return res_plus - res_minus
  415. def ins_payable(self, account_list, account='431') -> int:
  416. '''returns insurences payable in current month
  417. :param account_list is account from ncont.db'''
  418. ins = 0
  419. for acc in account_list:
  420. p = acc[1][:3] == account
  421. if p:
  422. ins += acc[8]
  423. return round(ins)
  424. def CAS_payable(self, account_list, accounts=('431.02', '431.05')) -> int:
  425. '''returns CAS payable in current month
  426. :param account_list is account from ncont.db'''
  427. CAS = 0
  428. acc_1, acc_2 = accounts
  429. for acc in account_list:
  430. p = acc[1] == acc_1
  431. d = acc[1] == acc_2
  432. if p: CAS += acc[8]
  433. if d: CAS += acc[8]
  434. return round(CAS)
  435. def CASS_payable(self, account_list, accounts=('431.04', '431.06')) -> int:
  436. '''returns CASS payable in current month
  437. :param account_list is account from ncont.db'''
  438. CASS = 0
  439. acc_1, acc_2 = accounts
  440. for acc in account_list:
  441. p = acc[1] == acc_1
  442. d = acc[1] == acc_2
  443. if p: CASS += acc[8]
  444. if d: CASS += acc[8]
  445. return round(CASS)
  446. def sal_tax_payable(self, account_list, account='431.44') -> int:
  447. '''returns salary tax payable in current month
  448. :param account_list is account from ncont.db'''
  449. tax = 0
  450. for acc in account_list:
  451. p = acc[1] == account
  452. if p:
  453. tax += acc[8]
  454. return round(tax)
  455. def cam_payable(self, account_list, account='436') -> int:
  456. '''returns CAM payable in current month
  457. :param account_list is account from ncont.db'''
  458. cam = 0
  459. for acc in account_list:
  460. p = acc[1][:3] == account
  461. if p:
  462. cam += acc[8]
  463. return round(cam)
  464. def vat_payable(self, account_list, accounts=('442.03', '442.04')) -> int:
  465. '''returns VAT payable in current month
  466. :param account_list is account from ncont.db'''
  467. tt = 0
  468. acc_1, acc_2 = accounts
  469. for acc in account_list:
  470. p = acc[1] == acc_1
  471. d = acc[1] == acc_2
  472. if p:
  473. tt += acc[8]
  474. elif d:
  475. tt -= acc[7] + acc[8]
  476. return round(tt)
  477. def vat_final(self, acc_list, accounts=('442.03', '442.04')) -> int:
  478. '''returns VAT final payable in current month
  479. :param account_list is account from ncont.db'''
  480. tt = 0
  481. acc_1, acc_2 = accounts
  482. for acc in acc_list:
  483. account = Account(clasa=acc[0],
  484. simbol=acc[1],
  485. denumire=acc[2],
  486. soldid=acc[3],
  487. soldic=acc[4],
  488. precedentd=acc[5],
  489. precedentc=acc[6],
  490. curentd=acc[7],
  491. curentc=acc[8])
  492. payable = account.simbol == acc_1
  493. deductible = account.simbol == acc_2
  494. if payable:
  495. tt += account.soldf('c')
  496. elif deductible:
  497. tt -= account.soldf('d')
  498. return round(tt)
  499. def tax_payable(self, account_list, account='441') -> int:
  500. '''returns income 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][:3] == account
  505. if p:
  506. tax += acc[8]
  507. return round(tax)
  508. def div_tax_payable(self, acc_list, accounts='446.07') -> int:
  509. '''returns dividend TAX payable in current month
  510. :param account_list is account from ncont.db'''
  511. tt = 0
  512. # acc_1, acc_2 = accounts
  513. for acc in acc_list:
  514. account = Account(clasa=acc[0],
  515. simbol=acc[1],
  516. denumire=acc[2],
  517. soldid=acc[3],
  518. soldic=acc[4],
  519. precedentd=acc[5],
  520. precedentc=acc[6],
  521. curentd=acc[7],
  522. curentc=acc[8])
  523. payable = account.simbol == accounts
  524. # deductible = account.simbol == acc_2
  525. if payable:
  526. tt += account.curentc
  527. # elif deductible:
  528. # tt -= account.soldf('d')
  529. return round(tt)
  530. def advance_final(self, acc_list, accounts='542') -> int:
  531. '''returns final dvances/year
  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[:3] == accounts
  546. # deductible = account.simbol == acc_2
  547. if payable:
  548. tt += account.soldf('d')
  549. # elif deductible:
  550. # tt -= account.soldf('d')
  551. return round(tt)
  552. def deb_div(self, acc_list, accounts='461') -> int:
  553. '''returns advances transfered to deb. diversi/year
  554. :param account_list is account from ncont.db'''
  555. tt = 0
  556. # acc_1, acc_2 = accounts
  557. for acc in acc_list:
  558. account = Account(clasa=acc[0],
  559. simbol=acc[1],
  560. denumire=acc[2],
  561. soldid=acc[3],
  562. soldic=acc[4],
  563. precedentd=acc[5],
  564. precedentc=acc[6],
  565. curentd=acc[7],
  566. curentc=acc[8])
  567. payable = account.simbol[:3] == accounts
  568. # deductible = account.simbol == acc_2
  569. if payable:
  570. tt += account.soldf('d')
  571. # elif deductible:
  572. # tt -= account.soldf('d')
  573. return round(tt)
  574. def credit_final(self, acc_list, accounts='455') -> int:
  575. '''returns credited ammount/year
  576. :param account_list is account from ncont.db'''
  577. tt = 0
  578. # acc_1, acc_2 = accounts
  579. for acc in acc_list:
  580. account = Account(clasa=acc[0],
  581. simbol=acc[1],
  582. denumire=acc[2],
  583. soldid=acc[3],
  584. soldic=acc[4],
  585. precedentd=acc[5],
  586. precedentc=acc[6],
  587. curentd=acc[7],
  588. curentc=acc[8])
  589. payable = account.simbol[:3] == accounts
  590. # deductible = account.simbol == acc_2
  591. if payable:
  592. tt += account.soldf('d')
  593. # elif deductible:
  594. # tt -= account.soldf('d')
  595. return round(tt)
  596. if __name__ == '__main__':
  597. mentor = WinMentor()
  598. # accounts = list(mentor.get_bank_accounts('WEBS'))
  599. # account_num = [n for n in accounts[1] if n.startswith(' ')]
  600. for account in mentor.get_bank_accounts('WEBS'):
  601. # if account[2].startswith(' '):
  602. print(account)