require_once("include/global.php");
$output = $_POST['output'];
if ($output != '')
{
//send it out!
$parts = importBOMData($_POST['assembly_ids'], $_POST['assembly_qty']);
$corps = loadSupplierData();
if ($output == 'json')
renderUniqueJSON($parts);
else if ($output == 'csv')
renderUniqueCSV($parts);
else
renderUniqueHTML($parts);
}
else
echo "Oops, you gotta POST here bro.";
function renderUniqueCSV($bom)
{
$types = $bom->getTypes();
foreach ($types AS $type)
{
$parts = $bom->getParts($type);
renderGenericPartsCSV($parts, ucfirst(strtolower($type)));
}
}
function renderUniqueJSON($bom)
{
$parts = $bom->getParts();
echo json_encode($parts);
}
function renderUniqueHTML($bom)
{
drawHeader("Choose Suppliers");
$types = $bom->getTypes();
$suppliers = $bom->getUniqueSuppliers();
?>
- Step 1: Choose which assemblies and the quantities of each.
- Step 2: Choose which suppliers you'd like to use.
- Step 3: Order your parts! Super easy.
Set a global supplier (it will choose this supplier if available below.)
drawFooter();
}
function renderGenericPartsCSV($parts, $name)
{
$fp = fopen('php://output', 'w');
fputcsv($fp, array($name));
fputcsv($fp, array("Name", "Quantity"));
if (count($parts))
foreach ($parts AS $part)
fputcsv($fp, array($part->name, $part->quantity));
fputcsv($fp, array());
fclose($fp);
}
function renderGenericPartsHTML($parts, $name)
{
?>
=$name?>
if (count($parts)): ?>
Part |
Quantity |
Suppliers |
foreach ($parts AS $part): ?>
$total += $part->quantity;?>
=$part->name?> |
=$part->quantity?> |
renderPartSuppliers($part) ?> |
endforeach ?>
Total: |
=$total?> |
else: ?>
No parts found.
endif ?>
}
function renderPartSuppliers($part)
{
global $corps;
echo '';
echo '';
if (!empty($part->unique_part->suppliers))
{
echo '';
}
else
{
echo '';
echo 'no suppliers - suggest one!';
}
echo "\n";
}
?>