dbread.py 29 KB

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