//getDept by empId public static DepartmentVM GetDept(int empId) { DepartmentVM department = new DepartmentVM(); using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { string deptCode = EmployeeBL.GetDeptCode(empId); department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)) .Select(d => new DepartmentVM() { DeptCode = d.DeptCode, DeptName = d.DeptName, DeptCtcNo = d.DeptCtcNo, DeptFaxNo = d.DeptFaxNo, ColPtId = d.ColPtId, DeptHeadId = d.DeptHeadId, DeptRepId = d.DeptRepId, DelegateApproverId = d.DelegateApproverId, DelegateFromDate = d.DelegateFromDate, DelegateToDate = d.DelegateToDate, EmpId = empId }).First <DepartmentVM>(); } return(department); }
public static void GeneratePurchaseOrderList(int empId, DateTime expected_Date, List <ItemVM> iList) { SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext(); //List<ItemVM> iList = ItemBL.GetAllItems().Take(20).ToList();//****************************hard Coded**************** List <ItemVM> items = new List <ItemVM>(); List <Supplier> suppliers = new List <Supplier>(); string orderby_name = EmployeeBL.GetEmp(empId).EmpName; string approvedby_name_rep = EmployeeBL.GetEmp(105).EmpName; string approvedby_name_mgr = EmployeeBL.GetEmp(104).EmpName; string filename = "PurchaseOrder_" + DateTime.Now.ToString("ddMMMMyyyy_HH_mm_ss") + ".pdf"; string filePath = HttpContext.Current.Server.MapPath("~/Report_Templates/"); string HTML = string.Empty; List <string> suppcodes1 = iList.Select(x => x.SuppCode1).Distinct().ToList(); List <string> suppcodes2 = iList.Select(x => x.SuppCode2).Distinct().ToList(); List <string> suppcodes3 = iList.Select(x => x.SuppCode3).Distinct().ToList(); foreach (string supp in suppcodes1) { List <Supplier> suppl = entities.Suppliers.Where(s => s.SuppCode.Equals(supp)).ToList(); suppliers.AddRange(suppl); } foreach (string supp in suppcodes2) { List <Supplier> suppl = entities.Suppliers.Where(s => s.SuppCode.Equals(supp)).ToList(); if (suppliers.Where(x => x.SuppCode.Equals(supp)).ToList().Count() == 0) { suppliers.AddRange(suppl); } } foreach (string supp in suppcodes3) { List <Supplier> suppl = entities.Suppliers.Where(s => s.SuppCode.Equals(supp)).ToList(); if (suppliers.Where(x => x.SuppCode.Equals(supp)).ToList().Count() == 0) { suppliers.AddRange(suppl); } } foreach (Supplier sup in suppliers) { HTML = string.Concat(HTML, File.ReadAllText(filePath + "POList_Header.txt", System.Text.Encoding.UTF8)); HTML = string.Concat(HTML, File.ReadAllText(filePath + "POList_Sub_Header.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[supp_name]", sup.SuppName); HTML = HTML.Replace("[supp_ctx_name]", sup.SuppCtcName); HTML = HTML.Replace("[supp_addr_1]", sup.SuppAddr); HTML = HTML.Replace("[expected_date]", expected_Date.ToString("dd MMMM yyyy")); int total_qyantity = 0; double total_amount = 0; foreach (ItemVM item in iList.Where(i => i.SuppCode1.Equals(sup.SuppCode) || i.SuppCode2.Equals(sup.SuppCode) || i.SuppCode3.Equals(sup.SuppCode))) { if (item != null) { double price = 0; if (sup.SuppCode.Equals(item.SuppCode1)) { price = item.Price1; } if (sup.SuppCode.Equals(item.SuppCode2)) { price = item.Price2; } if (sup.SuppCode.Equals(item.SuppCode3)) { price = item.Price3; } HTML = string.Concat(HTML, File.ReadAllText(filePath + "POList_Body.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[itemcode]", item.ItemCode); HTML = HTML.Replace("[item_desc]", item.Desc); HTML = HTML.Replace("[item_uom]", item.UOM); HTML = HTML.Replace("[item_order_qty]", item.TempOrderQty.ToString()); HTML = HTML.Replace("[item_price]", price.ToString("C")); HTML = HTML.Replace("[item_amount]", (item.TempOrderQty * price).ToString("C")); total_qyantity += item.TempOrderQty; //total_price += price; total_amount += item.ReorderQty * price; } else { break; } } HTML = string.Concat(HTML, File.ReadAllText(filePath + "POList_Footer.txt", System.Text.Encoding.UTF8)); //HTML = HTML.Replace("[total_qty]", total_qyantity.ToString()); //HTML = HTML.Replace("[total_price]", total_price.ToString("C")); HTML = HTML.Replace("[total_amount]", total_amount.ToString("C")); HTML = HTML.Replace("[order_by]", orderby_name); HTML = HTML.Replace("[approved_by]", total_qyantity >= 250 ? approvedby_name_mgr : approvedby_name_rep); HTML = HTML.Replace("[order_by_date]", System.DateTime.Now.ToString("dd MMMM yyyy")); HTML = HTML.Replace("[approved_by_date]", System.DateTime.Now.ToString("dd MMMM yyyy")); } PDFGenerator_A4Landscape(filename, HTML); EmailBL.SendPOEmail(empId, expected_Date, filename); }
public static string GenerateDisbursementListby_Dept_Employee_OrderNo(List <DisbursementDetailVM> disbList, string filename) { SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext(); //List<DisbursementDetailVM> disbList = entities.RequestDetails.Where(rd => rd.ReqQty > 0) //****************************hard Coded**************** // .Join(entities.Requests, rd => rd.ReqId, r => r.ReqId, (rd, r) => new { rd, r }) // .Join(entities.Items, rd => rd.rd.ItemCode, i => i.ItemCode, (rd, i) => new { rd, i }) // .Join(entities.Employees, r => r.rd.r.EmpId, e => e.EmpId, (r, e) => new { r, e }) // .Select(result => new DisbursementDetailVM // { // DeptCode = result.e.DeptCode, // ItemCode = result.r.rd.rd.ItemCode, // Category = result.r.i.Cat, // Description = result.r.i.Desc, // ReqQty = result.r.rd.rd.ReqQty, // AwaitQty = result.r.rd.rd.AwaitQty, // FulfilledQty = result.r.rd.rd.FulfilledQty, // EmpId = result.e.EmpId, // ReqId = result.r.rd.r.ReqId // }).ToList(); List <string> deptCodes = disbList.Select(d => d.DeptCode).Distinct().ToList(); string filePath = HttpContext.Current.Server.MapPath("~/Report_Templates/"); string HTML = string.Empty; // HTML = File.ReadAllText(filePath + "DisbursementListByDept_Header.txt", System.Text.Encoding.UTF8); foreach (string dept in deptCodes) { string collectionpint = entities.CollectionPoints .Join(entities.Departments.Where(d => d.DeptCode.Equals(dept)), c => c.ColPtId, d => d.ColPtId, (c, d) => new { c, d }).Select(x => x.c.Location).First().ToString(); string collectiontime = entities.CollectionPoints .Join(entities.Departments.Where(d => d.DeptCode.Equals(dept)), c => c.ColPtId, d => d.ColPtId, (c, d) => new { c, d }).Select(x => x.c.Time).First().ToString(); //string colpoint = entities.Departments.Where(d => d.ColPtId == d.co string repname = entities.Employees .Join(entities.Departments.Where(d => d.DeptCode.Equals(dept)), e => e.DeptCode, d => d.DeptCode, (e, d) => new { e, d }) .Where(r => r.e.EmpId == r.d.DeptRepId).Select(x => x.e.EmpName).First().ToString(); string deptname = entities.Departments.Where(d => d.DeptCode.Equals(dept)).Select(d => d.DeptName).First().ToString(); List <DisbursementDetailVM> dList = new List <DisbursementDetailVM>(); List <int> EmpList = new List <int>(); List <int> empIds = disbList.Select(d => d.EmpId).Distinct().ToList(); foreach (int emp in empIds) { if (disbList.Where(d => d.EmpId == emp && d.DeptCode.Equals(dept)).ToList().Count > 0) { HTML = string.Concat(HTML, File.ReadAllText(filePath + "DisbursementListByDept_Emp_Order_Header.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[disb-date]", DateTime.Now.ToString("dd MMMM yyyy")); HTML = HTML.Replace("[coll-point]", collectionpint); HTML = HTML.Replace("[coll-time]", collectiontime); HTML = HTML.Replace("[DeptName]", deptname); HTML = HTML.Replace("[rep-name]", repname); string empName = EmployeeBL.GetEmp(emp).EmpName; HTML = string.Concat(HTML, File.ReadAllText(filePath + "DisbursementListByDept_Emp_Order_Sub_Header.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[emp-name]", empName); foreach (DisbursementDetailVM dis in disbList.Where(d => d.EmpId == emp && d.DeptCode.Equals(dept))) { HTML = string.Concat(HTML, File.ReadAllText(filePath + "DisbursementListByDept_Emp_Order_Body.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[orderNo]", dis.ReqId.ToString()); HTML = HTML.Replace("[itemcode]", dis.ItemCode); HTML = HTML.Replace("[item_desc]", dis.Description); HTML = HTML.Replace("[request_qty]", dis.ReqQty.ToString()); HTML = HTML.Replace("[await_qty]", dis.AwaitQty.ToString()); HTML = HTML.Replace("[fulfilled_qty]", dis.FulfilledQty.ToString()); } HTML = string.Concat(HTML, File.ReadAllText(filePath + "DisbursementListByDept_Emp_Order_Footer.txt", System.Text.Encoding.UTF8)); } } } PDFGenerator(filename, HTML); return(filename); }