//set Delegate by DepartmentCode , fromDate , toDate and empId public static bool setDelegate(string deptCode, DateTime fromDate, DateTime toDate, int empId) { //DepartmentVM deptVM = new DepartmentVM(); using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Department department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)).First(); department.DeptCode = deptCode; department.DelegateFromDate = fromDate; department.DelegateToDate = toDate; department.DelegateApproverId = empId; int rowinserted = entities.SaveChanges(); if (rowinserted > 0) { string startDate = (department.DelegateFromDate ?? default(DateTime)).ToString("dd MMMM yyyy"); string endDate = (department.DelegateToDate ?? default(DateTime)).ToString("dd MMMM yyyy"); EmailBL.AddNewEmailToEmp(empId, "Assign Delegate", "You have been assigned as delegate from " + startDate + " to " + endDate); return(true); } else { return(false); } } }
// submit request // done public static RequestVM SubmitReq(int reqId, List <RequestDetailVM> reqDetList) { // make requestId in reqDetList is the same as reqId using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { RequestVM req = GetReq(reqId); for (int i = 0; i < reqDetList.Count; i++) { if (reqDetList[i].ReqId == reqId) { List <RequestDetail> rdlist = entities.RequestDetails.ToList(); for (int j = 0; j < rdlist.Count; j++) { if (reqDetList[i].ReqId == rdlist[j].ReqId && reqDetList[i].ReqLineNo == rdlist[j].ReqLineNo) { rdlist[j].ReqQty = reqDetList[i].ReqQty; rdlist[j].AwaitQty = reqDetList[i].AwaitQty; rdlist[j].FulfilledQty = reqDetList[i].FulfilledQty; entities.SaveChanges(); } } } } req.ReqDateTime = DateTime.Now; req.Status = "Submitted"; req = UpdateReq(req); int empId = req.EmpId; Employee emp = entities.Employees.Where(x => x.EmpId == empId).FirstOrDefault(); string deptCode = emp.DeptCode; Department dept = entities.Departments.Where(x => x.DeptCode == deptCode).FirstOrDefault(); int fromEmpId = req.EmpId; int toEmpId; if (dept.DelegateApproverId != null && DateTime.Compare(DateTime.Now, (DateTime)dept.DelegateFromDate) >= 0 && DateTime.Compare(DateTime.Now, (DateTime)dept.DelegateToDate) >= 0) { toEmpId = (int)dept.DelegateApproverId; } else { toEmpId = (int)dept.DeptHeadId; } string type = "Stationery Request"; string content = "A new stationery request has been submitted"; NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content); // for email EmailBL.SendNewReqEmail(empId, req); return(req); } catch (Exception ex) { throw ex; } } }
//set Rep by DepartmentCode , fromEmpId and toEmpId public static void setRep(string deptCode, int empId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Department department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)).First <Department>(); { department.DeptRepId = empId; entities.SaveChanges(); EmailBL.AddNewEmailToEmp(empId, "Assign Reprsentative", "You have been assigned as reprsentative for your department."); } } return; }
// reject request // done public static bool RejectRequest(int reqId, int empId, string cmt) { try { List <RequestVM> reqlist = GetReq(empId, "Submitted"); // for email RequestVM reqVM = new RequestVM(); int toId = 0; for (int i = 0; i < reqlist.Count; i++) { if (reqlist[i].ReqId == reqId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Request req = entities.Requests.Where(r => r.ReqId == reqId).FirstOrDefault(); toId = req.EmpId; req.ApproverId = empId; req.ApproverComment = cmt; req.ApprovedDateTime = DateTime.Now; req.Status = "Rejected"; entities.SaveChanges(); // for email reqVM.ReqId = req.ReqId; reqVM.EmpId = req.EmpId; reqVM.ApproverId = req.ApproverId; reqVM.ApproverComment = req.ApproverComment; reqVM.ReqDateTime = (DateTime)req.ReqDateTime; reqVM.ApprovedDateTime = (DateTime)req.ApprovedDateTime; //reqVM.CancelledDateTime = (DateTime)req.CancelledDateTime; reqVM.Status = req.Status; //reqVM.FulfilledDateTime = (DateTime)req.FulfilledDateTime; } } } int fromEmpId = empId; int toEmpId = toId; string type = "Stationery Request"; string content = "Your stationery request has been rejected : Please review quantities"; NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content); // for email EmailBL.SendReqApprEmail(toId, reqVM); return(true); } catch (Exception ex) { throw ex; } }
//set Delegate by DepartmentCode , fromDate , toDate and empId public static void setDelegate(string deptCode, DateTime fromDate, DateTime toDate, int empId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Department department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)).First(); department.DeptCode = deptCode; department.DelegateFromDate = fromDate; department.DelegateToDate = toDate; department.DelegateApproverId = empId; entities.SaveChanges(); string startDate = (department.DelegateFromDate ?? default(DateTime)).ToString("dd MMMM yyyy"); string endDate = (department.DelegateToDate ?? default(DateTime)).ToString("dd MMMM yyyy"); EmailBL.AddNewEmailToEmp(empId, "Assign Delegate", "You have been assigned as delegate from " + startDate + " to " + endDate); } }
public static void GenerateInventoryItemList(int empId) { string filename = "InventoryStatusReport_" + DateTime.Now.ToString("ddMMMMyyyy_HH_mm_ss") + ".pdf"; SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext(); List <ItemVM> InventoryItemList = ItemBL.GetAllItems(); string filePath = HttpContext.Current.Server.MapPath("~/Report_Templates/"); string HTML = string.Empty; HTML = string.Concat(HTML, File.ReadAllText(filePath + "InventoryItem_Header.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[date]", DateTime.Now.ToString("dd MMMM yyyy")); int sr_no = 1; foreach (ItemVM item in InventoryItemList) { HTML = string.Concat(HTML, File.ReadAllText(filePath + "InventoryItem_Body.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[#]", sr_no.ToString()); HTML = HTML.Replace("[itemcode]", item.ItemCode); HTML = HTML.Replace("[item_desc]", item.Desc); HTML = HTML.Replace("[location]", item.Location); HTML = HTML.Replace("[uom]", item.UOM); HTML = HTML.Replace("[item_balance]", item.Balance.ToString()); HTML = HTML.Replace("[item_restock_lvl]", item.ReorderLevel.ToString()); HTML = HTML.Replace("[item_restock_qty]", item.ReorderQty.ToString()); HTML = HTML.Replace("[item_supp1]", item.SuppCode1); HTML = HTML.Replace("[item_supp2]", item.SuppCode2); HTML = HTML.Replace("[item_supp3]", item.SuppCode3); sr_no += 1; } HTML = string.Concat(HTML, File.ReadAllText(filePath + "InventoryItem_Footer.txt", System.Text.Encoding.UTF8)); PDFGenerator_A3Landscape(filename, HTML); EmailBL.SendInvListEmail(empId, filename); }
//set Rep by DepartmentCode , fromEmpId and toEmpId public static bool setRep(string deptCode, int empId) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { Department department = entities.Departments.Where(d => d.DeptCode.Equals(deptCode)).First <Department>(); { department.DeptRepId = empId; int rowinserted = entities.SaveChanges(); if (rowinserted > 0) { EmailBL.AddNewEmailToEmp(empId, "Assign Representative", "You have been assigned as representative for your department."); return(true); } else { return(false); } } } }
public static void GenerateLowStockItemList(int empId) { string filename = "StationeryItemsWithLowStockQuantities_" + DateTime.Now.ToString("ddMMMMyyyy_HH_mm_ss") + ".pdf"; SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext(); List <ItemVM> LowStockItemList = ItemBL.GetLowStockItems(); string filePath = HttpContext.Current.Server.MapPath("~/Report_Templates/"); string HTML = string.Empty; HTML = string.Concat(HTML, File.ReadAllText(filePath + "LowStockItemList_Header.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[date]", DateTime.Now.ToString("dd MMMM yyyy")); int sr_no = 1; foreach (ItemVM item in LowStockItemList) { HTML = string.Concat(HTML, File.ReadAllText(filePath + "LowStockItemList_Body.txt", System.Text.Encoding.UTF8)); HTML = HTML.Replace("[#]", sr_no.ToString()); HTML = HTML.Replace("[itemcode]", item.ItemCode); HTML = HTML.Replace("[item_desc]", item.Desc); HTML = HTML.Replace("[uom]", item.UOM); HTML = HTML.Replace("[item_balance]", item.Balance.ToString()); HTML = HTML.Replace("[item_restock_lvl]", item.ReorderLevel.ToString()); HTML = HTML.Replace("[item_restock_qty]", item.ReccReorderQty.ToString()); HTML = HTML.Replace("[item_supp1]", item.SuppCode1); HTML = HTML.Replace("[item_p1]", item.Price1.ToString("C")); //string.Format("{0:C}", Math.Round(item.Price1,3)) HTML = HTML.Replace("[item_supp2]", item.SuppCode2); HTML = HTML.Replace("[item_p2]", item.Price2.ToString("C")); HTML = HTML.Replace("[item_supp3]", item.SuppCode3); HTML = HTML.Replace("[item_p3]", item.Price3.ToString("C")); sr_no += 1; } HTML = string.Concat(HTML, File.ReadAllText(filePath + "LowStockItemList_Footer.txt", System.Text.Encoding.UTF8)); PDFGenerator_A3Landscape(filename, HTML); EmailBL.SendLowStockEmail(empId, filename); }
// accept adjustment request // done public static bool AcceptRequest(string voucherNo, int empId, string cmt) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { // for email List <AdjustmentVM> adjListEmail = new List <AdjustmentVM>(); int toId = 0; List <Adjustment> adjList = entities.Adjustments.Where(a => a.VoucherNo.Equals(voucherNo)).ToList(); for (int i = 0; i < adjList.Count; i++) { if (adjList[i].ApproverId == empId) { adjList[i].ApproverComment = cmt; adjList[i].Status = "Approved"; int adjRaiseEmpId = adjList[i].EmpId; Employee adjRaiseEmp = entities.Employees.Where(x => x.EmpId == adjRaiseEmpId).FirstOrDefault(); if (adjRaiseEmp.Role.Equals("Store Clerk")) { toId = adjRaiseEmpId; } else { toId = entities.Employees.Where(x => x.Role.Equals("Store Clerk")).FirstOrDefault().EmpId; } // for email AdjustmentVM adj = new AdjustmentVM(); adj.VoucherNo = adjList[i].VoucherNo; adj.EmpId = adjList[i].EmpId; adj.DateTimeIssued = adjList[i].DateTimeIssued; adj.ItemCode = adjList[i].ItemCode; adj.Reason = adjList[i].Reason; adj.QtyChange = adjList[i].QtyChange; adj.Status = adjList[i].Status; adj.ApproverId = (int)adjList[i].ApproverId; adj.ApproverComment = adjList[i].ApproverComment; adjListEmail.Add(adj); string itemCode = adjList[i].ItemCode; Item item = entities.Items.Where(x => x.ItemCode.Equals(itemCode)).First(); item.Balance += adjList[i].QtyChange; TransactionVM trans = new TransactionVM(); trans.TranDateTime = DateTime.Now; trans.ItemCode = itemCode; trans.QtyChange = adjList[i].QtyChange; trans.UnitPrice = (double)item.Price1; trans.Desc = "Adjustment"; trans.DeptCode = ""; trans.SuppCode = ""; trans.VoucherNo = adjList[i].VoucherNo; TransactionBL.AddTran(trans); bool status = ItemBL.CheckLowStk(ItemUtility.Convert_ItemObj_To_ItemVMObj(item)); if (status) { NotificationBL.AddLowStkNotification(empId, item); } } } entities.SaveChanges(); int fromEmpId = empId; int toEmpId = toId; string type = "Adjustment Request"; string content = voucherNo + " has been approved: No comment"; NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content); // for email EmailBL.SendAdjApprEmail(toId, adjListEmail); return(true); } catch (Exception ex) { throw ex; } } }
// reject adjustment request // done public static bool RejectRequest(string voucherNo, int empId, string cmt) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { // for email List <AdjustmentVM> adjListEmail = new List <AdjustmentVM>(); int toId = 0; List <Adjustment> adjList = entities.Adjustments.Where(a => a.VoucherNo.Equals(voucherNo)).ToList(); for (int i = 0; i < adjList.Count; i++) { if (adjList[i].ApproverId == empId) { adjList[i].ApproverComment = cmt; adjList[i].Status = "Rejected"; int adjRaiseEmpId = adjList[i].EmpId; Employee adjRaiseEmp = entities.Employees.Where(x => x.EmpId == adjRaiseEmpId).FirstOrDefault(); if (adjRaiseEmp.Role.Equals("Store Clerk")) { toId = adjRaiseEmpId; } else { toId = entities.Employees.Where(x => x.Role.Equals("Store Clerk")).FirstOrDefault().EmpId; } // for email AdjustmentVM adj = new AdjustmentVM(); adj.VoucherNo = adjList[i].VoucherNo; adj.EmpId = adjList[i].EmpId; adj.DateTimeIssued = adjList[i].DateTimeIssued; adj.ItemCode = adjList[i].ItemCode; adj.Reason = adjList[i].Reason; adj.QtyChange = adjList[i].QtyChange; adj.Status = adjList[i].Status; adj.ApproverId = (int)adjList[i].ApproverId; adj.ApproverComment = adjList[i].ApproverComment; adjListEmail.Add(adj); } } entities.SaveChanges(); int fromEmpId = empId; int toEmpId = toId; string type = "Adjustment Request"; string content = voucherNo + " has been rejected: Please review quantities"; NotificationBL.AddNewNotification(fromEmpId, toEmpId, type, content); // for email EmailBL.SendAdjApprEmail(toId, adjListEmail); return(true); } catch (Exception ex) { throw ex; } } }
// raise adjustment // done public static bool RaiseAdjustments(int empId, List <ItemVM> iList) { using (SA46Team08ADProjectContext entities = new SA46Team08ADProjectContext()) { try { // for email List <AdjustmentVM> adjList = new List <AdjustmentVM>(); string vNum = GenerateVoucherNo(); for (int i = 0; i < iList.Count; i++) { if ((iList[i].TempQtyCheck - iList[i].Balance) != 0) { Adjustment a = new Adjustment(); a.VoucherNo = vNum; a.EmpId = empId; a.DateTimeIssued = DateTime.Now; a.ItemCode = iList[i].ItemCode; a.Reason = iList[i].TempReason; a.QtyChange = (int)iList[i].TempQtyCheck - iList[i].Balance; a.Status = "Submitted"; Employee emp = new Employee(); emp = entities.Employees.Where(x => x.Role.Equals("Store Supervisor")).FirstOrDefault(); double chgBck = a.QtyChange * iList[i].Price1; if (a.QtyChange < 0) { chgBck = chgBck * -1; } if (chgBck >= 250) { emp = entities.Employees.Where(x => x.Role.Equals("Store Manager")).FirstOrDefault(); } a.ApproverId = emp.EmpId; a.ApproverComment = ""; entities.Adjustments.Add(a); entities.SaveChanges(); // for email AdjustmentVM adj = new AdjustmentVM(); adj.VoucherNo = a.VoucherNo; adj.EmpId = a.EmpId; adj.DateTimeIssued = a.DateTimeIssued; adj.ItemCode = a.ItemCode; adj.Reason = a.Reason; adj.QtyChange = a.QtyChange; adj.Status = a.Status; adj.ApproverId = (int)a.ApproverId; adj.ApproverComment = a.ApproverComment; adjList.Add(adj); int fromEmpIdA = empId; int toEmpIdA = emp.EmpId; string typeA = "Adjustment Request"; string contentA = vNum + " has been raised"; NotificationBL.AddNewNotification(fromEmpIdA, toEmpIdA, typeA, contentA); } } // for email EmailBL.SendAdjReqEmail(empId, adjList); return(true); } catch (Exception ex) { throw ex; } } }
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); }