Esempio n. 1
0
def delete_payment(request,id=0):
	user = get_user(request)
	if not user.is_superuser:
		return redirect('/fobiddn/')
		
	if request.method == 'POST':
		delete_accepted = False
		payment = SellPayment.objects.get(pk=id)
		sale = payment.sale
		
		if payment.payment_method.name.lower() == 'credit':
			delete_accepted = True
		elif payment.payment_method.name.lower() == 'cash':
			delete_accepted = True
			#add cash out
			desc = f'Sale Payment Revert: {payment.sale.customer}'
			cash_out = CashOut(desc=desc,date=payment.date,amount=payment.amount)
			cashflow.make_cash_out(cash_out)
		elif payment.payment_method.name.lower() == 'check':
			if payment.account == None:
				delete_accepted = False
			else:
				delete_accepted = True
				#add withdraw
				desc = f'Sale Check Returnd: {payment.ref_num}'
				withdraw = Withdraw(account=payment.account, 
									desc=desc, 
									date=payment.date, 
									amount=payment.amount, 
									payment_method=payment.payment_method, 
									ref_num=payment.ref_num)
				bank.make_withdraw(withdraw)

		else:
			#add withdraw
			if payment.account == None:
				delete_accepted = False
			else:
				delete_accepted = True
				desc = f'Sale Payment Revert: {payment.sale.customer}'
				withdraw = Withdraw(account=payment.account, 
									desc=desc, 
									date=payment.date, 
									amount=payment.amount, 
									payment_method=payment.payment_method, 
									ref_num=payment.ref_num)
				bank.make_withdraw(withdraw)

		if delete_accepted:
			sale.paid = False
			sale.save()
			payment.delete()
		else:
			messages.add_message(request,messages.WARNING, 'Somthing went wrong!')
		url = f'/inventory-manager/sales/'
		return redirect(url)
Esempio n. 2
0
def delete_otherincome(request, id=0):
    user = get_user(request)
    if not user.is_superuser:
        return redirect('/fobiddn/')

    if request.method == 'POST':
        other_income = OtherIncome.objects.get(pk=id)
        delete_accepted = False

        if other_income.payment_method.name.lower() == 'credit':
            delete_accepted = True
        elif other_income.payment_method.name.lower() == 'credit':
            delete_accepted = True
        elif other_income.payment_method.name.lower() == 'cash':
            delete_accepted = True
            # add cash out
            desc = f'Other Income Revert: {other_income.name}'
            cash_out = CashOut(desc=desc,
                               date=other_income.date,
                               amount=other_income.amount)
            cashflow.make_cash_out(cash_out)
        elif other_income.payment_method.name.lower() == 'check':
            if other_income.account == None:
                delete_accepted = False
            else:
                delete_accepted = True
                # add withdraw
                desc = f'Returned Check: {other_income.ref_num}'
                withdraw = Withdraw(account=other_income.account,
                                    desc=desc,
                                    date=other_income.date,
                                    amount=other_income.amount,
                                    payment_method=other_income.payment_method,
                                    ref_num=other_income.ref_num)
                bank.make_withdraw(withdraw)
        else:
            if other_income.account == None:
                delete_accepted = False
            else:
                delete_accepted = True
                # add withdraw
                desc = f'Other Income Revert: {other_income.ref_num}'
                withdraw = Withdraw(account=other_income.account,
                                    desc=desc,
                                    date=other_income.date,
                                    amount=other_income.amount,
                                    payment_method=other_income.payment_method,
                                    ref_num=other_income.ref_num)
                bank.make_withdraw(withdraw)

        if delete_accepted:
            other_income.delete()
        messages.add_message(request, messages.WARNING, 'Somthing went wrong!')
        return redirect('/inventory-manager/other-incomes/')
def make_deposit(deposit):

    if deposit.payment_method.name.lower() == 'cash':
        if deposit.amount == None:
            return None
        else:
            deposit.save()
            acc = deposit.account
            acc.amount += deposit.amount
            acc.save()
            #make cash out
            cash_out = CashOut(desc=deposit.desc,
                               date=deposit.date,
                               amount=deposit.amount)
            cashflow.make_cash_out(cash_out)
            return True

    elif deposit.payment_method.name.lower() == 'check':
        if deposit.ref_num == None:
            return None
        else:
            check = None
            try:
                check = Check.objects.get(ref_num=deposit.ref_num)
            except:
                return None
            if check:
                deposit.amount = check.amount
                acc = deposit.account
                acc.amount += deposit.amount

                acc.save()
                deposit.save()
                check.delete()

                return True
            else:
                return None
    else:
        if deposit.amount == None:
            return None
        else:
            deposit.save()
            acc = deposit.account
            acc.amount += deposit.amount
            acc.save()
            return True
