@AbapCatalog.sqlViewName: 'PSRCALTAXRETBOX'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
//@EndUserText.label: 'Calculated Tax Return Box Information'
@VDM.viewType: #COMPOSITE
@ClientHandling.algorithm: #SESSION_VARIABLE
@ObjectModel.usageType.sizeCategory: #XL
@ObjectModel.usageType.serviceQuality: #P
@ObjectModel.usageType.dataClass: #MIXED
@AccessControl.personalData.blocking: #NOT_REQUIRED
@VDM.private: true
@AccessControl.blocking:#BLOCKED_DATA_INCLUDED
define view P_StRpCalTaxReturnBox
with parameters
P_TaxIsDeferredRelevant : figen_deferred_check,
P_TaxIsMossRelevant : figen_moss_check,
P_StatryRptgEntity : srf_reporting_entity,
P_StatryRptCategory : srf_rep_cat_id,
P_StatryRptRunID : srf_report_run_id,
P_ReportingCountry : land1,
P_TaxBoxConfiguration : figen_tdt_taxbox_config
as select from I_StRpTaxItemBoxConfiguration
(
P_TaxBoxConfiguration : $parameters.P_TaxBoxConfiguration
)
as I_StRpTaxItemGrpg
left outer join P_StRpTaxReturnCube (
P_StatryRptgEntity : $parameters.P_StatryRptgEntity,
P_StatryRptCategory : $parameters.P_StatryRptCategory,
P_StatryRptRunID : $parameters.P_StatryRptRunID,
P_ReportingCountry : $parameters.P_ReportingCountry
) as P_StRpTaxReturnItem
on
/*ParamReportingCountry is an attribute which contains the value of parameter P_ReportingCountry. Since the parameter cannot be put at
the left-hand side in a join condition hence in lower layer CDS view the value of P_ReportingCountry is assigned to ParamReportingCountry*/
(
/*Part 1: This part of condition is for RITA
ParamReportingCountry can never be initial in case of RITA.
TaxCountry is not initial in case when RITA is active for a country and configuration is present in FOT_ATR*.
ParamReportingCountry should match with the I_StRpTaxItemGrpg.Country, this condition is needed to pick the configuration from FOT_ATR*.
TaxCntryOrCompanyCodeCntry of tax line item is matched against the TaxCountry of the configuration and mapped to the correct box number.
The attribute TaxCntryOrCompanyCodeCntry is a derived attribute and is always filled with either TaxCountry or CompanyCodeCountry.*/
(
I_StRpTaxItemGrpg.TaxCountry is not initial and
ParameterReportingCountry = I_StRpTaxItemGrpg.Country and
P_StRpTaxReturnItem.TaxCntryOrCompanyCodeCntry = I_StRpTaxItemGrpg.TaxCountry
)
or
/*Part 2: This part caters to the following two scenarios
1. For Plants Abroad when the configuration is present in T007* or VG_CUST and reporting needs to be done for a country.
2. When TDT is active and configuration is present in FOT_ATR*.
First, a check is made, if ParamReportingCountry is not initial. This is needed for reporting country specific data.
ParamReportingCountry = I_StRpTaxItemGrpg.Country, this Condition is used to read the configuration for the specified country.
ParamReportingCountry = P_StRpTaxReturnItem.ReportingCountry, this condition ensures that only tax lines for ParamReportingCountry are reported.
When parameter ParamReportingCountry is passed, data for that country has to be reported, hence check against which tax line item has
ParamReportingCountry = ReportingCountry, ReportingCountry is a derived attribute, derived as follows in lower views
case
when ifitaxitem.TaxCountry <> '' then ifitaxitem.TaxCountry
when ifitaxitem.TaxReturnCountry <> '' then ifitaxitem.TaxReturnCountry
else CompanyCode.Country
end as ReportingCountry,
TaxCountry is empty in case when RITA is not active*/
(
ParameterReportingCountry = I_StRpTaxItemGrpg.Country and
I_StRpTaxItemGrpg.TaxCountry is initial
)
)
and P_StRpTaxReturnItem.TaxCode = I_StRpTaxItemGrpg.TaxCode
and (
P_StRpTaxReturnItem.TransactionTypeDetermination = I_StRpTaxItemGrpg.TransactionTypeDetermination
or I_StRpTaxItemGrpg.TransactionTypeDetermination = ''
)
and (
P_StRpTaxReturnItem.DebitCreditCode = I_StRpTaxItemGrpg.DebitCreditCode
or I_StRpTaxItemGrpg.DebitCreditCode = ''
)
and (
P_StRpTaxReturnItem.AccountingDocumentType = I_StRpTaxItemGrpg.AccountingDocumentType
or I_StRpTaxItemGrpg.AccountingDocumentType = ''
)
and (
P_StRpTaxReturnItem.SupplierAccountGroup = I_StRpTaxItemGrpg.SupplierAccountGroup
or I_StRpTaxItemGrpg.SupplierAccountGroup = ''
)
and (
P_StRpTaxReturnItem.TaxRateValidityStartDate between I_StRpTaxItemGrpg.TaxRateValidityStartDate
and I_StRpTaxItemGrpg.TaxRateValidityEndDate
)
{
key P_StRpTaxReturnItem.CompanyCode,
key P_StRpTaxReturnItem.AccountingDocument,
key P_StRpTaxReturnItem.FiscalYear,
key P_StRpTaxReturnItem.TaxItem,
key P_StRpTaxReturnItem.TransactionTypeDetermination,
key P_StRpTaxReturnItem.DebitCreditCode,
key P_StRpTaxReturnItem.AccountingDocumentType,
key P_StRpTaxReturnItem.SupplierAccountGroup,
key I_StRpTaxItemGrpg.TaxBox,
key I_StRpTaxItemGrpg.TaxDeclnAmountType,
key TaxBoxStrucValidityStartDate,
key I_StRpTaxItemGrpg.UnifiedTaxBoxStructureType,
key I_StRpTaxItemGrpg.TaxGroup,
key I_StRpTaxItemGrpg.DebitCreditCode as TaxItemGrpgDebitCreditCode,
key I_StRpTaxItemGrpg.AccountingDocumentType as TaxItemGrpgAcctgDocumentType,
key I_StRpTaxItemGrpg.SupplierAccountGroup as TaxItemGrpgSupplierAcctGroup,
key I_StRpTaxItemGrpg.SpecialGLCode as TaxItemGrpgSpecialGLCode,
key
case
when P_StRpTaxReturnItem.StatryRptgEntity is not null and P_StRpTaxReturnItem.StatryRptgEntity <> '' and P_StRpTaxReturnItem.StatryRptgEntity <> ' '
then P_StRpTaxReturnItem.StatryRptgEntity
else ''
end as StatryRptgEntity,
key
case
when P_StRpTaxReturnItem.StatryRptCategory is not null and P_StRpTaxReturnItem.StatryRptCategory <> '' and P_StRpTaxReturnItem.StatryRptCategory <> ' '
then P_StRpTaxReturnItem.StatryRptCategory
else ''
end as StatryRptCategory,
key
cast(case
when P_StRpTaxReturnItem.StatryRptRunID is not null and P_StRpTaxReturnItem.StatryRptRunID <> '' and P_StRpTaxReturnItem.StatryRptRunID <> '00000000'
then P_StRpTaxReturnItem.StatryRptRunID
else ''
end as srf_report_run_id ) as StatryRptRunID,
@VDM.lifecycle.status: #DEPRECATED
@VDM.lifecycle.successor: 'TaxBoxStrucValidityStartDate'
I_StRpTaxItemGrpg.ValidFrom,
I_StRpTaxItemGrpg.TaxBoxStructureType,
I_StRpTaxItemGrpg.TaxItemGroupingVersion,
I_StRpTaxItemGrpg.TaxItemGroupingAccountNumber,
@VDM.lifecycle.status: #DEPRECATED
@VDM.lifecycle.successor: 'TaxBoxStrucValidityEndDate'
ValidTo,
TaxBoxStrucValidityEndDate,
case $parameters.P_StatryRptgEntity
when P_StRpTaxReturnItem.StatryRptgEntity
then 'X'
else
case
when P_StRpTaxReturnItem.StatryRptgEntity is null or P_StRpTaxReturnItem.StatryRptgEntity = '' or P_StRpTaxReturnItem.StatryRptgEntity = ' '
then 'X'
else
''
end
end as ItelRelforReporting1,
case $parameters.P_StatryRptCategory
when P_StRpTaxReturnItem.StatryRptCategory
then 'X'
else
case
when P_StRpTaxReturnItem.StatryRptCategory is null or P_StRpTaxReturnItem.StatryRptCategory = '' or P_StRpTaxReturnItem.StatryRptCategory = ' '
then 'X'
else
''
end
end as ItelRelforReporting2,
case $parameters.P_StatryRptRunID
when P_StRpTaxReturnItem.StatryRptRunID
then 'X'
else
case
when P_StRpTaxReturnItem.StatryRptRunID is null or P_StRpTaxReturnItem.StatryRptRunID = '' or P_StRpTaxReturnItem.StatryRptRunID = '00000000'
then 'X'
else
''
end
end as ItelRelforReporting3,
//P_StRpTaxReturnItem
I_StRpTaxItemGrpg.Country,
P_StRpTaxReturnItem.TaxCode,
P_StRpTaxReturnItem.TaxCalculationProcedure,
@DefaultAggregation:#MIN
P_StRpTaxReturnItem.TaxRate,
@DefaultAggregation:#MIN
cast(I_StRpTaxItemGrpg.TaxRate as figen_taxcode_rate_per_grp) as TaxCodeRatePointer,
P_StRpTaxReturnItem.IPITaxRate,
@DefaultAggregation:#MIN
AdditionalTax1Rate,
P_StRpTaxReturnItem.TaxRateValidityStartDate,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
ConditionAmount,
Customer,
GLAccount,
TaxItemGroup,
BusinessPlace,
TaxJurisdiction,
LowestLevelTaxJurisdiction,
ReferenceDocumentType,
AlternativeReferenceDocument,
ReverseDocument,
ReverseDocumentFiscalYear,
ConditionRecord,
RoundingDecimalPlaces,
DocumentReferenceID,
Ledger,
LedgerGroup,
PostingDate,
DocumentDate,
TaxReportingDate,
ReportingDate,
TaxReportingDocumentDate,
FiscalPeriod,
OriginalFiscalPeriod,
@DefaultAggregation:#MIN
ExchangeRate,
IsReversal,
IsReversed,
AccountingDocumentHeaderText,
CompanyCodeCountry,
ReportingCountry,
cast(P_StRpTaxReturnItem.TaxReturnCountry as figen_tax_ret_country) as TaxReturnCountry,
@Semantics.currencyCode:true
CompanyCodeCurrency,
@Semantics.currencyCode:true
CountryCurrency,
@Semantics.currencyCode:true
DocumentCurrency,
@Semantics.currencyCode:true
ReportingCurrency,
@Semantics.currencyCode: true
AdditionalCurrency1,
@Semantics.currencyCode: true
AdditionalCurrency2,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'ReportingCurrency'
TaxBaseAmountInRptgCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'ReportingCurrency'
cast(case
when NonDeductibleInputTaxAmount <> 0
then
TaxAmountInRptgCrcy - NonDeductibleInputTaxAmount
else TaxAmountInRptgCrcy
end as glo_tax_amount_rptg_crcy ) as
TaxAmountInRptgCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'ReportingCurrency'
TotalGrossAmount,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
TotalGrossAmountInCoCodeCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'DocumentCurrency'
TotalGrossAmountInTransCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
P_StRpTaxReturnItem.TaxBaseAmountInCoCodeCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
cast(case
when NonDeductibleInputTaxAmount <> 0
then
P_StRpTaxReturnItem.TaxAmountInCoCodeCrcy - NonDeductibleInputTaxAmount
else P_StRpTaxReturnItem.TaxAmountInCoCodeCrcy
end as glo_taxamount_incompcodecrcy ) as
TaxAmountInCoCodeCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'DocumentCurrency'
P_StRpTaxReturnItem.TaxBaseAmountInTransCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'DocumentCurrency'
cast(case
when NonDeductibleInputTaxAmount <> 0
then
P_StRpTaxReturnItem.TaxAmount - NonDeductibleInputTaxAmount
else P_StRpTaxReturnItem.TaxAmount
end as glo_taxamount_indocucrcy ) as
TaxAmount,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CountryCurrency'
TaxBaseAmountInCountryCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CountryCurrency'
cast(case
when NonDeductibleInputTaxAmount <> 0
then
TaxAmountInCountryCrcy - NonDeductibleInputTaxAmount
else TaxAmountInCountryCrcy
end as lwste_bset ) as TaxAmountInCountryCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'AdditionalCurrency1'
TaxBaseAmtInAdditionalCrcy1,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'AdditionalCurrency2'
TaxBaseAmtInAdditionalCrcy2,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'AdditionalCurrency1'
cast(case
when NonDeductibleInputTaxAmount <> 0
then
TaxAmountInAdditionalCurrency1 - NonDeductibleInputTaxAmount
else TaxAmountInAdditionalCurrency1
end as h2ste ) as TaxAmountInAdditionalCurrency1,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'AdditionalCurrency2'
cast(case
when NonDeductibleInputTaxAmount <> 0
then
TaxAmountInAdditionalCurrency2 - NonDeductibleInputTaxAmount
else TaxAmountInAdditionalCurrency2
end as h3ste ) as TaxAmountInAdditionalCurrency2,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
DifferenceTaxAmtInCoCodeCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
DiffTaxBaseAmountInCoCodeCrcy,
P_StRpTaxReturnItem.TaxType,
P_StRpTaxReturnItem.TargetTaxCode,
BPTaxNumber,
ReportingVATRegistration,
TaxNumber1,
TaxNumber2,
ActiveTaxType,
TaxNumber3,
NmbrOfChmlCmplncMktCountries,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
case
when NonDeductibleInputTaxAmount <> 0
then
CalculatedTxAmtInCoCodeCrcy - NonDeductibleInputTaxAmount
else CalculatedTxAmtInCoCodeCrcy
end as
CalculatedTxAmtInCoCodeCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'DocumentCurrency'
case
when NonDeductibleInputTaxAmount <> 0
then
CalculatedTaxAmountInTransCrcy - NonDeductibleInputTaxAmount
else CalculatedTaxAmountInTransCrcy
end as
CalculatedTaxAmountInTransCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CountryCurrency'
case
when NonDeductibleInputTaxAmount <> 0
then
CalculatedTaxAmountInCntryCrcy - NonDeductibleInputTaxAmount
else CalculatedTaxAmountInCntryCrcy
end as
CalculatedTaxAmountInCntryCrcy,
BusinessPartner,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
CalcdTxBaseAmtInCoCodeCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'DocumentCurrency'
CalculatedTxBaseAmtInTransCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CountryCurrency'
CalculatedTxBaseAmtInCntryCrcy,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
NonDeductibleInputTaxAmount,
case $parameters.P_TaxIsDeferredRelevant
when 'Y'
then 'X'
else
case
when ( ActiveTaxType <> '04' and ActiveTaxType <> '06' ) or (P_StRpTaxReturnItem.AccountingDocument is null or P_StRpTaxReturnItem.AccountingDocument = '')
then 'X'
else ''
end
end as TaxIsDeferredRelevant, //Condition Check for Deferred Tax
case $parameters.P_TaxIsMossRelevant
when 'N'
then
case
when ( ActiveTaxType <> '05' and ActiveTaxType <> '07' ) or (P_StRpTaxReturnItem.AccountingDocument is null or P_StRpTaxReturnItem.AccountingDocument = '')
then 'X'
else ''
end
else 'X'
end as TaxIsMossRelevant, //Condition check for Moss Tax
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
DcblVATIncrdCostInRptgCrcy,
cast( case _JournalEntry.ReferenceDocumentType
when 'FKKSU'
then
substring(_JournalEntry.OriginalReferenceDocument,1, 12)
else
''
end as fikey_kk) as CAReconciliationKey,
BusinessPartnerName,
BusinessPartnerCountry,
TaxTypeName,
CustomerSupplierAddress,
TaxIsNotDeductible,
_JournalEntry.SenderCompanyCode,
_JournalEntry.SenderAccountingDocument,
_JournalEntry.SenderFiscalYear,
@DefaultAggregation:#SUM
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
BalanceAmountInTransacCurrency,
ConditionType,
ParameterReportingCountry,
TaxCntryOrCompanyCodeCntry,
I_StRpTaxItemGrpg.TaxCountry as TaxGrpgTaxCountry,
//New Fields
TaxBoxStructure,
TaxBoxStructureName,
TaxBoxName,
TaxBoxCondition,
TaxBoxAggregationOperation,
TaxGroupOperation,
IsNegativePosting,
P_StRpTaxReturnItem.TaxCountry,
TaxGroupFreeClassification,
//associtations
_ReportedItemsLog,
_TaxCodeText,
_TaxCode,
_ReportingCurrency,
_OneTimeAccountBP,
_JournalEntry,
_AccountingDocument,
_GLAccount,
_TaxJurisdiction,
_DebtorCreditorRblsPyblsItem,
_ReceivablesPayablesItem,
_TaxReceivablesPayablesItem,
_CompanyCodeCountry,
_TaxTypeText
// _TaxCode._TaxType._Text as _TaxTypeText
}
where I_StRpTaxItemGrpg.Country = $parameters.P_ReportingCountry
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_JOURNALENTRY",
"I_STRPTAXITEMBOXCONFIGURATION",
"P_STRPTAXRETURNCUBE"
],
"ASSOCIATED":
[
"I_ACCOUNTINGDOCUMENT",
"I_COUNTRY",
"I_CURRENCY",
"I_GLACCOUNT",
"I_JOURNALENTRY",
"I_ONETIMEACCOUNTBP",
"I_OPERATIONALACCTGDOCITEM",
"I_STRPJOURNALENTRYLOG",
"I_TAXCODE",
"I_TAXCODETEXT",
"I_TAXJURISDICTION",
"I_TAXTYPETEXT"
],
"BASE":
[
"P_STRPTAXRETURNCUBE"
],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/