TAKE FROM HTTP — различия между версиями
Материал из Фабиус wiki
Hisava (обсуждение | вклад) (Новая страница: «TAKE_FROM_HTTP - это программа из справочника R266 Запрос к офд = Текст = local fn := "9282000100001350", data :…») |
Hisava (обсуждение | вклад) м |
||
Строка 3: | Строка 3: | ||
= Текст = | = Текст = | ||
local fn := "9282000100001350", data := date(), body, head, json, msg, aa, bb, ii, del, fld, _, sql, tt, br, nn | local fn := "9282000100001350", data := date(), body, head, json, msg, aa, bb, ii, del, fld, _, sql, tt, br, nn | ||
− | head := { { 'Ofdapitoken', | + | head := { { 'Ofdapitoken', [] } } |
body := '{"fiscalDriveNumber" : "'+ fn + '", "date" : "' + sqlDate(data) + '"}' | body := '{"fiscalDriveNumber" : "'+ fn + '", "date" : "' + sqlDate(data) + '"}' | ||
try | try |
Версия 08:36, 21 февраля 2019
TAKE_FROM_HTTP - это программа из справочника R266
Запрос к офд
Текст
local fn := "9282000100001350", data := date(), body, head, json, msg, aa, bb, ii, del, fld, _, sql, tt, br, nn head := { { 'Ofdapitoken', [] } } body := '{"fiscalDriveNumber" : "'+ fn + '", "date" : "' + sqlDate(data) + '"}' try waitmsg( 'Подключение к офд Ярус', msg ) json := idhttppostJSON( 'https:/' + '/api.ofd-ya.ru/ofdapi/v1/documents', body, head ) // json := READTXTFILE2( 'json.txt', 'c:\fabius\ig2\' ) aa := ParseFromJSon( json ) bb := aa[2,2] del := [ kinddoc = 'FRO' and lvlnum = '1' and dtos( datdoc ) = '] + dtos( data ) + [' and k3name = '] + fn + [' ] sql := [ delete from docp] + ret_f_ext( data ) + [ where kinddoc = 'FRO' and 'SYSTEM.' = 'SYSTEM.' ] simplesql( sql, opdatapath ) fld := { 'datdoc', 'numdoc', 'kshift', 'nattr7', 'k3name' } fld := ' _0,d,4; _1,N,6; _2,C,60; _3,N,5; _4,N,14,4; _5,N,14,4; _6,N,14,4; ' _ := CreateTmpFile( fld, '_', ~IsFreeDel := true ) for ii := 1 to len( bb ) ( _ )->( dbappend() ) ( _ )->_0 := data nn := ascann( bb[ii], 'fiscalDocumentNumber' ) ( _ )->_1 := bb[ii,nn,2] nn := ascann( bb[ii], 'totalSum' ) ( _ )->_6 := val( bb[ii,nn,2] ) / 100 next fld := { 'datdoc', 'nattr7', 'sum' } sql := [ Select _0 datdoc, _1 nattr7, _6 "sum" from ] + TmpFilePath( _ ) aa := sqltoarr( sql, fld ) if !isempty( aa ) addall( 'FRO', '1', " ",, fld, aa,,,, year( data ), month( data ),,, true,, del ) endif finally closetable( _ ) hidemsg( msg ) end fld := ' _0,d,4; _1,N,6; _2,C,60; _3,N,5; _4,N,14,4; _5,N,14,4; _6,N,14,4; ' try _ := CreateTmpFile( fld, '_', ~IsFreeDel := true ) for ii := 1 to len( bb ) nn := ascann( bb[ii], 'items' ) aa := bb[ii,nn,2] for tt := 1 to len( aa ) ( _ )->( dbappend() ) ( _ )->_0 := data nn := ascann( bb[ii], 'fiscalDocumentNumber' ) ( _ )->_1 := bb[ii,nn,2] ( _ )->_2 := left( aa[tt,4,2], 60 ) br := at( ')', ( _ )->_2 ) ( _ )->_3 := substr( aa[tt,4,2], 2, br - 1 ) ( _ )->_4 := val( aa[tt,3,2] ) / 100 ( _ )->_5 := aa[tt,1,2] ( _ )->_6 := val( aa[tt,5,2] ) / 100 next next del := [ kinddoc = 'FRO' and lvlnum = '2' and dtos( datdoc ) = '] + dtos( data ) + [' and k3name = '] + fn + [' ] fld := { 'datdoc', 'nattr7', 'kanal2', 'k2name', 'nattr1', 'amnt', 'sum' } sql := [ Select _0 datdoc, _1 nattr7, _3 kanal2, _2 k2name, _4 nattr1, _5 amnt, _6 "sum" from ] + TmpFilePath( _ ) aa := sqltoarr( sql, fld ) if !isempty( aa ) addall( 'FRO', '2', " ",, fld, aa,,,, year( data ), month( data ),,, true,, del, { false, false, false, false, false } ) endif finally closetable( _ ) end sql := [ update fro2 set fro2.parent = fro1.rgnum from docp] + ret_f_ext( data ) + [ fro2 ; left outer join docp] + ret_f_ext( data ) + [ fro1 on fro2.nattr7 = fro1.nattr7 ; where fro1.kinddoc = 'FRO' and fro1.lvlnum = '1' and fro2.kinddoc = 'FRO' and fro2.lvlnum = '2' and fro2.parent = ] simplesql( sql, opdatapath ) // _0 дата // _1 fiscalDocumentNumber // _2 наименование // _3 код // _4 price // _5 quantity // _6 sum // _7 // _8 // _9 // writetxtfile( { json }, 'json.txt', 'c:\fabius\ig2\' ) // json := ReadTxtFile( 'json.txt', 'c:\fabius\ig2\' )