private static void printDocument_PrintPage(object sender, PrintPageEventArgs e) { var graphics = e.Graphics; var font6 = new Font("Courier New", 6); var font8 = new Font("Courier New", 8); var font10 = new Font("Courier New", 10); var font12 = new Font("Courier New", 12); var font14 = new Font("Courier New", 14); var formatLeft = new StringFormat(); formatLeft.Alignment = StringAlignment.Near; var formatCenter = new StringFormat(); formatCenter.Alignment = StringAlignment.Center; var formatRight = new StringFormat(); formatRight.Alignment = StringAlignment.Far; var blackPen = new Pen(Brushes.Black, 1F); blackPen.DashStyle = DashStyle.Dash; int startX = (int)(e.PageBounds.Width * 0.06f); // 6% dari batas kiri area print int startY = 15; // Jarak dari batas atas area print int startCenter = e.PageBounds.Width / 2; // Pertengahan area print int endOfLine = e.PageBounds.Width - (int)(e.PageBounds.Width * 0.06f); // 6% dari batas kanan area print int offset = 15; // Jarak baris antara huruf // -------------------------------- Header --------------------------------------- // // Title / nama cafe graphics.DrawString(MainProgram.Pengaturan.nama , font12.Bold(), Brushes.Black, startCenter, startY, formatCenter); // Cek jika alamat_1 tersedia if (!string.IsNullOrWhiteSpace(MainProgram.Pengaturan.alamat_1)) { offset += font12.Height; // alamat 1 graphics.DrawString(MainProgram.Pengaturan.alamat_1 , font8, Brushes.Black, startCenter, offset, formatCenter); } // Cek jika alamat_2 tersedia if (!string.IsNullOrWhiteSpace(MainProgram.Pengaturan.alamat_2)) { offset += font8.Height; // alamat 2 graphics.DrawString(MainProgram.Pengaturan.alamat_2 , font8, Brushes.Black, startCenter, offset, formatCenter); } // Cek jika telepon tersedia if (!string.IsNullOrWhiteSpace(MainProgram.Pengaturan.telpon)) { offset += font8.Height; // telepon graphics.DrawString(MainProgram.Pengaturan.telpon , font8, Brushes.Black, startCenter, offset, formatCenter); } // Cek jika kota tersedia if (!string.IsNullOrWhiteSpace(MainProgram.Pengaturan.kota)) { offset += font8.Height; // kota graphics.DrawString(MainProgram.Pengaturan.kota , font8, Brushes.Black, startCenter, offset, formatCenter); } // -------------------------------- End of Header -------------------------------- // offset += font8.Height; // Garis DrawLine(graphics, startX, offset, endOfLine, blackPen); // ------------------------------------------------------------------------------- // offset += 2; graphics.DrawString($"NOTA PENJUALAN", font8.Bold(), Brushes.Black, startX, offset); offset += font8.Height; // Tanggal graphics.DrawString($"{"TANGGAL".PadRight(12)} : " + $"{_penjualanModel.tanggal.ToString("dd/MM/yyyy HH:mm:ss")}" , font8, Brushes.Black, startX, offset); offset += font8.Height; // No Nota graphics.DrawString($"{"NO NOTA".PadRight(12)} : {_penjualanModel.no_nota}" , font8, Brushes.Black, startX, offset); offset += font8.Height; // Pelanggan graphics.DrawString($"{"PELANGGAN".PadRight(12)} : {_penjualanModel.pelanggan_nama}" , font8, Brushes.Black, startX, offset); offset += font8.Height; // Pembayaran graphics.DrawString($"{"PEMBAYARAN".PadRight(12)} : {_penjualanModel.status_pembayaran_nama}" , font8, Brushes.Black, startX, offset); offset += font8.Height; //// Operator //graphics.DrawString($"{"OPERATOR".PadRight(12)} : {MainProgram.OperatorActive.nama}" // , font8, Brushes.Black, startX, offset); //offset += font8.Height; // Garis DrawLine(graphics, startX, offset, endOfLine, blackPen); // ------------------------------------------------------------------------------- // offset += 2; // -------------------------------- List Item ------------------------------------ // foreach (var item in _penjualanModel.PenjualanDetails) { // Nama //------------------------------------------------------------------- // graphics.DrawString(item.barang_nama, font8, Brushes.Black, startX, offset); offset += font8.Height; // Qtx x Harga Sub Total //------------------------------------------------------------------- // var qty = item.qty.ToString("N0").PadLeft(5); var harga = item.Barang.harga_jual.ToString("N0"); graphics.DrawString(qty + " x " + harga, font8, Brushes.Black , startX, offset); var subTotal = item.total.ToString("N0").PadLeft(5); graphics.DrawString(subTotal, font8, Brushes.Black , endOfLine, offset, formatRight); offset += font8.Height; } // -------------------------------- End of List Item ----------------------------- // // Garis DrawLine(graphics, startX, offset, endOfLine, blackPen); // ------------------------------------------------------------------------------- // offset += 2; // Total Item graphics.DrawString("TOTAL ITEM", font8, Brushes.Black , startX, offset); graphics.DrawString(_penjualanModel.PenjualanDetails.ToList().Count.ToString("N0") , font8, Brushes.Black, endOfLine, offset, formatRight); offset += font8.Height; // Total Qty graphics.DrawString("TOTAL QTY", font8, Brushes.Black, startX, offset); graphics.DrawString(_penjualanModel.PenjualanDetails.ToList().Sum(p => p.qty).ToString("N0") , font8, Brushes.Black, endOfLine, offset, formatRight); offset += font8.Height; // Sub Total graphics.DrawString("SUB TOTAL", font8, Brushes.Black, startX, offset); graphics.DrawString(_penjualanModel.sub_total.ToString("C") , font8, Brushes.Black, endOfLine, offset, formatRight); offset += font8.Height; // Diskon graphics.DrawString("DISKON", font8, Brushes.Black, startX, offset); graphics.DrawString(_penjualanModel.diskon.ToString("C") , font8, Brushes.Black, endOfLine, offset, formatRight); offset += font8.Height; // Garis DrawLine(graphics, startX, offset, endOfLine, blackPen); // ------------------------------------------------------------------------------- // offset += 2; // Total graphics.DrawString("TOTAL", font12.Bold(), Brushes.Black, startX, offset); graphics.DrawString(_penjualanModel.grand_total.ToString("C") , font12.Bold(), Brushes.Black, endOfLine, offset, formatRight); offset += font12.Height; // Dibayar graphics.DrawString("DIBAYAR", font8, Brushes.Black, startX, offset); graphics.DrawString(_penjualanModel.jumlah_bayar.ToString("C") , font8, Brushes.Black, endOfLine, offset, formatRight); offset += font8.Height; // Kembali graphics.DrawString("KEMBALI", font8, Brushes.Black, startX, offset); graphics.DrawString(_penjualanModel.kembali.ToString("C") , font8, Brushes.Black, endOfLine, offset, formatRight); offset += font8.Height; // Garis DrawLine(graphics, startX, offset, endOfLine, blackPen); // ------------------------------------------------------------------------------- // offset += 2; graphics.DrawString("TERIMA KASIH", font8 , Brushes.Black, startCenter, offset, formatCenter); offset += font8.Height; graphics.DrawString("ATAS KUNJUNGAN ANDA", font8 , Brushes.Black, startCenter, offset, formatCenter); offset += font8.Height; // Garis DrawLine(graphics, startX, offset, endOfLine, blackPen); // ------------------------------------------------------------------------------- // offset += 2; graphics.DrawString("PERHATIAN:", font6 , Brushes.Black, startX, offset, formatLeft); offset += font6.Height; graphics.DrawString("Barang-barang yang sudah dibeli tidak dapat\ndikembalikan/ditukar.", font6 , Brushes.Black, startX, offset, formatLeft); }