protected static FR_L3TX_GTOFTO_1006 Execute(DbConnection Connection, DbTransaction Transaction, P_L3TX_GTOFTO_1006 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3TX_GTOFTO_1006();
            returnValue.Result = new L3TX_GTOFTO_1006();
            var item = new ORM_ACC_TAX_TaxOffice();
            returnValue.Result.TaxOffice = new L3TX_GTOFT_0914();
            var result = item.Load(Connection, Transaction, Parameter.ACC_TAX_TaxOfficeID);

            ORM_CMN_BPT_BusinessParticipant bparticipant = new ORM_CMN_BPT_BusinessParticipant();
            bparticipant.Load(Connection, Transaction, item.CMN_BPT_BusinessParticipant_RefID);
            returnValue.Result.TaxOffice.DisplayName = bparticipant.DisplayName;



            ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
            companyInfo.Load(Connection, Transaction, bparticipant.IfCompany_CMN_COM_CompanyInfo_RefID);

            ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
            ucd.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);

            returnValue.Result.TaxOffice.VATIdentificationNumber = companyInfo.VATIdentificationNumber;
            returnValue.Result.TaxOffice.ACC_TAX_TaxOfficeID     = item.ACC_TAX_TaxOfficeID;
            returnValue.Result.TaxOffice.Country_639_1_ISOCode   = ucd.Country_639_1_ISOCode;

            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5HI_GHIFHIID_1329 Execute(DbConnection Connection, DbTransaction Transaction, P_L5HI_GHIFHIID_1329 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5HI_GHIFHIID_1329();

            //Put your code here
            returnValue.Result = new L5HI_GHIFHIID_1329();

            ORM_HEC_HIS_HealthInsurance_Company.Query healthInsurenceQuery = new ORM_HEC_HIS_HealthInsurance_Company.Query();
            healthInsurenceQuery.HEC_HealthInsurance_CompanyID = Parameter.HEC_HealthInsurance_CompanyID;
            healthInsurenceQuery.Tenant_RefID = securityTicket.TenantID;
            healthInsurenceQuery.IsDeleted    = false;



            List <ORM_HEC_HIS_HealthInsurance_Company> healthInsurances = ORM_HEC_HIS_HealthInsurance_Company.Query.Search(Connection, Transaction, healthInsurenceQuery);
            if (healthInsurances.Count == 0)
            {
                return(null);
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant bpart = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
                {
                    CMN_BPT_BusinessParticipantID = healthInsurances[0].CMN_BPT_BusinessParticipant_RefID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).FirstOrDefault();


                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.Load(Connection, Transaction, bpart.IfCompany_CMN_COM_CompanyInfo_RefID);

                ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
                ucd.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);


                L5HI_GHIFT_1138 healthInsurance = new L5HI_GHIFT_1138();
                healthInsurance.HEC_HealthInsurance_CompanyID = healthInsurances[0].HEC_HealthInsurance_CompanyID;
                healthInsurance.DisplayName = bpart.DisplayName;
                healthInsurance.HealthInsurance_IKNumber = healthInsurances[0].HealthInsurance_IKNumber;
                healthInsurance.Country_ISO = ucd.Country_639_1_ISOCode;
                healthInsurance.Town        = ucd.Town;

                returnValue.Result.HealthInsurance = healthInsurance;
            }

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5HI_GHIFT_1138_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5HI_GHIFT_1138_Array();

            List <L5HI_GHIFT_1138> healthInsuranceResult = new List <L5HI_GHIFT_1138>();

            ORM_HEC_HIS_HealthInsurance_Company.Query healthInsurenceQuery = new ORM_HEC_HIS_HealthInsurance_Company.Query();
            healthInsurenceQuery.Tenant_RefID = securityTicket.TenantID;
            healthInsurenceQuery.IsDeleted    = false;
            List <ORM_HEC_HIS_HealthInsurance_Company> healthInsurances = ORM_HEC_HIS_HealthInsurance_Company.Query.Search(Connection, Transaction, healthInsurenceQuery);
            foreach (var healthInsurance in healthInsurances)
            {
                if (healthInsurance.CMN_BPT_BusinessParticipant_RefID == Guid.Empty)
                {
                    continue;
                }

                L5HI_GHIFT_1138 item = new L5HI_GHIFT_1138();
                ORM_CMN_BPT_BusinessParticipant bpart = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
                {
                    CMN_BPT_BusinessParticipantID = healthInsurance.CMN_BPT_BusinessParticipant_RefID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).FirstOrDefault();


                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.Load(Connection, Transaction, bpart.IfCompany_CMN_COM_CompanyInfo_RefID);

                ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
                ucd.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);

                item.HEC_HealthInsurance_CompanyID = healthInsurance.HEC_HealthInsurance_CompanyID;
                item.DisplayName = bpart.DisplayName;
                item.HealthInsurance_IKNumber = healthInsurance.HealthInsurance_IKNumber;
                item.Country_ISO = ucd.Country_639_1_ISOCode;
                item.Town        = ucd.Town;

                healthInsuranceResult.Add(item);
            }

            returnValue.Result = healthInsuranceResult.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Example #4
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3SO_SA_f_SHI_1535 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            bool saveResult          = false;
            var  Universal_C_Details = new ORM_CMN_UniversalContactDetail();
            Universal_C_Details.CMN_UniversalContactDetailID = Guid.NewGuid();
            Universal_C_Details.Street_Name   = Parameter.StreetName;
            Universal_C_Details.Street_Number = Parameter.StreetNumber;
            Universal_C_Details.Town          = Parameter.Town;
            Universal_C_Details.ZIP           = Parameter.ZIP;
            Universal_C_Details.IsCompany     = Parameter.IsCompany;
            Universal_C_Details.Tenant_RefID  = securityTicket.TenantID;
            Universal_C_Details.IsDeleted     = false;



            Universal_C_Details.Save(Connection, Transaction);

            var SHeader = ORM_LOG_SHP_Shipment_Header.Query.Search(Connection, Transaction,
                                                                   new ORM_LOG_SHP_Shipment_Header.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                LOG_SHP_Shipment_HeaderID = Parameter.LOG_SHP_Shipment_HeaderID
            }).SingleOrDefault();


            if (SHeader != null)
            {
                SHeader.Shippipng_AddressUCD_RefID = Universal_C_Details.CMN_UniversalContactDetailID;
                SHeader.Save(Connection, Transaction);
            }

            returnValue.Result = Universal_C_Details.CMN_UniversalContactDetailID;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3CCfTaIC_1526_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L3CCfTaIC_1526 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3CCfTaIC_1526_Array();
            //Put your code here
            List <L3CCfTaIC_1526> ProductList = new List <L3CCfTaIC_1526>();
            returnValue.Result = ProductList.ToArray();
            var _service = CatalogServiceFactory.GetSubscriptionService();

            //make data to send to Architecture so that they will know which catalog to update
            var subscriptionRequest = new SubscriptionRequest();
            subscriptionRequest.CatalogCode = Parameter.CatalogCodeITL;
            Customer customer = new Customer();

            // for only Tenant specific cases add Business Participant ID
            if (Parameter.SubscribedBy_BusinessParticipant_RefID != Guid.Empty)
            {
                customer.BusinessParticipantITL = Parameter.SubscribedBy_BusinessParticipant_RefID.ToString();
            }
            else
            {
                customer.BusinessParticipantITL = securityTicket.TenantID.ToString();
            }
            customer.TenantITL = securityTicket.TenantID.ToString();
            customer.Name      = Parameter.ClientName;
            // customer.SourceRealm = BOp.Infrastructure.PropertyRepository.Instance.RealmID.ToString();

            subscriptionRequest.Customer = customer;

            /*
             * @see if catalog with the same ITL for that bussinessParticipant exists
             * */
            var subscribedCatalogQuery = new ORM_CMN_PRO_SubscribedCatalog.Query();
            subscribedCatalogQuery.Tenant_RefID   = securityTicket.TenantID;
            subscribedCatalogQuery.CatalogCodeITL = Parameter.CatalogCodeITL;
            if (Parameter.SubscribedBy_BusinessParticipant_RefID != Guid.Empty)
            {
                subscribedCatalogQuery.SubscribedBy_BusinessParticipant_RefID = Parameter.SubscribedBy_BusinessParticipant_RefID;
            }
            subscribedCatalogQuery.IsDeleted = false;

            var subscribedCatalog = ORM_CMN_PRO_SubscribedCatalog.Query.Search(Connection, Transaction, subscribedCatalogQuery).FirstOrDefault();

            #region Get VAT

            var defaultCountryISOCode = cls_Get_DefaultCountryISOCode_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;

            var param = new P_L3TX_GTfCICaT_1359();
            param.CountryISOCode = "DE";



            var taxes = cls_Get_Taxes_for_CountryISOCode_and_TenantID.Invoke(Connection, Transaction, param, securityTicket).Result;
            //if there are no taxes for tenant
            Guid countryID = Guid.Empty;
            if (taxes.Length == 0)
            {
                var country = cls_Get_AllCountries_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result.FirstOrDefault();

                if (country != null)
                {
                    countryID = country.CMN_CountryID;
                }
            }
            else
            {
                countryID = taxes.First().CMN_CountryID; // ti slucajni posmatracu ovog koda nemoj zameriti na ovakvom resenju.
            }

            #endregion

            #region save

            if (subscribedCatalog == null)
            {
                /*
                 * @save ORM_CMN_PRO_SubscribedCatalog
                 * */
                subscribedCatalog = new ORM_CMN_PRO_SubscribedCatalog();
                subscribedCatalog.CMN_PRO_SubscribedCatalogID = Guid.NewGuid();
                subscribedCatalog.CatalogCodeITL         = Parameter.CatalogCodeITL;
                subscribedCatalog.SubscribedCatalog_Name = Parameter.CatalogName;
                subscribedCatalog.SubscribedBy_BusinessParticipant_RefID = Parameter.SubscribedBy_BusinessParticipant_RefID;
                subscribedCatalog.Tenant_RefID = securityTicket.TenantID;
                subscribedCatalog.SubscribedCatalog_ValidFrom    = Parameter.ValidFrom_Date;
                subscribedCatalog.SubscribedCatalog_ValidThrough = Parameter.ValidTo_Date;
                subscribedCatalog.SubscribedCatalog_Description  = Parameter.CatalogDescription;
                subscribedCatalog.Creation_Timestamp             = DateTime.Now;
                subscribedCatalog.IsDeleted = false;
                subscribedCatalog.SubscribedCatalog_CurrentRevision = Parameter.CatalogVersion;
                subscribedCatalog.IsCatalogPublic = Parameter.IsCatalogPublic;

                // check if language with that ISO exists for Tenant (Lower, exmpl de)
                var languageQuery = new ORM_CMN_Language.Query();
                languageQuery.ISO_639_1    = Parameter.CatalogLanguage_ISO_639_1_codes.ToLower();
                languageQuery.Tenant_RefID = securityTicket.TenantID;
                languageQuery.IsDeleted    = false;

                var language = ORM_CMN_Language.Query.Search(Connection, Transaction, languageQuery).FirstOrDefault();

                // if language does not exist for that Tenant
                if (language == null)
                {
                    //check if language with that ISO exists for Tenant (Upper exmpl DE)
                    languageQuery              = new ORM_CMN_Language.Query();
                    languageQuery.ISO_639_1    = Parameter.CatalogLanguage_ISO_639_1_codes.ToUpper();
                    languageQuery.Tenant_RefID = securityTicket.TenantID;
                    languageQuery.IsDeleted    = false;

                    language = ORM_CMN_Language.Query.Search(Connection, Transaction, languageQuery).FirstOrDefault();

                    // if language does not exist for that Tenant
                    if (language == null)
                    {
                        ORM_CMN_Language newLanguage = new ORM_CMN_Language();
                        newLanguage.CMN_LanguageID     = Guid.NewGuid();
                        newLanguage.ISO_639_1          = Parameter.CatalogLanguage_ISO_639_1_codes;
                        newLanguage.Creation_Timestamp = DateTime.Now;
                        newLanguage.Tenant_RefID       = securityTicket.TenantID;
                        newLanguage.IsDeleted          = false;
                        newLanguage.Save(Connection, Transaction);

                        subscribedCatalog.SubscribedCatalog_Language_RefID = newLanguage.CMN_LanguageID;
                    }
                    else
                    {
                        subscribedCatalog.SubscribedCatalog_Language_RefID = language.CMN_LanguageID;
                    }
                }
                else
                {
                    subscribedCatalog.SubscribedCatalog_Language_RefID = language.CMN_LanguageID;
                }

                // check if currency with that ISO exists for Tenant

                var currencyQuery = new ORM_CMN_Currency.Query();
                currencyQuery.ISO4127      = Parameter.CatalogCurrency_ISO_4217;
                currencyQuery.Tenant_RefID = securityTicket.TenantID;
                currencyQuery.IsDeleted    = false;

                var currency = ORM_CMN_Currency.Query.Search(Connection, Transaction, currencyQuery).FirstOrDefault();

                if (currency == null)
                {
                    ORM_CMN_Currency newCurrency = new ORM_CMN_Currency();
                    newCurrency.CMN_CurrencyID     = Guid.NewGuid();
                    newCurrency.ISO4127            = Parameter.CatalogCurrency_ISO_4217;
                    newCurrency.Tenant_RefID       = securityTicket.TenantID;
                    newCurrency.Creation_Timestamp = DateTime.Now;
                    newCurrency.Save(Connection, Transaction);

                    subscribedCatalog.SubscribedCatalog_Currency_RefID = newCurrency.CMN_CurrencyID;
                }
                else
                {
                    subscribedCatalog.SubscribedCatalog_Currency_RefID = currency.CMN_CurrencyID;
                }

                #region product group

                /*
                 * @Search product group
                 * */
                ORM_CMN_PRO_ProductGroup productGroup = new ORM_CMN_PRO_ProductGroup();

                var productGroupQuery = new ORM_CMN_PRO_ProductGroup.Query();
                productGroupQuery.Tenant_RefID             = securityTicket.TenantID;
                productGroupQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.Treatment);

                //if (Parameter.IsCatalogPublic == false)
                //{
                //    productGroupQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.HauseList);
                //}
                //else
                //{
                //    productGroupQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.ABDA);
                //}
                // for only Tenant specific cases add Business Participant ID
                if (Parameter.SubscribedBy_BusinessParticipant_RefID != Guid.Empty)
                {
                    productGroupQuery.GlobalPropertyMatchingID += Parameter.SubscribedBy_BusinessParticipant_RefID;
                }
                productGroupQuery.IsDeleted = false;

                productGroup = ORM_CMN_PRO_ProductGroup.Query.Search(Connection, Transaction, productGroupQuery).FirstOrDefault();

                if (productGroup == null)
                {
                    /*
                     * @Create product group for products if product group for that BP and Tenent does not exist
                     * */
                    productGroup = new ORM_CMN_PRO_ProductGroup();
                    productGroup.Tenant_RefID                  = securityTicket.TenantID;
                    productGroup.Creation_Timestamp            = DateTime.Now;
                    productGroup.CMN_PRO_ProductGroupID        = Guid.NewGuid();
                    productGroup.ProductGroup_Name             = new Dict(ORM_CMN_PRO_ProductGroup.TableName);
                    productGroupQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.Treatment);
                    productGroup.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "Treatment Group");

                    //if (Parameter.IsCatalogPublic == false)
                    //{
                    //    productGroup.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.HauseList);
                    //    productGroup.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "HauseList Group");
                    //}
                    //else
                    //{
                    //    productGroup.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.ABDA);
                    //    productGroup.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "ABDA Group");
                    //}

                    // for only Tenant specific cases add Business Participant ID
                    if (Parameter.SubscribedBy_BusinessParticipant_RefID != Guid.Empty)
                    {
                        productGroup.GlobalPropertyMatchingID += Parameter.SubscribedBy_BusinessParticipant_RefID;
                        productGroup.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "Treatment Group");
                    }
                    productGroup.Save(Connection, Transaction);
                }
                #endregion

                #region create priceList for Catalog

                /*
                 * @create pricelist_Release
                 * */
                ORM_CMN_SLS_Pricelist_Release pricelist_Release = new ORM_CMN_SLS_Pricelist_Release();
                pricelist_Release.CMN_SLS_Pricelist_ReleaseID = Guid.NewGuid();
                pricelist_Release.Release_Version             = "v1";
                if (Parameter.IsCatalogPublic == false)
                {
                    pricelist_Release.PricelistRelease_ValidFrom = Parameter.ValidFrom_Date;
                    pricelist_Release.PricelistRelease_ValidTo   = Parameter.ValidTo_Date;
                }
                else
                {
                    pricelist_Release.IsPricelistAlwaysActive = true;
                }
                pricelist_Release.Tenant_RefID       = securityTicket.TenantID;
                pricelist_Release.Creation_Timestamp = DateTime.Now;
                pricelist_Release.Pricelist_RefID    = Guid.NewGuid();//priceList.CMN_SLS_PricelistID
                pricelist_Release.Save(Connection, Transaction);

                /*
                 * @create pricelist
                 * */
                ORM_CMN_SLS_Pricelist priceList = new ORM_CMN_SLS_Pricelist();
                priceList.CMN_SLS_PricelistID = pricelist_Release.Pricelist_RefID;

                var DBLanguages = cls_Get_All_Languages.Invoke(Connection, Transaction, securityTicket).Result.ToList();

                Dict nameDict = new Dict("cmn_sls_pricelist");
                if (Parameter.IsCatalogPublic == false)
                {
                    for (int i = 0; i < DBLanguages.Count; i++)
                    {
                        nameDict.AddEntry(DBLanguages[i].CMN_LanguageID, Parameter.CatalogName + "_" + Parameter.ValidFrom_Date.ToShortDateString() + "_" + Parameter.ValidTo_Date.ToShortDateString());
                    }
                }
                else
                {
                    for (int i = 0; i < DBLanguages.Count; i++)
                    {
                        nameDict.AddEntry(DBLanguages[i].CMN_LanguageID, "ABDA_PriceList");
                    }
                }
                priceList.Pricelist_Name     = nameDict;
                priceList.Tenant_RefID       = securityTicket.TenantID;
                priceList.Creation_Timestamp = DateTime.Now;
                priceList.Save(Connection, Transaction);

                #endregion

                if (Parameter.IsCatalogPublic == false)
                {
                    #region create and save products in product group and give product its price , product amout and measure unit

                    /*
                     * @create and save products in product group
                     * */

                    bool isAlreadyInABDA = false;
                    foreach (var item in Parameter.Products)
                    {
                        ORM_CMN_PRO_Product product = new ORM_CMN_PRO_Product();

                        // only for Tenant specific cases add Business Participant ID (!Lucentis)
                        if (Parameter.SubscribedBy_BusinessParticipant_RefID == Guid.Empty)
                        {
                            var productQuery = new ORM_CMN_PRO_Product.Query();
                            productQuery.ProductITL   = item.ProductITL;
                            productQuery.Tenant_RefID = securityTicket.TenantID;
                            productQuery.IsDeleted    = false;
                            productQuery.IsProductAvailableForOrdering = true;

                            product = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, productQuery).FirstOrDefault();

                            //if it is not in ABDA
                            if (product == null)
                            {
                                product = new ORM_CMN_PRO_Product();
                                product.CMN_PRO_ProductID             = Guid.NewGuid();
                                product.Creation_Timestamp            = DateTime.Now;
                                product.Tenant_RefID                  = securityTicket.TenantID;
                                product.ProductITL                    = item.ProductITL;
                                product.Product_Name                  = item.Product_Name;
                                product.Product_Description           = item.Product_Description;
                                product.Product_Number                = item.Product_Number;
                                product.IsProduct_Article             = item.IsProduct_Article;
                                product.IsProductAvailableForOrdering = true;
                                product.PackageInfo_RefID             = Guid.NewGuid();//packageInfo.CMN_PRO_PAC_PackageInfoID

                                isAlreadyInABDA = false;
                            }
                            else
                            {
                                isAlreadyInABDA = true;
                            }
                        }
                        else
                        {
                            product.CMN_PRO_ProductID             = Guid.NewGuid();
                            product.Creation_Timestamp            = DateTime.Now;
                            product.Tenant_RefID                  = securityTicket.TenantID;
                            product.ProductITL                    = item.ProductITL;
                            product.Product_Name                  = item.Product_Name;
                            product.Product_Description           = item.Product_Description;
                            product.Product_Number                = item.Product_Number;
                            product.IsProduct_Article             = item.IsProduct_Article;
                            product.IsProductAvailableForOrdering = true;
                            product.PackageInfo_RefID             = Guid.NewGuid();//packageInfo.CMN_PRO_PAC_PackageInfoID

                            isAlreadyInABDA = false;
                        }

                        product.IfImportedFromExternalCatalog_CatalogSubscription_RefID = subscribedCatalog.CMN_PRO_SubscribedCatalogID;
                        product.Save(Connection, Transaction);

                        L3CCfTaIC_1526 pro = new L3CCfTaIC_1526();
                        pro.ProductID = product.CMN_PRO_ProductID;
                        if (product.IsProduct_Article)
                        {
                            pro.Dosage = item.Dosage;
                        }
                        pro.isEdit = false;
                        ProductList.Add(pro);

                        ORM_CMN_PRO_Product_2_ProductGroup product_2_productGroup = new ORM_CMN_PRO_Product_2_ProductGroup();
                        product_2_productGroup.CMN_PRO_Product_RefID      = product.CMN_PRO_ProductID;
                        product_2_productGroup.CMN_PRO_ProductGroup_RefID = productGroup.CMN_PRO_ProductGroupID;
                        product_2_productGroup.Tenant_RefID       = securityTicket.TenantID;
                        product_2_productGroup.Creation_Timestamp = DateTime.Now;
                        product_2_productGroup.Save(Connection, Transaction);

                        if (isAlreadyInABDA == false)
                        {
                            ORM_CMN_SLS_Price price = new ORM_CMN_SLS_Price();
                            price.CMN_SLS_PriceID        = Guid.NewGuid();
                            price.Tenant_RefID           = securityTicket.TenantID;
                            price.Creation_Timestamp     = DateTime.Now;
                            price.PricelistRelease_RefID = pricelist_Release.CMN_SLS_Pricelist_ReleaseID;
                            price.CMN_PRO_Product_RefID  = product.CMN_PRO_ProductID;
                            price.PriceAmount            = item.Price;
                            price.CMN_Currency_RefID     = subscribedCatalog.SubscribedCatalog_Currency_RefID;
                            price.Save(Connection, Transaction);

                            //add amount and Measure
                            ORM_CMN_PRO_PAC_PackageInfo packageInfo = new ORM_CMN_PRO_PAC_PackageInfo();
                            packageInfo.CMN_PRO_PAC_PackageInfoID = product.PackageInfo_RefID;
                            packageInfo.Tenant_RefID          = securityTicket.TenantID;
                            packageInfo.Creation_Timestamp    = DateTime.Now;
                            packageInfo.PackageContent_Amount = item.Amount;

                            //check if MeasureUnit exists for this Tenant
                            var unitsQuery = new ORM_CMN_Unit.Query();
                            unitsQuery.Tenant_RefID = securityTicket.TenantID;
                            unitsQuery.ISOCode      = item.MeasuredInUnit_ISO_um_ums;
                            unitsQuery.IsDeleted    = false;

                            var measuredInUnit = ORM_CMN_Unit.Query.Search(Connection, Transaction, unitsQuery).FirstOrDefault();
                            if (measuredInUnit == null)
                            {
                                ORM_CMN_Unit newMeasuredInUnit = new ORM_CMN_Unit();
                                newMeasuredInUnit.Tenant_RefID       = securityTicket.TenantID;
                                newMeasuredInUnit.Creation_Timestamp = DateTime.Now;
                                newMeasuredInUnit.ISOCode            = item.MeasuredInUnit_ISO_um_ums;
                                newMeasuredInUnit.CMN_UnitID         = Guid.NewGuid();
                                newMeasuredInUnit.Save(Connection, Transaction);

                                packageInfo.PackageContent_MeasuredInUnit_RefID = newMeasuredInUnit.CMN_UnitID;
                            }
                            else
                            {
                                packageInfo.PackageContent_MeasuredInUnit_RefID = measuredInUnit.CMN_UnitID;
                            }

                            packageInfo.Save(Connection, Transaction);

                            if (countryID != Guid.Empty)// if there is a country for this Tenant
                            {
                                #region Create Taxes

                                double productVAT = 0;
                                Double.TryParse(item.VAT, out productVAT);

                                var tax = taxes.Where(i => i.TaxRate == productVAT).SingleOrDefault();

                                if (tax == default(L3TX_GTfCICaT_1359))
                                {
                                    #region CreateTax

                                    var saveTaxParam = new P_L3TX_STX_1119();
                                    saveTaxParam.ACC_TAX_TaxeID = Guid.Empty;
                                    saveTaxParam.TaxName        = new Dict(ORM_ACC_TAX_Tax.TableName);
                                    saveTaxParam.TaxName.AddEntry(language.CMN_LanguageID, productVAT.ToString());
                                    saveTaxParam.TaxRate = productVAT;
                                    if (taxes.Length != 0)
                                    {
                                        saveTaxParam.EconomicRegion_RefID = taxes.First().CMN_EconomicRegionID;
                                        saveTaxParam.Country_RefID        = taxes.First().CMN_CountryID;
                                    }
                                    else
                                    {
                                        saveTaxParam.EconomicRegion_RefID = Guid.Empty;
                                        saveTaxParam.Country_RefID        = countryID;
                                    }
                                    var saveTaxResult = cls_Save_Tax.Invoke(Connection, Transaction, saveTaxParam, securityTicket).Result;

                                    #endregion

                                    #region Update Available taxes

                                    param = new P_L3TX_GTfCICaT_1359();
                                    param.CountryISOCode = "DE";

                                    taxes = cls_Get_Taxes_for_CountryISOCode_and_TenantID.Invoke(Connection, Transaction, param, securityTicket).Result;

                                    tax = taxes.Where(i => i.TaxRate == productVAT).SingleOrDefault();

                                    #endregion
                                }

                                var salesTax = new ORM_CMN_PRO_Product_SalesTaxAssignmnet();
                                salesTax.CMN_PRO_Product_SalesTaxAssignmnetID = Guid.NewGuid();
                                salesTax.Product_RefID            = product.CMN_PRO_ProductID;
                                salesTax.ApplicableSalesTax_RefID = tax.ACC_TAX_TaxeID;
                                salesTax.Creation_Timestamp       = DateTime.Now;
                                salesTax.Tenant_RefID             = securityTicket.TenantID;
                                salesTax.Save(Connection, Transaction);

                                #endregion
                            }
                        }
                    }
                    #endregion
                }

                /*
                 * @See if Supplier already exists in database
                 * */
                ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();

                var supplierQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                supplierQuery.BusinessParticipantITL = Parameter.SupplierData.SupplierITL;
                supplierQuery.Tenant_RefID           = securityTicket.TenantID;
                supplierQuery.IsDeleted = false;

                var supplier_bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, supplierQuery).FirstOrDefault();

                #region if supplier does not exist

                if (supplier_bussinessParticipant == null)
                {
                    /*
                     * @Make Supplier Data
                     * */

                    var tenantQuery = new ORM_CMN_Tenant.Query()
                    {
                        TenantITL    = Parameter.SupplierData.TenantITL,
                        Tenant_RefID = securityTicket.TenantID
                    };

                    var supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

                    if (supplierTenant == default(ORM_CMN_Tenant))
                    {
                        supplierTenant = new ORM_CMN_Tenant();
                        supplierTenant.CMN_TenantID       = Guid.NewGuid();
                        supplierTenant.TenantITL          = Parameter.SupplierData.TenantITL;
                        supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                        supplierTenant.Creation_Timestamp = DateTime.Now;
                        supplierTenant.Save(Connection, Transaction);
                    }

                    supplier.CMN_BPT_SupplierID            = Guid.NewGuid();
                    supplier.Ext_BusinessParticipant_RefID = Guid.NewGuid();//supplierBussinessParticipant.CMN_BPT_BusinessParticipantID
                    supplier.Creation_Timestamp            = DateTime.Now;
                    supplier.IsDeleted    = false;
                    supplier.Tenant_RefID = securityTicket.TenantID;
                    supplier.Save(Connection, Transaction);

                    ORM_CMN_BPT_BusinessParticipant supplierBussinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                    supplierBussinessParticipant.CMN_BPT_BusinessParticipantID = supplier.Ext_BusinessParticipant_RefID;
                    supplierBussinessParticipant.DisplayName            = Parameter.SupplierData.Supplier_Name;
                    supplierBussinessParticipant.BusinessParticipantITL = Parameter.SupplierData.SupplierITL;
                    supplierBussinessParticipant.Creation_Timestamp     = DateTime.Now;
                    supplierBussinessParticipant.Tenant_RefID           = securityTicket.TenantID;
                    supplierBussinessParticipant.IsCompany             = true;
                    supplierBussinessParticipant.IsTenant              = true;
                    supplierBussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                    supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();//companyInfo.CMN_COM_CompanyInfoID
                    supplierBussinessParticipant.Save(Connection, Transaction);

                    ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                    companyInfo.CMN_COM_CompanyInfoID = supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                    companyInfo.Creation_Timestamp    = DateTime.Now;
                    companyInfo.Tenant_RefID          = securityTicket.TenantID;
                    companyInfo.Contact_UCD_RefID     = Guid.NewGuid();//universalContactDetail.CMN_UniversalContactDetailID
                    companyInfo.Save(Connection, Transaction);

                    ORM_CMN_UniversalContactDetail universalContactDetail = new ORM_CMN_UniversalContactDetail();
                    universalContactDetail.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                    universalContactDetail.IsCompany             = true;
                    universalContactDetail.Country_639_1_ISOCode = Parameter.SupplierData.CountryISO;
                    universalContactDetail.Street_Name           = Parameter.SupplierData.Supplier_Name;
                    universalContactDetail.Street_Number         = Parameter.SupplierData.Street_Number;
                    universalContactDetail.ZIP                = Parameter.SupplierData.ZIP;
                    universalContactDetail.Town               = Parameter.SupplierData.Town;
                    universalContactDetail.Region_Code        = Parameter.SupplierData.Region_Code;
                    universalContactDetail.Tenant_RefID       = securityTicket.TenantID;
                    universalContactDetail.Creation_Timestamp = DateTime.Now;
                    universalContactDetail.Save(Connection, Transaction);
                }
                #endregion
                #region if supplier exists , check if its data is changed
                else
                {
                    var tenantQuery = new ORM_CMN_Tenant.Query()
                    {
                        TenantITL    = Parameter.SupplierData.TenantITL,
                        Tenant_RefID = securityTicket.TenantID
                    };

                    var supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

                    if (supplierTenant == default(ORM_CMN_Tenant))
                    {
                        supplierTenant = new ORM_CMN_Tenant();
                        supplierTenant.CMN_TenantID       = Guid.NewGuid();
                        supplierTenant.TenantITL          = Parameter.SupplierData.TenantITL;
                        supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                        supplierTenant.Creation_Timestamp = DateTime.Now;
                        supplierTenant.Save(Connection, Transaction);

                        supplier_bussinessParticipant.IsTenant = true;
                        supplier_bussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                    }

                    supplier_bussinessParticipant.DisplayName = Parameter.SupplierData.Supplier_Name;
                    supplier_bussinessParticipant.Save(Connection, Transaction);

                    var query = new ORM_CMN_BPT_Supplier.Query();
                    query.Ext_BusinessParticipant_RefID = supplier_bussinessParticipant.CMN_BPT_BusinessParticipantID;
                    query.Tenant_RefID = securityTicket.TenantID;
                    query.IsDeleted    = false;

                    supplier = ORM_CMN_BPT_Supplier.Query.Search(Connection, Transaction, query).First();

                    //edit universal contact details

                    var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
                    companyInfoQuery.CMN_COM_CompanyInfoID = supplier_bussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                    companyInfoQuery.Tenant_RefID          = securityTicket.TenantID;
                    companyInfoQuery.IsDeleted             = false;

                    var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First();

                    var universalContactDetailQuery = new ORM_CMN_UniversalContactDetail.Query();
                    universalContactDetailQuery.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                    universalContactDetailQuery.Tenant_RefID = securityTicket.TenantID;
                    universalContactDetailQuery.IsDeleted    = false;

                    var universalContactDetail = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, universalContactDetailQuery).First();

                    universalContactDetail.Country_639_1_ISOCode = Parameter.SupplierData.CountryISO;
                    universalContactDetail.Street_Name           = Parameter.SupplierData.Supplier_Name;
                    universalContactDetail.Street_Number         = Parameter.SupplierData.Street_Number;
                    universalContactDetail.ZIP         = Parameter.SupplierData.ZIP;
                    universalContactDetail.Town        = Parameter.SupplierData.Town;
                    universalContactDetail.Region_Code = Parameter.SupplierData.Region_Code;
                    universalContactDetail.Save(Connection, Transaction);
                }
                #endregion

                subscribedCatalog.SubscribedCatalog_PricelistRelease_RefID = pricelist_Release.CMN_SLS_Pricelist_ReleaseID;
                subscribedCatalog.PublishingSupplier_RefID = supplier.CMN_BPT_SupplierID;
                subscribedCatalog.Save(Connection, Transaction);

                /*
                 * @send Kika information which catalog has been subscribed to who
                 * */
                var result = _service.SubscribeToCatalog(subscriptionRequest);

                if (result.ResponseStatus != ResponseStatus.OK)
                {
                    throw new Exception("Catalog subscription failed!");
                }
            }
            #endregion

            returnValue.Result = ProductList.ToArray();
            return(returnValue);

            #endregion UserCode
        }
