-- Dumping data for table `tbl_payment_summary_details`
--


--
-- Table structure for table `tbl_payment_summary_invoices`
--

CREATE TABLE `tbl_payment_summary_invoices` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sale_invoice_id` int NOT NULL,
  `sub_total` decimal(16,2) NOT NULL,
  `total_discount` decimal(16,2) NOT NULL,
  `settled_amount` decimal(16,2) NOT NULL,
  `paid_returns` decimal(16,2) NOT NULL,
  `payAmount` decimal(16,2) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `ps_id` int NOT NULL,
  `is_settled` tinyint(1) NOT NULL DEFAULT '0',
  `net_total` decimal(16,2) NOT NULL,
  `is_cancelled` tinyint(1) NOT NULL DEFAULT '0',
  `allocated_amount` decimal(16,2) NOT NULL DEFAULT '0.00',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_payment_summary_invoices`
--


--
-- Table structure for table `tbl_po_products`
--

CREATE TABLE `tbl_po_products` (
  `po_product_id` int NOT NULL AUTO_INCREMENT,
  `po_id` int NOT NULL,
  `prn_id` int NOT NULL,
  `supplier_id` int NOT NULL,
  `product_id` int NOT NULL,
  `prn_qty` decimal(18,6) NOT NULL,
  `min_po_qty` decimal(18,6) NOT NULL,
  `balance_qty` decimal(18,6) NOT NULL,
  `inventory_qty` decimal(18,6) NOT NULL,
  `qty` decimal(18,6) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `unitPrice` decimal(11,4) NOT NULL,
  `total` decimal(11,4) NOT NULL,
  `status` varchar(50) NOT NULL,
  PRIMARY KEY (`po_product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_po_products`
--


--
-- Table structure for table `tbl_pos`
--

CREATE TABLE `tbl_pos` (
  `po_id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `supplier_id` int NOT NULL,
  `prn_id` int NOT NULL,
  `status` varchar(50) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `po_type` varchar(50) NOT NULL,
  `po_date` date NOT NULL DEFAULT '2020-01-01',
  `dis_type` varchar(10) NOT NULL,
  `discount_rate` decimal(11,2) NOT NULL,
  `discount` decimal(11,2) NOT NULL,
  `sub_total` decimal(11,2) NOT NULL,
  `total` decimal(11,2) NOT NULL,
  `location_id` int NOT NULL,
  `to_be_delivered_to` varchar(500) NOT NULL,
  `to_be_delivered_on` varchar(500) NOT NULL,
  `special_instructions` varchar(2500) NOT NULL,
  `currency_id` int NOT NULL DEFAULT '0',
  `exchange_rate` decimal(16,4) NOT NULL DEFAULT '0.0000',
  PRIMARY KEY (`po_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_pos`
--


--
-- Table structure for table `tbl_pos_details`
--

CREATE TABLE `tbl_pos_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_pos_details`
--


--
-- Table structure for table `tbl_prns`
--

CREATE TABLE `tbl_prns` (
  `prn_id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `status` varchar(50) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `location_id` int NOT NULL,
  PRIMARY KEY (`prn_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_prns`
--


--
-- Table structure for table `tbl_prns_contracts`
--

CREATE TABLE `tbl_prns_contracts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `contract_id` int NOT NULL,
  `prn_id` int NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `status` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_prns_contracts`
--


--
-- Table structure for table `tbl_prns_details`
--

CREATE TABLE `tbl_prns_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_prns_details`
--


--
-- Table structure for table `tbl_product_accounts`
--

CREATE TABLE `tbl_product_accounts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `product_id` int NOT NULL,
  `cogs_account` varchar(1000) NOT NULL,
  `asset_account` varchar(1000) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_accounts`
--


--
-- Table structure for table `tbl_product_branch_cost`
--

CREATE TABLE `tbl_product_branch_cost` (
  `id` int NOT NULL AUTO_INCREMENT,
  `cost` decimal(16,2) NOT NULL,
  `avg_cost` decimal(16,2) NOT NULL,
  `created_on` datetime NOT NULL,
  `product_id` int NOT NULL,
  `location_id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_branch_cost`
--


--
-- Table structure for table `tbl_product_brands`
--

CREATE TABLE `tbl_product_brands` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `brand` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `image` varchar(500) NOT NULL DEFAULT 'dist/img/empty.png',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_brands`
--


--
-- Table structure for table `tbl_product_brands_details`
--

CREATE TABLE `tbl_product_brands_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_brands_details`
--


--
-- Table structure for table `tbl_product_catalogue`
--

CREATE TABLE `tbl_product_catalogue` (
  `id` int NOT NULL AUTO_INCREMENT,
  `product_id` int NOT NULL,
  `qty` decimal(10,0) NOT NULL,
  `uniqid` varchar(1000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `customer_id` int NOT NULL,
  `unit_price` decimal(16,2) NOT NULL,
  `location_id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_catalogue`
--


--
-- Table structure for table `tbl_product_details`
--

CREATE TABLE `tbl_product_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_details`
--


--
-- Table structure for table `tbl_product_price_approvels`
--

CREATE TABLE `tbl_product_price_approvels` (
  `id` int NOT NULL AUTO_INCREMENT,
  `invoice_id` int NOT NULL,
  `product_id` int NOT NULL,
  `price` decimal(10,0) NOT NULL,
  `cost_price` decimal(10,0) NOT NULL,
  `minimum_price` decimal(10,0) NOT NULL,
  `entered_price` decimal(10,0) NOT NULL,
  `discounted_price` decimal(10,0) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `invoice_reference` varchar(500) NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_price_approvels`
--


--
-- Table structure for table `tbl_product_price_groups`
--

CREATE TABLE `tbl_product_price_groups` (
  `id` int NOT NULL AUTO_INCREMENT,
  `price_group` varchar(100) NOT NULL,
  `price_column` varchar(50) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `min_price_column` varchar(50) NOT NULL,
  `created_on` datetime NOT NULL DEFAULT '2020-01-01 00:00:00',
  `created_by` int NOT NULL,
  `updated_on` datetime NOT NULL DEFAULT '2020-01-01 00:00:00',
  `updated_by` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_price_groups`
--

INSERT INTO `tbl_product_price_groups` VALUES (1,'Default','price',1,0,'minimum_price','2020-01-01 00:00:00',0,'2020-01-01 00:00:00',0);

--
-- Table structure for table `tbl_product_price_history`
--

CREATE TABLE `tbl_product_price_history` (
  `id` int NOT NULL AUTO_INCREMENT,
  `product_id` int NOT NULL,
  `price` decimal(16,2) NOT NULL,
  `updated_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `type` varchar(50) NOT NULL DEFAULT 'price',
  `old_price` decimal(16,2) NOT NULL,
  `price_group_id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_price_history`
--


--
-- Table structure for table `tbl_product_searial_nos`
--

CREATE TABLE `tbl_product_searial_nos` (
  `id` int NOT NULL AUTO_INCREMENT,
  `product_id` int NOT NULL,
  `invoice_id` int NOT NULL,
  `serial_ref` varchar(100) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `serial_no` varchar(100) NOT NULL,
  `status` varchar(10) NOT NULL,
  `return_id` int NOT NULL,
  `returned_on` datetime NOT NULL DEFAULT '2020-01-01 00:00:00',
  `returned_by` int NOT NULL,
  `serial_id` int NOT NULL,
  `description` varchar(1000) NOT NULL,
  `serial_status` varchar(50) NOT NULL DEFAULT 'issued',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_searial_nos`
--


--
-- Table structure for table `tbl_product_serial_numbers`
--

CREATE TABLE `tbl_product_serial_numbers` (
  `id` int NOT NULL AUTO_INCREMENT,
  `product_id` int NOT NULL,
  `grn_uniqid` varchar(1000) NOT NULL,
  `grn_id` int NOT NULL,
  `serial_number` varchar(1000) NOT NULL,
  `grn_product_id` int NOT NULL,
  `status` varchar(100) NOT NULL,
  `is_authorized` tinyint(1) NOT NULL DEFAULT '0',
  `current_invoice_id` int NOT NULL,
  `serialRef` varchar(1000) NOT NULL,
  `return_id` int NOT NULL,
  `return_uniqid` varchar(1000) NOT NULL,
  `description` varchar(1000) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_serial_numbers`
--


--
-- Table structure for table `tbl_product_uom`
--

CREATE TABLE `tbl_product_uom` (
  `id` int NOT NULL AUTO_INCREMENT,
  `uom_id` int NOT NULL,
  `product_id` int NOT NULL,
  `value` decimal(11,4) NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `selling_precentage` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_product_uom`
--

INSERT INTO `tbl_product_uom` VALUES (1,9,1561,1.0000,0,0);

--
-- Table structure for table `tbl_productcategory`
--

CREATE TABLE `tbl_productcategory` (
  `productCategory_id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `category` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `serial_no` varchar(100) NOT NULL DEFAULT '',
  `image` varchar(500) NOT NULL DEFAULT 'dist/img/empty.png',
  `fn_acount_id` int NOT NULL,
  `fn_account_name` varchar(1000) NOT NULL,
  PRIMARY KEY (`productCategory_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_productcategory`
--


--
-- Table structure for table `tbl_productcategory_details`
--

CREATE TABLE `tbl_productcategory_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_productcategory_details`
--


--
-- Table structure for table `tbl_production_plans`
--

CREATE TABLE `tbl_production_plans` (
  `plan_id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `plan_date` datetime NOT NULL,
  `description` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `status` varchar(50) DEFAULT NULL,
  `is_outsource` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`plan_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_production_plans`
--


--
-- Table structure for table `tbl_production_plans_contracts`
--

CREATE TABLE `tbl_production_plans_contracts` (
  `productionPlansContract_id` int NOT NULL AUTO_INCREMENT,
  `contract_id` int NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `plan_id` int NOT NULL,
  PRIMARY KEY (`productionPlansContract_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_production_plans_contracts`
--


--
-- Table structure for table `tbl_production_plans_details`
--

CREATE TABLE `tbl_production_plans_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_production_plans_details`
--


--
-- Table structure for table `tbl_production_plans_process`
--

CREATE TABLE `tbl_production_plans_process` (
  `id` int NOT NULL AUTO_INCREMENT,
  `plan_id` int NOT NULL,
  `is_row_material` tinyint(1) NOT NULL DEFAULT '0',
  `product_id` int NOT NULL,
  `tree_id` varchar(50) NOT NULL,
  `is_process_start` tinyint(1) NOT NULL DEFAULT '0',
  `is_process_finished` tinyint(1) NOT NULL DEFAULT '0',
  `qty` decimal(18,6) NOT NULL,
  `is_proceed` int NOT NULL DEFAULT '0',
  `boqId` int NOT NULL DEFAULT '0',
  `parent_id` int NOT NULL DEFAULT '0',
  `mrn_qty` decimal(18,6) DEFAULT '0.000000',
  `allocated_qty` decimal(18,6) NOT NULL DEFAULT '0.000000',
  `process_started_on` datetime NOT NULL DEFAULT '2021-01-01 00:00:01',
  `process_started_by` int DEFAULT NULL,
  `process_finished_on` datetime NOT NULL DEFAULT '2021-01-01 00:00:01',
  `process_finished_by` int DEFAULT NULL,
  `actBoqId` int DEFAULT NULL,
  `production_qty` decimal(16,6) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_production_plans_process`
--


--
-- Table structure for table `tbl_products`
--

CREATE TABLE `tbl_products` (
  `product_id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `barcode` varchar(50) NOT NULL DEFAULT '',
  `category_id` int NOT NULL,
  `name` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `is_row_material` tinyint(1) NOT NULL DEFAULT '0',
  `product_tags` varchar(2500) DEFAULT NULL,
  `cat_tags` varchar(2500) DEFAULT NULL,
  `model_tags` varchar(2500) DEFAULT NULL,
  `brand_id` int NOT NULL,
  `brand_tags` varchar(2500) DEFAULT NULL,
  `product_search` varchar(500) DEFAULT NULL,
  `price` decimal(16,2) NOT NULL,
  `cost_price` decimal(16,2) NOT NULL,
  `is_inventoryProduct` tinyint(1) NOT NULL DEFAULT '0',
  `price_last_updated_on` datetime NOT NULL DEFAULT '2021-01-01 00:00:00',
  `bin_1` varchar(20) NOT NULL,
  `is_serial` tinyint(1) NOT NULL DEFAULT '0',
  `minimum_price` decimal(16,2) NOT NULL DEFAULT '0.00',
  `updated_price_group_id` int NOT NULL,
  `Branch` decimal(16,2) NOT NULL,
  `min_Branch` decimal(16,2) NOT NULL,
  `avg_cost_price` decimal(16,2) NOT NULL,
  `is_edit_name` tinyint(1) NOT NULL DEFAULT '0',
  `uom_id` int NOT NULL,
  `is_rent` tinyint(1) NOT NULL DEFAULT '0',
  `deposits` decimal(11,2) NOT NULL,
  `image` varchar(1000) NOT NULL DEFAULT 'dist/img/empty.png',
  `Cash` decimal(16,2) NOT NULL,
  `min_Cash` decimal(16,2) NOT NULL,
  `subcategory_id` int NOT NULL DEFAULT '0',
  `vat_percentage` decimal(11,2) NOT NULL DEFAULT '0.00',
  `import_id` int NOT NULL,
  `is_depositByItemCount` tinyint(1) NOT NULL DEFAULT '0',
  `reorder_qty` decimal(16,2) NOT NULL,
  `min_order_qty` decimal(16,2) NOT NULL,
  `is_sale` tinyint(1) NOT NULL DEFAULT '1',
  `is_meal` tinyint(1) NOT NULL DEFAULT '0',
  `is_bot` tinyint(1) NOT NULL DEFAULT '0',
  `p_id` int NOT NULL,
  PRIMARY KEY (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_products`
--


--
-- Table structure for table `tbl_productsubcategory`
--

CREATE TABLE `tbl_productsubcategory` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `category` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `serial_no` varchar(100) NOT NULL DEFAULT '',
  `image` varchar(500) NOT NULL DEFAULT 'dist/img/empty.png',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_productsubcategory`
--


--
-- Table structure for table `tbl_productsubcategory_details`
--

CREATE TABLE `tbl_productsubcategory_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_productsubcategory_details`
--


--
-- Table structure for table `tbl_project`
--

CREATE TABLE `tbl_project` (
  `project_id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `status` varchar(50) NOT NULL,
  `perimeterSurveyApproval` tinyint(1) NOT NULL DEFAULT '0',
  `blokingOutPlanApproval` tinyint(1) NOT NULL DEFAULT '0',
  `extractsApproval` tinyint(1) NOT NULL DEFAULT '0',
  `fragmentationApprovals` tinyint(1) NOT NULL DEFAULT '0',
  `waterBoardApproval` tinyint(1) NOT NULL DEFAULT '0',
  `electricityBoardApproval` tinyint(1) NOT NULL DEFAULT '0',
  `culvertAndBridgeApproval` tinyint(1) NOT NULL DEFAULT '0',
  `mode_of_purchase` varchar(50) NOT NULL DEFAULT '',
  `perimeterSurveyStatus` varchar(50) NOT NULL,
  `blokingOutPlanStatus` varchar(50) NOT NULL,
  `extractsStatus` varchar(50) NOT NULL,
  `fragmentationStatus` varchar(50) NOT NULL,
  `waterBoardStatus` varchar(50) NOT NULL,
  `electricityBoardStatus` varchar(50) NOT NULL,
  `culvertAndBridgeStatus` varchar(50) NOT NULL,
  PRIMARY KEY (`project_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_project`
--


--
-- Table structure for table `tbl_project_other_details`
--

CREATE TABLE `tbl_project_other_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_project_other_details`
--


--
-- Table structure for table `tbl_re_assemble`
--

CREATE TABLE `tbl_re_assemble` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `status` varchar(50) NOT NULL,
  `product_id` int NOT NULL DEFAULT '0',
  `discription` varchar(500) NOT NULL,
  `type` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `qty` decimal(11,2) NOT NULL DEFAULT '0.00',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_re_assemble`
--


--
-- Table structure for table `tbl_re_assemble_details`
--

CREATE TABLE `tbl_re_assemble_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_re_assemble_details`
--


--
-- Table structure for table `tbl_re_assemble_products`
--

CREATE TABLE `tbl_re_assemble_products` (
  `id` int NOT NULL AUTO_INCREMENT,
  `re_assemble_id` int NOT NULL,
  `product_id` int NOT NULL,
  `qty` decimal(11,2) NOT NULL DEFAULT '0.00',
  `description` varchar(50) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_re_assemble_products`
--


--
-- Table structure for table `tbl_reference_prifix`
--

CREATE TABLE `tbl_reference_prifix` (
  `id` int NOT NULL AUTO_INCREMENT,
  `type` varchar(45) DEFAULT NULL,
  `prifix` varchar(45) DEFAULT NULL,
  `number_padding` int DEFAULT NULL,
  `branch_id` int NOT NULL DEFAULT '0',
  `current_no` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=197 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_reference_prifix`
--

INSERT INTO `tbl_reference_prifix` VALUES (1,'contract','CSN-{trn_id}',6,1,0),(2,'purchase_requisition_note','PRN-{trn_id}',6,1,0),(3,'purchase_order','PO-{trn_id}',6,1,309),(4,'good_receive_note','GRN-{trn_id}',6,1,265),(5,'production_plan','PPO-{trn_id}',6,1,0),(6,'material_request_note','MRN-{trn_id}',6,1,0),(7,'sales_order','SO-{trn_id}',6,1,0),(8,'samples','SAM-{trn_id}',6,1,0),(9,'damage','DAM-{trn_id}',6,1,0),(10,'grn_returns','GRT-{trn_id}',6,1,0),(11,'dispatch','DSP-{trn_id}',6,1,0),(12,'material_request_issue','MRI-{trn_id}',6,1,0),(13,'supplier_payments','SUP-{trn_id}',6,1,47),(14,'customer_payments','CUP-{trn_id}',6,1,0),(15,'call_log','CRM-{trn_id}',4,1,0),(16,'advance_payment','SIAP/AP-{trn_id}',4,1,0),(17,'advance_payment','SIAP/AP-{trn_id}',4,1,0),(18,'over_payment','OVP-{trn_id}',4,1,0),(19,'advance_payment','SIAP/AP-{trn_id}',4,1,0),(20,'over_payment','OVP-{trn_id}',4,1,0),(21,'sales_invoice_return','SIR-{trn_id}',4,1,1),(22,'comisions','SIC-{trn_id}',4,1,0),(23,'sales_invoice','SIV-{trn_id}',4,1,0),(24,'estimate','AEE-{trn_id}',4,1,0),(25,'job_invoice','AEJI-{trn_id}',4,1,0),(26,'cancelled_invoice_over_payment','OPCI-{trn_id}',4,1,0),(27,'cancel_payment','CP-{trn_id}',4,1,2),(28,'estimation_invoice','AEEI-{trn_id}',4,1,0),(29,'draft_hold_invoices','INV-{serial_id}',4,1,4266),(30,'credit_invoices','INV-{trn_id}',4,1,0),(31,'Customer','CUS-{trn_id}',4,1,13),(32,'return_over_payment','OPRI-{trn_id}',4,1,0),(35,'StockAdjustment','SAJ-{trn_id}',4,1,0),(36,'product_category','{trn_id}',4,1,18),(37,'product','PRO-{trn_id}\r\n',4,1,1268),(102,'category_serial_no','{serial_id}',4,1,8),(103,'grn','SGRN-{trn_id}',4,0,0),(104,'stock','SGRN-{trn_id}',4,0,0),(105,'Stocktake','STK-{trn_id}',4,1,0),(108,'scanned_grn','SGRN-{trn_id}',4,1,0),(109,'re_assemble','RASB-{trn_id}',4,1,0),(110,'assemble','ASB-{trn_id}',4,1,0),(111,'paymentSummary','SIAP-{trn_id}',4,1,4266),(114,'PaymentAdjustment','PA-{trn_id}',4,1,0),(153,'inventry_transfer','IT-{trn_id}',4,1,0),(157,'expenses_type','exp-{trn_id}',4,1,0),(161,'expenses','exp-{trn_id}',4,1,0),(165,'SalesRep','SRP-{trn_id}',4,1,0),(169,'import_good_receive_note','IGRN-{trn_id}',6,1,0),(170,'import_good_receive_note','IGRN-{trn_id}',6,2,0),(171,'import_good_receive_note','IGRN-{trn_id}',6,3,0),(172,'import_good_receive_note','IGRN-{trn_id}',6,4,0),(173,'sales_invoice','SIV-{trn_id}',4,100,0),(174,'draft_hold_invoices','com-{serial_id}',4,100,0),(175,'pump_receipts','GPR-{trn_id}',4,1,0),(176,'pump_meter_reading','GPMR-{trn_id}',4,1,0),(177,'import_grn_returns','IGR-{trn_id}',4,1,0),(178,'samples_return','SR-{trn_id}',4,1,0),(179,'inv_cost','INVC-{trn_id}',4,1,0),(180,'inv_cost','INVC-{trn_id}',4,2,0),(181,'tax_free','ATF/01-{serial_id}',4,1,0),(182,'tax_free','ATF/02-{serial_id}',4,2,0),(183,'tax_free','ATF/03-{serial_id}',4,3,0),(184,'tax_free','ATF/04-{serial_id}',4,4,0),(185,'invoice_void','VOD{serial_id}',4,1,0),(186,'invoice_unsetled','UNS{serial_id}',4,1,34457),(187,'return_cheques','CR-{serial_id}',4,1,0),(188,'return_cheques','CR-{serial_id}',4,2,0),(189,'return_cheques','CR-{serial_id}',4,3,0),(190,'return_cheques','CR-{serial_id}',4,4,0),(191,'return_cheques','CR-{serial_id}',4,5,0),(192,'return_cheques','CR-{serial_id}',4,6,0),(193,'return_cheques','CR-{serial_id}',4,7,0),(194,'return_cheques','CR-{serial_id}',4,8,0),(195,'sales_invoice_return_tax','SIRT/1-{serial_id}',4,1,0),(196,'supplier_return_cheques','SCR-{trn_id}',4,1,0);

--
-- Table structure for table `tbl_report_groups`
--

CREATE TABLE `tbl_report_groups` (
  `group_id` int NOT NULL AUTO_INCREMENT,
  `group_name` varchar(100) NOT NULL,
  PRIMARY KEY (`group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_report_groups`
--

INSERT INTO `tbl_report_groups` VALUES (1,'Customer'),(2,'Sales'),(3,'Inventory'),(4,'Profit & Lost'),(5,'Expenses'),(6,'Suppliers');

--
-- Table structure for table `tbl_report_search_fields`
--

CREATE TABLE `tbl_report_search_fields` (
  `id` int NOT NULL AUTO_INCREMENT,
  `type` varchar(50) NOT NULL,
  `lable` varchar(100) NOT NULL,
  `default_value` varchar(100) NOT NULL,
  `report_id` int NOT NULL,
  `field_id` varchar(100) NOT NULL,
  `quary` text NOT NULL,
  `is_hidden` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=672 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_report_search_fields`
--

INSERT INTO `tbl_report_search_fields` VALUES (91,'Date','From date','default',1,'fromDate','',0),(92,'Date','To date','default',1,'toDate','',0),(117,'Date','From date','default',3,'fromDate','',0),(118,'Date','To date','default',3,'toDate','',0),(119,'Ajax Dropdown','Customer','select',3,'customer','SELECT * from (\r\nSELECT customer_id as id , concat(code ,\' - \'  ,customer_name )as text FROM tbl_customers \r\n)tmp\r\nwhere (text like \'%{customer}%\'  or  \'{customer}\'= \'0\')\r\norder by text',0),(226,'Date','From date','default',2,'fromDate','',0),(227,'Date','To date','default',2,'toDate','',0),(228,'Ajax Dropdown','Customer','Select',2,'customer','SELECT * from (\r\nSELECT customer_id as id , concat(code ,\' - \'  ,customer_name )as text FROM tbl_customers \r\n)tmp\r\nwhere (text like \'%{customer}%\'  or  \'{customer}\'= \'0\')\r\norder by text',0),(309,'Date','From Date','now',9,'from_date','',0),(310,'Date','To Date','now',9,'to_date','',0),(313,'Dropdown','Product category','GENARAL',7,'category_id','select tbl_productcategory.productCategory_id as id\r\n,tbl_productcategory.category as text\r\nfrom tbl_productcategory where tbl_productcategory.productCategory_id not in (1)',0),(329,'Date','From Date','default',5,'from','',0),(330,'Date','To Date','default',5,'to','',0),(331,'Dropdown','Category','All',5,'category_id','select tbl_productcategory.productCategory_id as id\r\n,tbl_productcategory.category as text\r\nfrom tbl_productcategory ',0),(398,'Dropdown','Product category','GENARAL',6,'category_id','select tbl_productcategory.productCategory_id as id\r\n,tbl_productcategory.category as text\r\nfrom tbl_productcategory where tbl_productcategory.productCategory_id not in (1)',0),(399,'Checkbox','Available stock only','1',6,'available_stock','',0),(400,'Textbox','Product Code','',6,'product_code','',0),(404,'Date','From date','now',8,'fromDate','',0),(405,'Date','To date','now',8,'toDate','',0),(406,'Dropdown','Category','All',8,'category_id','select tbl_productcategory.productCategory_id as id\r\n,tbl_productcategory.category as text\r\nfrom tbl_productcategory ',0),(550,'Date','From date','now',16,'from_date','',0),(551,'Date','To date','now',16,'to_date','',0),(552,'Dropdown','Branch','All branches',16,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(553,'Dropdown','Rep','All reps',16,'rep_id','select id as id\r\n,concat(code,\' - \',name) as text\r\nfrom tbl_sales_rep',0),(554,'Date','From date','now',17,'from_date','',0),(555,'Date','To date','now',17,'to_date','',0),(556,'Dropdown','Branch','All branches',17,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(557,'Dropdown','Rep','All reps',17,'rep_id','select id as id\r\n,concat(code,\' - \',name) as text\r\nfrom tbl_sales_rep',0),(560,'Date','From date','now',13,'from_date','',0),(561,'Date','To date','now',13,'to_date','',0),(562,'Dropdown','Types','All types',13,'type_id','select id as id\r\n,concat(code,\' - \',type) as text\r\nfrom tbl_expenses_type',0),(563,'Dropdown','Branch','All branch',13,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(572,'Date','From date','now',15,'from_date','',0),(573,'Date','To date','now',15,'to_date','',0),(574,'Dropdown','Types','All types',15,'type_id','select id as id\r\n,concat(code,\' - \',type) as text\r\nfrom tbl_expenses_type',0),(575,'Dropdown','Branch','All branch',15,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(580,'Date','From date','now',18,'from_date','',0),(581,'Date','To date','now',18,'to_date','',0),(582,'Dropdown','Types','All types',18,'type_id','select id as id\r\n,concat(code,\' - \',type) as text\r\nfrom tbl_expenses_type',0),(583,'Dropdown','Branch','All branch',18,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(600,'Dropdown','Product category','All categories',19,'category_id','select tbl_productcategory.productCategory_id as id\r\n,tbl_productcategory.category as text\r\nfrom tbl_productcategory where tbl_productcategory.productCategory_id not in (1)',0),(601,'Textbox','Product Code','',19,'product_code','',0),(602,'Dropdown','Branch','All branch',19,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(603,'Checkbox','Available stock only','1',19,'available_stock','',0),(618,'Date','From date','now',11,'from_date','',0),(619,'Date','To date','now',11,'to_date','',0),(620,'Dropdown','Branch','All branches',11,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(621,'Ajax Dropdown','Item','All items',11,'item_id','SELECT * from (\r\nSELECT product_id as id , concat(code ,\' - \',name )as text FROM tbl_products \r\n)tmp\r\nwhere (text like \'%{item_id}%\'  or  \'{item_id}\'= \'0\')\r\norder by text',0),(622,'Date','From date','now',10,'from_date','',0),(623,'Date','To date','now',10,'to_date','',0),(624,'Dropdown','Branch','All branches',10,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(625,'Date','From date','now',12,'from_date','',0),(626,'Date','To date','now',12,'to_date','',0),(627,'Dropdown','Branch','All branches',12,'branch_id','select branch_id as id\r\n,concat(Code,\' - \',Name) as text\r\nfrom tbl_branch',0),(628,'Ajax Dropdown','Category','All categories',12,'item_id','SELECT * from (\r\nSELECT productCategory_id as id , concat(code ,\' - \',category )as text FROM tbl_productcategory\r\n)tmp\r\nwhere (text like \'%{item_id}%\'  or  \'{item_id}\'= \'0\')\r\norder by text',0),(629,'Date','From date','now',14,'from_date','',0),(630,'Date','To date','now',14,'to_date','',0),(631,'Date','Date','now',20,'date','',0),(632,'Date','From date','now',22,'fromDate','',0),(633,'Date','To date','now',22,'toDate','',0),(634,'Dropdown','Order by','Default',22,'orderBy','SELECT \r\n    \'Highest\' AS id,\r\n    \'Order by Highest (Sale)\' AS text\r\nUNION ALL\r\nSELECT \r\n    \'Lowest\' AS id,\r\n    \'Order by Lowest (Sale)\' AS text',0),(635,'Date','As At','now',24,'toDate','',0),(636,'Dropdown','Order by','Highest',24,'orderBy','SELECT \r\n    \'Highest\' AS id,\r\n    \'Order by Highest (Amount)\' AS text\r\nUNION ALL\r\nSELECT \r\n    \'Lowest\' AS id,\r\n    \'Order by Lowest (Amount)\' AS text',0),(637,'Date','From date','now',23,'fromDate','',0),(638,'Date','To date','now',23,'toDate','',0),(639,'Ajax Dropdown','Customer','All customer',23,'customer','SELECT * from (\r\nSELECT customer_id as id , concat(code ,\' - \'  ,customer_name )as text FROM tbl_customers \r\n)tmp\r\nwhere (text like \'%{customer}%\'  or  \'{customer}\'= \'0\')\r\norder by text',0),(640,'Dropdown','Order by','Default',23,'orderBy','SELECT \r\n    \'Highest\' AS id,\r\n    \'Order by Highest (Amount)\' AS text\r\nUNION ALL\r\nSELECT \r\n    \'Lowest\' AS id,\r\n    \'Order by Lowest (Amount)\' AS text',0),(641,'Dropdown','Rep','All reps',23,'rep_id','select id as id\r\n,concat(code,\' - \',name) as text\r\nfrom tbl_sales_rep',0),(642,'Date','From Date','now',21,'date','',0),(643,'Date','To Date','now',21,'date1','',0),(644,'Ajax Dropdown','Customer','All',21,'customer','SELECT * from (\r\nSELECT customer_id as id , concat(code ,\' - \'  ,customer_name )as text FROM tbl_customers \r\n)tmp\r\nwhere (text like \'%{customer}%\'  or  \'{customer}\'= \'0\')\r\norder by text',0),(645,'Date','Date','default',4,'filterDate','',0),(646,'Date','Date','now',25,'date','',0),(647,'Dropdown','Cashier','All cashiers',25,'userId','select  user_Id as id ,  full_name as text\r\nfrom tbl_users\r\nwhere user_group_Id = 88\r\nand is_active  = 1',0),(660,'Date','From date','now',26,'fromDate','',0),(661,'Date','To date','now',26,'toDate','',0),(662,'Dropdown','Supplier','All suppliers',26,'sup_id','select supplier_id as id , name as text\r\nfrom tbl_supplier\r\nwhere is_active = 1',0),(669,'Date','From date','now',27,'fromDate','',0),(670,'Date','To date','now',27,'toDate','',0),(671,'Dropdown','Supplier','All suppliers',27,'sup_id','select supplier_id as id , name as text\r\nfrom tbl_supplier\r\nwhere is_active = 1',0);

--
-- Table structure for table `tbl_report_settings`
--

CREATE TABLE `tbl_report_settings` (
  `report_settings_id` int NOT NULL AUTO_INCREMENT,
  `report_name` varchar(100) NOT NULL,
  `report_template_id` varchar(50) NOT NULL,
  `orientation` varchar(100) NOT NULL,
  `page_size` varchar(20) NOT NULL,
  `sql` varchar(8000) NOT NULL,
  `system_id` int NOT NULL,
  `group_id` int NOT NULL,
  `funtion_routes` varchar(1000) NOT NULL,
  `report_order` int NOT NULL,
  `funtion_routes_excel` varchar(100) NOT NULL,
  `sql_excel` varchar(5000) NOT NULL,
  PRIMARY KEY (`report_settings_id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_report_settings`
--

INSERT INTO `tbl_report_settings` VALUES (1,'01 - Customer details','3','L','A4','select \r\ntbl_customers.code as Code_style_10_left\r\n,tbl_customers.customer_name as Name_style_30_left\r\n,tbl_customers.email as Email_style_20_left\r\n,tbl_customers.work_phone as Work_phone_style_40_left\r\nfrom tbl_customers\r\nwhere date(tbl_customers.created_on) BETWEEN \'{fromDate}\' AND \'{toDate}\'\r\n\r\n\r\n\r\n-- ************************\r\n--  on_hand_qty_sum_6_style_20_right \r\n-- on_hand_qty = column name\r\n-- sum = this column values get sum\r\n\r\n--  * _style_20_right = td/th styles   * mandatory **\r\n-- 20 = td/th width \r\n-- right = text align     left/right/center',1,1,'genarate-pdf',0,'',''),(2,'01 - Credit invoices','2','L','A4','select \r\ntbl_sale_invoice.code as code_style_10_left\r\n,c.customer_name  AS Customer_style_30_left\r\n,date(tbl_sale_invoice.created_on) as INV_date_style_15_center\r\n,net_total as INV_amount_sum_2_style_15_right\r\n,rpt_settled_amount as Settled_amount_sum_2_style_10_right\r\n,rpt_returns_amount as Returns_sum_2_style_10_right\r\n,(net_total + rpt_cash_returns - rpt_returns_amount - rpt_settled_amount ) as Balance_sum_2_style_10_right\r\n\r\n ,0 as category_id\r\n,\'\' as category\r\n\r\nfrom tbl_sale_invoice\r\ninner join tbl_customers c on c.customer_id = tbl_sale_invoice.customer_id\r\nwhere tbl_sale_invoice.status in (\'4\')\r\nand tbl_sale_invoice.is_settled = 0\r\nand date(tbl_sale_invoice.created_on) BETWEEN \'{fromDate}\' AND \'{toDate}\'\r\nand (tbl_sale_invoice.customer_id =  \'{customer}\'  or  \'{customer}\'=\'0\')\r\n\r\n\r\n\r\n\r\n-- ************************\r\n--  on_hand_qty_sum_6_style_20_right \r\n-- on_hand_qty = column name\r\n-- sum = this column values get sum\r\n\r\n--  * _style_20_right = td/th styles   * mandatory **\r\n-- 20 = td/th width \r\n-- right = text align     left/right/center',1,2,'genarate-pdf',0,'',''),(3,'02 - Settled Invoices','2','L','A4','select \r\ncode as code_style_20_left\r\n,date(created_on) as INV_date_style_20_left\r\n,net_total as INV_amount_sum_2_style_20_right\r\n,rpt_settled_amount as Settled_amount_sum_2_style_20_right\r\n,rpt_returns_amount as Returns_sum_2_style_20_right\r\n-- ,(net_total + rpt_cash_returns - rpt_returns_amount - rpt_settled_amount ) as Balance_sum_2_style_15_right\r\n\r\n ,0 as category_id\r\n,\'\' as category\r\n\r\nfrom tbl_sale_invoice\r\nwhere tbl_sale_invoice.status in (\'4\')\r\nand tbl_sale_invoice.is_settled = 1\r\nand date(created_on) BETWEEN \'{fromDate}\' AND \'{toDate}\'\r\nand (customer_id =  \'{customer}\'  or  \'{customer}\'=\'0\')\r\n\r\n\r\n\r\n\r\n-- ************************\r\n--  on_hand_qty_sum_6_style_20_right \r\n-- on_hand_qty = column name\r\n-- sum = this column values get sum\r\n\r\n--  * _style_20_right = td/th styles   * mandatory **\r\n-- 20 = td/th width \r\n-- right = text align     left/right/center',1,2,'genarate-pdf',0,'',''),(4,'03 - Daily sale','2','L','A4','select \r\n\r\n( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then concat(tbl_sale_invoice.code,\'<br>Cancelled\')\r\nelse  tbl_sale_invoice.code  end ) as  invoice_No_style_10_left\r\n\r\n,tbl_sale_invoice.created_on as INV_date_style_15_left\r\n,c.customer_name  AS Customer_style_15_left\r\n\r\n ,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse  (case when date(tbl_sale_invoice.created_on ) =  date(\'{filterDate}\') then tbl_sale_invoice.net_total  else \'0.00\' end )  end ) as INV_amount_sum_2_style_8_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse  ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'CASH\',\'{filterDate}\'),0)\r\nend ) as Cash_Payments_sum_2_style_8_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'CHEQUE\',\'{filterDate}\'),0)\r\nend ) as Cheque_Payments_sum_2_style_8_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'BANK\',\'{filterDate}\'),0)\r\nend ) as Bank_Payments_sum_2_style_7_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'CREDIT_CARD\',\'{filterDate}\'),0)\r\nend ) as Credit_cards_sum_2_style_7_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'OUTSTANDING\',\'{filterDate}\'),0)\r\nend ) as Assets_sum_2_style_7_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse (tbl_sale_invoice.net_total + tbl_sale_invoice.rpt_cash_returns - tbl_sale_invoice.rpt_settled_amount - tbl_sale_invoice.rpt_returns_amount)\r\nend ) as Outstanding_sum_2_style_5_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse (ifnull((select \r\n\r\ncase \r\nwhen tbl_customer_returns.return_type = \'CASH_RETURNS\' then \r\nsum(tbl_customer_returns.amount) *-1 else sum(tbl_customer_returns.amount) end\r\n\r\nfrom tbl_customer_returns\r\nwhere date(tbl_customer_returns.created_on) = date(\'{filterDate}\')\r\nand tbl_customer_returns.sale_invoice_id = tbl_sale_invoice.id\r\n),0))\r\nend ) as Rtns_sum_2_style_5_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(tbl_comisions.comis_amount,0)\r\nend ) as Comm_sum_2_style_5_right\r\n \r\nfrom tbl_sale_invoice\r\ninner join tbl_customers c on c.customer_id = tbl_sale_invoice.customer_id\r\nleft join tbl_comisions on tbl_comisions.sale_invoice_id =  tbl_sale_invoice.id\r\nleft join tbl_payment_summary_invoices on tbl_payment_summary_invoices.sale_invoice_id = tbl_sale_invoice.id\r\nwhere (\r\n\r\ndate(tbl_sale_invoice.created_on) = date(\'{filterDate}\') or \r\ntbl_sale_invoice.id in (\r\nselect tbl_payment_summary_invoices.sale_invoice_id from tbl_payment_summary_invoices\r\nwhere date(tbl_payment_summary_invoices.created_on) = date(\'{filterDate}\')\r\ngroup by tbl_payment_summary_invoices.sale_invoice_id) or\r\n\r\ntbl_sale_invoice.id in ( select tbl_customer_returns.sale_invoice_id\r\nfrom tbl_customer_returns\r\nwhere date(tbl_customer_returns.created_on) = date(\'{filterDate}\')\r\n)\r\n\r\n)\r\nand tbl_sale_invoice.status in (\'4\',\'102\',\'5\')\r\ngroup by tbl_sale_invoice.id\r\n-- order by tbl_sale_invoice.id\r\norder by SUBSTRING(tbl_sale_invoice.code, -2),tbl_sale_invoice.id',1,2,'genarate-pdf',0,'genarate-exel',''),(5,'04 - Item Sales Details','2','L','A4','Select ifnull(tbl_products.code, \'\' ) as Code_style_10_left \r\n, ifnull(tbl_products.name\r\n, tbl_sale_invoice_products.service_details ) as Item_style_20_left , \r\ntbl_products.description as Description_style_20_left,\r\nifnull(tbl_productcategory.category,\'\') as Category_style_20_left,\r\nsum(tbl_sale_invoice_products.qty) as Sale_Qty_style_15_right \r\n,(ifnull( pi.qty_in_stock,0))   Avl_qty_sum_6_style_15_right  \r\n,  ifnull(tbl_products.category_id,-1) as category_id\r\n,ifnull(tbl_productcategory.category,\'Custom product\') as category\r\n\r\nfrom tbl_sale_invoice \r\ninner join tbl_sale_invoice_products tbl_sale_invoice_products on tbl_sale_invoice_products.sale_invoice_id = tbl_sale_invoice.id\r\n\r\nLEFT join tbl_products on tbl_products.product_id = tbl_sale_invoice_products.product_id\r\nleft join tbl_productcategory on tbl_productcategory.productCategory_id =tbl_products.category_id\r\nLEFT JOIN  tbl_inventory pi ON         tbl_products .product_id=pi.product_id\r\n where date(tbl_sale_invoice.created_on) between date(\'{from}\') and date(\'{to}\')\r\nand (tbl_products.category_id = {category_id} or {category_id} = 0)\r\n \r\n and tbl_sale_invoice.status in (\'4\',\'102\') \r\n\r\n\r\n GROUP by tbl_sale_invoice_products.service_details\r\nORDER BY   ifnull(tbl_products.category_id,0)',1,2,'genarate-pdf',0,'',''),(6,'01 - Physical inventory','2','L','A4','SELECT   \r\n  p.code sku_style_10_left\r\n, (p.NAME) title_style_45_left\r\n,p.description as Description_style_25_left\r\n,(ifnull( pi.qty_in_stock,0))   on_hand_qty_sum_6_style_20_right  \r\n \r\n\r\n,  p.category_id\r\n,tbl_productcategory.category\r\n\r\n\r\nFROM      tbl_products p\r\ninner join tbl_productcategory on tbl_productcategory.productCategory_id = p.category_id\r\nLEFT JOIN  tbl_inventory pi\r\nON         p.product_id=pi.product_id\r\nwhere (({available_stock} = 1 and ifnull( pi.qty_in_stock,0) > 0 ) or ({available_stock} = 0))\r\nand ( p.category_id = case when  {category_id} = 0 then 1 else   {category_id} end )\r\n \r\nand ( p.code like case when  ltrim(rtrim(\'{product_code}\' ))= \'0\' then p.code else CONCAT(  ltrim(rtrim( \' {product_code} \')) , \'%\' )end )\r\n\r\nORDER BY   p.category_id,p.NAME,\r\n             p.code\r\n\r\n\r\n\r\n-- **********************************************************************\r\n--  on_hand_qty_sum_6_style_20_right \r\n-- on_hand_qty = column name\r\n-- _sum_ = this column values get sum\r\n\r\n--  ** _style_20_right = td/th styles   ** mandatory **\r\n-- 20 = td/th width \r\n-- right = text align     left/right/center',1,3,'genarate-pdf',0,'',''),(7,'02 - Re-Order Report','2','L','A4','SELECT   \r\n  p.code sku_style_10_left\r\n, (p.NAME) title_style_40_left\r\n,p.description as Description_style_15_left\r\n,(ifnull( pi.qty_in_stock,0))   on_Hand_qty_sum_6_style_15_right  \r\n ,(ifnull( pd.field_value,0))   on_Reorder_qty_style_10_right  \r\n, p.updated_on as Last_Update_style_10_left\r\n,  p.category_id\r\n,tbl_productcategory.category\r\n\r\n\r\nFROM      tbl_products p\r\ninner join tbl_productcategory on tbl_productcategory.productCategory_id = p.category_id\r\nLEFT JOIN  tbl_inventory pi ON         p.product_id=pi.product_id\r\nleft join tbl_product_details pd on  p.product_id=pd .parent_id and pd.field_name = \'reorder_qty\'\r\nwhere  ( p.category_id = case when  {category_id} = 0 then 1 else   {category_id} end )\r\nand (ifnull( pi.qty_in_stock,0)) <= ifnull( pd.field_value,0)\r\nand p.is_active = 1 and p.is_delete = 0\r\nORDER BY   p.category_id,p.NAME,\r\n             p.code',1,3,'genarate-pdf',0,'',''),(8,'05 - Fast moving item report','2','L','A4','select \r\ntbl_products.code as Code_style_10_left\r\n,tbl_products.name as Product_style_30_left\r\n,tbl_products.description as Description_style_20_left\r\n, count(tbl_sale_invoice_products.product_id)  as Sale_Count_style_10_right\r\n, sum(tbl_sale_invoice_products.qty)  as Sale_Qty_style_10_right\r\n, ROUND(ifnull(tbl_inventory.qty_in_stock,0) ,2) as Avaiable_count_style_10_right\r\n, ROUND(ifnull(tbl_product_details.field_value,0),2)  as Reorder_count_style_10_right\r\nfrom tbl_sale_invoice_products\r\ninner join tbl_sale_invoice on tbl_sale_invoice.id = tbl_sale_invoice_products.sale_invoice_id\r\nand tbl_sale_invoice.status in (\'4\',\'102\')\r\ninner join tbl_products on tbl_products.product_id = tbl_sale_invoice_products.product_id\r\nleft join tbl_inventory on tbl_inventory.product_id = tbl_sale_invoice_products.product_id\r\nleft join tbl_product_details on tbl_product_details.parent_id = tbl_sale_invoice_products.product_id\r\nand tbl_product_details.field_name in (\'reorder_qty\')\r\nwhere tbl_sale_invoice_products.created_on between \'{fromDate}\' and \'{toDate}\' \r\nand (tbl_products.category_id = {category_id} or {category_id} = 0)\r\ngroup by tbl_sale_invoice_products.product_id\r\norder by count(tbl_sale_invoice_products.product_id) desc',1,2,'genarate-pdf',0,'',''),(9,'03- Daily stock adjustment','3','L','A4','select tbl_stock_adjustment.created_on   as Date_style_20_left ,concat(tbl_products.code,\'-\',tbl_products.name) as Product_style_50_left\r\n,tbl_stock_adjustment_products.description as Description_style_20_left\r\n,tbl_stock_adjustment_products.qty as Qty_style_10_right\r\nfrom tbl_stock_adjustment_products\r\ninner join tbl_stock_adjustment on tbl_stock_adjustment.id = tbl_stock_adjustment_products.stock_adjustment_id\r\ninner join tbl_products on tbl_products.product_id = tbl_stock_adjustment_products.product_id\r\nwhere tbl_stock_adjustment.status = \'4\'\r\nand tbl_stock_adjustment.created_on  between  \'{from_date}\' and  \'{to_date}\'',1,3,'genarate-pdf',3,'',''),(10,'01 - Profit by sales invoices','2','L','A4','select \r\nb.Code as Branch_style_12_left \r\n,si.code as invoice_style_10_left\r\n ,si.sub_total as Sub_total_sum_2_style_12_right\r\n ,si.total_discount as Discount_sum_2_style_12_right\r\n ,si.net_total as Net_total_sum_2_style_12_right \r\n,sum(sip.costPrice*sip.qty) as Total_cost_sum_2_style_12_right\r\n ,si.rpt_returns_amount as Return_sum_2_style_12_right\r\n ,round(si.net_total-sum(sip.costPrice*sip.qty)-si.rpt_returns_amount,2) as Profit_sum_2_style_12_right \r\n ,round(((si.net_total-sum(sip.costPrice*sip.qty)-si.rpt_returns_amount)/sum(sip.costPrice*sip.qty))*100,2) as `%_style_6_right` \r\n,\'\' as category \r\n,0 as category_id \r\nfrom tbl_sale_invoice_products sip \r\ninner join tbl_products p on p.product_id = sip.product_id \r\ninner join tbl_sale_invoice si on si.id = sip.sale_invoice_id \r\ninner join tbl_branch_inventory_locations bil on bil.id = si.location_id \r\ninner join tbl_branch b on b.branch_id = bil.branch_id \r\nwhere si.created_on between \'{from_date}\' and \'{to_date}\' \r\nand (bil.branch_id = {branch_id} or {branch_id} = 0) \r\ngroup by sip.sale_invoice_id \r\norder by si.id',1,4,'genarate-pdf',1,'genarate-exel',''),(11,'02 - Profit by sales invoice item details','2','L','A4','select \r\nconcat(si.code,\' /date - \',date(si.created_on),\' - \',b.Code) as category\r\n,si.id as category_id\r\n,concat(p.code,\' - \',p.name)  as Item_style_23_left\r\n,sip.qty as Qty_sum_2_style_10_right\r\n,sip.costPrice as Cost_price_sum_2_style_11_right\r\n,sip.unit_price as Unit_price_sum_2_style_10_right\r\n,sip.discount as Discount_sum_2_style_10_right\r\n,sip.net_total as Net_total_sum_2_style_11_right\r\n,ifnull(rp.value,0.00) as Returns_sum_2_style_10_right\r\n,round(sip.net_total - (sip.costPrice*sip.qty) - ifnull(rp.value,0.00),2) as Profit_sum_2_style_10_right\r\n,round((sip.net_total - (sip.costPrice*sip.qty) - ifnull(rp.value,0.00))/(sip.costPrice*sip.qty)*100,2) as `%_style_5_right`\r\nfrom tbl_sale_invoice_products sip\r\ninner join tbl_products p on p.product_id = sip.product_id\r\ninner join tbl_sale_invoice si on si.id = sip.sale_invoice_id\r\ninner join tbl_branch_inventory_locations bil on bil.id = si.location_id\r\ninner join tbl_branch b on b.branch_id = bil.branch_id\r\nleft join tbl_return_products rp on rp.product_id = sip.product_id\r\nand rp.invoice_id = sip.sale_invoice_id\r\nwhere si.created_on between \'{from_date}\'  and  \'{to_date}\'\r\nand (bil.branch_id = {branch_id} or {branch_id} = 0)\r\nand (p.product_id = {item_id} or {item_id} = 0)\r\norder by si.id,si.created_on',1,4,'genarate-pdf',2,'genarate-exel',''),(12,'03 - Profit by sales items','2','L','A4','select \r\nconcat(p.code,\' - \',p.name)  as Item_style_23_left\r\n,sum(sip.qty) as Qty_sum_2_style_11_right\r\n,round(sum(sip.costPrice)/sum(sip.qty),2) as AVG_Cost_price_style_10_right\r\n,round(sum(sip.unit_price)/sum(sip.qty),2) as AVG_Unit_price_style_10_right\r\n,sum(sip.discount) as Discount_sum_2_style_10_right\r\n,sum(sip.net_total) as Net_total_sum_2_style_11_right\r\n,sum(ifnull(rp.value,0.00)) as Returns_sum_2_style_10_right\r\n,round(sum(sip.net_total - (sip.costPrice*sip.qty) - ifnull(rp.value,0.00)),2) as Profit_sum_2_style_10_right\r\n,round((sum(sip.net_total - (sip.costPrice*sip.qty) - ifnull(rp.value,0.00))/sum(sip.costPrice)*100),2) as `%_sum_2_style_5_right`\r\nfrom tbl_sale_invoice_products sip\r\ninner join tbl_products p on p.product_id = sip.product_id\r\ninner join tbl_sale_invoice si on si.id = sip.sale_invoice_id\r\ninner join tbl_branch_inventory_locations bil on bil.id = si.location_id\r\ninner join tbl_branch b on b.branch_id = bil.branch_id\r\nleft join tbl_return_products rp on rp.product_id = sip.product_id\r\nand rp.invoice_id = sip.sale_invoice_id\r\nwhere si.created_on between \'{from_date}\'  and  \'{to_date}\'\r\nand (bil.branch_id = {branch_id} or {branch_id} = 0)\r\nand (p.category_id = {item_id} or {item_id} = 0)\r\ngroup by p.product_id\r\norder by p.product_id',1,4,'genarate-pdf',3,'genarate-exel',''),(13,'01 - Expenses','2','L','A4','select \r\ne.code as Code_style_10_left\r\n,e.date as Date_style_10_left\r\n,concat(et.code,\' - \',et.type) as Type_style_30_left\r\n,e.description as Description_style_40_left\r\n,e.amount as Amount_sum_2_style_10_right\r\nfrom tbl_expenses e\r\ninner join tbl_expenses_type et on et.id = e.type_id\r\nwhere e.status = 4\r\nand e.date between \'{from_date}\' and \'{to_date}\'\r\nand (e.type_id = {type_id} or {type_id} = 0)\r\nand (e.branch_id = {branch_id} or {branch_id} = 0)',1,5,'genarate-pdf',1,'genarate-exel',''),(14,'04 - Profit & lost report','2','L','A4','this report generate by system.',1,4,'profit-lost-pdf',4,'genarate-exel',''),(15,'02 - Expenses by types','2','L','A4','select \r\ne.type_id as category_id\r\n,concat(et.code,\' - \',et.type) as category\r\n,e.code as Code_style_10_left\r\n,e.date as Date_style_10_left\r\n,concat(b.Code,\' - \',b.Name) as Branch_style_30_left\r\n,e.description as Description_style_40_left\r\n,e.amount as Amount_sum_2_style_10_right\r\nfrom tbl_expenses e\r\ninner join tbl_expenses_type et on et.id = e.type_id\r\ninner join tbl_branch b on b.branch_id = e.branch_id\r\nwhere e.status = 4\r\nand e.date between \'{from_date}\' and \'{to_date}\'\r\nand (e.type_id = {type_id} or {type_id} = 0)\r\nand (e.branch_id = {branch_id} or {branch_id} = 0)\r\norder by e.type_id,e.branch_id,e.date',1,5,'genarate-pdf',2,'genarate-exel',''),(16,'06 - Sales by rep','2','L','A4','select \r\nsr.id as category_id\r\n,concat(sr.code,\' - \',sr.name) as category\r\n,concat(b.Code,\' - \',b.Name) as Branch_style_28_left\r\n,si.code as Invoice_style_12_left\r\n,date(si.created_on) as Date_style_12_left\r\n,net_total as Net_total_sum_2_style_12_right\r\n,rpt_returns_amount as Returns_sum_2_style_12_right\r\n,rpt_settled_amount as Payments_sum_2_style_12_right\r\n,(net_total-rpt_returns_amount-rpt_settled_amount+rpt_cash_returns) as Balance_sum_2_style_12_right\r\nfrom tbl_sale_invoice si\r\ninner join tbl_sales_rep sr on sr.id = si.repId\r\ninner join tbl_branch_inventory_locations bil on bil.id = si.location_id\r\ninner join tbl_branch b on b.branch_id = bil.branch_id\r\nwhere si.status = 4\r\nand si.created_on between \'{from_date}\'  and  \'{to_date}\'\r\nand (bil.branch_id = {branch_id} or {branch_id} = 0)\r\nand (si.repId = {rep_id} or {rep_id} = 0)\r\norder by sr.id, b.branch_id',1,2,'genarate-pdf',0,'genarate-exel',''),(17,'07 - Branch sales by rep','2','L','A4','select \r\nb.branch_id as category_id\r\n,concat(b.Code,\' - \',b.Name) as category\r\n,concat(sr.code,\' - \',sr.name) as Rep_style_28_left\r\n,si.code as Invoice_style_12_left\r\n,date(si.created_on) as Date_style_12_left\r\n,net_total as Net_total_sum_2_style_12_right\r\n,rpt_returns_amount as Returns_sum_2_style_12_right\r\n,rpt_settled_amount as Payments_sum_2_style_12_right\r\n,(net_total-rpt_returns_amount-rpt_settled_amount+rpt_cash_returns) as Balance_sum_2_style_12_right\r\nfrom tbl_sale_invoice si\r\ninner join tbl_sales_rep sr on sr.id = si.repId\r\ninner join tbl_branch_inventory_locations bil on bil.id = si.location_id\r\ninner join tbl_branch b on b.branch_id = bil.branch_id\r\nwhere si.status = 4\r\nand si.created_on between \'{from_date}\'  and  \'{to_date}\'\r\nand (bil.branch_id = {branch_id} or {branch_id} = 0)\r\nand (si.repId = {rep_id} or {rep_id} = 0)\r\norder by b.branch_id,sr.id',1,2,'genarate-pdf',0,'genarate-exel',''),(18,'03 - Expenses by branches','2','L','A4','select \r\ne.branch_id as category_id\r\n,concat(b.Code,\' - \',b.Name) as category\r\n,e.code as Code_style_10_left\r\n,e.date as Date_style_10_left\r\n,concat(et.code,\' - \',et.type) as Type_style_30_left\r\n,e.description as Description_style_40_left\r\n,e.amount as Amount_sum_2_style_10_right\r\nfrom tbl_expenses e\r\ninner join tbl_expenses_type et on et.id = e.type_id\r\ninner join tbl_branch b on b.branch_id = e.branch_id\r\nwhere e.status = 4\r\nand e.date between \'{from_date}\' and \'{to_date}\'\r\nand (e.type_id = {type_id} or {type_id} = 0)\r\nand (e.branch_id = {branch_id} or {branch_id} = 0)\r\norder by e.branch_id,e.type_id,e.date',1,5,'genarate-pdf',3,'genarate-exel',''),(19,'04 - Inventory Valuation','2','L','A4','SELECT   \r\n  concat(p.code,\' - \',p.name) Product_style_45_left\r\n,tbl_productcategory.category as  Category_style_10_left\r\n,(ifnull( pi.qty_in_stock,0))   Qty_sum_2_style_15_right  \r\n,ifnull(pbc.cost,0) as Cost_sum_2_style_15_right\r\n,round(ifnull(pbc.cost,0)*ifnull( pi.qty_in_stock,0) ,2)as Value_sum_2_style_15_right\r\n \r\n\r\n, ifnull(bl.branch_id,0) as category_id\r\n,concat(ifnull(b.Code,\'\'),\' \',ifnull(b.Name,\'\')) as category\r\n\r\n\r\nFROM tbl_products p\r\ninner join tbl_productcategory on tbl_productcategory.productCategory_id = p.category_id\r\ninner JOIN  tbl_inventory pi ON p.product_id = pi.product_id\r\ninner JOIN  tbl_branch_inventory_locations bl ON bl.id = pi.location_id\r\ninner JOIN  tbl_branch b ON b.branch_id = bl.branch_id\r\nand (b.branch_id = {branch_id} or {branch_id} = 0)\r\ninner JOIN  tbl_product_branch_cost pbc ON pbc.product_id = p.product_id\r\nand pbc.location_id = pi.location_id\r\nwhere (({available_stock} = 1 and ifnull( pi.qty_in_stock,0) > 0 ) or ({available_stock} = 0)) \r\n\r\nand (  {category_id} = 0  or  p.category_id  =   {category_id} )\r\n \r\nand ( p.code like case when  ltrim(rtrim(\'{product_code}\' ))= \'0\' then p.code else CONCAT(  ltrim(rtrim( \' {product_code} \')) , \'%\' )end ) \r\n\r\nORDER BY   b.branch_id,p.category_id,p.name, p.code',1,3,'genarate-pdf',4,'',''),(20,'Day end Report','3','L','A4','Report generated system',1,2,'day-end-pdf',1,'',''),(21,'02 - Customer outstanding report','2,3,4','L','A4','select    \r\ndate(si.created_on) as Invoice_date_style_10_left\r\n,si.code as Invoice_no_style_10_left\r\n,srp.code  as Rep_code_style_12_left\r\n,si.net_total as Invoice_amount_sum_2_style_15_right\r\n,ifnull((\r\nselect group_concat(code separator \',\')\r\nfrom tbl_customer_returns\r\nwhere sale_invoice_id = si.id\r\ngroup by sale_invoice_id\r\n),\'\') as Return_no_style_15_left\r\n,   concat(\'(\',  si.rpt_returns_amount ,\')\') as Return_amounts_sum_2_style_10_right\r\n,(si.net_total+si.rpt_cash_returns) - (si.rpt_settled_amount + si.rpt_returns_amount) as To_pay_value_sum_2_style_15_right\r\n,DATEDIFF(date(now()),date(si.created_on)) as Days_style_6_right\r\n \r\n,case when (DATEDIFF(date(now()),date(si.created_on)) - 90) > 0 then  (90-DATEDIFF(date(now()),date(si.created_on)) )  else 0 end as Over_due_days_style_6_right\r\n\r\n \r\n, ifnull(si.customer_id ,-1) as category_id\r\n,concat(tbl_customers.code ,\' - \'  ,tbl_customers.customer_name,\'   |  \'  ,tbl_customers.address ) as category\r\nfrom tbl_sale_invoice si\r\nleft join tbl_customers on tbl_customers.customer_id = si.customer_id\r\nleft join tbl_sales_rep srp on srp.id = si.repId\r\nwhere (si.customer_id = {customer} or  {customer} =0 )\r\nand date(si.created_on)  between \'{date}\' and  \'{date1}\'\r\nand ( (si.net_total+si.rpt_cash_returns) - (si.rpt_settled_amount + si.rpt_returns_amount) ) > 0\r\nand status = \'4\'\r\norder by ifnull(si.customer_id ,-1)  , DATEDIFF(date(now()),date(si.created_on))  desc',1,1,'genarate-pdf',1,'',''),(22,'03 - Customer sales','2','L','A4','call rpt_customer_sale(\'sales\', \'{fromDate}\', \'{toDate}\', 0, \'{orderBy}\');',1,1,'genarate-pdf',3,'',''),(23,'04 - Customer wise sales','2','L','A4','call rpt_customer_sale(\'wise\', \'{fromDate}\', \'{toDate}\', {customer}, \'{orderBy}\',\'{rep_id}\');',1,1,'genarate-pdf',4,'',''),(24,'05 - Customer outstanding by days','2','L','A4','select \r\ntmp.customer as customer_style_30_left\r\n,tmp.credit_limit as credit_limit_style_10_right\r\n,`0-30` as `0-30_sum_2_style_10_right`\r\n,`31-60` as `31-60_sum_2_style_10_right`\r\n,`61-90` as `61-90_sum_2_style_10_right`\r\n,`91-120` as `91-120_sum_2_style_10_right`\r\n,`>120`  as `>120_sum_2_style_10_right`\r\n,(`0-30`+`31-60`+`61-90`+`91-120`+`>120`) as total_sum_2_style_10_right\r\nfrom (select \r\nconcat(c.code,\' - \',c.customer_name) as customer\r\n,c.customer_name\r\n,c.credit_limit as credit_limit\r\n,c.mobile_no as phone\r\n,get_customerOutstandingAmount(c.customer_id,\'{toDate}\',0) as `0-30`\r\n,get_customerOutstandingAmount(c.customer_id,\'{toDate}\',30) as `31-60`\r\n,get_customerOutstandingAmount(c.customer_id,\'{toDate}\',60) as `61-90`\r\n,get_customerOutstandingAmount(c.customer_id,\'{toDate}\',90) as `91-120`\r\n,get_customerOutstandingAmount(c.customer_id,\'{toDate}\',120) as `>120`\r\nfrom tbl_customers c\r\nwhere c.is_active = 1) tmp\r\nwhere (`0-30`+`31-60`+`61-90`+`91-120`+`>120`) > 0\r\n order by  \r\n			CASE  WHEN \'{orderBy}\' = \'0\' THEN tmp.customer_name END,\r\n			CASE  WHEN \'{orderBy}\' = \'Highest\' THEN ifnull((`0-30`+`31-60`+`61-90`+`91-120`+`>120`),0.00) END DESC,\r\n			CASE  WHEN \'{orderBy}\' = \'Lowest\' THEN ifnull((`0-30`+`31-60`+`61-90`+`91-120`+`>120`),0.00) END ASC;',1,1,'genarate-pdf',5,'',''),(25,'EOD- Cash report','3','L','A4','System generate report',1,2,'cash-report',0,'genarate-exel',''),(26,'Supplier Outstanding','2','L','A4','select name as Supplier_style_55_left\r\n,amount as Total_grn_amount_sum_2_style_15_right\r\n,paidAmount as Paid_amount_sum_2_style_15_right\r\n,amount - paidAmount as Outstanding_sum_2_style_15_right\r\nfrom (select \r\ns.name,sum(g.total) as amount,\r\nsum(ifnull((select sum(ifnull(sg.amount,0)) \r\n	from tbl_supplier_payments sp\r\n       inner join tbl_supplier_payments_grns sg on sg.supplier_payment_id= sp.id\r\n    where sg.grn_id = g.grn_id  \r\n    and sp.status = \'4\' \r\n    ),0)) as paidAmount\r\nfrom tbl_grns g\r\ninner join tbl_supplier s on s.supplier_id = g.supplier_id \r\nwhere g.grn_date between \'{fromDate}\' and \'{toDate}\'\r\nand g.status = \'4\' \r\nand (g.supplier_id  = {sup_id} or {sup_id} = 0 )\r\ngroup by g.supplier_id \r\n) tmp',1,6,'genarate-pdf',0,'genarate-exel','select name as Supplier \r\n,amount as Total_grn_amount \r\n,paidAmount as Paid_amount \r\n,amount - paidAmount as Outstanding \r\nfrom (select \r\ns.name,sum(g.total) as amount,\r\nsum(ifnull((select sum(ifnull(sp.amount,0)) \r\n	from tbl_supplier_payments sp\r\n    where sp.grn_id = g.grn_id  \r\n    and sp.status = \'4\' \r\n    ),0)) as paidAmount\r\nfrom tbl_grns g\r\ninner join tbl_supplier s on s.supplier_id = g.supplier_id \r\nwhere g.grn_date  between \'{fromDate}\' and \'{toDate}\'\r\nand g.status = \'4\' \r\nand (g.supplier_id  = {sup_id} or {sup_id} = 0 )\r\ngroup by g.supplier_id \r\n) tmp'),(27,'Supplier aging reports','2','L','A4','select code as Code_style_15_left\r\n,supplier as Supplier_style_45_left\r\n,total as Amount_sum_2_style_10_right\r\n,paid as Paid_sum_2_style_10_right\r\n,(total - paid) as Balance_sum_2_style_10_right\r\n,age as Age_style_10_right\r\nfrom (\r\nselect \r\ng.code \r\n,s.name as supplier\r\n,g.total\r\n,ifnull((select sum(ifnull(sg.amount,0)) \r\n	from tbl_supplier_payments sp\r\n       inner join tbl_supplier_payments_grns sg on sg.supplier_payment_id= sp.id\r\n    where sg.grn_id = g.grn_id  \r\n    and sp.status = \'4\' \r\n    ),0) as paid\r\n,DATEDIFF(now(),g.grn_date) as age\r\nfrom tbl_grns g\r\ninner join tbl_supplier s on s.supplier_id = g.supplier_id\r\nwhere g.grn_date between \'{fromDate}\' and \'{toDate}\'\r\nand g.status = \'4\' \r\nand (g.supplier_id  = {sup_id} or {sup_id} = 0 )\r\norder by g.grn_date ) tmp\r\nwhere total- paid > 0',1,6,'genarate-pdf',0,'genarate-exel','select name as Supplier \r\n,amount as Total_grn_amount \r\n,paidAmount as Paid_amount \r\n,amount - paidAmount as Outstanding \r\nfrom (select \r\ns.name,sum(g.total) as amount,\r\nsum(ifnull((select sum(ifnull(sp.amount,0)) \r\n	from tbl_supplier_payments sp\r\n    where sp.grn_id = g.grn_id  \r\n    and sp.status = \'4\' \r\n    ),0)) as paidAmount\r\nfrom tbl_grns g\r\ninner join tbl_supplier s on s.supplier_id = g.supplier_id \r\nwhere g.grn_date  between \'{fromDate}\' and \'{toDate}\'\r\nand g.status = \'4\' \r\nand (g.supplier_id  = {sup_id} or {sup_id} = 0 )\r\ngroup by g.supplier_id \r\n) tmp');

--
-- Table structure for table `tbl_report_sql_history`
--

CREATE TABLE `tbl_report_sql_history` (
  `id` int NOT NULL AUTO_INCREMENT,
  `report_id` int NOT NULL,
  `pdf_sql` varchar(5000) NOT NULL,
  `excel_sql` varchar(5000) NOT NULL,
  `changed_on` datetime NOT NULL,
  `changed_by` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_report_sql_history`
--

INSERT INTO `tbl_report_sql_history` VALUES (1,4,'select \r\n\r\n( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then concat(tbl_sale_invoice.code,\'<br>Cancelled\')\r\nelse  tbl_sale_invoice.code  end ) as  invoice_No_style_10_left\r\n\r\n,tbl_sale_invoice.created_on as INV_date_style_15_left\r\n,c.customer_name  AS Customer_style_15_left\r\n\r\n ,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse  (case when date(tbl_sale_invoice.created_on ) =  date(\'{filterDate}\') then tbl_sale_invoice.net_total  else \'0.00\' end )  end ) as INV_amount_sum_2_style_8_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse  ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'CASH\',\'{filterDate}\'),0)\r\nend ) as Cash_Payments_sum_2_style_8_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'CHEQUE\',\'{filterDate}\'),0)\r\nend ) as Cheque_Payments_sum_2_style_8_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'BANK\',\'{filterDate}\'),0)\r\nend ) as Bank_Payments_sum_2_style_7_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'CREDIT_CARD\',\'{filterDate}\'),0)\r\nend ) as Credit_cards_sum_2_style_7_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(get_invoicePayments(ifnull(tbl_payment_summary_invoices.ps_id,0),tbl_payment_summary_invoices.sale_invoice_id,\'OUTSTANDING\',\'{filterDate}\'),0)\r\nend ) as Assets_sum_2_style_7_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse (tbl_sale_invoice.net_total + tbl_sale_invoice.rpt_cash_returns - tbl_sale_invoice.rpt_settled_amount - tbl_sale_invoice.rpt_returns_amount)\r\nend ) as Outstanding_sum_2_style_5_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse (ifnull((select \r\n\r\ncase \r\nwhen tbl_customer_returns.return_type = \'CASH_RETURNS\' then \r\nsum(tbl_customer_returns.amount) *-1 else sum(tbl_customer_returns.amount) end\r\n\r\nfrom tbl_customer_returns\r\nwhere date(tbl_customer_returns.created_on) = date(\'{filterDate}\')\r\nand tbl_customer_returns.sale_invoice_id = tbl_sale_invoice.id\r\n),0))\r\nend ) as Rtns_sum_2_style_5_right\r\n\r\n,( case \r\nwhen tbl_sale_invoice.status in (\'5\')  then \'0.00\'\r\nelse ifnull(tbl_comisions.comis_amount,0)\r\nend ) as Comm_sum_2_style_5_right\r\n \r\nfrom tbl_sale_invoice\r\ninner join tbl_customers c on c.customer_id = tbl_sale_invoice.customer_id\r\nleft join tbl_comisions on tbl_comisions.sale_invoice_id =  tbl_sale_invoice.id\r\nleft join tbl_payment_summary_invoices on tbl_payment_summary_invoices.sale_invoice_id = tbl_sale_invoice.id\r\nwhere (\r\n\r\ndate(tbl_sale_invoice.created_on) = date(\'{filterDate}\') or \r\ntbl_sale_invoice.id in (\r\nselect tbl_payment_summary_invoices.sale_invoice_id from tbl_payment_summary_invoices\r\nwhere date(tbl_payment_summary_invoices.created_on) = date(\'{filterDate}\')\r\ngroup by tbl_payment_summary_invoices.sale_invoice_id) or\r\n\r\ntbl_sale_invoice.id in ( select tbl_customer_returns.sale_invoice_id\r\nfrom tbl_customer_returns\r\nwhere date(tbl_customer_returns.created_on) = date(\'{filterDate}\')\r\n)\r\n\r\n)\r\nand tbl_sale_invoice.status in (\'4\',\'102\',\'5\')\r\ngroup by tbl_sale_invoice.id\r\n-- order by tbl_sale_invoice.id\r\norder by SUBSTRING(tbl_sale_invoice.code, -2),tbl_sale_invoice.id','Not change','2025-12-11 12:26:42',77),(2,26,'select name as Supplier_style_55_left\r\n,amount as Total_grn_amount_sum_2_style_15_right\r\n,paidAmount as Paid_amount_sum_2_style_15_right\r\n,amount - paidAmount as Outstanding_sum_2_style_15_right\r\nfrom (select \r\ns.name,sum(g.total) as amount,\r\nsum(ifnull((select sum(ifnull(sp.amount,0)) \r\n	from tbl_supplier_payments sp\r\n    where sp.grn_id = g.grn_id  \r\n    and sp.status = \'4\' \r\n    ),0)) as paidAmount\r\nfrom tbl_grns g\r\ninner join tbl_supplier s on s.supplier_id = g.supplier_id \r\nwhere g.grn_date between \'{fromDate}\' and \'{toDate}\'\r\nand g.status = \'4\' \r\nand (g.supplier_id  = {sup_id} or {sup_id} = 0 )\r\ngroup by g.supplier_id \r\n) tmp','select name as Supplier \r\n,amount as Total_grn_amount \r\n,paidAmount as Paid_amount \r\n,amount - paidAmount as Outstanding \r\nfrom (select \r\ns.name,sum(g.total) as amount,\r\nsum(ifnull((select sum(ifnull(sp.amount,0)) \r\n	from tbl_supplier_payments sp\r\n    where sp.grn_id = g.grn_id  \r\n    and sp.status = \'4\' \r\n    ),0)) as paidAmount\r\nfrom tbl_grns g\r\ninner join tbl_supplier s on s.supplier_id = g.supplier_id \r\nwhere g.grn_date  between \'{fromDate}\' and \'{toDate}\'\r\nand g.status = \'4\' \r\nand (g.supplier_id  = {sup_id} or {sup_id} = 0 )\r\ngroup by g.supplier_id \r\n) tmp','2026-01-19 11:27:49',77),(3,26,'select name as Supplier_style_55_left\r\n,amount as Total_grn_amount_sum_2_style_15_right\r\n,paidAmount as Paid_amount_sum_2_style_15_right\r\n,amount - paidAmount as Outstanding_sum_2_style_15_right\r\nfrom (select \r\ns.name,sum(g.total) as amount,\r\nsum(ifnull((select sum(ifnull(sg.amount,0)) \r\n	from tbl_supplier_payments sp\r\n       inner join tbl_supplier_payments_grns sg on sg.supplier_payment_id= sp.id\r\n    where sg.grn_id = g.grn_id  \r\n    and sp.status = \'4\' \r\n    ),0)) as paidAmount\r\nfrom tbl_grns g\r\ninner join tbl_supplier s on s.supplier_id = g.supplier_id \r\nwhere g.grn_date between \'{fromDate}\' and \'{toDate}\'\r\nand g.status = \'4\' \r\nand (g.supplier_id  = {sup_id} or {sup_id} = 0 )\r\ngroup by g.supplier_id \r\n) tmp','Not change','2026-01-26 09:28:58',77),(4,27,'select code as Code_style_15_left\r\n,supplier as Supplier_style_45_left\r\n,total as Amount_sum_2_style_10_right\r\n,paid as Paid_sum_2_style_10_right\r\n,(total - paid) as Balance_sum_2_style_10_right\r\n,age as Age_style_10_right\r\nfrom (\r\nselect \r\ng.code \r\n,s.name as supplier\r\n,g.total\r\n,ifnull((select sum(ifnull(sg.amount,0)) \r\n	from tbl_supplier_payments sp\r\n       inner join tbl_supplier_payments_grns sg on sg.supplier_payment_id= sp.id\r\n    where sg.grn_id = g.grn_id  \r\n    and sp.status = \'4\' \r\n    ),0) as paid\r\n,DATEDIFF(now(),g.grn_date) as age\r\nfrom tbl_grns g\r\ninner join tbl_supplier s on s.supplier_id = g.supplier_id\r\nwhere g.grn_date between \'{fromDate}\' and \'{toDate}\'\r\nand g.status = \'4\' \r\nand (g.supplier_id  = {sup_id} or {sup_id} = 0 )\r\norder by g.grn_date ) tmp\r\nwhere total- paid > 0','Not change','2026-01-26 09:43:46',77);

--
-- Table structure for table `tbl_report_systems`
--

CREATE TABLE `tbl_report_systems` (
  `system_id` int NOT NULL AUTO_INCREMENT,
  `db_name` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `system_name` varchar(50) NOT NULL,
  `create_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `company_name` varchar(500) NOT NULL,
  `note` varchar(5000) NOT NULL,
  `address` varchar(500) NOT NULL,
  `mobile_no` varchar(50) NOT NULL,
  `phone_no` varchar(50) NOT NULL,
  `fax` varchar(50) NOT NULL,
  `email` varchar(500) NOT NULL,
  `web` varchar(500) NOT NULL,
  `logo` varchar(500) NOT NULL,
  PRIMARY KEY (`system_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_report_systems`
--

INSERT INTO `tbl_report_systems` VALUES (1,'1000_flux_coffe_mannar_erp','t','Main',0,'0000-00-00 00:00:00','The Coffee Manor','','xxxxx\r\nxxxx\r\nxxx','+ 94 xxxxxxxx','+ 94 xxxxxxxx','+ 94 xxxxxxx','test@sltnet.lk','https://test.com/','admin/SystemHeaderLogos/1000_TileMahagedara/1_.png');

--
-- Table structure for table `tbl_report_templates`
--

CREATE TABLE `tbl_report_templates` (
  `report_template_id` int NOT NULL AUTO_INCREMENT,
  `report_template_name` varchar(50) NOT NULL,
  `report_template_desc` varchar(100) NOT NULL,
  `templatePhysicalName` varchar(50) NOT NULL,
  PRIMARY KEY (`report_template_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_report_templates`
--

INSERT INTO `tbl_report_templates` VALUES (1,'Ceylon tea Physical Inventory Worksheet','Ceylon tea Physical Inventory Worksheet','ceylontea/PhysicalInventoryWorksheet'),(2,'With group sum','With group sum','rohanamotors/CommonGroupPdf'),(3,'Common PDF','_CommonPdf','_CommonPdf');

--
-- Table structure for table `tbl_return_cheques`
--

CREATE TABLE `tbl_return_cheques` (
  `id` int NOT NULL AUTO_INCREMENT,
  `payment_id` int NOT NULL,
  `return_date` date NOT NULL,
  `description` varchar(1000) NOT NULL,
  `status` varchar(100) NOT NULL,
  `code` varchar(100) NOT NULL,
  `created_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `bank_account_id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_return_cheques`
--


--
-- Table structure for table `tbl_return_cheques_suppliers`
--

CREATE TABLE `tbl_return_cheques_suppliers` (
  `id` int NOT NULL AUTO_INCREMENT,
  `payment_id` int NOT NULL,
  `return_date` date NOT NULL,
  `description` varchar(1000) NOT NULL,
  `status` varchar(100) NOT NULL,
  `code` varchar(100) NOT NULL,
  `created_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `bank_account_id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_return_cheques_suppliers`
--


--
-- Table structure for table `tbl_return_products`
--

CREATE TABLE `tbl_return_products` (
  `id` int NOT NULL AUTO_INCREMENT,
  `product_id` int NOT NULL,
  `qty` int NOT NULL,
  `value` decimal(11,2) NOT NULL,
  `return_id` int NOT NULL,
  `created_by` int NOT NULL,
  `created_on` int NOT NULL,
  `invoice_id` int NOT NULL,
  `product_type` varchar(50) NOT NULL,
  `custom_product_name` varchar(1000) NOT NULL,
  `sale_invoice_product_id` int NOT NULL,
  `uom_value` decimal(11,2) NOT NULL,
  `uom` varchar(50) NOT NULL,
  `product_uom` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_return_products`
--


--
-- Table structure for table `tbl_sale_invoice`
--

CREATE TABLE `tbl_sale_invoice` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `status` varchar(50) NOT NULL,
  `discount_type` varchar(10) NOT NULL DEFAULT '0.00',
  `discount_rate` decimal(11,2) NOT NULL DEFAULT '0.00',
  `total_discount` decimal(11,2) NOT NULL DEFAULT '0.00',
  `net_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `sub_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `customer_id` int NOT NULL,
  `rpt_settled_amount` decimal(16,2) NOT NULL,
  `rpt_returns_amount` decimal(16,2) NOT NULL,
  `is_settled` decimal(16,2) NOT NULL,
  `invoice_type_id` int NOT NULL,
  `bill_tax_amount` decimal(16,2) NOT NULL,
  `bill_tax` varchar(100) NOT NULL,
  `vehicle_id` int NOT NULL,
  `is_printed` tinyint(1) NOT NULL DEFAULT '0',
  `estimation_id` int NOT NULL,
  `invoice_category` varchar(50) NOT NULL,
  `is_permanent_cancelled` tinyint(1) NOT NULL DEFAULT '0',
  `rpt_cash_returns` decimal(16,2) NOT NULL,
  `is_credit_invoice` tinyint(1) NOT NULL DEFAULT '0',
  `phone_no` varchar(100) NOT NULL,
  `isInventoryUpdated` tinyint(1) NOT NULL DEFAULT '0',
  `is_advance_paid` tinyint(1) NOT NULL DEFAULT '0',
  `insurance_id` int NOT NULL DEFAULT '0',
  `invRef` varchar(500) NOT NULL DEFAULT '',
  `note` varchar(500) NOT NULL,
  `location_id` int NOT NULL,
  `invoiceNote` varchar(1000) NOT NULL,
  `repId` int NOT NULL,
  `so_id` int NOT NULL,
  `total_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `is_deposit_paid` tinyint(1) NOT NULL DEFAULT '0',
  `is_sendto_print` tinyint(1) NOT NULL DEFAULT '0',
  `printerSend_on` datetime NOT NULL DEFAULT '2020-01-01 00:00:00',
  `isTaxFree` tinyint(1) NOT NULL DEFAULT '0',
  `sale_location_id` int NOT NULL DEFAULT '0',
  `other` varchar(1000) NOT NULL,
  `repId2` int NOT NULL,
  `_billNet` decimal(16,2) NOT NULL,
  `_billSub` decimal(16,2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice`
--


--
-- Table structure for table `tbl_sale_invoice_cost`
--

CREATE TABLE `tbl_sale_invoice_cost` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sale_invoice_id` int NOT NULL,
  `cost_date` date NOT NULL,
  `location_id` int NOT NULL,
  `code` varchar(100) NOT NULL,
  `status` varchar(100) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `cost` decimal(16,2) NOT NULL,
  `description` varchar(1000) NOT NULL,
  `updated_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_cost`
--


--
-- Table structure for table `tbl_sale_invoice_cost_details`
--

CREATE TABLE `tbl_sale_invoice_cost_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_cost_details`
--


--
-- Table structure for table `tbl_sale_invoice_cost_products`
--

CREATE TABLE `tbl_sale_invoice_cost_products` (
  `id` int NOT NULL AUTO_INCREMENT,
  `cost_id` int NOT NULL,
  `product_id` int NOT NULL,
  `qty` decimal(11,6) NOT NULL,
  `unitPrice` decimal(11,2) NOT NULL,
  `total` decimal(11,2) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `uom_id` int NOT NULL,
  `uom_value` decimal(11,2) NOT NULL,
  `uom` varchar(50) NOT NULL,
  `product_uom` varchar(50) NOT NULL,
  `custam_product_name` varchar(500) NOT NULL,
  `type` varchar(100) NOT NULL DEFAULT 'product',
  `uom_selling_precentage` int NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_cost_products`
--


--
-- Table structure for table `tbl_sale_invoice_details`
--

CREATE TABLE `tbl_sale_invoice_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_details`
--


--
-- Table structure for table `tbl_sale_invoice_products`
--

CREATE TABLE `tbl_sale_invoice_products` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sale_invoice_id` int NOT NULL,
  `product_id` int NOT NULL,
  `unit_price` decimal(11,2) NOT NULL DEFAULT '0.00',
  `qty` decimal(11,2) NOT NULL DEFAULT '0.00',
  `discount_type` varchar(50) NOT NULL,
  `discount_rate` decimal(11,2) NOT NULL DEFAULT '0.00',
  `discount` decimal(11,2) NOT NULL DEFAULT '0.00',
  `net_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `returned_qty` decimal(16,2) NOT NULL DEFAULT '0.00',
  `tax` varchar(50) NOT NULL,
  `tax_amount` decimal(11,2) NOT NULL,
  `description` varchar(1000) NOT NULL,
  `work_type_id` int NOT NULL,
  `part_type` varchar(100) NOT NULL,
  `type` varchar(50) NOT NULL DEFAULT 'product',
  `service_details` varchar(1000) NOT NULL,
  `product_name` varchar(1000) NOT NULL,
  `estimationDetailsId` int NOT NULL,
  `discountApproved` varchar(500) NOT NULL,
  `costPrice` decimal(11,2) NOT NULL,
  `uom_id` int NOT NULL,
  `uom_value` decimal(11,4) NOT NULL,
  `uom` varchar(50) NOT NULL,
  `product_uom` varchar(10) NOT NULL,
  `per_item_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `total_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `is_depositItem` tinyint(1) NOT NULL DEFAULT '0',
  `for_rentItemId` int NOT NULL,
  `uom_selling_precentage` int NOT NULL DEFAULT '0',
  `product_price` decimal(16,2) NOT NULL,
  `is_depositByItemCount` tinyint(1) NOT NULL DEFAULT '0',
  `rentDays` int NOT NULL DEFAULT '1',
  `rent_type` varchar(100) NOT NULL,
  `additional_dis_type` varchar(10) NOT NULL DEFAULT '%',
  `additional_dis_rate` decimal(16,2) NOT NULL DEFAULT '0.00',
  `additional_dis_amount` decimal(16,2) NOT NULL DEFAULT '0.00',
  `ajustment_id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_products`
--


--
-- Table structure for table `tbl_sale_invoice_products_unsetled`
--

CREATE TABLE `tbl_sale_invoice_products_unsetled` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sale_invoice_id` int NOT NULL,
  `product_id` int NOT NULL,
  `unit_price` decimal(11,2) NOT NULL DEFAULT '0.00',
  `qty` decimal(11,2) NOT NULL DEFAULT '0.00',
  `discount_type` varchar(50) NOT NULL,
  `discount_rate` decimal(11,2) NOT NULL DEFAULT '0.00',
  `discount` decimal(11,2) NOT NULL DEFAULT '0.00',
  `net_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `returned_qty` decimal(16,2) NOT NULL DEFAULT '0.00',
  `tax` varchar(50) NOT NULL,
  `tax_amount` decimal(11,2) NOT NULL,
  `description` varchar(1000) NOT NULL,
  `work_type_id` int NOT NULL,
  `part_type` varchar(100) NOT NULL,
  `type` varchar(50) NOT NULL DEFAULT 'product',
  `service_details` varchar(1000) NOT NULL,
  `product_name` varchar(1000) NOT NULL,
  `estimationDetailsId` int NOT NULL,
  `discountApproved` varchar(500) NOT NULL,
  `costPrice` decimal(11,2) NOT NULL,
  `uom_id` int NOT NULL,
  `uom_value` decimal(11,4) NOT NULL,
  `uom` varchar(50) NOT NULL,
  `product_uom` varchar(10) NOT NULL,
  `per_item_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `total_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `is_depositItem` tinyint(1) NOT NULL DEFAULT '0',
  `for_rentItemId` int NOT NULL,
  `uom_selling_precentage` int NOT NULL DEFAULT '0',
  `product_price` decimal(16,2) NOT NULL,
  `is_depositByItemCount` tinyint(1) NOT NULL DEFAULT '0',
  `rentDays` int NOT NULL DEFAULT '1',
  `rent_type` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_products_unsetled`
--


--
-- Table structure for table `tbl_sale_invoice_products_void`
--

CREATE TABLE `tbl_sale_invoice_products_void` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sale_invoice_id` int NOT NULL,
  `product_id` int NOT NULL,
  `unit_price` decimal(11,2) NOT NULL DEFAULT '0.00',
  `qty` decimal(11,2) NOT NULL DEFAULT '0.00',
  `discount_type` varchar(50) NOT NULL,
  `discount_rate` decimal(11,2) NOT NULL DEFAULT '0.00',
  `discount` decimal(11,2) NOT NULL DEFAULT '0.00',
  `net_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `returned_qty` decimal(16,2) NOT NULL DEFAULT '0.00',
  `tax` varchar(50) NOT NULL,
  `tax_amount` decimal(11,2) NOT NULL,
  `description` varchar(1000) NOT NULL,
  `work_type_id` int NOT NULL,
  `part_type` varchar(100) NOT NULL,
  `type` varchar(50) NOT NULL DEFAULT 'product',
  `service_details` varchar(1000) NOT NULL,
  `product_name` varchar(1000) NOT NULL,
  `estimationDetailsId` int NOT NULL,
  `discountApproved` varchar(500) NOT NULL,
  `costPrice` decimal(11,2) NOT NULL,
  `uom_id` int NOT NULL,
  `uom_value` decimal(11,4) NOT NULL,
  `uom` varchar(50) NOT NULL,
  `product_uom` varchar(10) NOT NULL,
  `per_item_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `total_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `is_depositItem` tinyint(1) NOT NULL DEFAULT '0',
  `for_rentItemId` int NOT NULL,
  `uom_selling_precentage` int NOT NULL DEFAULT '0',
  `product_price` decimal(16,2) NOT NULL,
  `is_depositByItemCount` tinyint(1) NOT NULL DEFAULT '0',
  `rentDays` int NOT NULL DEFAULT '1',
  `rent_type` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_products_void`
--


--
-- Table structure for table `tbl_sale_invoice_unsetled`
--

CREATE TABLE `tbl_sale_invoice_unsetled` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `status` varchar(50) NOT NULL,
  `discount_type` varchar(10) NOT NULL DEFAULT '0.00',
  `discount_rate` decimal(11,2) NOT NULL DEFAULT '0.00',
  `total_discount` decimal(11,2) NOT NULL DEFAULT '0.00',
  `net_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `sub_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `customer_id` int NOT NULL,
  `rpt_settled_amount` decimal(16,2) NOT NULL,
  `rpt_returns_amount` decimal(16,2) NOT NULL,
  `is_settled` decimal(16,2) NOT NULL,
  `invoice_type_id` int NOT NULL,
  `bill_tax_amount` decimal(16,2) NOT NULL,
  `bill_tax` varchar(100) NOT NULL,
  `vehicle_id` int NOT NULL,
  `is_printed` tinyint(1) NOT NULL DEFAULT '0',
  `estimation_id` int NOT NULL,
  `invoice_category` varchar(50) NOT NULL,
  `is_permanent_cancelled` tinyint(1) NOT NULL DEFAULT '0',
  `rpt_cash_returns` decimal(16,2) NOT NULL,
  `is_credit_invoice` tinyint(1) NOT NULL DEFAULT '0',
  `phone_no` varchar(100) NOT NULL,
  `isInventoryUpdated` tinyint(1) NOT NULL DEFAULT '0',
  `is_advance_paid` tinyint(1) NOT NULL DEFAULT '0',
  `insurance_id` int NOT NULL DEFAULT '0',
  `invRef` varchar(500) NOT NULL DEFAULT '',
  `note` varchar(500) NOT NULL,
  `location_id` int NOT NULL,
  `invoiceNote` varchar(1000) NOT NULL,
  `repId` int NOT NULL,
  `so_id` int NOT NULL,
  `total_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `is_deposit_paid` tinyint(1) NOT NULL DEFAULT '0',
  `is_sendto_print` tinyint(1) NOT NULL DEFAULT '0',
  `printerSend_on` datetime NOT NULL DEFAULT '2020-01-01 00:00:00',
  `isTaxFree` tinyint(1) NOT NULL DEFAULT '0',
  `sale_location_id` int NOT NULL DEFAULT '0',
  `other` varchar(1000) NOT NULL,
  `repId2` int NOT NULL,
  `_billNet` decimal(16,2) NOT NULL,
  `_billSub` decimal(16,2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_unsetled`
--


--
-- Table structure for table `tbl_sale_invoice_void`
--

CREATE TABLE `tbl_sale_invoice_void` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `status` varchar(50) NOT NULL,
  `discount_type` varchar(10) NOT NULL DEFAULT '0.00',
  `discount_rate` decimal(11,2) NOT NULL DEFAULT '0.00',
  `total_discount` decimal(11,2) NOT NULL DEFAULT '0.00',
  `net_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `sub_total` decimal(11,2) NOT NULL DEFAULT '0.00',
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `customer_id` int NOT NULL,
  `rpt_settled_amount` decimal(16,2) NOT NULL,
  `rpt_returns_amount` decimal(16,2) NOT NULL,
  `is_settled` decimal(16,2) NOT NULL,
  `invoice_type_id` int NOT NULL,
  `bill_tax_amount` decimal(16,2) NOT NULL,
  `bill_tax` varchar(100) NOT NULL,
  `vehicle_id` int NOT NULL,
  `is_printed` tinyint(1) NOT NULL DEFAULT '0',
  `estimation_id` int NOT NULL,
  `invoice_category` varchar(50) NOT NULL,
  `is_permanent_cancelled` tinyint(1) NOT NULL DEFAULT '0',
  `rpt_cash_returns` decimal(16,2) NOT NULL,
  `is_credit_invoice` tinyint(1) NOT NULL DEFAULT '0',
  `phone_no` varchar(100) NOT NULL,
  `isInventoryUpdated` tinyint(1) NOT NULL DEFAULT '0',
  `is_advance_paid` tinyint(1) NOT NULL DEFAULT '0',
  `insurance_id` int NOT NULL DEFAULT '0',
  `invRef` varchar(500) NOT NULL DEFAULT '',
  `note` varchar(500) NOT NULL,
  `location_id` int NOT NULL,
  `invoiceNote` varchar(1000) NOT NULL,
  `repId` int NOT NULL,
  `so_id` int NOT NULL,
  `total_deposit` decimal(11,2) NOT NULL DEFAULT '0.00',
  `is_deposit_paid` tinyint(1) NOT NULL DEFAULT '0',
  `is_sendto_print` tinyint(1) NOT NULL DEFAULT '0',
  `printerSend_on` datetime NOT NULL DEFAULT '2020-01-01 00:00:00',
  `isTaxFree` tinyint(1) NOT NULL DEFAULT '0',
  `sale_location_id` int NOT NULL DEFAULT '0',
  `other` varchar(1000) NOT NULL,
  `repId2` int NOT NULL,
  `_billNet` decimal(16,2) NOT NULL,
  `_billSub` decimal(16,2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sale_invoice_void`
--


--
-- Table structure for table `tbl_sales_rep`
--

CREATE TABLE `tbl_sales_rep` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `name` varchar(500) NOT NULL,
  `phone_no` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sales_rep`
--


--
-- Table structure for table `tbl_sales_rep_details`
--

CREATE TABLE `tbl_sales_rep_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sales_rep_details`
--


--
-- Table structure for table `tbl_sample_details`
--

CREATE TABLE `tbl_sample_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sample_details`
--


--
-- Table structure for table `tbl_sample_products`
--

CREATE TABLE `tbl_sample_products` (
  `sample_product_id` int NOT NULL AUTO_INCREMENT,
  `sample_id` int NOT NULL,
  `product_id` int NOT NULL,
  `qty` decimal(18,6) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `unit_price` decimal(16,2) NOT NULL,
  `total` decimal(16,2) NOT NULL,
  PRIMARY KEY (`sample_product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sample_products`
--


--
-- Table structure for table `tbl_sample_return_details`
--

CREATE TABLE `tbl_sample_return_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sample_return_details`
--


--
-- Table structure for table `tbl_sample_return_products`
--

CREATE TABLE `tbl_sample_return_products` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sample_id` int NOT NULL,
  `product_id` int NOT NULL,
  `qty` decimal(18,6) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `unit_price` decimal(16,2) NOT NULL,
  `total` decimal(16,2) NOT NULL,
  `status` varchar(50) NOT NULL,
  `sample_return_id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sample_return_products`
--


--
-- Table structure for table `tbl_sample_returns`
--

CREATE TABLE `tbl_sample_returns` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sample_id` int NOT NULL,
  `code` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `return_date` date NOT NULL,
  `status` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `location_id` int NOT NULL DEFAULT '0',
  `total` decimal(16,2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_sample_returns`
--


--
-- Table structure for table `tbl_samples`
--

CREATE TABLE `tbl_samples` (
  `sample_id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `sample_date` date NOT NULL,
  `status` varchar(500) NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `customer_id` int NOT NULL,
  `location_id` int NOT NULL DEFAULT '0',
  `total` decimal(16,2) NOT NULL,
  PRIMARY KEY (`sample_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_samples`
--


--
-- Table structure for table `tbl_so`
--

CREATE TABLE `tbl_so` (
  `so_id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `contract_id` int NOT NULL,
  `so_date` date NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `status` varchar(50) NOT NULL,
  `dis_type` varchar(10) NOT NULL,
  `discount_rate` decimal(11,2) NOT NULL,
  `discount` decimal(11,2) NOT NULL,
  `sub_total` decimal(11,2) NOT NULL,
  `total` decimal(11,2) NOT NULL,
  `is_invoiced` tinyint(1) DEFAULT '0',
  `currency_id` int NOT NULL DEFAULT '0',
  `exchange_rate` decimal(16,2) NOT NULL DEFAULT '0.00',
  `customer_id` int DEFAULT NULL,
  `sale_type` varchar(45) DEFAULT NULL,
  `paid_amount` decimal(18,4) DEFAULT '0.0000',
  `location_id` int NOT NULL,
  `manual_bill_no` varchar(1000) NOT NULL,
  `vehicle_id` int NOT NULL,
  `transport_method_id` int NOT NULL,
  `price_group_id` int NOT NULL DEFAULT '1',
  `vehicle_no` varchar(50) NOT NULL,
  `manual_bill_date` varchar(100) NOT NULL DEFAULT '',
  `rpt_invoiced_qty` decimal(16,2) NOT NULL,
  `rpt_so_qty` decimal(16,2) NOT NULL,
  PRIMARY KEY (`so_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_so`
--


--
-- Table structure for table `tbl_so_details`
--

CREATE TABLE `tbl_so_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_so_details`
--


--
-- Table structure for table `tbl_so_products`
--

CREATE TABLE `tbl_so_products` (
  `so_product_id` int NOT NULL AUTO_INCREMENT,
  `so_id` int NOT NULL,
  `product_id` int NOT NULL,
  `ContractQty` decimal(11,6) NOT NULL,
  `unitPrice` decimal(11,2) NOT NULL,
  `total` decimal(11,2) NOT NULL,
  `allocated_qty` decimal(18,6) DEFAULT '0.000000',
  `dispatch_qty` decimal(18,6) DEFAULT '0.000000',
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `uom_id` int NOT NULL,
  `uom_value` decimal(11,2) NOT NULL,
  `uom` varchar(50) NOT NULL,
  `product_uom` varchar(50) NOT NULL,
  `custam_product_name` varchar(500) NOT NULL,
  `type` varchar(100) NOT NULL DEFAULT 'product',
  `uom_selling_precentage` int NOT NULL DEFAULT '0',
  `product_price` decimal(16,2) NOT NULL DEFAULT '0.00',
  `minimum_price` decimal(16,2) NOT NULL,
  PRIMARY KEY (`so_product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_so_products`
--


--
-- Table structure for table `tbl_status_log`
--

CREATE TABLE `tbl_status_log` (
  `id` int NOT NULL AUTO_INCREMENT,
  `status` varchar(10) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `parent_type` varchar(50) NOT NULL,
  `parent_id` int NOT NULL,
  `status_text` varchar(100) NOT NULL,
  `parent_code` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_status_log`
--


--
-- Table structure for table `tbl_stock_adjustment`
--

CREATE TABLE `tbl_stock_adjustment` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(50) NOT NULL,
  `status` varchar(50) NOT NULL,
  `description` varchar(1000) NOT NULL,
  `adjustment_date` date NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `is_stock_take` tinyint(1) NOT NULL DEFAULT '0',
  `take_type` varchar(50) NOT NULL,
  `location_id` int NOT NULL,
  `scanned_id` int NOT NULL,
  `doc_path` varchar(1000) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_stock_adjustment`
--


--
-- Table structure for table `tbl_stock_adjustment_details`
--

CREATE TABLE `tbl_stock_adjustment_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_stock_adjustment_details`
--


--
-- Table structure for table `tbl_stock_adjustment_products`
--

CREATE TABLE `tbl_stock_adjustment_products` (
  `id` int NOT NULL AUTO_INCREMENT,
  `stock_adjustment_id` int NOT NULL,
  `product_id` int NOT NULL,
  `qty` decimal(11,2) NOT NULL DEFAULT '0.00',
  `description` varchar(50) NOT NULL,
  `status` varchar(50) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `counted_qty` decimal(11,2) NOT NULL DEFAULT '0.00',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_stock_adjustment_products`
--


--
-- Table structure for table `tbl_supplier`
--

CREATE TABLE `tbl_supplier` (
  `supplier_id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(500) NOT NULL,
  `code` varchar(50) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL DEFAULT '2021-01-01 00:00:01',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `updated_by` int NOT NULL,
  `updated_on` datetime NOT NULL,
  `contact_person` varchar(100) NOT NULL,
  `contact_no` varchar(80) NOT NULL,
  `supplier_address` varchar(500) NOT NULL,
  `contact_no_2` varchar(80) NOT NULL,
  `rpt_settled_amount` decimal(16,2) NOT NULL,
  `rpt_outstanding_amount` decimal(16,2) NOT NULL,
  `rpt_return_amount` decimal(16,2) NOT NULL,
  `rpt_grn_total` decimal(16,2) NOT NULL DEFAULT '0.00',
  `rpt_grn_settled_total` decimal(16,2) NOT NULL DEFAULT '0.00',
  `rpt_grn_return_total` decimal(16,2) NOT NULL DEFAULT '0.00',
  `rpt_import_grn_total` decimal(16,2) NOT NULL DEFAULT '0.00',
  `rpt_import_grn_settled_total` decimal(16,2) NOT NULL DEFAULT '0.00',
  `rpt_import_grn_return_total` decimal(16,2) NOT NULL DEFAULT '0.00',
  PRIMARY KEY (`supplier_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_supplier`
--


--
-- Table structure for table `tbl_supplier_payment_details`
--

CREATE TABLE `tbl_supplier_payment_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `adjustment_id` int NOT NULL,
  `payAmount` decimal(16,2) NOT NULL,
  `type` varchar(50) NOT NULL,
  `status` varchar(50) NOT NULL,
  `payment_id` int NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_supplier_payment_details`
--


--
-- Table structure for table `tbl_supplier_payments`
--

CREATE TABLE `tbl_supplier_payments` (
  `id` int NOT NULL AUTO_INCREMENT,
  `payment_type` varchar(50) NOT NULL,
  `payment_date` date NOT NULL,
  `amount` decimal(16,2) NOT NULL,
  `cheque_date` date NOT NULL,
  `branch` varchar(50) NOT NULL,
  `bank_id` int NOT NULL,
  `online_reference` varchar(100) NOT NULL,
  `cheque_no` varchar(50) NOT NULL,
  `description` varchar(500) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `updated_on` datetime NOT NULL,
  `updated_by` int NOT NULL,
  `status` varchar(50) NOT NULL,
  `code` varchar(50) NOT NULL,
  `grn_id` int NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `adjustment_id` int NOT NULL,
  `type` varchar(50) NOT NULL DEFAULT 'GRN',
  `supplier_id` int NOT NULL,
  `is_bulk` tinyint(1) NOT NULL DEFAULT '0',
  `location_id` int NOT NULL,
  `is_returned` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_supplier_payments`
--


--
-- Table structure for table `tbl_supplier_payments_details`
--

CREATE TABLE `tbl_supplier_payments_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_supplier_payments_details`
--


--
-- Table structure for table `tbl_supplier_payments_grns`
--

CREATE TABLE `tbl_supplier_payments_grns` (
  `id` int NOT NULL AUTO_INCREMENT,
  `supplier_payment_id` int NOT NULL,
  `grn_id` int NOT NULL,
  `amount` decimal(16,2) NOT NULL,
  `status` varchar(10) NOT NULL,
  `type` varchar(50) NOT NULL,
  `is_cheque_returned` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_supplier_payments_grns`
--


--
-- Table structure for table `tbl_suppliers_details`
--

CREATE TABLE `tbl_suppliers_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `parent_id` int NOT NULL,
  `field_name` varchar(50) NOT NULL,
  `field_value` varchar(5000) NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_suppliers_details`
--


--
-- Table structure for table `tbl_system_settings`
--

CREATE TABLE `tbl_system_settings` (
  `id` int NOT NULL AUTO_INCREMENT,
  `code` varchar(100) NOT NULL,
  `description` varchar(5000) NOT NULL,
  `setting` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_system_settings`
--

INSERT INTO `tbl_system_settings` VALUES (1,'product_category_code_auto','Product category code auto generated or manually added','1'),(2,'product_code_auto','Product code auto generated or manually added','1'),(3,'product_code_with_category_code','Ex: category code + Product code\r\n    123-456','1'),(4,'select_2_search_characters','Boostrap select 2 search characters','2'),(5,'product_cost_method','product_cost_method','AVG_COST'),(6,'insurance_invoice','insurance invoice prifix',''),(8,'cash_customer_return_overpayments','cash customer allow create overpayments','1'),(9,'decimal_points','input decimal points','2'),(10,'customer_edit_approval','new customer or edit customer approval','0'),(11,'pdfPath','Invoice pdf template path','Demo/'),(12,'SO_product_image','Sales order product image and qty selected','1'),(13,'is_printPosPrinter','invoice print POS printer','1'),(14,'system_folder','production system falder name','demo'),(15,'pos_printer_key','pos printer requested key','13'),(16,'SO_product_lines','SO load product grid lines','10'),(17,'is_subCategoryAvailable','product catalog search enable product sub category screen','1'),(18,'product_code_with_brand_code','Product code with barnd code','0'),(19,'is_second_rep_available','enable second rep add in invoice','1'),(20,'SO_manual_bill_date','SO manual bill date added invoice date','1'),(21,'is_allMinimumPriceApproved','create invoice, minimum price > price approved','1'),(22,'is_vehicle_estimation','vehicle estimation or normal estimation','0'),(23,'is_product_category_edit','Product category edit available','1'),(24,'authentication_expire_minutes','Login authentication expire minutes','480'),(25,'is_popdf_view_import_details','is po pdf view import details','0'),(26,'common_inventory_location','Common inventory location - use one inventory location','0'),(27,'is_view_product_image','create invoice, search products view image','0'),(28,'return_not_allowed_payment_adjustment_reason_ids','if return product, not allowed debit notes','0'),(29,'is_daily_cash_in_remove','daily cash in popup not view in day start. invoice form','0'),(30,'credit_period_limit','credit period exceed and credit limit','0');

--
-- Table structure for table `tbl_tax`
--

CREATE TABLE `tbl_tax` (
  `id` int NOT NULL AUTO_INCREMENT,
  `tax` varchar(100) NOT NULL,
  `tax_percentage` decimal(11,2) NOT NULL,
  `type` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_tax`
--

INSERT INTO `tbl_tax` VALUES (1,'VAT(5%)',5.00,'bill'),(2,'VAT(20%)',20.00,'bill');

--
-- Table structure for table `tbl_temp_boq_details`
--

CREATE TABLE `tbl_temp_boq_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `uuid` varchar(500) NOT NULL,
  `boq_id` int NOT NULL,
  `catonsQty` decimal(11,2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_temp_boq_details`
--


--
-- Table structure for table `tbl_temp_contract_ids`
--

CREATE TABLE `tbl_temp_contract_ids` (
  `id` int NOT NULL AUTO_INCREMENT,
  `contract_id` int NOT NULL,
  `uuid` varchar(500) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_temp_contract_ids`
--


--
-- Table structure for table `tbl_temp_payments_details`
--

CREATE TABLE `tbl_temp_payments_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `advance_payments_id` int NOT NULL,
  `customer_id` int NOT NULL,
  `payment_type` varchar(100) NOT NULL,
  `sessionPaymentRef` varchar(100) NOT NULL,
  `amount` decimal(16,2) NOT NULL,
  `note` varchar(500) NOT NULL,
  `reference` varchar(500) NOT NULL,
  `cash_date` date NOT NULL,
  `cheque_date` date NOT NULL,
  `cheque_no` varchar(100) NOT NULL,
  `bank_id` int NOT NULL,
  `bank_branch` varchar(100) NOT NULL,
  `bank_account_id` int NOT NULL,
  `advancePaymnet_date` date NOT NULL,
  `created_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `card_type_id` int NOT NULL,
  `outstanding_type` varchar(100) NOT NULL,
  `outstanding_amount` decimal(16,2) NOT NULL,
  `outstanding_parent_id` int NOT NULL,
  `outstanding_sale_invoice_id` int NOT NULL,
  `outstanding_ref` varchar(100) NOT NULL,
  `receipt_no` varchar(1000) NOT NULL,
  `received_date` date NOT NULL DEFAULT '2000-01-01',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_temp_payments_details`
--


--
-- Table structure for table `tbl_template_details`
--

CREATE TABLE `tbl_template_details` (
  `template_details_id` int NOT NULL AUTO_INCREMENT,
  `template_code` varchar(100) DEFAULT '',
  `text` varchar(1000) DEFAULT '',
  `type` varchar(45) DEFAULT 'text',
  `data_type` varchar(45) DEFAULT NULL,
  `field_id` varchar(100) DEFAULT '',
  `field_rules` varchar(2000) DEFAULT '',
  `placeholder` varchar(100) DEFAULT '',
  `disabled` varchar(50) DEFAULT '',
  `class` varchar(2000) DEFAULT '',
  `default_values` varchar(2000) DEFAULT '',
  `drop_down_options` varchar(5000) DEFAULT NULL,
  `create_user_Id` int DEFAULT NULL,
  `create_datetime` datetime DEFAULT NULL,
  `is_active` int DEFAULT '1',
  PRIMARY KEY (`template_details_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_template_details`
--

INSERT INTO `tbl_template_details` VALUES (2,'customer','Fn account id','text','text','fn_account_id','','Enter...','','','','',77,'2024-09-27 07:53:07',1);

--
-- Table structure for table `tbl_templates`
--

CREATE TABLE `tbl_templates` (
  `id` int NOT NULL AUTO_INCREMENT,
  `type` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_templates`
--


--
-- Table structure for table `tbl_transport_methods`
--

CREATE TABLE `tbl_transport_methods` (
  `id` int NOT NULL AUTO_INCREMENT,
  `method` varchar(1000) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_transport_methods`
--

INSERT INTO `tbl_transport_methods` VALUES (1,'Transport'),(2,'Currier'),(3,'Threewheel'),(4,'Personal');

--
-- Table structure for table `tbl_uom`
--

CREATE TABLE `tbl_uom` (
  `id` int NOT NULL AUTO_INCREMENT,
  `uom` varchar(50) NOT NULL,
  `uom_short` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_uom`
--

INSERT INTO `tbl_uom` VALUES (1,'Pieces','pcs'),(5,'Nos','nos'),(6,'Grams','gm'),(7,'mililitters','ml'),(8,'Bottle','bottle'),(9,'Unit','unit');

--
-- Table structure for table `tbl_user_group_rights`
--

CREATE TABLE `tbl_user_group_rights` (
  `user_group_right_Id` int NOT NULL AUTO_INCREMENT,
  `user_group_Id` int NOT NULL,
  `user_right_id` int NOT NULL,
  `create_user_Id` int NOT NULL,
  `create_datetime` datetime NOT NULL,
  PRIMARY KEY (`user_group_right_Id`)
) ENGINE=InnoDB AUTO_INCREMENT=15948 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_user_group_rights`
--

INSERT INTO `tbl_user_group_rights` VALUES (10089,88,112,0,'0000-00-00 00:00:00'),(10090,88,114,0,'0000-00-00 00:00:00'),(10091,88,115,0,'0000-00-00 00:00:00'),(10092,88,390,0,'0000-00-00 00:00:00'),(10093,88,153,0,'0000-00-00 00:00:00'),(10094,88,154,0,'0000-00-00 00:00:00'),(10095,88,155,0,'0000-00-00 00:00:00'),(10096,88,229,0,'0000-00-00 00:00:00'),(10097,88,230,0,'0000-00-00 00:00:00'),(10098,88,231,0,'0000-00-00 00:00:00'),(10099,88,232,0,'0000-00-00 00:00:00'),(10100,88,233,0,'0000-00-00 00:00:00'),(10101,88,234,0,'0000-00-00 00:00:00'),(10102,88,314,0,'0000-00-00 00:00:00'),(14874,69,24,0,'0000-00-00 00:00:00'),(14875,69,109,0,'0000-00-00 00:00:00'),(14876,69,110,0,'0000-00-00 00:00:00'),(14877,69,111,0,'0000-00-00 00:00:00'),(14878,69,25,0,'0000-00-00 00:00:00'),(14879,69,76,0,'0000-00-00 00:00:00'),(14880,69,77,0,'0000-00-00 00:00:00'),(14881,69,107,0,'0000-00-00 00:00:00'),(14882,69,108,0,'0000-00-00 00:00:00'),(14883,69,106,0,'0000-00-00 00:00:00'),(14884,69,112,0,'0000-00-00 00:00:00'),(14885,69,113,0,'0000-00-00 00:00:00'),(14886,69,114,0,'0000-00-00 00:00:00'),(14887,69,115,0,'0000-00-00 00:00:00'),(14888,69,295,0,'0000-00-00 00:00:00'),(14889,69,318,0,'0000-00-00 00:00:00'),(14890,69,120,0,'0000-00-00 00:00:00'),(14891,69,121,0,'0000-00-00 00:00:00'),(14892,69,122,0,'0000-00-00 00:00:00'),(14893,69,123,0,'0000-00-00 00:00:00'),(14894,69,116,0,'0000-00-00 00:00:00'),(14895,69,117,0,'0000-00-00 00:00:00'),(14896,69,118,0,'0000-00-00 00:00:00'),(14897,69,119,0,'0000-00-00 00:00:00'),(14898,69,445,0,'0000-00-00 00:00:00'),(14899,69,446,0,'0000-00-00 00:00:00'),(14900,69,447,0,'0000-00-00 00:00:00'),(14901,69,448,0,'0000-00-00 00:00:00'),(14902,69,274,0,'0000-00-00 00:00:00'),(14903,69,275,0,'0000-00-00 00:00:00'),(14904,69,276,0,'0000-00-00 00:00:00'),(14905,69,277,0,'0000-00-00 00:00:00'),(14906,69,289,0,'0000-00-00 00:00:00'),(14907,69,290,0,'0000-00-00 00:00:00'),(14908,69,291,0,'0000-00-00 00:00:00'),(14909,69,361,0,'0000-00-00 00:00:00'),(14910,69,362,0,'0000-00-00 00:00:00'),(14911,69,364,0,'0000-00-00 00:00:00'),(14912,69,365,0,'0000-00-00 00:00:00'),(14913,69,367,0,'0000-00-00 00:00:00'),(14914,69,368,0,'0000-00-00 00:00:00'),(14915,69,418,0,'0000-00-00 00:00:00'),(14916,69,419,0,'0000-00-00 00:00:00'),(14917,69,135,0,'0000-00-00 00:00:00'),(14918,69,136,0,'0000-00-00 00:00:00'),(14919,69,137,0,'0000-00-00 00:00:00'),(14920,69,172,0,'0000-00-00 00:00:00'),(14921,69,187,0,'0000-00-00 00:00:00'),(14922,69,188,0,'0000-00-00 00:00:00'),(14923,69,189,0,'0000-00-00 00:00:00'),(14924,69,190,0,'0000-00-00 00:00:00'),(14925,69,191,0,'0000-00-00 00:00:00'),(14926,69,138,0,'0000-00-00 00:00:00'),(14927,69,139,0,'0000-00-00 00:00:00'),(14928,69,140,0,'0000-00-00 00:00:00'),(14929,69,173,0,'0000-00-00 00:00:00'),(14930,69,193,0,'0000-00-00 00:00:00'),(14931,69,194,0,'0000-00-00 00:00:00'),(14932,69,195,0,'0000-00-00 00:00:00'),(14933,69,196,0,'0000-00-00 00:00:00'),(14934,69,197,0,'0000-00-00 00:00:00'),(14935,69,162,0,'0000-00-00 00:00:00'),(14936,69,163,0,'0000-00-00 00:00:00'),(14937,69,164,0,'0000-00-00 00:00:00'),(14938,69,199,0,'0000-00-00 00:00:00'),(14939,69,200,0,'0000-00-00 00:00:00'),(14940,69,201,0,'0000-00-00 00:00:00'),(14941,69,202,0,'0000-00-00 00:00:00'),(14942,69,203,0,'0000-00-00 00:00:00'),(14943,69,319,0,'0000-00-00 00:00:00'),(14944,69,320,0,'0000-00-00 00:00:00'),(14945,69,321,0,'0000-00-00 00:00:00'),(14946,69,322,0,'0000-00-00 00:00:00'),(14947,69,323,0,'0000-00-00 00:00:00'),(14948,69,324,0,'0000-00-00 00:00:00'),(14949,69,325,0,'0000-00-00 00:00:00'),(14950,69,326,0,'0000-00-00 00:00:00'),(14951,69,327,0,'0000-00-00 00:00:00'),(14952,69,328,0,'0000-00-00 00:00:00'),(14953,69,331,0,'0000-00-00 00:00:00'),(14954,69,332,0,'0000-00-00 00:00:00'),(14955,69,333,0,'0000-00-00 00:00:00'),(14956,69,334,0,'0000-00-00 00:00:00'),(14957,69,335,0,'0000-00-00 00:00:00'),(14958,69,336,0,'0000-00-00 00:00:00'),(14959,69,337,0,'0000-00-00 00:00:00'),(14960,69,338,0,'0000-00-00 00:00:00'),(14961,69,339,0,'0000-00-00 00:00:00'),(14962,69,381,0,'0000-00-00 00:00:00'),(14963,69,382,0,'0000-00-00 00:00:00'),(14964,69,383,0,'0000-00-00 00:00:00'),(14965,69,384,0,'0000-00-00 00:00:00'),(14966,69,385,0,'0000-00-00 00:00:00'),(14967,69,386,0,'0000-00-00 00:00:00'),(14968,69,387,0,'0000-00-00 00:00:00'),(14969,69,388,0,'0000-00-00 00:00:00'),(14970,69,390,0,'0000-00-00 00:00:00'),(14971,69,141,0,'0000-00-00 00:00:00'),(14972,69,142,0,'0000-00-00 00:00:00'),(14973,69,143,0,'0000-00-00 00:00:00'),(14974,69,293,0,'0000-00-00 00:00:00'),(14975,69,154,0,'0000-00-00 00:00:00'),(14976,69,155,0,'0000-00-00 00:00:00'),(14977,69,229,0,'0000-00-00 00:00:00'),(14978,69,230,0,'0000-00-00 00:00:00'),(14979,69,231,0,'0000-00-00 00:00:00'),(14980,69,232,0,'0000-00-00 00:00:00'),(14981,69,233,0,'0000-00-00 00:00:00'),(14982,69,234,0,'0000-00-00 00:00:00'),(14983,69,281,0,'0000-00-00 00:00:00'),(14984,69,285,0,'0000-00-00 00:00:00'),(14985,69,359,0,'0000-00-00 00:00:00'),(14986,69,378,0,'0000-00-00 00:00:00'),(14987,69,444,0,'0000-00-00 00:00:00'),(14988,69,314,0,'0000-00-00 00:00:00'),(14989,69,174,0,'0000-00-00 00:00:00'),(14990,69,242,0,'0000-00-00 00:00:00'),(14991,69,243,0,'0000-00-00 00:00:00'),(14992,69,244,0,'0000-00-00 00:00:00'),(14993,69,298,0,'0000-00-00 00:00:00'),(14994,69,249,0,'0000-00-00 00:00:00'),(14995,69,250,0,'0000-00-00 00:00:00'),(14996,69,251,0,'0000-00-00 00:00:00'),(14997,69,252,0,'0000-00-00 00:00:00'),(14998,69,253,0,'0000-00-00 00:00:00'),(14999,69,254,0,'0000-00-00 00:00:00'),(15000,69,255,0,'0000-00-00 00:00:00'),(15001,69,256,0,'0000-00-00 00:00:00'),(15002,69,257,0,'0000-00-00 00:00:00'),(15003,69,540,0,'0000-00-00 00:00:00'),(15004,69,541,0,'0000-00-00 00:00:00'),(15005,69,542,0,'0000-00-00 00:00:00'),(15006,69,545,0,'0000-00-00 00:00:00'),(15007,69,546,0,'0000-00-00 00:00:00'),(15008,69,548,0,'0000-00-00 00:00:00'),(15009,69,297,0,'0000-00-00 00:00:00'),(15010,69,409,0,'0000-00-00 00:00:00'),(15011,69,410,0,'0000-00-00 00:00:00'),(15012,69,411,0,'0000-00-00 00:00:00'),(15013,69,412,0,'0000-00-00 00:00:00'),(15014,69,413,0,'0000-00-00 00:00:00'),(15015,69,414,0,'0000-00-00 00:00:00'),(15016,69,415,0,'0000-00-00 00:00:00'),(15017,69,416,0,'0000-00-00 00:00:00'),(15018,69,400,0,'0000-00-00 00:00:00'),(15019,69,401,0,'0000-00-00 00:00:00'),(15020,69,437,0,'0000-00-00 00:00:00'),(15021,69,438,0,'0000-00-00 00:00:00'),(15022,69,440,0,'0000-00-00 00:00:00'),(15023,69,441,0,'0000-00-00 00:00:00'),(15024,69,427,0,'0000-00-00 00:00:00'),(15025,69,428,0,'0000-00-00 00:00:00'),(15026,69,429,0,'0000-00-00 00:00:00'),(15027,69,430,0,'0000-00-00 00:00:00'),(15028,69,431,0,'0000-00-00 00:00:00'),(15029,69,432,0,'0000-00-00 00:00:00'),(15030,69,433,0,'0000-00-00 00:00:00'),(15031,69,434,0,'0000-00-00 00:00:00'),(15032,69,435,0,'0000-00-00 00:00:00'),(15033,69,443,0,'0000-00-00 00:00:00'),(15034,69,520,0,'0000-00-00 00:00:00'),(15035,69,521,0,'0000-00-00 00:00:00'),(15036,69,522,0,'0000-00-00 00:00:00'),(15037,69,523,0,'0000-00-00 00:00:00'),(15038,69,525,0,'0000-00-00 00:00:00'),(15266,87,124,0,'0000-00-00 00:00:00'),(15267,87,125,0,'0000-00-00 00:00:00'),(15268,87,126,0,'0000-00-00 00:00:00'),(15269,87,127,0,'0000-00-00 00:00:00'),(15270,87,120,0,'0000-00-00 00:00:00'),(15271,87,121,0,'0000-00-00 00:00:00'),(15272,87,122,0,'0000-00-00 00:00:00'),(15273,87,123,0,'0000-00-00 00:00:00'),(15274,87,116,0,'0000-00-00 00:00:00'),(15275,87,117,0,'0000-00-00 00:00:00'),(15276,87,118,0,'0000-00-00 00:00:00'),(15277,87,119,0,'0000-00-00 00:00:00'),(15278,87,274,0,'0000-00-00 00:00:00'),(15279,87,275,0,'0000-00-00 00:00:00'),(15280,87,276,0,'0000-00-00 00:00:00'),(15281,87,277,0,'0000-00-00 00:00:00'),(15282,87,278,0,'0000-00-00 00:00:00'),(15283,87,128,0,'0000-00-00 00:00:00'),(15284,87,129,0,'0000-00-00 00:00:00'),(15285,87,130,0,'0000-00-00 00:00:00'),(15286,87,131,0,'0000-00-00 00:00:00'),(15287,87,175,0,'0000-00-00 00:00:00'),(15288,87,176,0,'0000-00-00 00:00:00'),(15289,87,177,0,'0000-00-00 00:00:00'),(15290,87,178,0,'0000-00-00 00:00:00'),(15291,87,179,0,'0000-00-00 00:00:00'),(15292,87,180,0,'0000-00-00 00:00:00'),(15293,87,132,0,'0000-00-00 00:00:00'),(15294,87,133,0,'0000-00-00 00:00:00'),(15295,87,134,0,'0000-00-00 00:00:00'),(15296,87,181,0,'0000-00-00 00:00:00'),(15297,87,182,0,'0000-00-00 00:00:00'),(15298,87,183,0,'0000-00-00 00:00:00'),(15299,87,184,0,'0000-00-00 00:00:00'),(15300,87,185,0,'0000-00-00 00:00:00'),(15301,87,186,0,'0000-00-00 00:00:00'),(15302,87,135,0,'0000-00-00 00:00:00'),(15303,87,136,0,'0000-00-00 00:00:00'),(15304,87,137,0,'0000-00-00 00:00:00'),(15305,87,172,0,'0000-00-00 00:00:00'),(15306,87,187,0,'0000-00-00 00:00:00'),(15307,87,188,0,'0000-00-00 00:00:00'),(15308,87,189,0,'0000-00-00 00:00:00'),(15309,87,190,0,'0000-00-00 00:00:00'),(15310,87,191,0,'0000-00-00 00:00:00'),(15311,87,192,0,'0000-00-00 00:00:00'),(15312,87,138,0,'0000-00-00 00:00:00'),(15313,87,139,0,'0000-00-00 00:00:00'),(15314,87,140,0,'0000-00-00 00:00:00'),(15315,87,173,0,'0000-00-00 00:00:00'),(15316,87,193,0,'0000-00-00 00:00:00'),(15317,87,194,0,'0000-00-00 00:00:00'),(15318,87,195,0,'0000-00-00 00:00:00'),(15319,87,196,0,'0000-00-00 00:00:00'),(15320,87,197,0,'0000-00-00 00:00:00'),(15321,87,162,0,'0000-00-00 00:00:00'),(15322,87,163,0,'0000-00-00 00:00:00'),(15323,87,164,0,'0000-00-00 00:00:00'),(15324,87,199,0,'0000-00-00 00:00:00'),(15325,87,200,0,'0000-00-00 00:00:00'),(15326,87,201,0,'0000-00-00 00:00:00'),(15327,87,202,0,'0000-00-00 00:00:00'),(15328,87,203,0,'0000-00-00 00:00:00'),(15329,87,204,0,'0000-00-00 00:00:00'),(15330,87,156,0,'0000-00-00 00:00:00'),(15331,87,157,0,'0000-00-00 00:00:00'),(15332,87,158,0,'0000-00-00 00:00:00'),(15333,87,205,0,'0000-00-00 00:00:00'),(15334,87,206,0,'0000-00-00 00:00:00'),(15335,87,207,0,'0000-00-00 00:00:00'),(15336,87,208,0,'0000-00-00 00:00:00'),(15337,87,209,0,'0000-00-00 00:00:00'),(15338,87,210,0,'0000-00-00 00:00:00'),(15339,87,159,0,'0000-00-00 00:00:00'),(15340,87,160,0,'0000-00-00 00:00:00'),(15341,87,161,0,'0000-00-00 00:00:00'),(15342,87,211,0,'0000-00-00 00:00:00'),(15343,87,212,0,'0000-00-00 00:00:00'),(15344,87,213,0,'0000-00-00 00:00:00'),(15345,87,214,0,'0000-00-00 00:00:00'),(15346,87,215,0,'0000-00-00 00:00:00'),(15347,87,216,0,'0000-00-00 00:00:00'),(15348,87,319,0,'0000-00-00 00:00:00'),(15349,87,150,0,'0000-00-00 00:00:00'),(15350,87,145,0,'0000-00-00 00:00:00'),(15351,87,146,0,'0000-00-00 00:00:00'),(15352,87,217,0,'0000-00-00 00:00:00'),(15353,87,218,0,'0000-00-00 00:00:00'),(15354,87,219,0,'0000-00-00 00:00:00'),(15355,87,220,0,'0000-00-00 00:00:00'),(15356,87,221,0,'0000-00-00 00:00:00'),(15357,87,222,0,'0000-00-00 00:00:00'),(15358,87,170,0,'0000-00-00 00:00:00'),(15359,87,171,0,'0000-00-00 00:00:00'),(15360,87,223,0,'0000-00-00 00:00:00'),(15361,87,224,0,'0000-00-00 00:00:00'),(15362,87,225,0,'0000-00-00 00:00:00'),(15363,87,226,0,'0000-00-00 00:00:00'),(15364,87,227,0,'0000-00-00 00:00:00'),(15365,87,228,0,'0000-00-00 00:00:00'),(15366,87,293,0,'0000-00-00 00:00:00'),(15367,87,229,0,'0000-00-00 00:00:00'),(15368,87,285,0,'0000-00-00 00:00:00'),(15369,87,359,0,'0000-00-00 00:00:00'),(15370,87,174,0,'0000-00-00 00:00:00'),(15371,87,298,0,'0000-00-00 00:00:00'),(15372,87,294,0,'0000-00-00 00:00:00'),(15373,87,294,0,'0000-00-00 00:00:00'),(15374,87,294,0,'0000-00-00 00:00:00'),(15375,87,294,0,'0000-00-00 00:00:00'),(15376,87,315,0,'0000-00-00 00:00:00'),(15377,87,315,0,'0000-00-00 00:00:00'),(15378,87,315,0,'0000-00-00 00:00:00'),(15379,87,315,0,'0000-00-00 00:00:00'),(15380,87,317,0,'0000-00-00 00:00:00'),(15796,89,109,0,'0000-00-00 00:00:00'),(15797,89,110,0,'0000-00-00 00:00:00'),(15798,89,111,0,'0000-00-00 00:00:00'),(15799,89,76,0,'0000-00-00 00:00:00'),(15800,89,77,0,'0000-00-00 00:00:00'),(15801,89,107,0,'0000-00-00 00:00:00'),(15802,89,108,0,'0000-00-00 00:00:00'),(15803,89,106,0,'0000-00-00 00:00:00'),(15804,89,112,0,'0000-00-00 00:00:00'),(15805,89,113,0,'0000-00-00 00:00:00'),(15806,89,114,0,'0000-00-00 00:00:00'),(15807,89,115,0,'0000-00-00 00:00:00'),(15808,89,295,0,'0000-00-00 00:00:00'),(15809,89,318,0,'0000-00-00 00:00:00'),(15810,89,120,0,'0000-00-00 00:00:00'),(15811,89,121,0,'0000-00-00 00:00:00'),(15812,89,122,0,'0000-00-00 00:00:00'),(15813,89,123,0,'0000-00-00 00:00:00'),(15814,89,116,0,'0000-00-00 00:00:00'),(15815,89,117,0,'0000-00-00 00:00:00'),(15816,89,118,0,'0000-00-00 00:00:00'),(15817,89,119,0,'0000-00-00 00:00:00'),(15818,89,445,0,'0000-00-00 00:00:00'),(15819,89,446,0,'0000-00-00 00:00:00'),(15820,89,447,0,'0000-00-00 00:00:00'),(15821,89,448,0,'0000-00-00 00:00:00'),(15822,89,274,0,'0000-00-00 00:00:00'),(15823,89,275,0,'0000-00-00 00:00:00'),(15824,89,276,0,'0000-00-00 00:00:00'),(15825,89,277,0,'0000-00-00 00:00:00'),(15826,89,289,0,'0000-00-00 00:00:00'),(15827,89,290,0,'0000-00-00 00:00:00'),(15828,89,291,0,'0000-00-00 00:00:00'),(15829,89,361,0,'0000-00-00 00:00:00'),(15830,89,362,0,'0000-00-00 00:00:00'),(15831,89,364,0,'0000-00-00 00:00:00'),(15832,89,365,0,'0000-00-00 00:00:00'),(15833,89,367,0,'0000-00-00 00:00:00'),(15834,89,368,0,'0000-00-00 00:00:00'),(15835,89,418,0,'0000-00-00 00:00:00'),(15836,89,419,0,'0000-00-00 00:00:00'),(15837,89,135,0,'0000-00-00 00:00:00'),(15838,89,136,0,'0000-00-00 00:00:00'),(15839,89,137,0,'0000-00-00 00:00:00'),(15840,89,172,0,'0000-00-00 00:00:00'),(15841,89,187,0,'0000-00-00 00:00:00'),(15842,89,188,0,'0000-00-00 00:00:00'),(15843,89,190,0,'0000-00-00 00:00:00'),(15844,89,191,0,'0000-00-00 00:00:00'),(15845,89,138,0,'0000-00-00 00:00:00'),(15846,89,139,0,'0000-00-00 00:00:00'),(15847,89,140,0,'0000-00-00 00:00:00'),(15848,89,173,0,'0000-00-00 00:00:00'),(15849,89,193,0,'0000-00-00 00:00:00'),(15850,89,194,0,'0000-00-00 00:00:00'),(15851,89,196,0,'0000-00-00 00:00:00'),(15852,89,197,0,'0000-00-00 00:00:00'),(15853,89,162,0,'0000-00-00 00:00:00'),(15854,89,163,0,'0000-00-00 00:00:00'),(15855,89,164,0,'0000-00-00 00:00:00'),(15856,89,199,0,'0000-00-00 00:00:00'),(15857,89,200,0,'0000-00-00 00:00:00'),(15858,89,202,0,'0000-00-00 00:00:00'),(15859,89,203,0,'0000-00-00 00:00:00'),(15860,89,319,0,'0000-00-00 00:00:00'),(15861,89,320,0,'0000-00-00 00:00:00'),(15862,89,321,0,'0000-00-00 00:00:00'),(15863,89,322,0,'0000-00-00 00:00:00'),(15864,89,323,0,'0000-00-00 00:00:00'),(15865,89,324,0,'0000-00-00 00:00:00'),(15866,89,326,0,'0000-00-00 00:00:00'),(15867,89,327,0,'0000-00-00 00:00:00'),(15868,89,328,0,'0000-00-00 00:00:00'),(15869,89,331,0,'0000-00-00 00:00:00'),(15870,89,332,0,'0000-00-00 00:00:00'),(15871,89,333,0,'0000-00-00 00:00:00'),(15872,89,334,0,'0000-00-00 00:00:00'),(15873,89,335,0,'0000-00-00 00:00:00'),(15874,89,337,0,'0000-00-00 00:00:00'),(15875,89,338,0,'0000-00-00 00:00:00'),(15876,89,339,0,'0000-00-00 00:00:00'),(15877,89,381,0,'0000-00-00 00:00:00'),(15878,89,382,0,'0000-00-00 00:00:00'),(15879,89,383,0,'0000-00-00 00:00:00'),(15880,89,384,0,'0000-00-00 00:00:00'),(15881,89,385,0,'0000-00-00 00:00:00'),(15882,89,387,0,'0000-00-00 00:00:00'),(15883,89,388,0,'0000-00-00 00:00:00'),(15884,89,390,0,'0000-00-00 00:00:00'),(15885,89,141,0,'0000-00-00 00:00:00'),(15886,89,142,0,'0000-00-00 00:00:00'),(15887,89,143,0,'0000-00-00 00:00:00'),(15888,89,293,0,'0000-00-00 00:00:00'),(15889,89,154,0,'0000-00-00 00:00:00'),(15890,89,155,0,'0000-00-00 00:00:00'),(15891,89,229,0,'0000-00-00 00:00:00'),(15892,89,230,0,'0000-00-00 00:00:00'),(15893,89,232,0,'0000-00-00 00:00:00'),(15894,89,233,0,'0000-00-00 00:00:00'),(15895,89,234,0,'0000-00-00 00:00:00'),(15896,89,281,0,'0000-00-00 00:00:00'),(15897,89,359,0,'0000-00-00 00:00:00'),(15898,89,378,0,'0000-00-00 00:00:00'),(15899,89,444,0,'0000-00-00 00:00:00'),(15900,89,314,0,'0000-00-00 00:00:00'),(15901,89,174,0,'0000-00-00 00:00:00'),(15902,89,242,0,'0000-00-00 00:00:00'),(15903,89,243,0,'0000-00-00 00:00:00'),(15904,89,244,0,'0000-00-00 00:00:00'),(15905,89,249,0,'0000-00-00 00:00:00'),(15906,89,250,0,'0000-00-00 00:00:00'),(15907,89,251,0,'0000-00-00 00:00:00'),(15908,89,252,0,'0000-00-00 00:00:00'),(15909,89,253,0,'0000-00-00 00:00:00'),(15910,89,254,0,'0000-00-00 00:00:00'),(15911,89,256,0,'0000-00-00 00:00:00'),(15912,89,257,0,'0000-00-00 00:00:00'),(15913,89,540,0,'0000-00-00 00:00:00'),(15914,89,541,0,'0000-00-00 00:00:00'),(15915,89,542,0,'0000-00-00 00:00:00'),(15916,89,545,0,'0000-00-00 00:00:00'),(15917,89,548,0,'0000-00-00 00:00:00'),(15918,89,297,0,'0000-00-00 00:00:00'),(15919,89,409,0,'0000-00-00 00:00:00'),(15920,89,410,0,'0000-00-00 00:00:00'),(15921,89,411,0,'0000-00-00 00:00:00'),(15922,89,412,0,'0000-00-00 00:00:00'),(15923,89,413,0,'0000-00-00 00:00:00'),(15924,89,414,0,'0000-00-00 00:00:00'),(15925,89,415,0,'0000-00-00 00:00:00'),(15926,89,416,0,'0000-00-00 00:00:00'),(15927,89,400,0,'0000-00-00 00:00:00'),(15928,89,401,0,'0000-00-00 00:00:00'),(15929,89,437,0,'0000-00-00 00:00:00'),(15930,89,438,0,'0000-00-00 00:00:00'),(15931,89,440,0,'0000-00-00 00:00:00'),(15932,89,441,0,'0000-00-00 00:00:00'),(15933,89,427,0,'0000-00-00 00:00:00'),(15934,89,428,0,'0000-00-00 00:00:00'),(15935,89,429,0,'0000-00-00 00:00:00'),(15936,89,430,0,'0000-00-00 00:00:00'),(15937,89,431,0,'0000-00-00 00:00:00'),(15938,89,432,0,'0000-00-00 00:00:00'),(15939,89,433,0,'0000-00-00 00:00:00'),(15940,89,434,0,'0000-00-00 00:00:00'),(15941,89,435,0,'0000-00-00 00:00:00'),(15942,89,443,0,'0000-00-00 00:00:00'),(15943,89,520,0,'0000-00-00 00:00:00'),(15944,89,521,0,'0000-00-00 00:00:00'),(15945,89,522,0,'0000-00-00 00:00:00'),(15946,89,523,0,'0000-00-00 00:00:00'),(15947,89,525,0,'0000-00-00 00:00:00');

--
-- Table structure for table `tbl_user_groups`
--

CREATE TABLE `tbl_user_groups` (
  `user_group_Id` int NOT NULL AUTO_INCREMENT,
  `user_group_name` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `create_user_Id` int NOT NULL,
  `create_datetime` datetime NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`user_group_Id`)
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_user_groups`
--

INSERT INTO `tbl_user_groups` VALUES (69,'systemAdmin','System administrator',77,'2026-01-26 14:15:11',0,1),(87,'Stock Manager','Company Management team',109,'2026-01-27 16:09:51',0,1),(88,'Sales officer','sales officers',77,'2024-05-08 16:41:09',0,1),(89,'Office users','Office users',109,'2026-01-30 10:08:57',0,1);

--
-- Table structure for table `tbl_user_groups_reports`
--

CREATE TABLE `tbl_user_groups_reports` (
  `id` int NOT NULL AUTO_INCREMENT,
  `group_id` int NOT NULL,
  `report_id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1342 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_user_groups_reports`
--

INSERT INTO `tbl_user_groups_reports` VALUES (16,76,1),(41,81,4),(42,81,3),(43,81,2),(44,81,1),(45,82,1),(46,82,2),(47,82,3),(48,82,4),(49,83,1),(50,83,2),(51,83,3),(52,83,4),(54,84,3),(55,85,1),(56,85,2),(57,85,3),(58,85,4),(59,86,1),(60,86,2),(61,86,3),(62,86,4),(63,80,4),(64,80,3),(65,80,2),(66,80,1),(534,88,20),(1284,69,21),(1285,69,22),(1286,69,23),(1287,69,24),(1288,69,1),(1289,69,20),(1290,69,16),(1291,69,17),(1292,69,5),(1293,69,4),(1294,69,2),(1295,69,3),(1296,69,8),(1297,69,25),(1298,69,9),(1299,69,6),(1300,69,7),(1301,69,19),(1302,69,14),(1303,69,12),(1304,69,11),(1305,69,10),(1306,69,15),(1307,69,13),(1308,69,27),(1309,69,26),(1314,87,8),(1315,87,5),(1316,89,21),(1317,89,22),(1318,89,23),(1319,89,24),(1320,89,1),(1321,89,20),(1322,89,16),(1323,89,17),(1324,89,5),(1325,89,4),(1326,89,2),(1327,89,3),(1328,89,8),(1329,89,25),(1330,89,9),(1331,89,6),(1332,89,7),(1333,89,19),(1334,89,14),(1335,89,12),(1336,89,11),(1337,89,10),(1338,89,15),(1339,89,13),(1340,89,27),(1341,89,26);

--
-- Table structure for table `tbl_user_guide`
--

CREATE TABLE `tbl_user_guide` (
  `id` int NOT NULL AUTO_INCREMENT,
  `type` varchar(500) NOT NULL,
  `element` varchar(500) NOT NULL,
  `content` text NOT NULL,
  `position` varchar(500) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_user_guide`
--


--
-- Table structure for table `tbl_user_logins`
--

CREATE TABLE `tbl_user_logins` (
  `id` int NOT NULL AUTO_INCREMENT,
  `login_id` int DEFAULT NULL,
  `login_date_time` datetime DEFAULT NULL,
  `user_name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_user_logins`
--

INSERT INTO `tbl_user_logins` VALUES (1,109,'2026-02-24 10:30:48','nbit');

--
-- Table structure for table `tbl_user_rights`
--

CREATE TABLE `tbl_user_rights` (
  `user_right_Id` int NOT NULL AUTO_INCREMENT,
  `user_right_name` varchar(255) NOT NULL,
  `create_user_Id` int NOT NULL,
  `create_datetime` datetime NOT NULL,
  `user_right_code` varchar(255) DEFAULT NULL,
  `menu_order` decimal(11,2) NOT NULL DEFAULT '0.00',
  `main_menu_name` varchar(225) DEFAULT NULL,
  `main_menu_code` varchar(45) DEFAULT NULL,
  `page_path` varchar(5000) DEFAULT NULL,
  `main_menu_id` int DEFAULT NULL,
  `sub_menu_id` decimal(13,2) DEFAULT NULL,
  `main_menu_icon` varchar(500) DEFAULT NULL,
  `right_type` varchar(50) NOT NULL,
  `second_level` varchar(50) NOT NULL,
  `permission_order` int NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `target` varchar(100) NOT NULL DEFAULT '_parent',
  PRIMARY KEY (`user_right_Id`)
) ENGINE=InnoDB AUTO_INCREMENT=562 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_user_rights`
--

INSERT INTO `tbl_user_rights` VALUES (24,'User Groups',0,'0000-00-00 00:00:00','User_Groups',1.00,'User Managment','user','user-groups',2,1.00,'fa fa-users','','',1,1,'_parent'),(25,'Users',0,'0000-00-00 00:00:00','User_roles',1.00,'User Managment','user','users',2,2.00,'fa fa-users','','',1,1,'_parent'),(76,'Is create available',0,'0000-00-00 00:00:00','is_createusers',1.00,'User Managment','user','',0,2.00,'','other_right','',2,1,'_parent'),(77,'Is reset password',0,'0000-00-00 00:00:00','is_resetPasswordusers',1.00,'User Managment','user','',0,2.00,'','other_right','',3,1,'_parent'),(96,'Company Setup',77,'2000-01-01 00:00:00','company_setup',2.00,'Tools','tools','company',9,1.00,'fa fa-wrench',' ','',0,1,'_parent'),(102,'Branch',77,'2000-01-01 00:00:00','branch',2.00,'Tools','tools','branch',9,1.10,'fa fa-wrench',' ','',1,1,'_parent'),(103,'Is delete available',77,'2000-01-01 00:00:00','is_deletebranch',2.00,'Tools','tools','',0,1.10,NULL,'other_right','',2,1,'_parent'),(104,'Is edit available',77,'2000-01-01 00:00:00','is_editbranch',2.00,'Tools','tools','',0,1.10,NULL,'other_right','',3,1,'_parent'),(105,'Is create available',77,'2000-01-01 00:00:00','is_createbranch',2.00,'Tools','tools','',0,1.10,NULL,'other_right','',4,1,'_parent'),(106,'Dashboard',0,'0000-00-00 00:00:00','dashboard',100.00,'Dashboard','dashboard','dashboard',1,1.00,'fa fa-dashboard','single_menu','',0,1,'_parent'),(107,'Is edit available',0,'0000-00-00 00:00:00','is_editusers',1.00,'User Managment','user','',0,2.00,'','other_right','',4,1,'_parent'),(108,'Is delete available',0,'0000-00-00 00:00:00','is_deleteusers',1.00,'User Managment','user','',0,2.00,'','other_right','',5,1,'_parent'),(109,'Is delete available',0,'0000-00-00 00:00:00','is_deleteuser-groups',1.00,'User Managment','user','',0,1.00,'0','other_right','',2,1,'_parent'),(110,'Is edit available',0,'0000-00-00 00:00:00','is_edituser-groups',1.00,'User Managment','user','',0,1.00,'0','other_right','',3,1,'_parent'),(111,'Is create available',0,'0000-00-00 00:00:00','is_createuser-groups',1.00,'User Managment','user','',0,1.00,'0','other_right','',4,1,'_parent'),(112,'Customers List',77,'2000-01-01 00:00:00','customer',11.00,'Customers','customer','customer',17,1.00,'fa fa-user',' ','',1,1,'_parent'),(113,'Is delete available',77,'2000-01-01 00:00:00','is_deletecustomer',11.00,'Customers','customer','',0,1.00,NULL,'other_right','',2,1,'_parent'),(114,'Is edit available',77,'2000-01-01 00:00:00','is_editcustomer',11.00,'Customers','customer','',0,1.00,NULL,'other_right','',3,1,'_parent'),(115,'Is create available',77,'2000-01-01 00:00:00','is_createcustomer',11.00,'Customers','customer','',0,1.00,NULL,'other_right','',4,1,'_parent'),(116,'Product category',77,'2000-01-01 00:00:00','product_category',5.00,'Master','master','product-category',10,2.00,'fa fa-cogs',' ','',1,1,'_parent'),(117,'Is create available',77,'2000-01-01 00:00:00','is_createproduct-category',5.00,'Master','master','',0,2.00,NULL,'other_right','',2,1,'_parent'),(118,'Is edit available',77,'2000-01-01 00:00:00','is_editproduct-category',5.00,'Master','master','',0,2.00,NULL,'other_right','',3,1,'_parent'),(119,'Is delete available',77,'2000-01-01 00:00:00','is_deleteproduct-category',5.00,'Master','master','',0,2.00,NULL,'other_right','',4,1,'_parent'),(120,'Product',77,'2000-01-01 00:00:00','product',5.00,'Master','master','product',10,1.90,'fa fa-cogs',' ','',1,1,'_parent'),(121,'Is create available',77,'2000-01-01 00:00:00','is_createproduct',5.00,'Master','master','',0,1.90,NULL,'other_right','',2,1,'_parent'),(122,'Is edit available',77,'2000-01-01 00:00:00','is_editproduct',5.00,'Master','master','',0,1.90,NULL,'other_right','',3,1,'_parent'),(123,'Is delete available',77,'2000-01-01 00:00:00','is_deleteproduct',5.00,'Master','master','',0,1.90,NULL,'other_right','',4,1,'_parent'),(124,'BOQ',77,'2000-01-01 00:00:00','boq',5.00,'Master','master','boq',10,1.80,'fa fa-cogs',' ','',1,1,'_parent'),(125,'Is create available',77,'2000-01-01 00:00:00','is_createboq',5.00,'Master','master','',0,1.80,NULL,'other_right','',2,1,'_parent'),(126,'Is edit available',77,'2000-01-01 00:00:00','is_editboq',5.00,'Master','master','',0,1.80,NULL,'other_right','',3,1,'_parent'),(127,'Is delete available',77,'2000-01-01 00:00:00','is_deleteboq',5.00,'Master','master','',0,1.80,NULL,'other_right','',4,1,'_parent'),(128,'Contract',77,'2000-01-01 00:00:00','contract',5.10,'Transaction','transaction','contract',11,1.00,'fa fa-credit-card',' ','',1,1,'_parent'),(129,'Is create available',77,'2000-01-01 00:00:00','is_createcontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',2,1,'_parent'),(130,'Is edit available',77,'2000-01-01 00:00:00','is_editcontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',3,1,'_parent'),(131,'Is delete available',77,'2000-01-01 00:00:00','is_deletecontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',4,1,'_parent'),(132,'PRN',77,'2000-01-01 00:00:00','prn',5.10,'Transaction','transaction','prns',11,2.00,'fa fa-credit-card',' ','',1,1,'_parent'),(133,'Is create available',77,'2000-01-01 00:00:00','is_createprns',5.10,'Transaction','transaction','',0,2.00,NULL,'other_right','',2,1,'_parent'),(134,'Is edit available',77,'2000-01-01 00:00:00','is_editprns',5.10,'Transaction','transaction','',0,2.00,NULL,'other_right','',3,1,'_parent'),(135,'PO',77,'2000-01-01 00:00:00','po',5.10,'Transaction','transaction','po',11,3.00,'fa fa-credit-card',' ','',1,1,'_parent'),(136,'Is create available',77,'2000-01-01 00:00:00','is_createpo',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',2,1,'_parent'),(137,'Is edit available',77,'2000-01-01 00:00:00','is_editpo',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',3,1,'_parent'),(138,'GRN',77,'2000-01-01 00:00:00','grn',5.10,'Transaction','transaction','grn',11,4.00,'fa fa-credit-card',' ','',1,1,'_parent'),(139,'Is create available',77,'2000-01-01 00:00:00','is_creategrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',2,1,'_parent'),(140,'Is edit available',77,'2000-01-01 00:00:00','is_editgrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',3,1,'_parent'),(141,'Supplier List',77,'2000-01-01 00:00:00','supplier',10.00,'Suppliers','supplier','supplier',19,1.70,'fa fa-male',' ','',1,1,'_parent'),(142,'Is create available',77,'2000-01-01 00:00:00','is_createsupplier',10.00,'Suppliers','supplier','',0,1.70,NULL,'other_right','',2,1,'_parent'),(143,'Is edit available',77,'2000-01-01 00:00:00','is_editsupplier',10.00,'Suppliers','supplier','',0,1.70,NULL,'other_right','',3,1,'_parent'),(144,'MRN',77,'2000-01-01 00:00:00','mrn',5.20,'Production','production','mrn',12,2.00,'fa fa-gear',' ','',1,1,'_parent'),(145,'Is create available',77,'2000-01-01 00:00:00','is_createmrn',5.20,'Production','production','',0,2.00,NULL,'other_right','',2,1,'_parent'),(146,'Is edit available',77,'2000-01-01 00:00:00','is_editmrn',5.20,'Production','production','',0,2.00,NULL,'other_right','',3,1,'_parent'),(149,'Production plan',77,'2000-01-01 00:00:00','production_plan',5.20,'Production','production','production-plan',12,1.00,'fa fa-gear',' ','',1,1,'_parent'),(150,'Is create available',77,'2000-01-01 00:00:00','is_createproduction-plan',5.20,'Production','production','',0,1.00,NULL,'other_right','',2,1,'_parent'),(151,'Is edit available',77,'2000-01-01 00:00:00','is_editproduction-plan',5.20,'Production','production','',0,1.00,NULL,'other_right','',3,1,'_parent'),(152,'Is delete available',77,'2000-01-01 00:00:00','is_deleteproduction-plan',5.20,'Production','production','',0,1.00,NULL,'other_right','',4,1,'_parent'),(153,'Sales order',77,'2000-01-01 00:00:00','sales_order',9.00,'Sales','sales','sales-order',13,1.00,'fa fa-book',' ','',1,1,'_parent'),(154,'Is create available',77,'2000-01-01 00:00:00','is_createsales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',2,1,'_parent'),(155,'Is edit available',77,'2000-01-01 00:00:00','is_editsales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',3,1,'_parent'),(156,'Issue samples',77,'2000-01-01 00:00:00','issue_samples',5.10,'Transaction','transaction','samples',11,5.00,'fa fa-credit-card',' ','',1,1,'_parent'),(157,'Is create available',77,'2000-01-01 00:00:00','is_createsamples',5.10,'Transaction','transaction','',0,5.00,NULL,'other_right','',2,1,'_parent'),(158,'Is edit available',77,'2000-01-01 00:00:00','is_editsamples',5.10,'Transaction','transaction','',0,5.00,NULL,'other_right','',3,1,'_parent'),(159,'Damage',77,'2000-01-01 00:00:00','damage',5.10,'Transaction','transaction','damage',11,6.00,'fa fa-credit-card',' ','',1,1,'_parent'),(160,'Is create available',77,'2000-01-01 00:00:00','is_createdamage',5.10,'Transaction','transaction','',0,6.00,NULL,'other_right','',2,1,'_parent'),(161,'Is edit available',77,'2000-01-01 00:00:00','is_editdamage',5.10,'Transaction','transaction','',0,6.00,NULL,'other_right','',3,1,'_parent'),(162,'Supplier returns',77,'2000-01-01 00:00:00','grn_return',5.10,'Transaction','transaction','grn-returns',11,4.10,'fa fa-credit-card',' ','',1,1,'_parent'),(163,'Is create available',77,'2000-01-01 00:00:00','is_creategrn-returns',5.10,'Transaction','transaction','',0,4.10,NULL,'other_right','',2,1,'_parent'),(164,'Is edit available',77,'2000-01-01 00:00:00','is_editgrn-returns',5.10,'Transaction','transaction','',0,4.10,NULL,'other_right','',3,1,'_parent'),(165,'Dispatch',77,'2000-01-01 00:00:00','dispatch',9.00,'Sales','sales','dispatch',13,2.00,'fa fa-book',' ','',1,1,'_parent'),(166,'Is create available',77,'2000-01-01 00:00:00','is_createdispatch',9.00,'Sales','sales','',0,2.00,NULL,'other_right','',2,1,'_parent'),(167,'Is edit available',77,'2000-01-01 00:00:00','is_editdispatch',9.00,'Sales','sales','',0,2.00,NULL,'other_right','',3,1,'_parent'),(169,'MRN Issue',77,'2000-01-01 00:00:00','mrn_issue',5.20,'Production','production','mrn-issue',12,3.00,'fa fa-gear',' ','',1,1,'_parent'),(170,'Is create available',77,'2000-01-01 00:00:00','is_createmrn-issue',5.20,'Production','production','',0,3.00,NULL,'other_right','',2,1,'_parent'),(171,'Is edit available',77,'2000-01-01 00:00:00','is_editmrn-issue',5.20,'Production','production','',0,3.00,NULL,'other_right','',3,1,'_parent'),(172,'Show Rpt Values',77,'2000-01-01 00:00:00','show_rpt_values',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',4,1,'_parent'),(173,'Show GRN Rpt Values',77,'2000-01-01 00:00:00','show_grn_rpt_values',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',4,1,'_parent'),(174,'Reports',77,'2000-01-01 00:00:00','reports',4.00,'Reports','report','reports',1000,1.00,'fa fa-clipboard','single_menu','',1,1,'_parent'),(175,'Is print available',77,'2000-01-01 00:00:00','is_printcontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',5,1,'_parent'),(176,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelcontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',6,1,'_parent'),(177,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedcontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',7,1,'_parent'),(178,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedcontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',8,1,'_parent'),(179,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedcontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',9,1,'_parent'),(180,'Is re-open available',77,'2000-01-01 00:00:00','is_reopencontract',5.10,'Transaction','transaction','',0,1.00,NULL,'other_right','',10,1,'_parent'),(181,'Is print available',77,'2000-01-01 00:00:00','is_printprns',5.10,'Transaction','transaction','',0,2.00,NULL,'other_right','',5,1,'_parent'),(182,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelprns',5.10,'Transaction','transaction','',0,2.00,NULL,'other_right','',6,1,'_parent'),(183,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedprns',5.10,'Transaction','transaction','',0,2.00,NULL,'other_right','',7,1,'_parent'),(184,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedprns',5.10,'Transaction','transaction','',0,2.00,NULL,'other_right','',8,1,'_parent'),(185,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedprns',5.10,'Transaction','transaction','',0,2.00,NULL,'other_right','',9,1,'_parent'),(186,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenprns',5.10,'Transaction','transaction','',0,2.00,NULL,'other_right','',10,1,'_parent'),(187,'Is print available',77,'2000-01-01 00:00:00','is_printpo',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',5,1,'_parent'),(188,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelpo',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',6,1,'_parent'),(189,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedpo',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',7,1,'_parent'),(190,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedpo',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',8,1,'_parent'),(191,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedpo',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',9,1,'_parent'),(192,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenpo',5.10,'Transaction','transaction','',0,3.00,NULL,'other_right','',10,1,'_parent'),(193,'Is print available',77,'2000-01-01 00:00:00','is_printgrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',5,1,'_parent'),(194,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelgrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',6,1,'_parent'),(195,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedgrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',7,1,'_parent'),(196,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedgrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',8,1,'_parent'),(197,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedgrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',9,1,'_parent'),(198,'Is re-open available',77,'2000-01-01 00:00:00','is_reopengrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',10,1,'_parent'),(199,'Is print available',77,'2000-01-01 00:00:00','is_printgrn-returns',5.10,'Transaction','transaction','',0,4.10,NULL,'other_right','',5,1,'_parent'),(200,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelgrn-returns',5.10,'Transaction','transaction','',0,4.10,NULL,'other_right','',6,1,'_parent'),(201,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedgrn-returns',5.10,'Transaction','transaction','',0,4.10,NULL,'other_right','',7,1,'_parent'),(202,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedgrn-returns',5.10,'Transaction','transaction','',0,4.10,NULL,'other_right','',8,1,'_parent'),(203,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedgrn-returns',5.10,'Transaction','transaction','',0,4.10,NULL,'other_right','',9,1,'_parent'),(204,'Is re-open available',77,'2000-01-01 00:00:00','is_reopengrn-returns',5.10,'Transaction','transaction','',0,4.10,NULL,'other_right','',10,1,'_parent'),(205,'Is print available',77,'2000-01-01 00:00:00','is_printsamples',5.10,'Transaction','transaction','',0,5.00,NULL,'other_right','',5,1,'_parent'),(206,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelsamples',5.10,'Transaction','transaction','',0,5.00,NULL,'other_right','',6,1,'_parent'),(207,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedsamples',5.10,'Transaction','transaction','',0,5.00,NULL,'other_right','',7,1,'_parent'),(208,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedsamples',5.10,'Transaction','transaction','',0,5.00,NULL,'other_right','',8,1,'_parent'),(209,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedsamples',5.10,'Transaction','transaction','',0,5.00,NULL,'other_right','',9,1,'_parent'),(210,'Is re-open available',77,'2000-01-01 00:00:00','is_reopensamples',5.10,'Transaction','transaction','',0,5.00,NULL,'other_right','',10,1,'_parent'),(211,'Is print available',77,'2000-01-01 00:00:00','is_printdamage',5.10,'Transaction','transaction','',0,6.00,NULL,'other_right','',5,1,'_parent'),(212,'Is cancel available',77,'2000-01-01 00:00:00','is_canceldamage',5.10,'Transaction','transaction','',0,6.00,NULL,'other_right','',6,1,'_parent'),(213,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizeddamage',5.10,'Transaction','transaction','',0,6.00,NULL,'other_right','',7,1,'_parent'),(214,'Is rejected available',77,'2000-01-01 00:00:00','is_rejecteddamage',5.10,'Transaction','transaction','',0,6.00,NULL,'other_right','',8,1,'_parent'),(215,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizeddamage',5.10,'Transaction','transaction','',0,6.00,NULL,'other_right','',9,1,'_parent'),(216,'Is re-open available',77,'2000-01-01 00:00:00','is_reopendamage',5.10,'Transaction','transaction','',0,6.00,NULL,'other_right','',10,1,'_parent'),(217,'Is print available',77,'2000-01-01 00:00:00','is_printmrn',5.20,'Production','production','',0,2.00,NULL,'other_right','',5,1,'_parent'),(218,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelmrn',5.20,'Production','production','',0,2.00,NULL,'other_right','',6,1,'_parent'),(219,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedmrn',5.20,'Production','production','',0,2.00,NULL,'other_right','',7,1,'_parent'),(220,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedmrn',5.20,'Production','production','',0,2.00,NULL,'other_right','',8,1,'_parent'),(221,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedmrn',5.20,'Production','production','',0,2.00,NULL,'other_right','',9,1,'_parent'),(222,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenmrn',5.20,'Production','production','',0,2.00,NULL,'other_right','',10,1,'_parent'),(223,'Is print available',77,'2000-01-01 00:00:00','is_printmrn-issue',5.20,'Production','production','',0,3.00,NULL,'other_right','',5,1,'_parent'),(224,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelmrn-issue',5.20,'Production','production','',0,3.00,NULL,'other_right','',6,1,'_parent'),(225,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedmrn-issue',5.20,'Production','production','',0,3.00,NULL,'other_right','',7,1,'_parent'),(226,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedmrn-issue',5.20,'Production','production','',0,3.00,NULL,'other_right','',8,1,'_parent'),(227,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedmrn-issue',5.20,'Production','production','',0,3.00,NULL,'other_right','',9,1,'_parent'),(228,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenmrn-issue',5.20,'Production','production','',0,3.00,NULL,'other_right','',10,1,'_parent'),(229,'Is print available',77,'2000-01-01 00:00:00','is_printsales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',5,1,'_parent'),(230,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelsales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',6,1,'_parent'),(231,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedsales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',7,1,'_parent'),(232,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedsales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',8,1,'_parent'),(233,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedsales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',9,1,'_parent'),(234,'Is re-open available',77,'2000-01-01 00:00:00','is_reopensales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',10,1,'_parent'),(235,'Is print available',77,'2000-01-01 00:00:00','is_printdispatch',9.00,'Sales','sales','',0,2.00,NULL,'other_right','',5,1,'_parent'),(236,'Is cancel available',77,'2000-01-01 00:00:00','is_canceldispatch',9.00,'Sales','sales','',0,2.00,NULL,'other_right','',6,1,'_parent'),(237,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizeddispatch',9.00,'Sales','sales','',0,2.00,NULL,'other_right','',7,1,'_parent'),(238,'Is rejected available',77,'2000-01-01 00:00:00','is_rejecteddispatch',9.00,'Sales','sales','',0,2.00,NULL,'other_right','',8,1,'_parent'),(239,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizeddispatch',9.00,'Sales','sales','',0,2.00,NULL,'other_right','',9,1,'_parent'),(240,'Is re-open available',77,'2000-01-01 00:00:00','is_reopendispatch',9.00,'Sales','sales','',0,2.00,NULL,'other_right','',10,1,'_parent'),(241,'Meta Data Fields',77,'2000-01-01 00:00:00','meta',2.00,'Admin','admin','meta',14,14.10,'glyphicon glyphicon-user',' ','',1,1,'_parent'),(242,'Is delete available',77,'2000-01-01 00:00:00','is_deletemeta',2.00,'Admin','admin','',0,14.10,NULL,'other_right','',2,1,'_parent'),(243,'Is edit available',77,'2000-01-01 00:00:00','is_editmeta',2.00,'Admin','admin','',0,14.10,NULL,'other_right','',3,1,'_parent'),(244,'Is create available',77,'2000-01-01 00:00:00','is_createmeta',2.00,'Admin','admin','',0,14.10,NULL,'other_right','',4,1,'_parent'),(249,'Supplier payments',77,'2000-01-01 00:00:00','supplier_payments',6.00,'Payments','Payments','supplier-payments',15,1.00,'fa fa-money',' ','',1,1,'_parent'),(250,'Is create available',77,'2000-01-01 00:00:00','is_createsupplier-payments',6.00,'Payments','Payments','',0,1.00,NULL,'other_right','',2,1,'_parent'),(251,'Is edit available',77,'2000-01-01 00:00:00','is_editsupplier-payments',6.00,'Payments','Payments','',0,1.00,NULL,'other_right','',3,1,'_parent'),(252,'Is delete available',0,'2000-01-01 00:00:00','is_deletesupplier-payments',6.00,'Payments','Payments','',0,1.00,'0','other_right','',4,1,'_parent'),(253,'Is print available',77,'2000-01-01 00:00:00','is_printsupplier-payments',6.00,'Payments','Payments','',0,1.00,NULL,'other_right','',5,1,'_parent'),(254,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelsupplier-payments',6.00,'Payments','Payments','',0,1.00,NULL,'other_right','',6,1,'_parent'),(255,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedsupplier-payments',6.00,'Payments','Payments','',0,1.00,NULL,'other_right','',7,1,'_parent'),(256,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedsupplier-payments',6.00,'Payments','Payments','',0,1.00,NULL,'other_right','',8,1,'_parent'),(257,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedsupplier-payments',6.00,'Payments','Payments','',0,1.00,NULL,'other_right','',9,1,'_parent'),(258,'Is re-open available',77,'2000-01-01 00:00:00','is_reopensupplier-payments',6.00,'Payments','Payments','',0,1.00,NULL,'other_right','',10,1,'_parent'),(259,'Customer payments',77,'2000-01-01 00:00:00','customer_payments',6.00,'Payments','Payments','customer-payments',15,2.00,'fa fa-money',' ','',1,1,'_parent'),(260,'Is create available',77,'2000-01-01 00:00:00','is_createcustomer-payments',6.00,'Payments','Payments','',0,2.00,NULL,'other_right','',2,1,'_parent'),(261,'Is edit available',77,'2000-01-01 00:00:00','is_editcustomer-payments',6.00,'Payments','Payments','',0,2.00,NULL,'other_right','',3,1,'_parent'),(262,'Is delete available',0,'2000-01-01 00:00:00','is_deletecustomer-payments',6.00,'Payments','Payments','',0,2.00,'0','other_right','',4,1,'_parent'),(263,'Is print available',77,'2000-01-01 00:00:00','is_printcustomer-payments',6.00,'Payments','Payments','',0,2.00,NULL,'other_right','',5,1,'_parent'),(264,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelcustomer-payments',6.00,'Payments','Payments','',0,2.00,NULL,'other_right','',6,1,'_parent'),(265,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedcustomer-payments',6.00,'Payments','Payments','',0,2.00,NULL,'other_right','',7,1,'_parent'),(266,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedcustomer-payments',6.00,'Payments','Payments','',0,2.00,NULL,'other_right','',8,1,'_parent'),(267,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedcustomer-payments',6.00,'Payments','Payments','',0,2.00,NULL,'other_right','',9,1,'_parent'),(268,'Is re-open available',77,'2000-01-01 00:00:00','is_reopencustomer-payments',6.00,'Payments','Payments','',0,2.00,NULL,'other_right','',10,1,'_parent'),(269,'Call Log',77,'2000-01-01 00:00:00','call_log',5.30,'CRM','crm','call-log',16,6.00,'glyphicon glyphicon-phone-alt',' ','',1,1,'_parent'),(270,'Is delete available',77,'2000-01-01 00:00:00','is_deletecall-log',5.30,'CRM','crm','',16,6.00,NULL,'other_right','',2,1,'_parent'),(271,'Is edit available',77,'2000-01-01 00:00:00','is_editcall-log',5.30,'CRM','crm','',16,6.00,NULL,'other_right','',3,1,'_parent'),(272,'Is create available',77,'2000-01-01 00:00:00','is_createcall-log',5.30,'CRM','crm','',16,6.00,NULL,'other_right','',4,1,'_parent'),(273,'Reminder calender',77,'2000-01-01 00:00:00','reminder_calender',5.30,'CRM','crm','reminder',16,6.20,'glyphicon glyphicon-phone-alt','','',5,1,'_parent'),(274,'Product brands',77,'2000-01-01 00:00:00','product_brands',5.00,'Master','master','product-brands',10,3.00,'fa fa-cogs',' ','',1,1,'_parent'),(275,'Is create available',77,'2000-01-01 00:00:00','is_createproduct-brands',5.00,'Master','master','',0,3.00,NULL,'other_right','',2,1,'_parent'),(276,'Is edit available',77,'2000-01-01 00:00:00','is_editproduct-brands',5.00,'Master','master','',0,3.00,NULL,'other_right','',3,1,'_parent'),(277,'Is delete available',0,'2000-01-01 00:00:00','is_deleteproduct-brands',5.00,'Master','master','',0,3.00,'0','other_right','',4,1,'_parent'),(278,'Product search',77,'2000-01-01 00:00:00','product_search',5.00,'Master','master','product-search',10,4.00,'fa fa-cogs',' ','',1,1,'_parent'),(279,'Sales invoice',77,'2000-01-01 00:00:00','sale_invoice',9.00,'Sales','sales','sales-invoice',13,3.00,'fa fa-book',' ','',1,1,'_parent'),(280,'Is create available',77,'2000-01-01 00:00:00','is_createsales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',2,1,'_parent'),(281,'Is edit available',77,'2000-01-01 00:00:00','is_editsales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',3,1,'_parent'),(282,'Is delete available',0,'2000-01-01 00:00:00','is_deletesales-invoice',9.00,'Sales','sales','',0,3.00,'0','other_right','',4,1,'_parent'),(283,'Is print available',77,'2000-01-01 00:00:00','is_printsales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',5,1,'_parent'),(284,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelsales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',6,1,'_parent'),(285,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedsales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',7,1,'_parent'),(286,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedsales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',8,1,'_parent'),(287,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedsales-invoice',9.00,'sales','sales','',0,3.00,NULL,'other_right','',9,1,'_parent'),(288,'Is re-open available',77,'2000-01-01 00:00:00','is_reopensales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',10,1,'_parent'),(289,'Bank Accounts',77,'2000-01-01 00:00:00','bank_accounts',5.00,'Master','master','bank-accounts',10,5.00,'fa fa-cogs',' ','',1,1,'_parent'),(290,'Is edit available',77,'2000-01-01 00:00:00','is_editbank-accounts',5.00,'Master','master','',0,5.00,NULL,'other_right','',3,1,'_parent'),(291,'Is create available',77,'2000-01-01 00:00:00','is_createbank-accounts',5.00,'Master','master','',0,5.00,NULL,'other_right','',3,1,'_parent'),(292,'Vehicle List',77,'2000-01-01 00:00:00','customer_vehicle',12.00,'Vehicles','vehicle','customer-vehicle',18,1.00,'fa fa-car',' ','',1,1,'_parent'),(293,'Sales invoice list',77,'2000-01-01 00:00:00','sale_invoice_list',9.00,'Sales','sales','sales-invoice-lists',13,0.00,'fa fa-book',' ','',1,1,'_parent'),(294,'Estimate List',77,'2000-01-01 00:00:00','estimation',8.00,'Estimates','estimation','estiomation',3,1.00,'fa fa-tags',' ','',1,1,'_parent'),(295,'Is approve available',77,'2000-01-01 00:00:00','is_approvecustomer',11.00,'Customers','customer','',0,1.00,NULL,'other_right','',5,1,'_parent'),(297,'Invoice payments',77,'2000-01-01 00:00:00','invoice_payments',6.00,'Payments','Payments','invoice-payments',15,3.00,NULL,' ','',1,1,'_parent'),(298,'Company Setup',77,'2000-01-01 00:00:00','company_setup',3.00,'Admin','admin','company',14,14.20,'glyphicon glyphicon-user',' ','',1,1,'_parent'),(299,'Branch',77,'2000-01-01 00:00:00','branch',3.00,'Admin','admin','branch',14,14.30,'glyphicon glyphicon-user',' ','',1,1,'_parent'),(300,'Is delete available',77,'2000-01-01 00:00:00','is_deletebranch',3.00,'Admin','admin','',0,14.30,NULL,'other_right','',2,1,'_parent'),(301,'Is edit available',77,'2000-01-01 00:00:00','is_editbranch',3.00,'Admin','admin','',0,3.00,NULL,'other_right','',12,1,'_parent'),(302,'Is create available',77,'2000-01-01 00:00:00','is_createbranch',3.00,'Admin','admin','',0,14.30,NULL,'other_right','',4,1,'_parent'),(303,'Cancelled payments',77,'2000-01-01 00:00:00','cancelled_payments',6.00,'Payments','Payments','cancelled-payments',15,4.00,NULL,' ','',1,1,'_parent'),(304,'Job Card list',77,'2000-01-01 00:00:00','job',7.00,'Job Cards','job_card','job',20,1.00,'fa fa-briefcase',' ','',1,1,'_parent'),(305,'Work type',77,'2000-01-01 00:00:00','work_type',5.00,'Master','master','work-type',10,6.00,'fa fa-cogs',' ','',1,1,'_parent'),(306,'Is create available',77,'2000-01-01 00:00:00','is_creatework-type',5.00,'Master','master','',10,6.00,NULL,'other_right','',2,1,'_parent'),(307,'Is edit available',77,'2000-01-01 00:00:00','is_editwork-type',5.00,'Master','master','',10,6.00,NULL,'other_right','',3,1,'_parent'),(308,'Work Type Category',77,'2000-01-01 00:00:00','work_type_category',5.00,'Master','master','work-type-category',10,7.00,'fa fa-cogs',' ','',1,1,'_parent'),(309,'Is create available',77,'2000-01-01 00:00:00','is_creatework-type-category',5.00,'Master','master','',10,7.00,NULL,'other_right','',2,1,'_parent'),(310,'Is edit available',77,'2000-01-01 00:00:00','is_editwork-type-category',5.00,'Master','master','',10,7.00,NULL,'other_right','',3,1,'_parent'),(311,'Job Type',77,'2000-01-01 00:00:00','job_type',5.00,'Master','master','job-type',10,8.00,'fa fa-cogs',' ','',1,1,'_parent'),(312,'Is create available',77,'2000-01-01 00:00:00','is_createjob-type',5.00,'Master','master','',10,8.00,NULL,'other_right','',2,1,'_parent'),(313,'Is edit available',77,'2000-01-01 00:00:00','is_editjob-type',5.00,'Master','master','',10,8.00,NULL,'other_right','',3,1,'_parent'),(314,'Is permanent cancelled available',77,'2000-01-01 00:00:00','is_permanentCancelledAvailablesales-invoice',95.00,'Sales','sales','',0,3.00,NULL,'other_right','',2,1,'_parent'),(315,'Is authorized available ',77,'2000-01-01 00:00:00','is_authorized_availableestiomation',8.00,'Estimates','estimation','',1,1.00,'','other_right','',2,1,'_parent'),(316,'Is add new product to job invoice',77,'2000-01-01 00:00:00','is_newProductsales-invoice',95.00,'Sales','sales','',0,12.00,NULL,'other_right','',10,1,'_parent'),(317,'To do list',0,'2000-01-01 00:00:00','todolist',101.00,'To do list','todolist','to-do-list',12,1.00,'fa fa-list-ol','single_menu','',0,1,'_parent'),(318,'Product price',77,'2000-01-01 00:00:00','product price',5.00,'Master','master','product-price',10,1.70,'fa fa-money',' ','',1,1,'_parent'),(319,'Stock movement',77,'2000-01-01 00:00:00','stockMovement',5.10,'Transaction','transaction','stock-movement',11,7.00,'fa fa-exchange',' ','',1,1,'_parent'),(320,'Stock adjustment',77,'2000-01-01 00:00:00','stock_adjustment',5.10,'Transaction','transaction','stock-adjustment',11,8.00,NULL,' ','',1,1,'_parent'),(321,'Is create available',77,'2000-01-01 00:00:00','is_createstock-adjustment',5.10,'Transaction','transaction','',0,8.00,NULL,'other_right','',2,1,'_parent'),(322,'Is edit available',77,'2000-01-01 00:00:00','is_editstock-adjustment',5.10,'Transaction','transaction','',0,8.00,NULL,'other_right','',3,1,'_parent'),(323,'Is print available',77,'2000-01-01 00:00:00','is_printstock-adjustment',5.10,'Transaction','transaction','',0,8.00,NULL,'other_right','',4,1,'_parent'),(324,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelstock-adjustment',5.10,'Transaction','transaction','',0,8.00,NULL,'other_right','',5,1,'_parent'),(325,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedstock-adjustment',5.10,'Transaction','transaction','',0,8.00,NULL,'other_right','',6,1,'_parent'),(326,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedstock-adjustment',5.10,'Transaction','transaction','',0,8.00,NULL,'other_right','',7,1,'_parent'),(327,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedstock-adjustment',5.10,'Transaction','transaction','',0,8.00,NULL,'other_right','',8,1,'_parent'),(328,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenstock-adjustment',5.10,'Transaction','transaction','',0,8.00,NULL,'other_right','',9,1,'_parent'),(329,'Approved List',77,'2000-01-01 00:00:00','approved-list',11.00,'Customers','customer','approved-list',17,2.00,'fa fa-user',' ','',1,1,'_parent'),(330,'Job invoice list',77,'2000-01-01 00:00:00','job_invoice',9.00,'Sales','sales','job-invoice',13,4.00,'fa fa-book',' ','',1,1,'_parent'),(331,'Stock take',77,'2000-01-01 00:00:00','stock_take',5.10,'Transaction','transaction','stock-take',11,9.00,NULL,' ','',1,1,'_parent'),(332,'Is create available',77,'2000-01-01 00:00:00','is_createstock-take',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',2,1,'_parent'),(333,'Is edit available',77,'2000-01-01 00:00:00','is_editstock-take',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',3,1,'_parent'),(334,'Is print available',77,'2000-01-01 00:00:00','is_printstock-take',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',4,1,'_parent'),(335,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelstock-take',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',5,1,'_parent'),(336,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedstock-take',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',6,1,'_parent'),(337,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedstock-take',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',7,1,'_parent'),(338,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedstock-take',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',8,1,'_parent'),(339,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenstock-take',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',9,1,'_parent'),(340,'Assemble',77,'2000-01-01 00:00:00','assemble',15.00,'Assemble','assemble','assemble',20,1.10,NULL,' ','',1,1,'_parent'),(341,'Is create available',77,'2000-01-01 00:00:00','is_createassemble',15.00,'Assemble','assemble','',0,1.10,NULL,'other_right','',2,1,'_parent'),(342,'Is edit available',77,'2000-01-01 00:00:00','is_editassemble',15.00,'Assemble','assemble','',0,1.10,NULL,'other_right','',3,1,'_parent'),(343,'Is print available',77,'2000-01-01 00:00:00','is_printassemble',15.00,'Assemble','assemble','',0,1.10,NULL,'other_right','',4,1,'_parent'),(344,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelassemble',15.00,'Assemble','assemble','',0,1.10,NULL,'other_right','',5,1,'_parent'),(345,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedassemble',15.00,'Assemble','assemble','',0,1.10,NULL,'other_right','',6,1,'_parent'),(346,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedassemble',15.00,'Assemble','assemble','',0,1.10,NULL,'other_right','',7,1,'_parent'),(347,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedassemble',15.00,'Assemble','assemble','',0,1.10,NULL,'other_right','',8,1,'_parent'),(348,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenassemble',15.00,'Assemble','assemble','',0,1.10,NULL,'other_right','',9,1,'_parent'),(349,'Disassemble',77,'2000-01-01 00:00:00','reassemble',15.00,'Assemble','assemble','re-assemble',20,2.00,NULL,' ','',1,1,'_parent'),(350,'Is create available',77,'2000-01-01 00:00:00','is_createre-assemble',15.00,'Assemble','assemble','',0,2.00,NULL,'other_right','',2,1,'_parent'),(351,'Is edit available',77,'2000-01-01 00:00:00','is_editre-assemble',15.00,'Assemble','assemble','',0,2.00,NULL,'other_right','',3,1,'_parent'),(352,'Is print available',77,'2000-01-01 00:00:00','is_printre-assemble',15.00,'Assemble','assemble','',0,2.00,NULL,'other_right','',4,1,'_parent'),(353,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelre-assemble',15.00,'Assemble','assemble','',0,2.00,NULL,'other_right','',5,1,'_parent'),(354,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedre-assemble',15.00,'Assemble','assemble','',0,2.00,NULL,'other_right','',6,1,'_parent'),(355,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedre-assemble',15.00,'Assemble','assemble','',0,2.00,NULL,'other_right','',7,1,'_parent'),(356,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedre-assemble',15.00,'Assemble','assemble','',0,2.00,NULL,'other_right','',8,1,'_parent'),(357,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenre-assemble',15.00,'Assemble','assemble','',0,2.00,NULL,'other_right','',9,1,'_parent'),(358,'Job invoice list',77,'2000-01-01 00:00:00','job_invoice',9.00,'Sales','sales','job-invoice',13,4.00,'fa fa-book',' ','',1,1,'_parent'),(359,'Is copy available',77,'2000-01-01 00:00:00','is_copysales-invoice',9.00,'Sales','sales','',10,3.00,NULL,'other_right','',11,1,'_parent'),(360,'Insurance',77,'2000-01-01 00:00:00','insurance',5.00,'Master','master','insurance',10,9.00,'fa fa-cogs',' ','',1,1,'_parent'),(361,'Is create available',77,'2000-01-01 00:00:00','is_createinsurance',5.00,'Master','master','',10,9.00,NULL,'other_right','',2,1,'_parent'),(362,'Is edit available',77,'2000-01-01 00:00:00','is_editinsurance',5.00,'Master','master','',10,9.00,NULL,'other_right','',3,1,'_parent'),(363,'Make',77,'2000-01-01 00:00:00','make',5.00,'Master','master','make',10,10.00,'fa fa-cogs',' ','',1,1,'_parent'),(364,'Is create available',77,'2000-01-01 00:00:00','is_createmake',5.00,'Master','master','',10,10.00,NULL,'other_right','',2,1,'_parent'),(365,'Is edit available',77,'2000-01-01 00:00:00','is_editmake',5.00,'Master','master','',10,10.00,NULL,'other_right','',3,1,'_parent'),(366,'Model',77,'2000-01-01 00:00:00','model',5.00,'Master','master','model',10,11.00,'fa fa-cogs',' ','',1,1,'_parent'),(367,'Is create available',77,'2000-01-01 00:00:00','is_createmodel',5.00,'Master','master','',10,11.00,NULL,'other_right','',2,1,'_parent'),(368,'Is edit available',77,'2000-01-01 00:00:00','is_editmodel',5.00,'Master','master','',10,11.00,NULL,'other_right','',3,1,'_parent'),(369,'Credit/Debit Notes',77,'2000-01-01 00:00:00','payments_adjustment',5.10,'Transaction','transaction','payments-adjustment',11,9.00,NULL,' ','',1,1,'_parent'),(370,'Is create available',77,'2000-01-01 00:00:00','is_createpayments-adjustment',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',2,1,'_parent'),(371,'Is edit available',77,'2000-01-01 00:00:00','is_editpayments-adjustment',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',3,1,'_parent'),(372,'Is print available',77,'2000-01-01 00:00:00','is_printpayments-adjustment',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',4,1,'_parent'),(373,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelpayments-adjustment',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',5,1,'_parent'),(374,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedpayments-adjustment',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',6,1,'_parent'),(375,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedpayments-adjustment',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',7,1,'_parent'),(376,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedpayments-adjustment',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',8,1,'_parent'),(377,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenpayments-adjustment',5.10,'Transaction','transaction','',0,9.00,NULL,'other_right','',9,1,'_parent'),(378,'Is sale price / discount change',77,'2000-01-01 00:00:00','is_priceChangeAvailablesales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',12,1,'_parent'),(379,'Commission',77,'2000-01-01 00:00:00','commission',9.00,'Sales','sales','commission',13,5.00,'fa fa-book',' ','',1,1,'_parent'),(380,'Sales Return',77,'2000-01-01 00:00:00','sales_return',9.00,'Sales','sales','sales-return',13,6.00,'fa fa-book',' ','',1,1,'_parent'),(381,'Inventry transfer',77,'2000-01-01 00:00:00','inventry_transfer',5.10,'Transaction','transaction','inventry-transfer',11,10.00,'fa fa-credit-card',' ','',1,1,'_parent'),(382,'Is create available',77,'2000-01-01 00:00:00','is_createinventry-transfer',5.10,'Transaction','transaction','',0,10.00,NULL,'other_right','',2,1,'_parent'),(383,'Is edit available',77,'2000-01-01 00:00:00','is_editinventry-transfer',5.10,'Transaction','transaction','',0,10.00,NULL,'other_right','',3,1,'_parent'),(384,'Is print available',77,'2000-01-01 00:00:00','is_printinventry-transfer',5.10,'Transaction','transaction','',0,10.00,NULL,'other_right','',5,1,'_parent'),(385,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelinventry-transfer',5.10,'Transaction','transaction','',0,10.00,NULL,'other_right','',6,1,'_parent'),(386,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedinventry-transfer',5.10,'Transaction','transaction','',0,10.00,NULL,'other_right','',7,1,'_parent'),(387,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedinventry-transfer',5.10,'Transaction','transaction','',0,10.00,NULL,'other_right','',8,1,'_parent'),(388,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedinventry-transfer',5.10,'Transaction','transaction','',0,10.00,NULL,'other_right','',9,1,'_parent'),(389,'Is re-open available',77,'2000-01-01 00:00:00','is_reopeninventry-transfer',5.10,'Transaction','transaction','',0,10.00,NULL,'other_right','',10,1,'_parent'),(390,'Inventry balance',77,'2000-01-01 00:00:00','inventry_balance',5.10,'Transaction','transaction','inventry-balance',11,11.00,'fa fa-credit-card',' ','',1,1,'_parent'),(391,'Is create available',77,'2000-01-01 00:00:00','is_createinventry-balance',5.10,'Transaction','transaction','',0,11.00,NULL,'other_right','',2,1,'_parent'),(392,'Is edit available',77,'2000-01-01 00:00:00','is_editinventry-balance',5.10,'Transaction','transaction','',0,11.00,NULL,'other_right','',3,1,'_parent'),(393,'Is print available',77,'2000-01-01 00:00:00','is_printinventry-balance',5.10,'Transaction','transaction','',0,11.00,NULL,'other_right','',5,1,'_parent'),(394,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelinventry-balance',5.10,'Transaction','transaction','',0,11.00,NULL,'other_right','',6,1,'_parent'),(395,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedinventry-balance',5.10,'Transaction','transaction','',0,11.00,NULL,'other_right','',7,1,'_parent'),(396,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedinventry-balance',5.10,'Transaction','transaction','',0,11.00,NULL,'other_right','',8,1,'_parent'),(397,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedinventry-balance',5.10,'Transaction','transaction','',0,11.00,NULL,'other_right','',9,1,'_parent'),(398,'Is re-open available',77,'2000-01-01 00:00:00','is_reopeninventry-balance',5.10,'Transaction','transaction','',0,11.00,NULL,'other_right','',10,1,'_parent'),(399,'Expenses type',77,'2000-01-01 00:00:00','expenses_type',5.10,'Expenses','expenses','expenses-type',21,2.00,'fa fa-usd',' ','',1,1,'_parent'),(400,'Is create available',77,'2000-01-01 00:00:00','is_createexpenses-type',5.10,'Expenses','expenses','',0,2.00,NULL,'other_right','',2,1,'_parent'),(401,'Is edit available',77,'2000-01-01 00:00:00','is_editexpenses-type',5.10,'Expenses','expenses','',0,2.00,NULL,'other_right','',3,1,'_parent'),(408,'Expenses',77,'2000-01-01 00:00:00','expenses',5.10,'Expenses','expenses','expenses',21,1.00,'fa fa-usd',' ','',1,1,'_parent'),(409,'Is create available',77,'2000-01-01 00:00:00','is_createexpenses',5.10,'Expenses','expenses','',0,1.00,NULL,'other_right','',2,1,'_parent'),(410,'Is edit available',77,'2000-01-01 00:00:00','is_editexpenses',5.10,'Expenses','expenses','',0,1.00,NULL,'other_right','',3,1,'_parent'),(411,'Is print available',77,'2000-01-01 00:00:00','is_printexpenses',5.10,'Expenses','expenses','',0,1.00,NULL,'other_right','',5,1,'_parent'),(412,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelexpenses',5.10,'Expenses','expenses','',0,1.00,NULL,'other_right','',6,1,'_parent'),(413,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedexpenses',5.10,'Expenses','expenses','',0,1.00,NULL,'other_right','',7,1,'_parent'),(414,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedexpenses',5.10,'Expenses','expenses','',0,1.00,NULL,'other_right','',8,1,'_parent'),(415,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedexpenses',5.10,'Expenses','expenses','',0,1.00,NULL,'other_right','',9,1,'_parent'),(416,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenexpenses',5.10,'Expenses','expenses','',0,1.00,NULL,'other_right','',10,1,'_parent'),(417,'Sales rep',77,'2000-01-01 00:00:00','rep',5.00,'Master','master','sales-rep',10,12.00,'fa fa-money',' ','',1,1,'_parent'),(418,'Is create available',77,'2000-01-01 00:00:00','is_createsales-rep',5.00,'Master','master','',0,12.00,NULL,'other_right','',2,1,'_parent'),(419,'Is edit available',77,'2000-01-01 00:00:00','is_editsales-rep',5.00,'Master','master','',0,12.00,NULL,'other_right','',3,1,'_parent'),(420,'Administrator',77,'2000-01-01 00:00:00','admin',3.00,'Admin','admin','',14,14.60,'glyphicon glyphicon-user',' other_rights','',1,1,'_parent'),(421,'Price groups',77,'2000-01-01 00:00:00','price_group',5.00,'Master','master','price-group',10,1.60,'fa fa-money',' ','',1,1,'_parent'),(422,'Is create available',77,'2000-01-01 00:00:00','is_createprice-group',5.00,'Master','master','',0,1.60,NULL,'other_right','',2,1,'_parent'),(423,'Is edit available',77,'2000-01-01 00:00:00','is_editprice-group',5.00,'Master','master','',0,1.60,NULL,'other_right','',3,1,'_parent'),(424,'View all location details',77,'2000-01-01 00:00:00','is_view_all_location_details',3.00,'Admin','admin','',14,14.70,'glyphicon glyphicon-user',' other_rights','',1,1,'_parent'),(425,'Product catalogue',0,'2000-01-01 00:00:00','Product_catalogue',96.00,'Product catalogue','Product_catalogue','product-catalogue',22,1.00,'fa fa-archive','single_menu','',0,1,'_parent'),(426,'GRN',77,'2000-01-01 00:00:00','grn',5.15,'Import','Import','import-grn',23,3.00,'fa fa-plane',' ','',1,1,'_parent'),(427,'Is create available',77,'2000-01-01 00:00:00','is_createimport-grn',5.15,'Import','Import','',0,3.00,NULL,'other_right','',2,1,'_parent'),(428,'Is edit available',77,'2000-01-01 00:00:00','is_editimport-grn',5.15,'Import','Import','',0,3.00,NULL,'other_right','',3,1,'_parent'),(429,'Show GRN Rpt Values',77,'2000-01-01 00:00:00','show_grn_rpt_values',5.15,'Import','Import','',0,3.00,NULL,'other_right','',4,1,'_parent'),(430,'Is print available',77,'2000-01-01 00:00:00','is_printimport-grn',5.15,'Import','Import','',0,3.00,NULL,'other_right','',5,1,'_parent'),(431,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelimport-grn',5.15,'Import','Import','',0,3.00,NULL,'other_right','',6,1,'_parent'),(432,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedimport-grn',5.15,'Import','Import','',0,3.00,NULL,'other_right','',7,1,'_parent'),(433,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedimport-grn',5.15,'Import','Import','',0,3.00,NULL,'other_right','',8,1,'_parent'),(434,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedimport-grn',5.15,'Import','Import','',0,3.00,NULL,'other_right','',9,1,'_parent'),(435,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenimport-grn',5.15,'Import','Import','',0,3.00,NULL,'other_right','',10,1,'_parent'),(436,'Duties',77,'2000-01-01 00:00:00','duties',5.15,'Import','Import','duties',23,1.00,'fa fa-cogs',' ','',1,1,'_parent'),(437,'Is create available',77,'2000-01-01 00:00:00','is_createduties',5.15,'Import','Import','',0,1.00,NULL,'other_right','',2,1,'_parent'),(438,'Is edit available',77,'2000-01-01 00:00:00','is_editduties',5.15,'Import','Import','',0,1.00,NULL,'other_right','',3,1,'_parent'),(439,'Charges',77,'2000-01-01 00:00:00','charges',5.15,'Import','Import','charges',23,2.00,'fa fa-cogs',' ','',1,1,'_parent'),(440,'Is create available',77,'2000-01-01 00:00:00','is_createcharges',5.15,'Import','Import','',0,2.00,NULL,'other_right','',2,1,'_parent'),(441,'Is edit available',77,'2000-01-01 00:00:00','is_editcharges',5.15,'Import','Import','',0,2.00,NULL,'other_right','',3,1,'_parent'),(442,'grid generate retail price',77,'2000-01-01 00:00:00','is_generateRetailPricegrn',5.10,'Transaction','transaction','',0,4.00,NULL,'other_right','',9,1,'_parent'),(443,'Re-order analysis',77,'2000-01-01 00:00:00','reorder_analysis',95.50,'Analysis','Analysis','reorder-analysis',24,1.00,'fa fa-bar-chart-o',' ','',1,1,'_parent'),(444,'Is view all invoices',77,'2000-01-01 00:00:00','is_allInvoicessales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',13,1,'_parent'),(445,'Product sub category',77,'2000-01-01 00:00:00','product_sub_category',5.00,'Master','master','product-sub-category',10,2.10,'fa fa-cogs',' ','',1,1,'_parent'),(446,'Is create available',77,'2000-01-01 00:00:00','is_createproduct-sub-category',5.00,'Master','master','',0,2.10,NULL,'other_right','',2,1,'_parent'),(447,'Is edit available',77,'2000-01-01 00:00:00','is_editproduct-sub-category',5.00,'Master','master','',0,2.10,NULL,'other_right','',3,1,'_parent'),(448,'Is delete available',77,'2000-01-01 00:00:00','is_deleteproduct-sub-category',5.00,'Master','master','',0,2.10,NULL,'other_right','',4,1,'_parent'),(449,'Is view customer last product price in sales',77,'2000-01-01 00:00:00','is_cusSalePricesales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',14,1,'_parent'),(450,'Gas pumps',77,'2000-01-01 00:00:00','gasPump',5.40,'Gas station','gasStatiton','gas-pumps',25,1.00,'fa fa-podcast',' ','',1,1,'_parent'),(451,'Is create available',77,'2000-01-01 00:00:00','is_creategas-pumps',5.40,'Gas station','gasStatiton','',0,1.00,NULL,'other_right','',2,1,'_parent'),(452,'Is edit available',77,'2000-01-01 00:00:00','is_editgas-pumps',5.40,'Gas station','gasStatiton','',0,1.00,NULL,'other_right','',3,1,'_parent'),(453,'Is delete available',77,'2000-01-01 00:00:00','is_deletegas-pumps',5.40,'Gas station','gasStatiton','',0,1.00,NULL,'other_right','',4,1,'_parent'),(454,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenpump-receipts',5.40,'Gas station','gasStatiton','',0,2.00,NULL,'other_right','',10,1,'_parent'),(455,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedpump-receipts',5.40,'Gas station','gasStatiton','',0,2.00,NULL,'other_right','',9,1,'_parent'),(456,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedpump-receipts',5.40,'Gas station','gasStatiton','',0,2.00,NULL,'other_right','',8,1,'_parent'),(457,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedpump-receipts',5.40,'Gas station','gasStatiton','',0,2.00,NULL,'other_right','',7,1,'_parent'),(458,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelpump-receipts',5.40,'Gas station','gasStatiton','',0,2.00,NULL,'other_right','',6,1,'_parent'),(459,'Is print available',77,'2000-01-01 00:00:00','is_printpump-receipts',5.40,'Gas station','gasStatiton','',0,2.00,NULL,'other_right','',5,1,'_parent'),(460,'Is edit available',77,'2000-01-01 00:00:00','is_editpump-receipts',5.40,'Gas station','gasStatiton','',0,2.00,NULL,'other_right','',3,1,'_parent'),(461,'Is create available',77,'2000-01-01 00:00:00','is_createpump-receipts',5.40,'Gas station','gasStatiton','',0,2.00,NULL,'other_right','',2,1,'_parent'),(462,'Pump receipts',77,'2000-01-01 00:00:00','pump_receipts',5.40,'Gas station','gasStatiton','pump-receipts',25,2.00,'fa fa-credit-card',' ','',1,1,'_parent'),(463,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenpump-meter-reading',5.40,'Gas station','gasStatiton','',0,3.00,NULL,'other_right','',10,1,'_parent'),(464,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedpump-meter-reading',5.40,'Gas station','gasStatiton','',0,3.00,NULL,'other_right','',9,1,'_parent'),(465,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedpump-meter-reading',5.40,'Gas station','gasStatiton','',0,3.00,NULL,'other_right','',8,1,'_parent'),(466,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedpump-meter-reading',5.40,'Gas station','gasStatiton','',0,3.00,NULL,'other_right','',7,1,'_parent'),(467,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelpump-meter-reading',5.40,'Gas station','gasStatiton','',0,3.00,NULL,'other_right','',6,1,'_parent'),(468,'Is print available',77,'2000-01-01 00:00:00','is_printpump-meter-reading',5.40,'Gas station','gasStatiton','',0,3.00,NULL,'other_right','',5,1,'_parent'),(469,'Is edit available',77,'2000-01-01 00:00:00','is_editpump-meter-reading',5.40,'Gas station','gasStatiton','',0,3.00,NULL,'other_right','',3,1,'_parent'),(470,'Is create available',77,'2000-01-01 00:00:00','is_createpump-meter-reading',5.40,'Gas station','gasStatiton','',0,3.00,NULL,'other_right','',2,1,'_parent'),(471,'Pump meter reading',77,'2000-01-01 00:00:00','meter_reading',5.40,'Gas station','gasStatiton','pump-meter-reading',25,3.00,'fa fa-credit-card',' ','',1,1,'_parent'),(472,'Credit/Debit Notes',77,'2000-01-01 00:00:00','payments_adjustment',5.10,'Transaction','transaction','payments-adjustment',11,12.00,NULL,' ','',1,1,'_parent'),(473,'Is create available',77,'2000-01-01 00:00:00','is_createpayments-adjustment',5.10,'Transaction','transaction','',0,12.00,NULL,'other_right','',2,1,'_parent'),(474,'Is edit available',77,'2000-01-01 00:00:00','is_editpayments-adjustment',5.10,'Transaction','transaction','',0,12.00,NULL,'other_right','',3,1,'_parent'),(475,'Is print available',77,'2000-01-01 00:00:00','is_printpayments-adjustment',5.10,'Transaction','transaction','',0,12.00,NULL,'other_right','',4,1,'_parent'),(476,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelpayments-adjustment',5.10,'Transaction','transaction','',0,12.00,NULL,'other_right','',5,1,'_parent'),(477,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedpayments-adjustment',5.10,'Transaction','transaction','',0,12.00,NULL,'other_right','',6,1,'_parent'),(478,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedpayments-adjustment',5.10,'Transaction','transaction','',0,12.00,NULL,'other_right','',7,1,'_parent'),(479,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedpayments-adjustment',5.10,'Transaction','transaction','',0,12.00,NULL,'other_right','',8,1,'_parent'),(480,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenpayments-adjustment',5.10,'Transaction','transaction','',0,12.00,NULL,'other_right','',9,1,'_parent'),(481,'Is minimum price not validate',77,'2000-01-01 00:00:00','is_minimumPriceNotValidatesales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',15,1,'_parent'),(482,'Import GRN returns',77,'2000-01-01 00:00:00','import_grn_returns',5.15,'Import','Import','import-grn-returns',23,4.00,'fa fa-plane',' ','',1,1,'_parent'),(483,'Is create available',77,'2000-01-01 00:00:00','is_createimport-grn-returns',5.15,'Import','Import','',0,4.00,NULL,'other_right','',2,1,'_parent'),(484,'Is edit available',77,'2000-01-01 00:00:00','is_editimport-grn-returns',5.15,'Import','Import','',0,4.00,NULL,'other_right','',3,1,'_parent'),(485,'Is print available',77,'2000-01-01 00:00:00','is_printimport-grn-returns',5.15,'Import','Import','',0,4.00,NULL,'other_right','',5,1,'_parent'),(486,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelimport-grn-returns',5.15,'Import','Import','',0,4.00,NULL,'other_right','',6,1,'_parent'),(487,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedimport-grn-returns',5.15,'Import','Import','',0,4.00,NULL,'other_right','',7,1,'_parent'),(488,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedimport-grn-returns',5.15,'Import','Import','',0,4.00,NULL,'other_right','',8,1,'_parent'),(489,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedimport-grn-returns',5.15,'Import','Import','',0,4.00,NULL,'other_right','',9,1,'_parent'),(490,'Is re-open available',77,'2000-01-01 00:00:00','is_reopenimport-grn-returns',5.15,'Import','Import','',0,4.00,NULL,'other_right','',10,1,'_parent'),(491,'Is rep dashboard',0,'0000-00-00 00:00:00','is_rep_dashboard',100.00,'Dashboard','dashboard','dashboard',1,1.00,'fa fa-dashboard','other_right','',2,1,'_parent'),(492,'Is view only own salas oders',77,'2000-01-01 00:00:00','is_ownsaleOderssales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',11,1,'_parent'),(493,'Is own sale invoices',77,'2000-01-01 00:00:00','is_ownSaleInvoicessales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',16,1,'_parent'),(494,'Is view login branch details',0,'0000-00-00 00:00:00','is_login_branch_dashboard',100.00,'Dashboard','dashboard','dashboard',1,1.00,'fa fa-dashboard','other_right','',3,1,'_parent'),(495,'Is view only own salas oders',77,'2000-01-01 00:00:00','is_ownsaleOderssales-order',9.00,'Sales','sales','',0,1.00,NULL,'other_right','',11,1,'_parent'),(496,'Is own sale invoices',77,'2000-01-01 00:00:00','is_ownSaleInvoicessales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',16,1,'_parent'),(497,'Is view login branch details',0,'0000-00-00 00:00:00','is_login_branch_dashboard',100.00,'Dashboard','dashboard','dashboard',1,1.00,'fa fa-dashboard','other_right','',3,1,'_parent'),(498,'Sample return',77,'2000-01-01 00:00:00','return_samples',5.10,'Transaction','transaction','samples-return',11,5.10,'fa fa-credit-card',' ','',1,1,'_parent'),(499,'Is create available',77,'2000-01-01 00:00:00','is_createsamples-return',5.10,'Transaction','transaction','',0,5.10,NULL,'other_right','',2,1,'_parent'),(500,'Is edit available',77,'2000-01-01 00:00:00','is_editsamples-return',5.10,'Transaction','transaction','',0,5.10,NULL,'other_right','',3,1,'_parent'),(501,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelsamples-return',5.10,'Transaction','transaction','',0,5.10,NULL,'other_right','',6,1,'_parent'),(502,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedsamples-return',5.10,'Transaction','transaction','',0,5.10,NULL,'other_right','',7,1,'_parent'),(503,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedsamples-return',5.10,'Transaction','transaction','',0,5.10,NULL,'other_right','',8,1,'_parent'),(504,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedsamples-return',5.10,'Transaction','transaction','',0,5.10,NULL,'other_right','',9,1,'_parent'),(505,'Is re-open available',77,'2000-01-01 00:00:00','is_reopensamples-return',5.10,'Transaction','transaction','',0,5.10,NULL,'other_right','',10,1,'_parent'),(506,'Invoice cost',77,'2000-01-01 00:00:00','Invoice cost',9.00,'Sales','sales','invoice-cost',13,7.00,'fa fa-book',' ','',1,1,'_parent'),(507,'Is create available',77,'2000-01-01 00:00:00','is_createinvoice-cost',9.00,'Sales','sales','',0,7.00,NULL,'other_right','',2,1,'_parent'),(508,'Is edit available',77,'2000-01-01 00:00:00','is_editinvoice-cost',9.00,'Sales','sales','',0,7.00,NULL,'other_right','',3,1,'_parent'),(509,'Is print available',77,'2000-01-01 00:00:00','is_printinvoice-cost',9.00,'Sales','sales','',0,7.00,NULL,'other_right','',5,1,'_parent'),(510,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelinvoice-cost',9.00,'Sales','sales','',0,7.00,NULL,'other_right','',6,1,'_parent'),(511,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedinvoice-cost',9.00,'Sales','sales','',0,7.00,NULL,'other_right','',7,1,'_parent'),(512,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedinvoice-cost',9.00,'Sales','sales','',0,7.00,NULL,'other_right','',8,1,'_parent'),(513,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedinvoice-cost',9.00,'Sales','sales','',0,7.00,NULL,'other_right','',9,1,'_parent'),(514,'Is re-open available',77,'2000-01-01 00:00:00','is_reopeninvoice-cost',9.00,'Sales','sales','',0,7.00,NULL,'other_right','',10,1,'_parent'),(515,'Is view branch wise sale',0,'0000-00-00 00:00:00','is_view_all_branch_sale',100.00,'Dashboard','dashboard','dashboard',1,1.00,'fa fa-dashboard','other_right','',4,1,'_parent'),(516,'Is remove custom items button',77,'2000-01-01 00:00:00','is_removeCustomItemButtonsales-invoice',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',17,1,'_parent'),(517,'Events',77,'2000-01-01 00:00:00','events',5.00,'Accounts','Accounts','events',25,1.00,'fa fa-cogs',' ','',1,1,'_parent'),(518,'Is create available',77,'2000-01-01 00:00:00','is_createevents',5.00,'Accounts','Accounts','',25,1.00,NULL,'other_right','',2,1,'_parent'),(519,'Is edit available',77,'2000-01-01 00:00:00','is_editevents',5.00,'Accounts','Accounts','',25,1.00,NULL,'other_right','',3,1,'_parent'),(520,'Account details',77,'2000-01-01 00:00:00','account_details',5.00,'Accounts','Accounts','account-details',25,0.10,'fa fa-cogs',' ','',1,1,'_parent'),(521,'Meals',77,'2000-01-01 00:00:00','Meal',4.90,'Restaurant','Restaurant','meal',36,1.00,'fa fa-cutlery',' ','',1,1,'_parent'),(522,'Is create available',77,'2000-01-01 00:00:00','is_createmeal',4.90,'Restaurant','Restaurant','',0,1.00,NULL,'other_right','',2,1,'_parent'),(523,'Is edit available',77,'2000-01-01 00:00:00','is_editmeal',4.90,'Restaurant','Restaurant','',0,1.00,NULL,'other_right','',3,1,'_parent'),(524,'Is delete available',77,'2000-01-01 00:00:00','is_deletemeal',4.90,'Restaurant','Restaurant','',0,1.00,NULL,'other_right','',4,1,'_parent'),(525,'Sales summary',0,'0000-00-00 00:00:00','sales_summary',100.10,'Sales summary','sales_summary','sales-summary',37,1.00,'fa fa-area-chart','single_menu','',0,1,'_blank'),(526,'Invoice approved 3 month credit periods',77,'2000-01-01 00:00:00','3_month_credit_period',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',11,1,'_parent'),(527,'Invoice approved 6 month credit periods',77,'2000-01-01 00:00:00','6_month_credit_period',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',12,1,'_parent'),(528,'Invoice approved 12 month credit periods',77,'2000-01-01 00:00:00','12_month_credit_period',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',13,1,'_parent'),(529,'Invoice approved greater than 12 month credit periods',77,'2000-01-01 00:00:00','12<_month_credit_period',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',14,1,'_parent'),(530,'Invoice list view login branch',77,'2000-01-01 00:00:00','view_branch_invoices',9.00,'Sales','sales','',0,3.00,NULL,'other_right','',15,1,'_parent'),(531,'Return cheques',77,'2000-01-01 00:00:00','return_cheques',6.00,'Payments','Payments','return-cheques',15,5.00,'fa fa-money',' ','',1,1,'_parent'),(532,'Is create available',77,'2000-01-01 00:00:00','is_createreturn-cheques',6.00,'Payments','Payments','',0,5.00,NULL,'other_right','',2,1,'_parent'),(533,'Is edit available',77,'2000-01-01 00:00:00','is_editreturn-cheques',6.00,'Payments','Payments','',0,5.00,NULL,'other_right','',3,1,'_parent'),(534,'Is delete available',0,'2000-01-01 00:00:00','is_deletereturn-cheques',6.00,'Payments','Payments','',0,5.00,'0','other_right','',4,1,'_parent'),(535,'Is print available',77,'2000-01-01 00:00:00','is_printreturn-cheques',6.00,'Payments','Payments','',0,5.00,NULL,'other_right','',5,1,'_parent'),(536,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelreturn-cheques',6.00,'Payments','Payments','',0,5.00,NULL,'other_right','',6,1,'_parent'),(537,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedreturn-cheques',6.00,'Payments','Payments','',0,5.00,NULL,'other_right','',7,1,'_parent'),(538,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedreturn-cheques',6.00,'Payments','Payments','',0,5.00,NULL,'other_right','',8,1,'_parent'),(539,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedreturn-cheques',6.00,'Payments','Payments','',0,5.00,NULL,'other_right','',9,1,'_parent'),(540,'Supplier payment bulk',77,'2000-01-01 00:00:00','Supplier_payment_bulk',6.00,'Payments','Payments','supplier-payments-bulk',15,1.10,'fa fa-money',' ','',1,1,'_parent'),(541,'Is create available',77,'2000-01-01 00:00:00','is_createsupplier-payments-bulk',6.00,'Payments','Payments','',0,1.10,NULL,'other_right','',2,1,'_parent'),(542,'Is edit available',77,'2000-01-01 00:00:00','is_editsupplier-payments-bulk',6.00,'Payments','Payments','',0,1.10,NULL,'other_right','',3,1,'_parent'),(543,'Is delete available',0,'2000-01-01 00:00:00','is_deletesupplier-payments-bulk',6.00,'Payments','Payments','',0,1.10,'0','other_right','',4,1,'_parent'),(544,'Is print available',77,'2000-01-01 00:00:00','is_printsupplier-payments-bulk',6.00,'Payments','Payments','',0,1.10,NULL,'other_right','',5,1,'_parent'),(545,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelsupplier-payments-bulk',6.00,'Payments','Payments','',0,1.10,NULL,'other_right','',6,1,'_parent'),(546,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedsupplier-payments-bulk',6.00,'Payments','Payments','',0,1.10,NULL,'other_right','',7,1,'_parent'),(547,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedsupplier-payments-bulk',6.00,'Payments','Payments','',0,1.10,NULL,'other_right','',8,1,'_parent'),(548,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedsupplier-payments-bulk',6.00,'Payments','Payments','',0,1.10,NULL,'other_right','',9,1,'_parent'),(549,'Supplier return cheques',77,'2000-01-01 00:00:00','supplier_return_cheques',6.00,'Payments','Payments','supplier-return-cheques',15,5.10,'fa fa-money',' ','',1,1,'_parent'),(550,'Is create available',77,'2000-01-01 00:00:00','is_createsupplier-return-cheques',6.00,'Payments','Payments','',0,5.10,NULL,'other_right','',2,1,'_parent'),(551,'Is edit available',77,'2000-01-01 00:00:00','is_editsupplier-return-cheques',6.00,'Payments','Payments','',0,5.10,NULL,'other_right','',3,1,'_parent'),(552,'Is delete available',0,'2000-01-01 00:00:00','is_deletesupplier-return-cheques',6.00,'Payments','Payments','',0,5.10,'0','other_right','',4,1,'_parent'),(553,'Is print available',77,'2000-01-01 00:00:00','is_printsupplier-return-cheques',6.00,'Payments','Payments','',0,5.10,NULL,'other_right','',5,1,'_parent'),(554,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelsupplier-return-cheques',6.00,'Payments','Payments','',0,5.10,NULL,'other_right','',6,1,'_parent'),(555,'Is authorized available',77,'2000-01-01 00:00:00','is_authorizedsupplier-return-cheques',6.00,'Payments','Payments','',0,5.10,NULL,'other_right','',7,1,'_parent'),(556,'Is rejected available',77,'2000-01-01 00:00:00','is_rejectedsupplier-return-cheques',6.00,'Payments','Payments','',0,5.10,NULL,'other_right','',8,1,'_parent'),(557,'Is pending authorized available',77,'2000-01-01 00:00:00','is_pendingauthorizedsupplier-return-cheques',6.00,'Payments','Payments','',0,5.10,NULL,'other_right','',9,1,'_parent'),(558,'Over payments',77,'2000-01-01 00:00:00','over_payments',6.00,'Payments','Payments','over-payments',15,3.10,'fa fa-money',' ','',1,1,'_parent'),(559,'Is edit available',77,'2000-01-01 00:00:00','is_editover-payments',6.00,'Payments','Payments','',0,3.10,NULL,'other_right','',3,1,'_parent'),(560,'Is cancel available',77,'2000-01-01 00:00:00','is_cancelover-payments',6.00,'Payments','Payments','',0,3.10,NULL,'other_right','',6,1,'_parent'),(561,'Database backups',77,'2000-01-01 00:00:00','is_get_database_backups',3.00,'Admin','admin','',14,14.80,'glyphicon glyphicon-user',' other_rights','',1,1,'_parent');

--
-- Table structure for table `tbl_users`
--

CREATE TABLE `tbl_users` (
  `user_Id` int NOT NULL AUTO_INCREMENT,
  `user_name` varchar(255) NOT NULL,
  `full_name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `phone_no` varchar(255) NOT NULL,
  `user_description` text NOT NULL,
  `password` varchar(255) NOT NULL,
  `user_group_Id` int NOT NULL,
  `image` longblob,
  `create_user_Id` int NOT NULL,
  `create_datetime` datetime NOT NULL,
  `is_inactive` tinyint(1) NOT NULL DEFAULT '0',
  `district_id` int DEFAULT NULL,
  `branch_id` varchar(50) NOT NULL,
  `is_delete` tinyint(1) NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `user_type` varchar(100) NOT NULL DEFAULT 'Administration',
  `profile_id` int NOT NULL DEFAULT '0',
  `is_authentication` decimal(10,0) NOT NULL DEFAULT '0',
  `authentication_expire_on` datetime NOT NULL DEFAULT '2025-01-01 00:00:00',
  `auth_code` varchar(100) NOT NULL,
  `auth_code_ref` varchar(100) NOT NULL,
  PRIMARY KEY (`user_Id`)
) ENGINE=InnoDB AUTO_INCREMENT=111 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_users`
--

INSERT INTO `tbl_users` VALUES (77,'admin','Admin','thenuka@bbk-holdings.com','0767829912','sssss','$2a$10$exKZVCaLJO8bq.YgEQ.cBeOF/n055kXcTKv2eW9h1QHlfg/9t4b2u',69,_binary '        data:image/png;base64,[encoded data, 8788 characters]        ',77,'2026-01-26 14:09:49',0,0,'1',0,1,'Administration',0,0,'2025-01-01 00:00:00','',''),(105,'Sales','Sales','test@gmail.com','0777793848','ok','$2a$10$FwD7rSpJZLJU.eKwq6kNMe12SDd9kJZsxhPZ0LTQdPKDTKyV3IveS',89,_binary '     data:image/png;base64,[encoded data, 8788 characters]     ',109,'2026-01-30 10:05:29',0,NULL,'1',0,1,'Administration',0,0,'2025-01-01 00:00:00','',''),(106,'Sasindu','Sasindu Chathuranga','sasinduchathuranga@outlook.com','0762090042','artist','$2a$10$ZIHbQuGxft05T5Jnk4OskuQTlY1L.7kcXn.CrhRCBEh7JEujNVKo2',89,_binary '       data:image/png;base64,[encoded data, 8788 characters]       ',109,'2026-01-30 10:05:36',0,NULL,'1',0,0,'Administration',0,0,'2025-01-01 00:00:00','',''),(107,'Vishwa','Galagedarage Don Vishwaith Nayanapriya','vishwajith@thecoffemanor.com','admin','Accountant','$2a$10$EJBe6BypNLzkAbN2gQmh4eBdFeIlm2z1CzmVo5Eg5n9wqR3izfvx2',89,_binary '     data:image/png;base64,[encoded data, 8788 characters]     ',109,'2026-01-30 10:05:52',0,NULL,'1',0,1,'Administration',0,0,'2025-01-01 00:00:00','',''),(108,'Rashmika','Rashmika Kavindi','rashmikakavindi65@gmail.com','admin','Assistant accountant','$2a$10$VkGsUYSuIPeIgKl.otuwSuZ88Y4IphddvybM3exIXS.45HiTy9xgK',89,_binary '  data:image/png;base64,[encoded data, 8788 characters]  ',109,'2026-01-30 10:05:59',0,NULL,'1',0,1,'Administration',0,0,'2025-01-01 00:00:00','',''),(109,'nbit','Developer','info@fluxcode.com','0752417797','sssss','$2a$10$zR60SyVIBPLloNcQx3BrxOEXQIciEXOlcqJRqmdCTskfhSOlGcp9a',89,_binary ' data:image/png;base64,[encoded data, 8788 characters] ',109,'2026-01-30 10:06:29',0,0,'1',0,1,'Administration',0,0,'2025-01-01 00:00:00','',''),(110,'Gayathri','Gayathri SIVAPATHAM','gayathri204icloud@gmail.com','admin','Assistant accountantg','$2a$10$F2t/WBsct7kbOU7GrW3lbeV4XRyWRsgsanF9H4Z2WBViurqLbA8qC',89,_binary '        data:image/png;base64,[encoded data, 8788 characters]        ',109,'2026-01-30 10:06:37',0,NULL,'1',0,1,'Administration',0,0,'2025-01-01 00:00:00','','');

--
-- Table structure for table `tbl_vehicle_transfer_log`
--

CREATE TABLE `tbl_vehicle_transfer_log` (
  `id` int NOT NULL AUTO_INCREMENT,
  `vehicle_id` int NOT NULL,
  `customer_id` int NOT NULL,
  `new_customer_id` int NOT NULL,
  `created_by` int NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_vehicle_transfer_log`
--


--
-- Table structure for table `tbl_work_type`
--

CREATE TABLE `tbl_work_type` (
  `work_type_id` int NOT NULL AUTO_INCREMENT,
  `work_category_id` int NOT NULL,
  `type_name` varchar(200) NOT NULL,
  `type_order` varchar(50) NOT NULL,
  `is_vat` tinyint(1) NOT NULL,
  `is_nbit` tinyint(1) NOT NULL,
  `nbit_ratio` varchar(20) NOT NULL,
  `created_on` datetime NOT NULL,
  `updated_on` datetime NOT NULL,
  `created_by` int NOT NULL,
  `updated_by` int NOT NULL,
  `code` varchar(20) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL,
  PRIMARY KEY (`work_type_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_work_type`
--


--
-- Table structure for table `tbl_work_type_category`
--

CREATE TABLE `tbl_work_type_category` (
  `work_category_id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `order_no` varchar(50) NOT NULL,
  `created_on` datetime DEFAULT NULL,
  `updated_on` datetime DEFAULT NULL,
  `created_by` int DEFAULT NULL,
  `updated_by` int DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_delete` tinyint(1) NOT NULL,
  PRIMARY KEY (`work_category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_work_type_category`
--


--
-- Dumping events for database '1000_flux_retail_base'
--

--
-- Dumping routines for database '1000_flux_retail_base'
--
/*!50003 DROP FUNCTION IF EXISTS `getTransactionCode` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `getTransactionCode`(`t_type` VARCHAR(20), `t_id` INT) RETURNS varchar(300) CHARSET utf8mb3
BEGIN

DECLARE tcode varchar(300); 

 select 
CASE
	when t_type='PO' THEN (select code from tbl_pos where po_id=t_id)
	when t_type='GRN' THEN (select code from tbl_grns where grn_id=t_id)
	when t_type='SAMPLES' THEN (select code from tbl_samples where sample_id=t_id)
	when t_type='DAMAGES' THEN (select code from tbl_damage where damage_id=t_id)
	when t_type='GRNReturn' THEN (select code from tbl_grn_return where grn_return_id=t_id)
	when t_type='Sales' THEN (select code from tbl_sale_invoice where id=t_id)
	when t_type='dispatch' THEN (select code from tbl_dispatch where dispatch_id=t_id)
	when t_type='production_plan' THEN (select code from tbl_production_plans where plan_id=t_id)
	when t_type='mrn_issue' THEN (select code from tbl_mrn_issues  where mrn_issue_id=t_id)
	when t_type='mrn' THEN (select code from tbl_mrns where mrn_id=t_id)
	when t_type='sales_return' THEN (select code from tbl_customer_returns where id=t_id)
	when t_type='Sales_cancel' THEN (select concat(code,' - Cancelled') from tbl_sale_invoice where id=t_id)
	when t_type='stock_adjustment' THEN (select code from tbl_stock_adjustment where id=t_id)
	when t_type='assemble' THEN (select code from tbl_assemble where id=t_id)
	when t_type='re_assemble' THEN (select code from tbl_re_assemble where id=t_id)
	when t_type='inventoryTransfer' THEN (select code from tbl_inventory_transfer_location where id=t_id)
    
    when t_type='OPNB' THEN 'Open Balance'
ELSE '-'
END 
into tcode;

return tcode;

 
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_avinda_invoiceAllPayments` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_avinda_invoiceAllPayments`(`_psId` INT, `_invoiceId` INT, `_paymentType` VARCHAR(50), `_rptDate` DATE) RETURNS decimal(16,2)
BEGIN

DECLARE _amount DECIMAL;   

select 

sum(tbl_payment_summary_details.amount)

INTO   _amount

from tbl_payment_summary_invoices
inner join tbl_payment_summary_details on tbl_payment_summary_details.ps_id = tbl_payment_summary_invoices.ps_id
and tbl_payment_summary_details.payment_type in (_paymentType)

group by tbl_payment_summary_invoices.sale_invoice_id
having tbl_payment_summary_invoices.sale_invoice_id = _invoiceId;

RETURN _amount;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_avinda_invoicePayments` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_avinda_invoicePayments`(`_psId` INT, `_invoiceId` INT, `_paymentType` VARCHAR(50), `_rptDate` DATE) RETURNS decimal(16,2)
BEGIN

DECLARE _amount DECIMAL;   

select 

sum(tbl_payment_summary_details.amount)

INTO   _amount 

from tbl_payment_summary_invoices
inner join tbl_payment_summary_details on tbl_payment_summary_details.ps_id = tbl_payment_summary_invoices.ps_id
and tbl_payment_summary_details.payment_type in (_paymentType)
and date(tbl_payment_summary_details.created_on) = date(_rptDate)
group by tbl_payment_summary_invoices.sale_invoice_id
having tbl_payment_summary_invoices.sale_invoice_id = _invoiceId;

RETURN _amount;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_customerOutstandingAmount` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_customerOutstandingAmount`(`_customerId` INT, `_date` DATE, `_ageRage` INT) RETURNS decimal(16,2)
BEGIN

DECLARE _value DECIMAL(16,2) default 0.00; 

select 
ifnull(sum(balance),0.00) 
into _value
from (select 
(ifnull(si.net_total,0)+ifnull(si.rpt_cash_returns,0) - (ifnull(si.rpt_settled_amount,0)+ifnull(si.rpt_returns_amount,0))) as balance
,datediff(_date,date(si.created_on)) as outstandingAge
,si.customer_id
from tbl_sale_invoice si
where si.status = '4' ) tmp
where balance > 0
and tmp.customer_id = _customerId
and (
	case 
		when _ageRage = 0 then outstandingAge > 0 && outstandingAge <= 30 
		when _ageRage = 30 then outstandingAge > 31 && outstandingAge <= 60 
		when _ageRage = 60 then outstandingAge > 61 && outstandingAge <= 90 
		when _ageRage = 90 then outstandingAge > 91 && outstandingAge <= 120 
		when _ageRage = 120 then outstandingAge > 120 
        end
)
-- group by tmp.outstandingAge
;

RETURN _value;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_customerProductPrice` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_customerProductPrice`(`_cusId` INT, `_productId` INT) RETURNS decimal(16,2)
BEGIN

DECLARE _price DECIMAL;   

select unit_price into _price
from tbl_sale_invoice_products sip
inner join tbl_sale_invoice si on si.id = sip.sale_invoice_id
where si.customer_id = _cusId
and sip.product_id = _productId
and si.status = 4
order by si.created_on desc 
limit 0,1;


RETURN _price;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_end_meter_reading` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_end_meter_reading`(`_pumId` INT) RETURNS decimal(16,4)
BEGIN

DECLARE meterReading DECIMAL(16,4) default 0;   

select ifnull(gprp.pump_end,gp.meter_reading) into meterReading
from tbl_gas_pumps gp 
left join tbl_gas_pump_reading_pumps gprp on gprp.pump_id = gp.id
left join tbl_gas_pump_reading gpr on gpr.id = gprp.pump_reading_id
and gpr.status != '5'
where gp.id = _pumId
order by ifnull(gpr.reading_date,CURDATE()) desc limit 0,1; 


RETURN meterReading;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_invoiceOverPayments` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_invoiceOverPayments`(`_invoiceId` INT) RETURNS decimal(16,2)
BEGIN

DECLARE _amount DECIMAL; 

select sum(tbl_overpayments.amount)

INTO   _amount

from tbl_payment_summary
inner join tbl_payment_summary_invoices on tbl_payment_summary_invoices.ps_id = tbl_payment_summary.id
inner join tbl_sale_invoice on tbl_sale_invoice.id = tbl_payment_summary_invoices.sale_invoice_id
and tbl_sale_invoice.id = _invoiceId
inner join tbl_overpayments on tbl_overpayments.ps_id = tbl_payment_summary.id
group by tbl_sale_invoice.id
;

RETURN _amount;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_invoicePayments` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_invoicePayments`(`_psId` INT, `_invoiceId` INT, `_paymentType` VARCHAR(50), `_rptDate` DATE) RETURNS decimal(16,2)
BEGIN

DECLARE _amount DECIMAL;  

select 

sum(tbl_payment_allocation.allocation_amount)

INTO   _amount

from tbl_payment_allocation
where tbl_payment_allocation.ps_id = _psId
and tbl_payment_allocation.invoice_id = _invoiceId
and tbl_payment_allocation.payment_type in (_paymentType)
and date(tbl_payment_allocation.created_on) = date(_rptDate)
group by tbl_payment_allocation.payment_type; 

RETURN _amount;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_jobInvoiceQty` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_jobInvoiceQty`(`_estimationId` INT, `_invoiceId` INT, `_estimationDetailsId` INT) RETURNS decimal(16,2)
BEGIN

DECLARE _amount DECIMAL(16,2); 

select 
case when tbl_sale_invoice_products.type = 'service' then 1 else 
ifnull(sum(tbl_sale_invoice_products.qty),0) end

INTO   _amount

from tbl_sale_invoice_products
inner join tbl_sale_invoice on tbl_sale_invoice.id = tbl_sale_invoice_products.sale_invoice_id
where tbl_sale_invoice_products.estimationDetailsId = _estimationDetailsId
and tbl_sale_invoice.estimation_id = _estimationId
and tbl_sale_invoice_products.sale_invoice_id not in (_invoiceId);


RETURN _amount;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_so_invoicedProductQty` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_so_invoicedProductQty`(`_soId` INT, `_productId` INT, `_invId` INT, `_type` VARCHAR(50)) RETURNS decimal(16,2)
BEGIN

DECLARE _qty DECIMAL(16,2); 

if _type = 'estimation'
then

select sum(qty) INTO _qty
from tbl_sale_invoice_products sip
inner join tbl_sale_invoice si on si.id = sip.sale_invoice_id
where si.estimation_id = _soId
and si.status != 5
and sip.is_depositItem = 0
and (sip.product_id = _productId)
and sip.sale_invoice_id != _invId;

elseif (_type = 'estimationGrid') 
then

select sum(qty) INTO _qty
from tbl_sale_invoice_products sip
inner join tbl_sale_invoice si on si.id = sip.sale_invoice_id
where si.estimation_id = _soId
and si.status != 5
and sip.is_depositItem = 0;

elseif (_type = 'so') 
then

select sum(qty) INTO _qty
from tbl_sale_invoice_products sip
inner join tbl_sale_invoice si on si.id = sip.sale_invoice_id
where si.so_id = _soId
and si.status != 5
and sip.is_depositItem = 0
and (sip.product_id = _productId or _productId = 0)
and sip.sale_invoice_id != _invId;



end if;

RETURN _qty; 
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `get_so_productQty` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `get_so_productQty`(`_soId` INT, `_productId` INT, `_type` VARCHAR(50)) RETURNS decimal(16,2)
BEGIN

DECLARE _qty DECIMAL(16,2); 
if _type = 'estimation'
then

select sum(qty) INTO _qty
from tbl_estimate_details ed
where ed.estimate_id = _soId
and (ed.job = _productId);

elseif (_type = 'estimationGrid') 
then

select sum(qty) INTO _qty
from tbl_estimate_details ed
where ed.estimate_id = _soId;

elseif (_type = 'so') 
then

select sum(ContractQty) INTO _qty
from tbl_so_products sop
where sop.so_id = _soId
and (sop.product_id = _productId or _productId = 0);

end if;

RETURN _qty;  
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `grn_product_qty` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `grn_product_qty`(`_id` INT, `_grnId` INT, `_productId` INT, `_type` VARCHAR(50)) RETURNS decimal(16,2)
BEGIN

DECLARE qty DECIMAL default 0;   

if(_type = 'return')
	then

		select sum(grp.qty) into qty
		from tbl_grn_return_products grp
		inner join tbl_grn_return gr on gr.grn_return_id = grp.grn_return_id
		and gr.grn_id = _grnId
		where grp.product_id = _productId
		and grp.status != '5'
		and grp.grn_return_id != _id;

elseif (_type = 'grn')  
	then

		select grp.qty into qty
		from tbl_grn_return_products grp
		inner join tbl_grn_return gr on gr.grn_return_id = grp.grn_return_id
		and gr.grn_id = _grnId
		where grp.product_id = _productId
		and grp.status != '5';
        
elseif(_type = 'import_return') 
	then

		select sum(grp.qty) into qty
		from tbl_grn_import_return_products grp
		inner join tbl_grn_import_return gr on gr.grn_return_id = grp.grn_return_id
		and gr.grn_id = _grnId
		where grp.product_id = _productId
		and grp.status != '5'
		and grp.grn_return_id != _id;

elseif (_type = 'import_grn')  
	then

		select grp.qty into qty
		from tbl_grn_import_return_products grp
		inner join tbl_grn_import_return gr on gr.grn_return_id = grp.grn_return_id
		and gr.grn_id = _grnId
		where grp.product_id = _productId
		and grp.status != '5';

elseif (_type = 'damage_grn')  
	then

		select sum(dp.qty) into qty
		from tbl_damage_products dp
		inner join tbl_damage d on d.damage_id = dp.damage_id
		and d.grn_id = _grnId
        and d.grn_id > 0
		where dp.product_id = _productId
		and d.status != '5';

elseif (_type = '_damage_grn')  
	then

		select sum(dp.qty) into qty
		from tbl_damage_products dp
		inner join tbl_damage d on d.damage_id = dp.damage_id
		and d.grn_id = _grnId
		where dp.product_id = _productId
		and d.status != '5'
		and dp.damage_id != _id;
        
        
end if;

RETURN qty;
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `is_uber_invoice` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `is_uber_invoice`(`_invoiceId` INT) RETURNS int
BEGIN

DECLARE _count INT default 0;   

select count(*) into _count
from tbl_sale_invoice_products sip
inner join tbl_sale_invoice si on si.id = sip.sale_invoice_id
inner join tbl_products p on p.product_id = sip.product_id
inner join tbl_productcategory pc on pc.productCategory_id = p.category_id
where si.id = _invoiceId
and pc.category like '%UBER%';



RETURN ifnull(_count,0);
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `replaceSeparators` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` FUNCTION `replaceSeparators`(`source` VARCHAR(20)) RETURNS varchar(20) CHARSET utf8mb3
BEGIN

DECLARE tcode varchar(30);

 select REPLACE( source, '-', '' ) into tcode;
 select REPLACE( tcode, ' ', '' ) into tcode;
 select REPLACE( tcode, '.', '' ) into tcode;
 
return tcode;

 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `add_advance_payments` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `add_advance_payments`(IN `_psId` INT, IN `_userId` INT, IN `_sessionPaymentRef` VARCHAR(50), IN `_isAdvancePayment` BOOLEAN)
BEGIN

INSERT INTO tbl_payment_summary_details
            (ps_id,
             customer_id,
             payment_type,
             sessionpaymentref,
             amount,
             note,
             reference,
             cash_date,
             cheque_date,
             cheque_no,
             bank_id,
             bank_branch,
             bank_account_id,
             advancepaymnet_date,
             created_on,
             created_by,
             card_type_id,
             outstanding_type,
             outstanding_amount,
             outstanding_parent_id,
             outstanding_sale_invoice_id,
             outstanding_ref,
             is_advance_payment,
             receipt_no,
             received_date)
SELECT _psid,
       customer_id,
       payment_type,
       sessionpaymentref,
       amount,
       note,
       reference,
       cash_date,
       cheque_date,
       cheque_no,
       bank_id,
       bank_branch,
       bank_account_id,
       advancepaymnet_date,
       created_on,
       created_by,
       card_type_id,
       outstanding_type,
       outstanding_amount,
       outstanding_parent_id,
       outstanding_sale_invoice_id,
       outstanding_ref,
       _isadvancepayment,
		 receipt_no,
		 received_date
FROM   tbl_temp_payments_details
WHERE  tbl_temp_payments_details.created_by = _userid
       AND tbl_temp_payments_details.sessionpaymentref IN ( _sessionpaymentref )
; 

update tbl_payment_summary set rpt_remittanceTotal = (
select ifnull(sum(amount),0)
from tbl_payment_summary_details 
where tbl_payment_summary_details.ps_id = _psId )
WHERE  tbl_payment_summary.id = _psId
;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_calculate_contract` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_calculate_contract`(IN `suuid` VARCHAR(50))
BEGIN
select tbl_boq_product_details.product_id ,tbl_products.name
, sum(tbl_boq_product_details.qty *    tbl_temp_boq_details.catonsQty ) as total
,tbl_boq_product_details.qty
from tbl_boq
inner join tbl_boq_product_details on tbl_boq_product_details.boq_id = tbl_boq.boq_id
inner join tbl_temp_boq_details on tbl_temp_boq_details.boq_id = tbl_boq.boq_id
inner join tbl_products on tbl_products.product_id = tbl_boq_product_details.product_id
and uuid = suuid
group by tbl_boq_product_details.product_id;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_calculate_prn` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_calculate_prn`(IN `suuid` VARCHAR(50))
BEGIN

select tbl_contract_boqs_details.product_id ,tbl_products.name
, sum(tbl_contract_boqs_details.totalQty) as total
from tbl_contract_boqs_details
inner join tbl_temp_contract_ids on tbl_temp_contract_ids.contract_id = tbl_contract_boqs_details.contract_id
inner join tbl_products on tbl_products.product_id = tbl_contract_boqs_details.product_id
and uuid = suuid
group by tbl_contract_boqs_details.product_id
;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_dash_board_key_values` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_dash_board_key_values`()
BEGIN

DECLARE _job_total double DEFAULT 0; 
DECLARE _job_count double DEFAULT 0; 
DECLARE _job_count_wating_approve double DEFAULT 0; 
DECLARE _pay_amount double DEFAULT 0; 
DECLARE _outstanding_invoice_total double DEFAULT 0; 
DECLARE _outstanding_invoice_count double DEFAULT 0; 

DECLARE _jan_invoice double DEFAULT 0; 
DECLARE _feb_invoice double DEFAULT 0; 
DECLARE _mar_invoice double DEFAULT 0; 
DECLARE _apr_invoice double DEFAULT 0; 
DECLARE _may_invoice double DEFAULT 0; 
DECLARE _jun_invoice double DEFAULT 0; 
DECLARE _jul_invoice double DEFAULT 0; 
DECLARE _aug_invoice double DEFAULT 0; 
DECLARE _sep_invoice double DEFAULT 0; 
DECLARE _oct_invoice double DEFAULT 0; 
DECLARE _nov_invoice double DEFAULT 0; 
DECLARE _dec_invoice double DEFAULT 0; 

 select sum(job_total) , count(distinct job_reference) 
 Into _job_total ,_job_count 
 from tbl_jobs
 WHERE job_date >= DATE_SUB(CURRENT_DATE, INTERVAL DAYOFMONTH(CURRENT_DATE)-1 DAY)
 AND job_date <=  LAST_DAY(CURRENT_DATE);
 
 
 select  
 sum(CASE    WHEN status_id = 1 THEN 1   ELSE 0 END)
 Into  _job_count_wating_approve
 from tbl_jobs; 
 
   
   
 select sum(pay_amount) 
 into _pay_amount
 from tbl_customer_payments
  WHERE Payment_date >= DATE_SUB(CURRENT_DATE, INTERVAL DAYOFMONTH(CURRENT_DATE)-1 DAY)
 AND Payment_date <=  LAST_DAY(CURRENT_DATE);
   
   
select  
sum(invoice_total - ifnull((select sum(pay_amount) 
from tbl_customer_payments where tbl_customer_payments.invoice_id = tbl_invoices.invoice_id ),0))  ,
count(distinct invoice_reference)
 into _outstanding_invoice_total,_outstanding_invoice_count
from tbl_invoices
 where (invoice_total - ifnull((select sum(pay_amount) 
from tbl_customer_payments where tbl_customer_payments.invoice_id = tbl_invoices.invoice_id ),0))>0;


SELECT  
       sum(if(month(invoice_date) = 1, invoice_total, 0))  AS Jan,
       sum(if(month(invoice_date) = 2, invoice_total, 0))  AS Feb,
       sum(if(month(invoice_date) = 3, invoice_total, 0))  AS Mar,
       sum(if(month(invoice_date) = 4, invoice_total, 0))  AS Apr,
       sum(if(month(invoice_date) = 5, invoice_total, 0))  AS May,
       sum(if(month(invoice_date) = 6, invoice_total, 0))  AS Jun,
       sum(if(month(invoice_date) = 7, invoice_total, 0))  AS Jul,
       sum(if(month(invoice_date) = 8, invoice_total, 0))  AS Aug,
       sum(if(month(invoice_date) = 9, invoice_total, 0))  AS Sep,
       sum(if(month(invoice_date) = 10, invoice_total, 0)) AS Oct,
       sum(if(month(invoice_date) = 11, invoice_total, 0)) AS Nov,
       sum(if(month(invoice_date) = 12, invoice_total, 0)) AS `Dec`
       into  _jan_invoice ,
 _feb_invoice ,
 _mar_invoice ,
 _apr_invoice ,
 _may_invoice , 
 _jun_invoice ,
 _jul_invoice , 
 _aug_invoice ,
 _sep_invoice ,
 _oct_invoice ,
 _nov_invoice , 
 _dec_invoice 
FROM tbl_invoices
 WHERE invoice_date >= DATE_SUB(CURRENT_DATE, INTERVAL DAYOFYEAR(CURRENT_DATE)-1 DAY)
   AND invoice_date <=  LAST_DAY(CURRENT_DATE);

select _job_total,_job_count,_pay_amount,_job_count_wating_approve,
_outstanding_invoice_total,_outstanding_invoice_count,
 _jan_invoice ,
 _feb_invoice ,
 _mar_invoice ,
 _apr_invoice ,
 _may_invoice , 
 _jun_invoice ,
 _jul_invoice , 
 _aug_invoice ,
 _sep_invoice ,
 _oct_invoice ,
 _nov_invoice , 
 _dec_invoice 
;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_inventoryAnalysisGRNs` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_inventoryAnalysisGRNs`(IN `_productId` INT)
BEGIN

DECLARE _finished INTEGER DEFAULT 0; 
declare g_grnId int;
declare g_qty decimal(18,2);
declare g_date date;
declare balanceQty decimal(18,2);

DECLARE _grnCursor CURSOR FOR 
select g.grn_id,gp.qty,g.grn_date
from tbl_grn_products gp
inner join tbl_grns g on g.grn_id = gp.grn_id
where g.status = '4'
and gp.product_id = _productId
group by gp.grn_id
order by g.grn_date desc
limit 0,100;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET _finished = 1;

drop temporary table if exists _selectedGrnList;
create temporary table  _selectedGrnList(_allowcatedGrnQty decimal(18,4),_grnQty decimal(18,4),_grnDate date,_grnID int);

 select 
 ifnull(sum(qty_in_stock),0) into balanceQty
 from tbl_inventory_log ig
 where product_id = _productId;

OPEN _grnCursor; 
	_selectedGrn: LOOP 
		FETCH _grnCursor INTO  g_grnId,g_qty,g_date;
		IF _finished = 1 THEN  
			LEAVE _selectedGrn;
		END IF;
        
        if(balanceQty = 0 )
			then 
				set _finished = 1;
		end if;
        
			if(balanceQty >= g_qty)
				then
					INSERT INTO _selectedGrnList (_allowcatedGrnQty,`_grnQty`,`_grnDate`,`_grnID`) VALUES (g_qty,g_qty,g_date,g_grnId);
					set balanceQty = balanceQty - g_qty;
			elseif(balanceQty < g_qty && balanceQty > 0)
				then
					INSERT INTO _selectedGrnList (_allowcatedGrnQty,`_grnQty`,`_grnDate`,`_grnID`) VALUES (balanceQty,g_qty,g_date,g_grnId);
					set balanceQty = 0;
			end if;
        
END LOOP _selectedGrn;
CLOSE _grnCursor;

 select 
 grn.code as _referense 
 ,grn.grn_date as _date 
 ,ifnull(gp._allowcatedGrnQty,0) as _qty 
 ,ifnull(gp._grnQty,0) as _GRNqty 
 ,DATEDIFF(date(now()),grn.grn_date) _age 
 from _selectedGrnList gp 
 inner join tbl_grns grn on grn.grn_id = gp._grnID ; 

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_loged_details` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_loged_details`(IN `user_id` INT)
BEGIN

select 
'login_user' as type,
tbl_users.user_Id as id,
tbl_users.full_name as profile_name,
tbl_users.image as image_path,
tbl_user_groups.user_group_name as user_group_name,
'' as logo 
from tbl_users
inner join tbl_user_groups on tbl_user_groups.user_group_Id = tbl_users.user_group_Id
where tbl_users.user_Id = user_id
union 
select 
'company' as type,
tbl_company.company_id as id,
tbl_company.company_name as profile_name,
'' as image_path ,
'company_admin' as user_group_name,
tbl_company.logo as logo 
from tbl_company


;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_other_rights` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_other_rights`(IN `user_Id` INT, IN `user_right_code` VARCHAR(50))
BEGIN

select tbl_users.user_Id
from tbl_users
inner join tbl_user_group_rights on tbl_user_group_rights.user_group_Id = tbl_users.user_group_Id
inner join tbl_user_rights on tbl_user_rights.user_right_Id = tbl_user_group_rights.user_right_Id
where tbl_users.user_Id = user_Id
 and   length(trim(tbl_user_rights.user_right_code))>0
 and tbl_user_rights.user_right_code = user_right_code;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_print_invoice_details` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_print_invoice_details`(IN `_id` INT)
BEGIN

-- company name
select 
company_name as  text 
,'B' as textStyle 
,'15' as fontSize
, 'C' as alignment
, 0 as line
from tbl_company

union all
-- company address
select 
address  as text 
,'N' as textStyle 
,'10' as fontSize
, 'C' as alignment
, 0 as line
from tbl_company

union all
-- company address
select 
concat('Tel : ',phone_no)   as text 
,'N' as textStyle 
,'10' as fontSize
, 'C' as alignment
, 0 as line
from tbl_company

union all
-- company email
select 
concat('Email : ',email)   as text 
,'N' as textStyle 
,'10' as fontSize
, 'C' as alignment
, 0 as line
from tbl_company

union all
-- inv date
select 
concat('Col-2','Date : ',CAST(date(created_on)   as  CHAR(50)) ,',Time : ', CAST(time(created_on)   as CHAR(100))) as text 
,'N' as textStyle 
,'10' as fontSize
, 'C' as alignment
, 0 as line
from tbl_sale_invoice si
where id = _id
 
union all
-- inv code / user
select  
concat('Col-2','Inv# : ',CAST(code   as  CHAR(100)) ,',User : ', CAST(u.full_name   as CHAR(50))) as text 
,'N' as textStyle 
,'10' as fontSize
, 'C' as alignment
, 0 as line
from tbl_sale_invoice si
inner join tbl_users u on u.user_Id = si.created_by
where id = _id

 union all -- Line
 select  
  CAST('DrawLine'  as CHAR(50)) as text 
,'0' as textStyle 
,'0' as fontSize
, '0' as alignment
, 1 as line

 union all -- Text
 select
 CAST( concat('Product-header','Product Name,Amount') as CHAR(100))   as text 
,'N' as textStyle 
,'10' as fontSize
, 'L' as alignment
 , 0 as line
 
union all -- Line
 select  
  CAST('DrawLine'  as CHAR(50)) as text 
,'0' as textStyle 
,'0' as fontSize
, '0' as alignment
 , 2 as line
 
union all
-- product list
select 
 CAST(concat('Product-text',
(case 
	when sip.product_id > 0 then  p.name 
	when sip.type = 'custom_item' || p.is_edit_name = 1 then  sip.service_details 
else ifnull(p.name,'N/A') end )
 ,',',sip.qty,',',round(sip.unit_price-(sip.discount/qty),2),',',round(sip.net_total,2)) as CHAR(100)) as text  
,'N' as textStyle 
,'10' as fontSize
, 'C' as alignment
, 0 as line
from tbl_sale_invoice_products sip
left join tbl_products p on p.product_id = sip.product_id
where sale_invoice_id = _id
union all

 -- net total
select  
CAST(concat('Total :', net_total) as CHAR(100)) as text 
,'B' as textStyle 
,'15' as fontSize
, 'R' as alignment
, 0 as line
from tbl_sale_invoice si
where id = _id


/*
 -- bill discount
 union
select  all 
CAST(concat('Discount :', total_discount) as CHAR(100)) as text
,'N' as textStyle 
,'15' as fontSize
, 'R' as alignment
, 0 as line
from tbl_sale_invoice si
where id = _id

*/
-- product count
union all
select   
CAST(concat('Product Count :', sum(qty) ) as CHAR(100)) as text
,'N' as textStyle 
,'8' as fontSize
, 'L' as alignment
, 0 as line
from tbl_sale_invoice_products sip
left join tbl_products p on p.product_id = sip.product_id
where sale_invoice_id = _id

union all -- Line
 select  
  CAST('DrawLine'  as CHAR(50)) as text 
,'0' as textStyle 
,'0' as fontSize
, '0' as alignment
 , 3 as line
 
  union all -- Text
 select
 CAST('Thank you. Come Again!' as CHAR(200))   as text 
,'N' as textStyle 
,'10' as fontSize
, 'C' as alignment
 , 0 as line
;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_production_plan` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_production_plan`(IN `planId` INT)
BEGIN

  
DECLARE finished INTEGER DEFAULT 0;
DECLARE _boqId int DEFAULT 0; 
DECLARE _parent_id int DEFAULT 0; 
DECLARE _product_id int DEFAULT 0; 
DECLARE _is_proceed_count int DEFAULT 0; 
DEClARE curProduction CURSOR FOR select boqId,parent_id,product_id   from temp_boq where is_proceed = 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1; 
set @rowid:=0;


delete from tbl_production_plans_process where plan_id =planId;

DROP TEMPORARY TABLE IF EXISTS temp_boq;


CREATE TEMPORARY TABLE temp_boq ( boqId int,is_proceed int,tree_id varchar(50),parent_id int,product_id int,qty decimal(11,2));
insert into temp_boq
select tbl_boq.boq_id,1,@rowid:=@rowid+1 as rowid ,0,0,tbl_contract_boqs.qty from tbl_boq 
inner join tbl_products on tbl_products.product_id = tbl_boq.product_id
inner join tbl_contract_boqs on tbl_contract_boqs.boq_id = tbl_boq.boq_id
inner join tbl_contracts on tbl_contracts.contract_id = tbl_contract_boqs.contract_id
inner join tbl_production_plans_contracts on tbl_production_plans_contracts.contract_id = tbl_contract_boqs.contract_id
inner join tbl_production_plans on tbl_production_plans.plan_id = tbl_production_plans_contracts.plan_id
and tbl_production_plans_contracts.plan_id = planId
and tbl_products.is_row_material = 0;

set @rowid:=0;


INSERT INTO  `tbl_production_plans_process`
(  `plan_id`,
`is_row_material`,
`product_id`,
`tree_id` ,
`qty`,
boqId,
parent_id)
select planId,
tbl_products.is_row_material,
tbl_products. product_id,
@rowid:=@rowid+1,
tbl_contract_boqs.qty,
tbl_boq.boq_id,
tbl_boq.boq_id
from tbl_boq 
inner join tbl_products on tbl_products.product_id = tbl_boq.product_id
inner join tbl_contract_boqs on tbl_contract_boqs.boq_id = tbl_boq.boq_id
inner join tbl_contracts on tbl_contracts.contract_id = tbl_contract_boqs.contract_id
inner join tbl_production_plans_contracts on tbl_production_plans_contracts.contract_id = tbl_contract_boqs.contract_id
inner join tbl_production_plans on tbl_production_plans.plan_id = tbl_production_plans_contracts.plan_id
and tbl_production_plans_contracts.plan_id = planId
and tbl_products.is_row_material = 0;

set @rowid:=0;
 
atop:LOOP	
set  finished =0;
select 	count(*) 
 into _is_proceed_count    
 from temp_boq 
 where is_proceed = 1; 
	if(_is_proceed_count = 0) then
		LEAVE atop; 
	end if;
       
OPEN curProduction; 
	getEmail: LOOP
		FETCH curProduction INTO _boqId,_parent_id,_product_id;
		IF finished = 1 THEN  
			LEAVE getEmail;
		END IF;
        

         set @rowid:=0;
		 set @parant:=0;
         set @parant_qty:=0.0000000;
         select 	 tree_id,qty
			into @parant,@parant_qty    
		 from temp_boq 
		 where boqId = _boqId
         and parent_id = _parent_id;
         
          
    set @rowid_p:=0;
    DROP TEMPORARY TABLE IF EXISTS tmp_row_table;
      CREATE TEMPORARY TABLE IF NOT EXISTS tmp_row_table AS (
   select tbl_boq_product_details.product_id, @rowid_p:=@rowid_p+1  as row_id,tbl_boq_product_details.Qty
		 from tbl_boq
		 inner join tbl_boq_product_details on tbl_boq_product_details.boq_id = tbl_boq.boq_id
		 where tbl_boq.boq_id = _boqId
		 order by tbl_boq_product_details.product_id) ;
         
 
	     
        
        
       
        
	   insert into temp_boq
		 select boq_id,1, concat(@parant,'-', tmp_row_table.row_id )as rowid,_boqId,tbl_boq.product_id,tmp_row_table.Qty*@parant_qty 
         from tbl_boq 
         left join tmp_row_table on tmp_row_table.product_id = tbl_boq.product_id
         where tbl_boq.product_id in (
		 SELECT tbl_products.product_id FROM tbl_boq_product_details 
		 inner join tbl_products on tbl_products. product_id =tbl_boq_product_details.product_id
		 where boq_id = _boqId 
		 and is_row_material = 0
         );
        
         
         update temp_boq set is_proceed = 0   where boqId = _boqId;
      
		 
         INSERT INTO  `tbl_production_plans_process`
			(  `plan_id`,
			`is_row_material`,
			`product_id`,
			`tree_id` ,
			`qty`,
            boqId)
			select planId,
			tbl_products.is_row_material,
			tbl_products. product_id,
			concat(@parant,'-', @rowid:=@rowid+1 ) ,
			 tbl_boq_product_details.Qty*@parant_qty    ,
            _boqId
			FROM tbl_boq_product_details 
			inner join tbl_products on tbl_products. product_id =tbl_boq_product_details.product_id
			where boq_id = _boqId
            order by tbl_boq_product_details.product_id;

 
         
      
	END LOOP getEmail;
	CLOSE curProduction;
 

 END LOOP atop;
 

drop table temp_boq;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_usergroup_rights` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_usergroup_rights`(IN `usergroupId` INT)
    NO SQL
SELECT    
        CASE WHEN IFNULL(tbl_user_group_rights.user_right_Id,0)  =0 then 0
else 1
        END as selected,


tbl_user_rights.user_right_Id,tbl_user_rights.user_right_name ,main_menu_name,main_menu_code,sub_menu_id,second_level
FROM tbl_user_rights
left join tbl_user_group_rights  on tbl_user_rights.user_right_Id = tbl_user_group_rights.user_right_Id
and tbl_user_group_rights.user_group_Id = usergroupId
where tbl_user_rights.is_active = 1
order by menu_order , sub_menu_id ,  permission_order   asc ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `get_user_rights` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `get_user_rights`(IN `user_Id` INT)
BEGIN

select tbl_users.user_Id,tbl_users.user_group_Id,tbl_user_group_rights.user_right_Id,tbl_user_rights.user_right_code,tbl_user_rights.right_type,
tbl_user_rights.main_menu_name,tbl_user_rights.main_menu_code,tbl_user_rights.user_right_name,tbl_user_rights.page_path,
tbl_user_rights.main_menu_id,tbl_user_rights.sub_menu_id,tbl_user_rights.main_menu_icon,tbl_user_rights.second_level,tbl_user_rights.target
from tbl_users
inner join tbl_user_group_rights on tbl_user_group_rights.user_group_Id = tbl_users.user_group_Id
inner join tbl_user_rights on tbl_user_rights.user_right_Id = tbl_user_group_rights.user_right_Id
and tbl_user_rights.is_active = 1
where tbl_users.user_Id = user_Id
 and   length(trim(tbl_user_rights.user_right_code))>0
 order by menu_order DESC,main_menu_id,sub_menu_id;  
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `import_grn_cost` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `import_grn_cost`(`_grnId` INT)
BEGIN
 
DECLARE _finished INTEGER DEFAULT 0; 
declare _grnAmount decimal(18,2);
declare _chargesPer decimal(18,2);
declare _dutiesPer decimal(18,2);
declare _rate decimal(18,2);
declare _itemCost decimal(18,2); 
declare _itemNetCost decimal(18,2); 
declare _itemNetAvgCost decimal(18,2); 
declare _locationId int; 

declare c_id int; 
declare c_productId int; 
declare c_qty decimal(18,2);  
declare c_total decimal(18,2);  
declare c_hs_code varchar(100);
 
DECLARE _productCostCursor CURSOR FOR select grn_product_id,(qty+inventoryFreeQty) as qty,total,product_id,hs_code from tbl_grn_import_products where grn_id = _grnId;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _finished = 1;  
 
set _grnAmount = 0;
set _chargesPer = 0;
set _dutiesPer = 0;
set _rate = 0;

select total,round((total_charges/total),2),round((total_duties/total),2),exchange_rate,location_id
into _grnAmount,_chargesPer,_dutiesPer,_rate,_locationId
from tbl_grn_imports
where grn_id = _grnId ;


OPEN _productCostCursor;  
	productCost: LOOP
		FETCH _productCostCursor INTO  c_id,c_qty,c_total,c_productId,c_hs_code;
		IF _finished = 1 THEN  
			LEAVE productCost; 
		END IF;
        
		select sum(total) into _grnAmount
        from tbl_grn_import_products
        where grn_id = _grnId 
        and hs_code = c_hs_code;
         
        select round((sum(amount)/_grnAmount),2) into _dutiesPer 
		from tbl_grn_import_product_duties
		where grn_id = _grnId  
        and hs_code = c_hs_code;
         
        select round((sum(amount)/_grnAmount),2) into _dutiesPer
		from tbl_grn_import_product_duties
		where grn_id = _grnId 
        and hs_code = c_hs_code;
        
        set _itemCost = round((c_total/c_qty),2);
        set _itemNetCost = (_itemCost*_chargesPer) + (_itemCost*_dutiesPer) + (_itemCost*_rate);
          
        UPDATE `tbl_grn_import_products` SET  `calculated_cost` =  _itemNetCost 
        WHERE `grn_product_id` = c_id ;
         
END LOOP productCost;
CLOSE _productCostCursor;
 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `import_grn_costs` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `import_grn_costs`(IN `grnId` INT)
BEGIN

DECLARE _charges decimal(18,2);
DECLARE _exchangeRate decimal(18,2);

drop temporary table if exists hsCodCosts;
create temporary table  hsCodCosts(hs_code varchar(50)  , duty decimal(18,4)  );

 
 select exchange_rate
 into _exchangeRate
 from tbl_grn_imports where grn_id = grnId;


insert into hsCodCosts
SELECT tbl_grn_import_products.hs_code, duties.duty/sum(tbl_grn_import_products.total) 
 FROM tbl_grn_import_products 
 inner join  ( select hs_code,sum(amount) as duty
	from tbl_grn_import_product_duties
	where tbl_grn_import_product_duties.grn_id = grnId
	group by hs_code) duties on duties.hs_code =  tbl_grn_import_products.hs_code
where tbl_grn_import_products.grn_id = grnId
group by hs_code;

set _charges = 0;
SELECT (tbl_grn_imports.total_charges/sub_total )
into _charges
FROM tbl_grn_imports  
where tbl_grn_imports.grn_id = grnId ; 
 
 update  tbl_grn_import_products as grn_import_products
 left join hsCodCosts on hsCodCosts.hs_code =  grn_import_products.hs_code
 set total_chargers = (_charges) * grn_import_products.unitPrice ,
    total_duty = (duty) * grn_import_products.unitPrice ,
    lkr_unitCost = (_charges * grn_import_products.unitPrice) + (duty * grn_import_products.unitPrice) + (grn_import_products.unitPrice * _exchangeRate) 
 where grn_import_products.grn_id = grnId;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `rpt_customer_sale` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `rpt_customer_sale`(IN `_type` VARCHAR(50), IN `_fromDate` DATE, IN `_toDate` DATE, IN `_cusId` INT, IN `_orderBy` VARCHAR(50), IN `_rep` INT)
BEGIN

if _type = 'sales' then

		select
        concat(c.code,' - ',c.customer_name) as Customer_style_80_left
        ,sum(si.net_total) as Sale_sum_2_style_20_right
		from tbl_sale_invoice si
		inner join tbl_customers c on c.customer_id = si.customer_id
		where status = "4"
        and (date(si.created_on) between _fromDate and _toDate)
		and (si.repId = _rep or _rep = 0)
		group by si.customer_id
        order by  
			CASE  WHEN _orderBy = '0' THEN c.customer_name END,
			CASE  WHEN _orderBy = 'Highest' THEN SUM(si.net_total) END DESC,
			CASE  WHEN _orderBy = 'Lowest' THEN SUM(si.net_total) END ASC;
        
else

		select 
        si.code as Code_style_15_left
        ,date(si.created_on) as Date_style_15_left
        ,concat(c.code,' - ',c.customer_name) as Customer_style_55_left
		,si.net_total as Amount_sum_2_style_15_right
		from tbl_sale_invoice si
		inner join tbl_customers c on c.customer_id = si.customer_id
		where status = "4"
        and (date(si.created_on) between _fromDate and _toDate)
        and (si.customer_id = _cusId or _cusId = 0)
		and (si.repId = _rep or _rep = 0)
        order by  
			CASE  WHEN _orderBy = '0' THEN c.customer_name END,
			CASE  WHEN _orderBy = 'Highest' THEN si.net_total END DESC,
			CASE  WHEN _orderBy = 'Lowest' THEN si.net_total END ASC;

end if;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `rpt_customer_transactionHistory` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `rpt_customer_transactionHistory`(IN `_cusId` INT, IN `_fromDate` DATE, IN `_toDate` DATE, IN `_location` VARCHAR(50))
BEGIN

declare cusOutstanding decimal(16,2) default 0;
declare historyGeneratedOn datetime default now();
DECLARE _finished INTEGER DEFAULT 0;
DECLARE c_cusId INTEGER DEFAULT 0;
DECLARE c_parentId INTEGER DEFAULT 0;
declare c_cr decimal(16,2) default 0;
declare c_dr decimal(16,2) default 0;
declare c_tDateTime datetime default now();
declare c_code varchar(500) default '';
declare c_type varchar(500) default '';



DECLARE _productCostCursor CURSOR FOR 
	SELECT customer_id,parent_id,type,cr_value,br_value,transaction_datetime,parent_code
	FROM   (SELECT tbl_sale_invoice.customer_id AS customer_id,
				   tbl_sale_invoice.id          AS parent_id,
				   tbl_sale_invoice.code        AS parent_code,
				   'SALE_INVOICE'               AS type,
				   0.00   AS cr_value,
				   tbl_sale_invoice.net_total   AS br_value,
				   tbl_sale_invoice.created_on  AS transaction_datetime
			FROM   tbl_sale_invoice
			WHERE  tbl_sale_invoice.status = 4
			UNION ALL
			SELECT ps.customer_id            AS customer_id,
				   ps.id                     AS parent_id,
				   concat(si.code,'<small><br>',pa.payment_type, (case when pa.payment_type = 'CHEQUE' then concat(' - ',psd.cheque_no) else '' end),'</small>' ) AS parent_code,
				   'PAYMENTS'                AS type,
				   Sum(pa.allocation_amount) AS cr_value,
				   0.00                      AS br_value,
				   pa.created_on             AS transaction_datetime
			FROM   tbl_payment_allocation pa
				   INNER JOIN tbl_payment_summary_details psd 
						   ON psd.id = pa.payment_id
				   INNER JOIN tbl_payment_summary ps
						   ON ps.id = pa.ps_id
				   INNER JOIN tbl_sale_invoice si
						   ON si.id = pa.invoice_id
			WHERE  ps.status = 4
				   AND si.status = 4
			GROUP BY pa.ps_id
			UNION ALL
			SELECT tbl_customer_returns.customer_id AS customer_id,
				   tbl_customer_returns.id          AS parent_id,
				   tbl_customer_returns.code        AS parent_code,
				   tbl_customer_returns.return_type AS type,
				   CASE
					 WHEN tbl_customer_returns.return_type = 'CREDIT_RETURNS' THEN
					 0.00
					 ELSE tbl_customer_returns.amount
				   END                              AS cr_value,
				   tbl_customer_returns.amount      AS br_value,
				   tbl_customer_returns.created_on  AS transaction_datetime
			FROM   tbl_customer_returns
			WHERE  tbl_customer_returns.status = 4 
			UNION ALL
			SELECT tbl_overpayments.customer_id AS customer_id,
				   tbl_overpayments.id          AS parent_id,
				   tbl_overpayments.code        AS parent_code,
				   'OVER_PAYMENTS'              AS type,
				   tbl_overpayments.amount - rpt_settled_amount      AS cr_value,
				   0.00                         AS br_value,
				   tbl_overpayments.created_on  AS transaction_datetime
			FROM   tbl_overpayments
            where tbl_overpayments.amount - rpt_settled_amount > 0
            and canceled_payment_id = 0
			UNION ALL
			SELECT si.customer_id AS customer_id,
				   pj.id          AS parent_id,
				   pj.code        AS parent_code,
				   'PAYMENT_ADJUSTMENTS'              AS type,
				   pj.amount - pj.rpt_settled_amount      AS cr_value,
				   0.00                         AS br_value,
				   pj.created_on  AS transaction_datetime
			FROM   tbl_payment_adjustments pj
            inner join tbl_sale_invoice si on si.id = invoice_id
            where pj.amount - pj.rpt_settled_amount > 0
            and canceled_payment_id = 0 
            ) AS tmp 
		   WHERE tmp.customer_id = _cusId
	ORDER BY tmp.transaction_datetime;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET _finished = 1;
 
 delete from tbl_customer_transaction_history where customer_id = _cusId;
 
 OPEN _productCostCursor; 
	productCost: LOOP
		FETCH _productCostCursor INTO  c_cusId, c_parentId,c_type, c_cr, c_dr, c_tDateTime, c_code;
		IF _finished = 1 THEN  
			LEAVE productCost;
		END IF;
        
        set cusOutstanding = (cusOutstanding + c_dr) - c_cr;
        
         INSERT INTO `tbl_customer_transaction_history`
		(`customer_id`, `parent_id`, `type`, `cr_value`, `br_value`, `transaction_datetime`, `updated_by`, `updated_on`, `current_outstanding`, `parent_code`)
        values(
			_cusId
            ,c_parentId
            ,c_type
            ,c_cr
            ,c_dr
            ,c_tDateTime
            ,77
            ,now()
            ,cusOutstanding
            ,c_code
        );
        
END LOOP productCost;
CLOSE _productCostCursor;
 

UPDATE `tbl_customers` SET customer_history_generated_on = now() where customer_id = _cusId; 

if _location = 'report'
then
	select  
	type as Type_style_20_left
	,parent_code as Code_style_20_left
	,transaction_datetime as Date_style_15_left
	,br_value as DR_sum_2_style_15_right
	,cr_value as CR_sum_2_style_15_right
	,current_outstanding as Outstanding_style_15_right
	from tbl_customer_transaction_history
	where tbl_customer_transaction_history.customer_id =  _cusId
	and date(transaction_datetime) between _fromDate and _toDate 
	order by transaction_datetime asc , id desc;  
    
elseif _location = 'system'
then
	select  
	*
	from tbl_customer_transaction_history
	where tbl_customer_transaction_history.customer_id =  _cusId  
	order by transaction_datetime asc , id desc;  

end if;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `rpt_inventry_trnasactions` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `rpt_inventry_trnasactions`(IN `from_date` DATE, IN `to_date` DATE, IN `product_id` INT, IN `location_id` INT)
BEGIN
set @csum := 0;
select Date_style_10_left,Description_style_40_left,Location_style_15_left,Received_style_10_left as Received_style_10_right,  Issue__style_10_left as Issue__style_10_right,(@csum := @csum + qty_in_stock)  as Balance_style_15_right   from (
select 

now()  orderDate,
''  Date_style_10_left,
 getTransactionCode( 'OPNB',0)   Description_style_40_left, 

''   Received_style_10_left,
''   Location_style_15_left,

'' Issue__style_10_left, 
ifnull(sum(ilog.qty_in_stock),0)qty_in_stock  
from tbl_inventory_log ilog 
where ilog.product_id = product_id
and ilog.created_date_time between '2000-01-01' and  cast(concat(DATE_SUB(from_date, INTERVAL 1 DAY) , ' ', '23:59:59') as datetime) 
and  (ilog.location_id = location_id or location_id = 0)
 union
select 

ilog.created_date_time  orderDate,
DATE_FORMAT(ilog.created_date_time, '%Y-%m-%d')   Date_style_10_left,
  getTransactionCode( transaction_type,ilog.transaction_id)  Description_style_40_left,

CASE
    WHEN ifnull(ilog.qty_in_stock ,0)>=0 THEN ifnull(ilog.qty_in_stock ,0)
    ELSE ''
END Received_style_10_left,
bil.location Location_style_15_left,
CASE
    WHEN ifnull(ilog.qty_in_stock ,0) <= 0 THEN  abs(ifnull(ilog.qty_in_stock ,0))
    ELSE ''
END Issue__style_10_left, 
ilog.qty_in_stock as qty_in_stock 
from tbl_inventory_log ilog 
inner join tbl_branch_inventory_locations bil on bil.id =  ilog.location_id
where ilog.product_id = product_id
    and abs(ifnull(ilog.qty_in_stock ,0)) >0
and ilog.created_date_time between from_date and cast(concat(to_date, ' ', '23:59:59') as datetime)
and  (ilog.location_id = location_id or location_id = 0)) tmp
order by orderDate desc
;

 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `UpdateInventory` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `UpdateInventory`(`p_TransactionType` VARCHAR(50), `p_TransactionID` INT, `p_secondID` INT, `p_User` VARCHAR(50))
BEGIN
declare not_found int default 0;
declare v_QuantityAvaliable decimal(18,4); 
declare v_QuantityInstock decimal(18,4); 
declare v_QuantityReserved decimal(18,4); 
declare v_QuantityAllocated decimal(18,4); 
declare v_QuantitybackOrder decimal(18,4);   
declare v_SaleLocationID int;
declare v_GRNLocationID int;

declare v_productID int;
declare v_LocationID int;
declare v_ContainerID int;
declare v_OnOrderQty decimal(18,8); 
declare v_QtyInStock decimal(18,8);
declare v_QtyReserved decimal(18,8);
declare v_QtyAllocated decimal(18,8);
declare v_call_allocation_sp int;
DECLARE finished INTEGER DEFAULT 0;

DECLARE costMethod Varchar(12);
DECLARE costCalResult Varchar(12); 

DECLARE _grnTotalDiscount decimal(18,2);
declare _commonInventoryLocation int;

DECLARE _cursor CURSOR FOR select ProductID,LocationID,ContainerID,OnOrderQty,QtyInStock,QtyReserved,qtyAllocated,call_allocation_sp from InventoryList;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1; 

drop temporary table if exists InventoryList;
create temporary table  InventoryList(ProductID int , LocationID int , ContainerID int , OnOrderQty decimal(18,4) , 
QtyInStock decimal(18,4) , QtyReserved decimal(18,4),qtyAllocated decimal(18,4),call_allocation_sp int );


select ifnull(setting,0) into _commonInventoryLocation from tbl_system_settings where code = 'common_inventory_location';

if(p_TransactionType = 'PRN')
then
	
	insert into InventoryList
	select tmp.product_id as ProductID , ifnull(tmp.location_id,0) as LocationID , 0 as ContainerID, 
	0 as OnOrderQty ,0 as QtyInStock,IFNULL(tmp.prn_qty,0) as QtyReserved , 0 as qtyAllocated,
    0 as call_allocation_sp
	from (select  sum(tbl_production_plans_process.qty) as prn_qty
	,tbl_production_plans_process.product_id
	,(select tbl_prns.location_id
	from tbl_prns
	where tbl_prns.prn_id = p_TransactionID ) as location_id
	from tbl_production_plans_process
	inner join tbl_production_plans_contracts on tbl_production_plans_contracts.plan_id = tbl_production_plans_process.plan_id
	where tbl_production_plans_contracts.contract_id in (
	select tbl_prns_contracts.contract_id
	from tbl_prns_contracts
	where tbl_prns_contracts.prn_id = p_TransactionID )
	and tbl_production_plans_process.is_row_material = 1
	group by tbl_production_plans_process.product_id ) tmp;
    
     		

elseif (p_TransactionType = 'pump_receipts') 
then
 
	insert into InventoryList
	select product_id as ProductID , ifnull(gpr.location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(gprp.qty,0)*-1 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_gas_pump_receipt_products gprp
    inner join tbl_gas_pump_receipt gpr on gpr.id = gprp.receipt_id
    and gpr.status = '4'
	where gprp.receipt_id = p_TransactionID;
  
  	
elseif (p_TransactionType = 'GRN')  
then


	insert into InventoryList
	select product_id as ProductID , ifnull(location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL((qty+inventoryFreeQty),0) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_grn_products
    inner join tbl_grns on tbl_grns.grn_id = tbl_grn_products.grn_id
	where tbl_grn_products.grn_id = p_TransactionID;
    
    
    insert into InventoryList
	select tbl_grn_products.product_id as ProductID , ifnull(location_id,0) as LocationID , 
	0 as ContainerID, IFNULL((qty+inventoryFreeQty),0) *-1 as OnOrderQty , 0 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,
    
    0  as call_allocation_sp 
	from tbl_grn_products
    inner join tbl_grns on tbl_grns.grn_id = tbl_grn_products.grn_id
	inner join tbl_products on tbl_products.product_id = tbl_grn_products.product_id 
	where tbl_grn_products.grn_id = p_TransactionID;
    
    
    set _grnTotalDiscount = 0;
    select discount
    into _grnTotalDiscount
    from tbl_grns
    where grn_id = p_TransactionID ;
    
	UPDATE tbl_products 
	inner join tbl_grn_products on tbl_products.product_id = tbl_grn_products.product_id
	set avg_cost_price = (tbl_products.cost_price + (tbl_grn_products.total/(tbl_grn_products.inventoryFreeQty+tbl_grn_products.qty)) - (_grnTotalDiscount/(tbl_grn_products.inventoryFreeQty+tbl_grn_products.qty)) )/
			(case when tbl_products.cost_price = 0 then 1 else 2 end)
            ,cost_price = (tbl_grn_products.total/(tbl_grn_products.inventoryFreeQty+tbl_grn_products.qty)) - (_grnTotalDiscount/(tbl_grn_products.inventoryFreeQty+tbl_grn_products.qty))
	where grn_id = p_TransactionID ;
    
    call update_product_branch_cost(p_TransactionID);
	call update_acc_data(p_TransactionID,p_TransactionType);
  	
elseif (p_TransactionType = 'IMPORT-GRN')  
then

	insert into InventoryList
	select product_id as ProductID , ifnull(location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL((qty+inventoryFreeQty),0) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_grn_import_products
    inner join tbl_grn_imports on tbl_grn_imports.grn_id = tbl_grn_import_products.grn_id
	where tbl_grn_import_products.grn_id = p_TransactionID;
    
    call import_grn_costs(p_TransactionID);
    
	UPDATE tbl_products 
	inner join tbl_grn_import_products on tbl_products.product_id = tbl_grn_import_products.product_id
	set avg_cost_price = (tbl_products.cost_price + tbl_grn_import_products.lkr_unitCost) / (case when tbl_products.cost_price = 0 then 1 else 2 end)
            ,cost_price = tbl_grn_import_products.lkr_unitCost
	where grn_id = p_TransactionID ;
    
    call update_import_grn_branch_cost(p_TransactionID); 
	call update_acc_data(p_TransactionID,p_TransactionType);
    
elseif (p_TransactionType = 'SAMPLES')  
then
 
	insert into InventoryList
	select tbl_sample_products.product_id as ProductID , ifnull(tbl_samples.location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(tbl_sample_products.qty,0)*-1 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_sample_products
	inner join tbl_samples on tbl_samples.sample_id = tbl_sample_products.sample_id
	where tbl_sample_products.sample_id = p_TransactionID;
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
elseif (p_TransactionType = 'SAMPLES_RETURN')  
then
 
	insert into InventoryList
	select srp.product_id as ProductID , ifnull(sr.location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(srp.qty,0) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_sample_return_products srp
	inner join tbl_sample_returns sr on sr.id = srp.sample_return_id
	where srp.sample_return_id = p_TransactionID;
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
elseif (p_TransactionType = 'DAMAGES')
then
 
	insert into InventoryList
	select tbl_damage_products.product_id as ProductID , ifnull(tbl_damage.location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(tbl_damage_products.qty,0)*-1 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_damage_products
    inner join tbl_damage on tbl_damage.damage_id = tbl_damage_products.damage_id
	where tbl_damage_products.damage_id = p_TransactionID;
 		
	call update_acc_data(p_TransactionID,p_TransactionType);
 		

elseif (p_TransactionType = 'GRNReturn') 
then
 
	insert into InventoryList
	select product_id as ProductID , ifnull(tbl_grn_return.location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(qty,0)*-1 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_grn_return_products
    inner join tbl_grn_return on tbl_grn_return.grn_return_id = tbl_grn_return_products.grn_return_id
	where tbl_grn_return_products.grn_return_id = p_TransactionID;
    
	call update_acc_data(p_TransactionID,p_TransactionType);

elseif (p_TransactionType = 'ImportGRNReturn')  
then
 
	insert into InventoryList
	select product_id as ProductID , ifnull(tbl_grn_import_return.location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(qty,0)*-1 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_grn_import_return_products
    inner join tbl_grn_import_return on tbl_grn_import_return.grn_return_id = tbl_grn_import_return_products.grn_return_id
	where tbl_grn_import_return_products.grn_return_id = p_TransactionID;
    
	call update_acc_data(p_TransactionID,p_TransactionType);

elseif (p_TransactionType = 'inventoryTransfer') 
then
 
	insert into InventoryList
	select itlp.product_id as ProductID , ifnull(itl.from_location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(qty,0)*-1 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_inventory_transfer_location_products itlp
    inner join tbl_inventory_transfer_location itl on itl.id = itlp.transfer_id
	where itlp.transfer_id = p_TransactionID;
    
	insert into InventoryList
	select itlp.product_id as ProductID , ifnull(itl.to_location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(qty,0) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_inventory_transfer_location_products itlp
    inner join tbl_inventory_transfer_location itl on itl.id = itlp.transfer_id
	where itlp.transfer_id = p_TransactionID;
    
    call update_product_branch_cost_in_inventory_transfer(p_TransactionID); 
	call update_acc_data(p_TransactionID,p_TransactionType);
    
    
elseif (p_TransactionType = 'Sales') 
then
    insert into InventoryList
	select 
    ( case when ifnull(mi.id,0) = 0 then sip.product_id else mi.product_id end ) as ProductID  
    , (case when _commonInventoryLocation > 0 then _commonInventoryLocation else location_id end ) as LocationID 
    , 0 as ContainerID, 
	0 as OnOrderQty 
    ,IFNULL((( case when ifnull(mi.id,0) = 0 then sip.qty else mi.qty*sip.qty end )/( case when ifnull(mi.id,0) = 0 then sip.uom_value else mi.uom_value end )),0)*-1 as QtyInStock
    ,0 as QtyReserved, 
    
    0  as qtyAllocated,
    0 as call_allocation_sp
	from tbl_sale_invoice_products sip
	inner join tbl_sale_invoice si on si.id = sip.sale_invoice_id
    left join tbl_meal_ingredients mi on mi.meal_id = sip.product_id
	where si.id = p_TransactionID
    and si.status in ('4')
    and si.isInventoryUpdated = 0;
    
    update  tbl_sale_invoice set isInventoryUpdated = 1
    where tbl_sale_invoice.id = p_TransactionID
    and tbl_sale_invoice.status in ('4') 
    and tbl_sale_invoice.isInventoryUpdated = 0; 
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
elseif (p_TransactionType = 'INV_COST')  
then
   insert into InventoryList
	select scp.product_id as ProductID  
    , (case when _commonInventoryLocation > 0 then _commonInventoryLocation else sic.location_id end ) as LocationID 
    , 0 as ContainerID,0 as OnOrderQty ,scp.qty*-1 as QtyInStock,0 as QtyReserved, 
    0 as qtyAllocated,  
    0 as call_allocation_sp
	from tbl_sale_invoice_cost_products scp
	inner join tbl_sale_invoice_cost sic on sic.id = scp.cost_id
	and scp.cost_id = p_TransactionID
    and sic.status in ('4') ; 
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
elseif (p_TransactionType = 'SO')    
then
   insert into InventoryList
	select product_id as ProductID , so.location_id as LocationID , 0 as ContainerID,0 as OnOrderQty ,0 as QtyInStock,0 as QtyReserved, 
    0 as qtyAllocated,  
    0 as call_allocation_sp
	from tbl_so_products sp
	inner join tbl_so so on so.so_id = sp.so_id
	and sp.so_id = p_TransactionID
    and so.status in ('4') ;
    
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
    
elseif (p_TransactionType = 'Sales_cancel')

then


    insert into InventoryList
	select ( case when ifnull(mi.id,0) = 0 then sip.product_id else mi.product_id end ) as ProductID  
    , (case when _commonInventoryLocation > 0 then _commonInventoryLocation else location_id end ) as LocationID 
    , 0 as ContainerID, 
	0 as OnOrderQty ,IFNULL((( case when ifnull(mi.id,0) = 0 then sip.qty else mi.qty*sip.qty end )/( case when ifnull(mi.id,0) = 0 then sip.uom_value else mi.uom_value end )),0)-sum(ifnull(rp.qty/rp.uom_value,0)) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_sale_invoice_products sip
	inner join tbl_sale_invoice si on si.id = sip.sale_invoice_id
	left join tbl_return_products rp on rp.product_id = sip.product_id
    and rp.invoice_id = p_TransactionID
    left join tbl_meal_ingredients mi on mi.meal_id = sip.product_id
	where si.id = p_TransactionID
    and si.status in ('5') 
    and si.is_permanent_cancelled = 1

    and si.isInventoryUpdated = 1
    group by sip.sale_invoice_id,( case when ifnull(mi.id,0) = 0 then sip.product_id else mi.product_id end ); 
    
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
    
elseif (p_TransactionType = 'sales_return')
then
 
	insert into InventoryList
	select product_id as ProductID  
    , (case when _commonInventoryLocation > 0 then _commonInventoryLocation else si.location_id end ) as LocationID 
    , 0 as ContainerID, 0 as OnOrderQty ,IFNULL(qty/uom_value,0) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_return_products
    inner join tbl_sale_invoice si on si.id = tbl_return_products.invoice_id
	where tbl_return_products.return_id = p_TransactionID;
    
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
elseif (p_TransactionType = 'sales_rent_return') 
then
 
	insert into InventoryList
	select product_id as ProductID , location_id as LocationID , 0 as ContainerID, 
	0 as OnOrderQty ,IFNULL(qty/uom_value,0) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,
    0 as call_allocation_sp
	from tbl_sale_invoice_products
	inner join tbl_sale_invoice on tbl_sale_invoice.id = tbl_sale_invoice_products.sale_invoice_id
	and tbl_sale_invoice.id = p_TransactionID
    and tbl_sale_invoice.status in ('4');
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    

elseif (p_TransactionType = 'stock_adjustment') 
then
 
	insert into InventoryList
	select product_id as ProductID , IFNULL(sa.location_id,0) as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(qty,0) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_stock_adjustment_products
    inner join tbl_stock_adjustment sa on sa.id = tbl_stock_adjustment_products.stock_adjustment_id
	where tbl_stock_adjustment_products.stock_adjustment_id = p_TransactionID
    and tbl_stock_adjustment_products.status in ('4');
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
    
elseif (p_TransactionType = 'assemble')
then
 
	insert into InventoryList
	select product_id as ProductID , 0 as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(qty,0) as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_assemble
	where tbl_assemble.id = p_TransactionID
    and tbl_assemble.status in ('4');
 
	insert into InventoryList
	select tbl_assemble_products.product_id as ProductID , 0 as LocationID , 
	0 as ContainerID, 0 as OnOrderQty 
    ,IFNULL(tbl_assemble_products.qty,0)*-1 as QtyInStock
    ,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_assemble_products
    inner join tbl_assemble on tbl_assemble.id = tbl_assemble_products.assemble_id
	where tbl_assemble_products.assemble_id = p_TransactionID
    and tbl_assemble.status in ('4');
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
    
elseif (p_TransactionType = 're_assemble')
then
 
	insert into InventoryList
	select product_id as ProductID , 0 as LocationID , 
	0 as ContainerID, 0 as OnOrderQty ,IFNULL(qty,0)*-1 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_re_assemble
	where tbl_re_assemble.id = p_TransactionID
    and tbl_re_assemble.status in ('4');
 
	insert into InventoryList
	select tbl_re_assemble_products.product_id as ProductID , 0 as LocationID , 
	0 as ContainerID, 0 as OnOrderQty 
    ,IFNULL(tbl_re_assemble_products.qty,0) as QtyInStock
    ,0 as QtyReserved, 0 as qtyAllocated,0 as call_allocation_sp
	from tbl_re_assemble_products
    inner join tbl_re_assemble on tbl_re_assemble.id = tbl_re_assemble_products.re_assemble_id
	where tbl_re_assemble_products.re_assemble_id = p_TransactionID
    and tbl_re_assemble.status in ('4');
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
    
    
 elseif (p_TransactionType = 'dispatch')
then
    insert into InventoryList
	select product_id as ProductID , 0 as LocationID , 0 as ContainerID, 
	0 as OnOrderQty ,IFNULL(qty,0)*-1  as QtyInStock,IFNULL(qty,0)*-1 as QtyReserved, IFNULL(qty,0)*-1  as qtyAllocated,0 as call_allocation_sp
	from tbl_dispatch_products
	where dispatch_id = p_TransactionID;
    
    
	update    tbl_so_products    
	inner join tbl_dispatch_products on tbl_so_products.so_product_id = tbl_dispatch_products.so_product_id
	and tbl_so_products.product_id = tbl_dispatch_products.product_id
	set tbl_so_products.dispatch_qty = ifnull( tbl_so_products.dispatch_qty,0) + qty
	where dispatch_id = p_TransactionID;
    
	call update_acc_data(p_TransactionID,p_TransactionType);
    
elseif (p_TransactionType = 'production_plan')
then
 
		 
		  insert into InventoryList
		 select tbl_products.product_id as ProductID , 0 as LocationID , 0 as ContainerID, 
		 0 as OnOrderQty ,IFNULL(tbl_production_plans_process.mrn_qty,0)*-1 as QtyInStock,
         case when length(tree_id) >1 then IFNULL(tbl_production_plans_process.qty,0)*-1 else 0 end as QtyReserved,
		 case when length(tree_id) >1 then IFNULL(tbl_production_plans_process.mrn_qty,0)*-1 else 0 end as qtyAllocated ,
         0 as call_allocation_sp
		 from tbl_production_plans_process 
		 inner join tbl_products on tbl_products.product_id = tbl_production_plans_process.product_id 
		 where tbl_production_plans_process.plan_id = (select plan_id from tbl_production_plans_process where id = p_TransactionID) 
		 and tbl_production_plans_process.boqId  in (
											select boq_id from tbl_boq  
											where product_id = p_secondID) 
		 and length(tree_id) > 1;
         
         
		  insert into InventoryList
		 select tbl_production_plans_process.product_id as ProductID , 0 as LocationID , 0 as ContainerID, 
		 0 as OnOrderQty ,IFNULL(tbl_production_plans_process.qty,0)  as QtyInStock,
         case when length(tree_id) >1 then IFNULL(tbl_production_plans_process.qty,0) else 0 end as QtyReserved 
         ,0 as qtyAllocated ,  1 as call_allocation_sp
         from tbl_production_plans_process    where tree_id in (      
		 select distinct 
		 SUBSTRING(tbl_production_plans_process.tree_id , 1, length(tbl_production_plans_process.tree_id )-2) as perent_tree 
		 from tbl_production_plans_process 
		 inner join tbl_products on tbl_products.product_id = tbl_production_plans_process.product_id 
		 where tbl_production_plans_process.plan_id = (select plan_id from tbl_production_plans_process where id = p_TransactionID) 
		 and tbl_production_plans_process.boqId  in (
											select boq_id from tbl_boq  
											where product_id = p_secondID) )
         and tbl_production_plans_process.plan_id = (select plan_id from tbl_production_plans_process where id = p_TransactionID)   ;
         
elseif (p_TransactionType = 'mrn_issue')
then

	set @mrn_issue_type:= '';
	select 	mrn_issue_type
		into @mrn_issue_type  
		from tbl_mrn_issues 
		where mrn_issue_id = p_TransactionID;
			
            if(@mrn_issue_type = 'WITH_PRODUCTION_PLAN') then
				insert into InventoryList
				select product_id as ProductID , 0 as LocationID , 0 as ContainerID, 
				0 as OnOrderQty ,0 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,
				 1 as call_allocation_sp
				from tbl_mrn_issue_products 
				where mrn_issue_id = p_TransactionID;
            else 
				insert into InventoryList
				select product_id as ProductID , 0 as LocationID , 0 as ContainerID, 
				0 as OnOrderQty , qty*-1 as QtyInStock,0 as QtyReserved, 0 as qtyAllocated,
				 0 as call_allocation_sp
				from tbl_mrn_issue_products 
				where mrn_issue_id = p_TransactionID;
			end if;


    

elseif (p_TransactionType = 'mrn')
then

set @mrn_type:= '';
	select 	mrn_type
		into @mrn_type  
		from tbl_mrns 
		where mrn_id = p_TransactionID;

		if(@mrn_type = 'WITH_PRODUCTION_PLAN') then
		  update    tbl_mrns    
			inner join tbl_mrn_products on tbl_mrn_products.mrn_id = tbl_mrns.mrn_id
			inner join tbl_production_plans_process on tbl_production_plans_process.plan_id =  tbl_mrns.plan_id
			and tbl_mrn_products.product_id = tbl_production_plans_process.product_id
			set  tbl_production_plans_process.mrn_qty =  tbl_mrn_products.qty  
			where tbl_mrns.mrn_id = p_TransactionID and tbl_mrns.status = 4;
       end if; 
        
end if;

 

OPEN _cursor; 
	getEmail: LOOP
		FETCH _cursor INTO   v_productID ,v_LocationID ,v_ContainerID ,v_OnOrderQty ,v_QtyInStock ,v_QtyReserved,v_QtyAllocated,v_call_allocation_sp;
		IF finished = 1 THEN  
			LEAVE getEmail;
		END IF;
        
        set @count:=0; 
		select  count(*) into @count from tbl_inventory 
        where product_id = v_productID and  location_id = v_LocationID and container_id = v_ContainerID;
        
       if(@count>0)
		then
		
			 UPDATE tbl_inventory
			   SET `qty_in_stock` =  qty_in_stock + v_QtyInStock
				  ,`qty_on_order` = qty_on_order + v_OnOrderQty
				  ,`qty_reserved` = qty_reserved +v_QtyReserved
                  ,`qty_allocated` = qty_allocated +v_QtyAllocated 
				  ,`modified_by` = p_User
				  ,`modified_date_time` = NOW(3)
			 where product_id = v_productID and  location_id =  v_LocationID and container_id = v_ContainerID;
  
		else
		
			INSERT INTO tbl_inventory (`location_id`,`container_id`,`product_id`,
			`qty_in_stock`,`qty_on_order`,`qty_reserved`, `created_by`,`created_date_time`,
            `modified_by`,`modified_date_time`,`qty_allocated` )
			 VALUES
			   (v_LocationID
			   ,v_ContainerID
			   ,v_productID
			   ,v_QtyInStock
			   ,v_OnOrderQty 
			   ,v_QtyReserved 
			   ,p_User
			   ,NOW(3)
			   ,p_User
			   ,NOW(3)
               ,v_QtyAllocated);
  
		end if;
        
      
      
          if (v_call_allocation_sp = 1) then
       
			set @p_TransactionType = p_TransactionType;
			set @p_TransactionID = p_TransactionID;
			set @p_productID = v_productID;
			set @p_LocationID = v_LocationID;
			set @p_User = p_User;
		 	call Update_allocation_qty(@p_TransactionType, @p_TransactionID, @p_productID, @p_LocationID, @p_User);
            	end if;
            
            
            
	 
    INSERT INTO tbl_inventory_log (`location_id`,`container_id`,`product_id`,
	`qty_in_stock`,`qty_on_order`,`qty_reserved`, `created_by`,`created_date_time`,
	`modified_by`,`modified_date_time`,`qty_allocated`,`transaction_type`,`transaction_id` )
	 VALUES
	   (v_LocationID
	   ,v_ContainerID
	   ,v_productID
	   ,v_QtyInStock
	   ,v_OnOrderQty 
	   ,v_QtyReserved 
	   ,p_User
	   ,NOW(3)
	   ,p_User
	   ,NOW(3)
	   ,v_QtyAllocated
	   ,p_TransactionType
	   ,p_TransactionID 
       );
		
        
END LOOP getEmail;
CLOSE _cursor;

  end ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `updateOldPaymentallocation` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `updateOldPaymentallocation`()
BEGIN

declare v_ps_id int;
DECLARE finished INTEGER DEFAULT 0; 

DECLARE _cursor CURSOR FOR SELECT tbl_payment_summary.id
FROM tbl_payment_summary;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1; 


OPEN _cursor; 
	getEmail: LOOP
		FETCH _cursor INTO   v_ps_id ;
		IF finished = 1 THEN  
			LEAVE getEmail;
		END IF;
        
        
        call update_payment_allocation(v_ps_id);
 
END LOOP getEmail;
CLOSE _cursor;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_acc_data` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_acc_data`(`_tid` INT, `_type` VARCHAR(50))
BEGIN  

/* payment_adjustment - tbl_payment_adjustments
supplier_payments - tbl_supplier_payments
over_payments - tbl_overpayments
payment_summary - tbl_payment_summary
canceled_payments - tbl_canceled_payments
expenses - tbl_expenses
comisions - tbl_comisions
daily_cash - tbl_daily_cash 
///others in UpdateInventory/// */

 DECLARE v_SQL TEXT DEFAULT '';
    DECLARE finished_invoice INT DEFAULT 0;
    DECLARE exit_error INT DEFAULT 0;
    DECLARE error_message TEXT;

    -- Cursor declaration
    DECLARE _cursor_invoice CURSOR FOR 
        SELECT scripts FROM tbl_acc_events WHERE type = _type;

    -- Handlers
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished_invoice = 1;

    -- Error handler to simulate CATCH block
    DECLARE EXIT HANDLER FOR SQLEXCEPTION 
    BEGIN
        SET exit_error = 1;
        SET error_message = CONCAT('SQL Error executing: ', v_SQL);
        select error_message;
        -- Optionally log to an error table:
        INSERT INTO `tbl_acc_event_log`( `msg`, `status`, `created_on`, `event`, `transaction_id`) VALUES (error_message,'error',now(),_type,_tid);
    END;

    OPEN _cursor_invoice;

    getEmail_invoice:LOOP
        FETCH _cursor_invoice INTO v_SQL;

        IF finished_invoice = 1 THEN  
            LEAVE getEmail_invoice;
        END IF;

        SET @sql = v_SQL;
        SET @Selected_tid = _tid;

        PREPARE stmt FROM @sql;
        EXECUTE stmt USING @Selected_tid;
        DEALLOCATE PREPARE stmt;
        
        INSERT INTO `tbl_acc_event_log`( `msg`, `status`, `created_on`, `event`, `transaction_id`) VALUES (v_SQL,'success',now(),_type,_tid);

        -- Optionally check if error occurred
        IF exit_error = 1 THEN
            LEAVE getEmail_invoice;
        END IF;
    END LOOP getEmail_invoice; 

    CLOSE _cursor_invoice;  
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `Update_allocation_qty` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `Update_allocation_qty`(IN `p_TransactionType` VARCHAR(50), IN `p_TransactionID` INT, IN `p_productID` INT, IN `p_LocationID` INT, IN `p_User` VARCHAR(50))
BEGIN

declare v_ID int;
declare v_tree_id varchar(50);
declare v_qty decimal(18,6); 
declare v_allocsated_qty decimal(18,6); 
DECLARE finished INTEGER DEFAULT 0; 

DECLARE _cursor CURSOR FOR select id,tree_id,qty,allocated_qty from tbl_production_plans_process
inner join tbl_production_plans on tbl_production_plans.plan_id = tbl_production_plans_process.plan_id
where product_id = p_productID  and allocated_qty <> qty and length(tree_id) > 1
order by tbl_production_plans.plan_date ASc , tree_id desc;
 
DECLARE _cursor_sale CURSOR FOR select so_product_id as id,tbl_so.so_id,ContractQty,allocated_qty from tbl_so_products
inner join tbl_so on tbl_so.so_id = tbl_so_products.so_id
where product_id = p_productID  and allocated_qty <> ContractQty
order by tbl_so.so_date ASc  ;


DECLARE _cursor_mrn_issue CURSOR FOR   
select tbl_production_plans_process.id,tree_id,tbl_mrn_issue_products.qty,allocated_qty from tbl_mrn_issue_products 
inner join tbl_production_plans_process on tbl_production_plans_process.plan_id =  tbl_mrn_issue_products.plan_id
and tbl_mrn_issue_products.product_id = tbl_production_plans_process.product_id
where mrn_issue_id = p_TransactionID and  tbl_mrn_issue_products.product_id = p_productID; 

DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1; 
 

  if(p_TransactionType = 'production_plan')then

 OPEN _cursor; 
	getEmail: LOOP
		FETCH _cursor INTO   v_ID ,v_tree_id ,v_qty,v_allocsated_qty;
		IF finished = 1 THEN  
			LEAVE getEmail;
		END IF;
        
set @balance:=0; 
select ifnull(qty_in_stock,0) - ifnull(qty_allocated,0)  into @balance from tbl_inventory 
where product_id = p_productID and  location_id = p_LocationID ;
    
	if( ifnull(@balance,0)>0) then
		
 
        
        set @update_allocated_qty=0; 
        set @update_allocated_qty=v_qty-v_allocsated_qty; 
        
        if(@update_allocated_qty> @balance) then
				update tbl_production_plans_process  set allocated_qty = allocated_qty+  @balance ,
                  mrn_qty = allocated_qty+  @balance  
					where id = v_ID;
                
				update tbl_inventory set qty_allocated = qty_allocated+  @balance
					where product_id = p_productID and  location_id = p_LocationID ;
                
		elseif(@update_allocated_qty <= @balance) then
				update tbl_production_plans_process 
                set allocated_qty = allocated_qty+  @update_allocated_qty  , 
                 mrn_qty = mrn_qty+  @update_allocated_qty  
                where id = v_ID;
                
                update tbl_inventory set qty_allocated = qty_allocated+   @update_allocated_qty
					where product_id = p_productID and  location_id = p_LocationID ;
        end if;
        
        

        
       
	end if;
 END LOOP getEmail;
 CLOSE _cursor;
  end if;



 set finished = 0;
 if(p_TransactionType = 'mrn_issue')then

 OPEN _cursor_mrn_issue; 
	getEmail: LOOP
		FETCH _cursor_mrn_issue INTO   v_ID ,v_tree_id ,v_qty,v_allocsated_qty;
		IF finished = 1 THEN  
			LEAVE getEmail;
		END IF;
        
set @balance:=0; 
select ifnull(qty_in_stock,0) - ifnull(qty_allocated,0)  into @balance from tbl_inventory 
where product_id = p_productID and  location_id = p_LocationID ;
    
	if( ifnull(@balance,0)>0) then
		
 
        
        set @update_allocated_qty=0; 
        set @update_allocated_qty=v_qty; 
        
        if(@update_allocated_qty> @balance) then
				update tbl_production_plans_process  set allocated_qty = allocated_qty+  @balance 
					where id = v_ID;
                
				update tbl_inventory set qty_allocated = qty_allocated+  @balance
					where product_id = p_productID and  location_id = p_LocationID ;
                
		elseif(@update_allocated_qty <= @balance) then
				update tbl_production_plans_process 
                set allocated_qty = allocated_qty + @update_allocated_qty  where id = v_ID;
                
                update tbl_inventory set qty_allocated = qty_allocated+   @update_allocated_qty
					where product_id = p_productID and  location_id = p_LocationID ;
        end if;
        
        

        
       
	end if;
 END LOOP getEmail;
 CLOSE _cursor_mrn_issue;
  end if;


 set finished = 0;
 
  OPEN _cursor_sale; 
	getfinesh: LOOP
		FETCH _cursor_sale INTO   v_ID ,v_tree_id ,v_qty,v_allocsated_qty;
		IF finished = 1 THEN  
			LEAVE getfinesh;
		END IF;
        
set @balance:=0; 
select ifnull(qty_in_stock,0) - ifnull(qty_allocated,0)  into @balance from tbl_inventory 
where product_id = p_productID and  location_id = p_LocationID ;
    
	if( ifnull(@balance,0)>0) then
		
 
        
        set @update_allocated_qty=0; 
        set @update_allocated_qty=v_qty-v_allocsated_qty; 
        
        if(@update_allocated_qty> @balance) then
				update tbl_so_products  set allocated_qty =  allocated_qty+  @balance 
					where so_product_id = v_ID;
                
				update tbl_inventory set qty_allocated = qty_allocated+  @balance
					where product_id = p_productID and  location_id = p_LocationID ;
                
		elseif(@update_allocated_qty <= @balance) then
				update tbl_so_products 
                set allocated_qty = @update_allocated_qty  
                where so_product_id = v_ID;
                
                update tbl_inventory set qty_allocated = qty_allocated+   @update_allocated_qty
					where product_id = p_productID and  location_id = p_LocationID ;
        end if;
        
        

        
       
	end if;
 END LOOP getfinesh;
 CLOSE _cursor_sale;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_allSearchedProductPrices` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_allSearchedProductPrices`(`_productName` VARCHAR(50), `_productCode` VARCHAR(50), `_categoryId` INT, `_pracentage` DECIMAL)
BEGIN

UPDATE tbl_products 
inner join tbl_productcategory on tbl_productcategory.productCategory_id = tbl_products.category_id
SET price = (tbl_products.price + (tbl_products.price*_pracentage)/100)
 , price_last_updated_on = NOW()
where tbl_products.is_delete = 0 
and (tbl_products.name like concat('%',_productName,'%') or _productName = '')
and (tbl_products.code like concat('%',_productCode,'%') or _productCode = '')
and tbl_products.category_id = _categoryId; 


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_import_grn_branch_cost` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_import_grn_branch_cost`(`_grnId` INT)
BEGIN
 
DECLARE _finished INTEGER DEFAULT 0; 
declare _grnAmount decimal(18,2);
declare _chargesPer decimal(18,2);
declare _dutiesPer decimal(18,2);
declare _rate decimal(18,2);
declare _itemCost decimal(18,2); 
declare _itemNetCost decimal(18,2); 
declare _itemNetAvgCost decimal(18,2); 
declare _locationId int; 

declare c_id int; 
declare c_productId int; 
declare c_qty decimal(18,2);  
declare c_total decimal(18,2); 
declare c_hs_code varchar(100); 
 
DECLARE _productCostCursor CURSOR FOR select grn_product_id,(qty+inventoryFreeQty) as qty,total,product_id,hs_code from tbl_grn_import_products where grn_id = _grnId;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _finished = 1;  
 
set _grnAmount = 0;
set _chargesPer = 0;
set _dutiesPer = 0;
set _rate = 0; 

select total,round((total_charges/total),2),round((total_duties/total),2),exchange_rate,location_id
into _grnAmount,_chargesPer,_dutiesPer,_rate,_locationId
from tbl_grn_imports
where grn_id = _grnId ;



OPEN _productCostCursor; 
	productCost: LOOP
		FETCH _productCostCursor INTO  c_id,c_qty,c_total,c_productId,c_hs_code;
		IF _finished = 1 THEN  
			LEAVE productCost;
		END IF;
        
        select sum(total) into _grnAmount
        from tbl_grn_import_products
        where grn_id = _grnId 
        and hs_code = c_hs_code;
         
        select round((sum(amount)/_grnAmount),2) into _dutiesPer 
		from tbl_grn_import_product_duties
		where grn_id = _grnId  
        and hs_code = c_hs_code;
         
        set _itemCost = round((c_total/c_qty),2);
        set _itemNetCost = (_itemCost*ifnull(_chargesPer,0)) + (_itemCost*ifnull(_dutiesPer,0)) + (_itemCost*_rate);
         
        set @count:=0; 
		select  count(*),avg_cost 
        into @count,_itemNetAvgCost from tbl_product_branch_cost 
        where product_id = c_productId 
        and  location_id = _locationId;
        
        UPDATE `tbl_grn_import_products` SET  
        `calculated_cost` =  _itemNetCost 
        , `item_charges` = (_itemCost*ifnull(_chargesPer,0)) 
        , `item_duties` = (_itemCost*ifnull(_dutiesPer,0)) 
        , `lkr_price` = (_itemCost*_rate)
        WHERE `grn_product_id` = c_id ;
        
       if(@count>0)
		then
		
			 UPDATE tbl_product_branch_cost
			   SET `cost` =  _itemNetCost
				  ,`avg_cost` = (_itemNetCost+_itemNetAvgCost)/2
				  ,`created_on` = NOW(3)
			 where product_id = c_productId and  location_id = _locationId; 
  
		else
		
			INSERT INTO tbl_product_branch_cost (`cost`,`avg_cost`,`created_on`, `product_id`,`location_id`)
			 VALUES
			   (_itemNetCost,_itemNetCost,NOW(3),c_productId,_locationId);
  
		end if;
        
        
        
END LOOP productCost;
CLOSE _productCostCursor;
 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_invoice_allocation` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_invoice_allocation`(`_psId` INT, `v_id` INT, `v_payment_type` VARCHAR(50), `v_payment_type_amount` DECIMAL(18,8), `v_over_payment` DECIMAL(18,8), `v_over_payment_used` DECIMAL(18,8), `v_over_payment_cal` DECIMAL(18,8))
BEGIN
declare v_invoice_id int;
declare v_invoice_pay_amount decimal(18,8);
declare v_payment_type_amount_used decimal(18,8);
DECLARE finished_invoice INTEGER DEFAULT 0;

DECLARE _cursor_invoice CURSOR FOR 
select sale_invoice_id, (payAmount - allocated_amount) as payAmount from tbl_payment_summary_invoices where ps_id = _psId 
and (payAmount - allocated_amount) > 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished_invoice = 1;

set v_payment_type_amount_used = 0;

OPEN _cursor_invoice; 
	getEmail_invoice:LOOP
		FETCH _cursor_invoice INTO   v_invoice_id,v_invoice_pay_amount ;
		IF finished_invoice = 1 THEN  
			LEAVE getEmail_invoice;
		END IF;
        
        if( (v_payment_type_amount-v_over_payment_cal - v_payment_type_amount_used) >0 ) then
        
         
        if((v_payment_type_amount-v_over_payment_cal - v_payment_type_amount_used) >= (v_invoice_pay_amount)) then
              INSERT INTO `tbl_payment_allocation`
							(`invoice_id`,
							`allocation_amount`,`ps_id`,`payment_type`,`payment_id`,
							`created_on`)
							VALUES
							(
							v_invoice_id,
							(v_invoice_pay_amount),
							_psId,
							v_payment_type,
							v_id,
							NOW(3));
				update tbl_payment_summary_invoices set allocated_amount =allocated_amount +v_invoice_pay_amount
                where tbl_payment_summary_invoices.ps_id = _psId and sale_invoice_id = v_invoice_id;
           set v_payment_type_amount_used =  v_payment_type_amount_used +v_invoice_pay_amount;

        else
                      INSERT INTO `tbl_payment_allocation`
							(`invoice_id`,
							`allocation_amount`,`ps_id`,`payment_type`,`payment_id`,
							`created_on`)
							VALUES
							(
							v_invoice_id,
							(v_payment_type_amount-v_over_payment_cal-v_payment_type_amount_used),
							_psId,
							v_payment_type,
							v_id,
							NOW(3));
                            
              update tbl_payment_summary_invoices set allocated_amount = allocated_amount + (v_payment_type_amount-v_over_payment_cal-v_payment_type_amount_used)
												where tbl_payment_summary_invoices.ps_id = _psId and sale_invoice_id = v_invoice_id;
       
			set v_payment_type_amount_used =  v_payment_type_amount_used + (v_payment_type_amount-v_over_payment_cal-v_payment_type_amount_used);
       end if;
        
		end if;


		END LOOP getEmail_invoice;
CLOSE _cursor_invoice;  
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_invoice_returns` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_invoice_returns`(IN `_invoiceId` INT, IN `_productId` INT, IN `_type` VARCHAR(50))
BEGIN

if(_type = 'invoice_return') 
then

update tbl_sale_invoice set rpt_returns_amount = ( 
select ifnull(sum(tbl_customer_returns.amount),0)
from tbl_customer_returns
where tbl_customer_returns.sale_invoice_id = _invoiceId
and tbl_customer_returns.status = '4'
and (tbl_customer_returns.return_type = 'CASH_RETURNS'
or tbl_customer_returns.return_type = 'CREDIT_RETURNS') 
) where tbl_sale_invoice.id = _invoiceId;

update tbl_sale_invoice set rpt_cash_returns = ( 
select ifnull(sum(tbl_customer_returns.amount),0)
from tbl_customer_returns
where tbl_customer_returns.sale_invoice_id = _invoiceId
and tbl_customer_returns.status = '4'
and tbl_customer_returns.return_type = 'CASH_RETURNS'
) where tbl_sale_invoice.id = _invoiceId;

elseif(_type = 'invoice_product')
then

update tbl_sale_invoice_products set returned_qty = (
select ifnull(sum(tbl_return_products.qty),0)
from tbl_return_products
where tbl_return_products.invoice_id = _invoiceId
and tbl_return_products.sale_invoice_product_id = _productId
) where tbl_sale_invoice_products.id = _productId
and tbl_sale_invoice_products.sale_invoice_id = _invoiceId;

end if; 

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_invoice_values` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_invoice_values`(IN `_invId` INT)
BEGIN

declare isSVAT boolean default 0;
declare subTotal decimal(16,2) default 0;
declare billDiscount decimal(16,2) default 0;
declare billTax decimal(16,2) default 0;
declare billWithDiscount decimal(16,2) default 0;
declare billNetTotal decimal(16,2) default 0;

select is_svat into isSVAT
from tbl_sale_invoice si
inner join tbl_customers c on c.customer_id = si.customer_id 
where si.id =  _invId;

select  sum(net_total)   into subTotal
from tbl_sale_invoice_products sip
where sip.sale_invoice_id = _invId;

select 
( case when si.discount_type = '%' then (subTotal/100)*discount_rate else discount_rate end)  as discount into billDiscount
from tbl_sale_invoice si
where si.id =  _invId;

set billWithDiscount = subTotal-billDiscount;

select  
( case when isSVAT = 1 then 
			round(((billWithDiscount * SUBSTRING_INDEX(bill_tax, '~', -1) )/( SUBSTRING_INDEX(bill_tax, '~', -1) + 100)),2)
		else round(((billWithDiscount/100)*SUBSTRING_INDEX(bill_tax, '~', -1)),2) end ) as tax  into billTax 
from tbl_sale_invoice si
inner join tbl_customers c on c.customer_id = si.customer_id
where bill_tax != '0' 
and si.id =  _invId;

set billNetTotal = billWithDiscount;

if isSVAT = 0
then
 set billNetTotal = billWithDiscount+billTax;
end if;

UPDATE `tbl_sale_invoice` 
	SET `_billSub`= sub_total , `_billNet`= net_total ,`sub_total`= subTotal , `net_total`= billNetTotal 
where id = _invId;  


/*select * 
 
from (
	select

	round((((total-discount) * SUBSTRING_INDEX(tax, '~', -1) )/( SUBSTRING_INDEX(tax, '~', -1) + 100)),2)
	,round((((total-discount)/100)*SUBSTRING_INDEX(tax, '~', -1)),2)
	,(total-discount) as _total
	from (
		select 
		 round(((qty/uom_value)*unit_price),2) as total
		,round(( case when sip.discount_type = '%' then (((qty/uom_value)*unit_price)/100)*discount_rate else discount_rate end),2) as discount 
		,tax
		from tbl_sale_invoice_products sip
	) tmp
) tmpp*/


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_payment_allocation` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_payment_allocation`(`_psId` INT)
BEGIN
declare v_id int;
declare v_payment_type varchar(50); 
declare v_payment_type_amount decimal(18,8);
declare v_over_payment decimal(18,8);
declare v_over_payment_used decimal(18,8); 

 

DECLARE finished INTEGER DEFAULT 0; 

DECLARE _cursor CURSOR FOR SELECT tbl_payment_summary_details.id,payment_type,

case when payment_type ='CASH' then tbl_payment_summary_details.amount - (tbl_payment_summary.amount  - rpt_receivableTotal - ifnull(tbl_overpayments.amount,0) )
else tbl_payment_summary_details.amount end as payment_type_amount,
ifnull(tbl_overpayments.amount,0) as over_payment

FROM tbl_payment_summary_details 
inner join tbl_payment_summary on tbl_payment_summary.id = tbl_payment_summary_details.ps_id
left join tbl_overpayments on tbl_overpayments.ps_id = tbl_payment_summary.id 
where tbl_payment_summary_details.ps_id = _psId
order by tbl_payment_summary_details.id;



DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;  
set v_over_payment_used =0;

 
OPEN _cursor; 
	getEmail: LOOP
		FETCH _cursor INTO   v_id ,v_payment_type ,v_payment_type_amount ,v_over_payment ;
		IF finished = 1 THEN  
			LEAVE getEmail;
		END IF;
        
        set @over_payment:=0; 
		if(v_payment_type_amount >= (v_over_payment-v_over_payment_used)) then
			set @over_payment:=v_over_payment-v_over_payment_used; 
		else 
			set @over_payment:=v_payment_type_amount; 
		end if;
            
        call update_invoice_allocation(_psId,v_id ,v_payment_type ,v_payment_type_amount ,v_over_payment,v_over_payment_used,@over_payment);
 
set  v_over_payment_used=v_over_payment_used+@over_payment;
          
      
END LOOP getEmail;
CLOSE _cursor;
 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_production_status` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_production_status`()
BEGIN

UPDATE tbl_production_plans AS b
INNER JOIN  
 (
select  plan_id  ,
case when sum(qty)  = sum(allocated_qty) then 4 
	 when sum(qty) > 0  and sum(allocated_qty) = 0 then 3 
     when sum(qty) > 0  and sum(allocated_qty) >0 and sum(qty) != sum(allocated_qty) then 2 end as status
 from tbl_production_plans_process
 where length(tree_id) > 1 
 group by plan_id) tmp on  tmp.plan_id = b.plan_id
 SET b.status = tmp.status;
 
 
UPDATE tbl_so AS b
INNER JOIN  
 (
 select  tbl_so_products.so_id  ,sum(ContractQty) , sum(dispatch_qty),
case when   ifnull(is_invoiced,0) = 1 and  sum(dispatch_qty) = sum(allocated_qty)  then 11
	 when   ifnull(is_invoiced,0) = 1 and  sum(dispatch_qty) != sum(allocated_qty)  then 10
	 when sum(ContractQty)  = sum(allocated_qty) and ifnull(is_invoiced,0) = 1 then 9
	 when sum(ContractQty)  = sum(allocated_qty) then 8 
	 when sum(ContractQty) > 0  and sum(allocated_qty) = 0 then 6 
     when sum(ContractQty) > 0  and sum(allocated_qty) >0 and sum(ContractQty) != sum(allocated_qty) then 7 end as status
 from tbl_so_products
  inner join tbl_so on tbl_so.so_id = tbl_so_products.so_id
  group by tbl_so_products.so_id) tmp on  tmp.so_id = b.so_id
 SET b.status = tmp.status;
   
   
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_product_branch_cost` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_product_branch_cost`(`p_TransactionID` INT)
BEGIN
 
DECLARE _finished INTEGER DEFAULT 0;  
declare pc_LocationID int;
declare pc_productID int;
declare pc_cost decimal(18,2);
declare pc_avgCost decimal(18,2);
declare _grnTotalDiscount decimal(18,2);
declare _grnTransport decimal(18,2);
declare _grnTotalQty decimal(18,2);
declare _itemBillDiscount decimal(18,2);
declare _itemTotal decimal(18,2);
declare _oldCost decimal(18,2);


DECLARE _productCostCursor CURSOR FOR select cost,avg_cost,product_id,location_id from ProductCostList;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _finished = 1;  

 
drop temporary table if exists ProductCostList;
create temporary table  ProductCostList(cost decimal(18,4),avg_cost decimal(18,4),product_id int,location_id int);

set _grnTotalDiscount = 0;
set _grnTotalQty = 0;
set _grnTransport = 0;
select discount,sub_total,transport
into _grnTotalDiscount,_itemTotal,_grnTransport
from tbl_grns
where grn_id = p_TransactionID ;

select sum(qty) into _grnTotalQty
from tbl_grn_products
where grn_id = p_TransactionID ;

set _itemBillDiscount = _grnTotalDiscount/_grnTotalQty;

insert into ProductCostList
select  (tbl_grn_products.total/(tbl_grn_products.inventoryFreeQty+tbl_grn_products.qty)) - (((tbl_grn_products.total/_itemTotal)*_grnTotalDiscount)/tbl_grn_products.qty) + (((tbl_grn_products.total/_itemTotal)*_grnTransport)/tbl_grn_products.qty) as pc_cost
,(tbl_products.cost_price + (tbl_grn_products.total/(tbl_grn_products.inventoryFreeQty+tbl_grn_products.qty)) - ((((tbl_grn_products.total/_itemTotal)*_grnTotalDiscount)/tbl_grn_products.qty))  + (((tbl_grn_products.total/_itemTotal)*_grnTransport)/tbl_grn_products.qty) )/ (case when tbl_products.cost_price = 0 then 1 else 2 end) as pc_avgCost
,tbl_grn_products.product_id as pc_productID
, ifnull(tbl_grns.location_id,0) as pc_LocationID
from tbl_grn_products
inner join tbl_grns on tbl_grns.grn_id = tbl_grn_products.grn_id
inner join tbl_products on tbl_products.product_id = tbl_grn_products.product_id
where tbl_grn_products.grn_id = p_TransactionID
and tbl_grns.status = 4;

OPEN _productCostCursor; 
	productCost: LOOP
		FETCH _productCostCursor INTO  pc_cost,pc_avgCost,pc_productID,pc_LocationID;
		IF _finished = 1 THEN  
			LEAVE productCost;
		END IF;
        
        set @count:=0; 
		select  count(*),cost into @count,_oldCost from tbl_product_branch_cost 
        where product_id = pc_productID and  location_id = pc_LocationID limit 0,1;
        
       if(@count>0)
		then
		
			 UPDATE tbl_product_branch_cost
			   SET `cost` =  pc_cost
				  ,`avg_cost` = pc_cost
				  ,`created_on` = NOW(3)
			 where product_id = pc_productID and  location_id = pc_LocationID; 
  
		else
		
			INSERT INTO tbl_product_branch_cost (`cost`,`avg_cost`,`created_on`, `product_id`,`location_id`)
			 VALUES
			   (pc_cost,pc_cost,NOW(3),pc_productID,pc_LocationID);
  
		end if;
        
END LOOP productCost;
CLOSE _productCostCursor;



  

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_product_branch_cost_in_inventory_transfer` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_product_branch_cost_in_inventory_transfer`(`p_TransactionID` INT)
BEGIN

DECLARE _finished INTEGER DEFAULT 0;  
declare pc_LocationID int;
declare pc_productID int;
declare pc_cost decimal(18,2);
declare pc_avgCost decimal(18,2); 


DECLARE _productCostCursor CURSOR FOR select cost,avg_cost,product_id,location_id from ProductCostList;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _finished = 1;  

 
drop temporary table if exists ProductCostList;
create temporary table  ProductCostList(cost decimal(18,4),avg_cost decimal(18,4),product_id int,location_id int);
 

insert into ProductCostList
select 
ifnull(fbc.cost,0) as pc_cost
,((ifnull(fbc.cost,0) + ifnull(tbc.cost,0)) / (case when ifnull(fbc.cost,0) > 0 && ifnull(tbc.cost,0) > 0 then 2 else 1 end)) as pc_avgCost
,p.product_id as pc_productID
,il.to_location_id as pc_LocationID
from tbl_inventory_transfer_location_products lp
inner join tbl_inventory_transfer_location il on il.id = lp.transfer_id
inner join tbl_products p on p.product_id = lp.product_id
left join tbl_product_branch_cost fbc on fbc.location_id = il.from_location_id
and fbc.product_id = lp.product_id 
left join tbl_product_branch_cost tbc on tbc.location_id = il.to_location_id
and tbc.product_id = lp.product_id 
where il.status = '4'
and lp.transfer_id = p_TransactionID;

OPEN _productCostCursor; 
	productCost: LOOP
		FETCH _productCostCursor INTO  pc_cost,pc_avgCost,pc_productID,pc_LocationID;
		IF _finished = 1 THEN  
			LEAVE productCost;
		END IF;
        
        set @count:=0; 
		select  count(*) into @count from tbl_product_branch_cost 
        where product_id = pc_productID and  location_id = pc_LocationID;
        
       if(@count>0)
		then
		
			 UPDATE tbl_product_branch_cost
			   SET `cost` =  pc_cost
				  ,`avg_cost` = pc_avgCost
				  ,`created_on` = NOW(3)
			 where product_id = pc_productID and  location_id = pc_LocationID; 
  
		else
		
			INSERT INTO tbl_product_branch_cost (`cost`,`avg_cost`,`created_on`, `product_id`,`location_id`)
			 VALUES
			   (pc_cost,pc_avgCost,NOW(3),pc_productID,pc_LocationID); 
  
		end if;
        
END LOOP productCost;
CLOSE _productCostCursor;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_settled_amount` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_settled_amount`(IN `_type` VARCHAR(50), IN `_parentId` INT, IN `_psId` INT)
BEGIN

if(_type = 'RETURNS') 
then

update tbl_customer_returns set rpt_settled_amount = (
select ifnull(sum(tbl_payment_summary_details.amount),0)
from tbl_payment_summary_details
where tbl_payment_summary_details.payment_type in ('OUTSTANDING')
and tbl_payment_summary_details.outstanding_type in ('RETURNS')
and tbl_payment_summary_details.outstanding_parent_id = _parentId
) where tbl_customer_returns.id = _parentId;

update tbl_customer_returns set is_settled = 1
where tbl_customer_returns.id = _parentId
and tbl_customer_returns.amount = tbl_customer_returns.rpt_settled_amount;

elseif(_type = 'ADJUSTMENT') 
then

update tbl_payment_adjustments set rpt_settled_amount = (
select ifnull(sum(tbl_payment_summary_details.amount),0)
from tbl_payment_summary_details
where tbl_payment_summary_details.payment_type in ('OUTSTANDING')
and tbl_payment_summary_details.outstanding_type in ('ADJUSTMENT')
and tbl_payment_summary_details.outstanding_parent_id = _parentId
) where tbl_payment_adjustments.id = _parentId;

update tbl_payment_adjustments set is_settled = 1
where tbl_payment_adjustments.id = _parentId
and tbl_payment_adjustments.amount = tbl_payment_adjustments.rpt_settled_amount;

elseif(_type = 'OVER_PAYMENTS')
then

update tbl_overpayments set rpt_settled_amount = (
select ifnull(sum(tbl_payment_summary_details.amount),0)
from tbl_payment_summary_details
where tbl_payment_summary_details.payment_type in ('OUTSTANDING')
and tbl_payment_summary_details.outstanding_type in ('OVER_PAYMENTS')
and tbl_payment_summary_details.outstanding_parent_id = _parentId
) where tbl_overpayments.id = _parentId;

update tbl_overpayments set is_settled = 1
where tbl_overpayments.id = _parentId
and tbl_overpayments.amount = tbl_overpayments.rpt_settled_amount;

elseif(_type = 'ADVANCE')
then

update tbl_payment_summary set rpt_settled_amount = (
select ifnull(sum(tbl_payment_summary_details.amount),0)
from tbl_payment_summary_details
where tbl_payment_summary_details.payment_type in ('OUTSTANDING')
and tbl_payment_summary_details.outstanding_type in ('ADVANCE')
and tbl_payment_summary_details.outstanding_parent_id = _parentId
) where tbl_payment_summary.id = _parentId;

update tbl_payment_summary set is_settled = 1
where tbl_payment_summary.id = _parentId
and tbl_payment_summary.amount = tbl_payment_summary.rpt_settled_amount;

elseif(_type = 'SALE_INVOICE')
then

update tbl_sale_invoice set rpt_settled_amount = (
select ifnull(sum(tbl_payment_summary_invoices.payAmount),0)
from tbl_payment_summary_invoices
where tbl_payment_summary_invoices.sale_invoice_id = _parentId
and tbl_payment_summary_invoices.is_cancelled = 0
) where tbl_sale_invoice.id = _parentId;

update tbl_sale_invoice set is_settled = 1
where tbl_sale_invoice.id = _parentId
and (tbl_sale_invoice.rpt_settled_amount - tbl_sale_invoice.rpt_cash_returns) = (tbl_sale_invoice.net_total - tbl_sale_invoice.rpt_returns_amount);

update tbl_payment_summary set rpt_receivableTotal = (
select ifnull(sum(payAmount),0)
from tbl_payment_summary_invoices
where tbl_payment_summary_invoices.ps_id = _psId
and tbl_payment_summary_invoices.is_cancelled = 0 )
where tbl_payment_summary.id = _psId
;

elseif(_type = 'PAYMENT_CANCELLED')
then

update tbl_sale_invoice set rpt_settled_amount = (
select ifnull(sum(tbl_payment_summary_invoices.payAmount),0)
from tbl_payment_summary_invoices
where tbl_payment_summary_invoices.sale_invoice_id = _parentId
and tbl_payment_summary_invoices.is_cancelled = 0
) where tbl_sale_invoice.id = _parentId;

update tbl_sale_invoice set is_settled = 0
where tbl_sale_invoice.id = _parentId
and tbl_sale_invoice.net_total > tbl_sale_invoice.rpt_settled_amount; 


end if;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_supplier_rpt_details` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_supplier_rpt_details`(IN `supId` INT)
BEGIN

declare _grnSettledTotal decimal(18,4) default 0; 
declare _adjustmentSettledTotal decimal(18,4) default 0; 
declare _grnTotal decimal(18,4) default 0; 
declare _adjustmentTotal decimal(18,4) default 0; 
declare _returnTotal decimal(18,4) default 0; 

declare _grnImportSettledTotal decimal(18,4) default 0; 
declare _grnImportTotal decimal(18,4) default 0;
declare _returnImportTotal decimal(18,4) default 0; 


select sum(ifnull(sp.amount,0)) into _grnSettledTotal
from tbl_supplier_payments sp
inner join tbl_grns AS grn  ON grn.grn_id = sp.grn_id
where sp.supplier_id = supId
and sp.type = 'GRN'
and sp.is_returned = 0
and sp.status = '4';


select sum(ifnull(pa.amount-pa.rpt_settled_amount,0)) into _adjustmentSettledTotal
from tbl_payment_adjustments pa
left join tbl_grns AS grn  ON grn.grn_id = pa.grn_id
where grn.supplier_id = supId
and pa.status = '4';


select sum(ifnull(grn.total,0)) into _grnTotal
from tbl_grns grn
WHERE grn.supplier_id = supId
AND grn.status = '4';


select ifnull(sum(amount-rpt_settled_amount),0) into _adjustmentTotal
from tbl_payment_adjustments pa
inner join tbl_grns grn on grn.grn_id = pa.grn_id
where grn.supplier_id = supId
AND pa.status = '4';

select ifnull(sum(total),0) into _returnTotal
from tbl_grn_return grnR
where grnR.supplier_id = supId
AND grnR.status = '4'; 


select sum(ifnull(sp.amount,0)) into _grnImportSettledTotal
from tbl_supplier_payments sp
inner join tbl_grn_imports AS grn  ON grn.grn_id = sp.grn_id
where sp.supplier_id = supId
and sp.type = 'IMPORT_GRN'
and sp.is_returned = 0
and sp.status = '4';


select sum(ifnull(grn.total,0)) into _grnImportTotal
from tbl_grn_imports grn
WHERE grn.supplier_id = supId
AND grn.status = '4';


select ifnull(sum(total),0) into _returnImportTotal
from tbl_grn_import_return grnR
where grnR.supplier_id = supId
AND grnR.status = '4';


UPDATE tbl_supplier set 
rpt_settled_amount = ifnull(_grnSettledTotal,0) + ifnull(_adjustmentSettledTotal,0) + ifnull(_grnImportSettledTotal,0)
, rpt_outstanding_amount = ((ifnull(_grnTotal,0) + ifnull(_adjustmentTotal,0) + ifnull(_grnImportTotal,0)) - (ifnull(_grnSettledTotal,0) + ifnull(_returnTotal,0) + ifnull(_returnImportTotal,0)))
, rpt_return_amount = ifnull(_returnTotal,0) + ifnull(_returnImportTotal,0)
,rpt_grn_total = ifnull(_grnTotal,0)
,rpt_grn_settled_total = ifnull(_grnSettledTotal,0)
,rpt_grn_return_total = ifnull(_returnTotal,0)
,rpt_import_grn_total = ifnull(_grnImportTotal,0)
,rpt_import_grn_settled_total = ifnull(_grnImportSettledTotal,0)
,rpt_import_grn_return_total = ifnull(_returnImportTotal,0)
WHERE tbl_supplier.supplier_id = supId;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `update_trn_status` */;
DELIMITER ;;
CREATE DEFINER=`phpmyadmin`@`localhost` PROCEDURE `update_trn_status`()
BEGIN

UPDATE tbl_production_plans AS b
INNER JOIN  
 (
select  plan_id  ,
case when (sum(mrn_qty)  = sum(allocated_qty) and sum(case when is_row_material = 0 
and is_process_finished = 1 then 1 else 0 end) =sum(case when is_row_material = 0  then 1 else 0 end))  then 4 
	 when sum(mrn_qty) > 0  and sum(allocated_qty) = 0 then 3 
     when sum(mrn_qty) > 0  and sum(allocated_qty) >0 and sum(qty) != sum(allocated_qty) then 2 end as status
 from tbl_production_plans_process
 
 group by plan_id) tmp on  tmp.plan_id = b.plan_id
 SET b.status = tmp.status
 where b.status not in ('4');
 
 
UPDATE tbl_so AS b
INNER JOIN  
 (
 select  tbl_so_products.so_id  ,sum(ContractQty) , sum(dispatch_qty),
case  when sum(ContractQty)  = sum(allocated_qty) and sum(dispatch_qty) = 0 then 8 
 when sum(ContractQty) > 0  and sum(allocated_qty) = 0 then 6 
 when sum(ContractQty) > 0  and sum(allocated_qty) >0 and sum(ContractQty) != sum(allocated_qty) then 7 
when     sum(dispatch_qty) = sum(allocated_qty)  then 11
	 when     sum(dispatch_qty) != sum(allocated_qty)  then 10
	 when sum(ContractQty)  = sum(allocated_qty) and ifnull(is_invoiced,0) = 1 then 9
	 
     end as status
 from tbl_so_products
  inner join tbl_so on tbl_so.so_id = tbl_so_products.so_id
  group by tbl_so_products.so_id) tmp on  tmp.so_id = b.so_id
 SET b.status = tmp.status;
   
   
END ;;
DELIMITER ;


