Cet écran permet d'enregistrer une réception de marchandise. L'objectif est de mettre à jour le stock automatiquement.
Mécanisme de mise à jour du stock : Lors de la validation d'une entrée, on doit :
Exemple de Code WLangage (Validation Entrée) :
// Parcours des lignes de la table mémoire (Table_LigneEntree)
POUR TOUTE LIGNE nLigne DE Table_LigneEntree
// Recherche du produit concerné
HLitRecherchePremier(Produit, IDProduit, Table_LigneEntree.COL_IDProduit[nLigne])
SI HTrouve(Produit) ALORS
// Mise à jour du stock
Produit.QuantiteStock += Table_LigneEntree.COL_Quantite[nLigne]
HModifie(Produit)
FIN
FIN
Info("Entrée enregistrée et stock mis à jour.")
// Initialiser le contrôle PDF (invisible à l'exécution) PDFGestion est un PDFControl PDFGestion.CréeDocument()// Ajouter une police et un titre PDFGestion.AjoutePolice("Arial", 14, gras) PDFGestion.AjouteTexte(10, 10, "INVENTAIRE MENSUEL - MAGASIN CENTRAL") PDFGestion.AjouteLigne(10, 25, 200, 25, 1)
// Boucle sur les produits LirePremier(Produit) TANT QUE NON(Fin(Produit)) y = PDFGestion.CréePosition(10, yPos) PDFGestion.AjouteTexte(10, y, Produit.Réf) PDFGestion.AjouteTexte(50, y, Produit.Désignation) PDFGestion.AjouteTexte(150, y, Produit.Stock_Actif) LireSuivant(Produit) FIN
// Sauvegarde PDFGestion.SauveDocument("C:\Rapport.pdf") PDFGestion.FermeDocument()gestion de stock windev pdf
Avantage : Contrôle absolu sur la mise en page. Inconvénient : Plus long à coder qu’un état.
// Button "Export to PDF" on WIN_Products
PROCEDURE ExportStockToPDF()
sFileName = "Stock_Report_" + DateToString(Today(), "YYYYMMDD") + ".pdf"
// Execute report
iReportOpen(RPT_StockList, "", "", "", iWithoutParameter)
// Export to PDF
iExportToPDF(RPT_StockList, CompleteDir(sCurrentDir()) + sFileName, 1, 30)
// Confirmation
Info("PDF generated: " + sFileName)
// Optional: automatically open PDF
ShellExecute("open", sFileName)
WinDev possède un éditeur d'états puissant.
Pour générer un PDF via le code :
iDestination(iPDF, "C:\Temp\EtatStock.pdf")
iImprimeEtat(ETAT_Stock_Global)
LanceAppli("C:\Temp\EtatStock.pdf")
Dans l’éditeur de WinDEV :
Use a Window with input fields for Product, Quantity, and Type (Combo box: "IN" or "OUT").
Sample Code for Adding a Movement (in the "Validate" button):
// Add movement record MovementID = HMax("STOCK_MOVEMENT", "MovementID") + 1 HAdd("STOCK_MOVEMENT", MovementID, ProductID, Quantity, Type, CurrentDate(), Reason)// Update product stock IF Type = "IN" THEN HModify("PRODUCT", ProductID, "CurrentStock", CurrentStock + Quantity) ELSE HModify("PRODUCT", ProductID, "CurrentStock", CurrentStock - Quantity) END
// Refresh display TableDisplay(TABLE_Products)
Best practice: Wrap the two writes (movement + product update) in a transaction:
HTransactionStart() ... (HAdd, HModify) ... IF HTransactionEnd() = False THEN Error("Transaction failed")
| Problem | Likely Cause | Solution |
|---------|--------------|----------|
| Stock becomes negative | No check before OUT movement | Add validation: IF Quantity > CurrentStock THEN Error("Insufficient stock") |
| PDF report looks different on screen vs printed | Page margins or font embedding | In report editor, set "PDF options" → Embed fonts |
| Slow stock summary report | Missing index on ProductID in STOCK_MOVEMENT | Create index: HCreateIndex("STOCK_MOVEMENT", "ProductID") |
| Transaction fails but data partially saved | No error handling | Always check HTransactionEnd() and rollback on error |
WINDEV provides a complete environment for building professional stock management applications:
Next steps: