Exemplo n.º 1
0
def regist_regularly_payment(request):
    '''指定された年月日に登録済みの定期支払項目を一括で自動登録する'''
    today_str = u.createCurrentDateString()
    strdate = request.POST['reg_regist_date'].replace('-', '')
    note = u.get_nowdt().strftime('%Y/%m/%d %H:%M') + ' 自動登録です'
    qs_reg_list = db.RegularlyPayment.objects.all()
    groupid = u.get_nowdt().strftime('%Y%m%d%H%M%S%f')
    for qs in qs_reg_list:
        if qs.is_regist_automaticaly == 1:
            db.Journal.objects.create(
                date = strdate,
                group_id = groupid,
                br_acc_bot_uid = db.AccBot.objects.get(uid=qs.acc_bot_uid.uid),
                br_amount = u.getEmptyOrValueInt(qs.amount_per_month),
                cr_acc_bot_uid = db.AccBot.objects.get(uid=qs.acc_bot_uid_from.uid),
                cr_amount = u.getEmptyOrValueInt(qs.amount_per_month),
                note = note,
            )
    return redirect('/magi/sdss/regularly-payment/')
Exemplo n.º 2
0
def getAccountSuii(year, month, accID):

    if accID == 0:
        return []

    strDate = u.createCurrentYearMonthString(year, month)
    br_direction = db.AccBot.objects.get(uid=accID).acc_mid_uid.acc_top_uid.is_br

    # BSのみ前月末残高を計算
    if db.AccBot.objects.get(uid=accID).acc_mid_uid.acc_top_uid.uid >= 4:
        total = 0
    else:
        init_qs = db.Journal.objects.filter(date__lt=strDate)
        init_br = u.getEmptyOrValueInt(init_qs.filter(br_acc_bot_uid=accID).aggregate(Sum('br_amount'))['br_amount__sum'])
        init_cr = u.getEmptyOrValueInt(init_qs.filter(cr_acc_bot_uid=accID).aggregate(Sum('cr_amount'))['cr_amount__sum'])
        total = u.diffBrCr(init_br, init_cr, br_direction)
    print('total=' + str(total))
    # summing day by day ...
    dic = []
    nextMonth = u.createNextYearMonthString(year, month)
    qs = db.Journal.objects.filter(date__range=(strDate, nextMonth))
    curr_br_qs = qs.filter(br_acc_bot_uid=accID)
    curr_cr_qs = qs.filter(cr_acc_bot_uid=accID)

    # TODO 2019年現在にyearが2020だった場合の考慮はしてないが不要?
    isSyoribiYM = u.get_nowdt().year == year and u.get_nowdt().month == month

    # 1日 ~ 31日まで借方と貸方の差分を取得する。2月31日とかも処理するけど文字列型なので問題なし
    for i in range(1,32):
        # 処理当日以降のは登録しない
        if isSyoribiYM and i > u.get_nowdt().day:
            dic.append(0)
        else:
            today_br_sum = u.getEmptyOrValueInt(curr_br_qs.filter(date=(strDate+'{:02}'.format(i))).aggregate(Sum('br_amount'))['br_amount__sum'])
            today_cr_sum = u.getEmptyOrValueInt(curr_cr_qs.filter(date=(strDate+'{:02}'.format(i))).aggregate(Sum('cr_amount'))['cr_amount__sum'])
            print(str(i) + ': add to ' + str(u.diffBrCr(today_br_sum, today_cr_sum, br_direction)))
            total += u.diffBrCr(today_br_sum, today_cr_sum, br_direction)
            dic.append(total)
        #else:
        #    dic.append(0)
    #print(str(dic))
    return dic
Exemplo n.º 3
0
def regist(request):
    #入力チェックと登録用データ作成
    #TODO 入力チェックとUI側の入力チェックもこっちへ移す
    groupid = u.get_nowdt().strftime('%Y%m%d%H%M%S%f')
    strdate = request.POST['journal_date'].replace('-','')
    log.info('regist date as: ' + strdate)

    register_corresp = []
    register_corresp.append({'br_a': 'br_1_a', 'cr_a': 'cr_1_a', 'br_c': 'br_1_c', 'cr_c': 'cr_1_c'})
    register_corresp.append({'br_a': 'br_2_a', 'cr_a': 'cr_2_a', 'br_c': 'br_2_c', 'cr_c': 'cr_2_c'})
    register_corresp.append({'br_a': 'br_3_a', 'cr_a': 'cr_3_a', 'br_c': 'br_3_c', 'cr_c': 'cr_3_c'})
    register_corresp.append({'br_a': 'br_4_a', 'cr_a': 'cr_4_a', 'br_c': 'br_4_c', 'cr_c': 'cr_4_c'})
    register_corresp.append({'br_a': 'br_5_a', 'cr_a': 'cr_5_a', 'br_c': 'br_5_c', 'cr_c': 'cr_5_c'})
    register_corresp.append({'br_a': 'br_6_a', 'cr_a': 'cr_6_a', 'br_c': 'br_6_c', 'cr_c': 'cr_6_c'})
    register_corresp.append({'br_a': 'br_7_a', 'cr_a': 'cr_7_a', 'br_c': 'br_7_c', 'cr_c': 'cr_7_c'})
    register_corresp.append({'br_a': 'br_8_a', 'cr_a': 'cr_8_a', 'br_c': 'br_8_c', 'cr_c': 'cr_8_c'})
    registerd = False
    note_temp = ''
    for cor in register_corresp:
        if u.isIntAndNotZero(request.POST[cor['br_a']]) or u.isIntAndNotZero(request.POST[cor['cr_a']]):
            if registerd == True:
                note_temp = ''
            else:
                note_temp = request.POST['note']
            db.Journal.objects.create(
                date = strdate,
                group_id = groupid,
                br_acc_bot_uid = db.AccBot.objects.get(uid=request.POST[cor['br_c']]),
                br_amount = u.getEmptyOrValueInt(request.POST[cor['br_a']]),
                cr_acc_bot_uid = db.AccBot.objects.get(uid=request.POST[cor['cr_c']]),
                cr_amount = u.getEmptyOrValueInt(request.POST[cor['cr_a']]),
                note = note_temp,
            )
            registerd = True
            log.info('register journal object')
    # TODO ハードコーディングなのでショートカットにするとか200
    return redirect('/magi/sdss')