unit NaklUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, frxClass, frxADOComponents, frxDBSet,StdCtrls,
  frxDesgn;

type
  TNaklForm = class(TForm)
    frxDatasetPrCap: TfrxDBDataset;
    frxADOComponents1: TfrxADOComponents;
    frxDatasetPrStr: TfrxDBDataset;
    TrCheckBox: TCheckBox;
    forSumNDS_1: TCheckBox;
    PrCapQuery: TQuery;
    PrCapQueryIdDoc: TIntegerField;
    PrCapQueryIdPredpr: TSmallintField;
    PrCapQueryKodSkl: TSmallintField;
    PrCapQueryVidDoc: TSmallintField;
    PrCapQueryDateDoc: TDateTimeField;
    PrCapQueryNumDoc: TIntegerField;
    PrCapQueryNameGrOper: TStringField;
    PrCapQueryUNNPlatPredpr: TStringField;
    PrCapQueryOKPOPlatPredpr: TStringField;
    PrCapQueryUNNPlatSkl: TStringField;
    PrCapQueryOKPOPlatSkl: TStringField;
    PrCapQueryLICPlatPred: TStringField;
    PrCapQueryLICPlatSkl: TStringField;
    PrCapQueryNamePredpr: TStringField;
    PrCapQueryNameSkl: TStringField;
    PrCapQueryStHoFlSkl: TStringField;
    PrCapQueryNamePlatPredpr: TStringField;
    PrCapQueryRschetPlatPredpr: TStringField;
    PrCapQueryKodMFOPlatPredpr: TStringField;
    PrCapQueryBankPlatPredpr: TStringField;
    PrCapQueryTownBankPredpr: TStringField;
    PrCapQueryRSchetPlatSkl: TStringField;
    PrCapQueryKodMFOPlatSkl: TStringField;
    PrCapQueryBankPlatSkl: TStringField;
    PrCapQueryTownBankSkl: TStringField;
    PrCapQueryTownPredpr: TStringField;
    PrCapQueryStHoFlPredpr: TStringField;
    PrCapQueryTownPlatPredpr: TStringField;
    PrCapQueryStHoFlPlatPredpr: TStringField;
    PrCapQueryPhonePlatPredpr: TStringField;
    PrCapQueryFaxPlatPredpr: TStringField;
    PrCapQueryNamePlatSkl: TStringField;
    PrCapQueryFIODir: TStringField;
    PrCapQueryTownPlatSkl: TStringField;
    PrCapQueryStHoFlPlatSkl: TStringField;
    PrCapQueryPhonePlatSkl: TStringField;
    PrCapQueryFaxPlatSkl: TStringField;
    PrCapQueryDogovor: TStringField;
    PrCapQueryCelPriobr: TStringField;
    PrCapQueryFioMol: TStringField;
    PrCapQueryProfMol: TStringField;
    PrCapQueryDover: TStringField;
    PrCapQueryPutList: TStringField;
    PrCapQueryVoditel: TStringField;
    PrCapQueryMarkAvto: TStringField;
    PrCapQueryOwnAvto: TStringField;
    PrCapQueryNomAvto: TStringField;
    PrCapQuerySumNDS: TBCDField;
    PrCapQuerySumIncNDS: TBCDField;
    PrCapQuerySumNac: TBCDField;
    PrCapQuerySumNacOpt: TBCDField;
    PrCapQuerySumTrn: TBCDField;
    PrCapQuerySumSkid: TBCDField;
    PrCapQueryItogo: TBCDField;
    PrCapQueryItogoTov: TBCDField;
    PrCapQueryItogoTar: TBCDField;
    PrCapQueryItogoRoz: TBCDField;
    PrCapQueryItogoOO: TBCDField;
    PrCapQueryItogoKolF: TBCDField;
    PrCapQueryItogoKolM: TBCDField;
    PrCapQueryItogoMas: TBCDField;
    PrCapQueryItogoKolKzp: TBCDField;
    PrCapQueryPrSumNds: TStringField;
    PrCapQueryPrVsego: TStringField;
    PrCapQueryItogoKolTov: TBCDField;
    PrCapQuerySert: TStringField;
    PrCapQueryItogoNaim: TSmallintField;
    PrCapQueryItogoTovR: TBCDField;
    PrCapQueryItogoTarR: TBCDField;
    PrCapQuerySumOpl: TBCDField;
    PrCapQueryFIOGlBuh: TStringField;
    PrCapQueryPoluchat: TStringField;
    PrCapQueryIndexSkl: TStringField;
    PrCapQueryIndexPlatSkl: TStringField;
    PrCapQueryIndexPredpr: TStringField;
    PrCapQueryIndexPlatPredpr: TStringField;
    PrCapQueryTownSkl: TStringField;
    PrCapQueryTovar: TBCDField;
    PrCapQueryStTara: TBCDField;
    PrCapQueryTara: TBCDField;
    PrCapQuerySumNDSRozn: TBCDField;
    PrCapQuerySumSkidPokup: TBCDField;
    PrStrQuery: TQuery;
    PrStrQueryNameVidTov: TStringField;
    PrStrQueryKodGr: TSmallintField;
    PrStrQueryKodPGr: TSmallintField;
    PrStrQueryMinUp: TBCDField;
    PrStrQueryVidUp: TStringField;
    PrStrQueryArt: TStringField;
    PrStrQueryModel: TStringField;
    PrStrQuerySizes: TStringField;
    PrStrQueryHight: TStringField;
    PrStrQuerySort: TStringField;
    PrStrQuerySertif: TStringField;
    PrStrQueryFasov: TBCDField;
    PrStrQueryEdIz: TStringField;
    PrStrQueryCenO: TBCDField;
    PrStrQueryCenRoz: TBCDField;
    PrStrQueryCenSt: TBCDField;
    PrStrQueryNDS: TBCDField;
    PrStrQueryNacOpt: TBCDField;
    PrStrQueryNacRozn: TBCDField;
    PrStrQueryNacObpit: TBCDField;
    PrStrQuerySkidPokup: TBCDField;
    PrStrQueryNacPosr: TBCDField;
    PrStrQuerySkidPost: TBCDField;
    PrStrQueryNalTr: TBCDField;
    PrStrQueryNalProd: TBCDField;
    PrStrQueryKolF: TBCDField;
    PrStrQueryKolm: TSmallintField;
    PrStrQuerySumNDS: TBCDField;
    PrStrQuerySumNDSR: TBCDField;
    PrStrQueryPrRazl: TStringField;
    PrStrQueryCenPor: TBCDField;
    PrStrQueryCenPriobr: TBCDField;
    PrStrQueryNamePredpr: TStringField;
    PrStrQueryNameCountry: TStringField;
    PrStrQueryKolPor: TBCDField;
    PrStrQueryProtkl: TStringField;
    PrStrQuerySertif1: TStringField;
    PrStrQuerySertif2: TStringField;
    forVsegoSNDS_1: TCheckBox;
    forVesTrEdit: TEdit;
    forTTNEdit: TEdit;
    forNumDoc: TEdit;
    forSeria: TEdit;
    forPogr: TEdit;
    forRazg: TEdit;
    forVidPer: TEdit;
    forPrim: TEdit;
    forStoimost: TCheckBox;
    forStoimost2_1: TCheckBox;
    forStoimost2_2: TCheckBox;
    forCheckNastrGrTov: TCheckBox;
    forPr_CenPriobr: TCheckBox;
    forPr_CenTr: TCheckBox;
    forPr_ProcTr: TCheckBox;
    forPr_CenWNal: TCheckBox;
    forPRAll: TEdit;
    forIdDoc: TEdit;
    PrStrQueryIdDoc: TIntegerField;
    PrStrQueryVes: TBCDField;
    PrStrQueryIdPrizLog: TSmallintField;
    forOtpRaz: TEdit;
    forReturnTypeTrPredpr: TCheckBox;
    PrCapQueryDateOtgr: TDateTimeField;
    PrCapQueryOtpRaz: TStringField;
    PrCapQueryNdsBns: TBCDField;
    PrCapQuerySumBns: TBCDField;
    PrCapQuerySumNdsBonus: TBCDField;
    SumBnsQuery: TQuery;
    frxDBDataset1: TfrxDBDataset;
    forFace3: TCheckBox;
    PrCapQueryNameF3Predpr: TStringField;
    PrCapQueryRschetF3Predpr: TStringField;
    PrCapQueryKodMFOF3Predpr: TStringField;
    PrCapQueryBankF3Predpr: TStringField;
    PrCapQueryTownF3Predpr: TStringField;
    PrCapQueryTownBankF3: TStringField;
    PrCapQueryUNNF3Predpr: TStringField;
    PrCapQueryOKPOF3Predpr: TStringField;
    PrCapQueryLICF3Pred: TStringField;
    PrCapQueryIndexF3Predpr: TStringField;
    PrCapQueryStHoFlF3Predpr: TStringField;
    PrCapQueryIdF3: TSmallintField;
    forDateDov: TEdit;
    forVlTr: TEdit;
    PrStrQueryPNT: TIntegerField;
    PrStrQuerypriznsyria: TStringField;
    PrStrQueryUsl: TBCDField;
    forSposPogr: TEdit;
    forSposRazgr: TEdit;
    forVrPrib: TEdit;
    forVrUb: TEdit;
    forVrProst: TEdit;
    forMOLGruzPoluch: TEdit;
    forNomPric: TEdit;
    PrStrQueryKolKzp: TBCDField;
    PrStrQueryEdIzDop: TStringField;
    PrStrQuerySkidOv: TBCDField;
    PrStrQueryKolOv: TBCDField;
    PrStrQueryKolZ: TBCDField;
    mdb: TDatabase;
    PrStrQueryPNTTar1: TIntegerField;
    PrStrQueryPNTTar3: TIntegerField;
    frxDesigner1: TfrxDesigner;
    NameGrPrQuery: TQuery;
    PrCapQueryProfMol1: TStringField;
    PrStrQueryprLogBKS: TSmallintField;
    PrCapQuerySumNacRozn: TBCDField;
    PrCapQuerySumNacObpit: TBCDField;
    PrCapQueryTovarOO: TBCDField;
    FioDovQuery: TQuery;
    FioDovQueryFio: TStringField;
    frxReport2: TfrxReport;
    frxReport1: TfrxReport;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    function Propis(S:Currency;KK:integer):string;
    function Num(Q:string;X:integer):string;
    function PROPER(S: string): string;
    procedure Run();

  private
    NalProdEd: string;
    { Private declarations }
  public
      { Public declarations }
     function Rounding(Value:Currency):Currency; // Округление до сотых Суховаров А.А.
  end;

