Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get Sold Qty
Message
 
 
To
26/11/2010 22:06:35
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01490599
Message ID:
01490719
Views:
58
>Dear Naomi
>
>Please write some codes for me.
>
>Thanks

Try
create  cursor open_stock (dates d(8),codes c(4),products c(15),qty n(3),sold n(3),rate n(8,2),amount n(9,2))
insert into open_stock values({^2010-07-01},'1401','Hard Disk',1,0,1100,0)
replace all amount with qty*rate

&& purchase table
create  cursor purchase (dates d(8),codes c(4),products c(15),qty n(3),sold n(3),rate n(8,2),amount n(9,2))
insert into purchase values({^2010-07-01},'1401','Hard Disk',2,0,1200,0)
insert into purchase values({^2010-07-02},'1401','Hard Disk',3,0,1300,0)
insert into purchase values({^2010-07-03},'1401','Hard Disk',4,0,1400,0)
insert into purchase values({^2010-07-03},'1401','Hard Disk',8,0,1500,0)
replace all amount with qty*rate

&& sale table
create  cursor sales (dates d(8),codes c(4),products c(15),qty n(3))
insert into sales values({^2010-07-01},'1401','Hard Disk',2)
insert into sales values({^2010-07-04},'1401','Hard Disk',5)

&& Assuming our cursors are in the correct order - (By Date + Qty desc)
LOCAL ARRAY laSoldQty[1]
SELECT SUM(Qty) as TotalSoldQty FROM Sales INTO ARRAY laSoldQty

LOCAL lnSoldQty, lnQty 
lnSoldQty = laSoldQty[1]
SELECT Open_Stock
SCAN 
  lnQty = Qty 
  IF m.lnSoldQty >= m.lnQty
     replace Sold WITH m.lnQty
     lnSoldQty = m.lnSoldQty - m.lnQty
  ELSE
    && Current Qty is less than qty in the table
    replace Sold WITH m.lnSoldQty
    lnSoldQty = 0
    EXIT
  ENDIF
ENDSCAN

IF m.lnSoldQty > 0
        
   SELECT Purchase
   SCAN 
  lnQty = Qty 
  IF m.lnSoldQty >= m.lnQty
     replace Sold WITH m.lnQty
     lnSoldQty = m.lnSoldQty - m.lnQty
  ELSE
    && Current Qty is less than qty in the table
    replace Sold WITH m.lnSoldQty
    lnSoldQty = 0
    EXIT
  ENDIF
ENDSCAN
ENDIF

SELECT * FROM Open_Stock

SELECT * FROM Purchase
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform