(59446,62186629,1564496262,2344,4,55,0,0,0,12.7119,1.14,1.14,0,0,NULL,0,NULL,0,1,15,0,'2020-06-23 19:00:21','2020-06-23 19:00:21'),(59447,60731574,1564496262,3601,16,106,0,0,0,81.3559,7.32,7.32,0,0,NULL,0,NULL,0,2,96,0,'2020-06-23 19:06:07','2020-06-23 19:06:07'),(59448,63535828,149152684875,374,1,2,0,0,0,18,0,0,0,0,NULL,0,NULL,0,1,18,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59449,63535828,149152684875,367,1,2,0,0,0,14,0,0,0,0,NULL,0,NULL,0,2,14,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59450,63535828,149152684875,359,1,2,0,0,0,13,0,0,0,0,NULL,0,NULL,0,1,13,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59451,63535828,149152684875,360,1,2,0,0,0,104,0,0,0,0,NULL,0,NULL,0,4,104,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59452,63535828,149152684875,393,1,2,0,0,0,22,0,0,0,0,NULL,0,NULL,0,1,22,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59453,63535828,149152684875,378,1,2,0,0,0,10,0,0,0,0,NULL,0,NULL,0,1,10,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59454,63535828,149152684875,551,1,2,0,0,0,25,0,0,0,0,NULL,0,NULL,0,1,25,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59455,63535828,149152684875,1713,1,2,0,0,0,38,0,0,0,0,NULL,0,NULL,0,2,38,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59456,63535828,149152684875,2193,1,2,0,0,0,6,0,0,0,0,NULL,0,NULL,0,1,6,0,'2020-06-23 19:56:35','2020-06-23 19:56:35'),(59457,62722995,71759568988,1973,8,36,0,0,0,164,0,0,0,0,NULL,0,NULL,0,2,164,0,'2020-06-23 20:30:27','2020-06-23 20:30:27'),(59458,62722995,71759568988,2434,4,23,0,0,0,49.1525,4.42,4.42,0,0,NULL,0,NULL,0,2,58,0,'2020-06-23 20:30:27','2020-06-23 20:30:27'),(59459,62722995,71759568988,2431,4,23,0,0,0,20.339,1.83,1.83,0,0,NULL,0,NULL,0,1,24,0,'2020-06-23 20:30:27','2020-06-23 20:30:27'),(59460,64496961,71759568988,2431,4,23,0,0,0,20.339,1.83,1.83,0,0,NULL,0,NULL,0,1,24,0,'2020-06-23 20:42:44','2020-06-23 20:42:44'),(59461,64496961,71759568988,2434,4,23,0,0,0,49.1525,4.42,4.42,0,0,NULL,0,NULL,0,2,58,0,'2020-06-23 20:42:44','2020-06-23 20:42:44'),(59462,64496961,71759568988,1973,8,36,0,0,0,82,0,0,0,0,NULL,0,NULL,0,1,82,0,'2020-06-23 20:42:44','2020-06-23 20:42:44'),(59463,64496961,71759568988,883,8,39,0,0,0,49.1071,2.95,2.95,0,0,NULL,0,NULL,0,1,55,0,'2020-06-23 20:42:44','2020-06-23 20:42:44'),(59464,62031451,948268558416,1042,3,10,0,0,0,255,0,0,0,0,NULL,0,NULL,0,1,255,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59465,62031451,948268558416,1044,3,10,0,0,0,128,0,0,0,0,NULL,0,NULL,0,2,128,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59466,62031451,948268558416,1670,4,23,0,0,0,35.5932,3.2,3.2,0,0,NULL,0,NULL,0,1,42,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59467,62031451,948268558416,370,1,2,0,0,0,14,0,0,0,0,NULL,0,NULL,0,1,14,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59468,62031451,948268558416,2271,4,23,0,0,0,25.4237,2.29,2.29,0,0,NULL,0,NULL,0,2,30,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59469,62031451,948268558416,369,1,2,0,0,0,14,0,0,0,0,NULL,0,NULL,0,1,14,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59470,62031451,948268558416,2550,4,23,0,0,0,25.4237,2.29,2.29,0,0,NULL,0,NULL,0,2,30,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59471,62031451,948268558416,403,1,2,0,0,0,9,0,0,0,0,NULL,0,NULL,0,1,9,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59472,62031451,948268558416,364,1,2,0,0,0,39,0,0,0,0,NULL,0,NULL,0,1,39,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59473,62031451,948268558416,382,1,2,0,0,0,20,0,0,0,0,NULL,0,NULL,0,1,20,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59474,62031451,948268558416,373,1,2,0,0,0,10,0,0,0,0,NULL,0,NULL,0,1,10,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59475,62031451,948268558416,1214,2,84,0,0,0,44,0,0,0,0,NULL,0,NULL,0,2,44,0,'2020-06-23 21:14:20','2020-06-23 21:14:20'),(59476,61319140,87646508773,1450,4,24,0,0,0,43.75,2.63,2.63,0,0,NULL,0,NULL,0,1,49,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59477,61319140,87646508773,1027,3,9,0,0,0,40,2,2,0,0,NULL,0,NULL,0,2,44,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59478,61319140,87646508773,381,1,2,0,0,0,30,0,0,0,0,NULL,0,NULL,0,2,30,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59479,61319140,87646508773,364,1,2,0,0,0,37,0,0,0,0,NULL,0,NULL,0,1,37,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59480,61319140,87646508773,361,1,2,0,0,0,42,0,0,0,0,NULL,0,NULL,0,2,42,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59481,61319140,87646508773,378,1,2,0,0,0,9,0,0,0,0,NULL,0,NULL,0,1,9,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59482,61319140,87646508773,2035,3,8,0,0,0,74.2857,1.86,1.86,0,0,NULL,0,NULL,0,2,78,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59484,61319140,87646508773,2027,1,44,0,0,0,54,0,0,0,0,NULL,0,NULL,0,3,54,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59485,61319140,87646508773,369,1,2,0,0,0,26,0,0,0,0,NULL,0,NULL,0,2,26,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59486,61319140,87646508773,393,1,2,0,0,0,20,0,0,0,0,NULL,0,NULL,0,1,20,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59487,61319140,87646508773,367,1,2,0,0,0,6,0,0,0,0,NULL,0,NULL,0,1,6,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59489,61319140,87646508773,359,1,2,0,0,0,36,0,0,0,0,NULL,0,NULL,0,3,36,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59490,61319140,87646508773,2193,1,2,0,0,0,6,0,0,0,0,NULL,0,NULL,0,1,6,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59491,61319140,87646508773,389,1,2,0,0,0,16,0,0,0,0,NULL,0,NULL,0,1,16,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59492,61319140,87646508773,2354,6,19,0,0,0,47.4576,4.27,4.27,0,0,NULL,0,NULL,0,1,56,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59493,61319140,87646508773,392,1,2,0,0,0,17,0,0,0,0,NULL,0,NULL,0,1,17,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59494,61319140,87646508773,290,2,11,0,0,0,361.905,9.05,9.05,0,0,NULL,0,NULL,0,1,380,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59495,61319140,87646508773,370,1,2,0,0,0,13,0,0,0,0,NULL,0,NULL,0,1,13,0,'2020-06-23 23:14:13','2020-06-23 23:14:13'),(59496,64085542,208787558925,378,1,2,0,0,0,10,0,0,0,0,NULL,0,NULL,0,1,10,0,'2020-06-24 00:11:40','2020-06-24 00:11:40'),(59497,64085542,208787558925,367,1,2,0,0,0,7,0,0,0,0,NULL,0,NULL,0,1,7,0,'2020-06-24 00:11:40','2020-06-24 00:11:40'),(59498,64085542,208787558925,1733,9,31,0,0,0,83.8983,7.55,7.55,0,0,NULL,0,NULL,0,1,99,0,'2020-06-24 00:11:40','2020-06-24 00:11:40'),(59499,64085542,208787558925,2538,9,31,0,0,0,16.9492,1.53,1.53,0,0,NULL,0,NULL,0,1,20,0,'2020-06-24 00:11:40','2020-06-24 00:11:40'),(59500,64085542,208787558925,1027,3,9,0,0,0,20,1,1,0,0,NULL,0,NULL,0,1,22,0,'2020-06-24 00:11:40','2020-06-24 00:11:40'),(59501,64085542,208787558925,370,1,2,0,0,0,14,0,0,0,0,NULL,0,NULL,0,1,14,0,'2020-06-24 00:11:40','2020-06-24 00:11:40'),(59502,64085542,208787558925,369,1,2,0,0,0,14,0,0,0,0,NULL,0,NULL,0,1,14,0,'2020-06-24 00:11:40','2020-06-24 00:11:40'),(59503,64085542,208787558925,360,1,2,0,0,0,26,0,0,0,0,NULL,0,NULL,0,1,26,0,'2020-06-24 00:11:40','2020-06-24 00:11:40'),(59504,6044346,550145100785,1050,3,10,0,0,0,215,0,0,0,0,NULL,0,NULL,0,1,215,0,'2020-06-24 00:44:04','2020-06-24 00:44:04'),(59505,65371685,150379639967,946,4,22,0,0,0,154.237,13.88,13.88,0,0,NULL,0,NULL,0,1,182,0,'2020-06-24 01:30:53','2020-06-24 01:30:53'),(59506,65371685,150379639967,307,2,11,0,0,0,361.905,9.05,9.05,0,0,NULL,0,NULL,0,1,380,0,'2020-06-24 01:30:53','2020-06-24 01:30:53'),(59507,65929231,137176320353,2035,3,8,3,3,0,76.1905,1.90476,1.90476,0,0,'0',0,'0',0,2,80,0,'2020-06-24 07:54:35','2020-06-24 07:54:35'),(59508,65929231,137176320353,2042,3,43,3,3,0,17.1429,0.428571,0.428571,0,0,'0',0,'0',0,1,18,0,'2020-06-24 07:55:32','2020-06-24 07:55:32'),(59509,65929231,137176320353,2228,3,10,0,0,0,23,0,0,0,0,'0',0,'0',0,1,23,0,'2020-06-24 07:55:47','2020-06-24 07:55:47'),(59510,60753319,59404240545,980,5,28,0,0,0,499,0,0,0,0,NULL,0,NULL,0,1,499,0,'2020-06-24 08:10:07','2020-06-24 08:10:07'),(59511,64069304,59404240545,980,5,28,0,0,0,499,0,0,0,0,NULL,0,NULL,0,1,499,0,'2020-06-24 08:34:40','2020-06-24 08:34:40'),(59512,62620218,99375246237,3576,1,2,0,0,0,11,0,0,0,0,NULL,0,NULL,0,1,11,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59513,62620218,99375246237,374,1,2,0,0,0,36,0,0,0,0,NULL,0,NULL,0,2,36,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59514,62620218,99375246237,364,1,2,0,0,0,39,0,0,0,0,NULL,0,NULL,0,1,39,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59515,62620218,99375246237,395,1,2,0,0,0,18,0,0,0,0,NULL,0,NULL,0,2,18,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59516,62620218,99375246237,1214,2,84,0,0,0,66,0,0,0,0,NULL,0,NULL,0,3,66,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59517,62620218,99375246237,551,1,2,0,0,0,25,0,0,0,0,NULL,0,NULL,0,1,25,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59518,62620218,99375246237,408,1,2,0,0,0,8,0,0,0,0,NULL,0,NULL,0,1,8,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59519,62620218,99375246237,360,1,2,0,0,0,52,0,0,0,0,NULL,0,NULL,0,2,52,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59520,62620218,99375246237,1220,2,11,0,0,0,61.9048,1.55,1.55,0,0,NULL,0,NULL,0,1,65,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59521,62620218,99375246237,359,1,2,0,0,0,26,0,0,0,0,NULL,0,NULL,0,2,26,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59522,62620218,99375246237,377,1,2,0,0,0,16,0,0,0,0,NULL,0,NULL,0,1,16,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59523,62620218,99375246237,370,1,2,0,0,0,14,0,0,0,0,NULL,0,NULL,0,1,14,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59524,62620218,99375246237,362,1,2,0,0,0,12,0,0,0,0,NULL,0,NULL,0,1,12,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59525,62620218,99375246237,369,1,2,0,0,0,28,0,0,0,0,NULL,0,NULL,0,2,28,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59526,62620218,99375246237,366,1,2,0,0,0,19,0,0,0,0,NULL,0,NULL,0,1,19,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59527,62620218,99375246237,389,1,2,0,0,0,20,0,0,0,0,NULL,0,NULL,0,1,20,0,'2020-06-24 08:47:26','2020-06-24 08:47:26'),(59528,63955378,358445508115,365,1,2,0,0,0,12,0,0,0,0,NULL,0,NULL,0,1,12,0,'2020-06-24 09:39:39','2020-06-24 09:39:39'),(59529,63955378,358445508115,359,1,2,0,0,0,104,0,0,0,0,NULL,0,NULL,0,8,104,0,'2020-06-24 09:39:39','2020-06-24 09:39:39'),(59530,63955378,358445508115,360,1,2,0,0,0,260,0,0,0,0,NULL,0,NULL,0,10,260,0,'2020-06-24 09:39:39','2020-06-24 09:39:39'),(59531,62547478,36143879903,1449,9,30,0,0,0,74.5763,6.71,6.71,0,0,NULL,0,NULL,0,2,88,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59532,62547478,36143879903,360,1,2,0,0,0,52,0,0,0,0,NULL,0,NULL,0,2,52,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59533,62547478,36143879903,359,1,2,0,0,0,26,0,0,0,0,NULL,0,NULL,0,2,26,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59534,62547478,36143879903,1515,9,30,0,0,0,26.2712,2.36,2.36,0,0,NULL,0,NULL,0,1,31,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59535,62547478,36143879903,551,1,2,0,0,0,25,0,0,0,0,NULL,0,NULL,0,1,25,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59536,62547478,36143879903,1713,1,2,0,0,0,57,0,0,0,0,NULL,0,NULL,0,3,57,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59537,62547478,36143879903,381,1,2,0,0,0,32,0,0,0,0,NULL,0,NULL,0,2,32,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59538,62547478,36143879903,364,1,2,0,0,0,39,0,0,0,0,NULL,0,NULL,0,1,39,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59539,62547478,36143879903,3604,1,2,0,0,0,35,0,0,0,0,NULL,0,NULL,0,1,35,0,'2020-06-24 10:11:25','2020-06-24 10:11:25'),(59540,63362388,1445451847,1436,8,30,0,0,0,132.203,11.9,11.9,0,0,NULL,0,NULL,0,2,156,0,'2020-06-24 10:31:33','2020-06-24 10:31:33'),(59541,63362388,1445451847,393,1,2,0,0,0,22,0,0,0,0,NULL,0,NULL,0,1,22,0,'2020-06-24 10:31:33','2020-06-24 10:31:33'),(59542,63362388,1445451847,390,1,2,0,0,0,69,0,0,0,0,NULL,0,NULL,0,3,69,0,'2020-06-24 10:31:33','2020-06-24 10:31:33'),(59543,63362388,1445451847,373,1,2,0,0,0,40,0,0,0,0,NULL,0,NULL,0,4,40,0,'2020-06-24 10:31:33','2020-06-24 10:31:33'),(59544,63362388,1445451847,364,1,2,0,0,0,78,0,0,0,0,NULL,0,NULL,0,2,78,0,'2020-06-24 10:31:33','2020-06-24 10:31:33'),(59545,63362388,1445451847,448,1,2,0,0,0,22,0,0,0,0,NULL,0,NULL,0,2,22,0,'2020-06-24 10:31:33','2020-06-24 10:31:33'),(59546,65761052,913542796944,980,5,28,0,0,0,499,0,0,0,0,NULL,0,NULL,0,1,499,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59547,65761052,913542796944,389,1,2,0,0,0,20,0,0,0,0,NULL,0,NULL,0,1,20,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59548,65761052,913542796944,378,1,2,0,0,0,10,0,0,0,0,NULL,0,NULL,0,1,10,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59549,65761052,913542796944,382,1,2,0,0,0,20,0,0,0,0,NULL,0,NULL,0,1,20,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59550,65761052,913542796944,395,1,2,0,0,0,9,0,0,0,0,NULL,0,NULL,0,1,9,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59551,65761052,913542796944,370,1,2,0,0,0,14,0,0,0,0,NULL,0,NULL,0,1,14,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59552,65761052,913542796944,369,1,2,0,0,0,14,0,0,0,0,NULL,0,NULL,0,1,14,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59553,65761052,913542796944,367,1,2,0,0,0,7,0,0,0,0,NULL,0,NULL,0,1,7,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59554,65761052,913542796944,448,1,2,0,0,0,22,0,0,0,0,NULL,0,NULL,0,2,22,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59555,65761052,913542796944,381,1,2,0,0,0,16,0,0,0,0,NULL,0,NULL,0,1,16,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59556,65761052,913542796944,374,1,2,0,0,0,18,0,0,0,0,NULL,0,NULL,0,1,18,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59557,65761052,913542796944,359,1,2,0,0,0,13,0,0,0,0,NULL,0,NULL,0,1,13,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59558,65761052,913542796944,1214,2,84,0,0,0,44,0,0,0,0,NULL,0,NULL,0,2,44,0,'2020-06-24 10:56:57','2020-06-24 10:56:57'),(59559,60740879,1578219,1001,3,8,0,0,0,12.381,0.31,0.31,0,0,NULL,0,NULL,0,1,13,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59560,60740879,1578219,448,1,2,0,0,0,33,0,0,0,0,NULL,0,NULL,0,3,33,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59561,60740879,1578219,1352,3,9,0,0,0,14,0,0,0,0,NULL,0,NULL,0,1,14,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59562,60740879,1578219,1220,2,11,0,0,0,61.9048,1.55,1.55,0,0,NULL,0,NULL,0,1,65,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59563,60740879,1578219,1214,2,84,0,0,0,44,0,0,0,0,NULL,0,NULL,0,2,44,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59564,60740879,1578219,1077,3,43,0,0,0,28.5714,0.71,0.71,0,0,NULL,0,NULL,0,1,30,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59565,60740879,1578219,415,1,2,0,0,0,20,0,0,0,0,NULL,0,NULL,0,1,20,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59566,60740879,1578219,378,1,2,0,0,0,10,0,0,0,0,NULL,0,NULL,0,1,10,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59567,60740879,1578219,382,1,2,0,0,0,20,0,0,0,0,NULL,0,NULL,0,1,20,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59568,60740879,1578219,389,1,2,0,0,0,20,0,0,0,0,NULL,0,NULL,0,1,20,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59569,60740879,1578219,1868,3,42,0,0,0,224.762,5.62,5.62,0,0,NULL,0,NULL,0,2,236,0,'2020-06-24 11:29:07','2020-06-24 11:29:07'),(59570,61385933,7792259947,1214,2,84,0,0,0,22,0,0,0,0,NULL,0,NULL,0,1,22,0,'2020-06-24 11:53:13','2020-06-24 11:53:13'),(59571,61598482,261469688072,1560,4,23,0,0,0,16.9492,1.53,1.53,0,0,NULL,0,NULL,0,2,20,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59572,61598482,261469688072,1567,4,23,0,0,0,16.9492,1.53,1.53,0,0,NULL,0,NULL,0,2,20,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59573,61598482,261469688072,1693,4,23,0,0,0,8.47458,0.76,0.76,0,0,NULL,0,NULL,0,1,10,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59574,61598482,261469688072,2550,4,23,0,0,0,12.7119,1.14,1.14,0,0,NULL,0,NULL,0,1,15,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59575,61598482,261469688072,2271,4,23,0,0,0,12.7119,1.14,1.14,0,0,NULL,0,NULL,0,1,15,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59576,61598482,261469688072,1558,4,23,0,0,0,16.9492,1.53,1.53,0,0,NULL,0,NULL,0,2,20,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59577,61598482,261469688072,2214,4,55,0,0,0,33.8983,3.05,3.05,0,0,NULL,0,NULL,0,2,40,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59578,61598482,261469688072,915,4,23,0,0,0,50.8475,4.58,4.58,0,0,NULL,0,NULL,0,2,60,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59579,61598482,261469688072,2344,4,55,0,0,0,25.4237,2.29,2.29,0,0,NULL,0,NULL,0,2,30,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59580,61598482,261469688072,1447,8,30,0,0,0,33.8983,3.05,3.05,0,0,NULL,0,NULL,0,2,40,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59581,61598482,261469688072,480,9,30,0,0,0,46.6102,4.19,4.19,0,0,NULL,0,NULL,0,1,55,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59582,61598482,261469688072,1451,9,30,0,0,0,35.5932,3.2,3.2,0,0,NULL,0,NULL,0,1,42,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59583,61598482,261469688072,2040,3,43,0,0,0,130,0,0,0,0,NULL,0,NULL,0,2,130,0,'2020-06-24 12:01:15','2020-06-24 12:01:15'),(59584,63793023,21504858351,1016,3,40,0,0,0,37.2881,3.36,3.36,0,0,NULL,0,NULL,0,1,44,0,'2020-06-24 12:11:37','2020-06-24 12:11:37'),(59585,6232453,21504858351,1903,3,9,0,0,0,17,0,0,0,0,NULL,0,NULL,0,1,17,0,'2020-06-24 12:18:23','2020-06-24 12:18:23'),(59586,2020062614035140,1564393723,81,3,8,0,0,0,85.5,2.25,2.25,0,0,NULL,0,NULL,0,2,45,0,'2020-06-26 14:04:01','2020-06-26 14:04:01'),(59587,2020062614035140,1564393723,103,1,2,0,0,0,24,0,0,0,0,NULL,0,NULL,0,2,12,0,'2020-06-26 14:04:13','2020-06-26 14:04:13'),(59589,2020062615132240,824463864359,103,1,2,0,0,0,12,0,0,0,0,NULL,0,NULL,0,1,12,0,'2020-06-26 15:14:46','2020-06-26 15:14:46'),(59590,2020062615132240,824463864359,154,6,18,0,0,0,216.48,23.76,23.76,0,0,NULL,0,NULL,0,1,264,0,'2020-06-26 15:15:19','2020-06-26 15:15:19'),(59591,2020062615303140,1564393723,103,1,2,0,0,0,12,0,0,0,0,NULL,0,NULL,0,1,12,0,'2020-06-26 15:30:45','2020-06-26 15:30:45'),(59592,2020062615303140,1564393723,154,6,18,0,0,0,649.44,71.28,71.28,0,0,NULL,0,NULL,0,3,792,0,'2020-06-26 15:31:24','2020-06-26 15:31:24'),(59593,2020062616242140,1578329,103,1,2,0,0,0,12,0,0,0,0,NULL,0,NULL,0,1,12,0,'2020-06-26 16:24:48','2020-06-26 16:24:48'),(59595,2020062616334340,1564393723,2713,13,99,0,0,0,198.55,5.225,5.225,0,0,NULL,0,NULL,0,1,209,0,'2020-06-26 16:34:45','2020-06-26 16:34:45'),(59596,2020062616334340,1564393723,2674,13,99,0,0,0,265.05,6.975,6.975,0,0,NULL,0,NULL,0,1,279,0,'2020-06-26 16:35:29','2020-06-26 16:35:29'),(59599,2020062617191740,1564393723,81,3,8,0,0,0,42.75,1.125,1.125,0,0,NULL,0,NULL,0,1,45,0,'2020-06-26 17:19:22','2020-06-26 17:19:22'),(59600,2020062617191740,1564393723,2673,13,99,0,0,0,265.05,6.975,6.975,0,0,NULL,0,NULL,0,1,279,0,'2020-06-26 17:20:29','2020-06-26 17:20:29'),(59601,2020062617210440,1564393723,81,3,8,0,0,0,42.75,1.125,1.125,0,0,NULL,0,NULL,0,1,45,0,'2020-06-26 17:21:11','2020-06-26 17:21:11'),(59602,2020062617260840,1564393723,81,3,8,0,0,0,42.75,1.125,1.125,0,0,NULL,0,NULL,0,1,45,0,'2020-06-26 17:26:11','2020-06-26 17:26:11'),(59603,2020062617294640,1564393723,81,3,8,0,0,0,128.25,3.375,3.375,0,0,NULL,0,NULL,0,3,45,0,'2020-06-26 17:30:08','2020-06-26 17:30:08'),(59604,2020062617294640,1564393723,2673,13,99,0,0,0,265.05,6.975,6.975,0,0,NULL,0,NULL,0,1,279,0,'2020-06-26 17:30:19','2020-06-26 17:30:19'),(59605,2020062617294640,1564393723,2675,13,99,0,0,0,265.05,6.975,6.975,0,0,NULL,0,NULL,0,1,279,0,'2020-06-26 17:31:20','2020-06-26 17:31:20'),(59606,2020062617390840,1564393723,81,3,8,0,0,0,42.75,1.125,1.125,0,0,NULL,0,NULL,0,1,45,0,'2020-06-26 17:39:13','2020-06-26 17:39:13'),(59607,2020062617390840,1564393723,2674,13,99,0,0,0,265.05,6.975,6.975,0,0,NULL,0,NULL,0,1,279,0,'2020-06-26 17:39:30','2020-06-26 17:39:30'),(59608,2020062617443740,1564393723,103,1,2,0,0,0,12,0,0,0,0,NULL,0,NULL,0,1,12,0,'2020-06-26 17:46:21','2020-06-26 17:46:21'),(59609,2020062617443740,1564393723,3604,1,2,0,0,0,35,0,0,0,0,NULL,0,NULL,0,1,35,0,'2020-06-26 17:46:52','2020-06-26 17:46:52'),(59610,2020062617443740,1564393723,154,6,18,0,0,0,216.48,23.76,23.76,0,0,NULL,0,NULL,0,1,264,0,'2020-06-26 17:50:49','2020-06-26 17:50:49'),(59611,2020062617563240,1564393723,154,6,18,0,0,0,216.48,23.76,23.76,0,0,NULL,0,NULL,0,1,264,0,'2020-06-26 17:56:37','2020-06-26 17:56:37'),(59612,2020062617563240,1564393723,235,6,50,0,0,0,9.5,0.25,0.25,0,0,NULL,0,NULL,0,1,10,0,'2020-06-26 17:56:42','2020-06-26 17:56:42'),(59613,2020062617583340,1564393723,2674,13,99,0,0,0,265.05,6.975,6.975,0,0,NULL,0,NULL,0,1,279,0,'2020-06-26 17:58:48','2020-06-26 17:58:48'),(59614,2020062617583340,1564393723,2686,13,99,0,0,0,274.55,7.225,7.225,0,0,NULL,0,NULL,0,1,289,0,'2020-06-26 18:04:48','2020-06-26 18:04:48'),(59615,2020062617583340,1564393723,307,2,11,0,0,0,1083,28.5,28.5,0,0,NULL,0,NULL,0,3,380,0,'2020-06-26 18:04:58','2020-06-26 18:04:58'),(59616,2020062617583340,1564393723,359,1,2,0,0,0,78,0,0,0,0,NULL,0,NULL,0,6,78,0,'2020-06-26 18:05:18','2020-06-26 18:05:18'),(59617,2020070115485540,1564393723,103,1,2,0,0,0,12,0,0,0,0,NULL,0,NULL,0,1,12,0,'2020-07-01 15:48:58','2020-07-01 15:48:58'),(59619,2020070712170840,1577437,154,6,18,0,0,0,216.48,23.76,23.76,0,0,NULL,0,NULL,0,1,264,0,'2020-07-07 12:31:30','2020-07-07 12:31:30'),(59620,2020070712170840,1577437,235,6,50,0,0,0,9.5,0.25,0.25,0,0,NULL,0,NULL,0,1,10,0,'2020-07-07 12:31:46','2020-07-07 12:31:46'),(59621,2020070712170840,1577437,251,6,19,0,0,0,43.2,8.4,8.4,0,0,NULL,0,NULL,0,3,60,0,'2020-07-07 12:32:01','2020-07-07 12:32:01'),(59623,2020062616334340,1564393723,235,6,50,0,0,0,66.5,1.75,1.75,0,0,NULL,0,NULL,0,7,70,0,'2020-07-07 15:04:22','2020-07-07 15:04:22'),(59624,2020070715283240,1577437,235,6,50,0,0,0,28.5,0.75,0.75,0,0,NULL,0,'testcupon',3,3,30,0,'2020-07-07 15:28:47','2020-07-07 15:28:47'),(59625,2020062617210440,1564393723,165,7,16,0,0,0,287,31.5,31.5,0,0,'TESTDISCOUNT2',25,NULL,0,3,350,0,'2020-07-07 17:17:09','2020-07-07 17:17:09'),(59626,2020062617191740,1564393723,165,7,16,0,0,0,307.5,33.75,33.75,0,0,NULL,0,NULL,0,3,375,0,'2020-07-07 18:09:03','2020-07-07 18:09:03');

--
-- Dumping events for database 'ebillingdtls'
--

--
-- Dumping routines for database 'ebillingdtls'
--
/*!50003 DROP PROCEDURE IF EXISTS `sp_AddtoCart_OneProduct` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_AddtoCart_OneProduct`(IN `intProductID` INT, IN `intCustomerID` BIGINT, IN `intOrderID` BIGINT, IN `intQty` INT, IN `intUserID` INT)
BEGIN

DECLARE intStoreID,intProdCat,intProdSubCat,intPseudoStock,isOrderDetailsPresent,isProductDetailsPresent INT;
DECLARE fProdOfferPrice,fProdClubPrice,fIGSTPer,fCGSTPer,fSGSTPer float;
DECLARE fPriceP,fRate,fCGST,fSGST,fIGST,fperPrice FLOAT;
DECLARE isCustomerClubMember VARCHAR(10);
-- DECLARE EXIT HANDLER FOR sqlexception SELECT 'ERROR - ' Message;
SET intStoreID = 0; SET intProdCat = 0; SET intProdSubCat = 0;set intPseudoStock = 0; set isOrderDetailsPresent =0; SET isProductDetailsPresent =0;
SET fProdOfferPrice = 0;SET fProdClubPrice = 0;SET fIGSTPer = 0;SET fCGSTPer = 0;SET fSGSTPer = 0;
SET fPriceP =0; set fRate = 0; set fCGST = 0; set fSGST =0; set fIGST = 0;set fperPrice =0;

select adm_store INTO intStoreID from karloff_admin where id = intUserID;

/* INSERT INTO karloff_db_log(logdtls) 
VALUES(CONCAT(intProductID,';',intCustomerID,';',intOrderID,';',intQty,';',intUserID));*/

select PseudoStock,ProductCategory,ProductSubcategoryL1 into intPseudoStock,intProdCat,intProdSubCat	
from karloff_productdb where id = intProductID;
-- INSERT INTO karloff_db_log(logdtls) VALUES('Select product details');
 CALL sp_getProduct_pricedetails(intProductID,0,intCustomerID,intQty,fperPrice,fRate,fSGST,fCGST,fIGST,fPriceP);
/* INSERT INTO karloff_db_log(logdtls) 
 VALUES(CONCAT('QTY -',intQty,'; PER PRICE -',fperPrice,'; RATE-',fRate,'; FINAL PRICE - ',fPriceP));*/

SELECT Count(ID) into isProductDetailsPresent FROM karloff_weborder_details WHERE order_id = intOrderID and product_id = intProductID;

IF (isProductDetailsPresent > 0) THEN

 UPDATE karloff_weborder_details SET BaseValue = (BaseValue + fRate),CgstAmount = (CgstAmount + fCGST),SgstAmount = (SgstAmount + fSGST),
 IgstAmount = (IgstAmount + fIGST), qty = (qty + intQty),net_amount = (net_amount+ fPriceP)  
  WHERE order_id = intOrderID and product_id = intProductID;

ELSE
 INSERT INTO `karloff_weborder_details`(`order_id`,`customer_id`,`product_id`,`product_category_id`,`product_subcategory_id`,`BaseValue`,`CgstAmount`,
`SgstAmount`,`IgstAmount`,`qty`,`net_amount`,`updated_at`,`created_at`)
VALUES(intOrderID,intCustomerID,intProductID,intProdCat,intProdSubCat,fRate,fCGST,fSGST,fIGST,intQty,fPriceP,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP());

END IF;


SELECT Count(ID) into isOrderDetailsPresent FROM karloff_weborder WHERE order_id = intOrderID;

	IF (isOrderDetailsPresent > 0) THEN
				
		update karloff_weborder set BaseValue = (BaseValue + fRate),CgstAmount = (CgstAmount + fCGST), 
		SgstAmount = (SgstAmount + fSGST),IgstAmount = (IgstAmount + fIGST),InvoiceAmount = (InvoiceAmount + fPriceP),
		NetAmount = (NetAmount + fPriceP)
		where order_id = intOrderID;
		
		
	ELSE
       INSERT INTO `karloff_weborder`(`storeId`,`order_id`,`customer_id`,`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`InvoiceAmount`,
		`NetAmount`,`order_status`,`order_date`,`updated_at`,`created_at`)
		VALUES(intStoreID,intOrderID,intCustomerID,fRate,fCGST,fSGST,fIGST,fPriceP,fPriceP,7,Current_Date(),CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP());
	END IF;


 CALL sp_UpdatePsudoProductStock(intProductID,intQty,intOrderID,1);

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_AddtoCart_OneProduct_main` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_AddtoCart_OneProduct_main`(IN `intProductID` INT, IN `intCustomerID` VARCHAR(200), IN `intOrderID` VARCHAR(200), IN `intQty` INT, IN `intUserID` INT)
BEGIN

call sp_AddtoCart_OneProduct(intProductID,intCustomerID,intOrderID,intQty,intUserID);

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_Cupon_Applydetails` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_Cupon_Applydetails`(IN strOrderID VARCHAR(200),
IN strCuponDTLS VARCHAR(200),
OUT strOutPutDTLS varchar(500))
BEGIN
 DECLARE IsPromocodePresent,IsValidPromocode,IsCuponAlreadyApplied,intProductID,intCouponAmount,isProdPresent INT;
 DECLARE intSubCategoryID,intProductValue,isCashBackDiscountApplied INT;
 DECLARE intCustomerID LONG;
 DECLARE strDiscountType,strDiscountAppliedOn VARCHAR(50);
DECLARE totalSaleValue NUMERIC(10,2);
-- DECLARE EXIT HANDLER FOR sqlexception SELECT 'ERROR - ' Message;

 SET strDiscountType = ''; SET strDiscountAppliedOn = '';
 SET IsPromocodePresent = 0; SET IsValidPromocode =0; SET intCustomerID =0; set IsCuponAlreadyApplied =0;
 SET intProductID =0; SET intCouponAmount =0; SET intSubCategoryID =0; SET intProductValue = 0;
 SET totalSaleValue = 0; SET isCashBackDiscountApplied =0; SET isProdPresent=0;
 
 -- INSERT INTO karloff_db_log(logdtls) VALUES(CONCAT('order id -',strOrderID,';cupon -',strCuponDTLS));
 
 -- Check Promocode is present or not
 SELECT COUNT(ID)  INTO IsPromocodePresent FROM karloff_promo_code WHERE PromoCode = strCuponDTLS;
  IF (IsPromocodePresent > 0) THEN
  -- Check Promocode valid for today(DATE)
    SELECT COUNT(ID)  INTO IsValidPromocode FROM karloff_promo_code WHERE PromoCode = strCuponDTLS AND (CURRENT_TIMESTAMP BETWEEN ValidFrom AND ValidTill);
       IF (IsValidPromocode > 0) THEN       
	   
	   select customer_id into intCustomerID from karloff_weborder where order_id = strOrderID;
	   -- Check Already Applied or not
	  -- select COUNT(ID) INTO IsCuponAlreadyApplied from karloff_promocode_applied WHERE customer_id=intCustomerID AND coupon_applied = strCuponDTLS;
      select COUNT(ID) INTO IsCuponAlreadyApplied from karloff_weborder_details WHERE customer_id=intCustomerID AND (CouponCode = strCuponDTLS OR CashbackCode = strCuponDTLS) AND order_id <> strOrderID;
		IF (IsCuponAlreadyApplied = 0) THEN
	   -- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	   
	    SELECT DiscountType,CouponAmount,ProductId,ProductValue,SubCategoryId  
		INTO strDiscountType,intCouponAmount,intProductID,intProductValue,intSubCategoryID
		FROM karloff_promo_code WHERE PromoCode = strCuponDTLS; 
		-- ++++++++++++++++++++++++++++++++++++++
		/* SELECT BaseValue,CgstAmount,SgstAmount,IgstAmount,qty,net_amount FROM karloff_weborder_details WHERE qty>1;
		
		SELECT ROUND(SUM(BaseValue),2) AS baseval,ROUND(SUM(CgstAmount),2) AS cgstval,ROUND(SUM(SgstAmount),2) AS sgstval,
ROUND(SUM(IgstAmount),2) AS igstval,ROUND(SUM(BaseValue+CgstAmount+SgstAmount+IgstAmount),2) AS totalval
 FROM karloff_weborder_details WHERE order_id = 2020062617294640;
 */
  --  check 1)Product Cashback 2)Product Promocode Discount
 SELECT ROUND(SUM(BaseValue+CgstAmount+SgstAmount+IgstAmount),2) into totalSaleValue
 FROM karloff_weborder_details WHERE order_id = strOrderID and product_id = intProductID;
		-- ========================================
		SET isCashBackDiscountApplied = 0;
		IF (intProductValue <= totalSaleValue) THEN		 
		  SET isCashBackDiscountApplied = 1; SET strDiscountAppliedOn ='PRODUCTID';
          SET isProdPresent = 1;
        ELSEIF (intProductValue > totalSaleValue) THEN
            SET isProdPresent = 1;
            SET strOutPutDTLS = CONCAT('ERROR: Required cart amount ',intProductValue,' for ',(select ProductName from karloff_productdb where id = intProductID),' product!');	
		ELSE
		 IF (totalSaleValue = 0 OR totalSaleValue is NULL) THEN
		   SET strOutPutDTLS = 'ERROR: Cupon related product is not present!'; 
		 END IF;  
		END IF;
		
		 --  check 3)Sub-Category Cashback 4) Subcategory Promocode Discount
	   IF(isCashBackDiscountApplied = 0 AND isProdPresent = 0) THEN		
	     SELECT ROUND(SUM(BaseValue+CgstAmount+SgstAmount+IgstAmount),2) into totalSaleValue
         FROM karloff_weborder_details WHERE order_id = strOrderID and product_subcategory_id = intSubCategoryID;
	     IF (intProductValue <= totalSaleValue) THEN
		   SET isCashBackDiscountApplied = 1;	SET strDiscountAppliedOn ='PRODSUBCATID';	
		ELSE
			 IF totalSaleValue = 0 OR totalSaleValue is NULL THEN
			   SET strOutPutDTLS = CONCAT('ERROR: Cupon related product is not present!');	
			 END IF; 
		 END IF;
	    END IF;	  
		
		-- Check Applicable CUPON/DISCOUNT
        IF(isCashBackDiscountApplied = 1) THEN		
		 IF (strDiscountType = 'CASHBACK') THEN		  
			
			UPDATE `karloff_weborder_details` SET CashbackCode = strCuponDTLS,`CashbackDiscountAmount` = intCouponAmount
            WHERE order_id =strOrderID and (product_id =intProductID or product_subcategory_id = intSubCategoryID);
            
            UPDATE karloff_weborder SET CashbackTotalDiscount = intCouponAmount
            WHERE order_id = strOrderID AND customer_id = intCustomerID;

			SET strOutPutDTLS = CONCAT('SUCCESS: Good to go!;',intCouponAmount ,';0');
		ELSEIF (strDiscountType = 'DISCOUNT') THEN		  
		    
             UPDATE karloff_weborder_details SET CouponCode = strCuponDTLS,`CouponCodeDiscount` = intCouponAmount
             WHERE order_id = strOrderID and (product_id =intProductID or product_subcategory_id = intSubCategoryID);	

             UPDATE karloff_weborder SET CouponCodeTotalDiscount = intCouponAmount
             WHERE order_id = strOrderID AND customer_id = intCustomerID;
             
			CALL sp_updateOrderDetails_cuponapplied(strOrderID,intCouponAmount,intProductID,intSubCategoryID,strDiscountAppliedOn);
             
			SET strOutPutDTLS = CONCAT('SUCCESS: Good to go!;0;',intCouponAmount);				 
		  END IF;
		  INSERT INTO `karloff_promocode_applied`(`customer_id`,`coupon_applied`)
          VALUES(intCustomerID,strCuponDTLS);
		  -- Update WebOrder and WebOrder Details for product as PROMO Applied
		
       /* ELSE
         IF totalSaleValue = 0 THEN
           SET strOutPutDTLS = 'ERROR: Cupon related product is not present!';	
         ELSE
           SET strOutPutDTLS = 'ERROR: Total order amount is low!';	
         END IF;*/
          	
		END IF;
	-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	  
		ELSE
		 SET strOutPutDTLS = 'ERROR: Cupon previously applied!';
	    END IF;   
	  ELSE
		 SET strOutPutDTLS = 'ERROR: Promo code expired!';
	  END IF;
  ELSE
     SET strOutPutDTLS = 'ERROR: No Promo code present!';
  END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_Cupon_DetailsfrmOrder` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_Cupon_DetailsfrmOrder`(IN strOrderID VARCHAR(200),
OUT strOutPutDTLS varchar(500))
BEGIN
 DECLARE DiscountAmount,CashbackAmount INT;
 DECLARE strDiscountCode,strCashbackCode VARCHAR(100);
 
DECLARE done INT DEFAULT FALSE;
DECLARE cur_prodlist CURSOR FOR 
SELECT CouponCode,CouponCodeDiscount,CashbackCode,CashbackDiscountAmount
FROM karloff_weborder_details WHERE order_id = strOrderID;
 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; 

 OPEN cur_prodlist;
  read_loop: LOOP
    FETCH cur_prodlist INTO strDiscountCode,DiscountAmount,strCashbackCode,CashbackAmount;
    IF done THEN
      LEAVE read_loop;
    END IF;
    
      IF(strDiscountCode <> NULL OR strDiscountCode <> '') THEN	  
	   SET strOutPutDTLS = CONCAT('SUCCESS: Cupon Present!;0;',DiscountAmount,';',strDiscountCode);	  
	  ELSEIF(strCashbackCode <> NULL OR strCashbackCode <> '') THEN
	   SET strOutPutDTLS = CONCAT('SUCCESS: Cupon Present!;',CashbackAmount,';0;',strCashbackCode);
	  ELSE
	    SET strOutPutDTLS = 'NOTFOUND: No Promo code present!';
      END IF; 
   
  END LOOP;
  CLOSE cur_prodlist;
 
 END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_generateInvoice_details` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_generateInvoice_details`(IN `intCardAmount` INT, IN `intCashAmount` INT, IN `intPaytemAmount` INT, IN `intOnlineAmount` INT, IN `intUserID` INT, IN `intOrderID` BIGINT)
BEGIN
DECLARE intCurrentMaxInvoiveID,intNewInvoiveID,intTHISInvoiveIDPresent,intStoreID,intNetAmount INT;

set intCurrentMaxInvoiveID =0; set intNewInvoiveID =0;set intTHISInvoiveIDPresent =0;set intStoreID=0;set intNetAmount =0;

select MAX(invoice_id) into intCurrentMaxInvoiveID from karloff_invoice_master;
SET intNewInvoiveID = (intCurrentMaxInvoiveID + 1);
select COUNT(id) into intTHISInvoiveIDPresent from karloff_invoice_master where invoice_id = intNewInvoiveID;
IF (intTHISInvoiveIDPresent > 0) THEN
	SET intNewInvoiveID = (intNewInvoiveID + 1);
END IF;

select adm_store INTO intStoreID from karloff_admin where id = intUserID;
select NetAmount INTO intNetAmount from karloff_weborder where order_id = intOrderID;


INSERT INTO `karloff_invoice_master`(`invoice_id`,`order_id`,`customer_id`,`delivery_charge`,`GoCashPay`,`Promocode`,`PromocodeDiscount`,`PromoDiscBasePrice`,`PromoDiscGST`,
`CouponCodeTotalDiscount`,`CashbackTotalDiscount`,`discount_amount`,`RedeemAmount`,`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`InvoiceAmount`,`NetAmount`,
`round_off_amount`,`order_status`,`payment_code`,`InvoiceDate`,`order_receive_date`,`order_receive_datetime`,`delivery_date`,`sale_point`,`sales_person`,
`sale_type`,`updated_at`,`created_at`) 
SELECT intNewInvoiveID,`order_id`,`customer_id`,`delivery_charge`,`GoCashPay`,`Promocode`,`PromocodeDiscount`,`PromoDiscBasePrice`,`PromoDiscGST`,
`CouponCodeTotalDiscount`,`CashbackTotalDiscount`,`discount_amount`,`RedeemAmount`,`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`InvoiceAmount`,`NetAmount`,
`round_off_amount`,`order_status`,`payment_code`,Current_Date(),`order_date`,`order_datetime`,Current_Date(),intStoreID,intUserID,3,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()
 FROM `karloff_weborder` WHERE order_id = intOrderID;

UPDATE `karloff_invoice_master` SET order_status = 5 WHERE order_id = intOrderID;
UPDATE `karloff_weborder` SET order_status = 5 WHERE order_id = intOrderID;

INSERT INTO `karloff_invoice_details`(`invoice_id`,`order_id`,`customer_id`,`product_id`,`product_category_id`,`product_subcategory_id`,`CgstPercent`,`SgstPercent`,`IgstPercent`,
`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`RoundOffAmount`,`CouponCode`,`CouponCodeDiscount`,`CashbackCode`,`CashbackDiscountAmount`,
`subYesorNot`,`qty`,`net_amount`,`updated_at`,`created_at`)
SELECT intNewInvoiveID,`order_id`,`customer_id`,`product_id`,`product_category_id`,`product_subcategory_id`,`CgstPercent`,`SgstPercent`,`IgstPercent`,
`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`RoundOffAmount`,`CouponCode`,`CouponCodeDiscount`,`CashbackCode`,`CashbackDiscountAmount`,
`subYesorNot`,`qty`,`net_amount`,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP() FROM `karloff_weborder_details` WHERE order_id = intOrderID;

INSERT INTO `karloff_account_manager`(`invoice_no`,`NetAmount`,`PromocodeDiscount`,`GoCashAmount`,`cash_amount`,`card_amount`,`paytm_amount`,`online_amount`,
`settled`,`updated_at`,`created_at`) VALUES(intNewInvoiveID,intNetAmount,0,0,intCashAmount,intCardAmount,intPaytemAmount,intOnlineAmount,1,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP());

CALL sp_updatefinalStock_details(intOrderID);

-- CALL sp_updatemembership_details(intOrderID,);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_generateInvoice_details_main` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_generateInvoice_details_main`(IN `intCardAmount` INT, IN `intCashAmount` INT, IN `intPaytemAmount` INT, IN `intOnlineAmount` INT, IN `intUserID` INT, IN `intOrderID` VARCHAR(200))
BEGIN
CALL sp_generateInvoice_details(intCardAmount,intCashAmount,intPaytemAmount,intOnlineAmount,intUserID,intOrderID);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getAllProduct_lst` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getAllProduct_lst`()
BEGIN

 Select t1.id,ProductCode,HsnCode,ProductName,ProductMrp,ProductOfferprice,ProductClubprice,
PseudoStock,t2.CategoryName,t2.CategoryIconPath,t3.SubcategoryL1Name,t3.SubCategoryIconPath,
t4.unit_name,t5.packing_name,t6.colourName,t6.hexCode,BrandName,IndividualLimit,ProductVolume
from karloff_productdb t1 
left join karloff_category t2 on t1.ProductCategory = t2.id 
left join karloff_subcategorylevel1 t3 on t3.id = t1.ProductSubcategoryL1
left join karloff_unitdb t4 on t1.ProductUnit = t4.id
left join karloff_packingdb t5 on t1.ProductCategory = t5.id 
left join karloff_prod_colour t6 on t1.ProductSubcategoryL1 = t6.id
left join karloff_brand t7 on t1.ProductBrand = t7.id
where ((ProductCode <>'') OR (ProductCode <> NULL)) and CurrentStock > 0 
and PseudoStock > 0 and ProductEnable = 1;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getCartDetails_fromOrderID` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getCartDetails_fromOrderID`(IN `intOrderID` VARCHAR(200))
BEGIN

-- select `product_id`,`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`qty`,`net_amount` from karloff_weborder_details where order_id = intOrderID;
select t2.ProductName,t2.ProductCode,`product_id`,`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`qty`,`net_amount` 
from karloff_weborder_details t1,karloff_productdb t2 where t1.product_id=t2.id and order_id = intOrderID;


select `BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`NetAmount` from karloff_weborder where order_id = intOrderID;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getCustomerClubMemberDetails` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getCustomerClubMemberDetails`(IN `intCustomerID` BIGINT, OUT `strYesNo` VARCHAR(20))
BEGIN
DECLARE intRowPresent INT;
SET strYesNo = 'No';
SET intRowPresent = 0;

	select (Select Count(ID) from karloff_club_membership where customer_id = t1.customer_id 
	and  expiry >= Current_Date()) INTO intRowPresent 
	from karloff_customer t1 where t1.id = intCustomerID;
    
    IF (intRowPresent > 0) THEN
      SET strYesNo = 'Yes';
    END IF;
                
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getOrderCountdown_dtls` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getOrderCountdown_dtls`()
BEGIN

