Example #1
0
    def test_generate_proforma(self):
        provider = Provider('Pupik')
        provider.address = 'Kubelikova blah blah blah'
        provider.zip_code = '12655465'
        provider.city = 'Frantisek'
        provider.vat_id = 'CZ8590875682'
        provider.ir = '785684523'
        provider.email = '*****@*****.**'
        provider.bank_account = '2600420569/2010'
        provider.bank_name = 'RB'
        provider.note = u'zapsaná v obchodním rejstříku vedeném městským soudem v Praze,\noddíl C, vložka 176551'

        client = Client('Kkkk')
        client.summary = 'Bla blah blah'
        client.address = 'Kubelikova blah blah blah'
        client.zip_code = '12655465'
        client.city = 'Frantisek'
        client.vat_id = 'CZ8590875682'
        client.ir = '785684523'
        client.phone = '785684523'
        client.email = '*****@*****.**'
        client.note = u'zapsaná v obchodním rejstříku vedeném městským soudem v Praze,\noddíl C, vložka 176551'

        invoice = Invoice(client, provider, Creator('blah'))
        invoice.number = 'F20140007'
        invoice.use_tax = True
        invoice.title = u"Proforma faktura"
        invoice.add_item(Item(32, 600.6, description=u"Krátký popis", tax=50))
        invoice.add_item(Item(32, 2.5, tax=20))
        invoice.add_item(
            Item(
                5,
                25.42,
                description=u"Dlouhý popis blah blah blah blah blah blah blah blah blah blah blah "
                            u"blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
                            u"blah blah blah blah blah blah blah blah blah blah blah",
                tax=20,
            ),
        )
        for i in range(1, 26):
            invoice.add_item(Item(5, 25.42, description=u"Popis", tax=0))
        invoice.specific_symbol = 666
        invoice.date = datetime.date.today()
        invoice.variable_symbol = '000000001'
        invoice.number = 'F20140001'
        invoice.payback = datetime.date.today()
        invoice.currency = u'Kč'
        invoice.currency_locale = 'cs_CZ.UTF-8'
        invoice.rounding_result = True

        tmp_file = NamedTemporaryFile(delete=False)
        pdf = ProformaInvoice(invoice)
        pdf.gen(tmp_file.name, True)

        pdf = PdfFileReader(tmp_file)
        pdf_string = pdf.pages[1].extractText()
        self.assertTrue(u"Celkem s DPH: 32⁄255,-⁄K…" in pdf_string)
Example #2
0
    def test_generate(self):
        provider = Provider('Pupik')
        provider.address = 'Kubelikova blah blah blah'
        provider.zip = '12655465'
        provider.city = 'Frantisek'
        provider.vat_id = 'CZ8590875682'
        provider.ir = '785684523'
        provider.email = '*****@*****.**'
        provider.bank_account = '2600420569/2010'
        provider.bank_name = 'RB'
        provider.note = u'zapsaná v obchodním rejstříku vedeném městským soudem v Praze,\noddíl C, vložka 176551'

        client = Client('Kkkk')
        client.summary = 'Bla blah blah'
        client.address = 'Kubelikova blah blah blah'
        client.zip = '12655465'
        client.city = 'Frantisek'
        client.vat_id = 'CZ8590875682'
        client.ir = '785684523'
        client.phone = '785684523'
        client.email = '*****@*****.**'
        client.note = u'zapsaná v obchodním rejstříku vedeném městským soudem v Praze,\noddíl C, vložka 176551'

        invoice = Invoice(client, provider, Creator('blah'))
        invoice.title = u"Testovací faktura"
        invoice.add_item(Item(32, 600.6, description=u"Krátký popis", tax=50))
        invoice.add_item(Item(32, 2.5, tax=20))
        invoice.add_item(Item(5, 25.42,
                              description=u"Dlouhý popis blah blah blah blah blah blah blah blah blah blah blah "
                                          u"blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
                                          u"blah blah blah blah blah blah blah blah blah blah blah",
                              tax=20))
        for i in range(1, 26):
            invoice.add_item(Item(5, 25.42, description=u"Popis", tax=0))
        invoice.specific_symbol = 666
        invoice.taxable_date = datetime.date.today()
        invoice.variable_symbol = '000000001'
        invoice.number = 'F20140001'
        invoice.payback = datetime.date.today()
        invoice.currency = u'Kč'
        invoice.currency_locale = 'cs_CZ.UTF-8'
        invoice.rounding_result = True

        tmp_file = NamedTemporaryFile(delete=False)
        pdf = SimpleInvoice(invoice)
        pdf.gen(tmp_file.name, True)

        invoice.number = 1
        invoice.reason = u"Položka navíc"
        tmp_file1 = NamedTemporaryFile(delete=False)
        pdf = CorrectingInvoice(invoice)
        pdf.gen(tmp_file1.name)
Example #3
0
    def test_check_required_args(self):
        self.assertRaises(TypeError, Invoice)
        self.assertRaises(TypeError, Invoice, (), ())

        sample_data = (
            {'client': '', 'provider': '', 'creator': ''},
            {'client': Client('foo'), 'provider': '', 'creator': ''},
            {'client': Client('foo'), 'provider': Provider('bar'),
             'creator': ''},

        )
        for args in sample_data:
            self.assertRaises(AssertionError, Invoice, **args)
Example #4
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
            domain: Dict) -> List[EventType]:
        items = tracker.get_slot("dish")
        quant = tracker.get_slot("quant")
        id = tracker.get_slot("email")
        import os

        from tempfile import NamedTemporaryFile

        from InvoiceGenerator.api import Invoice, Item, Client, Provider, Creator

        os.environ["INVOICE_LANG"] = "en"

        client = Client('Valuable Customer')
        provider = Provider('XYZEE', bank_account='00000', bank_code='0000')
        creator = Creator('Amanul Haque')

        invoice = Invoice(client, provider, creator)
        invoice.currency_locale = 'en_US.UTF-8'
        for item, quantity in zip(items, quant):
            invoice.add_item(Item(quantity, 00, description=item))

        from InvoiceGenerator.pdf import SimpleInvoice

        pdf = SimpleInvoice(invoice)
        pdf.gen("D:\GoBaskt-Intern\Food CB\invoices\invoice.pdf",
                generate_qr_code=True)

        dispatcher.utter_message(text='Invoice Created')
        return []
Example #5
0
    def test_price(self):
        invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))
        items = [Item(1, 500), Item(2, 500), Item(3, 500)]
        for item in items:
            invoice.add_item(item)

        self.assertEqual(sum([item.total for item in items]), invoice.price)
Example #6
0
def gen_receipt(car_no='HR 02 AK 9064',mins = 50):
    os.environ["INVOICE_LANG"] = "en"
    client = Client("R/C Number: "+car_no)
    provider = Provider('Tez Parking', bank_account='2600420569', bank_code='2010',address='Tez Parking\n NIT Jalandhar', city='Jalandhar\n Punjab', zip_code='144001', phone='9138121216', email='*****@*****.**',  logo_filename='think.png')
    creator = Creator('Parking Operator')
    now = time()
    now = int(now)
    now = str(now)
    invoice = Invoice(client, provider, creator)
    invoice.currency_locale = 'en_US.UTF-8'
    rate =0.5
    if mins <= 60:
        rate = 20/60
    elif mins >60 and mins <= 180:
        rate = 40/60
    elif mins > 180 and mins <=300:
        rate = 50/60
    elif mins > 300 and mins <= 480:
        rate = 60/60
    elif mins > 480 and mins <= 720:
        rate = 80/60
    elif mins > 720 and mins <= 1440:
        rate = 100/60

    invoice_no = now+car_no[-4:]
    invoice.add_item(Item(mins, rate, description="Parking slot booking"))
    invoice.number = invoice_no

    pdf = SimpleInvoice(invoice)
    pdf.gen(invoice_no+".pdf", generate_qr_code=True)
    return invoice_no
Example #7
0
def invoice():
    pat = request.form.get('patient')
    idn = request.form.get('id')
    name = pat + "_" + idn
    client = Client(name)
    addr = Address(add)
    provider = Provider('ABC HOSPITAL',
                        bank_account='2600420569',
                        bank_code='2010')
    creator = Creator('DESK EXECUTIVE')
    bed = request.form.get('bedcost')
    med = request.form.get('medcost')
    dia = request.form.get('diacost')
    tot = request.form.get('total')
    d = request.form.get('Days')

    invoice = Invoice(client, provider, creator)
    invoice.currency = 'Rs'
    invoice.add_item(Item(d, bed, description="Bed cost"))
    invoice.add_item(Item(1, med, description="Medicine"))
    invoice.add_item(Item(1, dia, description="Diagnosis"))

    pdf = SimpleInvoice(invoice)
    url = "application/invoice/" + pat + "_" + idn + ".pdf"
    pdf.gen(url, generate_qr_code=True)

    patient_up = db.session.query(Patient).get(idn)
    patient_up.status = "discharged"
    db.session.commit()
    flash("Patient Discharged , Invoice generated in Invoice folder",
          "success")
    return redirect('/billing')
