Beispiel #1
0
        /// <summary>
        /// Update the collection point
        /// </summary>
        /// <param name="departmentId"></param>
        /// <param name="collectionPointId"></param>
        public static void UpdateCollectionPoint(string departmentId, int collectionPointId)
        {
            var dep = DbFactory.Instance.context.Departments.Where(x => x.departmentId == departmentId).First();

            dep.collectionPointId = collectionPointId;
            DbFactory.Instance.context.SaveChanges();

            string newPoint = DbFactory.Instance.context.CollectionPoints.AsNoTracking().Where(x => x.collectionPointId == collectionPointId).Select(x => x.collectionPointDescription).FirstOrDefault();

            string mailSubject = "Notification for changing the collection point";
            string mailContent = string.Format("{0} department: the new collection point is {1}", dep.departmentName, newPoint);

            bool result = MyEmail.SendEmail("*****@*****.**", mailSubject, mailContent);
        }
Beispiel #2
0
        /// <summary>
        /// Approves the request
        /// </summary>
        /// <param name="requestId"></param>
        /// <param name="remarks"></param>
        /// <returns></returns>
        public static Boolean ApproveRequest(int?requestId, string remarks)
        {
            try
            {
                Request request = DbFactory.Instance.context.Requests.Where(x => x.requestId == requestId && x.status == "pending").First();
                request.approvedDate = DateTime.Now.Date;
                request.status       = "approved";
                request.remark       = remarks;
                DbFactory.Instance.context.SaveChanges();

                // send the emial when DH approve the request (default clerk)
                string mailSubject = "Notification for Retrieval";
                string mailContent = string.Format("Store clerk: please retrieve goods");

                bool result = MyEmail.SendEmail("*****@*****.**", mailSubject, mailContent);
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Allocate the stationery to each department according to the alphabet after the clerk retrieve goods
        /// </summary>
        /// <param name="itemNo">item number</param>
        /// <param name="DueDate">due date to retrieval goods</param>
        /// <param name="qtyRetrieval">retrieval quantity</param>
        /// <param name="qtyDamaged">damaged quantity</param>
        /// <param name="qtyMissing">missing quantity</param>
        /// <returns></returns>
        public static bool AllocateGoods(string itemNo, DateTime DueDate, int qtyRetrieval, int qtyDamaged, int qtyMissing)
        {
            #region validation
            // Validation here (qty info)
            if (qtyRetrieval <= 0 || qtyDamaged < 0 || qtyMissing < 0)
            {
                return(false);
            }

            // Fetch the product info from database
            int?_balance = DbFactory.Instance.context.Inventories.AsNoTracking().Where(x => x.itemNo == itemNo).
                           Select(x => x.balance).First();
            int balance = _balance == null ? 0 : (int)_balance;

            RetrievalViewModel model = ViewRetrievalGood(itemNo, DueDate);

            // when the balance can and cannot cover the requirement
            if (balance < (model.quantityTotalNeed + qtyDamaged + qtyMissing))
            {
                // cannot cover
                int inputQ = qtyRetrieval + qtyDamaged + qtyMissing;
                if (inputQ != balance)
                {
                    return(false);
                }
            }
            else
            {
                // can cover
                if (model.quantityTotalNeed != qtyRetrieval)
                {
                    return(false);
                }
            }
            #endregion

            using (var dbContextTransaction = DbFactory.Instance.context.Database.BeginTransaction())
            {
                try
                {
                    // in here we deal with the problem goods
                    if (qtyDamaged != 0)
                    {
                        createAdjVoucher(itemNo, -qtyDamaged, DateTime.Now.Date, MyReasonCode.InstoreDamaged);
                    }
                    if (qtyMissing != 0)
                    {
                        createAdjVoucher(itemNo, -qtyMissing, DateTime.Now.Date, MyReasonCode.InstoreMissing);
                    }

                    #region Distribute goods here
                    var product = DbFactory.Instance.context.Inventories.Where(x => x.itemNo == itemNo).First();
                    product.balance = product.balance == null ? 0 : (int)product.balance;

                    // get department list
                    var deps = DbFactory.Instance.context.Departments.OrderBy(x => x.departmentId).ToList();

                    // go through each department
                    foreach (var dep in deps)
                    {
                        // get the requests of this department
                        List <Request> requests = DbFactory.Instance.context.Requests.Include("RequestDetails").Where(x => x.departmentId == dep.departmentId && x.status == "approved" && x.approvedDate <= DueDate).ToList();
                        if (requests == null || requests.Count == 0)
                        {
                            continue;
                        }

                        // record the original quantity of this item
                        int qtyOriginal = (int)product.balance;

                        // go through each request
                        foreach (var req in requests)
                        {
                            if (req.RequestDetails != null)
                            {
                                // go through each request detail
                                foreach (var rd in req.RequestDetails)
                                {
                                    if (rd.itemNo == itemNo && rd.status == "unfulfilled")
                                    {
                                        // allocate item here
                                        int qtyPack = rd.quantityNeed - rd.quantityReceive;
                                        if (product.balance >= qtyPack)
                                        {
                                            // update inventory table**
                                            product.balance -= qtyPack;

                                            // update request detail table**
                                            rd.quantityPacked = qtyPack;
                                            rd.status         = "preparing";
                                        }
                                        else if (product.balance > 0)
                                        {
                                            // not enough balance
                                            qtyPack          = (int)product.balance;
                                            product.balance -= qtyPack;

                                            // update request detail table**
                                            rd.quantityPacked = qtyPack;
                                            rd.status         = "preparing";

                                            break;
                                        }
                                        else
                                        {
                                            // when no balance for request
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        // insert stock card record here**
                        int qtyGap = (int)product.balance - qtyOriginal;

                        // when we have allocated the item to this department
                        if (qtyGap != 0)
                        {
                            var stkCard = new StockCard()
                            {
                                itemNo       = itemNo,
                                dateModified = DateTime.Now.Date,
                                remark       = dep.departmentId,
                                quantity     = qtyGap,
                                balance      = (int)product.balance
                            };
                            DbFactory.Instance.context.StockCards.Add(stkCard);

                            // update the database!
                            DbFactory.Instance.context.SaveChanges();

                            // send the email to notify the department
                            string sEmail = DbFactory.Instance.context.Staffs.AsNoTracking().Where(x => x.staffId == dep.staffIdDR).Select(x => x.staffEmail).FirstOrDefault();
                            if (sEmail != null)
                            {
                                string mailSubject = "Notification for Retrieval";
                                string mailContent = string.Format("{0} department({1}): please collect goods tomorrow", dep.departmentName, sEmail);

                                bool result = MyEmail.SendEmail("*****@*****.**", mailSubject, mailContent);
                            }
                        }
                    }
                    #endregion

                    // commit the transaction
                    dbContextTransaction.Commit();
                }
                catch (Exception e)
                {
                    dbContextTransaction.Rollback();
                    return(false);
                }
            }

            return(true);
        }