public IActionResult StationeryRetrievalForm2([FromRoute] int id)
        {
            StationeryRetrievalViewModel SRviewModel = new StationeryRetrievalViewModel();

            emp = JsonConvert.DeserializeObject <Employee>(HttpContext.Session.GetString("employee")) as Employee;

            //SR details_clerkid,date,...to show in SR details page //by htp
            StationeryRetrieval sr = srformservice.GetSRDetails(id);

            SRviewModel.stationeryRetrieval = sr;
            //data for requisition form summary in SR details //by htp
            List <RequisitionForm> rfList = srformservice.GetRequisitionDetailBySR_RF(id);

            SRviewModel.retrievalRequisitions = rfList;


            //data for warehouse stock preview table(all products) in SR details //by htp
            List <StationeryRetrievalProduct> srpList = srformservice.GetSRDetailProducts(id);

            SRviewModel.retrievalProducts = srpList;
            SRviewModel.employee          = emp;
            SRviewModel.srrfList          = srformservice.GetSRRFListBySRID(id);

            return(View("StationeryRetrievalFormTransaction", SRviewModel));
        }
Esempio n. 2
0
        //Get selected Stationery retrieval details //by htp
        public StationeryRetrieval GetSRDetails(int SRid)
        {
            StationeryRetrieval retrievalDetails = db.StationeryRetrievals
                                                   .Where(x => x.Id == SRid)
                                                   .FirstOrDefault();

            return(retrievalDetails);
        }
        /** Get list of Departments from Stationery Retrieval **/
        public List <String> getListOfDepartments(StationeryRetrieval sr)
        {
            List <String> departmentNames = (from sd in context.StationeryRetrievalDepts
                                             where (sd.RetrievalID == sr.RetrievalID) && (sd.DeletedFlag == false)
                                             select sd.Department.DeptName).Distinct().ToList();

            return(departmentNames);
        }
        /** generate Disbursement List **/
        public bool getnerateAllDisbursementLists()
        {
            StationeryRetrieval sr = getStationeryRetrieval();

            /** Get the list of Department wise stationery requests **/
            var sdList = (from sd in context.StationeryRetrievalDepts
                          where (sd.RetrievalID == sr.RetrievalID) &&
                          (sd.DeletedFlag == false)
                          select sd).ToList();

            try
            {
                /** Get list of unique department codes **/
                List <String> dcs          = sdList.Select(x => x.DeptCode).Distinct().ToList();
                ArrayList     deptCodeList = new ArrayList(dcs.ToArray());

                foreach (String deptCode in deptCodeList)
                {
                    /** Create Stationery Disbursement **/

                    createStationeryDisbursement(sr.RetrievalID, deptCode);


                    /** Retreive latest Stationery Disbursement record **/
                    int disbursementID = (from d in context.StationeryDisbursements
                                          orderby d.DisbursementID descending
                                          select d.DisbursementID).FirstOrDefault();

                    foreach (StationeryRetrievalDept sd in sdList)
                    {
                        if (sd.DeptCode.Equals(deptCode))
                        {
                            /**Create Stationery Disbursement details**/
                            StationeryDisbursementDetail addStationeryDisbursementDetail = new StationeryDisbursementDetail();
                            addStationeryDisbursementDetail.DisbursementID = disbursementID;
                            addStationeryDisbursementDetail.ItemCode       = sd.ItemCode;
                            addStationeryDisbursementDetail.RequestedQty   = sd.RequestedQty;
                            addStationeryDisbursementDetail.ActualQty      = sd.ActualQty;
                            addStationeryDisbursementDetail.DeletedFlag    = false;
                            context.AddToStationeryDisbursementDetails(addStationeryDisbursementDetail);
                            context.SaveChanges();
                        }
                    }
                }
                /** change Statiobnery Retrieval status **/
                sr.RetrievalStatus = true;
                context.SaveChanges();
            }

            catch (Exception ex)
            {
                success  = false;
                errorMsg = "Failed to generate Disbursement List for department";
                throw new CreateFailedException(errorMsg);
            }

            return(success);
        }
Esempio n. 5
0
        public List <StationeryRetrievalRequisitionForm> GetSRRFListBySRID(int id)
        {
            StationeryRetrieval sr = db.StationeryRetrievals.Find(id);
            List <StationeryRetrievalRequisitionForm> srrfList = db.StationeryRetrievalRequisitionForms
                                                                 .Where(x => x.StationeryRetrieval.Id == sr.Id)
                                                                 .ToList();

            return(srrfList);
        }
Esempio n. 6
0
        /** Get Stationery Retrieval ID **/
        public StationeryRetrieval getstationeryRetrieval()
        {
            var q = from i in context.StationeryRetrievals
                    where i.RetrievalStatus == false
                    select i;
            StationeryRetrieval sr = (StationeryRetrieval)q.FirstOrDefault();

            return(sr);
        }
        /** Get the latest Stationery Retrieval ID **/
        public StationeryRetrieval getStationeryRetrieval()
        {
            var q = from i in context.StationeryRetrievals
                    where i.RetrievalStatus == false
                    orderby i.RetrievalID descending
                    select i;
            StationeryRetrieval sr = (StationeryRetrieval)q.FirstOrDefault();

            return(sr);
        }
        public IActionResult ViewAssignedProductsInPendingSR([FromRoute] int id)
        {
            StationeryRetrievalViewModel srVModel = new StationeryRetrievalViewModel();

            emp = JsonConvert.DeserializeObject <Employee>(HttpContext.Session.GetString("employee")) as Employee;
            srVModel.employee          = emp;
            srVModel.retrievalProducts = srformservice.GetSRPListForAssign(id);
            StationeryRetrieval sr = srformservice.FindBySRId(id);

            srVModel.sRRFPList           = srformservice.FindSRRFPList(id);
            srVModel.stationeryRetrieval = sr;
            srVModel.srrfList            = srformservice.GetSRRFListBySRID(id);
            return(View("StationeryRetrievalFormAssignment", srVModel));
        }
Esempio n. 9
0
        public IActionResult ViewAssignedProductsInPendingSR(int SFId)
        {
            StationeryRetrievalViewModel srVModel = new StationeryRetrievalViewModel();

            //emp = JsonConvert.DeserializeObject<Employee>(HttpContext.Session.GetString("employee")) as Employee;
            //srVModel.employee = emp;
            srVModel.retrievalProducts = srfservice.GetSRPListForAssign(SFId);
            StationeryRetrieval sr = srfservice.FindBySRId(SFId);

            srVModel.sRRFPList           = srfservice.FindSRRFPList(SFId);
            srVModel.stationeryRetrieval = sr;
            srVModel.srrfList            = srfservice.GetSRRFListBySRID(SFId);
            return(Ok(srVModel));
        }
