Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Matematical question
Message
From
17/01/2019 03:05:36
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
 
To
16/01/2019 17:05:18
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows Server 2012 R2
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01665476
Message ID:
01665487
Views:
100
>Sorry,
>
>for better understanding i attach a small excel file.
>
>Thanks,
>Luis

Try
*Shoe.prg
*as many shoes per size in one box (the box cursor shows size)
*anything else in additional boxes (the box cursor shows size 0)

#DEFINE dnMaxQtPerBox 10

*Result cursor
CREATE CURSOR curBoxes (iOrderNo I,iNumber I,iSize I,iQty I)
*Source cursor (unsorted data)
*sort by tag
*with temp data to display the remainder
CREATE CURSOR curShoes (iOrderNo I,iSize I,iQty I,iBox I,iRemaiSize I,iRemaiTotal I)
INDEX ON BINTOC(iOrderNo)+BINTOC(iSize)+BINTOC(iQty) TAG _Order
INSERT INTO curShoes VALUES (166,40,02,0,0,0)
INSERT INTO curShoes VALUES (165,39,08,0,0,0)
INSERT INTO curShoes VALUES (165,40,01,0,0,0)
INSERT INTO curShoes VALUES (166,36,12,0,0,0)
INSERT INTO curShoes VALUES (165,37,02,0,0,0)
INSERT INTO curShoes VALUES (165,37,09,0,0,0)
INSERT INTO curShoes VALUES (165,38,03,0,0,0)
INSERT INTO curShoes VALUES (165,38,04,0,0,0)
INSERT INTO curShoes VALUES (166,38,03,0,0,0)
INSERT INTO curShoes VALUES (166,39,09,0,0,0)
INSERT INTO curShoes VALUES (166,37,05,0,0,0)
INSERT INTO curShoes VALUES (166,40,03,0,0,0)
INSERT INTO curShoes VALUES (165,36,09,0,0,0)
INSERT INTO curShoes VALUES (166,40,12,0,0,0)

LOCAL;
 lnGrabed,;
 lnRemainderPerOrder,;
 lnRemainderPerSize,;
 lnPackNo,;
 liLastOrder,;
 liSize

STORE 0 TO;
 lnGrabed,;
 lnRemainderPerOrder,;
 lnRemainderPerSize,;
 lnPackNo,;
 liLastOrder,;
 liSize

SCAN
*get data of new record
*process group changes
 DO CASE
  CASE m.liLastOrder#iOrderNo
*new order

   IF !EMPTY(m.lnRemainderPerOrder+lnRemainderPerSize) THEN
*store Remainder
    PackShoes(m.liLastOrder,0,lnPackNo,m.lnRemainderPerOrder+lnRemainderPerSize,.T.)
   ENDIF &&!EMPTY(m.lnRemainderPerOrder+lnRemainderPerSize)

*also first record -> iOrderNo should never be 0
   liLastOrder = iOrderNo
   liSize      = iSize

   STORE 0 TO;
    lnRemainderPerOrder,;
    lnRemainderPerSize,;
    lnPackNo

   lnGrabed   = iQty
*  &&m.liLastOrder#iOrderNo

  CASE m.liSize#iSize
*new size

*store Remainder per size to total Remainder
   lnRemainderPerOrder = m.lnRemainderPerOrder+m.lnRemainderPerSize

*also first record -> iOrderNo should never be 0
   liSize      = iSize

   STORE 0 TO;
    lnRemainderPerSize

   lnGrabed   = iQty
*  &&m.liSize#iSize

  OTHERWISE
   lnGrabed   = m.lnRemainderPerSize+iQty
 ENDCASE

*Try to pack per Size
 PackShoes(m.liLastOrder,m.liSize,@lnPackNo,@lnGrabed,.F.)

 lnRemainderPerSize = m.lnGrabed

 REPLACE;
  iRemaiSize  WITH m.lnRemainderPerSize,;
  iRemaiTotal WITH m.lnRemainderPerOrder
ENDSCAN &&All

*Remainder after last row?
IF !EMPTY(m.lnRemainderPerOrder+lnRemainderPerSize) THEN
 PackShoes(m.liLastOrder,0,@lnPackNo,m.lnRemainderPerOrder+lnRemainderPerSize,.T.)
ENDIF &&!EMPTY(m.lnRemainderPerOrder+lnRemainderPerSize)

SELECT curBoxes
LOCATE
BROWSE LAST NOWAIT

SELECT curShoes
LOCATE
BROWSE LAST NOWAIT

PROCEDURE PackShoes
 LPARAMETERS;
  tnOrder,;
  tnSize,;
  tnPackNo,;
  tnQty,;
  tlPackAll

*process
 DO WHILE m.tnQty>dnMaxQtPerBox-1
*as long as full box (one row might have qty > dnMaxQtPerBox, so more then one box per row)
  tnPackNo = m.tnPackNo+1
  INSERT INTO curBoxes VALUES (m.tnOrder,m.tnPackNo,m.tnSize,dnMaxQtPerBox)
  m.tnQty = m.tnQty-dnMaxQtPerBox
 ENDDO &&m.lnGrabed>9

 IF m.tlPackAll AND tnQty>0 THEN
  tnPackNo = m.tnPackNo+1
  INSERT INTO curBoxes VALUES (m.tnOrder,m.tnPackNo,m.tnSize,m.tnQty)

  m.tnQty = 0
 ENDIF &&m.tlPackAll AND tnQty>0
ENDPROC &&PackShoes
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform