/// <summary>
        /// Update sale basic
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private bool CTS190_UpdateSaleBasic(List <tbt_ContractDocument> dt)
        {
            try
            {
                if (dt == null || dt.Count == 0)
                {
                    return(false);
                }

                ISaleContractHandler handlerRC = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;

                // Get SaleBasic (SB)
                List <tbt_SaleBasic> dtSB = handlerRC.GetTbt_SaleBasic(dt[0].ContractCode, dt[0].OCC, null);

                if (dtSB.Count == 0)
                {
                    return(false);
                }

                dtSB[0].DocReceiveDate = dt[0].CollectDocDate;
                dtSB[0].DocAuditResult = dt[0].DocAuditResult;
                dtSB[0].DocumentCode   = dt[0].DocumentCode;


                handlerRC.UpdateTbt_SaleBasic(dtSB[0]);


                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Check permission for access screen CMS200
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult CMS200_Authority(CMS200_ScreenParameter param) // IN parameter: string strContractCode, string strServiceTypeCode
        {
            ObjectResultData res = new ObjectResultData();

            // Check permission
            if (!CheckUserPermission(ScreenID.C_SCREEN_ID_VIEW_CONTRACT_BILLING, FunctionID.C_FUNC_ID_OPERATE))
            {
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                return(Json(res));
            }

            // Check parameter is OK ?
            if (CommonUtil.IsNullOrEmpty(param.strContractCode) == false && CommonUtil.IsNullOrEmpty(param.strServiceTypeCode) == false)
            {
                param.ContractCode    = param.strContractCode;
                param.ServiceTypeCode = param.strServiceTypeCode;
            }
            else
            {
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0040);
                return(Json(res));
            }

            // Check exist data
            try
            {
                CommonUtil c            = new CommonUtil();
                string     ContractCode = c.ConvertContractCode(param.strContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);


                IRentralContractHandler handlerRC = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                ISaleContractHandler    handlerSC = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                List <dtTbt_RentalContractBasicForView> listRC = new List <dtTbt_RentalContractBasicForView>();
                List <dtTbt_SaleBasicForView>           listSC = new List <dtTbt_SaleBasicForView>();

                if (param.strServiceTypeCode == ServiceType.C_SERVICE_TYPE_RENTAL)
                {
                    listRC = handlerRC.GetTbt_RentalContractBasicForView(ContractCode);
                }
                else if (param.strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE)
                {
                    listSC = handlerSC.GetTbt_SaleBasicForView(ContractCode, null, true);
                }

                if (listRC.Count == 0 && listSC.Count == 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001);
                    return(Json(res));
                }
            }
            catch
            {
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001);
                return(Json(res));
            }



            return(InitialScreenEnvironment <CMS200_ScreenParameter>("CMS200", param, res));
        }
示例#3
0
        //public ActionResult CMS020_SearchBar_Authority()
        //{
        //    return InitialScreenEnvironment("CMS020_SearchBar");

        //}

        ////[Initialize("CMS020_SearchBar")]
        //public ActionResult CMS020_SearchBar()
        //{
        //    return View();
        //}

        /// <summary>
        /// Retrieve contract data from tbt_RentalContractBasic or tbt_SaleBasic.
        /// </summary>
        /// <param name="strContractCode"></param>
        /// <param name="strUserCode"></param>
        /// <returns></returns>
        private dsContractData CMS020_RetrieveContract(string strContractCode, string strUserCode)
        {
            try
            {
                CommonUtil cm = new CommonUtil();
                strContractCode = cm.ConvertContractCode(strContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);

                dsContractData                 dsContractData = new dsContractData();
                IRentralContractHandler        RentHand       = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                List <tbt_RentalContractBasic> dtRCB          = RentHand.GetTbt_RentalContractBasic(strContractCode, strUserCode);

                if (dtRCB.Count == 0)
                {
                    ISaleContractHandler SaleHand = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                    List <tbt_SaleBasic> dtSB     = SaleHand.GetTbt_SaleBasic(strContractCode, null, FlagType.C_FLAG_ON);

                    if (dtSB.Count > 0)
                    {
                        dsContractData.dtSB  = dtSB;
                        dsContractData.dtRCB = null;
                    }
                }
                else
                {
                    dsContractData.dtSB  = null;
                    dsContractData.dtRCB = dtRCB;
                }

                return(dsContractData);
            }
            catch (Exception) { throw; }
        }