var
  NaklForm: TNaklForm;
  {PRAll,}PrSumNds,PrVsego,PrSmall,Exsp: String;
  //===4===//
  {Memo4_1, Memo4_3, Memo4_2, Memo4_4,} Cen4_1, Cen4_2 : TfrxMemoView;
  //===5===//
//  Memo5_1, Memo5_3, Memo5_2, Memo5_4 : TfrxMemoView;
  //===6===//
  Memo6_3, Memo6_1, Memo6_4, Memo6_2, Sum6 : TfrxMemoView;
  //=== For other===//
  NumberTTN, Seria, SeriaSecondPage, Pogr, Razgr, PriborMemo{VidPerevoz,}, SumNDS_1,
  {SumNDS_2,} VsegoSNDS_3, VsegoSNDS_1, VsegoSNDS_2, Mest, MassaBrutto,
  NumNakl, Memo389, Memo388, Memo1,
  Memo338, Itog, KolProd, Stoimost, Stoimost2, {Stoimost3,} DataDoc,
  SummNDS, VsSNDS, KolGrMest, MassBrutt, Zakazchik,
  Memo94, Memo93, Primechanie, UNN_1 : TfrxMemoView;
  //=== Дополнительно ===//
  NamePredpr, NalProd, Memo59, Memo88, Memo89, Memo92, Memo92_2, Memo32, Memo33, Memo149, Memo159,
  {Memo95,} Memo96, Memo300, Memo336, SumSumNDS, Memo287, Memo35 : TfrxMemoView;
  //=== Суммы ===//
  SumTov, SumTar, SumStTar, SumTovRozn, SumTarRozn, SumVsSNds : TfrxMemoView;
  Memo3, Memo4, Memo5, Memo6, Memo7, Memo118, Memo28, Memo151, Memo161, Memo152, Memo153, Memo154, Memo291, Memo292, Memo8,
  Memo51, Memo34, Memo57 : TfrxMemoView;

  MasterData1 : TfrxMasterData;
  DetailData1 : TfrxDetailData;
  VssndsInt, i, IdCheckNastrGrTov : integer;
  S : Currency;
  VssndsFloat:Currency;
implementation

uses Math;

{$R *.dfm}

var DllApp : TApplication;

procedure TNaklForm.Run();
var StText, StText2, SumNdsText, VsSNdsText,qwert : String;
kolstr,kolline,kolitog,i,a,z : integer;
GrPr : integer;
begin
//NaklForm.Visible:=false;
//NaklForm.Hide;

if forPRAll.Text='' then
begin
PrCapQuery.Active:=False;
PrCapQuery.ParamByName('IdDoc').Value:=StrToInt(forIdDoc.Text); // SklDM.DocQuery.FieldByName('IdDoc').Value;
PrCapQuery.Active:=True;
end;
with PrCapQuery do
begin
Close;
SQL.Clear;
PrCapQuery.Sql.Add('SELECT PrintCaption.* ,DocCaption.Tovar,DocCaption.StTara,DocCaption.Tara,DocCaption.SumNDSRozn,');
PrCapQuery.Sql.Add(' DocCaption.SumBns,DocCaption.SumNdsBonus,');
PrCapQuery.Sql.Add('(DocCaption.SumSkidPokup9+DocCaption.SumSkidPokup16) as SumSkidPokup, ');
PrCapQuery.Sql.Add('DocCaption.SumNacRozn,DocCaption.SumNacObpit,DocCaption.TovarOO ');
PrCapQuery.Sql.Add(' from PrintCaption,DocCaption where PrintCaption.IdDoc=DocCaption.IdDoc and PrintCaption.IdDoc= '+forIdDoc.Text);
//IntToStr(SklDm.DocQuery.FieldByName('IdDoc').Value));
Open;
end;
with PrstrQuery do
begin
ParamByName('IdDoc').Value:=StrToInt(forIdDoc.Text); //SklDm.DocQuery.FieldByName('idDoc').Value;
Open;
end;

NameGrPrQuery.Active:=False;
NameGrPrQuery.ParamByName('IdDoc').Value:=forIdDoc.Text;
NameGrPrQuery.Active:=True;
if (NameGrPrQuery.FieldByName('NameGrPredpr').AsString)='райпо' then
Grpr:=1
else
GrPr:=0;
SumBnsQuery.Active:=False;
SumBnsQuery.ParamByName('IdDoc').Value:=forIdDoc.Text;
SumBnsQuery.Active:=True;
//===================//
//=== Вывод отчёта===//
//===================//

frxReport1.PrepareReport(true);
frxReport2.PrepareReport(true);

frxReport1.Modified:=True;
frxReport2.Modified:=True;

//=====================//
//=== 1-ая страница ===//
//=====================//

Memo149 := frxReport1.FindObject('Memo149') as TfrxMemoView;
Memo149.Text:='[frxDatasetPrCap."NameSkl"]';
Memo159 := frxReport1.FindObject('Memo159') as TfrxMemoView;
Memo159.Text:='[frxDatasetPrCap."NamePredpr"]';

Memo287 := frxReport1.FindObject('Memo287') as TfrxMemoView;
Memo287.Text:=forOtpRaz.Text;

Zakazchik := frxReport1.FindObject('Zakazchik') as TfrxMemoView;

if TrCheckBox.Checked
  then frxReport1.Variables['IdTrCheck']:=QuotedStr('1')
  else frxReport1.Variables['IdTrCheck']:=QuotedStr('0');

if forFace3.Checked
  then frxReport1.Variables['IdF3Check']:=QuotedStr('1')
  else frxReport1.Variables['IdF3Check']:=QuotedStr('0');

Memo151 := frxReport1.FindObject('Memo151') as TfrxMemoView;
Memo151.Text:=forSposPogr.Text;

Memo161 := frxReport1.FindObject('Memo161') as TfrxMemoView;
Memo161.Text:=forSposRazgr.Text;

Memo152 := frxReport1.FindObject('Memo152') as TfrxMemoView;
Memo152.Text:=forVrPrib.Text;

Memo153 := frxReport1.FindObject('Memo153') as TfrxMemoView;
Memo153.Text:=forVrUb.Text;

Memo154 := frxReport1.FindObject('Memo154') as TfrxMemoView;
Memo154.Text:=forVrProst.Text;

Memo8 := frxReport1.FindObject('Memo8') as TfrxMemoView;
Memo8.Text:=forNomPric.Text;

Memo291 := frxReport1.FindObject('Memo291') as TfrxMemoView;
if forMOLGruzPoluch.Text<>''
  then Memo291.Text:='[frxDatasetPrCap."ProfMol1"]'+ forMOLGruzPoluch.Text
  else Memo291.Text:='[frxDatasetPrCap."Poluchat"]';

Memo292 := frxReport1.FindObject('Memo292') as TfrxMemoView;
Memo118 := frxReport1.FindObject('Memo118') as TfrxMemoView;
if PrCapQuery.FieldByName('Dover').IsNull
  then begin
       Memo292.Text:='';
       Memo118.Text:='';
       end
  else
  begin
//  showmessage('KKKK');
 with FioDovQuery do
 begin
 ParamByName('IdPredpr').Value:= PrCapQuery.FieldByName('idpredpr').Value;
 ExecSql;
 open;
 end;
 If FioDovquery.RecordCount=1 then
 Memo118.Text:=' от '+forDateDov.Text+'г. выданной '+PrCapQuery.FieldByName('NamePlatPredpr').AsString+'  '+FioDovQuery.FieldByName('Fio').AsString
 else
 Memo118.Text:=' от '+forDateDov.Text+'г. выданной '+PrCapQuery.FieldByName('NamePlatPredpr').AsString;
      //  frxReport1.Variables['DateDov']:=QuotedStr(forDateDov.Text);
 end;
Memo28 := frxReport1.FindObject('Memo28') as  TfrxMemoView;
if forFace3.Checked=False
  then begin
       if TrCheckBox.Checked=True
          then Memo28.Text:='Грузополучатель'
          else Memo28.Text:='Грузоотправитель'
       end
  else
    Memo28.Text:=forVlTr.Text;
//    Memo28.Text:='';

if TrCheckBox.Checked then
begin
Zakazchik.Text:=PrCapQuery.FieldByName('NamePlatPredpr').Value+
', '+PrCapQuery.FieldByName('IndexPlatPredpr').Value+' '+PrCapQuery.FieldByName('TownPlatPredpr').Value +', '+ PrCapQuery.FieldByName('StHoFlPlatPredpr').Value+' ;';
end
else
begin
if forFace3.Checked then
begin
Zakazchik.Text:=PrCapQuery.FieldByName('NameF3Predpr').Value+
', '+PrCapQuery.FieldByName('IndexF3Predpr').Value+' '+PrCapQuery.FieldByName('TownF3Predpr').Value +', '+ PrCapQuery.FieldByName('StHoFlF3Predpr').Value+' ;';
end
else
begin
Zakazchik.Text:=PrCapQuery.FieldByName('NamePlatSkl').Value+
', '+PrCapQuery.FieldByName('IndexPlatSkl').Value+' '+PrCapQuery.FieldByName('TownPlatSkl').Value +',  ' + PrCapQuery.FieldByName('StHoFlPlatSkl').Value+' ;';
end;
end;

if forFace3.Checked=False
  then Zakazchik.Text:='';

SumNDS_1 := frxReport1.FindObject('SumNDS_1') as TfrxMemoView;

if forSumNDS_1.Checked=False then
SumNDS_1.Text:='[<frxDatasetPrCap."SumIncNDS">+<frxDatasetPrCap."SumNDSRozn">]'
else SumNDS_1.Text:='[<frxDatasetPrCap."SumIncNDS">+<frxDatasetPrCap."SumNDS">]';

SumNDS_1.GetData;
SumNDS_1.Value:=SumNDS_1.Value+PrCapQuery.FieldByName('SumNdsBonus').Value;
if SumNDS_1.Text<>'0' then
begin
S:=SumNDS_1.Value;
SumNDS_1.Memo.Text:=PROPER(Propis(S,0))+'   '
+Copy(SumNDS_1.Text, Pos(',', SumNDS_1.Text)+1, 2)+' коп.';
//SumNDS_1.Memo.Text:=AnsiUpperCase(Copy(Propis(S,0),1,1))+Copy(Propis(S,0),2,Length(Propis(S,0))-1);
//SumNDS_1.Memo.Text:=Propis(S,0);
//SumNDS_1.Memo.Text:=Copy(SumNDS_1.Memo.Text,1,45);
end
else
SumNDS_1.Memo.Text:='';
//end;

{SumNDS_2 := frxReport1.FindObject('SumNDS_2') as TfrxMemoView;
if forSumNDS_1.Checked=False then
SumNDS_2.Text:='[<frxDatasetPrCap."SumIncNDS">+<frxDatasetPrCap."SumNDSRozn">]'
else SumNDS_2.Text:='[<frxDatasetPrCap."SumIncNDS">+<frxDatasetPrCap."SumNDS">]';

SumNDS_2.GetData;
SumNDS_2.Value:=SumNDS_2.Value+PrCapQuery.FieldByName('SumNdsBonus').Value;
if SumNDS_2.Memo.Text<>'0' then
begin
S:=SumNDS_2.Value;
SumNDS_2.Memo.Text:=Propis(S,0);
SumNDS_2.Memo.Text:=Copy(SumNDS_2.Memo.Text,46,75);
end
else
SumNDS_2.Memo.Text:='';}

//--------------------//

//-------------------//
VsegoSNDS_1 := frxReport1.FindObject('VsegoSNDS_1') as TfrxMemoView;
VsegoSNDS_1.GetData;
if VsegoSNDS_1.Memo.Text<>'0' then
begin
{VsegoSNDS_1.Value:=VsegoSNDS_1.Value+PrCapQuery.FieldByName('SumBns').Value;
   if forVsegoSNDS_1.Checked=True then
 VsegoSNDS_1.Value:=PrCapQuery.FieldByName('ItogoRoz').Value ;}
// S:=VsegoSNDS_1.Value;
if forStoimost2_1.Checked=False
       then begin
            if forSumNDS_1.Checked=True then VsegoSNDS_1.Value:=PrCapQuery.FieldByName('Itogo').AsFloat+PrCapQuery.FieldByName('SumNDS').AsFloat+SumBnsQuery.FieldByName('sumbns').AsFloat
                                        else VsegoSNDS_1.Value:=PrCapQuery.FieldByName('ItogoRoz').AsFloat
            end
       else begin
            if forSumNDS_1.Checked=True then VsegoSNDS_1.Value:=PrCapQuery.FieldByName('ItogoOO').AsFloat+PrCapQuery.FieldByName('SumNDS').AsFloat
                                        else VsegoSNDS_1.Value:=PrCapQuery.FieldByName('ItogoRoz').AsFloat
            end;
 S := VsegoSNDS_1.Value;
 VsegoSNDS_1.Memo.Text:=PROPER(Propis(S,0))+'   '
+Copy(FloatToStrF(S,ffNumber,12,2), Pos(',', FloatToStrF(S,ffNumber,12,2))+1, 2)+' коп.';
// VsegoSNDS_1.Memo.Text:=Copy(VsegoSNDS_1.Memo.Text,1,26);
end
else
VsegoSNDS_1.Memo.Text:='';
{
VsegoSNDS_2 := frxReport1.FindObject('VsegoSNDS_2') as TfrxMemoView;
VsegoSNDS_2.GetData;
if VsegoSNDS_2.Memo.Text<>'0' then
begin
{VsegoSNDS_2.Value:=VsegoSNDS_2.Value+PrCapQuery.FieldByName('SumBns').Value;
   if forVsegoSNDS_1.Checked=True then
 VsegoSNDS_2.Value:=PrCapQuery.FieldByName('ItogoRoz').Value;}
//S:=VsegoSNDS_2.Value;
{if forStoimost2_1.Checked=False
       then begin
            if forSumNDS_1.Checked=True then VsegoSNDS_2.Value:=PrCapQuery.FieldByName('Itogo').AsFloat+PrCapQuery.FieldByName('SumNDS').AsFloat+SumBnsQuery.FieldByName('sumbns').AsFloat
                                        else VsegoSNDS_2.Value:=PrCapQuery.FieldByName('ItogoRoz').AsFloat
            end
       else begin
            if forSumNDS_1.Checked=True then VsegoSNDS_2.Value:=PrCapQuery.FieldByName('ItogoOO').AsFloat+PrCapQuery.FieldByName('SumNDS').AsFloat
                                        else VsegoSNDS_2.Value:=PrCapQuery.FieldByName('ItogoRoz').AsFloat
            end;
s:=StrToFloat(IntToStr(Round(VsegoSNDS_2.Value)));
VsegoSNDS_2.Memo.Text:=Propis(S,0);
VsegoSNDS_2.Memo.Text:=Copy(VsegoSNDS_2.Memo.Text,27,75);
end
else
VsegoSNDS_2.Memo.Text:='';

VsegoSNDS_3 := frxReport1.FindObject('VsegoSNDS_3') as TfrxMemoView;
VsegoSNDS_3.GetData;
if VsegoSNDS_3.Memo.Text<>'0' then
begin
{VsegoSNDS_3.Value:=VsegoSNDS_3.Value+PrCapQuery.FieldByName('SumBns').Value;
if forVsegoSNDS_1.Checked=True then
 VsegoSNDS_3.Value:=PrCapQuery.FieldByName('ItogoRoz').Value;}
//S:=VsegoSNDS_3.Value;
{if forStoimost2_1.Checked=False
       then begin
            if forSumNDS_1.Checked=True then VsegoSNDS_3.Value:=PrCapQuery.FieldByName('Itogo').AsFloat+PrCapQuery.FieldByName('SumNDS').AsFloat+SumBnsQuery.FieldByName('sumbns').AsFloat
                                        else VsegoSNDS_3.Value:=PrCapQuery.FieldByName('ItogoRoz').AsFloat
            end
       else begin
            if forSumNDS_1.Checked=True then VsegoSNDS_3.Value:=PrCapQuery.FieldByName('ItogoOO').AsFloat+PrCapQuery.FieldByName('SumNDS').AsFloat
                                        else VsegoSNDS_3.Value:=PrCapQuery.FieldByName('ItogoRoz').AsFloat
            end;
s:=StrToFloat(IntToStr(Round(VsegoSNDS_3.Value)));
VsegoSNDS_3.Memo.Text:=Propis(S,0);
VsegoSNDS_3.Memo.Text:=Copy(VsegoSNDS_3.Memo.Text,76,100);
end
else
VsegoSNDS_3.Memo.Text:=''; }

//-------------------//

Mest := frxReport1.FindObject('Mest') as TfrxMemoView;
Mest.GetData;
if Mest.Memo.Text<>'0' then
begin
S:=Mest.Value;
Mest.Memo.Text:=Propis(S,2);
end
else
Mest.Memo.Text:='';

//-------------------//

MassaBrutto := frxReport1.FindObject('MassaBrutto') as TfrxMemoView;
MassaBrutto.GetData;
If (forPRAll.Text<>' ') and (forVesTrEdit.Text<>'') then
MassaBrutto.Memo.Text:=FloatToStr(StrToFloat(MassaBrutto.Memo.Text)+StrToFloat(forVesTrEdit.Text));
if MassaBrutto.Memo.Text<>'0' then
begin
S:=MassaBrutto.Value;
MassaBrutto.Memo.Text:=Propis(S,1);
end
else
MassaBrutto.Memo.Text:='';

//-------------------//

Memo338 := frxReport1.FindObject('Memo338') as TfrxMemoView;
Memo338.GetData;
if NalProdEd<>'' then
Memo338.Memo.Text:=FloatToStr(Rounding(StrToFloat( NalProdEd )*PrStrQuery.FieldByName('KolF').Value));
if Memo338.Memo.Text='0' then
Memo338.Memo.Text:='';

//-------------------//

UNN_1 := frxReport1.FindObject('UNN_1') as TfrxMemoView;
if TrCheckBox.Checked then
UNN_1.Text:=PrCapQuery.FieldByName('UNNPlatPredpr').Value
else
begin
if forFace3.Checked then
UNN_1.Text:=PrCapQuery.FieldByName('UNNF3Predpr').Value
else
UNN_1.Text:=PrCapQuery.FieldByName('UNNPlatSkl').Value;
end;

//=== Если введён номер ТТН===//
NumberTTN := frxReport1.FindObject('NumberTTN') as TfrxMemoView;
If forPRAll.Text<>' ' then NumberTTN.Text:=forTTNEdit.Text
else NumberTTN.Text:=forNumDoc.Text;
//=== Если введёна серия===//
Seria := frxReport1.FindObject('Seria') as TfrxMemoView;
if forSeria.Text<>'' then Seria.Memo.Text:=forSeria.Text;
//=== Если введён пункт погрузки===//
Pogr := frxReport1.FindObject('Pogr') as TfrxMemoView;
if (forPogr.Text='') or (forPogr.Text=' ') or (forPogr.Text='  ') or (forPogr.Text='   ')
    then Pogr.Text:=PrCapQuery.FieldByName('TownSkl').Value+', '+PrCapQuery.FieldByName('StHoFlSkl').Value
    else Pogr.Memo.Text:=forPogr.Text;
//=== Если введён пункт разгрузки===//
Razgr := frxReport1.FindObject('Razgr') as TfrxMemoView;
if (forRazg.Text='') or (forRazg.Text=' ') or (forRazg.Text='  ') or (forRazg.Text='   ')
    then Razgr.Text:=PrCapQuery.FieldByName('TownPredpr').Value+', '+PrCapQuery.FieldByName('StHoFlPredpr').Value
    else Razgr.Memo.Text:=forRazg.Text;
//=== Если введён вид перевозки===//
PriborMemo := frxReport1.FindObject('PriborMemo') as TfrxMemoView;
if forVidPer.Text<>'' then PriborMemo.Memo.Text:='Подлинность акцизной марки (специального знака) проверено комиссионно прибором '+forVidPer.Text;
{VidPerevoz := frxReport1.FindObject('VidPerevoz') as TfrxMemoView;
if forVidPer.Text<>'' then VidPerevoz.Memo.Text:=forVidPer.Text;}
//=== Если введено примечание===//
Primechanie := frxReport1.FindObject('Primechanie') as TfrxMemoView;
if forPrim.Text<>'' then Primechanie.Memo.Text:=forPrim.Text;

//==================================//

Itog := frxReport1.FindObject('Itog') as TfrxMemoView;
if forPRAll.Text<>'*' then
Itog.Memo.Text:='Итого :'
else
Itog.Memo.Text:='Итого загружено :';


KolProd := frxReport1.FindObject('KolProd') as TfrxMemoView;
KolProd.GetData;
if KolProd.Value='0' then
  KolProd.Memo.Text:='';

Stoimost := frxReport1.FindObject('Stoimost') as TfrxMemoView;
//Stoimost.Text:='[frxDatasetPrCap."ItogoOO"]';
Stoimost.GetData;
if forStoimost2_1.Checked=False then
begin
   if forSumNDS_1.Checked then
      Stoimost.Text:=FloatToStr(PrCapQuery.FieldByName('Itogo').AsFloat+SumBnsQuery.FieldByName('sumbns').AsFloat)
   else Stoimost.Text:=FloatToStr(PrCapQuery.FieldByName('ItogoRoz').AsFloat)
end
else
begin
   if forSumNDS_1.Checked then
      Stoimost.Text:=FloatToStr(PrCapQuery.FieldByName('ItogoOO').AsFloat)
   else Stoimost.Text:=FloatToStr(PrCapQuery.FieldByName('ItogoRoz').AsFloat)
end;
{if forPRAll.Text<>'*' then
begin
if Stoimost.Value<>0 then
begin
Stoimost.Value:=Stoimost.Value+PrCapQuery.FieldByName('SumBns').Value;
Stoimost.Text:=FloatToStr(Round(StrToFloat(Stoimost.Value)));
end;
if forStoimost.Checked=False then
  begin
   Stoimost.Value:='';
   Stoimost.Text:='';
  end;
if (Stoimost.Text='0') or (Stoimost.Text='') then
  Stoimost.Text:='';
end
else
 Stoimost.Text:='';

if forVsegoSNDS_1.Checked=True then Stoimost.Text:='';}

//StText:=Stoimost.Text;

Stoimost2 := frxReport1.FindObject('Stoimost2') as TfrxMemoView;
//Stoimost2.Text:='[IIF(<frxDatasetPrCap."Itogo"><><frxDatasetPrCap."ItogoOO">,<frxDatasetPrCap."ItogoOO">,<frxDatasetPrCap."ItogoRoz">)]';
if (forSumNDS_1.Checked=True) and (forStoimost2_2.Checked=True) then Stoimost2.Text:=FloatToStr(Rounding(PrCapQuery.FieldByName('ItogoRoz').AsFloat));
Stoimost2.GetData;
{if (forPRAll.Text<>' ') and (Stoimost2.Value='0') then
Stoimost2.Text := ' ';
if forPRAll.Text<>'*' then
begin
if Stoimost2.Value<>0 then
begin
Stoimost2.Value:=Stoimost2.Value+PrCapQuery.FieldByName('SumBns').Value;
Stoimost2.Value:=FloatToStr(Round(StrToFloat(Stoimost2.Value)));
end;
// для расчета цен от опт.-зак.(CenO) при отсутст. в настройках "птицы"
if forStoimost2_1.Checked=False then
 Stoimost2.Text:=PrCapQuery.FieldByName('ItogoRoz').Value;
//конец
if(PrStrQuery.FieldByName('CenPriobr').Value=0)
 and(forStoimost2_2.Checked=False) then
  begin
   Stoimost2.Text:='';
   Stoimost2.Value:='0';
  end;
if Stoimost2.Value='0' then
  Stoimost2.Text:='';
end;}

//  then Stoimost2.Text:=PrStrQuery.fieldbyname('Itogo').Value;


{ if Stoimost2.Text <> '' then
  Stoimost2.Text := FloatToStr(Round(StrToFloat(Stoimost2.Value)));}

StText2 := Stoimost2.Text;

//Stoimost3 := frxReport1.FindObject('Stoimost3') as TfrxMemoView;
//Stoimost3.Text:='';
{if (<frxDatasetPrStr."CenPriobr"><>0) and (<Pr_SchCenPriobr>='1')
       then Stoimost3.Text:=FloatToStr(<frxDatasetPrCap."TovarOO">);}
//Stoimost3.GetData;
{ if (forPRAll.Text<>' ') and (Stoimost3.Value='0') then
  Stoimost3.Text := ' ';}
{ if forStoimost2_1.Checked=False then
  Stoimost3.Text:=' ';}
{ if forStoimost2_2.Checked=False then
  Stoimost3.Text:=' ';
if Stoimost3.Value='0' then
  Stoimost3.Text:=' ';}

SummNDS := frxReport1.FindObject('SummNDS') as TfrxMemoView;
if forSumNDS_1.Checked=False then
SummNDS.Text:='[<frxDatasetPrCap."SumIncNDS">+<frxDatasetPrCap."SumNDSRozn">]'
else SummNDS.Text:='[<frxDatasetPrCap."SumIncNDS">+<frxDatasetPrCap."SumNDS">]';

SummNDS.GetData;
if forPRAll.Text<>'*' then
begin
//if SummNDS.Value<>0 then
//begin
SummNDS.Value:=SummNDS.Value+PrCapQuery.FieldByName('SumNdsBonus').Value;
SummNDS.Value:=FloatToStr(Rounding(StrToFloat(SummNDS.Value)));
//end;
if SummNDS.Text<>' ' then
SummNDS.Text:=FloatToStr(Rounding(StrToFloat(SummNDS.Value)));
if SummNDS.Text='0' then
 SummNDS.Text:='';
end
else
 SummNDS.Value:='';

SumNdsText := SummNDS.Text;

Memo51 := frxReport1.FindObject('Memo51') as TfrxMemoView;
if forSumNDS_1.Checked=False then
Memo51.Text:='[frxDatasetPrCap."SumNDSRozn"]'
else Memo51.Text:='[frxDatasetPrCap."SumNDS"]';

Memo57 := frxReport1.FindObject('Memo57') as TfrxMemoView;
Memo57.Text:='[frxDatasetPrCap."SumSkid"]';

VsSNDS := frxReport1.FindObject('VsSNDS') as TfrxMemoView;
if forStoimost2_1.Checked then
   if forSumNDS_1.Checked=True then
      VsSNDS.Text:=FloatToStr(PrCapQuery.FieldByName('ItogoOO').AsFloat+PrCapQuery.FieldByName('SumNDS').AsFloat)
   else
      VsSNDS.Text:=FloatToStr(PrCapQuery.FieldByName('ItogoRoz').AsFloat)
else
   if forSumNDS_1.Checked=True then
      VsSNDS.Text:=FloatToStr(PrCapQuery.FieldByName('Itogo').AsFloat+PrCapQuery.FieldByName('SumNDS').AsFloat+SumBnsQuery.FieldByName('sumbns').AsFloat)
   else
      VsSNDS.Text:=FloatToStr(PrCapQuery.FieldByName('ItogoRoz').AsFloat);
VsSNdsText := VsSNDS.Text;
KolGrMest := frxReport1.FindObject('KolGrMest') as TfrxMemoView;
KolGrMest.GetData;
//=== Kol-vo naimenovaniy ===//
Memo92 := frxReport1.FindObject('Memo92') as TfrxMemoView;
Memo1 := frxReport2.FindObject('Memo1') as TfrxMemoView;
Memo1.Text:='[Line]';
Memo1.GetData;
//showmessage(Memo1.Value);
Memo92.Text:=Memo1.Value;
kolline:=Memo1.Value;
Memo1.Text:='[Line]';

//=== Kol-vo stranic ===//
//Memo389 := frxReport1.FindObject('Memo389') as TfrxMemoView;
{Memo35:= frxReport2.FindObject('Memo35') as TfrxMemoView;
Memo35.Text:='[<TotalPages#>]';
Memo35.GetData;
Memo389.Text:=Memo35.Value;
Memo35.Text:='[<TotalPages#>]';  }

{Memo35:= frxReport2.FindObject('Memo391') as TfrxMemoView;
Memo35.Text:='[<Page#>]';
Memo35.GetData;
Memo389.Text:=Memo35.Value;
Memo35.Text:='[<Page#>]';  }
kolstr:=kolline div 11;
if kolline mod 11=0 then kolstr:=kolline div 11
else kolstr:=(kolline div 11)+1;
Memo389 := frxReport1.FindObject('Memo389') as TfrxMemoView;
Memo389.Text:=IntToStr(kolstr);

MassBrutt := frxReport1.FindObject('MassBrutt') as TfrxMemoView;
MassBrutt.GetData;
If (forPRAll.Text<>' ') and (forVesTrEdit.Text<>'') then
begin
if MassBrutt.Value<>'' then
MassBrutt.Value:=FloatToStr(StrToFloat(MassBrutt.Value)+StrToFloat(forVesTrEdit.Text))
else
MassBrutt.Value:=forVesTrEdit.Text;
end;

//============//
//=== Суммы===//
//============//
SumTov := frxReport1.FindObject('SumTov') as TfrxMemoView;
if forPRAll.Text='*' then
SumTov.Text:='';
{If forReturnTypeTrPredpr.Checked=True then
SumTov.Text:='[<frxDatasetPrCap."ItogoTov">+<frxDatasetPrCap."SumTrn">]'
else}
SumTov.Text:='[frxDatasetPrCap."ItogoTov"]';
SumTov.GetData;
if SumTov.Value='0' then
  SumTov.Text:='';

SumTar := frxReport1.FindObject('SumTar') as TfrxMemoView;
SumTar.GetData;
if forPRAll.Text='*' then
SumTar.Text:='';
if SumTar.Value='0' then
  SumTar.Text:='';

SumStTar := frxReport1.FindObject('SumStTar') as TfrxMemoView;
SumStTar.GetData;
if forPRAll.Text='*' then
SumStTar.Text:='';
if SumStTar.Value='0' then
  SumStTar.Text:='';

SumTovRozn := frxReport1.FindObject('SumTovRozn') as TfrxMemoView;
SumTovRozn.GetData;
if forPRAll.Text='*' then
SumTovRozn.Text:='';
if SumTovRozn.Value='0' then
  SumTovRozn.Text:='';
 if SumTovRozn.Value <> 0 then
 begin
 if forStoimost2_2.Checked=True
     then
       SumTovRozn.Value := SumTovRozn.Value
     else
       SumTovRozn.Text:='';
 end;

SumTarRozn := frxReport1.FindObject('SumTarRozn') as TfrxMemoView;
//SumTarRozn.GetData;
if forPRAll.Text='*' then
SumTarRozn.Text:='';
if SumTarRozn.Value='0' then
  SumTarRozn.Text:='';
 if SumTarRozn.Value <> '' then
 begin
 if forStoimost2_2.Checked=True
   then
    SumTarRozn.Value := SumTarRozn.Value
   else
    SumTarRozn.Text:='';
 end;

//===================//
//=== Конец: Суммы===//
//===================//

//============================//
//=== Конец: 1-ая страница ===//
//============================//

frxReport1.ShowReport(true);

//=====================//
//=== 2-ая страница ===//
//=====================//
frxReport2.Variables['NameGrPr']:=GrPr;
if forReturnTypeTrPredpr.Checked=True
  then begin
       frxReport1.Variables['forTrPredpr']:=QuotedStr('1');
       frxReport2.Variables['forTrPredpr']:=QuotedStr('1');
       end
  else begin
       frxReport2.Variables['forTrPredpr']:=QuotedStr('0');
       frxReport2.Variables['forTrPredpr']:=QuotedStr('0');
       end;

if forCheckNastrGrTov.Checked
  then begin
       frxReport1.Variables['IdCheckNastrGrTov']:=QuotedStr('1');
       frxReport2.Variables['IdCheckNastrGrTov']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['IdCheckNastrGrTov']:=QuotedStr('0');
       frxReport2.Variables['IdCheckNastrGrTov']:=QuotedStr('0');
       end;

//===============================//
//=== Физический вес на овощи ===//
//===============================//
{Memo34 := frxReport2.FindObject('Memo34') as TfrxMemoView;
if PrStrQuery.FieldByName('KolZ').AsFloat<>0
then Memo34.Text:='физ. вес'+#13+'[frxDatasetPrStr."KolZ"]'
else Memo34.Text:='';   }
//======================================//
//=== Конец: Физический вес на овощи ===//
//======================================//

//==============================================//
//=== Дополнительно: заполнение мемо вручную ===//
//==============================================//
{Memo59 := frxReport2.FindObject('Memo59') as TfrxMemoView;
if PrStrQuery.FieldByName('SkidOv').AsFloat<>0
then
Memo59.Text:='[frxDatasetPrStr."NameVidTov"] [IIF((<frxDatasetPrStr."Fasov">=0) or (<frxDatasetPrStr."EdIz">='+chr(39)+'кг'+chr(39)+')'+
                                                                              ' or (<frxDatasetPrStr."EdIz">='+chr(39)+'т'+chr(39)+')'+
                                                                              ' or (<frxDatasetPrStr."EdIz">='+chr(39)+'ц'+chr(39)+'),'+chr(39)+chr(39)+',<frxDatasetPrStr."Fasov">)]'+#13+
                                                                              ' Скидка [frxDatasetPrStr."SkidOv"]%'
else
Memo59.Text:='[frxDatasetPrStr."NameVidTov"] [IIF((<frxDatasetPrStr."Fasov">=0) or (<frxDatasetPrStr."EdIz">='+chr(39)+'кг'+chr(39)+')'+
                                                                              ' or (<frxDatasetPrStr."EdIz">='+chr(39)+'т'+chr(39)+')'+
                                                                              ' or (<frxDatasetPrStr."EdIz">='+chr(39)+'ц'+chr(39)+'),'+chr(39)+chr(39)+',<frxDatasetPrStr."Fasov">)]';
}//Memo59.Text:='[frxDatasetPrStr."NameVidTov"] [IIF((<frxDatasetPrStr."Fasov">=0) or (<frxDatasetPrStr."Fasov">=1),'+chr(39)+chr(39)+',<frxDatasetPrStr."Fasov">)]';
Memo88 := frxReport2.FindObject('Memo88') as TfrxMemoView;
Memo88.Text:='[frxDatasetPrStr."EdIz"]';
//Memo89 := frxReport2.FindObject('Memo89') as TfrxMemoView;
//Memo89.Text:='[frxDatasetPrStr."KolF"]';
Memo32 := frxReport2.FindObject('Memo32') as TfrxMemoView;
Memo32.Text:='[frxDatasetPrStr."EdIzDop"]';
{Memo33 := frxReport2.FindObject('Memo33') as TfrxMemoView;
if PrStrQuery.FieldByName('KolKzp').AsFloat<>0
then Memo33.Text:='[frxDatasetPrStr."KolKzp"]';
if PrStrQuery.FieldByName('KolOv').AsFloat<>0
then Memo33.Text:='[frxDatasetPrStr."KolOv"]';  }

Memo92_2 := frxReport2.FindObject('Memo92') as TfrxMemoView;
Memo92_2.Text:='[IIF(<frxDatasetPrStr."NDS"><>0,<frxDatasetPrStr."NDS">,'+chr(39)+chr(39)+')]';
{Memo95 := frxReport2.FindObject('Memo95') as TfrxMemoView;
Memo95.Text:='[frxDatasetPrStr."VidUp"]';}
Memo96 := frxReport2.FindObject('Memo96') as TfrxMemoView;
Memo96.Text:='[IIF(<frxDatasetPrStr."KolM"><>0,<frxDatasetPrStr."KolM">,'+chr(39)+chr(39)+')]';

//ObosnCen := frxReport2.FindObject('ObosnCen') as TfrxMemoView;
//ObosnCen.Text:='[IIF(<frxDatasetPrStr."Sertif"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif">,'+chr(39)+chr(39)+')+'+chr(39)+' '+chr(39)+'+IIF(<frxDatasetPrStr."Sertif1"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif1">,'+chr(39)+chr(39)+')+'+chr(39)+' '+chr(39)+'+IIF(<frxDatasetPrStr."Sertif2"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif2">,'+chr(39)+chr(39)+')+'+chr(39)+' '+chr(39)+ '+IIF(<frxDatasetPrStr."Protkl"><>'+chr(39)+chr(39)+','+chr(39)+' Обосн. цены '+chr(39)+'+<frxDatasetPrStr."Protkl">,'+chr(39)+chr(39)+')]';
//              [IIF(<frxDatasetPrStr."Sertif"><>''                 ,<frxDatasetPrStr."Sertif">,''                 )+'                     '+IIF(<frxDatasetPrStr."Sertif1"><>'                 ',<frxDatasetPrStr."Sertif1">,'                 ')+'                     '+IIF(<frxDatasetPrStr."Sertif2"><>'                 ',<frxDatasetPrStr."Sertif2">,'                 ')+'                      '+IIF(<frxDatasetPrStr."Protkl"><>'                 ',          ' Обосн. цены '+         <frxDatasetPrStr."Protkl">,'')]

Memo300 := frxReport2.FindObject('Memo300') as TfrxMemoView;
if (forStoimost.Checked=True) and (forSumNDS_1.Checked=True) and (forPr_CenTr.Checked=True) and (forVsegoSNDS_1.Checked=False)
                              and (forStoimost2_2.Checked=False) and (forPr_ProcTr.Checked=False) and (forPr_CenWNal.Checked=False)
                              and (forStoimost2_1.Checked=False) and (forPr_CenPriobr.Checked=False)
  then Memo300.Text:='[<frxDatasetPrStr."Art">+IIF(<frxDatasetPrStr."CenPor"><>0,'+chr(39)+'ЦЕНА ЗА ПОРЦИЮ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenPor">)+'+chr(39)+' КОЛ-ВО ПОРЦИЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."KolPor">),IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."KodGr"><>15),'+chr(39)+chr(39)+',IIF(<frxDatasetPrStr."Sort">='+chr(39)+chr(39)+','+chr(39)+chr(39)+','+chr(39)+' СОРТ '+chr(39)+')+<frxDatasetPrStr."Sort">))+'+chr(39)+'  '+chr(39)+'+'
// забила 06.02.2012
//  else Memo300.Text:='[<frxDatasetPrStr."Art">+IIF(<frxDatasetPrStr."CenPor"><>0,'+chr(39)+'ЦЕНА ЗА ПОРЦИЮ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenPor">)+'+chr(39)+' КОЛ-ВО ПОРЦИЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."KolPor">),IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."KodGr"><>15),'+chr(39)+' ЦЕНА СО СТЕКЛОТАРОЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenSt">),IIF(<frxDatasetPrStr."Sort">='+chr(39)+chr(39)+','+chr(39)+chr(39)+','+chr(39)+' СОРТ '+chr(39)+')+<frxDatasetPrStr."Sort">))+'+chr(39)+'  '+chr(39)+'+';
  else Memo300.Text:='[<frxDatasetPrStr."Art">+IIF(<frxDatasetPrStr."Sort">='+chr(39)+chr(39)+','+chr(39)+chr(39)+','+chr(39)+' СОРТ '+chr(39)+'+<frxDatasetPrStr."Sort">)+'+chr(39)+'  '+chr(39)+'+ IIF(<frxDatasetPrStr."CenPor"><>0,'+chr(39)+'ЦЕНА ЗА ПОРЦИЮ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenPor">)+'+chr(39)+' КОЛ-ВО ПОРЦИЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."KolPor">),IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."PNTTAR1"><>0),'+chr(39)+' ЦЕНА СО СТЕКЛОТАРОЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenSt">),IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."PNTTar3"><>0),'+chr(39)+' ЦЕНА НАБОРА '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenSt">)+'+chr(39)+' *** '+chr(39)+','+chr(39)+chr(39)+')))+'+chr(39)+'  '+chr(39)+'+';

//убрал для Слуцка (см. ниже), чтобы печатался СОРТ и восстановил старое (см. выше) --- 26.11.2011
//    then Memo300.Text:='[IIF(<frxDatasetPrStr."Art"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Art">+'+chr(39)+' *** '+chr(39)+','+chr(39)+chr(39)+')+IIF(<frxDatasetPrStr."CenPor"><>0,'+chr(39)+'ЦЕНА ЗА ПОРЦИЮ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenPor">)+'+chr(39)+' КОЛ-ВО ПОРЦИЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."KolPor">)+'+chr(39)+' *** '+chr(39)+',IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."KodGr"><>15),'+chr(39)+chr(39)+',IIF(<frxDatasetPrStr."Sort">='+chr(39)+chr(39)+','+chr(39)+chr(39)+','+chr(39)+' СОРТ '+chr(39)+'+<frxDatasetPrStr."Sort">)))+'+chr(39)+'  '+chr(39)+'+'
//    else Memo300.Text:='[IIF(<frxDatasetPrStr."Art"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Art">+'+chr(39)+' *** '+chr(39)+','+chr(39)+chr(39)+')+IIF(<frxDatasetPrStr."CenPor"><>0,'+chr(39)+'ЦЕНА ЗА ПОРЦИЮ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenPor">)+'+chr(39)+' КОЛ-ВО ПОРЦИЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."KolPor">)+'+chr(39)+' *** '+chr(39)+',IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."PNTTar1"><>0),IIF(<frxDatasetPrStr."KodGr"><>15,'+chr(39)+' ЦЕНА СО СТЕКЛОТАРОЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenSt">)+'+chr(39)+' *** '+chr(39)+',IIF(<frxDatasetPrStr."Sort">='+chr(39)+chr(39)+','+chr(39)+chr(39)+','+chr(39)+' СОРТ '+chr(39)+'+<frxDatasetPrStr."Sort">)),IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."PNTTar3"><>0),'+chr(39)+' ЦЕНА НАБОРА '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenSt">)+'+chr(39)+' *** '+chr(39)+','+chr(39)+chr(39)+')))+'+chr(39)+'  '+chr(39)+'+';

//  then Memo300.Text:='[IIF(<frxDatasetPrStr."CenPor"><>0,'+chr(39)+'ЦЕНА ЗА ПОРЦИЮ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenPor">)+'+chr(39)+' КОЛ-ВО ПОРЦИЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."KolPor">),IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."KodGr"><>15),'+chr(39)+chr(39)+',<frxDatasetPrStr."Art">+IIF(<frxDatasetPrStr."Sort">='+chr(39)+chr(39)+','+chr(39)+chr(39)+','+chr(39)+' СОРТ '+chr(39)+')+<frxDatasetPrStr."Sort">))]'
//  else Memo300.Text:='[IIF(<frxDatasetPrStr."CenPor"><>0,'+chr(39)+'ЦЕНА ЗА ПОРЦИЮ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenPor">)+'+chr(39)+' КОЛ-ВО ПОРЦИЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."KolPor">),IIF((<frxDatasetPrStr."CenSt"><>0) and (<frxDatasetPrStr."KodGr"><>15),'+chr(39)+' ЦЕНА СО СТЕКЛОТАРОЙ '+chr(39)+'+FloatToStr(<frxDatasetPrStr."CenSt">),<frxDatasetPrStr."Art">+IIF(<frxDatasetPrStr."Sort">='+chr(39)+chr(39)+','+chr(39)+chr(39)+','+chr(39)+' СОРТ '+chr(39)+')+<frxDatasetPrStr."Sort">))]';


//Memo301 := frxReport2.FindObject('Memo301') as TfrxMemoView;
//Memo301.Text:='[IIF(<frxDatasetPrStr."Model"><>'+chr(39)+chr(39)+','+chr(39)+'Модель '+chr(39)+'+<frxDatasetPrStr."Model">,'+chr(39)+chr(39)+')+IIF(<frxDatasetPrStr."Sizes"><>'+chr(39)+chr(39)+','+chr(39)+'Размер '+chr(39)+'+<frxDatasetPrStr."Sizes">,'+chr(39)+chr(39)+')+IIF(<frxDatasetPrStr."Hight"><>'+chr(39)+chr(39)+','+chr(39)+'Рост '+chr(39)+'+<frxDatasetPrStr."Hight">,'+chr(39)+chr(39)+')]';

Memo300.Text:=Memo300.Text+'IIF(<frxDatasetPrStr."Model"><>'+chr(39)+chr(39)+','+chr(39)+' Модель '+chr(39)+'+<frxDatasetPrStr."Model">,'+chr(39)+chr(39)+')+IIF(<frxDatasetPrStr."Sizes"><>'+chr(39)+chr(39)+','+chr(39)+' Размер '+chr(39)+'+<frxDatasetPrStr."Sizes">,'+chr(39)+chr(39)+')+IIF(<frxDatasetPrStr."Hight"><>'+chr(39)+chr(39)+','+chr(39)+' Рост '+chr(39)+'+<frxDatasetPrStr."Hight">,'+chr(39)+chr(39)+')+';
Memo300.Text:=Memo300.Text+'IIF(<frxDatasetPrStr."Sertif"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif">,'+chr(39)+chr(39)+')+'+chr(39)+'  '+chr(39)+'+IIF(<frxDatasetPrStr."Sertif1"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif1">,'+chr(39)+chr(39)+')+'+chr(39)+' '+chr(39)+'+IIF(<frxDatasetPrStr."Sertif2"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif2">,'+chr(39)+chr(39)+')+'+chr(39)+' '+chr(39)+ '+IIF(<frxDatasetPrStr."Protkl"><>'+chr(39)+chr(39)+','+chr(39)+' Обосн. цены '+chr(39)+'+<frxDatasetPrStr."Protkl">,'+chr(39)+chr(39)+')]';

//Memo300.Text:=Memo300.Text+'[IIF(<frxDatasetPrStr."Model"><>'+chr(39)+chr(39)+','+chr(39)+' Модель '+chr(39)+'+<frxDatasetPrStr."Model">,'+chr(39)+chr(39)+')+IIF(<frxDatasetPrStr."Sizes"><>'+chr(39)+chr(39)+','+chr(39)+' Размер '+chr(39)+'+<frxDatasetPrStr."Sizes">,'+chr(39)+chr(39)+')+IIF(<frxDatasetPrStr."Hight"><>'+chr(39)+chr(39)+','+chr(39)+' Рост '+chr(39)+'+<frxDatasetPrStr."Hight">,'+chr(39)+chr(39)+')]';
//Memo300.Text:=Memo300.Text+'[IIF(<frxDatasetPrStr."Sertif"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif">,'+chr(39)+chr(39)+')+'+chr(39)+'  '+chr(39)+'+IIF(<frxDatasetPrStr."Sertif1"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif1">,'+chr(39)+chr(39)+')+'+chr(39)+' '+chr(39)+'+IIF(<frxDatasetPrStr."Sertif2"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."Sertif2">,'+chr(39)+chr(39)+')+'+chr(39)+' '+chr(39)+ '+IIF(<frxDatasetPrStr."Protkl"><>'+chr(39)+chr(39)+','+chr(39)+' Обосн. цены '+chr(39)+'+<frxDatasetPrStr."Protkl">,'+chr(39)+chr(39)+')]';

//Memo336 := frxReport2.FindObject('Memo336') as TfrxMemoView;
if (forStoimost.Checked=True) and (forSumNDS_1.Checked=True) and (forPr_CenTr.Checked=True) and (forVsegoSNDS_1.Checked=False)
                              and (forStoimost2_2.Checked=False) and (forPr_ProcTr.Checked=False) and (forPr_CenWNal.Checked=False)
                              and (forStoimost2_1.Checked=False) and (forPr_CenPriobr.Checked=False)
  then frxReport2.Variables['VernutTaru']:=QuotedStr('0')
  else frxReport2.Variables['VernutTaru']:=QuotedStr('1');


//=== Сумма по 9-ой колонке ===//
SumVsSNds := frxReport2.FindObject('SumVsSNds') as TfrxMemoView;
//=== Конец: Сумма по 9-ой колонке ===//

//=== Сумма по 6-ой колонке ===//
//=== Конец: Сумма по 6-ой колонке ===//


NamePredpr := frxReport2.FindObject('NamePredpr') as TfrxMemoView;
NamePredpr.Text:='[IIF(<frxDatasetPrStr."NamePredpr"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."NamePredpr">,IIF(<frxDatasetPrStr."NameCountry"><>'+chr(39)+chr(39)+',<frxDatasetPrStr."NameCountry">,'+chr(39)+chr(39)+'))]';
NalProd := frxReport2.FindObject('NalProd') as TfrxMemoView;
Cen4_1 := frxReport2.FindObject('Cen4_1') as TfrxMemoView;
Cen4_2 := frxReport2.FindObject('Cen4_2') as TfrxMemoView;
//===6===//
Memo6_1 := frxReport2.FindObject('Memo6_1') as TfrxMemoView;
Memo6_2 := frxReport2.FindObject('Memo6_2') as TfrxMemoView;
Memo6_3 := frxReport2.FindObject('Memo6_3') as TfrxMemoView;
Memo6_4 := frxReport2.FindObject('Memo6_4') as TfrxMemoView;

if forSumNDS_1.Checked=True // ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_ONds')
  then begin
       frxReport1.Variables['Pr_ONds']:=QuotedStr('1');
       frxReport2.Variables['Pr_ONds']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_ONds']:=QuotedStr('0');
       frxReport2.Variables['Pr_ONds']:=QuotedStr('0');
       end;

if forVsegoSNDS_1.Checked=True // ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_RNds')
  then begin
       frxReport1.Variables['Pr_RNds']:=QuotedStr('1');
       frxReport2.Variables['Pr_RNds']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_RNds']:=QuotedStr('0');
       frxReport2.Variables['Pr_RNds']:=QuotedStr('0');
       end;

if forStoimost2_2.Checked=True // (ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_CenRoz'))
  then begin
       frxReport1.Variables['Pr_CenRoz']:=QuotedStr('1');
       frxReport2.Variables['Pr_CenRoz']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_CenRoz']:=QuotedStr('0');
       frxReport2.Variables['Pr_CenRoz']:=QuotedStr('0');
       end;

if forStoimost.Checked=True // (ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_CenOpt'))
  then begin
       frxReport1.Variables['Pr_CenOpt']:=QuotedStr('1');
       frxReport2.Variables['Pr_CenOpt']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_CenOpt']:=QuotedStr('0');
       frxReport2.Variables['Pr_CenOpt']:=QuotedStr('0');
       end;

if forPr_CenPriobr.Checked=True // (ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_CenPriobr'))
  then begin
       frxReport1.Variables['Pr_CenPriobr']:=QuotedStr('1');
       frxReport2.Variables['Pr_CenPriobr']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_CenPriobr']:=QuotedStr('0');
       frxReport2.Variables['Pr_CenPriobr']:=QuotedStr('0');
       end;

if forPr_CenTr.Checked=True // (ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_CenTr'))
  then begin
       frxReport1.Variables['Pr_CenTr']:=QuotedStr('1');
       frxReport2.Variables['Pr_CenTr']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_CenTr']:=QuotedStr('0');
       frxReport2.Variables['Pr_CenTr']:=QuotedStr('0');
       end;

if forPr_ProcTr.Checked=True // (ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_ProcTr'))
  then begin
       frxReport1.Variables['Pr_ProcTr']:=QuotedStr('1');
       frxReport2.Variables['Pr_ProcTr']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_ProcTr']:=QuotedStr('0');
       frxReport2.Variables['Pr_ProcTr']:=QuotedStr('0');
       end;

if forPr_CenWNal.Checked=True // (ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_CenWNal'))
  then begin
       frxReport1.Variables['Pr_CenWNal']:=QuotedStr('1');
       frxReport2.Variables['Pr_CenWNal']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_CenWNal']:=QuotedStr('0');
       frxReport2.Variables['Pr_CenWNal']:=QuotedStr('0');
       end;

if forStoimost2_1.Checked=True // (ReturnTypeFieldN(SklDM.DocQueryKodSkl.Value,'Pr_SchCenPriobr'))
  then begin
       frxReport1.Variables['Pr_SchCenPriobr']:=QuotedStr('1');
       frxReport2.Variables['Pr_SchCenPriobr']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['Pr_SchCenPriobr']:=QuotedStr('0');
       frxReport2.Variables['Pr_SchCenPriobr']:=QuotedStr('0');
       end;

if forPRAll.Text='*'
  then begin
       frxReport1.Variables['PrAll']:=QuotedStr('1');
       frxReport2.Variables['PrAll']:=QuotedStr('1');
       end
  else begin
       frxReport1.Variables['PrAll']:=QuotedStr('0');
       frxReport2.Variables['PrAll']:=QuotedStr('0');
       end;

//=========//
//=== 8 ===//
//=========//

Memo93 := frxReport2.FindObject('Memo93') as TfrxMemoView;
Memo93.Text:='[IIF(<frxDatasetPrStr."SumNDS"><>0,<frxDatasetPrStr."SumNDS">,'+chr(39)+chr(39)+')]';

if forSumNDS_1.Checked=False //not(ReturnTypeFieldP(SklDM.DocQueryKodSkl.Value,'Pr_ONds'))
then
begin
Memo93.Text:=StringReplace(Memo93.Text,'SumNDS','SumNDSR',[rfReplaceAll,rfIgnoreCase]);
//Memo94.Text:=StringReplace(Memo94.Text,'SumNDS','SumNDSR',[rfReplaceAll,rfIgnoreCase]);
//SumSumNDS.Text:=StringReplace(SumSumNDS.Text,'SumNDS','SumNDSR',[rfReplaceAll,rfIgnoreCase]);
end;

//SumSumNDS.GetData;
//SumSumNDS.Value:=SumSumNDS.Value+PrCapQuery.FieldByName('SumNdsBonus').AsInteger;

//============================================================//
//=== Конец: Определяется, какие из Memo должны выводиться ===//
//============================================================//

NumNakl := frxReport2.FindObject('NumNakl') as TfrxMemoView;
//NumNakl.GetData;
If forPRAll.Text<>' ' then
NumNakl.Memo.Text:= forTTNEdit.Text
else
NumNakl.Memo.Text:=forNumDoc.Text;

SeriaSecondPage := frxReport2.FindObject('SeriaSecondPage') as TfrxMemoView;
if forSeria.Text<>'' then SeriaSecondPage.Text:=forSeria.Text;

//frxReport1.ShowReport(true);

Memo3 := frxReport2.FindObject('Memo3') as TfrxMemoView;
Memo4 := frxReport2.FindObject('Memo4') as TfrxMemoView;
Memo5 := frxReport2.FindObject('Memo5') as TfrxMemoView;
Memo6 := frxReport2.FindObject('Memo6') as TfrxMemoView;
Memo7 := frxReport2.FindObject('Memo7') as TfrxMemoView;

if (PrCapQuery.FieldByName('SumBns').Value<>0) then
Memo3.Text:='Бонус';

if (PrCapQuery.FieldByName('SumBns').Value<>0) then
Memo4.Text:=FloatToStr(PrCapQuery.FieldByName('SumBns').AsFloat);

if (PrCapQuery.FieldByName('SumBns').Value<>0) then
Memo5.Text:=FloatToStr(PrCapQuery.FieldByName('NdsBns').AsFloat);

if (PrCapQuery.FieldByName('SumBns').Value<>0) then
Memo6.Text:=FloatToStr(PrCapQuery.FieldByName('SumNdsBonus').AsFloat);

if (PrCapQuery.FieldByName('SumBns').Value<>0) then
Memo7.Text:=FloatToStr(PrCapQuery.FieldByName('SumBns').AsFloat);


//============================//
//=== Конец: 2-ая страница ===//
//============================//

frxReport2.ShowReport(true);

//==========================//
//=== Конец: Вывод отчёта===//
//==========================//

//frxReport1.ShowReport(true);
//frxReport2.ShowReport(true);

end;

procedure TNaklForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FioDovQuery.Close;
Action:=caFree;
NaklForm:=nil;
end;

//============================//
//=== Используемые функции ===//
//============================//

function TNaklForm.Propis(S:Currency;KK:Integer):string;
var
    S1:string;
    Rub:string;
    Kop:string;
    Prop:string;
    A1_1:string;
    A1_3:string;
    A4_6:string;
    A7_9:string;
    C:string;
begin
C:='000000000000000';
Prop:=' ';
S1:=FloatToStrF(S,ffFixed,15,2);
S1:=Copy(C,1,(15-length(S1)))+S1;
Rub:=Copy(S1,1,12);
Kop:=Copy(S1,14,2);
A1_1:=Copy(Rub,1,3);
A1_3:=Copy(Rub,4,3);
A4_6:=Copy(Rub,7,3);
A7_9:=Copy(Rub,10,3);
If StrToInt(A1_1)>0 then
Prop:=Num(A1_1,3);
If StrToInt(A1_3)>0 then
Prop:=Prop+Num(A1_3,1);
If StrToInt(A4_6)>0 then
Prop:=Prop+Num(A4_6,2);
If StrToInt(A7_9)>0 then
Prop:=Prop+Num(A7_9,0);
if Length(Prop)=1 then
Prop:='НОЛЬ';
if KK=0 then
//Propis:=Prop+'  руб.'+ Kop+'  коп.'
Propis:=Prop+'  белорусских рублей'
else
begin
if KK=1 then
Propis:=Prop+' ЗПТ '+ Kop
else
Propis:=Prop
end;
end;

function TNaklForm.Num(Q:string;X:integer):string;
var I,J,K,L:integer;
    A:Array[1..9,1..5] of string;
begin
A[1,1]:=' сто';
A[2,1]:=' двести';
A[3,1]:=' триста';
A[4,1]:=' четыреста';
A[5,1]:=' пятьсот';
A[6,1]:=' шестьсот';
A[7,1]:=' семьсот';
A[8,1]:=' восемьсот';
A[9,1]:=' девятьсот';
//*
A[1,2]:=' десять';
A[2,2]:=' двадцать';
A[3,2]:=' тридцать';
A[4,2]:=' сорок';
A[5,2]:=' пятьдесят';
A[6,2]:=' шестьдесят';
A[7,2]:=' семьдесят';
A[8,2]:=' восемьдесят';
A[9,2]:=' девяносто';
//*
A[1,3]:=' одиннадцать';
A[2,3]:=' двенадцать';
A[3,3]:=' тринадцать';
A[4,3]:=' четырнадцать';
A[5,3]:=' пятнадцать';
A[6,3]:=' шестнадцать';
A[7,3]:=' семнадцать';
A[8,3]:=' восемнадцать';
A[9,3]:=' девятнадцать';
//*
A[1,4]:=' один';
A[2,4]:=' два';
A[3,4]:=' три';
A[4,4]:=' четыре';
A[5,4]:=' пять';
A[6,4]:=' шесть';
A[7,4]:=' семь';
A[8,4]:=' восемь';
A[9,4]:=' девять';
//*
A[1,5]:=' одна';
A[2,5]:=' две';
A[3,5]:=' три';
A[4,5]:=' четыре';
A[5,5]:=' пять';
A[6,5]:=' шесть';
A[7,5]:=' семь';
A[8,5]:=' восемь';
A[9,5]:=' девять';
Result:='';
I:=StrToInt(Copy(Q,1,1));
J:=StrToInt(Copy(Q,2,1));
K:=StrToInt(Copy(Q,3,1));
L:=StrToInt(Q);
if I>0 then
Result:=Result+A[I,1];
if ((J>1) or ((J=1) and (K=0))) then
begin
Result:=Result+A[J,2];
  if K>0 then
  begin
   if X<>2 then
   Result:=Result+A[K,4]
   else
   Result:=Result+A[K,5];
  end;
end;
//*
if ((J=1) and (K>0)) then
Result:=Result+A[K,3];
if ((J=0) and (K>0)) then
begin
   if X<>2 then
   Result:=Result+A[K,4]
   else
   Result:=Result+A[K,5];
end;
//*
if X=3 then
begin
 if L>0 then
 Result:=Result+' миллиард';
 if (((L>4) and (L<21)) or (K>4) or ((J=0) and (K=0))) then
 Result:=Result+'ов'
 else
 begin
  if ((K>=2) and (K<=4)) then
  Result:=Result+'а';
 end;
end;
//*
if X=1 then
begin
 if L>0 then
 Result:=Result+' миллион';
 if (((L>4) and (L<21)) or (K>4) or ((J=0) and (K=0))) then
 Result:=Result+'ов'
 else
 begin
  if ((K>=2) and (K<=4)) then
  Result:=Result+'а';
 end;
end;
//*
if X=2 then
begin
 if L>0 then
 Result:=Result+' тысяч';
 if ((K=1) and ((L<9) or (L>20))) then
 Result:=Result+'а'
 else
 begin
  if (((K>1) and (K<5))and((L<9) or (L>20))and (J<>1)) then
  Result:=Result+'и';
 end;
end;
end;

function TNaklForm.PROPER(S: string): string;
var
  X: Integer;
begin
  Result := '';
  if Length(s) = 0 then
    exit;
  for X := 1 to length(s) do
    if s[x]<>' ' then begin
                      S[x] := AnsiUpperCase(s[x])[1];
                      Break;
                      end;
  Result := S;
end;

function TNaklForm.Rounding(Value:Currency):Currency; // Округление до сотых Суховаров А.А.
begin
  Result := Trunc(Value*100+0.5)/100;
end;


end.