Esempio n. 10
0
        /**Get all Approved and Outstanding Requests **/
        public bool generateStationeryRetrieval()
        {
            var q = from rd in context.RequestDetails
                    where rd.Request.RequestStatus.Equals("Approved") ||
                    rd.Request.RequestStatus.Equals("Outstanding") &&
                    (rd.DeletedFlag == false)
                    select rd;
            List <RequestDetail> rdList = q.ToList <RequestDetail>();

            if (!(rdList.Count == 0))
            {
                /** get unique item codes for the list of selected requests **/
                List <String> ids      = rdList.Select(x => x.ItemCode.ToString()).Distinct().ToList();
                ArrayList     itemList = new ArrayList(ids.ToArray());

                /** Create new Stationery Retrieval **/
                StationeryRetrieval addStationeryRetrieval = new StationeryRetrieval();
                addStationeryRetrieval.DateRetrieved   = DateTime.Now;
                addStationeryRetrieval.DeletedFlag     = false;
                addStationeryRetrieval.RetrievalStatus = false;
                context.AddToStationeryRetrievals(addStationeryRetrieval);
                try
                {
                    context.SaveChanges();
                    /** Select the latest Stationery Retrieval ID **/
                    int RetrievalID = (from i in context.StationeryRetrievals
                                       where i.RetrievalStatus == false
                                       select i.RetrievalID).FirstOrDefault();
                    /** Create Item wise and Department wise list **/
                    createItemWiseList(rdList, itemList, RetrievalID);
                    createDepartmentWiseList(rdList, itemList, RetrievalID);
                    changeRequestStatus(rdList);
                }
                catch (Exception ex)
                {
                    success  = false;
                    errorMsg = "Failed to generate Stationery Retrieval Form";
                    throw new CreateFailedException(errorMsg);
                }
            }
            else
            {
                success = false;
            }
            return(success);
        }
        /** Get stationery retrieval details **/
        public void displayStationeryRetrieval(StationeryRetrieval sr)
        {
            lblDBRetrievalID.Text = sr.RetrievalID.ToString();
            lblDBDate.Text        = sr.DateRetrieved.Value.ToString("dd/MM/yyyy");

            /** Get the item wise list **/
            StationeryRetrievalGrid.DataSource = srControl.getItemWiseList(sr.RetrievalID);
            StationeryRetrievalGrid.DataBind();

            /** Display first record in Department wise list **/
            StationeryRetrievalDetail sd = srControl.getFirstItem(sr.RetrievalID);

            lblDBItemNo.Text      = sd.ItemCode;
            lblDBDescription.Text = sd.Stock.ItemDescription;
            DepartmentWiseDetailsGrid.DataSource = srControl.getDepartmentWiseList(sr.RetrievalID, sd.ItemCode);
            DepartmentWiseDetailsGrid.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                /** check if there is current stationery retrieval **/

                StationeryRetrieval sr = srControl.getstationeryRetrieval();
                if (sr != null)
                {
                    visbleControls();
                    displayStationeryRetrieval(sr);
                    lblStatus.Text = "There is a current stationery retrieval. Please generate the Disbursement List";
                }
                else
                {
                    try
                    {
                        bool success = srControl.generateStationeryRetrieval();
                        if (success)
                        {
                            StationeryRetrieval srNew = srControl.getstationeryRetrieval();
                            displayStationeryRetrieval(srNew);
                            visbleControls();
                        }
                        else
                        {
                            hideControls();
                            lblStatus.Text = "No approved or outstanding request found !";
                        }
                    }
                    catch (Exception ex)
                    {
                        hideControls();
                        lblStatus.Text = "Failed to generate stationery retrieval !";
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                disbursementTable.Visible = false;
                FormButtons.Visible       = false;
                lblStatus.Text            = "";

                StationeryRetrieval stationeryRetrieval = gdControl.getStationeryRetrieval();
                if (stationeryRetrieval != null)
                {
                    lblDBRetrievalID.Text  = stationeryRetrieval.RetrievalID.ToString();
                    ddlDeptName.DataSource = gdControl.getListOfDepartments(stationeryRetrieval);
                    ddlDeptName.DataBind();

                    try
                    {
                        if (gdControl.getnerateAllDisbursementLists())
                        {
                            String departmentName = ddlDeptName.SelectedItem.Text;
                            if (departmentName != null)
                            {
                                displayDisbursementList(departmentName);
                            }
                        }
                    }
                    catch (CreateFailedException ex)
                    {
                        lblStatus.Text = ex.Message;
                    }
                }
                else
                {
                    lblStatus.Text = "No current Stationery Retrieval available! Please generate Stationery Retrieval Form";
                }
            }
        }
        public bool SaveAndDisburse(List <RequestByItemViewModel> model, string userId)
        {
            LogicDB context = new LogicDB();

            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    StationeryRetrieval retrieval = new StationeryRetrieval();
                    string rid = GetNewRetrievalId();
                    retrieval.RetrievalId = rid;
                    retrieval.RetrievedBy = userId;
                    retrieval.Date        = DateTime.Now;

                    foreach (var sr in model)
                    {
                        int retQty = sr.requestList.Sum(x => x.RetrievedQty);
                        if (retQty > 0)
                        {
                            TransactionDetail detail = new TransactionDetail();
                            detail.ItemId          = sr.ItemId;
                            detail.Quantity        = retQty;
                            detail.TransactionDate = DateTime.Now;
                            detail.Remarks         = "Retrieved";
                            detail.TransactionRef  = rid;
                            retrieval.TransactionDetail.Add(detail);

                            //Less off from stationery

                            var item = context.Stationery.FirstOrDefault(x => x.ItemId == sr.ItemId);
                            if (item != null)
                            {
                                item.QuantityWarehouse -= retQty;
                                item.QuantityTransit   += retQty;
                            }
                        }
                    }
                    context.StationeryRetrieval.Add(retrieval);
                    context.SaveChanges();

                    List <RequestByIdViewModel> requests = CreateDisbHelpers.GetRequestQuery(context).OrderBy(x => x.RequestId).ToList();

                    List <DisbursementByDeptViewModel> disbList = GenerateDisbursement(model);

                    foreach (var dept in disbList)
                    {
                        string currentDeptId = dept.DepartmentId;
                        string disbNo        = CreateDisbHelpers.GetNewDisbNo(context, currentDeptId);
                        string OTP;
                        do
                        {
                            Random rand = new Random();
                            OTP = rand.Next(10000).ToString("0000");
                        } while (context.Disbursement.Where(x => x.OTP == OTP).FirstOrDefault() != null);

                        Dictionary <string, int> tempDict = new Dictionary <string, int>();
                        foreach (var retItem in dept.requestList)
                        {
                            tempDict.Add(retItem.Description, retItem.RetrievedQty);
                        }

                        var deptReqList = requests.Where(x => x.DepartmentId == dept.DepartmentId).ToList();

                        foreach (var req in deptReqList)
                        {
                            bool isComplete = true;
                            foreach (var item in req.ItemList)
                            {
                                var disbItem = dept.requestList.FirstOrDefault(x => x.ItemId == item.ItemId);
                                if (disbItem != null)
                                {
                                    if (disbItem.RetrievedQty >= item.Quantity)
                                    {
                                        disbItem.RetrievedQty -= item.Quantity;
                                    }
                                    else
                                    {
                                        item.Quantity         = disbItem.RetrievedQty;
                                        disbItem.RetrievedQty = 0; //0
                                        isComplete            = false;
                                    }
                                }
                                else
                                {
                                    item.Quantity = 0;
                                    isComplete    = false;
                                }
                            }

                            foreach (var item in req.ItemList)
                            {
                                if (item.Quantity > 0)
                                {
                                    Disbursement      newDisb   = new Disbursement();
                                    TransactionDetail newDetail = new TransactionDetail();
                                    newDisb.DisbursementId    = CreateDisbHelpers.GetNewDisbId(context);
                                    newDisb.DisbursementNo    = disbNo;
                                    newDisb.DepartmentId      = currentDeptId;
                                    newDisb.DisbursedBy       = userId;
                                    newDisb.Date              = DateTime.Now;
                                    newDisb.RequestId         = req.RequestId;
                                    newDisb.Status            = "In Transit";
                                    newDisb.OTP               = OTP;
                                    newDetail.ItemId          = item.ItemId;
                                    newDetail.Quantity        = item.Quantity;
                                    newDetail.TransactionRef  = newDisb.DisbursementId;
                                    newDetail.TransactionDate = DateTime.Now;
                                    newDetail.UnitPrice       = item.UnitPrice;
                                    newDetail.Remarks         = "In Transit";
                                    newDisb.TransactionDetail.Add(newDetail);
                                    context.Disbursement.Add(newDisb);
                                    context.SaveChanges();
                                }
                            }

                            var currentReq = context.StationeryRequest.FirstOrDefault(x => x.RequestId == req.RequestId);
                            if (isComplete)
                            {
                                currentReq.Status = "Completed";
                            }
                            else
                            {
                                currentReq.Status = "Partially Fulfilled";
                            }
                        }
                        //Send email to dept rep
                        string email   = context.Department.FirstOrDefault(x => x.DepartmentId == dept.DepartmentId).AspNetUsers1.Email;
                        string subject = string.Format("Stationeries ready for collection (Disbursement No: {0})", disbNo);

                        string content = string.Format("Disbursement No: {0}{1}Please quote the OTP below when collecting your stationeries.{2}OTP: {3}{4}Collection Point: {5}{6}Time: {7}{8}Item\t\t\t\t\t\t\tQuantity{9}",
                                                       disbNo, Environment.NewLine, Environment.NewLine, OTP, Environment.NewLine, dept.CollectionDescription, Environment.NewLine, dept.CollectionTime, Environment.NewLine, Environment.NewLine);
                        foreach (KeyValuePair <string, int> entry in tempDict)
                        {
                            content += string.Format("{0}\t\t\t\t\t\t{1}{2}", entry.Key, entry.Value, Environment.NewLine);
                        }
                        Email.Send(email, subject, content);
                    }

                    dbContextTransaction.Commit();
                    return(true);
                }
                catch (Exception)
                {
                    dbContextTransaction.Rollback();
                    return(false);
                }
            }
        }
        public DBSeeder(InventoryManagementSystemContext db,
                        IWebHostEnvironment environment,
                        ProductService pService,
                        DepartmentService dService,
                        ProductCategoryService pcService,
                        DisbursementFormService dfService,
                        StationeryRetrievalFormService srfService,
                        EmployeeTypeService etService,
                        EmployeeService empService,
                        RequisitionService rfService,
                        DelegationService delService,
                        SupplierService supService,
                        SupplierProductService spService,
                        InventoryTransactionService itService)
        {
            _hostingEnvironment = environment;



            var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");

            string filePath6   = Path.Combine(uploads, "ProductCategory.csv");
            string jsonString6 = ReadCSVFileUtil.ReadCSVFile(filePath6);
            List <CSVProductCategory> productCategories = (List <CSVProductCategory>)JsonConvert.DeserializeObject(jsonString6, (typeof(List <CSVProductCategory>)));

            pcService.SaveProductCategoryFromCSV(productCategories);

            string             filePath7   = Path.Combine(uploads, "Supplier.csv");
            string             jsonString7 = ReadCSVFileUtil.ReadCSVFile(filePath7);
            List <CSVSupplier> suppliers   = (List <CSVSupplier>)JsonConvert.DeserializeObject(jsonString7, (typeof(List <CSVSupplier>)));

            supService.SaveSuppliersFromCSV(suppliers);

            string filePath3   = Path.Combine(uploads, "EmployeeType.csv");
            string jsonString3 = ReadCSVFileUtil.ReadCSVFile(filePath3);
            List <CSVEmployeeType> employeeTypes = (List <CSVEmployeeType>)JsonConvert.DeserializeObject(jsonString3, (typeof(List <CSVEmployeeType>)));

            etService.SaveEmployeeTypesFromCSV(employeeTypes);

            ProductCategory pc1  = pcService.findProductCategory("Clip");
            ProductCategory pc2  = pcService.findProductCategory("Envelope");
            ProductCategory pc3  = pcService.findProductCategory("Eraser");
            ProductCategory pc4  = pcService.findProductCategory("Exercise");
            ProductCategory pc5  = pcService.findProductCategory("File");
            ProductCategory pc6  = pcService.findProductCategory("Pen");
            ProductCategory pc7  = pcService.findProductCategory("Puncher");
            ProductCategory pc8  = pcService.findProductCategory("Pad");
            ProductCategory pc9  = pcService.findProductCategory("Paper");
            ProductCategory pc10 = pcService.findProductCategory("Ruler");
            ProductCategory pc11 = pcService.findProductCategory("Scissors");
            ProductCategory pc12 = pcService.findProductCategory("Tape");
            ProductCategory pc13 = pcService.findProductCategory("Sharpener");
            ProductCategory pc14 = pcService.findProductCategory("Shorthand");
            ProductCategory pc15 = pcService.findProductCategory("Stapler");
            ProductCategory pc16 = pcService.findProductCategory("Tacks");
            ProductCategory pc17 = pcService.findProductCategory("Tparency");
            ProductCategory pc18 = pcService.findProductCategory("Tray");

            string            filePath1  = Path.Combine(uploads, "Product.csv");
            string            jsonString = ReadCSVFileUtil.ReadCSVFile(filePath1);
            List <CSVProduct> products   = (List <CSVProduct>)JsonConvert.DeserializeObject(jsonString, (typeof(List <CSVProduct>)));

            pService.SaveProductsFromCSV(products);



            string filePath9   = Path.Combine(uploads, "SupplierProduct.csv");
            string jsonString9 = ReadCSVFileUtil.ReadCSVFile(filePath9);
            List <CSVSupplierProduct> supplierProducts = (List <CSVSupplierProduct>)JsonConvert.DeserializeObject(jsonString9, (typeof(List <CSVSupplierProduct>)));

            spService.SaveSupplierProductsFromCSV(supplierProducts);

            //save the images under images folder to database
            var           imagefolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");
            DirectoryInfo Folder      = new DirectoryInfo(imagefolder);

            FileInfo[]    Images     = Folder.GetFiles();
            List <String> imagesList = new List <String>();

            foreach (var image in Images)
            {
                imagesList.Add(String.Format(@"{0}", image.Name));
            }
            pService.SaveProductImages(imagesList);


            EmployeeType empType1 = etService.FindEmployeeTypeByEmployeeTypeName("Store Clerk");
            EmployeeType empType2 = etService.FindEmployeeTypeByEmployeeTypeName("Store Supervisor");
            EmployeeType empType3 = etService.FindEmployeeTypeByEmployeeTypeName("Store Manager");
            EmployeeType empType4 = etService.FindEmployeeTypeByEmployeeTypeName("Employee");
            EmployeeType empType5 = etService.FindEmployeeTypeByEmployeeTypeName("Department Head");
            EmployeeType empType6 = etService.FindEmployeeTypeByEmployeeTypeName("Department Representative");
            EmployeeType empType7 = etService.FindEmployeeTypeByEmployeeTypeName("Warehouse Packer");
            EmployeeType empType8 = etService.FindEmployeeTypeByEmployeeTypeName("Temporary Department Head");


            CollectionPoint cp1 = new CollectionPoint()
            {
                CollectionName = "Stationery Store - Administration Building"
            };
            CollectionPoint cp2 = new CollectionPoint()
            {
                CollectionName = "Management School"
            };
            CollectionPoint cp3 = new CollectionPoint()
            {
                CollectionName = "Medical School"
            };
            CollectionPoint cp4 = new CollectionPoint()
            {
                CollectionName = "Engineering School"
            };
            CollectionPoint cp5 = new CollectionPoint()
            {
                CollectionName = "Science School"
            };
            CollectionPoint cp6 = new CollectionPoint()
            {
                CollectionName = "University Hospital"
            };

            db.Add(cp1);
            db.Add(cp2);
            db.Add(cp3);
            db.Add(cp4);
            db.Add(cp5);
            db.Add(cp6);

            Department dept1 = new Department()
            {
                DepartmentName = "Store", DeptCode = "STOR", CollectionPoint = cp1, PhoneNumber = "12345678"
            };
            Department dept2 = new Department()
            {
                DepartmentName = "English Department", DeptCode = "ENDP", CollectionPoint = cp2, PhoneNumber = "98765432"
            };
            Department dept3 = new Department()
            {
                DepartmentName = "Chinese Department", DeptCode = "CHSL", CollectionPoint = cp2, PhoneNumber = "87654321"
            };
            Department dept4 = new Department()
            {
                DepartmentName = "Engineering Department", DeptCode = "ENGD", CollectionPoint = cp1, PhoneNumber = "76543219"
            };
            Department dept5 = new Department()
            {
                DepartmentName = "Arts Department", DeptCode = "ARTD", CollectionPoint = cp3, PhoneNumber = "53046012"
            };
            Department dept6 = new Department()
            {
                DepartmentName = "Business Department", DeptCode = "BIZD", CollectionPoint = cp4, PhoneNumber = "15397864"
            };
            Department dept7 = new Department()
            {
                DepartmentName = "Science Department", DeptCode = "SCID", CollectionPoint = cp5, PhoneNumber = "68425397"
            };
            Department dept8 = new Department()
            {
                DepartmentName = "Management Department", DeptCode = "MNGD", CollectionPoint = cp6, PhoneNumber = "86957412"
            };
            Department dept9 = new Department()
            {
                DepartmentName = "HQ Department", DeptCode = "HQDP", CollectionPoint = cp3, PhoneNumber = "32540325"
            };
            Department dept10 = new Department()
            {
                DepartmentName = "Music Department", DeptCode = "MSDP", CollectionPoint = cp4, PhoneNumber = "78954120"
            };

            db.Add(dept1);
            db.Add(dept2);
            db.Add(dept3);
            db.Add(dept4);
            db.Add(dept5);
            db.Add(dept6);
            db.Add(dept7);
            db.Add(dept8);
            db.Add(dept9);
            db.Add(dept10);
            db.SaveChanges();

            string             filePath4   = Path.Combine(uploads, "Employee.csv");
            string             jsonString4 = ReadCSVFileUtil.ReadCSVFile(filePath4);
            List <CSVEmployee> employees   = (List <CSVEmployee>)JsonConvert.DeserializeObject(jsonString4, (typeof(List <CSVEmployee>)));

            empService.SaveEmployeesFromCSV(employees);
            empService.SaveEmployeesSupervisedByFromCSV(employees);

            Employee emp1  = empService.GetEmployee("thinn");
            Employee emp2  = empService.GetEmployee("arjun");
            Employee emp3  = empService.GetEmployee("rohan");
            Employee emp4  = empService.GetEmployee("darell");
            Employee emp5  = empService.GetEmployee("yamone");
            Employee emp6  = empService.GetEmployee("sheryl");
            Employee emp7  = empService.GetEmployee("xinqi");
            Employee emp8  = empService.GetEmployee("yanbin");
            Employee emp9  = empService.GetEmployee("darellmgr2");
            Employee emp10 = empService.GetEmployee("thinn2");

            Product pr1 = pService.FindProductById(1);
            Product pr2 = pService.FindProductById(2);
            Product pr3 = pService.FindProductById(3);
            Product pr4 = pService.FindProductById(4);
            Product pr5 = pService.FindProductById(5);
            Product pr6 = pService.FindProductById(6);


            DateTime dd1  = new DateTime(2020, 8, 13, 8, 30, 20);
            DateTime dd2  = new DateTime(2020, 8, 14, 8, 30, 20);
            DateTime dd3  = new DateTime(2020, 8, 12, 8, 40, 20);
            DateTime dd4  = new DateTime(2020, 8, 10, 8, 30, 20);
            DateTime dd13 = new DateTime(2020, 8, 15, 8, 30, 20);



            RequisitionForm rq1 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd1.ToString("ddMMyy") + "/1", Employee = emp1, RFStatus = Enums.RFStatus.Approved, RFDate = dd1, RFApprovalDate = dd1, RFComments = "", RFApprovalBy = emp9
            };
            RequisitionForm rq2 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd2.ToString("ddMMyy") + "/1", Employee = emp1, RFStatus = Enums.RFStatus.Ongoing, RFDate = dd2, RFApprovalDate = dd1, RFComments = "", RFApprovalBy = emp9
            };
            //RequisitionForm rq3 = new RequisitionForm() { RFCode = "RF/" + emp2.Department.DeptCode + "/" + dd3.ToString("ddMMyy") + "/1", Employee = emp2, RFStatus = Enums.RFStatus.Approved, RFDate = dd3, RFApprovalDate = dd1, RFComments = "", RFApprovalBy = emp9 };
            RequisitionForm rq4 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd1.ToString("ddMMyy") + "/2", Employee = emp1, RFStatus = Enums.RFStatus.Submitted, RFDate = dd1
            };
            RequisitionForm rq5 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd2.ToString("ddMMyy") + "/2", Employee = emp1, RFStatus = Enums.RFStatus.Submitted, RFDate = dd2
            };

            db.Add(rq1);
            db.Add(rq2);
            //db.Add(rq3);
            db.Add(rq4);
            db.Add(rq5);



            RequisitionFormsProduct rq1_p1 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq1, Product = pr1, ProductRequested = 10, ProductApproved = 10
            };
            RequisitionFormsProduct rq1_p2 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq1, Product = pr2, ProductRequested = 10, ProductApproved = 10
            };
            RequisitionFormsProduct rq2_p1 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq2, Product = pr1, ProductRequested = 5, ProductApproved = 5
            };
            RequisitionFormsProduct rq2_p2 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq2, Product = pr2, ProductRequested = 3, ProductApproved = 2
            };
            //RequisitionFormsProduct rq3_p1 = new RequisitionFormsProduct() { RequisitionForm = rq3, Product = pr1, ProductRequested = 10, ProductApproved = 5 };
            //RequisitionFormsProduct rq3_p2 = new RequisitionFormsProduct() { RequisitionForm = rq3, Product = pr2, ProductRequested = 10, ProductApproved = 7 };
            RequisitionFormsProduct rq4_p1 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq1, Product = pr4, ProductRequested = 10, ProductApproved = 10
            };
            RequisitionFormsProduct rq5_p1 = new RequisitionFormsProduct()
            {
                RequisitionForm = rq1, Product = pr5, ProductRequested = 10, ProductApproved = 1
            };



            db.Add(rq1);
            db.Add(rq2);
            //db.Add(rq3);

            db.Add(rq1_p1);
            db.Add(rq1_p2);
            db.Add(rq2_p1);
            db.Add(rq2_p2);
            //db.Add(rq3_p1);
            //db.Add(rq3_p2);
            db.Add(rq4_p1);
            db.Add(rq5_p1);

            //db.SaveChanges();

            /*For Testing*/
            StationeryRetrieval sr1 = new StationeryRetrieval()
            {
                SRCode = "SR/" + dd1.ToString("ddMMyy") + "/1", SRStatus = Enums.SRStatus.PendingAssignment, SRComments = "Pending Assignment", SRDate = dd1, StoreClerk = emp1, WarehousePacker = emp7, SRRetrievalDate = dd2
            };
            StationeryRetrieval sr2 = new StationeryRetrieval()
            {
                SRCode = "SR/" + dd1.ToString("ddMMyy") + "/2", SRStatus = Enums.SRStatus.Assigned, SRComments = "Assigned", SRDate = dd1, StoreClerk = emp1, WarehousePacker = emp7, SRRetrievalDate = dd2, SRAssignedDate = dd13
            };

            //StationeryRetrieval sr3 = new StationeryRetrieval() { SRCode = "SR/" + dd1.ToString("ddMMyy") + "/3", SRStatus = Enums.SRStatus.Open, SRComments = "Open", SRDate = dd1, StoreClerk = emp1 };
            db.Add(sr1);
            db.Add(sr2);
            //db.Add(sr3);
            db.SaveChanges();

            StationeryRetrievalProduct srpr1 = new StationeryRetrievalProduct()
            {
                Product = pr1, ProductRequestedTotal = 5, StationeryRetrieval = sr1, ProductReceivedTotal = 4
            };
            StationeryRetrievalProduct srpr2 = new StationeryRetrievalProduct()
            {
                Product = pr2, ProductRequestedTotal = 10, StationeryRetrieval = sr1, ProductReceivedTotal = 10
            };
            StationeryRetrievalProduct srpr3 = new StationeryRetrievalProduct()
            {
                Product = pr1, ProductRequestedTotal = 5, StationeryRetrieval = sr2
            };
            StationeryRetrievalProduct srpr4 = new StationeryRetrievalProduct()
            {
                Product = pr2, ProductRequestedTotal = 10, StationeryRetrieval = sr2
            };

            db.Add(srpr1);
            db.Add(srpr2);
            db.Add(srpr3);
            db.Add(srpr4);
            //db.Add(srpr5);
            //db.Add(srpr6);
            db.SaveChanges();

            StationeryRetrievalRequisitionForm sr1_rf_1 = new StationeryRetrievalRequisitionForm()
            {
                RequisitionForm = rq1, SRRFStatus = Enums.SRRFStatus.PendingAssignment, StationeryRetrieval = sr1
            };
            StationeryRetrievalRequisitionForm sr1_rf_2 = new StationeryRetrievalRequisitionForm()
            {
                RequisitionForm = rq2, SRRFStatus = Enums.SRRFStatus.PendingAssignment, StationeryRetrieval = sr1
            };

            //StationeryRetrievalRequisitionForm sr2_rf_3 = new StationeryRetrievalRequisitionForm() { RequisitionForm = rq3, SRRFStatus = Enums.SRRFStatus.PendingAssignment, StationeryRetrieval = sr2 };
            db.Add(sr1_rf_1);
            db.Add(sr1_rf_2);
            //db.Add(sr2_rf_3);
            db.SaveChanges();

            StationeryRetrievalRequisitionFormProduct sr1_rf1_pr_1 = new StationeryRetrievalRequisitionFormProduct()
            {
                SR = sr1, RFP = rq1_p1
            };
            StationeryRetrievalRequisitionFormProduct sr1_rf1_pr_2 = new StationeryRetrievalRequisitionFormProduct()
            {
                SR = sr1, RFP = rq1_p2
            };
            StationeryRetrievalRequisitionFormProduct sr1_rf2_pr_1 = new StationeryRetrievalRequisitionFormProduct()
            {
                SR = sr1, RFP = rq2_p1
            };
            StationeryRetrievalRequisitionFormProduct sr1_rf2_pr_2 = new StationeryRetrievalRequisitionFormProduct()
            {
                SR = sr1, RFP = rq2_p2
            };

            //StationeryRetrievalRequisitionFormProduct sr1_rf3_pr_1 = new StationeryRetrievalRequisitionFormProduct() { SR = sr1, RFP = rq3_p2 };

            db.Add(sr1_rf1_pr_1);
            db.Add(sr1_rf1_pr_2);
            db.Add(sr1_rf2_pr_1);
            db.Add(sr1_rf2_pr_2);

            db.SaveChanges();
            /*End For Testing*/



            //Testing for RequisitionFormDisplay

            DateTime dd5 = new DateTime(2020, 8, 10, 8, 30, 20);
            DateTime dd6 = new DateTime(2020, 8, 11, 8, 30, 20);
            DateTime dd7 = new DateTime(2020, 8, 10, 8, 30, 20);

            string filePath5              = Path.Combine(uploads, "RequisitionForm.csv");
            string jsonString5            = ReadCSVFileUtil.ReadCSVFile(filePath5);
            List <CSVRequisitionForm> rfs = (List <CSVRequisitionForm>)JsonConvert.DeserializeObject(jsonString5, (typeof(List <CSVRequisitionForm>)));

            rfService.SaveRFFromCSV(rfs);

            RequisitionForm rq6 = new RequisitionForm()
            {
                RFCode = "RF/" + emp1.Department.DeptCode + "/" + dd5.ToString("ddMMyy") + "/1", Employee = emp1, RFStatus = Enums.RFStatus.NotCompleted, RFDate = dd5, RFApprovalDate = dd6, RFApprovalBy = emp9
            };
            RequisitionFormsProduct rfp1 = new RequisitionFormsProduct()
            {
                Product = pr1, ProductRequested = 10, RequisitionForm = rq6, ProductCollectedTotal = 9, ProductApproved = 10
            };
            RequisitionFormsProduct rfp2 = new RequisitionFormsProduct()
            {
                Product = pr2, ProductRequested = 20, RequisitionForm = rq6, ProductCollectedTotal = 7, ProductApproved = 10
            };

            db.Add(rq6);
            db.Add(rfp1);
            db.Add(rfp2);

            DisbursementForm df1 = new DisbursementForm()
            {
                CollectionPoint = cp1, DFCode = "DF/" + emp2.Department.DeptCode + "/" + dd1.ToString("ddMMyy") + "/1", DeptRep = emp2, StoreClerk = emp4, DFDeliveryDate = dd2, DFStatus = Enums.DFStatus.Created, DFDate = dd1
            };
            DisbursementForm df2 = new DisbursementForm()
            {
                CollectionPoint = cp2, DFCode = "DF/" + emp2.Department.DeptCode + "/" + dd1.ToString("ddMMyy") + "/2", DeptRep = emp2, StoreClerk = emp4, DFDeliveryDate = dd2, DFStatus = Enums.DFStatus.Completed, DFDate = dd1
            };
            DisbursementFormRequisitionForm dfrf1 = new DisbursementFormRequisitionForm()
            {
                DisbursementForm = df1, DFRFStatus = Enums.DFRFStatus.Assigned, RequisitionForm = rq1
            };
            DisbursementFormRequisitionForm dfrf2 = new DisbursementFormRequisitionForm()
            {
                DisbursementForm = df1, DFRFStatus = Enums.DFRFStatus.Assigned, RequisitionForm = rq2
            };
            DisbursementFormRequisitionFormProduct dfrfp1 = new DisbursementFormRequisitionFormProduct()
            {
                DisbursementForm = df1, RequisitionFormsProduct = rfp1, ProductCollected = 9
            };
            DisbursementFormRequisitionFormProduct dfrfp2 = new DisbursementFormRequisitionFormProduct()
            {
                DisbursementForm = df1, RequisitionFormsProduct = rfp2, ProductCollected = 7
            };

            db.Add(df1);
            db.Add(df2);
            db.Add(dfrf1);
            db.Add(dfrf2);
            db.Add(dfrfp1);
            db.Add(dfrfp2);
            db.SaveChanges();

            //DisbursementFormRequisitionForm dfrf3 = new DisbursementFormRequisitionForm() { DFRFStatus = Enums.DFRFStatus.PendingDelivery, DisbursementForm = df1, RequisitionForm = rq1 };
            //DisbursementFormRequisitionForm dfrf4 = new DisbursementFormRequisitionForm() { DFRFStatus = Enums.DFRFStatus.PendingDelivery, DisbursementForm = df1, RequisitionForm = rq2 };
            //db.Add(dfrf3);
            //db.Add(dfrf4);
            db.SaveChanges();
            DisbursementFormProduct dfp1 = new DisbursementFormProduct()
            {
                DisbursementForm = df1, Product = pr1, ProductToDeliverTotal = 10
            };
            DisbursementFormProduct dfp2 = new DisbursementFormProduct()
            {
                DisbursementForm = df1, Product = pr2, ProductToDeliverTotal = 40
            };

            db.Add(dfp1);
            db.Add(dfp2);
            db.SaveChanges();


            Supplier sup1  = db.Suppliers.Find(1);
            Supplier sup2  = db.Suppliers.Find(2);
            Supplier sup3  = db.Suppliers.Find(3);
            Supplier sup4  = db.Suppliers.Find(4);
            Supplier sup5  = db.Suppliers.Find(5);
            Supplier sup6  = db.Suppliers.Find(6);
            Supplier sup7  = db.Suppliers.Find(7);
            Supplier sup8  = db.Suppliers.Find(8);
            Supplier sup9  = db.Suppliers.Find(9);
            Supplier sup10 = db.Suppliers.Find(10);
            Supplier sup11 = db.Suppliers.Find(11);
            Supplier sup12 = db.Suppliers.Find(12);
            Supplier sup13 = db.Suppliers.Find(13);
            Supplier sup14 = db.Suppliers.Find(14);
            Supplier sup15 = db.Suppliers.Find(15);
            Supplier sup16 = db.Suppliers.Find(16);
            Supplier sup17 = db.Suppliers.Find(17);
            Supplier sup18 = db.Suppliers.Find(18);
            Supplier sup19 = db.Suppliers.Find(19);
            Supplier sup20 = db.Suppliers.Find(20);

            //db.Add(sup1);
            //db.Add(sup2);
            //db.Add(sup3);
            //db.Add(sup4);
            db.SaveChanges();

            DateTime dd8  = new DateTime(2020, 8, 10, 8, 30, 20);
            DateTime dd9  = new DateTime(2020, 8, 22, 8, 30, 20);
            DateTime dd10 = new DateTime(2020, 7, 10, 8, 40, 20);
            DateTime dd11 = new DateTime(2020, 9, 12, 8, 30, 20);
            DateTime dd12 = new DateTime(2020, 9, 13, 9, 30, 20);

            SupplierProduct sp1 = db.SupplierProducts.Find(1);
            SupplierProduct sp2 = db.SupplierProducts.Find(6);
            SupplierProduct sp3 = db.SupplierProducts.Find(3);
            SupplierProduct sp4 = db.SupplierProducts.Find(4);

            //db.Add(sp1);
            //db.Add(sp2);
            //db.Add(sp3);
            //db.Add(sp4);
            db.SaveChanges();

            PurchaseOrder po1 = new PurchaseOrder()
            {
                supplier = sup1, DeliverTo = "Logic University - Store", expectedDeliveryDate = dd9, IssuedBy = emp7, POStatus = Enums.POStatus.Issued, POComments = "Order affected by COVID", POCode = "PO/" + dd8.ToString("ddMMyy") + "/1", POIssueDate = dd8
            };
            PurchaseOrder po2 = new PurchaseOrder()
            {
                supplier = sup2, DeliverTo = "Logic University - Store", expectedDeliveryDate = dd11, IssuedBy = emp7, POStatus = Enums.POStatus.Completed, POComments = "Some Items may be out of stock", POCode = "PO/" + dd10.ToString("ddMMyy") + "/1", POIssueDate = dd10
            };
            PurchaseOrder po3 = new PurchaseOrder()
            {
                supplier = sup2, DeliverTo = "Logic University - Store", expectedDeliveryDate = dd12, IssuedBy = emp7, POStatus = Enums.POStatus.NotCompleted, POComments = "Urgent", POCode = "PO/" + dd10.ToString("ddMMyy") + "/2", POIssueDate = dd10
            };

            db.Add(po1);
            db.Add(po2);
            db.Add(po3);


            PurchaseOrderSupplierProduct posr1 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp1, POQuantityRequested = 10, POUnitPrice = sp1.ProductPrice, PurchaseOrder = po1
            };
            PurchaseOrderSupplierProduct posr2 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp2, POQuantityRequested = 15, POUnitPrice = sp2.ProductPrice, PurchaseOrder = po1
            };
            PurchaseOrderSupplierProduct posr3 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp3, POQuantityRequested = 5, POUnitPrice = sp3.ProductPrice, PurchaseOrder = po1
            };

            PurchaseOrderSupplierProduct posr4 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp1, POQuantityRequested = 3, POUnitPrice = sp1.ProductPrice, PurchaseOrder = po2
            };
            PurchaseOrderSupplierProduct posr5 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp2, POQuantityRequested = 5, POUnitPrice = sp2.ProductPrice, PurchaseOrder = po2
            };

            PurchaseOrderSupplierProduct posr6 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp3, POQuantityRequested = 3, POUnitPrice = sp3.ProductPrice, PurchaseOrder = po3
            };
            PurchaseOrderSupplierProduct posr7 = new PurchaseOrderSupplierProduct()
            {
                SupplierProduct = sp4, POQuantityRequested = 5, POUnitPrice = sp4.ProductPrice, PurchaseOrder = po3
            };

            db.Add(posr1);
            db.Add(posr2);
            db.Add(posr3);
            db.Add(posr4);
            db.SaveChanges();
            //--------------------------

            DeliveryOrder do2 = new DeliveryOrder()
            {
                DeliveryOrderNo = "D0121567", DOReceivedDate = dd11, PurchaseOrder = po2, Supplier = sup1, DOCode = "DO/" + dd11.ToString("ddMMyy") + "/1", ReceivedBy = emp7
            };
            DeliveryOrder do3 = new DeliveryOrder()
            {
                DeliveryOrderNo = "D011267", DOReceivedDate = dd12, PurchaseOrder = po3, Supplier = sup2, DOCode = "DO/" + dd12.ToString("ddMMyy") + "/1", ReceivedBy = emp7
            };

            db.Add(do2);
            db.Add(do3);
            db.SaveChanges();

            DeliveryOrderSupplierProduct dosr4 = new DeliveryOrderSupplierProduct()
            {
                PurchaseOrderSupplierProduct = posr4, DOQuantityReceived = 3, DeliveryOrder = do2
            };
            DeliveryOrderSupplierProduct dosr5 = new DeliveryOrderSupplierProduct()
            {
                PurchaseOrderSupplierProduct = posr5, DOQuantityReceived = 5, DeliveryOrder = do2
            };

            DeliveryOrderSupplierProduct dosr6 = new DeliveryOrderSupplierProduct()
            {
                PurchaseOrderSupplierProduct = posr6, DOQuantityReceived = 3, DeliveryOrder = do3
            };
            DeliveryOrderSupplierProduct dosr7 = new DeliveryOrderSupplierProduct()
            {
                PurchaseOrderSupplierProduct = posr7, DOQuantityReceived = 3, DeliveryOrder = do3
            };

            db.Add(dosr4);
            db.Add(dosr5);
            db.Add(dosr6);
            db.Add(dosr7);

            DateTime dd19 = new DateTime(2020, 8, 15, 0, 0, 0);
            DateTime dd20 = new DateTime(2020, 9, 15, 0, 0, 0);
            DateTime dd21 = new DateTime(2020, 7, 15, 10, 10, 0);

            DateTime dd22 = new DateTime(2020, 10, 15, 0, 0, 0);
            DateTime dd23 = new DateTime(2020, 11, 15, 0, 0, 0);


            DelegationForm delForm1 = new DelegationForm()
            {
                startDate       = dd19,
                endDate         = dd20,
                delegateComment = "Hello There",
                Delegatee       = emp10,
                DelegatedType   = empType8,
                DepartmentHead  = emp9,
                DLAssignedDate  = dd21,
                DLStatus        = Enums.DLStatus.Ongoing
            };

            DelegationForm delForm2 = new DelegationForm()
            {
                startDate       = dd22,
                endDate         = dd23,
                delegateComment = "Hello There",
                Delegatee       = emp10,
                DelegatedType   = empType8,
                DepartmentHead  = emp9,
                DLAssignedDate  = dd21,
                DLStatus        = Enums.DLStatus.Assigned
            };

            //DelegationForm delForm3 = new DelegationForm()
            //{
            //    startDate = dd22,
            //    endDate = dd23,
            //    delegateComment = "Hello There",
            //    Delegatee = emp10,
            //    DelegatedType = empType6,
            //    DepartmentHead = emp9,
            //    DLAssignedDate = dd21,
            //    DLStatus = Enums.DLStatus.Assigned
            //};

            db.Add(delForm1);
            db.Add(delForm2);

            db.SaveChanges();
        }
