public ActionResult IVS288_GenerateReportSummary(string[] slipNo)
        {
            IVS288_ScreenParameter param = GetScreenObject <IVS288_ScreenParameter>();

            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                if (slipNo == null || slipNo.Length == 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0006);
                }
                else if (param.LastSearchParam != null)
                {
                    IInventoryHandler service = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                    var lst = service.GetStockReport_ChangeArea_Detail(string.Join(",", slipNo));
                    IInventoryDocumentHandler docService = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                    param.PendingDownloadFilePath = docService.GenerateIVS288ChangeAreaReportSummary(lst, param.LastSearchParam);
                    param.PendingDownloadFileName = "ChangeaAreaReport.xlsx";
                    res.ResultData = true;
                }
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        public ActionResult IVS170_GenerateReport(IVS170_doGetStockCheckingList cond)
        {
            List <dtStockCheckingList> list = new List <dtStockCheckingList>();

            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

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

                //Validate #1
                //if (CommonUtil.IsNullAllField(cond))
                //{
                //    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0006);
                //    return Json(res);
                //}

                //Validate #2
                if ((!CommonUtil.IsNullOrEmpty(cond.ShelfNoFrom)) &&
                    (!CommonUtil.IsNullOrEmpty(cond.ShelfNoTo)) &&
                    (String.Compare(cond.ShelfNoFrom, cond.ShelfNoTo) > 0))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4015, null, new string[] { "ShelfNoFrom", "ShelfNoTo" });
                    return(Json(res));
                }

                IInventoryHandler handler = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                list = handler.GetStockCheckingList(cond);

                if (list == null || list.Count <= 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001, null, null);
                    return(Json(res));
                }

                IVS170_ScreenParameter    param      = GetScreenObject <IVS170_ScreenParameter>();
                IInventoryDocumentHandler docService = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                param.PendingDownloadFilePath = docService.GenerateIVS170StockTakingResult(list, cond);
                param.PendingDownloadFileName = "StockDifferenceList.xlsx";

                res.ResultData = true;
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }
Exemple #3
0
        /// <summary>
        /// Search instrument information
        /// </summary>
        /// <param name="Cond">Search condition object</param>
        /// <returns></returns>
        public ActionResult IVS100_SearchInventoryInstrument(IVS100SearchCond Cond)
        {
            IInventoryDocumentHandler handler = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;

            ObjectResultData res = new ObjectResultData();

            try
            {    //Valid Cond
                ValidatorUtil.BuildErrorMessage(res, this, new object[] { Cond });
                if (res.IsError)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    return(Json(res));
                }

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

                IVS100_ScreenParameter param = GetScreenObject <IVS100_ScreenParameter>();

                List <dtSearchInstrumentListResult> lstResult =

                    InvH.SearchInventoryInstrumentList(param.office.OfficeCode,
                                                       Cond.SourceLoc,
                                                       Cond.InstArea,
                                                       ShelfType.C_INV_SHELF_TYPE_NORMAL,
                                                       null,
                                                       null,
                                                       Cond.InstName,
                                                       Cond.InstCode,
                                                       new string[] { InstrumentArea.C_INV_AREA_SE_LENDING_DEMO }
                                                       );

                if (lstResult.Count == 0)
                {
                    //res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001);
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    return(Json(res));
                }
                else if (lstResult.Count > 1000)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4004);
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    return(Json(res));
                }

                res.ResultData = CommonUtil.ConvertToXml <dtSearchInstrumentListResult>(lstResult, "inventory\\IVS100_Instrument", CommonUtil.GRID_EMPTY_TYPE.SEARCH);
                return(Json(res));
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex); return(Json(res));
            }
        }
Exemple #4
0
        // Akat K. Test Download Report
        public void IVR_TestDownload(string strSessionKey)
        {
            IInventoryDocumentHandler invH = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;

            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + "test_download_slip.pdf");
            Response.ContentType     = "application/pdf";
            Response.Charset         = "UTF-8";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");

            Stream streamFile = invH.GenerateIVR010("50400520120201", "", CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);

            using (MemoryStream ms = new MemoryStream()) {
                streamFile.CopyTo(ms);
                Response.BinaryWrite(ms.ToArray());
            }
            Response.End();
        }
        public ActionResult IVS284_GenerateReportSummary(doIVS284SearchCondition reportParam)
        {
            IVS284_ScreenParameter param = GetScreenObject <IVS284_ScreenParameter>();

            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                if (reportParam == null || reportParam.ContractCodeSelected == null || reportParam.ContractCodeSelected.Length == 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0006);
                }
                else
                {
                    if (param.LastSearchParam == null)
                    {
                        param.LastSearchParam = reportParam;
                    }

                    IInventoryHandler service = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                    var lst = service.GetStockReport_InprocessToInstall(new doIVS284SearchCondition()
                    {
                        ReportType           = param.LastSearchParam.ReportType,
                        ContractCode         = null,
                        ContractCodeSelected = reportParam.ContractCodeSelected,
                        YearMonth            = reportParam.YearMonth,
                    });
                    IInventoryDocumentHandler docService = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                    param.PendingDownloadFilePath = docService.GenerateIVS284InprocessToInstallReportSummary(param.LastSearchParam.ReportType, lst, param.LastSearchParam);
                    param.PendingDownloadFileName = "InprocessToInstallReport.xlsx";
                    res.ResultData = true;
                }
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        public ActionResult IVS283_GenerateReport(doIVS283SearchCondition reportParam)
        {
            IVS283_ScreenParameter param = GetScreenObject <IVS283_ScreenParameter>();

            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                if (reportParam == null || reportParam.InstrumentCodeSelected == null || reportParam.InstrumentCodeSelected.Length == 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0006);
                }
                else
                {
                    if (param.LastSearchParam == null)
                    {
                        param.LastSearchParam = reportParam;
                    }

                    IInventoryHandler service = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                    var lst = service.GetStockReport_Movement(param.LastSearchParam.ReportType, string.Join(",", reportParam.InstrumentCodeSelected), reportParam.YearMonth);
                    IInventoryDocumentHandler docService = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                    param.PendingDownloadFilePath = docService.GenerateIVS283MovementReport(param.LastSearchParam.ReportType, lst);
                    param.PendingDownloadFileName = "MovementReport.xlsx";
                    res.ResultData = true;
                }
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        /// <summary>
        /// Confirming picking list registration.
        /// </summary>
        /// <param name="lstInstallationSlipNo">List of installation slip no. for registering.</param>
        /// <returns>Return ActionResult of confirmation process result.</returns>
        public ActionResult IVS240_ConfirmPickingList(List <string> lstInstallationSlipNo)
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION; //All message during confirmation process must be information dialog box.

            try
            {
                IVS240_ScreenParameter sParam = GetScreenObject <IVS240_ScreenParameter>(); //Add by Jutarat A. on 04122012

                ICommonHandler srvCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (srvCommon.IsSystemSuspending())
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, null, null);
                    return(Json(res));
                }

                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_PICKING_LIST, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, null, null);
                    return(Json(res));
                }

                if (lstInstallationSlipNo == null || lstInstallationSlipNo.Count <= 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4063);
                    res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, null, null);
                    return(Json(res));
                }

                IInventoryHandler srvInv   = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                List <string>     lstError = new List <string>();

                List <tbt_InventorySlip> lstInvSlip = new List <tbt_InventorySlip>();
                foreach (var strInstallationSlipNo in lstInstallationSlipNo)
                {
                    var lstTempInvSlip = srvInv.GetTbt_InventorySlip(null, strInstallationSlipNo);
                    //if (lstInvSlip.Count > 0 && lstInvSlip[0].PickingListNo != null)
                    //{
                    //    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4064
                    //        , new string[] { strInstallationSlipNo });
                    //    lstError.Add(strInstallationSlipNo);
                    //}

                    if (lstTempInvSlip.Any(p => p.PickingListNo != null))
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4064
                                            , new string[] { strInstallationSlipNo });
                        lstError.Add(strInstallationSlipNo);
                        res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, lstError, null);
                        return(Json(res));
                    }

                    lstInvSlip.AddRange(lstTempInvSlip);
                }

                //if (lstError.Count > 0)
                //{
                //    res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, lstError, null);
                //    return Json(res);
                //}

                string strPickingListNo = srvInv.GeneratePickingListNo();

                #region //R2
                foreach (var slip in lstInvSlip)
                {
                    slip.PickingListNo = strPickingListNo;

                    //Comment by Jutarat A. on 30052013 (Set at UpdateTbt_InventorySlip())
                    //slip.UpdateBy = CommonUtil.dsTransData.dtUserData.EmpNo;
                    //slip.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    //End Comment
                }
                #endregion

                srvInv.UpdateTbt_InventorySlip(lstInvSlip);

                IInventoryDocumentHandler srvInvDoc = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;

                //srvInvDoc.GenerateIVR170FilePath(strPickingListNo, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);
                sParam.ResultStream = srvInvDoc.GenerateIVR170(strPickingListNo, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime); //Modify by Jutarat A. on 04122012

                res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(true, null, strPickingListNo);
                return(Json(res));
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
                res.ResultData = this.IVS240_ConfirmPickingList_CreateResult(false, null, null);;
                return(Json(res));
            }
        }
