This topic is locked

Inventory Tracking in MySQL

11/5/2008 4:29:30 PM
PHPRunner General questions
C
chaintm author

Hello all,
Been working with tech support (btw great bunch of people) on some issues, but one here is more of a general question then technical support.
I am not all that great with mysql and php however, I know enough to be dangerous <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=10091&image=1&table=forumtopics' class='bbc_emoticon' alt=';)' />, so what I am looking to do is the following.
I have the following tables (but a ton more obviously but for what I need to get working, this is only part)..
===========================

[order_sales] - Order_num (master key)

  • event_time_start
  • event_time_end

    =============================

    [order_items] -order_num

    -ItemID

    ============================

    [items] - ItemID (master key)

    ============================
    Concept:
    order_sales is a huge table storing all order data, the initial start however is stated above. The user only can enter a time/date start and end the order number is generated by this automaticly once submited.

    After submission, the user is re-directed the order_items page. This has a pulldown menu with all items listed linking from the items table. When a user is searching this , I want to flag the system to say
    "Current selection is schedualed for use during selected times, are you sure you want to continue?"
    Idea here is that prior to the user loading the order_items page, the system checks the start and end times (and between) against other order_sales allready submitted to the system. When it does this , the next step is the check within those particular orders for items listed in those orders. So my thought process is this....
    Going in the "add page before process" (this taken from the reservation templete)
    [codebox]$rstt = CustomQuery("select from order_sales where Order_num=" . $values["Order_num"]);

    $rstt = $dal->order_sales->Query("Order_num=" . $values["Order_num"],"");

    while($rsh=db_fetch_array($rstt))

    {

    if($values["event_time_start"]>=$rsh["event_time_start"] && $values["event_time_start"]<=$rsh["event_time_end"] || $values["event_time_end"]>=$rsh["event_time_start"] && $values["event_time_end"]<=$rsh["event_time_end"] || $values["event_time_start"]<=$rsh["event_time_start"] && $values["event_time_end"]>=$rsh["event_time_end"])

    {

    $smarty->assign("message2","<div class=message><<< "Current selection is schedualed for use during selected times, are you sure you want to continue?">>></div>");

    return false;

    }

    }return true;[/codebox]
    Now while that should work for getting my times sorted, I need to referance the outcome to then check the values of ItemID under said order_sales... so..
    [codebox]$rstt = CustomQuery("select
    from order_items where Order_num=" . $values["order_num"]);

    $rstt = $dal->order_sales->Query("order_num=" . $values["order_num"],"");

    while($rsh=db_fetch_array($rstt))

    {

    if($values["????????"]<$rsh["????????????"])

    {

    $xt->assign("message2","<div class=message><<< Selected item is out of stock for this day >>></div>");

    return false;

    }

    }

    return true;[/codebox]
    I get lost here, I know I can check for the start middle and end date and times, do I need to assign this outcome with a new value? then call upon that value to check items within those orders? then after that if any item selected in the current order_items is selected from that list I get the response? I get how mathmatically it all works, I guess I need to learn more about structure and mostly syntex. The way I see it going in my head is ...
    If current order date/time end/start = any other order date/time end/start then query orders items , if items = current selected item then flag echo response. if not then do nothing.
    Or would it make sense if the sytem just subtracts from a total , I have a line for physical inventory and actual inventory. So I could use the physical as a constant regenerated number that is done after all this script executes and if that number is => then inventory number ignore, if <number echo response?
    I am desperate to get this working for my boss, any help or private help would be appreicated. Contact me anytime chaintm@yahoo.com and refer to this issue.. if you can help I would be in your debt.
    Hope this all makes sense,
    Noel B.

C
chaintm author 11/5/2008

Doh! I should also add,
I have the following code allready running on this page...
[codebox]$str = "select ItemRentalPrice,ItemThumb from items where ItemID='".$values["ItemID"]."'";

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

$values ['ItemRentalPrice'] = $data['ItemRentalPrice'];

$values ['ItemThumb'] = $data['ItemThumb'];

$values["Sub_total"] = $values["Qty_order"]$values["ItemRentalPrice"]1;$_SESSION["ItemThumb"] = $data["ItemThumb"];

$_SESSION["ItemRentalPrice"] = $data["ItemRentalPrice"];

return true;

[/codebox]
Another confusion issue I have with mysql is understand the $rs values etc, can it be stacked? can you mutli-query things when u need a bunch of stuff to happen? IE... can I do a $rs = CustomQuery($str)($str1))$str2); etc?
Again thnx all for any help in this.
Noel B.

J
Jane 11/6/2008

Hi,
execute each query separately:

$rs1 = CustomQuery($str1);

$rs2 = CustomQuery($str2);

C
chaintm author 11/6/2008

Jane you are the best btw <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=34841&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> very helpfull <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=34841&image=2&table=forumreplies' class='bbc_emoticon' alt=':)' />
Thnx for that info,
I came to a thought last night and wrote it down, what if I did it this way for the tracking...
Using the time/date checker code above that checks to see if the current order is = to any others. Could I not then just add to that code something like below?...
======================

