DECLARE @f_menu_id NUMERIC(18,0)
DECLARE @f_menu_seq NUMERIC(18,0)

IF EXISTS (SELECT 1 FROM cf_site WHERE site_cd = 'SMCP')
BEGIN
    BEGIN TRANSACTION

    BEGIN TRY

       
        ------------------------------------------------------------------------
    -- 1. Linen - Daily Linen Routine
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'm_lin_daily_linen_routine'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','m_lin_daily_linen_routine','Linen - Clean Linen Issue','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','M',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 2. Linen - Daily Linen Issue
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'm_lin_daily_linen_issue'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','m_lin_daily_linen_issue','Linen - Daily Linen Issue','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','M',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 3. Linen - New Linen Request Listing
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'm_lin_new_linen_rquest_listing'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','m_lin_new_linen_rquest_listing','Linen - Additional Linen Request','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','M',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 4. Linen - Linen Reject & Replace
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'm_lin_linen_reject_replace'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','m_lin_linen_reject_replace','Linen - Linen Reject & Replace','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','M',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 5. Linen - Satisfaction Survey
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'm_lin_linen_satisfaction_survey'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','m_lin_linen_satisfaction_survey','Linen - Satisfaction Survey','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','M',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 6. Linen - Linen Inventory
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'm_lin_linen_inventory'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','m_lin_linen_inventory','Linen - Linen Inventory Checklist','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','M',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 7. Linen Inventory - New Linen
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'o_new_linen'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','o_new_linen','Linen Inventory - New Linen','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','O',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 8. Linen Inventory - CCLS Count
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'o_ccls_count'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','o_ccls_count','Linen Inventory - CCLS Count','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','O',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 9. Linen Inventory - In-Use Count
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'o_in_use_count'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','o_in_use_count','Linen Inventory - In Use Count','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','O',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

    ------------------------------------------------------------------------
    -- 10. Linen Inventory - Laundry Count
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'o_laundry'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','o_laundry','Linen Inventory - Laundry Count','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','O',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

	 ------------------------------------------------------------------------
    -- 11. Linen Inventory - Reject Count
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'o_reject_count'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','o_reject_count','Linen Inventory - Reject Count','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','O',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END

     ------------------------------------------------------------------------
    -- 12. Linen Inventory - User Store Count
    ------------------------------------------------------------------------
    IF NOT EXISTS (
        SELECT 1
        FROM cf_menu
        WHERE object_name = 'o_user_store_count'
          AND program_category = 'MBL'
          AND object_type = 'M'
    )
    BEGIN
        SELECT @f_menu_seq = ISNULL(MAX(cf_menu_seq), 0) + 1
        FROM cf_menu
        WHERE program_category = 'MBL'
          AND object_type = 'M'

        INSERT INTO cf_menu (
            language_cd, object_name, object_descs, object_type, program_category,
            ico_name, remarks, cf_menu_seq, audit_column, custom_flag,
            external_program, access_audit, mobile_object_type,
            audit_user, audit_date, column1, column2, column3, column4, column5
        )
        VALUES (
            'DEFAULT','o_user_store_count','Linen Inventory - User Store Count','M','MBL',
            '(Default)',NULL,@f_menu_seq,'0','0',
            '0','0','O',
            'admin',GETDATE(),'Linen',NULL,NULL,NULL,NULL
        )

        SET @f_menu_id = SCOPE_IDENTITY()

        INSERT INTO cf_user_access (
            site_cd, empl_id, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag
        )
        SELECT site_cd, empl_id, @f_menu_id, 0,0,0,0,0,0
        FROM cf_site_user

        INSERT INTO cf_menu_template_access (
            template_cd, menuid, exe_flag, view_flag, new_flag, edit_flag, del_flag, print_flag, audit_user, audit_date
        )
        SELECT template_cd, @f_menu_id, 0,0,0,0,0,0, 'admin', GETDATE()
        FROM cf_menu_template
    END
    
        COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
        IF @@TRANCOUNT > 0
            ROLLBACK TRANSACTION

        SELECT
            ERROR_NUMBER() AS ErrorNumber,
            ERROR_MESSAGE() AS ErrorMessage
    END CATCH
END
ELSE
BEGIN
    PRINT 'SMCP site not found in cf_site. Linen menu script not executed.'
END