Dear all..
I try to make an inventory control, with FIFO(first in first out) base, but I have a problem with the next record.
this is the code i make :
[PHP]$db = new clsDBMassimo;
$product_id = $Stock->product_id->GetValue();
$AmOrdered = $Stock->stock_out_un it->GetValue();
//check if the stock is enough
$sql = "SELECT SUM(stock_in_un it) as Total FROM stock_level WHERE product_id = $product_id";
$db->query($sql);
$result = $db->next_record( );
if($result) ($Total = $db->f("Total"));
//if stock not enough, then cancel insert and give error message, but i still have an error
if($Total < $AmOrdered){
$Stock->Errors->addError("Stoc k Not Enough");=>in this part also have problem.event
$db->close(); though I already add an error, but stock out still inserted on table.any suggestion?
}else{ //if the stock is enough then select from table stock_level
$sql = "SELECT * FROM stock_level WHERE product_id = $product_id ORDER BY in_date";
$db->query($sql);
$result= $db->next_record( );
$IDnya = $db->f("stock_level _id");
$AmOnHand = $db->f("stock_in_un it");
while($db->next_record()) {
//loop as long as amount ordered > 0
while ($AmOrdered > 0){
if($AmOrdered < $AmOnHand){
$Res = $AmOnHand - $AmOrdered;
$update = "UPDATE stock_level SET stock_in_unit = $Res where stock_level_id = $IDnya";
$db->query($update) ;
$AmOrdered = 0;
}else{
$AmOrdered = $AmOrdered - $AmOnHand;
$update = "UPDATE stock_level SET stock_in_unit = 0 where stock_level_id = $IDnya";
$db->query($update) ;
//here should be move to the next record to get the next stock, but can not move to next record
}
}
}
$db->close();
} [/PHP]
Please give any suggestions, for the error I got or for the code structure. any helps are appreciated.
Thanks a lot
4 2317 dlite922 1,584
Recognized Expert Top Contributor
Let's see your next record function.
does it correctly? ie each time the while loop calls it, it returns the next record until empty?
try to put "echo" or "die('messa ge'" statement to try to see how the code is executing (tracing the logic)
Let us know...
Dan
Hi
thanks for reply. I forget to attach the function. Here's the function :
[PHP]function next_record() {
if (!$this->Query_ID)
return 0;
$this->Record = @mysql_fetch_ar ray($this->Query_ID);
$this->Row += 1;
$this->Errno = mysql_errno();
$this->Error = mysql_error();
$stat = is_array($this->Record);
if (!$stat && $this->Auto_Free) {
$this->free_result( );
}
return $stat;
}[/PHP]
dlite922 1,584
Recognized Expert Top Contributor
I think the problem lies in your db class and or in the way you are using it.
Did you write that class yourself?
you're initializing $result twice, with the same thing function call. In this case, next_record(). This function returns a boolean if the next record exists.
For example if you have only one record, the second time you call it, it will return false.
I wish I could help you more, but you must debug this yourself. I'm not too sure of the problem your having either, you didn't describe the issue well enough.
Dan
Hi Dan..
Thank you for your reply. You're right, the problem is the way I use my class.
After few day stuck, finally i did it :)
Thank you
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jason |
last post by:
Access 2000:
I have a customer-inventory table I need to loop through and compile a list
of all the inventory items the customer is tracking. The problem I am
finding is that a simple loop will pull out the customer details each time
their is an inventory item listed....I need to get the customer out ONCE and
list his items....is there an elegant way to do this:
Here is the table:
Cust-Invent Table
|
by: Rohit Raghuwanshi |
last post by:
Hello all,
we are running a delphi application with DB2 V8.01 which is causing
deadlocks when rows are being inserted into a table. Attaching the
Event Monitor Log (DEADLOCKS WITH DETAILS) here. From the log it looks
like the problem happens when 2 threads insert 1 record each in the
same table and then try to aquire a NS (Next Key Share)
lock on the record inserterd by the other thread.
Thanks
Rohit
|
by: pankaj_wolfhunter |
last post by:
Hi,
I need some clearance on the following questions:
1) Does LOAD command updates indexes defined for a table?
2) Is REPLACE option in the LOAD command a logged operation?
Help will be greatly appreciated.
TIA
|
by: qsweetbee |
last post by:
I have a form(fAddUsers) in my database. It is continue form for data
entry. Some fields are required fields. Some are optional fields.
There is 1 particular filed(TokenExpirationDate)on the form which is
depended on the other field(TokenID)whether it is blank or not. If
the "TokenID" field is blank, the "TokenExpirationDate" field can be
blank also. But if the "TokenID" field is not blank or null, the
"TokenExpirationDate" field must be...
|
by: James Fortune |
last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't
understand why people who know how to write code to completely replace
a front end do not write something that will automate the code that
implements managing unbound controls on forms given the superior
performance of unbound controls in a client/server environment. I can
easily understand a newbie using bound controls or someone with a
tight deadline. I guess I need...
| |
by: Peter Newman |
last post by:
vb.net 2003 Sql 2005
Ive been banging my head against a brick wall for the last day trying to
figure out what im doing wrong
I have a Dataset and a Form with text boxes that are bound to the dataset.
If i edit a record how do i trap for the
Dataset.HasChanges and update the datsbase as im doing it when i move from
one record to the next. this causes untold greif. what i want to do is
when clicking the btnNext get anychanges and give...
|
by: Peter Herath |
last post by:
I have created a report using sample codes taken by the forum. one problem is that the report displays the field/column names in the table in columnar format(field names display in rows.) but i want to be able to display filed names and its relevant data in tabular format in the repor but the code itself just displays only the fields in rows and another problem is that, to set the record source. the way i set the record source property of the...
|
by: StevenChiasson |
last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller.
This is more or less, your standard dynamic address book program. Adding, and listing work just fine. However, deleting, editing and viewing relies on member function retAddress. This function returns an array of pointers that are pointing to created objects. In action, all it...
|
by: LanaR |
last post by:
Hello,
one sql statement is causing severe performance issue. The problem occurs only in UDB environment, the same statemnt on the mainframe is running fine. I have an explain output from the sql. The statement itself is not that complicated, it is 3 selects and union all. Explain output is pretty big, but I could not find anything unusual. I'm new to db2 and I could be missing stuff. I am posting the explain output below and I really...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |