procedure auto_register_codes_in_prices(ID_ORG :int64 = 0; REGISTER_TOTAL :boolean = false; STEP :integer = 50);
  {
  procedure AUTO_REGISTER_CODES_IN_PRICES ( ID_ORG bigint = null, REGISTER_TOTAL TBOOL = 0)
  returns (
    RESULT_COUNT_ALL bigint,
    RESULT_COUNT_CURRENT bigint,
    RESULT_COUNT_GOODS bigint,
    RESULT_COUNT_GOODS_CLEAR bigint,
    RESULT_COUNT_PRODUCERS bigint,
    RESULT_COUNT_PRODUCERS_CLEAR bigint)
  }

var DS :tpfibdataset;
  strval1,strval2 :string;
begin

  with tmywait.create1('Èäåò ðåãèñòðàöèÿ êîäîâ â ïðàéñ-ëèñòàõ',selfscript) do
  try
    ds := tpfibdataset.create(selfscript);

    //ds.database := mainfibdatabase;
    ds.transaction := mainwritetransaction;

    if id_org<>0 then strval1 := inttostr(id_org) else strval1 := 'null';
    if register_total then strval2 := '1' else strval2 := '0';

    ds.selectsql.text := 'select * from auto_register_codes_in_prices('+strval1+','+strval2+','+inttostr(step)+') for update';                //:id_org,:register_total)';
    //if id_org<>0 then ds.parambyname('id_org').asinteger := id_org;
    //if register_total then ds.parambyname('register_total').assmallint := 1;

    ds.open;
    while not ds.eof do begin
      progressbarpos := ds.fieldbyname('result_count_current').asinteger * 100 div ds.fieldbyname('result_count_all').asinteger;
      advancedtext := ds.fieldbyname('result').asstring;
                     // 'Çàðåãèñòðèðîâàíî/ñíÿòî ñ ðåãèñòðàöèè: òîâàðîâ: '
                     // +ds.fieldbyname('result_count_goods').asstring+' / '+ds.fieldbyname('result_count_goods_clear').asstring
                     // +' ïðîèçâ. : '
                     // +ds.fieldbyname('result_count_producers').asstring+' / '+ds.fieldbyname('result_count_producers_clear').asstring;



      ds.next;
      application.processmessages;
    end;

    createhint('Îïåðàöèÿ ñèíõðîíèçàöèè çàâåðøåíà'+#13+advancedtext,'Ðåãèñòðàöèÿ êîäîâ',0);
    if ds.transaction.intransaction then ds.transaction.commit;
  finally
    free
  end
end;


begin
   // comment
   //auto_register_codes_in_prices; //(15001,false,25);


end.
