예제 #1
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;
        }
예제 #2
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;
        }