Re: Расчет остатков на начало периода
Добавлено: 26 ноя 2015, 14:50
oiko
Писал фейс когда-то можешь глянуть вдруг на идеи натолкнет
const
#include galnet.csc
#include galnet.ccm
end;
interface oborotv 'Оборотная ведомость в разрезе групп' (,,sci13esc);
show at (,,80,15);
table struct oborot_v
(
nrec:comp,
cmc:comp,
cpodr:comp,
cmol:comp,
cgrmc:comp,
datel:date,
datela:date,
namemc:string[80],
barkod:string[30],
typename:string[50],
edmc:string[30],
kol:double,
sum:double,
addkol:double,
addsum:double,
subkol:double,
subsum:double
)
with index
(oborot_v01=nrec(Unique, Surrogate, Journal),
oborot_v02=cmol+cgrmc+namemc,
oborot_v03=cmol+cgrmc+typename+namemc
);
table struct group1
(
cgr1:comp,
namegr1:string[80]
)
with index
(rpodr02=cgr1,
rpodr03=namegr1);
table struct group2
(
cgr1:comp,
cgr2:comp,
namegr2:string[80]
)
with index
(rgrmc01=cgr1+cgr2,
rgrmc02=cgr1+namegr2);
create view oborotv
var date1,date2,date3,date4:date;
v_podr,v_mc:string[80];
w1,w2,buff:word;
begkol,begsum,addkol,addsum,subkol,subsum:double;
prizn,prizn2:byte;
cspord:comp;
tname:string[50];
as select katmc.name from katmc(readonly),synonym katmc katmc2(readonly),
synonym pick pickmc, synonym pick pickgrmc, synonym pick pickskl, synonym pick pickmol,
synonym group1 group1s(rpodr03), synonym group2 group2s(rgrmc02),
synonym sporder sporder2, synonym sporder sporder3
where ((7 == Pickmc.wList
and 2 == Pickgrmc.wList
and 11 == Pickskl.wList
and 8 == Pickmol.wList
and Pickmol.crec==katmol.nrec
and Pickgrmc.crec==katmc2.cgroupmc
and Pickmc.crec==tmpsaldo1.cmc
and Pickmol.crec==tmpsaldo1.cmol
and katmol.cskl==tmpsaldo1.cpodr
and 0==sporder.sp
and Pickmc.crec==sporder.cmc
and katmol.nrec==sporder.ccmol
and katmol.cskl==sporder.ccpodr
and date1<<=sporder.dord
and date2>>=sporder.dord
and katmol.cskl==katpodr.nrec
and Pickmc.crec==katmc.nrec
and katmc.ced==kated.nrec
and katmc.ctype==TYPEMC.nrec
and katmc.cgroupmc==groupmc.nrec and
if (prizn=0,Pickmol.crec,katmc.cgroupmc)==group1.cgr1 and
if (prizn=0,Pickmol.crec,katmc.cgroupmc)==group2.cgr1 and
if (prizn=1,Pickmol.crec,katmc.cgroupmc)==group2.cgr2
and 0==sporder2.sp
and Pickmc.crec==sporder2.cmc
and katmol.nrec==sporder2.ccmol
and katmol.cskl==sporder2.ccpodr
and date2>>=sporder2.dord
and sporder2.cspsopr==spsopr.nrec
and 'sporder'==X$FILES.XF$NAME
and X$FILES.XF$CODE==attrnam.WTABLE
and 'Дата последнего прихода'==attrnam.name
and X$FILES.XF$CODE==attrval.WTABLE
and cspord==attrval.CREC
and attrnam.NREC==attrval.CATTRNAM
and 0==sporder3.sp
and Pickmc.crec==sporder3.cmc
and katmol.nrec==sporder3.ccmol
and katmol.cskl==sporder3.ccpodr
and date2>>=sporder3.dord
and group1s.cgr1==group2s.cgr1 and
if (prizn=0,group2s.cgr1,group2s.cgr2)==oborot_v.cmol and
if (prizn=1,group2s.cgr1,group2s.cgr2)==oborot_v.cgrmc
))
order ByName by oborot_v.cmol,oborot_v.cgrmc,oborot_v.namemc
order Bytype by oborot_v.cmol,oborot_v.cgrmc,oborot_v.typename,oborot_v.namemc;
form oborotv('OUT\%USER%\oborotv.out','oborotv');
panel StPn1;
table katmc
screen katpodrScr show at (,,,);
fields
date1:[10, 'DD/MM/YYYY'],pickbutton,noprotect;
date2:[10, 'DD/MM/YYYY'],pickbutton,noprotect;
v_podr:protect, pickbutton;
v_mc:protect, pickbutton;
prizn:noprotect;
prizn2:noprotect;
buttons
cmokSt;
<<
Период с .@@@@@@@@@@ по .@@@@@@@@@@
МОЛ .@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Группа МЦ .@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
(.) Склад - Группа МЦ ` (.) Наименование - тип `
(.) Группа МЦ - Склад ` (.) Тип - наименование `
<. OK .>
>>
end;//screen
end;//panel
handleevent
cminit:{
delete all Pickmc;
delete all Pickskl;
delete all Pickgrmc;
delete all oborot_v;
if not(ReadMyDSk(date1,'oborotv_dat1',false)) date1:=cur_date;
if not(ReadMyDSk(date2,'oborotv_dat2',false)) date2:=cur_date;
};
cmpick:{
case curfield of
#v_mc: {
delete all Pickmc;
RunInterface('L_MCU::GETSOMGM');
w2:=0
if (getfirst pickgrmc)=tsok
do {
w2:=w2+1;}
while (getnext pickgrmc)=tsok
set v_mc:='Выбрано групп МЦ: '+w2;}
#v_podr: {
delete all Pickskl;
delete all Pickmol;
RunInterface('L_MOL::GETSOMEMOL');
w1:=0
if (getfirst pickmol)=tsok
do {
insert pickskl set pickskl.wlist:=11,pickskl.crec:=if(getfirst katmol=tsok,katmol.cskl,0);
w1:=w1+1;}
while (getnext pickmol)=tsok
set v_podr:='Выбрано МОЛ: '+w1;}
end;//case
};
cmokSt:{Putcommand(cmdefault)};
cmdefault:{
if (date1>date(0,0,0) and date2>date(0,0,0)) then {
if (date1<=date2) then {
if (w1>0) then {
if (w2>0) then {
SaveMyDSk(date1,'oborotv_dat1');
SaveMyDSk(date2,'oborotv_dat2');
StartNewVisual(vtNumericVisual, vfTimer + vfBreak + vfConfirm, 'Отбор ТМЦ',1);
_loop pickgrmc
{
nextvisual;
_loop katmc2
{
insert pickmc set
pickmc.wlist:=7,
pickmc.crec:=katmc2.nrec;
};
};
stopVisual('',0);
Store_Init;
Store_ReInit;
Store_TypeOstatki(TRUE) ; // тїюф ∙шх юёЄрЄъш
Store_SkladProizv(0);
Store_Run(date1,comp(-2),comp(-2),comp(-2),comp(0), true, false, false);
StartNewVisual(vtNumericVisual, vfTimer + vfBreak + vfConfirm, 'Считаю ',1);
_loop pickmol
{
getfirst katmol;
if (getfirst katpodr)<>tsok
{
delete current pickmol;
}
}
_loop pickmol
{
getfirst katmol;
getfirst pickskl;
getfirst katpodr;
_loop pickmc
{
nextvisual;
getfirst katmc;
getfirst groupmc;
tname:='';
if (getfirst typemc)=tsok
{
tname:=typemc.name;
};
begkol:=0;
begsum:=0;
addkol:=0;
addsum:=0;
subkol:=0;
subsum:=0;
date3:=date(0,0,0);
date4:=date(0,0,0);
buff:=0;
if (modifier getfirst tmpsaldo1)=tsok
{
begkol:=tmpsaldo1.kol;
begsum:=tmpsaldo1.price*if(tmpsaldo1.kol<>0,tmpsaldo1.kol,1);
};
if (modifier getfirst sporder)=tsok
do {
if (sporder.vidorder=0)
then {
addkol:=addkol+sporder.kol;
addsum:=addsum+sporder.srprice*if(sporder.kol<>0,sporder.kol,1);
};
else
{
subkol:=subkol+sporder.kol;
subsum:=subsum+sporder.srprice*if(sporder.kol<>0,sporder.kol,1);
};
};
while (modifier getnext sporder)=tsok
if ((modifier getlast sporder2)=tsok)
do {
if (modifier getfirst spsopr)=tsok
{
if(spsopr.vidsopr=101)
{
date3:=sporder2.dord;
};
};
};
while ((modifier getprev sporder2)=tsok and date3=date(0,0,0))
if (date3=date(0,0,0))
{
if ((modifier getlast sporder2)=tsok)
{
cspord:=sporder2.nrec;
if (modifier getfirst attrnam)=tsok
{
if (modifier getfirst attrval)=tsok
{
if (attrval.Vdate>date(0,0,0))
{
date3:=attrval.Vdate;
};
};
};
};
};
if ((modifier getlast sporder3)=tsok)
do {
if (sporder3.kol>0 and sporder3.vidorder=0)
{
date4:=sporder3.dord;
cspord:=sporder3.nrec;
if (modifier getfirst attrnam)=tsok
{
if (modifier getfirst attrval)=tsok
{
if (attrval.Vdate>date(0,0,0))
{
date4:=attrval.Vdate;
};
};
};
};
};
while ((modifier getprev sporder3)=tsok and date4=date(0,0,0))
if (begkol<>0 or begsum<>0 or addkol<>0 or addsum<>0 or subkol<>0 or subsum<>0)
{
insert oborot_v set
oborot_v.kol:=begkol,
oborot_v.sum:=begsum,
oborot_v.addkol:=addkol,
oborot_v.addsum:=addsum,
oborot_v.subkol:=subkol,
oborot_v.subsum:=subsum,
oborot_v.cpodr:=katmol.cskl,
oborot_v.cmol:=pickmol.crec,
oborot_v.cmc:=pickmc.crec,
oborot_v.cgrmc:=katmc.cgroupmc,
oborot_v.namemc:=katmc.name,
oborot_v.barkod:=katmc.barkod,
oborot_v.datel:=date3,
oborot_v.datela:=date4,
oborot_v.typename:=tname,
oborot_v.edmc:=if(getfirst kated=tsok,kated.name,'не найдено');
if (modifier getfirst group1)<>tsok
{
if (prizn=0)
then {
group1.namegr1:=katmol.name+' '+katpodr.name;
group1.cgr1:=Pickmol.crec;
insert current group1;
};
else {
group1.namegr1:=GROUPMC.name;
group1.cgr1:=katmc.cgroupmc;
insert current group1;
}
};
if (modifier getfirst group2)<>tsok
{
if (prizn=0)
then {
group2.namegr2:=GROUPMC.name;
group2.cgr1:=Pickmol.crec;
group2.cgr2:=katmc.cgroupmc;
insert current group2;
};
else
{
group2.namegr2:=katmol.name+' '+katpodr.name;
group2.cgr1:=katmc.cgroupmc;
group2.cgr2:=Pickmol.crec;
insert current group2;
};
};
};
};
};
stopVisual('',0);
Store_Done;
oborotv.write(date1,0);
oborotv.write(date2,0);
oborotv.write(prizn,0);
if (prizn2=0)
then{
setorder(tiByName);
};
else{
setorder(tiBytype);
};
_loop group1s
{
oborotv.PutEventById(feDoLoop,fcstoborotv01);
oborotv.write(group1s.namegr1,0);
_loop group2s
{
oborotv.PutEventById(feDoLoop,fcstoborotv02);
oborotv.write(group2s.namegr2,0);
if (modifier getfirst oborot_v)=tsok
do {
oborotv.PutEventById(feDoLoop,fcstoborotv03);
oborotv.write(oborot_v.namemc,0);
oborotv.write(oborot_v.cmc,0);
oborotv.write(' '+oborot_v.barkod,0);
oborotv.write(oborot_v.typename,0);
oborotv.write(oborot_v.edmc,0);
oborotv.write(oborot_v.datel,0);
oborotv.write(oborot_v.datela,0);
oborotv.write(round(oborot_v.kol,3),0);
oborotv.write(round(oborot_v.sum,2),0);
oborotv.write(round(oborot_v.addkol,3),0);
oborotv.write(round(oborot_v.addsum,2),0);
oborotv.write(round(oborot_v.subkol,3),0);
oborotv.write(round(oborot_v.subsum,2),0);
};
while (modifier getnext oborot_v)=tsok
};
};
oborotv.showfile('oborotv');
abort;
closeinterface(0);
}; else {message ('Не выбрано ни одной группы мц',tsok);};
}; else {message ('Не выбрано ни одного склада',tsok);};
}; else {message ('Дата начала должна быть меньше даты конца',tsok);};
}; else {message ('Дата начала или конца не указаны',tsok);};
};
end;//he win
END.