internal Trader GetCustomer(string custcode,MyModel model,string pathToDatabase) { Trader cust = new Trader (); Trader comp = DataHelper.GetTrader (pathToDatabase, custcode); string tel = string.IsNullOrEmpty (comp.Tel) ? " " : comp.Tel.Trim (); string fax = string.IsNullOrEmpty (comp.Fax) ? " " : comp.Fax.Trim (); string addr1 =string.IsNullOrEmpty (comp.Addr1) ? "" : comp.Addr1.Trim (); string addr2 =string.IsNullOrEmpty (comp.Addr2) ? "" : comp.Addr2.Trim (); string addr3 =string.IsNullOrEmpty (comp.Addr3) ? "" : comp.Addr3.Trim (); string addr4 =string.IsNullOrEmpty (comp.Addr4) ? "" : comp.Addr4.Trim (); string gst =string.IsNullOrEmpty (comp.gst) ? "" : comp.gst.Trim (); cust = comp; string test = ""; if (addr1!="") test += comp.Addr1.Trim () + "\n"; if (addr2!="") test += comp.Addr2.Trim () + "\n"; if (addr3!="") test += comp.Addr3.Trim () + "\n"; if (addr4!="") test += comp.Addr4.Trim () + "\n"; model.CustomerAddress = test; return cust; }
internal string GetInvoiceText_Template(string templatefilename,string pathToDatabase,string userID,Invoice inv, InvoiceDtls[] list) { string template = GetTemplateFile(templatefilename, pathToDatabase); if (string.IsNullOrEmpty (template)) return ""; MyModel model = new MyModel (); model.Customer = GetCustomer(inv.custcode,model,pathToDatabase); model.PrintDate = DateTime.Now; model.UserID = userID; model.Invoicehdr = inv; model.InvDtls = new List<InvoiceDtls> (); model.TaxSumm = new List<TaxInfo> (); foreach (var item in list) { model.InvDtls.Add (item); } GetInvTaxInfo (list, pathToDatabase, model); VelocityEngine fileEngine = new VelocityEngine(); fileEngine.Init(); VelocityContext context = new VelocityContext(); StreamWriter ws = new StreamWriter(new MemoryStream()); context.Put("util", new CustomTool()); context.Put("model", model); fileEngine.Evaluate(context, ws, null, template); string text = ""; ws.Flush(); byte[] data = new byte[ws.BaseStream.Length-2]; ws.BaseStream.Position = 2; int nread = ws.BaseStream.Read(data, 0, data.Length); text = Encoding.UTF8.GetString(data, 0, nread); ws.Close(); return text; }
internal void GetInvTaxInfo(InvoiceDtls[] list, string pathToDatabase, MyModel model) { List<Item> list2 = new List<Item> (); using (var db = new SQLite.SQLiteConnection (pathToDatabase)) { list2 = db.Table<Item> ().ToList<Item> (); } var grp = from p in list group p by p.taxgrp into g select new { taxgrp = g.Key, ttltax = g.Sum (x => x.tax), ttlAmt = g.Sum (v => v.netamount) }; foreach (var g in grp) { TaxInfo taxinfo = new TaxInfo(); taxinfo.Tax = g.taxgrp.Trim(); taxinfo.TaxPer =0; var list3 = list2.Where(x => x.taxgrp == g.taxgrp).ToList(); if (list3.Count > 0) { taxinfo.TaxPer = list3[0].tax; } taxinfo.TaxAmt = g.ttltax; taxinfo.Amount = g.ttlAmt; model.TaxSumm.Add(taxinfo); } }