Exemple #8
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 #9
0
        /// <summary>
        /// Register transfer stock-out repairing instrument data
        /// </summary>
        /// <param name="Con">Register condition object</param>
        /// <returns></returns>
        public ActionResult IVS100_cmdConfirm(IVS100RegisterCond Con)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {       //Check Suspend
                IVS100_ScreenParameter prm = GetScreenObject <IVS100_ScreenParameter>();
                if (prm.ElemInstrument == null)
                {
                    prm.ElemInstrument = new List <IVS100INST>();
                }

                ICommonHandler ComH = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (ComH.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }
                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_REPAIR_REQUEST, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

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

                //prm.ElemInstrument = (from x in prm.ElemInstrument
                //                      orderby x.InstrumentCode, x.AreaCode
                //                      select x).ToList();

                foreach (IVS100INST i in prm.ElemInstrument)
                {
                    doCheckTransferQty Cond = new doCheckTransferQty();
                    Cond.OfficeCode     = prm.office.OfficeCode;
                    Cond.LocationCode   = prm.Location;
                    Cond.AreaCode       = i.AreaCode;
                    Cond.ShelfNo        = i.ShelfNo;
                    Cond.InstrumentCode = i.InstrumentCode;
                    Cond.TransferQty    = i.StockOutQty;

                    doCheckTransferQtyResult TransferQtyResult = InvH.CheckTransferQty(Cond);

                    i.InstrumentQty = TransferQtyResult.CurrentyQty;

                    //8.2.1
                    if (TransferQtyResult.OverQtyFlag == null)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4009, new string[] { i.InstrumentCode }, new string[] { i.StockOutQty_id });
                        res.ResultData = prm.ElemInstrument;
                        i.IsError      = true;
                        return(Json(res));
                    }
                    else if (TransferQtyResult.OverQtyFlag == true)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4008, new string[] { i.InstrumentCode }, new string[] { i.StockOutQty_id });
                        res.ResultData = prm.ElemInstrument;
                        i.IsError      = true;
                        return(Json(res));
                    }
                }

                string strInventorySlipNo = string.Empty;

                using (TransactionScope scope = new TransactionScope())
                {
                    //8.3
                    doRegisterTransferInstrumentData data = new doRegisterTransferInstrumentData();
                    data.SlipId = SlipID.C_INV_SLIPID_REPAIR_REQUEST;

                    tbt_InventorySlip InvSlip = new tbt_InventorySlip();
                    InvSlip.SlipNo                  = null;
                    InvSlip.SlipStatus              = InventorySlipStatus.C_INV_SLIP_STATUS_TRANSFER;
                    InvSlip.TransferTypeCode        = TransferType.C_INV_TRANSFERTYPE_REPAIR_REQUEST;
                    InvSlip.InstallationSlipNo      = null;
                    InvSlip.ProjectCode             = null;
                    InvSlip.PurchaseOrderNo         = null;
                    InvSlip.ContractCode            = null;
                    InvSlip.SlipIssueDate           = DateTime.Now;
                    InvSlip.StockInDate             = null;
                    InvSlip.StockOutDate            = DateTime.Now;
                    InvSlip.SourceLocationCode      = prm.Location;
                    InvSlip.DestinationLocationCode = InstrumentLocation.C_INV_LOC_REPAIRING;
                    InvSlip.SourceOfficeCode        = prm.office.OfficeCode;
                    InvSlip.DestinationOfficeCode   = prm.office.OfficeCode;
                    InvSlip.ApproveNo               = prm.ApproveNo;
                    InvSlip.Memo                     = prm.Memo;
                    InvSlip.StockInFlag              = null;
                    InvSlip.DeliveryOrderNo          = null;
                    InvSlip.ShelfType                = ShelfType.C_INV_SHELF_TYPE_NORMAL;
                    InvSlip.RepairSubcontractor      = prm.RepairSubContractor;
                    InvSlip.InstallationCompleteFlag = null;
                    InvSlip.ContractStartServiceFlag = null;
                    InvSlip.CustomerAcceptanceFlag   = null;
                    // doSlip.ProjectCompleteFlag=null;
                    InvSlip.PickingListNo = null;
                    InvSlip.CreateBy      = CommonUtil.dsTransData.dtUserData.EmpNo;
                    InvSlip.CreateDate    = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.UpdateDate    = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.UpdateBy      = CommonUtil.dsTransData.dtUserData.EmpNo;

                    data.InventorySlip = InvSlip;
                    data.lstTbt_InventorySlipDetail = new List <tbt_InventorySlipDetail>();

                    int iRunNo = 1;
                    foreach (IVS100INST i in prm.ElemInstrument)
                    {
                        tbt_InventorySlipDetail SlipDetail = new tbt_InventorySlipDetail();
                        SlipDetail.SlipNo              = null;
                        SlipDetail.RunningNo           = iRunNo;
                        SlipDetail.InstrumentCode      = i.InstrumentCode;
                        SlipDetail.SourceAreaCode      = i.AreaCode;
                        SlipDetail.DestinationAreaCode = i.AreaCode;
                        SlipDetail.SourceShelfNo       = i.ShelfNo;
                        SlipDetail.DestinationShelfNo  = ShelfNo.C_INV_SHELF_NO_OTHER_LOCATION;
                        SlipDetail.TransferQty         = i.StockOutQty;
                        SlipDetail.NotInstalledQty     = null;
                        SlipDetail.RemovedQty          = null;
                        SlipDetail.UnremovableQty      = null;
                        SlipDetail.InstrumentAmount    = null;

                        data.lstTbt_InventorySlipDetail.Add(SlipDetail);
                        iRunNo++;
                    }

                    //8.4
                    strInventorySlipNo = InvH.RegisterTransferInstrument(data);

                    //8.5
                    if (InvH.CheckNewInstrument(strInventorySlipNo) == 1)
                    {
                        //8.5.1
                        List <doGroupNewInstrument> groupNewInstrument = InvH.GetGroupNewInstrument(strInventorySlipNo);
                        foreach (doGroupNewInstrument i in groupNewInstrument)
                        {
                            //8.5.2
                            i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_REPAIR_REQUEST;
                            //8.5.3
                            #region Monthly Price @ 2015
                            decimal decMovingAveragePrice = InvH.GetMonthlyAveragePrice(i.Instrumentcode, InvSlip.SlipIssueDate, InventoryAccountCode.C_INV_ACCOUNT_CODE_INSTOCK, SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_LOCAL, SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US);
                            #endregion
                            InvH.UpdateAccountTransferNewInstrument(i, Convert.ToDecimal(decMovingAveragePrice));
                        }
                    }
                    //8.6
                    int blnCheckSecondhandInstrument = InvH.CheckSecondhandInstrument(strInventorySlipNo);
                    if (blnCheckSecondhandInstrument == 1)
                    {
                        //8.6.1
                        List <doGroupSecondhandInstrument> GroupSecondHandInstrument = InvH.GetGroupSecondhandInstrument(strInventorySlipNo);
                        foreach (doGroupSecondhandInstrument i in GroupSecondHandInstrument)
                        {
                            //8.6.2
                            i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_REPAIR_REQUEST;
                            InvH.UpdateAccountTransferSecondhandInstrument(i);
                        }
                    }

                    //8.7
                    int blnCheckSampleInstrument = InvH.CheckSampleInstrument(strInventorySlipNo);
                    if (blnCheckSampleInstrument == 1)
                    {
                        //8.7.1
                        List <doGroupSampleInstrument> GroupSampleInstrument = InvH.GetGroupSampleInstrument(strInventorySlipNo);
                        foreach (doGroupSampleInstrument i in GroupSampleInstrument)
                        {
                            //8.7.2
                            i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_REPAIR_REQUEST;
                            InvH.UpdateAccountTransferSampleInstrument(i, null);
                        }
                    }

                    scope.Complete();
                }

                //8.8.1
                IInventoryDocumentHandler handlerInventoryDocument = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                string strReportPath = handlerInventoryDocument.GenerateIVR070FilePath(strInventorySlipNo, prm.office.OfficeCode, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);

                prm.slipNoReportPath = strReportPath;
                prm.slipNo           = strInventorySlipNo;

                res.ResultData = strInventorySlipNo;

                return(Json(res));
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex); return(Json(res));
            }
        }
        /// <summary>
        /// Register pre-elimination.<br />
        /// - Check system suspending.<br />
        /// - Check permission.<br />
        /// - Check quantity.<br />
        /// - Insert inventory slip.<br />
        /// - Update account transfer new/second hand/sample instrument.<br />
        /// - Generate report.
        /// </summary>
        /// <returns></returns>
        public ActionResult IVS040_cmdConfirm()
        {
            ObjectResultData res = new ObjectResultData();

            try
            {       //Check Suspend
                IVS040_ScreenParameter prm = GetScreenObject <IVS040_ScreenParameter>();
                if (prm.ElemInstrument == null)
                {
                    prm.ElemInstrument = new List <IVS040INST>();
                }
                ICommonHandler ComH = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (ComH.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }
                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_PRE_ELIMINATION, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

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

                bool isError = false;
                foreach (IVS040INST i in prm.ElemInstrument)
                {
                    doCheckTransferQty Cond = new doCheckTransferQty();
                    Cond.OfficeCode     = prm.office.OfficeCode;
                    Cond.LocationCode   = prm.Location;
                    Cond.AreaCode       = i.AreaCode;
                    Cond.ShelfNo        = i.ShelfNo;
                    Cond.InstrumentCode = i.InstrumentCode;
                    Cond.TransferQty    = i.TransferInstrumentQty;

                    doCheckTransferQtyResult TransferQtyResult = InvH.CheckTransferQty(Cond);
                    i.InstrumentQty = TransferQtyResult.CurrentyQty;

                    //8.2.1

                    if (TransferQtyResult.OverQtyFlag == null)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4009, new string[] { i.InstrumentCode }, new string[] { i.TransQtyID });
                        //res.ResultData = i.InstrumentCode + "," + i.row_id;
                        isError = true;
                    }
                    else if (TransferQtyResult.OverQtyFlag == true)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4008, new string[] { i.InstrumentCode }, new string[] { i.TransQtyID });
                        //res.ResultData = i.InstrumentCode + "," + i.row_id;
                        isError = true;
                    }
                }
                if (isError)
                {
                    //res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    res.ResultData = prm.ElemInstrument;
                    return(Json(res));
                }

                string strInventorySlipNo = null;
                using (TransactionScope scope = new TransactionScope())
                {
                    //8.3
                    doRegisterTransferInstrumentData data = new doRegisterTransferInstrumentData();
                    data.SlipId        = SlipID.C_INV_SLIPID_PRE_ELIMINATE;
                    data.InventorySlip = new tbt_InventorySlip();
                    data.lstTbt_InventorySlipDetail = new List <tbt_InventorySlipDetail>();
                    tbt_InventorySlip InvSlip = new tbt_InventorySlip();
                    InvSlip.SlipStatus         = InventorySlipStatus.C_INV_SLIP_STATUS_COMPLETE;
                    InvSlip.TransferTypeCode   = TransferType.C_INV_TRANSFERTYPE_PRE_ELIMINATION;
                    InvSlip.SlipIssueDate      = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.StockInDate        = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.StockOutDate       = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.SourceLocationCode = prm.Location;
                    //InvSlip.DestinationLocationCode = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                    InvSlip.DestinationLocationCode = prm.DestinationLocation;
                    InvSlip.SourceOfficeCode        = prm.office.OfficeCode;
                    InvSlip.DestinationOfficeCode   = prm.office.OfficeCode;
                    InvSlip.ApproveNo  = prm.ApproveNo;
                    InvSlip.Memo       = prm.Memo;
                    InvSlip.ShelfType  = ShelfType.C_INV_SHELF_TYPE_NORMAL;
                    InvSlip.CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                    InvSlip.CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;

                    data.InventorySlip = InvSlip;

                    data.lstTbt_InventorySlipDetail = new List <tbt_InventorySlipDetail>();
                    int iRunNo = 1;
                    List <IVS040INST> sortedList = (
                        from row in prm.ElemInstrument
                        orderby row.InstrumentCode, row.AreaCode
                        select row
                        ).ToList <IVS040INST>();

                    foreach (IVS040INST i in sortedList)
                    {
                        tbt_InventorySlipDetail SlipDetail = new tbt_InventorySlipDetail();
                        SlipDetail.RunningNo           = iRunNo;
                        SlipDetail.InstrumentCode      = i.InstrumentCode;
                        SlipDetail.SourceAreaCode      = i.AreaCode;
                        SlipDetail.DestinationAreaCode = i.AreaCode;
                        SlipDetail.SourceShelfNo       = i.ShelfNo;
                        if (InstrumentLocation.C_INV_LOC_INSTOCK == prm.DestinationLocation)
                        {
                            SlipDetail.DestinationShelfNo = ShelfNo.C_INV_SHELF_NO_NOT_MOVE_SHELF;
                        }
                        else
                        {
                            SlipDetail.DestinationShelfNo = ShelfNo.C_INV_SHELF_NO_OTHER_LOCATION;
                        }
                        //SlipDetail.DestinationShelfNo = ShelfNo.C_INV_SHELF_NO_OTHER_LOCATION;
                        SlipDetail.TransferQty = i.TransferInstrumentQty;

                        data.lstTbt_InventorySlipDetail.Add(SlipDetail);
                        iRunNo++;
                    }

                    strInventorySlipNo = InvH.RegisterTransferInstrument(data);
                    if (InvH.CheckNewInstrument(strInventorySlipNo) == 1)
                    {
                        //8.5.1
                        List <doGroupNewInstrument> groupNewInstrument = InvH.GetGroupNewInstrument(strInventorySlipNo);
                        foreach (doGroupNewInstrument i in groupNewInstrument)
                        {
                            //i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                            #region Monthly Price @ 2015
                            //decimal decMovingAveragePrice = InvH.CalculateMovingAveragePrice(i);
                            var decMovingAveragePrice = InvH.GetMonthlyAveragePrice(i.Instrumentcode, InvSlip.SlipIssueDate, InventoryAccountCode.C_INV_ACCOUNT_CODE_INSTOCK, SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_LOCAL, SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US);
                            #endregion
                            InvH.UpdateAccountTransferNewInstrument(i, Convert.ToDecimal(decMovingAveragePrice));
                        }
                    }

                    //8.6
                    int blnCheckSecondhandInstrument = InvH.CheckSecondhandInstrument(strInventorySlipNo);
                    if (blnCheckSecondhandInstrument == 1)
                    {
                        List <doGroupSecondhandInstrument> GroupSecondHandInstrument = InvH.GetGroupSecondhandInstrument(strInventorySlipNo);
                        foreach (doGroupSecondhandInstrument i in GroupSecondHandInstrument)
                        {
                            //i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                            InvH.UpdateAccountTransferSecondhandInstrument(i);
                        }
                    }

                    //8.7

                    int blnCheckSampleInstrument = InvH.CheckSampleInstrument(strInventorySlipNo);
                    if (blnCheckSampleInstrument == 1)
                    {
                        List <doGroupSampleInstrument> GroupSampleInstrument = InvH.GetGroupSampleInstrument(strInventorySlipNo);
                        foreach (doGroupSampleInstrument i in GroupSampleInstrument)
                        {
                            //i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                            InvH.UpdateAccountTransferSampleInstrument(i, null);
                        }
                    }

                    scope.Complete();
                } //end transaction scope

                //8.8
                IInventoryDocumentHandler handlerInventoryDocument = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                string reportPath = handlerInventoryDocument.GenerateIVR020FilePath(strInventorySlipNo, prm.office.OfficeCode, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);
                prm.slipNo         = strInventorySlipNo;
                prm.reportFilePath = reportPath;
                UpdateScreenObject(prm);

                res.ResultData = strInventorySlipNo;

                return(Json(res));
            }
            catch (Exception ex)
            {
                res.ResultData = "toregister";
                res.AddErrorMessage(ex); return(Json(res));
            }
        }
        /// <summary>
        /// Register Elimination.<br />
        /// - Check system suspending.<br />
        /// - Check quantity.<br />
        /// - Insert inventory slip.<br />
        /// - Update account transfer new/second hand/sample instrument.<br />
        /// - Insert account stock moving.<br />
        /// - Generate report.
        /// </summary>
        /// <returns></returns>
        public ActionResult IVS050_cmdConfirm()
        {
            ObjectResultData res = new ObjectResultData();

            try
            {       //Check Suspend
                IVS050_ScreenParameter prm = GetScreenObject <IVS050_ScreenParameter>();
                if (prm.ElemInstrument == null)
                {
                    prm.ElemInstrument = new List <IVS040INST>();
                }
                ICommonHandler ComH = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (ComH.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }
                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_ELIMINATION, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

                IInventoryHandler InvH = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                //8.4.1
                bool isError = false;
                foreach (IVS040INST i in prm.ElemInstrument)
                {
                    doCheckTransferQty Cond = new doCheckTransferQty();
                    Cond.OfficeCode     = prm.office.OfficeCode;
                    Cond.LocationCode   = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                    Cond.AreaCode       = i.AreaCode;
                    Cond.ShelfNo        = i.ShelfNo;
                    Cond.InstrumentCode = i.InstrumentCode;
                    Cond.TransferQty    = i.TransferInstrumentQty;

                    doCheckTransferQtyResult TransferQtyResult = InvH.CheckTransferQty(Cond);
                    i.InstrumentQty = TransferQtyResult.CurrentyQty;

                    if (TransferQtyResult.OverQtyFlag == null)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4009, new string[] { i.InstrumentCode }, new string[] { i.TransQtyID });
                        //res.ResultData = i.InstrumentCode + "," + i.row_id;
                        isError = true;
                    }
                    else if (TransferQtyResult.OverQtyFlag == true)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4008, new string[] { i.InstrumentCode }, new string[] { i.TransQtyID });
                        //res.ResultData = i.InstrumentCode + "," + i.row_id;
                        isError = true;
                    }
                }
                if (isError)
                {
                    //res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    res.ResultData = prm.ElemInstrument;
                    return(Json(res));
                }

                string strInventorySlipNo = null;
                using (TransactionScope scope = new TransactionScope())
                {
                    //8.5
                    doRegisterTransferInstrumentData data = new doRegisterTransferInstrumentData();
                    data.SlipId = SlipID.C_INV_SLIPID_ELIMINATE;

                    data.InventorySlip = new tbt_InventorySlip();
                    data.lstTbt_InventorySlipDetail = new List <tbt_InventorySlipDetail>();
                    tbt_InventorySlip InvSlip = new tbt_InventorySlip();
                    InvSlip.SlipStatus              = InventorySlipStatus.C_INV_SLIP_STATUS_COMPLETE;
                    InvSlip.TransferTypeCode        = TransferType.C_INV_TRANSFERTYPE_ELIMINATION;
                    InvSlip.SlipIssueDate           = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.StockInDate             = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.StockOutDate            = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.SourceLocationCode      = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                    InvSlip.DestinationLocationCode = InstrumentLocation.C_INV_LOC_ELIMINATION;
                    InvSlip.SourceOfficeCode        = prm.office.OfficeCode;
                    InvSlip.DestinationOfficeCode   = prm.office.OfficeCode;
                    InvSlip.ApproveNo  = prm.ApproveNo;
                    InvSlip.Memo       = prm.Memo;
                    InvSlip.ShelfType  = ShelfType.C_INV_SHELF_TYPE_NORMAL;
                    InvSlip.CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                    InvSlip.CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                    InvSlip.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;

                    data.InventorySlip = InvSlip;

                    data.lstTbt_InventorySlipDetail = new List <tbt_InventorySlipDetail>();
                    int iRunNo = 1;
                    foreach (IVS040INST i in prm.ElemInstrument)
                    {
                        tbt_InventorySlipDetail SlipDetail = new tbt_InventorySlipDetail();
                        SlipDetail.SlipNo              = null;
                        SlipDetail.RunningNo           = iRunNo;
                        SlipDetail.InstrumentCode      = i.InstrumentCode;
                        SlipDetail.SourceAreaCode      = i.AreaCode;
                        SlipDetail.DestinationAreaCode = i.AreaCode;
                        SlipDetail.SourceShelfNo       = i.ShelfNo;
                        SlipDetail.DestinationShelfNo  = i.ShelfNo;
                        SlipDetail.TransferQty         = i.TransferInstrumentQty;
                        SlipDetail.InstrumentAmount    = i.TransferAmount;

                        data.lstTbt_InventorySlipDetail.Add(SlipDetail);
                        iRunNo++;
                    }
                    strInventorySlipNo = InvH.RegisterTransferInstrument(data);

                    List <tbt_AccountStockMoving> listInsertAccStockMoving = new List <tbt_AccountStockMoving>();

                    if (InvH.CheckNewInstrument(strInventorySlipNo) == 1)
                    {
                        //8.7.1
                        List <doGroupNewInstrument> groupNewInstrument = InvH.GetGroupNewInstrument(strInventorySlipNo);
                        foreach (doGroupNewInstrument i in groupNewInstrument)
                        {
                            i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_ELIMINATION;
                            #region Monthly Price @ 2015
                            //decimal decMovingAveragePrice = InvH.CalculateMovingAveragePrice(i);
                            decimal decMovingAveragePrice = InvH.GetMonthlyAveragePrice(i.Instrumentcode, InvSlip.SlipIssueDate, InventoryAccountCode.C_INV_ACCOUNT_CODE_INSTOCK, SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_LOCAL, SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US);
                            #endregion
                            bool canUpdate = InvH.UpdateAccountTransferNewInstrument(i, Convert.ToDecimal(decMovingAveragePrice));

                            if (!canUpdate)
                            {
                                scope.Dispose();
                                return(Json(res));
                            }

                            List <tbt_AccountInstock> listInstock = InvH.GetTbt_AccountInStock(i.Instrumentcode, InstrumentLocation.C_INV_LOC_PRE_ELIMINATION, prm.office.OfficeCode);
                            if (listInstock.Count <= 0)
                            {
                                scope.Dispose();
                                return(Json(res));
                            }
                            tbt_AccountStockMoving accountStockMoving = new tbt_AccountStockMoving();
                            accountStockMoving.SlipNo                      = strInventorySlipNo;
                            accountStockMoving.TransferTypeCode            = TransferType.C_INV_TRANSFERTYPE_ELIMINATION;
                            accountStockMoving.SourceAccountStockCode      = InventoryAccountCode.C_INV_ACCOUNT_CODE_INSTOCK;
                            accountStockMoving.DestinationAccountStockCode = InventoryAccountCode.C_INV_ACCOUNT_CODE_ELIMINATE;
                            accountStockMoving.SourceLocationCode          = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                            accountStockMoving.DestinationLocationCode     = InstrumentLocation.C_INV_LOC_ELIMINATION;
                            accountStockMoving.InstrumentCode              = i.Instrumentcode;
                            accountStockMoving.InstrumentQty               = i.TransferQty;
                            accountStockMoving.InstrumentPrice             = listInstock[0].MovingAveragePrice;
                            accountStockMoving.CreateDate                  = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            accountStockMoving.CreateBy                    = CommonUtil.dsTransData.dtUserData.EmpNo;
                            accountStockMoving.UpdateDate                  = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            accountStockMoving.UpdateBy                    = CommonUtil.dsTransData.dtUserData.EmpNo;
                            listInsertAccStockMoving.Add(accountStockMoving);
                        }
                    }

                    //8.8
                    int blnCheckSecondhandInstrument = InvH.CheckSecondhandInstrument(strInventorySlipNo);
                    if (blnCheckSecondhandInstrument == 1)
                    {
                        List <doGroupSecondhandInstrument> GroupSecondHandInstrument = InvH.GetGroupSecondhandInstrument(strInventorySlipNo);
                        foreach (doGroupSecondhandInstrument i in GroupSecondHandInstrument)
                        {
                            i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_ELIMINATION;
                            bool canUpdate = InvH.UpdateAccountTransferSecondhandInstrument(i);

                            if (!canUpdate)
                            {
                                scope.Dispose();
                                return(Json(res));
                            }

                            decimal sumTransferAmount = 0;
                            foreach (IVS040INST j in prm.ElemInstrument)
                            {
                                if (i.Instrumentcode == j.InstrumentCode &&
                                    (j.AreaCode == InstrumentArea.C_INV_AREA_SE_RENTAL || j.AreaCode == InstrumentArea.C_INV_AREA_SE_HANDLING_DEMO))
                                {
                                    sumTransferAmount += j.TransferAmount;
                                }
                            }

                            tbt_AccountStockMoving accountStockMoving = new tbt_AccountStockMoving();
                            accountStockMoving.SlipNo                      = strInventorySlipNo;
                            accountStockMoving.TransferTypeCode            = TransferType.C_INV_TRANSFERTYPE_ELIMINATION;
                            accountStockMoving.SourceAccountStockCode      = InventoryAccountCode.C_INV_ACCOUNT_CODE_INSTALLED;
                            accountStockMoving.DestinationAccountStockCode = InventoryAccountCode.C_INV_ACCOUNT_CODE_ELIMINATE;
                            accountStockMoving.SourceLocationCode          = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                            accountStockMoving.DestinationLocationCode     = InstrumentLocation.C_INV_LOC_ELIMINATION;
                            accountStockMoving.InstrumentCode              = i.Instrumentcode;
                            accountStockMoving.InstrumentQty               = i.TransferQty;
                            if (sumTransferAmount != 0)
                            {
                                accountStockMoving.InstrumentPrice = sumTransferAmount / i.TransferQty;
                            }
                            else
                            {
                                accountStockMoving.InstrumentPrice = 0;
                            }
                            accountStockMoving.CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            accountStockMoving.CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                            accountStockMoving.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            accountStockMoving.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                            listInsertAccStockMoving.Add(accountStockMoving);
                        }
                    }

                    //8.9

                    int blnCheckSampleInstrument = InvH.CheckSampleInstrument(strInventorySlipNo);
                    if (blnCheckSampleInstrument == 1)
                    {
                        List <doGroupSampleInstrument> GroupSampleInstrument = InvH.GetGroupSampleInstrument(strInventorySlipNo);
                        foreach (doGroupSampleInstrument i in GroupSampleInstrument)
                        {
                            i.DestinationLocationCode = InstrumentLocation.C_INV_LOC_ELIMINATION;
                            bool canUpdate = InvH.UpdateAccountTransferSampleInstrument(i, null);

                            if (!canUpdate)
                            {
                                scope.Dispose();
                                return(Json(res));
                            }

                            tbt_AccountStockMoving accountStockMoving = new tbt_AccountStockMoving();
                            accountStockMoving.SlipNo                      = strInventorySlipNo;
                            accountStockMoving.TransferTypeCode            = TransferType.C_INV_TRANSFERTYPE_ELIMINATION;
                            accountStockMoving.SourceAccountStockCode      = InventoryAccountCode.C_INV_ACCOUNT_CODE_INSTOCK;
                            accountStockMoving.DestinationAccountStockCode = InventoryAccountCode.C_INV_ACCOUNT_CODE_ELIMINATE;
                            accountStockMoving.SourceLocationCode          = InstrumentLocation.C_INV_LOC_PRE_ELIMINATION;
                            accountStockMoving.DestinationLocationCode     = InstrumentLocation.C_INV_LOC_ELIMINATION;
                            accountStockMoving.InstrumentCode              = i.Instrumentcode;
                            accountStockMoving.InstrumentQty               = i.TransferQty;
                            accountStockMoving.InstrumentPrice             = InventoryConfig.C_INV_DEFAULT_SAMPLE_AMOUNT;
                            accountStockMoving.CreateDate                  = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            accountStockMoving.CreateBy                    = CommonUtil.dsTransData.dtUserData.EmpNo;
                            accountStockMoving.UpdateDate                  = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            accountStockMoving.UpdateBy                    = CommonUtil.dsTransData.dtUserData.EmpNo;
                            listInsertAccStockMoving.Add(accountStockMoving);
                        }
                    }

                    //8.10
                    List <tbt_AccountStockMoving> resultInsert = InvH.InsertAccountStockMoving(listInsertAccStockMoving);
                    if (resultInsert.Count <= 0)
                    {
                        scope.Dispose();
                        return(Json(res));
                    }

                    scope.Complete();
                } //end transaction scope

                IInventoryDocumentHandler handlerInventoryDocument = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                string reportPath = handlerInventoryDocument.GenerateIVR030FilePath(strInventorySlipNo, prm.office.OfficeCode, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);
                prm.slipNo         = strInventorySlipNo;
                prm.reportFilePath = reportPath;
                UpdateScreenObject(prm);

                res.ResultData = strInventorySlipNo;

                return(Json(res));
            }
            catch (Exception ex)
            {
                res.ResultData = "toregister";
                res.AddErrorMessage(ex); return(Json(res));
            }
        }
        /// <summary>
        /// Register checking returned instrument.<br />
        /// - Check system suspending.<br />
        /// - Check quantity.<br />
        /// - Register transfer instrument.<br />
        /// - Update account transfer new/second hand/sample instrument.<br />
        /// - Generate report.
        /// </summary>
        /// <returns></returns>
        public ActionResult IVS140_Confirm()
        {
            string slipNo                = string.Empty;
            string slipNoReportPath      = string.Empty;
            IVS140_ScreenParameter param = GetScreenObject <IVS140_ScreenParameter>();
            IVS140_RegisterData    data  = new IVS140_RegisterData();

            if (param != null)
            {
                data = param.RegisterData;
            }

            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                IInventoryHandler handlerInventory = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                ICommonHandler    handlerCommon    = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

                // Is suspend ?
                if (handlerCommon.IsSystemSuspending())
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }

                //Business validate
                //int countBusinessWaringing = 0;
                foreach (var item in data.Detail)
                {
                    doCheckTransferQty doCheck = new doCheckTransferQty()
                    {
                        OfficeCode     = param.HeaderOffice[0].OfficeCode,
                        LocationCode   = InstrumentLocation.C_INV_LOC_RETURNED,
                        AreaCode       = item.AreaCode,
                        ShelfNo        = item.ShelfNo,
                        InstrumentCode = item.Instrumentcode,
                        TransferQty    = item.FixedReturnQty.HasValue ? item.FixedReturnQty.Value : 0
                    };


                    doCheckTransferQtyResult result = handlerInventory.CheckTransferQty(doCheck);

                    item.InstrumentQty = result.CurrentyQty;

                    if (result.OverQtyFlag == null)
                    {
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4009
                                            , new string[] { item.Instrumentcode }
                                            , new string[] { item.txtFixedReturnQtyID });
                        res.ResultData = new
                        {
                            IsSuccess = false,
                            Data      = data
                        };
                        return(Json(res));
                        //countBusinessWaringing++;
                    }
                    else if (result.OverQtyFlag == true)
                    {
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4008
                                            , new string[] { item.Instrumentcode }
                                            , new string[] { item.txtFixedReturnQtyID });
                        res.ResultData = new
                        {
                            IsSuccess = false,
                            Data      = data
                        };
                        return(Json(res));
                        //countBusinessWaringing++;
                    }
                }
                //if (countBusinessWaringing > 0)
                //{
                //    return Json(res);
                //}


                // Prepare data for Register
                doRegisterTransferInstrumentData dsRegisterData = new doRegisterTransferInstrumentData();

                dsRegisterData.SlipId        = SlipID.C_INV_SLIPID_CHECKING_RETURNED;
                dsRegisterData.InventorySlip = new tbt_InventorySlip()
                {
                    SlipStatus              = InventorySlipStatus.C_INV_SLIP_STATUS_COMPLETE,
                    TransferTypeCode        = TransferType.C_INV_TRANSFERTYPE_CHECKING_RETURNED,
                    SlipIssueDate           = DateTime.Now,
                    StockInDate             = DateTime.Now,
                    StockOutDate            = DateTime.Now,
                    SourceLocationCode      = InstrumentLocation.C_INV_LOC_RETURNED,
                    DestinationLocationCode = InstrumentLocation.C_INV_LOC_INSTOCK,
                    SourceOfficeCode        = param.HeaderOffice[0].OfficeCode,
                    DestinationOfficeCode   = param.HeaderOffice[0].OfficeCode,
                    ApproveNo  = data.Header.ApproveNo,
                    Memo       = data.Header.Memo,
                    ShelfType  = ShelfType.C_INV_SHELF_TYPE_NORMAL,
                    CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                    CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo,
                    UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                    UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo
                };

                dsRegisterData.lstTbt_InventorySlipDetail = new List <tbt_InventorySlipDetail>();
                tbt_InventorySlipDetail detail;
                for (int i = 0; i < data.Detail.Count; i++)
                {
                    detail = new tbt_InventorySlipDetail()
                    {
                        RunningNo           = (i + 1),
                        InstrumentCode      = data.Detail[i].Instrumentcode,
                        SourceAreaCode      = data.Detail[i].AreaCode,
                        DestinationAreaCode = data.Detail[i].AreaCode,
                        SourceShelfNo       = data.Detail[i].ShelfNo,
                        DestinationShelfNo  = ShelfNo.C_INV_SHELF_NO_NOT_MOVE_SHELF,
                        TransferQty         = data.Detail[i].FixedReturnQty
                    };

                    dsRegisterData.lstTbt_InventorySlipDetail.Add(detail);
                }

                // TODO: (Narupon) Uncomment for use TransactionScope

                // Save data to database..
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        // Register Inventory Tranfer data
                        string slipNo_result = handlerInventory.RegisterTransferInstrument(dsRegisterData);
                        slipNo       = slipNo_result;
                        param.SlipNo = slipNo_result;

                        // Check New instrument -- 8.5
                        int bCheckingNewInstrument = handlerInventory.CheckNewInstrument(slipNo_result);
                        if (bCheckingNewInstrument == 1)
                        {
                            List <doGroupNewInstrument> dtGroupNewInstrument = handlerInventory.GetGroupNewInstrument(slipNo_result);
                            foreach (var item in dtGroupNewInstrument)
                            {
                                #region Monthly Price @ 2015
                                //decimal decMovingAveragePrice = handlerInventory.CalculateMovingAveragePrice(item);
                                decimal decMovingAveragePrice = handlerInventory.GetMonthlyAveragePrice(item.Instrumentcode, dsRegisterData.InventorySlip.SlipIssueDate, InventoryAccountCode.C_INV_ACCOUNT_CODE_INSTOCK, SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_LOCAL, SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US);
                                #endregion
                                handlerInventory.UpdateAccountTransferNewInstrument(item, decMovingAveragePrice);
                            }
                        }

                        // Check secondhand instrument -- 8.6
                        int bCheckSeconhandInstrument = handlerInventory.CheckSecondhandInstrument(slipNo_result);
                        if (bCheckSeconhandInstrument == 1)
                        {
                            List <doGroupSecondhandInstrument> dtGroupSecondhandInstrument = handlerInventory.GetGroupSecondhandInstrument(slipNo_result);
                            foreach (var item in dtGroupSecondhandInstrument)
                            {
                                handlerInventory.UpdateAccountTransferSecondhandInstrument(item);
                            }
                        }


                        // Check sample instrument -- 8.6
                        int bCheckSampleInstrument = handlerInventory.CheckSampleInstrument(slipNo_result);
                        if (bCheckSampleInstrument == 1)
                        {
                            List <doGroupSampleInstrument> dtGroupSampleInstrument = handlerInventory.GetGroupSampleInstrument(slipNo_result);
                            foreach (var item in dtGroupSampleInstrument)
                            {
                                handlerInventory.UpdateAccountTransferSampleInstrument(item, null);
                            }
                        }

                        // Generate inventory slip report  // ReportID.C_INV_REPORT_ID_CHECKING_RETURNED = IVR090
                        IInventoryDocumentHandler handlerInventoryDocument = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                        slipNoReportPath = handlerInventoryDocument.GenerateIVR090FilePath(slipNo_result, param.HeaderOffice[0].OfficeCode, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);


                        scope.Complete(); // Commit transtion.
                    }
                    catch (Exception ex)
                    {
                        scope.Dispose();
                        throw ex;
                    }
                }
                // TODO: (Narupon) Uncomment for use TransactionScope

                param.SlipNoReportPath = slipNoReportPath;

                res.ResultData = new
                {
                    IsSuccess = true,
                    Data      = data,
                    SlipNo    = slipNo
                };
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        /// <summary>
        /// Register purchase order.<br />
        /// - Check system suspending.<br />
        /// - Check permission.<br />
        /// - Insert new purchase order.<br />
        /// - Generate report.
        /// </summary>
        /// <returns></returns>
        public ActionResult IVS250_cmdConfirm()
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                IVS250_ScreenParameter prm = GetScreenObject <IVS250_ScreenParameter>();
                if (prm.lstInstrument == null)
                {
                    prm.lstInstrument = new List <doInstrument250>();
                }
                if (prm.SpecifyPOrder250 == null)
                {
                    prm.SpecifyPOrder250 = new doSpecifyPOrder250();
                }
                //Check Suspend
                ICommonHandler ComH = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (ComH.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }
                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_REGISTER_PURCHASE_ORDER, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

                foreach (var i in prm.lstInstrument)
                {
                    IInstrumentMasterHandler InsH    = ServiceContainer.GetService <IInstrumentMasterHandler>() as IInstrumentMasterHandler;
                    List <tbm_Instrument>    lstInst = InsH.GetTbm_Instrument(i.InstrumentCode);

                    if (lstInst[0].LineUpTypeCode == LineUpType.C_LINE_UP_TYPE_LOGICAL_DELETE)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4140, new string[] { lstInst[0].InstrumentCode });
                        return(Json(res));
                    }
                }

                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        IInventoryHandler InvH = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                        string            strPurchaseOrderNo = InvH.GeneratePurchaseOrderNo(prm.Supplier.RegionCode);

                        tbt_PurchaseOrder doPurchaseOrder = new tbt_PurchaseOrder();
                        doPurchaseOrder.PurchaseOrderNo     = strPurchaseOrderNo;
                        doPurchaseOrder.PurhcaseOrderType   = prm.SpecifyPOrder250.PurchaseOrderType;
                        doPurchaseOrder.PurchaseOrderStatus = PurchaseOrderStatus.C_PURCHASE_ORDER_STATUS_WAIT_TO_RECEIVE;
                        doPurchaseOrder.SupplierCode        = prm.SpecifyPOrder250.SupplierCode;
                        doPurchaseOrder.TransportType       = prm.SpecifyPOrder250.TransportType;
                        doPurchaseOrder.Currency            = prm.SpecifyPOrder250.Currency;
                        doPurchaseOrder.BankName            = prm.Supplier.BankName;
                        doPurchaseOrder.AccountNo           = prm.Supplier.AccountNo;
                        doPurchaseOrder.AccountName         = prm.Supplier.AccountName;
                        doPurchaseOrder.ShippingDate        = prm.SpecifyPOrder250.AdjustDueDate;
                        doPurchaseOrder.Amount = prm.SpecifyPOrder250.TotalAmount;
                        if (prm.SpecifyPOrder250.PurchaseOrderType == PurchaseOrderType.C_PURCHASE_ORDER_TYPE_DOMESTIC ||
                            (prm.SpecifyPOrder250.PurchaseOrderType == PurchaseOrderType.C_PURCHASE_ORDER_TYPE_SECOM && prm.SpecifyPOrder250.Currency == CurrencyType.C_CURRENCY_TYPE_THB))
                        {
                            doPurchaseOrder.Vat = prm.SpecifyPOrder250.Vat;
                        }
                        doPurchaseOrder.Memo       = prm.SpecifyPOrder250.Memo;
                        doPurchaseOrder.CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                        doPurchaseOrder.CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                        doPurchaseOrder.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                        doPurchaseOrder.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                        doPurchaseOrder.WHT        = prm.SpecifyPOrder250.WHT;
                        doPurchaseOrder.Discount   = prm.SpecifyPOrder250.Discount;

                        List <tbt_PurchaseOrder> lst = new List <tbt_PurchaseOrder>();
                        lst.Add(doPurchaseOrder);
                        List <tbt_PurchaseOrder> dolstPurchaseOrder = InvH.InsertTbt_PurchaseOrder(lst);

                        if (dolstPurchaseOrder.Count <= 0)
                        {
                            throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0148, new string[] { TableName.C_TBL_NAME_INV_PURCHASE });
                        }

                        List <tbt_PurchaseOrderDetail> lstDetail = new List <tbt_PurchaseOrderDetail>();

                        //foreach (doInstrument250 i in prm.lstInstrument)
                        foreach (doInstrument250 i in prm.SpecifyPOrder250.InstrumentData) //Modify by Jutarat A. on 28102013
                        {
                            tbt_PurchaseOrderDetail OrderDetail = new tbt_PurchaseOrderDetail();
                            OrderDetail.PurchaseOrderNo   = strPurchaseOrderNo;
                            OrderDetail.InstrumentCode    = i.InstrumentCode;
                            OrderDetail.InstrumentName    = i.InstrumentName; //Add by Jutarat A. on 28102013
                            OrderDetail.Memo              = i.Memo;           //Add by Jutarat A. on 28102013
                            OrderDetail.UnitPrice         = i.UnitPrice;
                            OrderDetail.FirstOrderQty     = i.OrderQty;
                            OrderDetail.ModifyOrderQty    = null;
                            OrderDetail.ReceiveQty        = 0;
                            OrderDetail.CreateBy          = CommonUtil.dsTransData.dtUserData.EmpNo;
                            OrderDetail.CreateDate        = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            OrderDetail.UpdateDate        = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                            OrderDetail.UpdateBy          = CommonUtil.dsTransData.dtUserData.EmpNo;
                            OrderDetail.Unit              = i.Unit;
                            OrderDetail.OriginalUnitPrice = i.OriginalUnitPrice;
                            OrderDetail.Amount            = i.Amount;
                            lstDetail.Add(OrderDetail);
                        }
                        List <tbt_PurchaseOrderDetail> doPurchaseOrderDetail = InvH.InsertTbt_PurchaseOrderDetail(lstDetail);

                        if (doPurchaseOrderDetail.Count <= 0)
                        {
                            throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0148, new string[] { TableName.C_TBL_NAME_INV_PURCHASE_DETAIL });
                        }

                        //if (prm.SpecifyPOrder250.PurchaseOrderType == PurchaseOrderType.C_PURCHASE_ORDER_TYPE_SECOM)
                        //{
                        //    IInventoryDocumentHandler handlerInventoryDocument = ServiceContainer.GetService<IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                        //    string reportPath = handlerInventoryDocument.GenerateIVR190FilePath(strPurchaseOrderNo, prm.office.OfficeCode, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);
                        //    prm.slipNo = strPurchaseOrderNo;
                        //    prm.reportFilePath = reportPath;
                        //}
                        //else if (prm.SpecifyPOrder250.PurchaseOrderType == PurchaseOrderType.C_PURCHASE_ORDER_TYPE_DOMESTIC)
                        //{
                        //    IInventoryDocumentHandler handlerInventoryDocument = ServiceContainer.GetService<IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                        //    string reportPath = handlerInventoryDocument.GenerateIVR191FilePath(strPurchaseOrderNo, prm.office.OfficeCode, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);
                        //    prm.slipNo = strPurchaseOrderNo;
                        //    prm.reportFilePath = reportPath;
                        //}

                        IInventoryDocumentHandler handlerInventoryDocument = ServiceContainer.GetService <IInventoryDocumentHandler>() as IInventoryDocumentHandler;
                        string reportPath = handlerInventoryDocument.GenerateIVR192FilePath(strPurchaseOrderNo, prm.office.OfficeCode, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime);
                        prm.slipNo         = strPurchaseOrderNo;
                        prm.reportFilePath = reportPath;

                        scope.Complete();
                        res.ResultData = strPurchaseOrderNo;
                        return(Json(res));
                    }
                    catch (Exception ex)
                    {
                        res.AddErrorMessage(ex);
                        return(Json(res));
                    }
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex); return(Json(res));
            }
        }