Description
ConvertXmlToTableDetail
Parameters
ihComponent | input | handle | |
ihStartNode | input | handle | |
ihCurrentTable | input | handle | |
irParentRowid | input | rowid | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/tconvertinstalnetxml.p)
assign oiReturnStatus = -98.
if ihStartNode:local-name = "":U
then vcNodeName = ihStartNode:name.
else vcNodeName = ihStartNode:local-name.
create x-noderef vhNode in widget-pool "non-persistent".
if vcNodeName = "InvoiceHeader":U
then do:
find first tNETKnownTable where tNETKnownTable.tcTableName = "t_oCInvoice":U no-error.
assign vlInvoice = ?
vcOrderNumberBuyer = '':U
vcEANSupplier = '':U.
assign vhCurrentTable = (if available tNETKnownTable
then tNETKnownTable.thTableHandle
else ?).
/* Get out of here if you cannot find the desired table in the context
it is not necessary to read further on */
if not valid-handle(vhCurrentTable)
then do :
assign oireturnstatus = 0.
return.
end.
/* Create a reference between parent and child table */
vhCurrentTable:buffer-create().
if irParentRowid <> ?
then do :
create tNETTableRef.
assign tNETTableRef.trParentRowid = irParentRowid
tNETTableRef.trChildRowid = vhCurrentTable:rowid.
assign vhColumn = vhCurrentTable:buffer-field ("tc_ParentRowid":U)
vhColumn:buffer-value = string (irParentRowid).
end.
assign vhColumn = vhCurrentTable:buffer-field ("Company_ID":U)
vhColumn:buffer-value = viCompanyLoadedId.
assign vhColumn = vhCurrentTable:buffer-field ("tc_Rowid":U)
vhColumn:buffer-value = string (vhCurrentTable:rowid).
do viCnt = 1 to ihStartNode:num-children :
ihStartNode:get-child(vhNode,viCnt).
<M-1 run ConvertXmlToTableDetail (input ihComponent (ihComponent),
input vhNode (ihStartNode),
input vhCurrentTable (ihCurrentTable),
input vhCurrentTable:rowid (irParentRowid),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end.
end.
end.
else
/* if it is not a table, then try to read fields, or just fall further down in the structure */
/* Either t_oCinvoice or t_oCinvoiceVat */
if valid-handle(ihCurrentTable)
then do :
assign vcFieldName = "":U.
vhNode:get-parent(vhParentNode).
if vhNode:local-name = "":U
then vcParentName = vhNode:name.
else vcParentName = vhNode:local-name.
/* Mapping of the fields - also check of the Parent */
case vcParentName:
when "InvoiceHeader":U
then case vcNodeName:
when "CurrencyCode":U then assign vcFieldName = "tcCurrencyCode":U.
when "InvoiceTypeCode":U then assign vcFieldName = "CInvoiceType":U.
end case.
when "Supplier":U
then case vcNodeName:
when "GLN":U then assign vcEANSupplier = vhNode:node-value.
end case.
when "InvoiceReferences":U
then case vcNodeName:
when "OrderNumberBuyer":U then assign vcOrderNumberBuyer = if vcOrderNumberBuyer = "":U
then vhNode:node-value
else vcOrderNumberBuyer.
when "InvoiceNumber":U then assign vcFieldName = "CInvoiceVoucher":U.
end case.
when "Document":U
then case vcNodeName:
when "Date":U then assign vcFieldName = "CInvoiceDate":U.
when "DocumentNumber":U then assign vcFieldName = "CInvoiceReference":U.
end case.
when "InvoiceTotals":U
then case vcNodeName:
when "MessageAmount":U then assign vcFieldName = if vlInvoice then "CInvoiceOriginalCreditTC":U
else if vlInvoice <> ? then "CInvoiceOriginalDebitTC":U
else "":U.
end case.
when "TaxSpecification":U
then case vcNodeName:
when "BasisAmount":U then assign vcFieldName = if vlInvoice then "CInvoiceVATBaseCreditTC":U
else if vlInvoice <> ? then "CInvoiceVATBaseDebitTC":U
else "":U.
when "TaxAmount":U then assign vcFieldName = if vlInvoice then "CInvoiceVATCreditTC":U
else if vlInvoice <> ? then "CInvoiceVATDebitTC":U
else "":U.
end case.
end case.
if not vcFieldName = "":U
then do:
/* Search for the right column */
assign vhColumn = ihCurrentTable:buffer-field(vcFieldName) no-error.
if not valid-handle (vhColumn)
then do :
assign vhdatabaseInst = ihComponent
vcMessage = trim(substitute(#T-3'Business Relation Name':100(16050)T-3#,entry(2,vcNodeName,'-':U),ihCurrentTable:name)).
<M-2 run SetMessageInLog (input vcMessage (icMessage),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
assign oiReturnStatus = -3.
return.
end.
/* Read value from text node behind, and put it in buffer-value of vhColumn */
<M-4 run SetFieldValue (input ihStartNode (ihNode),
input vhColumn (ihField),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end.
/* Do we have the Invoice or the CreditNote */
if vhColumn:Name = "CInvoiceType":U
then do:
if vhColumn:buffer-value = "380":U
then assign vhColumn:buffer-value = {&INVOICETYPE-CREDITNOTE}.
if vhColumn:buffer-value = "384":U
then assign vhColumn:buffer-value = {&INVOICETYPE-INVOICE}.
assign vlInvoice = if vhColumn:buffer-value = {&INVOICETYPE-INVOICE}
then true
else if vhColumn:buffer-value = {&INVOICETYPE-CREDITNOTE}
then false
else ?.
end.
end.
end.
if vcFieldName = "":U or
not valid-handle(ihCurrentTable)
then do viCnt = 1 to ihStartNode:num-children :
ihStartNode:get-child(vhNode,viCnt).
<M-5 run ConvertXmlToTableDetail (input ihComponent (ihComponent),
input vhNode (ihStartNode),
input ? (ihCurrentTable),
input irParentRowid (irParentRowid),
output viFcReturnSuper (oiReturnStatus)) in TConvertInstalNETXML>
if viFcReturnSuper <> 0
then do :
assign oiReturnStatus = viFcReturnSuper.
return.
end.
end.
delete object vhNode.
delete object vhParentNode.
assign oiReturnStatus = 0.