Example #1
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>
        /// Validate before register.<br />
        /// - Check system suspending.<br />
        /// - Check user permission for screen IVS070.<br />
        /// - Check slip status.<br />
        /// - Check quantity.
        /// </summary>
        /// <param name="Cond"></param>
        /// <returns></returns>
        public ActionResult IVS070_cmdConfirm(IVS070RegisterCond Cond)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                IVS070_ScreenParameter prm       = GetScreenObject <IVS070_ScreenParameter>();
                string         SlipNo            = prm.SlipNo;
                string         SourceOffice      = prm.SourceOffice;
                string         DestinationOffice = prm.DestinationOffice;
                ICommonHandler ComH = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (ComH.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    res.ResultData = MessageUtil.MessageList.MSG0049;
                    return(Json(res));
                }
                if (!CheckUserPermission(ScreenID.C_INV_SCREEN_ID_TRANSFER_OFFICE_RECEIVE, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    res.ResultData = MessageUtil.MessageList.MSG0053;
                    return(Json(res));
                }

                IInventoryHandler        InvH = ServiceContainer.GetService <IInventoryHandler>() as IInventoryHandler;
                List <tbt_InventorySlip> dtTbt_InventorySlip = InvH.GetTbt_InventorySlip(SlipNo);

                tbt_InventorySlip InvenSlip = dtTbt_InventorySlip[0];
                //4.2.2

                if (InvenSlip.SlipStatus == InventorySlipStatus.C_INV_SLIP_STATUS_COMPLETE)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4012, new string[] { SlipNo });
                    res.ResultData = MessageUtil.MessageList.MSG4012;
                    return(Json(res));
                }

                //4.2.3
                foreach (IVS070INST i in Cond.StockInInstrument)
                {
                    doCheckTransferQty checkQty = new doCheckTransferQty();
                    checkQty.OfficeCode     = DestinationOffice;
                    checkQty.LocationCode   = InstrumentLocation.C_INV_LOC_TRANSFER;
                    checkQty.AreaCode       = i.DestinationAreaCode;
                    checkQty.ShelfNo        = ShelfNo.C_INV_SHELF_NO_OTHER_LOCATION;
                    checkQty.InstrumentCode = i.InstrumentCode;
                    checkQty.TransferQty    = Convert.ToInt32(i.TransferQty);
                    doCheckTransferQtyResult qtyResult = InvH.CheckTransferQty(checkQty);

                    if (qtyResult.OverQtyFlag == null)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4009, new string[] { i.InstrumentCode });
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                        res.ResultData  = i.row_id;
                        return(Json(res));
                    }
                    else if (qtyResult.OverQtyFlag == true)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_INVENTORY, MessageUtil.MessageList.MSG4008, new string[] { i.InstrumentCode });
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                        res.ResultData  = i.row_id;
                        return(Json(res));
                    }
                }

                //4.3 Return to screen and show message
                //res.ResultData = prm.SlipNo;
                return(Json(res));
            }
            catch (Exception ex)
            {
                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));
            }
        }