1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| Private Sub btnenregistrercommande_Click()
If (Me.TXTDATECOMMANDE <> "" And Me.TXTSUJETCOMMANDE <> "" And Me.TXTIDCLIENTT <> "" And Me.TXTNBPRODUITS2 <> "") Then
Dim db As DAO.Database
Dim rs As Recordset
Dim idcmd As Integer
''''''''METTRE A JOUR LES INFORMATIONS DE LA COMMANDE'''''''''''''''''''''
idcmd = Int(Me.txtidcommande.Value)
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM commandes WHERE idcommande=" & idcmd, dbOpenDynaset)
rs.Edit
rs("idclient") = Int(Me.TXTIDCLIENTT.Value)
rs("dateCommande") = Int(Me.TXTDATECOMMANDE)
rs("sujet") = Me.TXTSUJETCOMMANDE
rs("montantHT") = CDec(Me.TXTMONTANTHT)
rs("montantTTC") = CDec(Me.TXTMONTANTTTC)
rs.Update
rs.Close
Set rs = Nothing
'''''''''AJOUTER MODIFIER DANS LA TABLE COMMANDEdetails'''''''''''''''
Dim cmdDetails As CommandeDetails
Dim res As Boolean
Dim IdProduit As Integer
Dim qtecommande As Integer
Dim PrixUnitaire As Single
Dim resRch As Integer 'est egal a -1 si le produit n'existe pas dans la table commande
'sinon cette variable est egal la quantite de ce produit
For i = 0 To Me.txtlisteproduitdemandes.ListCount - 1
IdProduit = Int(Me.txtlisteproduitdemandes.Column(0, i))
qtecommande = Int(Me.txtlisteproduitdemandes.Column(3, i))
PrixUnitaire = Int(Me.txtlisteproduitdemandes.Column(2, i))
resRech = ISEXISTEMVTCOMMANDEDETAILS("CommandeDetails", idcmd, IdProduit)
If (resRech = -1) Then '-1 n'existe pas
Set cmdDetails = New CommandeDetails
cmdDetails.IdCommande = idcmd
cmdDetails.IdProduit = IdProduit
cmdDetails.PrixUnitaire = PrixUnitaire
cmdDetails.qtecommande = qtecommande
res = enregistrercommandeDetails(cmdDetails)
Set cmdDetails = Nothing
res = UpdateProduit(IdProduit, qtecommande, "-")
Else
If (resRech <> qtecommande) Then
Dim resl As Boolean
Dim diff As Integer
diff = resRech - qtecommande
rsl = updateMvtCommandeDetails("commandeDetails", idcmd, IdProduit, qtecommande)
If (diff > 0) Then
res = UpdateProduit(IdProduit, Abs(diff), "+")
Else
res = UpdateProduit(IdProduit, Abs(diff), "-")
End If
End If
End If
''''''''METTRE A JOUR LA TABLE MOUVEMENT''''''''''''''''''''''''
resRech = ISEXISTEMVTCOMMANDEDETAILS("mouvements", idcmd, IdProduit)
If (resRech = -1) Then
Dim mvt As mouvement
Set mvt = New mouvement
mvt.datemov = Now
mvt.IdCommande = idcmd
mvt.IdProduit = IdProduit
mvt.PrixUnitaire = PrixUnitaire
mvt.qtecommande = qtecommande
mvt.typemov = "sortie"
res = enregistrerMouvement(mvt)
Set mvt = Nothing
Else
res = updateMvtCommandeDetails("Mouvements", idcmd, IdProduit, qtecommande)
End If
Next i
'SUPPRIMER LES ENREGISTREMNTS DEJA SUPPRIMER LA LISTE txtlisteproduitdemandes COMMANDE DETAILS/MOUVEMENTS
Dim r1, r2, r3, r4
For Each item In copieListeproduits
rl = isexiste(Me.txtlisteproduitdemandes, 0, item.IdProduit)
If (rl = -1) Then 'c'est a dire l'element est supprimer de la liste txtlisteproduitdemandes
r2 = UpdateProduit(item.IdProduit, item.qtecommande, "+") 'RESTAURER LA QUANTITE DU PRODUIT SUPPRIMER
r3 = SupprimerMvtCommandeDetails("commandeDetails", idcmd, item.IdProduit)
r4 = SupprimerMvtCommandeDetails("mouvements", idcmd, item.IdProduit)
End If
Next
Set copieListeproduits = Nothing
DoCmd.Close acForm, Me.Name
DoCmd.Requery
Else
MsgBox "Impossible de mettre a jour cette demmande. Completer les informations svp", vbCritical, "Edition d'une commande"
End If
End Sub |
Partager