Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

static void CV_importAccessKeyInvoice(Args _args)

{
FiscalDocument_BR fiscalDocument;
VendInvoiceJour vendInvoiceJour;
PurchTable purchTable;
HAKPurchTable hakPurchTable;
int i;
str invoice, series, accessKey, establishment;
PurchId purchId;
ModelId model;
#File
IO iO;
FilenameOpen filename = @"C:\GSW\Import\OC.csv";
Container record;

iO = new CommaTextIo(filename,#IO_Read);

if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}

while (iO.status() == IO_Status::Ok)


{
iO.inFieldDelimiter(";");
record = iO.read();

if (record)
{
i++;

if (i > 1)
{
invoice = strLRTrim(conPeek(record, 1));
//model = strLRTrim(conPeek(record, 2));
//series = strLRTrim(conPeek(record, 3));
accessKey = strLRTrim(conPeek(record, 4));
//establishment = strLRTrim(conPeek(record, 5));
purchId = strLRTrim(conPeek(record, 7));

select firstOnly forUpdate purchTable


where purchTable.PurchId == purchId
join vendInvoiceJour
where vendInvoiceJour.PurchId == purchTable.PurchId
join forUpdate fiscalDocument
where fiscalDocument.RefRecId == vendInvoiceJour.RecId
&& fiscalDocument.RefTableId == vendInvoiceJour.TableId;
//&& fiscalDocument.Model == model
//&& fiscalDocument.FiscalDocumentSeries == series
//&& fiscalDocument.FiscalEstablishment == establishment;

if (purchTable)
{
purchTable.AccessKey_BR = strLRTrim(conPeek(record, 4));
fiscalDocument.AccessKey = strLRTrim(conPeek(record, 4));

ttsBegin;
purchTable.doUpdate();
fiscalDocument.doUpdate();

ttsCommit;

info(strFmt('Ordem %1 atualizada.', purchTable.PurchId));


}
}
}
}
}

You might also like