示例#4
0
        /// <summary>
        /// Get Sale digest by type, contract code and OCC.
        /// </summary>
        /// <param name="sType"></param>
        /// <param name="strLongContractCode"></param>
        /// <param name="OCC"></param>
        /// <returns></returns>
        public ActionResult getSaleDigestCMS150(string sType, string strLongContractCode, string OCC)
        {
            if (OCC.Trim() == "")
            {
                OCC = null;
            }
            if (strLongContractCode.Trim() == "")
            {
                strLongContractCode = null;
            }
            if (sType.Trim() == "")
            {
                sType = null;
            }

            List <View_dtSaleHistoryDigestList> vSaleHist = null;
            ObjectResultData res = new ObjectResultData();

            try
            {
                ISaleContractHandler  handSale      = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                ICommonHandler        comHand       = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                List <doMiscTypeCode> tmpCurrencies = comHand.GetMiscTypeCodeList(new List <doMiscTypeCode>()
                {
                    new doMiscTypeCode()
                    {
                        FieldName = MiscType.C_CURRENCT,
                        ValueCode = "%"
                    }
                }).ToList();
                List <dtTbt_SaleBasicForView> dtTbt_SaleBasicForView = handSale.GetTbt_SaleBasicForView(strLongContractCode, OCC, FlagType.C_FLAG_ON);
                //Add Currency to List
                for (int i = 0; i < dtTbt_SaleBasicForView.Count(); i++)
                {
                    dtTbt_SaleBasicForView[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                }

                if (dtTbt_SaleBasicForView.Count <= 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001);
                    // return Json(res);
                }
                else
                {
                    IViewContractHandler       handView            = ServiceContainer.GetService <IViewContractHandler>() as IViewContractHandler;
                    List <dtSaleHistoryDigest> dtSaleHistoryDigest = handView.GetSaleHistoryDigestList(dtTbt_SaleBasicForView[0].ContractCode, null, null);
                    //Add Currency to List
                    for (int i = 0; i < dtSaleHistoryDigest.Count(); i++)
                    {
                        dtSaleHistoryDigest[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                    }
                    vSaleHist = CommonUtil.ConvertObjectbyLanguage <dtSaleHistoryDigest, View_dtSaleHistoryDigestList>(dtSaleHistoryDigest, "ChangeTypeName", "IncidentARTypeName");
                }

                string XmlSaleHist = CommonUtil.ConvertToXml <View_dtSaleHistoryDigestList>(vSaleHist, "Common\\CMS150_sale", CommonUtil.GRID_EMPTY_TYPE.SEARCH);
                return(Json(XmlSaleHist));
            }
            catch (Exception ex) { res.AddErrorMessage(ex); return(Json(res)); }
        }
示例#5
0
        /// <summary>
        /// Reset data of screen
        /// </summary>
        /// <param name="lastOCC"></param>
        /// <returns></returns>
        public ActionResult ResetClick_CTS061(string lastOCC)
        {
            string expectedInstallCompleteDate = "";

            ObjectResultData res = new ObjectResultData();
            ObjectResultData resValidateBusiness = new ObjectResultData();
            CommonUtil       util = new CommonUtil();

            CTS061_ScreenParameter session;
            ISaleContractHandler   salehandler        = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
            IUserControlHandler    usercontrolhandler = ServiceContainer.GetService <IUserControlHandler>() as IUserControlHandler;

            try
            {
                //Set screen to Initial state
                session = CTS061_GetImportData();
                expectedInstallCompleteDate = CommonUtil.TextDate(salehandler.GetTbt_SaleBasic(session.DSSaleContract.dtTbt_SaleBasic[0].ContractCode, lastOCC, true)[0].ExpectedInstallCompleteDate);
                var saleContractInfo = usercontrolhandler.GetSaleContractBasicInformationData(session.ContractCode, null);

                InitialScreen_CTS061(session.ContractCode);
                session = GetScreenObject <CTS061_ScreenParameter>();

                CTS061_ScreenOutputObject outObj = new CTS061_ScreenOutputObject()
                {
                    CanOperate                  = true,
                    ContractCode                = session.ContractCode,
                    ContractCodeShort           = util.ConvertContractCode(session.ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT),
                    ExpectedInstallCompleteDate = expectedInstallCompleteDate,
                    InstallationStatusCode      = saleContractInfo[0].InstallationStatusCode,
                    InstallationStatusCodeName  = saleContractInfo[0].InstallationStatusCodeName,
                    LastOCC              = salehandler.GetLastOCC(session.ContractCode),
                    ImportantFlag        = saleContractInfo[0].PurchaserCustomerImportant.GetValueOrDefault(),
                    OperationOfficeName  = CommonUtil.TextCodeName(saleContractInfo[0].OperationOfficeCode, saleContractInfo[0].OperationOfficeName),
                    PurchaserAddressEN   = saleContractInfo[0].PurchaserAddressEN,
                    PurchaserAddressLC   = saleContractInfo[0].PurchaserAddressLC,
                    PurchaserCustCode    = util.ConvertCustCode(saleContractInfo[0].PurchaserCustCode, CommonUtil.CONVERT_TYPE.TO_SHORT),
                    PurchaserNameEN      = saleContractInfo[0].PurchaserNameEN,
                    PurchaserNameLC      = saleContractInfo[0].PurchaserNameLC,
                    RealCustomerCustCode = util.ConvertCustCode(saleContractInfo[0].RealCustomerCustCode, CommonUtil.CONVERT_TYPE.TO_SHORT),
                    SiteAddressEN        = saleContractInfo[0].SiteAddressEN,
                    SiteAddressLC        = saleContractInfo[0].SiteAddressLC,
                    SiteCode             = util.ConvertSiteCode(saleContractInfo[0].SiteCode, CommonUtil.CONVERT_TYPE.TO_SHORT),
                    SiteNameEN           = saleContractInfo[0].SiteNameEN,
                    SiteNameLC           = saleContractInfo[0].SiteNameLC
                };

                res.ResultData = outObj;
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
示例#6
0
        public ActionResult CMS180()
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                CMS180_ScreenParameter param = GetScreenObject <CMS180_ScreenParameter>();
                //for test
                //param.ContractCode = "N2700112";
                //param.InstallationSlipNo = "70000120120101";

                //Prepare for show section
                if (!CommonUtil.IsNullOrEmpty(param))
                {
                    ViewBag.ContractCode       = param.ContractCode;
                    ViewBag.InstallationSlipNo = param.InstallationSlipNo;
                }


                if (string.IsNullOrEmpty(param.ContractCode) == false)
                {
                    //Finding service type code
                    CommonUtil c = new CommonUtil();
                    string     longContractCode = c.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);

                    //Rental
                    IRentralContractHandler        handlerR         = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                    List <tbt_RentalContractBasic> dtRentalContract = handlerR.GetTbt_RentalContractBasic(longContractCode, null);
                    if (dtRentalContract.Count > 0)
                    {
                        param.ServiceTypeCode = ServiceType.C_SERVICE_TYPE_RENTAL;
                    }
                    else
                    {
                        // Sale
                        ISaleContractHandler handlerS       = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                        List <tbt_SaleBasic> dtSaleContract = handlerS.GetTbt_SaleBasic(longContractCode, null, true);
                        if (dtSaleContract.Count > 0)
                        {
                            param.ServiceTypeCode = ServiceType.C_SERVICE_TYPE_SALE;
                        }
                    }
                }
                ViewBag.ServiceTypeCode = param.ServiceTypeCode;
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            //ViewBag.AttachKey = GetCurrentKey();
            return(View());
        }
        /// <summary>
        /// Check data authority
        /// </summary>
        /// <param name="dtContractDocReceive"></param>
        /// <returns></returns>
        private bool CTS190_CheckDataAuthority(dtContractDocHeader dtContractDocReceive)
        {
            bool hasAuthority = false;

            // Old
            //List<OfficeDataDo> list = (from p in CommonUtil.dsTransData.dtOfficeData
            //                           where p.OfficeCode == dtContractDocReceive.ContractOfficeCode ||
            //                                 p.OfficeCode == dtContractDocReceive.OperationOfficeCode
            //                           select p).ToList<OfficeDataDo>();

            //hasAuthority = (list.Count > 0);

            IRentralContractHandler handlerRC   = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
            ISaleContractHandler    handlerSale = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
            // get RCB
            List <tbt_RentalContractBasic> dtRCB = handlerRC.GetTbt_RentalContractBasic(dtContractDocReceive.ContractCode, null);
            // get Sale basic
            List <tbt_SaleBasic> dtSB = handlerSale.GetTbt_SaleBasic(dtContractDocReceive.ContractCode, null, true);


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

            if (dtRCB.Count > 0)
            {
                list = (from p in CommonUtil.dsTransData.dtOfficeData
                        where p.OfficeCode == dtRCB[0].ContractOfficeCode ||
                        p.OfficeCode == dtRCB[0].OperationOfficeCode
                        select p).ToList <OfficeDataDo>();
            }
            else if (dtSB.Count > 0)
            {
                list = (from p in CommonUtil.dsTransData.dtOfficeData
                        where p.OfficeCode == dtSB[0].ContractOfficeCode ||
                        p.OfficeCode == dtSB[0].OperationOfficeCode
                        select p).ToList <OfficeDataDo>();
            }

            hasAuthority = (list.Count > 0);

            return(hasAuthority);
        }
示例#8
0
        ///<summary>
        ///Purpose   : Generate sale contract OCC
        ///Parameters: strContractCode = Q0000000038
        ///Expected  : Return OCC that is 9990.
        ///</summary>
        public string Case3()
        {
            ISaleContractHandler target = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
            string strContractCode      = "Q0000000038";
            string expected             = "9990";
            string actual;

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

            return(string.Format(RESULT_FORMAT, 3, expected, actual, CompareResult_String(expected, actual)));
        }
        /// <summary>
        /// Update data in case new/add sale and will insert new occurrence in case other installation type.
        /// </summary>
        /// <param name="doComplete"></param>
        public void CompleteInstallation(doCompleteInstallationData doComplete)
        {
            try
            {
                //Validation ServiceTypeCode and CompleteInstallationProcessFlag
                ApplicationErrorException.CheckMandatoryField <doCompleteInstallationData, doCompleteContractCompleteInstallation>(doComplete);

                //2. Check service type code and complete process flag
                if (doComplete.ServiceTypeCode == ServiceType.C_SERVICE_TYPE_RENTAL)
                {
                    if (doComplete.CompleteInstallationProcessFlag == FlagType.C_FLAG_ON)
                    {
                        IRentralContractHandler hand = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                        hand.CompleteInstallation(doComplete);
                    }
                    else if (doComplete.CompleteInstallationProcessFlag == FlagType.C_FLAG_OFF)
                    {
                        //do nothing
                    }
                }
                else if (doComplete.ServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE)
                {
                    ISaleContractHandler hand = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                    if (doComplete.CompleteInstallationProcessFlag == FlagType.C_FLAG_ON)
                    {
                        hand.CompleteInstallation(doComplete);
                    }
                    else if (doComplete.CompleteInstallationProcessFlag == FlagType.C_FLAG_OFF)
                    {
                        hand.CancelInstallation(doComplete);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#10
0
        ///<summary>
        ///Purpose   : Generate sale contract counter (last counter is maximum number)
        ///Parameters: strContractCode = Q0000000017
        ///Expected  : MSG3024: Cannot generate the contract counter. The number reach maximum.
        ///</summary>
        public string Case1()
        {
            ISaleContractHandler target = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
            string strContractCode      = "Q0000000017";
            string expected             = "MSG3024";
            string actual;

            try
            {
                target.GenerateContractCounter(strContractCode);
                actual = string.Empty;
            }
            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)));
        }
        public ActionResult CMS420()
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                CMS420_ScreenParameter param = GetScreenObject <CMS420_ScreenParameter>();
                CommonUtil             cm    = new CommonUtil();

                ViewBag._ContractCode = param.ContractCode;
                ViewBag._BillingOCC   = param.BillingOCC;

                string strContractCode = cm.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);

                ViewBag._CallerScreen = param.CallerScreenID;

                IViewBillingHandler   viewBillingHandler = ServiceContainer.GetService <IViewBillingHandler>() as IViewBillingHandler;
                IBillingHandler       billingHandler     = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
                ICommonHandler        comHand            = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                List <doMiscTypeCode> tmpCurrencies      = comHand.GetMiscTypeCodeList(new List <doMiscTypeCode>()
                {
                    new doMiscTypeCode()
                    {
                        FieldName = MiscType.C_CURRENCT,
                        ValueCode = "%"
                    }
                }).ToList();

                List <dtViewBillingOccList>            viewBillingOccListData        = viewBillingHandler.GetViewBillingOccList(strContractCode);
                List <dtViewBillingBasic>              viewBillingBasicData          = viewBillingHandler.GetViewBillingBasic(strContractCode, param.BillingOCC, null, null, null, null);
                List <doTbt_MonthlyBillingHistoryList> monthlyBillingHistoryListData = billingHandler.GetBillingHistoryList(strContractCode, param.BillingOCC, CurrencyUtil.C_CURRENCY_LOCAL, CurrencyUtil.C_CURRENCY_US);

                for (int i = 0; i < viewBillingOccListData.Count(); i++)
                {
                    viewBillingOccListData[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                }
                for (int i = 0; i < viewBillingBasicData.Count(); i++)
                {
                    viewBillingBasicData[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                }
                for (int i = 0; i < monthlyBillingHistoryListData.Count(); i++)
                {
                    monthlyBillingHistoryListData[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                }

                ICommonHandler handlerCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

                ViewBag.IsSpecialCareful                     = "0";
                ViewBag.txtVATUnchargedBillingTarget         = false;
                ViewBag.txtResultBasedMaintenanceBillingFlag = false;

                if (viewBillingOccListData.Count > 0)
                {
                    //Language mapping
                    CommonUtil.MappingObjectLanguage <dtViewBillingOccList>(viewBillingOccListData);

                    ViewBag.txtContractCode = cm.ConvertContractCode(viewBillingOccListData[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                }

                if (param.BillingOCC != null)
                {
                    if (viewBillingBasicData.Count > 0)
                    {
                        //Language mapping
                        CommonUtil.MappingObjectLanguage <dtViewBillingBasic>(viewBillingBasicData);

                        //Misc mapping
                        MiscTypeMappingList miscMapping = new MiscTypeMappingList();
                        miscMapping.AddMiscType(viewBillingBasicData.ToArray <dtViewBillingBasic>());
                        handlerCommon.MiscTypeMappingList(miscMapping);

                        if (viewBillingBasicData[0].CarefulFlag.HasValue)
                        {
                            ViewBag.IsSpecialCareful = viewBillingBasicData[0].CarefulFlag.Value == true ? "1" : "0";
                        }

                        ViewBag.IsPaymentMethod = viewBillingBasicData[0].PaymentMethod;

                        ViewBag.txtBillingCode               = string.Format("{0}-{1}", cm.ConvertContractCode(viewBillingBasicData[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT), viewBillingBasicData[0].BillingOCC);
                        ViewBag.txtBillingOffice             = CommonUtil.TextCodeName(viewBillingBasicData[0].BillingOfficeCode, viewBillingBasicData[0].OfficeName);
                        ViewBag.txtDebtTracingOffice         = CommonUtil.TextCodeName(viewBillingBasicData[0].DebtTracingOfficeCode, viewBillingBasicData[0].DebtTracingOfficeName);
                        ViewBag.txtBillingTargetCode         = cm.ConvertBillingTargetCode(viewBillingBasicData[0].BillingTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        ViewBag.txtPreviousBillingTargetCode = cm.ConvertBillingTargetCode(viewBillingBasicData[0].PreviousBillingTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        ViewBag.txtCustomerType              = viewBillingBasicData[0].CustTypeCodeName;
                        ViewBag.txtBillingClientNameEN       = viewBillingBasicData[0].FullNameEN;
                        ViewBag.txtBillingClientBranchNameEN = viewBillingBasicData[0].BranchNameEN;
                        ViewBag.txtBillingClientAddressEN    = viewBillingBasicData[0].AddressEN;
                        ViewBag.txtBillingClientNameLC       = viewBillingBasicData[0].FullNameLC;
                        ViewBag.txtBillingClientBranchNameLC = viewBillingBasicData[0].BranchNameLC;
                        ViewBag.txtBillingClientAddressLC    = viewBillingBasicData[0].AddressLC;
                        ViewBag.txtMonthlyBillingAmount      = viewBillingBasicData[0].TextTransferMonthlyBillingAmount;
                        //ViewBag.txtMonthlyBillingAmount = CommonUtil.TextNumeric(viewBillingBasicData[0].MonthlyBillingAmount);
                        ViewBag.txtPaymentMethod                   = viewBillingBasicData[0].PaymentMethodName;
                        ViewBag.txtBillingCycle                    = CommonUtil.TextNumeric(viewBillingBasicData[0].BillingCycle, 0);
                        ViewBag.txtCreditTerm                      = CommonUtil.TextNumeric(viewBillingBasicData[0].CreditTerm);
                        ViewBag.txtCalculationDailyFee             = viewBillingBasicData[0].CalDailyFeeStatusName;
                        ViewBag.txtLastBillingDate                 = CommonUtil.TextDate(viewBillingBasicData[0].LastBillingDate);
                        ViewBag.txtManagementCodeForSortDetails    = viewBillingBasicData[0].SortingType;
                        ViewBag.txtAdjustEndingDateOfBillingPeriod = CommonUtil.TextDate(viewBillingBasicData[0].AdjustEndDate);
                        ViewBag.txtBillingFlag                     = viewBillingBasicData[0].StopBillingFlagCodeName;
                        ViewBag.txtVATUnchargedBillingTarget       = viewBillingBasicData[0].VATUnchargedFlag.HasValue ? viewBillingBasicData[0].VATUnchargedFlag.Value : false;
                        ViewBag.txtBalanceOfDepositFee             = viewBillingBasicData[0].TextTransferBalanceDeposit;
                        //ViewBag.txtBalanceOfDepositFee = CommonUtil.TextNumeric(viewBillingBasicData[0].BalanceDeposit);
                        ViewBag.txtMonthlyFeeBeforeStop = viewBillingBasicData[0].TextTransferMonthlyFeeBeforeStop;
                        //ViewBag.txtMonthlyFeeBeforeStop = CommonUtil.TextNumeric(viewBillingBasicData[0].MonthlyFeeBeforeStop);
                        ViewBag.txtResultBasedMaintenanceBillingFlag = viewBillingBasicData[0].ResultBasedMaintenanceFlag.HasValue ? viewBillingBasicData[0].ResultBasedMaintenanceFlag.Value : false;
                        ViewBag.txtLastPaymentConditionChangingDate  = CommonUtil.TextDate(viewBillingBasicData[0].ChangeDate);
                        ViewBag.txtRegisteringDateOfLastChanging     = CommonUtil.TextDate(viewBillingBasicData[0].ChangeDate);
                        ViewBag.txtApproveNo         = viewBillingBasicData[0].ApproveNo;
                        ViewBag.txtDocumentReceiving = viewBillingBasicData[0].DocAuditResultName;

                        ViewBag.txtAdjustmentType      = viewBillingBasicData[0].AdjustType;
                        ViewBag.txtAdjustBillingAmount = viewBillingBasicData[0].TextTransferAdjustBillingPeriodAmount;
                        //ViewBag.txtAdjustBillingAmount = CommonUtil.TextNumeric(viewBillingBasicData[0].AdjustBillingPeriodAmount);

                        ViewBag.txtAdjustBillingPeriodStartDate = CommonUtil.TextDate(viewBillingBasicData[0].AdjustBillingPeriodStartDate);
                        ViewBag.txtAdjustBillingPeriodEndDate   = CommonUtil.TextDate(viewBillingBasicData[0].AdjustBillingPeriodEndDate);

                        ViewBag.txtIDNo = viewBillingBasicData[0].IDNo; //Add by Jutarat A. on 12122013
                    }

                    if (monthlyBillingHistoryListData != null)
                    {
                        if (monthlyBillingHistoryListData.Count > 0)
                        {
                            ViewBag.txtLastMonthlyBillingAmount = monthlyBillingHistoryListData[0].TextTransferMonthlyBillingAmount;
                            ViewBag.txtLastDate = CommonUtil.TextDate(monthlyBillingHistoryListData[0].BillingStartDate);
                            ViewBag.txtBillingAmountBeforeChanging1 = monthlyBillingHistoryListData.Count < 2 ? null : monthlyBillingHistoryListData[1].TextTransferMonthlyBillingAmount;
                            ViewBag.txtDateBeforeChanging1          = monthlyBillingHistoryListData.Count < 2 ? null : CommonUtil.TextDate(monthlyBillingHistoryListData[1].BillingStartDate);
                            ViewBag.txtBillingAmountBeforeChanging2 = monthlyBillingHistoryListData.Count < 3 ? null : monthlyBillingHistoryListData[2].TextTransferMonthlyBillingAmount;
                            ViewBag.txtDateBeforeChanging2          = monthlyBillingHistoryListData.Count < 3 ? null : CommonUtil.TextDate(monthlyBillingHistoryListData[2].BillingStartDate);
                            ViewBag.txtBillingAmountBeforeChanging3 = monthlyBillingHistoryListData.Count < 4 ? null : monthlyBillingHistoryListData[3].TextTransferMonthlyBillingAmount;
                            ViewBag.txtDateBeforeChanging3          = monthlyBillingHistoryListData.Count < 4 ? null : CommonUtil.TextDate(monthlyBillingHistoryListData[3].BillingStartDate);
                            ViewBag.txtBillingAmountBeforeChanging4 = monthlyBillingHistoryListData.Count < 5 ? null : monthlyBillingHistoryListData[4].TextTransferMonthlyBillingAmount;
                            ViewBag.txtDateBeforeChanging4          = monthlyBillingHistoryListData.Count < 5 ? null : CommonUtil.TextDate(monthlyBillingHistoryListData[4].BillingStartDate);
                            ViewBag.txtBillingAmountBeforeChanging5 = monthlyBillingHistoryListData.Count < 6 ? null : monthlyBillingHistoryListData[5].TextTransferMonthlyBillingAmount;
                            ViewBag.txtDateBeforeChanging5          = monthlyBillingHistoryListData.Count < 6 ? null : CommonUtil.TextDate(monthlyBillingHistoryListData[5].BillingStartDate);
                        }
                    }
                }

                //Finding service type code
                if (string.IsNullOrEmpty(strContractCode) == false)
                {
                    //Rental
                    IRentralContractHandler        handlerR         = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                    List <tbt_RentalContractBasic> dtRentalContract = handlerR.GetTbt_RentalContractBasic(strContractCode, null);
                    if (dtRentalContract.Count > 0)
                    {
                        param.ServiceTypeCode   = ServiceType.C_SERVICE_TYPE_RENTAL;
                        ViewBag.ServiceTypeCode = ServiceType.C_SERVICE_TYPE_RENTAL;
                        ViewBag.ProductTypeCode = dtRentalContract[0].ProductTypeCode;
                    }
                    else
                    {
                        // Sale
                        ISaleContractHandler handlerS       = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                        List <tbt_SaleBasic> dtSaleContract = handlerS.GetTbt_SaleBasic(strContractCode, null, true);
                        if (dtSaleContract.Count > 0)
                        {
                            param.ServiceTypeCode   = ServiceType.C_SERVICE_TYPE_SALE;
                            ViewBag.ServiceTypeCode = ServiceType.C_SERVICE_TYPE_SALE;
                            ViewBag.ProductTypeCode = dtSaleContract[0].ProductTypeCode;
                        }
                    }
                }

                return(View());
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
                return(Json(res));
            }
        }
        public ActionResult CMS190()
        {
            string strContractCode    = "";
            string strServiceTypeCode = "";

            try
            {
                CMS190_ScreenParameter param = GetScreenObject <CMS190_ScreenParameter>();
                strContractCode    = param.ContractCode;
                strServiceTypeCode = param.ServiceTypeCode;
            }
            catch
            {
            }

            /* ----- Set grobal variable for javascript side ---- */
            ViewBag._ServiceTypeCode = strServiceTypeCode;
            ViewBag._ContractCode    = strContractCode;

            CommonUtil c = new CommonUtil();


            List <dtTbt_RentalContractBasicForView> vw_dtRentalContract = new List <dtTbt_RentalContractBasicForView>();
            List <dtTbt_SaleBasicForView>           vw_dtSaleContract   = new List <dtTbt_SaleBasicForView>();
            List <dtTbt_RentalSecurityBasicForView> vw_dtRentalSecurity = new List <dtTbt_RentalSecurityBasicForView>();

            //List<dtContractTargetInfoByRelated> vw_dtMaintenanceContractInfo = new List<dtContractTargetInfoByRelated>();

            ViewBag.Currency = CommonValue.CURRENCY_UNIT;
            string dateFormat        = "dd-MMM-yyyy";
            string numberFormat      = "N0";
            string floatNumberFormat = "N2";

            // default ViewBag
            ViewBag.chkFire_monitoring      = false;
            ViewBag.chkCrime_prevention     = false;
            ViewBag.chkEmergency_report     = false;
            ViewBag.chkFacility_monitoring  = false;
            ViewBag.bOutOfRegulationDocFlag = false;



            try
            {
                strContractCode = c.ConvertContractCode(strContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);

                ICommonHandler handlerComm = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

                /******  get misc display value ******/
                List <string> lsFieldNames = new List <string>();
                lsFieldNames.Add(MiscType.C_RENTAL_CHANGE_TYPE);
                lsFieldNames.Add(MiscType.C_SALE_CHANGE_TYPE);
                lsFieldNames.Add(MiscType.C_SALE_TYPE);
                lsFieldNames.Add(MiscType.C_SALE_PROC_MANAGE_STATUS);

                List <doMiscTypeCode> MiscTypeList = handlerComm.GetMiscTypeCodeListByFieldName(lsFieldNames);
                /************************************/



                // Rental
                IRentralContractHandler handlerR = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                // Sale
                ISaleContractHandler handlerS = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                // Online
                IViewContractHandler handlerVC = ServiceContainer.GetService <IViewContractHandler>() as IViewContractHandler;

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

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

                string strInstallationStatusCode = "-";
                string strInstallationStatusName = "-";

                List <dtTbt_RentalContractBasicForView> dtRentalContract          = new List <dtTbt_RentalContractBasicForView>();
                List <dtTbt_SaleBasicForView>           dtSaleContract            = new List <dtTbt_SaleBasicForView>();
                List <dtTbt_RentalSecurityBasicForView> dtRentalSecurity          = new List <dtTbt_RentalSecurityBasicForView>();
                List <dtContractTargetInfoByRelated>    dtOnlineContractInfo      = new List <dtContractTargetInfoByRelated>();
                List <dtContractTargetInfoByRelated>    dtMaintenanceContractInfo = new List <dtContractTargetInfoByRelated>();
                ICommonHandler        comHand       = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                List <doMiscTypeCode> tmpCurrencies = comHand.GetMiscTypeCodeList(new List <doMiscTypeCode>()
                {
                    new doMiscTypeCode()
                    {
                        FieldName = MiscType.C_CURRENCT,
                        ValueCode = "%"
                    }
                }).ToList();

                if (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_RENTAL)
                {
                    dtRentalContract = handlerR.GetTbt_RentalContractBasicForView(strContractCode);
                    //Check Currency *For view
                    if (dtRentalContract[0].NormalDepositFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtRentalContract[0].NormalDepositFee = dtRentalContract[0].NormalDepositFeeUsd;
                    }
                    if (dtRentalContract[0].OrderDepositFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtRentalContract[0].OrderDepositFee = dtRentalContract[0].OrderDepositFeeUsd;
                    }
                    if (dtRentalContract[0].LastOrderContractFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtRentalContract[0].LastOrderContractFee = dtRentalContract[0].LastOrderContractFeeUsd;
                    }
                    if (dtRentalContract[0].ExemptedDepositFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtRentalContract[0].ExemptedDepositFee = dtRentalContract[0].ExemptedDepositFeeUsd;
                    }
                    //Add currency to List
                    for (int i = 0; i < dtRentalContract.Count(); i++)
                    {
                        dtRentalContract[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                    }
                }
                else if (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE)
                {
                    dtSaleContract = handlerS.GetTbt_SaleBasicForView(strContractCode, null, true);
                    if (dtSaleContract[0].NormalInstallFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].NormalInstallFee = dtSaleContract[0].NormalInstallFeeUsd;
                    }
                    if (dtSaleContract[0].OrderInstallFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].OrderInstallFee = dtSaleContract[0].OrderInstallFeeUsd;
                    }
                    if (dtSaleContract[0].InstallFeePaidBySECOMCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].InstallFeePaidBySECOM = dtSaleContract[0].InstallFeePaidBySECOMUsd;
                    }
                    if (dtSaleContract[0].InstallFeeRevenueBySECOMCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].InstallFeeRevenueBySECOM = dtSaleContract[0].InstallFeeRevenueBySECOMUsd;
                    }
                    if (dtSaleContract[0].OrderProductPriceCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].OrderProductPrice = dtSaleContract[0].OrderProductPriceUsd;
                    }
                    if (dtSaleContract[0].NormalProductPriceCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].NormalProductPrice = dtSaleContract[0].NormalProductPriceUsd;
                    }
                    if (dtSaleContract[0].BidGuaranteeAmount1CurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].BidGuaranteeAmount1 = dtSaleContract[0].BidGuaranteeAmount1Usd;
                    }
                    if (dtSaleContract[0].BidGuaranteeAmount2CurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].BidGuaranteeAmount2 = dtSaleContract[0].BidGuaranteeAmount2Usd;
                    }
                    if (dtSaleContract[0].NewBldMgmtCostCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                    {
                        dtSaleContract[0].NewBldMgmtCost = dtSaleContract[0].NewBldMgmtCostUsd;
                    }
                    //Add Currency to List
                    for (int i = 0; i < dtSaleContract.Count(); i++)
                    {
                        dtSaleContract[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                    }
                }


                if (dtRentalContract.Count > 0)
                {
                    // Get related data
                    dtRentalSecurity = handlerR.GetTbt_RentalSecurityBasicForView(strContractCode, dtRentalContract[0].LastOCC);

                    for (int i = 0; i < dtRentalSecurity.Count(); i++)
                    {
                        dtRentalSecurity[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                    }
                    //Must get InstallationInterfaceHandler.GetInstallationStatus (Next phase)
                    strInstallationStatusCode = iHandler.GetInstallationStatus(strContractCode);
                    //======== GET INSTALLATION STATUS NAME =============================
                    List <doMiscTypeCode> lst   = new List <doMiscTypeCode>();
                    List <doMiscTypeCode> miscs = new List <doMiscTypeCode>()
                    {
                        new doMiscTypeCode()
                        {
                            FieldName = MiscType.C_INSTALL_STATUS,
                            ValueCode = strInstallationStatusCode
                        }
                    };
                    lst = chandler.GetMiscTypeCodeList(miscs);
                    if (lst != null && lst.Count > 0)
                    {
                        strInstallationStatusName = lst[0].ValueDisplay;
                    }
                    //================================================================

                    // Select language
                    vw_dtRentalContract = CommonUtil.ConvertObjectbyLanguage <dtTbt_RentalContractBasicForView, dtTbt_RentalContractBasicForView>(dtRentalContract, "Quo_OfficeName", "Con_OfficeName", "Op_OfficeName");
                    vw_dtRentalSecurity = CommonUtil.ConvertObjectbyLanguage <dtTbt_RentalSecurityBasicForView, dtTbt_RentalSecurityBasicForView>(dtRentalSecurity,
                                                                                                                                                  "ProductName",
                                                                                                                                                  "DocumentName",
                                                                                                                                                  "DocumentNoName",
                                                                                                                                                  "SalesMan1_EmpFirstName",
                                                                                                                                                  "SalesMan1_EmpFirstName",
                                                                                                                                                  "SalesMan1_EmpLastName",
                                                                                                                                                  "SalesMan2_EmpFirstName",
                                                                                                                                                  "SalesMan2_EmpLastName",
                                                                                                                                                  "SalesSupport_EmpFirstName",
                                                                                                                                                  "SalesSupport_EmpLastName",
                                                                                                                                                  "Alm_EmpFirstName",
                                                                                                                                                  "Alm_EmpLastName",
                                                                                                                                                  "NegStaff1_EmpFirstName",
                                                                                                                                                  "NegStaff1_EmpLastName",
                                                                                                                                                  "NegStaff2_EmpFirstName",
                                                                                                                                                  "NegStaff2_EmpLastName",
                                                                                                                                                  "CompStaff_EmpFirstName",
                                                                                                                                                  "CompStaff_EmpLastName",
                                                                                                                                                  "Planner_EmpFirstName",
                                                                                                                                                  "Planner_EmpLastName",
                                                                                                                                                  "PlanChecker_EmpFirstName",
                                                                                                                                                  "PlanChecker_EmpLastName",
                                                                                                                                                  "PlanApprover_EmpFirstName",
                                                                                                                                                  "PlanApprover_EmpLastName"
                                                                                                                                                  );



                    /**** Convert code to short format *****/
                    foreach (var item in vw_dtRentalContract)
                    {
                        // contract code
                        item.ContractCode    = c.ConvertContractCode(item.ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        item.OldContractCode = c.ConvertContractCode(item.OldContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);

                        // customer code
                        item.ContractTargetCustCode = c.ConvertCustCode(item.ContractTargetCustCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        item.RealCustomerCustCode   = c.ConvertCustCode(item.RealCustomerCustCode, CommonUtil.CONVERT_TYPE.TO_SHORT);


                        //site code
                        item.SiteCode = c.ConvertSiteCode(item.SiteCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    }

                    // dtOnlineContractInfo
                    foreach (var item in dtOnlineContractInfo)
                    {
                        item.ContractCode = c.ConvertContractCode(item.ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    }
                }

                // Sale
                if (dtSaleContract.Count > 0)
                {
                    // Get related data
                    //dtOnlineContractInfo = handlerVC.GetContractTargetInfoByRelated(strContractCode, RelationType.C_RELATION_TYPE_SALE, dtSaleContract[0].OCC, ProductType.C_PROD_TYPE_SALE, ProductType.C_PROD_TYPE_AL, ProductType.C_PROD_TYPE_ONLINE, dtSaleContract[0].ProductTypeCode,
                    //                                                                 RelationType.C_RELATION_TYPE_MA, RelationType.C_RELATION_TYPE_SALE);
                    //dtMaintenanceContractInfo = handlerVC.GetContractTargetInfoByRelated(strContractCode, RelationType.C_RELATION_TYPE_MA, dtSaleContract[0].OCC, ProductType.C_PROD_TYPE_SALE, ProductType.C_PROD_TYPE_AL, ProductType.C_PROD_TYPE_ONLINE, dtSaleContract[0].ProductTypeCode,
                    //                                                                     RelationType.C_RELATION_TYPE_MA, RelationType.C_RELATION_TYPE_SALE);
                    dtOnlineContractInfo      = handlerVC.GetContractTargetInfoByRelated(strContractCode, RelationType.C_RELATION_TYPE_SALE, dtSaleContract[0].OCC, dtSaleContract[0].ProductTypeCode);
                    dtMaintenanceContractInfo = handlerVC.GetContractTargetInfoByRelated(strContractCode, RelationType.C_RELATION_TYPE_MA, dtSaleContract[0].OCC, dtSaleContract[0].ProductTypeCode);


                    //Must get InstallationInterfaceHandler.GetInstallationStatus (Next phase)
                    strInstallationStatusCode = iHandler.GetInstallationStatus(strContractCode);
                    //======== GET INSTALLATION STATUS NAME =============================
                    List <doMiscTypeCode> lst   = new List <doMiscTypeCode>();
                    List <doMiscTypeCode> miscs = new List <doMiscTypeCode>()
                    {
                        new doMiscTypeCode()
                        {
                            FieldName = MiscType.C_INSTALL_STATUS,
                            ValueCode = strInstallationStatusCode
                        }
                    };
                    lst = chandler.GetMiscTypeCodeList(miscs);
                    if (lst != null && lst.Count > 0)
                    {
                        strInstallationStatusName = lst[0].ValueDisplay;
                    }
                    //================================================================

                    // select language
                    vw_dtSaleContract = CommonUtil.ConvertObjectbyLanguage <dtTbt_SaleBasicForView, dtTbt_SaleBasicForView>(dtSaleContract,
                                                                                                                            "PurCust_CustName",
                                                                                                                            "PurCust_CustFullName",
                                                                                                                            "RealCust_CustName",
                                                                                                                            "RealCust_CustFullName",
                                                                                                                            "site_SiteName",
                                                                                                                            "QuoEmp_EmpFirstName",
                                                                                                                            "QuoEmp_EmpLastName",
                                                                                                                            "DocTemp_DocumentName",
                                                                                                                            "DocTemp_DocumentNoName",
                                                                                                                            "PlanEmp_EmpFirstName",
                                                                                                                            "PlanEmp_EmpLastName",
                                                                                                                            "planAppEmp_EmpFirstName",
                                                                                                                            "planAppEmp_EmpLastName",
                                                                                                                            "PlanChkrEmp_EmpFirstName",
                                                                                                                            "PlanChkrEmp_EmpLastName",
                                                                                                                            "ProductName",
                                                                                                                            "SalesMan1_EmpFirstName",
                                                                                                                            "SalesMan1_EmpLastName",
                                                                                                                            "Quo_OfficeName", "Con_OfficeName", "Sale_OfficeName", "Op_OfficeName");



                    /**** Convert code to short format *****/

                    // vw_dtSaleContract
                    foreach (var item in vw_dtSaleContract)
                    {
                        // contract code
                        item.ContractCode = c.ConvertContractCode(item.ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);

                        // customer code

                        item.CustCode_PurCust     = c.ConvertCustCode(item.CustCode_PurCust, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        item.CustCode_RealCust    = c.ConvertCustCode(item.CustCode_RealCust, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        item.RealCustomerCustCode = c.ConvertCustCode(item.RealCustomerCustCode, CommonUtil.CONVERT_TYPE.TO_SHORT);

                        // site code
                        item.SiteCode = c.ConvertSiteCode(item.SiteCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    }


                    // dtMaintenanceContractInfo
                    foreach (var item in dtMaintenanceContractInfo)
                    {
                        item.ContractCode = c.ConvertContractCode(item.ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    }

                    // Online contract
                    foreach (var item in dtOnlineContractInfo)
                    {
                        item.ContractCode = c.ConvertContractCode(item.ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    }
                }


                // Rental
                if (vw_dtRentalContract.Count > 0)
                {
                    /*  --- global variable for javascript side --*/

                    ViewBag._ContractCode       = vw_dtRentalContract[0].ContractCode;
                    ViewBag._OCC                = vw_dtRentalContract[0].LastOCC;
                    ViewBag._ContractTargetCode = vw_dtRentalContract[0].ContractTargetCustCode;
                    ViewBag._RealCustomerCode   = vw_dtRentalContract[0].RealCustomerCustCode;
                    ViewBag._SiteCode           = vw_dtRentalContract[0].SiteCode;
                    ViewBag._ServiceTypeCode    = vw_dtRentalContract[0].ServiceTypeCode;
                    ViewBag._OldContractCode    = vw_dtRentalContract[0].OldContractCode;

                    ViewBag.ProductTypeCode = vw_dtRentalContract[0].ProductTypeCode;
                    ViewBag.SiteCodeList    = vw_dtRentalContract[0].SiteCode;
                    ViewBag.ContractCode    = vw_dtRentalContract[0].ContractCode;

                    ViewBag.txtContractCode  = vw_dtRentalContract[0].ContractCode;
                    ViewBag.txtOccurrence    = vw_dtRentalContract[0].LastOCC;
                    ViewBag.txtUserCode      = vw_dtRentalContract[0].UserCode;
                    ViewBag.lnkCustomerCodeC = vw_dtRentalContract[0].ContractTargetCustCode;


                    ViewBag.lnkCustomerCodeR = vw_dtRentalContract[0].RealCustomerCustCode;
                    ViewBag.lnkSiteCode      = vw_dtRentalContract[0].SiteCode;

                    ViewBag.txtContractNameEng = vw_dtRentalContract[0].CustFullNameEN_Cust; // ContractTargetFullNameEN
                    ViewBag.txtContractAddrEng = vw_dtRentalContract[0].AddressFullEN_Cust;
                    ViewBag.txtSiteNameEng     = vw_dtRentalContract[0].SiteNameEN_Site;
                    ViewBag.txtSiteAddrEng     = vw_dtRentalContract[0].AddressFullEN_Site;

                    ViewBag.txtContractNameLocal = vw_dtRentalContract[0].CustFullNameLC_Cust; // ContractTargetFullNameLC
                    ViewBag.txtContractAddrLocal = vw_dtRentalContract[0].AddressFullLC_Cust;
                    ViewBag.txtSiteNameLocal     = vw_dtRentalContract[0].SiteNameLC_Site;
                    ViewBag.txtSiteAddrLocal     = vw_dtRentalContract[0].AddressFullLC_Site;

                    //Add by Jutarat A. on 26032014
                    ViewBag.txtCustomerContact = vw_dtRentalContract[0].ContactPersonName_Cust;
                    ViewBag.txtTelephoneNoCust = vw_dtRentalContract[0].PhoneNo_Cust;
                    ViewBag.txtFaxNo           = vw_dtRentalContract[0].FaxNo_Cust;

                    ViewBag.txtPersonInCharge  = vw_dtRentalContract[0].PersonInCharge_Site;
                    ViewBag.txtTelephoneNoSite = vw_dtRentalContract[0].PhoneNo_Site;
                    //End Add

                    //ViewBag.txtContactPoint = vw_dtRentalContract[0].ContactPoint;
                    ViewBag.txtContactPoint = CommonUtil.IsNullOrEmpty(vw_dtRentalContract[0].ContactPoint) == true ? "-" : vw_dtRentalContract[0].ContactPoint;



                    // section: contract detail info

                    //ViewBag.txtReceived_deposit_fee = vw_dtRentalContract[0].BilledDepositFee != null ? vw_dtRentalContract[0].BilledDepositFee.Value.ToString(floatNumberFormat) : "-";
                    // SA request to chagnge :31/Jan/2012  ref. UCCM1-8
                    //ViewBag.txtReceived_deposit_fee = vw_dtRentalContract[0].PaidDepositFee.HasValue ? vw_dtRentalContract[0].PaidDepositFee.Value.ToString(floatNumberFormat) : "-";
                    // SA request to chagnge#2 :15/Mar/2012 ref. UCCM1-75
                    ViewBag.txtReceived_deposit_fee = vw_dtRentalContract[0].TextTransferOrderDepositFee;
                    //ViewBag.txtReceived_deposit_fee = vw_dtRentalContract[0].OrderDepositFee.HasValue ? vw_dtRentalContract[0].OrderDepositFee.Value.ToString(floatNumberFormat) : "-";


                    ViewBag.txtOperation_office     = CommonUtil.TextCodeName(vw_dtRentalContract[0].OperationOfficeCode, vw_dtRentalContract[0].Op_OfficeName);
                    ViewBag.txtFirst_operation_date = vw_dtRentalContract[0].FirstSecurityStartDate != null ? vw_dtRentalContract[0].FirstSecurityStartDate.Value.ToString(dateFormat) : "-";
                    ViewBag.txtContract_fee         = vw_dtRentalContract[0].TextTransferLastOrderContractFee;
                    //ViewBag.txtContract_fee = vw_dtRentalContract[0].LastOrderContractFee != null ? vw_dtRentalContract[0].LastOrderContractFee.Value.ToString(floatNumberFormat) : "-";
                    ViewBag.txtContract_office     = CommonUtil.TextCodeName(vw_dtRentalContract[0].OfficeCode_Con, vw_dtRentalContract[0].Con_OfficeName);
                    ViewBag.txtLast_operation_date = vw_dtRentalContract[0].LastChangeImplementDate != null ? vw_dtRentalContract[0].LastChangeImplementDate.Value.ToString(dateFormat) : "-";
                    //ViewBag.txtProcessing_installation = "-";  Get value from InstallInterfaceHandler.GetInstallationSatatus (ContractCode)

                    if (strInstallationStatusCode != InstallationStatus.C_INSTALL_STATUS_NO_INSTALLATION)
                    {
                        ViewBag.txtProcessing_installation = CommonUtil.GetLabelFromResource(MessageUtil.MODULE_COMMON, "CMS190", "lblYes");
                    }
                    else
                    {
                        ViewBag.txtProcessing_installation = CommonUtil.GetLabelFromResource(MessageUtil.MODULE_COMMON, "CMS190", "lblNo");
                    }
                    //ViewBag.txtProcessing_installation = strInstallationStatusCode+" : "+strInstallationStatusName;

                    string strLastChangeTypeDisplayValue = handlerComm.GetMiscDisplayValue(MiscTypeList,
                                                                                           MiscType.C_RENTAL_CHANGE_TYPE,
                                                                                           vw_dtRentalContract[0].LastChangeType);
                    ViewBag.txtLast_change_type = CommonUtil.TextCodeName(vw_dtRentalContract[0].LastChangeType, strLastChangeTypeDisplayValue);
                    //ViewBag.txtProcessing_installation_status = "-"; Get value from InstallInterfaceHandler.GetInstallationSatatus (ContractCode)
                    ViewBag.txtProcessing_installation_status = strInstallationStatusCode + " : " + strInstallationStatusName;

                    ViewBag.lnkOld_contract_codeC = vw_dtRentalContract[0].OldContractCode;


                    //** // Change bOutOfRegulationDocFlag  --> to RentalContract[0].IrregurationDocUsageFlag (old: vw_dtRentalSecurity[0].DocAuditResult )
                    ViewBag.bOutOfRegulationDocFlag = vw_dtRentalContract[0].IrregurationDocUsageFlag.HasValue == true ? vw_dtRentalContract[0].IrregurationDocUsageFlag.Value : false;

                    ViewBag.txtRentalAttachImportanceFlag = vw_dtRentalContract[0].SpecialCareFlag;
                }

                if (vw_dtRentalSecurity.Count > 0)
                {
                    // section: contract detail info
                    ViewBag.txtProduct            = CommonUtil.TextCodeName(vw_dtRentalSecurity[0].ProductCode, vw_dtRentalSecurity[0].ProductName);
                    ViewBag.txtSecurity_type_code = vw_dtRentalSecurity[0].SecurityTypeCode;

                    // ContractStartDate - ContractEndDate
                    string strContractStartDate = vw_dtRentalSecurity[0].ContractStartDate != null ? vw_dtRentalSecurity[0].ContractStartDate.Value.ToString(dateFormat) : string.Empty;
                    //string strContractEndDate = vw_dtRentalSecurity[0].ContractEndDate != null ? vw_dtRentalSecurity[0].ContractEndDate.Value.ToString(dateFormat) : string.Empty;
                    string strContractEndDate = vw_dtRentalSecurity[0].CalContractEndDate != null ? vw_dtRentalSecurity[0].CalContractEndDate.Value.ToString(dateFormat) : string.Empty;

                    ViewBag.strContractStartDate = strContractStartDate;
                    ViewBag.strContractEndDate   = strContractEndDate;
                    if (CommonUtil.IsNullOrEmpty(strContractStartDate) == false && CommonUtil.IsNullOrEmpty(strContractEndDate) == false)
                    {
                        ViewBag.txtContract_duration = string.Format("{0} <span style='color:black;'> ~ </span> {1}", strContractStartDate, strContractEndDate);
                    }
                    else if (CommonUtil.IsNullOrEmpty(strContractStartDate) == false)
                    {
                        ViewBag.txtContract_duration = string.Format("{0} <span style='color:black;'> ~ </span> {1}", strContractStartDate, "-");
                    }
                    else if (CommonUtil.IsNullOrEmpty(strContractEndDate) == false)
                    {
                        ViewBag.txtContract_duration = string.Format("{0} <span style='color:black;'> ~ </span> {1}", "-", strContractEndDate);
                    }
                    else
                    {
                        ViewBag.txtContract_duration = string.Empty;
                    }



                    ViewBag.txtSalesman1 = CommonUtil.TextCodeName(vw_dtRentalSecurity[0].SalesmanEmpNo1, string.Format("{0} {1}", vw_dtRentalSecurity[0].SalesMan1_EmpFirstName, vw_dtRentalSecurity[0].SalesMan1_EmpLastName));;
                    ViewBag.txtContract_duration_month = vw_dtRentalSecurity[0].ContractDurationMonth != null ? vw_dtRentalSecurity[0].ContractDurationMonth.Value.ToString(numberFormat) : "-";
                    ViewBag.txtAuto_renew_months       = vw_dtRentalSecurity[0].AutoRenewMonth != null ? vw_dtRentalSecurity[0].AutoRenewMonth.Value.ToString(numberFormat) : "-";

                    // Change bOutOfRegulationDocFlag  --> to RentalContract[0].IrregurationDocUsageFlag
                    //ViewBag.bOutOfRegulationDocFlag = vw_dtRentalSecurity[0].DocAuditResult == "1" ? true : false  ;

                    ViewBag.chkFire_monitoring     = vw_dtRentalSecurity[0].FireMonitorFlag.HasValue == true ? vw_dtRentalSecurity[0].FireMonitorFlag.Value : false;
                    ViewBag.chkCrime_prevention    = vw_dtRentalSecurity[0].CrimePreventFlag.HasValue == true ? vw_dtRentalSecurity[0].CrimePreventFlag.Value : false;;
                    ViewBag.chkEmergency_report    = vw_dtRentalSecurity[0].EmergencyReportFlag.HasValue == true ? vw_dtRentalSecurity[0].EmergencyReportFlag.Value : false;;
                    ViewBag.chkFacility_monitoring = vw_dtRentalSecurity[0].FacilityMonitorFlag.HasValue == true ? vw_dtRentalSecurity[0].FacilityMonitorFlag.Value : false;;
                }

                // Sale
                if (vw_dtSaleContract.Count > 0)
                {
                    /*  --- global variable for javascript side --*/
                    ViewBag._ContractCode      = vw_dtSaleContract[0].ContractCode;
                    ViewBag._OCC               = vw_dtSaleContract[0].OCC;
                    ViewBag._PurchaserCustCode = vw_dtSaleContract[0].CustCode_PurCust;
                    ViewBag._RealCustomerCode  = vw_dtSaleContract[0].RealCustomerCustCode;
                    ViewBag._SiteCode          = vw_dtSaleContract[0].SiteCode;
                    ViewBag._ServiceTypeCode   = vw_dtSaleContract[0].ServiceTypeCode;
                    ViewBag.SiteCodeList       = vw_dtSaleContract[0].SiteCode;
                    ViewBag.ContractCode       = vw_dtSaleContract[0].ContractCode;
                    ViewBag.ProductTypeCode    = vw_dtSaleContract[0].ProductTypeCode;

                    ViewBag.txtContractCode = vw_dtSaleContract[0].ContractCode;
                    ViewBag.txtOccurrence   = vw_dtSaleContract[0].OCC;

                    ViewBag.lnkCustomerCodeC_Purchaser = vw_dtSaleContract[0].CustCode_PurCust;
                    ViewBag.lnkCustomerCodeR           = vw_dtSaleContract[0].RealCustomerCustCode;
                    ViewBag.lnkSiteCode = vw_dtSaleContract[0].SiteCode;

                    ViewBag.txtContractNameEng = vw_dtSaleContract[0].PurCust_CustFullNameEN;
                    ViewBag.txtContractAddrEng = vw_dtSaleContract[0].AddressFullEN_PurCust;
                    ViewBag.txtSiteNameEng     = vw_dtSaleContract[0].site_SiteNameEN;
                    ViewBag.txtSiteAddrEng     = vw_dtSaleContract[0].AddressFullEN_site;

                    ViewBag.txtContractNameLocal = vw_dtSaleContract[0].PurCust_CustFullNameLC;
                    ViewBag.txtContractAddrLocal = vw_dtSaleContract[0].AddressFullLC_PurCust;
                    ViewBag.txtSiteNameLocal     = vw_dtSaleContract[0].site_SiteNameLC;
                    ViewBag.txtSiteAddrLocal     = vw_dtSaleContract[0].AddressFullLC_site;

                    //Add by Jutarat A. on 26032014
                    ViewBag.txtCustomerContact = vw_dtSaleContract[0].ContactPersonName_PurCust;
                    ViewBag.txtTelephoneNoCust = vw_dtSaleContract[0].PhoneNo_PurCust;
                    ViewBag.txtFaxNo           = vw_dtSaleContract[0].FaxNo_PurCust;

                    ViewBag.txtPersonInCharge  = vw_dtSaleContract[0].PersonInCharge_site;
                    ViewBag.txtTelephoneNoSite = vw_dtSaleContract[0].PhoneNo_site;
                    //End Add

                    //ViewBag.txtContactPoint = vw_dtSaleContract[0].ContactPoint;
                    ViewBag.txtContactPoint = CommonUtil.IsNullOrEmpty(vw_dtSaleContract[0].ContactPoint) == true ? "-" : vw_dtSaleContract[0].ContactPoint;


                    // section : sale contract detail info
                    ViewBag.txtProduct = CommonUtil.TextCodeName(vw_dtSaleContract[0].ProductCode, vw_dtSaleContract[0].ProductName);

                    string strSaleTypeDisplayValue = handlerComm.GetMiscDisplayValue(MiscTypeList,
                                                                                     MiscType.C_SALE_TYPE,
                                                                                     vw_dtSaleContract[0].SalesType);
                    ViewBag.txtSale_type        = CommonUtil.TextCodeName(vw_dtSaleContract[0].SalesType, strSaleTypeDisplayValue);
                    ViewBag.txtProduct_Price    = vw_dtSaleContract[0].TextTransferOrderProductPrice;
                    ViewBag.txtInstallation_Fee = vw_dtSaleContract[0].TextTransferOrderInstallFee;
                    //ViewBag.txtBilling_amount = vw_dtSaleContract[0].TextTransferOrderSalePrice;
                    //ViewBag.txtBilling_amount = vw_dtSaleContract[0].OrderSalePrice != null ? vw_dtSaleContract[0].OrderSalePrice.Value.ToString(floatNumberFormat) : "-";

                    string SaleProdessManagementStatusDisplayValue = handlerComm.GetMiscDisplayValue(MiscTypeList,
                                                                                                     MiscType.C_SALE_PROC_MANAGE_STATUS,
                                                                                                     vw_dtSaleContract[0].SaleProcessManageStatus);
                    ViewBag.txtProcess_management_status = CommonUtil.TextCodeName(vw_dtSaleContract[0].SaleProcessManageStatus, SaleProdessManagementStatusDisplayValue);

                    ViewBag.txtLast_operation_date = vw_dtSaleContract[0].ChangeImplementDate != null ? vw_dtSaleContract[0].ChangeImplementDate.Value.ToString(dateFormat) : "-";

                    //ViewBag.txtProcessing_installation = "-";Get value from InstallInterfaceHandler.GetInstallationSatatus (ContractCode)
                    if (strInstallationStatusCode != InstallationStatus.C_INSTALL_STATUS_NO_INSTALLATION)
                    {
                        ViewBag.txtProcessing_installation = CommonUtil.GetLabelFromResource(MessageUtil.MODULE_COMMON, "CMS190", "lblYes");
                    }
                    else
                    {
                        ViewBag.txtProcessing_installation = CommonUtil.GetLabelFromResource(MessageUtil.MODULE_COMMON, "CMS190", "lblNo");
                    }
                    //ViewBag.txtProcessing_installation = strInstallationStatusCode + " : " + strInstallationStatusName;

                    string strChangeTypeDisplayValue = handlerComm.GetMiscDisplayValue(MiscTypeList,
                                                                                       MiscType.C_SALE_CHANGE_TYPE,
                                                                                       vw_dtSaleContract[0].ChangeType);
                    ViewBag.txtLast_change_type = CommonUtil.TextCodeName(vw_dtSaleContract[0].ChangeType, strChangeTypeDisplayValue);
                    //ViewBag.txtProcessing_installation_status = "-"; Get value from InstallInterfaceHandler.GetInstallationSatatus (ContractCode)
                    ViewBag.txtProcessing_installation_status = strInstallationStatusCode + " : " + strInstallationStatusName;

                    ViewBag.txtApprove_date = vw_dtSaleContract[0].FirstContractDate != null ? vw_dtSaleContract[0].FirstContractDate.Value.ToString(dateFormat) : "-";
                    ViewBag.txtSalesman1    = CommonUtil.TextCodeName(vw_dtSaleContract[0].SalesmanEmpNo1, string.Format("{0} {1}", vw_dtSaleContract[0].SalesMan1_EmpFirstName, vw_dtSaleContract[0].SalesMan1_EmpLastName));

                    ViewBag.txtInstrument_stock_out_date = vw_dtSaleContract[0].InstrumentStockOutDate != null ? vw_dtSaleContract[0].InstrumentStockOutDate.Value.ToString(dateFormat) : "-";
                    ViewBag.txtContract_office           = CommonUtil.TextCodeName(vw_dtSaleContract[0].ContractOfficeCode, vw_dtSaleContract[0].Con_OfficeName);

                    ViewBag.txtComplete_installation_date = vw_dtSaleContract[0].InstallCompleteDate != null ? vw_dtSaleContract[0].InstallCompleteDate.Value.ToString(dateFormat) : "-";
                    ViewBag.txtSales_office             = CommonUtil.TextCodeName(vw_dtSaleContract[0].SalesOfficeCode, vw_dtSaleContract[0].Sale_OfficeName);
                    ViewBag.txtCustomer_acceptance_date = vw_dtSaleContract[0].CustAcceptanceDate != null ? vw_dtSaleContract[0].CustAcceptanceDate.Value.ToString(dateFormat) : "-";
                    ViewBag.txtOperation_office         = CommonUtil.TextCodeName(vw_dtSaleContract[0].OperationOfficeCode, vw_dtSaleContract[0].Op_OfficeName);

                    ViewBag.txtSaleAttachImportanceFlag = vw_dtSaleContract[0].SpecialCareFlag;
                }

                if (dtOnlineContractInfo.Count > 0)
                {
                    ViewBag.lnkOnline_contract_code = dtOnlineContractInfo[0].ContractCode;
                    ViewBag._OnlineContractCode     = dtOnlineContractInfo[0].ContractCode;
                }

                if (dtMaintenanceContractInfo.Count > 0)
                {
                    ViewBag.lnkMaintenance_contract_code = dtMaintenanceContractInfo[0].ContractCode;
                    ViewBag._MaintenanceContractCode     = dtMaintenanceContractInfo[0].ContractCode;
                }

                return(View());
            }
            catch (Exception ex)
            {
                ObjectResultData res = new ObjectResultData();
                res.AddErrorMessage(ex);
                return(Json(res));
            }
        }
        //BLP014 - calculate difference of monthly fee

        /// <summary>
        /// Process BLP014 - Calculate difference monthly fee
        /// </summary>
        /// <param name="contractCode"></param>
        /// <param name="billingOCC"></param>
        /// <param name="changeDate"></param>
        /// <param name="monthlyBillingAmount"></param>
        /// <returns></returns>
        public AdjustOnNextPeriod CalculateDifferenceMonthlyFee(string contractCode, string billingOCC, DateTime changeDate, decimal monthlyBillingAmount, string callerObject)
        {
            var billingBasic = this.GetBillingBasic(contractCode, billingOCC, null, null, null, CurrencyUtil.C_CURRENCY_LOCAL, CurrencyUtil.C_CURRENCY_US);
            AdjustOnNextPeriod billingAdjustOnNextPeriod = null;

            if (billingBasic.Count == 0)
            {
                return(null);
            }

            var iChangeDate = Convert.ToInt32(changeDate.ToString("yyyyMMdd"));
            var iLastBillingDate_plus2day = Convert.ToInt32(billingBasic[0].LastBillingDate.Value.AddDays(2).ToString("yyyyMMdd"));
            var iLastBillingDate          = Convert.ToInt32(billingBasic[0].LastBillingDate.Value.ToString("yyyyMMdd"));


            // Case #1 : Change monthly fee
            if (monthlyBillingAmount > 0 || callerObject == ProcessID.C_PROCESS_ID_MANAGE_BILLING_BASIC_RESUME || callerObject == ProcessID.C_PROCESS_ID_MANAGE_BILLING_BASIC_STOP)
            {
                // Set start / end date
                DateTime dtBillingStartDate = changeDate;
                //DateTime dtBillingEndDate =  billingBasic[0].LastBillingDate.HasValue? billingBasic[0].LastBillingDate.Value.AddDays(1) : new DateTime(1,1,1);

                DateTime dtBillingEndDate = billingBasic[0].LastBillingDate.HasValue ? billingBasic[0].LastBillingDate.Value : new DateTime(1, 1, 1);


                if (iChangeDate <= iLastBillingDate)
                {
                    //decimal decNewBillingAmount = this.CalCulateBillingAmountPerHistory(dtBillingStartDate, dtBillingEndDate, monthlyBillingAmount, billingBasic[0].CalDailyFeeStatus);
                    //decimal decOldBillingAmount = this.CalculateBillingAmount(contractCode, billingOCC, billingBasic[0].CalDailyFeeStatus, dtBillingStartDate, dtBillingEndDate);
                    //decimal decDiffBillingAmount = 0;

                    //if (billingBasic[0].AdjustBillingPeriodAmount != null)
                    //{
                    //    decDiffBillingAmount = (decNewBillingAmount - decOldBillingAmount) + Convert.ToDecimal(billingBasic[0].AdjustBillingPeriodAmount);
                    //}
                    //else
                    //{
                    //    decDiffBillingAmount = (decNewBillingAmount - decOldBillingAmount);
                    //}

                    decimal decDiffMonthlyBillingAmount = monthlyBillingAmount - Convert.ToDecimal(billingBasic[0].MonthlyBillingAmount);
                    decimal decDiffBillingAmount        = this.CalCulateBillingAmountPerHistory(dtBillingStartDate, dtBillingEndDate, decDiffMonthlyBillingAmount, billingBasic[0].CalDailyFeeStatus) + Convert.ToDecimal(billingBasic[0].AdjustBillingPeriodAmount);
                    decDiffBillingAmount = RoundUp(decDiffBillingAmount, 2);                            //Add by Jutarat A. on 27012014

                    if (monthlyBillingAmount > Convert.ToDecimal(billingBasic[0].MonthlyBillingAmount)) // In case increase monthly fee, generate billing detail of "Difference of contract fee"
                    {
                        if (decDiffBillingAmount > 0)
                        {
                            DateTime?autoTransferDate = null;
                            if (billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_AUTO_TRANSFER || billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_CREDIT_CARD_TRANSFER)
                            {
                                autoTransferDate = this.GetNextAutoTransferDate(contractCode, billingOCC, billingBasic[0].PaymentMethod);

                                if (autoTransferDate.HasValue == false)
                                {
                                    billingBasic[0].PaymentMethod = PaymentMethod.C_PAYMENT_METHOD_BANK_TRANSFER;
                                }
                            }

                            // Billing type
                            var billingTypeDetail = this.GetBillingTypeDetailContinues(contractCode, billingOCC, BillingTypeGroup.C_BILLING_TYPE_GROUP_CONTINUES);

                            // CREATE Billing detail
                            if (billingTypeDetail.Count > 0)
                            {
                                string strBillingTypeCode = this.GetBillingTypeDifferenceFee(billingTypeDetail[0].BillingTypeCode);
                                // Prepare BillingDetail (data object)
                                tbt_BillingDetail billingDetail = new tbt_BillingDetail()
                                {
                                    ContractCode     = contractCode,
                                    BillingOCC       = billingOCC,
                                    IssueInvDate     = DateTime.Now,
                                    IssueInvFlag     = true,
                                    BillingTypeCode  = strBillingTypeCode,
                                    BillingAmount    = decDiffBillingAmount,
                                    BillingStartDate = dtBillingStartDate,
                                    BillingEndDate   = dtBillingEndDate,
                                    PaymentMethod    = billingBasic[0].PaymentMethod,
                                    PaymentStatus    = ((billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_AUTO_TRANSFER || billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_CREDIT_CARD_TRANSFER) ?
                                                        PaymentStatus.C_PAYMENT_STATUS_DETAIL_AUTO_CREDIT :
                                                        PaymentStatus.C_PAYMENT_STATUS_DETAIL_BANK_COLLECT),
                                    AutoTransferDate   = autoTransferDate,
                                    StartOperationDate = billingBasic[0].StartOperationDate
                                };

                                IRentralContractHandler rentalContralHandler             = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                                List <dtTbt_RentalContractBasicForView> dtRentalContract = rentalContralHandler.GetTbt_RentalContractBasicForView(contractCode);
                                if (dtRentalContract.Count > 0)
                                {
                                    billingDetail.ContractOCC = dtRentalContract[0].LastOCC;
                                }
                                else
                                {
                                    ISaleContractHandler saleHandler = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                                    List <tbt_SaleBasic> dtSaleBasic = saleHandler.GetTbt_SaleBasic(contractCode, null, true);
                                    if (dtSaleBasic != null && dtSaleBasic.Count > 0)
                                    {
                                        billingDetail.ContractOCC = dtSaleBasic[0].OCC;
                                    }
                                }
                                billingDetail.ForceIssueFlag = false;
                                // CREATE
                                this.ManageBillingDetail(billingDetail);

                                billingAdjustOnNextPeriod = new AdjustOnNextPeriod(); // set AdjustOnNextPeriod to empty
                            }
                        }
                        else if (decDiffBillingAmount < 0)
                        {
                            billingAdjustOnNextPeriod = new AdjustOnNextPeriod()
                            {
                                AdjustType = AdjustType.C_ADJUST_TYPE_REDUCT,
                                AdjustBillingPeriodAmount    = decDiffBillingAmount,
                                AdjustBillingPeriodStartDate = dtBillingStartDate,
                                AdjustBillingPeriodEndDate   = dtBillingEndDate
                            };
                        }
                        else // decDiffBillingAmount == billingBasic[0].AdjustBillingPeriodAmount
                        {
                            billingAdjustOnNextPeriod = new AdjustOnNextPeriod(); // set AdjustOnNextPeriod to empty
                        }
                    }
                    else if (monthlyBillingAmount < Convert.ToDecimal(billingBasic[0].MonthlyBillingAmount)) // In case decrease monthly fee, calculate "Adjust-on-next-period amount"
                    {
                        if (decDiffBillingAmount > 0)
                        {
                            billingAdjustOnNextPeriod = new AdjustOnNextPeriod()
                            {
                                AdjustType = AdjustType.C_ADJUST_TYPE_ADD,
                                AdjustBillingPeriodAmount    = decDiffBillingAmount,
                                AdjustBillingPeriodStartDate = dtBillingStartDate,
                                AdjustBillingPeriodEndDate   = dtBillingEndDate
                            };
                        }
                        else if (decDiffBillingAmount < 0)
                        {
                            billingAdjustOnNextPeriod = new AdjustOnNextPeriod()
                            {
                                AdjustType = AdjustType.C_ADJUST_TYPE_REDUCT,
                                AdjustBillingPeriodAmount    = decDiffBillingAmount,
                                AdjustBillingPeriodStartDate = dtBillingStartDate,
                                AdjustBillingPeriodEndDate   = dtBillingEndDate
                            };
                        }
                        else
                        {
                            billingAdjustOnNextPeriod = new AdjustOnNextPeriod();
                        }
                    }
                }
            }
            else // Case #2 : Monthly billing amount = 0, and it's not during stop , cancel contract   --- 4.
            {
                if (iChangeDate >= iLastBillingDate_plus2day)
                {
                    // Set start / end date
                    DateTime dtBillingStartDate = billingBasic[0].LastBillingDate.HasValue ? billingBasic[0].LastBillingDate.Value.AddDays(1) : new DateTime(1, 1, 1);
                    DateTime dtBillingEndDate   = changeDate.AddDays(-1); // tt

                    decimal decBillingAmount = this.CalculateBillingAmount(contractCode, billingOCC, billingBasic[0].CalDailyFeeStatus, dtBillingStartDate, dtBillingEndDate);

                    DateTime?autoTransferDate = null;
                    if (billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_AUTO_TRANSFER || billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_CREDIT_CARD_TRANSFER)
                    {
                        autoTransferDate = this.GetNextAutoTransferDate(contractCode, billingOCC, billingBasic[0].PaymentMethod);

                        if (autoTransferDate.HasValue == false)
                        {
                            billingBasic[0].PaymentMethod = PaymentMethod.C_PAYMENT_METHOD_BANK_TRANSFER;
                        }
                    }

                    // Billing type
                    var billingTypeDetail = this.GetBillingTypeDetailContinues(contractCode, billingOCC, BillingTypeGroup.C_BILLING_TYPE_GROUP_CONTINUES);

                    // CREATE Billing detail
                    tbt_BillingDetail billingDetail        = new tbt_BillingDetail();
                    tbt_BillingDetail billingDetail_manage = new tbt_BillingDetail();
                    if (billingTypeDetail.Count > 0)
                    {
                        string strBillingTypeCode = this.GetBillingTypeDifferenceFee(billingTypeDetail[0].BillingTypeCode);
                        // Prepare BillingDetail (data object)
                        billingDetail = new tbt_BillingDetail()
                        {
                            ContractCode     = contractCode,
                            BillingOCC       = billingOCC,
                            IssueInvDate     = DateTime.Now,
                            IssueInvFlag     = true,
                            BillingTypeCode  = strBillingTypeCode,
                            BillingAmount    = decBillingAmount,
                            BillingStartDate = dtBillingStartDate,
                            BillingEndDate   = dtBillingEndDate,
                            PaymentMethod    = billingBasic[0].PaymentMethod,
                            PaymentStatus    = ((billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_AUTO_TRANSFER || billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_CREDIT_CARD_TRANSFER) ?
                                                PaymentStatus.C_PAYMENT_STATUS_DETAIL_AUTO_CREDIT :
                                                PaymentStatus.C_PAYMENT_STATUS_DETAIL_BANK_COLLECT),
                            AutoTransferDate   = autoTransferDate,
                            StartOperationDate = billingBasic[0].StartOperationDate
                        };

                        IRentralContractHandler rentalContralHandler             = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                        List <dtTbt_RentalContractBasicForView> dtRentalContract = rentalContralHandler.GetTbt_RentalContractBasicForView(contractCode);
                        if (dtRentalContract.Count > 0)
                        {
                            billingDetail.ContractOCC = dtRentalContract[0].LastOCC;
                        }
                        else
                        {
                            ISaleContractHandler saleHandler = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                            List <tbt_SaleBasic> dtSaleBasic = saleHandler.GetTbt_SaleBasic(contractCode, null, true);
                            if (dtSaleBasic != null && dtSaleBasic.Count > 0)
                            {
                                billingDetail.ContractOCC = dtSaleBasic[0].OCC;
                            }
                        }
                        billingDetail.ForceIssueFlag = false;
                        // CREATE !
                        billingDetail_manage = this.ManageBillingDetail(billingDetail);
                    }

                    // CREATE Invoice
                    tbt_Invoice newInvoice = new tbt_Invoice()
                    {
                        AutoTransferDate     = autoTransferDate,
                        BillingTargetCode    = billingBasic[0].BillingTargetCode,
                        BillingTypeCode      = billingDetail.BillingTypeCode,
                        InvoicePaymentStatus = ((billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_AUTO_TRANSFER || billingBasic[0].PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_CREDIT_CARD_TRANSFER) ?
                                                PaymentStatus.C_PAYMENT_STATUS_INV_AUTO_CREDIT :
                                                PaymentStatus.C_PAYMENT_STATUS_INV_BANK_COLLECT),
                        IssueInvFlag  = true,
                        PaymentMethod = billingBasic[0].PaymentMethod,
                        IssueInvDate  = changeDate,
                    };

                    // CREATE !
                    List <tbt_BillingDetail> billingDetailList = new List <tbt_BillingDetail>();
                    billingDetailList.Add(billingDetail_manage);
                    this.ManageInvoiceByCommand(newInvoice, billingDetailList, false);
                }
                else if (iChangeDate <= iLastBillingDate)
                {
                    var invoice_betweenChangeDate = this.GetInvoiceOfChangeDate(contractCode, billingOCC, changeDate);

                    string[] statusList = { PaymentStatus.C_PAYMENT_STATUS_INV_BANK_COLLECT,
                                            PaymentStatus.C_PAYMENT_STATUS_INV_AUTO_CREDIT,
                                            PaymentStatus.C_PAYMENT_STATUS_FAIL_AUTO_INV_BANK,
                                            PaymentStatus.C_PAYMENT_STATUS_FAIL_NOTE_INV_BANK,
                                            PaymentStatus.C_PAYMENT_STATUS_FAIL_CHEQUE_INV_BANK,
                                            PaymentStatus.C_PAYMENT_STATUS_COUNTER_BAL };

                    if (invoice_betweenChangeDate.Count > 0 && statusList.Contains(invoice_betweenChangeDate[0].InvoicePaymentStatus))
                    {
                        // Cancel Invoice !!

                        var header = GetTbt_Invoice(invoice_betweenChangeDate[0].InvoiceNo, null);  // null mean Lastest InvoiceOCC
                        List <tbt_BillingDetail> detail = new List <tbt_BillingDetail>();
                        if (header.Count > 0)
                        {
                            detail = this.GetTbt_BillingDetailOfInvoice(header[0].InvoiceNo, header[0].InvoiceOCC);

                            this.UpdateInvoicePaymentStatus(header[0], detail, PaymentStatus.C_PAYMENT_STATUS_CANCEL);
                        }
                    }
                }
            }

            if (callerObject != ProcessID.C_PROCESS_ID_MANAGE_BILLING_BASIC_CANCEL)
            {
                // Create billing history
                tbt_MonthlyBillingHistory billingHistory = new tbt_MonthlyBillingHistory()
                {
                    ContractCode         = contractCode,
                    BillingOCC           = billingOCC,
                    MonthlyBillingAmount = monthlyBillingAmount,
                    BillingStartDate     = changeDate
                };
                this.CreateMonthlyBillingHistory(billingHistory);
            }


            return(billingAdjustOnNextPeriod);
        }
示例#14
0
        /// <summary>
        /// Check system suspending, user’s permission and user’s authority of screen
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult CTS055_Authority(CTS055_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                CommonUtil              util           = new CommonUtil();
                ISaleContractHandler    salehandler    = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                ICommonHandler          commonHandler  = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                IRentralContractHandler renderHandler  = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                IInstallationHandler    installhandler = ServiceContainer.GetService <IInstallationHandler>() as IInstallationHandler;

                //1.1 Check suspending
                if (commonHandler.IsSystemSuspending())
                {
                    res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0049, null, null);
                    return(Json(res));
                }

                //1.2 Check user's permission
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_CP12_CANCEL_UNIMPLEMENTED_CONTRACT, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0053, null, null);
                    return(Json(res));
                }

                //if (String.IsNullOrEmpty(param.ContractCode) && !String.IsNullOrEmpty(CommonUtil.dsTransData.dtCommonSearch.ContractCode))
                //{
                //    param.ContractCode = CommonUtil.dsTransData.dtCommonSearch.ContractCode;
                //}
                if (String.IsNullOrEmpty(param.ContractCode) && param.CommonSearch != null)
                {
                    if (CommonUtil.IsNullOrEmpty(param.CommonSearch.ContractCode) == false)
                    {
                        param.ContractCode = param.CommonSearch.ContractCode;
                    }
                }

                // Check parameter
                if ((param == null) ||
                    (String.IsNullOrEmpty(param.ContractCode)))
                {
                    // Not valid
                    //res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0011, new string[] { "Contract Code" }, null);
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0147, null, null);
                    return(Json(res));
                }

                //Comment by Jutarat A. on 08082012
                //var saleExists = salehandler.IsContractExist(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG));
                //if (saleExists.Count > 0 && saleExists[0].GetValueOrDefault())
                //{
                //    res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3278, null, null);
                //    return Json(res);
                //}

                // Check is contact exists
                var contractObj = renderHandler.GetTbt_RentalContractBasic(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG), null);

                if ((contractObj == null) ||
                    (contractObj.Count == 0))
                {
                    // Not found
                    //res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0011, new string[] { String.Format("Contract Code: {0}", param.ContractCode) }, null);
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0124, null, null);
                    return(Json(res));
                }

                //1.3 Check user's authority to view data

                /*
                 * if (CommonUtil.dsTransData.dtOfficeData.FindAll(delegate(OfficeDataDo s) { return s.OfficeCode == contractObj[0].ContractOfficeCode; }).Count == 0)
                 * {
                 *  res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0063, null, null);
                 *  return Json(res);
                 * }
                 *
                 * if (CommonUtil.dsTransData.dtOfficeData.FindAll(delegate(OfficeDataDo s) { return s.OfficeCode == contractObj[0].OperationOfficeCode; }).Count == 0)
                 * {
                 *  res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0063, null, null);
                 *  return Json(res);
                 * }
                 * */

                var existsContarctOffice = CommonUtil.dsTransData.dtOfficeData.Where(x => x.OfficeCode == contractObj[0].ContractOfficeCode);
                var existsOperateOffice  = CommonUtil.dsTransData.dtOfficeData.Where(x => x.OfficeCode == contractObj[0].OperationOfficeCode);

                if ((contractObj[0].ContractStatus == ContractStatus.C_CONTRACT_STATUS_BEF_START &&
                     (existsContarctOffice.Count() <= 0) && (existsOperateOffice.Count() <= 0)) ||
                    (contractObj[0].ContractStatus == ContractStatus.C_CONTRACT_STATUS_AFTER_START &&
                     (existsOperateOffice.Count() <= 0))
                    )
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0063, null, null);
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    return(Json(res));
                }

                var lastOCC = renderHandler.GetLastUnimplementedOCC(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG));
                if (String.IsNullOrEmpty(lastOCC) ||
                    contractObj[0].ProductTypeCode == ProductType.C_PROD_TYPE_MA ||
                    contractObj[0].ProductTypeCode == ProductType.C_PROD_TYPE_SG ||
                    contractObj[0].ProductTypeCode == ProductType.C_PROD_TYPE_BE
                    )
                {
                    res.AddErrorMessage("Contract", MessageUtil.MessageList.MSG3056, null, null);
                    return(Json(res));
                }


                if ((contractObj[0].LastChangeType == RentalChangeType.C_RENTAL_CHANGE_TYPE_CANCEL) ||
                    (contractObj[0].LastChangeType == RentalChangeType.C_RENTAL_CHANGE_TYPE_CANCEL_BEFORE_START) ||
                    (contractObj[0].LastChangeType == RentalChangeType.C_RENTAL_CHANGE_TYPE_END_CONTRACT) ||
                    (contractObj[0].LastChangeType == RentalChangeType.C_RENTAL_CHANGE_TYPE_TERMINATED))
                {
                    res.AddErrorMessage("Contract", MessageUtil.MessageList.MSG3001, null, null);
                    return(Json(res));
                }

                var secureObj = renderHandler.GetTbt_RentalSecurityBasic(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG), lastOCC);

                // Unimplement Addition
                string installStatus = installhandler.GetInstallationStatus(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG));
                if (((contractObj[0].ProductTypeCode == ProductType.C_PROD_TYPE_AL) ||
                     (contractObj[0].ProductTypeCode == ProductType.C_PROD_TYPE_RENTAL_SALE)) &&
                    ((installStatus != InstallationStatus.C_INSTALL_STATUS_NO_INSTALLATION) ||
                     (secureObj[0].InstallationCompleteFlag == FlagType.C_FLAG_ON)))
                {
                    res.AddErrorMessage("Contract", MessageUtil.MessageList.MSG3054, null, null);
                    return(Json(res));
                }

                string occCode = renderHandler.GetLastUnimplementedOCC(contractObj[0].ContractCode);

                if (String.IsNullOrEmpty(occCode))
                {
                    res.AddErrorMessage("Contract", MessageUtil.MessageList.MSG3055, null, null);
                    return(Json(res));
                }

                var dtRentalSecurityBasic = renderHandler.GetTbt_RentalSecurityBasicForView(contractObj[0].ContractCode, occCode.Trim())[0];

                if (StartType.C_START_TYPE_ALTER_START == contractObj[0].StartType &&
                    OCCType.C_FIRST_UNIMPLEMENTED_SECURITY_OCC == dtRentalSecurityBasic.OCC)
                {
                    res.AddErrorMessage("Contract", MessageUtil.MessageList.MSG3288, null, null);
                    return(Json(res));
                }

                if (contractObj[0].ContractStatus == SECOM_AJIS.Common.Util.ConstantValue.ContractStatus.C_CONTRACT_STATUS_BEF_START &&
                    dtRentalSecurityBasic.OCC == SECOM_AJIS.Common.Util.ConstantValue.OCCType.C_FIRST_UNIMPLEMENTED_SECURITY_OCC)
                {
                    res.AddErrorMessage("Contract", MessageUtil.MessageList.MSG3055, null, null);
                    return(Json(res));
                }

                //================ CHeck permission to view contract data ===================
                List <tbt_RentalContractBasic> listRentalContractBasic;
                listRentalContractBasic = renderHandler.GetTbt_RentalContractBasic(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG), null);

                //1.3 Check user's authority to view data
                if (CommonUtil.dsTransData.dtOfficeData.FindAll(delegate(OfficeDataDo s) { return(s.OfficeCode == contractObj[0].ContractOfficeCode); }).Count == 0)
                {
                    res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0063, null, null);
                    return(Json(res));
                }
                //===========================================================================

                CTS055_ScreenParameter session = InitialScreenSession_CTS055();
                session.ScreenParameter.ContractCode = util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                //return InitialScreenEnvironment("CTS054", session);
                return(InitialScreenEnvironment <CTS055_ScreenParameter>("CTS055", session, res));
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        /// <summary>
        /// Check permission for access screen CMS190
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult CMS190_Authority(CMS190_ScreenParameter param) // IN parameter: string strContractCode, string strServiceTypeCode
        {
            ObjectResultData res = new ObjectResultData();


            // Check permission
            if (!CheckUserPermission(ScreenID.C_SCREEN_ID_VIEW_CONTRACT_DIGEST, FunctionID.C_FUNC_ID_OPERATE))
            {
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                return(Json(res));
            }

            if (String.IsNullOrEmpty(param.strContractCode))
            {
                //param.strContractCode = CommonUtil.dsTransData.dtCommonSearch.ContractCode;
                if (param.CommonSearch != null)
                {
                    if (CommonUtil.IsNullOrEmpty(param.CommonSearch.ContractCode) == false)
                    {
                        param.strContractCode = param.CommonSearch.ContractCode;
                    }
                }
            }

            // Check parameter
            if (CommonUtil.IsNullOrEmpty(param.strContractCode) == true)
            {
                //res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0040);
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0147);
                return(Json(res));
            }

            // Check exist data
            try
            {
                CommonUtil c            = new CommonUtil();
                string     ContractCode = c.ConvertContractCode(param.strContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);


                // Rental
                IRentralContractHandler handlerR = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                // Sale
                ISaleContractHandler handlerS = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;

                //List<dtTbt_RentalContractBasicForView> dtRentalContract = new List<dtTbt_RentalContractBasicForView>();
                //List<dtTbt_SaleBasicForView> dtSaleContract = new List<dtTbt_SaleBasicForView>();

                List <tbt_RentalContractBasic> dtRentalContract = new List <tbt_RentalContractBasic>();
                List <tbt_SaleBasic>           dtSaleContract   = new List <tbt_SaleBasic>();

                // get data for check exist
                if (param.strServiceTypeCode == ServiceType.C_SERVICE_TYPE_RENTAL)
                {
                    dtRentalContract = handlerR.GetTbt_RentalContractBasic(ContractCode, null);
                }
                else if (param.strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE)
                {
                    dtSaleContract = handlerS.GetTbt_SaleBasic(ContractCode, null, true);
                }
                else
                {
                    dtRentalContract = handlerR.GetTbt_RentalContractBasic(ContractCode, null);


                    if (dtRentalContract.Count == 0)
                    {
                        dtSaleContract = handlerS.GetTbt_SaleBasic(ContractCode, null, true);

                        param.strServiceTypeCode = ServiceType.C_SERVICE_TYPE_SALE;
                    }
                    else
                    {
                        param.strServiceTypeCode = ServiceType.C_SERVICE_TYPE_RENTAL;
                    }
                }


                CommonUtil comUtil = new CommonUtil();

                if (dtRentalContract.Count > 0)
                {
                    param.strContractCode = comUtil.ConvertContractCode(dtRentalContract[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                }
                else if (dtSaleContract.Count > 0)
                {
                    param.strContractCode = comUtil.ConvertContractCode(dtSaleContract[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                }
                // parameter
                param.ContractCode    = param.strContractCode;
                param.ServiceTypeCode = param.strServiceTypeCode;


                if (dtRentalContract.Count == 0 && dtSaleContract.Count == 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001);
                    return(Json(res));
                }

                //CommonUtil.dsTransData.dtCommonSearch.ContractCode = param.strContractCode;
                //CommonUtil.dsTransData.dtCommonSearch.ProjectCode = null;
                param.CommonSearch = new ScreenParameter.CommonSearchDo()
                {
                    ContractCode = param.strContractCode
                };
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
                return(Json(res));
            }

            return(InitialScreenEnvironment <CMS190_ScreenParameter>("CMS190", param, res));
        }
示例#16
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));
        }
