REX2
Материал из Фабиус wiki
REX2 - это уровень 2 документа REX
CTRL+F10
Создать документ на основании установки цен
ТЕКСТ
local del del := true // del := YESNO( 'Удалять одинаковые цены ?', false ) local sql, r599, msg, aa, r20_kod, fld, pp, flt flt := [ USERKOD = ] + userKOD r20_kod := DOCS1->DANAL1 // магазин sql := [ DELETE FROM R599 WHERE 'SYSTEM.' = 'SYSTEM.' and USERKOD = ] + userKOD SIMPLESQL( sql, ReflisPath ) sql := [ Select DANAL2, NATTR1, ] + userKOD + [ From DOCS] + RET_F_EXT() + [ Where KINDDOC = 'UPR' and LVLNUM = '2' and DATDOC = '] + SQLDATE( DOCS1->DATDOC ) + [' and ; DREFL1 = 'R20 ' and DANAL1 = ] + r20_kod + [ and DANAL2 > 0 and NATTR1 > 0 and DREFL2 = 'R08 ' ] SIMPLESQL( [ Insert into ] + EXPANDREFLPATH( 'R599' ) + [( KOD, NEW_PRICE, USERKOD ) ] + sql, opdataPATH ) try r599 := OPENKLSF( 'R599' ) ( r599 )->( SETFILTER( flt ) ) ( r599 )->( DBGOTOP() ) while !( r599 )->( EOF() ) aa := REALNAME( 'R08', ( r599 )->KOD ) WAITMSG( aa, msg ) ( r599 )->PNAME := aa fld := { 'EAMNT', 'EDSUM' } aa := DAY_REST( ( r599 )->KOD, DOCS1->DATDOC, r20_kod ) if !ISEMPTY( aa ) ( r599 )->AMNT := aa[1,1] ( r599 )->OLD_SUM := aa[1,2] ( r599 )->OLD_PRICE := DIV_Z( ( r599 )->OLD_SUM, ( r599 )->AMNT, 2 ) ( r599 )->NEW_SUM := ROUND( ( r599 )->AMNT * ( r599 )->NEW_PRICE, 2 ) endif ( r599 )->( DBSKIP() ) end finally CLOSEKLSF( r599 ) HIDEMSG( msg ) end if del sql := [ DELETE FROM R599 WHERE 'SYSTEM.' = 'SYSTEM.' and OLD_PRICE = NEW_PRICE and USERKOD = ] + userKOD SIMPLESQL( sql, reflisPATH ) endif sql := [ DELETE FROM R599 WHERE OLD_PRICE = 0 and USERKOD = ] + userKOD SIMPLESQL( sql, reflisPATH ) // - в документе Переоценка по кнопке Ctrl F10 - не выводить в списке товар, если старая цена по нему = 0. r599 := CHOICEREFR( 'R599', "GRPRECORD( 'KOD' )",, flt ) if VALTYPE( r599 ) = 'N' r599 := { r599 } endif fld := { 'KANAL2', 'NATTR3', 'NATTR2', 'NATTR4' } sql := [ Select KOD KANAL2, OLD_PRICE NATTR3, NEW_PRICE NATTR2, AMNT NATTR4 From R599 Where KOD in ( ] + ARRASSTRING( r599 ) + [ ) and USERKOD = ] + userKOD aa := SQLTOARR( sql, fld, reflisPATH ) try isCalcAverPrice := true if !ISEMPTY( aa ) ADDALL( 'REX', '2', DOCS1->RGNUM,, fld, aa ) endif finally isCalcAverPrice := false end