Example #1
0
        public ActionResult MAS090_InsertInstrument(MAS090_SaveInstrument instrument)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                #region Check system suspending

                res = checkSystemSuspending();
                if (res.IsError)
                {
                    return(Json(res));
                }

                #endregion

                res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

                #region Validate require field

                ValidatorUtil validator = new ValidatorUtil(this);
                if (!instrument.SaleFlag.HasValue)
                {
                    instrument.SaleFlag = false;
                }
                if (!instrument.RentalFlag.HasValue)
                {
                    instrument.RentalFlag = false;
                }
                if (!instrument.InstrumentFlag.HasValue)
                {
                    instrument.InstrumentFlag = false;
                }
                if (!instrument.ZeroBahtAssetFlag.HasValue)
                {
                    instrument.ZeroBahtAssetFlag = false;
                }
                if (!instrument.MaintenanceFlag.HasValue)
                {
                    instrument.MaintenanceFlag = false;
                }
                if (!instrument.ControllerFlag.HasValue)
                {
                    instrument.ControllerFlag = false;
                }

                if (InstrumentType.C_INST_TYPE_GENERAL.Equals(instrument.InstrumentTypeCode))
                {
                    if (instrument.LineUpTypeCode == null)
                    {
                        validator.AddErrorMessage(MessageUtil.MODULE_MASTER,
                                                  MAS090_Screen,
                                                  MessageUtil.MODULE_COMMON,
                                                  MessageUtil.MessageList.MSG0007,
                                                  "RLineUpTypeCode",
                                                  "lblLineUpType",
                                                  "LineUpTypeCode");
                    }
                    if (instrument.ExpansionTypeCode == null)
                    {
                        validator.AddErrorMessage(MessageUtil.MODULE_MASTER,
                                                  MAS090_Screen,
                                                  MessageUtil.MODULE_COMMON,
                                                  MessageUtil.MessageList.MSG0007,
                                                  "RExpansionTypeCode",
                                                  "lblExpansionType",
                                                  "ExpansionTypeCode");
                    }
                }

                ValidatorUtil.BuildErrorMessage(res, validator);
                if (res.IsError)
                {
                    return(Json(res));
                }

                #endregion
                #region Check duplicate instrument information

                IInstrumentMasterHandler hand      = ServiceContainer.GetService <IInstrumentMasterHandler>() as IInstrumentMasterHandler;
                List <bool?>             listCheck = hand.CheckExistInstrument(instrument.InstrumentCode);
                if (listCheck.Count != 0 && listCheck[0].Value)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_MASTER, MessageUtil.MessageList.MSG1019);
                    return(Json(res));
                }

                #endregion



                // add by Jirawat Jannet on 216-12-23
                #region Set amount and currency type

                if (instrument.SaleUnitPriceCurrencyType == CurrencyUtil.C_CURRENCY_US)
                {
                    instrument.SaleUnitPriceUsd = instrument.SaleUnitPrice;
                    instrument.SaleUnitPrice    = null;
                }
                else
                {
                    instrument.SaleUnitPriceUsd = null;
                }

                if (instrument.RentalUnitPriceCurrencyType == CurrencyUtil.C_CURRENCY_US)
                {
                    instrument.RentalUnitPriceUsd = instrument.RentalUnitPrice;
                    instrument.RentalUnitPrice    = null;
                }
                else
                {
                    instrument.RentalUnitPriceUsd = null;
                }

                if (instrument.AddUnitPriceCurrencyType == CurrencyUtil.C_CURRENCY_US)
                {
                    instrument.AddUnitPriceUsd = instrument.AddUnitPrice;
                    instrument.AddUnitPrice    = null;
                }
                else
                {
                    instrument.AddUnitPriceUsd = null;
                }

                if (instrument.RemoveUnitPriceCurrencyType == CurrencyUtil.C_CURRENCY_US)
                {
                    instrument.RemoveUnitPriceUsd = instrument.RemoveUnitPrice;
                    instrument.RemoveUnitPrice    = null;
                }
                else
                {
                    instrument.RemoveUnitPriceUsd = null;
                }

                if (instrument.MoveUnitPriceCurrencyType == CurrencyUtil.C_CURRENCY_US)
                {
                    instrument.MoveUnitPriceUsd = instrument.MoveUnitPrice;
                    instrument.MoveUnitPrice    = null;
                }
                else
                {
                    instrument.MoveUnitPriceUsd = null;
                }

                #endregion
                #region Insert instrument data

                instrument.CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                instrument.CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                instrument.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                instrument.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;

                tbm_Instrument        inserted     = null;
                List <tbm_Instrument> listInserted = hand.InsertInstrument(instrument);
                if (listInserted.Count > 0)
                {
                    inserted = listInserted[0];
                }

                res.ResultData = inserted;

                #endregion
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
Example #2
0
        /// <summary>
        /// Using when Inventory stock-out intrument by project code
        /// </summary>
        /// <param name="strProjectCode"></param>
        /// <param name="doInstrumentList"></param>
        /// <param name="strStockOutMemo"></param>
        public void UpdateStockOutInstrument(string strProjectCode, List <doInstrument> doInstrumentList, string strStockOutMemo)
        {
            try
            {
                //1.	Check mandatory data
                //strProjectCode and instrument at least 1 are require fields.
                doUpdateStockOutInstrumentData updateDo = new doUpdateStockOutInstrumentData();
                updateDo.ProjectCode = strProjectCode;
                ApplicationErrorException.CheckMandatoryField(updateDo);
                if (CommonUtil.IsNullOrEmpty(strProjectCode))
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0007, "Project Code");
                }
                if (doInstrumentList.Count <= 0)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0007, "Instrument");
                }

                //2.	Begin tran;

                //3.	Validate business
                //3.1	Project code must exist in project table
                List <tbt_Project> projectList = base.GetTbt_Project(strProjectCode);

                //3.1.2.	Check project exist
                //If doTbt_Project	is null Then
                if (projectList.Count <= 0 || projectList[0] == null)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0011, strProjectCode);
                }

                //3.2	Project status must not be ‘Last completed’ or ‘Canceled’
                //3.2.1.	Project status must not be ‘Last completed’
                if (projectList[0].ProjectStatus == ProjectStatus.C_PROJECT_STATUS_LASTCOMPLETE)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3075);
                }

                //3.2.2.	Project status must not be ‘Canceled’
                if (projectList[0].ProjectStatus == ProjectStatus.C_PROJECT_STATUS_CANCEL)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3076);
                }

                //3.3	Check exist in instrument master for all instruments in doInstrumentList
                //3.3.1.	Loop all instrument in doInstrumentList
                IInstrumentMasterHandler hand = ServiceContainer.GetService <IInstrumentMasterHandler>() as IInstrumentMasterHandler;
                foreach (doInstrument doIn in doInstrumentList)
                {
                    //3.3.1.1.	Set local variable
                    // blnExistInstrument = False

                    //3.3.1.2.	Check exist instrument in master
                    List <bool?> blnExistInstrument = hand.CheckExistInstrument(doIn.InstrumentCode);

                    //3.3.1.3.	If blnExistInstrument = False Then
                    if (blnExistInstrument[0].Value == false)
                    {
                        throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0011, doIn.InstrumentCode);
                    }
                }

                using (TransactionScope scope = new TransactionScope())
                {
                    //Prepare insert data
                    tbt_ProjectStockoutInstrument doInsert = new tbt_ProjectStockoutInstrument();
                    doInsert.ProjectCode = strProjectCode;

                    //4.	Insert/update data in project stock-out intrument table
                    //4.1.1.	Loop all instrument in doInstrumentList
                    foreach (doInstrument doIn in doInstrumentList)
                    {
                        //4.1.1.2.	Check exist project stock-out intrument table
                        List <tbt_ProjectStockoutInstrument> doTbt_ProjectStockoutIntrument = this.GetTbt_ProjectStockoutInstrument(strProjectCode, doIn.InstrumentCode);

                        if (doTbt_ProjectStockoutIntrument.Count <= 0)
                        {
                            //4.1.1.3.	In case not exist: insert data to project stock-out intrument table
                            doInsert.InstrumentCode = doIn.InstrumentCode;
                            doInsert.InstrumentQty  = doIn.InstrumentQty;
                            this.InsertTbt_ProjectStockoutInstrument(doInsert);
                        }
                        else
                        {
                            //4.1.1.4.	In case exist: update data to project stock-out intrument table
                            doTbt_ProjectStockoutIntrument[0].InstrumentQty = doTbt_ProjectStockoutIntrument[0].InstrumentQty + doIn.InstrumentQty;
                            this.UpdateTbt_ProjectStockoutInstrument(doTbt_ProjectStockoutIntrument[0]);
                        }
                    }

                    //=============== TRS update 11/06/2012 =======================
                    tbt_ProjectStockOutMemo doStockoutMemo = new tbt_ProjectStockOutMemo();
                    doStockoutMemo.ProjectCode = strProjectCode;
                    doStockoutMemo.Memo        = strStockOutMemo;
                    InsertTbt_ProjectStockOutMemo(doStockoutMemo);
                    //=============================================================

                    scope.Complete();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }