protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5PO_UPOS_1546 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Bool(); //Put your code here var status = ORM_ORD_PRC_ProcurementOrder_Status.Query.Search(Connection, Transaction, new ORM_ORD_PRC_ProcurementOrder_Status.Query() { Tenant_RefID = securityTicket.TenantID, GlobalPropertyMatchingID = Parameter.Status, IsDeleted = false }).SingleOrDefault(); if (status != null) { var procurementOrderHeader = new ORM_ORD_PRC_ProcurementOrder_Header(); procurementOrderHeader.Load(Connection, Parameter.ProcurementOrderHeaderID); //if procurement order header with given ID doesn't exist, don't make changes in database if (procurementOrderHeader != null) { ORM_ORD_PRC_ProcurementOrder_StatusHistory statusHistory = new ORM_ORD_PRC_ProcurementOrder_StatusHistory(); statusHistory.Tenant_RefID = securityTicket.TenantID; statusHistory.ORD_PRC_ProcurementOrder_StatusHistoryID = Guid.NewGuid(); statusHistory.ProcurementOrder_Header_RefID = Parameter.ProcurementOrderHeaderID; statusHistory.ProcurementOrder_Status_RefID = status.ORD_PRC_ProcurementOrder_StatusID; statusHistory.Save(Connection, Transaction); procurementOrderHeader.Current_ProcurementOrderStatus_RefID = status.ORD_PRC_ProcurementOrder_StatusID; procurementOrderHeader.Save(Connection, Transaction); } } return(returnValue); #endregion UserCode }
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_L6SH_GMDfPH_0500_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L6SH_GMDfPH_0500 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L6SH_GMDfPH_0500_Array(); //Put your code here var supplier = cls_Get_Suppliers_for_PrivateSubscribedCatalogs.Invoke(Connection, Transaction, securityTicket).Result.FirstOrDefault(); #region Get All OrganizationalUnits //TODO: This is quick and dirty solution, remove it as soon as SLorenz remove MaveFile var organizationalUnits = ORM_CMN_BPT_CTM_OrganizationalUnit.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_OrganizationalUnit.Query() { Tenant_RefID = Guid.Parse(supplier.TenantITL) }); #endregion var paramShoppingProducts = new P_L5PO_GPPaSCIfH_1750(); paramShoppingProducts.ProcurementOrderHeaderID = Parameter.ProcurementHeaderID; var shoppingCartProcurementPositions = cls_Get_ProcurementPositions_and_ShoppingCartInfo_for_HeaderID.Invoke(Connection, Transaction, paramShoppingProducts, securityTicket) .Result.OrderBy(x => x.ORD_PRC_ShoppingCart_RefID); var maveResults = new List <L6SH_GMDfPH_0500>(); var procurementHeader = new ORM_ORD_PRC_ProcurementOrder_Header(); procurementHeader.Load(Connection, Transaction, Parameter.ProcurementHeaderID); var previousShoppingCartID = Guid.Empty; var currentShoppingCart = new ORM_ORD_PRC_ShoppingCart(); var accountsForTenant = cls_Get_AllDisplayNames_of_Accounts_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result; foreach (var shoppingCartProcurementPosition in shoppingCartProcurementPositions) { var maveResult = new L6SH_GMDfPH_0500(); var currentProduct = new ORM_CMN_PRO_Product(); currentProduct.Load(Connection, Transaction, shoppingCartProcurementPosition.CMN_PRO_Product_RefID); if (currentShoppingCart.ORD_PRC_ShoppingCartID == Guid.Empty || shoppingCartProcurementPosition.ORD_PRC_ShoppingCart_RefID != previousShoppingCartID) { currentShoppingCart.Load(Connection, Transaction, shoppingCartProcurementPosition.ORD_PRC_ShoppingCart_RefID); } var userThatApproved = accountsForTenant.FirstOrDefault(x => x.USR_AccountID == currentShoppingCart.CreatedBy_Account_RefID); #region Add ShoppingCart Position //TODO: This is quick and dirty solution, remove it as soon as SLorenz remove MaveFile var organizationalUnit = organizationalUnits.Where(i => i.CustomerTenant_OfficeITL == shoppingCartProcurementPosition.CMN_STR_OfficeID.ToString()).Single(); maveResult.CustomerNumber = supplier.ExternalSupplierProvidedIdentifier; maveResult.OrgUnitNumber = organizationalUnit.InternalOrganizationalUnitNumber; maveResult.OrderDateTime = procurementHeader.ProcurementOrder_Date; maveResult.PriceOfAllPositionsOverAll = procurementHeader.TotalValue_BeforeTax; maveResult.PZNorTXT = currentProduct.Product_Number; maveResult.UserThatApproved = userThatApproved.DisplayName; maveResult.OrderQuantity = Convert.ToInt32(shoppingCartProcurementPosition.Position_Quantity); maveResult.PositionPricePerUnit = shoppingCartProcurementPosition.Position_ValuePerUnit; maveResult.Comment = string.Empty; maveResult.IncreasingNumber = "108384"; maveResults.Add(maveResult); #endregion #region Add ShoppingCart Comment // get all comments for current shopping chart and do that just once! if (currentShoppingCart.ORD_PRC_ShoppingCartID != previousShoppingCartID) { previousShoppingCartID = currentShoppingCart.ORD_PRC_ShoppingCartID; var shoppingNoteParameter = new P_L5AWSAR_GSCNfSC_1454(); shoppingNoteParameter.ShoppingCartID = currentShoppingCart.ORD_PRC_ShoppingCartID; var shoppingCartNotes = cls_Get_ShoppingCart_Notes_for_ShoppingCartID.Invoke(Connection, Transaction, shoppingNoteParameter, securityTicket).Result; foreach (var note in shoppingCartNotes) { if (!note.IsNoteForProcurementOrder) { continue; } maveResult = new L6SH_GMDfPH_0500(); maveResult.CustomerNumber = supplier.ExternalSupplierProvidedIdentifier; maveResult.OrgUnitNumber = organizationalUnit.InternalOrganizationalUnitNumber; maveResult.OrderDateTime = procurementHeader.ProcurementOrder_Date; maveResult.PriceOfAllPositionsOverAll = procurementHeader.TotalValue_BeforeTax; maveResult.PZNorTXT = "TEXT"; maveResult.UserThatApproved = userThatApproved.DisplayName; maveResult.OrderQuantity = 0; maveResult.PositionPricePerUnit = 0; maveResult.Comment = note.Memo_Text; maveResult.IncreasingNumber = "108384"; maveResults.Add(maveResult); } } #endregion } returnValue.Result = maveResults.ToArray(); return(returnValue); #endregion UserCode }
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 }
protected static FR_L6PO_GPfCOCM_1502 Execute(DbConnection Connection, DbTransaction Transaction, P_L6PO_GPfCOCM_1502 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L6PO_GPfCOCM_1502(); returnValue.Result = new L6PO_GPfCOCM_1502(); #region Get Languages 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; var LanguageID = DBLanguages.Where(i => i.ISO_639_1 == "DE").SingleOrDefault().CMN_LanguageID; #endregion #region ORM_ORD_PRC_ProcurementOrder_Header var procurementHeader = new ORM_ORD_PRC_ProcurementOrder_Header(); procurementHeader.Load(Connection, Transaction, Parameter.ProcurementHeaderID); #endregion #region ORM_ORD_PRC_ProcurementOrder_Positions var paramShoppingProducts = new P_L5PO_GPPaSCIfH_1750(); paramShoppingProducts.ProcurementOrderHeaderID = Parameter.ProcurementHeaderID; var shoppingProducts = cls_Get_ProcurementPositions_and_ShoppingCartInfo_for_HeaderID.Invoke(Connection, Transaction, paramShoppingProducts, securityTicket).Result; #endregion #region Positions var positions = new List <L6PO_GPfCOCM_1502a>(); foreach (var shoppingProduct in shoppingProducts) { var product = new ORM_CMN_PRO_Product(); product.Load(Connection, Transaction, shoppingProduct.CMN_PRO_Product_RefID); if (String.IsNullOrEmpty(product.ProductITL)) { product.ProductITL = Guid.NewGuid().ToString(); product.Save(Connection, Transaction); } var catalogSubscription = new ORM_CMN_PRO_SubscribedCatalog(); catalogSubscription.Load(Connection, Transaction, product.IfImportedFromExternalCatalog_CatalogSubscription_RefID); var position = new L6PO_GPfCOCM_1502a(); position.ProductITL = product.ProductITL; position.ProductNumber = product.Product_Number; position.ProductName = product.Product_Name.GetContent(LanguageID); position.ProductDescription = product.Product_Description.GetContent(LanguageID); position.Comment = "NotDefinedBySender"; position.Quantity = shoppingProduct.Position_Quantity; position.IsProductReplacementAllowed = shoppingProduct.IsProductReplacementAllowed; position.SourceCatalogITL = catalogSubscription.CatalogCodeITL; position.UnitPrice = shoppingProduct.Position_ValuePerUnit; position.NetoPrice = shoppingProduct.Position_ValueTotal; var shoppingCart2Office = ORM_ORD_PRC_Office_ShoppingCart.Query.Search(Connection, Transaction, new ORM_ORD_PRC_Office_ShoppingCart.Query { ORD_PRC_ShoppingCart_RefID = shoppingProduct.ORD_PRC_ShoppingCart_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID } ).Single(); position.Quantites = new L6PO_GPfCOCM_1502b[] { new L6PO_GPfCOCM_1502b() { OfficeID = shoppingCart2Office.CMN_STR_Office_RefID, Quantity = shoppingProduct.Position_Quantity } }; positions.Add(position); } #endregion #region Comments var procurmentNotes = ORM_ORD_PRC_ProcurementOrder_Note.Query.Search(Connection, Transaction, new ORM_ORD_PRC_ProcurementOrder_Note.Query() { ORD_PRC_ProcurementOrder_Header_RefID = procurementHeader.ORD_PRC_ProcurementOrder_HeaderID, IsDeleted = false }).ToList(); var comments = new List <L6PO_GPfCOCM_1502c>(); foreach (var note in procurmentNotes) { comments.Add( new L6PO_GPfCOCM_1502c() { OfficeID = note.CMN_STR_Office_RefID, Content = note.Comment, PublilshDate = note.NotePublishDate, SequenceNumber = note.SequenceOrderNumber, Title = note.Title } ); } #endregion returnValue.Result.ProcurProcurementHeaderID = procurementHeader.ORD_PRC_ProcurementOrder_HeaderID; returnValue.Result.OrderNumber = procurementHeader.ProcurementOrder_Number; returnValue.Result.ProcurementOrderDate = procurementHeader.ProcurementOrder_Date; returnValue.Result.Comments = comments.ToArray(); returnValue.Result.Positions = positions.ToArray(); return(returnValue); #endregion UserCode }