def generate_billing_statement(request, order_id, percentage, code, template_no): try: order = Order.objects.get(id=order_id) number = random.randint(1, 999999) bs_no = "BS-" + str(number) while helper.check_duplicate_numbers(bs_no, 'billing'): number = random.randint(1, 999999) bs_no = "BS-" + str(number) item = helper.get_item_description(code, order.id) user = Profile.objects.get(user=request.user) BillingStatement.objects.create(order=order, number=bs_no, item=item, percentage=int(percentage), generated_by=user, state=1, price=0) context = {'order': order} messages.success(request, "Billing statement generated!") template = helper.get_payment_template(template_no) return render(request, template, context) except Order.DoesNotExist: raise Http404('Order does not exist')
def generate_po(request): number = random.randint(1, 999999) po_no = "PO-" + str(number) while helper.check_duplicate_numbers(po_no, 'purchase'): number = random.randint(1, 999999) po_no = "PO-" + str(number) request_body = request.body print(request_body) data = json.loads(request_body) supplier_id = data['supplier_id'] print(supplier_id) po_cart = data['po_cart'] profile = Profile.objects.get(user=request.user) PurchaseOrder.objects.create(supplier=Supplier.objects.get(id=supplier_id), generated_by=profile, number=po_no) po = PurchaseOrder.objects.latest("id") for item in po_cart: PurchaseOrderLine.objects.create( purchase_order=po, product=Product.objects.get(id=item['id']), quantity=item['qty']) products = Product.objects.all() all_po = PurchaseOrder.objects.all() context = { 'products': products, 'purchase_orders': all_po, 'messages': 'Purchase order generated!' } return render(request, 'inventory/index.html', context)
def generate_progress_report(request, order_id): try: order = Order.objects.get(id=order_id) project = Schedule.objects.filter(order=order).get( name__contains='Installation') profile = Profile.objects.get(user=request.user) progress_reports = ProgressReport.objects.filter(order=order) form = ProgressReportForm(request.POST or None) if form.is_valid(): progress = form.save(commit=False) number = random.randint(1, 999999) pr_no = "PR-" + str(number) while helper.check_duplicate_numbers(pr_no, 'deliver'): number = random.randint(1, 999999) pr_no = "DR-" + str(number) progress.number = pr_no progress.generated_by = profile progress.order = order progress.save() messages.success(request, 'Progress report generated') return redirect('orders:view-project', order_id=order.id) context = {'form': form} return render(request, 'orders/progress_report_form.html', context) except Order.DoesNotExist: raise Http404("Order Does Not Exist")
def add_maintenance_contract(request, order_id): try: order = Order.objects.get(id=order_id) form = MaintenanceContractForm(request.POST or None) context = {'form': form} if form.is_valid(): contract = form.save(commit=False) contract.order = order number = random.randint(1, 999999) mc_no = "MC-" + str(number) while helper.check_duplicate_numbers(mc_no, 'maintenance'): number = random.randint(1, 999999) mc_no = "MC-" + str(number) profile = Profile.objects.get(user=request.user) contract.number = mc_no contract.generated_by = profile contract.is_current = True contract.save() messages.success(request, 'Maintenance contract added!') return redirect('maintenance:overview', order_id=order.id) return render(request, 'maintenance/maintenance_form.html', context) except Order.DoesNotExist: raise Http404('Order does not exist')
def generate_pullout_slip(request, order_id): try: order = Order.objects.get(id=order_id) profile = Profile.objects.get(user=request.user) number = random.randint(1, 999999) pos = "PS-" + str(number) while helper.check_duplicate_numbers(pos, "pullout"): number = random.randint(1, 999999) pos = "PS-" + str(number) PullOutSlip.objects.create(order=order, generated_by=profile, number=pos) order.is_installed = True order.status = "Maintenance" order.save() messages.success(request, 'Pullout slip generated!') return redirect('orders:installation', order_id=order.id) except Order.DoesNotExist: raise Http404('Order does not exist')
def add_order_line(request): order = Order.objects.get(id=request.POST['order']) product = Product.objects.get(id=request.POST['product']) quantity = request.POST['quantity'] manpower = request.POST['manpower'] OrderLine.objects.create(order=order, product=product, quantity=quantity) order.has_project_requirements = True order.save() number = random.randint(1, 999999) inspector_no = "I-" + str(number) profile = Profile.objects.get(user=request.user) while helper.check_duplicate_numbers(inspector_no, "inspector"): number = random.randint(1, 999999) inspector_no = "I-" + str(number) InspectorReport.objects.create(order=order, inspector_report_no=inspector_no, manpower=manpower, generated_by=profile) return HttpResponse("added")
def generate_billing_statement(request): maintenance_id = request.POST['id'] order_id = request.POST['order'] order = Order.objects.get(id=order_id) maintenance_contract = MaintenanceContract.objects.get(id=maintenance_id) profile = Profile.objects.get(user=request.user) maintenance_expiration_date = helper.add_years( maintenance_contract.date_generated, maintenance_contract.duration) number = random.randint(1, 999999) bs_no = "BS-" + str(number) while helper.check_duplicate_numbers(bs_no, 'billing'): number = random.randint(1, 999999) bs_no = "BS-" + str(number) percentage = 100 / len( helper.get_date_intervals(maintenance_contract.date_generated, maintenance_expiration_date, maintenance_contract.payment)) item = str(percentage) + '% DOWN PAYMENT FOR MAINTENANCE SERVICE' BillingStatement.objects.create(order=order, number=bs_no, item=item, percentage=percentage, generated_by=profile, price=maintenance_contract.price * (decimal.Decimal(percentage) / 100), state=2) messages.success(request, 'Billing Statement Generated') return redirect('maintenance:contract-view', order_id=order.id)
def trouble_official_receipt(request): order = Order.objects.get(id=request.GET['id']) ticket = TroubleTicket.objects.get(id=request.GET['ticket']) billing_statement = BillingStatement.objects.filter(order=order).get( item__contains=ticket.subject) profile = Profile.objects.get(user=request.user) number = random.randint(1, 999999) or_no = "OR-" + str(number) while helper.check_duplicate_numbers(or_no, 'official'): number = random.randint(1, 999999) or_no = "OR-" + str(number) OfficialReceipt.objects.create(order=order, percentage=0, number=or_no, generated_by=profile, price=billing_statement.price, state=2) ticket.has_official_receipt = True ticket.save() messages.success(request, 'Official receipt generated!') return redirect('maintenance:overview', order_id=order.id)
def renew_contract(request): order = Order.objects.get(id=request.GET['id']) form = MaintenanceContractForm(request.POST or None) context = {'form': form} if form.is_valid(): contract = form.save(commit=False) contract.order = order number = random.randint(1, 999999) mc_no = "MC-" + str(number) while helper.check_duplicate_numbers(mc_no, 'maintenance'): number = random.randint(1, 999999) mc_no = "MC-" + str(number) profile = Profile.objects.get(user=request.user) contract.number = mc_no contract.generated_by = profile for mc in MaintenanceContract.objects.filter(order=order): mc.is_current = False mc.save() contract.is_current = True contract.save() messages.success(request, 'Maintenance contract added!') return redirect('maintenance:overview', order_id=order.id) return render(request, 'maintenance/maintenance_form.html', context)
def generate_official_receipt(request): maintenance_id = request.POST['id'] order_id = request.POST['order'] order = Order.objects.get(id=order_id) maintenance_contract = MaintenanceContract.objects.get(id=maintenance_id) profile = Profile.objects.get(user=request.user) maintenance_expiration_date = helper.add_years( maintenance_contract.date_generated, maintenance_contract.duration) number = random.randint(1, 999999) or_no = "OR-" + str(number) while helper.check_duplicate_numbers(or_no, 'official'): number = random.randint(1, 999999) or_no = "OR-" + str(number) percentage = 100 / len( helper.get_date_intervals(maintenance_contract.date_generated, maintenance_expiration_date, maintenance_contract.payment)) item = str(percentage) + '% DOWN PAYMENT FOR MAINTENANCE SERVICE' OfficialReceipt.objects.create(order=order, number=or_no, percentage=percentage, generated_by=profile, state=2, price=maintenance_contract.price * (decimal.Decimal(percentage) / 100)) official = OfficialReceipt.objects.latest('id') schedule = Schedule.objects.filter(order=order).filter( name__contains='Maintenance', start_date__month=official.date_created.month)[0] schedule.is_completed = True schedule.save() messages.success(request, 'Official Receipt Generated') return redirect('maintenance:contract-view', order_id=order.id)
def generate_certificate(request, order_id): try: order = Order.objects.get(id=order_id) profile = Profile.objects.get(user=request.user) number = random.randint(1, 999999) certificate = "CW-" + str(number) while helper.check_duplicate_numbers(certificate, "certificate"): number = random.randint(1, 999999) certificate = "CW-" + str(number) CertificateOfWarranty.objects.create(order=order, generated_by=profile, number=certificate) messages.success(request, 'Certificate of Warranty generated!') return redirect('orders:installation', order_id=order.id) except Order.DoesNotExist: raise Http404('Order does not exist')
def generate_letter_of_acceptance(request, order_id): try: order = Order.objects.get(id=order_id) profile = Profile.objects.get(user=request.user) number = random.randint(1, 999999) letter = "AL-" + str(number) while helper.check_duplicate_numbers(letter, "acceptance"): number = random.randint(1, 999999) letter = "AL-" + str(number) AcceptanceLetter.objects.create(order=order, generated_by=profile, number=letter) messages.success(request, 'Letter of Acceptance Generated') return redirect('orders:installation', order_id=order.id) except Order.DoesNotExist: raise Http404('Order does not exist')
def generate_official_receipt(request, order_id, percentage, template_no): try: order = Order.objects.get(id=order_id) number = random.randint(1, 999999) or_no = "OR-" + str(number) while helper.check_duplicate_numbers(or_no, 'official'): number = random.randint(1, 999999) or_no = "OR-" + str(number) user = Profile.objects.get(user=request.user) OfficialReceipt.objects.create(order=order, number=or_no, percentage=int(percentage), generated_by=user, state=1) context = {'order': order} messages.success(request, "Official receipt generated!") template = helper.get_payment_template(template_no) # if delivery if template_no == "2": order.is_delivered = True schedule = order.schedule_set.filter(name__contains='Deliver')[0] order.status = "Installation" schedule.is_completed = True schedule.save() order.save() return render(request, template, context) except Order.DoesNotExist: raise Http404('Order does not exist')
def trouble_billing_statement(request): order = Order.objects.get(id=request.GET['id']) ticket = TroubleTicket.objects.get(id=request.GET['ticket']) form = TroubleBillingStatementForm( request.POST or None, initial={'item': 'PAYMENT FOR SERVICE; Re: ' + ticket.subject}) context = {'form': form} if form.is_valid(): billing_statement = form.save(commit=False) number = random.randint(1, 999999) bs_no = "BS-" + str(number) while helper.check_duplicate_numbers(bs_no, 'billing'): number = random.randint(1, 999999) bs_no = "BS-" + str(number) profile = Profile.objects.get(user=request.user) billing_statement.order = order billing_statement.number = bs_no billing_statement.generated_by = profile billing_statement.state = 2 billing_statement.percentage = 0 billing_statement.save() ticket.has_billing_statement = True ticket.save() messages.success(request, 'Billing statement generated!') return redirect('maintenance:overview', order_id=order.id) return render(request, 'maintenance/trouble_bs.html', context)
def generate_delivery_receipt(request, order_id, template_no): try: order = Order.objects.get(id=order_id) user = Profile.objects.get(user=request.user) number = random.randint(1, 999999) dr_no = "DR-" + str(number) while helper.check_duplicate_numbers(dr_no, 'deliver'): number = random.randint(1, 999999) dr_no = "DR-" + str(number) DeliveryReceipt.objects.create(order=order, number=dr_no, generated_by=user) context = {'order': order} template = helper.get_payment_template(template_no) messages.success(request, "Delivery Receipt generated!") return render(request, template, context) except Order.DoesNotExist: raise Http404("Order does not exist")
def request_products(request): current_order = Order.objects.get(id=request.GET['order']) orders = Order.objects.filter(has_contract_done=True, has_retrieved_supplies=False) supplies = [] for order in orders: for line in order.orderline_set.all(): supply = {'id': line.product.id, 'quantity': line.quantity} supplies.append(supply) order.has_requested_products = True order.save() supplies = helper.merge_list(supplies) profile = Profile.objects.get(user=request.user) # supplier_list = [] # # for supplier in Supplier.objects.all(): # requested_supplies = [] # supplier_list.append( {"supplier" : supplier, "requested_supplies" : requested_supplies}) # # for product in supplier.product_set.all(): # for requested_supply in product.requestedsupply_set.all(): # requested_supplies.append(requested_supply) temp_suppliers = [] for x in supplies: product = Product.objects.get(id=x['id']) supplier = product.supplier.all()[0] if supplier not in temp_suppliers: temp_suppliers.append(supplier) for x in temp_suppliers: number = random.randint(1, 999999) po_no = "PO-" + str(number) while helper.check_duplicate_numbers(po_no, 'purchase'): number = random.randint(1, 999999) po_no = "PO-" + str(number) PurchaseOrder.objects.create(number=po_no, generated_by=profile, supplier=x) po = PurchaseOrder.objects.latest('id') for a in supplies: product = Product.objects.get(id=a['id']) if product.supplier.all()[0] == po.supplier: PurchaseOrderLine.objects.create(purchase_order=po, product=product, quantity=a['quantity']) for order in orders: order.has_retrieved_supplies = True order.status = 'Delivery' order.save() messages.success(request, 'Supplies requested') return redirect('orders:product_retrieval', order_id=current_order.id)
def contract_form(request, order_id): profile = Profile.objects.get(user=request.user) try: orders = Order.objects.all() order = Order.objects.get(id=order_id) order_line = OrderLine.objects.filter(order=order) form = ContractForm(request.POST or None) if form.is_valid(): contract = form.save(commit=False) contract.order = order warranty = request.POST['warranty'] # contract no number = random.randint(1, 999999) contract_no = "PO-" + str(number) while helper.check_duplicate_numbers(contract_no, 'contract'): number = random.randint(1, 999999) contract_no = "I-" + str(number) order.has_contract = True order.save() # TODO revise continue if contract.payment_terms == "50-40-10": term = contract.payment_terms.split("-") contract.first_percentage = term[0] contract.second_percentage = term[1] contract.third_percentage = term[2] elif contract.payment_terms == "50-30-20": term = contract.payment_terms.split("-") contract.first_percentage = term[0] contract.second_percentage = term[1] contract.third_percentage = term[2] elif contract.payment_terms == "Full Payment": pass contract.number = contract_no contract.generated_by = profile contract.save() messages.success(request, "Contract generated!") context = { 'order': order, 'orders': orders, 'has_contract': hasattr(order, "contract") } return render(request, 'orders/purchase_order_phase.html', context) context = { 'order': order, 'form': form, 'order_line': order_line, 'total_price': helper.get_total_price(order), } return render(request, 'orders/contract_form.html', context) except Order.DoesNotExist: raise Http404("Order does not exist")