<?php

include '../resources/init.php';
if (isset($_POST['type'])) {
    if ($_POST['type'] == "add") {
        try {
            $inv_item = new Inv_item();
            $inv_item->populate();
            $inv_item->store();
            $branches = Branch::findAll();
            foreach ($branches as $branch) {
                $stock = new Inv_stock();
                $stock->setBranchId($branch->getId());
                $stock->setItemId($inv_item->getId());
                $stock->setQuantity(0);
                $stock->store();
            }
        } catch (fExpectedException $e) {
            echo $e->printMessage();
        }
    } else {
        if ($_POST['type'] == "delete") {
            try {
                $inv_item = new Inv_item($_POST['key']);
                $inv_item->delete();
            } catch (fExpectedException $e) {
                echo $e->printMessage();
            }
        } else {
            if ($_POST['type'] == "edit") {
                try {