Example #6
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PR_SP__1122 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_HEC_MedicalPractis item = new ORM_HEC_MedicalPractis();

            if (Parameter.PracticeID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.PracticeID);
                if (result.Status != FR_Status.Success || item.HEC_MedicalPractiseID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }

                #region Delete

                if (Parameter.isDeleted == true)
                {
                    var query_BP_ContactPerson_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BP_ContactPerson_del.CMN_BPT_BusinessParticipantID = item.ContactPerson_RefID;
                    query_BP_ContactPerson_del.Tenant_RefID = securityTicket.TenantID;

                    var found_BP_ContactPerson_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BP_ContactPerson_del).First();
                    found_BP_ContactPerson_del.IsDeleted = true;

                    var query_PersonInfo_del = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo_del.CMN_PER_PersonInfoID = found_BP_ContactPerson_del.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    var found_PersonInfo_del = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo_del).First();
                    found_PersonInfo_del.IsDeleted = true;
                    found_PersonInfo_del.Save(Connection, Transaction);


                    var query_CommunicationContact_del = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact_del.PersonInfo_RefID = found_PersonInfo_del.CMN_PER_PersonInfoID;


                    var found_CommunicationContact_del = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact_del).First();
                    found_CommunicationContact_del.IsDeleted = true;

                    found_CommunicationContact_del.Save(Connection, Transaction);


                    var query_CompanyInfo_del = new ORM_CMN_COM_CompanyInfo.Query();
                    query_CompanyInfo_del.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                    var found_CompanyInfo_del = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo_del).First();
                    found_CompanyInfo_del.IsDeleted = true;

                    found_CompanyInfo_del.Save(Connection, Transaction);

                    var query_BP_Company_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BP_Company_del.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo_del.CMN_COM_CompanyInfoID;

                    var found_BP_Company_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BP_Company_del).First();
                    found_BP_Company_del.IsDeleted = true;
                    found_BP_Company_del.Save(Connection, Transaction);

                    var query_UniversalContactDetails_del = new ORM_CMN_UniversalContactDetail.Query();
                    query_UniversalContactDetails_del.CMN_UniversalContactDetailID = found_CompanyInfo_del.Contact_UCD_RefID;

                    var found_UniversalCompanyDetails_del = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_UniversalContactDetails_del).First();

                    found_UniversalCompanyDetails_del.IsDeleted = true;
                    found_UniversalCompanyDetails_del.Save(Connection, Transaction);

                    item.IsDeleted = true;
                    return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_MedicalPractiseID));
                }

                #endregion
                #region Edit

                var query1 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query1.CMN_BPT_BusinessParticipantID = item.ContactPerson_RefID;
                query1.Tenant_RefID    = securityTicket.TenantID;
                query1.IsCompany       = false;
                query1.IsNaturalPerson = true;
                query1.IsTenant        = false;

                var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First();


                var query2 = new ORM_CMN_PER_PersonInfo.Query();
                query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First();

                personInfo.FirstName    = Parameter.ContactPersonFirstName;
                personInfo.LastName     = Parameter.ContactPersonLastName;
                personInfo.PrimaryEmail = Parameter.ContactPersonEmail;
                personInfo.Save(Connection, Transaction);


                var query3 = new ORM_CMN_PER_CommunicationContact.Query();
                query3.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;


                var communicationContacts = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query3).First();
                communicationContacts.Contact_Type = Parameter.ContactTypePhone;
                communicationContacts.Content      = Parameter.ContactPersonPhoneNumber;

                communicationContacts.Save(Connection, Transaction);


                var query4 = new ORM_CMN_COM_CompanyInfo.Query();
                query4.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query4).First();
                companyInfo.CompanyInfo_EstablishmentNumber = Parameter.BSNR;

                companyInfo.Save(Connection, Transaction);

                var query5 = new ORM_CMN_BPT_BusinessParticipant.Query();
                query5.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;

                var extCompany = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query5).First();
                extCompany.DisplayName = Parameter.PracticeName;
                extCompany.Save(Connection, Transaction);

                var query6 = new ORM_CMN_UniversalContactDetail.Query();
                query6.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;

                var companyDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query6).First();

                companyDetails.ZIP               = Parameter.ZIP;
                companyDetails.Town              = Parameter.Town;
                companyDetails.Street_Name       = Parameter.PracticeStreet;
                companyDetails.Street_Number     = Parameter.PracticeNumber;
                companyDetails.Contact_Email     = Parameter.PracitceEmail;
                companyDetails.Street_Name_Line2 = Parameter.PracticeStreet2;

                companyDetails.Save(Connection, Transaction);
                #endregion
            }
            else
            {
                #region Save

                item.HEC_MedicalPractiseID = Guid.NewGuid();

                item.Creation_Timestamp = DateTime.Now;
                item.Tenant_RefID       = securityTicket.TenantID;


                //business Participants
                ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                Guid businessParticipantsID = Guid.NewGuid();

                contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantsID;
                contactPerson.IsCompany          = false;
                contactPerson.IsNaturalPerson    = true;
                contactPerson.IsTenant           = false;
                contactPerson.Creation_Timestamp = DateTime.Now;
                contactPerson.Tenant_RefID       = securityTicket.TenantID;

                item.ContactPerson_RefID = businessParticipantsID;

                //person info
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                Guid personInfoID = Guid.NewGuid();

                contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                contactPerson.Save(Connection, Transaction);

                personInfo.CMN_PER_PersonInfoID = personInfoID;
                personInfo.FirstName            = Parameter.ContactPersonFirstName;
                personInfo.LastName             = Parameter.ContactPersonLastName;
                personInfo.PrimaryEmail         = Parameter.ContactPersonEmail;
                personInfo.Creation_Timestamp   = DateTime.Now;
                personInfo.Tenant_RefID         = securityTicket.TenantID;

                personInfo.Save(Connection, Transaction);

                //Communication Contact
                ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContacts.PersonInfo_RefID   = personInfoID;
                communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                communicationContacts.Content            = Parameter.ContactPersonPhoneNumber;
                communicationContacts.Creation_Timestamp = DateTime.Now;
                communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                communicationContacts.Save(Connection, Transaction);


                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                Guid companyInfoID = Guid.NewGuid();
                companyInfo.CMN_COM_CompanyInfoID           = companyInfoID;
                companyInfo.Creation_Timestamp              = DateTime.Now;
                companyInfo.Tenant_RefID                    = securityTicket.TenantID;
                companyInfo.CompanyInfo_EstablishmentNumber = Parameter.BSNR;

                item.Ext_CompanyInfo_RefID = companyInfoID;


                ORM_CMN_BPT_BusinessParticipant extCompany = new ORM_CMN_BPT_BusinessParticipant();
                extCompany.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                extCompany.Creation_Timestamp            = DateTime.Now;
                extCompany.Tenant_RefID    = securityTicket.TenantID;
                extCompany.DisplayName     = Parameter.PracticeName;
                extCompany.IsCompany       = true;
                extCompany.IsNaturalPerson = false;
                extCompany.IsTenant        = false;
                extCompany.IsDeleted       = false;
                extCompany.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfoID;

                extCompany.Save(Connection, Transaction);

                ORM_CMN_UniversalContactDetail companyDetails = new ORM_CMN_UniversalContactDetail();
                Guid companyDetailsID = Guid.NewGuid();

                companyInfo.Contact_UCD_RefID = companyDetailsID;
                companyInfo.Save(Connection, Transaction);

                companyDetails.CMN_UniversalContactDetailID = companyDetailsID;
                companyDetails.Tenant_RefID       = securityTicket.TenantID;
                companyDetails.Creation_Timestamp = DateTime.Now;
                companyDetails.IsCompany          = true;
                companyDetails.ZIP               = Parameter.ZIP;
                companyDetails.Town              = Parameter.Town;
                companyDetails.Street_Name       = Parameter.PracticeStreet;
                companyDetails.Street_Number     = Parameter.PracticeNumber;
                companyDetails.Contact_Email     = Parameter.PracitceEmail;
                companyDetails.Street_Name_Line2 = Parameter.PracticeStreet2;
                companyDetails.IsDeleted         = false;
                companyDetails.Save(Connection, Transaction);

                item.Save(Connection, Transaction);


                #endregion
            }

            returnValue.Result = item.HEC_MedicalPractiseID;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MP_DPBID_1026 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            P_L3MP_GPfID_1222 param = new P_L3MP_GPfID_1222();
            param.HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID;
            var practice = cls_Get_Practice_For_ID.Invoke(Connection, Transaction, param, securityTicket).Result;
            if (practice != null)
            {
                ORM_CMN_UniversalContactDetail contactDetails = new ORM_CMN_UniversalContactDetail();
                if (practice.BaseInfo.CMN_UniversalContactDetailID != Guid.Empty)
                {
                    var result = contactDetails.Load(Connection, Transaction, practice.BaseInfo.CMN_UniversalContactDetailID);
                    if (result.Status != FR_Status.Success || contactDetails.CMN_UniversalContactDetailID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    contactDetails.IsDeleted = true;
                    contactDetails.Save(Connection, Transaction);
                }

                ORM_CMN_COM_CompanyInfo info = new ORM_CMN_COM_CompanyInfo();
                if (practice.BaseInfo.CMN_COM_CompanyInfoID != Guid.Empty)
                {
                    var result = info.Load(Connection, Transaction, practice.BaseInfo.CMN_COM_CompanyInfoID);
                    if (result.Status != FR_Status.Success || info.CMN_COM_CompanyInfoID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    info.IsDeleted = true;
                    info.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (practice.BaseInfo.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    var result = bParticipant.Load(Connection, Transaction, practice.BaseInfo.CMN_BPT_BusinessParticipantID);
                    if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    bParticipant.IsDeleted = true;
                    bParticipant.Save(Connection, Transaction);
                }


                ORM_HEC_MedicalPractis practis = new ORM_HEC_MedicalPractis();
                if (practice.BaseInfo.HEC_MedicalPractiseID != Guid.Empty)
                {
                    var result = practis.Load(Connection, Transaction, practice.BaseInfo.HEC_MedicalPractiseID);
                    if (result.Status != FR_Status.Success || practis.HEC_MedicalPractiseID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    practis.IsDeleted = true;
                    practis.Save(Connection, Transaction);
                }

                if (practice.BaseInfo.WeeklyOfficeHours_Template_RefID != Guid.Empty)
                {
                    ORM_CMN_CAL_WeeklyOfficeHours_Template consultationHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template();
                    if (practice.BaseInfo.WeeklyOfficeHours_Template_RefID != Guid.Empty)
                    {
                        var result = consultationHours.Load(Connection, Transaction, practice.BaseInfo.WeeklyOfficeHours_Template_RefID);
                        if (result.Status != FR_Status.Success || consultationHours.CMN_CAL_WeeklyOfficeHours_TemplateID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                        consultationHours.IsDeleted = true;
                        consultationHours.Save(Connection, Transaction);
                    }
                }
                if (practice.BaseInfo.WeeklySurgeryHours_Template_RefID != Guid.Empty)
                {
                    ORM_CMN_CAL_WeeklyOfficeHours_Template consultationHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template();
                    if (practice.BaseInfo.WeeklyOfficeHours_Template_RefID != Guid.Empty)
                    {
                        var result = consultationHours.Load(Connection, Transaction, practice.BaseInfo.WeeklySurgeryHours_Template_RefID);
                        if (result.Status != FR_Status.Success || consultationHours.CMN_CAL_WeeklyOfficeHours_TemplateID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                        consultationHours.IsDeleted = true;
                        consultationHours.Save(Connection, Transaction);
                    }
                }

                if (practice.ShippingAddress != null)
                {
                    ORM_CMN_UniversalContactDetail shippingDetails = new ORM_CMN_UniversalContactDetail();
                    if (practice.ShippingAddress.CMN_UniversalContactDetailID != Guid.Empty)
                    {
                        var result = shippingDetails.Load(Connection, Transaction, practice.ShippingAddress.CMN_UniversalContactDetailID);
                        if (result.Status != FR_Status.Success || contactDetails.CMN_UniversalContactDetailID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }

                        shippingDetails.IsDeleted = true;
                        shippingDetails.Save(Connection, Transaction);
                    }

                    ORM_CMN_COM_CompanyInfo_Address shippingAddress = new ORM_CMN_COM_CompanyInfo_Address();
                    if (practice.ShippingAddress.CMN_COM_CompanyInfo_AddressID != Guid.Empty)
                    {
                        var result = shippingAddress.Load(Connection, Transaction, practice.ShippingAddress.CMN_COM_CompanyInfo_AddressID);
                        if (result.Status != FR_Status.Success || shippingAddress.CMN_COM_CompanyInfo_AddressID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                        shippingAddress.IsDeleted = true;
                        shippingAddress.Save(Connection, Transaction);
                    }
                }

                var associatedBussinessParticipantsQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associatedBussinessParticipantsQuery.AssociatedBusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                associatedBussinessParticipantsQuery.IsDeleted = false;
                var associatedBussinessParticipants = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associatedBussinessParticipantsQuery);

                if (associatedBussinessParticipants.Count != 0)
                {
                    foreach (var assBussiness in associatedBussinessParticipants)
                    {
                        assBussiness.IsDeleted = true;
                        assBussiness.Save(Connection, Transaction);

                        //brisanje doktora ako je imao jednu praksu
                        //var d2pAssignmentQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                        //d2pAssignmentQuery.IsDeleted = false;
                        //d2pAssignmentQuery.BusinessParticipant_RefID = assBussiness.BusinessParticipant_RefID;
                        //var d2pAssignmentRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, d2pAssignmentQuery).ToArray();
                        //if (d2pAssignmentRes.Length == 0)
                        //{
                        //    var docQuery = new ORM_HEC_Doctor.Query();
                        //    docQuery.BusinessParticipant_RefID = assBussiness.BusinessParticipant_RefID;
                        //    var doctor =  ORM_HEC_Doctor.Query.Search(Connection, Transaction, docQuery).First();
                        //    P_L3MD_DDbID_1031 delDoc = new P_L3MD_DDbID_1031();
                        //    delDoc.DoctorID = doctor.HEC_DoctorID;
                        //    var delRes = cls_Delete_Doctor_byID.Invoke(Connection, Transaction, delDoc, securityTicket).Result;
                        //}
                    }
                }

                if (practice.OtherOphthal_PracticeData != null)
                {
                    ORM_HEC_PublicHealthcare_PhysitianAssociation association = new ORM_HEC_PublicHealthcare_PhysitianAssociation();
                    if (practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID != Guid.Empty)
                    {
                        var result = association.Load(Connection, Transaction, practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID);
                        if (result.Status != FR_Status.Success || association.HEC_PublicHealthcare_PhysitianAssociationID == Guid.Empty)
                        {
                            var item = STLD_MedicalAssociation.associationItems.FirstOrDefault(a => a.Value == practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID);
                            if (item != null)
                            {
                                association.IsDeleted = true;
                                association.HealthAssociation_Name = item.Text;
                                association.Save(Connection, Transaction);
                            }
                        }
                    }

                    var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
                    customerQuery.Ext_BusinessParticipant_RefID = practice.BaseInfo.CMN_BPT_BusinessParticipantID;
                    var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).FirstOrDefault();
                    if (customer != null)
                    {
                        customer.IsDeleted = true;
                        customer.Save(Connection, Transaction);
                    }

                    var companyTypeQuery = new ORM_CMN_COM_CompanyInfo_Type.Query();
                    companyTypeQuery.IsDeleted = false;
                    companyTypeQuery.CMN_COM_CompanyInfo_TypeID = practice.OtherOphthal_PracticeData.CMN_COM_CompanyInfo_TypeID;
                    var companyType      = ORM_CMN_COM_CompanyInfo_Type.Query.Search(Connection, Transaction, companyTypeQuery).First();
                    var pHealthcareQuery = new ORM_HEC_PublicHealthcare_PhysitianAssociation.Query();
                    pHealthcareQuery.HEC_PublicHealthcare_PhysitianAssociationID = practice.OtherOphthal_PracticeData.HEC_PublicHealthcare_PhysitianAssociationID;
                    var pHealthcare = ORM_HEC_PublicHealthcare_PhysitianAssociation.Query.Search(Connection, Transaction, pHealthcareQuery).First();
                    pHealthcare.IsDeleted = true;
                    pHealthcare.Save(Connection, Transaction);

                    if (customer != null)
                    {
                        var affinityStatusQuery = new ORM_CMN_BPT_CTM_AffinityStatus.Query();
                        affinityStatusQuery.CMN_BPT_CTM_AffinityStatusID = customer.CustomerAffinityStatus_RefID;
                        var affinityStatus = ORM_CMN_BPT_CTM_AffinityStatus.Query.Search(Connection, Transaction, affinityStatusQuery).First();
                        if (affinityStatus != null)
                        {
                            affinityStatus.IsDeleted = true;
                            affinityStatus.Save(Connection, Transaction);
                        }
                    }
                }
            }

            return(returnValue);

            #endregion UserCode
        }
Example #8
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_CBH_1606 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_BIL_BillHeader billHeader = null;
            ORM_BIL_BillHeader_2_BillStatus billHeader2BillStatus  = null;
            ORM_CMN_UniversalContactDetail  universalContactDetail = null;

            var BillParam = Parameter.Bill_Parameter.BillHeaderData;

            #region Preloading data

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);
            var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction,
                                                                 new ORM_CMN_BPT_CTM_Customer.Query()
            {
                CMN_BPT_CTM_CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID
            }).SingleOrDefault();

            List <L3ACAAD_GCAfT_1612> customerAddresses = cls_Get_CustomerAddresses_for_CustomerID.Invoke(Connection, Transaction, new P_L3ACAAD_GCAfCID_1612 {
                CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID
            }, securityTicket).Result.ToList();
            L3ACAAD_GCAfT_1612 customerAddress = customerAddresses.Where(x => x.AddressID == BillParam.BillingAddressID).SingleOrDefault();

            var incrNumberParam = new P_L2NR_GaIINfUA_1454()
            {
                GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.BillNumber)
            };
            var billNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber;

            #endregion

            #region Universal Contact Detail

            universalContactDetail = new ORM_CMN_UniversalContactDetail()
            {
                CMN_UniversalContactDetailID = Guid.NewGuid(),
                Country_639_1_ISOCode        = customerAddress.Country_639_1_ISOCode,
                Country_Name      = customerAddress.Country_Name,
                Street_Name       = customerAddress.Street_Name,
                Street_Number     = customerAddress.Street_Number,
                Town              = customerAddress.Town,
                ZIP               = customerAddress.ZIP,
                Tenant_RefID      = account.Tenant_RefID,
                CompanyName_Line1 = BillParam.BillingReceiverCustomer.DisplayName,
                First_Name        = BillParam.BillingReceiverCustomer.FirstName,
                Last_Name         = BillParam.BillingReceiverCustomer.LastName,
                IsCompany         = BillParam.BillingReceiverCustomer.IsCompany
            };
            universalContactDetail.Save(Connection, Transaction);
            #endregion

            #region Bill Header

            billHeader = new ORM_BIL_BillHeader
            {
                BIL_BillHeaderID = Guid.NewGuid(),
                BillNumber       = billNumber,
                CreatedBy_BusinessParticipant_RefID     = account.BusinessParticipant_RefID,
                BillRecipient_BuisnessParticipant_RefID = customer.Ext_BusinessParticipant_RefID,
                TotalValue_BeforeTax     = 0,
                TotalValue_IncludingTax  = 0,
                BillingAddress_UCD_RefID = universalContactDetail.CMN_UniversalContactDetailID,
                DateOnBill     = BillParam.BillingDate,
                BillComment    = BillParam.Comment,
                Currency_RefID = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result.CMN_CurrencyID,
                BillHeader_PaymentCondition_RefID = Parameter.Bill_Parameter.BillHeaderData.PaymentTargetID,
                Tenant_RefID = securityTicket.TenantID
            };

            billHeader.Save(Connection, Transaction);

            #endregion

            #region Method of Payment

            var methodOfPayment = new CL1_BIL.ORM_BIL_BillHeader_MethodOfPayment
            {
                BIL_BillHeader_MethodOfPaymentID = Guid.NewGuid(),
                ACC_PAY_Type_RefID         = Parameter.Bill_Parameter.BillHeaderData.PaymentTypeID,
                BIL_BillHeader_RefID       = billHeader.BIL_BillHeaderID,
                IsPreferredMethodOfPayment = true,
                SequenceNumber             = 0,
                Tenant_RefID = securityTicket.TenantID
            };
            methodOfPayment.Save(Connection, Transaction);

            #endregion

            #region Bill Status - Created

            var statusCreated = ORM_BIL_BillStatus.Query.Search(Connection, Transaction,
                                                                new ORM_BIL_BillStatus.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EBillStatus.Created),
                Tenant_RefID             = account.Tenant_RefID,
                IsDeleted = false
            }).Single();

            billHeader2BillStatus = new ORM_BIL_BillHeader_2_BillStatus
            {
                AssignmentID         = Guid.NewGuid(),
                BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID,
                BIL_BillStatus_RefID = statusCreated.BIL_BillStatusID,
                Tenant_RefID         = account.Tenant_RefID,
                IsCurrentStatus      = true
            };
            billHeader2BillStatus.Save(Connection, Transaction);

            #endregion

            returnValue.Result = billHeader.BIL_BillHeaderID;
            return(returnValue);

            #endregion UserCode
        }
Example #9
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5ACAAD_SOUA_1239 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            var address = new ORM_CMN_BPT_CTM_OrganizationalUnit_Address();
            var universalcontactdetails = new ORM_CMN_UniversalContactDetail();

            if (Parameter.IsDelete)
            {
                var resultAddress = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (address.CMN_BPT_CTM_OrganizationalUnit_AddressID != Guid.Empty)
                {
                    address.IsDeleted = true;
                    address.Save(Connection, Transaction);
                }
                var resultOrgUnit = universalcontactdetails.Load(Connection, Transaction, Parameter.UniversalContactDetailsID);
                if (universalcontactdetails.CMN_UniversalContactDetailID != Guid.Empty)
                {
                    universalcontactdetails.IsDeleted = true;
                    universalcontactdetails.Save(Connection, Transaction);
                }
            }
            else
            {
                if (Parameter.CMN_AddressID != Guid.Empty && Parameter.UniversalContactDetailsID != Guid.Empty)
                {
                    var resultAddress = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                    var resultOrgUnit = universalcontactdetails.Load(Connection, Transaction, Parameter.UniversalContactDetailsID);
                }
                else
                {
                    universalcontactdetails.CMN_UniversalContactDetailID = Guid.NewGuid();
                    universalcontactdetails.Tenant_RefID       = securityTicket.TenantID;
                    universalcontactdetails.Creation_Timestamp = DateTime.Now;
                    universalcontactdetails.IsDeleted          = false;

                    address.CMN_BPT_CTM_OrganizationalUnit_AddressID = Guid.NewGuid();
                    address.OrganizationalUnit_RefID             = Parameter.OrganizationalUnitID;
                    address.UniversalContactDetail_Address_RefID = universalcontactdetails.CMN_UniversalContactDetailID;
                    address.Tenant_RefID       = securityTicket.TenantID;
                    address.Creation_Timestamp = DateTime.Now;
                    address.IsDeleted          = false;
                }

                universalcontactdetails.Country_639_1_ISOCode = Parameter.Country_ISOCode;
                universalcontactdetails.Country_Name          = Parameter.Country_Name;
                universalcontactdetails.Street_Name           = Parameter.StreetName;
                universalcontactdetails.Street_Number         = Parameter.StreetNumber;
                universalcontactdetails.Town       = Parameter.Town;
                universalcontactdetails.ZIP        = Parameter.City_PostalCode;
                universalcontactdetails.IsReadOnly = Parameter.IsReadOnly;
                universalcontactdetails.Save(Connection, Transaction);

                address.AddressType = Parameter.IsBilling ? 2 : 1;
                address.IsPrimary   = Parameter.IsPrimary;
                address.Save(Connection, Transaction);
            }

            returnValue = new FR_Guid(address.CMN_BPT_CTM_OrganizationalUnit_AddressID);
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L6BL_GADfBSBR_1010 Execute(DbConnection Connection, DbTransaction Transaction, P_L6BL_GADfBSBR_1010 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6BL_GADfBSBR_1010();
            //Put your code here

            #region Retrieving bill header.

            ORM_BIL_BillHeader billHeader     = new ORM_BIL_BillHeader();
            FR_Base            billHeaderLoad = billHeader.Load(Connection, Transaction, Parameter.BillHeaderID);
            if (billHeaderLoad.Status != FR_Status.Success)
            {
                Exception ex = new Exception(billHeaderLoad.ErrorMessage);
                return(new FR_L6BL_GADfBSBR_1010(ex));
            }

            #endregion

            #region Retrieving universal contact details.

            ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
            FR_Base universalContactDetailsLoad = universalContactDetails.Load(Connection, Transaction, billHeader.BillingAddress_UCD_RefID);
            if (universalContactDetailsLoad.Status != FR_Status.Success)
            {
                Exception ex = new Exception(universalContactDetailsLoad.ErrorMessage);
                return(new FR_L6BL_GADfBSBR_1010(ex));
            }

            #endregion

            #region Retrieving business participants details.

            ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
            FR_Base businessParticipantLoad = businessParticipant.Load(Connection, Transaction, billHeader.BillRecipient_BuisnessParticipant_RefID);
            if (businessParticipantLoad.Status != FR_Status.Success)
            {
                Exception ex = new Exception(businessParticipantLoad.ErrorMessage);
                return(new FR_L6BL_GADfBSBR_1010(ex));
            }

            #endregion

            #region Retrieving customer details.

            ORM_CMN_BPT_CTM_Customer customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query {
                Ext_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID
            }).FirstOrDefault();
            if (customer == null)
            {
                Exception ex = new Exception("Retrieving ORM_CMN_BPT_CTM_Customer details failed.");
                return(new FR_L6BL_GADfBSBR_1010(ex));
            }

            #endregion

            #region Retriving method of payments (taking first one)

            ORM_BIL_BillHeader_MethodOfPayment methodOfPayment = ORM_BIL_BillHeader_MethodOfPayment.Query.Search(Connection, Transaction, new ORM_BIL_BillHeader_MethodOfPayment.Query
            {
                BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID
            }).FirstOrDefault();

            #endregion

            #region Retrieving payment type

            ORM_ACC_PAY_Type type = null;
            if (methodOfPayment != null)
            {
                type = ORM_ACC_PAY_Type.Query.Search(Connection, Transaction, new ORM_ACC_PAY_Type.Query {
                    ACC_PAY_TypeID = methodOfPayment.ACC_PAY_Type_RefID
                }).Single();
            }

            #endregion

            #region Retrieving payment condition

            ORM_ACC_PAY_Condition condition = ORM_ACC_PAY_Condition.Query.Search(Connection, Transaction, new ORM_ACC_PAY_Condition.Query {
                ACC_PAY_ConditionID = billHeader.BillHeader_PaymentCondition_RefID
            }).FirstOrDefault();

            #endregion


            #region Retrieving bill positions

            var allBillPositions = cls_Get_AllPositions_with_Articles_for_BillHeader.Invoke(Connection, Transaction, new P_L5BL_GAPwAfBH_1118 {
                BillHeaderID = billHeader.BIL_BillHeaderID
            }, securityTicket).Result;


            #endregion


            returnValue.Result = new L6BL_GADfBSBR_1010();
            returnValue.Result.BillShipmentBasedReportHeaderDetails = new L6BL_GADfBSBR_1010a();

            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderComment = billHeader.BillComment;
            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderDate    = billHeader.DateOnBill;
            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderNumber  = billHeader.BillNumber;
            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderTotalValue_BeforeTax    = billHeader.TotalValue_BeforeTax;
            returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderTotalValue_IncludingTax = billHeader.TotalValue_IncludingTax;

            if (condition != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderPaymentDeadline = billHeader.DateOnBill.AddDays(condition.MaximumPaymentTreshold_InDays);
            }
            if (type != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderPaymentType = type.PaymentType_Name;
            }
            if (businessParticipant != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantDisplayName = businessParticipant.DisplayName;
            }
            if (customer != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantNumber = customer.InternalCustomerNumber;
            }
            if (universalContactDetails != null)
            {
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantStreetName   = universalContactDetails.Street_Name;
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantStreetNumber = universalContactDetails.Street_Number;
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantCity         = universalContactDetails.Town;
                returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantZipCode      = universalContactDetails.ZIP;
            }


            #region bill positions

            returnValue.Result.BillPositions = null;
            List <L6BL_GADfBSBR_1010bp> unsortedBillPositionsTemp = new List <L6BL_GADfBSBR_1010bp>();

            if (allBillPositions.ShipmentBillPositions != null)
            {
                var unsortedBillPositions =
                    allBillPositions.ShipmentBillPositions.Where(x => x.BillPosition.CMN_BPT_CTM_OrganizationalUnitID == Guid.Empty).ToList();

                foreach (L5BL_GBPwAfBH_1848 unsortedBillPosition in unsortedBillPositions)
                {
                    L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp();
                    tempBillPosition.BIL_BillPositionID = unsortedBillPosition.BillPosition.BIL_BillPositionID;
                    tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)unsortedBillPosition.BillPosition.PositionPricePerUnitValue_BeforeTax;
                    tempBillPosition.BillPosition_ValuePerUnit_AfterTax  = (double)unsortedBillPosition.BillPosition.PositionPricePerUnitValue_IncludingTax;
                    tempBillPosition.ACC_TAX_TaxeID     = unsortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID;
                    tempBillPosition.TaxRate            = unsortedBillPosition.Article.Taxes.First().TaxRate;
                    tempBillPosition.TaxName_DictID     = unsortedBillPosition.Article.Taxes.First().TaxName_DictID;
                    tempBillPosition.HeaderID           = unsortedBillPosition.BillPosition.LOG_SHP_Shipment_HeaderID;
                    tempBillPosition.Header_Number      = unsortedBillPosition.BillPosition.ShipmentHeader_Number;
                    tempBillPosition.Creation_Timestamp = unsortedBillPosition.BillPosition.LOG_SHP_ShipmentHeader_Creation_Timestamp;
                    tempBillPosition.IsShipmentPosition = true;
                    tempBillPosition.Quantity           = unsortedBillPosition.BillPosition.Quantity;
                    unsortedBillPositionsTemp.Add(tempBillPosition);
                }
            }
            // now for customer orders return
            if (allBillPositions.OrderReturnBillPosition != null)
            {
                var unsortedCustomerOrderReturnPositions =
                    allBillPositions.OrderReturnBillPosition.Where(x => x.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID == Guid.Empty).OrderBy(x => x.OrderReturnBillPosition.DateOfCustomerReturn).ToList();

                foreach (L5OR_GCORPwAfBH_1051 unsortedBillPosition in unsortedCustomerOrderReturnPositions)
                {
                    L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp();
                    tempBillPosition.BIL_BillPositionID = unsortedBillPosition.OrderReturnBillPosition.BIL_BillPositionID;
                    tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)unsortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_BeforeTax;
                    tempBillPosition.BillPosition_ValuePerUnit_AfterTax  = (double)unsortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_IncludingTax;
                    tempBillPosition.ACC_TAX_TaxeID     = unsortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID;
                    tempBillPosition.TaxRate            = unsortedBillPosition.Article.Taxes.First().TaxRate;
                    tempBillPosition.TaxName_DictID     = unsortedBillPosition.Article.Taxes.First().TaxName_DictID;
                    tempBillPosition.HeaderID           = unsortedBillPosition.OrderReturnBillPosition.ORD_CUO_CustomerOrderReturn_HeaderID;
                    tempBillPosition.Header_Number      = unsortedBillPosition.OrderReturnBillPosition.CustomerOrderReturnNumber;
                    tempBillPosition.Creation_Timestamp = unsortedBillPosition.OrderReturnBillPosition.Creation_Timestamp;
                    tempBillPosition.IsShipmentPosition = false;
                    tempBillPosition.Quantity           = unsortedBillPosition.OrderReturnBillPosition.Quantity;
                    unsortedBillPositionsTemp.Add(tempBillPosition);
                }
            }

            returnValue.Result.BillPositions = unsortedBillPositionsTemp.ToArray();


            #region bill position organisation unit

            returnValue.Result.OrganizationalUnits = null;
            List <L6BL_GADfBSBR_1010bo> organizationalUnitsTemp = new List <L6BL_GADfBSBR_1010bo>();

            if (allBillPositions.ShipmentBillPositions != null)
            {
                List <L5BL_GBPwAfBH_1848> sortedBillPositions = allBillPositions.ShipmentBillPositions.Where(x => x.BillPosition.CMN_BPT_CTM_OrganizationalUnitID != Guid.Empty).ToList();

                foreach (L5BL_GBPwAfBH_1848 sortedBillPosition in sortedBillPositions)
                {
                    L6BL_GADfBSBR_1010bo tempOrganizationalUnit = organizationalUnitsTemp.FirstOrDefault(organizationalUnitTemp => organizationalUnitTemp.CMN_BPT_CTM_OrganizationalUnitID == sortedBillPosition.BillPosition.CMN_BPT_CTM_OrganizationalUnitID);


                    if (tempOrganizationalUnit == null)
                    {
                        tempOrganizationalUnit = new L6BL_GADfBSBR_1010bo();
                        tempOrganizationalUnit.BillPositions = new L6BL_GADfBSBR_1010bp[0];

                        tempOrganizationalUnit.CMN_BPT_CTM_OrganizationalUnitID     = sortedBillPosition.BillPosition.CMN_BPT_CTM_OrganizationalUnitID;
                        tempOrganizationalUnit.OrganizationalUnit_SimpleName        = sortedBillPosition.BillPosition.OrganizationalUnit_SimpleName;
                        tempOrganizationalUnit.OrganizationalUnit_Name              = sortedBillPosition.BillPosition.OrganizationalUnit_Name_DictID;
                        tempOrganizationalUnit.OrganizationalUnit_Description       = sortedBillPosition.BillPosition.OrganizationalUnit_Name_DictID;
                        tempOrganizationalUnit.InternalOrganizationalUnitNumber     = sortedBillPosition.BillPosition.InternalOrganizationalUnitNumber;
                        tempOrganizationalUnit.InternalOrganizationalUnitSimpleName = sortedBillPosition.BillPosition.InternalOrganizationalUnitSimpleName;
                        tempOrganizationalUnit.ExternalOrganizationalUnitNumber     = sortedBillPosition.BillPosition.ExternalOrganizationalUnitNumber;

                        organizationalUnitsTemp.Add(tempOrganizationalUnit);
                    }

                    L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp();
                    tempBillPosition.BIL_BillPositionID = sortedBillPosition.BillPosition.BIL_BillPositionID;
                    tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)sortedBillPosition.BillPosition.PositionPricePerUnitValue_BeforeTax;
                    tempBillPosition.BillPosition_ValuePerUnit_AfterTax  = (double)sortedBillPosition.BillPosition.PositionPricePerUnitValue_IncludingTax;
                    tempBillPosition.ACC_TAX_TaxeID     = sortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID;
                    tempBillPosition.TaxRate            = sortedBillPosition.Article.Taxes.First().TaxRate;
                    tempBillPosition.TaxName_DictID     = sortedBillPosition.Article.Taxes.First().TaxName_DictID;
                    tempBillPosition.HeaderID           = sortedBillPosition.BillPosition.LOG_SHP_Shipment_HeaderID;
                    tempBillPosition.Header_Number      = sortedBillPosition.BillPosition.ShipmentHeader_Number;
                    tempBillPosition.Creation_Timestamp = sortedBillPosition.BillPosition.LOG_SHP_ShipmentHeader_Creation_Timestamp;
                    tempBillPosition.IsShipmentPosition = true;
                    tempBillPosition.Quantity           = sortedBillPosition.BillPosition.Quantity;
                    //hate this

                    List <L6BL_GADfBSBR_1010bp> currentBillPositions = tempOrganizationalUnit.BillPositions.ToList();
                    currentBillPositions.Add(tempBillPosition);
                    tempOrganizationalUnit.BillPositions = currentBillPositions.ToArray();
                }
            }

            // now for organization unit in customer order return

            if (allBillPositions.OrderReturnBillPosition != null)
            {
                List <L5OR_GCORPwAfBH_1051> sortedBillPositionsforCustomerOrderReturn = allBillPositions.OrderReturnBillPosition.Where(x => x.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID != Guid.Empty).OrderBy(x => x.OrderReturnBillPosition.DateOfCustomerReturn).ToList();

                foreach (L5OR_GCORPwAfBH_1051 sortedBillPosition in sortedBillPositionsforCustomerOrderReturn)
                {
                    L6BL_GADfBSBR_1010bo tempOrganizationalUnit = organizationalUnitsTemp.FirstOrDefault(organizationalUnitTemp => organizationalUnitTemp.CMN_BPT_CTM_OrganizationalUnitID == sortedBillPosition.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID);


                    if (tempOrganizationalUnit == null)
                    {
                        tempOrganizationalUnit = new L6BL_GADfBSBR_1010bo();
                        tempOrganizationalUnit.BillPositions = new L6BL_GADfBSBR_1010bp[0];

                        tempOrganizationalUnit.CMN_BPT_CTM_OrganizationalUnitID     = sortedBillPosition.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID;
                        tempOrganizationalUnit.OrganizationalUnit_SimpleName        = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_SimpleName;
                        tempOrganizationalUnit.OrganizationalUnit_Name              = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_Name_DictID;
                        tempOrganizationalUnit.OrganizationalUnit_Description       = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_Name_DictID;
                        tempOrganizationalUnit.InternalOrganizationalUnitNumber     = sortedBillPosition.OrderReturnBillPosition.InternalOrganizationalUnitNumber;
                        tempOrganizationalUnit.InternalOrganizationalUnitSimpleName = sortedBillPosition.OrderReturnBillPosition.InternalOrganizationalUnitSimpleName;
                        tempOrganizationalUnit.ExternalOrganizationalUnitNumber     = sortedBillPosition.OrderReturnBillPosition.ExternalOrganizationalUnitNumber;

                        organizationalUnitsTemp.Add(tempOrganizationalUnit);
                    }

                    L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp();
                    tempBillPosition.BIL_BillPositionID = sortedBillPosition.OrderReturnBillPosition.BIL_BillPositionID;
                    tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)sortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_BeforeTax;
                    tempBillPosition.BillPosition_ValuePerUnit_AfterTax  = (double)sortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_IncludingTax;
                    tempBillPosition.ACC_TAX_TaxeID     = sortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID;
                    tempBillPosition.TaxRate            = sortedBillPosition.Article.Taxes.First().TaxRate;
                    tempBillPosition.TaxName_DictID     = sortedBillPosition.Article.Taxes.First().TaxName_DictID;
                    tempBillPosition.HeaderID           = sortedBillPosition.OrderReturnBillPosition.ORD_CUO_CustomerOrderReturn_HeaderID;
                    tempBillPosition.Header_Number      = sortedBillPosition.OrderReturnBillPosition.CustomerOrderReturnNumber;
                    tempBillPosition.Creation_Timestamp = sortedBillPosition.OrderReturnBillPosition.Creation_Timestamp;
                    tempBillPosition.IsShipmentPosition = false;
                    tempBillPosition.Quantity           = sortedBillPosition.OrderReturnBillPosition.Quantity;
                    //hate this

                    List <L6BL_GADfBSBR_1010bp> currentBillPositions = tempOrganizationalUnit.BillPositions.ToList();
                    currentBillPositions.Add(tempBillPosition);
                    tempOrganizationalUnit.BillPositions = currentBillPositions.ToArray();
                }
            }

            returnValue.Result.OrganizationalUnits = organizationalUnitsTemp.ToArray();
            #endregion


            #endregion

            return(returnValue);

            #endregion UserCode
        }
Example #11
0
        public static void Save_practices_to_DB(Practice_Model_from_xlsx Parameter, string connectionString, SessionSecurityTicket securityTicket)
        {
            DbConnection  Connection         = null;
            DbTransaction Transaction        = null;
            bool          cleanupConnection  = Connection == null;
            bool          cleanupTransaction = Transaction == null;

            if (cleanupConnection == true)
            {
                Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(connectionString);
                Connection.Open();
            }
            if (cleanupTransaction == true)
            {
                Transaction = Connection.BeginTransaction();
            }
            try
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");

                var  returnValue           = new FR_Guid();
                Guid companyInfoID         = Guid.NewGuid();
                Guid BusinessParticipantID = Guid.NewGuid();
                Guid PracticeAddressID     = Guid.NewGuid();
                Guid practice_id           = Guid.NewGuid();

                if (!String.IsNullOrEmpty(Parameter.LoginEmail))
                //uncomment this if you've created account
                // if(false)
                {
                    string[] stringUser  = Parameter.LoginEmail.Split('@');
                    string   usernameStr = stringUser[0];

                    try
                    {
                        var practiceAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            AccountSignInEmailAddress = Parameter.LoginEmail,
                        }).Single();

                        var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query();
                        accountGroupQuery.Tenant_RefID             = securityTicket.TenantID;
                        accountGroupQuery.IsDeleted                = false;
                        accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";

                        var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault();

                        if (accountGroup == null)
                        {
                            accountGroup = new ORM_USR_Account_FunctionLevelRights_Group();
                            accountGroup.Tenant_RefID             = securityTicket.TenantID;
                            accountGroup.Label                    = "mm.docconect.doc.app.group";
                            accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group";
                            accountGroup.Creation_Timestamp       = DateTime.Now;
                            accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid();
                            accountGroup.Save(Connection, Transaction);
                        }

                        var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query();
                        functionLevelRightQ.Tenant_RefID             = securityTicket.TenantID;
                        functionLevelRightQ.IsDeleted                = false;
                        functionLevelRightQ.GlobalPropertyMatchingID = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice";

                        var existingunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, functionLevelRightQ).SingleOrDefault();

                        Guid tempFunctionLevelRightID = Guid.Empty;

                        if (existingunctionLevelRight == null)
                        {
                            ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight();
                            functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid();
                            functionLevelRight.FunctionLevelRights_Group_RefID  = accountGroup.USR_Account_FunctionLevelRights_GroupID;
                            functionLevelRight.Tenant_RefID       = securityTicket.TenantID;
                            functionLevelRight.Creation_Timestamp = DateTime.Now;

                            functionLevelRight.RightName = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice";
                            functionLevelRight.GlobalPropertyMatchingID = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice";

                            functionLevelRight.Save(Connection, Transaction);

                            tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID;
                        }
                        else
                        {
                            tempFunctionLevelRightID = existingunctionLevelRight.USR_Account_FunctionLevelRightID;
                        }

                        var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight();
                        accountToFunctionLevelRight.Tenant_RefID             = securityTicket.TenantID;
                        accountToFunctionLevelRight.Creation_Timestamp       = DateTime.Now;
                        accountToFunctionLevelRight.AssignmentID             = Guid.NewGuid();
                        accountToFunctionLevelRight.Account_RefID            = practiceAccountInfo.USR_AccountID;
                        accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID; // USR_Account_FunctionLevelRightID
                        accountToFunctionLevelRight.Save(Connection, Transaction);

                        var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();

                        businessParticipantQ.IsDeleted    = false;
                        businessParticipantQ.Tenant_RefID = securityTicket.TenantID;
                        businessParticipantQ.CMN_BPT_BusinessParticipantID = practiceAccountInfo.BusinessParticipant_RefID;
                        BusinessParticipantID = practiceAccountInfo.BusinessParticipant_RefID;

                        var practiceinfoinBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single();

                        practiceinfoinBusinessParticipant.DisplayName            = Parameter.PracticeName;
                        practiceinfoinBusinessParticipant.IsCompany              = true;
                        practiceinfoinBusinessParticipant.Modification_Timestamp = DateTime.Now;
                        practiceinfoinBusinessParticipant.Save(Connection, Transaction);
                        companyInfoID = practiceinfoinBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;

                        var companyInfo = new ORM_CMN_COM_CompanyInfo.Query();

                        companyInfo.IsDeleted             = false;
                        companyInfo.Tenant_RefID          = securityTicket.TenantID;
                        companyInfo.CMN_COM_CompanyInfoID = companyInfoID;

                        var companyInfoPractice = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfo).Single();
                        companyInfoPractice.CompanyInfo_EstablishmentNumber = Parameter.BSNR;
                        companyInfoPractice.Save(Connection, Transaction);

                        var companyInfoAddressPractice = new ORM_CMN_COM_CompanyInfo_Address();
                        companyInfoAddressPractice.CompanyInfo_RefID   = companyInfoID;
                        companyInfoAddressPractice.IsDefault           = true;
                        companyInfoAddressPractice.IsShipping          = true;
                        companyInfoAddressPractice.IsBilling           = true;
                        companyInfoAddressPractice.Tenant_RefID        = securityTicket.TenantID;
                        companyInfoAddressPractice.Address_UCD_RefID   = Guid.NewGuid();
                        companyInfoAddressPractice.Address_Description = "Standard address for billing, shipping";
                        companyInfoAddressPractice.Save(Connection, Transaction);
                        PracticeAddressID = companyInfoAddressPractice.Address_UCD_RefID;

                        var universlContactPractice = new ORM_CMN_UniversalContactDetail();
                        universlContactPractice.IsDeleted    = false;
                        universlContactPractice.Tenant_RefID = securityTicket.TenantID;
                        universlContactPractice.CMN_UniversalContactDetailID = PracticeAddressID;
                        universlContactPractice.CompanyName_Line1            = Parameter.PracticeName;
                        universlContactPractice.IsCompany              = true;
                        universlContactPractice.Street_Name            = Parameter.Street;
                        universlContactPractice.Street_Number          = Parameter.No;
                        universlContactPractice.ZIP                    = Parameter.Zip;
                        universlContactPractice.Town                   = Parameter.City;
                        universlContactPractice.Contact_Email          = Parameter.MainEmail;
                        universlContactPractice.Contact_Telephone      = Parameter.MainPhone;
                        universlContactPractice.Contact_Fax            = Parameter.Fax;
                        universlContactPractice.Creation_Timestamp     = DateTime.Now;
                        universlContactPractice.Modification_Timestamp = DateTime.Now;
                        universlContactPractice.Save(Connection, Transaction);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Exception occured durng data retrieval in method cls_Save_Practice", ex);
                        //Log the error (uncomment dex variable name and add a line here to write a log.
                    }
                }
                //  else{
                var companyInfoAddress2 = new ORM_CMN_COM_CompanyInfo_Address();
                companyInfoAddress2.IsDeleted           = false;
                companyInfoAddress2.Tenant_RefID        = securityTicket.TenantID;
                companyInfoAddress2.CompanyInfo_RefID   = companyInfoID;
                companyInfoAddress2.IsDefault           = true;
                companyInfoAddress2.IsContact           = true;
                companyInfoAddress2.Address_UCD_RefID   = Guid.NewGuid();
                companyInfoAddress2.Address_Description = "Standard contact person data";
                companyInfoAddress2.Creation_Timestamp  = DateTime.Now;
                companyInfoAddress2.Save(Connection, Transaction);

                string personInfo      = Parameter.ContactPerson;
                string PersonFirstName = "";
                string PersonLastName  = "";
                int    i = personInfo.IndexOf(' ');
                if (i > 1)
                {
                    PersonFirstName = personInfo.Substring(0, i);
                    PersonLastName  = personInfo.Substring(i + 1);
                }
                else
                {
                    PersonFirstName = Parameter.ContactPerson;
                    PersonLastName  = " ";
                }

                var universlContactPractice2 = new ORM_CMN_UniversalContactDetail();
                universlContactPractice2.CMN_UniversalContactDetailID = companyInfoAddress2.Address_UCD_RefID;
                universlContactPractice2.IsDeleted              = false;
                universlContactPractice2.Tenant_RefID           = securityTicket.TenantID;
                universlContactPractice2.IsCompany              = false;
                universlContactPractice2.First_Name             = PersonFirstName;
                universlContactPractice2.Last_Name              = PersonLastName;
                universlContactPractice2.Contact_Email          = Parameter.Email;
                universlContactPractice2.Contact_Telephone      = Parameter.Phone;
                universlContactPractice2.Creation_Timestamp     = DateTime.Now;
                universlContactPractice2.Modification_Timestamp = DateTime.Now;
                universlContactPractice2.Save(Connection, Transaction);

                var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                business2bankAccount.IsDeleted    = false;
                business2bankAccount.Tenant_RefID = securityTicket.TenantID;
                business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID;
                business2bankAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                business2bankAccount.Creation_Timestamp = DateTime.Now;
                business2bankAccount.Save(Connection, Transaction);

                var bankAccountPractice = new ORM_ACC_BNK_BankAccount();
                bankAccountPractice.IsDeleted             = false;
                bankAccountPractice.Tenant_RefID          = securityTicket.TenantID;
                bankAccountPractice.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID;
                bankAccountPractice.OwnerText             = Parameter.AccountHolder;
                bankAccountPractice.IBAN               = Parameter.IBAN;
                bankAccountPractice.Bank_RefID         = Guid.NewGuid();
                bankAccountPractice.Creation_Timestamp = DateTime.Now;
                bankAccountPractice.Save(Connection, Transaction);

                var bank = new ORM_ACC_BNK_Bank();
                bank.IsDeleted          = false;
                bank.Tenant_RefID       = securityTicket.TenantID;
                bank.ACC_BNK_BankID     = bankAccountPractice.Bank_RefID;
                bank.BICCode            = Parameter.Bic;
                bank.BankName           = Parameter.Bank;
                bank.Creation_Timestamp = DateTime.Now;
                bank.Save(Connection, Transaction);

                var customer = new ORM_CMN_BPT_CTM_Customer();
                customer.IsDeleted    = false;
                customer.Tenant_RefID = securityTicket.TenantID;
                customer.Ext_BusinessParticipant_RefID = BusinessParticipantID;
                customer.CMN_BPT_CTM_CustomerID        = Guid.NewGuid();
                customer.Creation_Timestamp            = DateTime.Now;
                customer.Save(Connection, Transaction);

                var organizationalUnit = new ORM_CMN_BPT_CTM_OrganizationalUnit();
                organizationalUnit.IsDeleted         = false;
                organizationalUnit.Tenant_RefID      = securityTicket.TenantID;
                organizationalUnit.Customer_RefID    = customer.CMN_BPT_CTM_CustomerID;
                organizationalUnit.IsMedicalPractice = true;
                organizationalUnit.IfMedicalPractise_HEC_MedicalPractice_RefID = Guid.NewGuid();
                organizationalUnit.Creation_Timestamp     = DateTime.Now;
                organizationalUnit.Modification_Timestamp = DateTime.Now;
                organizationalUnit.Save(Connection, Transaction);

                var medicalPractice = new ORM_HEC_MedicalPractis();

                medicalPractice.IsDeleted              = false;
                medicalPractice.Tenant_RefID           = securityTicket.TenantID;
                medicalPractice.HEC_MedicalPractiseID  = organizationalUnit.IfMedicalPractise_HEC_MedicalPractice_RefID;
                medicalPractice.Creation_Timestamp     = DateTime.Now;
                medicalPractice.Modification_Timestamp = DateTime.Now;
                medicalPractice.Save(Connection, Transaction);

                practice_id = medicalPractice.HEC_MedicalPractiseID;

                var medicalPRactice2Universal = new ORM_HEC_MedicalPractice_2_UniversalProperty();

                medicalPRactice2Universal.IsDeleted    = false;
                medicalPRactice2Universal.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal.Value_Boolean          = Parameter.IsSurgeryPractice;
                medicalPRactice2Universal.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal.Save(Connection, Transaction);

                var practiceUniversal = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal.IsDeleted    = false;
                practiceUniversal.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal.PropertyName           = "Surgery Practice";
                practiceUniversal.IsValue_Boolean        = true;
                practiceUniversal.Creation_Timestamp     = DateTime.Now;
                practiceUniversal.Modification_Timestamp = DateTime.Now;
                practiceUniversal.Save(Connection, Transaction);


                var medicalPRactice2Universal2 = new ORM_HEC_MedicalPractice_2_UniversalProperty();
                medicalPRactice2Universal2.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal2.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal2.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal2.Value_Boolean          = Parameter.IsOrderDrugs;
                medicalPRactice2Universal2.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal2.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal2.Save(Connection, Transaction);

                var practiceUniversal2 = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal2.IsDeleted    = false;
                practiceUniversal2.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal2.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal2.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal2.PropertyName           = "Order Drugs";
                practiceUniversal2.IsValue_Boolean        = true;
                practiceUniversal2.Creation_Timestamp     = DateTime.Now;
                practiceUniversal2.Modification_Timestamp = DateTime.Now;
                practiceUniversal2.Save(Connection, Transaction);


                // default shipping date offset

                var medicalPRactice2Universal3 = new ORM_HEC_MedicalPractice_2_UniversalProperty();
                medicalPRactice2Universal3.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal3.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal3.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal3.Value_Number           = double.Parse(Parameter.DefaultShippingDateOffset);
                medicalPRactice2Universal3.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal3.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal3.Save(Connection, Transaction);

                var practiceUniversal3 = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal3.IsDeleted    = false;
                practiceUniversal3.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal3.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal3.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal3.PropertyName           = "Default Shipping Date Offset";
                practiceUniversal3.IsValue_Number         = true;
                practiceUniversal3.Creation_Timestamp     = DateTime.Now;
                practiceUniversal3.Modification_Timestamp = DateTime.Now;
                practiceUniversal3.Save(Connection, Transaction);

                var medicalPRactice2Universal4 = new ORM_HEC_MedicalPractice_2_UniversalProperty();
                medicalPRactice2Universal4.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal4.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal4.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal4.Value_Boolean          = Parameter.IsOnlyLabelRequired;
                medicalPRactice2Universal4.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal4.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal4.Save(Connection, Transaction);

                var practiceUniversal4 = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal4.IsDeleted    = false;
                practiceUniversal4.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal4.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal4.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal4.PropertyName           = "Only Label Required";
                practiceUniversal4.IsValue_Boolean        = true;
                practiceUniversal4.Creation_Timestamp     = DateTime.Now;
                practiceUniversal4.Modification_Timestamp = DateTime.Now;
                practiceUniversal4.Save(Connection, Transaction);

                var medicalPRactice2Universal5 = new ORM_HEC_MedicalPractice_2_UniversalProperty();
                medicalPRactice2Universal5.Tenant_RefID = securityTicket.TenantID;
                medicalPRactice2Universal5.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                medicalPRactice2Universal5.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid();
                medicalPRactice2Universal5.Value_Boolean          = Parameter.isWaiveServiceFee;
                medicalPRactice2Universal5.Creation_Timestamp     = DateTime.Now;
                medicalPRactice2Universal5.Modification_Timestamp = DateTime.Now;
                medicalPRactice2Universal5.Save(Connection, Transaction);

                var practiceUniversal5 = new ORM_HEC_MedicalPractice_UniversalProperty();
                practiceUniversal5.IsDeleted    = false;
                practiceUniversal5.Tenant_RefID = securityTicket.TenantID;
                practiceUniversal5.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal5.HEC_MedicalPractice_UniversalProperty_RefID;
                practiceUniversal5.PropertyName           = "Waive Service Fee";
                practiceUniversal5.IsValue_Boolean        = true;
                practiceUniversal5.Creation_Timestamp     = DateTime.Now;
                practiceUniversal5.Modification_Timestamp = DateTime.Now;
                practiceUniversal5.Save(Connection, Transaction);

                //   }



                Practice_Doctors_Model DPModel = new Practice_Doctors_Model();
                DPModel.account_status    = "aktiv";
                DPModel.id                = practice_id.ToString();
                DPModel.name              = Parameter.PracticeName;
                DPModel.name_untouched    = Parameter.PracticeName;
                DPModel.salutation        = "";
                DPModel.type              = "Practice";
                DPModel.autocomplete_name = Parameter.PracticeName;
                DPModel.address           = Parameter.Street + " " + Parameter.No;
                DPModel.zip               = Parameter.Zip;
                DPModel.city              = Parameter.City;


                DPModel.bank_untouched = Parameter.Bank != null ? Parameter.Bank : "";
                DPModel.bank           = Parameter.Bank != null ? Parameter.Bank : "";

                if (Parameter.Email != null)
                {
                    DPModel.email = Parameter.MainEmail;
                }

                DPModel.phone = Parameter.MainPhone;
                if (Parameter.IBAN != null)
                {
                    DPModel.iban = Parameter.IBAN;
                }
                if (Parameter.Bic != null)
                {
                    DPModel.bic = Parameter.Bic;
                }

                DPModel.bsnr_lanr      = Parameter.BSNR;
                DPModel.aditional_info = "";
                DPModel.contract       = 0;
                DPModel.tenantid       = securityTicket.TenantID.ToString();
                DPModel.role           = Parameter.IsSurgeryPractice ? "op" : "ac";
                List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>();
                DPModelL.Add(DPModel);

                Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString());


                //Commit the transaction
                if (cleanupTransaction == true)
                {
                    Transaction.Commit();
                }
                //Close the connection
                if (cleanupConnection == true)
                {
                    Connection.Close();
                }
            }



            catch (Exception ex)
            {
                try
                {
                    if (cleanupTransaction == true && Transaction != null)
                    {
                        Transaction.Rollback();
                    }
                }
                catch { }

                try
                {
                    if (cleanupConnection == true && Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch { }

                throw ex;
            }
        }
Example #12
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5DI_SRMP_1425 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            P_L2LN_GALFTID_1530 langParam = new P_L2LN_GALFTID_1530();
            langParam.Tenant_RefID = securityTicket.TenantID;
            var DBLanguages = cls_Get_All_Languages_ForTenantID.Invoke(Connection, Transaction, langParam, securityTicket).Result;

            #region Save
            if (Parameter.HEC_MedicalPractiseID == Guid.Empty)
            {
                ORM_HEC_MedicalPractis medicalPractice = new ORM_HEC_MedicalPractis();
                medicalPractice.HEC_MedicalPractiseID = Guid.NewGuid();
                medicalPractice.IsHospital            = Parameter.IsHospital;
                medicalPractice.Tenant_RefID          = securityTicket.TenantID;
                medicalPractice.IsDeleted             = false;
                medicalPractice.Save(Connection, Transaction);

                //*******************Save Medical Practice Type*******************
                if (Parameter.MedicalPracticeType != null && Parameter.MedicalPracticeType.Count() > 0)
                {
                    foreach (var medicalPracticeTypeParam in Parameter.MedicalPracticeType)
                    {
                        if (!medicalPracticeTypeParam.IsDeleted)
                        {
                            ORM_HEC_MedicalPractice_2_PracticeType medicalPracticeType = new ORM_HEC_MedicalPractice_2_PracticeType();
                            medicalPracticeType.AssignmentID = Guid.NewGuid();
                            medicalPracticeType.HEC_MedicalPractice_Type_RefID = medicalPracticeTypeParam.HEC_MedicalPractice_TypeID;
                            medicalPracticeType.HEC_MedicalPractice_RefID      = medicalPractice.HEC_MedicalPractiseID;
                            medicalPracticeType.Tenant_RefID = securityTicket.TenantID;
                            medicalPracticeType.IsDeleted    = false;
                            medicalPracticeType.Save(Connection, Transaction);
                        }
                    }
                }
                //*******************Save Medical Practice Service*******************
                //on front we must find if medical practice already exist for given service name
                if (Parameter.MedicalService != null && Parameter.MedicalService.Count() > 0)
                {
                    //ORM_HEC_MedicalService medicalService = ORM_HEC_MedicalService.Query.Search(Connection, Transaction, new ORM_HEC_MedicalService.Query
                    //{
                    //    HEC_MedicalServiceID = Parameter.MedicalService.HEC_MedicalServiceID,
                    //    IsDeleted = false,
                    //    Tenant_RefID = securityTicket.TenantID
                    //}).SingleOrDefault();
                    foreach (var medicalServiceParam in Parameter.MedicalService)
                    {
                        ORM_HEC_MedicalService medicalService = new ORM_HEC_MedicalService();
                        if (medicalServiceParam.NewMedicalService)
                        {
                            medicalService.HEC_MedicalServiceID = Guid.NewGuid();
                            medicalService.ServiceName          = medicalServiceParam.ServiceName;
                            medicalService.Tenant_RefID         = securityTicket.TenantID;
                            medicalService.IsDeleted            = false;
                            medicalService.Save(Connection, Transaction);
                        }

                        ORM_HEC_MedicalPractice_OfferedService medicalPracticeOfferedService = new ORM_HEC_MedicalPractice_OfferedService();
                        if (!medicalServiceParam.NewMedicalService)
                        {
                            medicalPracticeOfferedService.MedicalService_RefID = medicalServiceParam.HEC_MedicalServiceID;
                        }
                        else
                        {
                            medicalPracticeOfferedService.MedicalService_RefID = medicalService.HEC_MedicalServiceID;
                        }
                        medicalPracticeOfferedService.MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                        medicalPracticeOfferedService.IsDeleted             = false;
                        medicalPracticeOfferedService.Tenant_RefID          = securityTicket.TenantID;
                        medicalPracticeOfferedService.Save(Connection, Transaction);
                    }
                }
                //*******************Save Contact Person************************

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = Guid.NewGuid();
                personInfo.Title        = Parameter.ContactPersonTitle;
                personInfo.FirstName    = Parameter.ContactPersonFirstName;
                personInfo.LastName     = Parameter.ContactPersonLastName;
                personInfo.Tenant_RefID = securityTicket.TenantID;
                personInfo.IsDeleted    = false;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_BPT_BusinessParticipant businessParticpant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticpant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                businessParticpant.IsNaturalPerson = true;
                businessParticpant.DisplayName     = Parameter.ContactPersonTitle + " " + Parameter.ContactPersonFirstName + " " + Parameter.ContactPersonLastName;
                businessParticpant.Tenant_RefID    = securityTicket.TenantID;
                businessParticpant.IsDeleted       = false;
                businessParticpant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                businessParticpant.Save(Connection, Transaction);

                medicalPractice.ContactPerson_RefID = businessParticpant.CMN_BPT_BusinessParticipantID;

                //*******************Customer OrganizationalUnit************************
                ORM_CMN_BPT_CTM_OrganizationalUnit organizationalUnit = new ORM_CMN_BPT_CTM_OrganizationalUnit();
                organizationalUnit.CMN_BPT_CTM_OrganizationalUnitID = Guid.NewGuid();

                Dict medicationPracticeName = new Dict("hec_dia_potentialdiagnoses");
                for (int i = 0; i < DBLanguages.Length; i++)
                {
                    medicationPracticeName.AddEntry(DBLanguages[i].CMN_LanguageID, Parameter.MedicalPractiseName);
                }

                organizationalUnit.OrganizationalUnit_Name = medicationPracticeName;
                organizationalUnit.IsDeleted           = false;
                organizationalUnit.Tenant_RefID        = securityTicket.TenantID;
                organizationalUnit.Default_PhoneNumber = Parameter.Contact_Telephone;
                organizationalUnit.IsMedicalPractice   = true;
                organizationalUnit.IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                organizationalUnit.Save(Connection, Transaction);

                //*******************AppointmentType************************
                //if (Parameter.AppoitmentType != null && Parameter.AppoitmentType.Count() > 0)
                //{
                //    foreach (var item in Parameter.AppoitmentType)
                //    {
                //        ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability customerOrgUnitAvailability = new ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability();
                //        customerOrgUnitAvailability.PPS_TSK_Task_Template_CustomerOrgUnitAvailabilityID = Guid.NewGuid();
                //        customerOrgUnitAvailability.CMN_BPT_CTM_OrganizationalUnit_RefID = organizationalUnit.CMN_BPT_CTM_OrganizationalUnitID;
                //        customerOrgUnitAvailability.PPS_TSK_Task_Template_RefID = item.PPS_TSK_Task_Template_RefID;
                //        customerOrgUnitAvailability.Tenant_RefID = securityTicket.TenantID;
                //        customerOrgUnitAvailability.Save(Connection, Transaction);
                //    }
                //}
                //*******************Save Address************************
                ORM_CMN_UniversalContactDetail contactDetail = new ORM_CMN_UniversalContactDetail();
                contactDetail.CMN_UniversalContactDetailID = Guid.NewGuid();
                contactDetail.IsCompany           = true;
                contactDetail.Street_Name         = Parameter.Street_Name;
                contactDetail.Street_Number       = Parameter.Street_Number;
                contactDetail.Town                = Parameter.Town;
                contactDetail.Contact_Website_URL = Parameter.Contact_Website_URL;
                contactDetail.Contact_Telephone   = Parameter.Contact_Telephone;
                contactDetail.IsDeleted           = false;
                contactDetail.Tenant_RefID        = securityTicket.TenantID;
                contactDetail.Save(Connection, Transaction);

                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.CMN_COM_CompanyInfoID = Guid.NewGuid();
                companyInfo.Contact_UCD_RefID     = contactDetail.CMN_UniversalContactDetailID;
                companyInfo.IsDeleted             = false;
                companyInfo.Tenant_RefID          = securityTicket.TenantID;
                companyInfo.Save(Connection, Transaction);

                medicalPractice.Ext_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
                medicalPractice.Save(Connection, Transaction);

                //*******************Save Address************************
                //ORM_CMN_UniversalContactDetail contactDetail = new ORM_CMN_UniversalContactDetail();
                //contactDetail.CMN_UniversalContactDetailID = Guid.NewGuid();
                //contactDetail.IsCompany = true;
                //contactDetail.Street_Name = Parameter.Street_Name;
                //contactDetail.Street_Number = Parameter.Street_Number;
                //contactDetail.Town = Parameter.Town;
                //contactDetail.Contact_Website_URL = Parameter.Contact_Website_URL;
                //contactDetail.Contact_Telephone = Parameter.Contact_Telephone;
                //contactDetail.IsDeleted = false;
                //contactDetail.Tenant_RefID = securityTicket.TenantID;
                //contactDetail.Save(Connection, Transaction);

                //ORM_CMN_BPT_CTM_OrganizationalUnit_Address organizationalUnitAddress = new ORM_CMN_BPT_CTM_OrganizationalUnit_Address();
                //organizationalUnitAddress.UniversalContactDetail_Address_RefID = contactDetail.CMN_UniversalContactDetailID;
                //organizationalUnitAddress.OrganizationalUnit_RefID = organizationalUnit.CMN_BPT_CTM_OrganizationalUnitID;
                //organizationalUnitAddress.IsDeleted = false;
                //organizationalUnitAddress.Tenant_RefID = securityTicket.TenantID;
                //organizationalUnitAddress.Save(Connection, Transaction);

                returnValue.Result = medicalPractice.HEC_MedicalPractiseID;
            }
            #endregion
            //=====================Edit or Delete=====================
            else
            {
                ORM_HEC_MedicalPractis medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractis.Query
                {
                    HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID,
                    IsDeleted             = false,
                    Tenant_RefID          = securityTicket.TenantID
                }).Single();
                ORM_CMN_BPT_CTM_OrganizationalUnit organizationalUnit = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query
                {
                    IfMedicalPractise_HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                }).Single();

                #region Edit
                if (Parameter.IsDeleted == false)
                {
                    //*******************Edit Medical Practice Service*******************
                    if (Parameter.MedicalService != null && Parameter.MedicalService.Count() > 0)
                    {
                        foreach (var medicalServiceParam in Parameter.MedicalService)
                        {
                            ORM_HEC_MedicalPractice_OfferedService medicalPracticeOfferedService = ORM_HEC_MedicalPractice_OfferedService.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_OfferedService.Query
                            {
                                HEC_MedicalPractice_OfferedServiceID = medicalServiceParam.HEC_MedicalPractice_OfferedServiceID,
                                IsDeleted    = false,
                                Tenant_RefID = securityTicket.TenantID
                            }).SingleOrDefault();
                            ORM_HEC_MedicalService medicalService = ORM_HEC_MedicalService.Query.Search(Connection, Transaction, new ORM_HEC_MedicalService.Query
                            {
                                HEC_MedicalServiceID = medicalServiceParam.HEC_MedicalServiceID,
                                IsDeleted            = false,
                                Tenant_RefID         = securityTicket.TenantID
                            }).SingleOrDefault();

                            if (medicalServiceParam.NewMedicalService && !medicalServiceParam.IsDeleted)
                            {
                                medicalService = new ORM_HEC_MedicalService();
                                medicalService.HEC_MedicalServiceID = Guid.NewGuid();
                                medicalService.ServiceName          = medicalServiceParam.ServiceName;
                                medicalService.Tenant_RefID         = securityTicket.TenantID;
                                medicalService.IsDeleted            = false;
                                medicalService.Save(Connection, Transaction);
                            }

                            if (medicalPracticeOfferedService == null && !medicalServiceParam.IsDeleted)
                            {
                                medicalPracticeOfferedService = new ORM_HEC_MedicalPractice_OfferedService();
                                if (!medicalServiceParam.NewMedicalService)
                                {
                                    medicalPracticeOfferedService.MedicalService_RefID = medicalServiceParam.HEC_MedicalServiceID;
                                }
                                else
                                {
                                    medicalPracticeOfferedService.MedicalService_RefID = medicalService.HEC_MedicalServiceID;
                                }
                                medicalPracticeOfferedService.MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID;
                                medicalPracticeOfferedService.IsDeleted             = false;
                                medicalPracticeOfferedService.Tenant_RefID          = securityTicket.TenantID;
                                medicalPracticeOfferedService.Save(Connection, Transaction);
                            }
                            else if (medicalPracticeOfferedService != null && !medicalServiceParam.IsDeleted)
                            {
                                medicalPracticeOfferedService.MedicalService_RefID = medicalService.HEC_MedicalServiceID;
                                medicalPracticeOfferedService.Save(Connection, Transaction);
                            }
                            else if (medicalPracticeOfferedService != null && medicalServiceParam.IsDeleted)
                            {
                                medicalPracticeOfferedService.IsDeleted = true;
                                medicalPracticeOfferedService.Save(Connection, Transaction);
                            }
                        }
                    }


                    //*******************Edit Customer OrganizationalUnit************************
                    Dict medicationPracticeName = new Dict("hec_dia_potentialdiagnoses");
                    for (int i = 0; i < DBLanguages.Length; i++)
                    {
                        medicationPracticeName.AddEntry(DBLanguages[i].CMN_LanguageID, Parameter.MedicalPractiseName);
                    }

                    organizationalUnit.OrganizationalUnit_Name = medicationPracticeName;
                    organizationalUnit.Default_PhoneNumber     = Parameter.Contact_Telephone;
                    organizationalUnit.Save(Connection, Transaction);

                    //*******************Edit Contact Person************************
                    ORM_CMN_BPT_BusinessParticipant businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
                    {
                        CMN_BPT_BusinessParticipantID = medicalPractice.ContactPerson_RefID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).Single();
                    businessParticipant.DisplayName = Parameter.ContactPersonTitle + " " + Parameter.ContactPersonFirstName + " " + Parameter.ContactPersonLastName;
                    businessParticipant.Save(Connection, Transaction);

                    ORM_CMN_PER_PersonInfo personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query
                    {
                        CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID,
                        IsDeleted            = false,
                        Tenant_RefID         = securityTicket.TenantID
                    }).Single();
                    personInfo.Title     = Parameter.ContactPersonTitle;
                    personInfo.FirstName = Parameter.ContactPersonFirstName;
                    personInfo.LastName  = Parameter.ContactPersonLastName;
                    personInfo.Save(Connection, Transaction);

                    //*******************Edit Medical Practice Type*******************
                    foreach (var medicalPracticeTypeParam in Parameter.MedicalPracticeType)
                    {
                        ORM_HEC_MedicalPractice_2_PracticeType existingPracticeType = ORM_HEC_MedicalPractice_2_PracticeType.Query.Search(Connection, Transaction, new ORM_HEC_MedicalPractice_2_PracticeType.Query
                        {
                            HEC_MedicalPractice_RefID      = medicalPractice.HEC_MedicalPractiseID,
                            HEC_MedicalPractice_Type_RefID = medicalPracticeTypeParam.HEC_MedicalPractice_TypeID,
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID
                        }).SingleOrDefault();
                        if (existingPracticeType == null && !medicalPracticeTypeParam.IsDeleted)
                        {
                            ORM_HEC_MedicalPractice_2_PracticeType medicalPracticeType = new ORM_HEC_MedicalPractice_2_PracticeType();
                            medicalPracticeType.AssignmentID = Guid.NewGuid();
                            medicalPracticeType.HEC_MedicalPractice_Type_RefID = medicalPracticeTypeParam.HEC_MedicalPractice_TypeID;
                            medicalPracticeType.HEC_MedicalPractice_RefID      = medicalPractice.HEC_MedicalPractiseID;
                            medicalPracticeType.Tenant_RefID = securityTicket.TenantID;
                            medicalPracticeType.IsDeleted    = false;
                            medicalPracticeType.Save(Connection, Transaction);
                        }
                        else if (existingPracticeType != null && !medicalPracticeTypeParam.IsDeleted)
                        {
                            existingPracticeType.HEC_MedicalPractice_Type_RefID = medicalPracticeTypeParam.HEC_MedicalPractice_TypeID;
                            existingPracticeType.Save(Connection, Transaction);
                        }
                        else if (existingPracticeType != null && medicalPracticeTypeParam.IsDeleted)
                        {
                            existingPracticeType.IsDeleted = true;
                            existingPracticeType.Save(Connection, Transaction);
                        }
                    }

                    //*******************Edit AppointmentType*******************
                    //if (Parameter.AppoitmentType != null && Parameter.AppoitmentType.Count() > 0)
                    //{
                    //    foreach (var appointmentTypeParam in Parameter.AppoitmentType)
                    //    {
                    //        ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability existingAppointmentType = ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability.Query.Search(Connection, Transaction, new ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability.Query
                    //        {
                    //            CMN_BPT_CTM_OrganizationalUnit_RefID = organizationalUnit.CMN_BPT_CTM_OrganizationalUnitID,
                    //            PPS_TSK_Task_Template_RefID = appointmentTypeParam.PPS_TSK_Task_Template_RefID,
                    //            IsDeleted = false,
                    //            Tenant_RefID = securityTicket.TenantID
                    //        }).SingleOrDefault();
                    //        if (existingAppointmentType == null & !appointmentTypeParam.IsDeleted)
                    //        {
                    //            ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability customerOrgUnitAvailability = new ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability();
                    //            customerOrgUnitAvailability.PPS_TSK_Task_Template_CustomerOrgUnitAvailabilityID = Guid.NewGuid();
                    //            customerOrgUnitAvailability.CMN_BPT_CTM_OrganizationalUnit_RefID = organizationalUnit.CMN_BPT_CTM_OrganizationalUnitID;
                    //            customerOrgUnitAvailability.PPS_TSK_Task_Template_RefID = appointmentTypeParam.PPS_TSK_Task_Template_RefID;
                    //            customerOrgUnitAvailability.Tenant_RefID = securityTicket.TenantID;
                    //            customerOrgUnitAvailability.Save(Connection, Transaction);
                    //        }
                    //        else if (existingAppointmentType != null & !appointmentTypeParam.IsDeleted)
                    //        {
                    //            existingAppointmentType.PPS_TSK_Task_Template_RefID = appointmentTypeParam.PPS_TSK_Task_Template_RefID;
                    //            existingAppointmentType.Save(Connection, Transaction);
                    //        }
                    //        else if (existingAppointmentType != null & !appointmentTypeParam.IsDeleted)
                    //        {
                    //            existingAppointmentType.IsDeleted = true;
                    //            existingAppointmentType.Save(Connection, Transaction);
                    //        }
                    //    }
                    //}
                    //*******************Edit Address and name************************
                    ORM_CMN_COM_CompanyInfo companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo.Query
                    {
                        CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID,
                        IsDeleted             = false,
                        Tenant_RefID          = securityTicket.TenantID
                    }).Single();

                    ORM_CMN_UniversalContactDetail contactDetail = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query
                    {
                        CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).Single();
                    contactDetail.Street_Name         = Parameter.Street_Name;
                    contactDetail.Street_Number       = Parameter.Street_Number;
                    contactDetail.Town                = Parameter.Town;
                    contactDetail.Contact_Website_URL = Parameter.Contact_Website_URL;
                    contactDetail.Contact_Telephone   = Parameter.Contact_Telephone;
                    contactDetail.Save(Connection, Transaction);

                    returnValue.Result = medicalPractice.HEC_MedicalPractiseID;
                }
                #endregion
                #region Delete
                else
                {
                    ORM_HEC_MedicalPractice_2_PracticeType.Query.SoftDelete(Connection, Transaction, new ORM_HEC_MedicalPractice_2_PracticeType.Query
                    {
                        HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    });

                    ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability.Query.SoftDelete(Connection, Transaction, new ORM_PPS_TSK_Task_Template_CustomerOrgUnitAvailability.Query
                    {
                        CMN_BPT_CTM_OrganizationalUnit_RefID = organizationalUnit.CMN_BPT_CTM_OrganizationalUnitID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    });

                    ORM_HEC_MedicalPractice_OfferedService.Query.SoftDelete(Connection, Transaction, new ORM_HEC_MedicalPractice_OfferedService.Query
                    {
                        MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID,
                        IsDeleted             = false,
                        Tenant_RefID          = securityTicket.TenantID
                    });

                    ORM_CMN_BPT_BusinessParticipant businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
                    {
                        CMN_BPT_BusinessParticipantID = medicalPractice.ContactPerson_RefID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).Single();
                    businessParticipant.IsDeleted = true;
                    ORM_CMN_PER_PersonInfo personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query
                    {
                        CMN_PER_PersonInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID,
                        IsDeleted            = false,
                        Tenant_RefID         = securityTicket.TenantID
                    }).Single();
                    personInfo.IsDeleted = true;
                    ORM_CMN_COM_CompanyInfo companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo.Query
                    {
                        CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID,
                        IsDeleted             = false,
                        Tenant_RefID          = securityTicket.TenantID
                    }).Single();
                    companyInfo.IsDeleted = true;
                    ORM_CMN_UniversalContactDetail contactDetail = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query
                    {
                        CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).Single();
                    contactDetail.IsDeleted = true;

                    ORM_HEC_MedicalPractis.Query.SoftDelete(Connection, Transaction, new ORM_HEC_MedicalPractis.Query
                    {
                        HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID,
                        IsDeleted             = false,
                        Tenant_RefID          = securityTicket.TenantID
                    });
                    contactDetail.Save(Connection, Transaction);
                    companyInfo.Save(Connection, Transaction);
                    personInfo.Save(Connection, Transaction);
                    businessParticipant.Save(Connection, Transaction);
                }
                #endregion
                returnValue.Result = medicalPractice.HEC_MedicalPractiseID;
            }
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MP_SPBI_1602 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_HEC_MedicalPractis practices;
            if (Parameter.HEC_MedicalPractiseID != Guid.Empty)
            {
                var practicesQuery = new ORM_HEC_MedicalPractis.Query();
                practicesQuery.HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID;
                practices = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practicesQuery).First();
            }
            else
            {
                practices = new ORM_HEC_MedicalPractis();
                practices.HEC_MedicalPractiseID = Guid.NewGuid();
            }
            practices.Tenant_RefID = securityTicket.TenantID;
            if (Parameter.isLucentis == false)
            {
                practices.Contact_EmergencyPhoneNumber = Parameter.Contact_EmergencyPhoneNumber;
            }

            ORM_CMN_COM_CompanyInfo companyInfo;
            if (practices.Ext_CompanyInfo_RefID != Guid.Empty)
            {
                var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
                companyInfoQuery.CMN_COM_CompanyInfoID = practices.Ext_CompanyInfo_RefID;
                companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First();
            }
            else
            {
                companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.CMN_COM_CompanyInfoID = Guid.NewGuid();
                practices.Ext_CompanyInfo_RefID   = companyInfo.CMN_COM_CompanyInfoID;
            }
            companyInfo.Tenant_RefID = securityTicket.TenantID;
            if (Parameter.isLucentis)
            {
                companyInfo.CompanyInfo_EstablishmentNumber = Parameter.ifLucentis_BSNR;
            }

            ORM_CMN_BPT_BusinessParticipant bParticipant;
            var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            bParticipantQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            var bpRes = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery);
            if (bpRes.Count == 0)
            {
                bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bParticipant.IsCompany = true;
                bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            }
            else
            {
                bParticipant = bpRes.First();
            }
            bParticipant.DisplayName  = Parameter.PracticeName;
            bParticipant.Tenant_RefID = securityTicket.TenantID;


            ORM_CMN_UniversalContactDetail contactDetails;
            if (companyInfo.Contact_UCD_RefID != Guid.Empty)
            {
                var ucdQuery = new ORM_CMN_UniversalContactDetail.Query();
                ucdQuery.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                contactDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, ucdQuery).First();
            }
            else
            {
                contactDetails = new ORM_CMN_UniversalContactDetail();
                contactDetails.CMN_UniversalContactDetailID = Guid.NewGuid();
                companyInfo.Contact_UCD_RefID = contactDetails.CMN_UniversalContactDetailID;
                contactDetails.IsCompany      = true;
            }
            contactDetails.Tenant_RefID = securityTicket.TenantID;
            if (Parameter.isLucentis == false)
            {
                contactDetails.Contact_Website_URL = Parameter.Contact_Website_URL;
            }
            contactDetails.Contact_Email = Parameter.PracticeEmail;
            contactDetails.Town          = Parameter.Town;
            contactDetails.Street_Number = Parameter.Street_Number;
            contactDetails.Street_Name   = Parameter.Street_Name;
            contactDetails.ZIP           = Parameter.ZIP;
            if (Parameter.isLucentis == false)
            {
                contactDetails.Region_Name = Parameter.Region_Name;
            }
            if (Parameter.isLucentis)
            {
                contactDetails.Street_Name_Line2 = Parameter.Street_Name_Line2;
            }

            companyInfo.Save(Connection, Transaction);
            bParticipant.Save(Connection, Transaction);
            contactDetails.Save(Connection, Transaction);
            practices.Save(Connection, Transaction);

            returnValue.Result = practices.HEC_MedicalPractiseID;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5ACACU_SCC_1051 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            if (Parameter.IsDelete && (Parameter.CMN_BPT_CTM_CustomerID == Guid.Empty))
            {
                return(returnValue);
            }

            ORM_CMN_BPT_CTM_Customer customer;
            if (Parameter.CMN_BPT_CTM_CustomerID != Guid.Empty)
            {
                var customerQ = new ORM_CMN_BPT_CTM_Customer.Query();
                customerQ.Tenant_RefID           = securityTicket.TenantID;
                customerQ.IsDeleted              = false;
                customerQ.CMN_BPT_CTM_CustomerID = Parameter.CMN_BPT_CTM_CustomerID;
                customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQ).First();
                customer.InternalCustomerNumber = Parameter.Number;
                customer.IsCustomerOrderAutomaticallyApprovedOnReceipt =
                    Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            }
            else
            {
                customer = new ORM_CMN_BPT_CTM_Customer();
                customer.Tenant_RefID           = securityTicket.TenantID;
                customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid();
                customer.InternalCustomerNumber = Parameter.Number;
                customer.IsCustomerOrderAutomaticallyApprovedOnReceipt =
                    Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt;
            }

            ORM_CMN_BPT_CTM_AvailablePaymentType customer2PaymentType;

            var customer2PaymentTypeQ = new ORM_CMN_BPT_CTM_AvailablePaymentType.Query();
            customer2PaymentTypeQ.Tenant_RefID   = securityTicket.TenantID;
            customer2PaymentTypeQ.IsDeleted      = false;
            customer2PaymentTypeQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;

            customer2PaymentType = ORM_CMN_BPT_CTM_AvailablePaymentType.Query.Search(Connection, Transaction, customer2PaymentTypeQ).FirstOrDefault();
            if (customer2PaymentType == null)
            {
                customer2PaymentType = new ORM_CMN_BPT_CTM_AvailablePaymentType();
                customer2PaymentType.ACC_PAY_Type_RefID = Guid.NewGuid();
                customer2PaymentType.Tenant_RefID       = securityTicket.TenantID;
                customer2PaymentType.Customer_RefID     = customer.CMN_BPT_CTM_CustomerID;
            }
            customer2PaymentType.ACC_PAY_Type_RefID = Parameter.PaymentTypeID;
            customer2PaymentType.Save(Connection, Transaction);

            #region payment condition

            ORM_CMN_BPT_CTM_AvailablePaymentCondition customer2PaymentCondition;

            var customer2PaymentConditionQ = new ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query();
            customer2PaymentConditionQ.Tenant_RefID   = securityTicket.TenantID;
            customer2PaymentConditionQ.IsDeleted      = false;
            customer2PaymentConditionQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;

            customer2PaymentCondition = ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query.Search(Connection, Transaction, customer2PaymentConditionQ).FirstOrDefault();
            if (customer2PaymentCondition == null)
            {
                customer2PaymentCondition = new ORM_CMN_BPT_CTM_AvailablePaymentCondition();
                customer2PaymentCondition.ACC_PAY_Condition_RefID = Guid.NewGuid();
                customer2PaymentCondition.Tenant_RefID            = securityTicket.TenantID;
                customer2PaymentCondition.Customer_RefID          = customer.CMN_BPT_CTM_CustomerID;
            }
            customer2PaymentCondition.ACC_PAY_Condition_RefID = Parameter.PaymentConditionID;
            customer2PaymentCondition.Save(Connection, Transaction);

            #endregion

            ORM_CMN_BPT_BusinessParticipant bParticipant;
            if (customer.Ext_BusinessParticipant_RefID != Guid.Empty)
            {
                var bParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query();
                bParticipantQ.Tenant_RefID = securityTicket.TenantID;
                bParticipantQ.IsDeleted    = false;
                bParticipantQ.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID;
                bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQ).First();
            }
            else
            {
                bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Tenant_RefID = securityTicket.TenantID;
                bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bParticipant.IsCompany = true;
                customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            }

            bParticipant.DisplayName = Parameter.FirmName;

            ORM_CMN_COM_CompanyInfo company;
            if (bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID != Guid.Empty)
            {
                var companyQ = new ORM_CMN_COM_CompanyInfo.Query();
                companyQ.Tenant_RefID          = securityTicket.TenantID;
                companyQ.IsDeleted             = false;
                companyQ.CMN_COM_CompanyInfoID = bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                company = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyQ).First();
            }
            else
            {
                company = new ORM_CMN_COM_CompanyInfo();
                company.Tenant_RefID          = securityTicket.TenantID;
                company.CMN_COM_CompanyInfoID = Guid.NewGuid();
                bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = company.CMN_COM_CompanyInfoID;
            }

            ORM_CMN_UniversalContactDetail ucd;
            if (company.Contact_UCD_RefID != Guid.Empty)
            {
                var ucdQ = new ORM_CMN_UniversalContactDetail.Query();
                ucdQ.Tenant_RefID = securityTicket.TenantID;
                ucdQ.IsDeleted    = false;
                ucdQ.CMN_UniversalContactDetailID = company.Contact_UCD_RefID;
                ucd = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, ucdQ).First();
            }
            else
            {
                ucd = new ORM_CMN_UniversalContactDetail();
                ucd.Tenant_RefID = securityTicket.TenantID;
                ucd.CMN_UniversalContactDetailID = Guid.NewGuid();
                ucd.IsCompany             = true;
                company.Contact_UCD_RefID = ucd.CMN_UniversalContactDetailID;
            }

            ucd.CompanyName_Line1  = Parameter.FirmName;
            ucd.CompanyName_Line2  = Parameter.Additional;
            ucd.IsDeleted          = Parameter.IsDelete;
            company.IsDeleted      = Parameter.IsDelete;
            bParticipant.IsDeleted = Parameter.IsDelete;
            customer.IsDeleted     = Parameter.IsDelete;

            ucd.Save(Connection, Transaction);
            company.Save(Connection, Transaction);
            bParticipant.Save(Connection, Transaction);
            customer.Save(Connection, Transaction);

            returnValue.Result = customer.CMN_BPT_CTM_CustomerID;

            return(returnValue);

            #endregion UserCode
        }
