Exemplo n.º 1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5AAS_SSA_1528 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            var item             = new CL1_CMN_COM.ORM_CMN_COM_CompanyInfo_Address();
            var universalContact = new CL1_CMN.ORM_CMN_UniversalContactDetail();
            if (Parameter.CMN_COM_CompanyInfo_AddressID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.CMN_COM_CompanyInfo_AddressID);
                if (item.Address_UCD_RefID != Guid.Empty)
                {
                    universalContact.Load(Connection, Transaction, item.Address_UCD_RefID);
                }
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted             = true;
                universalContact.IsDeleted = true;
                universalContact.Save(Connection, Transaction);
                return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_COM_CompanyInfo_AddressID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.CMN_COM_CompanyInfo_AddressID == Guid.Empty)
            {
                item.Tenant_RefID             = securityTicket.TenantID;
                universalContact.Tenant_RefID = securityTicket.TenantID;
            }

            if (Parameter.IsDefault)
            {
                // Get all default company addresses
                var addresses = CL1_CMN_COM.ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction,
                                                                                         new CL1_CMN_COM.ORM_CMN_COM_CompanyInfo_Address.Query
                {
                    IsDeleted         = false,
                    IsDefault         = true,
                    IsBilling         = Parameter.IsBilling,
                    IsShipping        = Parameter.IsShipping,
                    CompanyInfo_RefID = item.CompanyInfo_RefID
                });
                addresses = addresses.Where(x => x.CMN_COM_CompanyInfo_AddressID != item.CMN_COM_CompanyInfo_AddressID).ToList();
                addresses.ForEach(x => x.IsDefault = false);
                addresses.ForEach(x => x.Save(Connection, Transaction));
            }
            item.IsContact                         = true;
            item.Address_UCD_RefID                 = universalContact.CMN_UniversalContactDetailID;
            item.CompanyInfo_RefID                 = Parameter.CompanyInfo_RefID;
            item.IsBilling                         = Parameter.IsBilling;
            item.IsShipping                        = Parameter.IsShipping;
            item.Address_UCD_RefID                 = universalContact.CMN_UniversalContactDetailID;
            item.IsDefault                         = Parameter.IsDefault;
            universalContact.CareOf                = Parameter.CareOf;
            universalContact.Street_Name           = Parameter.Street_Name;
            universalContact.Street_Number         = Parameter.Street_Number;
            universalContact.ZIP                   = Parameter.ZIP;
            universalContact.Town                  = Parameter.Town;
            universalContact.Country_639_1_ISOCode = Parameter.Country_639_1_ISOCode;
            universalContact.Save(Connection, Transaction);
            return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_COM_CompanyInfo_AddressID));

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

            var item = new CL1_CMN_BPT.ORM_CMN_BPT_Supplier();
            var businessParticipant = new CL1_CMN_BPT.ORM_CMN_BPT_BusinessParticipant();
            var companyInfo         = new CL1_CMN_COM.ORM_CMN_COM_CompanyInfo();
            var universalContact    = new CL1_CMN.ORM_CMN_UniversalContactDetail();
            var discountValue       = new CL1_CMN_BPT.ORM_CMN_BPT_Supplier_DiscountValue();
            var cashDiscountValue   = new CL1_CMN_BPT.ORM_CMN_BPT_Supplier_DiscountValue();


            var discountQuery = new CL1_ORD_PRC.ORM_ORD_PRC_DiscountType.Query();
            discountQuery.Tenant_RefID             = securityTicket.TenantID;
            discountQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EDiscountType.MainDiscount);
            var discount = CL1_ORD_PRC.ORM_ORD_PRC_DiscountType.Query.Search(Connection, Transaction, discountQuery).Single();

            var scontoQuery = new CL1_ORD_PRC.ORM_ORD_PRC_DiscountType.Query();
            scontoQuery.Tenant_RefID             = securityTicket.TenantID;
            scontoQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EDiscountType.CashDiscount);
            var sconto = CL1_ORD_PRC.ORM_ORD_PRC_DiscountType.Query.Search(Connection, Transaction, scontoQuery).SingleOrDefault();



            if (Parameter.CMN_BPT_SupplierID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.CMN_BPT_SupplierID);
                if (item.Ext_BusinessParticipant_RefID != Guid.Empty)
                {
                    businessParticipant.Load(Connection, Transaction, item.Ext_BusinessParticipant_RefID);
                }
                if (businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID != Guid.Empty)
                {
                    companyInfo.Load(Connection, Transaction, businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID);
                }
                if (companyInfo.Contact_UCD_RefID != Guid.Empty)
                {
                    universalContact.Load(Connection, Transaction, companyInfo.Contact_UCD_RefID);
                }

                var discountValueQuery = new CL1_CMN_BPT.ORM_CMN_BPT_Supplier_DiscountValue.Query();
                discountValueQuery.Supplier_RefID             = Parameter.CMN_BPT_SupplierID;
                discountValueQuery.Tenant_RefID               = securityTicket.TenantID;
                discountValueQuery.ORD_PRC_DiscountType_RefID = discount.ORD_PRC_DiscountTypeID;
                var foundDiscountValue = CL1_CMN_BPT.ORM_CMN_BPT_Supplier_DiscountValue.Query.Search(Connection, Transaction, discountValueQuery);

                if (foundDiscountValue.Count == 1)
                {
                    discountValue = foundDiscountValue.Single();
                }

                var scontoValueQuery = new CL1_CMN_BPT.ORM_CMN_BPT_Supplier_DiscountValue.Query();
                scontoValueQuery.Supplier_RefID             = Parameter.CMN_BPT_SupplierID;
                scontoValueQuery.Tenant_RefID               = securityTicket.TenantID;
                scontoValueQuery.ORD_PRC_DiscountType_RefID = sconto.ORD_PRC_DiscountTypeID;
                var foundCashValue = CL1_CMN_BPT.ORM_CMN_BPT_Supplier_DiscountValue.Query.Search(Connection, Transaction, scontoValueQuery);

                if (foundCashValue.Count == 1)
                {
                    cashDiscountValue = foundCashValue.Single();
                }
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                businessParticipant.IsDeleted = true;
                companyInfo.IsDeleted         = true;
                universalContact.IsDeleted    = true;

                #region Delete company info address
                P_L5AAS_GAfCI_1526 addressParam = new P_L5AAS_GAfCI_1526();
                addressParam.CompanyInfoID = companyInfo.CMN_COM_CompanyInfoID;
                var addresses = cls_Get_Addresses_for_CompanyInfoID.Invoke(Connection, Transaction, addressParam, securityTicket).Result;
                foreach (var a in addresses)
                {
                    P_L5AAS_SSA_1528 addressSaveParameter = new P_L5AAS_SSA_1528();
                    addressSaveParameter.CMN_COM_CompanyInfo_AddressID = a.CMN_COM_CompanyInfo_AddressID;
                    addressSaveParameter.CompanyInfo_RefID             = a.CompanyInfo_RefID;
                    addressSaveParameter.IsDeleted = true;
                    cls_Save_Supplier_Address.Invoke(Connection, Transaction, addressSaveParameter, securityTicket);
                }
                #endregion

                #region Delete Contact Persons
                P_L5AAS_GCPIfBP_1607 contactPersonParam = new P_L5AAS_GCPIfBP_1607();
                contactPersonParam.BusinessParticipantID = businessParticipant.CMN_BPT_BusinessParticipantID;
                var contactPersons = cls_Get_Contact_Person_Info_for_BusinessParticipantID.Invoke(Connection, Transaction, contactPersonParam, securityTicket).Result;
                foreach (var c in contactPersons)
                {
                    P_L5AAS_SSPCI_0832 contactPersonSaveParam = new P_L5AAS_SSPCI_0832();
                    contactPersonSaveParam.AssociatedBusinessParticipant_RefID = c.AssociatedBusinessParticipant_RefID;
                    contactPersonSaveParam.CMN_AddressID = c.CMN_AddressID;
                    contactPersonSaveParam.CMN_BPT_BusinessParticipantID = c.CMN_BPT_BusinessParticipantID;
                    cls_Save_Supplier_Contact_Person_Info.Invoke(Connection, Transaction, contactPersonSaveParam, securityTicket);
                }
                #endregion

                businessParticipant.Save(Connection, Transaction);
                companyInfo.Save(Connection, Transaction);
                universalContact.Save(Connection, Transaction);
                return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_BPT_SupplierID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.CMN_BPT_SupplierID == Guid.Empty)
            {
                item.Tenant_RefID = securityTicket.TenantID;
                businessParticipant.Tenant_RefID = securityTicket.TenantID;
                companyInfo.Tenant_RefID         = securityTicket.TenantID;
                universalContact.Tenant_RefID    = securityTicket.TenantID;
            }

            item.SupplierType_RefID                 = Parameter.CMN_BPT_Supplier_TypeID;
            item.Ext_BusinessParticipant_RefID      = businessParticipant.CMN_BPT_BusinessParticipantID;
            item.ExternalSupplierProvidedIdentifier = Parameter.SupplierProvidedExternalIdentifier;

            businessParticipant.DisplayName           = Parameter.DisplayName;
            businessParticipant.IsCompany             = true;
            businessParticipant.DefaultCurrency_RefID = Parameter.DefaultCurrency_RefID;
            businessParticipant.DefaultLanguage_RefID = Parameter.DefaultLanguage_RefID;
            businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;

            companyInfo.Contact_UCD_RefID = universalContact.CMN_UniversalContactDetailID;
            companyInfo.CompanyInfo_EstablishmentNumber = Parameter.CompanyInfo_EstablishmentNumber;
            companyInfo.AnnualRevenueAmountValue_RefID  = Parameter.AnnualRevenueAmountValue_RefID;
            companyInfo.VATIdentificationNumber         = Parameter.VATIdentificationNumber;

            universalContact.CompanyName_Line1     = Parameter.CompanyName_Line1;
            universalContact.Country_639_1_ISOCode = Parameter.Country_639_1_ISOCode;

            if (businessParticipant.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                businessParticipant.Save(Connection, Transaction);
            }

            if (companyInfo.CMN_COM_CompanyInfoID != Guid.Empty)
            {
                companyInfo.Save(Connection, Transaction);
            }

            if (universalContact.CMN_UniversalContactDetailID != Guid.Empty)
            {
                universalContact.Save(Connection, Transaction);
            }

            Guid savedSupplier = new FR_Guid(item.Save(Connection, Transaction), item.CMN_BPT_SupplierID).Result;

            #region DiscountValue


            if (discountValue.Tenant_RefID == Guid.Empty)
            {
                discountValue.CMN_BPT_Supplier_DiscountValueID = Guid.NewGuid();
                discountValue.Supplier_RefID             = savedSupplier;
                discountValue.ORD_PRC_DiscountType_RefID = discount.ORD_PRC_DiscountTypeID;
                discountValue.Tenant_RefID = securityTicket.TenantID;
            }

            discountValue.DiscountValue_in_percent = Parameter.DiscountValue;
            discountValue.Save(Connection, Transaction);


            if (cashDiscountValue.Tenant_RefID == Guid.Empty)
            {
                cashDiscountValue.CMN_BPT_Supplier_DiscountValueID = Guid.NewGuid();
                cashDiscountValue.Supplier_RefID             = savedSupplier;
                cashDiscountValue.ORD_PRC_DiscountType_RefID = sconto.ORD_PRC_DiscountTypeID;
                cashDiscountValue.Tenant_RefID = securityTicket.TenantID;
            }

            cashDiscountValue.DiscountValue_in_percent = Parameter.CashDiscountValue;
            cashDiscountValue.Save(Connection, Transaction);

            #endregion

            returnValue.Result = savedSupplier;
            return(returnValue);

            #endregion UserCode
        }