def InvestDetail(request): thisdate = fun.getThisdate(request) message = '' invest_type_list = fun.getAllinvest_type() invest_type_dict = {} for invest_type1 in invest_type_list: invest_type_dict[invest_type1.name] = invest_type1.cname #取得投資資產明細 try: invest_list = invest.objects.all().order_by('-id') except months.DoesNotExist: invest_list = {} #找出投資資產最後一筆的總投入金額, 總餘額 total = fun.getLastinvest_total(thisdate) rest = fun.getLastinvest_rest(total) if request.method == 'POST': #新增投資明細 if 'cash' in request.POST: resp_insertdate = request.POST['insertdate'] resp_invest_type = request.POST['invest_type'] resp_cash = request.POST['cash'] resp_memo = request.POST['memo'] now = fun.getNow() resp_created_at = now # 擷取現在時間 resp_modify_at = now # 擷取現在時間 #計篹總餘額 invest_type1 = invest_type_list.get(name=resp_invest_type) if invest_type1.pn == 'p': rest = int(rest) + int(resp_cash) else: rest = int(rest) - int(resp_cash) #新增投資明細資料 invest.objects.create(datetime=resp_insertdate, invest_type=resp_invest_type, cash=resp_cash, memo=resp_memo, created_at=resp_created_at, modify_at=resp_modify_at) message = '新增成功!' return render( request, 'invest_detail.html', { 'message': message, 'thisdate': thisdate, 'thispage': 'investdetail', 'insertdate': fun.getDate(), 'invest_list': invest_list, 'invest_type_dict': invest_type_dict, 'total': total, 'rest': rest, 'invest_type_list': invest_type_list })
def InvestDetail(request): thisdate = fun.getThisdate(request) message='' invest_type_list = fun.getAllinvest_type() invest_type_dict={} for invest_type1 in invest_type_list: invest_type_dict[invest_type1.name] = invest_type1.cname #取得投資資產明細 try: invest_list = invest.objects.all().order_by('-id') except months.DoesNotExist: invest_list={} #找出投資資產最後一筆的總投入金額, 總餘額 total = fun.getLastinvest_total(thisdate) rest = fun.getLastinvest_rest(total) if request.method == 'POST': #新增投資明細 if 'cash' in request.POST: resp_insertdate = request.POST['insertdate'] resp_invest_type = request.POST['invest_type'] resp_cash = request.POST['cash'] resp_memo = request.POST['memo'] now = fun.getNow() resp_created_at = now # 擷取現在時間 resp_modify_at = now # 擷取現在時間 #計篹總餘額 invest_type1 = invest_type_list.get(name=resp_invest_type) if invest_type1.pn =='p': rest = int(rest) + int(resp_cash) else: rest = int(rest) - int(resp_cash) #新增投資明細資料 invest.objects.create(datetime=resp_insertdate, invest_type=resp_invest_type, cash=resp_cash, memo=resp_memo, created_at=resp_created_at, modify_at=resp_modify_at) message='新增成功!' return render(request,'invest_detail.html', {'message':message ,'thisdate': thisdate ,'thispage': 'investdetail' ,'insertdate':fun.getDate() ,'invest_list':invest_list ,'invest_type_dict':invest_type_dict ,'total':total ,'rest':rest ,'invest_type_list': invest_type_list})
def MonthDetail(request): message='' thisdate = fun.getThisdate(request) #若無本月資料,直接結束並顯示頁面 try: cash_type_list = fun.getAllcash_type() cash_type_dict={} for cash_type1 in cash_type_list: cash_type_dict[cash_type1.name] = cash_type1.cname #取得當月月份明細 try: monthly_list = monthly.objects.filter(YM=thisdate).order_by('-id') except months.DoesNotExist: monthly_list={} #先取得總現金, 總信用卡 total_cash = fun.getLastmonthly_CashTotal(thisdate) total_credit = fun.getLastmonthly_CreditTotal(thisdate) if request.method == 'POST': #新增投資明細 if 'money' in request.POST: resp_insertdate = request.POST['insertdate'] resp_cash_type = request.POST['cash_type'] resp_money = request.POST['money'] resp_memo = request.POST['memo'] now = fun.getNow() resp_created_at = now # 擷取現在時間 resp_modify_at = now # 擷取現在時間 #計算類型&總和 if resp_cash_type=='cash': cash = resp_money credit = 0 total_cash = int(total_cash) + int(cash) else: cash = 0 credit = resp_money total_credit = int(total_credit) + int(credit) #新增月份明細資料 monthly.objects.create(datetime=resp_insertdate, cash_type=resp_cash_type, cash=cash, credit=credit, total_credit=total_credit, total_cash=total_cash, memo=resp_memo, YM=thisdate, created_at=resp_created_at, modify_at=resp_modify_at) message='新增成功!' thismonths = months.objects.filter(YM=thisdate) common_cost = thismonths.latest('id').common_cost #取得本月零用金 rcommon_cost = int(common_cost)- int(total_cash) - int(total_credit) #計算零用金餘額 #更新月份餘額 balance1 = thismonths.latest('id').balance if rcommon_cost < 0: balance1 = int(balance1) + int(rcommon_cost) thismonths.update(balance1=balance1) return render(request,'month_detail.html', {'message':message ,'thisdate': thisdate ,'insertdate':fun.getDate() ,'cash_type_list':cash_type_list ,'cash_type_dict':cash_type_dict ,'monthly_list':monthly_list ,'total_cash':total_cash ,'total_credit':total_credit ,'common_cost':common_cost ,'rcommon_cost':rcommon_cost ,'thispage': 'monthdetail'}) except months.DoesNotExist: return render(request, 'indexnomonth.html', {'message': '' ,'thisdate': thisdate ,'thispage': 'monthdetail' })
def MonthDetail(request): message = '' thisdate = fun.getThisdate(request) #若無本月資料,直接結束並顯示頁面 try: cash_type_list = fun.getAllcash_type() cash_type_dict = {} for cash_type1 in cash_type_list: cash_type_dict[cash_type1.name] = cash_type1.cname #取得當月月份明細 try: monthly_list = monthly.objects.filter(YM=thisdate).order_by('-id') except months.DoesNotExist: monthly_list = {} #先取得總現金, 總信用卡 total_cash = fun.getLastmonthly_CashTotal(thisdate) total_credit = fun.getLastmonthly_CreditTotal(thisdate) if request.method == 'POST': #新增投資明細 if 'money' in request.POST: resp_insertdate = request.POST['insertdate'] resp_cash_type = request.POST['cash_type'] resp_money = request.POST['money'] resp_memo = request.POST['memo'] now = fun.getNow() resp_created_at = now # 擷取現在時間 resp_modify_at = now # 擷取現在時間 #計算類型&總和 if resp_cash_type == 'cash': cash = resp_money credit = 0 total_cash = int(total_cash) + int(cash) else: cash = 0 credit = resp_money total_credit = int(total_credit) + int(credit) #新增月份明細資料 monthly.objects.create(datetime=resp_insertdate, cash_type=resp_cash_type, cash=cash, credit=credit, total_credit=total_credit, total_cash=total_cash, memo=resp_memo, YM=thisdate, created_at=resp_created_at, modify_at=resp_modify_at) message = '新增成功!' thismonths = months.objects.filter(YM=thisdate) common_cost = thismonths.latest('id').common_cost #取得本月零用金 rcommon_cost = int(common_cost) - int(total_cash) - int( total_credit) #計算零用金餘額 #更新月份餘額 balance1 = thismonths.latest('id').balance if rcommon_cost < 0: balance1 = int(balance1) + int(rcommon_cost) thismonths.update(balance1=balance1) return render( request, 'month_detail.html', { 'message': message, 'thisdate': thisdate, 'insertdate': fun.getDate(), 'cash_type_list': cash_type_list, 'cash_type_dict': cash_type_dict, 'monthly_list': monthly_list, 'total_cash': total_cash, 'total_credit': total_credit, 'common_cost': common_cost, 'rcommon_cost': rcommon_cost, 'thispage': 'monthdetail' }) except months.DoesNotExist: return render(request, 'indexnomonth.html', { 'message': '', 'thisdate': thisdate, 'thispage': 'monthdetail' })