public Models.Order CreateNewOrderWithSupplierWithFirstOrderDetail(ADProjectDb db, int empId, string supplier, int itemId) { Supplier selectedSupplier = GetSupplierByName(db, supplier); ItemCatalogue firstitem = GetItemCatalogue(db, itemId); // create new PO object with SupplierId and EmpId OrderStatus orderStatusDraft = db.OrderStatus.Where(x => x.OrderStatusId == 1).FirstOrDefault(); ADProject.Models.Order newOrder = new ADProject.Models.Order() { EmpId = empId, SupplierId = selectedSupplier.SupplierId, Supplier = selectedSupplier, OrderStatus = orderStatusDraft }; db.Order.Add(newOrder); //Need to save changes first so that the new order id will be generated db.SaveChanges(); // Get back the last added order, need its orderId newOrder = db.Order.OrderByDescending(o => o.OrderId).FirstOrDefault(); //Get the reordering qty var reorder = db.StockInfo.Where(x => x.ItemCatalogueId == itemId).FirstOrDefault().ReOrderQuantity; // Create and add the new orderdetail, qty is the default restock quantity OrderDetail firstOd = new OrderDetail() { OrderId = newOrder.OrderId, ItemId = itemId, ItemCatalogue = firstitem, OrderQuantity = reorder }; db.OrderDetail.Add(firstOd); newOrder.OrderDetails = new List <OrderDetail>(); newOrder.OrderDetails.Add(firstOd); db.SaveChanges(); return(newOrder); }
public ActionResult ViewVoucherDetail(string deleteid, string issubmit) { var db = new ADProjectDb(); AdjustmentVoucher adjustment = (AdjustmentVoucher)Session["newvoucher"]; List <AdjustmentDetail> details = (List <AdjustmentDetail>)Session["details"]; List <string> items = (List <string>)Session["des"]; if (deleteid != null) { for (int i = 0; i < details.Count; i++) { if (details[i].ItemCatalogueId.ToString() == deleteid) { details.Remove(details[i]); items.Remove(items[i]); } } } if (issubmit == "yes") { db.AdjustmentVoucher.Add(adjustment); for (int i = 0; i < details.Count(); i++) { db.AdjustmentDetail.Add(details[i]); } db.SaveChanges(); Session["detail"] = null; Session["newvoucher"] = null; return(RedirectToAction("ViewAllVouchers", "AdjustmentVoucher")); } ViewData["details"] = details; ViewData["itemdes"] = items; return(View()); }
public void AddtoAdjustmentVoucher(ADProjectDb db, int voucherId, AdjustmentDetail AD) { // Update cost of adjustmentDetail double price = (from IC in db.ItemCatalogue join SC in db.SupplierCatalogue on IC.ItemCatalogueId equals SC.ItemId where SC.SupplierRank == 1 where IC.ItemCatalogueId == AD.ItemCatalogueId select SC.ItemPrice).FirstOrDefault(); AD.Cost = AD.Quantity * price; //Add to AdjustmentDetail Database db.AdjustmentDetail.Add(AD); AdjustmentVoucher adjustmentVoucher = db.AdjustmentVoucher.Where(x => x.AdjustmentVoucherId == voucherId).FirstOrDefault(); if (adjustmentVoucher != null) { if (adjustmentVoucher.AdjustmentDetail == null) { adjustmentVoucher.AdjustmentDetail = new List <AdjustmentDetail>(); } adjustmentVoucher.AdjustmentDetail.Add(AD); } db.SaveChanges(); }
public void CreateDisbursementForApprovedRequest(ADProjectDb db, int requestId, int?collectionPointId, int quantity, int itemCatalogueId) { Employee sessionEmployee = GetEmployee(db); Disbursement disbursement = new Disbursement(); DisbursementDetail disbursementDetail = new DisbursementDetail(); CollectionPoint collectionPoint = db.CollectionPoint.Where(cp => cp.CollectionPointId == collectionPointId).SingleOrDefault(); Employee employee = sessionEmployee; DisbursementStatus disbursementStatus = db.DisbursementStatus.Where(ds => ds.Description == "PENDING").SingleOrDefault(); ItemCatalogue itemCatalogue = db.ItemCatalogue.Where(ic => ic.ItemCatalogueId == itemCatalogueId).SingleOrDefault(); Request request = db.Request.Where(r => r.RequestId == requestId).SingleOrDefault(); disbursement.CollectionPoint = collectionPoint; disbursement.Department = employee.Department; disbursement.Employee = employee; disbursement.RequestId = requestId; disbursementDetail.DisbursementStatus = disbursementStatus; disbursementDetail.DisburseQuantity = quantity; disbursementDetail.Disbursement = disbursement; disbursementDetail.ItemCatalogue = itemCatalogue; request.CollectionPoint = collectionPoint; db.Disbursement.Add(disbursement); db.DisbursementDetail.Add(disbursementDetail); db.SaveChanges(); }
public void SaveDelegation(ADProjectDb db, int delegatedEmployeeId, DateTime startDate, DateTime endDate, int assignedRoleId) { AssignRole assignRole = new AssignRole(); Employee delegatedEmployee = db.Employee .Where(emp => emp.EmployeeId == delegatedEmployeeId) .FirstOrDefault(); //One employee can only have 1 assigned role at a time if (delegatedEmployee.AssignRole != null) { DeleteDelegation(db, delegatedEmployeeId); } Employee departmentHead = GetDepartmentHead(db); assignRole.Employee = delegatedEmployee; assignRole.EmployeeId = delegatedEmployee.EmployeeId; assignRole.AssignedBy = departmentHead; assignRole.StartDate = startDate; assignRole.EndDate = endDate; assignRole.RoleId = assignedRoleId; delegatedEmployee.AssignRole = assignRole; db.SaveChanges(); }
public void UpdateCollectionPointForAllRequest(ADProjectDb db, int collectionPointId, int?employeeId = null) { int departmentId = (int)GetEmployee(db).DepartmentId; if (employeeId != null) { departmentId = (int)db.Employee .Where(emp => emp.EmployeeId == employeeId) .Select(emp => emp.DepartmentId) .FirstOrDefault(); } List <Request> requests = db.Request.Where(r => r.DepartmentId == departmentId).ToList(); CollectionPoint collectionPoint = db.CollectionPoint .Where(cp => cp.CollectionPointId == collectionPointId) .SingleOrDefault(); requests.ForEach(r => r.CollectionPoint = collectionPoint); List <Disbursement> disbursements = db.DisbursementDetail .Where(dd => dd.DisbursementStatus.Description != DisbursementStatusEnum.READY_FOR_COLLECTION.ToString()) .Select(dd => dd.Disbursement) .ToList(); disbursements.ForEach(d => d.CollectionPoint = collectionPoint); db.SaveChanges(); }
public void DeleteOrder(ADProjectDb db, int orderId) { // get the Order to delete and commit ADProject.Models.Order toDelete = db.Order.Where(x => x.OrderId == orderId).FirstOrDefault(); db.Order.Remove(toDelete); db.SaveChanges(); }
public ActionResult CreatePO(string Supplier) { int selectedSupplierId = Int32.Parse(Supplier); Order newOrder; Employee employee = Session["employee"] as Employee; // Save to database using (var db = new ADProjectDb()) { Supplier selectedSupplier = orderService.GetSupplier(db, selectedSupplierId); // create new PO object with SupplierId and EmpId OrderStatus orderStatusDraft = db.OrderStatus.Where(x => x.OrderStatusId == 1).FirstOrDefault(); newOrder = new Order() { EmpId = employee.EmployeeId, SupplierId = selectedSupplier.SupplierId, Supplier = selectedSupplier, OrderStatus = orderStatusDraft }; db.Order.Add(newOrder); db.SaveChanges(); // Get back the last added order, need its orderId newOrder = db.Order.OrderByDescending(o => o.OrderId).FirstOrDefault(); } // Redirect to the viewPO page return(RedirectToAction("ViewPO", new { orderId = newOrder.OrderId, returnController = "Inventory", returnMethod = "showLowStock" })); }
public ActionResult SaveApproval(int?itemCatalogueId, int?quantity, int?requestId, int?requestStatusId, int?collectionPointId = 1) { using (var db = new ADProjectDb()) { Request request = db.Request.Where(r => r.RequestId == requestId).SingleOrDefault(); RequestStatus requestStatus = db.RequestStatus.Where(rs => rs.RequestStatusId == requestStatusId).SingleOrDefault(); request.RequestStatus = requestStatus; db.SaveChanges(); string APPROVED = StatusEnums.RequestStatusEnum.APPROVED.ToString(); //Only if Request is approved, then create Disbursement if (requestStatus.RequestStatusDescription == APPROVED) { if (AlreadyHasDisbursement((int)requestId) == false) { departmentHeadService.CreateDisbursementForApprovedRequest(db, (int)requestId, (int)collectionPointId, (int)quantity, (int)itemCatalogueId); } } if (requestStatus.RequestStatusDescription != APPROVED) { if (AlreadyHasDisbursement((int)requestId)) { departmentHeadService.DeleteDisbursementForDisapprovedRequest(db, (int)requestId); } } return(RedirectToAction("ApproveRequest", "DepartmentHead")); } }
public void SetRequestStatusToDelivered(ADProjectDb db, int requestId) { Request request = db.Request.Where(r => r.RequestId == requestId).SingleOrDefault(); RequestStatus requestStatus = db.RequestStatus.Where(rs => rs.RequestStatusDescription == RequestStatusEnum.DELIVERED.ToString()).SingleOrDefault(); request.RequestStatus = requestStatus; db.SaveChanges(); }
public void DeleteOrderDetail(ADProjectDb db, int orderId, int itemId) { //get Orderdetail from database and delete OrderDetail toDelete = db.OrderDetail.Where(x => x.OrderId == orderId).Where(x => x.ItemId == itemId).FirstOrDefault(); db.OrderDetail.Remove(toDelete); db.SaveChanges(); }
public void UpdateCollectionPointOnlyForRequest(ADProjectDb db, int requestId, int collectionPointId) { Request targetRequest = db.Request.Where(r => r.RequestId == requestId).SingleOrDefault(); CollectionPoint collectionPoint = db.CollectionPoint.Where(cp => cp.CollectionPointId == collectionPointId).SingleOrDefault(); targetRequest.CollectionPoint = collectionPoint; db.SaveChanges(); }
public void ChangeOrderStatus(ADProjectDb db, int orderId, int orderStatusId) { Models.Order Order = db.Order.Where(x => x.OrderId == orderId).FirstOrDefault(); OrderStatus newOrderStatus = db.OrderStatus.Where(x => x.OrderStatusId == orderStatusId).FirstOrDefault(); Order.OrderStatus = newOrderStatus; db.SaveChanges(); }
public void UpdateOrderDetail(ADProjectDb db, int orderId, int itemId, int newQty) { OrderDetail Od = db.OrderDetail.Where(x => x.OrderId == orderId) .Where(x => x.ItemId == itemId) .FirstOrDefault(); Od.OrderQuantity = Od.OrderQuantity + newQty; db.SaveChanges(); }
public void UpdateOrderDetail(ADProjectDb db, int orderId, int itemId, int receivedQty) { //get Orderdetail from database and update recieved qty OrderDetail toUpdateOD = db.OrderDetail.Where(x => x.OrderId == orderId).Where(x => x.ItemId == itemId).FirstOrDefault(); toUpdateOD.ReceiveQuantity = receivedQty; toUpdateOD.ActDelDate = DateTime.Now; db.SaveChanges(); }
public void DeleteRequest(ADProjectDb db, int requestId) { Request request = db.Request .Where(r => r.RequestId == requestId) .SingleOrDefault(); db.Request.Remove(request); db.SaveChanges(); }
public void DeleteDisbursementForDisapprovedRequest(ADProjectDb db, int requestId) { Disbursement disbursement = db.DisbursementDetail .Where(dd => dd.Disbursement.RequestId == requestId) .Select(dd => dd.Disbursement) .FirstOrDefault(); db.Disbursement.Remove(disbursement); db.SaveChanges(); }
public void CreateEmptyVoucher(ADProjectDb db, int empId) { Employee employee = db.Employee.Where(x => x.EmployeeId == empId).FirstOrDefault(); AdjustmentVoucher newEntry = new AdjustmentVoucher() { RaisedByEmployee = employee, AdjustmentStatusId = 1 }; db.AdjustmentVoucher.Add(newEntry); db.SaveChanges(); }
public ActionResult submitVoucher(int VoucherId) { using (var db = new ADProjectDb()) { // Get adjustment voucher AdjustmentVoucher Voucher = adjustmentVoucherServices.GetOrder(db, VoucherId); Voucher.AdjustmentStatus = db.AdjustmentStatus.Where(x => x.AdjustmentStatusId == 4).FirstOrDefault(); Voucher.RaiseDate = DateTime.Today; db.SaveChanges(); return(Redirect("ViewAllVouchers")); } }
public void UpdateOrderStatus(ADProjectDb db, int orderId) { //If all the OD in the order has accepted date, then update order status to delivered. List <OrderDetail> ODList = db.OrderDetail.Where(x => x.OrderId == orderId).ToList(); List <OrderDetail> Outstanding = ODList.Where(x => x.ActDelDate == null).ToList(); if (Outstanding.Count == 0) { Models.Order order = db.Order.Where(x => x.OrderId == orderId).FirstOrDefault(); order.OrderStatus = db.OrderStatus.Where(x => x.OrderStatusId == 4).FirstOrDefault(); db.SaveChanges(); } }
public void SaveDisbursement(ADProjectDb db, int?disburseQuantity, int?recipientDisbursementDetailId, int?transferorDisbursementDetailId) { DisbursementDetail transferorDD = db.DisbursementDetail .Where(dd => dd.DisbursementDetailId == transferorDisbursementDetailId) .SingleOrDefault(); DisbursementDetail recipientDD = db.DisbursementDetail .Where(dd => dd.DisbursementDetailId == recipientDisbursementDetailId) .SingleOrDefault(); transferorDD.DisburseQuantity -= (int)disburseQuantity; recipientDD.DisburseQuantity += (int)disburseQuantity; db.SaveChanges(); }
public void UpdateDisbursementForApprovedRequest(ADProjectDb db, int requestId, int collectionPointId) { Disbursement disbursement = db.DisbursementDetail .Where(dd => dd.Disbursement.RequestId == requestId) .Select(dd => dd.Disbursement) .FirstOrDefault(); Request request = db.Request.Where(r => r.RequestId == requestId).SingleOrDefault(); CollectionPoint collectionPoint = db.CollectionPoint.Where(cp => cp.CollectionPointId == collectionPointId).SingleOrDefault(); request.CollectionPoint = collectionPoint; disbursement.CollectionPoint = collectionPoint; db.SaveChanges(); }
public void SaveStatus(ADProjectDb db, int disbursementStatusId, int?disbursementDetailId, int?disburseQuantity = null) { DisbursementDetail disbursementDetail = db.DisbursementDetail .Where(dd => dd.DisbursementDetailId == disbursementDetailId) .SingleOrDefault(); DisbursementStatus disbursementStatus = db.DisbursementStatus .Where(ds => ds.DisbursementStatusId == disbursementStatusId) .SingleOrDefault(); disbursementDetail.DisbursementStatus = disbursementStatus; if (disburseQuantity != null) { disbursementDetail.DisburseQuantity = (int)disburseQuantity; } db.SaveChanges(); }
public void UpdateStockCardStockInfo(ADProjectDb db, int itemId, int receivedQty, string supplierName) { StockCard toAddSC = new StockCard() { ItemCatalogueId = itemId, ChangeDate = DateTime.Now, ChangeDescription = "Supplier - " + supplierName, ChangeQuantity = receivedQty }; //Add new stockCard entry db.stockCard.Add(toAddSC); //get Stockinfo from database and update stock Qty StockInfo toUpdateSI = db.StockInfo.Where(x => x.ItemCatalogueId == itemId).FirstOrDefault(); toUpdateSI.StockQuantity = toUpdateSI.StockQuantity + receivedQty; db.SaveChanges(); }
public void DeleteDelegation(ADProjectDb db, int employeeId) { AssignRole assignRole = db.Employee .Where(emp => emp.EmployeeId == employeeId) .Select(emp => emp.AssignRole) .SingleOrDefault(); Employee employee = db.Employee .Where(emp => emp.EmployeeId == employeeId) .SingleOrDefault(); employee.AssignRole = null; db.AssignRole.Remove(assignRole); db.SaveChanges(); }
public void SaveRequest(ADProjectDb db, int itemCatalogueId, int quantity, bool?isUpdate, int?requestId) { using (db) { Employee employee = GetEmployee(db); RequestStatus requestStatus = db.RequestStatus.Where(rs => rs.RequestStatusDescription == StatusEnums.RequestStatusEnum.PENDING.ToString()).SingleOrDefault(); ItemCatalogue itemCatalogue = db.ItemCatalogue.Where(ic => ic.ItemCatalogueId == itemCatalogueId).SingleOrDefault(); Request request = new Request(); RequestDetail requestDetail = new RequestDetail(); //if update instead of create... isUpdate = (isUpdate == null ? false : isUpdate); if ((bool)isUpdate) { request = db.Request.Where(r => r.RequestId == requestId).SingleOrDefault(); requestDetail = db.RequestDetail.Where(rd => rd.Request.RequestId == requestId).SingleOrDefault(); } request.Department = employee.Department; request.RaisedByEmployee = employee; request.RequestDate = DateTime.Today; request.RequestStatus = requestStatus; RepresentativeService representativeService = new RepresentativeService(); CollectionPoint collectionPoint = representativeService.GetLatestCollectionPoint(db); request.CollectionPoint = collectionPoint; requestDetail.ItemCatalogue = itemCatalogue; requestDetail.Quantity = quantity; requestDetail.Request = request; if (isUpdate == false) { db.Request.Add(request); db.RequestDetail.Add(requestDetail); } db.SaveChanges(); Request lastestAddedRequest = db.Request.OrderByDescending(r => r.RequestId).FirstOrDefault(); } }
public void UpdateAdjDetails(ADProjectDb db, int itemId, int voucherid, int AdjQty, string VoucherReason) { AdjustmentDetail Ad = db.AdjustmentDetail.Where(x => x.AdjustmentVoucherId == voucherid) .Where(x => x.ItemCatalogueId == itemId) .FirstOrDefault(); Ad.Quantity = Ad.Quantity + AdjQty; double price = (from IC in db.ItemCatalogue join SC in db.SupplierCatalogue on IC.ItemCatalogueId equals SC.ItemId where SC.SupplierRank == 1 where IC.ItemCatalogueId == itemId select SC.ItemPrice).FirstOrDefault(); Ad.Cost = Ad.Quantity * price; Ad.Reason = VoucherReason; db.SaveChanges(); }
public void SaveOrderDetail(ADProjectDb db, int?orderQty, DateTime?expectedDelDate, int orderId, int itemId) { //get Orderdetail from database OrderDetail orderDetail = db.OrderDetail.Where(x => x.OrderId == orderId).Where(x => x.ItemId == itemId).FirstOrDefault(); // Now update qty and date if (orderQty != null) { orderDetail.OrderQuantity = orderQty.Value; } if (expectedDelDate != null) { orderDetail.ExpDelDate = expectedDelDate.Value; } db.SaveChanges(); }
protected void ReduceQuantity(ADProjectDb db, int disbursementDetailId, int disbursementStatusId) { DisbursementStatus disbursementStatus = db.DisbursementStatus .Where(ds => ds.DisbursementStatusId == disbursementStatusId) .SingleOrDefault(); if (disbursementStatus.Description != StatusEnums.DisbursementStatusEnum.COLLECTED.ToString()) { return; } DisbursementDetail disbursementDetail = db.DisbursementDetail .Where(dd => dd.DisbursementDetailId == disbursementDetailId) .SingleOrDefault(); StockInfo stockInfo = db.StockInfo .Where(stock => stock.ItemCatalogueId == disbursementDetail.ItemCatalogueId) .SingleOrDefault(); stockInfo.StockQuantity -= disbursementDetail.DisburseQuantity; db.SaveChanges(); }
public void AddOrderDetailtoOrder(ADProjectDb db, int orderId, int itemId, int orderQty) { //Create Orderdetail object OrderDetail toAdd = new OrderDetail() { OrderId = orderId, ItemId = itemId, OrderQuantity = orderQty }; db.OrderDetail.Add(toAdd); //Get that order and add orderdetail to it ADProject.Models.Order orderToAddto = db.Order.Where(x => x.OrderId == orderId).FirstOrDefault(); if (orderToAddto != null) { if (orderToAddto.OrderDetails == null) { orderToAddto.OrderDetails = new List <OrderDetail>(); } orderToAddto.OrderDetails.Add(toAdd); } db.SaveChanges(); }