Calcul automatique
Posté : 02 févr. 2015, 19:02
Bonjour à tous,
je coince sur un truc...
En fait j'ai 2 bases de données :
- une pour les coordonnées
- l'autre essentiellement pour des coûts
les deux bases sont liées par un numéro client
BASE des coûts :
BASE de données contact
- qu'une addition se fasse sur le champs "total_revenus" si et seulement si le num_opportunite est identique en fonction du num_client et de la condition WHERE de la requête sql à savoir WHERE derniere_date_modif BETWEEN (str_to_date( '".$choix_date_debut."' , '%d/%m/%Y %H:%i:%s')) AND (str_to_date( '".$choix_date_fin."' , '%d/%m/%Y %H:%i:%s'))
Avez-vous une idée de comment faire ?
Merci par avance.
Cordialement,
je coince sur un truc...
En fait j'ai 2 bases de données :
- une pour les coordonnées
- l'autre essentiellement pour des coûts
les deux bases sont liées par un numéro client
BASE des coûts :
-- phpMyAdmin SQL Dump
-
-- Base de données : `prol`
--
-- --------------------------------------------------------
--
-- Structure de la table `prol_estimation_revenus`
--
CREATE TABLE IF NOT EXISTS `prol_estimation_revenus` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`num_client` int(11) NOT NULL,
`num_opportunite` int(11) NOT NULL,
`q1` int(250) NOT NULL,
`q2` int(250) NOT NULL,
`q3` int(250) NOT NULL,
`q4` int(250) NOT NULL,
`total_revenus` int(250) NOT NULL,
`debut` int(4) NOT NULL,
`fin` int(4) NOT NULL,
`num_form` int(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ;
--
-- Contenu de la table `prol_estimation_revenus`
--
INSERT INTO `prol_estimation_revenus` (`id`, `num_client`, `num_opportunite`, `q1`, `q2`, `q3`, `q4`, `total_revenus`, `debut`, `fin`, `num_form`) VALUES
(28, 10009, 954, 5600, 8400, 8400, 8400, 30800, 2015, 2016, 0),
(29, 10009, 954, 2800, 0, 0, 0, 2800, 2015, 2016, 1);
BASE de données contact
--
-- Structure de la table `crm_prol_clients`
--
CREATE TABLE IF NOT EXISTS `prol_clients` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`quadri_courtier` varchar(50) NOT NULL,
`nom_courtier` varchar(250) NOT NULL,
`prenom_courtier` varchar(250) NOT NULL,
`statut_fiche` varchar(250) NOT NULL,
`num_client_prolival` int(11) NOT NULL,
`quadri_client` varchar(50) NOT NULL,
`rs` varchar(250) NOT NULL,
`civilite_ent` varchar(250) NOT NULL,
`nom_ent` varchar(250) NOT NULL,
`prenom_ent` varchar(250) NOT NULL,
`fonction_ent` varchar(250) NOT NULL,
`adresse` varchar(250) NOT NULL,
`complement_adresse` varchar(250) NOT NULL,
`cp` varchar(5) NOT NULL,
`ville` varchar(250) NOT NULL,
`pays` varchar(250) NOT NULL,
`siret` varchar(15) NOT NULL,
`ca` varchar(250) NOT NULL,
`resultat_ca` varchar(250) NOT NULL,
`effectif_ent` varchar(250) NOT NULL,
`mail` varchar(250) NOT NULL,
`telephone` varchar(20) NOT NULL,
`mobile` varchar(250) NOT NULL,
`fax` varchar(20) NOT NULL,
`activite_ent` varchar(250) NOT NULL,
`creer` int(11) DEFAULT NULL,
`modifier` int(11) DEFAULT NULL,
`publier` int(11) DEFAULT NULL,
`username` varchar(250) NOT NULL,
`sexe_username` varchar(250) NOT NULL,
`client_appele_le` datetime DEFAULT NULL,
`client_a_rappeler` datetime DEFAULT NULL,
`qui_rappel` varchar(250) NOT NULL,
`rendez_vous_debut` datetime DEFAULT NULL,
`rendez_vous_fin` datetime DEFAULT NULL,
`lieux_rdv` varchar(250) NOT NULL,
`objet_rdv` varchar(250) NOT NULL,
`description_rdv` varchar(250) NOT NULL,
`observations` text NOT NULL,
`date_creation_fiche` datetime DEFAULT NULL,
`envoye_par` varchar(250) NOT NULL,
`contact_dell` varchar(250) NOT NULL,
`constructeur` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=738 ;
setlocale(LC_MONETARY, 'it_IT');
// L. 1.234,56
// connexion � la base de donn�es
$conn = db_connect();
// cr�er la liste des membres
$listeMembres = "" ;
$listeContractes = "" ;
$listeAbandonnees = "";
$sql = "SELECT * FROM ".OPPORTUNITES." WHERE derniere_date_modif BETWEEN (str_to_date( '".$choix_date_debut."' , '%d/%m/%Y %H:%i:%s')) AND (str_to_date( '".$choix_date_fin."' , '%d/%m/%Y %H:%i:%s'))";
//echo $sql;
$result = mysql_query($sql) or die(mysql_error());
$addition = "0";
while($result && $row=mysql_fetch_array($result))
{
if (utf8_encode($row['opportunite_etape_commerciale'])!='contractée' || utf8_encode($row['opportunite_etape_commerciale'])!='perdue' || utf8_encode($row['opportunite_etape_commerciale'])!='abandonnée') {
$addition_pipe = $addition_pipe + $row['total_revenus'];
$listeMembres .= "<tr>
<td>".utf8_encode($row['num_opportunite'])."</td>
<td>".utf8_encode($row['entite'])."</td>
<td>".utf8_encode($row['contact_client'])."</td>
<td>".utf8_encode($row['nom_opportunite'])."</td>
<td>".utf8_encode(htmlentities($row['ligne_service_1']))."</td>
<td>".utf8_encode($row['ligne_service_2'])."</td>
<td>".utf8_encode(htmlentities($row['opportunite_etape_commerciale']))."</td>
<td>".utf8_encode(htmlentities($row['quadri_courtier']))."</td>
<td>".utf8_encode(htmlentities($row['estimation_echeance_opportunite']))."</td>
<td style='text-align:right;'>".money_format('%.2n', ($row['total_revenus']))."</td>";
}
J'aimerai si possible :- qu'une addition se fasse sur le champs "total_revenus" si et seulement si le num_opportunite est identique en fonction du num_client et de la condition WHERE de la requête sql à savoir WHERE derniere_date_modif BETWEEN (str_to_date( '".$choix_date_debut."' , '%d/%m/%Y %H:%i:%s')) AND (str_to_date( '".$choix_date_fin."' , '%d/%m/%Y %H:%i:%s'))
Avez-vous une idée de comment faire ?
Merci par avance.
Cordialement,