dbread.py 26 KB

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