示例#17
0
        //BackClick perform in javascript

        #endregion

        #region Method

        /// <summary>
        /// Check system suspending, user’s permission and user’s authority of screen
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult CTS061_Authority(CTS061_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                CommonUtil           util          = new CommonUtil();
                ICommonHandler       commonHandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                ISaleContractHandler saleHandler   = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;

                //1.1 Check suspending
                if (commonHandler.IsSystemSuspending())
                {
                    res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0049, new string[] { String.Format("Contract Code: {0}", param.ContractCode) }, null);
                    return(Json(res));
                }

                //1.2 Check user's permission
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_CQ12_CHANGE_COMPLETE_INSTALLATION_DATE, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0053, null, null);
                    return(Json(res));
                }

                // Check parameter
                if ((param == null) ||
                    (String.IsNullOrEmpty(param.ContractCode)))
                {
                    //if (String.IsNullOrEmpty(CommonUtil.dsTransData.dtCommonSearch.ContractCode))
                    //{
                    //    // Not valid
                    //    //res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0011, new string[] { "Contract Code" }, null);
                    //    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0147, null, null);
                    //    return Json(res);
                    //}
                    //else
                    //{
                    //    param.ContractCode = CommonUtil.dsTransData.dtCommonSearch.ContractCode;
                    //}

                    if (param.CommonSearch != null)
                    {
                        if (CommonUtil.IsNullOrEmpty(param.CommonSearch.ContractCode) == false)
                        {
                            param.ContractCode = param.CommonSearch.ContractCode;
                        }
                    }
                    if (String.IsNullOrEmpty(param.ContractCode))
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0147, null, null);
                        return(Json(res));
                    }
                }

                // Check is contact exists
                var contractObj = saleHandler.GetTbt_SaleBasic(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG), null, true);
                if ((contractObj == null) ||
                    (contractObj.Count == 0))
                {
                    // Not found
                    //res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0011, new string[] { String.Format("Contract Code: {0}", param.ContractCode) }, null);
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0124, null, null);
                    return(Json(res));
                }

                string lastOCC        = saleHandler.GetLastOCC(contractObj[0].ContractCode);
                var    dsSaleContract = saleHandler.GetEntireContract(contractObj[0].ContractCode, lastOCC);

                if ((dsSaleContract != null) &&
                    (dsSaleContract.dtTbt_SaleBasic != null) &&
                    (dsSaleContract.dtTbt_SaleBasic.Count != 0))
                {
                    /*
                     * if (CommonUtil.dsTransData.dtOfficeData.FindAll(delegate(OfficeDataDo s) { return s.OfficeCode == dsSaleContract.dtTbt_SaleBasic[0].ContractOfficeCode; }).Count == 0)
                     * {
                     *  res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0063, null, null);
                     *  return Json(res);
                     * }
                     *
                     * if (CommonUtil.dsTransData.dtOfficeData.FindAll(delegate(OfficeDataDo s) { return s.OfficeCode == dsSaleContract.dtTbt_SaleBasic[0].OperationOfficeCode; }).Count == 0)
                     * {
                     *  res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0063, null, null);
                     *  return Json(res);
                     * }*/

                    var existsContarctOffice = CommonUtil.dsTransData.dtOfficeData.Where(x => x.OfficeCode == dsSaleContract.dtTbt_SaleBasic[0].ContractOfficeCode);
                    var existsOperateOffice  = CommonUtil.dsTransData.dtOfficeData.Where(x => x.OfficeCode == dsSaleContract.dtTbt_SaleBasic[0].OperationOfficeCode);

                    if ((existsContarctOffice.Count() <= 0) && (existsOperateOffice.Count() <= 0))
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0063, null, null);
                        res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                        return(Json(res));
                    }

                    if (dsSaleContract.dtTbt_SaleBasic[0].InstallationCompleteFlag == FlagType.C_FLAG_ON)
                    {
                        res.AddErrorMessage("Contract", MessageUtil.MessageList.MSG3058, null, null);
                        return(Json(res));
                    }
                }
                else
                {
                    res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0011, new string[] { String.Format("Contract Code: {0}", param.ContractCode) }, null);
                    return(Json(res));
                }

                param.ScreenParameter = new CTS061_Parameter()
                {
                    contractCode = util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG)
                };
                param.ContractCode = param.ScreenParameter.contractCode;

                return(InitialScreenEnvironment <CTS061_ScreenParameter>("CTS061", param, res));
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
示例#18
0
        /// <summary>
        /// Get Sale Basic information from tbt_SaleBasic
        /// </summary>
        /// <param name="strLongContractCode"></param>
        /// <param name="OCC"></param>
        /// <returns></returns>
        public dsSaleBasicForHistDigestView GetSaleBasicForHistoryDigestView(string strLongContractCode, string OCC)
        {
            try
            {
                dsSaleBasicForHistDigestView dsSaleBasicForHDView = new dsSaleBasicForHistDigestView();
                ISaleContractHandler         handSale             = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                ICommonHandler        comHand       = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                List <doMiscTypeCode> tmpCurrencies = comHand.GetMiscTypeCodeList(new List <doMiscTypeCode>()
                {
                    new doMiscTypeCode()
                    {
                        FieldName = MiscType.C_CURRENCT,
                        ValueCode = "%"
                    }
                }).ToList();

                List <dtTbt_SaleBasicForView> dtTbt_SaleBasicForView = handSale.GetTbt_SaleBasicForView(strLongContractCode, OCC, FlagType.C_FLAG_ON);
                //Check Currency
                if (dtTbt_SaleBasicForView[0].NormalInstallFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].NormalInstallFee = dtTbt_SaleBasicForView[0].NormalInstallFeeUsd;
                }
                if (dtTbt_SaleBasicForView[0].OrderInstallFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].OrderInstallFee = dtTbt_SaleBasicForView[0].OrderInstallFeeUsd;
                }
                if (dtTbt_SaleBasicForView[0].InstallFeePaidBySECOMCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].InstallFeePaidBySECOM = dtTbt_SaleBasicForView[0].InstallFeePaidBySECOMUsd;
                }
                if (dtTbt_SaleBasicForView[0].InstallFeeRevenueBySECOMCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].InstallFeeRevenueBySECOM = dtTbt_SaleBasicForView[0].InstallFeeRevenueBySECOMUsd;
                }
                if (dtTbt_SaleBasicForView[0].OrderProductPriceCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].OrderProductPrice = dtTbt_SaleBasicForView[0].OrderProductPriceUsd;
                }
                if (dtTbt_SaleBasicForView[0].NormalProductPriceCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].NormalProductPrice = dtTbt_SaleBasicForView[0].NormalProductPriceUsd;
                }
                if (dtTbt_SaleBasicForView[0].BidGuaranteeAmount1CurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].BidGuaranteeAmount1 = dtTbt_SaleBasicForView[0].BidGuaranteeAmount1Usd;
                }
                if (dtTbt_SaleBasicForView[0].BidGuaranteeAmount2CurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].BidGuaranteeAmount2 = dtTbt_SaleBasicForView[0].BidGuaranteeAmount2Usd;
                }
                if (dtTbt_SaleBasicForView[0].NewBldMgmtCostCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US)
                {
                    dtTbt_SaleBasicForView[0].NewBldMgmtCost = dtTbt_SaleBasicForView[0].NewBldMgmtCostUsd;
                }

                //Add Currency to List
                for (int i = 0; i < dtTbt_SaleBasicForView.Count(); i++)
                {
                    dtTbt_SaleBasicForView[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                }

                if (dtTbt_SaleBasicForView.Count <= 0)
                {
                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001);
                }
                dsSaleBasicForHDView.dtTbt_SaleBasicForView = dtTbt_SaleBasicForView;


                //3.3
                //List<doMiscTypeCode> dtGetMiscTypeCode = new List<doMiscTypeCode>();
                //for (int i = 0; i < 3; i++)
                //    dtGetMiscTypeCode.Add(new doMiscTypeCode());
                //dtGetMiscTypeCode[0].FieldName = MiscType.C_SALE_CHANGE_TYPE;
                //dtGetMiscTypeCode[0].ValueCode = "%";
                //dtGetMiscTypeCode[1].FieldName = MiscType.C_INCIDENT_TYPE;
                //dtGetMiscTypeCode[1].ValueCode = "%";
                //dtGetMiscTypeCode[2].FieldName = MiscType.C_AR_TYPE;
                //dtGetMiscTypeCode[2].ValueCode = "%";
                //ICommonHandler handCom = ServiceContainer.GetService<ICommonHandler>() as ICommonHandler;

                //List<doMiscTypeCode> MiscTypeResult = handCom.GetMiscTypeCodeList(dtGetMiscTypeCode);
                //dsSaleBasicForHDView.dtMiscellaneousType = MiscTypeResult;
                //3.4
                IViewContractHandler       handView = ServiceContainer.GetService <IViewContractHandler>() as IViewContractHandler;
                List <dtSaleHistoryDigest> dtSaleHistoryDigestList = handView.GetSaleHistoryDigestList(dsSaleBasicForHDView.dtTbt_SaleBasicForView[0].ContractCode, null, null);

                //Add Currency to List
                for (int i = 0; i < dtSaleHistoryDigestList.Count(); i++)
                {
                    dtSaleHistoryDigestList[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                }

                dsSaleBasicForHDView.dtSaleHistoryDigestList = dtSaleHistoryDigestList;

                return(dsSaleBasicForHDView);
            }
            catch (Exception) { throw; }
        }
示例#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;
            }
        }
示例#20
0
        public ActionResult CMS210()
        {
            CMS210_ScreenParameter cond = new CMS210_ScreenParameter();

            try
            {
                cond = GetScreenObject <CMS210_ScreenParameter>();
            }
            catch
            {
            }

            // Keep ServiceTypeCode
            ViewBag.ServiceTypeCode = cond.ServiceTypeCode;

            CommonUtil c = new CommonUtil();

            cond.ContractCode         = c.ConvertContractCode(cond.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);
            cond.MATargetContractCode = c.ConvertContractCode(cond.MATargetContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);
            cond.ContractTargetCode   = c.ConvertCustCode(cond.ContractTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG);

            try
            {
                IRentralContractHandler handlerR = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                ISaleContractHandler    handlerS = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;

                List <dtTbt_RentalContractBasicForView> dtRentalContract = new List <dtTbt_RentalContractBasicForView>();
                List <dtTbt_SaleBasicForView>           dtSaleContract   = new List <dtTbt_SaleBasicForView>();
                ICommonHandler        comHand       = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                List <doMiscTypeCode> tmpCurrencies = comHand.GetMiscTypeCodeList(new List <doMiscTypeCode>()
                {
                    new doMiscTypeCode()
                    {
                        FieldName = MiscType.C_CURRENCT,
                        ValueCode = "%"
                    }
                }).ToList();

                if (cond.ServiceTypeCode == ServiceType.C_SERVICE_TYPE_RENTAL)
                {
                    dtRentalContract = handlerR.GetTbt_RentalContractBasicForView(cond.MATargetContractCode);

                    //Add Currency to List
                    for (int i = 0; i < dtRentalContract.Count(); i++)
                    {
                        dtRentalContract[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                    }

                    foreach (var item in dtRentalContract)
                    {
                        item.ContractCode = c.ConvertContractCode(item.ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    }


                    if (dtRentalContract.Count > 0)
                    {
                        ViewBag.txtContractCode = dtRentalContract[0].ContractCode;
                        ViewBag.txtContract_target_name_English    = dtRentalContract[0].CustFullNameEN_Cust;
                        ViewBag.txtContract_target_address_English = dtRentalContract[0].AddressFullEN_Cust;
                        ViewBag.txtSite_name_English             = dtRentalContract[0].SiteNameEN_Site;
                        ViewBag.Site_address_English             = dtRentalContract[0].AddressFullEN_Site;
                        ViewBag.txtContract_target_name_Local    = dtRentalContract[0].CustFullNameLC_Cust;
                        ViewBag.txtContract_target_address_Local = dtRentalContract[0].AddressFullLC_Cust;
                        ViewBag.txtSite_name_Local    = dtRentalContract[0].SiteNameLC_Site;
                        ViewBag.txtSite_address_Local = dtRentalContract[0].AddressFullLC_Site;

                        ViewBag.txtRentalAttachImportanceFlag = dtRentalContract[0].SpecialCareFlag;
                    }
                }
                else if (cond.ServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE)
                {
                    dtSaleContract = handlerS.GetTbt_SaleBasicForView(cond.MATargetContractCode, null, null);

                    //Add Currency to List
                    for (int i = 0; i < dtSaleContract.Count(); i++)
                    {
                        dtSaleContract[i].Currencies = new List <doMiscTypeCode>(tmpCurrencies);
                    }

                    foreach (var item in dtSaleContract)
                    {
                        item.ContractCode = c.ConvertContractCode(item.ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    }

                    if (dtSaleContract.Count > 0)
                    {
                        ViewBag.txtContractCode = dtSaleContract[0].ContractCode;
                        ViewBag.txtContract_target_name_English    = dtSaleContract[0].PurCust_CustFullNameEN;
                        ViewBag.txtContract_target_address_English = dtSaleContract[0].AddressFullEN_PurCust;
                        ViewBag.txtSite_name_English             = dtSaleContract[0].site_SiteNameEN;
                        ViewBag.Site_address_English             = dtSaleContract[0].AddressFullEN_site;
                        ViewBag.txtContract_target_name_Local    = dtSaleContract[0].PurCust_CustFullNameLC;
                        ViewBag.txtContract_target_address_Local = dtSaleContract[0].AddressFullLC_PurCust;
                        ViewBag.txtSite_name_Local    = dtSaleContract[0].site_SiteNameLC;
                        ViewBag.txtSite_address_Local = dtSaleContract[0].AddressFullLC_site;

                        ViewBag.txtSaleAttachImportanceFlag = dtSaleContract[0].SpecialCareFlag;
                    }
                }



                return(View());
            }
            catch (Exception ex)
            {
                ObjectResultData res = new ObjectResultData();
                res.AddErrorMessage(ex);
                return(Json(res));
            }
        }
        /// <summary>
        /// Add billing type to selected list
        /// </summary>
        /// <param name="BillingTypeCode"></param>
        /// <returns></returns>
        public ActionResult BLS030_AddBillingType(string BillingTypeCode)
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            if (string.IsNullOrEmpty(BillingTypeCode))
            {
                res.AddErrorMessage(MessageUtil.MODULE_BILLING, MessageUtil.MessageList.MSG6090);
                return(Json(res));
            }

            try
            {
                BLS030_ScreenParameter sParam = GetScreenObject <BLS030_ScreenParameter>();

                IBillingMasterHandler  billingMasterHandler = ServiceContainer.GetService <IBillingMasterHandler>() as IBillingMasterHandler;
                List <tbm_BillingType> BillingTypeList      = billingMasterHandler.GetBillingTypeOneTimeListData(sParam.strBillingServiceTypeCode);
                CommonUtil.MappingObjectLanguage <tbm_BillingType>(BillingTypeList);

                List <tbm_BillingType> BillingTypeList2 = (from t in BillingTypeList
                                                           where t.BillingTypeCode == BillingTypeCode
                                                           select t).ToList <tbm_BillingType>();

                if (sParam.doBillingTypeList == null)
                {
                    sParam.doBillingTypeList = new List <tbt_BillingTypeDetail>();
                }

                List <tbt_BillingTypeDetail> BillingTypeDetailExistList = (from t in sParam.doBillingTypeList
                                                                           where t.BillingTypeCode == BillingTypeCode
                                                                           select t).ToList <tbt_BillingTypeDetail>();

                if (BillingTypeDetailExistList.Count > 0)
                {
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        "BLS030",
                                        MessageUtil.MODULE_BILLING,
                                        MessageUtil.MessageList.MSG6004,
                                        new string[] { BillingTypeList2[0].BillingTypeCodeName },
                                        null);
                    return(Json(res));
                }

                tbt_BillingTypeDetail BillingTypeDetail = new tbt_BillingTypeDetail();

                ISaleContractHandler handlerSaleContract = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                var saleContractBasic_list = handlerSaleContract.GetSaleContractBasicForView(sParam.ContractProjectCodeLong);

                foreach (tbm_BillingType BillType in BillingTypeList2)
                {
                    BillingTypeDetail.BillingTypeCode = BillType.BillingTypeCode;

                    if (BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRODUCT_PRICE ||
                        BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE ||
                        BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE_DOWN ||
                        BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE_PARTIAL)
                    {
                        // ==
                        if (saleContractBasic_list.Count > 0)
                        {
                            if (BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRODUCT_PRICE)
                            {
                                BillingTypeDetail.InvoiceDescriptionEN = BillingType.C_BILLING_TYPE_SALE_PRODUCT_PRICE_PREFIX_EN + " " + saleContractBasic_list[0].ProductNameEN;
                                BillingTypeDetail.InvoiceDescriptionLC = BillingType.C_BILLING_TYPE_SALE_PRODUCT_PRICE_PREFIX_LC + " " + saleContractBasic_list[0].ProductNameLC;

                                BillType.BillingTypeNameEN = BillingType.C_BILLING_TYPE_SALE_PRODUCT_PRICE_PREFIX_EN + " " + saleContractBasic_list[0].ProductNameEN;
                                BillType.BillingTypeNameLC = BillingType.C_BILLING_TYPE_SALE_PRODUCT_PRICE_PREFIX_LC + " " + saleContractBasic_list[0].ProductNameLC;
                            }

                            else if (BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE)
                            {
                                BillingTypeDetail.InvoiceDescriptionEN = BillingType.C_BILLING_TYPE_SALE_PRICE_PREFIX_EN + " " + saleContractBasic_list[0].ProductNameEN;
                                BillingTypeDetail.InvoiceDescriptionLC = BillingType.C_BILLING_TYPE_SALE_PRICE_PREFIX_LC + " " + saleContractBasic_list[0].ProductNameLC;

                                BillType.BillingTypeNameEN = BillingType.C_BILLING_TYPE_SALE_PRICE_PREFIX_EN + " " + saleContractBasic_list[0].ProductNameEN;
                                BillType.BillingTypeNameLC = BillingType.C_BILLING_TYPE_SALE_PRICE_PREFIX_LC + " " + saleContractBasic_list[0].ProductNameLC;
                            }
                            else if (BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE_DOWN)
                            {
                                BillingTypeDetail.InvoiceDescriptionEN = BillingType.C_BILLING_TYPE_SALE_PRICE_DOWN_SUBFIX_EN + " " + saleContractBasic_list[0].ProductNameEN;
                                BillingTypeDetail.InvoiceDescriptionLC = BillingType.C_BILLING_TYPE_SALE_PRICE_DOWN_SUBFIX_LC + " " + saleContractBasic_list[0].ProductNameLC;

                                BillType.BillingTypeNameEN = BillingType.C_BILLING_TYPE_SALE_PRICE_DOWN_SUBFIX_EN + " " + saleContractBasic_list[0].ProductNameEN;
                                BillType.BillingTypeNameLC = BillingType.C_BILLING_TYPE_SALE_PRICE_DOWN_SUBFIX_LC + " " + saleContractBasic_list[0].ProductNameLC;
                            }

                            else if (BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE_PARTIAL)
                            {
                                BillingTypeDetail.InvoiceDescriptionEN = BillingType.C_BILLING_TYPE_SALE_PRICE_PARTIAL_SUBFIX_EN + " " + saleContractBasic_list[0].ProductNameEN;
                                BillingTypeDetail.InvoiceDescriptionLC = BillingType.C_BILLING_TYPE_SALE_PRICE_PARTIAL_SUBFIX_LC + " " + saleContractBasic_list[0].ProductNameLC;

                                BillType.BillingTypeNameEN = BillingType.C_BILLING_TYPE_SALE_PRICE_PARTIAL_SUBFIX_EN + " " + saleContractBasic_list[0].ProductNameEN;
                                BillType.BillingTypeNameLC = BillingType.C_BILLING_TYPE_SALE_PRICE_PARTIAL_SUBFIX_LC + " " + saleContractBasic_list[0].ProductNameLC;
                            }
                        }
                    }
                    else
                    {
                        BillingTypeDetail.InvoiceDescriptionEN = BillType.BillingTypeNameEN;
                        BillingTypeDetail.InvoiceDescriptionLC = BillType.BillingTypeNameLC;
                    }


                    BillingTypeDetail.BillingTypeGroup = BillType.BillingTypeCode;
                    sParam.doBillingTypeList.Add(BillingTypeDetail);
                }


                res.ResultData = BillingTypeList2;

                return(Json(res));
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
                return(Json(res));
            }
        }
示例#22
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;
            }
        }
