Пример #1
0
    def export_pdf(self, request, pk=None):
        response = HttpResponse(content_type='application/pdf')
        response[
            'Content-Disposition'] = 'attachment; filename=somefilename.pdf'
        queryset = self.filter_queryset(
            self.get_queryset().filter(is_init=False))

        pdf = TOPDF(response, 'Laporan Supplier', None)
        pdf.set_table_detail([
            pdf.set_subject('Laporan Supplier'),
            pdf.set_periode(request),
            pdf.set_user(request),
            pdf.set_date_created()
        ])
        pdf.set_break()

        temp = []
        number = 1
        header = [
            '#',
            'Nomer Supplier',
            'Nama Supplier',
            'Kontak Supplier',
            'Alamat Supplier',
        ]

        for obj in queryset:
            temp.append([
                number, obj.numcode, obj.name, obj.phone,
                short_text(obj.address)
            ])
            number += 1
        pdf.set_table(header, temp, 'LEFT', None)
        return pdf.build()
Пример #2
0
    def export_pdf(self, request, pk=None):
        response = HttpResponse(content_type='application/pdf')
        response[
            'Content-Disposition'] = 'attachment; filename=somefilename.pdf'
        queryset = self.filter_queryset(
            self.get_queryset().filter(is_init=False))

        pdf = TOPDF(response, 'Laporan Produk', None)
        pdf.set_table_detail([
            pdf.set_subject('Laporan Produk'),
            pdf.set_periode(request),
            pdf.set_user(request),
            pdf.set_date_created()
        ])
        pdf.set_break()

        temp = []
        number = 1
        header = [
            '#', 'Nomer Produk', 'Nama Produk', 'Harga Beli', 'Harga Jual',
            'Stok', 'Satuan'
        ]

        for obj in queryset:
            temp.append([
                number, obj.numcode, obj.name, obj.cogs, obj.price, obj.stock,
                obj.unit
            ])
            number += 1

        pdf.set_table(header, temp, 'LEFT', None)
        return pdf.build()
Пример #3
0
    def export_pdf(self, request, pk=None):
        response = HttpResponse(content_type='application/pdf')
        response[
            'Content-Disposition'] = 'attachment; filename=somefilename.pdf'
        queryset = self.filter_queryset(
            self.get_queryset().filter(is_init=False))
        products = queryset.values('product', ).annotate(
            Sum('total_in'), Sum('total_out'), Sum('end_balance'))

        pdf = TOPDF(response, 'Laporan Kartu Stok Produk Masuk & Keluar', None)
        pdf.set_heading('Laporan Kartu Stok Produk Masuk & Keluar')
        pdf.set_table_detail([
            pdf.set_subject('Laporan Kartu Stok'),
            pdf.set_periode(request),
            pdf.set_user(request),
            pdf.set_date_created()
        ])
        pdf.set_page_break()

        temp = []
        number = 1
        header = [
            '#', 'Tanggal', 'Saldo Awal', 'Stok Masuk', 'Stok Keluar',
            'Stok Akhir'
        ]
        for obj in products:
            product = Product.objects.get(pk=obj.get('product'))
            stock_cards = queryset.filter(product=product)
            pdf.set_table_detail([
                pdf.set_other('Kode Produk', product.numcode),
                pdf.set_other('Nama Produk', product.name),
                pdf.set_other(
                    'Total Masuk', '{} {}'.format(obj.get('total_in__sum'),
                                                  product.unit)),
                pdf.set_other(
                    'Total Keluar', '{} {}'.format(obj.get('total_out__sum'),
                                                   product.unit)),
                pdf.set_other('Total Saat Ini',
                              '{} {}'.format(product.stock, product.unit)),
            ])
            pdf.set_break()
            for sc in stock_cards:
                temp.append([
                    number, sc.date, '{} {}'.format(sc.init_balance,
                                                    product.unit),
                    '{} {}'.format(sc.total_in, product.unit),
                    '{} {}'.format(sc.total_out, product.unit),
                    '{} {}'.format(sc.end_balance, product.unit)
                ])
                number += 1
            pdf.set_table(header, temp, 'LEFT', None)
            temp = []
            number = 1
            pdf.set_page_break()

        return pdf.build()
