Exemplo n.º 1
0
    def SnapAndPrint(self):
        subprocess.run(PIC_COMMAND.split(" ")) 
        dummy = Dummy()
        
        dummy.text("\n\n\nBravoLT - GRPS - 2019\n\n\n")
        dummy.image("out.jpg")
        dummy.text("\n\n\nBravoLT - GRPS - 2019")

        self.printer._raw(dummy.output)
Exemplo n.º 2
0
    def test_print():

        global pos

        pos.close()

        dp = Dummy()

        bold_emphasis = b"\x1b\x21\x08"  # Sets text to bold
        second_typeface_emphasis = b"\x1b\x21\x01"  # Selects font B (different code to actual font size stuff)
        reset_emphasis = b"\x1b\x21\x00"  # Reset emphasis
        font_size_2x = b"\x1d\x21\x10"  # Change text size to 2x
        font_reset = b"\x1d\x21\x00"  # Reset text size

        dp.text("Test print\n\n")

        dp._raw(reset_emphasis)
        dp._raw(font_size_2x)
        dp.text("Font size two" + "\n")
        dp._raw(font_reset)

        dp._raw(second_typeface_emphasis)
        dp.text("Typeface two\n")
        dp._raw(reset_emphasis)

        dp._raw(bold_emphasis)
        dp.text("Bold text\n")
        dp._raw(reset_emphasis)

        dp.text("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"£$%^&*()-=_+[]{}'#@~;:<>?,./\\|'")

        dp.cut()

        test_handle = None

        test_handle = PosPrinter(int("0x" + SettingsUi.printProductIDLine.text(), base=16),
                                 int("0x" + SettingsUi.printVendorIDLine.text(), base=16),
                                 test_mode=True)

        if test_handle.failed:
            return

        test_handle.print(dp.output)
        test_handle.close()

        pos.reset()

        popup_message("Test printed!")
def test_printer_dummy_clear():
    printer = Dummy()
    printer.text("Hello")
    printer.clear()
    assert printer.output == b""
Exemplo n.º 4
0
def print_message(message, header):
    """
    Prints a message through the POS printer with set formatting.
    Does __not__ take note of the current enable setting for the printer.

    TODO: Handle NoneType in any message field

    :param message: instance of class HoppieMessage
    :param header: string, printout header
    :return: nil
    """

    bold_emphasis = b"\x1b\x21\x08"  # Sets text to bold
    second_typeface_emphasis = b"\x1b\x21\x01"  # Selects font B (different code to actual font size stuff)
    reset_emphasis = b"\x1b\x21\x00"  # Reset emphasis
    font_size_2x = b"\x1d\x21\x10"  # Change text size to 2x
    font_reset = b"\x1d\x21\x00"  # Reset text size

    dpos = Dummy()

    # print header
    dpos._raw(reset_emphasis)
    dpos._raw(font_size_2x)
    dpos.text(header + "\n")
    dpos._raw(font_reset)

    # print associated time
    dpos._raw(second_typeface_emphasis)
    dpos.text(f"Received {datetime.datetime.utcfromtimestamp(message.time).strftime('%d-%H%Mz')}")
    dpos.text("\n")
    dpos._raw(reset_emphasis)

    # print message type
    dpos._raw(bold_emphasis)
    dpos.text("Type: ")
    dpos._raw(reset_emphasis)
    dpos.text("{}\n".format(message.mode))

    # print sender
    dpos._raw(bold_emphasis)
    dpos.text("From: ")
    dpos._raw(reset_emphasis)
    dpos.text("{}\n".format(message.sender))

    # print message
    dpos._raw(bold_emphasis)
    dpos.text("Message: ")
    dpos._raw(reset_emphasis)
    dpos.text("{}\n\n\n".format(message.message))

    pos.print(dpos.output)

    helper.add_event((lambda: True), (lambda: ui.statusbar.showMessage("Commands sent to printer")))
Exemplo n.º 5
0
class DummyPrinter(object):
    def __init__(self):
        pass

    # TODO: find a way to clear out this set

    def print_ticket(self, order):
        self.d = Dummy()
        self.d.line_spacing(120)
        self.d.ln(1)

        self.d.set(align="center",
                   bold=True,
                   underline=2,
                   double_height=False,
                   double_width=False,
                   custom_size=True,
                   smooth=True,
                   width=2,
                   height=2,
                   invert=False,
                   density=8,
                   font='a')
        self.d.block_text(str(order.order_number) + ' ' + order.name + '\n',
                          font='a')
        self.d.ln(1)

        self.d.set(align="center",
                   bold=False,
                   underline=0,
                   double_height=False,
                   double_width=False,
                   custom_size=True,
                   smooth=True,
                   width=2,
                   height=2,
                   invert=False,
                   density=8,
                   font='a')
        self.d.block_text(order.order_type + '\n', columns=20, font='a')
        self.d.ln(1)

        self.d.text(order.formatted_number + '\n')
        self.d.text(order.date + '\n')
        self.d.text(order.time + '\n')
        self.d.text(' \n')

        self.d.set(align="left",
                   bold=True,
                   underline=0,
                   double_height=False,
                   double_width=False,
                   custom_size=True,
                   smooth=True,
                   width=2,
                   height=2,
                   invert=False,
                   density=8,
                   font='b')
        self.d.text('PICKUP TIME\n')

        self.d.set(align="left",
                   bold=False,
                   underline=0,
                   double_height=False,
                   double_width=False,
                   custom_size=True,
                   smooth=True,
                   width=2,
                   height=2,
                   invert=False,
                   density=8,
                   font='a')
        self.d.block_text(order.pickup_time + '\n', columns=20, font='a')

        self.d.ln(2)

        self.d.set(align="left",
                   bold=True,
                   underline=0,
                   double_height=False,
                   double_width=False,
                   custom_size=True,
                   smooth=True,
                   width=2,
                   height=2,
                   invert=False,
                   density=8,
                   font='b')
        self.d.text('ORDER\n')

        self.d.set(align="left",
                   bold=False,
                   underline=0,
                   double_height=False,
                   double_width=False,
                   custom_size=True,
                   smooth=True,
                   width=2,
                   height=2,
                   invert=False,
                   density=8,
                   font='a')
        self.d.block_text(order.order + '\n', columns=20, font='a')

        self.d.ln(2)

        if order.notes != '':
            self.d.set(align="left",
                       bold=True,
                       underline=0,
                       double_height=False,
                       double_width=False,
                       custom_size=True,
                       smooth=True,
                       width=2,
                       height=2,
                       invert=False,
                       density=8,
                       font='b')
            self.d.text('NOTES\n')

            self.d.set(align="left",
                       bold=False,
                       underline=0,
                       double_height=False,
                       double_width=False,
                       custom_size=True,
                       smooth=True,
                       width=2,
                       height=2,
                       invert=False,
                       density=8,
                       font='a')
            self.d.block_text(order.notes + '\n', columns=20, font='a')

        self.d.cut()

    def print_error_message(self, error_message):
        pass
Exemplo n.º 6
0
    def post(self, request):
        sale_form = SaleFormSet(request.POST, prefix="sale")

        # ======================================
        # Get investor who buy this checkout
        # ======================================
        investor_id = request.POST.get('investor', '')
        if investor_id == "":
            investor_id = 0
        investor = Investor.objects.filter(id=investor_id).first()
        if investor:
            buyer = investor.created_by
        # if buyer is not an investor, set buyer to id 0
        else:
            buyer = User.objects.filter(id=0).first()
            if not buyer:
                buyer = User(id=0,
                             username="******",
                             email="*****@*****.**",
                             first_name="None")
                buyer.save()
        # ======================================

        is_checkout = False
        parameter = request.POST.get("parameter")

        # ======================================
        # If checkhout finished, we add all the item in cart to checkout table
        # ======================================
        if parameter == "checkout":
            is_checkout = True

            if request.POST.get("price") != "" and request.POST.get(
                    "paid") != "":
                checkout = Checkout(
                    price=request.POST.get("price"),
                    paid=request.POST.get("paid"),
                    created_by=buyer,
                    sale_by=request.user,
                )
                checkout.save()
            else:
                is_checkout = False
                parameter = "hold"
        # ======================================

        # ======================================
        # For every item in sale form, we add it into table
        # ======================================
        item_sale_text = ""
        item_sale_discount_text = ""
        item_sale_amout = 0
        item_sale_discount_amout = 0
        item_sale_cashback_amout = 0
        for s in sale_form:
            if s.is_valid() and len(s.cleaned_data) > 0:
                product = Product.objects.filter(
                    id62=s.cleaned_data['product_id62']).first()
                item_sale = Sale(
                    product=product,
                    amount=int(s.cleaned_data['quantity']) *
                    int(s.cleaned_data['price'].replace(",", "")),
                    qty=int(s.cleaned_data['quantity']),
                    price=int(s.cleaned_data['price'].replace(",", "")),
                    created_by=buyer,
                    sale_by=request.user,
                )
                if product.applied_discount():
                    item_sale.discount = product.applied_discount()
                if is_checkout:
                    item_sale.status = 4
                    item_sale.checkout = checkout
                    item_sale.save()
                    cashback = item_sale.sold(request.user, buyer)
                    product.sale(int(s.cleaned_data['quantity']))

                    item_sale_amout += item_sale.amount
                    item_sale_text += "%s    @%d   x%d   %d\n" % (
                        product.display_name, item_sale.price, item_sale.qty,
                        item_sale.amount)
                    item_sale_cashback_amout += cashback
                    if product.applied_discount():
                        amount_discounted = item_sale.qty * (
                            item_sale.price - item_sale.discounted_price)
                        item_sale_discount_text += "%s       %d%%   %d\n" % (
                            product.display_name, item_sale.discount.reduction,
                            amount_discounted)
                        item_sale_discount_amout += amount_discounted
                else:
                    if parameter == "cancel":
                        item_sale.status = 2
                    if parameter == "hold":
                        item_sale.status = 3
                    item_sale.save()
            else:
                print s.errors
        # ======================================

        p_conf = settings.PRINTER_CONF
        if is_checkout and p_conf['print_on']:
            usb_conf = p_conf['usb_conf']
            printer = Usb(usb_conf['vendor_id'], usb_conf['product_id'],
                          usb_conf['timeout'], usb_conf['input_endpoint'],
                          usb_conf['output_endpoint'])

            receipt = Dummy()
            receipt.set(height=2, align='center', text_type="B")
            receipt.text('Koperasi Warung Kita Untuk Kita\n')
            receipt.set(align='center')
            receipt.text('Tanggal: %s - Pukul: %s\n' %
                         (datetime.datetime.now().strftime("%d-%m-%Y"),
                          datetime.datetime.now().strftime("%H:%M")))
            receipt.text('==============================================\n\n')
            receipt.set(align='right')
            receipt.text(item_sale_text)
            receipt.text('============================\n')
            receipt.text('Total :      Rp. %d\n\n' % item_sale_amout)
            if item_sale_discount_amout > 0:
                receipt.set(align='center')
                receipt.text('Diskon\n')
                receipt.set(align='right')
                receipt.text(item_sale_discount_text)
                receipt.text('============================\n')
                receipt.text('Total Diskon:      Rp.%d\n\n' %
                             item_sale_discount_amout)

            receipt.set(text_type="B", align="right")
            receipt.text('Total Harga :      Rp.%d\n' % item_sale_amout)
            if item_sale_discount_amout > 0:
                receipt.text('- Rp.%d\n' % item_sale_discount_amout)
                receipt.text('(Rp.%d)\n' %
                             (item_sale_amout - item_sale_discount_amout))
            receipt.text('Bayar :      Rp.%s\n' % checkout.paid)
            receipt.text('Kembalian :      Rp.%d\n\n\n' %
                         (int(checkout.paid) -
                          (item_sale_amout - item_sale_discount_amout)))

            receipt.set(height=2, align='center', text_type="B")
            if buyer.id > 0:
                receipt.text('%s %s\nTerimakasih Telah Berbelanja\n\n' %
                             (buyer.first_name, buyer.last_name))
                receipt.text('Anda Mendapatkan Cashback Sebesar Rp.%d' %
                             item_sale_cashback_amout)
            else:
                receipt.text('Terimakasih Telah Berbelanja')

            if p_conf['cut_paper']:
                receipt.cut()

            if p_conf['kick_drawer']:
                receipt.cashdraw(2)

            printer._raw(receipt.output)

        return redirect(reverse("core:sale"))
Exemplo n.º 7
0
class Rapor(QtGui.QDialog , Ui_Dialog7):
    def __init__(self):
        QtGui.QDialog.__init__(self)
        self.setupUi(self)
        #self.myddb = Myddb()
        self.kontrol=0
        self.dt = datetime.now() - timedelta(hours=5)
        self.dt = QtCore.QDate.fromString(str(self.dt.date()), 'yyyy-MM-dd')

        self.tableWidget.setRowCount(0)
        self.dateEdit.setDate(self.dt)
        self.dateEdit_2.setDate(self.dt)
        self.pushButton.clicked.connect(self.sloturunmaliyet)
        self.pushButton_3.clicked.connect(self.sloturunmaliyetxls)
        self.pushButton_2.clicked.connect(self.sloturunmaliyetpdf)
        self.pushButton_4.clicked.connect(self.slotekstre)
        self.pushButton_5.clicked.connect(self.cariekstre)
        self.tableWidget.setColumnWidth(0, 50)
        self.tableWidget.setColumnWidth(1, 50)
        self.tableWidget.setColumnWidth(2, 450)
        self.tableWidget.setColumnWidth(3, 25)
        self.tableWidget.setColumnWidth(4, 25)
        getcontext().prec = 12

    @pyqtSlot()
    def sloturunmaliyet(self):

        myddb1 = Myddb()
        self.d = Dummy()
        self.kontrol=1

        self.d.text(chr(27))
        self.d.text(chr(116))
        self.d.text(chr(61))

        self.d.set(font='a', align='left', height=1, width=1)

        



        print "caribakiye listesi"
        self.tableWidget.clearContents()
        self.tableWidget.setColumnWidth(0, 50)
        self.tableWidget.setColumnWidth(1, 50)
        self.tableWidget.setColumnWidth(2, 400)
        self.tableWidget.setColumnWidth(3, 50)
        self.tableWidget.setColumnWidth(4, 50)

        deger1 = self.dateEdit.date().toPyDate()
        deger2 = self.dateEdit_2.date().toPyDate()
        tar1 = deger1.strftime('%d_%m_%Y')
        tar2 = deger2.strftime('%d_%m_%Y')
        self.d.text("  "+tar1+ "  " +tar2 +" Urun Rapor"+" \n")

        self.wb = xlwt.Workbook(encoding="utf-8")
        self.dest_filename = "EKSTRE" + tar1 + tar2 + ".xls"
        date_format = xlwt.XFStyle()
        date_format.num_format_str = u'#,##0.00₺'
        date_xf = xlwt.easyxf(num_format_str='DD-MM-YYYY')
        self.ws1 = self.wb.add_sheet("ekstre")
        self.style1 = xlwt.easyxf('pattern: pattern solid, fore_colour red;')

        c = canvas.Canvas("EKSTRE" + tar1 + tar2 + ".pdf")

        pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
        c.setFont("Verdana", 16)

        item = "            KOD       STOK ADI                                         BİRİM               GİRİŞ                ÇIKIŞ                 BAKİYE                      "
        c.drawString(10, 800, item)
        tar1 = deger1.strftime('%Y-%m-%d')
        tar2 = deger2.strftime('%Y-%m-%d')

        myddb1.cur.execute("drop table if exists test.table3 ")

        myddb1.cur.execute(""" CREATE TEMPORARY TABLE  test.table3 AS (SELECT ciro.departman,pluno,hamad,sum(adet),sum(tutar) FROM bishop.ciro  inner join test.hammadde on  pluno=hamkod and
 date(tarih) between %s and %s and hesap IS NULL group by ciro.departman,pluno order by ciro.departman asc)""",(tar1,tar2))

        sql = """select * from table3 ; """

        bul2 = myddb1.cur.execute(sql)
        print bul2, tar1, tar2
        bul = myddb1.cur.fetchall()
        i = bul2
        j = 5
        self.tableWidget.setRowCount(i + 2)
        aa = 0
        bb = 0
        dep=1
        toplam = 0.0
        toplam1 = 0.0
        toplam2 = 0.0000
        bolum = 0
        bolum1 = 0

        for row1 in bul:

            item = str(row1[0])
            if dep!=row1[0]:
                aa=aa+1
                self.d.text("\n")
                self.d.text("Toplam :      " + (str(bolum)).rjust(20) + (str(bolum1)).rjust(10) + "\n")
                self.d.text("\n")
                bolum = 0
                bolum1 = 0

            dep=row1[0]
            self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
            c.drawString(5, 800 - (15 * (bb + 1)), item)
            self.ws1.write(aa,0,item)

            item = str(row1[1])
            c.drawString(50, 800 - (15 * (bb + 1)), item)
            self.ws1.write(aa, 1, item)
            self.d.text(item)
            self.d.text(" ")
            self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
            item = row1[2]
            c.drawString(400, 800 - (15 * (bb + 1)), item)
            self.ws1.write(aa, 2, item)
            self.d.text(item.ljust(30))
            self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            item = str(row1[3])

            toplam = toplam + float(row1[3])
            bolum=bolum+ float(row1[3])
            self.tableWidget.setItem(aa, 3, QtGui.QTableWidgetItem(item))

            #c.drawRightString( 440, 800 - (15 * (bb + 1)), "{:10.2f}".format(row1[3]))
            self.ws1.write(aa, 3, float(row1[3]))
            self.d.text(item)
            self.d.text("  ")


            item = str(row1[4])

            toplam1 = toplam1 + float(row1[4])
            bolum1=bolum1+ float(row1[4])
            self.tableWidget.setItem(aa, 4, QtGui.QTableWidgetItem(item))

            c.drawRightString(510, 800 - (15 * (bb + 1)), "{:10.2f}".format(row1[4]))
            self.ws1.write(aa, 4, float(row1[4]))
            self.d.text(item.rjust(8)+"\n")


            aa = aa + 1
            bb = bb + 1

            if (15 * (bb + 1)) >= 760:
                c.setFont("Verdana", 11)
                c.drawRightString(330, 800 - (15 * (bb + 1)), str(toplam))
                c.drawRightString(405, 800 - (15 * (bb + 1)), str(toplam1))
                c.drawRightString(480, 800 - (15 * (bb + 1)), str(toplam2))
                c.showPage()
                c.setFont("Verdana", 16)
                bb = 0

        c.setFont("Verdana", 11)
        c.drawRightString(330, 800 - (15 * (bb + 1)), str(toplam))
        c.drawRightString(405, 800 - (15 * (bb + 1)), str(toplam1))
        c.drawRightString(480, 800 - (15 * (bb + 1)), str(toplam2))
        self.ws1.write(aa + 1, 3, toplam)
        self.ws1.write(aa + 1, 4, toplam1)
        self.ws1.write(aa + 1, 5, toplam2)

        c.setFont("Courier", 60)
        # This next setting with make the text of our
        # watermark gray, nice touch for a watermark.
        c.setFillGray(0.3, 0.3)
        # Set up our watermark document. Our watermark
        # will be rotated 45 degrees from the direction
        # of our underlying document.
        c.saveState()
        c.translate(500, 100)
        c.rotate(45)
        c.drawCentredString(0, 0, "BISHOP NEN ©")
        c.drawCentredString(0, 300, "BISHOP NEN ©")
        c.drawCentredString(0, 600, "BISHOP NEN ©")
        c.restoreState()

        c.save()
        self.wb.save(self.dest_filename)
        self.d.text("\n")
        self.d.text("Toplam :      " + (str(bolum)).rjust(20) + (str(bolum1)).rjust(10) + "\n")

        self.d.text("\n")
        self.d.text("Genel Toplam :      "+(str(toplam)).rjust(20)+(str(toplam1)).rjust(10)+"\n")

        self.d.cut()

    @pyqtSlot()
    def cariekstre(self):
        p = Network("192.168.2.222")
        p._raw(self.d.output)
        print "elma"
        p=None
        print p

 #       z._raw(self.d.output)

    @pyqtSlot(int,int)
    def slotekstre(self, item):
        if self.kontrol==0:
            print " kasa"
        myddb1 = Myddb()
        self.d = Dummy()
        self.d.text(chr(27))
        self.d.text(chr(116))
        self.d.text(chr(61))

        self.kontrol = 1
        self.d.set(font='a', align='left', height=2, width=1)

        print "ekstrerapor"
        self.tableWidget.clearContents()
        self.tableWidget.setColumnWidth(0, 150)
        self.tableWidget.setColumnWidth(1, 100)
        self.tableWidget.setColumnWidth(2, 75)
        self.tableWidget.setColumnWidth(3, 75)
        self.tableWidget.setColumnWidth(4, 75)
        self.tableWidget.setColumnWidth(5, 75)

        deger1 = self.dateEdit.date().toPyDate()
        deger2 = self.dateEdit_2.date().toPyDate()
        tar1 = deger1.strftime('%d_%m_%Y')
        tar2 = deger2.strftime('%d_%m_%Y')
        self.d.text("  " + tar1 + "  " + tar2 + " Kasa Raporu " + " \n\n")

        self.wb = xlwt.Workbook(encoding="utf-8")
        self.dest_filename = "EKSTRE" + tar1 + tar2 + ".xls"
        date_format = xlwt.XFStyle()
        date_format.num_format_str = u'#,##0.00₺'
        date_xf = xlwt.easyxf(num_format_str='DD/MM/YYYY')
        self.ws1 = self.wb.add_sheet("ekstre")
        self.style1 = xlwt.easyxf('pattern: pattern solid, fore_colour red;')

        c = canvas.Canvas("EKSTRE" + tar1 + tar2 + ".pdf")
        pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
        c.setFont("Verdana", 8)

        item = "         FİŞ NO       TARİH                AÇIKLAMA                             BORÇ                  ALACAK                    BAKİYE                      "
        c.drawString(10, 810, item)
        tar1 = deger1.strftime('%Y-%m-%d')
        tar2 = deger2.strftime('%Y-%m-%d')

        sql = """select kasano,sum(tutar) from kasa where date(tarih) between %s and %s  group by kasano; """

        bul2 = myddb1.cur.execute(sql, (tar1, tar2))
        print bul2, tar1, tar2

        bul = myddb1.cur.fetchall()
        i = bul2
        j = 5
        self.tableWidget.setRowCount(i+5)
        aa = 0
        bb = 0
        dep=0
        toplam = 0.0
        toplam1 = 0.0
        toplam2 = 0.0000
        for row1 in bul:


            if row1[0]==100:
                item = str(row1[0])+" Nakit "
                self.ws1.write(aa, 0, item)
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)
                self.d.text(item.ljust(30) + " ")
                item = str(row1[1])
                self.d.text(item.rjust(10) + " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam = Decimal(toplam) + (row1[1])

                toplam1 = Decimal(toplam1) + (row1[1])
                item=QtGui.QTableWidgetItem(item)
                item.setTextAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight)
                self.tableWidget.setItem(aa, 1, item)

                item= ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))


            if row1[0]==101:
                item = str(row1[0]) + " Indirim "
                self.ws1.write(aa, 0, item)
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)
                self.d.text(item.ljust(30) + " ")

                item = str(row1[1])
                self.d.text(item.rjust(10) + " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)

                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                item = ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0]==102:
                item = str(row1[0])+" Servis "
                self.ws1.write(aa, 0, item)
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)
                self.d.text(item.ljust(30) + " ")

                item = str(row1[1])
                self.d.text(item.rjust(10)+ " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam = Decimal(toplam) - (row1[1])
                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                item= ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0]==105:
                item = str(row1[0])+" Denizbank "
                self.ws1.write(aa, 0, item)
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)
                self.d.text(item.ljust(30) + " ")

                item = str(row1[1])
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam2=Decimal(toplam2)+(row1[1])
                toplam1 = Decimal(toplam1) + (row1[1])
                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                self.d.text(item.rjust(10)+ " \n")
                self.tableWidget.item(aa, 1).setTextAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight)

                item= ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0]==106:
                item = str(row1[0])+" Yapi Kredi "
                self.ws1.write(aa, 0, item)
                self.d.text(item.ljust(30) + " ")
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)

                item = str(row1[1])
                self.d.text(item.rjust(10)+ " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam2=Decimal(toplam2)+(row1[1])
                toplam1 = Decimal(toplam1) + (row1[1])
                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                item= ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0]==111:
                item = str(row1[0])+" Harcamalar "
                self.ws1.write(aa, 0, item)
                self.d.text(item.ljust(30) + " ")
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)

                item = str(row1[1])
                self.d.text(item.rjust(10)+ " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam = Decimal(toplam) + (row1[1])
                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                item= ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))





            aa = aa + 1
            bb = bb + 1


            if (15 * (bb + 1)) >= 760:
                c.setFont("Verdana", 10)
                c.drawString(210, 800 - (15 * (bb + 1)), str(toplam))
                c.drawString(270, 800 - (15 * (bb + 1)), str(toplam1))
                c.drawString(350, 800 - (15 * (bb + 1)), str(toplam2))
                c.showPage()
                c.setFont("Verdana", 8)
                bb = 0
        c.setFont("Verdana", 10)
        self.ws1.write(aa+1, 3, toplam)
        self.ws1.write(aa+1, 4, toplam1)
        self.ws1.write(aa+1, 5, toplam2)
        c.drawString(270, 800 - (15 * (bb + 1)), str(toplam))
        c.drawString(350, 800 - (15 * (bb + 1)), str(toplam1))
        c.drawString(430, 800 - (15 * (bb + 1)), str(toplam2))

        #todo genel toplam yazılacak
        c.setFont("Courier", 60)
        # This next setting with make the text of our
        # watermark gray, nice touch for a watermark.
        c.setFillGray(0.3, 0.3)
        # Set up our watermark document. Our watermark
        # will be rotated 45 degrees from the direction
        # of our underlying document.
        c.saveState()
        c.translate(500, 100)
        c.rotate(45)
        c.drawCentredString(0, 0, "BISHOP NEN ©")
        c.drawCentredString(0, 300, "BISHOP NEN ©")
        c.drawCentredString(0, 600, "BISHOP NEN ©")
        c.restoreState()

        self.kontrol=0
        self.d.text("\n\n")

        item = "Genel Toplam "
        self.d.text(item.ljust(30) + " ")
        self.tableWidget.setItem(aa + 1, 0, QtGui.QTableWidgetItem(item))
        item = str(toplam1)
        self.d.text(item.rjust(10)+ " \n")
        self.tableWidget.setItem(aa + 1, 1, QtGui.QTableWidgetItem(item))

        item = "Kasa Kalan Nakit "
        self.d.text(item.ljust(30) + " ")
        self.tableWidget.setItem(aa + 2, 0, QtGui.QTableWidgetItem(item))
        item = str(toplam)
        self.d.text(item.rjust(10) + " \n")
        self.tableWidget.setItem(aa + 2, 1, QtGui.QTableWidgetItem(item))

        item = "Kredi Kart Toplam "
        self.d.text(item.ljust(30) + " ")
        self.tableWidget.setItem(aa + 3, 0, QtGui.QTableWidgetItem(item))
        item = str(toplam2)
        self.d.text(item.rjust(10)+ " \n")
        self.tableWidget.setItem(aa + 3, 1, QtGui.QTableWidgetItem(item))

        aa=aa+5
        self.d.text(u"\n\n\n Ödemeler \n")

        sql = """select
        aciklama, tutar
        from kasa where
        tutar < 0 and posid = 2000 and tarih
        between %s and %s """

        bul2 = myddb1.cur.execute(sql, (tar1, tar2))
        print bul2, tar1, tar2

        bul = myddb1.cur.fetchall()
        print bul
        i = bul2
        j = 5
        self.tableWidget.setRowCount(i + aa+1)

        bb = 0
        dep = 0
        toplam = 0.0
        toplam1 = 0.0
        toplam2 = 0.0000
        for row1 in bul:


            item = (row1[0])
      #      self.ws1.write(aa, 0, item)
            self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
            c.drawString(150, 800 - (15 * (bb + 1)), item)
            self.d.text(item.ljust(30) + " ")
            item = str(row1[1])
            self.d.text(item.rjust(10) + " \n")
       #     self.ws1.write(aa, 3, float(row1[1]))
            c.drawRightString(310, 800 - (15 * (bb + 1)), item)
            toplam = Decimal(toplam) + (row1[1])

            toplam1 = Decimal(toplam1) + (row1[1])
            item = QtGui.QTableWidgetItem(item)
            item.setTextAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight)
            self.tableWidget.setItem(aa, 1, item)

            aa=aa+1


        self.d.barcode(tar1, "CODE39", 80, 3)
        self.d.set(font='a', align='left', height=1, width=1)
        self.d.text(u"\n\n\n  İmza : \n")
        self.d.cut()
        c.save()
        self.wb.save(self.dest_filename)

    @pyqtSlot()
    def sloturunmaliyetpdf(self):
        deger1 = self.dateEdit.date().toPyDate()
        deger2 = self.dateEdit_2.date().toPyDate()
        tar1 = deger1.strftime('%d%m%Y')
        tar2 = deger2.strftime('%d%m%Y')

        if sys.platform == "win32":
            os.startfile("EKSTRE" + tar1 + tar2 + ".pdf")
        else:
            opener = "open" if sys.platform == "darwin" else "xdg-open"
            subprocess.call([opener, "EKSTRE" + tar1 + tar2 + ".pdf"])

    def sloturunmaliyetxls(self):
        deger1 = self.dateEdit.date().toPyDate()
        deger2 = self.dateEdit_2.date().toPyDate()
        tar1 = deger1.strftime('%d%m%Y')
        tar2 = deger2.strftime('%d%m%Y')

        if sys.platform == "win32":
            os.startfile("EKSTRE" + tar1 + tar2 + ".xls")
        else:
            opener = "open" if sys.platform == "darwin" else "xdg-open"
            subprocess.call([opener, "EKSTRE" + tar1 + tar2 + ".xls"])