Example #8
0
def invoice(order):
    os.environ["INVOICE_LANG"] = "en"

    info = UserAddress.objects.get(user=order.client)
    info_seller = UserAddress.objects.get(user=User.objects.get(
        username='******'))
    client = Client('{}'.format(info.company_name),
                    '{} {}'.format(info.home_number, info.local_number),
                    '{} {}'.format(info.post, info.city))
    provider = Provider('{}'.format(info_seller.company_name),
                        '{} {}'.format(info_seller.home_number,
                                       info_seller.local_number),
                        '{} {}'.format(info_seller.post, info_seller.city),
                        bank_account='00000',
                        bank_code='0000')
    creator = Creator('Shop')

    invoice = Invoice(client, provider, creator)
    invoice.currency_locale = 'en_US.UTF-8'
    for item in order.product_list.product_list.all():
        invoice.add_item(
            Item('{}'.format(item.amount),
                 '{}'.format(item.product.price),
                 description="{}".format(item.product.name)))

    pdf = SimpleInvoice(invoice)
    pdf.gen("pro-forma.pdf")
Example #9
0
def gen_pdf(request):
    # pdf = render_to_pdf('shop/pdf_template.html', {"data" :"Subham"})
    # response = HttpResponse(pdf, content_type='application/pdf')
    # filename = "output.pdf"
    # content = "attachment; filename=output.pdf"
    # response['Content-Disposition'] = content
    # return response

    # choose english as language
    os.environ["INVOICE_LANG"] = "en"

    client = Client('Client company')
    provider = Provider('My company',
                        bank_account='2600420569',
                        bank_code='2010')
    creator = Creator('John Doe')

    invoice = Invoice(client, provider, creator)
    invoice.currency_locale = 'en_US.UTF-8'
    invoice.add_item(Item(32, 600, description="Item 1"))
    invoice.add_item(Item(60, 50, description="Item 2", tax=21))
    invoice.add_item(Item(50, 60, description="Item 3", tax=0))
    invoice.add_item(Item(5, 600, description="Item 4", tax=15))
    pdf = SimpleInvoice(invoice)
    pdf.gen("invoice.pdf", generate_qr_code=True)
    return JsonResponse({'message': 'This is search page'})
Example #10
0
    def test_check_attrs(self):
        attrs = ('title', 'variable_symbol', 'specific_symbol', 'paytype',
                 'currency', 'date', 'payback', 'taxable_date')

        invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))

        for attr in attrs:
            self.assertTrue(hasattr(invoice, attr))
Example #11
0
    def test_add_item(self):
        invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))

        self.assertRaises(AssertionError, invoice.add_item, '')

        for item in [Item(1, 500), Item(2, 500), Item(3, 500)]:
            invoice.add_item(item)

        self.assertEquals(3, len(invoice.items))
Example #12
0
    def test_generate_breakdown_vat_table(self):
        invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))
        invoice.add_item(Item(1, 500, tax=50))
        invoice.add_item(Item(3, 500, tax=50))
        invoice.add_item(Item(500, 5, tax=0))
        invoice.add_item(Item(5, 500, tax=0))

        expected = [(0.00, 5000.0, 5000.0, 0),(50.0, 2000.0, 3000.0, 1000.0)]

        self.assertEquals(expected, invoice.generate_breakdown_vat_table())
def setClient(clientName, clientAddress, clientPostCode, clientAdditionalData):
    client = Client(clientName, clientAddress, clientPostCode,
                    clientAdditionalData)
    invoice = Invoice(client,
                      provider,
                      creator,
                      number=datetime.datetime.now().strftime("%d-%m-%y"))
    invoice.currency_locale = 'pl_PL.UTF-8'
    invoice.use_tax = True
    return invoice
Example #14
0
 def test_price_tax_rounding(self):
     """
     Test, that the price that sums up to 1756.5 gets rounded according to rounding strategy.
     """
     invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))
     invoice.add_item(Item(5, 290, tax=21))
     invoice.rounding_result = True
     invoice.use_tax = True
     self.assertEqual(1754, invoice.price_tax)
     invoice.rounding_strategy = decimal.ROUND_HALF_UP
     self.assertEqual(1755, invoice.price_tax)
Example #15
0
    def test_price_tax(self):
        invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))
        items = [
            Item(1, 500, tax='99.9'),
            Item(2, 500, tax='99.9'),
            Item(3, 500, tax='99.9'),
        ]
        for item in items:
            invoice.add_item(item)

        self.assertEqual(5997, invoice.price_tax)
