/*
SQLyog Ultimate v11.33 (64 bit)
MySQL - 5.5.21 : Database - Stock
*********************************************************************
*/


/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`Stock` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `Stock`;

/*Table structure for table `MENUSTX` */

DROP TABLE IF EXISTS `MENUSTX`;

CREATE TABLE `MENUSTX` (
  `id` decimal(6,0) DEFAULT NULL,
  `parent_id` decimal(6,0) DEFAULT NULL,
  `title` char(50) DEFAULT NULL,
  `url` char(50) DEFAULT NULL,
  `menu_order` decimal(6,0) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `MENUSTX` */

insert  into `MENUSTX`(`id`,`parent_id`,`title`,`url`,`menu_order`) values ('1','0','Master','#','1'),('2','0','Transaksi','#','1'),('3','0','Laporan','#','1'),('4','1','Barang','barang.php','1'),('5','1','Suplier','suplier.php','2'),('6','1','Customer','customer.php','3'),('9','1','Stok Gdg','stokgd.php','7'),('10','1','Stok Toko','stoktk.php','8'),('16','2','Beli putus','beligd.php','1'),('17','2','Jual putus','jualgd.php','2'),('18','2','Konsinyasi','','3'),('19','18','Kirim toko','kirimtk.php','1'),('20','18','Jual Toko','jualtk.php','2'),('21','18','Retur Toko','returtk.php','3'),('21','3','Harga Beli Terakhir','hargabeli.php','4'),('22','3','Harga Jual Terakhir','hargajual.php','5'),('23','3','Harga Kirim Terakhir','hargatk.php','6'),('901','0','About','#','1'),('902','901','Edit Profile','#','1'),('903','901','About','#','2'),('999','0','Logout','keluar.php','1');

/*Table structure for table `apl_user` */

DROP TABLE IF EXISTS `apl_user`;

CREATE TABLE `apl_user` (
  `KODE_KANTOR` char(4) DEFAULT NULL,
  `USER` char(20) NOT NULL DEFAULT '',
  `PASSWORD` varchar(255) DEFAULT NULL,
  `LEVEL` decimal(5,0) DEFAULT '1',
  `CONFIRMKEY` char(20) NOT NULL,
  `EMAIL` char(30) NOT NULL,
  `FULLNAME` char(40) NOT NULL,
  `KETERANGAN` char(40) DEFAULT NULL,
  `login_session_key` varchar(255) DEFAULT NULL,
  `email_status` varchar(255) DEFAULT NULL,
  `password_expire_date` datetime DEFAULT '2024-03-21 00:00:00',
  `password_reset_key` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`USER`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `apl_user` */

insert  into `apl_user`(`KODE_KANTOR`,`USER`,`PASSWORD`,`LEVEL`,`CONFIRMKEY`,`EMAIL`,`FULLNAME`,`KETERANGAN`,`login_session_key`,`email_status`,`password_expire_date`,`password_reset_key`) values ('001','admin','admin123','0','','','Admin',NULL,NULL,NULL,'2024-03-21 00:00:00',NULL),('001','hendro','hendro123','0','','','Hendro','IT-Superedp',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','direksi','direksi','100','','hendro@sritex.co.id','direksi','direksi',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','fany','fany','14','','fanny.salvado@gmail.com','Fanny','HRD (SAP)',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','anna','anna','12','','','Ana','Akuntansi (SAP)',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','arnold','arnold123','12','','','Arnold','Arnold (SAP)',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','hendro2','hendro123','12','','','Hendro','IT',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','han','hanpur123','12','','','Han Purnomo','Komisaris (SAP)',NULL,NULL,'2024-03-21 00:00:00',NULL),('003','hendro3','hendro123','13','','','Hendro','IT Sragen',NULL,NULL,'2024-03-21 00:00:00',NULL),('002','rina','kla123','15','','','Gwat Liu','Op. Klaten',NULL,NULL,'2024-03-21 00:00:00',NULL),('003','ratih','sragen123','15','','','Ratih','Op. Sragen',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','vera','vera','0','','','Vera','CEO',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','trishia','tris58','11','','fanny.salvado@gmail.com','Fanny','HRD (SAP)',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','umum','umum','14','','','Umum','Umum',NULL,NULL,'2024-03-21 00:00:00',NULL),('001','wawan','wwn34','14','','','Wawan','Kredit',NULL,NULL,'2024-03-21 00:00:00',NULL),('004','novia','novia57','16','','','Novia','Kre. Solo',NULL,NULL,'2024-03-21 00:00:00',NULL),('006','test','$2y$10$DdXAoPFoHmaQU9nTshQALeFsSaBpn4n9u9dgULx3gxbS1i2BvjaHC','1','test','sky_proj@yahoo.com','testing','testing','441a01a1b7d1216843dcdb647522a231',NULL,'2024-03-21 00:00:00',NULL);

/*Table structure for table `barang` */

DROP TABLE IF EXISTS `barang`;

CREATE TABLE `barang` (
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) DEFAULT NULL,
  `jml_stok` int(5) DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`kode_brg`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `barang` */

insert  into `barang`(`kode_brg`,`nama_brg`,`jml_stok`,`keterangan`) values ('0001','TAHU.',0,'dibuat:202108301'),('0002','TEMPE',0,'dibuat:20210830'),('0003','JAMUR',0,'dibuat:20210830'),('0004','WORTEL',0,'dibuat:20210830'),('0006','SINGKONG MANIS',0,''),('0005','SINGKONG BAKAR',0,'-'),('0007','SINGKONG ASIN',0,''),('0008','SPYN TEMPE BAWANG',0,''),('0009','SPYN KENTANG BAWANG',0,''),('0010','TH TAHU ORI',0,''),('0011','TH TAHU PEDAS',0,'');

/*Table structure for table `beligd` */

DROP TABLE IF EXISTS `beligd`;

CREATE TABLE `beligd` (
  `no_beligd` char(5) NOT NULL,
  `tgl_beligd` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_sup` char(5) DEFAULT NULL,
  `nama_sup` char(50) DEFAULT NULL,
  `total` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_beligd`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `beligd` */

insert  into `beligd`(`no_beligd`,`tgl_beligd`,`nota_manual`,`kode_sup`,`nama_sup`,`total`,`keterangan`) values ('00001','2024-09-27',NULL,'001','LUMBA-LUMBA',11800,''),('00002','2024-09-27',NULL,'001','LUMBA-LUMBA',3600,'TAMBAHAN'),('00003','2024-09-28',NULL,'001','LUMBA-LUMBA',1700,''),('00004','2024-09-29',NULL,'001','LUMBA-LUMBA',NULL,'');

/*Table structure for table `beligd_detail` */

DROP TABLE IF EXISTS `beligd_detail`;

CREATE TABLE `beligd_detail` (
  `no_beligd` char(5) NOT NULL,
  `tgl_beligd` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_sup` char(5) NOT NULL,
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) DEFAULT NULL,
  `jml_beligd` int(5) DEFAULT NULL,
  `hrg_beligd` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_beligd`,`kode_sup`,`kode_brg`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `beligd_detail` */

insert  into `beligd_detail`(`no_beligd`,`tgl_beligd`,`nota_manual`,`kode_sup`,`kode_brg`,`nama_brg`,`jml_beligd`,`hrg_beligd`,`keterangan`) values ('00001','2024-09-27',NULL,'001','0001','TAHU.',5,2200,''),('00002','2024-09-27',NULL,'001','0001','TAHU.',3,1200,''),('00001','2024-09-27',NULL,'001','0002','TEMPE',4,200,''),('00003','2024-09-28',NULL,'001','0001','TAHU.',1,1500,''),('00003','2024-09-28',NULL,'001','0002','TEMPE',2,100,'');

/*Table structure for table `customer` */

DROP TABLE IF EXISTS `customer`;

CREATE TABLE `customer` (
  `kode_cust` char(5) NOT NULL,
  `nama_cust` char(50) DEFAULT NULL,
  `alamat_cust` char(50) DEFAULT NULL,
  `kota_cust` char(50) DEFAULT NULL,
  `keterangan` char(150) DEFAULT NULL,
  PRIMARY KEY (`kode_cust`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

/*Data for the table `customer` */

insert  into `customer`(`kode_cust`,`nama_cust`,`alamat_cust`,`kota_cust`,`keterangan`) values ('A001','ATRIA','KARTINI 33','SURAKARTA','LAMA'),('C001','CHARLI','DAWUNG','SURAKARTA','-');

/*Table structure for table `hak` */

DROP TABLE IF EXISTS `hak`;

CREATE TABLE `hak` (
  `ID_HAK` decimal(5,0) NOT NULL DEFAULT '0',
  `OPEN_HAK` tinyint(1) DEFAULT '0',
  `ADD_HAK` tinyint(1) DEFAULT '0',
  `EDIT_HAK` tinyint(1) DEFAULT '0',
  `DEL_HAK` tinyint(1) DEFAULT '0',
  `PRINT_HAK` tinyint(1) DEFAULT '0',
  `BCADD_HAK` tinyint(1) DEFAULT '0',
  `BCDEL_HAK` tinyint(1) DEFAULT '0',
  `KETERANGAN` char(50) DEFAULT NULL,
  PRIMARY KEY (`ID_HAK`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `hak` */

insert  into `hak`(`ID_HAK`,`OPEN_HAK`,`ADD_HAK`,`EDIT_HAK`,`DEL_HAK`,`PRINT_HAK`,`BCADD_HAK`,`BCDEL_HAK`,`KETERANGAN`) values ('2',1,0,0,1,0,0,0,NULL),('4',1,0,1,0,0,0,0,NULL),('5',1,0,1,0,1,0,0,NULL),('6',1,0,1,1,0,0,0,NULL),('7',1,0,1,1,1,0,0,NULL),('8',1,1,0,0,0,0,0,NULL),('9',1,1,0,0,1,0,0,NULL),('10',1,1,0,1,0,0,0,NULL),('11',1,1,0,1,1,0,0,NULL),('12',1,1,1,0,0,0,0,NULL),('13',1,1,1,0,1,0,0,NULL),('14',1,1,1,1,0,0,0,NULL),('15',1,1,1,1,1,0,0,NULL),('0',0,0,0,0,0,0,0,NULL),('17',1,0,0,1,0,1,0,NULL),('3',1,0,0,1,1,0,0,NULL),('1',1,0,0,0,1,0,0,NULL),('16',1,0,0,0,1,1,0,NULL),('18',1,0,0,1,1,1,0,NULL),('19',1,0,1,0,0,1,0,NULL),('20',1,0,1,0,1,1,0,NULL),('21',1,0,1,1,0,1,0,NULL),('22',1,0,1,1,1,1,0,NULL),('23',1,1,0,0,0,1,0,NULL),('24',1,1,0,0,1,1,0,NULL),('25',1,1,0,1,0,1,0,NULL),('26',1,1,0,1,1,1,0,NULL),('27',1,1,1,0,0,1,0,NULL),('28',1,1,1,0,1,1,0,NULL),('29',1,1,1,1,0,1,0,NULL),('30',1,1,1,1,1,1,0,NULL),('31',1,0,0,0,1,0,1,NULL),('32',1,0,0,1,0,0,1,NULL),('33',1,0,0,1,1,0,1,NULL),('34',1,0,1,0,0,0,1,NULL),('35',1,0,1,0,1,0,1,NULL),('36',1,0,1,1,0,0,1,NULL),('37',1,0,1,1,1,0,1,NULL),('38',1,1,0,0,0,0,1,NULL),('39',1,1,0,0,1,0,1,NULL),('40',1,1,0,1,0,0,1,NULL),('41',1,1,0,1,1,0,1,NULL),('42',1,1,1,0,0,0,1,NULL),('43',1,1,1,0,1,0,1,NULL),('44',1,1,1,1,0,0,1,NULL),('45',1,1,1,1,1,0,1,NULL),('46',1,0,0,0,1,1,1,NULL),('47',1,0,0,1,0,1,1,NULL),('48',1,0,0,1,1,1,1,NULL),('49',1,0,1,0,0,1,1,NULL),('50',1,0,1,0,1,1,1,NULL),('51',1,0,1,1,0,1,1,NULL),('52',1,0,1,1,1,1,1,NULL),('53',1,1,0,0,0,1,1,NULL),('54',1,1,0,0,1,1,1,NULL),('55',1,1,0,1,0,1,1,NULL),('56',1,1,0,1,1,1,1,NULL),('57',1,1,1,0,0,1,1,NULL),('58',1,1,1,0,1,1,1,NULL),('59',1,1,1,1,0,1,1,NULL),('60',1,1,1,1,1,1,1,NULL),('61',1,0,0,0,0,0,0,NULL);

/*Table structure for table `hakgroup` */

DROP TABLE IF EXISTS `hakgroup`;

CREATE TABLE `hakgroup` (
  `level` decimal(15,0) NOT NULL DEFAULT '0',
  `nm_file_php` char(40) NOT NULL DEFAULT '',
  `id_hak` decimal(15,0) NOT NULL DEFAULT '0',
  PRIMARY KEY (`level`,`nm_file_php`,`id_hak`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `hakgroup` */

insert  into `hakgroup`(`level`,`nm_file_php`,`id_hak`) values ('0','axbcm.php','60'),('0','axbcmFunc.php','60'),('0','barang.php','60'),('0','barangFunc.php','60'),('0','beligd.php','60'),('0','beligdFunc.php','60'),('0','coba.php','60'),('0','coba2.php','60'),('0','customer.php','60'),('0','customerFunc.php','60'),('0','hargabeli.php','60'),('0','hargabeliFunc.php','60'),('0','hargajual.php','60'),('0','hargajualFunc.php','60'),('0','hargatk.php','60'),('0','hargatkFunc.php','60'),('0','jualgd.php','60'),('0','jualgdFunc.php','60'),('0','jualtk.php','60'),('0','jualtkFunc.php','60'),('0','kirimtk.php','60'),('0','kirimtkFunc.php','60'),('0','pegawai.php','60'),('0','pegawaiFunc.php','60'),('0','regisConfirm(desktop).php','60'),('0','regisConfirm(mobile).php','60'),('0','regisedit(desktop).php','60'),('0','regisedit(mobile).php','60'),('0','regisedit.php','60'),('0','returtk.php','60'),('0','returtkFunc.php','60'),('0','sipendar.php','60'),('0','sipendarFunc.php','60'),('0','stokgd.php','60'),('0','stokgdFunc.php','60'),('0','stoktk.php','60'),('0','stoktkFunc.php','60'),('0','suplier.php','60'),('0','suplierFunc.php','60'),('0','toner.php','60'),('0','tonerfunc.php','60'),('11','absen.php','16'),('11','absenFunc.php','16'),('11','absensum.php','16'),('11','absensumFunc.php','16'),('11','pegawai.php','60'),('11','pegawaiFunc.php','60'),('12','absen.php','1'),('12','absensum.php','1'),('12','akp.php','1'),('12','akpFunc.php','1'),('12','pegawai.php','1'),('12','pegawaiFunc.php','1'),('12','slik.php','1'),('13','absen.php','61'),('13','absenFunc.php','61'),('13','pegawai.php','61'),('13','pegawaiFunc.php','61'),('14','absen.php','1'),('14','absenFunc.php','1'),('15','absen.php','15'),('15','absenFunc.php','15'),('15','absensum.php','1'),('15','absensumFunc.php','1'),('15','pegawai.php','1'),('15','pegawaiFunc.php','1'),('16','slik.php','60'),('16','slikFunc.php','60'),('100','absen.php','1'),('100','axaplppbyr.php','1'),('100','axbcm.php','1'),('100','beacukai.php','1'),('100','bukupesan.php','1'),('100','bukupesanx(desktop).php','1'),('100','bukupesanx(mobile).php','1'),('100','bukupesanx.php','1'),('100','cust.php','1'),('100','item.php','1'),('100','supl.php','1');

/*Table structure for table `historytk` */

DROP TABLE IF EXISTS `historytk`;

CREATE TABLE `historytk` (
  `jenis` char(1) NOT NULL COMMENT 'K=kirim J=jual R=retur',
  `no_toko` char(5) NOT NULL,
  `tgl_toko` date DEFAULT NULL,
  `sup_cust` char(5) NOT NULL,
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) DEFAULT NULL,
  `jml_toko` int(5) DEFAULT NULL,
  `hrg_toko` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`jenis`,`no_toko`,`sup_cust`,`kode_brg`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

/*Data for the table `historytk` */

insert  into `historytk`(`jenis`,`no_toko`,`tgl_toko`,`sup_cust`,`kode_brg`,`nama_brg`,`jml_toko`,`hrg_toko`,`keterangan`) values ('J','00001','2024-10-03','C001','0001','TAHU.',1,999,''),('J','00001','2024-10-03','C001','0002','TEMPE',1,1000,''),('J','00001','0000-00-00','C001','0004','WORTEL',0,1000,''),('J','J0001','2024-05-24','C001','0001','TAHU.',1,999,''),('K','K1','2024-05-20','C001','0001','TAHU.',4,999,'dibuat:20210830'),('K','K1','2024-05-20','C001','0004','WORTEL',3,1000,'dibuat:20210830'),('K','K2','2024-05-21','C001','0001','TAHU',1,201,''),('K','K3','2024-05-22','A001','0001','TAHU.',2,202,'-'),('K','K3','2024-05-22','A001','0003','JAMUR',4,1000,'dibuat:20210830'),('K','K3','2024-05-22','C001','0001','TAHU',2,202,'-'),('R','00001','2024-10-08','C001','0001','TAHU.',1,999,''),('R','00001','2024-10-08','C001','0002','TEMPE',1,1000,'');

/*Table structure for table `jualgd` */

DROP TABLE IF EXISTS `jualgd`;

CREATE TABLE `jualgd` (
  `no_jualgd` char(5) NOT NULL,
  `tgl_jualgd` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_cust` char(5) DEFAULT NULL,
  `nama_cust` char(50) DEFAULT NULL,
  `total` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_jualgd`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `jualgd` */

insert  into `jualgd`(`no_jualgd`,`tgl_jualgd`,`nota_manual`,`kode_cust`,`nama_cust`,`total`,`keterangan`) values ('00001','2024-09-25',NULL,'A001','ATRIA',2001,''),('00002','2024-09-27',NULL,'A001','ATRIA',9001,''),('00003','2024-09-28',NULL,'A001','ATRIA',NULL,'');

/*Table structure for table `jualgd_detail` */

DROP TABLE IF EXISTS `jualgd_detail`;

CREATE TABLE `jualgd_detail` (
  `no_jualgd` char(5) NOT NULL,
  `tgl_jualgd` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_cust` char(5) NOT NULL,
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) DEFAULT NULL,
  `jml_jualgd` int(5) DEFAULT NULL,
  `hrg_jualgd` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_jualgd`,`kode_cust`,`kode_brg`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `jualgd_detail` */

insert  into `jualgd_detail`(`no_jualgd`,`tgl_jualgd`,`nota_manual`,`kode_cust`,`kode_brg`,`nama_brg`,`jml_jualgd`,`hrg_jualgd`,`keterangan`) values ('00001','2024-09-25',NULL,'A001','0001','TAHU.',1,2000,''),('00002','2024-09-27',NULL,'A001','0001','TAHU.',3,3000,''),('00001','2024-09-25',NULL,'A001','0002','TEMPE',1,1,''),('00002','2024-09-27',NULL,'A001','0002','TEMPE',1,1,'');

/*Table structure for table `jualtk` */

DROP TABLE IF EXISTS `jualtk`;

CREATE TABLE `jualtk` (
  `no_jualtk` char(5) NOT NULL,
  `tgl_jualtk` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_cust` char(5) NOT NULL,
  `nama_cust` char(50) DEFAULT NULL,
  `total` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_jualtk`,`kode_cust`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `jualtk` */

insert  into `jualtk`(`no_jualtk`,`tgl_jualtk`,`nota_manual`,`kode_cust`,`nama_cust`,`total`,`keterangan`) values ('00001','2024-10-03','12','C001','CHARLI',1999,''),('00002','2024-10-05',NULL,'A001','ATRIA',NULL,'');

/*Table structure for table `jualtk_detail` */

DROP TABLE IF EXISTS `jualtk_detail`;

CREATE TABLE `jualtk_detail` (
  `no_jualtk` char(5) NOT NULL,
  `tgl_jualtk` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `no_kirimtk` char(5) NOT NULL,
  `kode_cust` char(5) NOT NULL,
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) DEFAULT NULL,
  `jml_jualtk` int(5) DEFAULT NULL,
  `hrg_jualtk` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_jualtk`,`no_kirimtk`,`kode_cust`,`kode_brg`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `jualtk_detail` */

insert  into `jualtk_detail`(`no_jualtk`,`tgl_jualtk`,`nota_manual`,`no_kirimtk`,`kode_cust`,`kode_brg`,`nama_brg`,`jml_jualtk`,`hrg_jualtk`,`keterangan`) values ('00001','2024-10-03','12','K1','C001','0001','TAHU.',1,999,''),('J0001','2024-05-24',NULL,'K2','C001','0002','tempe',2,1000,'dibuat:20210830'),('J0001','2024-05-24',NULL,'K3','C001','0003','jamur',4,1000,'dibuat:20210830'),('J0001','2024-05-24',NULL,'K1','C001','0004','tempe jadah',3,1000,'dibuat:20210830'),('00001','2024-10-03','12','K1','C001','0004','WORTEL',1,1000,'');

/*Table structure for table `kirimtk` */

DROP TABLE IF EXISTS `kirimtk`;

CREATE TABLE `kirimtk` (
  `no_kirimtk` char(5) NOT NULL,
  `tgl_kirimtk` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_cust` char(5) NOT NULL,
  `nama_cust` char(50) DEFAULT NULL,
  `total` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_kirimtk`,`kode_cust`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `kirimtk` */

insert  into `kirimtk`(`no_kirimtk`,`tgl_kirimtk`,`nota_manual`,`kode_cust`,`nama_cust`,`total`,`keterangan`) values ('K1','2024-05-20','112','C001','CHARLI',6996,'dibuat:20210830'),('K2','2024-05-21',NULL,'C001','CHARLI',2201,'dibuat:20210830'),('K3','2024-05-22',NULL,'A001','ATRIA',4404,'dibuat:20210830'),('K4','2024-05-23',NULL,'A001','ATRIA',NULL,'dibuat:20210830');

/*Table structure for table `kirimtk_detail` */

DROP TABLE IF EXISTS `kirimtk_detail`;

CREATE TABLE `kirimtk_detail` (
  `no_kirimtk` char(5) NOT NULL,
  `tgl_kirimtk` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_cust` char(5) NOT NULL,
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) NOT NULL,
  `jml_kirimtk` int(5) DEFAULT NULL,
  `hrg_kirimtk` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_kirimtk`,`kode_cust`,`kode_brg`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `kirimtk_detail` */

insert  into `kirimtk_detail`(`no_kirimtk`,`tgl_kirimtk`,`nota_manual`,`kode_cust`,`kode_brg`,`nama_brg`,`jml_kirimtk`,`hrg_kirimtk`,`keterangan`) values ('K1','2024-05-20','112','C001','0001','TAHU.',4,999,'dibuat:20210830'),('K2','2024-05-21',NULL,'C001','0002','TEMPE',2,1000,'dibuat:20210830'),('K3','2024-05-22',NULL,'A001','0003','JAMUR',4,1000,'dibuat:20210830'),('K1','2024-05-20','112','C001','0004','WORTEL',3,1000,'dibuat:20210830'),('K3','2024-05-22',NULL,'A001','0001','TAHU.',2,202,'-'),('K2','2024-05-21',NULL,'C001','0001','TAHU.',1,201,'');

/*Table structure for table `kota` */

DROP TABLE IF EXISTS `kota`;

CREATE TABLE `kota` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `kode_kantor` char(4) NOT NULL,
  `kota` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;

/*Data for the table `kota` */

insert  into `kota`(`id`,`kode_kantor`,`kota`) values (1,'001','solo'),(2,'002','klaten'),(3,'003','sragen'),(4,'004','boyolali'),(5,'005','magelang');

/*Table structure for table `returtk` */

DROP TABLE IF EXISTS `returtk`;

CREATE TABLE `returtk` (
  `no_returtk` char(5) NOT NULL,
  `tgl_returtk` date DEFAULT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_cust` char(5) DEFAULT NULL,
  `nama_cust` char(50) DEFAULT NULL,
  `total` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_returtk`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `returtk` */

insert  into `returtk`(`no_returtk`,`tgl_returtk`,`nota_manual`,`kode_cust`,`nama_cust`,`total`,`keterangan`) values ('00001','2024-10-08','NK0012','C001','CHARLI',1999,'');

/*Table structure for table `returtk_detail` */

DROP TABLE IF EXISTS `returtk_detail`;

CREATE TABLE `returtk_detail` (
  `no_returtk` char(5) NOT NULL,
  `tgl_returtk` date DEFAULT NULL,
  `no_kirimtk` char(5) NOT NULL,
  `nota_manual` char(8) DEFAULT NULL,
  `kode_cust` char(5) NOT NULL,
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) DEFAULT NULL,
  `jml_returtk` int(5) DEFAULT NULL,
  `hrg_returtk` float DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`no_returtk`,`no_kirimtk`,`kode_cust`,`kode_brg`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `returtk_detail` */

insert  into `returtk_detail`(`no_returtk`,`tgl_returtk`,`no_kirimtk`,`nota_manual`,`kode_cust`,`kode_brg`,`nama_brg`,`jml_returtk`,`hrg_returtk`,`keterangan`) values ('00001','2024-10-08','K1','NK0012','C001','0001','TAHU.',1,999,''),('00001','2024-10-08','K2','NK0012','C001','0002','TEMPE',1,1000,'');

/*Table structure for table `stokgd` */

DROP TABLE IF EXISTS `stokgd`;

CREATE TABLE `stokgd` (
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) DEFAULT NULL,
  `jml_stokgd` int(5) DEFAULT NULL,
  `harga_stokgd` float DEFAULT NULL COMMENT 'harga terakhir beli',
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`kode_brg`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `stokgd` */

insert  into `stokgd`(`kode_brg`,`nama_brg`,`jml_stokgd`,`harga_stokgd`,`keterangan`) values ('0001','TAHU.',1,1200,'-'),('0002','TEMPE',3,1200,'-'),('0004','WORTEL',1,1200,'dibuat:20210830'),('0003','JAMUR',2,1200,'dibuat:20210830');

/*Table structure for table `stoktk` */

DROP TABLE IF EXISTS `stoktk`;

CREATE TABLE `stoktk` (
  `kode_cust` char(5) NOT NULL,
  `kode_brg` char(5) NOT NULL,
  `nama_brg` char(100) DEFAULT NULL,
  `jml_stoktk` int(5) DEFAULT NULL,
  `harga_stoktk` float NOT NULL,
  `keterangan` char(100) DEFAULT NULL,
  PRIMARY KEY (`kode_cust`,`kode_brg`,`harga_stoktk`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `stoktk` */

insert  into `stoktk`(`kode_cust`,`kode_brg`,`nama_brg`,`jml_stoktk`,`harga_stoktk`,`keterangan`) values ('C001','0001','TAHU.',1,201,''),('C001','0001','TAHU.',2,999,'dibuat:20210830'),('C001','0004','WORTEL',2,1000,'dibuat:20210830'),('C001','0002','TEMPE',1,1000,'dibuat:20210830'),('C001','0003','JAMUR',4,1000,'dibuat:20210830'),('C001','0001','TAHU.',2,202,'-');

/*Table structure for table `suplier` */

DROP TABLE IF EXISTS `suplier`;

CREATE TABLE `suplier` (
  `kode_sup` char(5) NOT NULL,
  `nama_sup` char(50) DEFAULT NULL,
  `alamat_sup` char(50) DEFAULT NULL,
  `kota_sup` char(50) DEFAULT NULL,
  `keterangan` char(150) DEFAULT NULL,
  PRIMARY KEY (`kode_sup`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

/*Data for the table `suplier` */

insert  into `suplier`(`kode_sup`,`nama_sup`,`alamat_sup`,`kota_sup`,`keterangan`) values ('001','LUMBA-LUMBA','','MALANG',''),('002','SOPONYONO','','MALANG',''),('003','KIKY','','MALANG',''),('004','TOHIR','','MALANG',''),('005','MAC CHEESE','','MALANG','');

/*Table structure for table `test` */

DROP TABLE IF EXISTS `test`;

CREATE TABLE `test` (
  `no` char(5) DEFAULT NULL,
  `tgl` date DEFAULT NULL,
  `jml` decimal(5,0) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

/*Data for the table `test` */

insert  into `test`(`no`,`tgl`,`jml`) values (NULL,'2024-05-21',NULL);

/*Table structure for table `test2` */

DROP TABLE IF EXISTS `test2`;

CREATE TABLE `test2` (
  `id_beligd` int(5) DEFAULT NULL,
  `no_beligd` char(5) NOT NULL DEFAULT '',
  `tgl_beligd` date NOT NULL DEFAULT '0000-00-00',
  `kode_sup` char(5) NOT NULL DEFAULT '',
  `nama_sup` char(50) DEFAULT NULL,
  `keterangan` char(100) DEFAULT NULL
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

/*Data for the table `test2` */

insert  into `test2`(`id_beligd`,`no_beligd`,`tgl_beligd`,`kode_sup`,`nama_sup`,`keterangan`) values (1,'1','2023-11-28','C001','Vera','dibuat:20210830'),(2,'2','2023-11-30','B001','Bagus','dibuat:20210830'),(3,'3','2023-12-01','A002','Ani','dibuat:20210830'),(4,'4','2023-12-11','A001','Agus','dibuat:20210830'),(5,'00005','2023-12-20','001','Lumba-lumba','S'),(6,'00006','2023-12-14','005','Mac Cheese','TES'),(7,'00007','2023-12-27','003','Kiky','123');

/* Trigger structure for table `barang` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `barang_update` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `barang_update` AFTER UPDATE ON `barang` FOR EACH ROW BEGIN
	update `stock`.`beligd_detail`  SET `nama_brg` = new.nama_brg WHERE `kode_brg` = new.kode_brg ;
	UPDATE `stock`.`jualgd_detail`  SET `nama_brg` = new.nama_brg WHERE `kode_brg` = new.kode_brg ;	
	UPDATE `stock`.`kirimtk_detail` SET `nama_brg` = new.nama_brg WHERE `kode_brg` = new.kode_brg ;
	UPDATE `stock`.`stokgd` 	SET `nama_brg` = new.nama_brg WHERE `kode_brg` = new.kode_brg ;
	UPDATE `stock`.`stoktk` 	SET `nama_brg` = new.nama_brg WHERE `kode_brg` = new.kode_brg ;	
	UPDATE `stock`.`jualtk_detail`  SET `nama_brg` = new.nama_brg WHERE `kode_brg` = new.kode_brg ;
	/*
	UPDATE `stock`.`returtk_detail` SET `nama_brg` = new.nama_brg WHERE `kode_brg` = new.kode_brg ;
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `beligd_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `beligddetail_add` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `beligddetail_add` AFTER INSERT ON `beligd_detail` FOR EACH ROW BEGIN
	INSERT IGNORE stokgd (kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_beligd, new.hrg_beligd, new.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stokgd=jml_stokgd+new.jml_beligd,
	harga_stokgd=new.hrg_beligd;        
	
  
	/*
	INSERT IGNORE barang (kode_brg,nama_brg,jml_stok) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_beligd) 
	ON DUPLICATE KEY UPDATE 
	jml_stok=jml_stok+new.jml_beligd;        
	*/
	/*
	UPDATE barang
	SET
	  jml_stok=jml_stok+new.jml_beligd
	WHERE kode_brg=new.kode_brg; 	
	-- beli stokgd
	INSERT IGNORE stokgd (tipe,kode_sup,kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES ('B',new.kode_sup,new.kode_brg,new.nama_brg,new.jml_beligd,new.hrg_beligd,new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stokgd=jml_stokgd+new.jml_beligd,
	keterangan=new.keterangan;        
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `beligd_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `beligddetail_update` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `beligddetail_update` BEFORE UPDATE ON `beligd_detail` FOR EACH ROW BEGIN
	UPDATE `stock`.`stokgd` set 
	  jml_stokgd=jml_stokgd-old.jml_beligd+new.jml_beligd,
	  harga_stokgd=new.hrg_beligd;
	
    /*	
	INSERT IGNORE barang (kode_brg,nama_brg,jml_stok) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_beligd) 
	ON DUPLICATE KEY UPDATE 
	jml_stok=jml_stok+new.jml_beligd;        
	*/
	/*
	UPDATE barang
	SET
	  jml_stok=jml_stok+new.jml_beligd
	WHERE kode_brg=new.kode_brg; 	
	-- beli stokgd
	INSERT IGNORE stokgd (tipe,kode_sup,kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES ('B',new.kode_sup,new.kode_brg,new.nama_brg,new.jml_beligd,new.hrg_beligd,new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stokgd=jml_stokgd+new.jml_beligd,
	keterangan=new.keterangan;        
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `beligd_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `beligddetail_del` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `beligddetail_del` BEFORE DELETE ON `beligd_detail` FOR EACH ROW BEGIN
	UPDATE `stock`.`stokgd` SET 
	  jml_stokgd=jml_stokgd-old.jml_beligd;
      
        /*
	UPDATE barang
	SET
	  jml_stok=jml_stok-old.jml_beligd
	WHERE kode_brg=old.kode_brg;        
	-- Hitung stok
	UPDATE stokgd
	SET
	jml_stokgd=jml_stokgd-old.jml_beligd
	WHERE tipe='B' and kode_sup=old.kode_sup AND kode_brg=old.kode_brg and harga_stokgd=old.hrg_beligd;        
	*/
	/* hapus jika jml_stokgd sdh 0 
	DELETE FROM stokgd
	WHERE kode_sup=old.kode_sup AND kode_brg=old.kode_brg AND jml_stokgd=0 ;	
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `customer` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `customer_update` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `customer_update` AFTER UPDATE ON `customer` FOR EACH ROW BEGIN
	UPDATE `stock`.`kirimtk` SET `nama_cust` = new.nama_cust WHERE `kode_cust` = new.kode_cust ;
	UPDATE `stock`.`stoktk` SET `nama_cust` = new.nama_cust WHERE `kode_cust` = new.kode_cust ;
	/*
	UPDATE `stock`.`jualtk`  SET `nama_cust` = new.nama_cust WHERE `kode_cust` = new.kode_cust ;
	UPDATE `stock`.`returtk` SET `nama_cust` = new.nama_cust WHERE `kode_cust` = new.kode_cust ;
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `jualgd_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `jualgddetail_add` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `jualgddetail_add` AFTER INSERT ON `jualgd_detail` FOR EACH ROW BEGIN
	UPDATE `stock`.`stokgd` SET 
	  jml_stokgd=jml_stokgd-new.jml_jualgd;
	    
        /*
	UPDATE barang
	SET
	  jml_stok=jml_stok-new.jml_jualgd
	WHERE kode_brg=new.kode_brg; 		   	
	-- jual stokgd
	INSERT IGNORE stokgd (tipe,kode_sup,kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES ('J',new.kode_cust,new.kode_brg,new.nama_brg,new.jml_jualgd,new.hrg_jualgd,new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stokgd=jml_stokgd-new.jml_jualgd,
	keterangan=new.keterangan;        	
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `jualgd_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `jualgddetail_update` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `jualgddetail_update` AFTER UPDATE ON `jualgd_detail` FOR EACH ROW BEGIN		
    	UPDATE `stock`.`stokgd` SET 
	  jml_stokgd=jml_stokgd+old.jml_jualgd-new.jml_jualgd;
    /*
	UPDATE barang
	SET
	  jml_stok=jml_stok+old.jml_jualgd-new.jml_jualgd
	WHERE kode_brg=new.kode_brg;        	
	-- hitung stok	
	-- UPDATE stokgd
	-- SET
	--  jml_stokgd=jml_stokgd-old.jml_jualgd+new.jml_jualgd,
	--  keterangan=new.keterangan
	-- WHERE jenis='J' AND kode_cust=new.kode_cust AND kode_brg=new.kode_brg AND harga_stokgd=new.hrg_jualgd; 		
     */     
     /*
	INSERT IGNORE stokgd (tipe,kode_cust,kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES ('J',new.kode_cust,new.kode_brg,new.nama_brg,new.jml_jualgd,new.hrg_jualgd,new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stokgd=jml_stokgd+old.jml_jualgd-new.jml_jualgd,
	harga_stokgd=new.hrg_jualgd,
	keterangan=new.keterangan;  
     */
	
	
    END */$$


DELIMITER ;

/* Trigger structure for table `jualgd_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `jualgddetail_del` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `jualgddetail_del` BEFORE DELETE ON `jualgd_detail` FOR EACH ROW BEGIN
	 UPDATE `stock`.`stokgd` SET 
	   jml_stokgd=jml_stokgd+old.jml_jualgd;
			      
        /*
	UPDATE barang
	SET
	  jml_stok=jml_stok-old.jml_beligd
	WHERE kode_brg=old.kode_brg;        
	-- Hitung stok
	UPDATE stokgd
	SET
	jml_stokgd=jml_stokgd-old.jml_beligd
	WHERE tipe='B' and kode_sup=old.kode_sup AND kode_brg=old.kode_brg and harga_stokgd=old.hrg_beligd;        
	*/
	/* hapus jika jml_stokgd sdh 0 
	DELETE FROM stokgd
	WHERE kode_sup=old.kode_sup AND kode_brg=old.kode_brg AND jml_stokgd=0 ;	
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `jualtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `jualtkdetail_add` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `jualtkdetail_add` AFTER INSERT ON `jualtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (new.kode_cust,new.kode_brg,new.nama_brg,new.jml_jualtk, new.hrg_jualtk, new.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stoktk=jml_stoktk-new.jml_jualtk; -- , harga_stoktk=new.hrg_jualtk; -- , keterangan=new.keterangan;
		
	-- Update hisotrytk
	INSERT IGNORE `historytk` (jenis, no_toko, sup_cust, tgl_toko, kode_brg, nama_brg, jml_toko, hrg_toko, keterangan)
	VALUES ("J", new.no_jualtk,new.kode_cust,new.tgl_jualtk,new.kode_brg,new.nama_brg,new.jml_jualtk,new.hrg_jualtk,new.keterangan);
	
    END */$$


DELIMITER ;

/* Trigger structure for table `jualtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `jualtkdetail_update` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `jualtkdetail_update` BEFORE UPDATE ON `jualtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (old.kode_cust,old.kode_brg,old.nama_brg,old.jml_jualtk, old.hrg_jualtk, old.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stoktk=jml_stoktk+old.jml_jualtk-new.jml_jualtk;
		
	-- Update hisotrytk
	INSERT IGNORE `historytk` (jenis, no_toko, sup_cust, tgl_toko, kode_brg, nama_brg, jml_toko, hrg_toko, keterangan)
	VALUES ("J", new.no_jualtk,new.kode_cust,new.tgl_jualtk,new.kode_brg,new.nama_brg,new.jml_jualtk,new.hrg_jualtk,new.keterangan)
	ON DUPLICATE KEY UPDATE 	
	jml_toko=jml_toko+old.jml_jualtk-new.jml_jualtk; -- , harga_stoktk=new.hrg_jualtk; -- , keterangan=new.keterangan;
		  	
    END */$$


DELIMITER ;

/* Trigger structure for table `jualtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `jualtkdetail_del` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `jualtkdetail_del` BEFORE DELETE ON `jualtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (old.kode_cust,old.kode_brg,old.nama_brg,old.jml_jualtk, old.hrg_jualtk, old.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stoktk=jml_stoktk+old.jml_jualtk; -- , harga_stoktk=new.hrg_jualtk; -- , keterangan=new.keterangan;
		
	-- Update historytk (hapus history)
	DELETE FROM historytk
	WHERE `jenis` = "J" 
	  AND `no_toko` = old.no_kirimtk 
	  AND `sup_cust` = old.kode_cust 
	  AND `kode_brg` = old.kode_brg;	
    END */$$


DELIMITER ;

/* Trigger structure for table `kirimtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `kirimtkdetail_add` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `kirimtkdetail_add` AFTER INSERT ON `kirimtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (no_kirimtk,kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (new.no_kirimtk,new.kode_cust,new.kode_brg,new.nama_brg,new.jml_kirimtk, new.hrg_kirimtk, new.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stoktk=jml_stoktk+new.jml_kirimtk,
	harga_stoktk=new.hrg_kirimtk,
	keterangan=new.keterangan;
	
	-- Update Stok gudang
	INSERT IGNORE stokgd (kode_brg,nama_brg,jml_stokgd) 
	VALUES (new.kode_brg,new.nama_brg,-new.jml_kirimtk) 
	ON DUPLICATE KEY UPDATE 	
	jml_stokgd=jml_stokgd-new.jml_kirimtk;
	
	-- Update hisotrytk
	INSERT IGNORE `historytk` (jenis, no_toko, sup_cust, tgl_toko, kode_brg, nama_brg, jml_toko, hrg_toko, keterangan)
	VALUES ("K",new.no_kirimtk,new.kode_cust,new.tgl_kirimtk,new.kode_brg,new.nama_brg,new.jml_kirimtk,new.hrg_kirimtk,new.keterangan);
	
	/*
	INSERT IGNORE barang (kode_brg,nama_brg,jml_stok) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_kirimtk) 
	ON DUPLICATE KEY UPDATE 
	jml_stok=jml_stok+new.jml_kirimtk;        
	*/
	/*
	UPDATE barang
	SET
	  jml_stok=jml_stok+new.jml_kirimtk
	WHERE kode_brg=new.kode_brg; 	
	-- beli stoktk
	INSERT IGNORE stoktk (tipe,kode_sup,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES ('B',new.kode_sup,new.kode_brg,new.nama_brg,new.jml_kirimtk,new.hrg_kirimtk,new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stoktk=jml_stoktk+new.jml_kirimtk,
	keterangan=new.keterangan;        
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `kirimtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `kirimtkdetail_update` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `kirimtkdetail_update` BEFORE UPDATE ON `kirimtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (old.kode_cust,old.kode_brg,old.nama_brg,old.jml_kirimtk,old.hrg_kirimtk,old.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stoktk=jml_stoktk-old.jml_kirimtk+new.jml_kirimtk,
	harga_stoktk=new.hrg_kirimtk,
	keterangan=new.keterangan;
	
	-- Update Stok gudang
	INSERT IGNORE stokgd (kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES (old.kode_brg,old.nama_brg,old.jml_kirimtk,old.hrg_kirimtk,old.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stokgd=jml_stokgd+old.jml_kirimtk-new.jml_kirimtk;
	-- Update hisotrytk (hanya terhadap stoktk)
	INSERT IGNORE `historytk` (jenis, no_toko, sup_cust, tgl_toko, kode_brg, nama_brg, jml_toko, hrg_toko, keterangan)
	VALUES ("K",new.no_kirimtk, new.kode_cust, new.tgl_kirimtk,new.kode_brg,new.nama_brg,new.jml_kirimtk,new.hrg_kirimtk,new.keterangan)
	ON DUPLICATE KEY UPDATE 	
	jml_toko=new.jml_kirimtk,
	hrg_toko=new.hrg_kirimtk;
	
	
    /*	
	INSERT IGNORE barang (kode_brg,nama_brg,jml_stok) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_kirimtk) 
	ON DUPLICATE KEY UPDATE 
	jml_stok=jml_stok+new.jml_kirimtk;        
	*/
	/*
	UPDATE barang
	SET
	  jml_stok=jml_stok+new.jml_kirimtk
	WHERE kode_brg=new.kode_brg; 	
	-- beli stoktk
	INSERT IGNORE stoktk (tipe,kode_sup,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES ('B',new.kode_sup,new.kode_brg,new.nama_brg,new.jml_kirimtk,new.hrg_kirimtk,new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stoktk=jml_stoktk+new.jml_kirimtk,
	keterangan=new.keterangan;        
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `kirimtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `kirimtkdetail_del` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `kirimtkdetail_del` BEFORE DELETE ON `kirimtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (old.kode_cust,old.kode_brg,old.nama_brg,old.jml_kirimtk,old.hrg_kirimtk,old.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stoktk=jml_stoktk-old.jml_kirimtk;
	
	-- Update Stok gudang
	INSERT IGNORE stokgd (kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES (old.kode_brg,old.nama_brg,old.jml_kirimtk,old.hrg_kirimtk,old.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stokgd=jml_stokgd+old.jml_kirimtk;
	
	-- Update historytk (hapus history)
	DELETE FROM historytk
	WHERE `jenis` = "K" 
	  AND `no_toko` = old.no_kirimtk 
	  AND `sup_cust` = old.kode_cust 
	  AND `kode_brg` = old.kode_brg;	
	  
	/*
	INSERT IGNORE barang (kode_brg,nama_brg,jml_stok) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_kirimtk) 
	ON DUPLICATE KEY UPDATE 
	jml_stok=jml_stok+new.jml_kirimtk;        
	*/
	/*
	UPDATE barang
	SET
	  jml_stok=jml_stok+new.jml_kirimtk
	WHERE kode_brg=new.kode_brg; 	
	-- beli stoktk
	INSERT IGNORE stoktk (tipe,kode_sup,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES ('B',new.kode_sup,new.kode_brg,new.nama_brg,new.jml_kirimtk,new.hrg_kirimtk,new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stoktk=jml_stoktk+new.jml_kirimtk,
	keterangan=new.keterangan;        
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `returtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `returtkdetail_add` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `returtkdetail_add` AFTER INSERT ON `returtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (new.kode_cust,new.kode_brg,new.nama_brg,new.jml_returtk, new.hrg_returtk, new.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stoktk=jml_stoktk-new.jml_returtk; -- , harga_stoktk=new.hrg_returtk; -- , keterangan=new.keterangan;
	
	-- Update Stok gudang
	INSERT IGNORE stokgd (kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_returtk, new.hrg_returtk, new.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stokgd=jml_stokgd+new.jml_returtk;   
		
	-- Update hisotrytk
	INSERT IGNORE `historytk` (jenis, no_toko, sup_cust, tgl_toko, kode_brg, nama_brg, jml_toko, hrg_toko, keterangan)
	VALUES ("R", new.no_returtk,new.kode_cust,new.tgl_returtk,new.kode_brg,new.nama_brg,new.jml_returtk,new.hrg_returtk,new.keterangan);
	
    END */$$


DELIMITER ;

/* Trigger structure for table `returtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `returtkdetail_update` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `returtkdetail_update` BEFORE UPDATE ON `returtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (new.kode_cust,new.kode_brg,new.nama_brg,new.jml_returtk, new.hrg_returtk, new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stoktk=jml_stoktk+old.jml_returtk-new.jml_returtk;
	
	-- Update Stok gudang
	INSERT IGNORE stokgd (kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_returtk, new.hrg_returtk, new.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stokgd=jml_stokgd-old.jml_returtk+new.jml_returtk;        
		
	-- Update hisotrytk
	INSERT IGNORE `historytk` (jenis, no_toko, sup_cust, tgl_toko, kode_brg, nama_brg, jml_toko, hrg_toko, keterangan)
	VALUES ("J", new.no_returtk,new.kode_cust,new.tgl_returtk,new.kode_brg,new.nama_brg,new.jml_returtk,new.hrg_returtk,new.keterangan)
	ON DUPLICATE KEY UPDATE 	
	jml_toko=jml_toko+old.jml_returtk-new.jml_returtk; -- , harga_stoktk=new.hrg_returtk; -- , keterangan=new.keterangan;
		  	
    END */$$


DELIMITER ;

/* Trigger structure for table `returtk_detail` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `returtkdetail_del` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `returtkdetail_del` BEFORE DELETE ON `returtk_detail` FOR EACH ROW BEGIN
        -- Update Stok toko dan harga toko
	INSERT IGNORE stoktk (kode_cust,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES (old.kode_cust,old.kode_brg,old.nama_brg,old.jml_returtk,old.hrg_returtk,old.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stoktk=jml_stoktk+old.jml_returtk;
	
	-- Update Stok gudang
	INSERT IGNORE stokgd (kode_brg,nama_brg,jml_stokgd,harga_stokgd,keterangan) 
	VALUES (old.kode_brg,old.nama_brg,old.jml_returtk,old.hrg_returtk,old.keterangan) 
	ON DUPLICATE KEY UPDATE 	
	jml_stokgd=jml_stokgd-old.jml_returtk;
	
	-- Update historytk (hapus history)
	DELETE FROM historytk
	WHERE `jenis` = "R" 
	  AND `no_toko` = old.no_returtk 
	  AND `sup_cust` = old.kode_cust 
	  AND `kode_brg` = old.kode_brg;	
	  
	/*
	INSERT IGNORE barang (kode_brg,nama_brg,jml_stok) 
	VALUES (new.kode_brg,new.nama_brg,new.jml_returtk) 
	ON DUPLICATE KEY UPDATE 
	jml_stok=jml_stok+new.jml_returtk;        
	*/
	/*
	UPDATE barang
	SET
	  jml_stok=jml_stok+new.jml_returtk
	WHERE kode_brg=new.kode_brg; 	
	-- beli stoktk
	INSERT IGNORE stoktk (tipe,kode_sup,kode_brg,nama_brg,jml_stoktk,harga_stoktk,keterangan) 
	VALUES ('B',new.kode_sup,new.kode_brg,new.nama_brg,new.jml_returtk,new.hrg_returtk,new.keterangan) 
	ON DUPLICATE KEY UPDATE 
	jml_stoktk=jml_stoktk+new.jml_returtk,
	keterangan=new.keterangan;        
	*/
    END */$$


DELIMITER ;

/* Trigger structure for table `suplier` */

DELIMITER $$

/*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `suplier_update` */$$

/*!50003 CREATE */ /*!50017 DEFINER = 'root'@'%' */ /*!50003 TRIGGER `suplier_update` AFTER UPDATE ON `suplier` FOR EACH ROW BEGIN
	update `stock`.`beligd` SET `nama_sup` = new.nama_sup WHERE `kode_sup` = new.kode_sup ;
	UPDATE `stock`.`stokgd` SET `nama_sup` = new.nama_sup WHERE `kode_sup` = new.kode_sup ;
    END */$$


DELIMITER ;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
