Created
November 14, 2022 14:19
-
-
Save ajikamaludin/3a948690fdb30642082c94b8fc652f8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"os" | |
// "github.com/hennedo/escpos" | |
"github.com/seer-robotics/escpos" | |
) | |
type Item struct { | |
Name string | |
Qty string | |
Total string | |
} | |
var items = []Item{ | |
{ | |
Name: "ayam goreng", | |
Qty: "11", | |
Total: "1.000.000", | |
}, | |
{ | |
Name: "bebek goreng panjang", | |
Qty: "1", | |
Total: "900.000", | |
}, | |
{ | |
Name: "Indomie Goreng", | |
Qty: "99", | |
Total: "10.000", | |
}, | |
} | |
func main() { | |
socket, err := os.OpenFile("/dev/rfcomm0", os.O_RDWR, 0) | |
if err != nil { | |
println(err.Error()) | |
} | |
defer socket.Close() | |
w := bufio.NewWriter(socket) | |
p := escpos.New(w) | |
// all | |
p.SetFontSize(1, 1) | |
p.SetEmphasize(1) | |
// header | |
p.SetAlign("center") | |
p.Write("ALFAMART NUSANTARA") | |
p.Linefeed() | |
p.Write("083840745543") | |
p.Linefeed() | |
p.Linefeed() | |
p.Write("CV. MAKMUR JAYA SEJAHTRA") | |
p.Linefeed() | |
p.Write("JL.MT HARYANTO NO.168 RT00/RW10") | |
p.Linefeed() | |
p.Write("NPWP: 74.927.667.1-522.0000") | |
p.Linefeed() | |
p.Write("================================") | |
p.Linefeed() | |
p.Write("Kasir: Budiman") | |
p.SetMoveX(200) | |
p.Write("Order#31398nsd") | |
p.Linefeed() | |
p.Write("================================") | |
p.Linefeed() | |
p.SetAlign("left") | |
for _, v := range items { | |
p.Write(v.Name) | |
if len(v.Qty) >= 2 { | |
p.SetMoveX(240) | |
p.Write(v.Qty) | |
} else { | |
p.SetMoveX(250) | |
p.Write(v.Qty) | |
} | |
if len(v.Total) > 7 { | |
p.SetMoveX(275) | |
p.Write(v.Total) | |
} else if len(v.Total) > 6 { | |
p.SetMoveX(300) | |
p.Write(v.Total) | |
} else { | |
p.SetMoveX(310) | |
p.Write(v.Total) | |
} | |
p.Linefeed() | |
} | |
p.Write("-------------------------------") | |
p.Linefeed() | |
p.Write("Total Item") | |
p.SetMoveX(240) | |
p.Write("10") | |
p.SetMoveX(300) | |
p.Write("999.999") | |
p.Linefeed() | |
p.Write("Tunai") | |
p.SetMoveX(310) | |
p.Write("99.999") | |
p.Linefeed() | |
p.Write("Kembali") | |
p.SetMoveX(300) | |
p.Write("100.999") | |
p.Linefeed() | |
p.Write("PPN ( 100.000)") | |
p.Linefeed() | |
p.Linefeed() | |
p.SetAlign("center") | |
p.Write("Terima kasih sudah berbelanja") | |
p.Linefeed() | |
p.Write("Kritik&Saran: 15000959") | |
p.Linefeed() | |
p.Write("SMS/WA: 083840745543") | |
p.Linefeed() | |
p.Linefeed() | |
p.FormfeedD(20) | |
w.Flush() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment