Beispiel #1
0
def list_treatments(request, customer_id):
    ctx = {}
    patient = get_object_or_404(Patient, customer=customer_id) 
    ctx['patient'] = patient
    ctx['treatments'] = patient.treatment_set.all().order_by('-id')
    return render_response(
        request,
        'treatment_list.html',
        ctx
    )
Beispiel #2
0
def add_customer(request):
    ctx = {}
    redirect_to = reverse('jazzpos.views.list_customers')
    initial = {
        'store': request.session['store_id'],
        'customer_type': 'patient',
    }
    ctx['form'] = process_form(request,
                               CustomerForm,
                               initial=initial,
                               redirect_to=redirect_to)
    return render_response(request, 'customer_add.html', ctx)
Beispiel #3
0
def list_customers(request):
    ctx = {}
    qs = Customer.objects.all()

    if request.GET.get('q', None) is not None:
        form = TextSearchForm(request.GET)
        if form.is_valid():
            q = form.cleaned_data['q']
            qs = qs.filter(Q(name__icontains=q) | Q(patient__icno=q))

    ctx['customer_list'] = qs.order_by('-id')

    return render_response(request, 'jazzpos/customer_list.html', ctx)
Beispiel #4
0
def add_customer(request):
    ctx = {}
    redirect_to = reverse('jazzpos.views.list_customers')
    initial = {
        'store': request.session['store_id'],
        'customer_type': 'patient',
    }
    ctx['form'] = process_form(request, CustomerForm, initial=initial, redirect_to=redirect_to)
    return render_response(
        request,
        'customer_add.html',
        ctx
    )
Beispiel #5
0
def list_payments(request, order_id):
    ctx = {}
    order = get_object_or_404(pos_models.Order, pk=order_id)
    payments = Payment.objects.filter(order=order_id)
    initial = {
        'order_id': order_id,
    }

    ctx['payments'] = payments
    ctx['order'] = order
    ctx['customer'] = order.customer
    ctx['payment_form'] = process_form(request, PaymentForm, initial=initial)
    return render_response(request, 'xpos/payment_list.html', ctx)
Beispiel #6
0
def switch_store(request, store_id=None):
    try:
        store_id = int(store_id)
    except:
        store_id = None

    if store_id is None:
        return render_response(
            request,
            'stores_switch.html',
        )

    store = get_object_or_404(Store, pk=store_id)
    redirect_to = request.GET.get('redirect_to', '/')
    request.session['store_id'] = store.id
    return redirect(redirect_to)
Beispiel #7
0
def switch_store(request, store_id=None):
    try:
        store_id = int(store_id)
    except:
        store_id = None

    if store_id is None:
        return render_response(
            request,
            'stores_switch.html',
        )

    store = get_object_or_404(Store, pk=store_id)
    redirect_to = request.GET.get('redirect_to', '/')
    request.session['store_id'] = store.id
    return redirect(redirect_to)
Beispiel #8
0
def add_treatment(request, patient_id):
    patient = get_object_or_404(Patient, pk=patient_id)
    ctx = {}
    redirect_to = reverse('jazzpos.views.list_treatments', args=(patient.customer_id,))
    initial = {
        'store': request.session['store_id'],
        'patient': patient,
    }
    ctx['form'] = process_form(request, TreatmentForm, initial=initial, redirect_to=redirect_to)
    ctx['patient'] = patient
    ctx['action'] = 'Tambah'
    return render_response(
        request,
        'treatment_edit.html',
        ctx
    )
Beispiel #9
0
def add_treatment(request, patient_id):
    patient = get_object_or_404(Patient, pk=patient_id)
    ctx = {}
    redirect_to = reverse('jazzpos.views.list_treatments',
                          args=(patient.customer_id, ))
    initial = {
        'store': request.session['store_id'],
        'patient': patient,
    }
    ctx['form'] = process_form(request,
                               TreatmentForm,
                               initial=initial,
                               redirect_to=redirect_to)
    ctx['patient'] = patient
    ctx['action'] = 'Tambah'
    return render_response(request, 'treatment_edit.html', ctx)
Beispiel #10
0
def list_payments(request, order_id):
    ctx = {}
    order = get_object_or_404(pos_models.Order, pk=order_id)
    payments = Payment.objects.filter(order=order_id)
    initial = {
        'order_id': order_id,
    }

    ctx['payments'] = payments
    ctx['order'] = order
    ctx['customer'] = order.customer
    ctx['payment_form'] = process_form(request, PaymentForm, initial=initial)
    return render_response(
        request,
        'xpos/payment_list.html',
        ctx
    )
Beispiel #11
0
def list_customers(request):
    ctx = {}
    qs = Customer.objects.all()

    if request.GET.get('q', None) is not None:
        form = TextSearchForm(request.GET)
        if form.is_valid():
            q = form.cleaned_data['q']
            qs = qs.filter(Q(name__icontains=q) | Q(patient__icno=q))

    ctx['customer_list'] = qs.order_by('-id')

    return render_response(
        request,
        'jazzpos/customer_list.html',
        ctx
    )
Beispiel #12
0
def view_statement(request, customer_id):
    from xpos.utils import sql
    from django.db.models import Sum, F
    from xpos.models import get_previous_order_total, get_previous_payment_total
    from xpos.models import get_all_transactions

    ctx = {}
    customer = get_object_or_404(Customer, pk=customer_id)
    current_date = datetime.now()
    month = request.GET.get('month', current_date.month)
    year = request.GET.get('year', current_date.year)
    first_day, last_day = calendar.monthrange(int(year), int(month))
    fdom = datetime.strptime('%s-%s-%s 00:00:00' % (year, month, 1), '%Y-%m-%d %H:%M:%S')
    ldom = datetime.strptime('%s-%s-%s 23:59:59' % (year, month, last_day), '%Y-%m-%d %H:%M:%S')

    previous_order_total = get_previous_order_total(customer, fdom, request.store)
    previous_payment_total = get_previous_payment_total(customer, fdom, request.store)
    current_order_total = get_previous_order_total(customer, ldom, request.store)
    current_payment_total = get_previous_payment_total(customer, ldom, request.store)

    previous_balance = previous_payment_total - previous_order_total
    current_balance = current_payment_total - current_order_total
    ctx['previous_balance'] = previous_balance
    ctx['current_balance'] = current_balance
    ctx['customer'] = customer
    transactions = get_all_transactions(request.store, customer, start_date=fdom, end_date=ldom)

    if len(transactions) > 0:
        total_credit = sum([txn['amount'] for txn in transactions if txn['type'] == 'credit'])
        total_debit = sum([txn['amount'] for txn in transactions if txn['type'] == 'debit'])
    else:
        total_credit = Decimal('0.00')
        total_debit = Decimal('0.00')

    ctx['transactions'] = transactions
    ctx['total_debit'] = total_debit
    ctx['total_credit'] = total_credit
    ctx['current_order_total'] = total_debit + previous_balance
    
    return render_response(
        request,
        'xpos/account_statement.html',
        ctx
    )
Beispiel #13
0
def edit_patient(request, customer_id):
    patient = get_object_or_404(Patient, customer=customer_id)

    # allow only customer own store except for admin
    if not request.user.is_superuser:
        if patient.customer.store != request.store:
            return HttpResponseForbidden()

    ctx = {}
    redirect_to = reverse('jazzpos.views.view_customer', args=(customer_id,))
    initial = {
        'store': request.session['store_id'],
    }
    ctx['form'] = process_form(request, PatientForm, initial=initial, redirect_to=redirect_to, instance=patient)
    ctx['patient'] = patient
    return render_response(
        request,
        'patient_edit.html',
        ctx
    )
Beispiel #14
0
def edit_patient(request, customer_id):
    patient = get_object_or_404(Patient, customer=customer_id)

    # allow only customer own store except for admin
    if not request.user.is_superuser:
        if patient.customer.store != request.store:
            return HttpResponseForbidden()

    ctx = {}
    redirect_to = reverse('jazzpos.views.view_customer', args=(customer_id, ))
    initial = {
        'store': request.session['store_id'],
    }
    ctx['form'] = process_form(request,
                               PatientForm,
                               initial=initial,
                               redirect_to=redirect_to,
                               instance=patient)
    ctx['patient'] = patient
    return render_response(request, 'patient_edit.html', ctx)
Beispiel #15
0
def show_order(request, order_id):
    order = get_object_or_404(pos_models.Order, pk=order_id)
    payments = Payment.objects.filter(order=order_id)
    initial = {
        'order_id': order_id,
    }
    response_dict = {
        "order_item_form": process_form(request, OrderItemForm, initial=initial),
        "order": order,
        "customer": order.customer,
        "payments": payments,
        "payment_form": process_form(request, PaymentForm, initial=initial),
        "confirm_form": process_form(request, OrderConfirmForm, initial=initial),
        "cancel_form": process_form(request, OrderCancelForm, initial=initial),
    }

    return render_response(
        request,
        'xpos/order_detail.html',
        response_dict
    )
Beispiel #16
0
def show_order(request, order_id):
    order = get_object_or_404(pos_models.Order, pk=order_id)
    payments = Payment.objects.filter(order=order_id)
    initial = {
        'order_id': order_id,
    }
    response_dict = {
        "order_item_form": process_form(request,
                                        OrderItemForm,
                                        initial=initial),
        "order": order,
        "customer": order.customer,
        "payments": payments,
        "payment_form": process_form(request, PaymentForm, initial=initial),
        "confirm_form": process_form(request,
                                     OrderConfirmForm,
                                     initial=initial),
        "cancel_form": process_form(request, OrderCancelForm, initial=initial),
    }

    return render_response(request, 'xpos/order_detail.html', response_dict)
Beispiel #17
0
def edit_treatment(request, treatment_id):
    treatment = get_object_or_404(Treatment, pk=treatment_id)

    # allow only customer own store except for admin
    if not request.user.is_superuser:
        if treatment.store != request.store:
            return HttpResponseForbidden()

    ctx = {}
    redirect_to = reverse('jazzpos.views.list_treatments', args=(treatment.patient.customer_id,))
    initial = {
        'store': request.session['store_id'],
    }
    ctx['form'] = process_form(request, TreatmentForm, initial=initial, redirect_to=redirect_to, instance=treatment)
    ctx['treatment'] = treatment
    ctx['patient'] = treatment.patient
    ctx['action'] = 'Edit'
    return render_response(
        request,
        'treatment_edit.html',
        ctx
    )
Beispiel #18
0
def edit_treatment(request, treatment_id):
    treatment = get_object_or_404(Treatment, pk=treatment_id)

    # allow only customer own store except for admin
    if not request.user.is_superuser:
        if treatment.store != request.store:
            return HttpResponseForbidden()

    ctx = {}
    redirect_to = reverse('jazzpos.views.list_treatments',
                          args=(treatment.patient.customer_id, ))
    initial = {
        'store': request.session['store_id'],
    }
    ctx['form'] = process_form(request,
                               TreatmentForm,
                               initial=initial,
                               redirect_to=redirect_to,
                               instance=treatment)
    ctx['treatment'] = treatment
    ctx['patient'] = treatment.patient
    ctx['action'] = 'Edit'
    return render_response(request, 'treatment_edit.html', ctx)
