I_PT_SAFTSlsInvcBillgCust

DDL: I_PT_SAFTSLSINVCBILLGCUST Type: view_entity COMPOSITE Package: GLO_FIN_IS_SAFT_PT

Customer from Billing Document

I_PT_SAFTSlsInvcBillgCust is a Composite CDS View that provides data about "Customer from Billing Document" in SAP S/4HANA. It reads from 14 data sources and exposes 40 fields with key fields CompanyCode, PortugueseInvoiceNumber, DocumentDate, char30asBusinessPartnerCustomer, PortugueseInvoiceNumber. It has 1 association to related views. Part of development package GLO_FIN_IS_SAFT_PT.

Data Sources (14)

SourceAliasJoin Type
I_PT_SAFTIsAlternateAccount AltAcct inner
I_PT_SAFTIsAlternateAccount AltAcct inner
I_GLAccountInCompanyCode CompAcct inner
I_GLAccountInCompanyCode CompAcct inner
I_Customer Cust inner
I_Customer Cust inner
I_CustomerCompany CustCompany inner
I_CustomerCompany CustCompany inner
I_BillingDocument Doc inner
I_InvoiceList Doc inner
I_PT_SAFTBillgDocCustAddrHist Hist inner
I_PT_SAFTBillgDocCustAddrHist Hist inner
I_PT_BillgDocDgtlSgntr Sig from
I_PT_BillgDocDgtlSgntr Sig union

Associations (1)

CardinalityTargetAliasCondition
[0..1] I_SAFTCustTaxRegnNmbr _CustLand Doc.PayerParty = _CustLand.CustomerNum and Doc.VATRegistrationCountry = _CustLand.Country

Annotations (8)

NameValueLevelField
AccessControl.authorizationCheck #MANDATORY view
VDM.viewType #COMPOSITE view
AccessControl.personalData.blocking #BLOCKED_DATA_INCLUDED view
EndUserText.label Customer from Billing Document view
Metadata.ignorePropagatedAnnotations true view
ObjectModel.usageType.serviceQuality #D view
ObjectModel.usageType.sizeCategory #XL view
ObjectModel.usageType.dataClass #MIXED view

Fields (40)

KeyFieldSource TableSource FieldDescription
KEY CompanyCode I_PT_BillgDocDgtlSgntr CompanyCode
KEY PortugueseInvoiceNumber I_PT_BillgDocDgtlSgntr PortugueseInvoiceNumber
KEY DocumentDate I_InvoiceList BillingDocumentDate
KEY char30asBusinessPartnerCustomer
AccountingDocument I_InvoiceList BillingDocument
Customer I_InvoiceList PayerParty
char20asCustomerVATRegistration
CompanyName
CustomerSupplierAddressendasStreetName
CityNameendasCityName
PostalCodeendasPostalCode
CountryendasPT_SAFTCountryText
CompanyContactPersonFullName
PhoneNumber
FaxNumber
EmailAddress
WebsiteURL
PayerParty I_InvoiceList PayerParty
SDDocumentCategory I_InvoiceList SDDocumentCategory
IsOneTimeAccount I_Customer IsOneTimeAccount
CompanyCode
KEY PortugueseInvoiceNumber I_PT_BillgDocDgtlSgntr PortugueseInvoiceNumber
KEY DocumentDate I_InvoiceList InvoiceListBillingDate
KEY BusinessPartnerCustomer I_PT_SAFTBillgDocCustAddrHist PortugueseCustomerWithVersion
AccountingDocument I_InvoiceList AccountingDocument
Customer I_InvoiceList PayerParty
CompanyName
CustomerSupplierAddressendasStreetName
CityNameendasCityName
PostalCodeendasPostalCode
CountryendasPT_SAFTCountryText
CompanyContactPersonFullName
PhoneNumber
FaxNumber
EmailAddress
WebsiteURL
PayerParty I_InvoiceList PayerParty
SDDocumentCategory I_InvoiceList SDDocumentCategory
IsOneTimeAccount I_Customer IsOneTimeAccount
_PayerParty I_InvoiceList _PayerParty
@Consumption.dbHints: [ 'USE_HEX_PLAN' ]
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #MANDATORY
@VDM.viewType: #COMPOSITE
@AccessControl.personalData.blocking: #BLOCKED_DATA_INCLUDED
@EndUserText.label: 'Customer from Billing Document'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
  serviceQuality: #D,
  sizeCategory: #XL,
  dataClass: #MIXED
}
define view entity I_PT_SAFTSlsInvcBillgCust
  as select from           I_PT_BillgDocDgtlSgntr        as Sig

    inner join             I_BillingDocument             as Doc         on  Sig.BillingDocument = Doc.BillingDocument --NRG
                                                                        and Sig.CompanyCode     = Doc.CompanyCode --NRG
    inner join             I_Customer                    as Cust        on  Cust.Customer         = Doc.PayerParty
                                                                        and Cust.IsOneTimeAccount = ' '

    inner join             I_CustomerCompany             as CustCompany on  Cust.Customer   = CustCompany.Customer
                                                                        and Doc.CompanyCode = CustCompany.CompanyCode
    inner join             I_PT_SAFTBillgDocCustAddrHist as Hist        on  Sig.BillingDocument = Hist.BillingDocument
                                                                        and Sig.CompanyCode     = Hist.CompanyCode
                                                                        and Cust.Customer       = Hist.Customer

    inner join             I_PT_SAFTIsAlternateAccount   as AltAcct     on AltAcct.CompanyCode = Sig.CompanyCode

    inner join             I_GLAccountInCompanyCode      as CompAcct    on  CompAcct.GLAccount   = CustCompany.ReconciliationAccount
                                                                        and CompAcct.CompanyCode = Doc.CompanyCode

    left outer to one join I_PT_SAFTWorkingDocType       as w           on  Sig.NumberRangeInterval = w.NumberRangeInterval
                                                                        and Sig.CompanyCode         = w.CompanyCode
                                                                        and Doc.FiscalYear          = w.FiscalYear

  association [0..1] to I_SAFTCustTaxRegnNmbr as _CustLand on  Doc.PayerParty             = _CustLand.CustomerNum
                                                           and Doc.VATRegistrationCountry = _CustLand.Country

{
  key     Sig.CompanyCode,
  key     Sig.PortugueseInvoiceNumber,
  key     Doc.BillingDocumentDate                                 as DocumentDate,
  key     cast(case when _CustLand.Country is not initial
          then
          case when Doc.VATRegistrationCountry is not initial then
            concat(Hist.PortugueseCustomerWithVersion, concat('/', Doc.VATRegistrationCountry ))
            else concat(Hist.PortugueseCustomerWithVersion, concat('/', Hist.Country)) end
          //   concat(Hist.PortugueseCustomerWithVersion, concat('/', _MultVat.CustomerCountry))

          else case when Hist.Country != Cust.Country
             then concat(Hist.PortugueseCustomerWithVersion,concat('/',Hist.Country))
             else Hist.PortugueseCustomerWithVersion
             end end  as abap.char(30))                           as BusinessPartnerCustomer,

          Doc.BillingDocument                                     as AccountingDocument,

          Doc.PayerParty                                          as Customer,


          cast( case when _CustLand.Country  is not initial
           then case when _CustLand.Country = 'AE'
              then _CustLand.CustomerVATRegistration
              else substring(_CustLand.CustomerVATRegistration,3,18) end
          else
           case when Cust.VATRegistration is not initial
           then substring(Cust.VATRegistration,3,18)
           else case when Cust.TaxNumber1 is not initial then Cust.TaxNumber1
           else case when Cust.TaxNumber2 is not initial then Cust.TaxNumber2
           else case when Cust.TaxNumber3 is not initial then Cust.TaxNumber3
           else case when Cust.TaxNumber4 is not initial then Cust.TaxNumber4
           else case when Cust.TaxNumber5 is not initial then Cust.TaxNumber5
           else case when Cust.TaxNumber6 is not initial then Cust.TaxNumber6
//           else '999999990'

           end end end end end end end
          end  as abap.char(20))                                  as CustomerVATRegistration,

          case when AltAcct.AlternativeGLAccountIsUsed is not initial
                then CompAcct.AlternativeGLAccount
               else CustCompany.ReconciliationAccount
          end                                                     as ReconciliationAccount,

          cast (Hist.CompanyName as bu_name1tx)                   as CompanyName,
          case when Hist.CustomerSupplierAddress is initial
            then 'Desconhecido'
            else Hist.CustomerSupplierAddress
          end                                                     as StreetName,

          case when Hist.CityName is initial
            then 'Desconhecido'
            else Hist.CityName
          end                                                     as CityName,

          case when Hist.PostalCode is initial
            then '0000-000'
            else Hist.PostalCode
          end                                                     as PostalCode,

          case when Hist.Country is initial
            then 'Desconhecido'
            else Hist.Country
          end                                                     as PT_SAFTCountryText,


          coalesce ( Hist.ContactPersonName, '' )                 as CompanyContactPersonFullName,
          coalesce ( Hist.PhoneNumber, '' )                       as PhoneNumber,
          cast(coalesce ( Hist.FaxNumber, '' ) as abap.char(31) ) as FaxNumber,
          coalesce ( Hist.EmailAddress, '' )                      as EmailAddress,
          coalesce ( Hist.SearchURLAddress, '' )                  as WebsiteURL,

          cast( case
                when Doc.SDDocumentCategory = 'U' or Doc.SDDocumentCategory = '3' or Doc.SDDocumentCategory = '4' or w.NumberRangeInterval = Sig.NumberRangeInterval
                  then 'X'
                  else ' '
                end  as boole_d)                                  as SalesDocumentIsWorkingDocument,
          Doc.PayerParty,
          Doc.SDDocumentCategory,
          Cust.IsOneTimeAccount,
          Doc._PayerParty
}