Example #16
0
    def test_generate_with_vat(self):
        invoice = Invoice(Client('Kkkk'), Provider('Pupik'), Creator('blah'))
        invoice.add_item(Item(32, 600))
        invoice.add_item(Item(60, 50, tax=10))
        invoice.add_item(Item(50, 60, tax=5))
        invoice.add_item(Item(5, 600, tax=50))

        tmp_file = NamedTemporaryFile()

        pdf = SimpleInvoice(invoice)
        pdf.gen(tmp_file.name)
Example #17
0
    def _get_invoice(self, order, clientName):
        client = Client(clientName)
        provider = Provider(os.getenv("company"), bank_account=os.getenv("bank_account"),
                            bank_code=os.getenv("bank_code"))
        creator = Creator(os.getenv("creator"))

        invoice = Invoice(client, provider, creator)
        for snapshot in order.snapshots:
            invoice.add_item(Item(count=snapshot.quantity, price=snapshot.price, description=snapshot.name,
                                  tax=int(os.getenv("Vat")), unit='$'))
        invoice.currency = '$'
        return invoice
Example #18
0
    def test_generate_breakdown_vat(self):
        invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))
        invoice.add_item(Item(1, 500, tax=50))
        invoice.add_item(Item(3, 500, tax=50))
        invoice.add_item(Item(500, 5, tax=0))
        invoice.add_item(Item(5, 500, tax=0))

        expected = {
            0.0: {'total': 5000.0, 'total_tax': 5000.0, 'tax': 0.0},
            50.0: {'total': 2000.0, 'total_tax': 3000.0, 'tax': 1000}}

        self.assertEquals(expected, invoice.generate_breakdown_vat())
def booking_invoice(request, booking_id):
    if request.method == 'POST':
        form = CreateInvoiceForm(request.POST or None)
        if form.is_valid():
            booking = Booking.objects.get(id=booking_id)
            gs = GuestBooking.objects.filter(booking=booking).first()
            items = RoomServiceBooking.objects.filter(booking=booking).all()
            os.environ["INVOICE_LANG"] = "en"
            client = Client(xstr(gs.guest.name) + " " + xstr(gs.guest.surname),
                            phone=xstr(gs.guest.phone),
                            email=xstr(gs.guest.email),
                            vat_id=xstr(gs.guest.id_number),
                            address=xstr(gs.guest.address),
                            zip_code=xstr(gs.guest.zip_code))
            provider = Provider(
                'Yahomas',
                bank_account='22946662932',
                bank_code='210',
                city="Istanbul",
                zip_code="34700",
                phone="+9002122443262",
                # logo_filename="/home/tugcan/Dropbox/SWE/Yahomas/yahomas_stamp_small.png"
            )
            creator = Creator(
                'Yahomas',
                # stamp_filename="/home/tugcan/Dropbox/SWE/Yahomas/YahomasStamp.png"
            )
            invoice = Invoice(client, provider, creator)
            invoice.currency = "$"
            invoice.number = str(booking_id)[:13]
            days = abs((booking.start_date - booking.end_date).days)
            if days <= 0:
                days = 1
            invoice.add_item(
                Item(days,
                     booking.room.price *
                     (100 - float(form.cleaned_data['discount'])) / 100,
                     description="Room 1"))
            for item in items:
                invoice.add_item(
                    Item(1, item.item.price, description=item.item.name))

            pdf = SimpleInvoice(invoice)
            file_path = f"{djangoSettings.STATIC_ROOT}/{str(booking_id)}.pdf"
            pdf.gen(file_path, generate_qr_code=True)

            with open(file_path, 'rb') as file:
                response = HttpResponse(file.read(),
                                        content_type='application/pdf')
                response[
                    'Content-Disposition'] = 'attachment; filename=invoice.pdf'
                return response
Example #20
0
    def test_generate(self):
        provider = Provider('Pupik')
        provider.address = 'Kubelikova blah blah blah'
        provider.zip = '12655465'
        provider.city = 'Frantisek'
        provider.vat_id = 'CZ8590875682'
        provider.ir = '785684523'
        provider.email = '*****@*****.**'
        provider.bank_account = '2600420569/2010'
        provider.bank_name = 'RB'
        provider.note = u'zapsaná v obchodním rejstříku vedeném městským soudem v Praze,\noddíl C, vložka 176551'

        client = Client('Kkkk')
        client.summary = 'Bla blah blah'
        client.address = 'Kubelikova blah blah blah'
        client.zip = '12655465'
        client.city = 'Frantisek'
        client.vat_id = 'CZ8590875682'
        client.ir = '785684523'
        client.phone = '785684523'
        client.email = '*****@*****.**'
        client.note = u'zapsaná v obchodním rejstříku vedeném městským soudem v Praze,\noddíl C, vložka 176551'

        invoice = Invoice(client, provider, Creator('blah'))
        invoice.add_item(Item(32, 600.6, tax=50))
        invoice.add_item(Item(32, 2.5, tax=20))
        invoice.add_item(Item(5, 25.42, tax=20))
        invoice.add_item(Item(5, 25.42, tax=0))
        invoice.specific_symbol = 666
        invoice.taxable_date = '1.1.1979'
        invoice.variable_symbol = '000000001'
        invoice.currency = u'Kč'
        invoice.rounding_result = True


        tmp_file = NamedTemporaryFile(delete=False)

        pdf = SimpleInvoice(invoice)
        pdf.gen(tmp_file.name, True)
Example #21
0
    def test_generate_with_vat(self):
        invoice = Invoice(Client('Kkkk'), Provider('Pupik'), Creator('blah'))
        invoice.number = 'F20140001'
        invoice.add_item(Item(32, 600))
        invoice.add_item(Item(60, 50, tax=10))
        invoice.add_item(Item(50, 60, tax=5))
        invoice.add_item(Item(5, 600, tax=50))
        invoice.currency_locale = 'en_US.UTF-8'

        tmp_file = NamedTemporaryFile(delete=False)

        pdf = SimpleInvoice(invoice)
        pdf.gen(tmp_file.name)
Example #22
0
def bill_generator(request):
    try:
        global bill_no
        fs = FileSystemStorage()
        os.environ["INVOICE_LANG"] = "en"
        table_no = request.data["no"]
        client = Client('Table ' + str(table_no))
        clerk = request.data["email"]
        provider = Provider('Restaurant',
                            bank_account='2600420569',
                            bank_code='2010')
        creator = Creator(clerk)
        invoice = Invoice(client, provider, creator)

        data = request.data["order"]  # quantity,price, name

        invoice.currency_locale = 'en_IN'
        invoice.currency = "INR"
        invoice.number = bill_no
        balance = list(Variable.objects.all().values())[0]["balance"]
        bill_no += 1

        for item in data:
            invoice.add_item(
                Item(item[1], item[2] / item[1], description=item[0], tax=14))
            my_custom_sql(
                "insert into sales(item_code,quantity) values({},{})".format(
                    int(item[3]), item[1]))
            balance += item[2]
            #print("select count(*) from sales where (item_code = {} && date >= {});".format(item[3], str((datetime.today() - timedelta(days=3)).strftime("%Y-%d,%Y"))))
            # count = my_custom_sql("select count(*) from sales where (item_code = {} && date >= {});".format(item[3], str((datetime.today() - timedelta(days=3)).strftime("%Y-%m-%d"))))[0][0]

        Variable.objects.all().delete()
        Variable(balance=balance).save()
        filename = "invoice" + str(bill_no) + ".pdf"
        pdf = SimpleInvoice(invoice)
        pdf.gen(filename, generate_qr_code=True)
        t = Thread(target=calculateThreshold, args=(data, ))
        t.start()

        if fs.exists(filename):
            with fs.open(filename) as pdf:
                response = HttpResponse(pdf, content_type='application/pdf')
                #response['Content-Disposition'] = 'attachment; filename="mypdf.pdf"' #user will be prompted with the browser’s open/save file
                response['Content-Disposition'] = 'inline; filename={}'.format(
                    filename
                )  #user will be prompted display the PDF in the browser
                return response

    except FileNotFoundError:
        raise Http404()
def create_invoice(provider_name, provider_address, provider_postcode, client_name, client_address, client_postcode, items_list):
    provider = Provider(provider_name, provider_address, provider_postcode, bank_account='2600420569', bank_code='2010')
    creator = Creator('')
    client = Client(client_name, client_address, client_postcode)

    invoice = Invoice(client, provider, creator, number=datetime.datetime.now().strftime("%d-%m-%y"))
    invoice.currency_locale = 'pl_PL.UTF-8'
    invoice.use_tax = False
    for i in range(0,len(items_list),3):
        item_count = items_list[i]
        item_price = items_list[i+1]
        item_name = items_list[i+2]
        invoice.add_item(Item(item_count, item_price, description=item_name))
    pdf = ProformaInvoice(invoice)
    pdf.gen("Proforma.pdf", generate_qr_code=False)
def setProvider(clientName, clientAddress, clientPostCode,
                clientAdditionalData):
    provider = Provider(clientName, clientAddress, clientPostCode,
                        clientAdditionalData)
    client = Client('AS Lomza',
                    'Niewodowo 50',
                    "18-421 Piątnica",
                    bank_account='2600420569',
                    bank_code='2010')
    invoice = Invoice(client,
                      provider,
                      creator,
                      number=datetime.datetime.now().strftime("%d-%m-%y"))
    invoice.currency_locale = 'pl_PL.UTF-8'
    invoice.use_tax = True
    return invoice
Example #25
0
def create_invoice(user, order):
    os.environ["INVOICE_LANG"] = "en"

    client_address = user.customer.street + ',<br/>' + user.customer.area
    client_zip_code = user.customer.zipcode
    client_phone = str(user.customer.phone)
    client_email = user.email

    provider_address = 'No.185, Bellman Ford St.' + ',<br/>' + 'T. Nagar'
    provider_zip_code = '600056'
    provider_phone = '044-42353988'
    provider_email = '*****@*****.**'
    payment_method = order.get_payment_type_display()

    client = Client(
        summary=user.customer.fullname,
        address=client_address,
        zip_code=client_zip_code,
        phone=client_phone,
        email=client_email,
    )
    provider = Provider(
        summary='The Water Company',
        address=provider_address,
        zip_code=provider_zip_code,
        phone=provider_phone,
        email=provider_email,
        payment_method=payment_method,
    )
    creator = Creator('TWC')

    invoice = Invoice(client, provider, creator, str(order.id))
    invoice.currency_locale = 'en.UTF-8'
    items = OrderItem.objects.filter(order=order)
    for item in items:
        invoice.add_item(
            Item(item.quantity, item.price, description=item.product.name))

    pdf = SimpleInvoice(invoice)
    pdf.gen(MEDIA_ROOT + '/orders/' + str(order.id) + ".pdf",
            generate_qr_code=False)
Example #26
0
    def invoicing(self, c, lines, iva=21, invoice_num=None):
        if not invoice_num:
            invoice_num = "F000001"
        else:
            invoice_num = 'F{}'.format(str(invoice_num).zfill(6))
        # choose catalan language
        os.environ["INVOICE_LANG"] = "ca"

        client = Client(
            c.name, address=c.direccio, zip_code=c.cp, phone=c.phone, email=c.email, vat_id=c.cif,
        )
        name, cp, address, city, email, phone = self.get_config_file_info()

        provider = Provider(
            name, zip_code=cp, address=address, city=city, email=email, phone=phone, vat_id='E17087289',
            logo_filename=ICONS + '/logo_factura.jpg'
        )

        creator = Creator(name)

        invoice = Invoice(client, provider, creator)
        os.environ["INVOICE_LANG"] = "ca"
        invoice.currency_locale = 'ca_ES.UTF-8'
        invoice.currency = '€'
        invoice.number = invoice_num
        invoice.use_tax = True
        invoice.date = datetime.now()
        for line_product in lines:
            price_without_iva = self.extract_iva(line_product.price, iva)
            invoice.add_item(
                Item(
                    count=line_product.quant, price=float(price_without_iva), description=line_product.name, tax=iva
                )
            )

        f = NamedTemporaryFile(delete=False, suffix='.pdf')
        pdf_path = f.name
        pdf = SimpleInvoice(invoice)
        pdf.gen(pdf_path, generate_qr_code=False)

        return pdf_path
Example #27
0
    def test_generate_with_vat(self):
        os.environ["INVOICE_LANG"] = "en"
        invoice = Invoice(Client('Kkkk'), Provider('Pupik'), Creator('blah'))
        invoice.number = 'F20140001'
        invoice.use_tax = True
        invoice.add_item(Item(32, 600))
        invoice.add_item(Item(60, 50, tax=10))
        invoice.add_item(Item(50, 60, tax=5))
        invoice.add_item(Item(5, 600, tax=50))
        invoice.currency_locale = 'en_US.UTF-8'
        invoice.currency = 'USD'

        tmp_file = NamedTemporaryFile(delete=False)

        pdf = SimpleInvoice(invoice)
        pdf.gen(tmp_file.name)

        pdf = PdfFileReader(tmp_file)
        pdf_string = pdf.pages[0].extractText()
        self.assertTrue("$3,000.00" in pdf_string)
        self.assertTrue("Total with tax: $30,150.00" in pdf_string)
        self.assertTrue("Creator: blah" in pdf_string)
