P_PL_SAFTINVOICEHEADERVERSION2

CDS View

SAFT FA Invoice Header Basic Data

P_PL_SAFTINVOICEHEADERVERSION2 is a CDS View in S/4HANA. SAFT FA Invoice Header Basic Data. It contains 22 fields. 1 CDS views read from this table.

CDS Views using this table (1)

ViewTypeJoinVDMDescription
I_PL_SAFTGetInvoiceHeader view_entity from COMPOSITE SAFT PL FA Invoice Header

Fields (22)

KeyField CDS FieldsUsed in Views
KEY AccountingDocument AccountingDocument 1
KEY CompanyCode CompanyCode 1
KEY FiscalYear FiscalYear 1
AmountInTransactionCurrency AmountInTransactionCurrency 1
CompanyCodeAddress PL_SAFTCompanyCodeAddress 1
CompanyName CompanyName 1
CompanyVATRegistration CompanyVATRegistration 1
CorrectionInvoice PL_SAFTCorrectionInvoice 1
Country PL_SAFTCountry 1
CustomerSupplierAddress PL_SAFTCustomerSupplierAddress 1
CustomerSupplierCountry PL_SAFTCustomerSupplierCountry 1
CustomerSupplierName CustomerSupplierName 1
DeliveryDate DeliveryDate 1
DocumentDate DocumentDate 1
InvoiceDocumentNumber PL_SAFTInvoiceDocumentNumber 1
IsEUTriangularDeal IsEUTriangularDeal 1
IsReversal IsReversal 1
IsReversed IsReversed 1
PL_SAFTInvoiceType PL_SAFTInvoiceType 1
SDDocumentReasonText SDDocumentReasonText 1
TransactionCurrency TransactionCurrency 1
VATRegistration VATRegistration 1
@AccessControl.authorizationCheck: #NOT_REQUIRED
@AccessControl.personalData.blocking : #NOT_REQUIRED
@VDM.viewType: #COMPOSITE
@VDM.private:true
@ObjectModel.usageType.serviceQuality: #P
@ObjectModel.usageType.sizeCategory: #XL
@ObjectModel.usageType.dataClass: #MIXED

define view entity P_PL_SAFTInvoiceHeaderVersion2
 with parameters
    P_StartDate : datum,
    P_EndDate   : datum
  as select from           P_PL_SAFTInvoiceHeaderBasic(
                               P_StartDate:$parameters.P_StartDate,
                               P_EndDate: $parameters.P_EndDate)                                                          as Invoice


    left outer to one join P_PL_SAFTAcctgInvcBscVersion2                                                                  as AccountingInvoice    on  AccountingInvoice.CompanyCode        = Invoice.CompanyCode
                                                                                                                                                  and AccountingInvoice.FiscalYear         = Invoice.FiscalYear
                                                                                                                                                  and AccountingInvoice.AccountingDocument = Invoice.AccountingDocument

    left outer to one join P_PL_SAFTBillingDocument                                                                       as BillingDocument      on Invoice.BillingDocument = BillingDocument.BillingDocument

    inner join             P_PL_SAFTInvoiceTaxEUCode                                                                      as InvoiceTaxEUCode     on  InvoiceTaxEUCode.CompanyCode        = Invoice.CompanyCode
                                                                                                                                                  and InvoiceTaxEUCode.AccountingDocument = Invoice.AccountingDocument
                                                                                                                                                  and InvoiceTaxEUCode.FiscalYear         = Invoice.FiscalYear

    left outer to one join I_CompanyTaxDetail                                                                           as CompanyTaxDetails    on  Invoice.CompanyCode = CompanyTaxDetails.CompanyCode
                                                                                                                                                  and 'PL'  = CompanyTaxDetails.Country