Exemplo n.º 8
0
        })

        for ticket in reservering['tickets']:
            if ticket["title"] == "High Tea":
                reserveringPrinten.append({"opmerking": "^^ High Tea"})

        aantalReserveringen += 1

if reserveringPrinten:

    logging.debug('%s reserveringen worden geprint', aantalReserveringen)

    kitchen = Network(os.getenv("IP_PRINTER"))  #Printer IP Address
    output = Dummy()

    output.text("Reservering Update (" + tijdVandaagPrint + " " +
                datumVandaagPrint + ")\n\n")

    # Maak tekst zwart
    output._raw(b'\x1B\x35' + b'\x01')

    for reserveringPrint in reserveringPrinten:

        if reserveringPrint.get("bericht"):
            output.text(reserveringPrint.get("bericht") + "\n")

        if reserveringPrint.get("opmerking"):
            # Maak tekst rood
            output._raw(b'\x1B\x34' + b'\x01')
            output.text(reserveringPrint.get("opmerking") + "\n")
            # Maak tekst zwart
            output._raw(b'\x1B\x35' + b'\x01')
Exemplo n.º 9
0
class Receipt:
    def __init__(self):
        from escpos.printer import Usb, Dummy

        self.eps = Usb(0x4b8, 0x0e03)
        self.dps = Dummy()

    def print_header(self, opts):
        """Responsible for printing the header part of the receipt,
           :param:opts: include all options that could go into the
           header like logo, company name and all that
        """
        if COMPANY_LOGO in opts.keys():
            self.imgesprint(opts[COMPANY_LOGO])
            self.esprint(LINE_BREAK)

        if COMPANY_NAME in opts.keys():
            self.esprint(opts[COMPANY_NAME])
            self.esprint(LINE_BREAK)

        if COMPANY_CONTACT in opts.keys():
            self.esprint(TEL)
            self.esprint(opts[COMPANY_CONTACT])
            self.esprint(LINE_BREAK)

        if COMPANY_LOCATION in opts.keys():
            self.esprint(LOC)
            self.esprint(opts[COMPANY_LOCATION])
            self.esprint(LINE_BREAK)

        self.n_char(SN_RULER, PAPER_MAX_WIDTH, w=1, h=1)
        self.esprint(LINE_BREAK)

        if RECEIPT_NAME in opts.keys():
            RNO = opts[RECEIPT_NUMBER] if RECEIPT_NUMBER in opts.keys() else ''
            RECEIPT = opts[RECEIPT_NAME] + SPACE_CHAR + HASH_NO + RNO
            self.cesprint(RECEIPT)
            char = len(RECEIPT)
            self.cesprint(self.n_char_generate(DO_RULER, char), w=1, h=2)
            self.esprint(LINE_BREAK)

        if CUSTOMER_NAME in opts.keys():
            self.lesprint(CUSTOMER, LEFT_PROPERTY_WIDTH)
            self.esprint(COLON_CHAR)
            self.n_char(SPACE_CHAR, LR_ALIGN)
            self.esprint(opts[CUSTOMER_NAME])
            self.esprint(LINE_BREAK)

        if CASHIER_NAME in opts.keys():
            self.lesprint(CASHIER, LEFT_PROPERTY_WIDTH)
            self.esprint(COLON_CHAR)
            self.n_char(SPACE_CHAR, LR_ALIGN)
            self.esprint(opts[CASHIER_NAME])
            self.esprint(LINE_BREAK)

        if RECEIPT_DATE in opts.keys():
            self.lesprint(DATE, LEFT_PROPERTY_WIDTH)
            self.esprint(COLON_CHAR)
            self.n_char(SPACE_CHAR, LR_ALIGN)
            self.esprint(opts[RECEIPT_DATE])
            self.esprint(LINE_BREAK)

        if CURRENCY_NAME in opts.keys():
            self.lesprint(CURRENCY_NAME_TITLE, LEFT_PROPERTY_WIDTH)
            self.esprint(COLON_CHAR)
            self.n_char(SPACE_CHAR, LR_ALIGN)
            self.esprint(opts[CURRENCY_NAME])
            self.esprint(LINE_BREAK)

    def print_items(self, items):
        """Responsible for printing the receipt part of
           the receipt.
        """
        self.n_char(SN_RULER, PAPER_MAX_WIDTH, w=1, h=1)
        self.esprint(LINE_BREAK)
        self.esprint(ITEM_TITLE)
        self.n_char(SPACE_CHAR, ITEM_TITLE_SPACE_AFTER)
        self.esprint(QTY_TITLE)
        self.n_char(SPACE_CHAR, QTY_TITLE_SPACE_AFTER)
        self.esprint(SP_TITLE)
        self.n_char(SPACE_CHAR, SP_TITLE_SPACE_AFTER)
        self.esprint(TOTAL_TITLE)
        self.n_char(SPACE_CHAR, TOTAL_TITLE_SPACE_AFTER)
        self.esprint(LINE_BREAK)
        self.n_char(DO_RULER, PAPER_MAX_WIDTH, w=1, h=2)
        self.esprint(LINE_BREAK)
        sum_total = 0
        for item in items:
            product = item[ITEM] if len(item[ITEM]) < ITEM_MAX_WIDTH else item[
                ITEM][:ITEM_MAX_WIDTH - ELIPSES_WIDTH] + ELIPSES
            qty = item[QTY] if isinstance(item[QTY], int) else round(
                str_2_num(item[QTY]), 2)
            price = round(str_2_num(item[SP]), 2)
            total = round(qty * price, 2)
            sum_total += total
            self.print_space(product, ITEM_MAX_WIDTH)
            self.print_space(str(qty), QTY_MAX_WIDTH)
            self.print_space(str(price), SP_MAX_WIDTH)
            self.print_space(str(total), TOTAL_MAX_WIDTH)
            self.esprint(LINE_BREAK)
        self.n_char(SN_RULER, PAPER_MAX_WIDTH, w=1, h=1)
        self.esprint(LINE_BREAK)
        self.esprint(TOTAL_TXT)
        leave = TOTAL_TXT_WIDTH
        self.n_char(SPACE_CHAR,
                    PAPER_MAX_WIDTH - TOTAL_MAX_WIDTH - leave,
                    w=1,
                    h=1)
        self.esprint(str(sum_total))
        self.esprint(LINE_BREAK)
        self.n_char(DO_RULER, PAPER_MAX_WIDTH, w=1, h=2)
        self.esprint(LINE_BREAK)

    def print_message(self, msg):
        self.cesprint(msg, char=STAR_CHAR)
        self.esprint(LINE_BREAK)

    def print_vat(self, vmsg):
        self.esprint(LINE_BREAK)
        self.cesprint(vmsg)
        self.esprint(LINE_BREAK)

    def print_me(self, me):
        self.esprint(me)

    def print_space(self, text, width, w=1, h=1):
        """Print text and then print space character
        for remaining space = width - texlen. For now texlen is not expected
        to be greater than width, if so just truncate to width.
        """
        texlen = len(text)
        if texlen > width:
            text = text[:width]
        self.lesprint(text, width)

    def imgesprint(self, path, align='center'):
        """Responsible for image printing"""
        self.dps.set(align=align)
        self.dps.image(path)

    def esprint(self, text, w=1, h=1):
        """A prudent wrapper around printing text with [self.eps.text()]"""
        self.dps.set(height=h, width=w)
        self.dps.text(text)

    def escut(self):
        self.eps.cut()

    def estop(self):
        self.eps.close()

    def cesprint(self, text, width=PAPER_MAX_WIDTH, char=SPACE_CHAR, w=1, h=1):
        """center align text and fill space left with :param:char:"""
        texlen = len(text)
        if texlen > width:
            diff = width % texlen
        else:
            diff = width - texlen
        if diff == 0:
            ldiff = rdiff = 0
        elif diff % 2 == 0:
            ldiff = rdiff = diff // 2
        else:
            ldiff = diff // 2
            rdiff = ldiff + 1
        self.n_char(char, ldiff)
        self.esprint(text, w, h)
        self.n_char(char, rdiff)

    def resprint(self, text, width=PAPER_MAX_WIDTH, char=SPACE_CHAR, w=1, h=1):
        """right align text and fill space left with :param:char:"""
        texlen = len(text)
        diff = width - texlen
        self.n_char(char, diff)
        self.esprint(text, w, h)

    def lesprint(self, text, width=PAPER_MAX_WIDTH, char=SPACE_CHAR, w=1, h=1):
        """light align text and fill space left with :param:char:"""
        texlen = len(text)
        diff = width - texlen
        self.esprint(text, w, h)
        self.n_char(char, diff, w, h)

    def n_char(self, char, n, w=1, h=1):
        """Print char n times"""
        for i in range(n):
            self.esprint(char, w, h)

    def n_char_generate(self, char, n):
        """ Return string of char n time"""
        return char * n

    def get_longest_item(self, items):
        """Return the length of the longest
           Item name in the list of items
        """
        # Assume longest is initially zero
        longest = 0
        for item in items:
            # get length of item name
            length = len(item[ITEM])
            if length > longest:
                longest = length
        return longest

    def esecute(self):
        self.eps._raw(self.dps.output)
Exemplo n.º 10
0
class Rapor(QtGui.QDialog, Ui_Dialog7):
    def __init__(self):
        QtGui.QDialog.__init__(self)
        self.setupUi(self)
        #self.myddb = Myddb()
        self.kontrol = 0
        self.dt = datetime.now() - timedelta(hours=5)
        self.dt = QtCore.QDate.fromString(str(self.dt.date()), 'yyyy-MM-dd')

        self.tableWidget.setRowCount(0)
        self.dateEdit.setDate(self.dt)
        self.dateEdit_2.setDate(self.dt)
        self.pushButton.clicked.connect(self.sloturunmaliyet)
        self.pushButton_3.clicked.connect(self.sloturunmaliyetxls)
        self.pushButton_2.clicked.connect(self.sloturunmaliyetpdf)
        self.pushButton_4.clicked.connect(self.slotekstre)
        self.pushButton_5.clicked.connect(self.cariekstre)
        self.tableWidget.setColumnWidth(0, 50)
        self.tableWidget.setColumnWidth(1, 50)
        self.tableWidget.setColumnWidth(2, 450)
        self.tableWidget.setColumnWidth(3, 25)
        self.tableWidget.setColumnWidth(4, 25)
        getcontext().prec = 12

    @pyqtSlot()
    def sloturunmaliyet(self):

        myddb1 = Myddb()
        self.d = Dummy()
        self.kontrol = 1

        self.d.text(chr(27))
        self.d.text(chr(116))
        self.d.text(chr(61))

        self.d.set(font='a', align='left', height=1, width=1)

        print "caribakiye listesi"
        self.tableWidget.clearContents()
        self.tableWidget.setColumnWidth(0, 50)
        self.tableWidget.setColumnWidth(1, 50)
        self.tableWidget.setColumnWidth(2, 400)
        self.tableWidget.setColumnWidth(3, 50)
        self.tableWidget.setColumnWidth(4, 50)

        deger1 = self.dateEdit.date().toPyDate()
        deger2 = self.dateEdit_2.date().toPyDate()
        tar1 = deger1.strftime('%d_%m_%Y')
        tar2 = deger2.strftime('%d_%m_%Y')
        self.d.text("  " + tar1 + "  " + tar2 + " Urun Rapor" + " \n")

        self.wb = xlwt.Workbook(encoding="utf-8")
        self.dest_filename = "EKSTRE" + tar1 + tar2 + ".xls"
        date_format = xlwt.XFStyle()
        date_format.num_format_str = u'#,##0.00₺'
        date_xf = xlwt.easyxf(num_format_str='DD-MM-YYYY')
        self.ws1 = self.wb.add_sheet("ekstre")
        self.style1 = xlwt.easyxf('pattern: pattern solid, fore_colour red;')

        c = canvas.Canvas("EKSTRE" + tar1 + tar2 + ".pdf")

        pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
        c.setFont("Verdana", 16)

        item = "            KOD       STOK ADI                                         BİRİM               GİRİŞ                ÇIKIŞ                 BAKİYE                      "
        c.drawString(10, 800, item)
        tar1 = deger1.strftime('%Y-%m-%d')
        tar2 = deger2.strftime('%Y-%m-%d')

        myddb1.cur.execute("drop table if exists test.table3 ")

        myddb1.cur.execute(
            """ CREATE TEMPORARY TABLE  test.table3 AS (SELECT ciro.departman,pluno,hamad,sum(adet),sum(tutar) FROM bishop.ciro  inner join test.hammadde on  pluno=hamkod and
 date(tarih) between %s and %s and hesap IS NULL group by ciro.departman,pluno order by ciro.departman asc)""",
            (tar1, tar2))

        sql = """select * from table3 ; """

        bul2 = myddb1.cur.execute(sql)
        print bul2, tar1, tar2
        bul = myddb1.cur.fetchall()
        i = bul2
        j = 5
        self.tableWidget.setRowCount(i + 2)
        aa = 0
        bb = 0
        dep = 1
        toplam = 0.0
        toplam1 = 0.0
        toplam2 = 0.0000
        bolum = 0
        bolum1 = 0

        for row1 in bul:

            item = str(row1[0])
            if dep != row1[0]:
                aa = aa + 1
                self.d.text("\n")
                self.d.text("Toplam :      " + (str(bolum)).rjust(20) +
                            (str(bolum1)).rjust(10) + "\n")
                self.d.text("\n")
                bolum = 0
                bolum1 = 0

            dep = row1[0]
            self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
            c.drawString(5, 800 - (15 * (bb + 1)), item)
            self.ws1.write(aa, 0, item)

            item = str(row1[1])
            c.drawString(50, 800 - (15 * (bb + 1)), item)
            self.ws1.write(aa, 1, item)
            self.d.text(item)
            self.d.text(" ")
            self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
            item = row1[2]
            c.drawString(400, 800 - (15 * (bb + 1)), item)
            self.ws1.write(aa, 2, item)
            self.d.text(item.ljust(30))
            self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            item = str(row1[3])

            toplam = toplam + float(row1[3])
            bolum = bolum + float(row1[3])
            self.tableWidget.setItem(aa, 3, QtGui.QTableWidgetItem(item))

            #c.drawRightString( 440, 800 - (15 * (bb + 1)), "{:10.2f}".format(row1[3]))
            self.ws1.write(aa, 3, float(row1[3]))
            self.d.text(item)
            self.d.text("  ")

            item = str(row1[4])

            toplam1 = toplam1 + float(row1[4])
            bolum1 = bolum1 + float(row1[4])
            self.tableWidget.setItem(aa, 4, QtGui.QTableWidgetItem(item))

            c.drawRightString(510, 800 - (15 * (bb + 1)),
                              "{:10.2f}".format(row1[4]))
            self.ws1.write(aa, 4, float(row1[4]))
            self.d.text(item.rjust(8) + "\n")

            aa = aa + 1
            bb = bb + 1

            if (15 * (bb + 1)) >= 760:
                c.setFont("Verdana", 11)
                c.drawRightString(330, 800 - (15 * (bb + 1)), str(toplam))
                c.drawRightString(405, 800 - (15 * (bb + 1)), str(toplam1))
                c.drawRightString(480, 800 - (15 * (bb + 1)), str(toplam2))
                c.showPage()
                c.setFont("Verdana", 16)
                bb = 0

        c.setFont("Verdana", 11)
        c.drawRightString(330, 800 - (15 * (bb + 1)), str(toplam))
        c.drawRightString(405, 800 - (15 * (bb + 1)), str(toplam1))
        c.drawRightString(480, 800 - (15 * (bb + 1)), str(toplam2))
        self.ws1.write(aa + 1, 3, toplam)
        self.ws1.write(aa + 1, 4, toplam1)
        self.ws1.write(aa + 1, 5, toplam2)

        c.setFont("Courier", 60)
        # This next setting with make the text of our
        # watermark gray, nice touch for a watermark.
        c.setFillGray(0.3, 0.3)
        # Set up our watermark document. Our watermark
        # will be rotated 45 degrees from the direction
        # of our underlying document.
        c.saveState()
        c.translate(500, 100)
        c.rotate(45)
        c.drawCentredString(0, 0, "BISHOP NEN ©")
        c.drawCentredString(0, 300, "BISHOP NEN ©")
        c.drawCentredString(0, 600, "BISHOP NEN ©")
        c.restoreState()

        c.save()
        self.wb.save(self.dest_filename)
        self.d.text("\n")
        self.d.text("Toplam :      " + (str(bolum)).rjust(20) +
                    (str(bolum1)).rjust(10) + "\n")

        self.d.text("\n")
        self.d.text("Genel Toplam :      " + (str(toplam)).rjust(20) +
                    (str(toplam1)).rjust(10) + "\n")

        self.d.cut()

    @pyqtSlot()
    def cariekstre(self):
        p = Network("192.168.2.222")
        p._raw(self.d.output)
        print "elma"
        p = None
        print p

