///<summary>
        ///Purpose   : Mandatory check1 (How does the system perform if action type is not specified.)
        ///Parameters:  doUpdateQuotationData
        ///                - QuotationTargetCode = NULL
        ///                - Alphabet = NULL
        ///                - LastUpdateDate = NULL
        ///                - ContractCode = NULL
        ///                - ActionTypeCode = NULL
        ///Expected  : MSG0007: These field was required: ActionTypeCode.
        ///</summary>
        public string Case1()
        {
            IQuotationHandler     target   = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            doUpdateQuotationData doUpdate = new doUpdateQuotationData();

            doUpdate.QuotationTargetCode = null;
            doUpdate.Alphabet            = null;
            doUpdate.LastUpdateDate      = DateTime.MinValue;
            doUpdate.ContractCode        = null;
            doUpdate.ActionTypeCode      = null;
            string expected = "MSG0007";
            string actual;

            try
            {
                int result = target.UpdateQuotationData(doUpdate);
                actual = result.ToString();
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 1, expected, actual, CompareResult_String(expected, actual)));
        }
Example #2
0
        /// <summary>
        /// Check screen authority and permission
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult QUS012_Authority(QUS012_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                CommonUtil cmm = new CommonUtil();
                param.Condition.QuotationTargetCode =
                    cmm.ConvertQuotationTargetCode(param.Condition.QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG);

                IQuotationHandler handler = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
                param.doRentalQuotationData = handler.GetRentalQuotationData(param.Condition);

                if (param.doRentalQuotationData != null && param.doRentalQuotationData.dtTbt_QuotationBasic != null)
                {
                    param.doQuotationInstallationDetail = handler.GetTbt_QuotationInstallationDetail(
                        param.doRentalQuotationData.dtTbt_QuotationBasic.QuotationTargetCode,
                        param.doRentalQuotationData.dtTbt_QuotationBasic.Alphabet
                        ).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(InitialScreenEnvironment <QUS012_ScreenParameter>(QUS012_SCREEN_NAME, param, res));
        }
        ///<summary>
        ///Purpose   : Update quotation data when action type = 4 (cancel)
        ///Parameters:  doUpdateQuotationData
        ///                - QuotationTargetCode = Q0000000536
        ///                - Alphabet = NULL
        ///                - LastUpdateDate = NULL
        ///                - ContractCode = NULL
        ///                - ActionTypeCode = 4
        ///Expected  : See expectation test case14
        ///</summary>
        public string Case14()
        {
            IQuotationHandler     target   = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            doUpdateQuotationData doUpdate = new doUpdateQuotationData();

            doUpdate.QuotationTargetCode = "Q0000000536";
            doUpdate.Alphabet            = null;
            doUpdate.LastUpdateDate      = DateTime.MinValue;
            doUpdate.ContractCode        = null;
            doUpdate.ActionTypeCode      = "4";
            string expected = "1";
            string actual;

            try
            {
                //Login user = 510729
                //Process datetime = 2011-11-19  10:30:00.000
                CommonUtil.dsTransData.dtUserData.EmpNo = "510729";
                CommonUtil.dsTransData.dtOperationData.ProcessDateTime = new DateTime(2011, 11, 19, 10, 30, 00);

                CommonUtil.dsTransData.dtOperationData.GUID = "Case14";
                int result = target.UpdateQuotationData(doUpdate);
                actual = result.ToString();
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 14, expected, actual, CompareResult_String(expected, actual)));
        }
        ///<summary>
        ///Purpose   : Mandatory check1  (QuotationHandler.GenerateQuotation)
        ///Parameters: dsGenerateQuotationData
        ///             dtHeader[0]
        ///                 - ContractCode = NULL
        ///                 - InstallationFee = NULL
        ///                 - InstallationSlipNo = NULL
        ///                 - InstallationEngineerEmpNo = NULL
        ///                 - ApproveNo1 = NULL
        ///                 - ApproveNo2 = NULL
        ///             dtInstrumentDetails[] = Empty list
        ///Expected  : MSG0007: These field was required: ContractCode, InstallationFee, dtInstrumentDetails[].
        ///</summary>
        public string Case1()
        {
            IQuotationHandler target   = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            dsGenerateData    doUpdate = new dsGenerateData();

            //header
            doUpdate.dtHeader = new dtHeader();
            doUpdate.dtHeader.ContractCode              = null;
            doUpdate.dtHeader.InstallationFee           = null;
            doUpdate.dtHeader.InstallationSlipNo        = null;
            doUpdate.dtHeader.InstallationEngineerEmpNo = null;
            doUpdate.dtHeader.ApproveNo1 = null;
            doUpdate.dtHeader.ApproveNo2 = null;
            //detail
            doUpdate.dtInstrumentDetails = new List <dtInstrumentDetails>();

            string expected = "MSG0007";
            string actual;

            try
            {
                actual = target.GenerateQuotation(doUpdate);
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 1, expected, actual, CompareResult_String(expected, actual)));
        }
Example #5
0
        public ActionResult QUS010()
        {
            QUS010_ScreenParameter Cond = GetScreenObject <QUS010_ScreenParameter>();

            if (!Cond.IsPopup)
            {
                ViewBag.ViewMode = "1";
            }
            else
            {
                ViewBag.ViewMode = "2";
            }

            IQuotationHandler hand = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;

            ViewBag.strCallerScreenID      = Cond.CallerScreenID;
            ViewBag.strServiceTypeCode     = Cond.strServiceTypeCode;
            ViewBag.strTargetCodeTypeCode  = Cond.strTargetCodeTypeCode;
            ViewBag.strQuotationTargetCode = Cond.strQuotationTargetCode;
            ViewBag.C_SCREEN_ID_MAIN       = ScreenID.C_SCREEN_ID_MAIN;
            ViewBag.C_SCREEN_ID_FN99       = ScreenID.C_SCREEN_ID_FN99;
            ViewBag.C_SCREEN_ID_FQ99       = ScreenID.C_SCREEN_ID_FQ99;
            ViewBag.C_SCREEN_ID_FN99       = ScreenID.C_SCREEN_ID_FN99;
            ViewBag.C_SCREEN_ID_FQ99       = ScreenID.C_SCREEN_ID_FQ99;
            ViewBag.C_LOCK_STATUS_UNLOCK   = LockStatus.C_LOCK_STATUS_UNLOCK;
            ViewBag.C_SCREEN_ID_MAIN       = ScreenID.C_SCREEN_ID_MAIN;
            ViewBag.C_SCREEN_ID_CP12_PLAN  = ScreenID.C_SCREEN_ID_CP12_CHANGE_PLAN;
            ViewBag.C_SCREEN_ID_CP12_INST  = ScreenID.C_SCREEN_ID_CP12_MODIFY_INSTRUMENT_QTY;
            ViewBag.C_SCREEN_ID_CQ12       = ScreenID.C_SCREEN_ID_CQ12_CHANGE_PLAN;
            ViewBag.C_PROD_TYPE_SALE       = ProductType.C_PROD_TYPE_SALE;

            return(View());
        }
Example #6
0
        ///<summary>
        ///Purpose   : Purge data from db
        ///Procedure : 1. Directly call QuotationHandler.DeleteQuotation from test class.
        ///            2. Check return result of the process and remaining data in DB.
        ///            Change locked table - tbt_QuotationSentryGuardDetails
        ///Expected  : 1. dtBatchProcessResult (7 cases following locked tables)
        ///                .Result  = 0
        ///                .BatchStatus = NULL
        ///                .Total  = 13
        ///                .Complete = 0
        ///                .Failed  = 13
        ///                .ErrorMessage = Delete quotation process is failed. Cannot delete tbt_QuotationSentryGuardDetails. All deleted data is rollbacked.
        ///            2. Expected data in db
        ////                - Not change from before running the process
        ///</summary>
        public string Case2()
        {
            IQuotationHandler    target   = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            dtBatchProcessResult expected = CreateExpectForErrorCase("tbt_QuotationSentryGuardDetails");
            dtBatchProcessResult actual   = null;
            string error = string.Empty;

            try
            {
                List <dtBatchProcessResult> lst = target.DeleteQuotation();
                actual = lst[0];
            }
            catch (ApplicationErrorException ex)
            {
                error = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                error = ex.StackTrace;
            }

            if (error == string.Empty)
            {
                return(CompareDtBatchProcessResult(actual, expected, 2));
            }
            else
            {
                return(string.Format(RESULT_FORMAT_ERROR, 2, "Fail", error));
            }
        }
Example #7
0
        ///<summary>
        ///Purpose   : Individual lock (no quotation was locked)
        ///Pre-Condition :  Create stub6 to test expectation input for LogHandler.WriteTransactionLog
        ///Parameters:  strQuotationTargetCode =  FQ0000000508
        ///             strAlphabet = "CA"
        ///             strLockStyleCode = 3
        ///Expected  : See expectation test case9
        ///</summary>
        public string Case9()
        {
            IQuotationHandler target = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            string            strQuotationTargetCode = "FQ0000000508";
            string            strAlphabet            = "CA";
            string            strLockStyleCode       = "3";
            string            expected = "True";
            string            actual;

            try
            {
                CommonUtil.dsTransData.dtOperationData.GUID = "Case9";
                bool result = target.LockQuotation(strQuotationTargetCode, strAlphabet, strLockStyleCode);
                actual = result.ToString();
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 9, expected, actual, CompareResult_String(expected, actual)));
        }
Example #8
0
        ///<summary>
        ///Purpose   : Individual lock (all quotations was locked)
        ///Pre-Condition :  Create stub6 to test expectation input for LogHandler.WriteTransactionLog
        ///Parameters:  strQuotationTargetCode =   FMA0000000486
        ///             strAlphabet = CA
        ///             strLockStyleCode = 3
        ///Expected  :  No data in DB is updated. LogHandler.WriteTransactionLog is not called.
        ///</summary>
        public string Case12()
        {
            IQuotationHandler target = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            string            strQuotationTargetCode = "FMA0000000486";
            string            strAlphabet            = "CA";
            string            strLockStyleCode       = "3";
            string            expected = "False";
            string            actual;

            try
            {
                //Login user = 470228
                //Process datetime = 2012/01/15  09:30:00 AM
                CommonUtil.dsTransData.dtUserData.EmpNo = "470228";
                CommonUtil.dsTransData.dtOperationData.ProcessDateTime = new DateTime(2012, 1, 15, 9, 30, 00);

                CommonUtil.dsTransData.dtOperationData.GUID = "Case12";
                bool result = target.LockQuotation(strQuotationTargetCode, strAlphabet, strLockStyleCode);
                actual = result.ToString();
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 12, expected, actual, CompareResult_String(expected, actual)));
        }
Example #9
0
        ///<summary>
        ///Purpose   : Mandatory check (QuotationHandler.CountQuotationBasic)
        ///Parameters:  strQuotationTargetCode = NULL
        ///             strAlphabet = NULL
        ///             strLockStyleCode = 1
        ///Expected  : MSG0007: These field was required: strQuotationTargetCode.
        ///</summary>
        public string Case2()
        {
            IQuotationHandler target = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            string            strQuotationTargetCode = null;
            string            strAlphabet            = null;
            string            strLockStyleCode       = "1";
            string            expected = "MSG0007";
            string            actual;

            try
            {
                target.LockQuotation(strQuotationTargetCode, strAlphabet, strLockStyleCode);
                actual = string.Empty;
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 2, expected, actual, CompareResult_String(expected, actual)));
        }
        ///<summary>
        ///Purpose   : Get contract data (How does the system perform if an invalid instrument is specified, master data not found.)
        ///Parameters: dsGenerateQuotationData
        ///             dtHeader[0]
        ///                 - ContractCode = N0000000346
        ///                 - InstallationFee = 250000.00
        ///                 - InstallationSlipNo = NULL
        ///                 - InstallationEngineerEmpNo = NULL
        ///                 - ApproveNo1 = NULL
        ///                 - ApproveNo2 = NULL
        ///             dtInstrumentDetails[]
        ///                - dtInstrumentDetails[0]
        ///                 - InstrumentCode  = AC-A1030TH
        ///                 - InstallQty = 5
        ///                 - AcmAddQty = NULL
        ///                 - AcmRemoveQty = NULL
        ///                - dtInstrumentDetails[1]
        ///                 - InstrumentCode = U100i
        ///                 - InstallQty = 20
        ///                 - AcmAddQty = NULL
        ///                 - AcmRemoveQty = NULL
        ///Expected  : MSG2016: Cannot generate quotation. Rental unit price of the instrument code, U100i, not found.
        ///</summary>
        public string Case6()
        {
            IQuotationHandler target   = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            dsGenerateData    doUpdate = new dsGenerateData();

            //header
            doUpdate.dtHeader = new dtHeader();
            doUpdate.dtHeader.ContractCode              = "N0000000346";
            doUpdate.dtHeader.InstallationFee           = 250000.00M;
            doUpdate.dtHeader.InstallationSlipNo        = null;
            doUpdate.dtHeader.InstallationEngineerEmpNo = null;
            doUpdate.dtHeader.ApproveNo1 = null;
            doUpdate.dtHeader.ApproveNo2 = null;
            //detail
            doUpdate.dtInstrumentDetails = new List <dtInstrumentDetails>();
            //detail[0]
            dtInstrumentDetails dt1 = new dtInstrumentDetails();

            dt1.InstrumentCode = "AC-A1030TH";
            dt1.InstallQty     = 5;
            dt1.AcmAddQty      = null;
            dt1.AcmRemoveQty   = null;
            doUpdate.dtInstrumentDetails.Add(dt1);
            //detail[1]
            dtInstrumentDetails dt2 = new dtInstrumentDetails();

            dt2.InstrumentCode = "U100i";
            dt2.InstallQty     = 20;
            dt2.AcmAddQty      = null;
            dt2.AcmRemoveQty   = null;
            doUpdate.dtInstrumentDetails.Add(dt2);

            string expected = "MSG2016";
            string actual;

            try
            {
                actual = target.GenerateQuotation(doUpdate);
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 6, expected, actual, CompareResult_String(expected, actual)));
        }
        /// <summary>
        /// Load result data to grid
        /// </summary>
        /// <param name="doCond"></param>
        /// <returns></returns>
        public ActionResult QUS040_XML(QUS040_SearchQuotationTarget doCond)
        {
            string           XMLpath = "Quotation\\QUS040";
            ObjectResultData res     = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                List <View_dtSearchQuotationTargetListlResult> nlst = null;

                ValidatorUtil.BuildErrorMessage(res, this, new object[] { doCond });
                if (res.IsError == false)
                {
                    CommonUtil ComUtil = new CommonUtil();
                    doCond.QuotationTargetCode = ComUtil.ConvertQuotationTargetCode(doCond.QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                    doCond.ContractTargetCode  = ComUtil.ConvertCustCode(doCond.ContractTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                    doCond.SiteCode            = ComUtil.ConvertSiteCode(doCond.SiteCode, CommonUtil.CONVERT_TYPE.TO_LONG);

                    IQuotationHandler handler = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
                    List <dtSearchQuotationTargetListResult> lst = handler.SearchQuotationTargetList(doCond);

                    nlst = CommonUtil.ConvertObjectbyLanguage <dtSearchQuotationTargetListResult, View_dtSearchQuotationTargetListlResult>(lst, "QuotationOfficeName", "OperationOfficeName", "EmpFullName");
                }
                if (doCond.QuotationDateFrom != null && doCond.QuotationDateTo != null)
                {
                    if (DateTime.Compare(Convert.ToDateTime(doCond.QuotationDateFrom), Convert.ToDateTime(doCond.QuotationDateTo)) > 0)
                    {
                        res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                        res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2001, null, new string[] { "QuotationDateFrom", "QuotationDateTo" });
                        return(Json(res));
                    }
                }

                res.ResultData = CommonUtil.ConvertToXml <View_dtSearchQuotationTargetListlResult>(nlst, XMLpath, CommonUtil.GRID_EMPTY_TYPE.SEARCH);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        ///<summary>
        ///Purpose   : Get quotation target (How does the system perform if it cannot get a record from tbt_QuotationTarget)
        ///Parameters: strQuotationTargetCode = FN0000000144
        ///Expected  : MSG2003: Quotation target not found, FN0000144.
        ///</summary>
        public string Case2()
        {
            IQuotationHandler target = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            string            strQuotationTargetCode = "FN0000000144";
            string            expected = "MSG2003";
            string            actual;

            try
            {
                actual = target.GenerateQuotationAlphabet(strQuotationTargetCode);
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 2, expected, actual, CompareResult_String(expected, actual)));
        }
        ///<summary>
        ///Purpose   : Mandatory check
        ///Parameters: strProductTypeCode = NULL
        ///Expected  : MSG0007: These field was required: strProductTypeCode
        ///</summary>
        public string Case1()
        {
            IQuotationHandler target             = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            string            strProductTypeCode = null;
            string            expected           = "MSG0007";
            string            actual;

            try
            {
                actual = target.GenerateQuotationTargetCode(strProductTypeCode);
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 1, expected, actual, CompareResult_String(expected, actual)));
        }
Example #14
0
        public void UpdateOperationOffice(string contractCode, string operationOfficeCode)
        {
            try
            {
                if (string.IsNullOrEmpty(contractCode) || string.IsNullOrEmpty(operationOfficeCode))
                {
                    return;
                }

                ISaleContractHandler saleHandler = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                var lstSales = saleHandler.GetTbt_SaleBasic(contractCode, null, null);
                if (lstSales != null && lstSales.Count > 0)
                {
                    foreach (var sale in lstSales)
                    {
                        sale.OperationOfficeCode = operationOfficeCode;
                        saleHandler.UpdateTbt_SaleBasic(sale);
                    }
                }

                IQuotationHandler quotationHandler = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;

                var lstQuotationTarget = quotationHandler.GetTbt_QuotationTargetByContractCode(contractCode);
                if (lstQuotationTarget != null && lstQuotationTarget.Count > 0)
                {
                    foreach (var q in lstQuotationTarget)
                    {
                        quotationHandler.UpdateQuotationTarget(new doUpdateQuotationTargetData()
                        {
                            QuotationTargetCode    = q.QuotationTargetCode,
                            ContractTransferStatus = q.ContractTransferStatus,
                            ContractCode           = q.ContractCode,
                            TransferDate           = q.TransferDate,
                            TransferAlphabet       = q.TransferAlphabet,
                            LastAlphabet           = q.LastAlphabet,
                            QuotationOfficeCode    = q.QuotationTargetCode,
                            OperationOfficeCode    = operationOfficeCode,
                        });
                    }
                }

                IInstallationHandler installHandler = ServiceContainer.GetService <IInstallationHandler>() as IInstallationHandler;

                var lstInstallationBasic = installHandler.GetTbt_InstallationBasicData(contractCode);
                if (lstInstallationBasic != null && lstInstallationBasic.Count > 0)
                {
                    foreach (var ib in lstInstallationBasic)
                    {
                        ib.OperationOfficeCode = operationOfficeCode;
                        installHandler.UpdateTbt_InstallationBasic(ib);
                    }
                }

                var lstInstallationHistory = installHandler.GetTbt_InstallationHistory(contractCode, null, null);
                if (lstInstallationHistory != null && lstInstallationHistory.Count > 0)
                {
                    foreach (var ih in lstInstallationHistory)
                    {
                        ih.OperationOfficeCode = operationOfficeCode;
                    }

                    installHandler.UpdateTbt_InstallationHistory(lstInstallationHistory);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #15
0
        /// <summary>
        /// Import quotation data
        /// </summary>
        /// <param name="ScreenID"></param>
        /// <param name="DataList"></param>
        /// <returns></returns>
        public ActionResult QUS050_ImportData(string ScreenID, List <string> DataList)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                dsImportData importData = new dsImportData()
                {
                    dtTbt_QuotationCustomer           = new List <tbt_QuotationCustomer>(),
                    dtTbt_QuotationSite               = new List <tbt_QuotationSite>(),
                    dtTbt_QuotationTarget             = new List <tbt_QuotationTarget>(),
                    dtTbt_QuotationBasic              = new List <tbt_QuotationBasic>(),
                    dtTbt_QuotationOperationType      = new List <tbt_QuotationOperationType>(),
                    dtTbt_QuotationInstrumentDetails  = new List <tbt_QuotationInstrumentDetails>(),
                    dtTbt_QuotationFacilityDetails    = new List <tbt_QuotationFacilityDetails>(),
                    dtTbt_QuotationBeatGuardDetails   = new List <tbt_QuotationBeatGuardDetails>(),
                    dtTbt_QuotationSentryGuardDetails = new List <tbt_QuotationSentryGuardDetails>(),
                    dtTbt_QuotationMaintenanceLinkage = new List <tbt_QuotationMaintenanceLinkage>()
                };

                #region Mapping Data

                List <object> impLst = new List <object>()
                {
                    importData.dtTbt_QuotationCustomer,
                    importData.dtTbt_QuotationSite,
                    importData.dtTbt_QuotationTarget,
                    importData.dtTbt_QuotationBasic,
                    importData.dtTbt_QuotationOperationType,
                    importData.dtTbt_QuotationInstrumentDetails,
                    importData.dtTbt_QuotationFacilityDetails,
                    importData.dtTbt_QuotationBeatGuardDetails,
                    importData.dtTbt_QuotationSentryGuardDetails,
                    importData.dtTbt_QuotationMaintenanceLinkage
                };

                string      filePath = CommonUtil.WebPath + SECOM_AJIS.Common.Util.ConstantValue.CommonValue.IMPORT_TEMPLATE_FILE;
                XmlDocument doc      = new XmlDocument();
                doc.Load(filePath);
                XmlNodeList nodes = doc.SelectNodes("tables/table");

                bool          isError     = false;
                List <string> setFailList = new List <string>();
                int           lineIdx     = 0;
                int           nodeIdx     = 0;
                for (; nodeIdx < nodes.Count; nodeIdx++)
                {
                    if (lineIdx < DataList.Count)
                    {
                        /* --- Check Table name --- */
                        string[] tbName = DataList[lineIdx].Split(",".ToCharArray());
                        if (nodes[nodeIdx].Attributes["name"].Value != tbName[0] ||
                            lineIdx + 1 >= DataList.Count)
                        {
                            isError = true;
                            break;
                        }

                        lineIdx += 1;

                        /* --- Check Column --- */
                        bool     isSameCol = false;
                        string[] cols      = DataList[lineIdx].Split(",".ToCharArray());
                        if (cols != null)
                        {
                            if (nodes[nodeIdx].ChildNodes.Count <= cols.Length)
                            {
                                int colIdx = 0;
                                for (; colIdx < nodes[nodeIdx].ChildNodes.Count; colIdx++)
                                {
                                    string colName  = cols[colIdx] == null ? "" : cols[colIdx];
                                    string cColName = nodes[nodeIdx].ChildNodes[colIdx].Attributes["name"].Value;
                                    if (cColName == null)
                                    {
                                        cColName = "";
                                    }

                                    colName  = colName.Trim().ToUpper();
                                    cColName = cColName.Trim().ToUpper();

                                    if (colName != cColName)
                                    {
                                        break;
                                    }
                                }

                                bool isColOver = false;
                                if (colIdx < cols.Length)
                                {
                                    for (int nColIdx = colIdx; nColIdx < cols.Length; nColIdx++)
                                    {
                                        if (CommonUtil.IsNullOrEmpty(cols[nColIdx]) == false)
                                        {
                                            isColOver = true;
                                            break;
                                        }
                                    }
                                }
                                if (isColOver == false &&
                                    colIdx == nodes[nodeIdx].ChildNodes.Count)
                                {
                                    isSameCol = true;
                                }
                            }
                        }
                        if (isSameCol == false)
                        {
                            isError = true;
                            break;
                        }

                        /* --- Get next Table --- */
                        string nextTable = null;
                        if (nodeIdx + 1 < nodes.Count)
                        {
                            nextTable = nodes[nodeIdx + 1].Attributes["name"].Value;
                        }

                        /* --- Loop fill data to each table --- */
                        lineIdx += 1;
                        while (lineIdx < DataList.Count)
                        {
                            tbName = DataList[lineIdx].Split(",".ToCharArray());
                            if (nextTable == tbName[0])
                            {
                                break;
                            }

                            bool isEmpty = true;
                            foreach (string d in tbName)
                            {
                                if (CommonUtil.IsNullOrEmpty(d) == false)
                                {
                                    isEmpty = false;
                                    break;
                                }
                            }
                            if (isEmpty)
                            {
                                isError = true;
                                break;
                            }

                            string data = DataList[lineIdx];

                            string[] lst = new string[nodes[nodeIdx].ChildNodes.Count];
                            for (int dIdx = 0; dIdx < nodes[nodeIdx].ChildNodes.Count; dIdx++)
                            {
                                if (data.Length <= 0 && dIdx < nodes[nodeIdx].ChildNodes.Count - 1)
                                {
                                    isError = true;
                                    break;
                                }

                                int tIdx  = 0;
                                int cmIdx = data.IndexOf(",");
                                int ccIdx = data.IndexOf("\"");

                                string val = string.Empty;
                                if (cmIdx < 0)
                                {
                                    val = data;
                                }
                                else if (cmIdx < ccIdx || ccIdx < 0)
                                {
                                    val   = data.Substring(tIdx, cmIdx);
                                    tIdx += cmIdx + 1;
                                }
                                else
                                {
                                    int cceIdx = data.IndexOf("\"", ccIdx + 1);
                                    if (cceIdx <= 0)
                                    {
                                        val = data;
                                    }
                                    else
                                    {
                                        val   = data.Substring(tIdx + 1, cceIdx - 1);
                                        tIdx += cceIdx + 2;
                                    }
                                }

                                lst[dIdx] = val;
                                data      = data.Substring(tIdx);
                            }

                            lineIdx += 1;
                            if (isError)
                            {
                                break;
                            }
                            else
                            {
                                if (nodeIdx < impLst.Count)
                                {
                                    object obj = impLst[nodeIdx];

                                    /* --- Create Object --- */
                                    object objDo = Activator.CreateInstance(obj.GetType().GetGenericArguments()[0]);

                                    MethodInfo mf = obj.GetType().GetMethod("Add");
                                    if (mf != null)
                                    {
                                        mf.Invoke(obj, new object[] { objDo });
                                    }

                                    for (int colIdx = 0; colIdx < nodes[nodeIdx].ChildNodes.Count; colIdx++)
                                    {
                                        bool canSetValue = CommonUtil.SetObjectValue(objDo, nodes[nodeIdx].ChildNodes[colIdx].Attributes["name"].Value, lst[colIdx] != string.Empty ? lst[colIdx] : null);
                                        if (canSetValue == false)
                                        {
                                            string v = nodes[nodeIdx].ChildNodes[colIdx].Attributes["name"].Value;
                                            if (setFailList.IndexOf(v) < 0)
                                            {
                                                setFailList.Add(v);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (isError)
                    {
                        break;
                    }
                }

                if (nodeIdx < nodes.Count)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2020);
                    return(Json(res));
                }
                if (setFailList.Count > 0)
                {
                    string txt = CommonUtil.TextList(setFailList.ToArray());
                    res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2084, new string[] { txt });
                    return(Json(res));
                }

                #endregion
                #region Check Mandatory

                ValidatorUtil validator = new ValidatorUtil();
                List <object> objLst    = new List <object>();
                if (ScreenID == SECOM_AJIS.Common.Util.ConstantValue.ScreenID.C_SCREEN_ID_QTN_TARGET)
                {
                    if (importData.dtTbt_QuotationCustomer.Count == 0)
                    {
                        validator.AddErrorMessage(
                            MessageUtil.MODULE_COMMON,
                            MessageUtil.MessageList.MSG0007,
                            "CustomerList",
                            "CustPartTypeCode, CustCode (or CustNameEN, CustNameLC, CustTypeCode, RegionCode)");
                    }
                    else
                    {
                        int cidx = 1;
                        foreach (tbt_QuotationCustomer cust in importData.dtTbt_QuotationCustomer)
                        {
                            if (CommonUtil.IsNullOrEmpty(cust.CustPartTypeCode))
                            {
                                validator.AddErrorMessage(
                                    MessageUtil.MODULE_COMMON,
                                    MessageUtil.MessageList.MSG0007,
                                    "CustPartTypeCode" + cidx,
                                    "CustPartTypeCode" + cidx);
                            }
                            if (CommonUtil.IsNullOrEmpty(cust.CustCode))
                            {
                                List <string> eLst = new List <string>();

                                if (CommonUtil.IsNullOrEmpty(cust.CustNameEN))
                                {
                                    eLst.Add("CustNameEN" + cidx);
                                }
                                if (CommonUtil.IsNullOrEmpty(cust.CustNameLC))
                                {
                                    eLst.Add("CustNameLC" + cidx);
                                }
                                if (CommonUtil.IsNullOrEmpty(cust.CustTypeCode))
                                {
                                    eLst.Add("CustTypeCode" + cidx);
                                }
                                if (CommonUtil.IsNullOrEmpty(cust.RegionCode))
                                {
                                    eLst.Add("RegionCode" + cidx);
                                }

                                if (eLst.Count == 4)
                                {
                                    validator.AddErrorMessage(
                                        MessageUtil.MODULE_COMMON,
                                        MessageUtil.MessageList.MSG0007,
                                        "Customer" + cidx,
                                        string.Format("CustCode{0} (or CustNameEN{0}, CustNameLC{0}, CustTypeCode{0}, RegionCode{0})", cidx));
                                }
                                else
                                {
                                    foreach (string s in eLst)
                                    {
                                        validator.AddErrorMessage(
                                            MessageUtil.MODULE_COMMON,
                                            MessageUtil.MessageList.MSG0007,
                                            s,
                                            s);
                                    }
                                }
                            }

                            cidx++;
                        }
                    }

                    tbt_QuotationSite site = new tbt_QuotationSite();
                    if (importData.dtTbt_QuotationSite.Count > 0)
                    {
                        site = importData.dtTbt_QuotationSite[0];
                    }
                    if (CommonUtil.IsNullOrEmpty(site.SiteNo))
                    {
                        List <string> eLst = new List <string>();
                        if (CommonUtil.IsNullOrEmpty(site.SiteNameEN))
                        {
                            eLst.Add("SiteNameEN");
                        }
                        if (CommonUtil.IsNullOrEmpty(site.SiteNameLC))
                        {
                            eLst.Add("SiteNameLC");
                        }
                        if (CommonUtil.IsNullOrEmpty(site.AddressEN))
                        {
                            eLst.Add("AddressEN");
                        }
                        if (CommonUtil.IsNullOrEmpty(site.AddressLC))
                        {
                            eLst.Add("AddressLC");
                        }
                        //if (CommonUtil.IsNullOrEmpty(site.RoadEN))
                        //    eLst.Add("RoadEN");
                        //if (CommonUtil.IsNullOrEmpty(site.RoadLC))
                        //    eLst.Add("RoadLC");
                        if (CommonUtil.IsNullOrEmpty(site.SubDistrictEN))
                        {
                            eLst.Add("SubDistrictEN");
                        }
                        if (CommonUtil.IsNullOrEmpty(site.SubDistrictLC))
                        {
                            eLst.Add("SubDistrictLC");
                        }
                        if (CommonUtil.IsNullOrEmpty(site.BuildingUsageCode))
                        {
                            eLst.Add("BuildingUsageCode");
                        }
                        if (CommonUtil.IsNullOrEmpty(site.ProvinceCode))
                        {
                            eLst.Add("ProvinceCode");
                        }
                        if (CommonUtil.IsNullOrEmpty(site.ProvinceCode))
                        {
                            eLst.Add("DistrictCode");
                        }

                        if (eLst.Count == 11)
                        {
                            validator.AddErrorMessage(
                                MessageUtil.MODULE_COMMON,
                                MessageUtil.MessageList.MSG0007,
                                "Site",
                                "SiteNo (or SiteNameEN, SiteNameLC, AddressEN, AddressLC, SubDistrictEN, SubDistrictLC, BuildingUsageCode, ProvinceCode, DistrictCode)");
                        }
                        else
                        {
                            foreach (string s in eLst)
                            {
                                validator.AddErrorMessage(
                                    MessageUtil.MODULE_COMMON,
                                    MessageUtil.MessageList.MSG0007,
                                    s,
                                    s);
                            }
                        }
                    }

                    if (importData.dtTbt_QuotationTarget.Count == 0)
                    {
                        importData.dtTbt_QuotationTarget.Add(new tbt_QuotationTarget());
                    }
                    foreach (tbt_QuotationTarget target in importData.dtTbt_QuotationTarget)
                    {
                        objLst.Add(CommonUtil.CloneObject <tbt_QuotationTarget, QUS050_tbt_QuotationTarget>(target));
                    }
                }
                else
                {
                    if (importData.dtTbt_QuotationTarget.Count == 0)
                    {
                        importData.dtTbt_QuotationTarget.Add(new tbt_QuotationTarget());
                    }
                    foreach (tbt_QuotationTarget target in importData.dtTbt_QuotationTarget)
                    {
                        objLst.Add(CommonUtil.CloneObject <tbt_QuotationTarget, QUS050_tbt_QuotationTarget_D>(target));
                    }

                    if (importData.dtTbt_QuotationBasic.Count == 0)
                    {
                        importData.dtTbt_QuotationBasic.Add(new tbt_QuotationBasic());
                    }
                    foreach (tbt_QuotationBasic basic in importData.dtTbt_QuotationBasic)
                    {
                        /* --- Update QuotationTargetCode --- */
                        /* ---------------------------------- */
                        basic.QuotationTargetCode = importData.dtTbt_QuotationTarget[0].QuotationTargetCode;
                        /* ---------------------------------- */

                        objLst.Add(CommonUtil.CloneObject <tbt_QuotationBasic, QUS050_tbt_QuotationBasic>(basic));
                    }
                }

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

                #endregion
                #region Business Check

                if (ScreenID == SECOM_AJIS.Common.Util.ConstantValue.ScreenID.C_SCREEN_ID_QTN_TARGET)
                {
                    bool isFoundTarget = false;
                    bool isFoundReal   = false;
                    if (importData.dtTbt_QuotationCustomer.Count > 0 && importData.dtTbt_QuotationCustomer.Count <= 2)
                    {
                        foreach (tbt_QuotationCustomer cust in importData.dtTbt_QuotationCustomer)
                        {
                            if (cust.CustPartTypeCode != SECOM_AJIS.Common.Util.ConstantValue.CustPartType.C_CUST_PART_TYPE_CONTRACT_TARGET &&
                                cust.CustPartTypeCode != SECOM_AJIS.Common.Util.ConstantValue.CustPartType.C_CUST_PART_TYPE_REAL_CUST)
                            {
                                res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2025);
                                return(Json(res));
                            }

                            if (cust.CustPartTypeCode == SECOM_AJIS.Common.Util.ConstantValue.CustPartType.C_CUST_PART_TYPE_CONTRACT_TARGET)
                            {
                                if (isFoundTarget == true)
                                {
                                    res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2093);
                                    return(Json(res));
                                }
                                else
                                {
                                    isFoundTarget = true;
                                }
                            }
                            else if (cust.CustPartTypeCode == SECOM_AJIS.Common.Util.ConstantValue.CustPartType.C_CUST_PART_TYPE_REAL_CUST)
                            {
                                if (isFoundReal == true)
                                {
                                    res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2093);
                                    return(Json(res));
                                }
                                else
                                {
                                    isFoundReal = true;
                                }
                            }

                            QUS050_tbt_QuotationCustomer_BC custBC =
                                CommonUtil.CloneObject <tbt_QuotationCustomer, QUS050_tbt_QuotationCustomer_BC>(cust);
                            ObjectResultData r = ValidatorUtil.BuildErrorMessage(custBC);
                            if (r != null)
                            {
                                if (r.IsError)
                                {
                                    res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2021);
                                    return(Json(res));
                                }
                            }
                        }
                        if (isFoundTarget == false)
                        {
                            res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2024);
                            return(Json(res));
                        }
                    }
                    else
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2026);
                        return(Json(res));
                    }

                    if (importData.dtTbt_QuotationSite != null)
                    {
                        if (importData.dtTbt_QuotationSite.Count > 0)
                        {
                            QUS050_tbt_QuotationSite_BC siteBC =
                                CommonUtil.CloneObject <tbt_QuotationSite, QUS050_tbt_QuotationSite_BC>(importData.dtTbt_QuotationSite[0]);
                            ValidatorUtil.BuildErrorMessage(res, new object[] { siteBC });
                            if (res.IsError)
                            {
                                return(Json(res));
                            }
                        }
                    }
                }

                #endregion
                #region Data Authority Check

                string QuotationOfficeCode = null;
                if (ScreenID == SECOM_AJIS.Common.Util.ConstantValue.ScreenID.C_SCREEN_ID_QTN_TARGET)
                {
                    if (importData.dtTbt_QuotationTarget != null)
                    {
                        if (importData.dtTbt_QuotationTarget.Count > 0)
                        {
                            QuotationOfficeCode = importData.dtTbt_QuotationTarget[0].QuotationOfficeCode;
                        }
                    }
                }
                else
                {
                    IQuotationHandler handler = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
                    if (importData.dtTbt_QuotationBasic.Count > 0)
                    {
                        CommonUtil cmm = new CommonUtil();
                        string     qt  = cmm.ConvertQuotationTargetCode(importData.dtTbt_QuotationBasic[0].QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG);

                        doGetQuotationDataCondition cond = new doGetQuotationDataCondition()
                        {
                            QuotationTargetCode = qt
                        };
                        List <tbt_QuotationTarget> lst = handler.GetTbt_QuotationTarget(cond);
                        if (lst.Count <= 0)
                        {
                            ISaleContractHandler shandler = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                            List <tbt_SaleBasic> sLst     = shandler.GetTbt_SaleBasic(qt, null, true);
                            if (sLst.Count <= 0)
                            {
                                IRentralContractHandler        rhandler = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                                List <tbt_RentalContractBasic> rLst     = rhandler.GetTbt_RentalContractBasic(qt, null);
                                if (rLst.Count <= 0)
                                {
                                    res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2003, new string[] { importData.dtTbt_QuotationBasic[0].QuotationTargetCode });
                                    return(Json(res));
                                }
                                else
                                {
                                    if (rLst[0].ContractStatus == ContractStatus.C_CONTRACT_STATUS_BEF_START)
                                    {
                                        QuotationOfficeCode = rLst[0].ContractOfficeCode;
                                    }
                                    else
                                    {
                                        QuotationOfficeCode = rLst[0].OperationOfficeCode;
                                    }
                                }
                            }
                            else
                            {
                                if (sLst[0].ContractStatus == ContractStatus.C_CONTRACT_STATUS_BEF_START)
                                {
                                    QuotationOfficeCode = sLst[0].ContractOfficeCode;
                                }
                                else
                                {
                                    QuotationOfficeCode = sLst[0].OperationOfficeCode;
                                }
                            }
                        }
                        else
                        {
                            QuotationOfficeCode = lst[0].OperationOfficeCode;
                        }
                    }
                }

                if (QuotationOfficeCode != null && CommonUtil.dsTransData.dtOfficeData != null)
                {
                    bool isFound = false;
                    foreach (OfficeDataDo office in CommonUtil.dsTransData.dtOfficeData)
                    {
                        if (office.OfficeCode == QuotationOfficeCode)
                        {
                            isFound = true;
                            break;
                        }
                    }
                    if (isFound == false)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2023);
                        return(Json(res));
                    }
                }

                #endregion

                QUS050_ScreenParameter param = GetScreenObject <QUS050_ScreenParameter>();
                if (param != null)
                {
                    param.ImportData = importData;
                }

                res.ResultData = new object[] { importData, GetCurrentKey() };
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }
Example #16
0
        public ActionResult QUS010_XML(QUS010_SearchQuotation Cond)
        {
            QUS010_ScreenParameter param = GetScreenObject <QUS010_ScreenParameter>();

            string xmlPath = "Quotation\\QUS010";

            if (param.IsPopup == false) // plain screen
            {
                xmlPath = "Quotation\\QUS010_nonSel";
            }



            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            List <View_dtSearchQuotationListResult> dtSearchQuo = new List <View_dtSearchQuotationListResult>();

            try
            {
                ValidatorUtil.BuildErrorMessage(res, this, new object[] { Cond });
                if (res.IsError)
                {
                    res.ResultData = CommonUtil.ConvertToXml <View_dtSearchQuotationListResult>(dtSearchQuo, xmlPath, CommonUtil.GRID_EMPTY_TYPE.SEARCH);
                    return(Json(res));
                }
                if (Cond.QuotationDateFrom != null && Cond.QuotationDateTo != null)
                {
                    if (DateTime.Compare(Convert.ToDateTime(Cond.QuotationDateFrom), Convert.ToDateTime(Cond.QuotationDateTo)) > 0)
                    {
                        res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                        res.AddErrorMessage(MessageUtil.MODULE_QUOTATION, MessageUtil.MessageList.MSG2001, null, new string[] { "QuotationDateFrom", "QuotationDateTo" });
                        return(Json(res));
                    }
                }
                CommonUtil ComU = new CommonUtil();
                Cond.QuotationTargetCode = ComU.ConvertQuotationTargetCode(Cond.QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                Cond.ContractTargetCode  = ComU.ConvertCustCode(Cond.ContractTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                Cond.SiteCode            = ComU.ConvertSiteCode(Cond.SiteCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                if (!(param.CallerScreenID == ScreenID.C_SCREEN_ID_FN99 || param.CallerScreenID == ScreenID.C_SCREEN_ID_FQ99))
                {
                    Cond.ServiceTypeCode    = null;
                    Cond.TargetCodeTypeCode = null;
                }
                Cond.ContractTransferStatus = param.strContractTransferStatus;

                IQuotationHandler handler = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
                List <dtSearchQuotationListResult> lst = handler.SearchQuotationList(Cond);
                dtSearchQuo = CommonUtil.ClonsObjectList <dtSearchQuotationListResult, View_dtSearchQuotationListResult>(lst);

                CommonUtil.MappingObjectLanguage <View_dtSearchQuotationListResult>(dtSearchQuo);

                ICommonHandler      hand       = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                MiscTypeMappingList lstMiscMap = new MiscTypeMappingList();
                lstMiscMap.AddMiscType(dtSearchQuo.ToArray());
                hand.MiscTypeMappingList(lstMiscMap);

                res.ResultData = CommonUtil.ConvertToXml <View_dtSearchQuotationListResult>(dtSearchQuo, xmlPath, CommonUtil.GRID_EMPTY_TYPE.SEARCH);
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        ///<summary>
        ///Purpose   : Generate quotation (quotation target already exists)
        ///Parameters: dsGenerateQuotationData
        ///             dtHeader[0]
        ///                 - ContractCode = N0000000346
        ///                 - InstallationFee = 100000.00
        ///                 - InstallationSlipNo = 0001001201004008
        ///                 - InstallationEngineerEmpNo = 540902
        ///                 - ApproveNo1 = AR-000000005001
        ///                 - ApproveNo2 = AR-000000005008
        ///             dtInstrumentDetails[]
        ///                - dtInstrumentDetails[0]
        ///                 - InstrumentCode  = AC-A1030TH
        ///                 - InstallQty = 9999
        ///                 - AcmAddQty = NULL
        ///                 - AcmRemoveQty = 9000
        ///                - dtInstrumentDetails[1]
        ///                 - InstrumentCode = GEA-CE4-D36P-IP
        ///                 - InstallQty = 20
        ///                 - AcmAddQty = 5
        ///                 - AcmRemoveQty = NULL
        ///                - dtInstrumentDetails[2]
        ///                 - InstrumentCode = JKT-03120
        ///                 - InstallQty = 56
        ///                 - AcmAddQty = NULL
        ///                 - AcmRemoveQty = NULL
        ///                - dtInstrumentDetails[3]
        ///                 - InstrumentCode = SP40S
        ///                 - InstallQty = 0
        ///                 - AcmAddQty = 7
        ///                 - AcmRemoveQty = NULL
        ///                - dtInstrumentDetails[4]
        ///                 - InstrumentCode = HSG-IP65BIR
        ///                 - InstallQty = 40
        ///                 - AcmAddQty = 7
        ///                 - AcmRemoveQty = 3
        ///Expected  : See expectation test case7
        ///</summary>
        public string Case7()
        {
            IQuotationHandler target   = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            dsGenerateData    doUpdate = new dsGenerateData();

            //header
            doUpdate.dtHeader = new dtHeader();
            doUpdate.dtHeader.ContractCode              = "N0000000346";
            doUpdate.dtHeader.InstallationFee           = 100000.00M;
            doUpdate.dtHeader.InstallationSlipNo        = "0001001201004008";
            doUpdate.dtHeader.InstallationEngineerEmpNo = "540902";
            doUpdate.dtHeader.ApproveNo1 = "AR-000000005001";
            doUpdate.dtHeader.ApproveNo2 = "AR-000000005008";
            //detail
            doUpdate.dtInstrumentDetails = new List <dtInstrumentDetails>();
            //detail[0]
            dtInstrumentDetails dt1 = new dtInstrumentDetails();

            dt1.InstrumentCode = "AC-A1030TH";
            dt1.InstallQty     = 9999;
            dt1.AcmAddQty      = null;
            dt1.AcmRemoveQty   = 9000;
            doUpdate.dtInstrumentDetails.Add(dt1);
            //detail[1]
            dtInstrumentDetails dt2 = new dtInstrumentDetails();

            dt2.InstrumentCode = "GEA-CE4-D36P-IP";
            dt2.InstallQty     = 20;
            dt2.AcmAddQty      = 5;
            dt2.AcmRemoveQty   = null;
            doUpdate.dtInstrumentDetails.Add(dt2);
            //detail[2]
            dtInstrumentDetails dt3 = new dtInstrumentDetails();

            dt3.InstrumentCode = "JKT-03120";
            dt3.InstallQty     = 56;
            dt3.AcmAddQty      = null;
            dt3.AcmRemoveQty   = null;
            doUpdate.dtInstrumentDetails.Add(dt3);
            //detail[3]
            dtInstrumentDetails dt4 = new dtInstrumentDetails();

            dt4.InstrumentCode = "SP40S";
            dt4.InstallQty     = 0;
            dt4.AcmAddQty      = 7;
            dt4.AcmRemoveQty   = null;
            doUpdate.dtInstrumentDetails.Add(dt4);
            //detail[4]
            dtInstrumentDetails dt5 = new dtInstrumentDetails();

            dt5.InstrumentCode = "HSG-IP65BIR";
            dt5.InstallQty     = 40;
            dt5.AcmAddQty      = 7;
            dt5.AcmRemoveQty   = 3;
            doUpdate.dtInstrumentDetails.Add(dt5);

            string expected = "AB";
            string actual;

            try
            {
                CommonUtil.dsTransData.dtOperationData.GUID = "Case7";
                actual = target.GenerateQuotation(doUpdate);
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 7, expected, actual, CompareResult_String(expected, actual)));
        }
        ///<summary>
        ///Purpose   : Generate quotation (quotation target already exists)
        ///Parameters: dsGenerateQuotationData
        ///             dtHeader[0]
        ///                 - ContractCode = N0000000385
        ///                 - InstallationFee = 472000.75
        ///                 - InstallationSlipNo = 0001001201005009
        ///                 - InstallationEngineerEmpNo = 490441
        ///                 - ApproveNo1 = AR-000000005009
        ///                 - ApproveNo2 = null
        ///             dtInstrumentDetails[]
        ///                - dtInstrumentDetails[0]
        ///                 - InstrumentCode  = IQ-600NB
        ///                 - InstallQty = 25
        ///                 - AcmAddQty = 3
        ///                 - AcmRemoveQty = 0
        ///                - dtInstrumentDetails[1]
        ///                 - InstrumentCode = JKT-03120
        ///                 - InstallQty = 12
        ///                 - AcmAddQty = 0
        ///                 - AcmRemoveQty = 2
        ///                - dtInstrumentDetails[2]
        ///                 - InstrumentCode = SMK-2000A
        ///                 - InstallQty = 10
        ///                 - AcmAddQty = 0
        ///                 - AcmRemoveQty = 0
        ///                - dtInstrumentDetails[3]
        ///                 - InstrumentCode = UL135S
        ///                 - InstallQty = 0
        ///                 - AcmAddQty = 6
        ///                 - AcmRemoveQty = 0
        ///                - dtInstrumentDetails[4]
        ///                 - InstrumentCode = YV10X5B-SA2-PRO
        ///                 - InstallQty = 1
        ///                 - AcmAddQty = 17
        ///                 - AcmRemoveQty = 4
        ///Expected  : See expectation test case9
        ///</summary>
        public string Case9()
        {
            IQuotationHandler target   = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
            dsGenerateData    doUpdate = new dsGenerateData();

            //header
            doUpdate.dtHeader = new dtHeader();
            doUpdate.dtHeader.ContractCode              = "N0000000385";
            doUpdate.dtHeader.InstallationFee           = 472000.75M;
            doUpdate.dtHeader.InstallationSlipNo        = "0001001201005009";
            doUpdate.dtHeader.InstallationEngineerEmpNo = "490441";
            doUpdate.dtHeader.ApproveNo1 = "AR-000000005009";
            doUpdate.dtHeader.ApproveNo2 = null;
            //detail
            doUpdate.dtInstrumentDetails = new List <dtInstrumentDetails>();
            //detail[0]
            dtInstrumentDetails dt1 = new dtInstrumentDetails();

            dt1.InstrumentCode = "IQ-600NB";
            dt1.InstallQty     = 25;
            dt1.AcmAddQty      = 3;
            dt1.AcmRemoveQty   = 0;
            doUpdate.dtInstrumentDetails.Add(dt1);
            //detail[1]
            dtInstrumentDetails dt2 = new dtInstrumentDetails();

            dt2.InstrumentCode = "JKT-03120";
            dt2.InstallQty     = 12;
            dt2.AcmAddQty      = 0;
            dt2.AcmRemoveQty   = 2;
            doUpdate.dtInstrumentDetails.Add(dt2);
            //detail[2]
            dtInstrumentDetails dt3 = new dtInstrumentDetails();

            dt3.InstrumentCode = "SMK-2000A";
            dt3.InstallQty     = 10;
            dt3.AcmAddQty      = 0;
            dt3.AcmRemoveQty   = 0;
            doUpdate.dtInstrumentDetails.Add(dt3);
            //detail[3]
            dtInstrumentDetails dt4 = new dtInstrumentDetails();

            dt4.InstrumentCode = "UL135S";
            dt4.InstallQty     = 0;
            dt4.AcmAddQty      = 6;
            dt4.AcmRemoveQty   = 0;
            doUpdate.dtInstrumentDetails.Add(dt4);
            //detail[4]
            dtInstrumentDetails dt5 = new dtInstrumentDetails();

            dt5.InstrumentCode = "YV10X5B-SA2-PRO";
            dt5.InstallQty     = 1;
            dt5.AcmAddQty      = 17;
            dt5.AcmRemoveQty   = 4;
            doUpdate.dtInstrumentDetails.Add(dt5);

            string expected = "AA";
            string actual;

            try
            {
                CommonUtil.dsTransData.dtOperationData.GUID = "Case9";
                actual = target.GenerateQuotation(doUpdate);
            }
            catch (ApplicationErrorException ex)
            {
                actual = ex.ErrorResult.Message.Code;
            }
            catch (Exception ex)
            {
                actual = ex.StackTrace;
            }

            return(string.Format(RESULT_FORMAT, 9, expected, actual, CompareResult_String(expected, actual)));
        }
Example #19
0
        /// <summary>
        /// Get entire draft sale contract
        /// </summary>
        /// <param name="cond"></param>
        /// <param name="mode"></param>
        /// <param name="procType"></param>
        /// <returns></returns>
        public doDraftSaleContractData GetEntireDraftSaleContract(doDraftSaleContractCondition cond, doDraftSaleContractData.SALE_CONTRACT_MODE mode, doDraftSaleContractData.PROCESS_TYPE procType)
        {
            try
            {
                doDraftSaleContractData saleData = null;

                if (mode == doDraftSaleContractData.SALE_CONTRACT_MODE.QUOTATION)
                {
                    CommonUtil cmm = new CommonUtil();
                    doGetQuotationDataCondition qcond = new doGetQuotationDataCondition();
                    qcond.QuotationTargetCode = cond.QuotationTargetCodeLong;
                    qcond.Alphabet            = cond.Alphabet;
                    qcond.ServiceTypeCode     = ServiceType.C_SERVICE_TYPE_SALE;


                    if (procType == doDraftSaleContractData.PROCESS_TYPE.NEW)
                    {
                        qcond.TargetCodeTypeCode = TargetCodeType.C_TARGET_CODE_TYPE_QTN_CODE;
                    }
                    else
                    {
                        qcond.TargetCodeTypeCode = TargetCodeType.C_TARGET_CODE_TYPE_CONTRACT_CODE;
                    }

                    qcond.ContractFlag = true;

                    IQuotationHandler qhandler = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
                    dsQuotationData   qData    = qhandler.GetQuotationData(qcond);
                    if (qData != null)
                    {
                        #region Check Authority

                        bool hasAuthority             = false;
                        List <OfficeDataDo> officeLst = CommonUtil.dsTransData.dtOfficeData;
                        if (qData.dtTbt_QuotationTarget != null &&
                            officeLst.Count > 0)
                        {
                            foreach (OfficeDataDo office in officeLst)
                            {
                                if (office.OfficeCode == qData.dtTbt_QuotationTarget.QuotationOfficeCode ||
                                    office.OfficeCode == qData.dtTbt_QuotationTarget.OperationOfficeCode)
                                {
                                    hasAuthority = true;
                                    break;
                                }
                            }
                        }
                        if (hasAuthority == false)
                        {
                            throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0063);
                        }

                        #endregion

                        saleData = new doDraftSaleContractData();

                        if (qData.dtTbt_QuotationTarget.UpdateDate != null)
                        {
                            saleData.LastUpdateDateQuotationData = qData.dtTbt_QuotationTarget.UpdateDate.Value;
                        }

                        #region Set Draft Sale Contract

                        saleData.doTbt_DraftSaleContract = CommonUtil.CloneObject <tbt_QuotationBasic, tbt_DraftSaleContract>(qData.dtTbt_QuotationBasic);
                        if (saleData.doTbt_DraftSaleContract != null)
                        {
                            saleData.doTbt_DraftSaleContract.QuotationTargetCode = cond.QuotationTargetCodeLong;
                            saleData.doTbt_DraftSaleContract.Alphabet            = cond.Alphabet;
                            saleData.doTbt_DraftSaleContract.ProductTypeCode     = qData.dtTbt_QuotationTarget.ProductTypeCode;
                            saleData.doTbt_DraftSaleContract.BranchNameEN        = qData.dtTbt_QuotationTarget.BranchNameEN;
                            saleData.doTbt_DraftSaleContract.BranchNameLC        = qData.dtTbt_QuotationTarget.BranchNameLC;
                            saleData.doTbt_DraftSaleContract.BranchAddressEN     = qData.dtTbt_QuotationTarget.BranchAddressEN;
                            saleData.doTbt_DraftSaleContract.BranchAddressLC     = qData.dtTbt_QuotationTarget.BranchAddressLC;

                            saleData.doTbt_DraftSaleContract.PurchaserMemo    = qData.dtTbt_QuotationTarget.ContractTargetMemo;
                            saleData.doTbt_DraftSaleContract.RealCustomerMemo = qData.dtTbt_QuotationTarget.RealCustomerMemo;

                            foreach (tbt_QuotationCustomer cust in qData.dtTbt_QuotationCustomer)
                            {
                                if (cust.CustPartTypeCode == CustPartType.C_CUST_PART_TYPE_CONTRACT_TARGET)
                                {
                                    saleData.doTbt_DraftSaleContract.PurchaserCustCode = cust.CustCode;
                                }
                                else if (cust.CustPartTypeCode == CustPartType.C_CUST_PART_TYPE_REAL_CUST)
                                {
                                    saleData.doTbt_DraftSaleContract.RealCustomerCustCode = cust.CustCode;
                                }
                            }
                            if (qData.dtTbt_QuotationSite != null)
                            {
                                saleData.doTbt_DraftSaleContract.SiteCode = qData.dtTbt_QuotationSite.SiteCode;
                            }

                            saleData.doTbt_DraftSaleContract.ConnectTargetCode = qData.dtTbt_QuotationBasic.SaleOnlineContractCode;
                            if (CommonUtil.IsNullOrEmpty(saleData.doTbt_DraftSaleContract.ConnectTargetCode) == false)
                            {
                                saleData.doTbt_DraftSaleContract.ConnectionFlag = FlagType.C_FLAG_ON;
                            }
                            else
                            {
                                saleData.doTbt_DraftSaleContract.ConnectionFlag = FlagType.C_FLAG_OFF;
                            }


                            saleData.doTbt_DraftSaleContract.NormalProductPriceCurrencyType = qData.dtTbt_QuotationBasic.ProductPriceCurrencyType;
                            saleData.doTbt_DraftSaleContract.NormalProductPrice             = qData.dtTbt_QuotationBasic.ProductPrice;
                            saleData.doTbt_DraftSaleContract.NormalProductPriceUsd          = qData.dtTbt_QuotationBasic.ProductPriceUsd;

                            saleData.doTbt_DraftSaleContract.NormalInstallFeeCurrencyType = qData.dtTbt_QuotationBasic.InstallationFeeCurrencyType;
                            saleData.doTbt_DraftSaleContract.NormalInstallFee             = qData.dtTbt_QuotationBasic.InstallationFee;
                            saleData.doTbt_DraftSaleContract.NormalInstallFeeUsd          = qData.dtTbt_QuotationBasic.InstallationFeeUsd;

                            if (CommonUtil.IsNullOrEmpty(saleData.doTbt_DraftSaleContract.NormalProductPrice) == false ||
                                CommonUtil.IsNullOrEmpty(saleData.doTbt_DraftSaleContract.NormalInstallFee) == false)
                            {
                                saleData.doTbt_DraftSaleContract.NormalSalePrice = 0;

                                //if (CommonUtil.IsNullOrEmpty(saleData.doTbt_DraftSaleContract.NormalProductPrice) == false)
                                //    saleData.doTbt_DraftSaleContract.NormalSalePrice += saleData.doTbt_DraftSaleContract.NormalProductPrice;
                                //if (CommonUtil.IsNullOrEmpty(saleData.doTbt_DraftSaleContract.NormalInstallFee) == false)
                                //    saleData.doTbt_DraftSaleContract.NormalSalePrice += saleData.doTbt_DraftSaleContract.NormalInstallFee;
                            }
                            saleData.doTbt_DraftSaleContract.NormalSpecialItemPrice = 0;
                            saleData.doTbt_DraftSaleContract.NormalOtherProdPrice   = 0;
                            saleData.doTbt_DraftSaleContract.NormalOtherInstallFee  = 0;

                            //saleData.doTbt_DraftSaleContract.OrderProductPrice = qData.dtTbt_QuotationBasic.ProductPrice;
                            //saleData.doTbt_DraftSaleContract.OrderInstallFee = qData.dtTbt_QuotationBasic.InstallationFee;
                            //saleData.doTbt_DraftSaleContract.OrderSalePrice = saleData.doTbt_DraftSaleContract.NormalSalePrice;

                            saleData.doTbt_DraftSaleContract.OrderProductPriceCurrencyType = qData.dtTbt_QuotationBasic.ProductPriceCurrencyType;
                            saleData.doTbt_DraftSaleContract.OrderProductPrice             = null;
                            saleData.doTbt_DraftSaleContract.OrderProductPriceUsd          = null;

                            saleData.doTbt_DraftSaleContract.OrderInstallFeeCurrencyType = qData.dtTbt_QuotationBasic.InstallationFeeCurrencyType;
                            saleData.doTbt_DraftSaleContract.OrderInstallFee             = null;
                            saleData.doTbt_DraftSaleContract.OrderInstallFeeUsd          = null;

                            saleData.doTbt_DraftSaleContract.OrderSalePrice = null;

                            saleData.doTbt_DraftSaleContract.TotalSaleBilingAmt_Agreed = 0;

                            saleData.doTbt_DraftSaleContract.QuotationStaffEmpNo = qData.dtTbt_QuotationTarget.QuotationStaffEmpNo;
                            saleData.doTbt_DraftSaleContract.QuotationOfficeCode = qData.dtTbt_QuotationTarget.QuotationOfficeCode;
                            saleData.doTbt_DraftSaleContract.OperationOfficeCode = qData.dtTbt_QuotationTarget.OperationOfficeCode;
                            saleData.doTbt_DraftSaleContract.AcquisitionTypeCode = qData.dtTbt_QuotationTarget.AcquisitionTypeCode;
                            saleData.doTbt_DraftSaleContract.IntroducerCode      = qData.dtTbt_QuotationTarget.IntroducerCode;
                            saleData.doTbt_DraftSaleContract.MotivationTypeCode  = qData.dtTbt_QuotationTarget.MotivationTypeCode;

                            saleData.doTbt_DraftSaleContract.ApproveNo1 = null;
                            saleData.doTbt_DraftSaleContract.ApproveNo2 = null;
                            saleData.doTbt_DraftSaleContract.ApproveNo3 = null;
                            saleData.doTbt_DraftSaleContract.ApproveNo4 = null;
                            saleData.doTbt_DraftSaleContract.ApproveNo5 = null;

                            saleData.doTbt_DraftSaleContract.CreateBy   = null;
                            saleData.doTbt_DraftSaleContract.CreateDate = null;
                            saleData.doTbt_DraftSaleContract.UpdateBy   = null;
                            saleData.doTbt_DraftSaleContract.UpdateDate = null;

                            List <tbt_DraftSaleContract> contractLst = this.GetTbt_DraftSaleContract(cond.QuotationTargetCodeLong);
                            if (contractLst.Count > 0)
                            {
                                saleData.doTbt_DraftSaleContract.CreateBy   = contractLst[0].CreateBy;
                                saleData.doTbt_DraftSaleContract.CreateDate = contractLst[0].CreateDate;
                                saleData.doTbt_DraftSaleContract.UpdateBy   = contractLst[0].UpdateBy;
                                saleData.doTbt_DraftSaleContract.UpdateDate = contractLst[0].UpdateDate;
                            }

                            if (saleData.doTbt_DraftSaleContract.ProductTypeCode == ProductType.C_PROD_TYPE_ONLINE)
                            {
                                ISaleContractHandler shandler = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                                if (qData.dtTbt_QuotationBasic.SaleOnlineContractCode != null)
                                {
                                    doSaleContractData doSaleContract = shandler.GetSaleContractData(qData.dtTbt_QuotationBasic.SaleOnlineContractCode, null);
                                    if (doSaleContract != null)
                                    {
                                        saleData.doTbt_DraftSaleContract.SecurityAreaFrom = doSaleContract.dtTbt_SaleBasic.SecurityAreaFrom;
                                        saleData.doTbt_DraftSaleContract.SecurityAreaTo   = doSaleContract.dtTbt_SaleBasic.SecurityAreaTo;
                                    }
                                }
                            }
                        }

                        #endregion
                        #region Set Draft Sale Customer

                        MiscTypeMappingList    cmLst    = new MiscTypeMappingList();
                        ICustomerMasterHandler chandler = ServiceContainer.GetService <ICustomerMasterHandler>() as ICustomerMasterHandler;
                        foreach (tbt_QuotationCustomer cust in qData.dtTbt_QuotationCustomer)
                        {
                            doCustomerWithGroup icust = null;
                            if (cust.CustCode != null)
                            {
                                List <doCustomerWithGroup> lst = chandler.GetCustomerWithGroup(cust.CustCode);
                                if (lst.Count > 0)
                                {
                                    icust = lst[0];
                                }
                            }
                            else
                            {
                                icust = CommonUtil.CloneObject <tbt_QuotationCustomer, doCustomerWithGroup>(cust);
                                if (icust != null)
                                {
                                    icust.CustomerGroupData = new List <dtCustomeGroupData>();
                                }

                                IMasterHandler mhandler = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;

                                if (icust.BusinessTypeCode != null)
                                {
                                    List <tbm_BusinessType> btLst = mhandler.GetTbm_BusinessType();
                                    foreach (tbm_BusinessType bt in btLst)
                                    {
                                        if (bt.BusinessTypeCode == icust.BusinessTypeCode)
                                        {
                                            icust.BusinessTypeName = bt.BusinessTypeName;
                                            break;
                                        }
                                    }
                                }
                                if (icust.RegionCode != null)
                                {
                                    List <tbm_Region> rLst = mhandler.GetTbm_Region();
                                    foreach (tbm_Region r in rLst)
                                    {
                                        if (r.RegionCode == icust.RegionCode)
                                        {
                                            icust.Nationality = r.Nationality;
                                            break;
                                        }
                                    }
                                }
                                if (icust.CustTypeCode != null)
                                {
                                    cmLst.AddMiscType(icust);
                                }
                            }
                            if (icust != null)
                            {
                                if (cust.CustPartTypeCode == CustPartType.C_CUST_PART_TYPE_CONTRACT_TARGET)
                                {
                                    saleData.doPurchaserCustomer = icust;
                                }
                                else if (cust.CustPartTypeCode == CustPartType.C_CUST_PART_TYPE_REAL_CUST)
                                {
                                    saleData.doRealCustomer = icust;
                                }
                            }
                        }

                        ICommonHandler cmmhandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                        cmmhandler.MiscTypeMappingList(cmLst);

                        #endregion
                        #region Set Draft Sale Site

                        if (qData.dtTbt_QuotationSite != null)
                        {
                            if (qData.dtTbt_QuotationSite.SiteCode != null)
                            {
                                ISiteMasterHandler shandler = ServiceContainer.GetService <ISiteMasterHandler>() as ISiteMasterHandler;
                                List <doSite>      lst      = shandler.GetSite(qData.dtTbt_QuotationSite.SiteCode, null);
                                if (lst.Count > 0)
                                {
                                    saleData.doSite = lst[0];
                                }
                            }
                            else
                            {
                                saleData.doSite = CommonUtil.CloneObject <tbt_QuotationSite, doSite>(qData.dtTbt_QuotationSite);

                                IMasterHandler           mhandler = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;
                                List <tbm_BuildingUsage> blst     = mhandler.GetTbm_BiuldingUsage();
                                foreach (tbm_BuildingUsage b in blst)
                                {
                                    if (b.BuildingUsageCode == saleData.doSite.BuildingUsageCode)
                                    {
                                        saleData.doSite.BuildingUsageName = b.BuildingUsageName;
                                        break;
                                    }
                                }
                            }
                        }

                        #endregion
                        #region Set Draft Sale Instrument

                        saleData.doTbt_DraftSaleInstrument = new List <tbt_DraftSaleInstrument>();
                        if (qData.dtTbt_QuotationInstrumentDetails != null)
                        {
                            foreach (tbt_QuotationInstrumentDetails inst in qData.dtTbt_QuotationInstrumentDetails)
                            {
                                tbt_DraftSaleInstrument dInst = new tbt_DraftSaleInstrument();
                                dInst.QuotationTargetCode = cond.QuotationTargetCodeLong;
                                dInst.InstrumentCode      = inst.InstrumentCode;
                                dInst.InstrumentQty       = inst.InstrumentQty;
                                dInst.InstrumentTypeCode  = InstrumentType.C_INST_TYPE_GENERAL;

                                if (CommonUtil.IsNullOrEmpty(dInst.InstrumentQty) == false)
                                {
                                    if (CommonUtil.IsNullOrEmpty(inst.AddQty) == false)
                                    {
                                        dInst.InstrumentQty += inst.AddQty;
                                    }
                                    if (CommonUtil.IsNullOrEmpty(inst.RemoveQty) == false)
                                    {
                                        dInst.InstrumentQty -= inst.RemoveQty;
                                    }
                                }

                                saleData.doTbt_DraftSaleInstrument.Add(dInst);
                            }
                        }
                        if (qData.dtTbt_QuotationFacilityDetails != null)
                        {
                            foreach (tbt_QuotationFacilityDetails facility in qData.dtTbt_QuotationFacilityDetails)
                            {
                                tbt_DraftSaleInstrument dInst = new tbt_DraftSaleInstrument();
                                dInst.QuotationTargetCode = cond.QuotationTargetCode;
                                dInst.InstrumentCode      = facility.FacilityCode;
                                dInst.InstrumentQty       = facility.FacilityQty;
                                dInst.InstrumentTypeCode  = InstrumentType.C_INST_TYPE_MONITOR;

                                saleData.doTbt_DraftSaleInstrument.Add(dInst);
                            }
                        }

                        if (saleData.doTbt_DraftSaleInstrument.Count > 0)
                        {
                            InstrumentMappingList instMappingLst = new InstrumentMappingList();
                            instMappingLst.AddInstrument(saleData.doTbt_DraftSaleInstrument.ToArray());

                            IInstrumentMasterHandler ihandler = ServiceContainer.GetService <IInstrumentMasterHandler>() as IInstrumentMasterHandler;
                            ihandler.InstrumentListMapping(instMappingLst);
                        }

                        #endregion
                        #region Set Draft Relation Type

                        saleData.doTbt_RelationType = new List <tbt_RelationType>();

                        /* -- Sale Online --- */
                        if (CommonUtil.IsNullOrEmpty(qData.dtTbt_QuotationBasic.SaleOnlineContractCode) == false)
                        {
                            saleData.doTbt_RelationType.Add(new tbt_RelationType()
                            {
                                RelatedContractCode = qData.dtTbt_QuotationBasic.SaleOnlineContractCode,
                                RelatedOCC          = qData.dtTbt_QuotationBasic.LastOccNo,
                                OCC          = null,
                                RelationType = RelationType.C_RELATION_TYPE_SALE
                            });
                        }

                        #endregion
                    }
                }
                else if (mode == doDraftSaleContractData.SALE_CONTRACT_MODE.DRAFT ||
                         mode == doDraftSaleContractData.SALE_CONTRACT_MODE.APPROVE)
                {
                    saleData = new doDraftSaleContractData();

                    #region Set Draft Sale Contract

                    List <tbt_DraftSaleContract> contractLst = this.GetTbt_DraftSaleContract(cond.QuotationTargetCodeLong);
                    if (contractLst.Count > 0)
                    {
                        saleData.doTbt_DraftSaleContract = contractLst[0];
                    }
                    else
                    {
                        return(null);
                    }

                    #endregion
                    #region Check Authority

                    bool hasAuthority             = false;
                    List <OfficeDataDo> officeLst = CommonUtil.dsTransData.dtOfficeData;
                    if (saleData.doTbt_DraftSaleContract != null &&
                        officeLst.Count > 0)
                    {
                        foreach (OfficeDataDo office in officeLst)
                        {
                            if (office.OfficeCode == saleData.doTbt_DraftSaleContract.QuotationOfficeCode ||
                                office.OfficeCode == saleData.doTbt_DraftSaleContract.OperationOfficeCode)
                            {
                                hasAuthority = true;
                                break;
                            }
                        }
                    }
                    if (hasAuthority == false)
                    {
                        throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0063);
                    }

                    #endregion
                    #region Check Contract status

                    if (mode == doDraftSaleContractData.SALE_CONTRACT_MODE.DRAFT &&
                        saleData.doTbt_DraftSaleContract.DraftSaleContractStatus != ApprovalStatus.C_APPROVE_STATUS_RETURNED)
                    {
                        throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3100);
                    }
                    else if (mode == doDraftSaleContractData.SALE_CONTRACT_MODE.APPROVE)
                    {
                        if (saleData.doTbt_DraftSaleContract.DraftSaleContractStatus == ApprovalStatus.C_APPROVE_STATUS_APPROVED)
                        {
                            throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3246);
                        }
                        else if (saleData.doTbt_DraftSaleContract.DraftSaleContractStatus == ApprovalStatus.C_APPROVE_STATUS_REJECTED)
                        {
                            throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3244);
                        }
                        else if (saleData.doTbt_DraftSaleContract.DraftSaleContractStatus == ApprovalStatus.C_APPROVE_STATUS_RETURNED)
                        {
                            throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3245);
                        }
                    }

                    #endregion

                    #region Set Draft Sale E-mail

                    saleData.doTbt_DraftSaleEmail = this.GetTbt_DraftSaleEmail(cond.QuotationTargetCodeLong);
                    if (saleData.doTbt_DraftSaleEmail != null)
                    {
                        IEmployeeMasterHandler empHandler = ServiceContainer.GetService <IEmployeeMasterHandler>() as IEmployeeMasterHandler;

                        List <tbm_Employee> emps = new List <tbm_Employee>();
                        foreach (tbt_DraftSaleEmail email in saleData.doTbt_DraftSaleEmail)
                        {
                            emps.Add(new tbm_Employee()
                            {
                                EmpNo = email.ToEmpNo
                            });
                        }
                        List <tbm_Employee> empList = empHandler.GetEmployeeList(emps);
                        if (empList.Count > 0)
                        {
                            foreach (tbt_DraftSaleEmail email in saleData.doTbt_DraftSaleEmail)
                            {
                                foreach (tbm_Employee emp in empList)
                                {
                                    if (emp.EmpNo == email.ToEmpNo)
                                    {
                                        email.EmailAddress = emp.EmailAddress;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                    #region Set Draft Sale Instrument

                    saleData.doTbt_DraftSaleInstrument = this.GetTbt_DraftSaleInstrument(cond.QuotationTargetCodeLong);
                    if (saleData.doTbt_DraftSaleInstrument.Count > 0)
                    {
                        InstrumentMappingList instMappingLst = new InstrumentMappingList();
                        instMappingLst.AddInstrument(saleData.doTbt_DraftSaleInstrument.ToArray());

                        IInstrumentMasterHandler ihandler = ServiceContainer.GetService <IInstrumentMasterHandler>() as IInstrumentMasterHandler;
                        ihandler.InstrumentListMapping(instMappingLst);
                    }

                    #endregion
                    #region Set Draft Sale Billing Target

                    saleData.doTbt_DraftSaleBillingTarget = this.GetTbt_DraftSaleBillingTarget(cond.QuotationTargetCodeLong);

                    #endregion

                    #region Set Contract Customer

                    ICustomerMasterHandler custhandler = ServiceContainer.GetService <ICustomerMasterHandler>() as ICustomerMasterHandler;
                    if (CommonUtil.IsNullOrEmpty(saleData.doTbt_DraftSaleContract.PurchaserCustCode) == false)
                    {
                        List <doCustomerWithGroup> custLst = custhandler.GetCustomerWithGroup(saleData.doTbt_DraftSaleContract.PurchaserCustCode);
                        if (custLst.Count > 0)
                        {
                            saleData.doPurchaserCustomer = custLst[0];
                        }
                    }
                    if (CommonUtil.IsNullOrEmpty(saleData.doTbt_DraftSaleContract.RealCustomerCustCode) == false)
                    {
                        List <doCustomerWithGroup> custLst = custhandler.GetCustomerWithGroup(saleData.doTbt_DraftSaleContract.RealCustomerCustCode);
                        if (custLst.Count > 0)
                        {
                            saleData.doRealCustomer = custLst[0];
                        }
                    }

                    #endregion
                    #region Set Site

                    ISiteMasterHandler shandler = ServiceContainer.GetService <ISiteMasterHandler>() as ISiteMasterHandler;
                    List <doSite>      siteLst  = shandler.GetSite(saleData.doTbt_DraftSaleContract.SiteCode, saleData.doTbt_DraftSaleContract.RealCustomerCustCode);
                    if (siteLst.Count > 0)
                    {
                        saleData.doSite = siteLst[0];
                    }

                    #endregion

                    doGetQuotationDataCondition qcond = new doGetQuotationDataCondition();
                    qcond.QuotationTargetCode = cond.QuotationTargetCodeLong;
                    qcond.Alphabet            = saleData.doTbt_DraftSaleContract.Alphabet;//cond.Alphabet;
                    qcond.ServiceTypeCode     = ServiceType.C_SERVICE_TYPE_SALE;

                    if (saleData.doTbt_DraftSaleContract.SaleProcessType == SaleProcessType.C_SALE_PROCESS_TYPE_ADD_SALE)
                    {
                        qcond.TargetCodeTypeCode = TargetCodeType.C_TARGET_CODE_TYPE_CONTRACT_CODE;
                    }
                    else
                    {
                        qcond.TargetCodeTypeCode = TargetCodeType.C_TARGET_CODE_TYPE_QTN_CODE;
                    }

                    qcond.ContractFlag = true;

                    IQuotationHandler qhandler = ServiceContainer.GetService <IQuotationHandler>() as IQuotationHandler;
                    dsQuotationData   qData    = qhandler.GetQuotationData(qcond);
                    if (qData != null)
                    {
                        if (qData.dtTbt_QuotationTarget.UpdateDate != null)
                        {
                            saleData.LastUpdateDateQuotationData = qData.dtTbt_QuotationTarget.UpdateDate.Value;
                        }
                    }
                }

                if (saleData != null)
                {
                    if (saleData.doTbt_DraftSaleContract != null)
                    {
                        #region Set Product Name

                        IProductMasterHandler   mhandler = ServiceContainer.GetService <IProductMasterHandler>() as IProductMasterHandler;
                        List <View_tbm_Product> pLst     = mhandler.GetTbm_ProductByLanguage(
                            saleData.doTbt_DraftSaleContract.ProductCode,
                            saleData.doTbt_DraftSaleContract.ProductTypeCode);

                        if (pLst.Count > 0)
                        {
                            saleData.doTbt_DraftSaleContract.ProductName = pLst[0].ProductName;
                        }

                        #endregion
                        #region Set Misc Name

                        MiscTypeMappingList miscLst = new MiscTypeMappingList();
                        miscLst.AddMiscType(saleData.doTbt_DraftSaleContract);
                        miscLst.AddMiscType(saleData.doTbt_DraftSaleInstrument.ToArray());

                        ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                        chandler.MiscTypeMappingList(miscLst);

                        #endregion
                        #region Set Employee Name

                        EmployeeMappingList empLst = new EmployeeMappingList();
                        empLst.AddEmployee(saleData.doTbt_DraftSaleContract);

                        IEmployeeMasterHandler emphandler = ServiceContainer.GetService <IEmployeeMasterHandler>() as IEmployeeMasterHandler;
                        emphandler.EmployeeListMapping(empLst);

                        #endregion
                    }
                }

                return(saleData);
            }
            catch (Exception)
            {
                throw;
            }
        }