示例#23
0
        /// <summary>
        /// Check system suspending, user’s permission and user’s authority of screen
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult CTS054_Authority(CTS054_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            try
            {
                CommonUtil              util          = new CommonUtil();
                ISaleContractHandler    salehandler   = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;
                ICommonHandler          commonHandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                IRentralContractHandler renderHandler = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                //return InitialScreenEnvironment("CTS054", session);

                // Natthavat S., 2012/01/30
                // Check Authority Here

                //1.1 Check suspending
                if (commonHandler.IsSystemSuspending())
                {
                    res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0049, null, null);
                    return(Json(res));
                }

                //1.2 Check user's permission
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_CP12_CHANGE_EXPECTED_OPR_DATE, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0053, null, null);
                    return(Json(res));
                }

                //if (String.IsNullOrEmpty(param.ContractCode) && !String.IsNullOrEmpty(CommonUtil.dsTransData.dtCommonSearch.ContractCode))
                //{
                //    param.ContractCode = CommonUtil.dsTransData.dtCommonSearch.ContractCode;
                //}
                if (String.IsNullOrEmpty(param.ContractCode) && param.CommonSearch != null)
                {
                    if (CommonUtil.IsNullOrEmpty(param.CommonSearch.ContractCode) == false)
                    {
                        param.ContractCode = param.CommonSearch.ContractCode;
                    }
                }

                // Check parameter
                if ((param == null) ||
                    (String.IsNullOrEmpty(param.ContractCode)))
                {
                    // Not valid
                    //res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0011, new string[] { "Contract Code" }, null);
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0147, null, null);
                    return(Json(res));
                }

                //Comment by Jutarat A. on 08082012
                //var saleExists = salehandler.IsContractExist(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG));
                //if (saleExists.Count > 0 && saleExists[0].GetValueOrDefault())
                //{
                //    res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3278, null, null);
                //    return Json(res);
                //}

                // Check is contact exists
                var contractObj = renderHandler.GetTbt_RentalContractBasic(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG), null);
                if ((contractObj == null) ||
                    (contractObj.Count == 0))
                {
                    // Not found
                    //res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0011, new string[] { String.Format("Contract Code: {0}", param.ContractCode) }, null);
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0124, null, null);
                    return(Json(res));
                }

                //1.3 Check user's authority to view data

                /*
                 * if (CommonUtil.dsTransData.dtOfficeData.Where(x => x.OfficeCode == contractObj[0].ContractOfficeCode).Count() == 0)
                 * {
                 *  //if (CommonUtil.dsTransData.dtOfficeData.FindAll(delegate(OfficeDataDo s) { return s.OfficeCode == listRentalContractBasic[0].ContractOfficeCode; }).Count == 0)
                 *  res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0063, null, null);
                 *  return Json(res);
                 * }
                 *
                 * if (CommonUtil.dsTransData.dtOfficeData.Where(x => x.OfficeCode == contractObj[0].OperationOfficeCode).Count() == 0)
                 * {
                 *  //if (CommonUtil.dsTransData.dtOfficeData.FindAll(delegate(OfficeDataDo s) { return s.OfficeCode == listRentalContractBasic[0].OperationOfficeCode; }).Count == 0)
                 *  res.AddErrorMessage("Common", MessageUtil.MessageList.MSG0063, null, null);
                 *  return Json(res);
                 * }*/

                var existsContarctOffice = CommonUtil.dsTransData.dtOfficeData.Where(x => x.OfficeCode == contractObj[0].ContractOfficeCode);
                var existsOperateOffice  = CommonUtil.dsTransData.dtOfficeData.Where(x => x.OfficeCode == contractObj[0].OperationOfficeCode);

                if ((contractObj[0].ContractStatus == ContractStatus.C_CONTRACT_STATUS_BEF_START &&
                     (existsContarctOffice.Count() <= 0) && (existsOperateOffice.Count() <= 0)) ||
                    (contractObj[0].ContractStatus == ContractStatus.C_CONTRACT_STATUS_AFTER_START &&
                     (existsOperateOffice.Count() <= 0))
                    )
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0063, null, null);
                    //res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    return(Json(res));
                }

                string lastOCC = "";
                lastOCC = renderHandler.GetLastUnimplementedOCC(util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG));
                if (String.IsNullOrEmpty(lastOCC))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3053, null, null);
                    //res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    return(Json(res));
                }

                CTS054_ScreenParameter session = InitialScreenSession_CTS054();
                session.ScreenParameter.ContractCode = util.ConvertContractCode(param.ContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                //session.ScreenParameter.ContractCode = param.ContractCode;
                session.ContractCode = session.ScreenParameter.ContractCode;
                session.CommonSearch = param.CommonSearch;

                return(InitialScreenEnvironment <CTS054_ScreenParameter>("CTS054", session, res));
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        public ActionResult CMS200()
        {
            string strContractCode    = "";
            string strServiceTypeCode = "";

            try
            {
                CMS200_ScreenParameter param = GetScreenObject <CMS200_ScreenParameter>();
                strContractCode    = param.ContractCode;
                strServiceTypeCode = param.ServiceTypeCode;
            }
            catch
            {
            }

            // Keep service type code
            ViewBag.ServiceTypeCode = strServiceTypeCode;

            // Keep contract code  (short)
            ViewBag._ContractCode       = strContractCode;
            ViewBag._OCC                = string.Empty;
            ViewBag._ContractTargetCode = string.Empty;
            ViewBag._RealCustomerCode   = string.Empty;
            ViewBag._PurchaserCustCode  = string.Empty;
            ViewBag._SiteCode           = string.Empty;



            CommonUtil c = new CommonUtil();

            strContractCode = c.ConvertContractCode(strContractCode, CommonUtil.CONVERT_TYPE.TO_LONG);

            try
            {
                IRentralContractHandler handlerRC = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
                ISaleContractHandler    handlerSC = ServiceContainer.GetService <ISaleContractHandler>() as ISaleContractHandler;

                if (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_RENTAL)
                {
                    List <dtTbt_RentalContractBasicForView> listRC = handlerRC.GetTbt_RentalContractBasicForView(strContractCode);

                    if (listRC.Count > 0)
                    {
                        // convert code to short format
                        listRC[0].ContractCode           = c.ConvertContractCode(listRC[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        listRC[0].ContractTargetCustCode = c.ConvertCustCode(listRC[0].ContractTargetCustCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        listRC[0].RealCustomerCustCode   = c.ConvertCustCode(listRC[0].RealCustomerCustCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        listRC[0].SiteCode = c.ConvertSiteCode(listRC[0].SiteCode, CommonUtil.CONVERT_TYPE.TO_SHORT);


                        // gorbal javascript variable
                        ViewBag._OCC = listRC[0].LastOCC;
                        ViewBag._ContractTargetCode = listRC[0].ContractTargetCustCode;
                        ViewBag._RealCustomerCode   = listRC[0].RealCustomerCustCode;
                        ViewBag._SiteCode           = listRC[0].SiteCode;



                        ViewBag.txtContractCode      = listRC[0].ContractCode;
                        ViewBag.txtUserCode          = listRC[0].UserCode;
                        ViewBag.lnkCustomerCodeC     = listRC[0].ContractTargetCustCode;
                        ViewBag.lnkCustomerCodeR     = listRC[0].RealCustomerCustCode;
                        ViewBag.lnkSiteCode          = listRC[0].SiteCode;
                        ViewBag.txtContractNameEng   = listRC[0].CustFullNameEN_Cust;
                        ViewBag.txtContractAddrEng   = listRC[0].AddressFullEN_Cust;
                        ViewBag.txtSiteNameEng       = listRC[0].SiteNameEN_Site;
                        ViewBag.txtSiteAddrEng       = listRC[0].AddressFullEN_Site;
                        ViewBag.txtContractNameLocal = listRC[0].CustFullNameLC_Cust;
                        ViewBag.txtContractAddrLocal = listRC[0].AddressFullLC_Cust;
                        ViewBag.txtSiteNameLocal     = listRC[0].SiteNameLC_Site;
                        ViewBag.txtSiteAddrLocal     = listRC[0].AddressFullLC_Site;
                        //ViewBag.txtContactPoint  = listRC[0].ContactPoint  ;
                        ViewBag.txtContactPoint = CommonUtil.IsNullOrEmpty(listRC[0].ContactPoint) == true ? "-" : listRC[0].ContactPoint;

                        ViewBag.txtRentalAttachImportanceFlag = listRC[0].SpecialCareFlag;

                        ViewBag.ProductTypeCode = listRC[0].ProductTypeCode;
                    }
                }
                else if (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE)
                {
                    List <dtTbt_SaleBasicForView> listSC = handlerSC.GetTbt_SaleBasicForView(strContractCode, null, true);

                    if (listSC.Count > 0) // SCB : Sale Contract Basic
                    {
                        // convert code to short format
                        listSC[0].ContractCode      = c.ConvertContractCode(listSC[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        listSC[0].CustCode_PurCust  = c.ConvertCustCode(listSC[0].CustCode_PurCust, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        listSC[0].CustCode_RealCust = c.ConvertCustCode(listSC[0].CustCode_RealCust, CommonUtil.CONVERT_TYPE.TO_SHORT);
                        listSC[0].SiteCode          = c.ConvertSiteCode(listSC[0].SiteCode, CommonUtil.CONVERT_TYPE.TO_SHORT);

                        // gorbal javascript variable
                        ViewBag._OCC = listSC[0].OCC;
                        ViewBag._PurchaserCustCode = listSC[0].CustCode_PurCust;
                        ViewBag._RealCustomerCode  = listSC[0].CustCode_RealCust;
                        ViewBag._SiteCode          = listSC[0].SiteCode;



                        ViewBag.txtSCBContractCode       = listSC[0].ContractCode;
                        ViewBag.lnkSCBPurchaserC         = listSC[0].CustCode_PurCust;
                        ViewBag.lnkSCBCustomerCodeR      = listSC[0].CustCode_RealCust;
                        ViewBag.lnkSCBSiteCode           = listSC[0].SiteCode;
                        ViewBag.txtSCBPurchaserNameEng   = listSC[0].PurCust_CustFullNameEN;
                        ViewBag.txtSCBPurchaserAddrEng   = listSC[0].AddressFullEN_PurCust;
                        ViewBag.txtSCBSiteNameEng        = listSC[0].site_SiteNameEN;
                        ViewBag.txtSCBSiteAddrEng        = listSC[0].AddressFullEN_site;
                        ViewBag.txtSCBPurchaserNameLocal = listSC[0].PurCust_CustFullNameLC;
                        ViewBag.txtSCBPurchaserAddrLocal = listSC[0].AddressFullLC_PurCust;
                        ViewBag.txtSCBSiteNameLocal      = listSC[0].site_SiteNameLC;
                        ViewBag.txtSCBSiteAddrLocal      = listSC[0].AddressFullLC_site;
                        //ViewBag.txtSCBContactPoint  = listSC[0].ContactPoint  ;
                        ViewBag.txtSCBContactPoint = CommonUtil.IsNullOrEmpty(listSC[0].ContactPoint) == true ? "-" : listSC[0].ContactPoint;

                        ViewBag.txtSaleAttachImportanceFlag = listSC[0].SpecialCareFlag;

                        ViewBag.ProductTypeCode = listSC[0].ProductTypeCode;
                    }
                }



                return(View());
            }
            catch (Exception ex)
            {
                ObjectResultData res = new ObjectResultData();
                res.AddErrorMessage(ex);
                return(Json(res));
            }
        }