public static void InsertCustomer(Catalogue c) { using (Team10ADModel m = new Team10ADModel()) { m.Catalogues.Add(c); m.SaveChanges(); } }
public static void UpdateCustomer(Catalogue c) { using (Team10ADModel m = new Team10ADModel()) { m.Entry(c).State = System.Data.Entity.EntityState.Modified; m.SaveChanges(); } }
public static void CancelRequisition(int reqid) { using (Team10ADModel context = new Team10ADModel()) { Model.Requisition req = context.Requisitions.Where(x => x.RequisitionID == reqid).First(); req.Status = "Cancelled"; context.SaveChanges(); } }
public static void UpdateRep(Employee r) { using (Team10ADModel m = new Team10ADModel()) { var query = (from s in m.Departments where s.RepresentativeID == r.EmployeeID select s).ToList()[0]; m.Entry(query).State = System.Data.Entity.EntityState.Modified; m.SaveChanges(); } }
public void SelectCollection(string pointID, int employeeid) { string departmentCode = tm.Employees.Where(x => x.EmployeeID == employeeid).Select(dc => dc.DepartmentCode).First(); Department department = tm.Departments.Where(x => x.DepartmentCode == departmentCode).First(); department.PointID = Int32.Parse(pointID); department.RepresentativeID = employeeid; tm.SaveChanges(); }
//////Voucher public static void InsertVoucher(List <StockAdjustmentVoucherDetail> detailList, int storeStaffID) { using (Team10ADModel m = new Team10ADModel()) { StockAdjustmentVoucher voucher = new StockAdjustmentVoucher(); voucher.StoreStaffID = storeStaffID; voucher.DateIssue = DateTime.Now; voucher.Status = "Pending"; m.StockAdjustmentVouchers.Add(voucher); m.SaveChanges(); foreach (StockAdjustmentVoucherDetail detail in detailList) { detail.VoucherID = voucher.VoucherID; m.StockAdjustmentVoucherDetails.Add(detail); m.SaveChanges(); } } }
public static void UpdateCatalogues(List <Catalogue> clist) { using (Team10ADModel m = new Team10ADModel()) { foreach (Catalogue c in clist) { m.Entry(c).State = System.Data.Entity.EntityState.Modified; } m.SaveChanges(); } }
public static void ReqStatusProcessing(ArrayList reqIdList) { using (Team10ADModel context = new Team10ADModel()) { foreach (int id in reqIdList) { Requisition r = context.Requisitions.Where(x => x.RequisitionID == id).First(); r.Status = "Processing"; context.SaveChanges(); } } }
public static string UpdateRetrievalDetails(List <RetrievalDetail> b) { using (Team10ADModel m = new Team10ADModel()) { foreach (RetrievalDetail r in b) { m.Entry(r).State = System.Data.Entity.EntityState.Modified; } m.SaveChanges(); } return("xiiiii"); }
/////////////////////////////////Requisition public static void UpdateReqStatus(Requisition req) { using (Team10ADModel context = new Team10ADModel()) { Requisition updateReq = context.Requisitions.Where(x => x.RequisitionID == req.RequisitionID).First(); updateReq.RequestorID = req.RequestorID; updateReq.ApprovalDate = DateTime.Now; updateReq.Status = req.Status; updateReq.Remarks = req.Remarks; context.SaveChanges(); } }
public static void rejectRequisition(int requisitionId, string remarks) { using (Team10ADModel entities = new Team10ADModel()) { Requisition req = entities.Requisitions.Where(p => p.RequisitionID == requisitionId).SingleOrDefault(); req.Status = "Rejected"; req.Remarks = remarks; entities.SaveChanges(); } //Send email LogicUtility.Instance.SendRequisitionResponseEmail(requisitionId, remarks, "REJECTED"); }
protected void AcknowledgeButton_Click(object sender, EventArgs e) { Team10ADModel context = new Team10ADModel(); int voucherid = Convert.ToInt32(VouchderIdBox.Text); StockAdjustmentVoucher voucher = context.StockAdjustmentVouchers.Where(v => v.VoucherID == voucherid).First(); voucher.ApproverID = (int)Session["clerkid"]; voucher.DateApproved = DateTime.Now; voucher.Status = "Approved"; context.SaveChanges(); Response.Redirect("AdjustmentVoucherList.aspx"); }
public static void approveRequisition(int requisitionId, string remarks, string approverID) { //DateTime approvalDate = new DateTime(); using (Team10ADModel entities = new Team10ADModel()) { Requisition req = entities.Requisitions.Where(p => p.RequisitionID == requisitionId).SingleOrDefault(); req.Status = "Approved"; req.Remarks = remarks; req.ApprovalDate = DateTime.Now; req.ApproverID = Convert.ToInt32(approverID); //RequisitionDetail reqDetails = entities.RequisitionDetails.Where() entities.SaveChanges(); //Send email LogicUtility.Instance.SendRequisitionResponseEmail(requisitionId, remarks, "APPROVED"); } }
////////UpdateDisbursement public static void UpdateDisbursement(List <DisbursementDetail> input) { using (Team10ADModel m = new Team10ADModel()) { Disbursement disbursement = new Disbursement(); disbursement.DisbursementID = Convert.ToInt32(input[0].DisbursementID); m.Disbursements.Attach(disbursement); m.Entry(disbursement).Property(x => x.Status).IsModified = true; m.SaveChanges(); //foreach (StockAdjustmentVoucherDetail detail in detailList) //{ // detail.VoucherID = voucher.VoucherID; // m.StockAdjustmentVoucherDetails.Add(detail); // m.SaveChanges(); //} } }
public static void updateItemStockLevel(Dictionary <string, int> reqListItems) { using (Team10ADModel entities = new Team10ADModel()) { Catalogue catReqItem = new Catalogue(); string key; int keyValue; int balance; int pendDelQty; int pendReqQty; int reorderLvl; int stockCheckQty; //for(int index = 0; index < reqListItems.Count; index++) //{ // key= reqListItems[ // catReqItem = entities.Catalogues.Where(p => p.ItemCode == reqListItems[index].Key.ToString()).FirstOrDefault(); //} foreach (KeyValuePair <string, int> catItem in reqListItems) { key = catItem.Key; keyValue = catItem.Value; catReqItem = entities.Catalogues.Where(p => p.ItemCode == key).FirstOrDefault(); catReqItem.PendingRequestQuantity = keyValue; balance = (int)catReqItem.BalanceQuantity; pendDelQty = (int)catReqItem.PendingDeliveryQuantity; pendReqQty = keyValue; reorderLvl = (int)catReqItem.ReorderLevel; stockCheckQty = balance + pendDelQty - pendReqQty; //if the reorder level more than (balance+pending delivery quantity - pending request delivery), shortfall status = false if (stockCheckQty < reorderLvl) { catReqItem.ShortfallStatus = "True"; } } entities.SaveChanges(); } }
//Make into list of Requisition - Required: ItemCode, Quantity, RequestorID, RequisitionDate, Status public static List <RequisitionDetail> CreateRequisition(List <CartData> oldList) { requestorID = Int32.Parse(oldList.Select(x => x).First().reqid); List <CartData> cartList = CombineDuplicates(oldList); //Convert CartData to RequisitonDetail object List <RequisitionDetail> requisitionList = new List <RequisitionDetail>(); foreach (var item in cartList) { RequisitionDetail requisitionDTO = new RequisitionDetail(); requisitionDTO.ItemCode = item.itemCode; requisitionDTO.QuantityRequested = Int32.Parse(item.quantity); requisitionList.Add(requisitionDTO); } using (Team10ADModel context = new Team10ADModel()) { Requisition requisition = new Requisition(); { requisition.RequisitionDate = DateTime.Now; requisition.Status = "Pending"; requisition.RequisitionDetails = requisitionList; requisition.RequestorID = requestorID; }; context.Requisitions.Add(requisition); context.SaveChanges(); //Send notification LogicUtility.Instance.SendRequisitionEmail(requisition.RequisitionID, requisition.RequestorID, requisition.RequisitionDate.ToString()); } return(requisitionList); }
protected void UpdateButton_Click(object sender, EventArgs e) { Team10ADModel context = new Team10ADModel(); int needAdjustment = (int)Session["AdjustVoucherId"]; //int needAdjustment = 1000002; List <StockAdjustmentVoucherDetail> userinput = context.StockAdjustmentVoucherDetails.Where(x => x.VoucherID == needAdjustment).ToList();; foreach (StockAdjustmentVoucherDetail v in userinput) { foreach (GridViewRow row in dgvCreateAdj.Rows) { if ((row.Cells[0].Text).Equals(v.ItemCode)) { TextBox reasonbox = (TextBox)row.FindControl("ReasonTextBox"); v.Reason = reasonbox.Text; context.SaveChanges(); } } } Response.Redirect("AdjustmentVoucherList.aspx"); }
public static bool SavePOInfo(List <POIntermediate> poList, int storeStaffID) { bool result = false; //string test = ""; HashSet <string> supSet = new HashSet <string>(); //Save supplier names in HashSet foreach (var item in poList) { supSet.Add(item.SupplierName); } //Create different PO objects depending on suppliers int count = supSet.Count; //Iterate through hashset to createPO- Convert to Array and iterate Array string[] stringArray = supSet.ToArray(); foreach (string supName in stringArray) { //TEST // test += supName; //Create a PO for each unique supplier using (Team10ADModel m = new Team10ADModel()) { List <PurchaseOrderDetail> poDetailList = new List <PurchaseOrderDetail>(); PurchaseOrder po = new PurchaseOrder(); PurchaseOrderDetail pd; int?minOrderQty; //CreationDate po.CreationDate = DateTime.Now; //StoreStaffID po.StoreStaffID = storeStaffID; //Get from POIntermediate: SupplierCode, PODetails: ItemCode,Quantity, UnitPrice, Status foreach (var poIntermediate in poList) { if (supName == poIntermediate.SupplierName && poIntermediate.Quantity != 0) { pd = new PurchaseOrderDetail(); po.SupplierCode = poIntermediate.SupplierName; pd.ItemCode = poIntermediate.ItemCode; pd.Quantity = poIntermediate.Quantity; pd.UnitPrice = m.SupplierDetails .Where(x => x.ItemCode == pd.ItemCode) .Select(x => x.Price).First(); minOrderQty = m.Catalogues .Where(x => x.ItemCode == pd.ItemCode) .Select(x => x.MinimumOrderQuantity).First(); pd.Status = "Unreceived"; //Only add if order qty >= Min order qty if (pd.Quantity >= minOrderQty) { poDetailList.Add(pd); } } } po.PurchaseOrderDetails = poDetailList; //Status po.Status = "Unreceived"; //Only save changes if PO is not empty if (poDetailList.Count != 0) { m.PurchaseOrders.Add(po); foreach (PurchaseOrderDetail item in poDetailList) { Catalogue c = m.Catalogues.Where(x => x.ItemCode == item.ItemCode).Select(x => x).First(); //Add pending delivery qty int?qty = m.Catalogues.Where(x => x.ItemCode == item.ItemCode).Select(x => x.PendingDeliveryQuantity).First(); int?balanceQty = m.Catalogues.Where(x => x.ItemCode == item.ItemCode).Select(x => x.BalanceQuantity).First(); int?reorderQty = m.Catalogues.Where(x => x.ItemCode == item.ItemCode).Select(x => x.ReorderLevel).First(); qty += item.Quantity.GetValueOrDefault(); c.PendingDeliveryQuantity = qty; if (qty >= (reorderQty - balanceQty)) { //Set shortfall to false c.ShortfallStatus = "False"; } } m.SaveChanges(); result = true; } } //return test; } return(result); }
//Saving goods received data into 5 tables public static void SavingGoodsReceived(int poid, GoodsReceivedRecord grr, List <GoodsReceivedRecordDetail> grrdlist) { Team10ADModel context = new Team10ADModel(); context.GoodsReceivedRecords.Add(grr); context.SaveChanges(); foreach (GoodsReceivedRecordDetail detail in grrdlist) { Catalogue item = context.Catalogues.Where(i => i.ItemCode == detail.ItemCode).First(); item.BalanceQuantity += detail.ReceivedQuantity; item.PendingDeliveryQuantity -= detail.ReceivedQuantity; context.SaveChanges(); detail.GoodReceiveID = grr.GoodReceiveID; detail.QuantityAfter = item.BalanceQuantity; context.GoodsReceivedRecordDetails.Add(detail); context.SaveChanges(); } List <PurchaseOrderDetail> podetaillist = context.PurchaseOrderDetails.Where(x => x.POID == poid).ToList(); foreach (PurchaseOrderDetail detail in podetaillist) { if (GetTotalGoodsReceived(poid, detail.ItemCode) >= detail.Quantity) { detail.Status = "Received"; } else if (GetTotalGoodsReceived(poid, detail.ItemCode) == 0) { detail.Status = "Unreceived"; } else { detail.Status = "Partial"; } context.SaveChanges(); } PurchaseOrder po = context.PurchaseOrders.Where(x => x.POID == poid).First(); int counter = 0; int partial = 0; foreach (PurchaseOrderDetail detail in podetaillist) { if (detail.Status == "Partial") { counter++; partial++; } else if (detail.Status == "Unreceived") { counter++; } } if (counter == 0) { po.Status = "Received"; } if (partial > 0) { po.Status = "Received"; } context.SaveChanges(); }
public static void GenerateRetrievalList(List <RequisitionDetail> reqdetaillist, List <Requisition> reqList, int clerkid) { using (Team10ADModel context = new Team10ADModel()) { List <RetrievalDetail> retrievallist = new List <RetrievalDetail>(); //Creating a new retrieval record Retrieval retrievalnew = new Retrieval(); retrievalnew.RetrievalDate = DateTime.Now; retrievalnew.StoreStaffID = clerkid; retrievalnew.Status = "Unretrieved"; //Special bit of code to prevent Entity Framework from reinsert existing objects into database //The attach keyword lets EF become aware that the data existing. It only need to ref them //It prevents the entire graph from being added context.Retrievals.Add(retrievalnew); foreach (Requisition r in reqList) { context.Requisitions.Attach(r); } retrievalnew.Requisitions = reqList; context.SaveChanges(); foreach (RequisitionDetail requisition in reqdetaillist) { //Counter to check that there is no existing itemcode in the List<RequisitionDetail> int itemcounter = 0; foreach (RetrievalDetail retrieval in retrievallist) { //If itemcode exist and quantity not fulfilled, just increment the requested quantity if ((retrieval.ItemCode == requisition.ItemCode && (requisition.QuantityRequested - requisition.QuantityRetrieved) > 0) || (retrieval.ItemCode == requisition.ItemCode && requisition.QuantityRetrieved == null)) { itemcounter++; if (requisition.QuantityRetrieved == null) { retrieval.RequestedQuantity += requisition.QuantityRequested; } else { retrieval.RequestedQuantity += (requisition.QuantityRequested - requisition.QuantityRetrieved); } } } //If no existing itemcode and quantity not fulfilled in the List<RetrievalDetail>, create a new instance of it if ((itemcounter == 0 && (requisition.QuantityRequested - requisition.QuantityRetrieved) > 0) || (itemcounter == 0 && requisition.QuantityRetrieved == null)) { RetrievalDetail ret = new RetrievalDetail(); ret.RetrievalID = retrievalnew.RetrievalID; ret.ItemCode = requisition.ItemCode; if (requisition.QuantityRetrieved == null) { ret.RequestedQuantity = requisition.QuantityRequested; } else { ret.RequestedQuantity = (requisition.QuantityRequested - requisition.QuantityRetrieved); } retrievallist.Add(ret); } } //Saving the retrieval detail list into database foreach (RetrievalDetail retrieval in retrievallist) { context.RetrievalDetails.Add(retrieval); context.SaveChanges(); } } //Havent check the quantity to make sure not complete //Havent enable partial retrieval based on balance quantity of items }
/////////////////////////////////Temp modify "userinput" to "retrievaldetaillist" START public static void UpdateRetrievalDetailsFull(int retrievalid, List <RetrievalDetail> retrievaldetaillist, int clerkid) { using (Team10ADModel context = new Team10ADModel()) { //Updating quantities in Catalogue, Retrieval and RetrievalDetail tables foreach (RetrievalDetail userdetail in retrievaldetaillist) { RetrievalDetail existingdata = context.RetrievalDetails.Where(r => r.RetrievalID == userdetail.RetrievalID && r.ItemCode == userdetail.ItemCode).First(); existingdata.RetrievedQuantity = userdetail.RetrievedQuantity; Catalogue item = context.Catalogues.Where(x => x.ItemCode == userdetail.ItemCode).First(); item.BalanceQuantity -= userdetail.RetrievedQuantity; item.PendingRequestQuantity -= userdetail.RetrievedQuantity; context.SaveChanges(); } Retrieval retrieval = context.Retrievals.Where(x => x.RetrievalID == retrievalid).First(); retrieval.Status = "Retrieved"; context.SaveChanges(); //Generate Disbursement and DisbursementDetails //List<RetrievalDetail> retrievaldetaillist = retrieval.RetrievalDetails.ToList(); /////////////////////////////////Temp modify "userinput" to "retrievaldetaillist" END List <Requisition> reqlist = retrieval.Requisitions.ToList(); List <Department> fulldeptlist = context.Departments.ToList(); //Preparing the retrieved qty of the item to be splitted amount the disbursement Dictionary <string, int> retrievedqtybal = new Dictionary <string, int>(); foreach (RetrievalDetail rd in retrievaldetaillist) { //Assign zero if there is no value stored int balqty = (rd.RetrievedQuantity == null) ? 0 : (int)rd.RetrievedQuantity; retrievedqtybal.Add(rd.ItemCode, balqty); } foreach (Department d in fulldeptlist) { //Counter to check if disbursement record was generated for this department //This will determine to create a new disbursement for this department or not int deptcounter = 0; List <DisbursementDetail> disDetailList = new List <DisbursementDetail>(); //Disbursement disbursementnew = new Disbursement(); Disbursement disbursement = new Disbursement(); foreach (RetrievalDetail retrievaldetail in retrievaldetaillist) { //Match all requisition record of this retrieval to see if any match a department foreach (Requisition r in reqlist) { //Counter to check for partial or completed requisition int notcompletedcheck = 0; //If match department, loop through the requisition detail and save into disbursement detail if (d.DepartmentCode == r.Employee.DepartmentCode) { deptcounter++; //Creating a new disbursement if (deptcounter == 1) { //Disbursement disbursement = new Disbursement(); disbursement.CollectionDate = DateTime.Now; disbursement.PointID = r.Employee.Department.CollectionPoint.PointID; disbursement.DepartmentCode = r.Employee.DepartmentCode; disbursement.Status = "Uncollected"; disbursement.StoreStaffID = clerkid; context.Disbursements.Add(disbursement); context.SaveChanges(); //disbursementnew = context.Disbursements.OrderByDescending(x => x.DisbursementID).First(); } List <RequisitionDetail> reqDetailList = r.RequisitionDetails.ToList(); foreach (RequisitionDetail reqdetail in reqDetailList) { //Counter to make sure no duplicates of the item is created in the details int itemcounter = 0; foreach (DisbursementDetail disDetail in disDetailList) { //If itemcode exist, increment the requested quantity in the disbursement //Assign the quantity retrieved to the corresponding requisition //Decrement from the temporary store of the balance retrieved quantity if (disDetail.ItemCode == reqdetail.ItemCode && reqdetail.ItemCode == retrievaldetail.ItemCode) { itemcounter++; //The outer if set checks if the retrieved qty is sufficient to split among the departments if (retrievedqtybal[disDetail.ItemCode] >= reqdetail.QuantityRequested) { //Checks for partial/new requisition cases //If null can ignore the quantity retrieved in the requisition if (reqdetail.QuantityRetrieved == null) { disDetail.QuantityRequested += reqdetail.QuantityRequested; reqdetail.QuantityRetrieved = reqdetail.QuantityRequested; retrievedqtybal[disDetail.ItemCode] -= (int)reqdetail.QuantityRequested; } //If not null can safetly do the math else { disDetail.QuantityRequested += (reqdetail.QuantityRequested - reqdetail.QuantityRetrieved); reqdetail.QuantityRetrieved += (reqdetail.QuantityRequested - reqdetail.QuantityRetrieved); retrievedqtybal[disDetail.ItemCode] -= (int)(reqdetail.QuantityRequested - reqdetail.QuantityRetrieved); } } else if ((retrievedqtybal[disDetail.ItemCode] < reqdetail.QuantityRequested) && (retrievedqtybal[disDetail.ItemCode] > 0)) { if (reqdetail.QuantityRetrieved == null) { disDetail.QuantityRequested += retrievedqtybal[disDetail.ItemCode]; reqdetail.QuantityRetrieved += retrievedqtybal[disDetail.ItemCode]; retrievedqtybal[disDetail.ItemCode] -= (int)retrievedqtybal[disDetail.ItemCode]; } else { if (reqdetail.QuantityRetrieved + retrievedqtybal[disDetail.ItemCode] > reqdetail.QuantityRequested) { disDetail.QuantityRequested += (retrievedqtybal[disDetail.ItemCode] - reqdetail.QuantityRetrieved); reqdetail.QuantityRetrieved += (retrievedqtybal[disDetail.ItemCode] - reqdetail.QuantityRetrieved); retrievedqtybal[disDetail.ItemCode] -= (int)(retrievedqtybal[disDetail.ItemCode] - reqdetail.QuantityRetrieved); } else { disDetail.QuantityRequested += retrievedqtybal[disDetail.ItemCode]; reqdetail.QuantityRetrieved += retrievedqtybal[disDetail.ItemCode]; retrievedqtybal[disDetail.ItemCode] -= retrievedqtybal[disDetail.ItemCode]; } } } else { //Actually not necessary since balance available to split to disbursement is already 0 //Just putting a zero incase of null value if (reqdetail.QuantityRetrieved == null) { disDetail.QuantityRequested += 0; reqdetail.QuantityRetrieved = 0; } } } } //If no existing itemcode in the List<RequisitionDetail>, create a new instance of it if (reqdetail.ItemCode == retrievaldetail.ItemCode && itemcounter == 0) { DisbursementDetail disburementdetail = new DisbursementDetail(); disburementdetail.DisbursementID = disbursement.DisbursementID; disburementdetail.ItemCode = reqdetail.ItemCode; if (retrievedqtybal[disburementdetail.ItemCode] >= reqdetail.QuantityRequested) { //Checks for partial/new requisition cases //If null can ignore the quantity retrieved in the requisition if (reqdetail.QuantityRetrieved == null) { disburementdetail.QuantityRequested = reqdetail.QuantityRequested; reqdetail.QuantityRetrieved = reqdetail.QuantityRequested; retrievedqtybal[disburementdetail.ItemCode] -= (int)reqdetail.QuantityRequested; } //If not null can safetly do the math else { disburementdetail.QuantityRequested = (reqdetail.QuantityRequested - reqdetail.QuantityRetrieved); reqdetail.QuantityRetrieved += (reqdetail.QuantityRequested - reqdetail.QuantityRetrieved); retrievedqtybal[disburementdetail.ItemCode] -= (int)(reqdetail.QuantityRequested - reqdetail.QuantityRetrieved); } } else if ((retrievedqtybal[disburementdetail.ItemCode] < reqdetail.QuantityRequested) && (retrievedqtybal[disburementdetail.ItemCode] > 0)) { if (reqdetail.QuantityRetrieved == null) { disburementdetail.QuantityRequested = retrievedqtybal[disburementdetail.ItemCode]; reqdetail.QuantityRetrieved = retrievedqtybal[disburementdetail.ItemCode]; retrievedqtybal[disburementdetail.ItemCode] -= retrievedqtybal[disburementdetail.ItemCode]; } else { if (reqdetail.QuantityRetrieved + retrievedqtybal[disburementdetail.ItemCode] > reqdetail.QuantityRequested) { disburementdetail.QuantityRequested = (retrievedqtybal[disburementdetail.ItemCode] - reqdetail.QuantityRetrieved); reqdetail.QuantityRetrieved += (retrievedqtybal[disburementdetail.ItemCode] - reqdetail.QuantityRetrieved); retrievedqtybal[disburementdetail.ItemCode] -= (int)(retrievedqtybal[disburementdetail.ItemCode] - reqdetail.QuantityRetrieved); } else { disburementdetail.QuantityRequested = retrievedqtybal[disburementdetail.ItemCode]; reqdetail.QuantityRetrieved += retrievedqtybal[disburementdetail.ItemCode]; retrievedqtybal[disburementdetail.ItemCode] -= retrievedqtybal[disburementdetail.ItemCode]; } } } else { if (reqdetail.QuantityRetrieved == null) { reqdetail.QuantityRetrieved = 0; } disburementdetail.QuantityRequested = 0; } disDetailList.Add(disburementdetail); } } //Loop through details of requisition to check for completeness foreach (RequisitionDetail rd in reqDetailList) { if (rd.QuantityRequested != rd.QuantityRetrieved) { notcompletedcheck++; } } if (notcompletedcheck == 0) { r.Status = "Completed"; } else { r.Status = "Partial"; } context.SaveChanges(); } } } //Creating a new set of disbursement details if (deptcounter > 0) { foreach (DisbursementDetail ddetail in disDetailList) { context.DisbursementDetails.Add(ddetail); //TODO: Send notification email context.SaveChanges(); } LogicUtility.Instance.SendDisbursementEmail(disbursement.DisbursementID); } } } }
public static int GenerateAdjustmentVoucherDetails(List <RetrievalDetail> suggested, List <RetrievalDetail> userinput, int clerkid) { using (Team10ADModel context = new Team10ADModel()) { //To be returned for redirecting to the correct adjustment detail int adjustmentVoucherId = 0; //Counter to check whether there is any item that need adjustment int needAdjustment = 0; //StockAdjustmentVoucher adjNew = new StockAdjustmentVoucher(); List <StockAdjustmentVoucherDetail> adjDetailList = new List <StockAdjustmentVoucherDetail>(); foreach (RetrievalDetail sDetail in suggested) { foreach (RetrievalDetail uDetail in userinput) { if (sDetail.ItemCode == uDetail.ItemCode) { //Check that there is a change in suggested quantity and that the balance is below the requested quantity //This is to give clerk the flexibility to still reduce the quantity and not trigger an adjustment if (sDetail.RetrievedQuantity < sDetail.RequestedQuantity && sDetail.RetrievedQuantity != uDetail.RetrievedQuantity) { needAdjustment++; if (needAdjustment == 1) { StockAdjustmentVoucher adj = new StockAdjustmentVoucher(); adj.StoreStaffID = clerkid; adj.DateIssue = DateTime.Now; adj.Status = "Pending"; context.StockAdjustmentVouchers.Add(adj); context.SaveChanges(); //adjNew = context.StockAdjustmentVouchers.OrderByDescending(x => x.VoucherID).First(); //adjustmentVoucherId = adjNew.VoucherID; adjustmentVoucherId = adj.VoucherID; } StockAdjustmentVoucherDetail adjDetail = new StockAdjustmentVoucherDetail(); adjDetail.VoucherID = adjustmentVoucherId; adjDetail.ItemCode = uDetail.ItemCode; adjDetail.QuantityAdjusted = -(uDetail.Catalogue.BalanceQuantity - uDetail.RetrievedQuantity); Catalogue item = context.Catalogues.Where(x => x.ItemCode == adjDetail.ItemCode).First(); item.BalanceQuantity -= (uDetail.Catalogue.BalanceQuantity - uDetail.RetrievedQuantity); adjDetail.QuantityAfter = item.BalanceQuantity; adjDetailList.Add(adjDetail); context.SaveChanges(); } } } } if (needAdjustment > 0) { foreach (StockAdjustmentVoucherDetail detail in adjDetailList) { context.StockAdjustmentVoucherDetails.Add(detail); context.SaveChanges(); } } StoreStaff supervisor = context.StoreStaffs.Where(x => x.Title == "Supervisor").First(); StoreStaff manager = context.StoreStaffs.Where(x => x.Title == "Manager").First(); if (adjustmentVoucherId > 0 && AdjustmentVoucherCost(adjustmentVoucherId) <= 250) { LogicUtility.Instance.SendAdjustmentEmail(adjustmentVoucherId, supervisor.StoreStaffID); } else if (adjustmentVoucherId > 0 && AdjustmentVoucherCost(adjustmentVoucherId) > 250) { LogicUtility.Instance.SendAdjustmentEmail(adjustmentVoucherId, manager.StoreStaffID); } return(adjustmentVoucherId); } }