fromwin32importwin32apiimportwin32printimportwin32uiimportjsonimportsysimportwin32condefprintBill(data,printer_name):line="--------------------------------------------------------------------------------------------------"dc=win32ui.CreateDC()dc.CreatePrinterDC(printer_name)dc.StartDoc("Print Text")dc.StartPage()# header
y=-10font_name="Arial"font_size=80dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))dc.TextOut(145,y,data['shop_name'])font_size=40dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+65dc.TextOut(145,y,"R E S T U R E N T")font_size=30dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+40dc.TextOut(145,y,data['shop_address'])y=y+35dc.TextOut(165,y,data['telephone'])font_size=20dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+25dc.TextOut(0,y,line)font_size=30dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+25tblData="Table: "+data['table_id']if(data['table_id']==""):tblData="Take Away"dc.TextOut(0,y,"Bill No: "+str(data['bill_id']))# dc.TextOut(0,y"Table: "+data['table_id'])
dc.TextOut(390,y,tblData)y=y+30dc.TextOut(0,y,data['date'])font_size=20dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+25dc.TextOut(0,y,line)font_size=30dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":700# 400 corresponds to normal weight
}))y=y+25total=0.0dc.TextOut(90,y,"Qty")dc.TextOut(250,y,"Price")dc.TextOut(470,y,"Total")y=y+35font_size=20dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))dc.TextOut(0,y,line)font_size=30dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+25#--------------------------------------------------------------------------
#dc.TextOut(300,y,"{:>10}".format("%.2f"%i["Price"]))
#dc.TextOut(430,y, "{:>10}".format("%.2f"% (i["Quantity"] *i["Price"] )))
foriindata["items"]:# dc.SetTextAlign(win32con.TA_LEFT | win32con.TA_BASELINE)
dc.TextOut(0,y,i["Description"])y=y+35dc.TextOut(100,y,str(i["Quantity"]))# dc.SetTextAlign(win32con.TA_RIGHT | win32con.TA_BASELINE)
dc.TextOut(200,y,"{:>10}".format("%.2f"%i["Price"]))dc.TextOut(430,y,"{:>10}".format("%.2f"%(i["Quantity"]*i["Price"])))y=y+35total=total+(i["Quantity"]*i["Price"])font_size=20dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))dc.TextOut(0,y,line)font_size=50dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+25dc.TextOut(250,y,"Total: "+str("%.2f"%total))font_size=20dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+55dc.TextOut(0,y,line)font_size=30dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+25dc.TextOut(0,y,"Note: "+str(data["note"]))font_size=20dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+35dc.TextOut(0,y,line)font_size=30dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":400# 400 corresponds to normal weight
}))y=y+25dc.TextOut(150,y,"Thank You Come Again!")font_size=20dc.SelectObject(win32ui.CreateFont({"name":font_name,"height":font_size,"weight":700# 400 corresponds to normal weight
}))y=y+35dc.TextOut(155,y,"Solution by CodGlo - 0779 438 974")y=y+50dc.TextOut(155,y,"")dc.EndPage()dc.EndDoc()dc.DeleteDC()passdefjsonTodict(filepath,printer_name):data={}withopen(filepath,'r')asfile:data=json.load(file)print(data)printBill(data,printer_name)pass# jsonTodict("11.json","")
num_args=len(sys.argv)if(num_args==3):printer_name=sys.argv[1]file_path=sys.argv[2]jsonTodict(file_path,printer_name)
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)