Esempio n. 1
0
function evalPPAutoApproveReject($approveReject, $isLab = null, $pp_kod = null, $categoryId = null, $appeal = null)
{
    $fQPreEvalPPsFinal = false;
    if (is_null($appeal)) {
        $appeal = 0;
    }
    if (!is_null($pp_kod) && $pp_kod) {
        $result = selectQuery("SELECT pp_rs_kod_lab,pp_rs_kod_api,pp_rs_kod_product\n\t\t FROM p_product WHERE pp_kod = " . $pp_kod, 1);
    } else {
        $result = selectQuery("SELECT pp_rs_kod_lab,pp_rs_kod_api,pp_rs_kod_product\n\t\t FROM p_product WHERE pp_kod = " . $_SESSION['product_reg']['ppID'], 1);
    }
    /*
    $result = selectQuery( "SELECT pp_rs_kod_lab,pp_rs_kod_api,pp_rs_kod_product
     FROM p_product WHERE pp_kod = " . $_SESSION['product_reg']['ppID'],1 );
    */
    if ($result) {
        $ppaGoAhead = true;
        if (!isset($result["pp_rs_kod_product"])) {
            $ppaGoAhead = false;
        }
        if (qLaaIsLabApplicable($categoryId) && !isset($result["pp_rs_kod_lab"])) {
            $ppaGoAhead = false;
        }
        if (qLaaIsAPIApplicable($categoryId) && !isset($result["pp_rs_kod_api"])) {
            $ppaGoAhead = false;
        }
        if ($ppaGoAhead) {
            $pp_rs_kod = 0;
            if ($approveReject == "APPROVE") {
                if (!is_null($isLab) && $isLab == 'LAB') {
                    if (qLaaIsLabApplicable($categoryId)) {
                        if (qLaaIsAPIApplicable($categoryId)) {
                            if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_api"] == 1111 && $result["pp_rs_kod_product"] == 1111) {
                                $pp_rs_kod = 1111;
                            } else {
                                if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_api"] == 1112 || $result["pp_rs_kod_product"] == 1112)) {
                                    $pp_rs_kod = 1112;
                                }
                            }
                        } else {
                            if (!is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_product"] == 1111) {
                                $pp_rs_kod = 1111;
                            } else {
                                if (!is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_product"] == 1112) {
                                    $pp_rs_kod = 1112;
                                }
                            }
                        }
                    }
                } else {
                    if ($_SESSION['department'] == 'API') {
                        if (qLaaIsLabApplicable($categoryId)) {
                            if (!is_null($result["pp_rs_kod_lab"]) && !is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_lab"] == 1111 && $result["pp_rs_kod_product"] == 1111) {
                                $pp_rs_kod = 1111;
                            } else {
                                if (!is_null($result["pp_rs_kod_lab"]) && !is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_lab"] == 1112 || $result["pp_rs_kod_product"] == 1112)) {
                                    $pp_rs_kod = 1112;
                                }
                            }
                        } else {
                            if (!is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_product"] == 1111) {
                                $pp_rs_kod = 1111;
                            } else {
                                if (!is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_product"] == 1112) {
                                    $pp_rs_kod = 1112;
                                }
                            }
                        }
                    } else {
                        if ($_SESSION['department'] == 'PRODUCT') {
                            if (qLaaIsLabApplicable($categoryId) && qLaaIsAPIApplicable($categoryId)) {
                                if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_lab"]) && $result["pp_rs_kod_api"] == 1111 && $result["pp_rs_kod_lab"] == 1111) {
                                    $pp_rs_kod = 1111;
                                } else {
                                    if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_lab"]) && ($result["pp_rs_kod_api"] == 1112 || $result["pp_rs_kod_lab"] == 1112)) {
                                        $pp_rs_kod = 1112;
                                    }
                                }
                            } else {
                                if (!qLaaIsLabApplicable($categoryId) && qLaaIsAPIApplicable($categoryId)) {
                                    if (!is_null($result["pp_rs_kod_api"]) && $result["pp_rs_kod_api"] == 1111) {
                                        $pp_rs_kod = 1111;
                                    } else {
                                        if (!is_null($result["pp_rs_kod_api"]) && $result["pp_rs_kod_api"] == 1112) {
                                            $pp_rs_kod = 1112;
                                        }
                                    }
                                } else {
                                    if (qLaaIsLabApplicable($categoryId) && !qLaaIsAPIApplicable($categoryId)) {
                                        if (!is_null($result["pp_rs_kod_lab"]) && $result["pp_rs_kod_lab"] == 1111) {
                                            $pp_rs_kod = 1111;
                                        } else {
                                            if (!is_null($result["pp_rs_kod_lab"]) && $result["pp_rs_kod_lab"] == 1112) {
                                                $pp_rs_kod = 1112;
                                            }
                                        }
                                    } else {
                                        if (!qLaaIsLabApplicable($categoryId) && !qLaaIsAPIApplicable($categoryId)) {
                                            $pp_rs_kod = 1111;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($approveReject == "REJECT") {
                    if (!is_null($isLab) && $isLab == 'LAB') {
                        if (qLaaIsLabApplicable($categoryId)) {
                            if (qLaaIsAPIApplicable($categoryId)) {
                                if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_api"] == 1111 || $result["pp_rs_kod_api"] == 1112) && ($result["pp_rs_kod_product"] == 1111 || $result["pp_rs_kod_product"] == 1112)) {
                                    $pp_rs_kod = 1112;
                                }
                            } else {
                                if (!is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_product"] == 1111 || $result["pp_rs_kod_product"] == 1112)) {
                                    $pp_rs_kod = 1112;
                                }
                            }
                        }
                    } else {
                        if ($_SESSION['department'] == 'API') {
                            if (qLaaIsLabApplicable($categoryId)) {
                                if (!is_null($result["pp_rs_kod_lab"]) && !is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_lab"] == 1111 || $result["pp_rs_kod_lab"] == 1112) && ($result["pp_rs_kod_product"] == 1111 || $result["pp_rs_kod_product"] == 1112)) {
                                    $pp_rs_kod = 1112;
                                }
                            } else {
                                if (!is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_product"] == 1111 || $result["pp_rs_kod_product"] == 1112)) {
                                    $pp_rs_kod = 1112;
                                }
                            }
                        } else {
                            if ($_SESSION['department'] == 'PRODUCT') {
                                if (qLaaIsLabApplicable($categoryId) && qLaaIsAPIApplicable($categoryId)) {
                                    if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_lab"]) && ($result["pp_rs_kod_lab"] == 1111 || $result["pp_rs_kod_lab"] == 1112) && ($result["pp_rs_kod_api"] == 1111 || $result["pp_rs_kod_api"] == 1112)) {
                                        $pp_rs_kod = 1112;
                                    }
                                } else {
                                    if (!qLaaIsLabApplicable($categoryId) && qLaaIsAPIApplicable($categoryId)) {
                                        if (!is_null($result["pp_rs_kod_api"]) && ($result["pp_rs_kod_api"] == 1111 || $result["pp_rs_kod_api"] == 1112)) {
                                            $pp_rs_kod = 1112;
                                        }
                                    } else {
                                        if (qLaaIsLabApplicable($categoryId) && !qLaaIsAPIApplicable($categoryId)) {
                                            if (!is_null($result["pp_rs_kod_lab"]) && ($result["pp_rs_kod_lab"] == 1111 || $result["pp_rs_kod_lab"] == 1112)) {
                                                $pp_rs_kod = 1112;
                                            }
                                        } else {
                                            if (!qLaaIsLabApplicable($categoryId) && !qLaaIsAPIApplicable($categoryId)) {
                                                $pp_rs_kod = 1112;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($pp_rs_kod) {
                if (!is_null($pp_kod) && $pp_kod) {
                    $sqlQueryAuto = "UPDATE p_product SET pp_rs_kod = " . $pp_rs_kod . " WHERE pp_kod = " . $pp_kod;
                    insupdelQuery($sqlQueryAuto);
                } else {
                    $sqlQueryAuto = "UPDATE p_product SET pp_rs_kod = " . $pp_rs_kod . " WHERE pp_kod = " . $_SESSION['product_reg']['ppID'];
                    insupdelQuery($sqlQueryAuto);
                }
                $fQPreEvalPPsFinal = true;
            } else {
                // echo "extr";
                // PP Auto Send Correspondence to client.
                evalPPAutoCorrespondAR($isLab, $pp_kod, $categoryId);
            }
        }
    }
    return $fQPreEvalPPsFinal;
}
function evalKUTrayAutoApproveReject($approveReject, $isLab = null, $currProdId, $appeal = null)
{
    $categoryId = qGetProdCatId($currProdId);
    if (is_null($appeal)) {
        $appeal = 0;
    }
    $result = selectQuery("SELECT pp_rs_kod_lab,pp_rs_kod_api,pp_rs_kod_product\n\t\t FROM p_product WHERE pp_kod = " . $currProdId, 1);
    if ($result) {
        $pkuGoAhead = true;
        if (!isset($result["pp_rs_kod_product"])) {
            $pkuGoAhead = false;
        }
        if (qLaaIsLabApplicable($categoryId) && !isset($result["pp_rs_kod_lab"])) {
            $pkuGoAhead = false;
        }
        if (qLaaIsAPIApplicable($categoryId) && !isset($result["pp_rs_kod_api"])) {
            $pkuGoAhead = false;
        }
        if ($pkuGoAhead) {
            $pp_rs_kod = 0;
            if ($approveReject == "APPROVE") {
                if (!is_null($isLab) && $isLab == 'LAB') {
                    if (qLaaIsLabApplicable($categoryId)) {
                        if (qLaaIsAPIApplicable($categoryId)) {
                            if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_api"] == 9008 && $result["pp_rs_kod_product"] == 9008) {
                                $pp_rs_kod = 9008;
                            } else {
                                if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_api"] == 9050 || $result["pp_rs_kod_product"] == 9050)) {
                                    $pp_rs_kod = 9050;
                                }
                            }
                        } else {
                            if (!is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_product"] == 9008) {
                                $pp_rs_kod = 9008;
                            } else {
                                if (!is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_product"] == 9050) {
                                    $pp_rs_kod = 9050;
                                }
                            }
                        }
                    }
                } else {
                    if ($_SESSION['department'] == 'API') {
                        if (qLaaIsLabApplicable($categoryId)) {
                            if (!is_null($result["pp_rs_kod_lab"]) && !is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_lab"] == 9008 && $result["pp_rs_kod_product"] == 9008) {
                                $pp_rs_kod = 9008;
                            } else {
                                if (!is_null($result["pp_rs_kod_lab"]) && !is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_lab"] == 9050 || $result["pp_rs_kod_product"] == 9050)) {
                                    $pp_rs_kod = 9050;
                                }
                            }
                        } else {
                            if (!is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_product"] == 9008) {
                                $pp_rs_kod = 9008;
                            } else {
                                if (!is_null($result["pp_rs_kod_product"]) && $result["pp_rs_kod_product"] == 9050) {
                                    $pp_rs_kod = 9050;
                                }
                            }
                        }
                    } else {
                        if ($_SESSION['department'] == 'PRODUCT') {
                            if (qLaaIsLabApplicable($categoryId) && qLaaIsAPIApplicable($categoryId)) {
                                if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_lab"]) && $result["pp_rs_kod_api"] == 9008 && $result["pp_rs_kod_lab"] == 9008) {
                                    $pp_rs_kod = 9008;
                                    // echo $pp_rs_kod;
                                } else {
                                    if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_lab"]) && ($result["pp_rs_kod_api"] == 9050 || $result["pp_rs_kod_lab"] == 9050)) {
                                        $pp_rs_kod = 9050;
                                    }
                                }
                            } else {
                                if (!qLaaIsLabApplicable($categoryId) && qLaaIsAPIApplicable($categoryId)) {
                                    if (!is_null($result["pp_rs_kod_api"]) && $result["pp_rs_kod_api"] == 9008) {
                                        $pp_rs_kod = 9008;
                                        // echo $pp_rs_kod;
                                    } else {
                                        if (!is_null($result["pp_rs_kod_api"]) && $result["pp_rs_kod_api"] == 9050) {
                                            $pp_rs_kod = 9050;
                                        }
                                    }
                                } else {
                                    if (qLaaIsLabApplicable($categoryId) && !qLaaIsAPIApplicable($categoryId)) {
                                        if (!is_null($result["pp_rs_kod_lab"]) && $result["pp_rs_kod_lab"] == 9008) {
                                            $pp_rs_kod = 9008;
                                            // echo $pp_rs_kod;
                                        } else {
                                            if (!is_null($result["pp_rs_kod_lab"]) && $result["pp_rs_kod_lab"] == 9050) {
                                                $pp_rs_kod = 9050;
                                            }
                                        }
                                    } else {
                                        if (!qLaaIsLabApplicable($categoryId) && !qLaaIsAPIApplicable($categoryId)) {
                                            $pp_rs_kod = 9008;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($approveReject == "REJECT") {
                    if (!is_null($isLab) && $isLab == 'LAB') {
                        if (qLaaIsLabApplicable($categoryId)) {
                            if (qLaaIsAPIApplicable($categoryId)) {
                                if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_api"] == 9008 || $result["pp_rs_kod_api"] == 9050) && ($result["pp_rs_kod_product"] == 9008 || $result["pp_rs_kod_product"] == 9050)) {
                                    $pp_rs_kod = 9050;
                                }
                            } else {
                                if (!is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_product"] == 9008 || $result["pp_rs_kod_product"] == 9050)) {
                                    $pp_rs_kod = 9050;
                                }
                            }
                        }
                    } else {
                        if ($_SESSION['department'] == 'API') {
                            if (qLaaIsLabApplicable($categoryId)) {
                                if (!is_null($result["pp_rs_kod_lab"]) && !is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_lab"] == 9008 || $result["pp_rs_kod_lab"] == 9050) && ($result["pp_rs_kod_product"] == 9008 || $result["pp_rs_kod_product"] == 9050)) {
                                    $pp_rs_kod = 9050;
                                }
                            } else {
                                if (!is_null($result["pp_rs_kod_product"]) && ($result["pp_rs_kod_product"] == 9008 || $result["pp_rs_kod_product"] == 9050)) {
                                    $pp_rs_kod = 9050;
                                }
                            }
                        } else {
                            if ($_SESSION['department'] == 'PRODUCT') {
                                if (qLaaIsLabApplicable($categoryId) && qLaaIsAPIApplicable($categoryId)) {
                                    if (!is_null($result["pp_rs_kod_api"]) && !is_null($result["pp_rs_kod_lab"]) && ($result["pp_rs_kod_lab"] == 9008 || $result["pp_rs_kod_lab"] == 9050) && ($result["pp_rs_kod_api"] == 9008 || $result["pp_rs_kod_api"] == 9050)) {
                                        $pp_rs_kod = 9050;
                                    }
                                } else {
                                    if (!qLaaIsLabApplicable($categoryId) && qLaaIsAPIApplicable($categoryId)) {
                                        if (!is_null($result["pp_rs_kod_api"]) && ($result["pp_rs_kod_api"] == 9008 || $result["pp_rs_kod_api"] == 9050)) {
                                            $pp_rs_kod = 9050;
                                        }
                                    } else {
                                        if (qLaaIsLabApplicable($categoryId) && !qLaaIsAPIApplicable($categoryId)) {
                                            if (!is_null($result["pp_rs_kod_lab"]) && ($result["pp_rs_kod_lab"] == 9008 || $result["pp_rs_kod_lab"] == 9050)) {
                                                $pp_rs_kod = 9050;
                                            }
                                        } else {
                                            if (!qLaaIsLabApplicable($categoryId) && !qLaaIsAPIApplicable($categoryId)) {
                                                $pp_rs_kod = 9050;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($pp_rs_kod) {
                $sqlQueryAuto = "UPDATE p_product SET pp_rs_kod = " . $pp_rs_kod . " WHERE pp_kod = " . $currProdId;
                insupdelQuery($sqlQueryAuto);
                if ($appeal == 1) {
                    $sqlQuery = "UPDATE p_product SET pp_pkk_appeal_stat = 55,pp_pkk_tkh_appeal = '" . date('Y-m-d H:i:s') . "' WHERE pp_kod = " . $currProdId;
                    insupdelQuery($sqlQuery);
                }
                $sqlUpdFdt = "INSERT INTO p_product_status_his ( ppsh_pp_kod,ppsh_process,ppsh_date_evaluation ) VALUES ( " . $currProdId . ",'evaluation','" . date("Y-m-d H:i:s") . "' )";
                $ret = insupdelQuery($sqlUpdFdt);
            }
        }
    }
}