@AbapCatalog.sqlViewName: 'CPESLSLC'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #MANDATORY
@ObjectModel.usageType.sizeCategory: #XL
@ObjectModel.usageType.serviceQuality: #D
@ObjectModel.usageType.dataClass: #MIXED
@VDM.viewType: #CONSUMPTION
@Analytics: { dataCategory: #CUBE }
@Analytics.internalName: #LOCAL
@ClientHandling.algorithm: #SESSION_VARIABLE
@AccessControl.personalData.blocking: #BLOCKED_DATA_INCLUDED
@EndUserText.label: 'Sales Ledger Peru - Cube'
@Metadata.allowExtensions:true
define view C_PE_StRpSalesLedgerCube
as select from P_PE_SalesTaxAggrgd as SalesTaxEntry
inner join I_StRpJournalEntryLog as StRpJournalEntryLog on StRpJournalEntryLog.CompanyCode = SalesTaxEntry.CompanyCode
and StRpJournalEntryLog.AccountingDocument = SalesTaxEntry.AccountingDocument
and StRpJournalEntryLog.FiscalYear = SalesTaxEntry.FiscalYear
left outer to one join I_ExchangeRate as ExchangeRate on ExchangeRate.SourceCurrency = SalesTaxEntry.TransactionCurrency
and ExchangeRate.TargetCurrency = SalesTaxEntry.CountryCurrency
and SalesTaxEntry.TransactionCurrency <> SalesTaxEntry.CountryCurrency
and ExchangeRate.ExchangeRateType = SalesTaxEntry.ExchangeRateType
and ExchangeRate.ExchangeRateEffectiveDate = SalesTaxEntry.ExchangeRateEffectiveDate
left outer to one join P_PE_CFinBillingDocAggrgd as CFinBillingDocument on CFinBillingDocument.CentralFinanceBillingDocument = SalesTaxEntry.OriginalReferenceDocument
and CFinBillingDocument.CompanyCode = SalesTaxEntry.CompanyCode
association[0..1] to I_JournalEntry as _JournalEntry on _JournalEntry.CompanyCode = SalesTaxEntry.CompanyCode
and _JournalEntry.ReferenceDocumentType = 'VBRK'
and SalesTaxEntry.PE_OriginalDocumentType = ''
and SalesTaxEntry.PE_OriginalDocumentSeries = ''
and SalesTaxEntry.PE_OriginalDocumentNumber = ''
and CFinBillingDocument.SalesDocument is not null
and CFinBillingDocument.SalesDocument <> ''
and CFinBillingDocument.SalesDocument = _JournalEntry.OriginalReferenceDocument
{
key SalesTaxEntry.CompanyCode,
key SalesTaxEntry.FiscalYear,
key SalesTaxEntry.AccountingDocument,
key StRpJournalEntryLog.StatryRptCategory,
key StRpJournalEntryLog.StatryRptgEntity,
key StRpJournalEntryLog.StatryRptRunID,
SalesTaxEntry.Ledger,
SalesTaxEntry.LogicalSystem,
SalesTaxEntry.OriginalReferenceDocument,
SalesTaxEntry.PE_CompanyCodeTaxNumber,
SalesTaxEntry.CompanyCodeName,
SalesTaxEntry.CalendarYearMonth,
SalesTaxEntry.DocumentDate,
SalesTaxEntry.DocumentNetDueDate,
SalesTaxEntry.PE_OfficialDocumentType,
SalesTaxEntry.PE_DocumentSerialNumber,
SalesTaxEntry.PE_OfficialDocumentNumber,
SalesTaxEntry.TaxNumberType,
SalesTaxEntry.TaxNumber1,
SalesTaxEntry.CustomerName,
SalesTaxEntry.CountryCurrency,
SalesTaxEntry.TransactionCurrency,
cast ( case
when ( SalesTaxEntry.PE_OriginalDocumentType = '' or SalesTaxEntry.PE_OriginalDocumentType is initial )
then _JournalEntry.DocumentDate
end as fipe_original_document_date ) as PE_OriginalDocumentDate,
cast( case
when ( SalesTaxEntry.PE_OriginalDocumentType = '' or SalesTaxEntry.PE_OriginalDocumentType is initial )
then substring(_JournalEntry.DocumentReferenceID,1,2)
else ''
end
as fipe_original_document_type ) as PE_OriginalDocumentType,
cast( case
when ( SalesTaxEntry.PE_OriginalDocumentType = '' or SalesTaxEntry.PE_OriginalDocumentType is initial )
then case instr(substring(_JournalEntry.DocumentReferenceID,4,13), '-')
when 2
then substring(_JournalEntry.DocumentReferenceID,4,1)
when 3
then substring(_JournalEntry.DocumentReferenceID,4,2)
when 4
then substring(_JournalEntry.DocumentReferenceID,4,3)
when 5
then substring(_JournalEntry.DocumentReferenceID,4,4)
else ''
end
else ''
end
as fipe_original_document_series ) as PE_OriginalDocumentSeries,
cast( case
when ( SalesTaxEntry.PE_OriginalDocumentType = '' or SalesTaxEntry.PE_OriginalDocumentType is initial )
then
case instr(substring(_JournalEntry.DocumentReferenceID,4,13), '-')
when 2
then substring(_JournalEntry.DocumentReferenceID,6,11)
when 3
then substring(_JournalEntry.DocumentReferenceID,7,10)
when 4
then substring(_JournalEntry.DocumentReferenceID,8,9)
when 5
then substring(_JournalEntry.DocumentReferenceID,9,8)
else ''
end
end
as fipe_original_document_number ) as PE_OriginalDocumentNumber,
CFinBillingDocument.SalesDocument,
cast( case SalesTaxEntry.TransactionCurrency
when 'PEN'
then 1
else ExchangeRate.ExchangeRate
end
as fipe_exchange_rate ) as ExchangeRate,
SalesTaxEntry.FiscalPeriod,
SalesTaxEntry.ReportingDate,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_ExportAmountInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_TaxableBaseAmountInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_DiscountBaseAmtInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_VATAmountInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_VATDiscountAmountInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_ExemptTaxAmountInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_SelectiveAcqnAmtInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_TxBaseOnRiceAmtInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_TaxOnRiceAmountInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_TxOnPlasticBagAmtInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_OthTxAndChrgsAmtInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
SalesTaxEntry.PE_NonTxblBaseAmtInCtryCrcy,
@Semantics.amount.currencyCode: 'CountryCurrency'
cast( coalesce(SalesTaxEntry.PE_ExportAmountInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_TaxableBaseAmountInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_DiscountBaseAmtInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_VATAmountInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_VATDiscountAmountInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_ExemptTaxAmountInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_NonTxblBaseAmtInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_SelectiveAcqnAmtInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_TxBaseOnRiceAmtInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_TaxOnRiceAmountInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_TxOnPlasticBagAmtInCtryCrcy, 0)
+ coalesce(SalesTaxEntry.PE_OthTxAndChrgsAmtInCtryCrcy, 0)
as fipe_total_tax_documents ) as TotalAmountInLocalCurrency
}
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_EXCHANGERATE",
"I_JOURNALENTRY",
"I_STRPJOURNALENTRYLOG",
"P_PE_CFINBILLINGDOCAGGRGD",
"P_PE_SALESTAXAGGRGD"
],
"ASSOCIATED":
[
"I_JOURNALENTRY"
],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/