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)
def delete_expense(request, id=0): user = get_user(request) if not user.is_superuser: return redirect('/fobiddn/') if request.method == 'POST': expense = Expense.objects.get(pk=id) delete_accepted = False if expense.payment_method.name.lower() == 'credit': delete_accepted = True elif expense.payment_method.name.lower() == 'cash': delete_accepted = True # add cash out desc = f'Expense Revert: {expense.name}' cash_in = CashIn(desc=desc, date=expense.date, amount=expense.amount) cashflow.make_cash_in(cash_in) elif expense.payment_method.name.lower() == 'check': if expense.account == None: delete_accepted = False else: delete_accepted = True # add deposit desc = f'Returned Check: {expense.ref_num}' deposit = Deposit(account=expense.account, desc=desc, date=expense.date, amount=expense.amount, payment_method=expense.payment_method, ref_num=expense.ref_num) bank.make_withdraw(deposit) else: if expense.account == None: delete_accepted = False else: delete_accepted = True # add deposit desc = f'Expense Revert: {expense.ref_num}' deposit = Deposit(account=expense.account, desc=desc, date=expense.date, amount=expense.amount, payment_method=expense.payment_method, ref_num=expense.ref_num) bank.make_withdraw(deposit) if delete_accepted: expense.delete() else: messages.add_message(request, messages.WARNING, 'Somthing went wrong!') return redirect('/inventory-manager/expenses/')
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 delete_salery(request, id=0): user = get_user(request) if not user.is_superuser: return redirect('/fobiddn/') if request.method == 'POST': salery = Salery.objects.get(pk=id) delete_accepted = False if salery.payment_method.name.lower() == 'credit': delete_accepted = True elif salery.payment_method.name.lower() == 'cash': delete_accepted = True # add cash out desc = f'Salery Revert: emp_code - {salery.employee.code}' cash_in = CashIn(desc=desc, date=salery.date, amount=salery.amount) cashflow.make_cash_in(cash_in) elif salery.payment_method.name.lower() == 'check': if salery.account == None: delete_accepted = False else: delete_accepted = True # add deposit desc = f'Salery Returnd Check: emp_code - {salery.employee.code}' deposit = Deposit(account=salery.account, desc=desc, date=salery.date, amount=salery.amount, payment_method=salery.payment_method, ref_num=salery.ref_num) bank.make_withdraw(deposit) else: if salery.account == None: delete_accepted = False else: delete_accepted = True # add deposit desc = f'Salery Revert: emp_code - {salery.employee.code}' deposit = Deposit(account=salery.account, desc=desc, date=salery.date, amount=salery.amount, payment_method=salery.payment_method, ref_num=salery.ref_num) bank.make_withdraw(deposit) if delete_accepted: salery.delete() else: messages.add_message(request, messages.WARNING, 'Somthing went wrong!') return redirect('/inventory-manager/salery/')
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)
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)
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)