/// <summary>
///发票绘制/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PdInvoice_PrintPage(objectsender, PrintPageEventArgs e)
{string[] journal =currentResponse.Journal.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);string pos_time = journal[9].Replace("POS Time:", "");if (!string.IsNullOrEmpty(orderTableEntity.member_No))
pos_time= journal[10].Replace("POS Time:", "");var s1 = new BaseRepository<BillConsumeDetailEntityTable>();var s2 = new BaseRepository<BillPayDetailEntityTable>();var list1 = s1.GetList(o => o.order_No ==orderTableEntity.orderNo);var list2 = s2.GetList(o => o.order_No ==orderTableEntity.orderNo);int right_space = 32;
e.Graphics.Clear(Color.White);
Rectangle rect= new Rectangle(0, 0, 300, 360);#region StringFormatStringFormat sf_center= newStringFormat();
sf_center.Alignment=StringAlignment.Center;
sf_center.LineAlignment=StringAlignment.Center;
StringFormat sf_left= newStringFormat();
sf_left.Alignment=StringAlignment.Near;
sf_left.LineAlignment=StringAlignment.Center;
StringFormat sf_right= newStringFormat();
sf_right.Alignment=StringAlignment.Far;
sf_right.LineAlignment=StringAlignment.Center;#endregionFont tipsFont= new Font("微软雅黑", 9F, FontStyle.Bold);
Font txtFont= new Font("微软雅黑", 9F);
e.Graphics.DrawString($"{merchantStoreEntity.name}", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_center);
rect.Y+= 20;
e.Graphics.DrawString($"===========================================", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 20;
e.Graphics.DrawString($"PH#:{merchantStoreEntity.phone} MOB#:{merchantStoreEntity.mobile}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_center);if (!string.IsNullOrEmpty(merchantStoreEntity.store_advertising))
{
rect.Y+= 20;
e.Graphics.DrawString($"{merchantStoreEntity.store_advertising}", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_center);
}
rect.Y+= 20;
e.Graphics.DrawString($"========= FISCAL INVOICE ===============", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 20;
e.Graphics.DrawString($"TIN:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString(currentResponse.TIN, txtFont, Brushes.Black,new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"Company:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{currentResponse.BusinessName}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"Store:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{merchantStoreEntity.name}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"Address:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{currentResponse.Address}", txtFont, Brushes.Black, new Rectangle(42, rect.Y, rect.Width - 76, 40), sf_right);
rect.Y+= 40;
e.Graphics.DrawString($"District:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{currentResponse.District}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"Cashier TIN:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{CashierFlowContext.Instance.CurrentEmployee.employeeName}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"POS Number:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{orderTableEntity.orderNo}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"POS Time:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString(pos_time.Trim(), txtFont, Brushes.Black,new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);if (!string.IsNullOrEmpty(orderTableEntity.member_No))
{
rect.Y+= 20;
e.Graphics.DrawString($"Buyer TIN:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{orderTableEntity.member_No}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
}
rect.Y+= 20;
e.Graphics.DrawString($"-----------------NORMAL SALE--------------------", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 20;
e.Graphics.DrawString($"Items", txtFont, Brushes.Black, new Rectangle(4, rect.Y, rect.Width, 20), sf_center);
rect.Y+= 20;
e.Graphics.DrawString($"===========================================", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 18;
e.Graphics.DrawString($"Name Price Qty. Total", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 16;var goodsSvr = new BaseRepository<GoodsTableEntity>();foreach (var detailRow inlist1)
{var goods = goodsSvr.GetFirst(g => g.goodsNo ==detailRow.goods_No);string label = goods == null ?ConfigObj.MISCELLANEOUS_Rate_Label : goods.taxLabels;
e.Graphics.DrawString($"{detailRow.goods_Name} ({label})", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{detailRow.sale_price.ToString("C2").Substring(1)}", txtFont, Brushes.Black, new Rectangle(rect.Width / 2 - 86, rect.Y + 16, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{detailRow.qty}", txtFont, Brushes.Black, new Rectangle(rect.Width / 2 - 8, rect.Y + 16, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{detailRow.amount.ToString("C2").Substring(1)}", txtFont, Brushes.Black, new Rectangle(0, rect.Y + 16, rect.Width - right_space - 8, 20), sf_right);
rect.Y+= 34;
}
e.Graphics.DrawString($"Total Purchase:", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{orderTableEntity.payAmount.ToString("C2").Substring(1)}", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;var service = new BaseRepository<Payment_method_tableEntity>();var p = service.GetFirst(pm => pm.pm_Id ==list2.FirstOrDefault().payment_method);
e.Graphics.DrawString($"Payment Method:", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);if (p.TaxcoreName !=p.pm_Name)
e.Graphics.DrawString(p.TaxcoreName, tipsFont, Brushes.Black,new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);elsee.Graphics.DrawString($"{p.pm_Name}", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"===========================================", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 18;
e.Graphics.DrawString($"Label Name Rate", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString("Tax", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;foreach (var rate incurrentResponse.TaxItems)
{
e.Graphics.DrawString($"{rate.Label} {rate.CategoryName} {rate.Rate}%", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{rate.Amount.ToString("C2").Substring(1)}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
}
e.Graphics.DrawString($"--------------------------------------------------", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 20;
e.Graphics.DrawString($"Total Tax:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{currentResponse.TaxItems.Sum(t => t.Amount).ToString("C2").Substring(1)}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"===========================================", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 20;
e.Graphics.DrawString($"SDC Time:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);string dt = Convert.ToDateTime(currentResponse.DT).ToString("dd/MM/yyyy HH:mm:ss");if (ConfigObj.RequstBaseURL.Contains("sandbox"))
{
dt= Convert.ToDateTime(currentResponse.DT.AddHours(-12)).ToString("dd/MM/yyyy HH:mm:ss");//.ToString("dd/MM/yyyy HH:mm:ss");
}
e.Graphics.DrawString($"{dt}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"SDC Invoice No:", new Font("微软雅黑", 8.2F), Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_left);
e.Graphics.DrawString($"{currentResponse.IN}", new Font("微软雅黑", 8.2F), Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"Invoice Counter:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_left);
e.Graphics.DrawString($"{currentResponse.IC}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"===========================================", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 20;byte[] bytes =Convert.FromBase64String(currentResponse.VerificationQRCode);
MemoryStream memStream= newMemoryStream(bytes);
Image mImage=Image.FromStream(memStream);
e.Graphics.DrawImage(mImage,new Rectangle(8, rect.Y, 266, 266));
rect.Y+= 266;
e.Graphics.DrawString($"====== END OF FISCAL INVOICE ==========", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 20;
e.Graphics.DrawString($"Subtotal ({list1.Count()} items)", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{list1.Sum(o => o.amount).ToString("C2").Substring(1)}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);if (orderTableEntity.payMethodName.Contains("->("))
{
rect.Y+= 20;
e.Graphics.DrawString($"===========Aggregated payment============", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
rect.Y+= 20;
e.Graphics.DrawString($"Payment method:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{orderTableEntity.payMethodName}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"Payment Amount:", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{orderTableEntity.payAmount.ToString("C2").Substring(1)}", txtFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
}if (p.is_cash.ToUpper().Equals("Y") && (list2.Any(o => o.exchangeAmount > 0)))
{
rect.Y+= 20;
e.Graphics.DrawString($"Collection:", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{(orderTableEntity.payAmount + orderTableEntity.payBackAmount).ToString("C2").Substring(1)}", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
rect.Y+= 20;
e.Graphics.DrawString($"Change:", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_left);
e.Graphics.DrawString($"{orderTableEntity.payBackAmount.ToString("C2").Substring(1)}", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width - right_space, 20), sf_right);
}if (!string.IsNullOrEmpty(merchantStoreEntity.store_advertising_footer))
{
rect.Y+= 22;
e.Graphics.DrawString($"{merchantStoreEntity.store_advertising_footer}", tipsFont, Brushes.Black, new Rectangle(0, rect.Y, rect.Width, 20), sf_center);
}
}