public void CreatePurchaseOrder(string userId, string supplierId) { List <PurchaseCart> cartList = dbcontext.purchaseCarts.Where(x => x.EmployeeId == userId).ToList(); Employee emp = deptService.findEmployeeById(userId); PurchaseOrder newPurchaseOrder = new PurchaseOrder(); newPurchaseOrder.Id = Guid.NewGuid().ToString(); newPurchaseOrder.EmployeeId = emp.Id; newPurchaseOrder.Employee = emp; newPurchaseOrder.status = POStatus.PENDING; newPurchaseOrder.date = DateTime.Now; newPurchaseOrder.SupplierId = supplierId; foreach (var i in cartList) { Inventory inv = dbcontext.inventories.Where(x => x.Id == i.Id).FirstOrDefault(); PurchaseOrderDetails purchaseOrderDetail = new PurchaseOrderDetails(); purchaseOrderDetail.Id = Guid.NewGuid().ToString(); purchaseOrderDetail.PurchaseOrderId = newPurchaseOrder.Id; purchaseOrderDetail.Inventory = i.Inventory; purchaseOrderDetail.InventoryId = i.InventoryId; purchaseOrderDetail.quantity = i.Qty; dbcontext.Add(purchaseOrderDetail); } dbcontext.Add(newPurchaseOrder); dbcontext.purchaseCarts.RemoveRange(cartList); dbcontext.SaveChanges(); }
public void CreateRequisition(string userId) { List <EmployeeCart> cartList = dbcontext.employeeCarts.Where(x => x.EmployeeId == userId).ToList(); Employee emp = deptService.findEmployeeById(userId); Requisition newRequisition = new Requisition(emp.Departments.DeptCode); newRequisition.status = ReqStatus.AWAITING_APPROVAL; Employee approver = deptService.setApprover(userId); newRequisition.ApprovedEmployee = approver; newRequisition.ApprovedEmployeeId = approver.Id; newRequisition.Employee = emp; newRequisition.EmployeeId = emp.Id; newRequisition.DepartmentId = emp.Departments.Id; foreach (var i in cartList) { /* Inventory inv = dbcontext.inventories.Where(x => x.Id == i.Id).FirstOrDefault();*/ RequisitionDetail requisitionDetail = new RequisitionDetail(); requisitionDetail.Id = Guid.NewGuid().ToString(); requisitionDetail.RequisitionId = newRequisition.Id; requisitionDetail.Inventory = i.Inventory; requisitionDetail.RequestedQty = i.Qty; dbcontext.Add(requisitionDetail); } dbcontext.Add(newRequisition); dbcontext.employeeCarts.RemoveRange(cartList); dbcontext.SaveChanges(); notificationService.sendNotification(NotificationType.REQUISITION, newRequisition, null, null); }
public void saveRequisitionsAsDisbursement(string userId, Dictionary <Departments, List <RequisitionDetail> > requisitionsForDepartment) { Employee employee = deptService.findEmployeeById(userId); foreach (var dept in requisitionsForDepartment) { //Create new disbursement Disbursement d = new Disbursement(); d.Id = Guid.NewGuid().ToString(); d.GeneratedDate = DateTime.Now; d.CollectionDate = DateTime.Now.AddDays(1); d.Departments = dept.Key; d.storeClerk = employee; d.DepartmentsId = dept.Key.Id; d.status = DisbusementStatus.PENDING; dbcontext.Add(d); dbcontext.SaveChanges(); //In each new disbursement, create new disbursement foreach (var req in dept.Value) { DisbursementDetail ddetail = new DisbursementDetail(); ddetail.Id = Guid.NewGuid().ToString(); ddetail.DisbursementId = d.Id; ddetail.Disbursement = d; ddetail.RequisitionDetail = req; ddetail.disbursedQty = req.DistributedQty; dbcontext.Add(ddetail); dbcontext.SaveChanges(); } } }