public static UserModel AssignDepRep(int id) { LUSSISEntities entities = new LUSSISEntities(); user um = entities.users.Where(p => p.userid == id).First <user>(); user um1 = entities.users.Where(p => p.deptid == um.deptid && p.role == ConUser.Role.DEPARTMENTREP).First <user>(); um1.role = ConUser.Role.EMPLOYEEREP; um.role = ConUser.Role.DEPARTMENTREP; entities.SaveChanges(); UserModel umm = CovertDBUsertoAPIUser(um); NotificationModel nom = new NotificationModel(); nom.Deptid = um.deptid; nom.Role = ConUser.Role.DEPARTMENTREP; nom.Title = "Department Representative"; nom.NotiType = ConNotification.NotiType.DeptRepAssigned; nom.ResID = um.userid; nom.Remark = um.fullname + " has been assigned as a Department Representative!"; nom = NotificationRepo.CreatNotification(nom, out string error); nom.Deptid = um.deptid; nom.Role = ConUser.Role.EMPLOYEEREP; nom.Title = "Department Representative"; nom.NotiType = ConNotification.NotiType.DeptRepAssigned; nom.ResID = um.userid; nom.Remark = um.fullname + " has been assigned as a Department Representative!"; nom = NotificationRepo.CreatNotification(nom, out error); return(umm); }
// To change the status from pending to complete public static RequisitionWithOutstandingModel Complete (RequisitionWithOutstandingModel ordm, out string error) { LUSSISEntities entities = new LUSSISEntities(); error = ""; outstandingrequisition req = new outstandingrequisition(); RequisitionWithOutstandingModel reqoutm = new RequisitionWithOutstandingModel(); List <RequisitionDetailsWithOutstandingModel> reqdm = new List <RequisitionDetailsWithOutstandingModel>(); try { // finding the db object using API model req = entities.outstandingrequisitions .Where(x => x.requisition.reqid == ordm.Reqid) .FirstOrDefault(); if (req.requisition.status == ConRequisition.Status.OUTSTANDINGREQUISITION || req.status == ConOutstandingsRequisition.Status.DELIVERED) { req.status = ConOutstandingsRequisition.Status.COMPLETE; req.requisition.status = ConRequisition.Status.COMPLETED; entities.SaveChanges(); foreach (outstandingrequisitiondetail rqdm in req.outstandingrequisitiondetails) { reqdm.Add(new RequisitionDetailsWithOutstandingModel(req.reqid, rqdm.itemid, rqdm.item.description, rqdm.qty, rqdm.item.category.name, rqdm.item.uom, rqdm.qty)); } reqoutm = new RequisitionWithOutstandingModel(req.reqid, req.requisition.raisedby, req.requisition.user.fullname , req.requisition.approvedby, req.requisition.user1.fullname, req.requisition.cpid, req.requisition.collectionpoint.cpname , req.requisition.deptid, req.requisition.department.deptname, req.status, req.requisition.reqdate, 999, "Z" + req.requisition.deptid, reqdm); NotificationModel nom = new NotificationModel(); nom.Datetime = DateTime.Now; nom.Deptid = 11; nom.Remark = "The Outstanding Items with Requisition ID (" + req.reqid + ") is now collected"; nom.Role = ConUser.Role.CLERK; nom.Title = "Outstanding Items Collected"; nom.NotiType = ConNotification.NotiType.OutstandingItemsCollected; nom.ResID = req.reqid; nom = NotificationRepo.CreatNotification(nom, out error); } else { error = "Status not Outstanding"; reqoutm = new RequisitionWithOutstandingModel(); } } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(reqoutm); }
//Create new Requisition with Detials public static RequisitionModel CreateRequisitionwithDetails(RequisitionModel reqm, List <RequisitionDetailsModel> reqd, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); requisition req = new requisition(); List <requisitiondetail> reqlist = new List <requisitiondetail>(); try { req.reqid = reqm.Reqid; req.raisedby = reqm.Raisedby; req.approvedby = reqm.Approvedby; req.deptid = reqm.Depid; req.cpid = reqm.Cpid; req.status = ConRequisition.Status.PENDING; req.reqdate = DateTime.Now; req = entities.requisitions.Add(req); entities.SaveChanges(); foreach (RequisitionDetailsModel rdm in reqd) { requisitiondetail rqd = new requisitiondetail { reqid = req.reqid, itemid = rdm.Itemid, qty = rdm.Qty }; rqd = entities.requisitiondetails.Add(rqd); entities.SaveChanges(); reqlist.Add(rqd); } reqm = GetRequisitionByRequisitionId(req.reqid, out error); NotificationModel nom = new NotificationModel(); nom.Deptid = DepartmentRepo.GetDepartmentByUserid(reqm.Raisedby ?? default(int), out error).Deptid; nom.Role = ConUser.Role.HOD; nom.Title = "Requisition Approval"; nom.NotiType = ConNotification.NotiType.RequisitionApproval; nom.ResID = reqm.Reqid; nom.Remark = "A new requisition has been raised by " + reqm.Rasiedbyname + "!"; nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(reqm); }
//cancel delegation public static DelegationModel CancelDelegation(DelegationModel dm, out String error) { error = ""; // declare and initialize new LUSSISEntities to perform update LUSSISEntities entities = new LUSSISEntities(); delegation d = new delegation(); try { // finding the delegation object using delegation API model d = entities.delegations.Where(p => p.delid == dm.Delid).First <delegation>(); d.active = ConDelegation.Active.INACTIVE; // saving the update entities.SaveChanges(); UserRepo.Canceldelegateuser(dm.Userid); // return the updated model dm = GetDelegationByDelegationID(d.delid, out error); user us = entities.users.Where(p => p.userid == dm.Userid).FirstOrDefault(); NotificationModel nom = new NotificationModel(); nom.Deptid = us.deptid; nom.Role = ConUser.Role.EMPLOYEEREP; nom.Title = "Authority Cancellation"; nom.NotiType = ConNotification.NotiType.DelegationAssigned; nom.ResID = dm.Userid; nom.Remark = us.fullname + " has been removed as a Temp Head of Department!"; nom = NotificationRepo.CreatNotification(nom, out error); nom.Deptid = us.deptid; nom.Role = ConUser.Role.TEMPHOD; nom.Title = "Authority Cancellation"; nom.NotiType = ConNotification.NotiType.DelegationAssigned; nom.ResID = dm.Userid; nom.Remark = us.fullname + " has been removed as a Temp Head of Department!"; nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(dm); }
public static DepartmentCollectionPointModel UpdateDepartmentCollectionPoint(DepartmentCollectionPointModel dcpm, out string error) { error = ""; // declare and initialize new LUSSISEntities to perform update LUSSISEntities entities = new LUSSISEntities(); departmentcollectionpoint dcp = new departmentcollectionpoint(); try { dcp = entities.departmentcollectionpoints.Where(p => p.deptcpid == dcpm.DeptCpID).FirstOrDefault <departmentcollectionpoint>(); dcp.deptid = dcpm.DeptID; dcp.cpid = dcpm.CpID; dcp.status = dcpm.Status; // saving the update entities.SaveChanges(); // return the updated model dcpm = GetDepartmentCollectionPointByDcpID(dcp.deptcpid, out error); if (dcpm.Status == ConDepartmentCollectionPoint.Status.ACTIVE) { NotificationModel nom = new NotificationModel(); nom.Deptid = dcpm.DeptID; nom.Role = ConUser.Role.HOD; nom.Title = "Approved Collection Point"; nom.NotiType = ConNotification.NotiType.ClerkApprovedCollectionPointChange; nom.ResID = dcpm.DeptCpID; nom.Remark = "The new collection point change request has been approved by the store"; nom = NotificationRepo.CreatNotification(nom, out error); } else if (dcpm.Status == ConDepartmentCollectionPoint.Status.REJECTED) { NotificationModel nom = new NotificationModel(); nom.Deptid = dcpm.DeptID; nom.Role = ConUser.Role.HOD; nom.Title = "Rejected Collection Point"; nom.NotiType = ConNotification.NotiType.ClerkRejectedCollectionPointChange; nom.ResID = dcpm.DeptCpID; nom.Remark = "The new collection point change request has been rejected by the store"; nom = NotificationRepo.CreatNotification(nom, out error); } } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(dcpm); }
//create the requisition public static RequisitionModel CreateRequisition(RequisitionModel req, out string error) { error = ""; bool RaisedByTempHOD = true; LUSSISEntities entities = new LUSSISEntities(); requisition reqn = new requisition(); try { reqn.raisedby = req.Raisedby; reqn.approvedby = req.Approvedby; if (req.Approvedby == null || req.Approvedby == 0) { reqn.approvedby = req.Raisedby; RaisedByTempHOD = false; } reqn.deptid = req.Depid; reqn.cpid = req.Cpid; reqn.status = ConRequisition.Status.PENDING; reqn.reqdate = DateTime.Now; reqn = entities.requisitions.Add(reqn); entities.SaveChanges(); req = GetRequisitionByRequisitionId(reqn.reqid, out error); if (!RaisedByTempHOD) { NotificationModel nom = new NotificationModel(); nom.Deptid = DepartmentRepo.GetDepartmentByUserid(reqn.raisedby ?? default(int), out error).Deptid; nom.Role = ConUser.Role.HOD; nom.Title = "Requisition Approval"; nom.NotiType = ConNotification.NotiType.RequisitionApproval; nom.ResID = reqn.reqid; nom.Remark = "A new requisition has been raised by " + req.Rasiedbyname + "!"; nom = NotificationRepo.CreatNotification(nom, out error); } else { req.Status = ConRequisition.Status.APPROVED; req = UpdateRequisition(req, out error); } } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(req); }
public static DepartmentCollectionPointModel AddDepartmentCollectionPoint(DepartmentCollectionPointModel dcpm, out string error) { error = ""; // declare and initialize new LUSSISEntities to perform update LUSSISEntities entities = new LUSSISEntities(); try { departmentcollectionpoint dcp = new departmentcollectionpoint { deptid = dcpm.DeptID, cpid = dcpm.CpID, status = dcpm.Status }; entities.departmentcollectionpoints.Add(dcp); // saving the update entities.SaveChanges(); // return the updated model dcpm = GetDepartmentCollectionPointByDcpID(dcp.deptcpid, out error); NotificationModel nom = new NotificationModel(); nom.Deptid = 11; nom.Role = ConUser.Role.CLERK; nom.Title = "Collection Point Request"; nom.NotiType = ConNotification.NotiType.CollectionPointChangeRequestApproval; nom.ResID = dcpm.DeptCpID; nom.Remark = "The new collection point change has been requested!"; nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(dcpm); }
//create delegation public static DelegationModel CreateDelegation(DelegationModel dele, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); delegation d = new delegation(); DelegationModel ndel = new DelegationModel(); try { DepartmentModel dep = DepartmentRepo.GetDepartmentByUserid(dele.Userid, out error); List <UserModel> userlist = UserRepo.GetUserByDeptid(dep.Deptid, out error); foreach (UserModel u in userlist) { List <DelegationModel> delelist = GetDelegationByUserId(u.Userid, out error); foreach (DelegationModel deleg in delelist) { delegation del = entities.delegations.Where(p => p.delid == deleg.Delid).FirstOrDefault <delegation>(); del.active = ConDelegation.Active.INACTIVE; if (u.Role != ConUser.Role.DEPARTMENTREP) { UserRepo.Canceldelegateuser(u.Userid); } entities.SaveChanges(); } } d.startdate = dele.Startdate; d.enddate = dele.Enddate; d.userid = dele.Userid; d.active = ConDelegation.Active.ACTIVE; d.assignedby = dele.AssignedbyId; d = entities.delegations.Add(d); entities.SaveChanges(); dele = GetDelegationByDelegationID(d.delid, out error); user us = entities.users.Where(p => p.userid == dele.Userid).FirstOrDefault(); NotificationModel nom = new NotificationModel(); nom.Deptid = us.deptid; nom.Role = ConUser.Role.TEMPHOD; nom.Title = "New Authority"; nom.NotiType = ConNotification.NotiType.DelegationAssigned; nom.ResID = dele.Userid; nom.Remark = us.fullname + " has been assigned as a Temp HOD from " + dele.Startdate.Value.ToShortDateString() + " to " + dele.Enddate.Value.ToShortDateString(); nom = NotificationRepo.CreatNotification(nom, out error); nom.Deptid = us.deptid; nom.Role = ConUser.Role.EMPLOYEEREP; nom.Title = "New Authority"; nom.NotiType = ConNotification.NotiType.DelegationAssigned; nom.ResID = dele.Userid; nom.Remark = us.fullname + " has been assigned as a Temp HOD from " + dele.Startdate.Value.ToShortDateString() + " to " + dele.Enddate.Value.ToShortDateString(); nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(dele); }
// update the Requisition public static RequisitionModel UpdateRequisition(RequisitionModel reqm, out string error) { error = ""; // declare and initialize new LUSSISEntities to perform update LUSSISEntities entities = new LUSSISEntities(); requisition req = new requisition(); try { // finding the inventory object using Inventory API model req = entities.requisitions.Where(p => p.reqid == reqm.Reqid).First <requisition>(); // transfering data from API model to DB Model req.reqid = reqm.Reqid; req.raisedby = reqm.Raisedby; req.approvedby = reqm.Approvedby; req.deptid = reqm.Depid; req.status = reqm.Status; // saving the update entities.SaveChanges(); if (req.status == ConRequisition.Status.DELIVERED) { NotificationModel nom = new NotificationModel(); nom.Deptid = reqm.Depid; nom.Role = ConUser.Role.DEPARTMENTREP; nom.Title = "Ready to Collect"; nom.NotiType = ConNotification.NotiType.DeliveredRequisition; nom.ResID = reqm.Reqid; nom.Remark = "Requisition is now ready to collect"; nom = NotificationRepo.CreatNotification(nom, out error); } else if (req.status == ConRequisition.Status.APPROVED) { NotificationModel nom = new NotificationModel(); nom.Deptid = reqm.Depid; nom.Role = ConUser.Role.EMPLOYEEREP; nom.Title = "HOD Requisition"; nom.NotiType = ConNotification.NotiType.HODApprovedRequistion; nom.ResID = reqm.Reqid; nom.Remark = "The new requisition has been approved by Head of Department"; nom = NotificationRepo.CreatNotification(nom, out error); nom.Deptid = reqm.Depid; nom.Role = ConUser.Role.DEPARTMENTREP; nom.Title = "HOD Requisition"; nom.NotiType = ConNotification.NotiType.HODApprovedRequistion; nom.ResID = reqm.Reqid; nom.Remark = "The new requisition has been approved by Head of Department"; nom = NotificationRepo.CreatNotification(nom, out error); nom.Deptid = 11; nom.Role = ConUser.Role.CLERK; nom.Title = "New Requisition"; nom.NotiType = ConNotification.NotiType.HODApprovedRequistion; nom.ResID = reqm.Reqid; nom.Remark = "The new requisition has been rasied by " + reqm.Depname; nom = NotificationRepo.CreatNotification(nom, out error); } else if (req.status == ConRequisition.Status.REQUESTPENDING) { NotificationModel nom = new NotificationModel(); nom.Deptid = reqm.Depid; nom.Role = ConUser.Role.HOD; nom.Title = "Approved Requisition"; nom.NotiType = ConNotification.NotiType.ClerkApprovedRequisiton; nom.ResID = reqm.Reqid; nom.Remark = "The new requisition has been approved by the store"; nom = NotificationRepo.CreatNotification(nom, out error); nom.Deptid = reqm.Depid; nom.Role = ConUser.Role.TEMPHOD; nom.Title = "Approved Requisition"; nom.NotiType = ConNotification.NotiType.ClerkApprovedRequisiton; nom.ResID = reqm.Reqid; nom.Remark = "The new requisition has been approved by the store"; nom = NotificationRepo.CreatNotification(nom, out error); } else if (req.status == ConRequisition.Status.COMPLETED || req.status == ConRequisition.Status.OUTSTANDINGREQUISITION) { NotificationModel nom = new NotificationModel(); nom.Deptid = 11; nom.Role = ConUser.Role.CLERK; nom.Title = "Items Collected"; nom.NotiType = ConNotification.NotiType.CollectedRequistion; nom.ResID = reqm.Reqid; nom.Remark = "The Items in Requisiton has been collected by Department Rep!"; nom = NotificationRepo.CreatNotification(nom, out error); } // return the updated model reqm = CovertDBRequisitiontoAPIRequisition(req); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(reqm); }
//Update Adjustment public static AdjustmentModel UpdateAdjustment(AdjustmentModel adjm, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); NotificationModel nom = new NotificationModel(); adjustment adj = new adjustment(); try { adj = entities.adjustments.Where(a => a.adjid == adjm.Adjid).First <adjustment>(); adj.raisedby = adjm.Raisedby; adj.raisedto = adjm.Raisedto; adj.issueddate = adjm.Issueddate; adj.status = adjm.Status; nom.Remark = "The Adjustment Voucher has been Rejected!"; if (adj.status == ConAdjustment.Active.APPROVED) { nom.Remark = "The Adjustment Voucher has been Approved!"; } List <AdjustmentDetailModel> adjustds = AdjustmentDetailRepo.GetAdjustmentDetailByAdjID(adj.adjid, out error); foreach (AdjustmentDetailModel adjustd in adjustds) { InventoryModel inventm = InventoryRepo.GetInventoryByItemid(adjustd.Itemid, out error); inventory invent = entities.inventories.Where(i => i.invid == inventm.Invid).First <inventory>(); invent.stock += adjustd.Adjustedqty; InventoryTransactionModel invtm = new InventoryTransactionModel(); invtm.InvID = invent.invid; invtm.ItemID = invent.itemid; invtm.Qty = adjustd.Adjustedqty; invtm.TransType = ConInventoryTransaction.TransType.ADJUSTMENT; invtm.TransDate = DateTime.Now; invtm.Remark = adjustd.Reason; invtm = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error); } entities.SaveChanges(); adjm = GetAdjustmentByID(adj.adjid, out error); nom.Deptid = DepartmentRepo.GetDepartmentByUserid(adj.raisedto ?? default(int), out error).Deptid; nom.Role = UserRepo.GetUserByUserID(adj.raisedby ?? default(int)).Role; nom.Title = "Adjustment Approval"; nom.NotiType = ConNotification.NotiType.Adjustment; nom.ResID = adj.adjid; nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(adjm); }
//Create new Adjustment public static AdjustmentModel CreateAdjustment(AdjustmentModel adjm, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); adjustment adj = new adjustment(); try { adj.raisedby = adjm.Raisedby; adj.issueddate = adjm.Issueddate; adj.status = ConAdjustment.Active.PENDING; List <AdjustmentDetailModel> adjds = adjm.Adjds; //check item price foreach (AdjustmentDetailModel adjd in adjds) { adj.raisedto = 0; SupplierItemModel supp = SupplierItemRepo.GetSupplierItemByItemId(adjd.Itemid, out error); double? price = Math.Abs((Int32)adjd.Adjustedqty) * supp.Price; //Check total price of each item to consider who to report to if (price >= ConAdjustment.Active.REPORTMANAGER) { user user = entities.users.Where(u => u.role == ConUser.Role.MANAGER).First(); adj.raisedto = user.userid; } else { user user = entities.users.Where(u => u.role == ConUser.Role.SUPERVISOR).First(); adj.raisedto = user.userid; } } adj = entities.adjustments.Add(adj); entities.SaveChanges(); foreach (AdjustmentDetailModel adjdm in adjds) { adjustmentdetail adjd = new adjustmentdetail { adjid = adj.adjid, itemid = adjdm.Itemid, adjustedqty = adjdm.Adjustedqty, reason = adjdm.Reason }; adjd = entities.adjustmentdetails.Add(adjd); entities.SaveChanges(); } adjm = GetAdjustmentByID(adj.adjid, out error); NotificationModel nom = new NotificationModel(); nom.Deptid = DepartmentRepo.GetDepartmentByUserid(adj.raisedto ?? default(int), out error).Deptid; nom.Role = UserRepo.GetUserByUserID(adj.raisedto ?? default(int)).Role; nom.Title = "New Adjustment"; nom.NotiType = ConNotification.NotiType.Adjustment; nom.ResID = adj.adjid; nom.Remark = "A new adjustment has been raised by clerk!"; nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(adjm); }