dbread.py 30 KB

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