-- --------------------------------------------------------
-- Host:                         127.0.0.1
-- Server version:               5.7.33 - MySQL Community Server (GPL)
-- Server OS:                    Win64
-- HeidiSQL Version:             11.2.0.6213
-- --------------------------------------------------------

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

-- Dumping structure for view hgagent.ptl_bal_qty_view
DROP VIEW IF EXISTS `ptl_bal_qty_view`;
-- Creating temporary table to overcome VIEW dependency errors
CREATE TABLE `ptl_bal_qty_view` (
	`list_promoter_task_data_id` BIGINT(20) UNSIGNED NULL,
	`promoter_id` BIGINT(20) UNSIGNED NOT NULL,
	`product_name` VARCHAR(191) NULL COLLATE 'utf8mb4_unicode_ci',
	`promoter_task_list_id` BIGINT(20) UNSIGNED NOT NULL,
	`promoter_task_list_product_id` BIGINT(20) UNSIGNED NULL,
	`t_qty` INT(11) NULL,
	`o_qty` INT(11) NULL,
	`l_qty` INT(1) NOT NULL,
	`remark` VARCHAR(191) NULL COLLATE 'utf8mb4_unicode_ci'
) ENGINE=MyISAM;

-- Dumping structure for view hgagent.ptl_bal_qty_view
DROP VIEW IF EXISTS `ptl_bal_qty_view`;
-- Removing temporary table and create final VIEW structure
DROP TABLE IF EXISTS `ptl_bal_qty_view`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `ptl_bal_qty_view` AS SELECT lptd.`id` as list_promoter_task_data_id, lpt.`promoter_id` as promoter_id, ptlp.`name` as product_name, lpt.`promoter_task_list_id` as promoter_task_list_id, lptd.`promoter_task_list_product_id` as promoter_task_list_product_id, lptd.`t_qty` AS t_qty, lptd.`o_qty` AS o_qty, 0 as l_qty, lptd.`remark` as remark
    FROM `list_promoter_task` lpt LEFT JOIN `list_promoter_task_data` lptd ON lptd.`list_promoter_task_id` = lpt.`id` LEFT JOIN `promoter_task_list_products` ptlp ON ptlp.`id` = lptd.`promoter_task_list_product_id` ;

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