def invoice_add(request): results = {} if request.is_ajax(): up = request.user.userprofile tp = TypePrice.objects.filter(id=request.POST['type_price'][0])[0] up.save() if tp: if len(up.current_doctor.invoices.all()): i = up.current_doctor.invoices.order_by('-date_end')[0] if i.date_end > datetime.date(datetime.today()): f_day = i.date_end + relativedelta(days=+1) active = False else: f_day = datetime.today() active = True else: f_day = datetime.today() active = True new_invoice = Invoice(type_price=tp, date_start=f_day, date_end=f_day + relativedelta(months=+tp.num_months), price_exVAT=int(tp.price_exVAT), active=active) new_invoice.save() up.current_doctor.invoices.add(new_invoice) results['return'] = True results['id'] = new_invoice.id results['type_price'] = str(new_invoice.type_price) results['date_start'] = new_invoice.date_start results['date_end'] = new_invoice.date_end else: results['return'] = False else: results['return'] = False return HttpResponse(json.dumps(results))
def home(request): c = {} if request.user.is_authenticated(): if request.user.is_superuser: # admin c['list'] = Doctor.objects.all() return render(request, 'list.tpl', c) else: # TODO MUST BE RUN BY A CRON DAEMON old_i = request.user.userprofile.current_doctor.invoices.filter( active=True) i = request.user.userprofile.current_doctor.invoices.filter( date_start__lte=date.today(), date_end__gte=date.today()) if len(i) and len(old_i): current_i = i[0] if old_i is not current_i: old_i[0].active = False old_i[0].save() current_i.active = True current_i.save() new_pi = PrintInvoice( i[0], request.user.userprofile.current_doctor) new_pi.save() # TODO send mail avec invoice else: if request.user.userprofile.current_doctor.can_recharge: old_i[0].active = False old_i[0].save() f_day = datetime.today() new_i = Invoice( type_price=old_i[0].type_price, date_start=f_day, date_end=f_day + relativedelta(months=+old_i.type_price.num_months), price_exVAT=int(old_i[0].type_price.price_exVAT), active=True) new_i.save() new_pi = PrintInvoice( new_i, request.user.userprofile.current_doctor) new_pi.save() # TODO send mail avec invoice else: # TODO send mail pour dire va mettre à jour sinon dans 7 jours, on cloture # gérer la cloture print "HERE" # ---------------------- # TODO préparer les data pour le dashboard c['plan'] = request.user.userprofile.current_doctor.slots.filter( date=datetime.now()).order_by("id") c['invoice'] = request.user.userprofile.current_doctor.invoices.filter( active=True)[0] date_max = request.user.userprofile.current_doctor.slots.all( ).order_by("date") c['date_max'] = date_max[0].date if date_max else None return render(request, 'dashboard.tpl', c) else: c['list'] = Doctor.objects.filter(view_in_list=True) return render(request, 'list.tpl', c)
def home(request): c = {} if request.user.is_authenticated(): if request.user.is_superuser: # admin c['list'] = Doctor.objects.all() return render(request, 'list.tpl', c) else: # TODO MUST BE RUN BY A CRON DAEMON old_i = request.user.userprofile.current_doctor.invoices.filter(active=True) i = request.user.userprofile.current_doctor.invoices.filter(date_start__lte=date.today(), date_end__gte=date.today()) if len(i) and len(old_i): current_i = i[0] if old_i is not current_i: old_i[0].active = False old_i[0].save() current_i.active = True current_i.save() new_pi = PrintInvoice(i[0], request.user.userprofile.current_doctor) new_pi.save() # TODO send mail avec invoice else: if request.user.userprofile.current_doctor.can_recharge: old_i[0].active = False old_i[0].save() f_day = datetime.today() new_i = Invoice(type_price=old_i[0].type_price, date_start=f_day, date_end=f_day + relativedelta(months=+old_i.type_price.num_months), price_exVAT=int(old_i[0].type_price.price_exVAT), active=True) new_i.save() new_pi = PrintInvoice(new_i, request.user.userprofile.current_doctor) new_pi.save() # TODO send mail avec invoice else: # TODO send mail pour dire va mettre à jour sinon dans 7 jours, on cloture # gérer la cloture print "HERE" # ---------------------- # TODO préparer les data pour le dashboard c['plan'] = request.user.userprofile.current_doctor.slots.filter(date=datetime.now()).order_by("id") c['invoice'] = request.user.userprofile.current_doctor.invoices.filter(active=True)[0] date_max = request.user.userprofile.current_doctor.slots.all().order_by("date") c['date_max'] = date_max[0].date if date_max else None return render(request, 'dashboard.tpl', c) else: c['list'] = Doctor.objects.filter(view_in_list=True) return render(request, 'list.tpl', c)