Rechnungen an API abfragen, Monatliche Statistik für Umsatz

This commit is contained in:
holger.trampe 2021-01-28 17:48:05 +01:00
parent 9ae3d75fe0
commit 9034360452
7 changed files with 94 additions and 16 deletions

View File

@ -32,8 +32,12 @@
<td>{{ele.start|date:"d.m.Y"}}</td>
<td>{{ele.end|date:"d.m.Y"}}</td>
<td>
{% loadFinalMoneyByAgency ele.agency as fm %}
{{fm|floatformat:2|intcomma}} €
{% loadBillValue ele as fm %}
{% if fm != False %}
{{fm|floatformat:2|intcomma}} €
{% else %}
Fehler bei Rechnungsabfrage (ID {{ele.pk}})
{% endif %}
</td>
<td>
{% if ele.billstatus == "open" %} <i class="far fa-times-circle" style="color: red"></i> {% elif ele.billstatus == "paid" %} <i class="far fa-check-circle" style="color: green"></i> {% endif %}

View File

@ -14,6 +14,26 @@
<div class="chart-container" style="">
<canvas id="all_stats"></canvas>
</div>
<hr>
<h5>Monatliche Umsätze</h5>
<table>
<thead>
<td style="min-width: 80px;">Monat</td>
<td>Umsatz</td>
</thead>
{% for m in money %}
<tr>
<td>
{{m.salesmonthdate|date:"m/Y"}}
</td>
<td>
{{m.value}} €
</td>
</tr>
{% endfor %}
</table>
<hr>
<h5>Zahlenübersicht stand jetzt</h5>
<table>

View File

@ -11,8 +11,9 @@ from datetime import date
import datetime
from adm.models import MainStatistic
register = template.Library()
import requests
from django.conf import settings
import json
'''
Agenturdaten zurückgeben
@ -43,3 +44,33 @@ def getAgencyGroupName(group):
@register.simple_tag
def loadAboCount():
return len(Agency.objects.filter(paymentplan=1))
# Return an Tax-Free Value of bill
@register.simple_tag
def loadBillValue(bill):
headers = {
'Authorization': 'Bearer ' + settings.LEX_API,
'Content-Type': 'application/json',
'Accept': 'application/json',
}
lexdata = {
"renderType" : "pdf"
}
json_data = json.dumps(lexdata)
returnvalue = False
try:
r_final = requests.get("https://api.lexoffice.io/v1/invoices/"+bill.lexid, data=json_data, headers=headers)
billdata = json.loads(r_final.text)
returnvalue = billdata['totalPrice']['totalNetAmount']
except:
pass
return returnvalue

View File

@ -4,7 +4,7 @@ from django.shortcuts import render, redirect, reverse
from django.urls import reverse_lazy
from django.conf import settings
from django.http import HttpResponseRedirect,HttpResponse, JsonResponse
from .models import MainStatistic
from .models import MainStatistic, MainSalesMonth
from django.contrib.auth.models import User
from chat.models import ChatMessage
from users.models import Agency, AgencyBills, RegNotfallhilfe
@ -28,6 +28,7 @@ import requests
from django.template.loader import render_to_string
from cloud.models import DataFile
import math
import requests
'''
Prüfung, ob angemeldeter User Mitarbeiterstatus hat. IMMER PER DISPATCH EINBAUEN!
'''
@ -106,7 +107,8 @@ class AdmMain(TemplateView):
"agencycount" : len(Agency.objects.all()),
"usercount" : len(User.objects.all().exclude(is_staff=True, is_superuser=True)),
"standardcount" : len(Standards.objects.all()),
"chatmessagescount" : len(ChatMessage.objects.all())
"chatmessagescount" : len(ChatMessage.objects.all()),
"money" : MainSalesMonth.objects.all(),
})
return context
@ -489,17 +491,16 @@ def statisticCronJob(request, code):
# COUNT INVOICES WHEN FIRST DAY OF MONTH
lastmonth = today - timedelta(days=today.day)
#if today.day == 1:
if today.day == 28:
monthvalue = 0.0
if today.day == 1:
for bill in AgencyBills.objects.filter(billdate__month=lastmonth.month):
pass
# TASK: Hier den Rechungsbeitrag abfragen und aufaddieren, dazu bitte einmal Rechnungen aus der Prod abfragen ;)
newvalue = getLexOfficeBill(bill.lexid)
if newvalue != False:
monthvalue += newvalue
nm = MainSalesMonth(value=monthvalue)
nm.save()
newMainS = MainStatistic(agencys=agencycount,users=usercount,standards=standardcount,chatmessages=chatmesscount, active_abos=abocount, absenceobjects=absenceobjects, user_active_timemanagement=user_active_timemanagement, organizerobjects=organizerobjects, agency_recoverobjects=agency_recoverobjects, allfiles=allfiles, allfiles_storage=allfiles_storage, logins=logins)
newMainS.save()
@ -509,7 +510,29 @@ def statisticCronJob(request, code):
data.update({"status" : "failed"})
return JsonResponse(data)
# Return an Tax-Free Value of bill
def getLexOfficeBill(billid):
headers = {
'Authorization': 'Bearer ' + settings.LEX_API,
'Content-Type': 'application/json',
'Accept': 'application/json',
}
lexdata = {
"renderType" : "pdf"
}
json_data = json.dumps(lexdata)
returnvalue = False
try:
r_final = requests.get("https://api.lexoffice.io/v1/invoices/"+billid, data=json_data, headers=headers)
billdata = json.loads(r_final.text)
returnvalue = billdata['totalPrice']['totalNetAmount']
except:
pass
return returnvalue