Beispiel #19
0
def view_reports(request):
    from xpos.models import get_all_transactions
    from xpos.models import calculate_total_checque_payment
    from xpos.models import calculate_total_cash_payment
    from xpos.models import calculate_total_sale

    if request.GET.get('format', None) == 'csv':
        template = 'xpos/reports.csv'
        output_format = 'csv'
    else:
        template = 'xpos/reports.html'
        output_format = 'html'

    ctx = {}
    current_date = datetime.now()
    day = request.GET.get('day', None)
    month = request.GET.get('month', current_date.month)
    year = request.GET.get('year', current_date.year)
    first_day, last_day = calendar.monthrange(int(year), int(month))

    if day:
        fdom = datetime.strptime('%s-%s-%s 00:00:00' % (year, month, day), '%Y-%m-%d %H:%M:%S')
        ldom = datetime.strptime('%s-%s-%s 23:59:59' % (year, month, day), '%Y-%m-%d %H:%M:%S')
    else:
        first_day, last_day = calendar.monthrange(int(year), int(month))
        fdom = datetime.strptime('%s-%s-%s 00:00:00' % (year, month, 1), '%Y-%m-%d %H:%M:%S')
        ldom = datetime.strptime('%s-%s-%s 23:59:59' % (year, month, last_day), '%Y-%m-%d %H:%M:%S')

    transactions = get_all_transactions(request.store, start_date=fdom, end_date=ldom)
    if len(transactions) > 0:
        total_cash = calculate_total_cash_payment(transactions)
        total_cheque = calculate_total_checque_payment(transactions)
        total_sale = calculate_total_sale(transactions)
    else:
        total_cash = Decimal('0.00')
        total_cheque = Decimal('0.00')
        total_sale = Decimal('0.00')

    ctx['transactions'] = transactions
    ctx['total_sale'] = total_sale
    ctx['total_cash'] = total_cash
    ctx['total_cheque'] = total_cheque
    ctx['total_payment'] = total_cash + total_cheque
    ctx['report_month'] = month
    ctx['report_year'] = year

    if output_format == 'csv':
        response = HttpResponse(mimetype='text/csv')
        response['Content-Disposition'] = 'attachment; filename=jazzpos.csv'
        writer = csv.writer(response)
        writer.writerow(['Tarikh', 'Transaksi', 'Belian', 'Bayaran Tunai', 'Bayaran Cek'])
        for transaction in transactions:
            csv_row = []
            csv_row.append(transaction['date'].strftime('%d-%m-%Y'))
            csv_row.append(transaction['description'])
            if transaction['type'] == 'debit':
                csv_row.append(transaction['amount'])
            else:
                csv_row.append('')
            if transaction.get('method', None) == 'TUNAI':
                csv_row.append(transaction['amount'])
            else:
                csv_row.append('')
            if transaction.get('method', None) == 'CEK':
                csv_row.append(transaction['amount'])
            else:
                csv_row.append('')

            writer.writerow(csv_row)
        return response

    return render_response(
        request,
        'xpos/reports.html',
        ctx
    )
Beispiel #20
0
def profile(request):
    return render_response(request, 'kecupuapp_base/profile.html')
Beispiel #21
0
def index(request):
    return render_response(request, 'index.html')
Beispiel #22
0
def view_statement(request, customer_id):
    from xpos.utils import sql
    from django.db.models import Sum, F
    from xpos.models import get_previous_order_total, get_previous_payment_total
    from xpos.models import get_all_transactions

    ctx = {}
    customer = get_object_or_404(Customer, pk=customer_id)
    current_date = datetime.now()
    month = request.GET.get('month', current_date.month)
    year = request.GET.get('year', current_date.year)
    first_day, last_day = calendar.monthrange(int(year), int(month))
    fdom = datetime.strptime('%s-%s-%s 00:00:00' % (year, month, 1),
                             '%Y-%m-%d %H:%M:%S')
    ldom = datetime.strptime('%s-%s-%s 23:59:59' % (year, month, last_day),
                             '%Y-%m-%d %H:%M:%S')
    ctx['years'] = range(2013, 2020)
    ctx['selected_year'] = year

    if 'date_start' in request.GET or 'date_end' in request.GET:
        form = DateSearchForm(request.GET)
        if form.is_valid():
            date_start = form.cleaned_data['date_start']
            date_end = form.cleaned_data['date_end']
        else:
            date_start = fdom
            date_end = ldom
    else:
        form = DateSearchForm()
        date_start = fdom
        date_end = ldom

    ctx['search_form'] = form

    previous_order_total = get_previous_order_total(customer, date_start,
                                                    request.store)
    previous_payment_total = get_previous_payment_total(
        customer, date_start, request.store)
    current_order_total = get_previous_order_total(customer, date_end,
                                                   request.store)
    current_payment_total = get_previous_payment_total(customer, date_end,
                                                       request.store)

    previous_balance = previous_payment_total - previous_order_total
    current_balance = current_payment_total - current_order_total
    ctx['previous_balance'] = previous_balance
    ctx['current_balance'] = current_balance
    ctx['customer'] = customer

    transactions = get_all_transactions(request.store,
                                        customer,
                                        start_date=date_start,
                                        end_date=date_end)

    if len(transactions) > 0:
        total_credit = sum(
            [txn['amount'] for txn in transactions if txn['type'] == 'credit'])
        total_debit = sum(
            [txn['amount'] for txn in transactions if txn['type'] == 'debit'])
    else:
        total_credit = Decimal('0.00')
        total_debit = Decimal('0.00')

    ctx['transactions'] = transactions
    ctx['total_debit'] = total_debit
    ctx['total_credit'] = total_credit
    # assume total_debit not paid yet, so it's negative
    ctx['current_order_total'] = abs(-(total_debit) + previous_balance)

    return render_response(request, 'xpos/account_statement.html', ctx)
