public RequisitionDetail(int id, Requisition requisitionId, Item itemId, int qty, int deliveredQty)
 {
     this.Id = id;
     this.Requisition = requisitionId;
     this.Item = itemId;
     this.Qty = qty;
     this.DeliveredQty = deliveredQty;
 }
        public RequestStationeryControl()
        {
            currentEmployee = Util.ValidateUser(Constants.EMPLOYEE_ROLE.EMPLOYEE);
            InventoryEntities inventory = new InventoryEntities();

            requisitionBroker = new RequisitionBroker(inventory);
            itemBroker = new ItemBroker(inventory);
            employeeBroker = new EmployeeBroker(inventory);

            requisition = new Requisition();
            requisition.CreatedBy = Util.GetEmployee(employeeBroker);
            requisition.Department = requisition.CreatedBy.Department;
            requisition.Status = Converter.objToInt(Constants.REQUISITION_STATUS.PENDING);
            requisition.Id = requisitionBroker.GetRequisitionId(requisition);

            itemAdded = 0;

            dataColumn = new DataColumn[] { new DataColumn(columnName[0]),
                                            new DataColumn(columnName[1]),
                                            new DataColumn(columnName[2]) };
        }
        //,Boolean isSaved)
        /// <summary>
        /// Logically delete the Requisition by setting the status to 2 in the Requisition table
        ///  Return Constants.DB_STATUS
        /// </summary>
        /// <param name="requisiton"></param>
        /// <returns></returns>
        public Constants.DB_STATUS Delete(Requisition requisiton)
        {
            Constants.DB_STATUS status = Constants.DB_STATUS.UNKNOWN;

            try
            {
                //requisitionObj = inventory.Requisitions.Where(reqObj => reqObj.Id == requisiton.Id).First();
                //requisitionObj.Id = requisiton.Id;
                //requisitionObj.ApprovedBy = requisiton.ApprovedBy;
                //requisitionObj.Id = requisiton.Id;
               // requisitionObj.Status = requisiton.Status;
                //requisitionObj.Status = 6;
                //if(isSaved) inventory.SaveChanges();
                inventory.SaveChanges();
                status = Constants.DB_STATUS.SUCCESSFULL;
            }
            catch (Exception e)
            {
                status = Constants.DB_STATUS.FAILED;
            }
            return status;
        }
        //, Boolean isSaved)
        /// <summary>
        /// Insert Requisition data to the Requisition Table according to the Requisition Parameter
        ///  Return Constants.DB_STATUS
        /// </summary>
        /// <param name="requisition"></param>
        /// <returns></returns>
        public Constants.DB_STATUS Insert(Requisition requisition)
        {
            Constants.DB_STATUS status = Constants.DB_STATUS.UNKNOWN;

            try
            {
                inventory.AddToRequisitions(requisition);
                //foreach (RequisitionDetail requisitionDetail in requisition.RequisitionDetails)
                //{
                //    this.Insert(requisitionDetail);
                //}
             //   if (isSaved) inventory.SaveChanges();//to add in all insert method
                inventory.SaveChanges();
                status = Constants.DB_STATUS.SUCCESSFULL;
            }
            catch (Exception e)
            {
                status = Constants.DB_STATUS.FAILED;
            }

            return status;
        }
 /// <summary>
 /// Retrieve the Requisition and RequisitionDetail information according to the Requisition Parameter 
 /// 
 /// </summary>
 /// <param name="requisition"></param>
 /// <returns></returns>
 public Requisition GetRequisition(Requisition requisition)
 {
     try
     {
         if (requisition.Status != 0)
         {
             int status = Converter.objToInt(requisition.Status);
             requisitionObj = inventory.Requisitions.Where(reqObj => reqObj.Id.Contains(requisition.Id) && reqObj.Status == status).First();
         }
         else
         {
             requisitionObj = inventory.Requisitions.Where(reqObj => reqObj.Id.Contains(requisition.Id)).First();
         }
     }
     catch (Exception e)
     {
         requisitionObj = null;
     }
     //if (!req.Equals(null))
     //{
     //    var requisitionDetailsResult = from rd in inventory.RequisitionDetails
     //                                   where rd.Requisition.Id == req.Id
     //                                   select rd;
     //    foreach (RequisitionDetail rd in requisitionDetailsResult)
     //    {
     //        req.RequisitionDetails.Add(rd);
     //    }
     //    return req;
     //}
     return requisitionObj;
 }
        /// <summary>
        /// Get the last requisition Id from requistion table
        /// </summary>
        /// <param name="requisition"></param>
        /// <returns>
        /// Return RequisitionId
        /// </returns>
        public string GetRequisitionId(Requisition requisition)
        {
            try
            {
                int idInt;
                string newYr;
                if (inventory.Requisitions.Where(r => r.Id.IndexOf(requisition.Department.Id) > -1).Count() > 0)
                {
                    Requisition lastRequisition = inventory.Requisitions.Where(r => r.Id.IndexOf(requisition.Department.Id) > -1).OrderByDescending(x => x.CreatedDate).First();

                    if (lastRequisition != null)
                    {
                        string requisitionId = lastRequisition.Id;
                        string[] stringList = requisitionId.Split('/');
                        string idString = stringList[1];
                        idInt = Converter.objToInt(idString);

                        int yearInt = DateTime.Now.Year;
                        string yrString = yearInt.ToString();
                        char[] charYr = yrString.ToCharArray();
                        newYr = charYr[2].ToString() + charYr[3].ToString();
                        if (newYr.Equals(stringList[2]))
                        {
                            idInt++;
                        }
                        else
                        {
                            idInt = 1;
                        }
                    }
                    else
                    {
                        idInt = 1;
                        newYr = DateTime.Now.Year.ToString().Substring(2);
                    }
                }
                else
                {
                    idInt = 1;
                    newYr = DateTime.Now.Year.ToString().Substring(2);
                }

                return requisition.Department.Id + "/" + idInt + "/" + newYr;
            }
            catch (Exception e)
            {
                return "Unknown";
            }
        }
 /// <summary>
 /// Create a new Requisition object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 public static Requisition CreateRequisition(global::System.String id, global::System.DateTime createdDate, global::System.Int32 status)
 {
     Requisition requisition = new Requisition();
     requisition.Id = id;
     requisition.CreatedDate = createdDate;
     requisition.Status = status;
     return requisition;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Requisitions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRequisitions(Requisition requisition)
 {
     base.AddObject("Requisitions", requisition);
 }
        //public RequisitionDetail SelectRequisitionID(string requisitionId)
        //{
        //    //requisition = new Requisition();
        //    RequisitionDetail requisitionDetail = new RequisitionDetail();
        //    requisitionDetail.Id = requisitionId;
        //    RequisitionDetail resultRequisitionDetail=requisitionBroker.GetRequisitionDetail(requisitionDetail);
        //}
        /// <summary>
        ///     Refresh requisition list after withdraw one requisition
        ///     Created By:JinChengCheng
        ///     Created Date:26-01-2012
        ///     Modified By:
        ///     Modified Date:
        ///     Modification Reason:
        ///     Modified By:
        ///     Modified Date:
        ///     Modification Reason:
        /// </summary>
        /// <param name="requisitionId"></param>
        /// <returns>The return type of this method is datatable.</returns>
        public Constants.ACTION_STATUS SelectWithdraw(string requisitionId, string remarks)
        {
            Constants.REQUISITION_STATUS requisitionStatus = Constants.REQUISITION_STATUS.WITHDRAW;
            Constants.ACTION_STATUS status = Constants.ACTION_STATUS.UNKNOWN;

            //Employee employee = new Employee();
            //employee.Id = currentEmployee.Id;
            //employee = employeeBroker.GetEmployee(employee);

            requisition = new Requisition();
            requisition.Id = requisitionId;
            requisition = requisitionBroker.GetRequisition(requisition);
            requisition.Remarks = (remarks == null ? String.Empty : remarks);
            //requisition.ApprovedBy = employee;
            //requisition.ApprovedDate = DateTime.Now;
            requisition.Status = Converter.objToInt(requisitionStatus);
            if (requisitionBroker.Update(requisition) == Constants.DB_STATUS.FAILED)
            {
                status = Constants.ACTION_STATUS.FAIL;
            }
            else
            {
                status = Constants.ACTION_STATUS.SUCCESS;
            }

            return status;
            //Constants.ACTION_STATUS status = Constants.ACTION_STATUS.UNKNOWN;
            //Constants.DB_STATUS dbStatus = requisitionBroker.Delete(requisition);
            //dbStatus = Constants.DB_STATUS.SUCCESSFULL;
            //if (requisitionList.Count == 1)
            //    return null;
            //else
            //    return GetRequisitionList();
        }
 public RequisitionCollectionDetail(int id, Requisition requisitionId, RequisitionCollection requisitionCollectionId)
 {
     this.Id = id;
     this.Requisition = requisitionId;
     this.RequisitionCollection = requisitionCollectionId;
 }
Exemple #11
0
 public RequisitionCollectionDetail(int id, Requisition requisitionId, RequisitionCollection requisitionCollectionId)
 {
     this.Id                    = id;
     this.Requisition           = requisitionId;
     this.RequisitionCollection = requisitionCollectionId;
 }
        public Constants.ACTION_STATUS SetDeliveryDate(int retrievalNo, DateTime deliveryDate)
        {
            Constants.ACTION_STATUS setStatus = Constants.ACTION_STATUS.UNKNOWN;

            Retrieval retrieval = retrievalList.Find(delegate(Retrieval r) { return r.Id == retrievalNo; });

            foreach (RetrievalDetail retrievalDetail in retrieval.RetrievalDetails)
            {
                Requisition requisition = new Requisition();
                requisition.Id = retrievalDetail.Requisition.Id;
                requisition = requisitionBroker.GetRequisition(requisition);

                RequisitionCollectionDetail requisitionCollectionDetail = requisitionCollectionBroker.GetRequisitionCollectionDetail(requisition);

                RequisitionCollection requisitionCollection = new RequisitionCollection();
                requisitionCollection.Id = requisitionCollectionDetail.RequisitionCollection.Id;
                requisitionCollection = requisitionCollectionBroker.GetRequisitionCollection(requisitionCollection);
                requisitionCollection.DeliveryDate = DateTime.Now;
                requisitionCollection.DeliveryBy = Util.GetEmployee(employeeBroker);

                requisitionCollectionBroker.Update(requisitionCollection);
            }

            return setStatus;
        }
 public void SelectRequisition(Requisition requisition)
 {
     RequisitionDetail requisitionDetail = new RequisitionDetail();
     requisitionDetail.Requisition = requisition;
     RequisitionDetail resultRequisitionDetail = requisitionBroker.GetRequisitionDetail(requisitionDetail);
     // show on UI
 }
 /// <summary>
 ///     Show requisition detail according to the selected requisition
 ///     Created By:JinChengCheng
 ///     Created Date:26-01-2012
 ///     Modified By:Thazin Win
 ///     Modified Date:02-02-2012
 ///     Modification Reason:To retrieve detail data
 ///     Modified By:
 ///     Modified Date:
 ///     Modification Reason:
 /// </summary>
 /// <param name="requisitionId"></param>
 /// <returns>The return type of this method is datatable.</returns>
 public Constants.ACTION_STATUS SelectRequisitionID(string requisitionId)
 {
     Constants.ACTION_STATUS selectStatus = Constants.ACTION_STATUS.UNKNOWN;
     requisition = RequisitionList.Find(delegate(Requisition req) { return req.Id.Contains(requisitionId); });
     if (requisition != null)
     {
         selectStatus = Constants.ACTION_STATUS.SUCCESS;
     }
     else
     {
         selectStatus = Constants.ACTION_STATUS.FAIL;
     }
     return selectStatus;
 }
 public Constants.ACTION_STATUS SelectRejectRequisition(Requisition requisition)
 {
     Constants.ACTION_STATUS status = Constants.ACTION_STATUS.UNKNOWN;
     requisition.Status = (int)Constants.REQUISITION_STATUS.REJECTED;
     requisitionBroker.Update(requisition);
     status = Constants.ACTION_STATUS.SUCCESS;
     return status;
 }
        //public Requisition EnterRequisitionID(string requisitionId)
        //{
        //    requisition = new Requisition();
        //    requisition.Id = requisitionId;
        //    requisitionBroker.GetRequisition(requisition);
        //    return requisition;
        //}
        /// <summary>
        ///     Show one requisition according to requisitionId parameter
        ///     Created By:JinChengCheng
        ///     Created Date:26-01-2012
        ///     Modified By:
        ///     Modified Date:
        ///     Modification Reason:
        ///     Modified By:
        ///     Modified Date:
        ///     Modification Reason:
        /// </summary>
        /// <param name="requisitionId"></param>
        /// <returns>The return type of this method is datatable.</returns>
        public DataTable EnterRequisitionID(string requisitionId)
        {
            requisition = new Requisition();
            requisition.Id = requisitionId;
            requisition = requisitionBroker.GetRequisition(requisition);
            requisitionDetail = new RequisitionDetail();
            requisitionDetail.Requisition.Id = requisitionId;
            requisitionDetail = requisitionBroker.GetRequisitionDetail(requisitionDetail);
            dt = new DataTable();

            dr = dt.NewRow();
            dr["requisitionId"] = requisition.Id;
            dr["requisitionDate/Time"] = requisition.CreatedDate;
            dr["status"] = requisition.Status;
            dr["remainingQty"] = requisitionDetail.Qty - requisitionDetail.DeliveredQty;
            dr["remarks"] = requisition.Remarks;
            dt.Rows.Add(dr);
            return dt;
        }
        private Constants.ACTION_STATUS SelectActionRequisition(Dictionary<string, string> remarks, Constants.REQUISITION_STATUS requisitionStatus)
        {
            Constants.ACTION_STATUS status = Constants.ACTION_STATUS.UNKNOWN;
            // employeeBroker = new EmployeeBroker(inventory);
            if (remarks.Count > 0)
            {
                status = Constants.ACTION_STATUS.SUCCESS;
                Requisition requisition;

                Employee employee = new Employee();
                employee.Id = currentEmployee.Id;
                employee = employeeBroker.GetEmployee(employee);

                foreach (string key in remarks.Keys)
                {

                    requisition = pendingRequisitionList.ElementAt(Converter.objToInt(key));
                    requisition.Status = Converter.objToInt(requisitionStatus);
                    requisition.Remarks = remarks[key];
                    requisition.ApprovedBy = employee;
                    requisition.ApprovedDate = DateTime.Now;

                    pendingRequisitionList[Converter.objToInt(key)] = requisition;

                    //pendingRequisitionList.Remove(requisition);

                    if (requisitionBroker.Update(requisition) == Constants.DB_STATUS.FAILED)
                    {
                        status = Constants.ACTION_STATUS.FAIL;
                        break;
                    }
                }
            }
            else
            {
                status = Constants.ACTION_STATUS.FAIL;
            }

            return status;
        }
        /// <summary>
        /// Update Requisition data to Requisition Table according to the Requisition Parameter
        ///  Return Constants.DB_STATUS
        /// </summary>
        /// <param name="requisition"></param>
        /// <returns></returns>
        public Constants.DB_STATUS Update(Requisition requisition)
        {
            Constants.DB_STATUS status = Constants.DB_STATUS.UNKNOWN;

            try
            {
                //requisitionObj = inventory.Requisitions.Where(reqObj => reqObj.Id == requisition.Id).First();
                //Employee empId=inventory.Employees.Where(e=>e.Id==requisition.CreatedBy.Id).First();
                //Employee approvedBy=inventory.Employees.Where(e=>e.Id==requisition.ApprovedBy.Id).First();
                //Department department = inventory.Departments.Where(d => d.Id == requisition.Department.Id).First();
                ////requisitionObj.Id = requisition.Id;
                //requisitionObj.Department = department;
                //requisitionObj.CreatedBy = empId;
                //requisitionObj.ApprovedBy = approvedBy;
                //requisitionObj.ApprovedDate = requisition.ApprovedDate;
                //requisitionObj.CreatedDate = requisition.CreatedDate;
                //foreach (RequisitionDetail requisitionDetail in requisition.RequisitionDetails)
                //{
                //    this.Update(requisitionDetail);
                //}
                //if (isSaved) inventory.SaveChanges();
                inventory.SaveChanges();
                status = Constants.DB_STATUS.SUCCESSFULL;
            }
            catch (Exception e)
            {
                status = Constants.DB_STATUS.FAILED;
            }
            return status;
        }
        static void Main()
        {
            // Write the Main Program for RequistionBrokerTest here...

            RequisitionBroker reqBroker = new RequisitionBroker();
               Requisition req = new Requisition();
            RequisitionDetail reqDetail=new RequisitionDetail();
            Department dept = new Department();
            Item item = new Item();
            Employee emp = new Employee();
            dept.Id = "COMM";
            emp.Id = 1;
            emp.Department = dept;
            emp.Role = new Role();
            emp.Role.Id = 1;
            emp.User = new User();
            emp.User.Employee = emp;
            emp.User1 = new User();
            emp.User1.Employee = emp;

            req.Department = dept;

              //  req.Employee = emp;

            //req.Employee.Id=1;
            req.Remarks="Insert Test";
            //req.ApprovedDate=new DateTime(23-01-2012);
            //req.CreatedDate=new DateTime(23-01-2012);
            req.Status=1;
            req.Employee = emp;
            req.Employee1 = emp;

               // reqDetail.Requisition.Id
               // reqDetail.Item.Id="1";
            item.Id = "1";
             reqDetail.Item=item;
            reqDetail.Qty=10;
            reqDetail.DeliveredQty=20;
            req.RequisitionDetails.Add(reqDetail);
            reqDetail.Item.Employee = reqDetail.Requisition.Employee;

            if (reqBroker.Insert(req).Equals("FAILED"))
            {
                Console.WriteLine("Successful");
            }
            else
            {
                Console.WriteLine("Error");
            }
            /*  req.Id = "1";

               if (reqBroker.GetRequisition(req) != null)
               {
               Console.WriteLine(reqBroker.GetRequisition(req).Remarks);
               foreach(RequisitionDetail reqDetial in reqBroker.GetRequisition(req).RequisitionDetails)
               Console.WriteLine(reqDetial.DeliveredQty);
               }

               if (reqBroker.GetAllRequisition().Count > 0)
               {
               Console.WriteLine("Retrieve all requisitions");
               foreach (Requisition r in reqBroker.GetAllRequisition())
               {
                   Console.WriteLine(r.Id + " " + r.Remarks);
                   foreach (RequisitionDetail rd in r.RequisitionDetails)
                   {
                       Console.WriteLine(rd.Id + " " + rd.Item.Description);
                   }
               }
               }
               else
               {
               Console.WriteLine("Cannot read all requisitions");
               }

               Console.WriteLine(SystemStoreInventorySystemUtil.Converter.objToInt(SystemStoreInventorySystemUtil.Constants.VISIBILITY_STATUS.SHOW));
               Console.WriteLine(SystemStoreInventorySystemUtil.Constants.VISIBILITY_STATUS.SHOW);
            */

            #region /* Do not remove this or write codes after this  */
            ISSConsole.Pause();
            #endregion
        }
        /// <summary>
        ///     Refresh requisition list after withdraw one requisition
        ///     Created By:JinChengCheng
        ///     Created Date:26-01-2012
        ///     Modified By:
        ///     Modified Date:
        ///     Modification Reason:
        ///     Modified By:
        ///     Modified Date:
        ///     Modification Reason:
        /// </summary>
        /// <param name="requisitionId"></param>
        /// <returns>The return type of this method is datatable.</returns>
        public Constants.ACTION_STATUS Setstatus(string requisitionId, Constants.REQUISITION_STATUS Reqstatus, string remarks, DataTable dt)
        {
            Constants.ACTION_STATUS status = Constants.ACTION_STATUS.UNKNOWN;
            requisition = RequisitionList.Find(delegate(Requisition req) { return req.Id.Contains(requisitionId); });
            if (Reqstatus != Constants.REQUISITION_STATUS.REJECTED)
            {
                foreach (RequisitionDetail temp in requisition.RequisitionDetails)
                {
                    DataRow[] dr = dt.Select(" ItemCode = '" + temp.Item.Id + "'");
                    if (dr != null && dr.Length > 0)
                    {
                        temp.Qty = Convert.ToInt16(dr[0][1].ToString());
                        temp.DeliveredQty = Convert.ToInt16(dr[0][2].ToString());
                    }
                }
            }

            requisition.Remarks = remarks;
            requisition.Status = (int)(Reqstatus);
            requisitionBroker.Update(requisition);

            if(Reqstatus == Constants.REQUISITION_STATUS.COMPLETE)
            {
                RequisitionCollection RC = null;

                //Get all submitted requisitions
                RequisitionCollectionDetail rcDetails = requisitionCollectionBroker.GetAllRequisitionCollectionDetail(requisitionId);

                if(rcDetails != null)
                {
                    RC = requisitionCollectionBroker.GetAllRequisitionCollectionByRequisitionCollectionID(rcDetails.RequisitionCollection.Id.ToString());
                }

                foreach(RequisitionCollectionDetail rcd in RC.RequisitionCollectionDetails)
                {
                    if(rcd.Requisition.Status == (int)Constants.REQUISITION_STATUS.COMPLETE)
                        RC.Status = (int)Constants.COLLECTION_STATUS.COLLECTED;
                    else
                        RC.Status = (int)Constants.COLLECTION_STATUS.NEED_TO_COLLECT;
                }

                requisitionCollectionBroker.Update(RC);
            }
            return status;
        }
        /// <summary>
        ///     Show requisition detail according to the selected requisition
        ///     Created By:JinChengCheng
        ///     Created Date:26-01-2012
        ///     Modified By:Thazin Win
        ///     Modified Date:02-02-2012
        ///     Modification Reason:To retrieve detail data
        ///     Modified By:
        ///     Modified Date:
        ///     Modification Reason:
        /// </summary>
        /// <param name="requisitionId"></param>
        /// <returns>The return type of this method is datatable.</returns>
        public Constants.ACTION_STATUS SelectRequisitionID(string requisitionId)
        {
            Constants.ACTION_STATUS selectStatus = Constants.ACTION_STATUS.UNKNOWN;

            requisition = pendingRequisitionList.Find(delegate(Requisition req) { return req.Id.Contains(requisitionId); });

            if (requisition != null)
            {
                selectStatus = Constants.ACTION_STATUS.SUCCESS;
            }
            else
            {
                selectStatus = Constants.ACTION_STATUS.FAIL;
            }

            return selectStatus;

            //  dt = new DataTable();
            //  dt.Columns.Add("itemNo");
            //  dt.Columns.Add("itemDescription");
            //  dt.Columns.Add("requiredQty");
            //  dt.Columns.Add("receivedQty");
            //  dt.Columns.Add("remainingQty");

            //  List<RequisitionDetail> requistionDetailList;
            //  requisition = new Requisition();
            //  itemBroker = new ItemBroker(inventory);
            //  requisition.Id = requisitionId;
            //  requisitionDetail=new RequisitionDetail();
            //  requisitionDetail.Requisition=requisition;
            //  requistionDetailList = requisitionBroker.GetAllRequisitionDetailByObj(requisitionDetail);

            //foreach (RequisitionDetail temp in requistionDetailList)
            //  {
            //      dr = dt.NewRow();

            //      Item item = new Item();
            //      item =temp.Item ;
            //      item = itemBroker.GetItem(item);
            //      dr["itemNo"] = item.Id;
            //      dr["itemDescription"] = item.Description;
            //      dr["requiredQty"] = temp.Qty;
            //      dr["receivedQty"] = temp.DeliveredQty.HasValue ? temp.DeliveredQty.Value : 0;
            //      if (temp.DeliveredQty.Equals(null))
            //          dr["remainingQty"] = 0;
            //      else
            //          dr["remainingQty"] = temp.Qty - temp.DeliveredQty;
            //      dt.Rows.Add(dr);
            //  }
            //  return dt;
        }