Hello,
I’m trying to calculate Patch Panel based on optic count
I tried to achieve the result as below but it doesn’t always work correctly
I am open to your suggestions, If my codes are correct, where is wrong?
$optic = 301; // Number of Optical Dots
$patchpanelarray = array("1=>12", "2=>24", "3=>48", "4=>72", "5=>96" ); // Number of Patch Panels and Ports
// Let's find the most port patch panel
$patchpanel = end($patchpanelarray); // 96
// Is the most multi-port patch panel optical port large?
if($optic >= $patchpanel){
// How many 96 port panels from the sample optical point count
$i = 0;
while($i < $optic){
$i=$i+$patchpanel;
if($i <= $optic){
$carpan[] = $i;
}
}
// Calculating the array we get how many panels there are
$numberofpanels = count($carpan);
// We find the number increasing from the coefficient of 96
$remainingnumber = ($optic-end($carpan)); // We find that the extra number is 13
// Quantity and id array creation for 96 port patch panel
$patchpanel_id = array($numberofpanels=>array_search($patchpanel, $patchpanelarray);
//Now let's find the patch panel for 13 optical points
if($remainingnumber >0){
// From the function, we want the patch panel to give 13 ports and more.
// Since there are no 13 ports, it has 24 and will give 24 ports.
$secondpatchpanel = closest($remainingnumber, $patchpanelarray);
// Now let's get the quantity and id of the found products into an array
$quantity = 1; //There is always 1 available here
$patchpanel_id = array($quantity=>array_search($secondpatchpanel, $patchpanelarray);
}
}else{ // If the highest port is less than 96 ports, the number of optical points
$quantity = 1; //There is always 1 available here
$patchpanel_id = array($quantity=>array_search($optic, $patchpanelarray);
}
function closest($number, $array) {
sort($array);
foreach ($array as $a) {
if ($a >= $number) return $a;
}
return end($array); // or return NULL;
}
I did something like this, but I don’t know how accurate it is