示例#1
0
 public bool savedisb(Disbursement_M disb,int userid)
 {
     Disbursement_M disbl = new Disbursement_M();
     disbl =disb;
     bool ans = false;
     ans = drep.saveDisblist(disbl,userid);
     return ans;
 }
        public static bool SaveDisbursement(List<int> quant, List<int> dep, int itemID, List<int> quantreq)
        {
            DepartmentService sdepser = new DepartmentService();
            //int count;
            int totcount;
            totcount = dep.Count();
            bool ans = true;
            int userid= Convert.ToInt32(HttpContext.Current.Session["userid"].ToString());

            Disbursement_M disb=new Disbursement_M();
            for (int i = 0; i < totcount; i++)
            {
                disb.ItemID = itemID;
                disb.DepID = dep[i];
                disb.RequiredQuant = quantreq[i];
                disb.QuantinHand = quant[i];
                sdepser.savedisb(disb,userid);

            }

            return ans;
        }
示例#3
0
        public bool CreateDisbursement(DisbursementM[] disbursement)
        {
            DepartmentService departmentService = new DepartmentService();
            try
            {
                for (int i = 0; i < disbursement.Count(); i++)
                {
                    DisbursementM d = disbursement[i];
                    Disbursement_M m = new Disbursement_M();
                    m.DepID = Convert.ToInt32( d.DepID);
                    m.ItemID = Convert.ToInt32(d.ItemID);
                    m.QuantinHand = Convert.ToInt32(d.QuantityInHand);
                    m.RequiredQuant =Convert.ToInt32( d.RequiredQuant);
                    departmentService.savedisb(m,Convert.ToInt32(d.UpdatedUserID));

                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
示例#4
0
        public bool saveDisblist(Disbursement_M disbl,int userid)
        {
            bool ans = false;
            List<requisitiondetail> rdlist = new List<requisitiondetail>();
            //requisitiondetail rd =new requisitiondetail();
            disbursementdetail disbdet = new disbursementdetail();
            disbursement disb = new disbursement();
            checkdate = DateTime.Today;
            string status = "Ready";

            //checking whether the disb-list already exists

            var q = from d in se.disbursements
                    where d.DisbDepID == disbl.DepID &&
                    d.DisbStatus == status
                    select d;
            disb = q.FirstOrDefault();

            //if disb-list already exits

            if (disb != null)
            {
                item newitem = new item();
                newitem = se.items.Find(disbl.ItemID);

                disbursementdetail ddetail = new disbursementdetail();
                var a = from dd in se.disbursementdetails
                        where dd.DisbID == disb.DisbID &&
                        dd.DisbItemID == disbl.ItemID
                        select dd;
                ddetail = a.FirstOrDefault();
                if (ddetail != null)
                {
                    //if (disbl.RequiredQuant >= ddetail.DisbItemQuantReq)
                    //{
                    //    ddetail.DisbItemQuantReq = ddetail.DisbItemQuantReq + disbl.RequiredQuant;
                    //    ddetail.DisbItemQuantDelivered = ddetail.DisbItemQuantDelivered + disbl.QuantinHand;

                    //}
                    //else
                    //{

                    //    ddetail.DisbItemQuantDelivered = ddetail.DisbItemQuantDelivered + disbl.QuantinHand;
                    //}
                    if (ddetail.DisbItemQuantReq == ddetail.DisbItemQuantDelivered)
                    {
                        ddetail.DisbItemQuantReq = ddetail.DisbItemQuantReq + disbl.RequiredQuant;
                        ddetail.DisbItemQuantDelivered = ddetail.DisbItemQuantDelivered + disbl.QuantinHand;
                    }
                    else if(ddetail.DisbItemQuantReq>ddetail.DisbItemQuantDelivered)
                    {
                        if (ddetail.DisbItemQuantReq > (ddetail.DisbItemQuantDelivered + disbl.QuantinHand))
                        {
                            int toadd = (disbl.RequiredQuant - (ddetail.DisbItemQuantReq - ddetail.DisbItemQuantDelivered)) ?? default(int);
                            ddetail.DisbItemQuantReq = ddetail.DisbItemQuantReq + toadd;
                            ddetail.DisbItemQuantDelivered = ddetail.DisbItemQuantDelivered + disbl.QuantinHand;

                        }
                        else
                        {
                            ddetail.DisbItemQuantDelivered = ddetail.DisbItemQuantDelivered + disbl.QuantinHand;
                        }
                    }

                    try
                    {
                        se.SaveChanges();
                        newitem.ItemQuant = newitem.ItemQuant -disbl.QuantinHand;

                        createTransaction(disbl, newitem,userid);

                        CheckForOutStanding(disbl);
                        ans = true;
                    }
                    catch (Exception ex)
                    {
                        ans = false;

                    }
                    //check for outstanding request

                }
                else
                {
                    disbursementdetail newdd = new disbursementdetail();
                    newdd.DisbID = disb.DisbID;
                    newdd.DisbItemID = disbl.ItemID;
                    newdd.DisbItemQuantDelivered = disbl.QuantinHand;
                    newdd.DisbItemQuantReq = disbl.RequiredQuant;
                    try
                    {
                        se.disbursementdetails.Add(newdd);
                        se.SaveChanges();
                        newitem.ItemQuant = newitem.ItemQuant -  disbl.QuantinHand;

                        //saving transaction
                        createTransaction(disbl, newitem,userid);

                        CheckForOutStanding(disbl);
                        ans = true;
                    }
                    catch (Exception ex)
                    {
                        ans = false;

                    }

                }
                return ans;

            }
            else
            {
                // creating a new disbursement
                ans = createDisbursement(disbl,userid);

            }
            return ans;
        }
示例#5
0
        //method to manage outstanding requests
        public void CheckForOutStanding(Disbursement_M disbl)
        {
            List<requisitiondetail> rdlist = new List<requisitiondetail>();
            checkdate = DateTime.Today; //checking requestions brfore today
            //checkdate = DateTime.Today.AddDays(2);
            requisitiondetail rcheck = new requisitiondetail();
            //checking
            requisition rq = new requisition();
            var m = from r in se.requisitiondetails
                    where
                    r.ReqItemID == disbl.ItemID &&
                    r.requisition.ReqDepID == disbl.DepID &&
                    r.ReqStatus=="approved" &&
                    r.requisition.ReqApproveDate < checkdate
                    select r;
            rdlist = m.ToList();
            rcheck = m.FirstOrDefault();
            foreach (requisitiondetail rd in rdlist)
            {
                //if (rd.requisition.ReqReason == "outstanding")
                //{
                //    //rd.ReqStatus = "confirmed";
                //    //se.SaveChanges();
                //    //totalcount = totalcount + rd.ReqQuantityReq;
                //    outstandingReqList.Add(rd);

                //}
                //else
                //{
                //    normalReqList.Add(rd);
                //    //changing the status to confirmed
                //    //rd.ReqStatus = "confirmed";
                //    //se.SaveChanges();
                //    //totalcount = totalcount + rd.ReqQuantityReq; //getting the count of items ordered by the dep
                //}
                rd.ReqStatus = "confirmed";
                try
                {
                    se.SaveChanges();
                }
                catch (Exception ex)
                {
                    string error;
                    if (ex.InnerException != null)
                    {
                        Exception ex1;
                        ex1 = ex.InnerException;
                        error = ex1.InnerException.StackTrace;

                    }
                    else
                    {
                        string error1;
                        error1 = ex.InnerException.Message;

                    }

                }
            }
            if (disbl.QuantinHand < disbl.RequiredQuant)
            {
                int outstanding = disbl.RequiredQuant - disbl.QuantinHand;
                requisition outreq = new requisition();
                requisitiondetail outreqdet = new requisitiondetail();

                //creating an oustanding request automatically
                outreq.ReqApproveEmpID = rcheck.requisition.ReqApproveEmpID;
                outreq.ReqApproveDate = rcheck.requisition.ReqApproveDate; // come back here to make sure your logic is right
                outreq.ReqStatus = "outstanding";
                outreq.ReqDate = rcheck.requisition.ReqDate;
                outreq.ReqDepID = rcheck.requisition.ReqDepID;
                outreq.ReqEmpId = rcheck.requisition.ReqEmpId;
                outreq.ReqReason = "outstanding";
                try
                {
                    se.requisitions.Add(outreq);
                    se.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }

                //creating an autogenerated requestdetails for that particular item
                outreqdet.ReqID = outreq.ReqID;
                outreqdet.ReqItemID = disbl.ItemID;
                outreqdet.ReqQuantityReq = outstanding;
                outreqdet.ReqStatus = "approved";
                try
                {
                    se.requisitiondetails.Add(outreqdet);
                    se.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
            }
        }
示例#6
0
        public bool createTransaction(Disbursement_M disbl, item newitem,int userid)
        {
            bool ans = false;
            //Save In transaction
            transaction t = new transaction();
            t.TransDate = DateTime.Now;
            t.TransItemID = disbl.ItemID;
            t.TransItemQuant = disbl.RequiredQuant;
            t.TransItemBalance = newitem.ItemQuant ?? default (int);
            t.TransReason = "Retrived For Department " + disbl.DepID;
            t.TransactionType = "out";
            t.TranUserID = userid;
            t.TransCode = "RTR";
            try
            {
                se.transactions.Add(t);
                se.SaveChanges();
                ans = true;
            }
            catch
            {
                ans = false;

            }
            return ans;
        }
示例#7
0
        public bool createDisbursement(Disbursement_M disbl,int userid)
        {
            bool ans = false;
            List<requisitiondetail> rdlist = new List<requisitiondetail>();
            //requisitiondetail rd =new requisitiondetail();
            disbursementdetail disbdet = new disbursementdetail();
            disbursement disb = new disbursement();
            item newitem = new item();

            //
            newitem = se.items.Find(disbl.ItemID);

            //creating a new disbursement
            disbursement disb1 = new disbursement();
            disb1.DisbDepID = disbl.DepID;
            disb1.DisbStatus = "Ready";
            disb1.DisbReceiveDate = null;
            disb1.DisbCreateDate = DateTime.Today;
            se.disbursements.Add(disb1);
            se.SaveChanges();

            //creating a Disbursement details

            disbdet.DisbID = disb1.DisbID;
            disbdet.DisbItemID = disbl.ItemID;
            disbdet.DisbItemQuantDelivered = disbl.QuantinHand;
            disbdet.DisbItemQuantReq = disbl.RequiredQuant;

            try
            {
                se.disbursementdetails.Add(disbdet);
                se.SaveChanges();

                newitem.ItemQuant = newitem.ItemQuant - disbl.QuantinHand;
                se.SaveChanges();

                createTransaction(disbl, newitem, userid);

                ans = true;
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

            if (ans == true)
            {
                CheckForOutStanding(disbl);
                ans = true;
            }
            return ans;
        }