Esempio n. 16
0
        public bool saveReceivedProds3(List <StationeryRetrievalProduct> srpList,
                                       int SRid,
                                       Employee warehousepacker,
                                       Employee storeclerk,
                                       List <StationeryRetrievalRequisitionForm> srrfList)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())
            {
                try
                {
                    //Check for store clerk and warehouse packer
                    Employee _whpacker = empService.FindByUsernameAndPassword(warehousepacker.Username.ToLower(), warehousepacker.Password);
                    Employee _stclerk  = empService.FindByUsernameAndPassword(storeclerk.Username.ToLower(), storeclerk.Password);

                    if (_whpacker.EmployeeType.EmployeeTypeName != "Warehouse Packer")
                    {
                        throw new Exception("The user type is wrong");
                    }

                    if (_stclerk.EmployeeType.EmployeeTypeName != "Store Clerk" && _stclerk.EmployeeType.EmployeeTypeName != "Store Supervisor" && _stclerk.EmployeeType.EmployeeTypeName != "Store Manager")
                    {
                        throw new Exception("The user type is wrong");
                    }

                    if (_whpacker == null || _stclerk == null)
                    {
                        throw new Exception("The username or password is wrong, please login again");
                    }

                    DateTime transactDate = DateTime.Now;

                    //Create RF List
                    List <RequisitionForm> _rfList = new List <RequisitionForm>();

                    //Create new empty list to save to db
                    List <StationeryRetrievalProduct> _srpList = new List <StationeryRetrievalProduct>();

                    //Create new empty list to save to db
                    List <StationeryRetrievalRequisitionForm> _srrfList = new List <StationeryRetrievalRequisitionForm>();

                    //Find sr
                    StationeryRetrieval _sr = db.StationeryRetrievals.Find(SRid);
                    _sr.SRStatus        = SRStatus.PendingAssignment;
                    _sr.WarehousePacker = _whpacker;
                    _sr.SRRetrievalDate = transactDate;
                    _sr.StoreClerk      = _stclerk;
                    db.StationeryRetrievals.Update(_sr);
                    db.SaveChanges();



                    //Define invtrans Code
                    int count = invtService.FindInvTransByTodayCount();

                    foreach (StationeryRetrievalProduct srp in srpList)
                    {
                        if (srp.ProductReceivedTotal < 0)
                        {
                            throw new Exception("This value should not be negative");
                        }

                        count++;

                        StationeryRetrievalProduct _srp = db.StationeryRetrievalProduct.Find(srp.Id);
                        _srp.ProductReceivedTotal = srp.ProductReceivedTotal;
                        _srpList.Add(_srp);
                        db.StationeryRetrievalProduct.Update(_srp);
                        db.SaveChanges();

                        //Check for logic in terms of each RFP should not have more than what was specified


                        //create itCode
                        string invtransCode = "IT" + "/" + DateTime.Now.ToString("ddMMyy") + "/" + count.ToString();

                        //Create It
                        InventoryTransaction _it = new InventoryTransaction()
                        {
                            EmployeeId = _sr.StoreClerk.Id,
                            ProductId  = _srp.Product.Id,
                            Employee   = _sr.StoreClerk,
                            InventoryChangeQuantity = -_srp.ProductReceivedTotal,
                            InventoryTransComments  = _sr.SRCode,
                            InventoryTransDate      = _sr.SRRetrievalDate,
                            ITStatus = ITStatus.Auto,
                            ITCode   = invtransCode,
                            Product  = _srp.Product
                        };

                        db.InventoryTransactions.Add(_it);
                        db.SaveChanges();



                        //Adjust Inventory Quantity
                        Product _p = db.Products.Find(_srp.Product.Id);
                        _p.InventoryQuantity = _p.InventoryQuantity + _it.InventoryChangeQuantity;
                        if (_p.InventoryQuantity < 0)
                        {
                            throw new Exception(_p.InventoryQuantity + " is not enough");
                        }
                        db.Products.Update(_p);
                        db.SaveChanges();
                    }

                    foreach (StationeryRetrievalRequisitionForm srrf in srrfList)
                    {
                        StationeryRetrievalRequisitionForm _srrf = db.StationeryRetrievalRequisitionForms.Find(srrf.Id);
                        _srrf.SRRFStatus = SRRFStatus.PendingAssignment;
                        db.StationeryRetrievalRequisitionForms.Update(_srrf);
                        db.SaveChanges();

                        RequisitionForm _rf = db.RequisitionForms.Find(_srrf.RequisitionForm.Id);
                        _rf.RFStatus = RFStatus.Ongoing;

                        db.RequisitionForms.Update(_rf);
                        db.SaveChanges();
                    }
                    db.SaveChanges();

                    transcat.Commit();
                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }
Esempio n. 17
0
        public bool SaveStationaryRetrievalProducts(List <SRProductViewModel> productlist, Employee emp, string comment, List <int> selectedrequisiton, List <StationeryRetrievalProduct> srpList)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())

            {
                try
                {
                    Employee _emp = db.Employees.Find(emp.Id);
                    List <RequisitionForm> rfList = FindRFListByRF(selectedrequisiton);

                    //Create empty srrfList
                    List <StationeryRetrievalRequisitionForm> _srrfList = new List <StationeryRetrievalRequisitionForm>();

                    //Create empty rfpList
                    List <RequisitionFormsProduct> _rfpList = new List <RequisitionFormsProduct>();

                    //Create empty srrfpList
                    List <StationeryRetrievalRequisitionFormProduct> _srrfpList = new List <StationeryRetrievalRequisitionFormProduct>();

                    //Create empty srpList
                    List <StationeryRetrievalProduct> _srpList = new List <StationeryRetrievalProduct>();

                    //Find the list of rfs on that day by the same employee
                    int count = FindStationaryRetrievalFormByDeptTodayCount(_emp) + 1;
                    //Define RF Code
                    string srfCode = "SR" + "/" + DateTime.Now.ToString("ddMMyy") + "/" + count.ToString();

                    //Create New SRF and SRFP

                    //DateTime ddToday = DateTime.Now;
                    StationeryRetrieval srfForm = new StationeryRetrieval()
                    {
                        StoreClerk = _emp,
                        SRCode     = srfCode,
                        SRStatus   = SRStatus.Open,
                        SRComments = comment,
                        SRDate     = DateTime.Now
                    };

                    db.StationeryRetrievals.Add(srfForm);
                    db.SaveChanges();

                    foreach (RequisitionForm rf in rfList)
                    {
                        StationeryRetrievalRequisitionForm _srrf = new StationeryRetrievalRequisitionForm()
                        {
                            StationeryRetrieval = srfForm,
                            RequisitionForm     = rf,
                            SRRFStatus          = SRRFStatus.Open
                        };
                        db.Add(_srrf);
                        _srrfList.Add(_srrf);
                        db.SaveChanges();

                        List <RequisitionFormsProduct> individualrfpList = db.RequisitionFormsProducts
                                                                           .Where(x => x.RequisitionForm == rf)
                                                                           .ToList();
                        foreach (RequisitionFormsProduct individualrfp in individualrfpList)
                        {
                            _rfpList.Add(individualrfp);
                        }
                    }

                    foreach (RequisitionFormsProduct _rfp in _rfpList)
                    {
                        StationeryRetrievalRequisitionFormProduct _srrfp = new StationeryRetrievalRequisitionFormProduct()
                        {
                            SR              = srfForm,
                            RFP             = _rfp,
                            ProductAssigned = 0
                        };
                        _srrfpList.Add(_srrfp);
                        db.Add(_srrfp);
                        db.SaveChanges();
                    }

                    if (productlist == null)
                    {
                        throw new Exception("No products to be stored as a Stationary Retrieval Form");
                    }
                    else
                    {
                        foreach (SRProductViewModel p in productlist)
                        {
                            Product product = db.Products.Where(x => x.ProductName == p.productname).FirstOrDefault();

                            StationeryRetrievalProduct _srfProduct = new StationeryRetrievalProduct();
                            _srfProduct.StationeryRetrieval   = srfForm;
                            _srfProduct.Product               = product;
                            _srfProduct.ProductRequestedTotal = p.productqty;
                            db.StationeryRetrievalProduct.Add(_srfProduct);
                            db.SaveChanges();
                        }
                        foreach (var requ_id in selectedrequisiton)
                        {
                            RequisitionForm requform = db.RequisitionForms.Where(x => x.Id == requ_id).FirstOrDefault();
                            requform.RFStatus = RFStatus.Ongoing;
                            db.SaveChanges();
                        }
                    }

                    transcat.Commit();
                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }
Esempio n. 18
0
        public IHttpActionResult SetRetrievalList(SetStationeryRetrievalApiModel apiModelToSet)
        {
            //remove entries that are ignored
            apiModelToSet.ApiModelList.RemoveAll(m => m.NewQuantity == 0 && m.Remarks == "");

            //This controller method will generate stationery retrieval, disbursement, stock adjustment
            string currentUserId  = User.Identity.GetUserId();
            string newRetrievalId = GenerateRetrievalId();
            //create a new stationery retrieval with pending delivery
            StationeryRetrieval retrievalInDb = new StationeryRetrieval
            {
                RetrievalId = newRetrievalId,
                RetrievedBy = apiModelToSet.UserId,
                Date        = DateTime.Today,
            };

            _context.StationeryRetrieval.Add(retrievalInDb);
            _context.SaveChanges();

            int newTransactionId = GenerateTransactionDetailId() - 1;//-1 to get last value, id will be increased in foreach loop
            //check if there is need to raise a stock adjustment, put to list to get total of each item and compare with warehouse
            string        newStockAdjustmentId = GenerateStockAdjustmentId();
            List <string> items = apiModelToSet.ApiModelList.Select(m => m.ItemId).Distinct().ToList();
            Dictionary <string, StockAdjustmentValidate> stockAdjustmentDict = new Dictionary <string, StockAdjustmentValidate>();

            foreach (string item in items)
            {
                stockAdjustmentDict.Add(item, new StockAdjustmentValidate());
            }

            foreach (StationeryRetrievalApiModel current in apiModelToSet.ApiModelList)
            {
                stockAdjustmentDict[current.ItemId].RequestedQty += current.NeededQuantity.GetValueOrDefault();
                stockAdjustmentDict[current.ItemId].RetrievedQty += current.NewQuantity.GetValueOrDefault();
                stockAdjustmentDict[current.ItemId].WarehouseQty  = _context.Stationery.Where(m => m.ItemId == current.ItemId).Select(m => m.QuantityWarehouse).FirstOrDefault();
                stockAdjustmentDict[current.ItemId].Remarks      += current.Remarks;
            }

            bool stockAdjustmentRequired = false;

            foreach (KeyValuePair <string, StockAdjustmentValidate> currentValidate in stockAdjustmentDict)
            {
                //check retrieved<requested and retrieved!=warehouse qty, means there are damaged item, will automatically raise stock adjustment
                if (currentValidate.Value.RetrievedQty < currentValidate.Value.RequestedQty &&
                    currentValidate.Value.RetrievedQty != currentValidate.Value.WarehouseQty)
                {
                    //check if there are any stock adjustment raised, if yes it will skip as to prevent double raise
                    bool existingItemYetApproved = false;
                    List <StockAdjustment> stockAdjustmentNotApproved = _context.StockAdjustment.Where(m => m.ApprovedBy == null).ToList();
                    foreach (StockAdjustment current in stockAdjustmentNotApproved)
                    {
                        foreach (TransactionDetail subDetail in current.TransactionDetail)
                        {
                            if (subDetail.ItemId == currentValidate.Key)
                            {
                                existingItemYetApproved = true;
                                break;
                            }
                        }

                        if (existingItemYetApproved == true)
                        {
                            newTransactionId += 1;
                        }
                        break;
                    }

                    //create a stock adjustment if item does not have a stock adjustment
                    if (existingItemYetApproved == false)
                    {
                        newTransactionId += 1;
                        TransactionDetail transactionStockAdjustmentInDb = new TransactionDetail
                        {
                            TransactionId   = newTransactionId,
                            ItemId          = currentValidate.Key,
                            Quantity        = currentValidate.Value.RetrievedQty - currentValidate.Value.WarehouseQty,
                            Remarks         = currentValidate.Value.Remarks.IsNullOrWhiteSpace() ? "Stock adjustment from Mobile" : currentValidate.Value.Remarks,
                            TransactionRef  = newStockAdjustmentId,
                            TransactionDate = DateTime.Now,
                            UnitPrice       = _context.Stationery.FirstOrDefault(m => m.ItemId == currentValidate.Key).FirstSuppPrice,
                        };
                        _context.TransactionDetail.Add(transactionStockAdjustmentInDb);
                        _context.SaveChanges();
                        stockAdjustmentRequired = true;
                    }
                }
            }

            if (stockAdjustmentRequired)
            {
                StockAdjustment stockAdjustmentInDb = new StockAdjustment
                {
                    StockAdjId = newStockAdjustmentId,
                    PreparedBy = currentUserId,
                    Remarks    = "Damage",
                    Date       = DateTime.Now
                };
                _context.StockAdjustment.Add(stockAdjustmentInDb);
                _context.SaveChanges();
            }

            //preparing for disbursement
            List <string> departmentId = apiModelToSet.ApiModelList.Select(m => m.DepartmentId).Distinct().ToList();
            Dictionary <string, List <TransactionDetail> > keyTransactionList = new Dictionary <string, List <TransactionDetail> >();

            foreach (string depId in departmentId)
            {
                keyTransactionList.Add(depId, new List <TransactionDetail>());
            }

            foreach (StationeryRetrievalApiModel current in apiModelToSet.ApiModelList)
            {
                newTransactionId += 1;
                //create stationery TransactionDetail for retrieval
                TransactionDetail transactionInDb = new TransactionDetail
                {
                    TransactionId   = newTransactionId,
                    ItemId          = current.ItemId,
                    Quantity        = current.NewQuantity.GetValueOrDefault(),
                    Remarks         = "Retrieved",
                    TransactionRef  = newRetrievalId,
                    TransactionDate = DateTime.Now,
                    UnitPrice       = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId).FirstSuppPrice,
                };
                _context.TransactionDetail.Add(transactionInDb);
                _context.SaveChanges();

                //minus the quantity from stock and put it to in transit
                Stationery stationeryInDb = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId);
                stationeryInDb.QuantityWarehouse -= transactionInDb.Quantity;
                stationeryInDb.QuantityTransit   += transactionInDb.Quantity;

                ////calculate amount of stock to raise less the amount pending approval
                //int quantityPendingApproval = _context.TransactionDetail.Where(m =>
                //        m.TransactionRef.StartsWith("SAD-") && m.StockAdjustment.ApprovedBy.IsNullOrWhiteSpace())
                //    .Sum(m => m.Quantity);

                ////automatically raise stock adjustment if quantity different
                //if (current.NewQuantity != current.NeededQuantity)
                //{
                //    newTransactionId += 1;
                //    TransactionDetail transactionStockAdjustmentInDb = new TransactionDetail
                //    {
                //        TransactionId = newTransactionId,
                //        ItemId = current.ItemId,
                //        Quantity = current.NewQuantity.GetValueOrDefault()-stationeryInDb.QuantityWarehouse+quantityPendingApproval,
                //        Remarks = current.Remarks.IsNullOrWhiteSpace()?"Stock adjustment from Mobile":current.Remarks,
                //        TransactionRef = newStockAdjustmentId,
                //        TransactionDate = DateTime.Now,
                //        UnitPrice = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId).FirstSuppPrice,
                //    };
                //    _context.TransactionDetail.Add(transactionStockAdjustmentInDb);
                //    _context.SaveChanges();
                //}

                //issue a disbursement with status in transit
                //for disbursement (transaction ref not initialized yet
                newTransactionId += 1;
                TransactionDetail transactionDisbursementInDb = new TransactionDetail
                {
                    TransactionId   = newTransactionId,
                    ItemId          = current.ItemId,
                    Quantity        = current.NewQuantity.GetValueOrDefault(),
                    Remarks         = "In Transit",
                    TransactionDate = DateTime.Now,
                    UnitPrice       = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId).FirstSuppPrice,
                };
                keyTransactionList[current.DepartmentId].Add(transactionDisbursementInDb);
            }

            int newDisbIdWithoutPrefixInt = GenerateDisbursementIdSuffixOnly() - 1; //-1 to prepare for for loop, will + 1 for each loop
            int newDisbNoWithoutPrefixInt = GenerateDisbursementNoSuffixOnly() - 1; //-1 to prepare for for loop, will + 1 for each loop

            foreach (KeyValuePair <string, List <TransactionDetail> > pair in keyTransactionList)
            {
                //getting disbursementId
                newDisbIdWithoutPrefixInt += 1;
                string newDisbursementIdWithoutPrefixString = newDisbIdWithoutPrefixInt.ToString().PadLeft(6, '0');
                string disbursementId = "DISB" + newDisbursementIdWithoutPrefixString;

                //getting disbursementNo
                newDisbNoWithoutPrefixInt += 1;
                string            newDisbursementNoWithoutPrefixString = newDisbNoWithoutPrefixInt.ToString().PadLeft(5, '0');
                string            disbursementNo = "D" + pair.Key + newDisbursementNoWithoutPrefixString;
                StationeryRequest requestLinked  = _context.StationeryRequest.OrderByDescending(m => m.RequestId)
                                                   .FirstOrDefault(m => m.Status == "Pending Disbursement" || m.Status == "Partially Fulfilled");
                Disbursement disbursementInDb = new Disbursement
                {
                    DisbursementId = disbursementId,
                    DisbursementNo = disbursementNo,
                    DepartmentId   = pair.Key,
                    AcknowledgedBy = null,
                    DisbursedBy    = currentUserId,
                    Date           = DateTime.Now,
                    RequestId      = requestLinked.RequestId,
                    Status         = "In Transit",
                    OTP            = GenerateOTP()
                };
                _context.Disbursement.Add(disbursementInDb);
                _context.SaveChanges();

                //emailing the disbursement to department rep
                //string depRepEmail = _context.Department.FirstOrDefault(m => m.DepartmentId == pair.Key).AspNetUsers1.Email;
                string recipient = "*****@*****.**"; //dummy email used
                string title     = "Disbursement is scheduled on " + requestLinked.CollectionDate;
                string body      = "The Stationery Request " + requestLinked.RequestId + " will be issued on " +
                                   requestLinked.CollectionDate + ". Kindly use the OTP " + disbursementInDb.OTP +
                                   " to retrieve it.";
                Email.Send(recipient, title, body);

                for (int i = 0; i < pair.Value.Count; i++)
                {
                    pair.Value[i].TransactionRef = disbursementId;
                }

                _context.TransactionDetail.AddRange(pair.Value);
                _context.SaveChanges();
            }

            //changing stationery records that matches to In Transit
            List <StationeryRequest> partiallyAndPendingRequest =
                _context.StationeryRequest.Where(m => m.Status == "Partially Fulfilled" || m.Status == "Pending Disbursement").ToList();

            for (int i = 0; i < apiModelToSet.ApiModelList.Count; i++)
            {
                for (int j = 0; j < partiallyAndPendingRequest.Count; j++)
                {
                    for (int k = 0; k < partiallyAndPendingRequest[j].TransactionDetail.Count; k++)
                    {
                        if (apiModelToSet.ApiModelList[i].DepartmentId == partiallyAndPendingRequest[j].DepartmentId && apiModelToSet.ApiModelList[i].ItemId == partiallyAndPendingRequest[j].TransactionDetail.ElementAt(k).ItemId)
                        {
                            string            affectedStationeryRequestId = partiallyAndPendingRequest[j].RequestId;
                            StationeryRequest stationeryRequestedToModify =
                                _context.StationeryRequest.FirstOrDefault(m =>
                                                                          m.RequestId == affectedStationeryRequestId);
                            stationeryRequestedToModify.Status = "In Transit";
                            _context.SaveChanges();
                        }
                    }
                }
            }
            //foreach (StationeryRetrievalApiModel apiModel in apiModelToSet.ApiModelList)
            //{
            //    foreach (StationeryRequest stationeryRequest in partiallyAndPendingRequest)
            //    {
            //        foreach (TransactionDetail transactionDetail in stationeryRequest.TransactionDetail)
            //        {
            //            apiModelToSet.ApiModelList[i].DepartmentId == quest.DepartmentId && apiModel.ItemId == transactionDetail.ItemId)
            //            stationeryRequest
            //        }
            //    }
            //}

            //Email the clerk if item is below reorder level
            foreach (StationeryRetrievalApiModel current in apiModelToSet.ApiModelList)
            {
                Stationery stationery = _context.Stationery.FirstOrDefault(m => m.ItemId == current.ItemId);
                if (stationery.QuantityWarehouse < stationery.ReorderQuantity)
                {
                    string recipient = "*****@*****.**";
                    string title     = "Item " + stationery.Description + " needs to be ordered";
                    string body      = "The current item quantity is less than reorder level of " +
                                       stationery.ReorderQuantity + ". Kindly restock the supplies.";
                    Email.Send(recipient, title, body);
                }
            }
            return(Ok());
        }