#       z._raw(self.d.output)

    @pyqtSlot(int, int)
    def slotekstre(self, item):
        if self.kontrol == 0:
            print " kasa"
        myddb1 = Myddb()
        self.d = Dummy()
        self.d.text(chr(27))
        self.d.text(chr(116))
        self.d.text(chr(61))

        self.kontrol = 1
        self.d.set(font='a', align='left', height=2, width=1)

        print "ekstrerapor"
        self.tableWidget.clearContents()
        self.tableWidget.setColumnWidth(0, 150)
        self.tableWidget.setColumnWidth(1, 100)
        self.tableWidget.setColumnWidth(2, 75)
        self.tableWidget.setColumnWidth(3, 75)
        self.tableWidget.setColumnWidth(4, 75)
        self.tableWidget.setColumnWidth(5, 75)

        deger1 = self.dateEdit.date().toPyDate()
        deger2 = self.dateEdit_2.date().toPyDate()
        tar1 = deger1.strftime('%d_%m_%Y')
        tar2 = deger2.strftime('%d_%m_%Y')
        self.d.text("  " + tar1 + "  " + tar2 + " Kasa Raporu " + " \n\n")

        self.wb = xlwt.Workbook(encoding="utf-8")
        self.dest_filename = "EKSTRE" + tar1 + tar2 + ".xls"
        date_format = xlwt.XFStyle()
        date_format.num_format_str = u'#,##0.00₺'
        date_xf = xlwt.easyxf(num_format_str='DD/MM/YYYY')
        self.ws1 = self.wb.add_sheet("ekstre")
        self.style1 = xlwt.easyxf('pattern: pattern solid, fore_colour red;')

        c = canvas.Canvas("EKSTRE" + tar1 + tar2 + ".pdf")
        pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
        c.setFont("Verdana", 8)

        item = "         FİŞ NO       TARİH                AÇIKLAMA                             BORÇ                  ALACAK                    BAKİYE                      "
        c.drawString(10, 810, item)
        tar1 = deger1.strftime('%Y-%m-%d')
        tar2 = deger2.strftime('%Y-%m-%d')

        sql = """select kasano,sum(tutar) from kasa where date(tarih) between %s and %s  group by kasano; """

        bul2 = myddb1.cur.execute(sql, (tar1, tar2))
        print bul2, tar1, tar2

        bul = myddb1.cur.fetchall()
        i = bul2
        j = 5
        self.tableWidget.setRowCount(i + 5)
        aa = 0
        bb = 0
        dep = 0
        toplam = 0.0
        toplam1 = 0.0
        toplam2 = 0.0000
        for row1 in bul:

            if row1[0] == 100:
                item = str(row1[0]) + " Nakit "
                self.ws1.write(aa, 0, item)
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)
                self.d.text(item.ljust(30) + " ")
                item = str(row1[1])
                self.d.text(item.rjust(10) + " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam = Decimal(toplam) + (row1[1])

                toplam1 = Decimal(toplam1) + (row1[1])
                item = QtGui.QTableWidgetItem(item)
                item.setTextAlignment(QtCore.Qt.AlignVCenter
                                      | QtCore.Qt.AlignRight)
                self.tableWidget.setItem(aa, 1, item)

                item = ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0] == 101:
                item = str(row1[0]) + " Indirim "
                self.ws1.write(aa, 0, item)
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)
                self.d.text(item.ljust(30) + " ")

                item = str(row1[1])
                self.d.text(item.rjust(10) + " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)

                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                item = ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0] == 102:
                item = str(row1[0]) + " Servis "
                self.ws1.write(aa, 0, item)
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)
                self.d.text(item.ljust(30) + " ")

                item = str(row1[1])
                self.d.text(item.rjust(10) + " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam = Decimal(toplam) - (row1[1])
                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                item = ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0] == 105:
                item = str(row1[0]) + " Denizbank "
                self.ws1.write(aa, 0, item)
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)
                self.d.text(item.ljust(30) + " ")

                item = str(row1[1])
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam2 = Decimal(toplam2) + (row1[1])
                toplam1 = Decimal(toplam1) + (row1[1])
                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                self.d.text(item.rjust(10) + " \n")
                self.tableWidget.item(
                    aa, 1).setTextAlignment(QtCore.Qt.AlignVCenter
                                            | QtCore.Qt.AlignRight)

                item = ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0] == 106:
                item = str(row1[0]) + " Yapi Kredi "
                self.ws1.write(aa, 0, item)
                self.d.text(item.ljust(30) + " ")
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)

                item = str(row1[1])
                self.d.text(item.rjust(10) + " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam2 = Decimal(toplam2) + (row1[1])
                toplam1 = Decimal(toplam1) + (row1[1])
                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                item = ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            if row1[0] == 111:
                item = str(row1[0]) + " Harcamalar "
                self.ws1.write(aa, 0, item)
                self.d.text(item.ljust(30) + " ")
                self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
                c.drawString(150, 800 - (15 * (bb + 1)), item)

                item = str(row1[1])
                self.d.text(item.rjust(10) + " \n")
                self.ws1.write(aa, 3, float(row1[1]))
                c.drawRightString(310, 800 - (15 * (bb + 1)), item)
                toplam = Decimal(toplam) + (row1[1])
                self.tableWidget.setItem(aa, 1, QtGui.QTableWidgetItem(item))
                item = ""
                c.drawRightString(390, 800 - (15 * (bb + 1)), item)
                self.tableWidget.setItem(aa, 2, QtGui.QTableWidgetItem(item))

            aa = aa + 1
            bb = bb + 1

            if (15 * (bb + 1)) >= 760:
                c.setFont("Verdana", 10)
                c.drawString(210, 800 - (15 * (bb + 1)), str(toplam))
                c.drawString(270, 800 - (15 * (bb + 1)), str(toplam1))
                c.drawString(350, 800 - (15 * (bb + 1)), str(toplam2))
                c.showPage()
                c.setFont("Verdana", 8)
                bb = 0
        c.setFont("Verdana", 10)
        self.ws1.write(aa + 1, 3, toplam)
        self.ws1.write(aa + 1, 4, toplam1)
        self.ws1.write(aa + 1, 5, toplam2)
        c.drawString(270, 800 - (15 * (bb + 1)), str(toplam))
        c.drawString(350, 800 - (15 * (bb + 1)), str(toplam1))
        c.drawString(430, 800 - (15 * (bb + 1)), str(toplam2))

        #todo genel toplam yazılacak
        c.setFont("Courier", 60)
        # This next setting with make the text of our
        # watermark gray, nice touch for a watermark.
        c.setFillGray(0.3, 0.3)
        # Set up our watermark document. Our watermark
        # will be rotated 45 degrees from the direction
        # of our underlying document.
        c.saveState()
        c.translate(500, 100)
        c.rotate(45)
        c.drawCentredString(0, 0, "BISHOP NEN ©")
        c.drawCentredString(0, 300, "BISHOP NEN ©")
        c.drawCentredString(0, 600, "BISHOP NEN ©")
        c.restoreState()

        self.kontrol = 0
        self.d.text("\n\n")

        item = "Genel Toplam "
        self.d.text(item.ljust(30) + " ")
        self.tableWidget.setItem(aa + 1, 0, QtGui.QTableWidgetItem(item))
        item = str(toplam1)
        self.d.text(item.rjust(10) + " \n")
        self.tableWidget.setItem(aa + 1, 1, QtGui.QTableWidgetItem(item))

        item = "Kasa Kalan Nakit "
        self.d.text(item.ljust(30) + " ")
        self.tableWidget.setItem(aa + 2, 0, QtGui.QTableWidgetItem(item))
        item = str(toplam)
        self.d.text(item.rjust(10) + " \n")
        self.tableWidget.setItem(aa + 2, 1, QtGui.QTableWidgetItem(item))

        item = "Kredi Kart Toplam "
        self.d.text(item.ljust(30) + " ")
        self.tableWidget.setItem(aa + 3, 0, QtGui.QTableWidgetItem(item))
        item = str(toplam2)
        self.d.text(item.rjust(10) + " \n")
        self.tableWidget.setItem(aa + 3, 1, QtGui.QTableWidgetItem(item))

        aa = aa + 5
        self.d.text(u"\n\n\n Ödemeler \n")

        sql = """select
        aciklama, tutar
        from kasa where
        tutar < 0 and posid = 2000 and tarih
        between %s and %s """

        bul2 = myddb1.cur.execute(sql, (tar1, tar2))
        print bul2, tar1, tar2

        bul = myddb1.cur.fetchall()
        print bul
        i = bul2
        j = 5
        self.tableWidget.setRowCount(i + aa + 1)

        bb = 0
        dep = 0
        toplam = 0.0
        toplam1 = 0.0
        toplam2 = 0.0000
        for row1 in bul:

            item = (row1[0])
            #      self.ws1.write(aa, 0, item)
            self.tableWidget.setItem(aa, 0, QtGui.QTableWidgetItem(item))
            c.drawString(150, 800 - (15 * (bb + 1)), item)
            self.d.text(item.ljust(30) + " ")
            item = str(row1[1])
            self.d.text(item.rjust(10) + " \n")
            #     self.ws1.write(aa, 3, float(row1[1]))
            c.drawRightString(310, 800 - (15 * (bb + 1)), item)
            toplam = Decimal(toplam) + (row1[1])

            toplam1 = Decimal(toplam1) + (row1[1])
            item = QtGui.QTableWidgetItem(item)
            item.setTextAlignment(QtCore.Qt.AlignVCenter
                                  | QtCore.Qt.AlignRight)
            self.tableWidget.setItem(aa, 1, item)

            aa = aa + 1

        self.d.barcode(tar1, "CODE39", 80, 3)
        self.d.set(font='a', align='left', height=1, width=1)
        self.d.text(u"\n\n\n  İmza : \n")
        self.d.cut()
        c.save()
        self.wb.save(self.dest_filename)

    @pyqtSlot()
    def sloturunmaliyetpdf(self):
        deger1 = self.dateEdit.date().toPyDate()
        deger2 = self.dateEdit_2.date().toPyDate()
        tar1 = deger1.strftime('%d%m%Y')
        tar2 = deger2.strftime('%d%m%Y')

        if sys.platform == "win32":
            os.startfile("EKSTRE" + tar1 + tar2 + ".pdf")
        else:
            opener = "open" if sys.platform == "darwin" else "xdg-open"
            subprocess.call([opener, "EKSTRE" + tar1 + tar2 + ".pdf"])

    def sloturunmaliyetxls(self):
        deger1 = self.dateEdit.date().toPyDate()
        deger2 = self.dateEdit_2.date().toPyDate()
        tar1 = deger1.strftime('%d%m%Y')
        tar2 = deger2.strftime('%d%m%Y')

        if sys.platform == "win32":
            os.startfile("EKSTRE" + tar1 + tar2 + ".xls")
        else:
            opener = "open" if sys.platform == "darwin" else "xdg-open"
            subprocess.call([opener, "EKSTRE" + tar1 + tar2 + ".xls"])
Exemplo n.º 11
0
class EscPosPrint(BasePrint):
    '''
    print data to a ESC/POS printer.
    '''
    font = 'A'

    def __init__(self, encode=None, **kwargs):
        BasePrint.__init__(self, **kwargs)
        from escpos.printer import Dummy
        self.dummy = Dummy()
        if encode:
            self.dummy.codepage = encode
        self.dummy.hw('init')
        self.texts = []

    def _get_char_width(self, c):
        w = BasePrint._get_char_width(self, c)
        if self.font == 'A':
            w = w * 12
        elif self.font == 'B':
            if w == 1:
                w = 9
            else:
                w = 16
        return w

    def print_text(self, text):
        self.texts.append(text)
        self.dummy.text(text)

    def _set_with_node(self, node):
        font = get_node_attr(node, 'font', '')
        align = get_node_attr(node, 'align', '')
        size = get_node_attr_int(node, 'size', 0)
        text_type = 'B' if get_node_attr(node, 'bold', '') else '' + 'U' if get_node_attr(node, 'underline', '') else ''
        setd = {}
        if font:
            setd['font'] = font
            self.font = font
        if align:
            setd['align'] = align
        if size:
            setd['width'] = size
            setd['height'] = size
        if text_type:
            setd['text_type'] = text_type
        if setd:
            self.dummy.set(**setd)

    def _handle_node(self, node):
        tag = node.tagName.lower()
        if tag in ['table', 'text', 'td', 'tr']:
            self._set_with_node(node)
        BasePrint._handle_node(self, node)

    def handle_cut(self, node):
        self.dummy.cut()

    def handle_image(self, node):
        src = get_node_attr(node, 'src', '')
        path = self.get_url_to_path(src)
        if path:
            from PIL import Image
            img = Image.open(path)
            img = align_image(img, self.width, get_node_attr(node, 'align', 'left'))
            self.dummy.image(img)

    def handle_img(self, node):
        self.handle_image(node)

    def handle_qrcode(self, node):
        native = get_node_attr(node, 'native', 'False').upper() == 'TRUE'
        code = get_node_text(node)
        size = get_node_attr_int(node, 'size', 5)
        if not native:
            img = get_qrcode_image(code, size=size)
            img = align_image(img, self.width, get_node_attr(node, 'align', 'left'))
            self.dummy.image(img)
        else:
            self.dummy.qr(code, size=size, native=native)

    def handle_barcode(self, node):
        native = get_node_attr(node, 'native', 'False').upper() == 'TRUE'
        codetype = get_node_attr(node, 'type', 'EAN13').lower()
        code = get_node_text(node)
        if not native:
            import qrcode
            img = get_barcode_image(code, codetype=codetype)
            img = align_image(img, self.width, get_node_attr(node, 'align', 'left'))
            self.dummy.image(img)
        else:
            self.dummy.barcode(code, codetype.upper(), font=get_node_attr(node, 'font', 'A').upper(), pos=get_node_attr(node, 'pos', 'BELOW').upper(), function_type=get_node_attr(node, 'function', 'B').upper())

    def handle_beep(self, node):
        self.dummy._raw(b'\x1B\x42\x01\x01')

    def raw_send(self, msg):
        self.dummy._raw(msg)

    def get_data(self):
        return self.dummy.output

    def get_text(self):
        return ''.join(self.texts)
CREEP_CARD = ArtifactCardData(1006)
CONSUMABLE_SHOP_CARDS = [
    ArtifactCardData(3003),
    ArtifactCardData(3004),
    ArtifactCardData(3005),
    ArtifactCardData(3006)
]
SECRET_SHOP_CARDS = []
for card_id, card_data in id_to_card_dict.items():
    if card_data["card_type"] == "Item" and not (3003 <= card_id <= 3006):
        SECRET_SHOP_CARDS.append(ArtifactCardData(card_id))

dummy_printer = Dummy()
dummy_printer.set(align="center")
dummy_printer.text("\n" * 5)
dummy_printer.text("<-------\nL")
dummy_printer.text("\n" * 4)
left_arrow_raw = dummy_printer.output

dummy_printer = Dummy()
dummy_printer.set(align="center")
dummy_printer.text("\n" * 5)
dummy_printer.text("------->\nR")
dummy_printer.text("\n" * 4)
right_arrow_raw = dummy_printer.output

dummy_printer = Dummy()
dummy_printer.set(align="center")
dummy_printer.text("\n" * 4)
dummy_printer.text("|\n|\nV")
Exemplo n.º 13
0
def test_function_text_dies_ist_ein_test_lf():
    """test the text printing function with simple string and compare output"""
    instance = Dummy()
    instance.text('Dies ist ein Test.\n')
    assert instance.output == b'Dies ist ein Test.\n'