-- select count(id) as totalid from karloff_weborder where order_status =1;

select 
(select count(id) from karloff_weborder where order_status =1) as neworder,
(select count(id) from karloff_weborder where order_status in (2,3)) as processorder ,
(select count(id) from karloff_weborder where order_status =4) as dispatchorder ,
(select count(id) from karloff_weborder where order_status =5) as deliveredorder  
from dual;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getOrderList_fromStatusID` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getOrderList_fromStatusID`(IN intOrderStatusID INT)
BEGIN

	/* select order_id,t1.customer_id,t1.updated_at,t1.created_at,t2.name,t2.mobile,NetAmount,order_status 
from karloff_weborder t1 ,karloff_customer t2 
where order_id not in (select order_id from karloff_invoice_master) and t1.customer_id = t2.customer_id 
and t1.order_status = intOrderStatusID; */

 select order_id,t1.customer_id,t2.customer_id,t1.updated_at,t1.created_at,t2.name,t2.mobile,NetAmount,
 order_status,t1.payment_code,t3.payment_name,delivery_charge,GoCashPay,RedeemAmount
from karloff_weborder t1 ,karloff_customer t2,karloff_payment_mode t3 
where t1.customer_id = t2.customer_id and t3.payment_code = t1.payment_code
and t1.order_status = intOrderStatusID;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getOrder_Details` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getOrder_Details`(IN strOrderID VARCHAR(200))
BEGIN