Beispiel #23
0
def view_statement(request, customer_id):
    from xpos.utils import sql
    from django.db.models import Sum, F
    from xpos.models import get_previous_order_total, get_previous_payment_total
    from xpos.models import get_all_transactions

    ctx = {}
    customer = get_object_or_404(Customer, pk=customer_id)
    current_date = datetime.now()
    month = request.GET.get('month', current_date.month)
    year = request.GET.get('year', current_date.year)
    first_day, last_day = calendar.monthrange(int(year), int(month))
    fdom = datetime.strptime('%s-%s-%s 00:00:00' % (year, month, 1), '%Y-%m-%d %H:%M:%S')
    ldom = datetime.strptime('%s-%s-%s 23:59:59' % (year, month, last_day), '%Y-%m-%d %H:%M:%S')
    ctx['years'] = range(2013, 2020)
    ctx['selected_year'] = year

    if 'date_start' in request.GET or 'date_end' in request.GET:
        form = DateSearchForm(request.GET)
        if form.is_valid():
            date_start = form.cleaned_data['date_start']
            date_end = form.cleaned_data['date_end']
        else:
            date_start = fdom
            date_end = ldom
    else:
        form = DateSearchForm()
        date_start = fdom
        date_end = ldom

    ctx['search_form'] = form


    previous_order_total = get_previous_order_total(customer, date_start, request.store)
    previous_payment_total = get_previous_payment_total(customer, date_start, request.store)
    current_order_total = get_previous_order_total(customer, date_end, request.store)
    current_payment_total = get_previous_payment_total(customer, date_end, request.store)

    previous_balance = previous_payment_total - previous_order_total
    current_balance = current_payment_total - current_order_total
    ctx['previous_balance'] = previous_balance
    ctx['current_balance'] = current_balance
    ctx['customer'] = customer

    transactions = get_all_transactions(
            request.store,
            customer,
            start_date=date_start,
            end_date=date_end
        )

    if len(transactions) > 0:
        total_credit = sum([txn['amount'] for txn in transactions if txn['type'] == 'credit'])
        total_debit = sum([txn['amount'] for txn in transactions if txn['type'] == 'debit'])
    else:
        total_credit = Decimal('0.00')
        total_debit = Decimal('0.00')

    ctx['transactions'] = transactions
    ctx['total_debit'] = total_debit
    ctx['total_credit'] = total_credit
    # assume total_debit not paid yet, so it's negative
    ctx['current_order_total'] = abs(-(total_debit) + previous_balance)
    
    return render_response(
        request,
        'xpos/account_statement.html',
        ctx
    )
Beispiel #24
0
def index(request):
    return render_response(request, 'index.html')
Beispiel #25
0
def list_treatments(request, customer_id):
    ctx = {}
    patient = get_object_or_404(Patient, customer=customer_id)
    ctx['patient'] = patient
    ctx['treatments'] = patient.treatment_set.all().order_by('-id')
    return render_response(request, 'treatment_list.html', ctx)
Beispiel #26
0
 def profile(self, request):
     from kecupuapp_base.shortcuts import render_response
     return render_response(request, 'kecupuapp_base/profile.html')
Beispiel #27
0
 def profile(self, request):
     from kecupuapp_base.shortcuts import render_response 
     return render_response(request, 'kecupuapp_base/profile.html')