Exemple #1
0
        /// <summary>
        /// Add check instrument.<br />
        /// - Validate require field.<br />
        /// - Check shelf type.<br />
        /// - Check duplicate add.<br />
        /// - Add to list.
        /// </summary>
        /// <param name="OfficeCode"></param>
        /// <param name="gridCurrentPage"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ActionResult IVS160_AddInstrumentToList(string OfficeCode, List <tbt_InventoryCheckingSlipDetail> gridCurrentPage, IVS160_AddData data)
        {
            IVS160_ScreenParameter param = GetScreenObject <IVS160_ScreenParameter>();

            List <dtCheckingDetailList> list = new List <dtCheckingDetailList>();

            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                if (param.DetailList == null)
                {
                    param.DetailList  = new List <tbt_InventoryCheckingSlipDetail>();
                    param.CurrentPage = 1;
                }
                if (param.DetailList_ForView == null)
                {
                    param.DetailList_ForView = new List <dtCheckingDetailList>();
                }

                // Check required field.
                if (ModelState.IsValid == false)
                {
                    ValidatorUtil.BuildErrorMessage(res, this);
                    if (res.IsError)
                    {
                        return(Json(res));
                    }
                }

                // Business checking # 1
                IShelfMasterHandler handlerShelfMaster = ServiceContainer.GetService <IShelfMasterHandler>() as IShelfMasterHandler;
                List <tbm_Shelf>    listShelf          = handlerShelfMaster.GetTbm_Shelf(data.ShelfNo);
                if (listShelf.Count <= 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4048, new string[] { data.ShelfNo }, new string[] { "ShelfNo" });
                    return(Json(res));
                }
                else
                {
                    data.ShelfNo = listShelf[0].ShelfNo;

                    // Business checking # 2 (duplicate)
                    var isExist = param.DetailList.Count == 0 ? false : param.DetailList.Any(d => d.key == data.key);  //(from p in param.DetailList where p.key == data.key select p).Any<tbt_InventoryCheckingSlipDetail>();

                    if (isExist)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4081, null, null);
                        return(Json(res));
                    }

                    //if (listShelf[0].ShelfTypeCode == ShelfType.C_INV_SHELF_TYPE_NORMAL
                    //    && (listShelf[0].AreaCode != data.AreaCode || string.Compare(listShelf[0].InstrumentCode, data.InstrumentCode, true) == 0)
                    //    && OfficeCode == ViewBag.HeadOfficeCode)
                    //{
                    //    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4079, new string[] { data.ShelfNo }, new string[] { "ShelfNo" });
                    //    return Json(res);
                    //}

                    //if (listShelf[0].ShelfTypeCode == ShelfType.C_INV_SHELF_TYPE_EMPTY)
                    //{
                    //    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4080, null, new string[] { "ShelfNo" });
                    //    return Json(res);
                    //}
                }


                // Update current page  (update value of CheckingQty)

                // 1. Update DetailList
                var currentPage = (from p in param.DetailList where p.Page == param.CurrentPage select p).ToList <tbt_InventoryCheckingSlipDetail>();
                for (int i = 0; i < currentPage.Count; i++)
                {
                    if (currentPage[i].key == gridCurrentPage[i].key)
                    {
                        currentPage[i].CheckingQty      = gridCurrentPage[i].CheckingQty; // gridCurrentPage[i].CheckingQty.HasValue ? gridCurrentPage[i].CheckingQty.Value : 0;
                        currentPage[i].txtCheckingQtyID = gridCurrentPage[i].txtCheckingQtyID;
                    }
                }

                // 2. Update DetailList_ForView
                var currentPage_ForView = (from p in param.DetailList_ForView where p.Page == param.CurrentPage select p).ToList <dtCheckingDetailList>();
                for (int i = 0; i < currentPage_ForView.Count; i++)
                {
                    if (currentPage_ForView[i].key == gridCurrentPage[i].key)
                    {
                        currentPage_ForView[i].CheckingQty      = gridCurrentPage[i].CheckingQty; // gridCurrentPage[i].CheckingQty.HasValue ? gridCurrentPage[i].CheckingQty.Value : 0;
                        currentPage_ForView[i].txtCheckingQtyID = gridCurrentPage[i].txtCheckingQtyID;
                    }
                }



                // Add new entry
                int nextRunningNo = param.DetailList.Count == 0 ? 1 : (param.DetailList[param.DetailList.Count - 1].RunningNoInSlip + 1);

                // Prepare

                // 1. RowItem (for save)
                tbt_InventoryCheckingSlipDetail newRowItem = new tbt_InventoryCheckingSlipDetail()
                {
                    InstrumentCode  = data.InstrumentCode,
                    RunningNoInSlip = nextRunningNo,
                    AreaCode        = data.AreaCode,
                    ShelfNo         = data.ShelfNo,
                    StockQty        = 0,    // 0 for add new
                    CheckingQty     = null, //0,  // defualt 0 , and user will input again in grid
                    AddFlag         = true,
                    CreateDate      = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                    CreateBy        = CommonUtil.dsTransData.dtUserData.EmpNo,
                    UpdateDate      = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                    UpdateBy        = CommonUtil.dsTransData.dtUserData.EmpNo,
                };

                // 2. RowItem (for view)
                dtCheckingDetailList newRowItem_ForView = CommonUtil.CloneObject <IVS160_AddData, dtCheckingDetailList>(data);
                newRowItem_ForView.CheckingQty = null; // 0;
                newRowItem_ForView.AddFlag     = true;

                // Add to list
                param.DetailList.Add(newRowItem);
                param.DetailList_ForView.Add(newRowItem_ForView);


                // Prepare list for return to show in grid
                int maxpage = param.DetailList_ForView.Max(m => m.Page);
                currentPage_ForView = (from p in param.DetailList_ForView where p.Page == maxpage select p).ToList <dtCheckingDetailList>();

                param.CurrentPage = maxpage;

                list = currentPage_ForView;
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }

            res.ResultData = CommonUtil.ConvertToXml <dtCheckingDetailList>(list, "Inventory\\IVS160", CommonUtil.GRID_EMPTY_TYPE.SEARCH);
            return(Json(res));
        }
