def make_withdraw(withdraw): if withdraw.payment_method.name.lower() == 'cash': if withdraw.amount == None: return None else: withdraw.save() acc = withdraw.account acc.amount -= withdraw.amount acc.save() #make cash in cash_in = CashIn(desc=withdraw.desc, date=withdraw.date, amount=withdraw.amount) cashflow.make_cash_in(cash_in) return True else: if withdraw.amount == None: return None else: withdraw.save() acc = withdraw.account acc.amount -= withdraw.amount acc.save() return True
def add_otherincome(request, id=0): if request.method == 'POST': if id == 0: form = AddOtherIncomeForm(request.POST) else: instance = OtherIncome.objects.get(pk=id) form = AddOtherIncomeForm(request.POST,instance=instance) payment_accepted = False if form.is_valid(): other_income = form.save(commit=False) payment_method = other_income.payment_method ref_num = other_income.ref_num eff_date = other_income.eff_date if payment_method.name.lower() == 'credit': payment_accepted = True other_income.paid = False elif payment_method.name.lower() == 'cash': payment_accepted = True #add cash in desc = f'Other Income: {other_income.name}' cash_in = CashIn(desc=desc,date=other_income.date,amount=other_income.amount) cashflow.make_cash_in(cash_in) other_income.paid = True elif payment_method.name.lower() == 'check': if ref_num == None or eff_date == None: payment_accepted = False else: payment_accepted = True #add check to check table check = Check(date=other_income.date,ref_num=ref_num,eff_date=eff_date,amount=other_income.amount) check.save() other_income.paid = True else: payment_accepted = True #add deposit desc = f'Othe Income: {other_income.name}' deposit = Deposit(account=other_income.account, desc=desc, date=other_income.date, amount=other_income.amount, payment_method=other_income.payment_method) bank.make_deposit(deposit) other_income.paid = True if payment_accepted: other_income.save() else: messages.add_message(request,messages.WARNING, 'Invalid Payment Details') return redirect('/inventory-manager/other-incomes/') else: form = None if id == 0: form = AddOtherIncomeForm() else: instance = OtherIncome.objects.get(pk=id) form = AddOtherIncomeForm(instance=instance) context = {'form':form, 'formname':'Add Other Income'} return render(request,'inventory_manager/other/form_template.html', context)
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 = BuyPayment.objects.get(pk=id) receive = payment.buy if payment.payment_method.name.lower() == 'credit': delete_accepted = True elif payment.payment_method.name.lower() == 'cash': delete_accepted = True desc = f'Receive Payment Revert: {payment.buy.supplire}' cash_in = CashIn(desc=desc, date=payment.date, amount=payment.amount) cashflow.make_cash_in(cash_in) elif payment.payment_method.name.lower() == 'check': #add deposti if payment.account == None: delete_accepted = False else: delete_accepted = True desc = f'Receive Check Returnd: {payment.ref_num}' deposit = Deposit(account=payment.account, desc=desc, date=payment.date, amount=payment.amount, payment_method=payment.payment_method, ref_num=payment.ref_num) bank.make_deposit(deposit) else: #add deposti if payment.account == None: delete_accepted = False else: delete_accepted = True desc = f'Receive Payment Revert: {payment.ref_num}' deposit = Deposit(account=payment.account, desc=desc, date=payment.date, amount=payment.amount, payment_method=payment.payment_method, ref_num=payment.ref_num) bank.make_deposit(deposit) if delete_accepted: receive.paid = False receive.save() payment.delete() else: messages.add_message(request, messages.WARNING, 'Somthing went wrong!') url = f'/inventory-manager/receives/' 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_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 = AddPaymentForm(request.POST) payment_accepted = False payment = None if form.is_valid(): payment = form.save() sale = payment.sale payments = SellPayment.objects.filter(sale=sale) total_payment = 0 last_payment = None for payment in payments: total_payment += payment.amount last_payment = payment if total_payment > sale.amount: ddt = total_payment - sale.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 in desc = f'Sale Payment: "{payment.sale.customer}"' cash_in = CashIn(desc=desc,date=payment.sale.date,amount=payment.amount) cashflow.make_cash_in(cash_in) elif payment_method.name.lower() == 'check': if ref_num == None or eff_date == None: payment_accepted = False else: payment_accepted = True #add check to check table check = Check(date=payment.date,ref_num=ref_num,eff_date=eff_date,amount=payment.amount) check.save() else: payment_accepted = True #add deposit desc = f'Sale Payment: "{payment.sale.customer}"' deposit = Deposit(account=payment.account, desc=desc, date=payment.date, amount=payment.amount, payment_method=payment.payment_method) bank.make_deposit(deposit) if payment_accepted: payment.save() last_payment.save() if total_payment >= sale.amount: sale.paid = True sale.save() else: payment.delete() messages.add_message(request,messages.WARNING, 'Invalid Payment Details') return redirect('/inventory-manager/sales/') else: sale = Sell.objects.get(pk=id) data = {'sale':sale, 'amount':sale.amount,} form = AddPaymentForm(data) context = {'formname':'Add Payment', 'form':form} return render(request, 'inventory_manager/product/form_template.html', context)
def add_other_sale(request, id=0): if request.method == 'POST': currentuser = get_user(request) payment_accepted = False if id == 0: form = AddOtherSaleForm(request.POST) else: instance = OtherSell.objects.get(pk=id) form = AddOtherSaleForm(request.POST, instance=instance) other_sale = None if form.is_valid(): other_sale = form.save(commit=False) total_amount = 0 dispatch_note_num = other_sale.dispatch_note_num dispatchs = SellDispatch.objects.filter(dispatch_note_num=dispatch_note_num) #get all dipatch notes for dispatch in dispatchs: total_amount += dispatch.amount other_sale.created_user = currentuser other_sale.amount = total_amount payment_method = other_sale.payment_method ref_num = other_sale.ref_num eff_date = other_sale.eff_date if payment_method.name.lower() == 'credit': payment_accepted = True other_sale.paid = False elif payment_method.name.lower() == 'cash': payment_accepted = True #add cash in desc = f'Other Sale Payment: {other_sale.customer}' cash_in = CashIn(desc=desc,date=other_sale.date,amount=other_sale.amount) cashflow.make_cash_in(cash_in) other_sale.paid = True elif payment_method.name.lower() == 'check': if ref_num == None or eff_date == None: payment_accepted = False else: payment_accepted = True #add check to check table check = Check(date=other_sale.date,ref_num=ref_num,eff_date=eff_date,amount=other_sale.amount) check.save() other_sale.paid = True else: payment_accepted = True #add deposit desc = f'Other Sale Payment: {other_sale.customer}' deposit = Deposit(account=other_sale.account, desc=desc, date=other_sale.date, amount=other_sale.amount, payment_method=other_sale.payment_method) bank.make_deposit(deposit) other_sale.paid = True if payment_accepted: for dispatch in dispatchs: stock = dispatch.stock stock.qty -= dispatch.qty stock.save() other_sale.save() else: messages.add_message(request,messages.WARNING, 'Invalid Payment Details') else: messages.add_message(request,messages.WARNING, 'Form is Invalid') return redirect('/inventory-manager/other-sales/') else: if id == 0: form = AddOtherSaleForm() else: instance = OtherSell.objects.get(pk=id) form = AddOtherSaleForm(instance=instance) context = {'formname':'Add Other Sale', 'form':form} return render(request, 'inventory_manager/product/form_template.html', context)