Need help writing this program using php?

Alex S

New member
I'm writing a program for school that's suppose to simulate a inventory control program that is to accept order details for an item, and generate a shipping list and a back order list.
A dialogue is to appear on the screen for the input values, and print two reports as required; Shipping List and Back Order list.
My output should display (For the Shipping List) a Order Number, Item Number, Quantity Shipped, and a message confirming if all requested items were shipped or only partially.
The Back Order list should display the same, except that there instead of quantity shipped, it shows the amount back ordered and a message confirming this.
I have written most of the code already. What I'm having problems with is the calculations and the message displays.
Here's what I have:

<?php
//mainline

$orderNumber = 0;
$itemNumber = 0;
$qtyReq = 0;
$qtyOH = 0;
$qtyShip = 0;
$qtyBO = 0;
$message= "";


sList($sList); // function call to open the shipping list
BO($backOrder); // function call to open the back order list

printf("\nEnter Order Number or 0 to exit: ");
fscanf(STDIN, "%s", $orderNumber);

while($orderNumber != "0")
{
printf("\nEnter Item Number or 0 to exit: ");
fscanf(STDIN, "%s", $itemNumber);
while($itemNumber != "0")
{
printf("\nEnter requested quantity: ");
fscanf(STDIN, "%s", $qtyReq);

printf("\nEnter quantity on hand: ");
fscanf(STDIN, "%s", $qtyOH);

doCalc( $qtyReq, $qtyOH, $qtyShip, $qtyBO, $message);
WriteFiles($sList, $orderNumber, $itemNumber, $qtyShip, $message);

printf("\nEnter Item Number or 0 to exit: ");
fscanf(STDIN, "%s", $itemNumber);
}

if($itemNumber == "0")
{
printf("\nEnter Order Number or 0 to exit: ");
fscanf(STDIN, "%s", $orderNumber);
}
}

//fscanf(STDIN, "%s", $buster);
//end mainline

function sList(&$sList)
{
$sList=fopen("shippinglist.txt", "w");
fprintf($sList,"MITRE-11 HARDWARE\n\n");
fprintf($sList,"INVENTORY CONTROL SHIPPING LIST\n\n");
fprintf($sList,"ORDER NO. ITEM NO. UNITS SHIPPED MESSAGE\n");
}

function BO(&$backOrder)
{
$backOrder=fopen("backorder.txt", "w");
fprintf($backOrder,"MITRE-11 HARDWARE\n\n");
fprintf($backOrder,"INVENTORY CONTROL BACK ORDER LIST\n\n");
fprintf($backOrder,"ORDER NO. ITEM NO. UNITS SHIPPED MESSAGE\n");
}

function doCalc( $qtyReq, $qtyOH, &$qtyShip, &$qtyBO, &$message)
{
if($qtyOH >= $qtyReq)
{
$qtyShip = ($qtyOH-$qtyReq);
$qtyBO = 0;
$message = printf($sList,"\nShippment Filled");
}
if($qtyOH > "0" )
{
$qtyShip = $qtyOH;
$qtyBO = ($qtyReq - $qtyOH);
$message = printf($sList,"\nShippment Partially Filled");
}
else
{
$qtyShip = 0;
$qtyBO = $qtyReq;
$message = printf($sList,"\nOUT OF STOCK");
}
}

function WriteFiles($sList, $orderNumber, $itemNumber, $qtyShip, $message)
{
fprintf($sList, "\n%-5s %11s %10s %10s", $orderNumber, $itemNumber, $qtyShip, $message);
}

?>

What I think is happening, for the calculations, is that inside the function doCalc, the first IF statement says, ($qtyOH >= $qtyReq), but it's skipping that IF statement and moving onto the second which is ($qtyOH > "0" ). This gives me the quantity shipped the same as on hand, instead of doing the subtraction needed in the first IF statement.
As for the message, I'm completely lost. I keep getting a value of 0 instead of a printf statement.

----Please Note that this code is not yet finished!----
As of right now I'm trying just to get it working as though all the requested items are less than the quantity on hand. After that, I should manage to do the rest by myself. (Though if you want to go ahead and finish it for me, I'm fine with that :p )
 
Back
Top