• Rajaa ABOUMAAD
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
hello, I'm trying to affect a value to a field depending on the value of two other, for example if the quantity of a product requested by a seller is greater than the quantity in the store, the value of our field must be the value of the quantity in the store, this is my code and thank you in advance

VF page:
 
<apex:page controller="ProduitDemandeClass"  >
    
    <apex:form >
        
        <apex:pageBlock >
            <apex:commandButton value="Enregistrer" />
            
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!produitsDemande}" var="pr">
                    <apex:column value="{!pr.Produit__c}"/>
                    <apex:column value="{!pr.Quantit_demande__c}" />
                    <apex:column value="{!pr.Quantit_Accorde__c}"/>
                    <apex:column headerValue="Action">
                        <apex:commandButton value="Modifier"  onclick="window.location='/apex/ValeurAccorde?id={!pr.Produit__c}'; return false;" />
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

apex class:
 
public with sharing class ProduitDemandeClass {
    public String  idcharg {get;set;}
    LIST<les_Produit_demander__c> produitsDemande  {get;set;} 
    
    public List<les_Produit_demander__c> getproduitsDemande() {
        
        if(produitsDemande == null){
            
            produitsDemande = [select Id,Produit__c,Quantit_demande__c,Quantit_Accorde__c from  les_Produit_demander__c where Demande_de_Chargement__c= :idcharg];
            Integer i=0;
            for(les_Produit_demander__c pr :produitsDemande){
                list<Stock_par_agence__c> p =[select QuantiteTotaleRestante__c from 	Stock_par_agence__c where 	Produit__c= :pr.Produit__c];
                if(p != null && p.size() > 0){
                    if(p.get(0).QuantiteTotaleRestante__c > pr.Quantit_demande__c){
                        pr.Quantit_Accorde__c=pr.Quantit_demande__c;
                   
                        update pr;
                    }
                    else {
                        pr.Quantit_Accorde__c=p.get(0).QuantiteTotaleRestante__c;
                        
                       update pr;
                       
                    }
                } 
            }
             
        }
        return produitsDemande;
    }
    
    public ProduitDemandeClass(){
        idcharg=ApexPages.currentPage().getParameters().get('id');
    }
}



 
hello, I'm trying to affect a value to a field depending on the value of two other, for example if the quantity of a product requested by a seller is greater than the quantity in the store, the value of our field must be the value of the quantity in the store, this is my code and thank you in advance

VF page:
 
<apex:page controller="ProduitDemandeClass"  >
    
    <apex:form >
        
        <apex:pageBlock >
            <apex:commandButton value="Enregistrer" />
            
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!produitsDemande}" var="pr">
                    <apex:column value="{!pr.Produit__c}"/>
                    <apex:column value="{!pr.Quantit_demande__c}" />
                    <apex:column value="{!pr.Quantit_Accorde__c}"/>
                    <apex:column headerValue="Action">
                        <apex:commandButton value="Modifier"  onclick="window.location='/apex/ValeurAccorde?id={!pr.Produit__c}'; return false;" />
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

apex class:
 
public with sharing class ProduitDemandeClass {
    public String  idcharg {get;set;}
    LIST<les_Produit_demander__c> produitsDemande  {get;set;} 
    
    public List<les_Produit_demander__c> getproduitsDemande() {
        
        if(produitsDemande == null){
            
            produitsDemande = [select Id,Produit__c,Quantit_demande__c,Quantit_Accorde__c from  les_Produit_demander__c where Demande_de_Chargement__c= :idcharg];
            Integer i=0;
            for(les_Produit_demander__c pr :produitsDemande){
                list<Stock_par_agence__c> p =[select QuantiteTotaleRestante__c from 	Stock_par_agence__c where 	Produit__c= :pr.Produit__c];
                if(p != null && p.size() > 0){
                    if(p.get(0).QuantiteTotaleRestante__c > pr.Quantit_demande__c){
                        pr.Quantit_Accorde__c=pr.Quantit_demande__c;
                   
                        update pr;
                    }
                    else {
                        pr.Quantit_Accorde__c=p.get(0).QuantiteTotaleRestante__c;
                        
                       update pr;
                       
                    }
                } 
            }
             
        }
        return produitsDemande;
    }
    
    public ProduitDemandeClass(){
        idcharg=ApexPages.currentPage().getParameters().get('id');
    }
}