def get(self, request): company, branch = token_helper(request) item_id = request.GET.get('id') start_date = request.GET.get('start') end_date = request.GET.get('end') if item_id and start_date and end_date: menu_item = MenuItem.objects.get(pk=item_id) itemlines = Itemline.objects.filter( order__branch=branch, order__created_at__gte=start_date, order__created_at__lte=end_date, item=menu_item) elif item_id: menu_item = MenuItem.objects.get(pk=item_id) itemlines = Itemline.objects.filter(order__branch=branch, item=menu_item) else: return Response({ 'message': 'Validation Error.', 'status': status.HTTP_400_BAD_REQUEST, 'response': '' }) final_data = itemlines.order_by('order__created_at').values( 'order__created_at').annotate(sum=Sum('price')) return Response({ 'message': 'sale report by menuitem', 'status': status.HTTP_200_OK, 'response': final_data })
def patch(self, request, pk, *args, **kwargs): company, branch = token_helper(request) order = Order.objects.get(pk=pk) if order.branch.company == company: order.order_status = request.data.get('order_status', 'revised') serializer = OrderSerializer(order, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response({ 'message': 'Order {} updated succesfully'.format(order.pk), 'status': status.HTTP_200_OK, 'response': serializer.data }) return Response({ 'message': serializer.errors, 'status': status.HTTP_400_BAD_REQUEST }) else: return Response({ 'message': 'Unauthorized', 'status': status.HTTP_401_UNAUTHORIZED })
def patch(self, request, pk, *args, **kwargs): company, branch = token_helper(request) seating = Seating.objects.get(pk=pk) print(seating.branch.company.id) print(company.id) if seating.branch.company == company: serializer = SeatingSerializer(seating, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response({ 'message': 'Seating {} updated succesfully'.format(seating.pk), 'status': status.HTTP_200_OK, 'response': serializer.data }) return Response({ 'message': serializer.errors, 'status': status.HTTP_400_BAD_REQUEST }) else: return Response({ 'message': 'Unauthorized', 'status': status.HTTP_401_UNAUTHORIZED })
def patch(self, request, pk, *args, **kwargs): company, branch = token_helper(request) item = MenuItem.objects.get(pk=pk) if item.category.department.branch == branch: serializer = MenuItemSerializer(item, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response({ 'message': 'Item {} updated succesfully'.format(item.item_name), 'status': status.HTTP_200_OK, 'response': serializer.data }) return Response({ 'message': serializer.errors, 'status': status.HTTP_400_BAD_REQUEST }) else: return Response({ 'message': 'Unauthenticated', 'status': status.HTTP_401_UNAUTHORIZED })
def get(self, request): company, branch = token_helper(request) if branch is not None: notific = branch.notification.all() notifications = [] message_arr = notific.values_list('message').distinct() for message in message_arr: notification = NotificationTable.objects.filter( message=message[0]).first() notifications.append(notification) else: notific = NotificationTable.objects.filter(branch__company=company) notifications = [] message_arr = notific.values_list('message').distinct() for message in message_arr: notification = NotificationTable.objects.filter( message=message[0]).first() notifications.append(notification) serializer = NotificationSerializer(notifications, many=True) return Response({ 'message': 'notification list', 'status': status.HTTP_200_OK, 'response': serializer.data })
def patch(self, request, pk, *args, **kwargs): company, branch = token_helper(request) uom = UnitOfMaterial.objects.get(pk=pk) if uom.company == company: serializer = UnitOfMaterialSerailzier(uom, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response({ 'message': '{} updated succesfully'.format(uom.uom), 'status': status.HTTP_200_OK, 'response': serializer.data }) return Response({ 'message': serializer.errors, 'status': status.HTTP_400_BAD_REQUEST }) else: return Response({ 'message': 'Unauthorized', 'status': status.HTTP_401_UNAUTHORIZED })
def patch(self, request, pk, *args, **kwargs): company, branch = token_helper(request) category = Category.objects.get(pk=pk) if category.department.branch.company == company: serializer = CategoryCreateUpdateSerializer(category, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response({ 'message': 'Category {} updated succesfully'.format( category.category_name), 'status': status.HTTP_200_OK, 'response': serializer.data }) return Response({ 'message': serializer.errors, 'status': status.HTTP_400_BAD_REQUEST }) else: return Response({ 'message': 'Unauthorized', 'status': status.HTTP_401_UNAUTHORIZED })
def get(self, request, pk): try: company, branch = token_helper(request) obj = Employee.objects.get(pk=pk) if obj.company == company: serializer = EmployeeSerializer(obj) return Response({ 'message': 'Department {} detail'.format(obj.employee_name), 'status': status.HTTP_200_OK, 'response': serializer.data }) else: return Response({ 'message': 'Unauthorized', 'status': status.HTTP_401_UNAUTHORIZED }) except Exception as e: return Response({ 'message': "Employee doesn't exist", 'status': status.HTTP_400_BAD_REQUEST })
def get(self, request): company, branch = token_helper(request) if branch is not None: payment = VendorPayment.objects.filter(branch=branch) else: payment = VendorPayment.objects.filter(branch__company = company) serializer = VendorPaymentListSerializer(payment, many = True) return Response({"message": "success", "status": status.HTTP_200_OK, "response":serializer.data})
def get(self, request): final_amount = 0 company, branch = token_helper(request) context = {} payment_mode_dict = {} advanced_payment_dict = {} credit_payment_dict = {} if request.GET.get('sale_mode'): payment_mode = request.GET.get('sale_mode') invoices = Invoice.objects.filter(payment_mode=payment_mode) for invoice in invoices: try: credit = Credit.objects.get(invoice=invoice) if credit.credit_status == 'credited': credit_payment_dict[ invoice.id] = credit.transaction_amount advanced_payment_dict[invoice.id] = 0 else: advanced_payment_dict[ invoice.id] = credit.transaction_amount credit_payment_dict[invoice.id] = 0 except: credit_payment_dict[invoice.id] = 0 advanced_payment_dict[invoice.id] = 0 context['sale_mode'] = payment_mode else: invoices = Invoice.objects.filter(branch=branch) for invoice in invoices: try: credit = Credit.objects.get(invoice=invoice) if credit.credit_status == 'credited': credit_payment_dict[ invoice.id] = credit.transaction_amount advanced_payment_dict[invoice.id] = 0 else: advanced_payment_dict[ invoice.id] = credit.transaction_amount credit_payment_dict[invoice.id] = 0 except: credit_payment_dict[invoice.id] = 0 advanced_payment_dict[invoice.id] = 0 context['sale_mode'] = 'All' for invoice in invoices: payment_mode_dict[invoice.id] = invoice.payment_mode final_amount += invoice.final_bill_amount context['final_amount'] = final_amount context['invoices'] = invoices context['advance_payment_dict'] = advanced_payment_dict context['credit_payment_dict'] = credit_payment_dict context['payment_mode_dict'] = payment_mode_dict response = HttpResponse(content_type='application/pdf') template = get_template('salereportbysalemode.html') html = template.render(context) pdf = pisa.CreatePDF(html, dest=response) if pdf.err: return HttpResponse('we had some errors <pre>' + html + '</pre>') return response
def get(self, request): company, branch = token_helper(request) obj = company.customer_set.all() serializer = CustomerSerializer(obj, many=True) return Response({ 'message': 'Customers list', 'status': status.HTTP_200_OK, 'response': serializer.data })
def get(self, request): company, branch = token_helper(request) uom = company.uom.all() serializer = UnitOfMaterialSerailzier(uom, many=True) return Response({ 'message': 'Unit of Material list', 'status': status.HTTP_200_OK, 'response': serializer.data })
def get(self, request): company, branch = token_helper(request) obj = CreditHistory.objects.filter(customer__company=company) serializer = CreditHistorySerializer(obj, many=True) return Response({ 'message': 'Credit List', 'status': status.HTTP_200_OK, 'response': serializer.data })
def get(self, request, pk): company, branch = token_helper(request) customer = Customer.objects.get(pk=pk, company=company) obj = customer.credit.all() serializer = CreditSerializer(obj, many=True) return Response({ 'message': 'Credit History list', 'status': status.HTTP_200_OK, 'response': serializer.data })
def get(self, request): company, branch = token_helper(request) if branch is not None: seating = branch.seating.all() else: seating = Seating.objects.filter(branch__company=company) serializer = SeatingListSerializer(seating, many=True) return Response({ 'message': 'seating list', 'status': status.HTTP_200_OK, 'response': serializer.data })
def get(self, request): company, branch = token_helper(request) if branch is not None: order = branch.order.all() else: order = Order.objects.filter(branch__company=company) serializer = OrderListSerializer(order, many=True) return Response({ 'message': 'Orders list', 'status': status.HTTP_200_OK, 'response': serializer.data })
def get(self, request): company, branch = token_helper(request) if branch is not None: obj = SeatingType.objects.filter(branch=branch) else: obj = SeatingType.objects.filter(branch__company=company) serializer = SeatingTypeSerializer(obj, many=True) return Response({ 'message': 'Seating Types', 'status': status.HTTP_200_OK, 'response': serializer.data })
def get(self, request): try: company, branch = token_helper(request) if branch is not None: obj = branch.invoice.all() else: obj = Invoice.objects.filter(branch__company=company) serializer = InvoiceListSerializer(obj, many=True) return Response({'message': 'Invoice list by branch', 'status': status.HTTP_200_OK, 'response': serializer.data}) except Branch.DoesNotExist: return Response({'message': 'branch doesnot exist', 'status': status.HTTP_400_BAD_REQUEST})
def SaleReportByPaymentModeService(request): company, branch = token_helper(request) start_date = request.GET.get('start') end_date = request.GET.get('end') if start_date and end_date: invoices = Invoice.objects.filter(created_at__gte=start_date, created_at__lte=end_date, branch=branch) else: invoices = Invoice.objects.filter(branch=branch) return invoices.values('created_at', 'payment_mode').order_by('created_at').annotate( sum=Sum('final_bill_amount'))
def delete(self, request, pk): try: company, branch = token_helper(request) obj = Customer.objects.get(pk=pk, company=company) obj.delete() return Response({ 'message': 'Customer successfully deleted', 'status': status.HTTP_200_OK }) except Exception as e: return Response({ 'message': "Customer doesn't exist", 'status': status.HTTP_400_BAD_REQUEST })
def get(self, request): company, branch = token_helper(request) context = {} if request.GET.get('start_date'): try: start_date = request.GET.get('start_date') context['start_date'] = start_date end_date = request.GET.get('end_date') context['end_date'] = end_date print(end_date) invoices = Invoice.objects.filter(bill_date__gte=start_date, bill_date__lte=end_date, branch=branch) except Exception as e: start_date = request.GET.get('start_date') context['start_date'] = start_date invoices = Invoice.objects.filter(bill_date__gte=start_date, branch=branch) elif request.GET.get('date'): date = request.GET.get('date') context['date'] = date invoices = Invoice.objects.filter(bill_date=date, branch=branch) context['invoices'] = invoices final_amount = 0 for invoice in invoices: final_amount += invoice.final_bill_amount template_path = 'salereportbydate.html' context = { 'invoices': invoices, 'start_date': start_date, 'end_date': end_date, 'final_amount': final_amount } # Create a Django response object, and specify content_type as pdf response = HttpResponse(content_type='application/pdf') """ this line downloads the pdf directly """ # response['Content-Disposition'] = 'attachment; filename="report.pdf"' # find the template and render it. template = get_template(template_path) html = template.render(context) # create a pdf pisaStatus = pisa.CreatePDF(html, dest=response) # if error then show some funy view if pisaStatus.err: return HttpResponse('We had some errors <pre>' + html + '</pre>') return response
def get(self, request): try: company, request = token_helper(request) customer = Customer.objects.filter(company=company) serializer = CustomerInvoiceHelperSerializer(customer, many=True) return Response({ 'message': 'customer info', 'status': status.HTTP_200_OK, 'response': serializer.data}) except Customer.DoesNotExist: return Response({ 'message': 'customer doesnot exist', 'status': status.HTTP_400_BAD_REQUEST })
def post(self, request): company, branch = token_helper(request) request.data['company'] = company.id serializer = BranchSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response({ 'message': 'Branch added successfully', 'status': status.HTTP_200_OK, 'response': serializer.data }) return Response({ 'message': serializer.errors, 'status': status.HTTP_400_BAD_REQUEST })
def get(self, request): try: company, branch = token_helper(request) obj = company.branch.all() serializer = BranchSerializer(obj, many=True) return Response({ 'message': 'Branch list', 'status': status.HTTP_200_OK, 'response': serializer.data }) except: return Response({ 'mesasge': 'company doesnot exist', 'status': status.HTTP_400_BAD_REQUEST })
def get(self, request): company, branch = token_helper(request) try: obj = company.reward serializer = RewardSerializer(obj) return Response({ 'message': 'Reward', 'status': status.HTTP_200_OK, 'response': serializer.data }) except: return Response({ 'message': 'No reward defined yet', 'status': status.HTTP_400_BAD_REQUEST })
def post(self, request): company, branch = token_helper(request) request.data['branch'] = branch.id serializer = SeatingTypeSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response({ 'message': 'Seating type added', 'status': status.HTTP_200_OK, 'response': serializer.data }) return Response({ 'message': serializer.errors, 'status': status.HTTP_400_BAD_REQUEST })
def put(self, request, pk): company, branch = token_helper(request) invoice = Invoice.objects.get(pk=pk) if invoice.branch == branch: invoice.remark = request.data.get('remark') invoice.invoice_status='canceled' invoice.save() return Response({ 'message': 'remarks added', 'status': status.HTTP_200_OK }) else: return Response({ 'message': 'Unauthorized', 'status': status.HTTP_401_UNAUTHORIZED })
def patch(self, request, pk): company, branch = token_helper(request) vendor_payment = VendorPayment.objects.get(pk=pk) if vendor_payment.branch.company == company: serializer = VendorPaymentUpdateSerializer(vendor_payment, data=request.data, partial = True) if serializer.is_valid(): serializer.save() if serializer.data['payment_status'] == "paid": bill = BillOfStock.objects.get(branch = serializer.data['branch'], id = serializer.data['bill_of_stock']) if bill: bill.payment_status = serializer.data["payment_status"] bill.save() else: return Response({'message': 'payment status is unpaid please pay your due amount'}) return Response({"message":"success", "status":status.HTTP_200_OK, "response":serializer.data}) return Response({"message":"error", "status":status.HTTP_400_BAD_REQUEST, "response":serializer.errors})
def get(self, request, pk): try: company, branch = token_helper(request) obj = Invoice.objects.get(pk=pk) if obj.branch.company == company: serializer = InvoiceListSerializer(obj) return Response({'message': 'Invoice detail', 'status': status.HTTP_200_OK, 'response': serializer.data}) else: return Response({ 'message': 'Unauthorized', 'status': status.HTTP_401_UNAUTHORIZED }) except Exception as e: return Response({'message': "Invoice doesn't exist", 'status': status.HTTP_400_BAD_REQUEST})
def get(self, request): company, branch = token_helper(request) if branch is not None: seatings = Seating.objects.filter(branch=branch) reservations = [] for seating in seatings: reservations.append(seating.reservation) else: seatings = Seating.objects.filter(branch__company=company) reservations = [] for seating in seatings: reservations.append(seating.reservation) serializer = ReservationSerilizer(reservations, many=True) return Response({ 'message': 'Reservation list', 'status': status.HTTP_200_OK, 'response': serializer.data })