скрытое
ТекстЗапроса = "SELECT SMDOCUMENTS.ID
|FROM SMDOCUMENTS, SMClientInfo ";
Если НачДата=КонДата Тогда
ТекстЗапроса = ТекстЗапроса+"
|where (to_char(SMDOCUMENTS.CREATEDAT,'RRRR:MM:DD') = to_char(:НачДата~~,'RRRR:MM:DD'))";
Иначе
ТекстЗапроса = ТекстЗапроса+"
|where (to_char(SMDOCUMENTS.CREATEDAT,'RRRR:MM:DD') >= to_char(:НачДата~~,'RRRR:MM:DD') and to_char(SMDOCUMENTS.CREATEDAT,'RRRR:MM:DD') <= to_char(:КонДата~~,'RRRR:MM:DD'))";
КонецЕсли;
ТекстЗапроса = ТекстЗапроса+"
|and (SMDOCUMENTS.CLIENTINDEX=SMClientInfo.ID)
|and (SMClientInfo.INN=:ИНН)";
Если КПП="" Тогда
ТекстЗапроса=ТекстЗапроса+"
|and (SMClientInfo.KPP is Null)";
Иначе
ТекстЗапроса=ТекстЗапроса+"
|and (SMClientInfo.KPP=:КПП)";
КонецЕсли;
ТекстЗапроса=ТекстЗапроса+"
|and (SMDOCUMENTS.DOCSTATE=3)
|and ((SMDOCUMENTS.LOCATIONFROM in (:спис))or(SMDOCUMENTS.LOCATIONTO in (:спис)))
|order by SMDOCUMENTS.CREATEDAT";
ТекстЗапроса = "SELECT SMDOCUMENTS.ID
|FROM SMDOCUMENTS ";
Если НачДата=КонДата Тогда
ТекстЗапроса = ТекстЗапроса+"
|where (to_char(SMDOCUMENTS.CREATEDAT,'RRRR:MM:DD') = to_char(:НачДата~~,'RRRR:MM:DD'))";
Иначе
ТекстЗапроса = ТекстЗапроса+"
|where (to_char(SMDOCUMENTS.CREATEDAT,'RRRR:MM:DD') >= to_char(:НачДата~~,'RRRR:MM:DD') and to_char(SMDOCUMENTS.CREATEDAT,'RRRR:MM:DD') <= to_char(:КонДата~~,'RRRR:MM:DD'))";
КонецЕсли;
ТекстЗапроса=ТекстЗапроса+"
|and (SMDOCUMENTS.DOCSTATE=3)
|and (SMDOCUMENTS.doctype in ('WI','WO','IW','PE'))
|and ((SMDOCUMENTS.LOCATIONFROM in (:спис))or(SMDOCUMENTS.LOCATIONTO in (:спис)))
|order by SMDOCUMENTS.CREATEDAT";
Иначе
Если флИзм=1 Тогда
ТекстЗапроса = "SELECT SMDOCLOG.ID
|FROM SMDOCLOG,SMDOCUMENTS";
Если НачДата=КонДата Тогда
ТекстЗапроса = ТекстЗапроса+"
|where (to_char(smdoclog.eventtime,'RRRR:MM:DD') = to_char(:НачДата~~,'RRRR:MM:DD'))";
Иначе
ТекстЗапроса = ТекстЗапроса+"
|where (to_char(SMDOCLOG.EVENTTIME,'RRRR:MM:DD') >= to_char(:НачДата~~,'RRRR:MM:DD') and to_char(SMDOCLOG.EVENTTIME,'RRRR:MM:DD') <= to_char(:КонДата~~,'RRRR:MM:DD'))";
КонецЕсли;
ТекстЗапроса = ТекстЗапроса+"
|and (to_char(smdoclog.eventtime,'RRRR:MM:DD') >= to_char(smdoclog.docdate,'RRRR:MM:DD'))
|and (smdoclog.NEWSTATE=3)
|and (SMDOCUMENTS.doctype in ('WI','WO','IW','PE'))
|and ((SMDOCUMENTS.ID=SMDOCLOG.ID)and(SMDOCUMENTS.doctype=SMDOCLOG.doctype)and((SMDOCUMENTS.LOCATIONFROM in (:спис))or(SMDOCUMENTS.LOCATIONTO in (:спис))))
|order by SMDOCLOG.DOCDATE";
Иначе //флИзм<>1 Тогда
ТекстЗапроса = "SELECT SMDOCLOG.ID
|FROM SMDOCLOG,SMDOCUMENTS";
Если НачДата=КонДата Тогда
ТекстЗапроса = ТекстЗапроса+"
|where ((to_char(smdoclog.eventtime,'RRRR:MM:DD') = to_char(:НачДата~~,'RRRR:MM:DD'))
|or (to_char(smdoclog.docdate,'RRRR:MM:DD') = to_char(:НачДата~~,'RRRR:MM:DD')))";
Иначе
ТекстЗапроса = ТекстЗапроса+"
|where ((to_char(SMDOCLOG.EVENTTIME,'RRRR:MM:DD') >= to_char(:НачДата~~,'RRRR:MM:DD') and to_char(SMDOCLOG.EVENTTIME,'RRRR:MM:DD') <= to_char(:КонДата~~,'RRRR:MM:DD'))
|or (to_char(smdoclog.docdate,'RRRR:MM:DD') >= to_char(:НачДата~~,'RRRR:MM:DD') and to_char(smdoclog.docdate,'RRRR:MM:DD') <= to_char(:КонДата~~,'RRRR:MM:DD')))";
КонецЕсли;
ТекстЗапроса = ТекстЗапроса+"
//|and (to_char(smdoclog.eventtime,'RRRR:MM:DD') >= to_char(smdoclog.docdate,'RRRR:MM:DD'))
|and (smdoclog.NEWSTATE=3) and (SMDOCUMENTS.ID=SMDOCLOG.ID) and (SMDOCUMENTS.doctype=SMDOCLOG.doctype)
|and (SMDOCUMENTS.doctype in ('WI','WO','IW','PE'))
|and ((SMDOCUMENTS.LOCATIONFROM in (:спис)) or (SMDOCUMENTS.LOCATIONTO in (:спис)))
|order by SMDOCLOG.DOCDATE";
ТекстЗапроса = "SELECT ALL SACardClass.Tree, SACardClass.NAME
|FROM SACardClass";
//RS.Отладка(1);
тзТовар=RS.ВыполнитьИнструкцию(ТекстЗапроса,, 1);
//контрагенты
ТекстЗапроса = "SELECT ALL SMClientInfo.ID, SMClientInfo.NAME as Имя, SMClientInfo.INN as ИНН, SMClientInfo.KPP as КПП,
|SMClientInfo.PASSPORT as Паспорт
|FROM SMClientInfo";
ТекстЗапроса = "SELECT ALL FFMAPREP.SALETYPE as DOCTYPE, FFMAPREP.SALEID as DOCID, FFMAPREP.INCOMEID as INCOMEID,
|FFMAPREP.SALELOCATIONFROM as Склад, FFMAPREP.SALELOCATIONTO as СкладВ, FFMAPREP.SALEDATE as CREDATE,
|FFMAPREP.SALECLIENTINDEX as SUPPLIER, SACardClass.Tree as Узел,
|FFMAPREP.SALESUM as Всего, FFMAPREP.SALEQ as Колво, FFMAPREP.SALENOVAT as Сумма, FFMAPREP.SALEVATRATE as СтавкаНДС, FFMAPREP.PRIMECOST as ВсегоСебест,
|FFMAPREP.PRIMECOSTNOVAT as СуммаСебест, FFDOCUMENTS.USEROP as ПользОпер, FFDOCUMENTS.SUPPLIERINVOICE as INVOICE, FFDOCUMENTS.SUPPLINVOICECREATE as SUPDATA, FFDOCUMENTS.SupplierDoc as NAKLAD,
|SAOperation.NAME as Операция
|FROM FFMAPREP, SAOperation,SMCARD, SACardClass, FFDOCUMENTS
|where (FFMAPREP.SALEID in (:спис))
|and (FFMAPREP.RECTYPE=1)
|and (SAOperation.ID in (:Операции))
|and (FFMAPREP.SALEID=FFDOCUMENTS.ID)
|and (FFMAPREP.SALETYPE=FFDOCUMENTS.DOCTYPE)
|and (FFDOCUMENTS.OpCode=SAOperation.ID)
|and (FFMAPREP.ARTICLE=SMCARD.ARTICLE)
|and (SMCARD.IDCLASS=SACardClass.ID)
|order by FFMAPREP.SALEID";
ТекстЗапроса = "SELECT ALL SMUSEROP.ID,SMUSEROP.TITLE
|FROM SMUSEROP";
ТекстЗапроса = "SELECT ALL SMSTORELOCATIONS.ID,SMSTORELOCATIONS.NAME
|FROM SMSTORELOCATIONS ";
ТекстЗапроса = "SELECT ALL SAOperation.ID,SAOperation.NAME
|FROM SAOperation Where SAOperation.ID in (0,1,2,4,10,11, 12)"
ф