TPS 170329
Материал из Фабиус wiki
TPS_170329 - это "Процент брака от выработки"
Условие отбора
local ip, my, end_data, fld, _, sql, _2 fld := ' _1,N,5; _2,C,60; _3,N,14,4; _4,N,14,4; _5,N,14,4; _6,N,14,4; _7,N,14,4;' _ := CreateTmpFile( fld, '_', ~IsFreeDel := true, ~Own := Self ) _2 := CreateTmpFile( fld, '_2', ~IsFreeDel := true, ~Own := Self ) ip := InputPeriod2() if Empty( ip ) return endif M->QwrTitle := ' ( ' + DKShift_str( ip[1] ) + ' - ' + DKShift_str( ip[2] ) + ' )' my := StoD( ip[1] ) end_data := StoD( ip[2] ) + 1 while my <> end_data // PAC4 sql := [ Select DANAL2, AMNT From DOCP] + Ret_f_ext( my ) + [ Where KINDDOC = 'PAC' and LVLNUM = '4' and ; DATDOC = '] + SqlDate( my ) + [' and DSHIFT between '] + ip[1] + [' and '] + ip[2] + [' ] SimpleSql( [ Insert into ] + TmpFilePath( _2 ) + [( _1, _3 ) ] + sql, OpdataPath ) // 28 sql := [ Select DANAL2, AMNT From PRVS] + Ret_f_ext( my ) + [ Where DEBT = '28 ' and DREFL1 = 'R10 ' and DANAL1 = 2 and ; DATDOC = '] + SqlDate( my ) + [' and DSHIFT between '] + ip[1] + [' and '] + ip[2] + [' ] SimpleSql( [ Insert into ] + TmpFilePath( _2 ) + [( _1, _5 ) ] + sql, OpdataPath ) my := my + 1 end // _2 -> _ sql := [ Select _1, Sum( _3 ), Sum( _5 ) From ] + TmpFilePath( _2 ) + [ Group by _1 ] SimpleSql( [ Insert into ] + TmpFilePath( _ ) + [( _1, _3, _5 ) ] + sql, OpdataPath ) sql := [ Update _ Set _4 = Round( _3 * WEIGHT, 2 ), _6 = Round( _5 * WEIGHT, 2 ) From ] + TmpFilePath( _ ) + [ _ left outer join R11 ON _1 = KOD ] SimpleSql( sql, ReflisPath ) sql := [ Update ] + TmpFilePath( _ ) + [ Set _7 = Round( _5 * 100 / _3, 1 ) Where _3 > 0 and _5 > 0 ] SimpleSql( sql, TempPath ) ( _ )->( DbGoTop() ) result := _ // _1 код // _2 наименование // _3 штук // _4 кг // _5 брак штук // _6 брак кг // _7 процент брака // _8 // _9