Exemple #2
0
        /// <summary>
        /// Register checking instrument.<br />
        /// - Check system suspending.<br />
        /// - Check implement stock checking.<br />
        /// - Insert checking slip.<br />
        /// - Generate report.
        /// </summary>
        /// <param name="gridCurrentPage"></param>
        /// <param name="checkingDate"></param>
        /// <returns></returns>
        public ActionResult IVS160_Confirm()
        {
            string strInventorySlipNo = string.Empty;
            string slipNoReportPath   = string.Empty;

            ObjectResultData res = new ObjectResultData();

            try
            {
                IVS160_ScreenParameter param = GetScreenObject <IVS160_ScreenParameter>();
                int iTotalItem = 0;
                int iTotalPage = 0;

                if (param.DetailList != null)
                {
                    if (param.DetailList.Count > 0)
                    {
                        iTotalItem = param.DetailList == null ? 0 : param.DetailList.Count;
                        iTotalPage = param.DetailList == null ? 0 : param.DetailList.Max(m => m.Page);
                    }
                }

                if (param.DetailList == null)
                {
                    param.DetailList  = new List <tbt_InventoryCheckingSlipDetail>();
                    param.CurrentPage = 1;
                }
                if (param.DetailList_ForView == null)
                {
                    param.DetailList_ForView = new List <dtCheckingDetailList>();
                }


                // Is suspend ?
                ICommonHandler handlerCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (handlerCommon.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }

                IInventoryHandler handlerInventory = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;

                // Check for the implement stock checkint
                if (handlerInventory.CheckImplementStockChecking() == 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4003);
                    return(Json(res));
                }

                ILogHandler handlerLog = ServiceContainer.GetService <ILogHandler>() as ILogHandler;
                IInventoryDocumentHandler handlerInventoryDocument = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;

                if (param.DetailList.Count > 0)
                {
                    // TODO: (Narupon) Uncomment for use TransactionScope

                    // Save data to database..
                    using (TransactionScope scope = new TransactionScope())
                    {
                        strInventorySlipNo = handlerInventory.GenerateInventorySlipNo(param.OfficeCode, SlipID.C_INV_SLIPID_CHEKCING_INSTRUMENT);
                        param.SlipNo       = strInventorySlipNo;

                        // Save header ...
                        List <tbt_InventoryCheckingSlip> header     = new List <tbt_InventoryCheckingSlip>();
                        tbt_InventoryCheckingSlip        headerItem = new tbt_InventoryCheckingSlip()
                        {
                            SlipNo            = strInventorySlipNo,
                            SlipStatus        = InventoryCheckingSlipStatus.C_INV_SLIP_STATUS_CHECKING,
                            CheckingYearMonth = param.CheckingYearMonth,
                            CheckingStartDate = param.CheckingDate,
                            LocationCode      = param.LocationCode,
                            OfficeCode        = param.OfficeCode,
                            CreateDate        = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                            CreateBy          = CommonUtil.dsTransData.dtUserData.EmpNo,
                            UpdateDate        = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                            UpdateBy          = CommonUtil.dsTransData.dtUserData.EmpNo
                        };
                        header.Add(headerItem);
                        List <tbt_InventoryCheckingSlip> headerSavedResult = handlerInventory.InsertTbt_InventoryCheckingSlip(header);

                        // Save detail..
                        var lstLatestSlip = handlerInventory.GetCheckingDetailList(new doGetCheckingDetailList()
                        {
                            CheckingYearMonth = param.CheckingYearMonth,
                            OfficeCode        = param.OfficeCode,
                            LocationCode      = param.LocationCode,
                            AreaCode          = param.AreaCode,
                        });

                        List <tbt_InventoryCheckingSlipDetail> lstUpdatingDetail = new List <tbt_InventoryCheckingSlipDetail>();
                        foreach (var item in lstLatestSlip)
                        {
                            tbt_InventoryCheckingSlipDetail newRowItem = new tbt_InventoryCheckingSlipDetail()
                            {
                                SlipNo             = strInventorySlipNo,
                                InstrumentCode     = item.InstrumentCode,
                                RunningNoInSlip    = item.RunningNoInSlip,
                                AreaCode           = item.AreaCode,
                                ShelfNo            = item.ShelfNo,
                                StockQty           = item.StockQty,
                                CheckingQty        = item.CheckingQty,
                                DefaultCheckingQty = item.CheckingQty,
                                AddFlag            = item.AddFlag,
                                CreateDate         = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                                CreateBy           = CommonUtil.dsTransData.dtUserData.EmpNo,
                                UpdateDate         = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                                UpdateBy           = CommonUtil.dsTransData.dtUserData.EmpNo
                            };

                            lstUpdatingDetail.Add(newRowItem);
                        }
                        ;

                        foreach (var newdetail in param.DetailList.Where(d => d.DefaultCheckingQty != d.CheckingQty))
                        {
                            var editdetail = lstUpdatingDetail.Where(d => d.key == newdetail.key).FirstOrDefault();
                            if (editdetail == null)
                            {
                                newdetail.SlipNo          = strInventorySlipNo;
                                newdetail.RunningNoInSlip = lstUpdatingDetail.Max(d => d.RunningNoInSlip) + 1;
                                lstUpdatingDetail.Add(newdetail);
                            }
                            else
                            {
                                editdetail.CheckingQty = newdetail.CheckingQty;
                            }
                        }

                        List <tbt_InventoryCheckingSlipDetail> detailSavedResult = handlerInventory.InsertTbt_InventoryCheckingSlipDetail(lstUpdatingDetail);

                        // Generate report ...  // C_INV_REPORT_ID_CHECKING_INSTRUMENT_RESULT = IVR110

                        slipNoReportPath = handlerInventoryDocument.GenerateIVR110FilePath(strInventorySlipNo, param.OfficeCode, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);

                        param.SlipNoReportPath = slipNoReportPath;

                        scope.Complete(); // Commit transtion.
                    }

                    // TODO: (Narupon) Uncomment for use TransactionScope

                    res.ResultData = strInventorySlipNo;
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
                return(Json(res));
            }

            return(Json(res));
        }
Exemple #3
0
        /// <summary>
        /// Search checking detail.
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ActionResult IVS160_SearchResponse(IVS160_SearchCondition cond)
        {
            IVS160_ScreenParameter param = GetScreenObject <IVS160_ScreenParameter>();

            List <dtCheckingDetailList> list         = new List <dtCheckingDetailList>();
            List <dtCheckingDetailList> list_ForView = new List <dtCheckingDetailList>();
            ObjectResultData            res          = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                // Check required field.
                if (ModelState.IsValid == false)
                {
                    ValidatorUtil.BuildErrorMessage(res, this);
                    if (res.IsError)
                    {
                        return(Json(res));
                    }
                }

                // Keep office code
                param.OfficeCode = cond.OfficeCode;

                // Keep location code
                param.LocationCode = cond.LocationCode;

                param.AreaCode = cond.AreaCode;

                IInventoryHandler handlerInventory = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                list = handlerInventory.GetCheckingDetailList(cond);

                // clear
                param.DetailList         = new List <tbt_InventoryCheckingSlipDetail>();
                param.DetailList_ForView = new List <dtCheckingDetailList>();
                param.CurrentPage        = 0;

                if (list.Count > 0)
                {
                    // clone from dtCheckingDetailList -> tbt_InventoryCheckingSlipDetail
                    tbt_InventoryCheckingSlipDetail newRowItem;
                    foreach (var item in list)
                    {
                        newRowItem = new tbt_InventoryCheckingSlipDetail()
                        {
                            InstrumentCode     = item.InstrumentCode,
                            RunningNoInSlip    = item.RunningNoInSlip,
                            AreaCode           = item.AreaCode,
                            ShelfNo            = item.ShelfNo,
                            StockQty           = item.StockQty,
                            CheckingQty        = item.CheckingQty,
                            DefaultCheckingQty = item.CheckingQty,
                            AddFlag            = item.AddFlag,
                            CreateDate         = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                            CreateBy           = CommonUtil.dsTransData.dtUserData.EmpNo,
                            UpdateDate         = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                            UpdateBy           = CommonUtil.dsTransData.dtUserData.EmpNo
                        };
                        item.DefaultCheckingQty = item.CheckingQty;

                        param.DetailList.Add(newRowItem);
                    }
                    ;

                    param.DetailList_ForView.AddRange(list);
                    param.CurrentPage = 1;
                }


                list_ForView = (from p in param.DetailList_ForView where p.Page == param.CurrentPage select p).ToList <dtCheckingDetailList>();
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }

            res.ResultData = CommonUtil.ConvertToXml <dtCheckingDetailList>(list_ForView, "Inventory\\IVS160", CommonUtil.GRID_EMPTY_TYPE.SEARCH);
            return(Json(res));
        }