I have a very strange situation here:
I have a report done in the following way:
I do a select sql into a cursor called rapport
If I do a BROWSE before calling my report, it works perfectly
If I don't, only the FIRST LINE of details comes out (repeately).
???!!! Am I crazy or what ??!!
Here is the code:
LPARAMETERS pClientId
PRIVATE lSubTotal, lGST, lPST, lTotal, lcur_blno
PUBLIC pInvno
STORE oSession.get_next_id("INVOICE") TO pInvno
STORE DATE() TO linvdate
SELECT bld.*,;
bl.ident,;
bl.clientid, bl.blno, bl.consname, bl.ref_client,;
bl.pick_date, bl.deliv_date,;
bl.amount AS bl_amount, ;
bl.mnt_gst as bl_mnt_gst,;
bl.mnt_pst AS bl_mnt_pst,;
bl.curr,;
arclient.code,;
arclient.offname, arclient.addr1, arclient.addr2,;
arclient.city, arclient.state, arclient.zip, arclient.country,;
arclient.tel1, arclient.fax, arclient.email,;
arclient.crlimit, arclient.gst_exem, arclient.pst_exem,;
arclient.terms, arclient.terms_days,;
blzone.descr AS zone, blserv.descrfr AS serviceFr, blserv.descren AS serviceEn,;
linvdate AS invdate,;
pInvno AS invno,;
0000000000.00 AS inv_subtotal,;
0000000000.00 AS inv_gst,;
0000000000.00 AS inv_pst,;
0000000000.00 AS inv_total;
FROM bld, bl, arclient;
LEFT OUTER JOIN blzone ON blzone.ident = bl.zoneid;
LEFT OUTER JOIN blserv ON blserv.ident = bl.serviceid;
WHERE bl.ident = bld.idbl AND;
bl.clientid = pClientId AND;
arclient.ident = bl.clientid;
ORDER BY bld.idbl, bld.bldline;
INTO CURSOR rapport READWRITE
*-----------------------------------------------------------*
* Creation de la facture *
*-----------------------------------------------------------*
* 1) On va chercher les totaux
SELECT rapport
GO TOP
STORE 0 TO lSubTotal
STORE 0 TO lGST, lPST
STORE 0 TO lTotal
STORE 0 TO lcur_blno
DO WHILE !EOF()
IF lcur_blno != rapport.blno
STORE rapport.blno TO lcur_blno
lSubTotal = lSubTotal + rapport.bl_amount
lGST = lGST + rapport.bl_mnt_gst
lPST = lPST + rapport.bl_mnt_pst
ENDIF
SELECT rapport
SKIP
ENDDO
lTotal = lSubTotal + lGST + lPST
* 2) On fait le header de facture
STORE oSession.get_next_id("ARINV") TO lident
INSERT INTO arinv(ident,;
type,;
invnocode, invno,;
invdte, duedte,;
acc_year, acc_period,;
consolid, activity, consolno,;
fileid, dept,;
status,;
custid,;
descr,;
inv_mnt, inv_tx_gst, inv_tx_pst,;
mnt_paid, curr,;
cur_rate,;
cr_by, cr_datetime,;
mod_by, mod_datetime,;
posted,;
printed,;
notes,;
voided,;
inv_duty, inv_tx_tvh);
VALUES (lident,;
"R",;
"", pInvno,;
linvdate, linvdate + arclient.terms_days,;
oSession.cur_op_year, oSession.cur_op_period,;
0, wscie.bl_activity, 0,;
0, "BL",;
"P",;
pClientId,;
"LOCAL TRUCKING",;
lTotal, lGst, lPST,;
0, oSession.Currency,;
1,;
oSession.USerCode, DATETIME(),;
oSession.UserCode, DATETIME(),;
.F.,;
.T.,;
"",;
.F.,;
0, 0)
* 3) On fait les détails de la facture
* (En meme temps, on inscrit les totaux)
SELECT rapport
GO TOP
i=1
DO WHILE !EOF()
i=i+1
INSERT INTO arinvd (ident, invline,;
invcode,;
descr,;
inv_mnt, inv_mnt_cur,;
tx_gst_code, tx_pst_code,;
isduty,;
tx_tvh_code);
VALUES (lident, i,;
rapport.invcode,;
rapport.descr,;
rapport.amount, rapport.curr,;
IIF(rapport.appl_gst,1,0), IIF(rapport.appl_pst,1,0),;
.f.,;
0)
i=i+1
SELECT rapport
REPLACE rapport.inv_subtotal WITH lSubTotal
REPLACE rapport.inv_gst WITH lGst
REPLACE rapport.inv_pst WITH lPst
REPLACE rapport.inv_total WITH lTotal
SKIP
ENDDO
* 4) Indiquer au bl qu'il est facturé (chacun d'eux)
SELECT rapport
GO TOP
STORE 0 TO lcur_blno
DO WHILE !EOF()
IF lcur_blno != rapport.blno
STORE rapport.blno TO lcur_blno
UPDATE bl SET invoiced = .T.,;
idinv = lident;
WHERE ident = rapport.ident
ENDIF
SELECT rapport
SKIP
ENDDO
SELECT bl
=TABLEUPDATE(2,.T.)
*-----------------------------------------------------------*
SELECT rapport
GO TOP
BROWSE && If I comment this line, it will show n times the 1st detailed line
&& (n being the number of detailed lines)
MODIFY REPORT blinv
REPORT FORM blinv PREVIEW