Пример #4
0
    def export_pdf(self, request, pk=None):
        response = HttpResponse(content_type='application/pdf')
        response[
            'Content-Disposition'] = 'attachment; filename=somefilename.pdf'
        queryset = self.filter_queryset(self.get_queryset().filter(
            is_calculate=True, is_init=False))
        queryset = queryset.prefetch_related('stockoutitemout')

        pdf = TOPDF(response, 'Laporan Stok Keluar', None)
        pdf.set_heading('Laporan Stok Keluar')
        for obj in queryset:
            temp_detail = []
            temp_detail += [
                pdf.set_subject(f'Laporan Stok Keluar {obj.numcode}'),
                pdf.set_periode(request),
                pdf.set_user(request),
                pdf.set_date_created(),
            ]

            temp = []
            header = ['Nomer Produk', 'Nama Produk', 'Stok Keluar']
            items = obj.stockoutitemout.values(
                'product__numcode',
                'product__name',
                'product__unit',
            ).annotate(Sum('quantity'))
            total = obj.stockoutitemout.aggregate(Sum('quantity'))
            units = []

            for item in items:
                temp.append([
                    item.get('product__numcode'),
                    item.get('product__name'),
                    '{} {}'.format(item.get('quantity__sum'),
                                   item.get('product__unit')),
                ])

                units.append(item.get('product__unit'))

            units = ', '.join(list(set(units)))
            temp_detail += [
                pdf.set_other('Nomer Stok Keluar', obj.numcode),
                pdf.set_other('Tanggal', obj.date),
                pdf.set_other('Nomer Pelanggan', obj.customer.numcode),
                pdf.set_other('Pelanggan', obj.customer.name),
                pdf.set_other('Kontak Supplier', obj.customer.phone),
                pdf.set_other(
                    'Total Stok Keluar',
                    '{} {}'.format(total.get('quantity__sum'), units)),
            ]
            pdf.set_table_detail(temp_detail)
            pdf.set_break(0.2, 0.2)

            pdf.set_table(header, temp, 'LEFT', None)
            pdf.set_page_break()
        return pdf.build()
Пример #5
0
    def print_pdf(self, request, pk=None):
        obj = self.get_object()
        response = HttpResponse(content_type='application/pdf')
        response[
            'Content-Disposition'] = 'attachment; filename=somefilename.pdf'

        pdf = TOPDF(response, 'Laporan Stok Masuk', None)
        pdf.set_heading('Laporan Stok Masuk')
        temp_detail = []
        temp_detail += [
            pdf.set_subject(f'Laporan Stok Masuk {obj.numcode}'),
            pdf.set_periode(request),
            pdf.set_user(request),
            pdf.set_date_created(),
        ]

        temp = []
        header = ['Nomer Produk', 'Nama Produk', 'Stok Masuk']
        items = obj.stockinitemin.values(
            'product__numcode',
            'product__name',
            'product__unit',
        ).annotate(Sum('quantity'))
        total = obj.stockinitemin.aggregate(Sum('quantity'))

        units = []
        for item in items:
            temp.append([
                item.get('product__numcode'),
                item.get('product__name'),
                '{} {}'.format(item.get('quantity__sum'),
                               item.get('product__unit')),
            ])
            units.append(item.get('product__unit'))

        units = ', '.join(list(set(units)))

        temp_detail += [
            pdf.set_other('Nomer Stok Masuk', obj.numcode),
            pdf.set_other('Tanggal', obj.date),
            pdf.set_other('Nomer Supplier', obj.supplier.numcode),
            pdf.set_other('Supplier', obj.supplier.name),
            pdf.set_other('Kontak Supplier', obj.supplier.phone),
            pdf.set_other('Total Stok Masuk',
                          '{} {}'.format(total.get('quantity__sum'), units)),
        ]
        pdf.set_table_detail(temp_detail)
        pdf.set_break(0.2, 0.2)

        pdf.set_table(header, temp, 'LEFT', None)
        pdf.set_page_break()
        return pdf.build()
Пример #6
0
    def print_pdf(self, request, pk=None):
        obj = self.get_object()
        response = HttpResponse(content_type='application/pdf')
        response[
            'Content-Disposition'] = 'attachment; filename=somefilename.pdf'

        pdf = TOPDF(response, 'Laporan Barang Keluar', None)
        temp_detail = []
        temp_detail += [
            pdf.set_subject(f'Laporan Stok Keluar {obj.numcode}'),
            pdf.set_periode(request),
            pdf.set_user(request),
            pdf.set_date_created(),
        ]

        temp = []
        header = ['Nomer Produk', 'Nama Produk', 'Stok Masuk']
        items = obj.stockoutitemout.values(
            'product__numcode',
            'product__name',
        ).annotate(Sum('quantity'))
        total = obj.stockoutitemout.aggregate(Sum('quantity'))

        for item in items:
            temp.append([
                item.get('product__numcode'),
                item.get('product__name'),
                item.get('quantity__sum'),
            ])

        temp_detail += [
            pdf.set_other('Nomer Stok Keluar', obj.numcode),
            pdf.set_other('Tanggal', obj.date),
            pdf.set_other('Nomer Pelanggan', obj.customer.numcode),
            pdf.set_other('Pelanggan', obj.customer.name),
            pdf.set_other('Kontak Pelanggan', obj.customer.phone),
            pdf.set_other('Total Stok Keluar', total.get('quantity__sum')),
        ]
        pdf.set_table_detail(temp_detail)
        pdf.set_break(0.2, 0.2)

        pdf.set_table(header, temp, 'LEFT', None)
        pdf.set_page_break()
        return pdf.build()