$opcion = $_GET["opcion"];
switch ($opcion) {
    case "saveItems":
        $porder = new PurchaseOrder();
        $max = $_POST["max"];
        $date1 = $_POST["txtDate1"];
        $date2 = $_POST["txtDate2"];
        $items = array();
        for ($i = 0; $i <= $max; $i++) {
            if (isset($_POST["hidItem" . $i])) {
                if ($_POST["txtRealPurchaseQty" . $i] != "" || $_POST["txtPrice" . $i] != "") {
                    $items[] = array("iditem" => $_POST["hidItem" . $i], "idvendor" => $_POST["cmbVendor" . $i], "quantity" => $_POST["txtRealPurchaseQty" . $i], "price" => $_POST["txtPrice" . $i]);
                }
            }
        }
        $response = $porder->saveItems($items, $date1, $date2);
        $msg = "";
        if ($response) {
            $msg = "The items where succesfully saved";
        } else {
            $msg = "Couldn't save the data";
        }
        header("Location: ../view/purchaseOrders.php?msg={$msg}");
        break;
    case "generatePurchaseOrders":
        $porder = new PurchaseOrder();
        $max = $_POST["max"];
        $items = array();
        for ($i = 0; $i < $max; $i++) {
            if (isset($_POST["hidItem" . $i])) {
                $items[] = array("iditem" => $_POST["hidItem" . $i], "idvendor" => $_POST["hidVendor" . $i], "quantity" => $_POST["txtRealPurchaseQty" . $i], "price" => $_POST["txtPrice" . $i], "order" => $_POST["txtOrder" . $i]);