protected static FR_L6WS_GSCDfSCID_1458 Execute(DbConnection Connection, DbTransaction Transaction, P_L6WS_GSCDfSCID_1458 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L6WS_GSCDfSCID_1458(); //Put your code here if (Parameter.ShoppingCartID == Guid.Empty) { return(null); } returnValue.Result = new L6WS_GSCDfSCID_1458(); #region ShoppingCart returnValue.Result.ShoppingCart = cls_Get_ShoppingCart_for_ShoppingCartID.Invoke(Connection, Transaction, new P_L6WS_GSCfSCID_1448() { ShoppingCartID = Parameter.ShoppingCartID }, securityTicket).Result; if (returnValue.Result.ShoppingCart == null) { return(null); } #endregion #region ShoppingCart_Notes returnValue.Result.ShoppingCart_Notes = cls_Get_ShoppingCart_Notes_for_ShoppingCartID.Invoke(Connection, Transaction, new P_L5AWSAR_GSCNfSC_1454() { ShoppingCartID = Parameter.ShoppingCartID }, securityTicket).Result.OrderBy(i => i.UpdatedOn).ToArray(); #endregion #region Articles ORM_ORD_PRC_ShoppingCart_Product.Query shoppingCartProductsQuery = new ORM_ORD_PRC_ShoppingCart_Product.Query(); shoppingCartProductsQuery.ORD_PRC_ShoppingCart_RefID = returnValue.Result.ShoppingCart.ORD_PRC_ShoppingCartID; shoppingCartProductsQuery.IsDeleted = false; shoppingCartProductsQuery.IsCanceled = false; shoppingCartProductsQuery.Tenant_RefID = securityTicket.TenantID; List <ORM_ORD_PRC_ShoppingCart_Product> productList = ORM_ORD_PRC_ShoppingCart_Product.Query.Search(Connection, Transaction, shoppingCartProductsQuery); List <Guid> articleIds = new List <Guid>(); if (productList != null && productList.Count > 0) { articleIds.AddRange(productList.Select(i => i.CMN_PRO_Product_RefID)); } List <L3AR_GAfAL_0942> articleInfos = new List <L3AR_GAfAL_0942>(); if (articleIds.Count > 0) { articleInfos = cls_Get_Articles_for_ArticleList.Invoke(Connection, Transaction, new P_L3AR_GAfAL_0942() { ProductID_List = articleIds.ToArray() }, securityTicket).Result.ToList(); } List <L6WS_GSCDfSCID_1458_Product> products = new List <L6WS_GSCDfSCID_1458_Product>(); L6WS_GSCDfSCID_1458_Product product; L3AR_GAfAL_0942 articleInfo; double taxRate = 0; #region ORM and Querie objects ORM_CMN_PRO_Product orm_product; ORM_CMN_SLS_Price.Query priceQuery; ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query taxAssignmentQuery; ORM_ACC_TAX_Tax orm_tax; #endregion foreach (var productItem in productList) { #region check procurement order date and number if (returnValue.Result.OrderDate == null || returnValue.Result.OrderDate.Ticks == 0) { ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition.Query shoppingCartOrderPositionQuery = new ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition.Query(); shoppingCartOrderPositionQuery.IsDeleted = false; shoppingCartOrderPositionQuery.Tenant_RefID = securityTicket.TenantID; shoppingCartOrderPositionQuery.ORD_PRC_ShoppingCart_Product_RefID = productItem.ORD_PRC_ShoppingCart_ProductID; List <ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition> shoppingCartOrderPositionList = ORM_ORD_PRC_ShoppingCart_2_ProcurementOrderPosition.Query.Search(Connection, Transaction, shoppingCartOrderPositionQuery); foreach (var shoppingCartOrderPosition in shoppingCartOrderPositionList) { ORM_ORD_PRC_ProcurementOrder_Position procurementOrder_Position = new ORM_ORD_PRC_ProcurementOrder_Position(); var procurementOrder_PositionResult = procurementOrder_Position.Load(Connection, Transaction, shoppingCartOrderPosition.ORD_PRC_ProcurementOrder_Position_RefID); if (procurementOrder_PositionResult.Status != FR_Status.Success || procurementOrder_Position.ORD_PRC_ProcurementOrder_PositionID == Guid.Empty) { continue; } ORM_ORD_PRC_ProcurementOrder_Header procurementOrder_Header = new ORM_ORD_PRC_ProcurementOrder_Header(); var procurementOrder_HeaderResult = procurementOrder_Header.Load(Connection, Transaction, procurementOrder_Position.ProcurementOrder_Header_RefID); if (procurementOrder_HeaderResult.Status != FR_Status.Success || procurementOrder_Header.ORD_PRC_ProcurementOrder_HeaderID == Guid.Empty) { continue; } returnValue.Result.OrderDate = procurementOrder_Header.ProcurementOrder_Date; returnValue.Result.OrderNumber = procurementOrder_Header.ProcurementOrder_Number; break; } } #endregion #region get product orm_product = new ORM_CMN_PRO_Product(); var productResult = orm_product.Load(Connection, Transaction, productItem.CMN_PRO_Product_RefID); if (productResult.Status != FR_Status.Success || orm_product.CMN_PRO_ProductID == Guid.Empty) { continue; } #endregion #region get price ORM_CMN_PRO_SubscribedCatalog.Query catalogQuery = new ORM_CMN_PRO_SubscribedCatalog.Query(); catalogQuery.Tenant_RefID = securityTicket.TenantID; catalogQuery.IsDeleted = false; List <ORM_CMN_PRO_SubscribedCatalog> catalogList = ORM_CMN_PRO_SubscribedCatalog.Query.Search(Connection, Transaction, catalogQuery); priceQuery = new ORM_CMN_SLS_Price.Query(); priceQuery.CMN_PRO_Product_RefID = orm_product.CMN_PRO_ProductID; priceQuery.Tenant_RefID = securityTicket.TenantID; priceQuery.IsDeleted = false; List <ORM_CMN_SLS_Price> prices = ORM_CMN_SLS_Price.Query.Search(Connection, Transaction, priceQuery); ORM_CMN_SLS_Price price = prices.Where(i => catalogList.Select(j => j.SubscribedCatalog_PricelistRelease_RefID).Contains(i.PricelistRelease_RefID)).FirstOrDefault(); #endregion #region get taxes taxRate = 0; taxAssignmentQuery = new ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query(); taxAssignmentQuery.Product_RefID = orm_product.CMN_PRO_ProductID; taxAssignmentQuery.Tenant_RefID = securityTicket.TenantID; taxAssignmentQuery.IsDeleted = false; List <ORM_CMN_PRO_Product_SalesTaxAssignmnet> taxAssignmentList = ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query.Search(Connection, Transaction, taxAssignmentQuery); foreach (var taxAssignment in taxAssignmentList) { orm_tax = new ORM_ACC_TAX_Tax(); var taxResult = orm_tax.Load(Connection, Transaction, taxAssignment.ApplicableSalesTax_RefID); if (taxResult.Status == FR_Status.Success && orm_tax.ACC_TAX_TaxeID != Guid.Empty) { taxRate += orm_tax.TaxRate; } } #endregion #region set product item product = new L6WS_GSCDfSCID_1458_Product(); product.CMN_PRO_Product_RefID = orm_product.CMN_PRO_ProductID; product.PriceAmount = price == null ? 0 : (price.PriceAmount == null ? 0 : Double.Parse(price.PriceAmount.ToString())); product.TaxRate = taxRate; product.Quantity = productItem.Quantity.ToString(); product.IsProductCanceled = productItem.IsCanceled; if (!String.IsNullOrEmpty(productItem.Comment)) { string[] comments = productItem.Comment.Split('@'); if (comments.Length == 2) { product.ProductComment = comments[1]; } } product.IsProductReplacementAllowed = productItem.IsProductReplacementAllowed; articleInfo = articleInfos.FirstOrDefault(i => i.CMN_PRO_ProductID == orm_product.CMN_PRO_ProductID); if (articleInfo != null) { product.Product_Name = articleInfo.Product_Name; product.Product_Number = articleInfo.Product_Number; product.UnitAmount = articleInfo.UnitAmount.ToString(); product.UnitIsoCode = articleInfo.UnitIsoCode; product.DossageFormName = articleInfo.DossageFormName; } #endregion products.Add(product); } returnValue.Result.Products = products.ToArray(); #endregion #region Person info // current user ORM_CMN_PER_PersonInfo_2_Account.Query accountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); accountQuery.USR_Account_RefID = securityTicket.AccountID; accountQuery.Tenant_RefID = securityTicket.TenantID; accountQuery.IsDeleted = false; ORM_CMN_PER_PersonInfo_2_Account account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, accountQuery).FirstOrDefault(); if (account != null) { ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo(); var personInfoResult = personInfo.Load(Connection, Transaction, account.CMN_PER_PersonInfo_RefID); if (personInfoResult.Status == FR_Status.Success && personInfo.CMN_PER_PersonInfoID != Guid.Empty) { returnValue.Result.CurrentUser = personInfo.FirstName + " " + personInfo.LastName; } } #region Approved by user ORM_ORD_PRC_ShoppingCart_Status.Query stusesQuery = new ORM_ORD_PRC_ShoppingCart_Status.Query(); stusesQuery.Tenant_RefID = securityTicket.TenantID; stusesQuery.IsDeleted = false; List <ORM_ORD_PRC_ShoppingCart_Status> statuses = ORM_ORD_PRC_ShoppingCart_Status.Query.Search(Connection, Transaction, stusesQuery); ORM_ORD_PRC_ShoppingCart_Status approvedStatus = statuses.FirstOrDefault(i => i.GlobalPropertyMatchingID.Contains("approved")); if (approvedStatus != null) { ORM_ORD_PRC_ShoppingCartStatus_History.Query statusHistoryQuery = new ORM_ORD_PRC_ShoppingCartStatus_History.Query(); statusHistoryQuery.Tenant_RefID = securityTicket.TenantID; statusHistoryQuery.IsDeleted = false; statusHistoryQuery.ORD_PRC_ShoppingCart_RefID = returnValue.Result.ShoppingCart.ORD_PRC_ShoppingCartID; statusHistoryQuery.ORD_PRC_ShoppingCart_Status_RefID = approvedStatus.ORD_PRC_ShoppingCart_StatusID; ORM_ORD_PRC_ShoppingCartStatus_History statusHistory = ORM_ORD_PRC_ShoppingCartStatus_History.Query.Search(Connection, Transaction, statusHistoryQuery).FirstOrDefault(); if (statusHistory != null) { accountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); accountQuery.USR_Account_RefID = statusHistory.PerformedBy_Account_RefID; accountQuery.Tenant_RefID = securityTicket.TenantID; accountQuery.IsDeleted = false; account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, accountQuery).FirstOrDefault(); if (account != null) { ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo(); var personInfoResult = personInfo.Load(Connection, Transaction, account.CMN_PER_PersonInfo_RefID); if (personInfoResult.Status == FR_Status.Success && personInfo.CMN_PER_PersonInfoID != Guid.Empty) { returnValue.Result.ApprovedByUser = personInfo.FirstName + " " + personInfo.LastName; returnValue.Result.DateOfApproval = statusHistory.Creation_Timestamp; } } } } #endregion #endregion return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3TX_STX_1119 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); // Set Economic region if (Parameter.EconomicRegion_RefID == Guid.Empty) { var countryRegion = ORM_CMN_Country_2_EconomicRegion.Query.Search(Connection, Transaction, new ORM_CMN_Country_2_EconomicRegion.Query { IsDeleted = false, CMN_Country_RefID = Parameter.Country_RefID }).SingleOrDefault(); if (countryRegion == null) { var country = new ORM_CMN_Country(); country.Load(Connection, Transaction, Parameter.Country_RefID); var region = new ORM_CMN_EconomicRegion(); region.EconomicRegion_Name = new Dict() { DictionaryID = Guid.NewGuid() }; region.Tenant_RefID = country.Tenant_RefID; region.IsEconomicRegionCountry = true; foreach (var content in country.Country_Name.Contents) { region.EconomicRegion_Name.AddEntry(content.LanguageID, content.Content); } region.Save(Connection, Transaction); countryRegion = new ORM_CMN_Country_2_EconomicRegion(); countryRegion.CMN_EconomicRegion_RefID = region.CMN_EconomicRegionID; countryRegion.CMN_Country_RefID = country.CMN_CountryID; countryRegion.Tenant_RefID = country.Tenant_RefID; countryRegion.Save(Connection, Transaction); } Parameter.EconomicRegion_RefID = countryRegion.CMN_EconomicRegion_RefID; } var item = new ORM_ACC_TAX_Tax(); if (Parameter.ACC_TAX_TaxeID != Guid.Empty) { item.Load(Connection, Transaction, Parameter.ACC_TAX_TaxeID); } if (Parameter.IsDeleted == true) { item.IsDeleted = true; return(new FR_Guid(item.Save(Connection, Transaction), item.ACC_TAX_TaxeID)); } //Creation specific parameters (Tenant, Account ... ) if (Parameter.ACC_TAX_TaxeID == Guid.Empty) { item.Tenant_RefID = securityTicket.TenantID; } item.EconomicRegion_RefID = Parameter.EconomicRegion_RefID; item.TaxName = Parameter.TaxName; item.TaxRate = Parameter.TaxRate; return(new FR_Guid(item.Save(Connection, Transaction), item.ACC_TAX_TaxeID)); #endregion UserCode }