Example #15
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PH_SP_1226 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_HEC_Pharmacy item = new ORM_HEC_Pharmacy();


            if (Parameter.PharmacyID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.PharmacyID);
                if (result.Status != FR_Status.Success)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }

                #region Delete

                if (Parameter.IsDeleted)
                {
                    //Contact person data finding and deleting
                    var query_BusinessParticipant_ContactPerson_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BusinessParticipant_ContactPerson_del.CMN_BPT_BusinessParticipantID = item.ContactPerson_BusinessParticipant_RefID;
                    query_BusinessParticipant_ContactPerson_del.Tenant_RefID = item.Tenant_RefID;

                    ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_ContactPerson_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_ContactPerson_del).First();
                    found_BusinessParticipant_ContactPerson_del.IsDeleted = true;

                    var query_PersonInfo_del = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo_del.CMN_PER_PersonInfoID = found_BusinessParticipant_ContactPerson_del.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    ORM_CMN_PER_PersonInfo found_PersonInfo_del = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo_del).First();
                    found_PersonInfo_del.IsDeleted = true;

                    var query_CommunicationContact_del = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact_del.PersonInfo_RefID = found_PersonInfo_del.CMN_PER_PersonInfoID;

                    ORM_CMN_PER_CommunicationContact found_CommunicationContact_del = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact_del).First();
                    found_CommunicationContact_del.IsDeleted = true;

                    found_BusinessParticipant_ContactPerson_del.Save(Connection, Transaction);
                    found_CommunicationContact_del.Save(Connection, Transaction);
                    found_PersonInfo_del.Save(Connection, Transaction);


                    //Company (pharmacy) finding and deleting

                    var query_CompanyInfo_del = new ORM_CMN_COM_CompanyInfo.Query();
                    query_CompanyInfo_del.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                    ORM_CMN_COM_CompanyInfo found_CompanyInfo_del = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo_del).First();
                    found_CompanyInfo_del.IsDeleted = true;

                    var query_CompanyContactDetails_del = new ORM_CMN_UniversalContactDetail.Query();
                    query_CompanyContactDetails_del.CMN_UniversalContactDetailID = found_CompanyInfo_del.Contact_UCD_RefID;

                    ORM_CMN_UniversalContactDetail found_CompanyContactDetails_del = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_CompanyContactDetails_del).First();
                    found_CompanyContactDetails_del.IsDeleted = true;

                    var query_BusinessParticipant_Company_del = new ORM_CMN_BPT_BusinessParticipant.Query();
                    query_BusinessParticipant_Company_del.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo_del.CMN_COM_CompanyInfoID;

                    ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_Company_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_Company_del).First();
                    found_BusinessParticipant_Company_del.IsDeleted = true;

                    found_CompanyInfo_del.Save(Connection, Transaction);
                    found_CompanyContactDetails_del.Save(Connection, Transaction);
                    found_BusinessParticipant_Company_del.Save(Connection, Transaction);

                    item.IsDeleted = true;
                    return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_PharmacyID));
                }

                #endregion

                #region Edit

                //Contact person data finding and edit

                var query_BusinessParticipant_ContactPerson = new ORM_CMN_BPT_BusinessParticipant.Query();
                query_BusinessParticipant_ContactPerson.CMN_BPT_BusinessParticipantID = item.ContactPerson_BusinessParticipant_RefID;
                query_BusinessParticipant_ContactPerson.Tenant_RefID = item.Tenant_RefID;

                ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_ContactPerson = new ORM_CMN_BPT_BusinessParticipant();
                if (item.ContactPerson_BusinessParticipant_RefID != null && item.ContactPerson_BusinessParticipant_RefID != Guid.Empty)
                {
                    found_BusinessParticipant_ContactPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_ContactPerson).First();
                }
                else
                {
                    found_BusinessParticipant_ContactPerson = null;
                }
                if (found_BusinessParticipant_ContactPerson != null)
                {
                    var query_PersonInfo = new ORM_CMN_PER_PersonInfo.Query();
                    query_PersonInfo.CMN_PER_PersonInfoID = found_BusinessParticipant_ContactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID;

                    ORM_CMN_PER_PersonInfo found_PersonInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo).First();
                    found_PersonInfo.FirstName    = Parameter.ContactFirstName;
                    found_PersonInfo.LastName     = Parameter.ContactLastName;
                    found_PersonInfo.PrimaryEmail = Parameter.ContactEmail;

                    var query_CommunicationContact = new ORM_CMN_PER_CommunicationContact.Query();
                    query_CommunicationContact.PersonInfo_RefID = found_PersonInfo.CMN_PER_PersonInfoID;

                    ORM_CMN_PER_CommunicationContact found_CommunicationContact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact).First();
                    found_CommunicationContact.Content = Parameter.ContactPhoneNumber;

                    found_CommunicationContact.Save(Connection, Transaction);
                    found_PersonInfo.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                    Guid businessParticipantID = Guid.NewGuid();

                    contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantID;
                    contactPerson.IsCompany          = false;
                    contactPerson.IsNaturalPerson    = true;
                    contactPerson.IsTenant           = false;
                    contactPerson.Creation_Timestamp = DateTime.Now;
                    contactPerson.Tenant_RefID       = securityTicket.TenantID;

                    item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;

                    //person info
                    ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                    Guid personInfoID = Guid.NewGuid();

                    contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                    contactPerson.Save(Connection, Transaction);

                    personInfo.CMN_PER_PersonInfoID = personInfoID;
                    personInfo.FirstName            = Parameter.ContactFirstName;
                    personInfo.LastName             = Parameter.ContactLastName;
                    personInfo.PrimaryEmail         = Parameter.ContactEmail;
                    personInfo.Creation_Timestamp   = DateTime.Now;
                    personInfo.Tenant_RefID         = securityTicket.TenantID;

                    personInfo.Save(Connection, Transaction);

                    //Communication Contact
                    ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                    communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                    communicationContacts.PersonInfo_RefID   = personInfoID;
                    communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                    communicationContacts.Content            = Parameter.ContactPhoneNumber;
                    communicationContacts.Creation_Timestamp = DateTime.Now;
                    communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                    communicationContacts.Save(Connection, Transaction);


                    item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;
                    item.Save(Connection, Transaction);
                }

                //Company (pharmacy) finding and edit

                var query_CompanyInfo = new ORM_CMN_COM_CompanyInfo.Query();
                query_CompanyInfo.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID;

                ORM_CMN_COM_CompanyInfo found_CompanyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo).First();

                var query_CompanyContactDetails = new ORM_CMN_UniversalContactDetail.Query();
                query_CompanyContactDetails.CMN_UniversalContactDetailID = found_CompanyInfo.Contact_UCD_RefID;

                ORM_CMN_UniversalContactDetail found_CompanyContactDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_CompanyContactDetails).FirstOrDefault();
                if (found_CompanyContactDetails != null)
                {
                    found_CompanyContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                    found_CompanyContactDetails.Contact_Email     = Parameter.MainEmail;
                    found_CompanyContactDetails.Street_Name       = Parameter.Street;
                    found_CompanyContactDetails.Street_Number     = Parameter.Number;
                    found_CompanyContactDetails.Street_Name_Line2 = Parameter.Street2;
                    found_CompanyContactDetails.Town = Parameter.Town;
                    found_CompanyContactDetails.ZIP  = Parameter.ZIP;
                    found_CompanyContactDetails.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
                    universalContactDetails.CMN_UniversalContactDetailID = Guid.NewGuid();
                    universalContactDetails.IsCompany         = true;
                    universalContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                    universalContactDetails.Street_Name       = Parameter.Street;
                    universalContactDetails.Street_Name_Line2 = Parameter.Street2;
                    universalContactDetails.Street_Number     = Parameter.Number;
                    universalContactDetails.Contact_Email     = Parameter.MainEmail;
                    universalContactDetails.ZIP          = Parameter.ZIP;
                    universalContactDetails.Town         = Parameter.Town;
                    universalContactDetails.Tenant_RefID = securityTicket.TenantID;


                    universalContactDetails.Save(Connection, Transaction);

                    found_CompanyInfo.Contact_UCD_RefID = universalContactDetails.CMN_UniversalContactDetailID;
                    found_CompanyInfo.Save(Connection, Transaction);
                }

                var query_BusinessParticipant_Company = new ORM_CMN_BPT_BusinessParticipant.Query();
                query_BusinessParticipant_Company.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo.CMN_COM_CompanyInfoID;

                ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_Company = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_Company).First();
                found_BusinessParticipant_Company.DisplayName = Parameter.PharmacyName;


                found_BusinessParticipant_Company.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                #region Save

                item.HEC_PharmacyID = Guid.NewGuid();

                item.Creation_Timestamp = DateTime.Now;
                item.Tenant_RefID       = securityTicket.TenantID;

                //business Participants
                ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant();
                Guid businessParticipantID = Guid.NewGuid();

                contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantID;
                contactPerson.IsCompany          = false;
                contactPerson.IsNaturalPerson    = true;
                contactPerson.IsTenant           = false;
                contactPerson.Creation_Timestamp = DateTime.Now;
                contactPerson.Tenant_RefID       = securityTicket.TenantID;

                item.ContactPerson_BusinessParticipant_RefID = businessParticipantID;

                //person info
                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                Guid personInfoID = Guid.NewGuid();

                contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID;
                contactPerson.Save(Connection, Transaction);

                personInfo.CMN_PER_PersonInfoID = personInfoID;
                personInfo.FirstName            = Parameter.ContactFirstName;
                personInfo.LastName             = Parameter.ContactLastName;
                personInfo.PrimaryEmail         = Parameter.ContactEmail;
                personInfo.Creation_Timestamp   = DateTime.Now;
                personInfo.Tenant_RefID         = securityTicket.TenantID;

                personInfo.Save(Connection, Transaction);

                //Communication Contact
                ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact();

                communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid();
                communicationContacts.PersonInfo_RefID   = personInfoID;
                communicationContacts.Contact_Type       = Parameter.ContactTypePhone;
                communicationContacts.Content            = Parameter.ContactPhoneNumber;
                communicationContacts.Creation_Timestamp = DateTime.Now;
                communicationContacts.Tenant_RefID       = securityTicket.TenantID;

                communicationContacts.Save(Connection, Transaction);

                //ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                //Guid companyInfoID = Guid.NewGuid();

                ORM_CMN_COM_CompanyInfo extCompanyInfo = new ORM_CMN_COM_CompanyInfo();
                Guid extCompanyInfoID = Guid.NewGuid();
                extCompanyInfo.CMN_COM_CompanyInfoID = extCompanyInfoID;
                Guid contactUCDID = Guid.NewGuid();
                extCompanyInfo.Contact_UCD_RefID  = contactUCDID;
                extCompanyInfo.Creation_Timestamp = DateTime.Now;
                extCompanyInfo.Tenant_RefID       = securityTicket.TenantID;

                item.Ext_CompanyInfo_RefID = extCompanyInfoID;

                ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
                universalContactDetails.CMN_UniversalContactDetailID = contactUCDID;
                universalContactDetails.IsCompany         = true;
                universalContactDetails.CompanyName_Line1 = Parameter.PharmacyName;
                universalContactDetails.Street_Name       = Parameter.Street;
                universalContactDetails.Street_Name_Line2 = Parameter.Street2;
                universalContactDetails.Street_Number     = Parameter.Number;
                universalContactDetails.Contact_Email     = Parameter.MainEmail;
                universalContactDetails.ZIP          = Parameter.ZIP;
                universalContactDetails.Town         = Parameter.Town;
                universalContactDetails.Tenant_RefID = securityTicket.TenantID;

                ORM_CMN_BPT_BusinessParticipant extCompany = new ORM_CMN_BPT_BusinessParticipant();
                extCompany.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                extCompany.Creation_Timestamp            = DateTime.Now;
                extCompany.Tenant_RefID    = securityTicket.TenantID;
                extCompany.DisplayName     = Parameter.PharmacyName;
                extCompany.IsCompany       = true;
                extCompany.IsNaturalPerson = false;
                extCompany.IsTenant        = false;
                extCompany.IsDeleted       = false;
                extCompany.IfCompany_CMN_COM_CompanyInfo_RefID = extCompanyInfoID;

                extCompany.Save(Connection, Transaction);
                extCompanyInfo.Save(Connection, Transaction);
                universalContactDetails.Save(Connection, Transaction);
                item.Save(Connection, Transaction);

                returnValue.Result = item.HEC_PharmacyID;
                #endregion
            }

            return(returnValue);

            #endregion UserCode
        }
