<h2>Sub Category</h2>
				<form action = "inventory-sub.php" method = "get">
					<label for="maincc">Choose Main Category: </label>
					<span id="maincc">
						<select name = "maincc">
							<?php 
Inv_maincategory::findAllOption();
?>
						</select>
					</span>
					<input id="submitBTN" type="submit" value="Submit" />
				</form>
			<?php 
if (isset($_GET['maincc'])) {
    try {
        $inv_subcategories = Inv_subcategory::findByMainCategoryCode($_GET['maincc']);
        $inv_maincategory = new Inv_maincategory($_GET['maincc']);
    } catch (fExpectedException $e) {
        echo $e->printMessage();
    }
    printf("<br /><h3 id=\"mainCategoryTitle\" key=\"%s\">%s</h3>", $_GET['maincc'], $inv_maincategory->prepareDescription());
    printf("<table><thead><tr><td>Sub Category Code</td><td>Description</td><td>Main Category Code</td><td>Status</td></tr></thead><tbody>");
    foreach ($inv_subcategories as $inv_subcategory) {
        printf("<tr><td class=\"hideFirst\"><span class=\"varInput\" id=\"Id\">%s</span></td>\r\n\t\t\t\t\t\t\t\t<td><span class=\"varInput\" id=\"Categorycode\">%s</span></td>\r\n\t\t\t\t\t\t\t\t<td><span class=\"varInput\" id=\"Description\">%s</span></td>\r\n\t\t\t\t\t\t\t\t<td><span class=\"varInput\" id=\"MainCategorycode\">%s</span></td>\r\n\t\t\t\t\t\t\t\t<td><span class=\"varInput\" id=\"Status\">%s</span></td>", $inv_subcategory->prepareId(), $inv_subcategory->prepareCategoryCode(), $inv_subcategory->prepareDescription(), $inv_subcategory->prepareMainCategoryCode(), $inv_subcategory->prepareStatus() == 1 ? "Active" : "Inactive");
        printf("<td id=\"iconCell\" class=\"hideFirst\"><ul id=\"icons\" class=\"ui-widget ui-helper-clearfix\">\r\n\t\t\t\t\t\t<li id=\"save\" title=\"Save\" class=\"ui-state-default ui-corner-all\"><span class=\"ui-icon ui-icon-circle-check\"></span></li>\r\n\t\t\t\t\t\t<li id=\"cancel\" title=\"Cancel\" class=\"ui-state-default ui-corner-all\"><span class=\"ui-icon ui-icon-circle-close\"></span></li>\r\n\t\t\t\t\t\t</ul></td></tr>");
    }
    ?>
				<tr id="newItem">
					<td>
						<span id="Categorycode">
							<input type="text" name="category_code" value="Input Category Code" />
						</select>
					</span>
					<label for="subcc"> Choose Sub Category: </label>
					<span id="subcc">
						<select name = "subcc">
						</select>
					</span>
					<input id="submitBTN" type="submit" value="Submit" />
				</form>
			<?php 
if (isset($_GET['maincc'])) {
    try {
        $inv_subcategories = Inv_subcategory::findByMainCategoryCode($_GET['maincc']);
        $inv_classifications = Inv_classification::findBySubCategoryCode($_GET['subcc']);
        $inv_maincategory = new Inv_maincategory($_GET['maincc']);
        $inv_subcategory = new Inv_subcategory($_GET['subcc']);
    } catch (fExpectedException $e) {
        echo $e->printMessage();
    }
    printf("<br /><h3 id=\"mainCategoryTitle\" key=\"%s\">%s</h3>", $_GET['maincc'], $inv_maincategory->prepareDescription());
    printf("<h4 id=\"subCategoryTitle\" key=\"%s\">%s</h4>", $_GET['subcc'], $inv_subcategory->prepareDescription());
    printf("<table><thead><tr><td>Classification Code</td><td>Description</td><td>Sub Category Code</td><td>Status</td></tr></thead><tbody>");
    foreach ($inv_classifications as $inv_classification) {
        printf("<tr><td class=\"hideFirst\"><span class=\"varInput\" id=\"Id\">%s</span></td>\r\n\t\t\t\t\t\t\t\t<td><span class=\"varInput\" id=\"Classificationcode\">%s</span></td>\r\n\t\t\t\t\t\t\t\t<td><span class=\"varInput\" id=\"Description\">%s</span></td>\r\n\t\t\t\t\t\t\t\t<td><span class=\"varInput\" id=\"SubCategorycode\">%s</span></td>\r\n\t\t\t\t\t\t\t\t<td><span class=\"varInput\" id=\"Status\">%s</span></td>", $inv_classification->prepareId(), $inv_classification->prepareClassificationCode(), $inv_classification->prepareDescription(), $inv_classification->prepareSubCategoryCode(), $inv_classification->prepareStatus() == 1 ? "Active" : "Inactive");
        printf("<td id=\"iconCell\" class=\"hideFirst\"><ul id=\"icons\" class=\"ui-widget ui-helper-clearfix\">\r\n\t\t\t\t\t\t<li id=\"save\" title=\"Save\" class=\"ui-state-default ui-corner-all\"><span class=\"ui-icon ui-icon-circle-check\"></span></li>\r\n\t\t\t\t\t\t<li id=\"cancel\" title=\"Cancel\" class=\"ui-state-default ui-corner-all\"><span class=\"ui-icon ui-icon-circle-close\"></span></li>\r\n\t\t\t\t\t\t</ul></td></tr>");
    }
    ?>
				<tr id="newItem">
					<td>
						<span id="Classificationcode">
							<input type="text" name="classification_code" value="Input Classification Code" />
            $inv_subcategory = new Inv_subcategory($_POST['key']);
            $inv_subcategory->populate();
            $inv_subcategory->store();
        } catch (fExpectedException $e) {
            echo $e->printMessage();
        }
    } else {
        if ($_POST['type'] == "delete") {
            try {
                $inv_subcategory = new Inv_subcategory($_POST['key']);
                $inv_subcategory->delete();
            } catch (fExpectedException $e) {
                echo $e->printMessage();
            }
        } else {
            if ($_POST['type'] == "add") {
                try {
                    $inv_subcategory = new Inv_subcategory();
                    $inv_subcategory->populate();
                    $inv_subcategory->store();
                } catch (fExpectedException $e) {
                    echo $e->printMessage();
                }
            } else {
                if ($_POST['type'] == "option") {
                    Inv_subcategory::findOptionByMainCategoryCode($_POST['key']);
                }
            }
        }
    }
}
         $inv_maincategory->populate();
         $inv_maincategory->store();
         $inv_subcategories = Inv_subcategory::findByMainCategoryCode($_POST['key']);
         foreach ($inv_subcategories as $inv_subcategory) {
             $inv_subcategory->setMainCategoryCode($_POST['category_code']);
             $inv_subcategory->store();
         }
     } catch (fExpectedException $e) {
         echo $e->printMessage();
     }
 } else {
     if ($_POST['type'] == "delete") {
         try {
             $inv_maincategory = new Inv_maincategory($_POST['key']);
             $inv_maincategory->delete();
             $inv_subcategories = Inv_subcategory::findByMainCategoryCode($_POST['key']);
             foreach ($inv_subcategories as $inv_subcategory) {
                 $inv_subcategory->delete();
             }
         } catch (fExpectedException $e) {
             echo $e->printMessage();
         }
     } else {
         if ($_POST['type'] == "add") {
             try {
                 $inv_maincategory = new Inv_maincategory();
                 $inv_maincategory->populate();
                 $inv_maincategory->store();
             } catch (fExpectedException $e) {
                 echo $e->printMessage();
             }