select InvoiceAmount, NetAmount, round_off_amount,status_name,delivery_date,
                t2.name,t2.mobile,t2.cust_gst,t2.customer_id,t1.created_at,
                t1.payment_code,t4.payment_name,delivery_charge,GoCashPay,RedeemAmount,t4.id as paymentid
				from karloff_weborder t1, karloff_customer t2,karloff_order_status t3,karloff_payment_mode t4
                 where t1.customer_id = t2.customer_id and t3.id = t1.order_status and t4.payment_code = t1.payment_code
                 and order_id = strOrderID;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getProduct_dtls` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getProduct_dtls`(IN strProductCode VARCHAR(50))
BEGIN

 Select t1.id,ProductCode,HsnCode,ProductName,ProductMrp,ProductOfferprice,ProductClubprice,
PseudoStock,t2.CategoryName,t2.CategoryIconPath,t3.SubcategoryL1Name,t3.SubCategoryIconPath,
t4.unit_name,t5.packing_name,t6.colourName,t6.hexCode,BrandName,IndividualLimit,ProductVolume
from karloff_productdb t1 
left join karloff_category t2 on t1.ProductCategory = t2.id 
left join karloff_subcategorylevel1 t3 on t3.id = t1.ProductSubcategoryL1
left join karloff_unitdb t4 on t1.ProductUnit = t4.id
left join karloff_packingdb t5 on t1.ProductCategory = t5.id 
left join karloff_prod_colour t6 on t1.ProductSubcategoryL1 = t6.id
left join karloff_brand t7 on t1.ProductBrand = t7.id
where ((ProductCode <>'') OR (ProductCode <> NULL)) and CurrentStock > 0 
and PseudoStock > 0 and ProductEnable = 1 AND ProductCode like CONCAT(strProductCode,"%");

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getProduct_pricedetails` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getProduct_pricedetails`(IN intProductID INT,
IN intDiscountAmount INT,
IN intCustomerID LONG,
IN intQty INT,
OUT intRateAmount FLOAT,
OUT intAmount FLOAT,
OUT intCGSTAmount FLOAT,
OUT intSGSTAmount FLOAT,
OUT intIGSTAmount FLOAT,
OUT intPRICEAmount FLOAT)
BEGIN
DECLARE isCustomerClubMember VARCHAR(10);
DECLARE fProdOfferPrice,fProdClubPrice,fIGSTPer,fCGSTPer,fSGSTPer float;
DECLARE fPriceP FLOAT;
 
SET isCustomerClubMember = ''; 
SET fProdOfferPrice = 0;SET fProdClubPrice = 0;SET fIGSTPer = 0;SET fCGSTPer = 0;SET fSGSTPer = 0;
-- SET fPriceP =0; set fRate = 0; set fCGST = 0; set fSGST =0; set fIGST = 0;
SET fPriceP =0;

 CALL sp_getCustomerClubMemberDetails(intCustomerID,isCustomerClubMember);
 
/* INSERT INTO karloff_db_log(logdtls) 
VALUES(CONCAT(intProductID,';',intDiscountAmount,';',intCustomerID,';',isCustomerClubMember,';')); */

 select ProductOfferprice,ProductClubprice,ProductIgst,ProductCgst,ProductSgst
  into fProdOfferPrice,fProdClubPrice,fIGSTPer,fCGSTPer,fSGSTPer
   from karloff_productdb where id = intProductID;
			 
		IF (isCustomerClubMember = 'Yes') THEN
		  SET fPriceP = fProdClubPrice;
		ELSE
		 SET fPriceP = fProdOfferPrice;
		END IF;
	 	
	SET intRateAmount = fPriceP;	
    
	set fPriceP = (fPriceP * intQty);
    
    IF (intDiscountAmount > 0) THEN
      SET fPriceP = (fPriceP - intDiscountAmount);
    END IF;
    
	-- set fRate = (fPriceP * intQty);
	set intCGSTAmount = (fPriceP * (fCGSTPer/100));
	set intSGSTAmount = (fPriceP * (fSGSTPer/100));
	set intIGSTAmount = (fPriceP * (fIGSTPer/100));
	set intAmount = (fPriceP -(intCGSTAmount + intSGSTAmount + intIGSTAmount));
	SET intPRICEAmount = fPriceP;
    

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_getSearch_OrderList` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_getSearch_OrderList`(IN intOrderID VARCHAR(200),
IN intOrderDate VARCHAR(200),
IN intOrderStatus VARCHAR(200),
IN intCustomerID VARCHAR(200),
IN strCustomerName VARCHAR(200),
IN strCustomerMobile VARCHAR(200))
BEGIN
DECLARE strQuery TEXT;
/*
DECLARE strQuery TEXT;

SET @strQuery = CONCAT(@strQuery," where FK_TypeID = ",intExamTypeID," and IsActive = 1 ");
SET @strQuery = CONCAT(@strQuery,"; ");

   PREPARE stmt FROM @strQuery;   
    EXECUTE stmt;	
	DEALLOCATE PREPARE stmt;

*/
-- select ID,status_name from karloff_order_status t1 where id in(1,2,3,4); 
-- SET @strQuery = CONCAT(@strQuery," select order_id,t1.customer_id,t2.customer_id,t1.updated_at,t1.created_at,t2.name,t2.mobile,NetAmount,");
SET @strQuery = "select order_id,t1.customer_id,t2.customer_id,t1.updated_at,t1.created_at,t2.name,t2.mobile,NetAmount,";
SET @strQuery = CONCAT(@strQuery," order_status,t1.payment_code,t3.payment_name,delivery_charge,GoCashPay,RedeemAmount");
SET @strQuery = CONCAT(@strQuery," from karloff_weborder t1 ,karloff_customer t2,karloff_payment_mode t3 ");
SET @strQuery = CONCAT(@strQuery," where t1.customer_id = t2.customer_id and t3.payment_code = t1.payment_code");

IF ((intOrderStatus IS NOT NULL) AND (intOrderStatus <> '')) THEN
   SET @strQuery = CONCAT(@strQuery," and t1.order_status ='", intOrderStatus,"'");
END IF;

IF ((intOrderID IS NOT NULL) AND (intOrderID <> '')) THEN
   SET @strQuery = CONCAT(@strQuery," and t1.order_id like('", intOrderID,"%')");
END IF;
-- ++++++++++++++++++++++++++++++++++++
IF ((intCustomerID IS NOT NULL) AND (intCustomerID <> '')) THEN
   SET @strQuery = CONCAT(@strQuery," and t2.customer_id like('", intCustomerID,"%')");
END IF;
IF ((strCustomerName IS NOT NULL) AND (strCustomerName <> '')) THEN
   SET @strQuery = CONCAT(@strQuery," and t2.name like('", strCustomerName,"%')");
END IF;
IF ((strCustomerMobile IS NOT NULL) AND (strCustomerMobile <> '')) THEN
   SET @strQuery = CONCAT(@strQuery," and t2.mobile like('", strCustomerMobile,"%')");
END IF;
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SET @strQuery = CONCAT(@strQuery,";");

PREPARE stmt FROM @strQuery;   
EXECUTE stmt;	
DEALLOCATE PREPARE stmt; 

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_insert_CustomerAddress` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_insert_CustomerAddress`(IN strCustomerID VARCHAR(200),
 IN strCustName VARCHAR(200),IN strCustMobile VARCHAR(200),
 IN strCustHouseNo VARCHAR(200),IN strCustLocality VARCHAR(200),
 IN strCustLandmark VARCHAR(200),IN strCustCity VARCHAR(200),IN strCustState VARCHAR(200),
 IN strCustPin VARCHAR(200),IN strCustAddresType VARCHAR(200),
 IN strCustisDefault INT)
BEGIN

update karloff_address_manager set is_default=1 where customer_id = strCustomerID;

INSERT INTO `karloff_address_manager`(`customer_id`,`full_name`,`phone_no`,`house_no`,`locality`,`landmark`,`city`,`state`,`type`,`is_default`,`pincode`,`updated_at`,`created_at`)
VALUES(strCustomerID,strCustName,strCustMobile,strCustHouseNo,strCustLocality,strCustLandmark,strCustCity,strCustState,strCustAddresType,strCustisDefault,strCustPin,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP());

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_orderstatus_list` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_orderstatus_list`(IN intFlag INT)
BEGIN
 IF (intFlag = 0) THEN
	select ID,status_name from karloff_order_status t1;
  ELSEIF (intFlag = 1) THEN
	select ID,status_name from karloff_order_status t1 where id in(0,1,2,3,4,5,6); 
  ELSEIF (intFlag = 2) THEN
	select ID,status_name from karloff_order_status t1 where id in(1,2,3,4); 
  END IF; 
  
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_remove_orderdetails` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_remove_orderdetails`(IN `intOrderID` VARCHAR(200))
BEGIN
SELECT `product_id`,`product_category_id`,`product_subcategory_id`,`qty` 
FROM `karloff_weborder_details` WHERE order_id =intOrderID;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_set_CustomerAddressDefault` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_set_CustomerAddressDefault`(IN strCustomerID VARCHAR(200),
IN intAddressID VARCHAR(200))
BEGIN