Example #16
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5HI_SHI_1158 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();



            FR_Base result = new FR_Base();
            //Put your code here
            var item = new ORM_HEC_HIS_HealthInsurance_Company();
            if (Parameter.HEC_HealthInsurance_CompanyID != Guid.Empty)
            {
                result = item.Load(Connection, Transaction, Parameter.HEC_HealthInsurance_CompanyID);
                if (result.Status != FR_Status.Success || item.HEC_HealthInsurance_CompanyID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            item.HealthInsurance_IKNumber = Parameter.HealthInsurance_IKNumber;
            item.Tenant_RefID             = securityTicket.TenantID;

            ORM_CMN_BPT_BusinessParticipant bpart = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
            {
                CMN_BPT_BusinessParticipantID = item.CMN_BPT_BusinessParticipant_RefID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).FirstOrDefault();
            if (bpart == null || bpart.CMN_BPT_BusinessParticipantID == Guid.Empty)
            {
                bpart = new ORM_CMN_BPT_BusinessParticipant();
            }
            bpart.DisplayName  = Parameter.CompanyName;
            bpart.Tenant_RefID = securityTicket.TenantID;


            item.CMN_BPT_BusinessParticipant_RefID = bpart.CMN_BPT_BusinessParticipantID;

            ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
            result = companyInfo.Load(Connection, Transaction, bpart.IfCompany_CMN_COM_CompanyInfo_RefID);
            if (result.Status != FR_Status.Success || companyInfo.CMN_COM_CompanyInfoID == Guid.Empty)
            {
                companyInfo = new ORM_CMN_COM_CompanyInfo();
            }
            bpart.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            bpart.Save(Connection, Transaction);

            ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
            result = ucd.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);
            if (result.Status != FR_Status.Success || ucd.CMN_UniversalContactDetailID == Guid.Empty)
            {
                ucd = new ORM_CMN_UniversalContactDetail();
            }
            companyInfo.Tenant_RefID      = securityTicket.TenantID;
            companyInfo.Contact_UCD_RefID = ucd.CMN_UniversalContactDetailID;
            companyInfo.Save(Connection, Transaction);


            returnValue.Result = item.HEC_HealthInsurance_CompanyID;

            if (Parameter.Country_ISO != "")
            {
                ucd.Country_639_1_ISOCode = Parameter.Country_ISO;
                ucd.Town         = Parameter.Town;
                ucd.Tenant_RefID = securityTicket.TenantID;
            }
            ucd.Save(Connection, Transaction);

            item.Save(Connection, Transaction);


            return(returnValue);

            #endregion UserCode
        }
Example #17
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3TX_STXO_0929 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            var item        = new ORM_ACC_TAX_TaxOffice();
            if (Parameter.ACC_TAX_TaxOfficeID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.ACC_TAX_TaxOfficeID);
                if (result.Status != FR_Status.Success || item.ACC_TAX_TaxOfficeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }

                ORM_CMN_BPT_BusinessParticipant.Query bptQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                bptQuery.CMN_BPT_BusinessParticipantID = item.CMN_BPT_BusinessParticipant_RefID;
                bptQuery.Tenant_RefID = securityTicket.TenantID;
                bptQuery.IsDeleted    = false;

                ORM_CMN_BPT_BusinessParticipant bparticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bptQuery).FirstOrDefault();

                bparticipant.DisplayName = Parameter.DisplayName;
                bparticipant.Save(Connection, Transaction);

                ORM_CMN_COM_CompanyInfo.Query cmpInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
                cmpInfoQuery.CMN_COM_CompanyInfoID = bparticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                cmpInfoQuery.IsDeleted             = false;
                cmpInfoQuery.Tenant_RefID          = securityTicket.TenantID;

                ORM_CMN_COM_CompanyInfo companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, cmpInfoQuery).FirstOrDefault();
                companyInfo.VATIdentificationNumber = Parameter.VATIdentificationNumber;
                companyInfo.Save(Connection, Transaction);
                returnValue.Result = item.ACC_TAX_TaxOfficeID;

                if (companyInfo.Contact_UCD_RefID != Guid.Empty)
                {
                    var countries = cls_Get_AllCountries.Invoke(Connection, Transaction, securityTicket).Result;

                    ORM_CMN_UniversalContactDetail.Query ucdQuery = new ORM_CMN_UniversalContactDetail.Query();
                    ucdQuery.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                    ucdQuery.Tenant_RefID = securityTicket.TenantID;
                    ucdQuery.IsDeleted    = false;

                    ORM_CMN_UniversalContactDetail ucd = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, ucdQuery).FirstOrDefault();
                    ucd.Country_639_1_ISOCode = Parameter.Country_ISO;
                    ucd.Save(Connection, Transaction);
                }
            }
            else
            {
                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.VATIdentificationNumber = Parameter.VATIdentificationNumber;
                companyInfo.Tenant_RefID            = securityTicket.TenantID;


                ORM_CMN_BPT_BusinessParticipant bparticipant = new ORM_CMN_BPT_BusinessParticipant();
                bparticipant.DisplayName = Parameter.DisplayName;
                bparticipant.IsCompany   = true;
                bparticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
                bparticipant.Tenant_RefID = securityTicket.TenantID;
                bparticipant.Save(Connection, Transaction);

                ORM_ACC_TAX_TaxOffice taxOffice = new ORM_ACC_TAX_TaxOffice();
                taxOffice.CMN_BPT_BusinessParticipant_RefID = bparticipant.CMN_BPT_BusinessParticipantID;
                taxOffice.Tenant_RefID = securityTicket.TenantID;
                taxOffice.Save(Connection, Transaction);
                returnValue.Result = taxOffice.ACC_TAX_TaxOfficeID;

                if (Parameter.Country_ISO != "")
                {
                    var countries = cls_Get_AllCountries.Invoke(Connection, Transaction, securityTicket).Result;
                    ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail();
                    ucd.Country_639_1_ISOCode = Parameter.Country_ISO;
                    ucd.Tenant_RefID          = securityTicket.TenantID;
                    ucd.Save(Connection, Transaction);
                    companyInfo.Contact_UCD_RefID = ucd.CMN_UniversalContactDetailID;
                }

                companyInfo.Save(Connection, Transaction);
            }



            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Example #18
