//check disbursement
        public static bool checkDisbursmentID(string Dis_ID, string RepID)
        {
            bool isDisbursmentIDCorrect = false;

            using (InventorySysDBEntities cntx = new InventorySysDBEntities())
            {
                Staff Rep = cntx.Staffs.Find(RepID);
                // whether disbursment exist
                Disbursement dis = cntx.Disbursements.Find(Dis_ID);
                if (dis != null)
                {
                    // Rep only can see its own disbursment
                    if (dis.RepStaff_ID == Rep.Staff_ID)
                    {
                        // only the submitted disbursment can be seen
                        switch (dis.Status)
                        {
                        case "Received":
                            break;

                        case "Submitted":
                            isDisbursmentIDCorrect = true;
                            break;
                        }
                    }
                }

                return(isDisbursmentIDCorrect);
            }
        }
        public static void ConfirmRecivedItems(string DI, List <DisbursementDetail> ddlist)
        {
            Staff rep = new Staff();

            using (InventorySysDBEntities cntx = new InventorySysDBEntities())
            {
                //update disbursmentdetail
                foreach (DisbursementDetail dd in ddlist)
                {
                    updateDisbursmentDetail(cntx, dd);
                }

                //update disbursment
                Disbursement disbursment = cntx.Disbursements.Find(DI);
                rep = StaffController.getRepByDepID(disbursment.Dept_ID);

                disbursment.Receive_Date = DateTime.Now;
                disbursment.Status       = "Recieved";

                // update Requisition
                List <Requisition> reqList = getRequisitionsByDI(DI);
                foreach (Requisition req in reqList)
                {
                    Requisition reqData = cntx.Requisitions.Find(req.Requisition_ID);
                    reqData.Status = "Received";
                }

                cntx.SaveChanges();
            }
            SendNotificationController.SendNotificaition(rep, DI);
        }
Beispiel #3
0
        ////staff List get by dept
        //public static List<Staff> getStaffListByDepIDandroleID(string DepID, string roleID)
        //{
        //    using (InventorySysDBEntities cntx = new InventorySysDBEntities())
        //    {
        //        var q = from x in cntx.Staffs
        //                where x.Dept_ID == DepID
        //                where x.Role_ID == roleID
        //                select x;
        //        Console.Write(q.ToString());
        //        return q.ToList();
        //    }

        //}

        //update collection point according to staff and collection point

        public static Staff GetRepByDeptID(string deptID)
        {
            using (InventorySysDBEntities cntx = new InventorySysDBEntities())
            {
                var q = from x in cntx.Staffs where x.Dept_ID == deptID && x.Role_ID == "RepStaff" select x;
                return(q.First());
            }
        }
        public static void updateDisbursmentDetail(InventorySysDBEntities cntx, DisbursementDetail newDD)
        {
            // update disbursmentDetailRow
            string             DI     = newDD.Disbursement_ID;
            string             itemID = newDD.Item_ID;
            DisbursementDetail oldDD  = cntx.DisbursementDetails.Find(DI, itemID);

            oldDD.Quantity = newDD.Quantity;
        }
Beispiel #5
0
 //collection List
 public static List <CollectionPoint> getAllCollection()
 {
     using (InventorySysDBEntities cntx = new InventorySysDBEntities())
     {
         var q = from x in cntx.CollectionPoints
                 select x;
         return(q.ToList());
     }
 }
        //confirm received
        public static List <Requisition> getRequisitionsByDI(string DI)
        {
            using (InventorySysDBEntities cntx = new InventorySysDBEntities())
            {
                var q = from req in cntx.Requisitions
                        where req.Disbursement_ID == DI
                        select req;

                return(q.ToList());
            }
        }
Beispiel #7
0
 //staff List get by dept
 public static List <Staff> getStaffListByDepID(string DepID)
 {
     using (InventorySysDBEntities cntx = new InventorySysDBEntities())
     {
         var q = from x in cntx.Staffs
                 where x.Dept_ID == DepID && (x.Role_ID == "Staff" || x.Role_ID == "RepStaff")
                 select x;
         Console.Write(q.ToString());
         return(q.ToList());
     }
 }
Beispiel #8
0
        //collection get by dept
        public static CollectionPoint getCollectionInfoByDepID(string DepId)
        {
            using (InventorySysDBEntities cntx = new InventorySysDBEntities())
            {
                var q = from d in cntx.Departments
                        where d.Dept_ID == DepId
                        select d.CollectionPoint;

                return(q.ToList().First());
            }
        }
Beispiel #9
0
        //public static bool ChangeRepToStaff(string deptID)
        //{
        //    using (InventorySysDBEntities cntx = new InventorySysDBEntities())
        //    {

        //        Staff stf = GetRepByDeptID(deptID);
        //        Staff repStaff = cntx.Staffs.Find(stf.Staff_ID);
        //        if (repStaff != null)
        //        {
        //            repStaff.Role_ID = "Staff";
        //            cntx.SaveChanges();
        //            return true;
        //        }
        //        else
        //            return false;
        //    }
        //}

        //public static bool ChangeStaffToRep(string staffID)
        //{
        //    using (InventorySysDBEntities cntx = new InventorySysDBEntities())
        //    {
        //        var q = from x in cntx.Staffs where x.Staff_ID == staffID select x;
        //        if (q.ToList().Count > 0)
        //        {
        //            q.First().Role_ID = "RepStaff";
        //            cntx.SaveChanges();
        //            return true;
        //        }
        //        else
        //            return false;
        //    }
        //}

        public static void UpdateCollectionPoint(string DeptID, string ColID)
        {
            using (InventorySysDBEntities cntx = new InventorySysDBEntities())
            {
                var        q = from x in cntx.Departments where x.Dept_ID == DeptID select x;
                Department d = q.First();

                d.Collection_ID = ColID;
                cntx.SaveChanges();
            }
        }
        public static List <DisbursmentItemModel_M> getDisbursmentItems(string Dis_ID)
        {
            using (InventorySysDBEntities cntx = new InventorySysDBEntities())
            {
                var q = from ri in cntx.RequisitionItems
                        where ri.Requisition.Disbursement_ID == Dis_ID
                        group ri by ri.Item_ID into g
                        join i in cntx.Items on g.Key equals i.Item_ID
                        select new DisbursmentItemModel_M
                {
                    ItemCode = g.Key,
                    ItemDes  = i.Item_Name,
                    NeedQty  = g.Sum(m => m.Required_Qty),
                    UOM      = i.UOM
                };

                return(q.ToList());
            }
        }
Beispiel #11
0
        public static bool UpdateCollectionPoint(string DeptID, string staffID, string ColID)
        {
            using (InventorySysDBEntities cntx = new InventorySysDBEntities())
            {
                using (var dbContextTransaction = cntx.Database.BeginTransaction())
                {
                    try
                    {
                        //make here the changes

                        Staff stf      = GetRepByDeptID(DeptID);
                        Staff repStaff = cntx.Staffs.Find(stf.Staff_ID);
                        repStaff.Role_ID = "Staff";



                        var changeStaffTRep             = from x in cntx.Staffs where x.Staff_ID == staffID select x;
                        changeStaffTRep.First().Role_ID = "RepStaff";


                        var        updateCollectionPoint = from x in cntx.Departments where x.Dept_ID == DeptID select x;
                        Department d = updateCollectionPoint.First();
                        d.Collection_ID = ColID;


                        cntx.SaveChanges();
                        dbContextTransaction.Commit();

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        return(false);
                    }
                }
            }
        }