-- --------------------------------------------------------
-- Host:                         153.92.1.116
-- Server version:               8.0.46-0ubuntu0.22.04.2 - (Ubuntu)
-- Server OS:                    Linux
-- HeidiSQL Version:             12.7.0.6850
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

-- Dumping structure for table st_skaititajs.dati_tirs
CREATE TABLE IF NOT EXISTS `dati_tirs` (
  `id` int unsigned NOT NULL DEFAULT '0' COMMENT 'Datu id',
  `numurs` decimal(14,0) NOT NULL COMMENT 'Skaitītāja numurs',
  `obis` decimal(3,0) unsigned NOT NULL DEFAULT '180' COMMENT 'Koeficents',
  `radijums` decimal(14,0) unsigned NOT NULL COMMENT 'Skaitītāja rādījums',
  `datums` date NOT NULL COMMENT 'Rādījuma uzņemšanas datums',
  `skaitit_garums` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table st_skaititajs.dati_tirs: ~128 rows (approximately)
INSERT INTO `dati_tirs` (`id`, `numurs`, `obis`, `radijums`, `datums`, `skaitit_garums`) VALUES
	(1, 10498, 180, 22191, '2003-12-01', 5),
	(2, 96397, 180, 43651, '2003-12-01', 5),
	(3, 32687084, 180, 6040, '2003-12-01', 6),
	(4, 32469776, 180, 13004, '2003-12-01', 6),
	(5, 4224014, 180, 3402, '2003-12-01', 4),
	(6, 32778874, 180, 7444, '2003-12-01', 6),
	(7, 4547010, 180, 6115, '2003-12-01', 4),
	(8, 110081, 180, 45565, '2003-12-01', 5),
	(9, 32647524, 180, 14562, '2003-12-01', 6),
	(10, 32719941, 180, 11668, '2003-12-01', 6),
	(11, 50028646, 180, 181, '2003-12-01', 6),
	(12, 3639101, 180, 7734, '2003-12-01', 4),
	(13, 32778527, 180, 9799, '2003-12-01', 6),
	(14, 10392, 180, 29325, '2003-12-01', 5),
	(15, 50028590, 180, 672, '2003-12-01', 6),
	(16, 97125, 180, 39140, '2003-12-01', 5),
	(17, 32996418, 180, 10127, '2003-12-01', 6),
	(18, 291044, 180, 8566, '2003-12-01', 4),
	(19, 7950242, 180, 39581, '2003-12-01', 5),
	(20, 23860702, 180, 7010, '2003-12-01', 4),
	(21, 556043, 180, 15238, '2003-12-01', 6),
	(22, 3493235, 180, 5483, '2003-12-01', 4),
	(214, 50050895, 180, 45805, '2004-09-01', 5),
	(305, 50088638, 180, 7646, '2005-01-01', 4),
	(489, 29375625, 180, 15048, '2005-09-01', 6),
	(509, 251280, 180, 9333, '2005-10-01', 4),
	(512, 29292035, 180, 15766, '2005-10-01', 6),
	(541, 29292026, 180, 3469, '2005-11-01', 4),
	(542, 29292037, 180, 51742, '2005-11-01', 5),
	(569, 29292023, 180, 1999, '2005-12-01', 6),
	(613, 93125, 180, 15922, '2006-02-01', 6),
	(615, 29446699, 180, 36, '2006-02-01', 6),
	(616, 29446616, 180, 3348, '2006-02-01', 6),
	(619, 29376219, 180, 24, '2006-02-01', 6),
	(622, 29376210, 180, 4589, '2006-02-01', 6),
	(626, 29376264, 180, 18460, '2006-02-01', 6),
	(631, 29376213, 180, 94, '2006-02-01', 6),
	(634, 29376263, 180, 1324, '2006-02-01', 6),
	(635, 29446613, 180, 1860, '2006-02-01', 6),
	(641, 29376231, 180, 26379, '2006-03-01', 6),
	(880, 32735797, 180, 5194, '2006-11-01', 6),
	(882, 50121054, 180, 38691, '2006-11-01', 6),
	(1222, 50152351, 180, 47385, '2007-11-01', 6),
	(1290, 50156373, 180, 15687, '2008-02-01', 6),
	(1346, 50161280, 180, 70, '2008-03-01', 6),
	(1355, 50158093, 180, 15111, '2008-04-01', 6),
	(1642, 557538, 180, 16519, '2008-12-01', 6),
	(1674, 568796, 180, 44575, '2008-12-17', 6),
	(1696, 580689, 180, 10042, '2009-02-01', 6),
	(1713, 568693, 180, 316, '2009-02-01', 8),
	(2144, 50135314, 180, 54098, '2010-01-29', 6),
	(2191, 32414204, 180, 63380, '2010-02-25', 6),
	(2310, 50028987, 180, 33433, '2010-05-27', 6),
	(2331, 32735197, 180, 36766, '2010-06-29', 6),
	(2584, 83543477, 180, 26843, '2010-12-31', 6),
	(2811, 56993, 182, 4128, '2011-06-30', 8),
	(2861, 50089149, 180, 3426, '2011-07-30', 6),
	(3081, 52685418, 180, 4494, '2012-01-30', 8),
	(3336, 52685472, 180, 87290, '2012-06-30', 6),
	(3444, 341236, 180, 10744, '2012-09-30', 6),
	(3447, 34237, 180, 20107, '2012-09-30', 6),
	(3448, 34231, 180, 40158, '2012-09-30', 6),
	(3698, 264, 180, 38684, '2013-03-30', 6),
	(4329, 53119305, 180, 3943, '2014-05-30', 6),
	(4337, 53117522, 180, 1798, '2014-05-30', 6),
	(4338, 53117426, 180, 32505, '2014-05-30', 6),
	(4877, 32199561, 180, 4914, '2015-04-30', 6),
	(4903, 32276933, 180, 0, '2015-05-30', 8),
	(4905, 32202631, 180, 15462, '2015-05-30', 8),
	(5228, 11669109, 180, 10712, '2015-12-31', 6),
	(5231, 11688670, 180, 5261, '2015-12-31', 6),
	(5241, 100145, 180, 143870, '2015-12-31', 6),
	(5250, 11669252, 180, 10316, '2015-12-31', 6),
	(5251, 11667994, 180, 52872, '2015-12-31', 6),
	(5253, 11667895, 180, 2240, '2015-12-31', 8),
	(5257, 11671877, 180, 1698, '2015-12-31', 6),
	(5263, 11675292, 180, 4297, '2015-12-31', 8),
	(5343, 432778527, 180, 4601, '2016-02-29', 8),
	(5359, 93543477, 180, 2981, '2016-02-29', 8),
	(5367, 32149396, 180, 9548, '2016-03-31', 8),
	(5394, 82776, 180, 37201, '2016-03-31', 8),
	(5895, 1611742, 182, 1740, '2017-01-31', 6),
	(5957, 32558090, 180, 13691, '2017-02-28', 8),
	(5964, 32245598, 180, 3537, '2017-02-28', 8),
	(5971, 32295119, 180, 4731, '2017-02-28', 6),
	(5972, 32248826, 180, 10882, '2017-03-31', 8),
	(5979, 50086615, 180, 13661, '2017-03-31', 6),
	(5983, 33165911, 180, 20953, '2017-03-31', 6),
	(6046, 11400194, 180, 1761, '2017-04-30', 6),
	(6300, 91005292, 180, 14543, '2017-09-30', 8),
	(6715, 6251280, 180, 38, '2018-06-29', 9),
	(7220, 4109420729, 180, 2245, '2019-04-30', 9),
	(7224, 4109420527, 180, 2368, '2019-04-30', 9),
	(7229, 4109420280, 180, 32910, '2019-04-30', 6),
	(7231, 4109420145, 180, 4947, '2019-04-30', 9),
	(7235, 4109420471, 180, 2950, '2019-04-30', 9),
	(7236, 4109420325, 180, 88173, '2019-04-30', 6),
	(7243, 4114492386, 180, 11009, '2019-04-30', 6),
	(7247, 4114492229, 180, 7263, '2019-04-30', 4),
	(7265, 4114492173, 180, 2902, '2019-05-31', 8),
	(7266, 4114492027, 180, 17227, '2019-05-31', 8),
	(7267, 4109420886, 180, 20589, '2019-05-31', 6),
	(7270, 85682335, 180, 2451, '2019-05-31', 9),
	(7279, 91002891, 180, 32975, '2019-05-31', 6),
	(7960, 5301873827, 180, 6863, '2020-06-30', 9),
	(8036, 5110914629, 180, 81007, '2020-09-01', 6),
	(8144, 5110833045, 180, 8041, '2020-10-31', 9),
	(8192, 5110224320, 180, 7954, '2020-12-01', 8),
	(8387, 5116907043, 180, 4302, '2021-03-31', 9),
	(8403, 5116905827, 180, 653, '2021-03-31', 10),
	(8426, 5116907100, 180, 23448, '2021-05-01', 6),
	(8435, 5117901127, 180, 7897, '2021-05-01', 9),
	(8765, 4107948968, 180, 19440, '2022-01-28', 6),
	(8766, 524351225, 180, 15021, '2022-01-28', 6),
	(8800, 4117013300, 180, 15591, '2022-05-01', 6),
	(8930, 6102615629, 180, 2010, '2014-06-30', 6),
	(8936, 6102615900, 180, 25190, '2014-09-19', 6),
	(9030, 6100663686, 180, 9286, '2021-11-02', 9),
	(9085, 6103887463, 180, 0, '0000-00-00', 0),
	(9410, 6100599167, 180, 0, '0000-00-00', 0),
	(9411, 610404380, 180, 0, '0000-00-00', 0),
	(9423, 6104043480, 180, 0, '0000-00-00', 0),
	(9521, 950028987, 180, 0, '0000-00-00', 0),
	(9531, 92202631, 180, 0, '0000-00-00', 0),
	(9555, 6110960924, 180, 0, '0000-00-00', 0),
	(9556, 6107272443, 180, 0, '0000-00-00', 0),
	(9557, 6107261429, 180, 0, '0000-00-00', 0),
	(9558, 6107261586, 180, 0, '0000-00-00', 0);

-- Dumping structure for table st_skaititajs.skaititajs_tirs
CREATE TABLE IF NOT EXISTS `skaititajs_tirs` (
  `id` int unsigned NOT NULL DEFAULT '0' COMMENT 'Datu id',
  `numurs` decimal(14,0) NOT NULL COMMENT 'Skaitītāja numurs',
  `skaititaja_garums` decimal(2,0) unsigned NOT NULL DEFAULT '0' COMMENT 'Skaitītāja numura garums',
  `burts` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Skaitītāja numura burts',
  `rad_garums` decimal(2,0) NOT NULL COMMENT 'Skaitītāja rādījuma zīmju skaits',
  `datums` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table st_skaititajs.skaititajs_tirs: ~128 rows (approximately)
INSERT INTO `skaititajs_tirs` (`id`, `numurs`, `skaititaja_garums`, `burts`, `rad_garums`, `datums`) VALUES
	(1, 10498, 7, '', 5, '2003-12-01'),
	(2, 96397, 7, '', 5, '2003-12-01'),
	(3, 32687084, 8, '', 6, '2003-12-01'),
	(4, 32469776, 8, '', 6, '2003-12-01'),
	(5, 4224014, 7, '', 4, '2003-12-01'),
	(6, 32778874, 8, '', 6, '2003-12-01'),
	(7, 4547010, 7, '', 4, '2003-12-01'),
	(8, 110081, 7, '', 5, '2003-12-01'),
	(9, 32647524, 8, '', 6, '2003-12-01'),
	(10, 32719941, 8, '', 6, '2003-12-01'),
	(11, 50028646, 8, '', 6, '2003-12-01'),
	(12, 3639101, 7, '', 4, '2003-12-01'),
	(13, 32778527, 8, '', 6, '2003-12-01'),
	(14, 10392, 7, '', 5, '2003-12-01'),
	(15, 50028590, 8, '', 6, '2003-12-01'),
	(16, 97125, 7, '', 5, '2003-12-01'),
	(17, 32996418, 8, '', 6, '2003-12-01'),
	(18, 291044, 6, '', 4, '2003-12-01'),
	(19, 7950242, 7, '', 5, '2003-12-01'),
	(20, 23860702, 8, '', 4, '2003-12-01'),
	(21, 556043, 7, '', 6, '2003-12-01'),
	(22, 3493235, 7, '', 4, '2003-12-01'),
	(214, 50050895, 8, '', 6, '2004-09-01'),
	(305, 50088638, 8, '', 6, '2005-01-01'),
	(489, 29375625, 8, '', 6, '2005-09-01'),
	(509, 251280, 6, '', 8, '2005-10-01'),
	(512, 29292035, 8, '', 6, '2005-10-01'),
	(541, 29292026, 8, '', 6, '2005-11-01'),
	(542, 29292037, 8, '', 6, '2005-11-01'),
	(569, 29292023, 8, '', 6, '2005-12-01'),
	(613, 93125, 7, '', 5, '2006-02-01'),
	(615, 29446699, 8, '', 6, '2006-02-01'),
	(616, 29446616, 8, '', 6, '2006-02-01'),
	(619, 29376219, 8, '', 6, '2006-02-01'),
	(622, 29376210, 8, '', 6, '2006-02-01'),
	(626, 29376264, 8, '', 6, '2006-02-01'),
	(631, 29376213, 8, '', 6, '2006-02-01'),
	(634, 29376263, 8, '', 6, '2006-02-01'),
	(635, 29446613, 8, '', 6, '2006-02-01'),
	(641, 29376231, 8, '', 6, '2006-03-01'),
	(880, 32735797, 8, '', 6, '2006-11-01'),
	(882, 50121054, 8, '', 6, '2006-11-01'),
	(1222, 50152351, 8, '', 6, '2007-11-01'),
	(1290, 50156373, 8, '', 6, '2008-02-01'),
	(1346, 50161280, 8, '', 6, '2008-03-01'),
	(1355, 50158093, 8, '', 6, '2008-04-01'),
	(1642, 557538, 6, '', 8, '2008-12-01'),
	(1674, 568796, 6, '', 8, '2008-12-17'),
	(1696, 580689, 6, '', 8, '2009-02-01'),
	(1713, 568693, 6, '', 8, '2009-02-01'),
	(2144, 50135314, 8, '', 6, '2010-01-29'),
	(2191, 32414204, 8, '', 6, '2010-02-25'),
	(2310, 50028987, 8, '', 6, '2010-05-27'),
	(2331, 32735197, 8, '', 6, '2010-06-29'),
	(2584, 83543477, 8, '', 6, '2010-12-31'),
	(2811, 56993, 5, '', 8, '2011-06-30'),
	(2861, 50089149, 8, '', 6, '2011-07-30'),
	(3081, 52685418, 8, '', 6, '2012-01-30'),
	(3336, 52685472, 8, '', 6, '2012-06-30'),
	(3444, 341236, 6, '', 1, '2012-09-30'),
	(3447, 34237, 5, '', 5, '2012-09-30'),
	(3448, 34231, 5, '', 1, '2012-09-30'),
	(3698, 264, 6, 'W', 6, '2013-03-30'),
	(4329, 53119305, 8, '', 6, '2014-05-30'),
	(4337, 53117522, 8, '', 6, '2014-05-30'),
	(4338, 53117426, 8, '', 6, '2014-05-30'),
	(4877, 32199561, 8, '', 6, '2015-04-30'),
	(4903, 32276933, 8, '', 6, '2015-05-30'),
	(4905, 32202631, 8, '', 6, '2015-05-30'),
	(5228, 11669109, 8, '', 8, '2015-12-31'),
	(5231, 11688670, 8, '', 8, '2015-12-31'),
	(5241, 100145, 6, '', 8, '2015-12-31'),
	(5250, 11669252, 8, '', 8, '2015-12-31'),
	(5251, 11667994, 8, '', 8, '2015-12-31'),
	(5253, 11667895, 8, '', 8, '2015-12-31'),
	(5257, 11671877, 8, '', 8, '2015-12-31'),
	(5263, 11675292, 8, '', 8, '2015-12-31'),
	(5343, 432778527, 9, '', 8, '2016-02-29'),
	(5359, 93543477, 8, '', 8, '2016-02-29'),
	(5367, 32149396, 8, '', 6, '2016-03-31'),
	(5394, 82776, 5, '', 8, '2016-03-31'),
	(5895, 1611742, 8, '', 7, '2017-01-31'),
	(5957, 32558090, 8, '', 6, '2017-02-28'),
	(5964, 32245598, 8, '', 7, '2017-02-28'),
	(5971, 32295119, 8, '', 6, '2017-02-28'),
	(5972, 32248826, 8, '', 6, '2017-03-31'),
	(5979, 50086615, 8, '', 6, '2017-03-31'),
	(5983, 33165911, 9, '', 6, '2017-03-31'),
	(6046, 11400194, 8, '', 8, '2017-04-30'),
	(6300, 91005292, 8, '', 8, '2017-09-30'),
	(6715, 6251280, 7, '', 8, '2018-06-29'),
	(7220, 4109420729, 10, '', 9, '2019-04-30'),
	(7224, 4109420527, 10, '', 9, '2019-04-30'),
	(7229, 4109420280, 10, '', 9, '2019-04-30'),
	(7231, 4109420145, 10, '', 9, '2019-04-30'),
	(7235, 4109420471, 10, '', 9, '2019-04-30'),
	(7236, 4109420325, 10, '', 9, '2019-04-30'),
	(7243, 4114492386, 10, '', 9, '2019-04-30'),
	(7247, 4114492229, 10, '', 9, '2019-04-30'),
	(7265, 4114492173, 10, '', 9, '2019-05-31'),
	(7266, 4114492027, 10, '', 9, '2019-05-31'),
	(7267, 4109420886, 10, '', 9, '2019-05-31'),
	(7270, 85682335, 8, '', 0, '2019-05-31'),
	(7279, 91002891, 8, '', 8, '2019-05-31'),
	(7960, 5301873827, 10, '', 9, '2020-06-30'),
	(8036, 5110914629, 10, '', 9, '2020-09-01'),
	(8144, 5110833045, 10, '', 9, '2020-10-31'),
	(8192, 5110224320, 10, '', 9, '2020-12-01'),
	(8387, 5116907043, 10, '', 9, '2021-03-31'),
	(8403, 5116905827, 10, '', 9, '2021-03-31'),
	(8426, 5116907100, 10, '', 9, '2021-05-01'),
	(8435, 5117901127, 10, '', 9, '2021-05-01'),
	(8765, 4107948968, 10, '', 10, '2022-01-28'),
	(8766, 524351225, 9, '', 10, '2022-01-28'),
	(8800, 4117013300, 10, '', 10, '2022-05-01'),
	(8930, 6102615629, 10, '', 9, '2014-06-30'),
	(8936, 6102615900, 10, '', 9, '2014-09-19'),
	(9030, 6100663686, 10, '', 9, '2021-11-02'),
	(9085, 6103887463, 10, '', 9, '0000-00-00'),
	(9410, 6100599167, 10, '', 9, '0000-00-00'),
	(9411, 610404380, 9, '', 9, '0000-00-00'),
	(9423, 6104043480, 10, '', 9, '0000-00-00'),
	(9521, 950028987, 9, '', 9, '0000-00-00'),
	(9531, 92202631, 8, '', 10, '0000-00-00'),
	(9555, 6110960924, 10, '', 9, '0000-00-00'),
	(9556, 6107272443, 10, '', 9, '0000-00-00'),
	(9557, 6107261429, 10, '', 9, '0000-00-00'),
	(9558, 6107261586, 10, '', 9, '0000-00-00');

-- Dumping structure for view st_skaititajs.skaititajs_tirs_view
-- Creating temporary table to overcome VIEW dependency errors
CREATE TABLE `skaititajs_tirs_view` 
) ENGINE=MyISAM;

-- Dumping structure for procedure st_skaititajs.sp_Paterins
DELIMITER //
CREATE PROCEDURE `sp_Paterins`()
BEGIN

    DECLARE v_beigas DATE;
    DECLARE v_no DATE;
    DECLARE v_lidz DATE;

    SET v_beigas = LAST_DAY(STR_TO_DATE(CONCAT(p_gads,'-',p_menesis,'-01'), '%Y-%m-%d'));

    SET v_no = DATE_SUB(v_beigas, INTERVAL 10 DAY);
    SET v_lidz = DATE_ADD(v_beigas, INTERVAL 5 DAY);

    SELECT
        id,
        name,
        obis,
        skaitit_num,

        rad_no,
        rad_lidz,
        dat_no,
        dat_lidz,

        CASE
            
            WHEN rad_lidz >= rad_no THEN rad_lidz - rad_no

            
            ELSE
                (POW(10, CHAR_LENGTH(CAST(rad_no AS CHAR))) - rad_no)
                + rad_lidz
        END AS paterins

    FROM paterins

    WHERE dat_lidz BETWEEN v_no AND v_lidz
      AND dat_lidz IS NOT NULL
      AND dat_lidz <> '0000-00-00'

    ORDER BY name ASC;

END//
DELIMITER ;

-- Dumping structure for table st_skaititajs.uzskaite_tira
CREATE TABLE IF NOT EXISTS `uzskaite_tira` (
  `id` int unsigned NOT NULL DEFAULT '0' COMMENT 'Datu id',
  `object_id` int unsigned NOT NULL COMMENT 'Objekta id',
  `numurs` decimal(14,0) NOT NULL COMMENT 'Skaitītāja numurs',
  `datums_no` date NOT NULL COMMENT 'Skaitītāja uzstādīšanas datums',
  `Datums_lidz` date NOT NULL COMMENT 'Skaitītāja noņemšanas datums'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table st_skaititajs.uzskaite_tira: ~128 rows (approximately)
INSERT INTO `uzskaite_tira` (`id`, `object_id`, `numurs`, `datums_no`, `Datums_lidz`) VALUES
	(1, 7, 10498, '2003-12-01', '2004-01-01'),
	(2, 9, 96397, '2003-12-01', '2004-01-01'),
	(3, 11, 32687084, '2003-12-01', '2004-01-01'),
	(4, 12, 32469776, '2003-12-01', '2004-01-01'),
	(5, 13, 4224014, '2003-12-01', '2004-01-01'),
	(6, 18, 32778874, '2003-12-01', '2004-01-01'),
	(7, 19, 4547010, '2003-12-01', '2004-01-01'),
	(8, 20, 110081, '2003-12-01', '2004-01-01'),
	(9, 21, 32647524, '2003-12-01', '2004-01-01'),
	(10, 23, 32719941, '2003-12-01', '2004-01-01'),
	(11, 26, 50028646, '2003-12-01', '2004-01-01'),
	(12, 27, 3639101, '2003-12-01', '2004-01-01'),
	(13, 29, 32778527, '2003-12-01', '2004-01-01'),
	(14, 30, 10392, '2003-12-01', '2004-01-01'),
	(15, 32, 50028590, '2003-12-01', '2004-01-01'),
	(16, 34, 97125, '2003-12-01', '2004-01-01'),
	(17, 39, 32996418, '2003-12-01', '2004-01-01'),
	(18, 41, 291044, '2003-12-01', '2004-01-01'),
	(19, 42, 7950242, '2003-12-01', '2004-01-01'),
	(20, 43, 23860702, '2003-12-01', '2004-01-01'),
	(21, 49, 556043, '2003-12-01', '2004-01-01'),
	(22, 51, 3493235, '2003-12-01', '2004-01-01'),
	(214, 19, 50050895, '2004-09-01', '2004-10-01'),
	(305, 16, 50088638, '2005-01-01', '2005-02-01'),
	(489, 43, 29375625, '2005-08-24', '2005-09-01'),
	(509, 30, 251280, '2005-09-28', '2005-10-01'),
	(512, 38, 29292035, '2005-09-01', '2005-10-01'),
	(541, 47, 29292026, '2005-09-01', '2005-11-01'),
	(542, 48, 29292037, '2005-10-01', '2005-11-01'),
	(569, 44, 29292023, '2005-11-01', '2005-12-01'),
	(613, 34, 93125, '2006-01-01', '2006-01-28'),
	(615, 7, 29446699, '2006-01-21', '2006-02-01'),
	(616, 9, 29446616, '2006-01-26', '2006-02-01'),
	(619, 13, 29376219, '2006-01-27', '2006-02-01'),
	(622, 20, 29376210, '2006-01-26', '2006-02-01'),
	(626, 27, 29376264, '2006-01-28', '2006-02-01'),
	(631, 34, 29376213, '2006-01-28', '2006-02-01'),
	(634, 41, 29376263, '2006-01-26', '2006-02-01'),
	(635, 42, 29446613, '2006-01-26', '2006-02-01'),
	(641, 51, 29376231, '2006-01-29', '2006-02-01'),
	(880, 49, 32735797, '2006-09-01', '2006-10-01'),
	(882, 52, 50121054, '2006-09-01', '2006-10-01'),
	(1222, 50, 50152351, '2007-08-01', '2007-09-01'),
	(1290, 0, 50156373, '2007-11-01', '2007-12-01'),
	(1346, 0, 50161280, '2007-12-01', '2008-01-01'),
	(1355, 0, 50158093, '2007-12-01', '2008-01-01'),
	(1642, 31, 557538, '2008-09-01', '2008-09-30'),
	(1674, 2, 568796, '2008-10-01', '2008-11-01'),
	(1696, 37, 580689, '2008-10-01', '2008-11-01'),
	(1713, 3, 568693, '2008-11-01', '2008-12-01'),
	(2144, 6, 50135314, '2009-09-28', '2009-10-29'),
	(2191, 17, 32414204, '2009-10-29', '2009-11-29'),
	(2310, 9, 50028987, '2010-01-29', '2010-02-25'),
	(2331, 38, 32735197, '2010-02-24', '2010-02-25'),
	(2584, 45, 83543477, '2010-07-29', '2010-08-31'),
	(2811, 0, 56993, '2011-01-28', '2011-02-28'),
	(2861, 13, 50089149, '2011-03-04', '2011-03-28'),
	(3081, 8, 52685418, '2011-07-30', '2011-08-30'),
	(3336, 33, 52685472, '2012-01-23', '2012-01-30'),
	(3444, 44, 341236, '2012-03-20', '2012-03-31'),
	(3447, 47, 34237, '2012-03-15', '2012-03-31'),
	(3448, 48, 34231, '2012-03-20', '2012-03-31'),
	(3698, 10, 0, '2012-08-30', '2012-09-30'),
	(4329, 15, 53119305, '2013-09-28', '2013-11-05'),
	(4337, 21, 53117522, '2013-09-28', '2013-11-05'),
	(4338, 22, 53117426, '2013-09-28', '2013-11-05'),
	(4877, 12, 32199561, '2014-09-19', '2014-09-29'),
	(4903, 41, 32276933, '2014-09-19', '2014-09-29'),
	(4905, 43, 32202631, '2014-09-18', '2014-09-29'),
	(5228, 11, 11669109, '2015-04-22', '2015-04-30'),
	(5231, 14, 11688670, '2015-04-26', '2015-04-30'),
	(5241, 24, 100145, '2015-03-31', '2015-04-30'),
	(5250, 35, 11669252, '2015-04-20', '2015-04-30'),
	(5251, 36, 11667994, '2015-04-26', '2015-04-30'),
	(5253, 38, 11667895, '2015-04-20', '2015-04-30'),
	(5257, 42, 11671877, '2015-04-20', '2015-04-30'),
	(5263, 48, 11675292, '2015-04-20', '2015-04-30'),
	(5343, 29, 432778527, '2015-05-30', '2015-06-30'),
	(5359, 45, 93543477, '2015-05-26', '2015-06-30'),
	(5367, 53, 32149396, '2015-05-30', '2015-06-30'),
	(5394, 28, 82776, '2015-06-30', '2015-07-30'),
	(5895, 0, 1611742, '2016-05-23', '2016-05-30'),
	(5957, 8, 32558090, '2016-06-17', '2016-06-30'),
	(5964, 15, 32245598, '2016-05-30', '2016-06-30'),
	(5971, 21, 32295119, '2016-06-18', '2016-06-30'),
	(5972, 22, 32248826, '2016-06-12', '2016-06-30'),
	(5979, 29, 50086615, '2016-05-18', '2016-06-30'),
	(5983, 33, 33165911, '2016-06-18', '2016-06-30'),
	(6046, 45, 11400194, '2016-06-27', '2016-07-29'),
	(6300, 29, 91005292, '2016-11-30', '2016-12-31'),
	(6715, 30, 6251280, '2017-08-08', '2017-08-31'),
	(7220, 0, 4109420729, '2018-06-19', '2018-06-29'),
	(7224, 8, 4109420527, '2018-06-19', '2018-06-29'),
	(7229, 13, 4109420280, '2018-06-19', '2018-06-29'),
	(7231, 15, 4109420145, '2018-06-19', '2018-06-29'),
	(7235, 19, 4109420471, '2018-06-19', '2018-06-29'),
	(7236, 20, 4109420325, '2018-06-19', '2018-06-29'),
	(7243, 28, 4114492386, '2018-06-19', '2018-06-29'),
	(7247, 31, 4114492229, '2018-06-19', '2018-06-29'),
	(7265, 49, 4114492173, '2018-06-19', '2018-06-29'),
	(7266, 50, 4114492027, '2018-06-19', '2018-06-29'),
	(7267, 51, 4109420886, '2018-06-19', '2018-06-29'),
	(7270, 1, 85682335, '0000-00-00', '2030-07-20'),
	(7279, 10, 91002891, '2018-06-29', '2018-07-30'),
	(7960, 1, 5301873827, '2012-08-20', '2030-08-20'),
	(8036, 23, 5110914629, '2019-09-05', '2019-09-30'),
	(8144, 24, 5110833045, '2019-11-11', '2019-11-30'),
	(8192, 18, 5110224320, '2019-12-12', '2019-12-31'),
	(8387, 44, 5116907043, '2020-02-29', '2020-04-01'),
	(8403, 16, 5116905827, '2020-04-01', '2020-04-30'),
	(8426, 47, 5116907100, '2020-04-07', '2020-04-30'),
	(8435, 21, 5117901127, '2020-04-07', '2020-05-01'),
	(8765, 2, 4107948968, '2020-11-03', '2020-12-01'),
	(8766, 3, 524351225, '2020-11-03', '2020-12-01'),
	(8800, 37, 4117013300, '2020-11-15', '2020-12-01'),
	(8930, 6, 6102615629, '2021-02-17', '2021-02-28'),
	(8936, 12, 6102615900, '2021-02-17', '2021-02-28'),
	(9030, 52, 6100663686, '2021-03-28', '2021-03-31'),
	(9085, 53, 6103887463, '2021-04-23', '2021-05-01'),
	(9410, 22, 6100599167, '2021-11-04', '2021-11-30'),
	(9411, 26, 610404380, '2021-10-26', '2021-11-30'),
	(9423, 26, 6104043480, '2021-11-30', '2021-12-31'),
	(9521, 9, 950028987, '2022-08-26', '2022-08-31'),
	(9531, 43, 92202631, '2022-08-27', '2022-08-31'),
	(9555, 29, 6110960924, '2022-12-04', '2022-12-31'),
	(9556, 32, 6107272443, '2022-12-08', '2022-12-31'),
	(9557, 33, 6107261429, '2022-12-13', '2022-12-31'),
	(9558, 34, 6107261586, '2022-12-13', '2022-12-31');

-- Removing temporary table and create final VIEW structure
DROP TABLE IF EXISTS `skaititajs_tirs_view`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `skaititajs_tirs_view` AS select `skaititajs_tirs`.`id` AS `id`,`skaititajs_tirs`.`numurs` AS `numurs`,`skaititajs_tirs`.`garums` AS `garums`,`skaititajs_tirs`.`burts` AS `burts`,`skaititajs_tirs`.`rad_garums` AS `rad_garums`,`skaititajs_tirs`.`datums` AS `datums`,(case when ((`skaititajs_tirs`.`burts` is not null) and (`skaititajs_tirs`.`burts` <> '')) then concat(upper(`skaititajs_tirs`.`burts`),lpad(`skaititajs_tirs`.`numurs`,(`skaititajs_tirs`.`garums` - length(`skaititajs_tirs`.`burts`)),'0')) else lpad(`skaititajs_tirs`.`numurs`,`skaititajs_tirs`.`garums`,'0') end) AS `formatets_numurs` from `skaititajs_tirs`;

/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