0
        protected static FR_String Execute(DbConnection Connection, DbTransaction Transaction, P_OR_SOtMM_1311 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_String();
            //Put your code here

            var data = cls_Get_Account_Information_with_PracticeID.Invoke(Connection, Transaction, securityTicket).Result;

            var isNewPharmacy = Parameter.Order.default_pharmacy == Guid.Empty;

            var current_order_status      = isNewPharmacy ? "MO10" : "MO1";
            var current_order_status_code = isNewPharmacy ? 10 : 1;

            var all_languages = ORM_CMN_Language.Query.Search(Connection, Transaction, new ORM_CMN_Language.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            });

            var practice_info = cls_Get_Practice_Details_for_Report.Invoke(Connection, Transaction, new P_DO_GPDFR_0840()
            {
                PracticeID = data.PracticeID
            }, securityTicket).Result;

            var trigger_acc = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
            {
                USR_AccountID = securityTicket.AccountID
            }).Single();
            var culture            = new CultureInfo("de", true);
            var delivery_date      = DateTime.ParseExact(Parameter.Order.delivery_date, "dd.MM.yyyy", culture);
            var delivery_date_from = DateTime.ParseExact(Parameter.Order.delivery_date_from, "HH:mm", culture);
            delivery_date_from = delivery_date.AddHours(delivery_date_from.Hour).AddMinutes(delivery_date_from.Minute);
            var delivery_date_to = DateTime.ParseExact(Parameter.Order.delivery_date_to, "HH:mm", culture);
            delivery_date_to = delivery_date.AddHours(delivery_date_to.Hour).AddMinutes(delivery_date_to.Minute);
            var drug_names   = new List <string>();
            var cmn_products = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product.Query()
            {
                Tenant_RefID = securityTicket.TenantID, IsDeleted = false
            });
            var hec_products = ORM_HEC_Product.Query.Search(Connection, Transaction, new ORM_HEC_Product.Query()
            {
                Tenant_RefID = securityTicket.TenantID, IsDeleted = false
            });
            var drugs = cls_Get_Drug_Details_on_Tenant.Invoke(Connection, Transaction, securityTicket).Result;

            #region save and get pharmacy
            if (isNewPharmacy)
            {
                Parameter.Order.default_pharmacy = cls_Save_Pharmacy.Invoke(Connection, Transaction, new P_PH_SP_1124
                {
                    Pharmacy = new Pharmacy.Model.Pharmacy(Guid.Empty, Parameter.Order.pharmacy_name, String.Empty, String.Empty,
                                                           String.Empty, Parameter.Order.pharmacy_street, Parameter.Order.pharmacy_street_number, Parameter.Order.pharmacy_zip_code,
                                                           Parameter.Order.pharmacy_town, true, String.Empty)
                }, securityTicket).Result;
            }

            var pharmacy = cls_Get_Pharmacy_for_PharmacyID.Invoke(Connection, Transaction, new P_PH_GPfPID_1535
            {
                PharmacyID = Parameter.Order.default_pharmacy
            }, securityTicket).Result;
            #endregion

            var ordersForReport = new List <ReportOrderItem>();

            foreach (var order_id in Parameter.Order.order_ids)
            {
                #region Status
                var header = ORM_ORD_PRC_ProcurementOrder_Header.Query.Search(Connection, Transaction, new ORM_ORD_PRC_ProcurementOrder_Header.Query()
                {
                    ORD_PRC_ProcurementOrder_HeaderID = order_id,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();

                header.ProcurementOrder_Supplier_RefID = pharmacy != null ? pharmacy.CompanyBPID : Guid.Empty;

                var header_comment = new ORM_ORD_PRC_ProcurementOrder_Note();
                header_comment.Comment      = Parameter.Order.comment;
                header_comment.Title        = "Order comment";
                header_comment.Tenant_RefID = securityTicket.TenantID;
                header_comment.ORD_PRC_ProcurementOrder_Header_RefID = order_id;

                header_comment.Save(Connection, Transaction);

                ORM_ORD_PRC_ProcurementOrder_Position.Query order_positionQ = new ORM_ORD_PRC_ProcurementOrder_Position.Query();
                order_positionQ.Tenant_RefID = securityTicket.TenantID;
                order_positionQ.IsDeleted    = false;
                order_positionQ.ProcurementOrder_Header_RefID = order_id;
                var order_position   = ORM_ORD_PRC_ProcurementOrder_Position.Query.Search(Connection, Transaction, order_positionQ).SingleOrDefault();
                var position_comment = order_position != null ? order_position.Position_Comment ?? String.Empty : String.Empty;

                var drug_order_status = new ORM_ORD_PRC_ProcurementOrder_Status();
                drug_order_status.GlobalPropertyMatchingID = String.Format("mm.doc.connect.drug.order.status.{0}", current_order_status.ToLower());
                drug_order_status.Status_Code  = current_order_status_code;
                drug_order_status.Tenant_RefID = securityTicket.TenantID;
                drug_order_status.Status_Name  = new Dict(ORM_ORD_PRC_ProcurementOrder_Status.TableName);
                foreach (var lang in all_languages)
                {
                    drug_order_status.Status_Name.AddEntry(lang.CMN_LanguageID, current_order_status);
                }
                drug_order_status.Save(Connection, Transaction);

                var drug_order_status_history = new ORM_ORD_PRC_ProcurementOrder_StatusHistory();
                drug_order_status_history.ProcurementOrder_Header_RefID = header.ORD_PRC_ProcurementOrder_HeaderID;
                drug_order_status_history.ProcurementOrder_Status_RefID = drug_order_status.ORD_PRC_ProcurementOrder_StatusID;
                drug_order_status_history.Tenant_RefID     = securityTicket.TenantID;
                drug_order_status_history.IsStatus_Created = true;
                drug_order_status_history.TriggeredAt_Date = DateTime.Now;
                drug_order_status_history.TriggeredBy_BusinessParticipant_RefID = trigger_acc.BusinessParticipant_RefID;
                drug_order_status_history.Save(Connection, Transaction);

                header.Current_ProcurementOrderStatus_RefID = drug_order_status.ORD_PRC_ProcurementOrder_StatusID;
                header.Save(Connection, Transaction);
                #endregion Status

                var ord_drug_order = ORM_ORD_PRC_ProcurementOrder_Position.Query.Search(Connection, Transaction, new ORM_ORD_PRC_ProcurementOrder_Position.Query()
                {
                    ProcurementOrder_Header_RefID = order_id,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();


                ord_drug_order.Position_RequestedDateOfDelivery       = delivery_date.Date;
                ord_drug_order.RequestedDateOfDelivery_TimeFrame_From = delivery_date_from;
                ord_drug_order.RequestedDateOfDelivery_TimeFrame_To   = delivery_date_to;
                ord_drug_order.Save(Connection, Transaction);

                var hec_drug_order = ORM_HEC_PRC_ProcurementOrder_Position.Query.Search(Connection, Transaction, new ORM_HEC_PRC_ProcurementOrder_Position.Query()
                {
                    Ext_ORD_PRC_ProcurementOrder_Position_RefID = ord_drug_order.ORD_PRC_ProcurementOrder_PositionID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single();

                var drug_id = ORM_HEC_ACT_PlannedAction_PotentialProcedure_RequiredProduct.Query.Search(Connection, Transaction, new ORM_HEC_ACT_PlannedAction_PotentialProcedure_RequiredProduct.Query()
                {
                    BoundTo_HealthcareProcurementOrderPosition_RefID = hec_drug_order.HEC_PRC_ProcurementOrder_PositionID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).Single().HealthcareProduct_RefID;

                var drugName = drugs.First(t => t.DrugID == drug_id).DrugName;
                drug_names.Add(drugName);

                if (Parameter.Order.doctor_id != Guid.Empty)
                {
                    var authorizing_doctor_details = cls_Get_Doctor_BasicInformation_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDBIfDID_1034()
                    {
                        DoctorID = Parameter.Order.doctor_id
                    }, securityTicket).Result;

                    hec_drug_order.Clearing_Doctor_RefID      = Parameter.Order.doctor_id;
                    hec_drug_order.ClearingDoctor_DisplayName = GenericUtils.GetDoctorName(authorizing_doctor_details);
                    hec_drug_order.Save(Connection, Transaction);
                }

                var shipping_address = new ORM_CMN_UniversalContactDetail();
                shipping_address.Modification_Timestamp = DateTime.Now;
                shipping_address.Tenant_RefID           = securityTicket.TenantID;
                shipping_address.Street_Name            = Parameter.Order.street;
                shipping_address.Street_Number          = Parameter.Order.number;
                shipping_address.ZIP  = Parameter.Order.zip;
                shipping_address.Town = Parameter.Order.city;
                shipping_address.CompanyName_Line1 = Parameter.Order.receiver;
                shipping_address.Save(Connection, Transaction);

                var ord_drug_order_header = new ORM_ORD_PRC_ProcurementOrder_Header();
                ord_drug_order_header.Load(Connection, Transaction, ord_drug_order.ProcurementOrder_Header_RefID);
                ord_drug_order_header.ShippingAddressUCD_RefID        = shipping_address.CMN_UniversalContactDetailID;
                ord_drug_order_header.Modification_Timestamp          = DateTime.Now;
                ord_drug_order_header.ProcurementOrder_Supplier_RefID = pharmacy != null ? pharmacy.CompanyBPID : Guid.Empty;
                ord_drug_order_header.Save(Connection, Transaction);


                ordersForReport.Add(new ReportOrderItem
                {
                    Name            = drugName,
                    PositionComment = position_comment,
                    Patient         = new ReportOrderPatientInformation
                    {
                        PatientID = hec_drug_order.OrderedFor_Patient_RefID,
                        FeeWaived = hec_drug_order.IsOrderForPatient_PatientFeeWaived
                    }
                });
            }

            #region Send e-mail if urgent order

            var defaultshippingDateOffset = cls_Get_Practice_PropertyValue_for_PropertyName_and_PracticeID.Invoke(Connection, Transaction, new P_DO_GPPVfPNaPID_0916()
            {
                PracticeID   = data.PracticeID,
                PropertyName = "Default Shipping Date Offset"
            }, securityTicket).Result.NumericValue;

            var company_settings = cls_Get_Company_Settings.Invoke(Connection, Transaction, securityTicket).Result;
            var ordernum         = company_settings.ImmediateOrderInterval;

            if (delivery_date > DateTime.Now.AddDays(-defaultshippingDateOffset).AddMinutes(ordernum))
            {
                try
                {
                    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
                    var mailToL = new List <String>();

                    var accountMails = cls_Get_All_Account_LoginEmails_Who_Receive_Notifications.Invoke(Connection, Transaction, securityTicket).Result.ToList();
                    foreach (var mail in accountMails)
                    {
                        mailToL.Add(mail.LoginEmail);
                    }
                    var mailToFromCompanySettings = company_settings.Email;
                    mailToL.Add(mailToFromCompanySettings);

                    var appName        = WebConfigurationManager.AppSettings["mmAppUrl"];
                    var prefix         = HttpContext.Current.Request.Url.AbsoluteUri.Contains("https") ? "https://" : "http://";
                    var imageUrl       = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("api")) + "Content/images/logo.png";
                    var email_template = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/UrgentOrderEmailTemplate.html"));

                    var     subjectsJson = File.ReadAllText(HttpContext.Current.Server.MapPath("~/EmailTemplates/EmailSubjects.json"));
                    dynamic subjects     = JsonConvert.DeserializeObject(subjectsJson);
                    var     subjectMail  = subjects["UrgentOrderSubject"].ToString();

                    email_template = EmailTemplater.SetTemplateData(email_template, new
                    {
                        orders = drug_names.Select(t => new
                        {
                            order_date_time_from = delivery_date_from.ToString("dd.MM.yyyy HH:mm"),
                            order_date_time_to   = delivery_date_to.ToString("HH:mm"),
                            name      = data.AccountInformation.name,
                            drug_name = t
                        }),
                        mmapp_dashboard_url     = prefix + HttpContext.Current.Request.Url.Authority + "/" + appName,
                        medios_connect_logo_url = imageUrl
                    }, "{{", "}}");

                    var mailFrom      = WebConfigurationManager.AppSettings["mailFrom"];
                    var mailsDistinct = mailToL.Distinct().ToList();
                    foreach (var mailTo in mailsDistinct)
                    {
                        EmailNotificationSenderUtil.SendEmail(mailFrom, mailTo, subjectMail, email_template);
                    }
                }
                catch (Exception ex)
                {
                    LogUtils.Logger.LogDocAppInfo(new LogUtils.LogEntry(System.Reflection.MethodInfo.GetCurrentMethod(), ex, null, "Urgent order: Email sending failed."), "EmailExceptions");
                }
            }

            #endregion SEND MAIL URGENT ORDER

            #region Update case order number
            var case_order_number = cls_Save_Case_Order_Number_for_OrderIDs.Invoke(Connection, Transaction, new P_CAS_SCONfOID_1442
            {
                order_ids     = Parameter.Order.order_ids.ToArray(),
                practice_bsnr = practice_info.BSNR
            }, securityTicket).Result;
            #endregion

            #region Create PDF report
            if (isNewPharmacy)
            {
                #region patient information
                var patients_info = cls_Get_Patient_Details_for_PatientIDs.Invoke(Connection, Transaction, new P_PA_GPDfPIDs_1354
                {
                    PatientIDs = ordersForReport.Select(x => x.Patient).Select(x => x.PatientID).Distinct().ToArray()
                }, securityTicket).Result;

                foreach (var order in ordersForReport)
                {
                    var patient_info = patients_info.Single(x => x.PatientID == order.Patient.PatientID);

                    order.Patient.FirstName       = patient_info.FirstName;
                    order.Patient.LastName        = patient_info.LastName;
                    order.Patient.BirthDate       = patient_info.BirthDate;
                    order.Patient.Hip             = patient_info.HipName;
                    order.Patient.InsuranceStatus = patient_info.InsuranceStatus;
                }
                #endregion

                #region Repack data for report
                var orderPdfReport  = new OrderPdfReportGenerator();
                var reportOrderInfo = new ReportOrderInformation
                {
                    DeliveryDate     = delivery_date,
                    DeliveryTimeFrom = delivery_date_from,
                    DeliveryTimeTo   = delivery_date_to,
                    CreationDate     = DateTime.Now,
                    OrderNumber      = case_order_number,
                    HeaderComment    = Parameter.Order.comment ?? String.Empty,
                    OrderedDrugs     = ordersForReport,
                };
                var reportPractice = new OrderParticipantInformation
                {
                    City   = practice_info.City,
                    Email  = practice_info.Contact_Email,
                    Name   = practice_info.Name,
                    Number = practice_info.Street_Number,
                    Phone  = practice_info.Contact_Telephone,
                    Street = practice_info.Street_Name,
                    Zip    = practice_info.ZIP
                };
                var reportPharmacy = new OrderParticipantInformation
                {
                    Name   = pharmacy.PharmacyName,
                    Street = pharmacy.Street_Name,
                    Number = pharmacy.Street_Number,
                    Zip    = pharmacy.ZIP,
                    City   = pharmacy.Town,
                    Email  = pharmacy.Contact_Email,
                    Phone  = pharmacy.Contact_Telephone
                };
                #endregion

                var bytes = orderPdfReport.Generate(
                    new Model.OrderReportParameters
                {
                    Orders   = reportOrderInfo,
                    Pharmacy = reportPharmacy,
                    Practice = reportPractice
                },
                    HttpContext.Current.Server.MapPath("~/ReportContent/SubmitOrderPdfReportContent.xml")
                    );

                var _providerFactory = ProviderFactory.Instance;
                var documentProvider = _providerFactory.CreateDocumentServiceProvider();
                var fileName         = String.Format("{0}-{1}-{2}.pdf", "Submited Orders", pharmacy.PharmacyName, DateTime.Now.ToString("dd.MM.yyyy HH:mm"));
                var documentID       = documentProvider.UploadDocument(bytes, fileName, securityTicket.SessionTicket, HttpContext.Current.Request.UserHostAddress);
                var reportURL        = documentProvider.GenerateDownloadLink(documentID, securityTicket.SessionTicket, true, true);

                var parameterDoc = new P_OR_UOPDFR_1049();

                parameterDoc.DocumentID      = documentID;
                parameterDoc.Mime            = UtilMethods.GetMimeType(fileName);
                parameterDoc.DocumentName    = fileName;
                parameterDoc.CaseOrderNumber = case_order_number;
                parameterDoc.OrderIDs        = Parameter.Order.order_ids.ToArray();

                cls_Upload_Order_PDF_Report.Invoke(Connection, Transaction, parameterDoc, securityTicket);

                returnValue.Result = reportURL;
            }
            #endregion

            return(returnValue);

            #endregion UserCode
        }
Example #19
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OP_SP_1602 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            P_L2LN_GALFTID_1530 langParam = new P_L2LN_GALFTID_1530();
            langParam.Tenant_RefID = securityTicket.TenantID;
            var languages = cls_Get_All_Languages_ForTenantID.Invoke(Connection, Transaction, langParam, securityTicket).Result;

            P_L3MP_SPBI_1602 basePracticeParam = new P_L3MP_SPBI_1602();
            basePracticeParam.HEC_MedicalPractiseID        = Parameter.HEC_MedicalPractiseID;
            basePracticeParam.Contact_EmergencyPhoneNumber = Parameter.PhoneNumber;
            basePracticeParam.Contact_Website_URL          = Parameter.HomepageURL;
            basePracticeParam.PracticeEmail = Parameter.ContactEmail;
            basePracticeParam.PracticeName  = Parameter.DisplyName;
            basePracticeParam.Region_Name   = Parameter.AddressRegion;
            basePracticeParam.Street_Name   = Parameter.AddressStreetName;
            basePracticeParam.Street_Number = Parameter.AddressStreetNumber;
            basePracticeParam.Town          = Parameter.AddressCity;
            basePracticeParam.ZIP           = Parameter.AddressZipCode;
            var practiceID = cls_Save_Practice_BaseInfo.Invoke(Connection, Transaction, basePracticeParam, securityTicket).Result;

            var practicesQuery = new ORM_HEC_MedicalPractis.Query();
            practicesQuery.HEC_MedicalPractiseID = practiceID;
            var practices = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practicesQuery).First();

            var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
            companyInfoQuery.CMN_COM_CompanyInfoID = practices.Ext_CompanyInfo_RefID;
            var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First();

            var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            bParticipantQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            var bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).First();

            ORM_CMN_BPT_BusinessParticipant bpContctPerson;

            if (practices.ContactPerson_RefID != Guid.Empty)
            {
                var bpContctPersonQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                bpContctPersonQuery.CMN_BPT_BusinessParticipantID = practices.ContactPerson_RefID;
                bpContctPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bpContctPersonQuery).First();
            }
            else
            {
                bpContctPerson = new ORM_CMN_BPT_BusinessParticipant();
                bpContctPerson.Tenant_RefID    = securityTicket.TenantID;
                bpContctPerson.IsNaturalPerson = true;
            }
            bpContctPerson.DisplayName = Parameter.ContactPerson_Name;
            bpContctPerson.Save(Connection, Transaction);

            practices.ContactPerson_RefID = bpContctPerson.CMN_BPT_BusinessParticipantID;

            ORM_CMN_CAL_WeeklyOfficeHours_Template officeHours;
            ORM_CMN_CAL_WeeklyOfficeHours_Template consultingHours;
            if (practices.WeeklyOfficeHours_Template_RefID != Guid.Empty && practices.WeeklySurgeryHours_Template_RefID != Guid.Empty)
            {
                var officeHoursQuery = new ORM_CMN_CAL_WeeklyOfficeHours_Template.Query();
                officeHoursQuery.CMN_CAL_WeeklyOfficeHours_TemplateID = practices.WeeklyOfficeHours_Template_RefID;
                officeHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery).First();

                officeHoursQuery.CMN_CAL_WeeklyOfficeHours_TemplateID = practices.WeeklySurgeryHours_Template_RefID;
                consultingHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery).First();
            }
            else
            {
                officeHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template();
                officeHours.CMN_CAL_WeeklyOfficeHours_TemplateID = Guid.NewGuid();
                consultingHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template();
                consultingHours.CMN_CAL_WeeklyOfficeHours_TemplateID = Guid.NewGuid();

                practices.WeeklyOfficeHours_Template_RefID  = officeHours.CMN_CAL_WeeklyOfficeHours_TemplateID;
                practices.WeeklySurgeryHours_Template_RefID = consultingHours.CMN_CAL_WeeklyOfficeHours_TemplateID;
            }
            consultingHours.Tenant_RefID         = securityTicket.TenantID;
            officeHours.Tenant_RefID             = securityTicket.TenantID;
            consultingHours.FormattedOfficeHours = Parameter.Consultation_FormattedOfficeHours;
            officeHours.FormattedOfficeHours     = Parameter.Working_FormattedOfficeHours;

            consultingHours.Save(Connection, Transaction);
            officeHours.Save(Connection, Transaction);

            ORM_CMN_COM_CompanyInfo_Type companyType;

            var companyTypeQuery = new ORM_CMN_COM_CompanyInfo_Type.Query();
            companyTypeQuery.IsDeleted = false;
            companyTypeQuery.CMN_COM_CompanyInfo_TypeID = Parameter.PracticeType_RefID;
            companyType = ORM_CMN_COM_CompanyInfo_Type.Query.Search(Connection, Transaction, companyTypeQuery).FirstOrDefault();
            if (companyType == null)
            {
                companyType = new ORM_CMN_COM_CompanyInfo_Type();
                companyType.CMN_COM_CompanyInfo_TypeID    = Parameter.PracticeType_RefID;
                companyType.CompanyType_Name              = new Dict();
                companyType.CompanyType_Name.DictionaryID = Guid.NewGuid();
                if (languages != null)
                {
                    foreach (var item in languages)
                    {
                        companyType.CompanyType_Name.AddEntry(item.CMN_LanguageID, STLD_PracticeType.typesItems.First(t => t.Value == Parameter.PracticeType_RefID).Text);
                    }
                }
            }
            companyInfo.CompanyType_RefID = Parameter.PracticeType_RefID;

            ORM_HEC_PublicHealthcare_PhysitianAssociation pHealthcare;
            var pHealthcareQuery = new ORM_HEC_PublicHealthcare_PhysitianAssociation.Query();
            pHealthcareQuery.HEC_PublicHealthcare_PhysitianAssociationID = Parameter.HealthAssociation_RefID;
            pHealthcare = ORM_HEC_PublicHealthcare_PhysitianAssociation.Query.Search(Connection, Transaction, pHealthcareQuery).FirstOrDefault();
            if (pHealthcare == null)
            {
                pHealthcare = new ORM_HEC_PublicHealthcare_PhysitianAssociation();
                pHealthcare.HEC_PublicHealthcare_PhysitianAssociationID = Parameter.HealthAssociation_RefID;
                pHealthcare.HealthAssociation_Name = STLD_MedicalAssociation.associationItems.First(t => t.Value == Parameter.HealthAssociation_RefID).Text;
                pHealthcare.Save(Connection, Transaction);
            }
            practices.AssociatedWith_PhysitianAssociation_RefID = Parameter.HealthAssociation_RefID;

            ORM_CMN_BPT_CTM_Customer customer;
            var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery);
            if (customerRes.Count == 0)
            {
                customer = new ORM_CMN_BPT_CTM_Customer();
                customer.CMN_BPT_CTM_CustomerID        = Guid.NewGuid();
                customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            }
            else
            {
                customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First();
            }

            var affinityStatusQuery = new ORM_CMN_BPT_CTM_AffinityStatus.Query();
            affinityStatusQuery.CMN_BPT_CTM_AffinityStatusID = Parameter.AffinityStatus_RefID;
            var affinityStatus = ORM_CMN_BPT_CTM_AffinityStatus.Query.Search(Connection, Transaction, affinityStatusQuery).FirstOrDefault();
            if (affinityStatus == null)
            {
                affinityStatus = new ORM_CMN_BPT_CTM_AffinityStatus();
                affinityStatus.CMN_BPT_CTM_AffinityStatusID     = Parameter.AffinityStatus_RefID;
                affinityStatus.AffinityStatus_Name              = new Dict();
                affinityStatus.AffinityStatus_Name.DictionaryID = Guid.NewGuid();
                if (languages != null)
                {
                    foreach (var item in languages)
                    {
                        affinityStatus.AffinityStatus_Name.AddEntry(item.CMN_LanguageID, STLD_AffinityStatus.affinityItems.First(t => t.Value == Parameter.AffinityStatus_RefID).Text);
                    }
                }
                affinityStatus.Save(Connection, Transaction);
            }

            customer.CustomerAffinityStatus_RefID = Parameter.AffinityStatus_RefID;
            customer.Tenant_RefID = securityTicket.TenantID;

            customer.Save(Connection, Transaction);

            ORM_CMN_COM_CompanyInfo_Address compAddress;
            ORM_CMN_UniversalContactDetail  address;

            var compAddressQuery = new ORM_CMN_COM_CompanyInfo_Address.Query();
            compAddressQuery.Tenant_RefID      = securityTicket.TenantID;
            compAddressQuery.CompanyInfo_RefID = practices.Ext_CompanyInfo_RefID;
            var compAddressRes = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, compAddressQuery);

            if (compAddressRes.Count > 0)
            {
                compAddress = compAddressRes.First();
                var addressQuery = new ORM_CMN_UniversalContactDetail.Query();
                addressQuery.CMN_UniversalContactDetailID = compAddress.Address_UCD_RefID;
                address = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, addressQuery).First();
            }
            else
            {
                compAddress = new ORM_CMN_COM_CompanyInfo_Address();
                compAddress.CMN_COM_CompanyInfo_AddressID = Guid.NewGuid();
                compAddress.IsShipping        = true;
                compAddress.CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;

                address = new ORM_CMN_UniversalContactDetail();
                address.CMN_UniversalContactDetailID = Guid.NewGuid();

                compAddress.Address_UCD_RefID = address.CMN_UniversalContactDetailID;
            }

            address.Town          = Parameter.ShippingAddressCity;
            address.Street_Number = Parameter.ShippingAddressStreetNumber;
            address.Street_Name   = Parameter.ShippingAddressStreetName;
            address.ZIP           = Parameter.ShippingAddressZipCode;
            address.Region_Name   = Parameter.ShippingAddressRegion;

            address.Tenant_RefID = securityTicket.TenantID;
            address.Save(Connection, Transaction);
            compAddress.Tenant_RefID = securityTicket.TenantID;
            compAddress.Save(Connection, Transaction);

            ORM_CMN_BPT_BusinessParticipant contactPBP;
            if (practices.ContactPerson_RefID != Guid.Empty)
            {
                var contactPBPQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                contactPBPQuery.CMN_BPT_BusinessParticipantID = practices.ContactPerson_RefID;
                contactPBP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, contactPBPQuery).First();
            }
            else
            {
                contactPBP = new ORM_CMN_BPT_BusinessParticipant();
                contactPBP.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                contactPBP.IsCompany          = true;
                practices.ContactPerson_RefID = contactPBP.CMN_BPT_BusinessParticipantID;
            }
            contactPBP.DisplayName  = Parameter.ContactPerson_Name;
            contactPBP.Tenant_RefID = securityTicket.TenantID;
            contactPBP.Save(Connection, Transaction);

            companyInfo.Save(Connection, Transaction);
            practices.Save(Connection, Transaction);
            returnValue.Result = practices.HEC_MedicalPractiseID;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3TE_CTITS_1108 Execute(DbConnection Connection, DbTransaction Transaction, P_L3TE_CTITS_1108 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3TE_CTITS_1108();
            returnValue.Result = new L3TE_CTITS_1108();
            returnValue.Status = FR_Status.Error_Internal;

            #region Load or Create Tenant
            var tenantQuery = new ORM_CMN_Tenant.Query()
            {
                TenantITL    = Parameter.TenantITL,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            };

            var customerTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

            if (customerTenant == default(ORM_CMN_Tenant))
            {
                customerTenant = new ORM_CMN_Tenant();
                customerTenant.CMN_TenantID                 = Guid.NewGuid();
                customerTenant.TenantITL                    = Parameter.TenantITL;
                customerTenant.Tenant_RefID                 = securityTicket.TenantID;
                customerTenant.Creation_Timestamp           = DateTime.Now;
                customerTenant.UniversalContactDetail_RefID = Guid.NewGuid();
                if (customerTenant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create BusinessParticipant
            var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                IsTenant = true,
                IfTenant_Tenant_RefID = customerTenant.CMN_TenantID,
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false
            }).SingleOrDefault();

            if (businessParticipant == default(ORM_CMN_BPT_BusinessParticipant))
            {
                businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                businessParticipant.BusinessParticipantITL        = Parameter.BusinessParticipantITL;
                businessParticipant.DisplayName = Parameter.CompanyName;
                businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();
                businessParticipant.IfTenant_Tenant_RefID = customerTenant.CMN_TenantID;
                businessParticipant.IsCompany             = true;
                businessParticipant.IsTenant           = true;
                businessParticipant.Tenant_RefID       = securityTicket.TenantID;
                businessParticipant.Creation_Timestamp = DateTime.Now;
                if (businessParticipant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create CompanyInfo
            var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo.Query()
            {
                CMN_COM_CompanyInfoID = businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID,
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false
            }).SingleOrDefault();

            if (companyInfo == default(ORM_CMN_COM_CompanyInfo))
            {
                companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.CMN_COM_CompanyInfoID = businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfo.Contact_UCD_RefID     = Guid.NewGuid();
                companyInfo.Tenant_RefID          = securityTicket.TenantID;
                companyInfo.Creation_Timestamp    = DateTime.Now;
                if (companyInfo.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create UniversalContactDetails for Tenant and CompanyInfo
            var ucdTenant = ORM_CMN_UniversalContactDetail.Query.Search(
                Connection,
                Transaction,
                new ORM_CMN_UniversalContactDetail.Query()
            {
                CMN_UniversalContactDetailID = customerTenant.UniversalContactDetail_RefID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (ucdTenant == default(ORM_CMN_UniversalContactDetail))
            {
                ucdTenant = new ORM_CMN_UniversalContactDetail();
                ucdTenant.CMN_UniversalContactDetailID = customerTenant.UniversalContactDetail_RefID;
                ucdTenant.UniversalContactDetailsITL   = Parameter.TenantUniversalContactDetailITL;
                ucdTenant.IsCompany          = true;
                ucdTenant.CompanyName_Line1  = Parameter.CompanyName;
                ucdTenant.Contact_Email      = Parameter.ContactEmail;
                ucdTenant.Tenant_RefID       = securityTicket.TenantID;
                ucdTenant.Creation_Timestamp = DateTime.Now;
                if (ucdTenant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }

            var ucdCompanyInfo = ORM_CMN_UniversalContactDetail.Query.Search(
                Connection,
                Transaction,
                new ORM_CMN_UniversalContactDetail.Query()
            {
                CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (ucdCompanyInfo == default(ORM_CMN_UniversalContactDetail))
            {
                ucdCompanyInfo = new ORM_CMN_UniversalContactDetail();
                ucdCompanyInfo.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                ucdCompanyInfo.UniversalContactDetailsITL   = Parameter.CompanyInfoUniversalContactDetailITL;
                ucdCompanyInfo.IsCompany          = true;
                ucdCompanyInfo.CompanyName_Line1  = Parameter.CompanyName;
                ucdCompanyInfo.Contact_Email      = Parameter.ContactEmail;
                ucdCompanyInfo.Tenant_RefID       = securityTicket.TenantID;
                ucdCompanyInfo.Creation_Timestamp = DateTime.Now;
                if (ucdCompanyInfo.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            returnValue.Result.TenantID = customerTenant.CMN_TenantID;
            returnValue.Result.BusinessParticipantID               = businessParticipant.CMN_BPT_BusinessParticipantID;
            returnValue.Result.TenantUniversalContactDetailID      = ucdTenant.CMN_UniversalContactDetailID;
            returnValue.Result.CompanyInfoUniversalContactDetailID = ucdCompanyInfo.CMN_UniversalContactDetailID;
            returnValue.Result.CompanyInfoID = companyInfo.CMN_COM_CompanyInfoID;
            returnValue.Status = FR_Status.Success;

            return(returnValue);

            #endregion UserCode
        }
Example #21
0
        protected static FR_L3DO_SDO_1801 Execute(DbConnection Connection, DbTransaction Transaction, P_L3DO_SDO_1801 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3DO_SDO_1801();
            returnValue.Result = new L3DO_SDO_1801();

            ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail();
            universalContactDetails.CMN_UniversalContactDetailID = Guid.NewGuid();
            universalContactDetails.Contact_Email         = Parameter.UniversalContactDetails.Email;
            universalContactDetails.Contact_Telephone     = Parameter.UniversalContactDetails.Phone;
            universalContactDetails.Country_Name          = Parameter.UniversalContactDetails.Country;
            universalContactDetails.Country_639_1_ISOCode = Parameter.UniversalContactDetails.CountryIso;
            universalContactDetails.Creation_Timestamp    = DateTime.Now;
            universalContactDetails.First_Name            = Parameter.UniversalContactDetails.FirstName;
            universalContactDetails.Last_Name             = Parameter.UniversalContactDetails.LastName;
            universalContactDetails.Street_Name           = Parameter.UniversalContactDetails.StreetName;
            universalContactDetails.Street_Number         = Parameter.UniversalContactDetails.StreetNumber;
            universalContactDetails.ZIP          = Parameter.UniversalContactDetails.Zip;
            universalContactDetails.Town         = Parameter.UniversalContactDetails.Town;
            universalContactDetails.Tenant_RefID = securityTicket.TenantID;
            universalContactDetails.POBox        = Parameter.UniversalContactDetails.POBox;
            universalContactDetails.Save(Connection, Transaction);


            ORM_CMN_NumberRange_UsageArea numberRangeUsageArea = ORM_CMN_NumberRange_UsageArea.Query.Search(Connection, Transaction, new ORM_CMN_NumberRange_UsageArea.Query()
            {
                IsDeleted              = false,
                Tenant_RefID           = securityTicket.TenantID,
                GlobalStaticMatchingID = NumberRangeGlobalPropertyMatchingID
            }).FirstOrDefault();


            if (numberRangeUsageArea == null)
            {
                throw new Exception(String.Format("Number range usage area with GPMID = {0} was not found.", NumberRangeGlobalPropertyMatchingID));
            }

            ORM_CMN_NumberRange numberRange = ORM_CMN_NumberRange.Query.Search(Connection, Transaction, new ORM_CMN_NumberRange.Query()
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID,
                NumberRange_UsageArea_RefID = numberRangeUsageArea.CMN_NumberRange_UsageAreaID
            }).FirstOrDefault();

            if (numberRange == null)
            {
                throw new Exception(String.Format("Number range for area with GPMID = {0} was not found.", NumberRangeGlobalPropertyMatchingID));
            }

            numberRange.Value_Current++;
            numberRange.Save(Connection, Transaction);

            string distributionOrderNumber = numberRange.FixedPrefix + numberRange.Value_Current.ToString().PadLeft(numberRange.Formatting_NumberLength, numberRange.Formatting_LeadingFillCharacter[0]);

            ORM_ORD_DIS_DistributionOrder_Header header = new ORM_ORD_DIS_DistributionOrder_Header();
            header.Charged_CostCenter_RefID              = Parameter.IsCostCenterOrderRefID;
            header.Creation_Timestamp                    = DateTime.Now;
            header.DistributeTo_UCDAddress_RefID         = universalContactDetails.CMN_UniversalContactDetailID;
            header.DistributionOrderDate                 = DateTime.Now;
            header.DistributionOrderNumber               = distributionOrderNumber;
            header.IfForDelivery_LogisticsProvider_RefID = Parameter.IsForDeliveryLogisticProviderRefID.ToString();
            header.IfForDelivery_ShipmentType_RefID      = Parameter.IsForDeliveryShipmentTypeRefID;
            header.IfForPickup_PointOfSale_RefID         = Parameter.IsForPickupPointOfSaleRefID;
            header.IsCostCenterOrder = Parameter.IsCostCenterOrder;
            header.IsDeleted         = false;
            header.IsForDelivery     = Parameter.IsForDelivery;
            header.ORD_DIS_DistributionOrder_HeaderID = Guid.NewGuid();
            header.Tenant_RefID = securityTicket.TenantID;
            header.InternallyCharged_Currency_RefID     = Parameter.CurrencyID;
            header.InternallyCharged_TotalNetPriceValue = 0;
            header.IsForPickup = Parameter.IsForPickup;


            foreach (var item in Parameter.DistributionOrderPositions)
            {
                if (item.Quantity == 0)
                {
                    continue;
                }

                ORM_CMN_PRO_ASS_AssortmentVariant assortmentVariant = ORM_CMN_PRO_ASS_AssortmentVariant.Query.Search(Connection, Transaction, new ORM_CMN_PRO_ASS_AssortmentVariant.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    Ext_CMN_PRO_Product_Variant_RefID = item.ProductVariantID
                }).FirstOrDefault();


                ORM_ORD_DIS_DistributionOrder_Position position = null;

                if (assortmentVariant == null)
                {
                    //This means that this product might be local one
                    position = new ORM_ORD_DIS_DistributionOrder_Position();

                    position.Product_RefID         = item.ProductID;
                    position.Product_Variant_RefID = item.ProductVariantID;
                }
                else
                {
                    //This means that product is from assortment and we are supposed to take orginal product.
                    List <ORM_CMN_PRO_ASS_AssortmentVariant_VendorVariant> assortmentVendorVariats = ORM_CMN_PRO_ASS_AssortmentVariant_VendorVariant.Query.Search(Connection, Transaction, new ORM_CMN_PRO_ASS_AssortmentVariant_VendorVariant.Query()
                    {
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_PRO_ASS_AssortmentVariant_RefID = assortmentVariant.CMN_PRO_ASS_AssortmentVariantID
                    });

                    ORM_CMN_PRO_ASS_AssortmentVariant_VendorVariant defaultVendorVariant = assortmentVendorVariats.FirstOrDefault(x => x.IsDefaultVendorVariant == true);
                    if (defaultVendorVariant == null)
                    {
                        defaultVendorVariant = assortmentVendorVariats.First();
                    }

                    if (defaultVendorVariant != null)
                    {
                        ORM_CMN_PRO_Product_Variant productVariant = ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product_Variant.Query()
                        {
                            IsDeleted    = false,
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_PRO_Product_VariantID = defaultVendorVariant.CMN_PRO_Product_Variant_RefID
                        }).FirstOrDefault();

                        if (productVariant != null)
                        {
                            position = new ORM_ORD_DIS_DistributionOrder_Position();

                            position.Product_RefID         = productVariant.CMN_PRO_Product_RefID;
                            position.Product_Variant_RefID = productVariant.CMN_PRO_Product_VariantID;
                        }
                    }
                }


                if (position != null)
                {
                    position.Creation_Timestamp                   = DateTime.Now;
                    position.DistributionOrder_Header_RefID       = header.ORD_DIS_DistributionOrder_HeaderID;
                    position.ORD_DIS_DistributionOrder_PositionID = Guid.NewGuid();
                    position.Quantity     = item.Quantity;
                    position.Tenant_RefID = securityTicket.TenantID;
                    position.InternallyCharged_TotalNetPriceValue = item.PriceValueTotal;

                    position.Save(Connection, Transaction);

                    if (item.DistributionOrderPositionCustomizations != null && item.DistributionOrderPositionCustomizations.Where(x => x.CustomizationVariantID != Guid.Empty).Count() > 0)
                    {
                        foreach (var itemCustomization in item.DistributionOrderPositionCustomizations)
                        {
                            if (itemCustomization.CustomizationVariantID != Guid.Empty)
                            {
                                ORM_ORD_DIS_DistributionOrder_Position_Customization customization = new ORM_ORD_DIS_DistributionOrder_Position_Customization();
                                customization.ORD_DIS_DistributionOrder_Position_CustomizationID = itemCustomization.DistributionOrderPositionCustomizationID;
                                customization.Tenant_RefID = securityTicket.TenantID;
                                customization.DistributionOrder_Position_RefID = position.ORD_DIS_DistributionOrder_PositionID;
                                customization.CustomizationVariant_Name        = itemCustomization.CustomizationVariantName;
                                customization.Customization_Variant_RefID      = itemCustomization.CustomizationVariantID;
                                customization.Customization_Name = itemCustomization.CustomizationName;

                                customization.Save(Connection, Transaction);
                            }
                        }
                    }
                }

                header.InternallyCharged_TotalNetPriceValue += position.InternallyCharged_TotalNetPriceValue;
            }

            header.Save(Connection, Transaction);

            foreach (var item in Parameter.Documents)
            {
                ORM_DOC_Document document = new ORM_DOC_Document();
                document.Alias              = item.Alias;
                document.PrimaryType        = item.PrimaryType;
                document.DOC_DocumentID     = item.DocumentID;
                document.Creation_Timestamp = DateTime.Now;
                document.Tenant_RefID       = securityTicket.TenantID;
                document.Save(Connection, Transaction);

                ORM_ORD_DIS_DistributionOrder_Header_Document orderDocument = new ORM_ORD_DIS_DistributionOrder_Header_Document();
                orderDocument.Creation_Timestamp             = DateTime.Now;
                orderDocument.DistributionOrder_Header_RefID = header.ORD_DIS_DistributionOrder_HeaderID;
                orderDocument.Document_RefID = document.DOC_DocumentID;
                orderDocument.ORD_DIS_DistributionOrder_Header_DocumentID = Guid.NewGuid();
                orderDocument.Tenant_RefID = securityTicket.TenantID;
                orderDocument.Save(Connection, Transaction);
            }

            ORM_USR_Account account = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
            {
                Tenant_RefID  = securityTicket.TenantID,
                USR_AccountID = securityTicket.AccountID,
                IsDeleted     = false
            }).FirstOrDefault();

            ORM_ORD_DIS_DistributionOrder_Header_History history = new ORM_ORD_DIS_DistributionOrder_Header_History();
            history.Comment                                    = Parameter.UniversalContactDetails.Comment;
            history.Creation_Timestamp                         = DateTime.Now;
            history.DistributionOrder_Header_RefID             = header.ORD_DIS_DistributionOrder_HeaderID;
            history.IsCreated                                  = true;
            history.ORD_DIS_DistributionOrder_Header_HistoryID = Guid.NewGuid();
            history.Tenant_RefID                               = securityTicket.TenantID;
            history.TriggeredBy_BusinessParticipant_RefID      = account != null ? account.BusinessParticipant_RefID : Guid.Empty;
            history.Save(Connection, Transaction);

            returnValue.Result.DistributionOrderHeaderID = header.ORD_DIS_DistributionOrder_HeaderID;
            returnValue.Result.DistributionOrderNumber   = header.DistributionOrderNumber;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3CA_CoUSfIC_1545 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            /*
             * @See if Supplier already exists in database
             * */
            ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();

            var supplierQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            supplierQuery.BusinessParticipantITL = Parameter.SupplierITL;
            supplierQuery.Tenant_RefID           = securityTicket.TenantID;
            supplierQuery.IsDeleted = false;

            var supplier_bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, supplierQuery).FirstOrDefault();

            #region if supplier does not exist

            if (supplier_bussinessParticipant == null)
            {
                /*
                 * @Make Supplier Data
                 * */

                var tenantQuery = new ORM_CMN_Tenant.Query()
                {
                    TenantITL    = Parameter.TenantITL,
                    Tenant_RefID = securityTicket.TenantID
                };

                var supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

                if (supplierTenant == default(ORM_CMN_Tenant))
                {
                    supplierTenant = new ORM_CMN_Tenant();
                    supplierTenant.CMN_TenantID       = Guid.NewGuid();
                    supplierTenant.TenantITL          = Parameter.TenantITL;
                    supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                    supplierTenant.Creation_Timestamp = DateTime.Now;
                    supplierTenant.Save(Connection, Transaction);
                }

                supplier.CMN_BPT_SupplierID            = Guid.NewGuid();
                supplier.Ext_BusinessParticipant_RefID = Guid.NewGuid();//supplierBussinessParticipant.CMN_BPT_BusinessParticipantID
                supplier.Creation_Timestamp            = DateTime.Now;
                supplier.IsDeleted    = false;
                supplier.Tenant_RefID = securityTicket.TenantID;
                supplier.Save(Connection, Transaction);

                ORM_CMN_BPT_BusinessParticipant supplierBussinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                supplierBussinessParticipant.CMN_BPT_BusinessParticipantID = supplier.Ext_BusinessParticipant_RefID;
                supplierBussinessParticipant.DisplayName            = Parameter.Supplier_Name;
                supplierBussinessParticipant.BusinessParticipantITL = Parameter.SupplierITL;
                supplierBussinessParticipant.Creation_Timestamp     = DateTime.Now;
                supplierBussinessParticipant.Tenant_RefID           = securityTicket.TenantID;
                supplierBussinessParticipant.IsCompany             = true;
                supplierBussinessParticipant.IsTenant              = true;
                supplierBussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();//companyInfo.CMN_COM_CompanyInfoID
                supplierBussinessParticipant.Save(Connection, Transaction);

                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.CMN_COM_CompanyInfoID = supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfo.Creation_Timestamp    = DateTime.Now;
                companyInfo.Tenant_RefID          = securityTicket.TenantID;
                companyInfo.Contact_UCD_RefID     = Guid.NewGuid();//universalContactDetail.CMN_UniversalContactDetailID
                companyInfo.Save(Connection, Transaction);

                ORM_CMN_UniversalContactDetail universalContactDetail = new ORM_CMN_UniversalContactDetail();
                universalContactDetail.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                universalContactDetail.IsCompany             = true;
                universalContactDetail.Country_639_1_ISOCode = Parameter.CountryISO;
                universalContactDetail.Street_Name           = Parameter.Supplier_Name;
                universalContactDetail.Street_Number         = Parameter.Street_Number;
                universalContactDetail.ZIP                = Parameter.ZIP;
                universalContactDetail.Town               = Parameter.Town;
                universalContactDetail.Region_Code        = Parameter.Region_Code;
                universalContactDetail.Tenant_RefID       = securityTicket.TenantID;
                universalContactDetail.Creation_Timestamp = DateTime.Now;
                universalContactDetail.Save(Connection, Transaction);
            }
            #endregion
            #region if supplier exists , check if its data is changed
            else
            {
                var tenantQuery = new ORM_CMN_Tenant.Query()
                {
                    TenantITL    = Parameter.TenantITL,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                };

                ORM_CMN_Tenant supplierTenant;

                if (ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).Count > 1)
                {
                    supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).First(); //QUICKFIX
                }
                else
                {
                    supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();
                }

                if (supplierTenant == default(ORM_CMN_Tenant))
                {
                    supplierTenant = new ORM_CMN_Tenant();
                    supplierTenant.CMN_TenantID       = Guid.NewGuid();
                    supplierTenant.TenantITL          = Parameter.TenantITL;
                    supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                    supplierTenant.Creation_Timestamp = DateTime.Now;
                    supplierTenant.Save(Connection, Transaction);

                    supplier_bussinessParticipant.IsTenant = true;
                    supplier_bussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                }

                supplier_bussinessParticipant.DisplayName = Parameter.Supplier_Name;
                supplier_bussinessParticipant.Save(Connection, Transaction);

                var query = new ORM_CMN_BPT_Supplier.Query();
                query.Ext_BusinessParticipant_RefID = supplier_bussinessParticipant.CMN_BPT_BusinessParticipantID;
                query.Tenant_RefID = securityTicket.TenantID;
                query.IsDeleted    = false;

                supplier = ORM_CMN_BPT_Supplier.Query.Search(Connection, Transaction, query).First();

                //edit universal contact details

                var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
                companyInfoQuery.CMN_COM_CompanyInfoID = supplier_bussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfoQuery.Tenant_RefID          = securityTicket.TenantID;
                companyInfoQuery.IsDeleted             = false;

                var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First();

                var universalContactDetailQuery = new ORM_CMN_UniversalContactDetail.Query();
                universalContactDetailQuery.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                universalContactDetailQuery.Tenant_RefID = securityTicket.TenantID;
                universalContactDetailQuery.IsDeleted    = false;

                var universalContactDetail = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, universalContactDetailQuery).First();

                universalContactDetail.Country_639_1_ISOCode = Parameter.CountryISO;
                universalContactDetail.Street_Name           = Parameter.Supplier_Name;
                universalContactDetail.Street_Number         = Parameter.Street_Number;
                universalContactDetail.ZIP         = Parameter.ZIP;
                universalContactDetail.Town        = Parameter.Town;
                universalContactDetail.Region_Code = Parameter.Region_Code;
                universalContactDetail.Save(Connection, Transaction);
            }
            #endregion

            returnValue.Result = supplier.CMN_BPT_SupplierID;
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_SCS_1333 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var adress         = new ORM_CMN_UniversalContactDetail();
            var company2Adress = new ORM_CMN_COM_CompanyInfo_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = adress.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || adress.CMN_UniversalContactDetailID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                company2Adress.Address_UCD_RefID = Parameter.CMN_AddressID;
            }

            if (Parameter.CMN_COM_CompanyInfo_AddressID != Guid.Empty)
            {
                var result = company2Adress.Load(Connection, Transaction, Parameter.CMN_COM_CompanyInfo_AddressID);
                if (result.Status != FR_Status.Success || company2Adress.CMN_COM_CompanyInfo_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            if (Parameter.IsDeleted == true)
            {
                adress.IsDeleted         = true;
                company2Adress.IsDeleted = true;
                company2Adress.Save(Connection, Transaction);
                return(new FR_Guid(adress.Save(Connection, Transaction), adress.CMN_UniversalContactDetailID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.CMN_AddressID == Guid.Empty)
            {
                company2Adress.Address_UCD_RefID = adress.CMN_UniversalContactDetailID;
                company2Adress.Tenant_RefID      = securityTicket.TenantID;
                adress.Tenant_RefID = securityTicket.TenantID;
            }

            adress.Street_Name   = Parameter.Street_Name;
            adress.Street_Number = Parameter.Street_Number;
            adress.Town          = Parameter.City_Name;
            adress.ZIP           = Parameter.City_PostalCode;
            adress.Country_Name  = Parameter.Country_Name;
            adress.Region_Code   = Parameter.Country_ISOCode;

            company2Adress.IsDefault           = Parameter.IsDefault;
            company2Adress.Address_Description = Parameter.AddressName;
            company2Adress.CompanyInfo_RefID   = Parameter.CompanyInfo_RefID;
            company2Adress.IsBilling           = Parameter.IsAddress_Billing;
            company2Adress.IsShipping          = Parameter.IsAddress_Shipping;

            company2Adress.Save(Connection, Transaction);
            return(new FR_Guid(adress.Save(Connection, Transaction), adress.CMN_UniversalContactDetailID));

            #endregion UserCode
        }
Example #24
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3PR_SA_1744 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            #region Save

            if (Parameter.IsDeleted)
            {
                if (ORM_CMN_CAL_EVT_Presentation_ExternalParticipant.Query.Search(Connection, Transaction, new ORM_CMN_CAL_EVT_Presentation_ExternalParticipant.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    CMN_CAL_EVT_Presentation_ParticipantID = Parameter.PresentationID,
                    IsDeleted = false
                }).Count != 1)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                }
                else
                {
                    var presentation_ExternalParticipant = ORM_CMN_CAL_EVT_Presentation_ExternalParticipant.Query.Search(Connection, Transaction, new ORM_CMN_CAL_EVT_Presentation_ExternalParticipant.Query
                    {
                        Tenant_RefID = securityTicket.TenantID,
                        CMN_CAL_EVT_Presentation_ParticipantID = Parameter.PresentationID,
                        IsDeleted = false
                    }).Single();
                    presentation_ExternalParticipant.IsDeleted = true;
                    presentation_ExternalParticipant.Save(Connection, Transaction);

                    returnValue.Result = presentation_ExternalParticipant.CMN_CAL_EVT_Presentation_ParticipantID;
                }
            }
            else
            {
                if (Parameter.CMN_UniversalContactDetailID == Guid.Empty)
                {
                    ORM_CMN_UniversalContactDetail ucd = new ORM_CMN_UniversalContactDetail()
                    {
                        CMN_UniversalContactDetailID = Guid.NewGuid(),
                        Tenant_RefID      = securityTicket.TenantID,
                        First_Name        = Parameter.FirstName,
                        Last_Name         = Parameter.LastName,
                        Contact_Email     = Parameter.Email,
                        Contact_Telephone = Parameter.Phone
                    };
                    ucd.Save(Connection, Transaction);

                    ORM_CMN_CAL_EVT_Presentation_ExternalParticipant presentationParticipant = new ORM_CMN_CAL_EVT_Presentation_ExternalParticipant()
                    {
                        CMN_CAL_EVT_Presentation_ParticipantID = Guid.NewGuid(),
                        Tenant_RefID = securityTicket.TenantID,
                        IsRegisteredThroughWebsite = true,
                        RegistrationDate           = DateTime.Now,
                        Presentation_RefID         = Parameter.PresentationID,
                        Participant_UCD_RefID      = ucd.CMN_UniversalContactDetailID
                    };
                    presentationParticipant.Save(Connection, Transaction);

                    returnValue.Result = presentationParticipant.CMN_CAL_EVT_Presentation_ParticipantID;
                }
            }
            #endregion

            #endregion
            return(returnValue);

            #endregion UserCode
        }
Example #25
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_PH_SP_1124 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            #region Pharmacy
            var pharmacy = ORM_HEC_Pharmacy.Query.Search(Connection, Transaction, new ORM_HEC_Pharmacy.Query
            {
                Tenant_RefID   = securityTicket.TenantID,
                IsDeleted      = false,
                HEC_PharmacyID = Parameter.Pharmacy.PharmacyID
            }).SingleOrDefault();

            if (pharmacy == null)
            {
                pharmacy = new ORM_HEC_Pharmacy();
                pharmacy.Tenant_RefID = securityTicket.TenantID;
            }
            #endregion

            #region CompanyInfo

            var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo.Query
            {
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false,
                CMN_COM_CompanyInfoID = pharmacy.Ext_CompanyInfo_RefID
            }).SingleOrDefault();
            if (companyInfo == null)
            {
                companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.Tenant_RefID = securityTicket.TenantID;


                pharmacy.Ext_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            }

            var contractUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID
            }).SingleOrDefault();
            if (contractUCD == null)
            {
                contractUCD = new ORM_CMN_UniversalContactDetail();
                contractUCD.Tenant_RefID = securityTicket.TenantID;
                contractUCD.IsCompany    = true;
            }
            contractUCD.CompanyName_Line1 = Parameter.Pharmacy.PharmacyName;
            contractUCD.First_Name        = Parameter.Pharmacy.PharmacyName;
            contractUCD.Contact_Email     = Parameter.Pharmacy.Email;
            contractUCD.Contact_Telephone = Parameter.Pharmacy.PhoneNumber;
            contractUCD.Contact_Fax       = Parameter.Pharmacy.Fax;
            contractUCD.Street_Name       = Parameter.Pharmacy.Street;
            contractUCD.Street_Number     = Parameter.Pharmacy.StreetNumber;
            contractUCD.ZIP  = Parameter.Pharmacy.ZipCode;
            contractUCD.Town = Parameter.Pharmacy.Town;
            contractUCD.Save(Connection, Transaction);

            companyInfo.Contact_UCD_RefID = contractUCD.CMN_UniversalContactDetailID;
            companyInfo.Save(Connection, Transaction);

            var ciBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID
            }).SingleOrDefault();
            if (ciBusinessParticipant == null)
            {
                ciBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                ciBusinessParticipant.Tenant_RefID = securityTicket.TenantID;
                ciBusinessParticipant.IsCompany    = true;
                ciBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            }

            ciBusinessParticipant.Save(Connection, Transaction);

            var pharmacyType = EPharmacyType.Internal.Value();
            if (Parameter.Pharmacy.IsExternalPharmacy)
            {
                pharmacyType = EPharmacyType.External.Value();
            }

            var businessParticipantGroup = ORM_CMN_BPT_BusinessParticipant_Group.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_Group.Query
            {
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted                = false,
                GlobalPropertyMatchingID = pharmacyType
            }).SingleOrDefault();
            if (businessParticipantGroup == null)
            {
                businessParticipantGroup = new ORM_CMN_BPT_BusinessParticipant_Group();
                businessParticipantGroup.Tenant_RefID             = securityTicket.TenantID;
                businessParticipantGroup.GlobalPropertyMatchingID = pharmacyType;
                businessParticipantGroup.Save(Connection, Transaction);
            }

            var bpToBpGroup = ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                CMN_BPT_BusinessParticipant_RefID       = ciBusinessParticipant.CMN_BPT_BusinessParticipantID,
                CMN_BPT_BusinessParticipant_Group_RefID = businessParticipantGroup.CMN_BPT_BusinessParticipant_GroupID
            }).SingleOrDefault();
            if (bpToBpGroup == null)
            {
                bpToBpGroup = new ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup();
                bpToBpGroup.Tenant_RefID = securityTicket.TenantID;
                bpToBpGroup.CMN_BPT_BusinessParticipant_Group_RefID = businessParticipantGroup.CMN_BPT_BusinessParticipant_GroupID;
                bpToBpGroup.CMN_BPT_BusinessParticipant_RefID       = ciBusinessParticipant.CMN_BPT_BusinessParticipantID;
                bpToBpGroup.Save(Connection, Transaction);
            }
            #endregion

            #region ContactPersonInfo
            var contactInfo = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                CMN_BPT_BusinessParticipantID = pharmacy.ContactPerson_BusinessParticipant_RefID
            }).SingleOrDefault();
            if (contactInfo == null)
            {
                contactInfo = new ORM_CMN_BPT_BusinessParticipant();
                contactInfo.Tenant_RefID    = securityTicket.TenantID;
                contactInfo.IsNaturalPerson = true;
            }

            var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query
            {
                Tenant_RefID         = securityTicket.TenantID,
                IsDead               = false,
                CMN_PER_PersonInfoID = contactInfo.IfNaturalPerson_CMN_PER_PersonInfo_RefID
            }).SingleOrDefault();
            if (personInfo == null)
            {
                personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Tenant_RefID = securityTicket.TenantID;
            }
            var splitedName = Parameter.Pharmacy.ContactPersonName.Split(' ');
            var firstName   = splitedName.Length > 1 ? string.Join(" ", splitedName.Take(splitedName.Length - 1)) : splitedName[0];
            var lastName    = splitedName.Length > 1 ? splitedName.Last() : "";

            personInfo.FirstName = firstName;
            personInfo.LastName  = lastName;
            personInfo.Save(Connection, Transaction);

            contactInfo.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
            contactInfo.Save(Connection, Transaction);

            pharmacy.ContactPerson_BusinessParticipant_RefID = contactInfo.CMN_BPT_BusinessParticipantID;

            #endregion

            pharmacy.Save(Connection, Transaction);

            returnValue.Result = pharmacy.HEC_PharmacyID;
            return(returnValue);

            #endregion UserCode
        }