update karloff_address_manager set is_default=1 where customer_id = strCustomerID;

update karloff_address_manager set is_default=0 
where customer_id = strCustomerID and id = intAddressID;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_subscription_list` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_subscription_list`()
BEGIN
/* SELECT T1.ID,T4.customer_id,T4.name,T4.mobile,T5.id as PID,T5.ProductCode,T5.ProductName,T1.ProductQty,T1.SubscriptionStartDate,T1.LastOrderDeliverDate,
T2.SubscriptionName,T2.DayFrequency,T2.DaysCycle,T3.StatusName,T1.SubscriptionDaysCycle,
 (T1.LastOrderDeliverDate + INTERVAL T2.DayFrequency DAY) as NextDeliveryDate
FROM karloff_subscription T1,karloff_subscription_name T2,karloff_subscription_status T3,karloff_customer T4,karloff_productdb T5
WHERE T1.CustomerId = T4.customer_id
AND T1.ProductId = T5.id
AND T1.SubscriptionStatus = T3.id
AND T1.SubscriptionName = T2.id 
AND T3.ID =1; */

select * from (SELECT T1.ID,T4.customer_id,T4.name,T4.mobile,T5.id as PID,T5.ProductCode,T5.ProductName,T1.ProductQty,T1.SubscriptionStartDate,T1.LastOrderDeliverDate,
T2.SubscriptionName,T2.DayFrequency,T2.DaysCycle,T3.StatusName,T1.SubscriptionDaysCycle,
 (T1.LastOrderDeliverDate + INTERVAL T2.DayFrequency DAY) as NextDeliveryDate
FROM karloff_subscription T1,karloff_subscription_name T2,karloff_subscription_status T3,karloff_customer T4,karloff_productdb T5
WHERE T1.CustomerId = T4.customer_id
AND T1.ProductId = T5.id
AND T1.SubscriptionStatus = T3.id
AND T1.SubscriptionName = T2.id 
AND T3.ID =1) as testdb order by NextDeliveryDate asc; 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_updatefinalStock_details` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_updatefinalStock_details`(IN `intOrderID` BIGINT)
BEGIN
 -- **********************************************
  DECLARE done INT DEFAULT FALSE;
  DECLARE prodid,prodcatid,prodsubcatid,qtydtls INT; 
  
 DECLARE cursor_Prod CURSOR FOR 
 SELECT `product_id`,`product_category_id`,`product_subcategory_id`,`qty` 
 FROM `karloff_weborder_details` WHERE order_id = intOrderID;  
 
   DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
     
   OPEN cursor_Prod;
  read_loop: LOOP
    FETCH cursor_Prod INTO prodid,prodcatid,prodsubcatid,qtydtls;
    IF done THEN
      LEAVE read_loop;
    END IF;
   -- ========================================= 
    update karloff_productdb set CurrentStock = (CurrentStock - qtydtls) where id = prodid and ProductCategory = prodcatid and ProductSubcategoryL1 = prodsubcatid;
  -- ==============================================
  END LOOP;
  CLOSE cursor_Prod;
	 
 -- ********************************************
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_updateOrderDetails_cuponapplied` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_updateOrderDetails_cuponapplied`(IN strOrderID VARCHAR(200),
IN intCouponAmount INT,
IN intProductID INT,
IN intSubCategoryID INT,
IN strDiscountAppliedOn VARCHAR(50))
BEGIN
DECLARE intQty INT;
DECLARE isCustomerClubMember VARCHAR(10);
DECLARE intCustomerID LONG;
DECLARE fProdOfferPrice,fProdClubPrice,fIGSTPer,fCGSTPer,fSGSTPer float;
DECLARE fPriceP,fRate,fCGST,fSGST,fIGST,fperPrice FLOAT;

SET intQty = 0;
-- SET isCustomerClubMember = ''; 
SET intCustomerID=0;
SET fProdOfferPrice = 0;SET fProdClubPrice = 0;SET fIGSTPer = 0;SET fCGSTPer = 0;SET fSGSTPer = 0;
SET fPriceP =0; set fRate = 0; set fCGST = 0; set fSGST =0; set fIGST = 0;set fperPrice=0;

 select customer_id into intCustomerID from karloff_weborder where order_id = strOrderID;
 -- CALL `sp_getCustomerClubMemberDetails`(intCustomerID,isCustomerClubMember);
  
  
 IF (strDiscountAppliedOn = 'PRODUCTID') THEN	
 -- UPDATE WEB-ORDER AND WEB-ORDER-DETAILS TABLE BEFORE PROCESS
	 SELECT `BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`net_amount`,QTY 
	INTO fRate,fCGST,fSGST,fIGST,fPriceP,intQty
	FROM karloff_weborder_details WHERE order_id = strOrderID AND product_id = intProductID;

	update karloff_weborder set BaseValue = (BaseValue - fRate),CgstAmount = (CgstAmount - fCGST), 
	SgstAmount = (SgstAmount - fSGST),IgstAmount = (IgstAmount - fIGST),InvoiceAmount = (InvoiceAmount - fPriceP),
	NetAmount = (NetAmount - fPriceP),updated_at= CURRENT_TIMESTAMP() where order_id = strOrderID;
    -- RESET ALL VALUES    
    SET fPriceP =0; set fRate = 0; set fCGST = 0; set fSGST =0; set fIGST = 0; set fperPrice =0;   
        
 -- GET PRODUCT VALUE DETAILS
     CALL sp_getProduct_pricedetails(intProductID,intCouponAmount,intCustomerID,intQty,fperPrice,fRate,fSGST,fCGST,fIGST,fPriceP);

 /* INSERT INTO karloff_db_log(logdtls) 
 VALUES(CONCAT('Disc -',intCouponAmount,'; QTY -',intQty,'; PER PRICE -',fperPrice,'; RATE-',fRate,'; FINAL PRICE - ',fPriceP));
*/
 
 -- APPLIED FINAL DETAILS
   UPDATE karloff_weborder_details SET `BaseValue` = fRate,`CgstAmount`= fCGST,`SgstAmount`= fSGST,
   `IgstAmount`= fIGST,`net_amount`= fPriceP 	
	WHERE order_id = strOrderID AND product_id = intProductID;
 
	update karloff_weborder set BaseValue = (BaseValue + fRate),CgstAmount = (CgstAmount + fCGST), 
	SgstAmount = (SgstAmount + fSGST),IgstAmount = (IgstAmount + fIGST),InvoiceAmount = (InvoiceAmount + fPriceP),
	NetAmount = (NetAmount + fPriceP),updated_at= CURRENT_TIMESTAMP() where order_id = strOrderID;
    
 ELSEIF (strDiscountAppliedOn = 'PRODSUBCATID') THEN
 
   CALL sp_updateOrderDetails_cuponapplied_2(strOrderID,intCouponAmount,intSubCategoryID);
   
 END IF;
 --  select * from karloff_promo_code;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_updateOrderDetails_cuponapplied_2` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_updateOrderDetails_cuponapplied_2`(IN strOrderID VARCHAR(200),
IN intCouponAmount INT,
IN intSubCategoryID INT)
BEGIN
DECLARE intQty,intProductID INT;
DECLARE isCustomerClubMember VARCHAR(10);
DECLARE intCustomerID LONG;
DECLARE fProdOfferPrice,fProdClubPrice,fIGSTPer,fCGSTPer,fSGSTPer float;
DECLARE fPriceP,fRate,fCGST,fSGST,fIGST,fperPrice FLOAT;
-- ++++++++++++++++++++++++++++++++++
DECLARE done INT DEFAULT FALSE;
DECLARE cur_prodlist CURSOR FOR 
SELECT BaseValue,CgstAmount,SgstAmount,IgstAmount,net_amount,QTY,product_id
FROM karloff_weborder_details WHERE order_id = intOrderID AND product_subcategory_id = intSubCategoryID;
 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; 
-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++


SET intQty = 0; set intProductID = 0;
SET isCustomerClubMember = ''; SET intCustomerID=0;
SET fProdOfferPrice = 0;SET fProdClubPrice = 0;SET fIGSTPer = 0;SET fCGSTPer = 0;SET fSGSTPer = 0;
SET fPriceP =0; set fRate = 0; set fCGST = 0; set fSGST =0; set fIGST = 0;set fperPrice=0;

  select customer_id into intCustomerID from karloff_weborder where order_id = strOrderID; 
 -- +++++++++++++++++++++++++++++++++++++++
 OPEN cur_prodlist;
  read_loop: LOOP
    FETCH cur_prodlist INTO fRate,fCGST,fSGST,fIGST,fPriceP,intQty,intProductID;
    IF done THEN
      LEAVE read_loop;
    END IF;
  
    update karloff_weborder set BaseValue = (BaseValue - fRate),CgstAmount = (CgstAmount - fCGST), 
	SgstAmount = (SgstAmount - fSGST),IgstAmount = (IgstAmount - fIGST),InvoiceAmount = (InvoiceAmount - fPriceP),
	NetAmount = (NetAmount - fPriceP),updated_at= CURRENT_TIMESTAMP() where order_id = intOrderID;
    -- RESET ALL VALUES    
    SET fPriceP =0; set fRate = 0; set fCGST = 0; set fSGST =0; set fIGST = 0; set fperPrice =0;   
        
 -- GET PRODUCT VALUE DETAILS 
    CALL sp_getProduct_pricedetails(intProductID,intCouponAmount,intCustomerID,intQty,fperPrice,fRate,fSGST,fCGST,fIGST,fPriceP);

 
 -- APPLIED FINAL DETAILS
   UPDATE karloff_weborder_details SET `BaseValue` = fRate,`CgstAmount`= fCGST,`SgstAmount`= fSGST,
   `IgstAmount`= fIGST,`net_amount`= fPriceP 	
	WHERE order_id = intOrderID AND product_id = intProductID;
 
	update karloff_weborder set BaseValue = (BaseValue + fRate),CgstAmount = (CgstAmount + fCGST), 
	SgstAmount = (SgstAmount + fSGST),IgstAmount = (IgstAmount + fIGST),InvoiceAmount = (InvoiceAmount + fPriceP),
	NetAmount = (NetAmount + fPriceP),updated_at= CURRENT_TIMESTAMP() where order_id = intOrderID;       
   
  END LOOP;
  CLOSE cur_prodlist;
-- ++++++++++++++++++++++++++++++++++++++    
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_UpdatePsudoProductStock` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_UpdatePsudoProductStock`(IN `intProductID` INT, IN `intQty` INT, IN `intOrderID` VARCHAR(200), IN `intRemoved` INT)
BEGIN

	IF (intRemoved = 1) THEN  -- Product Added on cart
      update karloff_productdb set PseudoStock = (PseudoStock - intQty) where id = intProductID;
	ELSE   -- Product Removed from cart
       update karloff_productdb set PseudoStock = (PseudoStock + intQty) where id = intProductID;
   
     CALL sp_UpdateWebOrderTableforProductRemoved(intProductID,intQty,intOrderID);
	
    END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_UpdateWebOrderTableforProductRemoved` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_UpdateWebOrderTableforProductRemoved`(IN `intProductID` INT, IN `intQty` INT, IN `intOrderID` BIGINT)
BEGIN

DECLARE fPriceP,fRate,fCGST,fSGST,fIGST FLOAT;
DECLARE intTotalProductinCart INT;

SET fPriceP =0; set fRate = 0; set fCGST = 0; set fSGST =0; set fIGST = 0;
SET intTotalProductinCart = 0;

SELECT `BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`net_amount` 
INTO fRate,fCGST,fSGST,fIGST,fPriceP
FROM karloff_weborder_details WHERE order_id = intOrderID AND product_id = intProductID;


update karloff_weborder set BaseValue = (BaseValue - fRate),CgstAmount = (CgstAmount - fCGST), 
		SgstAmount = (SgstAmount - fSGST),IgstAmount = (IgstAmount - fIGST),InvoiceAmount = (InvoiceAmount - fPriceP),
		NetAmount = (NetAmount - fPriceP),updated_at= CURRENT_TIMESTAMP()
		where order_id = intOrderID;

DELETE FROM karloff_weborder_details WHERE order_id = intOrderID AND product_id = intProductID;

SELECT COUNT(ID) INTO intTotalProductinCart FROM karloff_weborder_details WHERE order_id = intOrderID;
IF (intTotalProductinCart = 0) THEN
  DELETE FROM karloff_weborder WHERE order_id = intOrderID;
END IF;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_update_CustomerMembership` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_update_CustomerMembership`(IN strCustomerID VARCHAR(200),
IN strOrderID VARCHAR(200),
IN intMembershipID INT)
BEGIN

-- update karloff_address_manager set is_default=1 where customer_id = strCustomerID;
/*
INSERT INTO `karloff_club_membership`(`customer_id`,`membership_id`,`transaction_id`,`expiry`,`status`,`created_at`,`updated_at`)
VALUES(
**************************************

INSERT INTO `karloff_transaction`(`txn_id`,`paymentCategory`,`txn_amount`,`payment_mode`,`bank_txnid`,`txn_order_id`,`txn_status`,`txn_type`,
`txn_gateway_name`,`txn_resp_code`,`txn_bank_name`,`txn_date`,`order_date`,`order_datetime`,`isRefund`)
VALUES( );

 INSERT INTO `karloff_weborder_details`(`order_id`,`customer_id`,`product_id`,`product_category_id`,`product_subcategory_id`,`BaseValue`,`CgstAmount`,
`SgstAmount`,`IgstAmount`,`qty`,`net_amount`,`updated_at`,`created_at`)
VALUES(intOrderID,intCustomerID,intProductID,intProdCat,intProdSubCat,fRate,fCGST,fSGST,fIGST,intQty,fPriceP,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP());


 INSERT INTO `karloff_weborder`(`storeId`,`order_id`,`customer_id`,`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`InvoiceAmount`,
		`NetAmount`,`order_status`,`order_date`,`updated_at`,`created_at`)
		VALUES(int

*/
select * from  karloff_address_manager ;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_update_deliverydetails` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_update_deliverydetails`(IN strOrderID VARCHAR(200),
IN strDateDTLS VARCHAR(200),
IN intslotid INT,
OUT strOutPutDTLS VARCHAR(200))
BEGIN
DECLARE strfromd,strtod,finaldetails VARCHAR(60);
select TIME_FORMAT(DeliverySlotFrom, '%r'),TIME_FORMAT(DeliverySlotUpto, '%r') into strfromd,strtod from karloff_delivery_slot where id = intslotid;
set finaldetails = CONCAT(strDateDTLS,', ',strfromd,' - ',strtod);
update karloff_weborder set delivery_date = finaldetails  where order_id = strOrderID;
set strOutPutDTLS = finaldetails;
-- update karloff_address_manager set is_default=1 where customer_id = strCustomerID;
/*
 select TIME_FORMAT('17:20:25', '%r');
 
 
 INSERT INTO `karloff_weborder_details`(`order_id`,`customer_id`,`product_id`,`product_category_id`,`product_subcategory_id`,`BaseValue`,`CgstAmount`,
`SgstAmount`,`IgstAmount`,`qty`,`net_amount`,`updated_at`,`created_at`)
VALUES(intOrderID,intCustomerID,intProductID,intProdCat,intProdSubCat,fRate,fCGST,fSGST,fIGST,intQty,fPriceP,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP());


 INSERT INTO `karloff_weborder`(`storeId`,`order_id`,`customer_id`,`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`InvoiceAmount`,
		`NetAmount`,`order_status`,`order_date`,`updated_at`,`created_at`)
		VALUES(int

*/
-- select * from  karloff_address_manager ;
-- SET strOutPutDTLS ='okaY SP CALL';
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sp_update_orderdelivaryboydetails` */;
DELIMITER ;;
CREATE  PROCEDURE `sp_update_orderdelivaryboydetails`(IN intOrderID VARCHAR(200),
IN intdelivaryboyid INT)
BEGIN
DECLARE strpaymentcode VARCHAR(60);

INSERT INTO `karloff_deliveryboystat`(`deliveryBoyId`,`orderId`,`status`,`updated_at`,`created_at`)
VALUES(intdelivaryboyid,intOrderID,4,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP);

/* select payment_code into strpaymentcode from karloff_weborder where order_id = intOrderID;
 IF(strpaymentcode = 'TXN_SUCCESS') THEN
 
 ELSE
 
 END IF; */
update karloff_weborder set order_status= 4 where order_id = intOrderID;


/* 
select TIME_FORMAT(DeliverySlotFrom, '%r'),TIME_FORMAT(DeliverySlotUpto, '%r') into strfromd,strtod from karloff_delivery_slot where id = intslotid;
set finaldetails = CONCAT(strDateDTLS,', ',strfromd,' - ',strtod);
update karloff_weborder set delivery_date = finaldetails  where order_id = strOrderID;
set strOutPutDTLS = finaldetails; */
-- select TIME_FORMAT('17:20:25', '%r');
-- update karloff_address_manager set is_default=1 where customer_id = strCustomerID;
/*
 select TIME_FORMAT('17:20:25', '%r');
 
 
 INSERT INTO `karloff_weborder_details`(`order_id`,`customer_id`,`product_id`,`product_category_id`,`product_subcategory_id`,`BaseValue`,`CgstAmount`,
`SgstAmount`,`IgstAmount`,`qty`,`net_amount`,`updated_at`,`created_at`)
VALUES(intOrderID,intCustomerID,intProductID,intProdCat,intProdSubCat,fRate,fCGST,fSGST,fIGST,intQty,fPriceP,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP());


 INSERT INTO `karloff_weborder`(`storeId`,`order_id`,`customer_id`,`BaseValue`,`CgstAmount`,`SgstAmount`,`IgstAmount`,`InvoiceAmount`,
		`NetAmount`,`order_status`,`order_date`,`updated_at`,`created_at`)
		VALUES(int

*/
-- select * from  karloff_address_manager ;
-- SET strOutPutDTLS ='okaY SP CALL';
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `test_procedure` */;
DELIMITER ;;
CREATE  PROCEDURE `test_procedure`()
BEGIN
DECLARE intProductID,intQty,intUserID INT;
DECLARE intCustomerID,intOrderID BIGINT;
  DECLARE strCuponDTLS,strOutPutDTLS VARCHAR(500);
 --  `sp_AddtoCart_OneProduct`(IN intProductID INT,IN intCustomerID BIGINT,IN intOrderID BIGINT,IN intQty INT,IN intUserID INT) 
 
/* SET intProductID = 103; SET intQty =1;  SET intUserID = 40;
  SET intCustomerID = 1577437; SET intOrderID =2020070712170840; 
  
 call `sp_AddtoCart_OneProduct`(intProductID,intCustomerID,intOrderID,intQty,intUserID);*/
-- SELECT Param3;
 -- select ;
 
/* SET intProductID = 259; SET intQty =2;
  SET intOrderID =2020060617165140; 
 call sp_UpdatePsudoProductStock(intProductID,intQty,intOrderID,0); */
 
 -- CALL sp_getSearch_OrderList('','','','','','');
 
 -- call sp_getOrderCountdown_dtls();
 /* SET intOrderID =2020062617210440; set strCuponDTLS = 'TESTDISCOUNT2';
 call sp_Cupon_Applydetails(intOrderID,strCuponDTLS,strOutPutDTLS);
 select strOutPutDTLS; */
  SET intOrderID =2020062617210440;
 call sp_Cupon_DetailsfrmOrder(intOrderID,strOutPutDTLS);
 select strOutPutDTLS;
 
END ;;
DELIMITER ;


