PCR-360 Wiki

Require one Phone per Service

PHP
/****
    Prerequisite: UDF unique identifier must be "EQPISPHONE" or else instance of "EQPISPHONE" below must be changed
    to match the unique name of the checkbox/bool UDF

    Requires >= PCR-360 2.1.3.3

    Description: CC: Restrict 1 phone to service
    Table Name: custom_CC_ADD_EQP_TO_SERVICE
    Table Record: null
    Action: Save

    $data = service/action;
    $params = equipment being added;
****/
$isValid = true;
$udf = $this->query("SELECT RECID FROM USER_DEFINED_FIELDS WHERE IDENTIFIER = 'EQPISPHONE'");
$phoneQty = 0;
$equipment = [$params] + (!empty($data['equipment']) ? $data['equipment']:[]);
foreach ($equipment as $eqp) {
    $eqpUdfv = $this->query("SELECT BOOL_VALUE FROM USER_DEFINED_FIELDS_VALS WHERE TABLE_RECID = ? AND UDF_RECID = ? AND TABLE_NAME = 'EQP_CATALOG'", [$eqp['CATALOG'], $udf[0]['RECID']]);
    if (count($eqpUdfv) && $eqpUdfv[0]['BOOL_VALUE'] === "1") {
        if ($eqp['qty'] > 1) {
            $isValid = false;
            break;
        } else {
            $phoneQty += $eqp['qty'];
            if ($phoneQty > 1) {
                $isValid = false;
                break;
            }
        }
    }
}
if (!$isValid) {
    $this->setMessage('We\'re Sorry!<br /><br />Only one (1) phone set is allowed per service.');
    return false;
}
return true;