Example #28
0
def invoice():
    form = InvoiceForm()
    print(form)
    if form.validate_on_submit():
        client = form.client.data
        creator = form.creator.data
        item_name = form.item_name.data
        price = form.price.data
        quantity = form.quantity.data
        a = current_user
        client = Client(client)
        provider = Provider(a.name, bank_account=a.gstnumber, bank_code='2018')
        creator = Creator(creator)
        os.environ["INVOICE_LANG"] = "en"
        invoice = Invoice(client, provider, creator)
        invoice.currency_locale = "en_US.UTF_8"

        invoice.add_item(Item(quantity, price, item_name))
        from InvoiceGenerator.pdf import SimpleInvoice
        pdf = SimpleInvoice(invoice)
        pdf.gen("invoice.pdf", generate_qr_code=False)
        return send_file("invoice.pdf")
    return render_template('invoice.html', form=form)
Example #29
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)
        if self.request.user.profile.is_warsztat():
            form = WarsztatCheckoutForm(self.request.POST or None)

        try:
            order = Order.objects.get(customer=self.request.user, ordered=False)
            if form.is_valid():
                street_address = form.cleaned_data.get('street_address')
                apartment_address = form.cleaned_data.get('apartment_address')
                country = form.cleaned_data.get('country')
                zip_code = form.cleaned_data.get('zip_code')
                payment_option = form.cleaned_data.get('payment_option')

                checkout_address = CheckoutAddress(
                    user=self.request.user,
                    street_address=street_address,
                    apartment_address=apartment_address,
                    country=country,
                    zip_code=zip_code
                )
                checkout_address.save()
                order.checkout_address = checkout_address
                order.save()

                PAYMENT_OPTIONS = tuple()
                if self.request.user.profile.is_warsztat():
                    PAYMENT_OPTIONS = PAYMENT_WARSZTAT
                else:
                    PAYMENT_OPTIONS = PAYMENT

                for payment_tuple in PAYMENT_OPTIONS:
                    if payment_option == payment_tuple[0]:
                        order.payment_method = payment_tuple[1]
                        order.ordered = True

                        if order.payment_method == 'Faktura':
                            os.environ["INVOICE_LANG"] = "pl"

                            client = Client(order.customer.username + '<br />'
                                            + str(order.customer.email) + '<br />'
                                            + order.customer.profile.street_address + '<br />'
                                            + order.customer.profile.postal_code + ' '
                                            + order.customer.profile.city
                                            )
                            provider = Provider('Auto Parts', bank_account='2600420569', bank_code='2010')
                            creator = Creator('Jan Kowalski')
                            invoice = Invoice(client, provider, creator)
                            invoice.number = order.id
                            invoice.currency = 'PLN'
                            invoice.currency_locale = 'pl_PL.UTF-8'
                            for order_line in order.order_lines.all():
                                invoice.add_item(Item(order_line.quantity, order_line.product.get_discount_price(),
                                                      description=order_line.product.name, tax=23))

                            pdf_name = "invoice" + str(order.id) + ".pdf"
                            pdf = SimpleInvoice(invoice)
                            pdf.gen(pdf_name)
                            with open(pdf_name, 'rb') as f:
                                order.invoice_file.save(pdf_name, File(f))
                            if os.path.exists(pdf_name):
                                os.remove(pdf_name)

                        order.save()
                        return redirect('pages:orders_list')

                messages.warning(self.request, "Niepoprawna metoda płatności")
                return redirect('pages:checkout')

        except ObjectDoesNotExist:
            messages.error(self.request, "Nie masz żadnego zamówienia")
            return redirect("pages:order-summary")
Example #30
0
    def test_difference_rounding(self):
        invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))
        invoice.add_item(Item(1, 2.5, tax=50))

        self.assertEquals(0.25, invoice.difference_in_rounding)