Esempio n. 19
0
        public bool SetProductsAssignedInSR(int SRId,
                                            List <StationeryRetrievalRequisitionFormProduct> srrfpList,
                                            List <StationeryRetrievalProduct> srpList,
                                            List <StationeryRetrievalRequisitionForm> srrfList)
        {
            using (IDbContextTransaction transcat = db.Database.BeginTransaction())
            {
                try
                {
                    DateTime assignDate = DateTime.Now;
                    Dictionary <int, int> _prodCountCheckDict = new Dictionary <int, int>();

                    //Find SR
                    StationeryRetrieval _sr = db.StationeryRetrievals.Find(SRId);

                    //Find SRPList through db
                    List <StationeryRetrievalProduct> _srpList = new List <StationeryRetrievalProduct>();

                    //Find SRRFList through db
                    List <StationeryRetrievalRequisitionForm> _srrfList = new List <StationeryRetrievalRequisitionForm>();

                    //Find pList through db
                    List <Product> _pList = new List <Product>();

                    //Find pList through db
                    List <RequisitionForm> _rfList = new List <RequisitionForm>();

                    //Find rfpList through db
                    List <RequisitionFormsProduct> _rfpList = new List <RequisitionFormsProduct>();

                    //Find SRRFPList THROUGH db
                    List <StationeryRetrievalRequisitionFormProduct> _srrfpList = new List <StationeryRetrievalRequisitionFormProduct>();

                    foreach (StationeryRetrievalProduct srp in srpList)
                    {
                        StationeryRetrievalProduct _srp = db.StationeryRetrievalProduct.Find(srp.Id);
                        _srp.ProductReceivedTotal = _srp.ProductReceivedTotal;
                        _srpList.Add(_srp);
                        _pList.Add(_srp.Product);
                    }

                    foreach (StationeryRetrievalRequisitionForm srrf in srrfList)
                    {
                        StationeryRetrievalRequisitionForm _srrf = db.StationeryRetrievalRequisitionForms.Find(srrf.Id);
                        _srrfList.Add(_srrf);
                        _rfList.Add(_srrf.RequisitionForm);
                    }

                    foreach (StationeryRetrievalRequisitionFormProduct srrfp in srrfpList)
                    {
                        if (srrfp.ProductAssigned < 0)
                        {
                            throw new Exception("You cannot assign less than 0");
                        }
                        StationeryRetrievalRequisitionFormProduct _srrfp = db.StationeryRetrievalRequisitionFormProducts.Find(srrfp.Id);
                        if (_srrfp.RFP.ProductBalanceForSR < _srrfp.ProductAssigned)
                        {
                            throw new Exception("You cannot have a value less than the productApproved");
                        }
                        ;
                        _srrfpList.Add(_srrfp);
                    }

                    foreach (RequisitionForm _rf in _rfList)
                    {
                        List <RequisitionFormsProduct> _rfpIndividualList = db.RequisitionFormsProducts
                                                                            .Where(x => x.RequisitionForm == _rf)
                                                                            .ToList();
                        foreach (RequisitionFormsProduct _rfpIndividual in _rfpIndividualList)
                        {
                            _rfpList.Add(_rfpIndividual);
                        }
                    }



                    //Assign Dictionary
                    for (int i = 0; i < _srpList.Count; i++)
                    {
                        int p = _srpList[i].Product.Id;
                        _prodCountCheckDict[p] = 0;
                    }

                    //Update Dict Value for Checking
                    for (int i = 0; i < _srrfpList.Count; i++)
                    {
                        int p2 = _srrfpList[i].RFP.Product.Id;
                        //Check total quantity collected is the same as quantity assigned
                        _prodCountCheckDict[p2] = _prodCountCheckDict[p2] + srrfpList[i].ProductAssigned;
                        Debug.WriteLine(_srrfpList[i].RFP.Product.Id + ": " + _prodCountCheckDict[p2]);
                    }

                    //This is to check if the value received is the sme as the value that is assigned.
                    foreach (KeyValuePair <int, int> entry in _prodCountCheckDict)
                    {
                        for (int i = 0; i < _srpList.Count; i++)
                        {
                            if (entry.Key == _srpList[i].Product.Id)
                            {
                                if (entry.Value != _srpList[i].ProductReceivedTotal)
                                {
                                    throw new Exception("The quantity doesnt match");
                                }
                            }
                        }
                    }

                    //update SRP Quantity
                    foreach (StationeryRetrievalProduct _srp in _srpList)
                    {
                        db.StationeryRetrievalProduct.Update(_srp);
                        db.SaveChanges();
                    }

                    //Update SRRFP quantity
                    for (int i = 0; i < srrfpList.Count; i++)
                    {
                        StationeryRetrievalRequisitionFormProduct _srrfp = FindSRRFPById(srrfpList[i].Id);
                        _srrfp.ProductAssigned = srrfpList[i].ProductAssigned;
                        db.StationeryRetrievalRequisitionFormProducts.Update(_srrfp);
                        db.SaveChanges();
                    }

                    //Update SRRF Status
                    foreach (StationeryRetrievalRequisitionForm _srrf in _srrfList)
                    {
                        _srrf.SRRFStatus = SRRFStatus.Assigned;
                        db.Update(_srrf);
                        db.SaveChanges();
                    }

                    //foreach (RequisitionForm _rf in _rfList)
                    //{
                    //    _rf.RFStatus = RFStatus.NotCompleted;
                    //    db.RequisitionForms.Update(_rf);
                    //    db.SaveChanges();
                    //}

                    //Validation
                    foreach (RequisitionFormsProduct _rfp in _rfpList)
                    {
                        List <StationeryRetrievalRequisitionFormProduct> _srrfpCheckList = _srrfpList.Where(x => x.RFP == _rfp).ToList();
                        int sumofProd = _srrfpCheckList.Select(x => x.ProductAssigned).Sum();
                        if (_rfp.ProductApproved < sumofProd)
                        {
                            throw new Exception("Sum of Assigned Products exceeded ProductsApproved");
                        }
                        foreach (StationeryRetrievalRequisitionFormProduct _srrfp in _srrfpCheckList)
                        {
                            if (_rfp.Product.Id == _srrfp.RFP.Product.Id)
                            {
                                if (_rfp.ProductApproved < _rfp.ProductCollectedTotal + _srrfp.ProductAssigned)
                                {
                                    throw new Exception("Sum of Collected Products with Product Assigned is more than the Sum of the Assigned Products");
                                }
                            }
                        }
                    }

                    //Update SR Status
                    _sr.SRStatus       = SRStatus.Assigned;
                    _sr.SRAssignedDate = assignDate;
                    db.StationeryRetrievals.Update(_sr);
                    db.SaveChanges();

                    transcat.Commit();
                    return(true);
                }
                catch
                {
                    transcat.Rollback();
                    return(false);
                }
            }
        }