示例#1
0
 def statusReport(self, kpv):
     vs = Vara.objects.all()
     SH = {'A':0, 'V':0, 'I':0}
     TH = {'A':0, 'V':0, 'I':0}
     RS = {'A':0, 'V':0, 'I':0}
     for v in vs:
         vts = Varatehing.objects.all().filter(vara=v, vaartuspaev__lte=kpv).order_by('vaartuspaev','-tyyp','-kogus')
         l_vt = ''
         for vt in vts:
             l_vt = vt
         if l_vt != '':
             if float(l_vt.yldkogus) > 0:
                 v = l_vt.vara
                 if v.vp_tyyp not in ['A','V','I']:
                     # print u'Tüüp ' + v.vp_tyyp + ' -> A'
                     v.vp_tyyp = 'A'
                 SH.update({v.vp_tyyp: SH.get(v.vp_tyyp) + float(l_vt.soetushind)})
                 TH.update({v.vp_tyyp: TH.get(v.vp_tyyp) + float(l_vt.turuhind)})
                 RS.update({v.vp_tyyp: RS.get(v.vp_tyyp) + float(l_vt.reserv)})
     return ({'Kpv': date2str(kpv)}, 
             [{'tyyp':'Aktsiad', 'sh':SH.get('A'), 'th':TH.get('A'), 'rs':RS.get('A')},
                    {'tyyp':u'Võlakirjad', 'sh':SH.get('V'), 'th':TH.get('V'), 'rs':RS.get('V')},
                    {'tyyp':'Alt.investeeringud', 'sh':SH.get('I'), 'th':TH.get('I'), 'rs':RS.get('I')},
                    {'tyyp':'KOKKU', 'sh':SH.get('A')+SH.get('V')+SH.get('I'), 
                     'th':TH.get('A')+TH.get('V')+TH.get('I'), 'rs':RS.get('A')+RS.get('V')+RS.get('I')}]
             )
示例#2
0
 def reservMovementReport(self, pr):
     t_Res = 0
     v_Res = 0
     ts = Tehing.objects.all().filter(pearaamat=pr).order_by('maksepaev')
     kres = Konto.objects.get(pk='264')
     data = []
     for t in ts:
         # vara otsing
         vts = Varatehing.objects.all().filter(vaartuspaev=t.maksepaev)
         l_v = None
         l_v_res = 0
         l_info = ''
         for vt in vts:
             brs = Pangakirje.objects.all().filter(tehing=t)
             for br in brs:
                 if self.identify(br.selgitus) == vt.vara.id:
                     if l_v != None:
                         # print 'Mitu sobivat kirjet? '+ l_info + '|' + t.tehingutyyp.kirjeldus+':'+br.selgitus
                         pass
                     l_v = vt.vara.id
                     l_v_res = self.getReservDiff(l_v, t.maksepaev)
                     l_info = t.sisu+':'+br.selgitus+ ' (' + vt.vara.vp_tyyp + ')'
             if l_v == None and vt.tyyp == 'H' and re.search('.*mberhindamine', t.sisu):
                 ss = t.sisu.split('(')
                 if len(ss) > 1:
                     s = ss[1].rstrip(')')
                     vs = Vara.objects.all().filter(nimetus=s)
                     for v in vs:
                         l_v = v.id
                         l_v_res = self.getReservDiff(l_v, t.maksepaev)
                         l_info = t.sisu + ' (' + v.vp_tyyp + ')'
                         break
                     if l_v == None:
                         print ' ? Ei leia ', s
                         pass
         # konto 264 otsing
         ks = Kanne.objects.all().filter(tehing=t, konto=kres)
         l_k = None
         l_t_res = 0
         for k in ks:
             l_t_res = l_t_res + (-1 if k.on_deebet else 1) * k.summa
             l_k = k
         abi = ''
         if l_k != None:
             ks = Kanne.objects.all().filter(tehing=t).exclude(konto=kres)
             for k in ks:
                 abi = abi + (',' if abi != '' else '') + k.konto.kontonumber 
         if l_v != None and l_k != None:
             t_Res += l_t_res
             v_Res += l_v_res    
             data.append({'kpv':date2str(t.maksepaev), 'tehing':l_info + ' - ' +abi, 'dk':l_t_res, 'dv':l_v_res, 'k':t_Res, 'v':v_Res, 't':t.id})
         elif l_v == None and l_k != None:
             print ' >>!v> ',t,l_k,l_t_res
         elif l_v != None and l_v_res != 0 and l_k == None:
             print ' >>!k> ',t,l_info,l_v_res
     return data
示例#3
0
    def export_ledger_table(self, csv_file, pr):
        if csv_file.closed:
            return False
        ts = Tehing.objects.all().filter(pearaamat=pr).order_by('maksepaev')
        ks = Konto.objects.all()
        # päis
        line = u'Kuupäev;Tehing;'
        for k in ks:
            if len(k.kontonumber) > 2:
                line = line + 'D-'+k.kontonumber+ ';K-'+k.kontonumber+';'
        csv_file.write(line+'\n')
        # algsaldo
        line = '1.1.'+smart_unicode(pr.aasta)+';ALGSALDO;'
        for k in ks:
            if len(k.kontonumber) > 2:
                sk = 0
                sd = 0
                kns = Algsaldo.objects.all().filter(pearaamat= pr,konto=k)
                for kn in kns:
                    if kn.on_deebet:
                        sd += float(kn.summa)
                    else:
                        sk += float(kn.summa)
                line = line + smart_unicode(round(sd,2)).replace('.', ',') + ';' + smart_unicode(round(sk,2)).replace('.', ',') + ';'
        csv_file.write(line+'\n')

        # tehingud
        kuu = 2
        ctrld = date(pr.aasta, kuu, 1)
        for t in ts:
            # vahesaldo
            if t.maksepaev >= ctrld:
                line = date2str(ctrld)+';SALDO '+smart_unicode(kuu-1)+u'. kuu järel;'
                for k in ks:
                    if len(k.kontonumber) > 2:
                        sk = 0
                        sd = 0
                        kns = Algsaldo.objects.all().filter(pearaamat= pr,konto=k)
                        for kn in kns:
                            if kn.on_deebet:
                                sd += float(kn.summa)
                            else:
                                sk += float(kn.summa)
                        kns = Kanne.objects.all().filter(tehing__pearaamat=pr, tehing__maksepaev__lt=ctrld, konto=k)
                        for kn in kns:
                            if kn.on_deebet:
                                sd += float(kn.summa)
                            else:
                                sk += float(kn.summa)
                        if k.osa in ('A','K'):
                            sld = sd - sk
                            if sld > 0:
                                sd = sld
                                sk = 0
                            else:
                                sk = abs(sld)
                                sd = 0
                        else:
                            sld = sk - sd
                            if sld > 0:
                                sk = sld
                                sd = 0
                            else:
                                sd = abs(sld)
                                sk = 0
                        line = line + smart_unicode(round(sd,2)).replace('.', ',') + ';' + smart_unicode(round(sk,2)).replace('.', ',') + ';'
                csv_file.write(line+'\n')
                if kuu < 12:
                    kuu += 1
                    ctrld = date(pr.aasta, kuu, 1)
                else:
                    ctrld = date(pr.aasta+1, 1, 1)
            # tehing    
            line = date2str(t.maksepaev)+';'+smart_unicode(t.sisu)+';'
            for k in ks:
                if len(k.kontonumber) > 2:
                    sk = 0
                    sd = 0
                    kns = Kanne.objects.all().filter(tehing=t,konto=k)
                    for kn in kns:
                        if kn.on_deebet:
                            sd += float(kn.summa)
                        else:
                            sk += float(kn.summa)
                    line = line + smart_unicode(round(sd,2)).replace('.', ',') + ';' + smart_unicode(round(sk,2)).replace('.', ',') + ';'
                    
            csv_file.write(line+'\n')
        # lõppsaldo
        line = '31.12.'+smart_unicode(pr.aasta)+u';LÕPPSALDO;'
        for k in ks:
            if len(k.kontonumber) > 2:
                sk = 0
                sd = 0
                kns = Algsaldo.objects.all().filter(pearaamat= pr,konto=k)
                for kn in kns:
                    if kn.on_deebet:
                        sd += float(kn.summa)
                    else:
                        sk += float(kn.summa)
                kns = Kanne.objects.all().filter(tehing__pearaamat=pr, konto=k)
                for kn in kns:
                    if kn.on_deebet:
                        sd += float(kn.summa)
                    else:
                        sk += float(kn.summa)
                if k.osa in ('A','K'):
                    sld = sd - sk
                    if sld > 0:
                        sd = sld
                        sk = 0
                    else:
                        sk = abs(sld)
                        sd = 0
                else:
                    sld = sk - sd
                    if sld > 0:
                        sk = sld
                        sd = 0
                    else:
                        sd = abs(sld)
                        sk = 0
                line = line + smart_unicode(round(sd,2)).replace('.', ',') + ';' + smart_unicode(round(sk,2)).replace('.', ',') + ';'
        csv_file.write(line+'\n')
        csv_file.close()
        return True