Example #31
0
    def test_generate(self):
        provider = Provider('Pupik')
        provider.address = 'Kubelikova blah blah blah'
        provider.zip_code = '12655465'
        provider.city = 'Frantisek'
        provider.vat_id = 'CZ8590875682'
        provider.ir = '785684523'
        provider.email = '*****@*****.**'
        provider.bank_account = '2600420569'
        provider.bank_code = '2010'
        provider.bank_name = 'RB'
        provider.note = u'zapsaná v obchodním rejstříku vedeném městským soudem v Praze,\noddíl C, vložka 176551'

        client = Client('Kkkk')
        client.summary = 'Bla blah blah'
        client.address = 'Kubelikova blah blah blah'
        client.zip_code = '12655465'
        client.city = 'Frantisek'
        client.vat_id = 'CZ8590875682'
        client.ir = '785684523'
        client.phone = '785684523'
        client.email = '*****@*****.**'
        client.note = u'zapsaná v obchodním rejstříku vedeném městským soudem v Praze,\noddíl C, vložka 176551'

        invoice = Invoice(client, provider, Creator('blah'))
        invoice.use_tax = True
        invoice.title = u"Testovací faktura"
        invoice.add_item(Item(32, '600.6', description=u"Krátký popis", tax=15))
        invoice.add_item(Item(32, '2.5', tax=21))
        invoice.add_item(
            Item(
                5, '25.42',
                description=u"Dlouhý popis blah blah blah blah blah blah blah blah blah blah blah "
                            u"blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
                            u"blah blah blah blah blah blah blah blah blah blah blah",
                tax=21,),)
        for i in range(1, 26):
            invoice.add_item(Item(5, '25.42', description=u"Popis", tax=0))
        invoice.specific_symbol = 666
        invoice.taxable_date = datetime.date.today()
        invoice.variable_symbol = '000000001'
        invoice.number = 'F20140001'
        invoice.payback = datetime.date.today()
        invoice.currency = u'Kč'
        invoice.currency_locale = 'cs_CZ.UTF-8'
        invoice.rounding_result = True

        tmp_file = NamedTemporaryFile(delete=False)
        SimpleInvoice(invoice).gen(tmp_file.name)
        xml_string = tmp_file.read()

        root = self.assertXmlDocument(xml_string)
        self.assertXpathValues(
            root,
            './dataPack/dataPackItem/invoice/partnerIdentity/address/street/text()',
            'Kubelikova blah blah blah',
        )
        self.assertXpathValues(
            root,
            './dataPack/dataPackItem/invoice/invoiceHeader/number/numberRequested/text()',
            'F20140001',
        )
        self.assertXpathValues(
            root,
            './dataPack/dataPackItem/invoice/invoiceDetail/invoiceItem/text/text()',
            'Popis',
        )
        self.assertXpathValues(
            root,
            './dataPack/dataPackItem/invoice/invoiceSummary/priceLow/text/text()',
            '22102.080',
        )
        self.assertXpathValues(
            root,
            './dataPack/dataPackItem/invoice/invoiceSummary/priceHighVAT/text/text()',
            '43.4910',
        )
Example #32
0
    def test_use_tax(self):
        invoice = Invoice(Client('Foo'), Provider('Bar'), Creator('Blah'))
        invoice.add_item(Item(1, 500, tax=99.9))
        invoice.add_item(Item(500, 5))

        self.assertTrue(invoice.use_tax)
Example #33
0
import os
from InvoiceGenerator.api import Invoice, Item, Client, Provider, Creator
from InvoiceGenerator.pdf import SimpleInvoice
from tempfile import NamedTemporaryFile

# choose en as language
os.environ["INVOICE_LANG"] = "tr"

client = Client('İşin Başı Reklam Bilgi Teknolojileri ve Ticaret A.Ş')
client.address = 'GÜLBAHÇE GÜLBAHÇE CAD.NO:1/17'
client.city = 'URLA/İZMİR'
client.zip = '35000'
client.vat_id = '4820575342'
client.ir = 'Urla'
provider = Provider('İşin Başı Reklam Bilgi Teknolojileri ve Ticaret A.Ş')
provider.address = 'GÜLBAHÇE GÜLBAHÇE CAD.NO:1/17'
provider.city = 'URLA/İZMİR'
provider.zip = '35000'
provider.vat_id = '4820575342'
provider.ir = 'Urla'
creator = Creator('Workif')

invoice = Invoice(client, provider, creator)
invoice.currency_locale = 'tr_TR.UTF-8'
invoice.currency = '₺'
invoice.date = '10-12-2017'
invoice.number = '205123123112'
invoice.add_item(Item(1, 1.24, description="Ödeme Hizmeti Komisyonu"))

tmp_file = NamedTemporaryFile(delete=False)
pdf = SimpleInvoice(invoice)
import os

from tempfile import NamedTemporaryFile

from InvoiceGenerator.api import Invoice, Item, Client, Provider, Creator
from InvoiceGenerator.pdf import SimpleInvoice
# choose english as language
os.environ["INVOICE_LANG"] = "en"

client = Client('Client company')
provider = Provider('My company', bank_account='2600420569', bank_code='2010')
creator = Creator('John Doe')

invoice = Invoice(client, provider, creator)
invoice.currency_locale = 'en_US.UTF-8'
invoice.add_item(Item(32, 600, description="Item 1"))
invoice.add_item(Item(60, 50, description="Item 2", tax=21))
invoice.add_item(Item(50, 60, description="Item 3", tax=0))
invoice.add_item(Item(5, 600, description="Item 4", tax=15))

pdf = SimpleInvoice(invoice)
pdf.gen("invoice.pdf", generate_qr_code=True)