Derived SQL interpretation, reconstructed from the parsed view metadata (data sources, associations, and field mappings). SAP annotations are omitted and the structure is reformulated as SQL — this is a functional approximation, not the verbatim SAP source.
-- Derived SQL interpretation of CDS view P_BR_ReportingNFTaxCalculation.
-- Reconstructed from parsed metadata (data sources, associations, fields).
-- SAP annotations are omitted and the structure is reformulated as SQL;
-- this is a functional approximation, not the verbatim SAP source. Some join
-- conditions may be unavailable and a few CDS constructs are kept as-is.
-- SQL view name: PBRNFTAXCALC
CREATE VIEW P_BR_ReportingNFTaxCalculation AS
SELECT
BR_NotaFiscal,
BR_NotaFiscalItem,
BR_TaxType,
OriginalTaxGroup,
CompanyCode,
BusinessPlace,
BR_PaymentForm,
BR_NFIssueDate,
BR_NFSeries,
BR_NFPartnerType,
length(BR_NFPartner) AS PartnerFieldLength,
BR_NFPartner,
LicensePlate,
BR_NFeNumber,
BR_NFIssuedBy,
BR_NFSituationCode,
BR_NFType,
BR_NFDocumentType,
BR_NFModel,
BR_NFDirection,
BR_IsNFe,
BR_NFPartnerRegionCode,
BR_NFIsCanceled,
BR_CTeJurisdictionCodeOrigin,
BR_CTeJurisdictionCodeDest,
FreightPayer,
BR_NFPartnerTaxJurisdiction,
BR_NFCancellationDate,
BR_NFShippingUnitBrand,
BR_NFSVerificationCode,
BR_NFSubSeries,
SupplierInvoice,
BR_NFSNumber,
BR_NFPartnerStateTaxNumber,
BR_NFIsMunicipal,
BR_NFHasServiceItem,
SalesDocumentCurrency,
HeaderWeightUnit,
IncotermsClassification,
BR_NFPartnerMunicipalTaxNumber,
BR_NFReferenceDocument,
BR_NFPostingDate,
CreationDate,
CreatedByUser,
BR_NFIsCreatedManually,
BR_NFPartnerFunction,
AccountingDocument,
BR_NFIsContingency,
BR_CTeDocumentType,
BR_CTeServiceType,
PaymentTerms,
BR_NFArrivalOrDepartureDate,
BR_NFPartnerName1,
BR_NFPartnerDistrictName,
BR_NFPartnerCityName,
BR_NFPartnerPostalCode,
BR_NFPartnerStreetName,
BusinessPartnerHouseNumber,
BPHsNmbrSuplmntTxt,
PhoneNumber,
MaterialOldID,
Material,
MaterialName,
BR_NFIsPhysicalMvtOfMaterial,
BR_ICMSTaxSituation,
BR_CFOPCode,
BR_IPITaxSituation,
BR_PISTaxSituation,
BR_COFINSTaxSituation,
GLAccount,
BR_MaterialUsage,
ValuationType,
BR_NFExternalItemNumber,
BR_NFIsServiceItem,
BR_ICMSTaxLaw,
BR_IPITaxLaw,
BR_MaterialOrigin,
BR_COFINSTaxLaw,
BR_PISTaxLaw,
QuantityInBaseUnit,
BR_NFItemType,
BR_IPIControlSealCode,
BR_IPIControlSealQuantityValue,
BR_ICMSBaseDetn,
PurchaseOrder,
PurchaseOrderItem,
NFHeaderTotalAmount,
NetPriceAmount,
BR_NFTotalAmount,
BR_NFTotalAmountWithTaxes,
BR_NFValueAmountWithTaxes,
NetValueAmount,
BR_NFDiscountAmountWithTaxes,
BR_NFFreightAmountWithTaxes,
BR_NFInsuranceAmountWithTaxes,
BR_NFNetOtherExpensesAmount,
BR_ExemptedICMSAmount,
NCMCode,
BR_NFSourceDocumentNumber,
BR_NFSourceDocumentType,
BR_NFSourceDocumentItem,
Plant,
Batch,
BR_ISSTaxSituation,
BR_ISSTaxLaw,
BR_NFItemIsStatistical,
BR_ReferenceNFNumber,
BR_ReferenceNFItem,
BR_NFPriceAmountWithTaxes,
CostCenter,
BR_NBSCode,
BaseUnit,
TaxGroup,
BR_NFItemOriginalBaseAmount,
BR_OriglNFItemExclBaseAmount,
BR_OriglNFItemOtherBaseAmount,
BR_OriginalNFItemTaxRate,
BR_NFItemOriginalTaxAmount,
BR_NFItemTaxBasePct1,
BR_NFItemTaxBasePct2,
BR_NFItemIsStatisticalTax,
BR_NFItemHasFixedMktTariff,
BR_NFItemFixedMktTariffBaseQty,
BR_NFItemFixedMarketTariffUnit,
BR_NFItemWhldgCollectionCode,
BR_NFItemFixedMktTariffTaxRate,
BR_NFItemFixedMktTariffQty,
BR_NFItmFxdMktTariffUnit4Dcmls,
BR_NFItemHasWithholdingTax,
BR_NFSServiceTypeIncoming,
BR_NFSServiceTypeOutgoing,
TaxJurisdiction,
BR_UFTaxJurisdiction,
BR_NFIsTaxInNetAmount,
BR_ICMSIsIncludedInAmount,
NFItemExcludedBaseAmount,
NFItemOtherBaseAmount,
NFItemBaseAmount,
BR_IPIReductionTaxAmount,
BR_ICMSReductionTaxAmount,
BR_TaxIsISSQN,
NFItemTaxRate,
NFItemTaxAmount,
_Txtype.BR_ICMSPartilhaSubdivisionCode AS BR_ICMSPartilhaSubdivisionCode,
case when BR_TaxIsISSQN = 1 then NFItemTaxRate else 0 end AS BR_ISSQNTaxRate,
case when BR_TaxIsISSQN = 1 then NFItemTaxAmount else 0 end AS BR_ISSQNTaxAmount,
case when BR_TaxIsISSQN = 1 then NFItemExcludedBaseAmount else 0 end AS BR_ISSQNTaxExcludedBaseAmount,
case when BR_TaxIsISSQN = 1 then NFItemOtherBaseAmount else 0 end AS BR_ISSQNTaxOtherBaseAmount,
case when TaxGroup = 'ICMS' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '' and _Txtype.BR_TaxType <> 'ICSC' and NFItemBaseAmount > 0 then NFItemTaxAmount else 0 end AS BR_ICMSTaxAmount,
case when TaxGroup = 'ICMS' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '' and _Txtype.BR_TaxType <> 'ICSC' then NFItemExcludedBaseAmount else 0 end AS BR_ICMSTaxExcludedBaseAmount,
case when TaxGroup = 'ICMS' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '' and _Txtype.BR_TaxType <> 'ICSC' then NFItemOtherBaseAmount else 0 end AS BR_ICMSTaxOtherBaseAmount,
case when TaxGroup = 'ICST' and BR_NFItemIsStatisticalTax <> 'X' and _Txtype.BR_TaxType <> 'ICFP' then NFItemTaxRate else 0 end AS BR_ICMSSTTaxRate,
case when TaxGroup = 'ICST' and BR_NFItemIsStatisticalTax <> 'X' and _Txtype.BR_TaxType <> 'ICFP' then NFItemTaxAmount else 0 end AS BR_ICMSSTTaxAmount,
case when TaxGroup = 'ICST' and BR_NFItemIsStatisticalTax <> 'X' and _Txtype.BR_TaxType <> 'ICFP' then NFItemExcludedBaseAmount else 0 end AS BR_ICMSSTTaxExcludedBaseAmount,
case when TaxGroup = 'ICST' and BR_NFItemIsStatisticalTax <> 'X' and _Txtype.BR_TaxType <> 'ICFP' then NFItemOtherBaseAmount else 0 end AS BR_ICMSSTTaxOtherBaseAmount,
case when TaxGroup = 'IPI' and BR_NFItemIsStatisticalTax <> 'X' then NFItemTaxRate else 0 end AS BR_IPITaxRate,
case when TaxGroup = 'IPI' and BR_NFItemIsStatisticalTax <> 'X' then NFItemTaxAmount else 0 end AS BR_IPITaxAmount,
case when TaxGroup = 'IPI' and BR_NFItemIsStatisticalTax <> 'X' then NFItemExcludedBaseAmount else 0 end AS BR_IPITaxExcludedBaseAmount,
case when TaxGroup = 'IPI' and BR_NFItemIsStatisticalTax <> 'X' then NFItemOtherBaseAmount else 0 end AS BR_IPITaxOtherBaseAmount,
case when TaxGroup = 'PIS' then NFItemTaxRate else 0 end AS BR_AppliedPISTaxAmount,
case when TaxGroup = 'PIS' then NFItemTaxAmount else 0 end AS BR_PISTaxAmount,
case when TaxGroup = 'PIS' then NFItemExcludedBaseAmount else 0 end AS BR_PISTaxExcludedBaseAmount,
case when TaxGroup = 'PIS' then NFItemOtherBaseAmount else 0 end AS BR_PISTaxOtherBaseAmount,
case when TaxGroup = 'PIS' then BR_NFItemHasFixedMktTariff else '0' end AS BR_PISTaxIsFiscalTariff,
case when TaxGroup = 'PIS' then BR_NFItemFixedMktTariffTaxRate else 0 end AS BR_PISTxFiscalTariffBaseAmount,
case when TaxGroup = 'WHPI' then NFItemTaxRate else 0 end AS BR_PISSTTaxRate,
case when TaxGroup = 'WHPI' then NFItemTaxAmount else 0 end AS BR_PISSTTaxAmount,
case when TaxGroup = 'WHPI' then NFItemExcludedBaseAmount else 0 end AS BR_PISSTTaxExcludedBaseAmount,
case when TaxGroup = 'WHPI' then NFItemOtherBaseAmount else 0 end AS BR_PISSTTaxOtherBaseAmount,
case when TaxGroup = 'WHPI' then BR_NFItemHasFixedMktTariff else '0' end AS BR_PISSTTaxIsFiscalTariff,
case when TaxGroup = 'WHPI' then BR_NFItemFixedMktTariffTaxRate else 0 end AS BR_PISSTTxFsclTariffBaseAmount,
case when TaxGroup = 'COFI' then NFItemTaxRate else 0 end AS BR_AppliedCOFINSTaxAmount,
case when TaxGroup = 'COFI' then NFItemTaxAmount else 0 end AS BR_COFINSTaxAmount,
case when TaxGroup = 'COFI' then NFItemExcludedBaseAmount else 0 end AS BR_COFINSTaxExcludedBaseAmount,
case when TaxGroup = 'COFI' then NFItemOtherBaseAmount else 0 end AS BR_COFINSTaxOtherBaseAmount,
case when TaxGroup = 'COFI' then BR_NFItemHasFixedMktTariff else '0' end AS BR_COFINSTaxIsFiscalTariff,
case when TaxGroup = 'COFI' then BR_NFItemFixedMktTariffTaxRate else 0 end AS BR_COFINSTxFsclTrifBaseAmount,
case when TaxGroup = 'WHCO' then NFItemTaxRate else 0 end AS BR_COFINSSTTaxRate,
case when TaxGroup = 'WHCO' then NFItemTaxAmount else 0 end AS BR_COFINSSTTaxAmount,
case when TaxGroup = 'WHCO' then NFItemExcludedBaseAmount else 0 end AS BR_COFINSSTTaxExcldBaseAmount,
case when TaxGroup = 'WHCO' then NFItemOtherBaseAmount else 0 end AS BR_COFINSSTTaxOtherBaseAmount,
case when TaxGroup = 'WHCO' then BR_NFItemHasFixedMktTariff else '0' end AS BR_COFINSSTTaxIsFiscalTariff,
case when TaxGroup = 'WHCO' then BR_NFItemFixedMktTariffTaxRate else 0 end AS BR_COFINSSTTxFsclTrifBaseAmt,
case when TaxGroup = 'IRRW' then NFItemTaxAmount else 0 end AS BR_IRRFTaxAmount,
case when TaxGroup = 'ICOP' and _Txtype.BR_TaxType <> 'ICCP' then NFItemTaxRate else 0 end AS BR_DIFALTaxRate,
case when TaxGroup = 'ICOP' and _Txtype.BR_TaxType <> 'ICCP' then NFItemTaxAmount else 0 end AS BR_DIFALTaxAmount,
case when TaxGroup = 'ICOP' and _Txtype.BR_TaxType <> 'ICCP' then NFItemExcludedBaseAmount else 0 end AS BR_DIFALTaxExcludedBaseAmount,
case when TaxGroup = 'ICOP' and _Txtype.BR_TaxType <> 'ICCP' then NFItemOtherBaseAmount else 0 end AS BR_DIFALTaxOtherBaseAmount,
case when TaxGroup = 'ICOP' and _Txtype.BR_TaxType <> 'ICCP' then BR_NFItemHasFixedMktTariff else '0' end AS BR_DIFALTaxIsFiscalTariff,
case when TaxGroup = 'ICOP' and _Txtype.BR_TaxType <> 'ICCP' then BR_NFItemFixedMktTariffTaxRate else 0 end AS BR_DIFALTxFsclTariffBaseAmount,
case when TaxGroup = 'IPI' and BR_NFItemIsStatisticalTax <> 'X' then BR_NFItemOriginalTaxAmount else 0 end AS BR_OriginalIPITaxAmount,
case when TaxGroup = 'PIS' and BR_NFItemIsStatisticalTax <> 'X' then BR_NFItemOriginalTaxAmount else 0 end AS BR_OriginalPISTaxAmount,
case when TaxGroup = 'COFI' and BR_NFItemIsStatisticalTax <> 'X' then BR_NFItemOriginalTaxAmount else 0 end AS BR_OriginalCOFINSTaxAmount,
case when TaxGroup = 'ICMS' and BR_NFItemIsStatisticalTax <> 'X' and _Txtype.BR_TaxType = 'ICSC' then BR_NFItemOriginalTaxAmount else 0 end AS BR_OriginalFCPOnICMSTaxAmount,
case when TaxGroup = 'ICST' and BR_NFItemIsStatisticalTax <> 'X' and _Txtype.BR_TaxType = 'ICFP' then BR_NFItemOriginalTaxAmount else 0 end AS BR_OriglFCPOnICMSSTTaxAmount,
case when TaxGroup = 'ICMS' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '002' and NFItemBaseAmount > 0 and NFItemTaxAmount > 0 then NFItemTaxRate else 0 end AS BR_ICMSOriginTaxRate,
case when TaxGroup = 'ICMS' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '002' and NFItemBaseAmount > 0 then NFItemTaxAmount else 0 end AS BR_ICMSOriginTaxAmount,
case when TaxGroup = 'ICMS' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '001' and NFItemBaseAmount > 0 and NFItemTaxAmount > 0 then NFItemTaxRate else 0 end AS BR_ICMSDestinationTaxRate,
case when TaxGroup = 'ICMS' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '001' and NFItemBaseAmount > 0 then NFItemTaxAmount else 0 end AS BR_ICMSDestinationTaxAmount,
case when TaxGroup = 'ICMS' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '003' and _Txtype.BR_TaxType <> 'ICSC' and NFItemBaseAmount > 0 then NFItemTaxAmount else 0 end AS BR_FCPOnICMSTaxAmount,
case when TaxGroup = 'ICST' and _Txtype.BR_ICMSPartilhaSubdivisionCode = '004' and _Txtype.BR_TaxType = 'ICFP' and NFItemBaseAmount > 0 then NFItemTaxAmount else 0 end AS BR_FCPOnICMSSTTaxAmount,
case when TaxGroup = 'ICST' and BR_NFItemIsStatisticalTax = 'X' and _Txtype.BR_TaxType <> 'ICFP' then NFItemTaxAmount else 0 end AS BR_ICMSSTStatisticalTaxAmount,
case when TaxGroup = 'IPI' and BR_NFItemIsStatisticalTax = 'X' then NFItemTaxAmount else 0 end AS BR_IPIStatisticalTaxAmount,
case when BR_TaxType = 'ICZG' then NFItemTaxAmount else 0 end AS BR_ICZGTaxAmount,
case when TaxGroup = 'PIS' and BR_NFItemIsStatisticalTax <> 'X' and BR_NFIsTaxInNetAmount = 'X' then 'X' else '' end AS BR_PISIsIncludedInAmount,
case when TaxGroup = 'COFI' and BR_NFItemIsStatisticalTax <> 'X' and BR_NFIsTaxInNetAmount = 'X' then 'X' else '' end AS BR_COFINSIsIncludedInAmount
FROM P_BR_ReportingNFTaxRate
LEFT OUTER JOIN I_BR_TaxType AS _Txtype ON BR_TaxType = _Txtype.BR_TaxType AND OriginalTaxGroup = _Txtype.BR_TaxGroup -- association [1..1]
;