-- --------------------------------------------------------
-- Server OS:                    Win64
-- HeidiSQL Version:             11.2.0.6213
-- --------------------------------------------------------


-- Dumping structure for view hgagent.pl_bal_qty_view
-- Creating temporary table to overcome VIEW dependency errors
CREATE TABLE `pl_bal_qty_view` (
	`id` BIGINT(20) UNSIGNED NOT NULL,
	`pl_id` BIGINT(20) UNSIGNED NULL,
	`ref_no` VARCHAR(191) NULL COLLATE 'utf8mb4_unicode_ci',
	`item_code` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_unicode_ci',
	`description` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_unicode_ci',
	`ordered_qty` INT(11) NOT NULL,
	`picked_qty` BIGINT(11) NOT NULL,
	`picking_qty` BIGINT(11) NOT NULL
) ENGINE=MyISAM;

-- Dumping structure for view hgagent.pl_bal_qty_view
-- Removing temporary table and create final VIEW structure
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `pl_bal_qty_view` AS SELECT pld.`id` as id, pld.`picking_list_id` as pl_id, pl.ref_no AS ref_no, pld.`item_code`, pld.`description`, pld.`ordered_qty`, 0 as `picked_qty`, 0 as `picking_qty`
    FROM `picking_list_data` pld LEFT JOIN picking_lists pl on pl.id=pld.picking_list_id
    GROUP BY pld.`item_code`
    UNION ALL
    SELECT pld.`id` as id, pld.`picking_list_id` as pl_id, pl.ref_no AS ref_no, pld.`item_code`, pld.`description`, pld.`ordered_qty`, pld.`picked_qty`, pld.`picking_qty`
    FROM `picking_list_data` pld LEFT JOIN picking_lists pl on  pl.id=pld.picking_list_id ;

