I can't seem to get the php program to write the results to the fshp and fbo files under the function write files section at the bottom of the code to complete writing to the files. I am not allowed to use global.
I can't seem to get the php program to write the results to the fshp and fbo files under the function write files section at the bottom of the code to complete writing to the files. I am not allowed to use global.
<?php
// MAINLINE
//input vars
$orderId = "";
$itemId = "";
$qtyRequested = 0;
$qtyOnHand = 0;
// output vars
$qtyShipped = 0;
$qtyBackOrdered = 0;
$message = "";
PrepareFiles($fshp,$fbo );
printf("\n Enter the Order Id or (0) to exit program: ");
fscanf(STDIN, "%s", $orderId);
while($orderId != "0")
{
printf("\n Enter the Item Id or (0) to exit the order: " );
fscanf(STDIN, "%s", $itemId);
while($itemId != "0")
{
printf("\n Enter the Qty Requested:");
fscanf(STDIN, "%d", $qtyRequested);
printf("\n Enter the Qty On Hand:");
fscanf(STDIN, "%d", $qtyOnHand);
printf("\n Enter the Item Id or (0) to exit the order: " );
fscanf(STDIN, "%s", $itemId);
}
printf("\n Enter the Order Id or (0) to exit program: ");
fscanf(STDIN, "%s", $orderId);
}
fclose($fshp);
fclose($fbo);
// END MAINLINE
function PrepareFiles(&$fshp,&$fbo )
{
$fshp = fopen("shipped.txt", "w") or die("shipped not opened");
fprintf($fshp,"\n SHIPPED REPORT\n");
fprintf($fshp,"\n Order Id Item Id Shipped Message\n");
$fbo = fopen("backorder.txt", "w") or die("backorder not opened");
fprintf($fbo,"\n BACK ORDER REPORT\n");
fprintf($fbo,"\n Order Id Item Id Backordered\n");
}
function DoCalcs($qtyOnHand,$qtyRequested, &$qtyShipped, &$qtyBackOrdered, &$message)
{
printf("\n DoCalcs\n"); ///
if($qtyRequested <= $qtyOnHand)
{
$qtyShipped = $qtyRequested;
$qtyBackordered = 0;
$message = "Fully Filled";
}
else
{
if($qtyOnHand !=0)
{
$qtyShipped = $qtyOnHand;
$qtyBackOrdered = $qtyRequested - $qtyOnHand;
$message = "Partially Filled";
}
else
{
$qtyShipped = 0;
$qtyBackOrdered = $qtyRequested;
$message = "Out of Stock";
}
}
}
function WriteFiles($fship, $fbo, $orderId, $itemId, $qtyOnHand, $qtyRequested, &$qtyShipped, &$qtyBackOrdered, &$message)
{
printf("\n WriteFiles\n");
fprintf($fshp, "$orderId $itemId $qtyShipped $message\n");
fprintf($fbo, "$orderId $itemId $qtyBackOrdered\n");
}
?>
Step by step
Solved in 3 steps