-- --------------------------------------------------------
-- Server OS:                    Win64
-- HeidiSQL Version:             11.0.0.5919
-- --------------------------------------------------------


USE generator;

-- Dumping structure for table generator.no_distribusi_linen
CREATE TABLE IF NOT EXISTS `no_distribusi_linen` (
  `RUANGAN` char(10) NOT NULL,
  `TANGGAL` date NOT NULL,
  `NOMOR` smallint(6) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`RUANGAN`,`TANGGAL`,`NOMOR`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- Data exporting was unselected.

-- Dumping structure for table generator.no_penerimaan_alat_kotor_cssd
CREATE TABLE IF NOT EXISTS `no_penerimaan_alat_kotor_cssd` (
  `RUANGAN` char(10) NOT NULL,
  `TANGGAL` date NOT NULL,
  `NOMOR` smallint(6) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`RUANGAN`,`TANGGAL`,`NOMOR`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- Data exporting was unselected.

-- Dumping structure for table generator.no_penerimaan_linen
CREATE TABLE IF NOT EXISTS `no_penerimaan_linen` (
  `RUANGAN` char(10) NOT NULL,
  `TANGGAL` date NOT NULL,
  `NOMOR` smallint(6) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`RUANGAN`,`TANGGAL`,`NOMOR`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- Data exporting was unselected.

-- Dumping structure for table generator.no_pengembalian_alat_cssd
CREATE TABLE IF NOT EXISTS `no_pengembalian_alat_cssd` (
  `RUANGAN` char(10) NOT NULL,
  `TANGGAL` date NOT NULL,
  `NOMOR` smallint(6) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`RUANGAN`,`TANGGAL`,`NOMOR`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- Data exporting was unselected.

-- Dumping structure for function generator.generateNoDistribusiLinen
DELIMITER //
CREATE FUNCTION `generateNoDistribusiLinen`(
	`PRUANGAN` CHAR(10),
	`PTANGGAL` DATE
) RETURNS varchar(19) CHARSET latin1
    DETERMINISTIC
BEGIN
	INSERT INTO generator.no_distribusi_linen(RUANGAN, TANGGAL)
	VALUES(PRUANGAN, PTANGGAL);
		
	RETURN CONCAT(PRUANGAN, DATE_FORMAT(PTANGGAL, '%y%m%d'), LPAD(LAST_INSERT_ID(), 4, '0'));
END//
DELIMITER ;

-- Dumping structure for function generator.generateNoPenerimaanAlatKotorCssd
DELIMITER //
CREATE FUNCTION `generateNoPenerimaanAlatKotorCssd`(
	`PRUANGAN` CHAR(10)
,
	`PTANGGAL` DATE
) RETURNS varchar(19) CHARSET latin1
    DETERMINISTIC
BEGIN
	INSERT INTO generator.no_penerimaan_alat_kotor_cssd(RUANGAN, TANGGAL)
	VALUES(PRUANGAN, PTANGGAL);
		
	RETURN CONCAT(PRUANGAN, DATE_FORMAT(PTANGGAL, '%y%m%d'), LPAD(LAST_INSERT_ID(), 4, '0'));
END//
DELIMITER ;

-- Dumping structure for function generator.generateNoPenerimaanLinen
DELIMITER //
CREATE FUNCTION `generateNoPenerimaanLinen`(
	`PRUANGAN` CHAR(10),
	`PTANGGAL` DATE
) RETURNS varchar(19) CHARSET latin1
    DETERMINISTIC
BEGIN
	INSERT INTO generator.no_penerimaan_linen(RUANGAN, TANGGAL)
	VALUES(PRUANGAN, PTANGGAL);
		
	RETURN CONCAT(PRUANGAN, DATE_FORMAT(PTANGGAL, '%y%m%d'), LPAD(LAST_INSERT_ID(), 4, '0'));
END//
DELIMITER ;

-- Dumping structure for function generator.generateNoPengembalianAlatCssd
DELIMITER //
CREATE FUNCTION `generateNoPengembalianAlatCssd`(
	`PRUANGAN` CHAR(10),
	`PTANGGAL` DATE
) RETURNS varchar(19) CHARSET latin1
    DETERMINISTIC
BEGIN
	INSERT INTO generator.no_pengembalian_alat_cssd(RUANGAN, TANGGAL)
	VALUES(PRUANGAN, PTANGGAL);
		
	RETURN CONCAT(PRUANGAN, DATE_FORMAT(PTANGGAL, '%y%m%d'), LPAD(LAST_INSERT_ID(), 4, '0'));
END//
DELIMITER ;

