dbread.py 29 KB

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