def issue_pettycash(request):
    if request.method == 'POST':
        form = PettyCashIssueForm(request.POST)
        if form.is_valid():
            issue = form.save()
            cash = get_pettycash_object()
            if cash:
                cash.amount += issue.amount
                cash_out = CashOut(desc='Petty Cash Issue',
                                   date=issue.date,
                                   amount=issue.amount)
                make_cash_out(cash_out)
            else:
                cash = PettyCash(id=1, amount=issue.amount)
            cash.save()
            return redirect('/finance-manager/pettycash-issuings/')
    else:
        form = PettyCashIssueForm()
        context = {'formname': 'Issue Petty Cash', 'form': form}
        return render(request, 'finance_manager/pettycash/form_template.html',
                      context)
def add_payment(request, id=0):
    if request.method == 'POST':
        form = AddBuyPaymentForm(request.POST)

        payment_accepted = False
        payment = None

        if form.is_valid():
            payment = form.save()
            receive = payment.buy
            payments = BuyPayment.objects.filter(buy=receive)

            total_payment = 0
            last_payment = None

            for payment in payments:
                total_payment += payment.amount
                last_payment = payment

            if total_payment > receive.amount:
                ddt = total_payment - receive.amount
                last_payment.amount -= ddt

            payment.amount = last_payment.amount

            payment_method = payment.payment_method
            ref_num = payment.ref_num
            eff_date = payment.eff_date

            if payment_method.name.lower() == 'credit':
                payment_accepted = True
            elif payment_method.name.lower() == 'cash':
                payment_accepted = True
                #add cash out
                desc = f'Receive Payment: {payment.buy.supplire}'
                cash_out = CashOut(desc=desc,
                                   date=payment.date,
                                   amount=payment.amount)
                cashflow.make_cash_out(cash_out)
            elif payment_method.name.lower() == 'check':
                if ref_num == None or eff_date == None or payment.account == None:
                    payment_accepted = False
                else:
                    payment_accepted = True
                    #add withdraw
                    desc = f'Receive Check Payment: {payment.ref_num}'
                    withdraw = Withdraw(account=payment.account,
                                        desc=desc,
                                        date=payment.date,
                                        amount=payment.amount,
                                        payment_method=payment.payment_method,
                                        ref_num=payment.ref_num)
                    bank.make_withdraw(withdraw)
            else:
                payment_accepted = True
                #add withdraw
                desc = f'Receive Payment: {payment.buy.supplire}'
                withdraw = Withdraw(account=payment.account,
                                    desc=desc,
                                    date=payment.date,
                                    amount=payment.amount,
                                    payment_method=payment.payment_method,
                                    ref_num=payment.ref_num)
                bank.make_withdraw(withdraw)

            if payment_accepted:
                payment.save()
                last_payment.save()

                if total_payment >= receive.amount:
                    receive.paid = True
                    receive.save()
            else:
                payment.delete()
                messages.add_message(request, messages.WARNING,
                                     'Invalid Payment Details')

            return redirect('/inventory-manager/receives/')
    else:
        receive = Buy.objects.get(pk=id)
        data = {
            'buy': receive,
            'date': receive.date,
            'amount': receive.amount,
        }
        form = AddBuyPaymentForm(data)
        context = {'formname': 'Add Payment', 'form': form}
        return render(request, 'inventory_manager/material/form_template.html',
                      context)
