--[[ 18e30c85b6b1528a ]] local caption = 'Zmena dátumov dokladov' if not db.Opened then MessageBox('Otvorte prosím účtovníctvo, v ktorom si želáte zmeniť ' .. 'dátumy dokladov a spustite tento skript znovu.', caption, 64) return false elseif FrmMain.ActiveEvid.TableName ~= 'obrat' then MessageBox('Nastavte sa do evidencie Obratov a spustite tento skript znovu.', caption, 0x30) return false else local g = FrmMain.ActiveEvid.Table local t = {} g:First() while not g.Eof do if g.Selected then table.insert(t, g:Field'RowID') end g:Next() end if MessageBox('Označili ste ' .. #t .. ' obratov. Želáte si pokračovať?', caption, 0x30 + 0x4) ~= 6 then return false end local frm = New 'TForm' frm.Caption = caption frm.Position = 'poMainFormCenter' frm.Width = 360 std_gui:Init(frm) std_gui:Add('rbZauct', 'TRadioButton', 'Dátum zaúčtovania').Checked = false std_gui:Add('rbSplat', 'TRadioButton', 'Dátum splatnosti').Checked = true std_gui:Add('edtDatumDen', 'TXEdit', 'Posun dní').Text = '0' std_gui:Add('edtDatumMesiac', 'TXEdit', 'Posun mesiacov').Text = '0' std_gui:Add('', 'TOkCancelButtons', '') frm.ClientHeight = std_gui.Y local mvdni = 0 local mvmes = 0 local colum = '' frm.btnOk.OnClick = function(Sender) if not misc.ValidNumeric(Sender.Parent.edtDatumDen) or not misc.ValidNumeric(Sender.Parent.edtDatumMesiac) then Sender.Parent.ModalResult = 0 return nil end mvdni = tonumber(Sender.Parent.edtDatumDen.Text) mvmes = tonumber(Sender.Parent.edtDatumMesiac.Text) if Sender.Parent.rbZauct.Checked then colum = 'DatumZauct' else colum = 'DatumSplat' end end; if frm:ShowModal() == 1 then local s = sql( 'SELECT RowID, ' .. colum .. ' FROM obrat WHERE RowID IN (' .. table.concat(t, ', ') .. ');' ) local res = true if db:locktable 'obrat' then db:begin() for rowid, datum in s:each() do datum = date.fix(date.offset(datum, mvmes, 'm')) datum = date.fix(date.offset(datum, mvdni, 'd')) res = db:exec( 'UPDATE obrat SET ' .. colum .. ' = ' .. datum .. ' WHERE RowID = ' .. rowid .. ';' ) if not res then break end end db:finish(res) db:unlocktable 'obrat' end if res then MessageBox('Oprava dokladov je ukončená.', caption, 64) end return res end return false end