dbread.py 29 KB

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