Do date/time check AND THEN if current itemID = date/time check itemID's then echo "not avalible are you sure you want to continue?"
=====================
How would I go about this? I know you can compare values etc, what if I compare the values of time as the code on the first post in this thread , could I not just add another statement below to check then all those times found to see if the current value ItemID is = to any ItemID value from the time/date search? if possible can I see an excample? That would be great!
Noel B

J
Jane 11/7/2008

Hi,
to check two dates use following code:

if (strtotime($values["StartDateField"])-strtotime($values["EndDateField"])<0)

echo "Incorrect date";

C
chaintm author 11/7/2008

Well not exactly what I wanted , but I can use that concept to check a value = the other after the date search is done. So using your excample, I can run my date/time checker <>= to current and then run the comparrison to itemID using the date idea you are giving <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=34887&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> I will give this a shot.

C
chaintm author 11/10/2008

I sent this in email as well just encase and if responded there will follow up here for others to refer too..
Does the IF statement and the THEN statement work like this?? Can someone help me clean up the

syntex a bit? I think I have it right, just something missing I think, I might have repeat values, not

sure if some are even needed at this point. I figure someone with a bit more experiance can look at this code

and say, "yea, you need to change it like this..."
BEFORE RECORD ADDED...
[codebox]$str = "select ItemID from order_item where Order_num =".$_SESSION [$strTableName."_masterkey1"];

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

$values ['ItemID] = $data['ItemID'];

$_SESSION["ItemID"] = $data["ItemID"];
if($_SESSION["ItemID"] =
ItemID from order_items);

THEN

$rstt = CustomQuery("select * from order_sales where Order_num=".$_SESSION [$strTableName."_masterkey1"];$rstt = $dal->order_sales->Query("Order_num=" . $values["Order_num"],"");

while($rsh=db_fetch_array($rstt))

{

if($values["event_time_start"]>=$rsh["event_time_start"] && $values["event_time_start"]<=$rsh["event_time_end"] || $values["event_time_end"]>=$rsh["event_time_start"] && $values["event_time_end"]<=$rsh["event_time_end"] || $values["event_time_start"]<=$rsh["event_time_start"] && $values["event_time_end"]>=$rsh["event_time_end"]) {

$xt->assign("message2","<div class=message><<< Selected item is already schedualed for these dates >>></div>");

return false;

}

}return true;// return true if you like to proceed with adding new record

// return false in other case [/codebox]
Now the session is the current item selected in the pulldown box and I am using that for the check to

see if the item is being used in any other order. If it is , THEN the system checks the times to make

sure if the times are within the given current order time. If not, nothing happens, if so a message is given.

J
Jane 11/11/2008

answered in your personal email.

C
chaintm author 11/12/2008

Thank you, getting really close, sent another email, I am very close to getting it done <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=34995&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
//Fatal error: Call to undefined function CustomeQuery() in D:\vhosts\mj4u\output\include\order_items_events.php on line 201
marked in the code, is the error I am getting ,current build up has this build, it is the
http://demo.asprunner.net/chaintm_yahoo_co...r_items_add.php
once upon submit, the error occurs, I have it going with partial code, I think I am just off on wording?
[codebox]//=============== carry over values from other tables ===========//

$str = "select ItemRentalPrice,ItemThumb from items where ItemID='".$values["ItemID"]."'";

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

$values ['ItemRentalPrice'] = $data['ItemRentalPrice'];

$values ['ItemThumb'] = $data['ItemThumb'];

$values["Sub_total"] = $values["Qty_order"]$values["ItemRentalPrice"]1;

$_SESSION["ItemThumb"] = $data["ItemThumb"];

$_SESSION["ItemRentalPrice"] = $data["ItemRentalPrice"];

//============== global ======================//

global $strTableName;

//============ query ItemID from order_items table to see if duplicate ItemID ==========//

$str = "select ItemID from order_items where ItemID=".$values["ItemID"];

$rs = CustomQuery($str);

if ($data = db_fetch_array($rs))

{

//============ query from order_items table for Order_num ========//

$str = "select Order_num from order_items where Order_num=".$_SESSION[$strTableName."_masterkey1"];

$rs = CustomeQuery($str); //Fatal error: Call to undefined function CustomeQuery() in D:\vhosts\mj4u\output\include\order_items_events.php on line 201

}

if ($data = db_fetch_array($rs))

{

//===========query from order_sales table for dates======//

global $dal;

$rstt = $dal->order_sales->Query("Order_num=" . $values["Order_num"],"");

$rsh=db_fetch_array($rstt);

}

if($values["event_time_start"]>=$rsh["event_time_start"] && $values["event_time_start"]<=$rsh["event_time_end"] ||

$values["event_time_end"]>=$rsh["event_time_start"] && $values["event_time_end"]<=$rsh["event_time_end"] ||

$values["event_time_start"]<=$rsh["event_time_start"] && $values["event_time_end"]>=$rsh["event_time_end"])

{

echo "duplicate item for this order";

return false;

}

else

{

return true;

}[/codebox]