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 }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_EBH_1108 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); #region Preloading data var BillParam = Parameter.Bill_Parameter.BillHeaderData; var billHeader = CL1_BIL.ORM_BIL_BillHeader.Query.Search(Connection, Transaction, new CL1_BIL.ORM_BIL_BillHeader.Query() { BIL_BillHeaderID = BillParam.BIL_BillHeaderID }).SingleOrDefault(); var ucd = CL1_CMN.ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new CL1_CMN.ORM_CMN_UniversalContactDetail.Query() { CMN_UniversalContactDetailID = BillParam.CMN_UniversalContactDetailID }).SingleOrDefault(); var account = new CL1_USR.ORM_USR_Account(); account.Load(Connection, Transaction, securityTicket.AccountID); var customer = CL1_CMN_BPT_CTM.ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new CL1_CMN_BPT_CTM.ORM_CMN_BPT_CTM_Customer.Query() { CMN_BPT_CTM_CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID }).SingleOrDefault(); #endregion if (BillParam.BillingAddressID != Guid.Empty) { 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(); ucd.CMN_UniversalContactDetailID = BillParam.CMN_UniversalContactDetailID; ucd.Country_639_1_ISOCode = customerAddress.Country_639_1_ISOCode; ucd.Country_Name = customerAddress.Country_Name; ucd.Street_Name = customerAddress.Street_Name; ucd.Street_Number = customerAddress.Street_Number; ucd.Town = customerAddress.Town; ucd.ZIP = customerAddress.ZIP; ucd.Tenant_RefID = account.Tenant_RefID; ucd.CompanyName_Line1 = BillParam.BillingReceiverCustomer.DisplayName; ucd.First_Name = BillParam.BillingReceiverCustomer.FirstName; ucd.Last_Name = BillParam.BillingReceiverCustomer.LastName; ucd.IsCompany = BillParam.BillingReceiverCustomer.IsCompany; ucd.Save(Connection, Transaction); } billHeader.CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID; billHeader.BillRecipient_BuisnessParticipant_RefID = customer.Ext_BusinessParticipant_RefID; billHeader.Tenant_RefID = account.Tenant_RefID; billHeader.BillingAddress_UCD_RefID = ucd.CMN_UniversalContactDetailID; billHeader.DateOnBill = BillParam.BillingDate; billHeader.BillComment = BillParam.Comment; billHeader.BillHeader_PaymentCondition_RefID = Parameter.Bill_Parameter.BillHeaderData.PaymentTargetID; billHeader.Save(Connection, Transaction); #region Method of Payment var methodOfPayment = CL1_BIL.ORM_BIL_BillHeader_MethodOfPayment.Query.Search(Connection, Transaction, new CL1_BIL.ORM_BIL_BillHeader_MethodOfPayment.Query { BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID }).SingleOrDefault(); if (methodOfPayment == null) { 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.ACC_PAY_Type_RefID = Parameter.Bill_Parameter.BillHeaderData.PaymentTypeID; methodOfPayment.Save(Connection, Transaction); #endregion returnValue.Result = billHeader.BIL_BillHeaderID; return(returnValue); #endregion UserCode }