Esempio n. 6
0
def add_salery(request, id=0):
    if request.method == 'POST':
        if id == 0:
            form = AddSaleryForm(request.POST)
        else:
            salery = Salery.objects.get(pk=id)
            form = AddSaleryForm(request.POST, instance=salery)

        payment_accepted = False

        if form.is_valid():
            salery = form.save(commit=False)

            worked_days = salery.worked_days
            rate = salery.rate

            leave_ddt = salery.leave_ddt
            other_ddt = salery.other_ddt
            other_payments = salery.other_payments

            if salery.employee.is_permenet:
                salery_amount = salery.employee.basic_salery

            else:
                if worked_days == None or rate == None:
                    payment_accepted = False
                    return redirect('/inventory-manager/salery/')
                else:
                    salery_amount = rate * worked_days

            if other_payments:
                salery_amount += other_payments

            if leave_ddt:
                salery_amount -= leave_ddt

            if other_ddt:
                salery_amount -= other_ddt

            #adding salery
            salery.amount = salery_amount

            payment_method = salery.payment_method
            ref_num = salery.ref_num
            eff_date = salery.eff_date

            if payment_method.name.lower() == 'credit':
                payment_accepted = True
                salery.paid = False
            elif payment_method.name.lower() == 'cash':
                payment_accepted = True
                #add cash out
                desc = f'Salery Payment: emp_code - {salery.employee.code}'
                cash_out = CashOut(desc=desc,
                                   date=salery.date,
                                   amount=salery.amount)
                cashflow.make_cash_out(cash_out)
                salery.paid = True

            elif payment_method.name.lower() == 'check':
                if ref_num == None or eff_date == None:
                    payment_accepted = False
                else:
                    payment_accepted = True
                    # make Withdraw
                    desc = f'Salery Check Payment: emp_code - {salery.employee.code}'
                    withdraw = Withdraw(account=salery.account,
                                        desc=desc,
                                        date=salery.date,
                                        amount=salery.amount,
                                        payment_method=salery.payment_method,
                                        ref_num=salery.ref_num)
                    bank.make_withdraw(withdraw)
                    salery.paid = True
            else:
                payment_accepted = True
                #make withdraw
                desc = f'Salery Payment: emp_code - {salery.employee.code}'
                withdraw = Withdraw(account=salery.account,
                                    desc=desc,
                                    date=salery.date,
                                    amount=salery.amount,
                                    payment_method=salery.payment_method,
                                    ref_num=salery.ref_num)
                bank.make_withdraw(withdraw)
                salery.paid = True

            if payment_accepted:
                salery.save()
            else:
                messages.add_message(request, messages.WARNING,
                                     'Invalid Payment Details')

        return redirect('/inventory-manager/salery/')
    else:
        if id == 0:
            form = AddSaleryForm()
        else:
            salery = Salery.objects.get(pk=id)
            form = AddSaleryForm(instance=salery)

        context = {'formname': 'Add Salery', 'form': form}
        return render(request, 'inventory_manager/other/form_template.html',
                      context)
Esempio n. 7
0
def add_expense(request, id=0):
    if request.method == 'POST':
        if id == 0:
            form = AddExpenseForm(request.POST)
        else:
            instance = Expense.objects.get(pk=id)
            form = AddExpenseForm(request.POST, instance=instance)

        payment_accepted = False

        if form.is_valid():
            expense = form.save(commit=False)

            payment_method = expense.payment_method
            ref_num = expense.ref_num
            eff_date = expense.eff_date
            if payment_method.name.lower() == 'credit':
                payment_accepted = True
                expense.paid = False
            elif payment_method.name.lower() == 'cash':
                payment_accepted = True
                #add cash out
                desc = f'Expense Payment: {expense.name}'
                cash_out = CashOut(desc=desc,
                                   date=expense.date,
                                   amount=expense.amount)
                cashflow.make_cash_out(cash_out)
                expense.paid = True

            elif payment_method.name.lower() == 'check':
                if ref_num == None or eff_date == None:
                    payment_accepted = False
                else:
                    payment_accepted = True
                    # make Withdraw
                    desc = f'Expense Check Payment: {expense.ref_num}'
                    withdraw = Withdraw(account=expense.account,
                                        desc=desc,
                                        date=expense.date,
                                        amount=expense.amount,
                                        payment_method=expense.payment_method,
                                        ref_num=expense.ref_num)
                    bank.make_withdraw(withdraw)
                    expense.paid = True
            else:
                payment_accepted = True
                #make withdraw
                desc = f'Expense Payment: {expense.name}'
                withdraw = Withdraw(account=expense.account,
                                    desc=desc,
                                    date=expense.date,
                                    amount=expense.amount,
                                    payment_method=expense.payment_method,
                                    ref_num=expense.ref_num)
                bank.make_withdraw(withdraw)
                expense.paid = True

            if payment_accepted:
                expense.save()
            else:
                messages.add_message(request, messages.WARNING,
                                     'Invalid Payment Details')

        return redirect('/inventory-manager/expenses/')
    else:
        if id == 0:
            form = AddExpenseForm()
        else:
            instance = Expense.objects.get(pk=id)
            form = AddExpenseForm(instance=instance)
        context = {'form': form, 'formname': 'Add Expense'}
        return render(request, 'inventory_manager/other/form_template.html',
                      context)