{
  key Invoice.CompanyCode,
  key Invoice.AccountingDocument,
  key Invoice.FiscalYear,
  key Invoice.AccountingDocumentItem,


      Invoice.Customer,
      Invoice.Supplier,

      case
         when Invoice.VATRegistration is not initial
          then
            case substring(Invoice.VATRegistration,1,1)
                    when '1' then Invoice.VATRegistration
                    when '2' then Invoice.VATRegistration
                    when '3' then Invoice.VATRegistration
                    when '4' then Invoice.VATRegistration
                    when '5' then Invoice.VATRegistration
                    when '6' then Invoice.VATRegistration
                    when '7' then Invoice.VATRegistration
                    when '8' then Invoice.VATRegistration
                    when '9' then Invoice.VATRegistration
                    when '0' then Invoice.VATRegistration
                 else replace(replace(Invoice.VATRegistration,'-','' ),Invoice._Customer.Country,'')
              end
          when ( InvoiceTaxEUCode.EUTaxClassification = '1' or InvoiceTaxEUCode.EUTaxClassification = '3' or InvoiceTaxEUCode.EUTaxClassification = '4'
                 or InvoiceTaxEUCode.EUTaxClassification = 'C' or InvoiceTaxEUCode.EUTaxClassification = 'M' or InvoiceTaxEUCode.EUTaxClassification = 'H' )
               and Invoice._Customer.VATRegistration is not initial
          then
          case substring(Invoice._Customer.VATRegistration,1,1)
                    when '1' then Invoice._Customer.VATRegistration
                    when '2' then Invoice._Customer.VATRegistration
                    when '3' then Invoice._Customer.VATRegistration
                    when '4' then Invoice._Customer.VATRegistration
                    when '5' then Invoice._Customer.VATRegistration
                    when '6' then Invoice._Customer.VATRegistration
                    when '7' then Invoice._Customer.VATRegistration
                    when '8' then Invoice._Customer.VATRegistration
                    when '9' then Invoice._Customer.VATRegistration
                    when '0' then Invoice._Customer.VATRegistration
                 else replace(replace(Invoice._Customer.VATRegistration,'-','' ),Invoice._Customer.Country,'')
              end
        when Invoice._Customer.TaxNumber1 is not initial
          then
          case substring(Invoice._Customer.TaxNumber1 ,1,1)
                    when '1' then Invoice._Customer.TaxNumber1
                    when '2' then Invoice._Customer.TaxNumber1
                    when '3' then Invoice._Customer.TaxNumber1
                    when '4' then Invoice._Customer.TaxNumber1
                    when '5' then Invoice._Customer.TaxNumber1
                    when '6' then Invoice._Customer.TaxNumber1
                    when '7' then Invoice._Customer.TaxNumber1
                    when '8' then Invoice._Customer.TaxNumber1
                    when '9' then Invoice._Customer.TaxNumber1
                    when '0' then Invoice._Customer.TaxNumber1
                 else replace(replace(Invoice._Customer.TaxNumber1,'-','' ),Invoice._Customer.Country,'')
              end
        when Invoice._OneTimeAccountBP.TaxID1 is not initial
          then
          case substring(Invoice._OneTimeAccountBP.TaxID1,1,1)
                    when '1' then Invoice._OneTimeAccountBP.TaxID1
                    when '2' then Invoice._OneTimeAccountBP.TaxID1
                    when '3' then Invoice._OneTimeAccountBP.TaxID1
                    when '4' then Invoice._OneTimeAccountBP.TaxID1
                    when '5' then Invoice._OneTimeAccountBP.TaxID1
                    when '6' then Invoice._OneTimeAccountBP.TaxID1
                    when '7' then Invoice._OneTimeAccountBP.TaxID1
                    when '8' then Invoice._OneTimeAccountBP.TaxID1
                    when '9' then Invoice._OneTimeAccountBP.TaxID1
                    when '0' then Invoice._OneTimeAccountBP.TaxID1
                 else replace(replace(Invoice._OneTimeAccountBP.TaxID1,'-','' ),Invoice._Customer.Country,'')
              end
         else 'BRAK'
       end                                                                                                          as VATRegistration,

      case
          when Invoice._OneTimeAccountBP.BusinessPartnerName1 is not null and Invoice._OneTimeAccountBP.BusinessPartnerName1 is not initial
              then concat_with_space(concat_with_space(concat_with_space(Invoice._OneTimeAccountBP.BusinessPartnerName1,Invoice._OneTimeAccountBP.BusinessPartnerName2, 1),
                          Invoice._OneTimeAccountBP.BusinessPartnerName3,1),Invoice._OneTimeAccountBP.BusinessPartnerName4,1)
          when Invoice.Customer is not null and Invoice.Customer is not initial
              then concat(concat(concat_with_space(Invoice._Customer._AddressRepresentation.OrganizationName1,Invoice._Customer._AddressRepresentation.OrganizationName2, 1),
                                   Invoice._Customer._AddressRepresentation.OrganizationName3),Invoice._Customer._AddressRepresentation.OrganizationName4)
          else  concat_with_space(concat_with_space(concat_with_space(Invoice._Supplier._AddressRepresentation.OrganizationName1,Invoice._Supplier._AddressRepresentation.OrganizationName2, 1),
                          Invoice._Supplier._AddressRepresentation.OrganizationName3,1),Invoice._Supplier._AddressRepresentation.OrganizationName4,1)
      end                                                                                                           as CustomerSupplierName,

       case
         when Invoice._OneTimeAccountBP.BusinessPartnerName1 is not initial
             then concat(concat_with_space(Invoice._OneTimeAccountBP.StreetAddressName,Invoice._OneTimeAccountBP.PostalCode, 1),
                      Invoice._OneTimeAccountBP.CityName)
         when Invoice.Customer is not initial
             then concat_with_space(concat_with_space(concat_with_space(Invoice._Customer._AddressRepresentation.StreetName,Invoice._Customer._AddressRepresentation.HouseNumber, 1),
                              Invoice._Customer._AddressRepresentation.PostalCode,1),Invoice._Customer._AddressRepresentation.CityName,1)
         else concat_with_space(concat_with_space(concat_with_space(Invoice._Supplier._AddressRepresentation.StreetName,Invoice._Supplier._AddressRepresentation.HouseNumber, 1),
                     Invoice._Supplier._AddressRepresentation.PostalCode,1),Invoice._Supplier._AddressRepresentation.CityName,1)
      end                                                                                                           as CustomerSupplierAddress,

      //P_5A

      case
        when ( InvoiceTaxEUCode.EUTaxClassification = '1' or InvoiceTaxEUCode.EUTaxClassification = '3' or InvoiceTaxEUCode.EUTaxClassification = '4'
             or InvoiceTaxEUCode.EUTaxClassification = 'C' or InvoiceTaxEUCode.EUTaxClassification = 'M' or InvoiceTaxEUCode.EUTaxClassification = 'H' )
             then
                case
                when Invoice.VATRegistration is not initial
                  then
                     case substring(Invoice.VATRegistration,1,1)
                            when '1' then ''
                            when '2' then ''
                            when '3' then ''
                            when '4' then ''
                            when '5' then ''
                            when '6' then ''
                            when '7' then ''
                            when '8' then ''
                            when '9' then ''
                            when '0' then ''
                     else substring(Invoice.VATRegistration,1,2)
                  end
      //replace(replace(Invoice.VATRegistration,'-','' ),_Customer.Country,'')

                when ( InvoiceTaxEUCode.EUTaxClassification = '1' or InvoiceTaxEUCode.EUTaxClassification = '3' or InvoiceTaxEUCode.EUTaxClassification = '4'
                  or InvoiceTaxEUCode.EUTaxClassification = 'C' or InvoiceTaxEUCode.EUTaxClassification = 'M' or InvoiceTaxEUCode.EUTaxClassification = 'H' )
                  and Invoice._Customer.VATRegistration is not initial
                then
                     case substring(Invoice._Customer.VATRegistration,1,1)
                            when '1' then ''
                            when '2' then ''
                            when '3' then ''
                            when '4' then ''
                            when '5' then ''
                            when '6' then ''
                            when '7' then ''
                            when '8' then ''
                            when '9' then ''
                            when '0' then ''
                     else substring(Invoice._Customer.VATRegistration,1,2)
                    end
              when Invoice._Customer.TaxNumber1 is not initial
                  then
                       case substring(Invoice._Customer.TaxNumber1 ,1,1)
                              when '1' then ''
                              when '2' then ''
                              when '3' then ''
                              when '4' then ''
                              when '5' then ''
                              when '6' then ''
                              when '7' then ''
                              when '8' then ''
                              when '9' then ''
                              when '0' then ''
                       else substring(Invoice._Customer.TaxNumber1,1,2)
                      end
                when Invoice._OneTimeAccountBP.TaxID1 is not initial
                   then
                         case substring(Invoice._OneTimeAccountBP.TaxID1 ,1,1)
                                when '1' then ''
                                when '2' then ''
                                when '3' then ''
                                when '4' then ''
                                when '5' then ''
                                when '6' then ''
                                when '7' then ''
                                when '8' then ''
                                when '9' then ''
                                when '0' then ''
                         else substring(Invoice._OneTimeAccountBP.TaxID1,1,2)
                         end

               else 'PL'
            end
        else ''
      end                                                                                                           as CustomerSupplierCountry,
      /*case when InvoiceVatReg.VATRegistration is not initial
        then
          case
            when _OneTimeAccountBP.Country is not null and _OneTimeAccountBP.Country is not initial
               then _OneTimeAccountBP.Country
            when _Customer.Country is not null and _Customer.Country is not initial
               then _Customer.Country
            else _Supplier.Country
          end
        else ''
      end                                                                                                           as CustomerSupplierCountry,*/


      case
          when Invoice._CompanyCode.Country = 'PL'
            then
              case substring(Invoice._CompanyCode.VATRegistration,1,1)
                    when '1' then Invoice._CompanyCode.VATRegistration
                    when '2' then Invoice._CompanyCode.VATRegistration
                    when '3' then Invoice._CompanyCode.VATRegistration
                    when '4' then Invoice._CompanyCode.VATRegistration
                    when '5' then Invoice._CompanyCode.VATRegistration
                    when '6' then Invoice._CompanyCode.VATRegistration
                    when '7' then Invoice._CompanyCode.VATRegistration
                    when '8' then Invoice._CompanyCode.VATRegistration
                    when '9' then Invoice._CompanyCode.VATRegistration
                    when '0' then Invoice._CompanyCode.VATRegistration
                 else replace(Invoice._CompanyCode.VATRegistration, 'PL', '')
              end
          when CompanyTaxDetails.CompanyCode = Invoice.CompanyCode and CompanyTaxDetails.Country = 'PL'
            then
              case substring(CompanyTaxDetails.VATRegistration,1,1)
                    when '1' then CompanyTaxDetails.VATRegistration
                    when '2' then CompanyTaxDetails.VATRegistration
                    when '3' then CompanyTaxDetails.VATRegistration
                    when '4' then CompanyTaxDetails.VATRegistration
                    when '5' then CompanyTaxDetails.VATRegistration
                    when '6' then CompanyTaxDetails.VATRegistration
                    when '7' then CompanyTaxDetails.VATRegistration
                    when '8' then CompanyTaxDetails.VATRegistration
                    when '9' then CompanyTaxDetails.VATRegistration
                    when '0' then CompanyTaxDetails.VATRegistration
                 else replace(CompanyTaxDetails.VATRegistration, 'PL', '')
              end
          else 'BRAK'
        end                                                                                                         as CompanyVATRegistration,

      concat_with_space(concat_with_space(concat_with_space(Invoice._CompanyCode._OrgAddressDefaultRprstn.AddresseeName1,Invoice._CompanyCode._OrgAddressDefaultRprstn.AddresseeName2, 1),
                        Invoice._CompanyCode._OrgAddressDefaultRprstn.AddresseeName3,1),Invoice._CompanyCode._OrgAddressDefaultRprstn.AddresseeName4,1) as CompanyName,

      concat_with_space(concat_with_space(concat_with_space(Invoice._CompanyCode._OrgAddressDefaultRprstn.CityName,Invoice._CompanyCode._OrgAddressDefaultRprstn.PostalCode, 1),
                                 Invoice._CompanyCode._OrgAddressDefaultRprstn.StreetName,1),Invoice._CompanyCode._OrgAddressDefaultRprstn.HouseNumber,1)           as CompanyCodeAddress,

      //P_4A

      case
        when ( InvoiceTaxEUCode.EUTaxClassification = '1' or InvoiceTaxEUCode.EUTaxClassification = '3' or InvoiceTaxEUCode.EUTaxClassification = '4'
             or InvoiceTaxEUCode.EUTaxClassification = 'C' or InvoiceTaxEUCode.EUTaxClassification = 'M' or InvoiceTaxEUCode.EUTaxClassification = 'H' )
      then
      case
          when Invoice._CompanyCode.Country = 'PL'
                  then
                     case substring(Invoice._CompanyCode.VATRegistration,1,1)
                            when '1' then ''
                            when '2' then ''
                            when '3' then ''
                            when '4' then ''
                            when '5' then ''
                            when '6' then ''
                            when '7' then ''
                            when '8' then ''
                            when '9' then ''
                            when '0' then ''

                            else substring(Invoice._CompanyCode.VATRegistration,1,2)
                     end
      //replace(replace(Invoice.VATRegistration,'-','' ),_Customer.Country,'')

                when CompanyTaxDetails.CompanyCode = Invoice.CompanyCode and CompanyTaxDetails.Country = 'PL'
                    then
                      case substring(CompanyTaxDetails.VATRegistration,1,1)
                            when '1' then ''
                            when '2' then ''
                            when '3' then ''
                            when '4' then ''
                            when '5' then ''
                            when '6' then ''
                            when '7' then ''
                            when '8' then ''
                            when '9' then ''
                            when '0' then ''
                     else
                        substring(CompanyTaxDetails.VATRegistration,1,2)
                    end
                else 'PL'
            end
        else ''
      end                                                                                                           as Country,
      /*case when InvoiceVatReg.CompanyVATRegistration is not initial
        then _CompanyCode.Country
        else ''
      end                                                                                                           as Country,*/


      case when Invoice.ReferenceDocumentType = 'VBRK' and BillingDocument.BillingDocument is not null
            then ltrim(Invoice.BillingDocument,'0')
            else

            case when AccountingInvoice.DocumentReferenceID is not initial
                    then AccountingInvoice.DocumentReferenceID
                else concat(ltrim(Invoice.AccountingDocument,'0'),concat('/',Invoice.FiscalYear))
            end
      end                                                                                                           as InvoiceDocumentNumber,

      case when BillingDocument.BillingDocument is not null
        then BillingDocument.PL_SAFTInvoiceType
        else AccountingInvoice.PL_SAFTInvoiceType
      end                                                                                                           as PL_SAFTInvoiceType,


      Invoice.DocumentDate,
      Invoice.PostingDate,

      case when BillingDocument.BillingDocument is not null
        then
          case when BillingDocument.BillingDocumentDate <> BillingDocument.DeliveryDate
            then BillingDocument.DeliveryDate
            else BillingDocument.BillingDocumentDate
          end
        else AccountingInvoice.TaxReportingDate
      end                                                                                                           as DeliveryDate,


      //P_23

      case when Invoice.IsEUTriangularDeal = 'X'
        then 'X'
        else ' '
      end                                                                                                           as IsEUTriangularDeal,


      cast(case
            when     BillingDocument.PL_SAFTInvoiceType = 'KOREKTA'
                 and Invoice.DocumentReferenceID is not null
                 and Invoice.DocumentReferenceID is not initial
             then ltrim(Invoice.DocumentReferenceID,'0')

            when BillingDocument.PL_SAFTInvoiceType = 'KOREKTA'
              then 'BRAK'

            when AccountingInvoice.PL_SAFTInvoiceType = 'KOREKTA'
                 and AccountingInvoice.IsReversal = 'X'
                 and AccountingInvoice.InvoiceReference is not null
                 and AccountingInvoice.InvoiceReference is not initial
              then
                concat(ltrim(AccountingInvoice.InvoiceReference,'0'), concat('/',AccountingInvoice.InvoiceReferenceFiscalYear))

            when AccountingInvoice.PL_SAFTInvoiceType = 'KOREKTA'
                 and AccountingInvoice.IsReversal = ''
                 and Invoice.InvoiceReference is not null
                 and Invoice.InvoiceReference is not initial
              then
                concat(ltrim(Invoice.InvoiceReference,'0'), concat('/',Invoice.InvoiceReferenceFiscalYear))

            when AccountingInvoice.PL_SAFTInvoiceType = 'KOREKTA'
              then 'BRAK'
      end as xblnr)                                                                                                 as CorrectionInvoice,

      case
        when BillingDocument.PL_SAFTInvoiceType = 'KOREKTA'
             and BillingDocument._SDDocumentReason.SDDocumentReason is not null
             and BillingDocument._SDDocumentReason.SDDocumentReason is not initial
          then coalesce(BillingDocument._SDDocumentReason._Text[1: Language = 'L'].SDDocumentReasonText,
               coalesce(BillingDocument._SDDocumentReason._Text[1: Language = 'E'].SDDocumentReasonText,
               coalesce(BillingDocument._SDDocumentReason._Text[1: Language = $session.system_language].SDDocumentReasonText,'BRAK')))
        when BillingDocument.PL_SAFTInvoiceType = 'KOREKTA'
          then 'BRAK'
        when AccountingInvoice.PL_SAFTInvoiceType = 'KOREKTA'
             and Invoice.DocumentItemText is not null
             and Invoice.DocumentItemText is not initial
          then Invoice.DocumentItemText
        when AccountingInvoice.PL_SAFTInvoiceType = 'KOREKTA'
          then 'BRAK'
      end                                                                                                           as SDDocumentReasonText,


      Invoice.TransactionCurrency,
      Invoice.CompanyCodeCurrency,

      @Semantics.amount.currencyCode: 'TransactionCurrency'
      - Invoice.AmountInTransactionCurrency                                                                         as AmountInTransactionCurrency,
      @Semantics.amount.currencyCode: 'CompanyCodeCurrency'
      - Invoice.AmountInCompanyCodeCurrency                                                                         as AmountInCompanyCodeCurrency,

      Invoice.IsReversal,
      Invoice.IsReversed,

      Invoice._Customer,
      Invoice._Supplier,
      Invoice._OneTimeAccountBP

}
where
     BillingDocument.PL_SAFTInvoiceType   is not null
  or AccountingInvoice.PL_SAFTInvoiceType is not null