where
      Doc.CancelledBillingDocument = '' //Do not select cancel documents

  //  and Doc.BillingDocumentCategory  <> 'P' //Do not select DP Requests

  and Cust.IsOneTimeAccount        = ' '

union select from        I_PT_BillgDocDgtlSgntr        as Sig

  inner join             I_InvoiceList                 as Doc         on  Doc.InvoiceList = Sig.BillingDocument
                                                                      and Doc.CompanyCode = Sig.CompanyCode
  inner join             I_Customer                    as Cust        on  Cust.Customer         = Doc.PayerParty
                                                                      and Cust.IsOneTimeAccount = ' '

  inner join             I_CustomerCompany             as CustCompany on  Cust.Customer   = CustCompany.Customer
                                                                      and Doc.CompanyCode = Sig.CompanyCode
  inner join             I_PT_SAFTBillgDocCustAddrHist as Hist        on  Sig.BillingDocument = Hist.BillingDocument
                                                                      and Sig.CompanyCode     = Hist.CompanyCode
                                                                      and Cust.Customer       = Hist.Customer

  inner join             I_PT_SAFTIsAlternateAccount   as AltAcct     on AltAcct.CompanyCode = Sig.CompanyCode

  inner join             I_GLAccountInCompanyCode      as CompAcct    on  CompAcct.GLAccount   = CustCompany.ReconciliationAccount
                                                                      and CompAcct.CompanyCode = Doc.CompanyCode

  left outer to one join I_PT_SAFTWorkingDocType       as w           on  Sig.NumberRangeInterval = w.NumberRangeInterval
                                                                      and Sig.CompanyCode         = w.CompanyCode
                                                                      and Doc.FiscalYear          = w.FiscalYear

{
  key    Sig.CompanyCode,
  key    Sig.PortugueseInvoiceNumber,

  key    Doc.InvoiceListBillingDate              as DocumentDate, //VDM

  key    Hist.PortugueseCustomerWithVersion      as BusinessPartnerCustomer,

         Doc.AccountingDocument,
         Doc.PayerParty                          as Customer,
         case when Hist.CustomerVATRegistration is initial or Hist.CustomerVATRegistration is null
                 then '999999990'
                 else Hist.CustomerVATRegistration
         end                                     as CustomerVATRegistration,

         case when AltAcct.AlternativeGLAccountIsUsed is not initial
               then CompAcct.AlternativeGLAccount
              else CustCompany.ReconciliationAccount
         end                                     as ReconciliationAccount,

         cast (Hist.CompanyName as bu_name1tx)   as CompanyName,
         case when Hist.CustomerSupplierAddress is initial
           then 'Desconhecido'
           else Hist.CustomerSupplierAddress
         end                                     as StreetName,

         case when Hist.CityName is initial
           then 'Desconhecido'
           else Hist.CityName
         end                                     as CityName,

         case when Hist.PostalCode is initial
           then '0000-000'
           else Hist.PostalCode
         end                                     as PostalCode,

         case when Hist.Country is initial
           then 'Desconhecido'
           else Hist.Country
         end                                     as PT_SAFTCountryText,

         coalesce ( Hist.ContactPersonName, '' ) as CompanyContactPersonFullName,
         coalesce ( Hist.PhoneNumber, '' )       as PhoneNumber,
         coalesce ( Hist.FaxNumber, '' )         as FaxNumber,
         coalesce ( Hist.EmailAddress, '' )      as EmailAddress,
         coalesce ( Hist.SearchURLAddress, '' )  as WebsiteURL,

         case
               when Doc.SDDocumentCategory = 'U' or Doc.SDDocumentCategory = '3' or Doc.SDDocumentCategory = '4' or w.NumberRangeInterval = Sig.NumberRangeInterval
                 then 'X'
                 else ' '
               end                               as SalesDocumentIsWorkingDocument,
         Doc.PayerParty,
         Doc.SDDocumentCategory,
         Cust.IsOneTimeAccount,
         Doc._PayerParty
}
where
      Doc.CancelledInvoiceList = '' //Do not select cancel documents

  //  and Doc.BillingDocumentCategory  <> 'P' //Do not select DP Requests

  and Cust.IsOneTimeAccount    = ' '