diff --git a/dev/initdemo/initdemo.sql b/dev/initdemo/initdemo.sql index 30b4cc1ea0e..663cba0dde8 100644 --- a/dev/initdemo/initdemo.sql +++ b/dev/initdemo/initdemo.sql @@ -1399,60 +1399,6 @@ INSERT INTO `llx_chargesociales` VALUES (1,'2002-05-15 00:00:00','Acompte 1er Tr /*!40000 ALTER TABLE `llx_chargesociales` ENABLE KEYS */; UNLOCK TABLES; --- --- Table structure for table `llx_co_fa` --- - -DROP TABLE IF EXISTS `llx_co_fa`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `llx_co_fa` ( - `rowid` int(11) NOT NULL auto_increment, - `fk_commande` int(11) NOT NULL default '0', - `fk_facture` int(11) NOT NULL default '0', - PRIMARY KEY (`rowid`), - KEY `fk_commande` (`fk_commande`), - KEY `fk_facture` (`fk_facture`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -SET character_set_client = @saved_cs_client; - --- --- Dumping data for table `llx_co_fa` --- - -LOCK TABLES `llx_co_fa` WRITE; -/*!40000 ALTER TABLE `llx_co_fa` DISABLE KEYS */; -/*!40000 ALTER TABLE `llx_co_fa` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `llx_co_pr` --- - -DROP TABLE IF EXISTS `llx_co_pr`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `llx_co_pr` ( - `rowid` int(11) NOT NULL auto_increment, - `fk_commande` int(11) default NULL, - `fk_propale` int(11) default NULL, - PRIMARY KEY (`rowid`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -SET character_set_client = @saved_cs_client; - --- --- Dumping data for table `llx_co_pr` --- - -LOCK TABLES `llx_co_pr` WRITE; -/*!40000 ALTER TABLE `llx_co_pr` DISABLE KEYS */; -/*!40000 ALTER TABLE `llx_co_pr` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `llx_commande` --- - DROP TABLE IF EXISTS `llx_commande`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -2730,30 +2676,6 @@ LOCK TABLES `llx_export_model` WRITE; /*!40000 ALTER TABLE `llx_export_model` ENABLE KEYS */; UNLOCK TABLES; --- --- Table structure for table `llx_fa_pr` --- - -DROP TABLE IF EXISTS `llx_fa_pr`; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -CREATE TABLE `llx_fa_pr` ( - `rowid` int(11) NOT NULL auto_increment, - `fk_facture` int(11) default NULL, - `fk_propal` int(11) default NULL, - PRIMARY KEY (`rowid`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -SET character_set_client = @saved_cs_client; - --- --- Dumping data for table `llx_fa_pr` --- - -LOCK TABLES `llx_fa_pr` WRITE; -/*!40000 ALTER TABLE `llx_fa_pr` DISABLE KEYS */; -/*!40000 ALTER TABLE `llx_fa_pr` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `llx_facture` -- diff --git a/doc/dev/dbmodel/dolibarr_schema.xml b/doc/dev/dbmodel/dolibarr_schema.xml index 9d89676fa5e..e394c88cc7f 100644 --- a/doc/dev/dbmodel/dolibarr_schema.xml +++ b/doc/dev/dbmodel/dolibarr_schema.xml @@ -2286,86 +2286,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -4449,43 +4369,6 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index c277d8f926b..a9909f52738 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -604,8 +604,15 @@ class Commande extends CommonObject { if ($this->id && $this->propale_id) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_pr (fk_commande, fk_propale) VALUES ('.$this->id.','.$this->propale_id.')'; - $this->db->query($sql); + // Add proposal link + // TODO normaliser ? + $this->origin_id = $this->propale_id; + $this->origin = "propal"; + $ret = $this->add_object_linked(); + if (! $ret) + { + dol_print_error($this->db); + } // On recupere les differents contact interne et externe $prop = New Propal($this->db, $this->socid, $this->propale_id); @@ -932,11 +939,11 @@ class Commande extends CommonObject $sql.= ', c.note, c.note_public, c.ref_client, c.model_pdf, c.fk_adresse_livraison'; $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= ', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_facture'; - $sql.= ', cp.fk_propale'; + $sql.= ', el.fk_source'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'cond_reglement as cr ON (c.fk_cond_reglement = cr.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id)'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'co_pr as cp ON (cp.fk_commande = c.rowid)'; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = c.rowid AND el.targettype = '".$this->element."'"; $sql.= " WHERE c.entity = ".$conf->entity; if ($ref) $sql.= " AND c.ref='".$ref."'"; else $sql.= " AND c.rowid=".$id; @@ -978,7 +985,7 @@ class Commande extends CommonObject $this->date_livraison = $obj->date_livraison; $this->adresse_livraison_id = $obj->fk_adresse_livraison; // TODO obsolete $this->fk_delivery_address = $obj->fk_adresse_livraison; - $this->propale_id = $obj->fk_propale; + $this->propale_id = $obj->fk_source; $this->lignes = array(); if ($this->statut == 0) $this->brouillon = 1; @@ -1878,7 +1885,9 @@ class Commande extends CommonObject $err++; } - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."co_pr WHERE fk_commande = ".$this->id; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; + $sql.= " WHERE fk_target = ".$this->id; + $sql.= " AND targettype = ".$this->element; if (! $this->db->query($sql) ) { $err++; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index f4225156be1..9e7b2b0b2b7 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -2081,9 +2081,12 @@ else /* * Liste des factures */ - $sql = 'SELECT f.rowid,f.facnumber, f.total_ttc, '.$db->pdate('f.datef').' as df'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'co_fa as cf'; - $sql .= ' WHERE f.rowid = cf.fk_facture AND cf.fk_commande = '. $commande->id; + $sql = "SELECT f.rowid,f.facnumber, f.total_ttc, ".$db->pdate('f.datef')." as df"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."element_element as el"; + $sql.= " WHERE f.rowid = el.fk_target"; + $sql.= " AND el.fk_source = ".$commande->id; + $sql.= " AND el.sourcetype = '".$commande->element."'"; $result = $db->query($sql); if ($result) diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index dcd4ff51a83..6f48b79cb6f 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -868,16 +868,21 @@ class CommonObject /** * Load array of objects linked to current object. Links are loaded into this->linked_object array. */ - function load_object_linked() + function load_object_linked($sourceid='',$sourcetype='',$targetid='',$targettype='') { $this->linked_object=array(); + + $sourceid = (!empty($sourceid)?$sourceid:$this->id); + $targetid = (!empty($targetid)?$targetid:$this->id); + $sourcetype = (!empty($sourcetype)?$sourcetype:$this->origin); + $targettype = (!empty($targettype)?$targettype:$this->element); // Links beetween objects are stored in this table $sql = 'SELECT fk_source, sourcetype, fk_target, targettype'; $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; - $sql.= " WHERE (fk_source = '".$this->id."' AND sourcetype = '".$this->origin."')"; - $sql.= " OR (fk_target = '".$this->id."' AND targettype = '".$this->element."')"; - + $sql.= " WHERE (fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."')"; + $sql.= " OR (fk_target = '".$targetid."' AND targettype = '".$targettype."')"; + dol_syslog("CommonObject::load_object_linked sql=".$sql); $resql = $this->db->query($sql); if ($resql) @@ -887,11 +892,11 @@ class CommonObject while ($i < $num) { $obj = $this->db->fetch_object($resql); - if ($obj->fk_source == $this->id) + if ($obj->fk_source == $sourceid) { $this->linked_object[]=array('linkid'=>$obj->fk_target, 'type'=>$obj->targettype); } - if ($obj->fk_target == $this->id) + if ($obj->fk_target == $targetid) { $this->linked_object[]=array('linkid'=>$obj->fk_source, 'type'=>$obj->sourcetype); } @@ -902,96 +907,6 @@ class CommonObject { dol_print_error($this->db); } - - - // For backward compatibility, read other old link tables co_fa (will be moved later) - if ($this->element == 'facture' || $this->element == 'commande') - { - if ($this->element == 'facture') $sql = "SELECT fk_commande as sourceid"; - if ($this->element == 'commande') $sql = "SELECT fk_facture as sourceid"; - $sql.= ' FROM '.MAIN_DB_PREFIX.'co_fa'; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - dol_syslog("CommonObject::load_object_linked sql=".$sql); - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - if ($this->element == 'facture') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'order'); - if ($this->element == 'commande') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'invoice'); - $i++; - } - } - } - // For backward compatibility, read other old link tables fa_pr (will be moved later) - if ($this->element == 'facture' || $this->element == 'propal') - { - if ($this->element == 'facture') $sql = "SELECT fk_propal as sourceid"; - if ($this->element == 'propal') $sql = "SELECT fk_facture as sourceid"; - $sql.= ' FROM '.MAIN_DB_PREFIX.'fa_pr'; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - dol_syslog("CommonObject::load_object_linked sql=".$sql); - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - if ($this->element == 'facture') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'propal'); - if ($this->element == 'propal') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'invoice'); - $i++; - } - } - } - // For backward compatibility, read other old link tables co_pr (will be moved later) - if ($this->element == 'commande' || $this->element == 'propal') - { - if ($this->element == 'commande') $sql = "SELECT fk_propale as sourceid"; - if ($this->element == 'propal') $sql = "SELECT fk_commande as sourceid"; - $sql.= ' FROM '.MAIN_DB_PREFIX.'co_pr'; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - dol_syslog("CommonObject::load_object_linked sql=".$sql); - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - if ($this->element == 'commande') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'propal'); - if ($this->element == 'propal') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'order'); - $i++; - } - } - } - // For backward compatibility, read other old link tables co_exp (will be moved later) - if ($this->element == 'commande' || $this->element == 'expedition') - { - if ($this->element == 'commande') $sql = "SELECT fk_expedition as sourceid"; - if ($this->element == 'expedition') $sql = "SELECT fk_commande as sourceid"; - $sql.= ' FROM '.MAIN_DB_PREFIX.'co_exp'; - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; - dol_syslog("CommonObject::load_object_linked sql=".$sql); - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - if ($this->element == 'commande') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'sending'); - if ($this->element == 'expedition') $this->linked_object[]=array('linkid'=>$obj->sourceid, 'type'=>'order'); - $i++; - } - } - } } } diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index 6922280b0f0..2c0d71170b2 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -283,7 +283,7 @@ if ($id > 0 || ! empty($ref)) print ''; } - // Conditions et modes de règlement + // Conditions et modes de r�glement print '
'; print '"; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ""; - $total = $total + $objp->total; + $total = $total + $invoice->total; $i++; } print ""; print ""; print "\n"; print "
'; print $langs->trans('PaymentConditionsShort'); @@ -537,7 +537,7 @@ if ($id > 0 || ! empty($ref)) /* - * Documents générés + * Documents generes * */ $comref = dol_sanitizeFileName($commande->ref); @@ -554,8 +554,11 @@ if ($id > 0 || ! empty($ref)) * Liste des factures */ $sql = "SELECT f.rowid,f.facnumber, f.total_ttc, ".$db->pdate("f.datef")." as df"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."co_fa as cf"; - $sql .= " WHERE f.rowid = cf.fk_facture AND cf.fk_commande = ". $commande->id; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."element_element as el"; + $sql.= " WHERE f.rowid = el.fk_target"; + $sql.= " AND el.fk_source = ". $commande->id; + $sql.= " AND el.sourcetype = '".$commande->element."'"; $result = $db->query($sql); if ($result) @@ -605,7 +608,7 @@ if ($id > 0 || ! empty($ref)) } else { - // Commande non trouvée + // Commande non trouvee print "Commande inexistante"; } } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 9f8bb8a4816..2c9a7e0335b 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3371,9 +3371,11 @@ else * Propales rattachees */ $sql = 'SELECT '.$db->pdate('p.datep').' as dp, p.total_ht, p.ref, p.ref_client, p.rowid as propalid'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'propal as p'; - $sql .= ", ".MAIN_DB_PREFIX."fa_pr as fp"; - $sql .= " WHERE fp.fk_propal = p.rowid AND fp.fk_facture = ".$fac->id; + $sql.= ' FROM '.MAIN_DB_PREFIX.'propal as p'; + $sql.= ", ".MAIN_DB_PREFIX."element_element as el"; + $sql.= " WHERE el.fk_source = p.rowid"; + $sql.= " AND el.fk_target = ".$fac->id; + $sql.= " AND el.targettype = '".$fac->element."'"; dol_syslog("facture.php: sql=".$sql); $resql = $db->query($sql); @@ -3427,7 +3429,12 @@ else if($conf->commande->enabled) { $sql = 'SELECT '.$db->pdate('c.date_commande').' as date_commande, c.total_ht, c.ref, c.ref_client, c.rowid as id'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'co_fa as co_fa WHERE co_fa.fk_commande = c.rowid AND co_fa.fk_facture = '.$fac->id; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c'; + $sql.= ', '.MAIN_DB_PREFIX.'element_element as el'; + $sql.= ' WHERE el.fk_source = c.rowid'; + $sql.= " AND el.fk_target = ".$fac->id; + $sql.= " AND el.targettype = '".$fac->element."'"; + $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/compta/facture/facture-rec.class.php b/htdocs/compta/facture/facture-rec.class.php index 990efacd5bb..43ff8484195 100644 --- a/htdocs/compta/facture/facture-rec.class.php +++ b/htdocs/compta/facture/facture-rec.class.php @@ -195,11 +195,11 @@ class FactureRec extends Facture $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement'; $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_facture'; - $sql.= ', cf.fk_commande'; + $sql.= ', el.fk_source'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'cond_reglement as c ON f.fk_cond_reglement = c.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'co_fa as cf ON cf.fk_facture = f.rowid'; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'"; // TODO remplacer par une fonction $sql.= ' WHERE f.rowid='.$rowid; if ($socid > 0) $sql.= ' AND f.fk_soc = '.$socid; diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 22f79d8a282..602ed5d5148 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -662,12 +662,12 @@ if ($conf->facture->enabled && $conf->commande->enabled && $user->rights->comman $sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc,"; $sql.= " s.nom, s.rowid as socid,"; - $sql.= " p.rowid, p.ref, p.facture, p.fk_statut, p.total_ht, p.total_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe AS s"; + $sql.= " c.rowid, c.ref, c.facture, c.fk_statut, c.total_ht, c.total_ttc"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= ", ".MAIN_DB_PREFIX."commande AS p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid"; + $sql.= ", ".MAIN_DB_PREFIX."commande as c"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'"; $sql.= " WHERE p.fk_soc = s.rowid"; $sql.= " AND p.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index 06d5bdc09b1..a4237599667 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -541,62 +541,12 @@ if ($id > 0 || ! empty($ref)) /* * Factures associees */ - // Cas des factures lies directement - $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.fk_statut, f.paye"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql.= ", ".MAIN_DB_PREFIX."fa_pr as fp"; - //$sql.= ", ".MAIN_DB_PREFIX."societe as s"; - $sql.= " WHERE fp.fk_facture = f.rowid"; - $sql.= " AND fp.fk_propal = ".$propal->id; - //$sql.= " AND f.fk_soc = s.rowid"; - //$sql.= " AND s.entity = ".$conf->entity; - //$sql.= " UNION "; - // Cas des factures lier via la commande - $sql2= "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.fk_statut, f.paye"; - $sql2.= " FROM ".MAIN_DB_PREFIX."facture as f"; - //$sql2.= ", ".MAIN_DB_PREFIX."societe as s"; - $sql2.= ", ".MAIN_DB_PREFIX."co_pr as cp"; - $sql2.= ", ".MAIN_DB_PREFIX."co_fa as cf"; - $sql2.= " WHERE cp.fk_propale = ".$propal->id; - $sql2.= " AND cf.fk_commande = cp.fk_commande"; - $sql2.= " AND cf.fk_facture = f.rowid"; - //$sql2.= " AND f.fk_soc = s.rowid"; - //$sql2.= " AND s.entity = ".$conf->entity; + $linkedInvoices = $propal->getInvoiceArrayList(); - dol_syslog("propal.php::liste factures sql=".$sql); - $resql=$db->query($sql); - $resql2=null; - if ($resql) + if (is_array($linkedInvoices)) { - dol_syslog("propal.php::liste factures sql2=".$sql2); - $resql2=$db->query($sql2); - } - if ($resql2) - { - $tab_sqlobj=array(); + $num_fac_asso = sizeOf($linkedInvoices); - $num_fac_asso = $db->num_rows($resql); - for ($i = 0;$i < $num_fac_asso;$i++) - { - $sqlobj = $db->fetch_object($resql); - $tab_sqlobj[] = $sqlobj; - //$tab_sqlobjOrder[]= $sqlobj->dc; - } - $db->free($resql); - - $num_fac_asso = $db->num_rows($resql2); - for ($i = 0;$i < $num_fac_asso;$i++) - { - $sqlobj = $db->fetch_object($resql2); - $tab_sqlobj[] = $sqlobj; - //$tab_sqlobjOrder[]= $sqlobj->dc; - } - $db->free($resql2); - - //array_multisort ($tab_sqlobjOrder,$tab_sqlobj); - - $num_fac_asso = sizeOf($tab_sqlobj); - //$num_fac_asso = $db->num_rows($resql); $i = 0; $total = 0; if ($somethingshown) { print '
'; $somethingshown=1; } if ($num_fac_asso > 1) print_titre($langs->trans("RelatedBills")); @@ -613,25 +563,22 @@ if ($id > 0 || ! empty($ref)) $staticfacture=new Facture($db); $var=True; - while ($i < $num_fac_asso) + foreach($linkedInvoices as $key => $invoice) { - //$objp = $db->fetch_object($resql); - $objp = array_shift($tab_sqlobj); $var=!$var; print "
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber.''.dol_print_date($objp->df,'day').''.price($objp->total).''.$staticfacture->LibStatut($objp->paye,$objp->fk_statut,3).''.img_object($langs->trans("ShowBill"),"bill").' '.$invoice->facnumber.''.dol_print_date($invoice->df,'day').''.price($invoice->total).''.$staticfacture->LibStatut($invoice->paye,$invoice->fk_statut,3).'
".$langs->trans("TotalHT")."".price($total)." 
"; - //$db->free(); } @@ -673,7 +620,7 @@ else $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND p.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($viewstatut <> '') $sql.= " AND p.fk_statut in ($viewstatut)"; // viewstatut peut etre combinaisons separe par virgules diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 3518e9f1bf4..21157ed2b5a 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -255,17 +255,27 @@ class Facture extends CommonObject // Mise a jour lien avec propal ou commande if (! $error && $this->id && $this->propalid) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fa_pr (fk_facture, fk_propal) VALUES ('.$this->id.','.$this->propalid.')'; - dol_syslog("Facture::Create sql=".$sql); - $resql=$this->db->query($sql); - if (! $resql) $error++; + // TODO normaliser ? + $this->origin_id = $this->propalid; + $this->origin = "propal"; + $ret = $this->add_object_linked(); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } } if (! $error && $this->id && $this->commandeid) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_fa (fk_facture, fk_commande) VALUES ('.$this->id.','.$this->commandeid.')'; - dol_syslog("Facture::Create sql=".$sql); - $resql=$this->db->query($sql); - if (! $resql) $error++; + // TODO normaliser ? + $this->origin_id = $this->commandeid; + $this->origin = "commande"; + $ret = $this->add_object_linked(); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } } /* @@ -545,11 +555,11 @@ class Facture extends CommonObject $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet'; $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_facture'; - $sql.= ', cf.fk_commande'; + $sql.= ', el.fk_source'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'cond_reglement as c ON f.fk_cond_reglement = c.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'co_fa as cf ON cf.fk_facture = f.rowid'; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = '".$this->element."'"; $sql.= ' WHERE f.entity = '.$conf->entity; if ($ref) $sql.= " AND f.facnumber='".$ref."'"; else $sql.= " AND f.rowid=".$rowid; @@ -964,69 +974,61 @@ class Facture extends CommonObject $error=0; $this->db->begin(); - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'fa_pr WHERE fk_facture = '.$rowid; + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'element_element'; + $sql.= ' WHERE fk_target = '.$rowid; + $sql.= ' AND targettype = '.$this->element; + if ($this->db->query($sql)) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'co_fa WHERE fk_facture = '.$rowid; + // On met a jour le lien des remises + $list_rowid_det=array(); + $sql = 'SELECT fd.rowid FROM '.MAIN_DB_PREFIX.'facturedet as fd WHERE fk_facture = '.$rowid; + $resql=$this->db->query($sql); + while ($obj = $this->db->fetch_object($resql)) + { + $list_rowid_det[]=$obj->rowid; + } + + // On desaffecte de la facture les remises liees + if (sizeof($list_rowid_det)) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; + $sql.= ' SET fk_facture = NULL'; + $sql.= ' WHERE fk_facture in ('.join(',',$list_rowid_det).')'; + + dol_syslog("Facture.class::delete sql=".$sql); + if (! $this->db->query($sql)) + { + $this->error=$this->db->error()." sql=".$sql; + dol_syslog("Facture.class::delete ".$this->error, LOG_ERR); + $this->db->rollback(); + return -5; + } + } + + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid; if ($this->db->query($sql)) { - // On met a jour le lien des remises - $list_rowid_det=array(); - $sql = 'SELECT fd.rowid FROM '.MAIN_DB_PREFIX.'facturedet as fd WHERE fk_facture = '.$rowid; + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid; $resql=$this->db->query($sql); - while ($obj = $this->db->fetch_object($resql)) + if ($resql) { - $list_rowid_det[]=$obj->rowid; - } + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers - // On d�saffecte de la facture les remises li�es - if (sizeof($list_rowid_det)) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; - $sql.= ' SET fk_facture = NULL'; - $sql.= ' WHERE fk_facture in ('.join(',',$list_rowid_det).')'; - - dol_syslog("Facture.class::delete sql=".$sql); - if (! $this->db->query($sql)) - { - $this->error=$this->db->error()." sql=".$sql; - dol_syslog("Facture.class::delete ".$this->error, LOG_ERR); - $this->db->rollback(); - return -5; - } - } - - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid; - if ($this->db->query($sql)) - { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid; - $resql=$this->db->query($sql); - if ($resql) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error()." sql=".$sql; - dol_syslog("Facture.class::delete ".$this->error, LOG_ERR); - $this->db->rollback(); - return -6; - } + $this->db->commit(); + return 1; } else { $this->error=$this->db->error()." sql=".$sql; dol_syslog("Facture.class::delete ".$this->error, LOG_ERR); $this->db->rollback(); - return -4; + return -6; } } else @@ -1034,7 +1036,7 @@ class Facture extends CommonObject $this->error=$this->db->error()." sql=".$sql; dol_syslog("Facture.class::delete ".$this->error, LOG_ERR); $this->db->rollback(); - return -3; + return -4; } } else diff --git a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php index 940e4f10891..5239470ffba 100644 --- a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php +++ b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php @@ -399,7 +399,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition $outputlangs->load('orders'); foreach($object->linked_object as $key => $val) { - if ($val['type'] == 'order') + if ($val['type'] == 'commande') { $newobject=new Commande($this->db); $result=$newobject->fetch($val['linkid']); diff --git a/htdocs/includes/modules/facture/pdf_crabe.modules.php b/htdocs/includes/modules/facture/pdf_crabe.modules.php index 6fb1e093de7..2108f3ad3b8 100644 --- a/htdocs/includes/modules/facture/pdf_crabe.modules.php +++ b/htdocs/includes/modules/facture/pdf_crabe.modules.php @@ -1034,7 +1034,7 @@ class pdf_crabe extends ModelePDFFactures $outputlangs->load('orders'); foreach($object->linked_object as $key => $val) { - if ($val['type'] == 'order') + if ($val['type'] == 'commande') { $newobject=new Commande($this->db); $result=$newobject->fetch($val['linkid']); diff --git a/htdocs/includes/modules/facture/pdf_oursin.modules.php b/htdocs/includes/modules/facture/pdf_oursin.modules.php index 3c6458406eb..939a8a0156a 100644 --- a/htdocs/includes/modules/facture/pdf_oursin.modules.php +++ b/htdocs/includes/modules/facture/pdf_oursin.modules.php @@ -1037,7 +1037,7 @@ class pdf_oursin extends ModelePDFFactures $outputlangs->load('orders'); foreach($object->linked_object as $key => $val) { - if ($val['type'] == 'order') + if ($val['type'] == 'commande') { $newobject=new Propal($this->db); $result=$newobject->fetch($val['linkid']); diff --git a/htdocs/includes/modules/livraison/pdf/pdf_sirocco.modules.php b/htdocs/includes/modules/livraison/pdf/pdf_sirocco.modules.php index 2263db3575e..65b67ff22ff 100644 --- a/htdocs/includes/modules/livraison/pdf/pdf_sirocco.modules.php +++ b/htdocs/includes/modules/livraison/pdf/pdf_sirocco.modules.php @@ -481,7 +481,7 @@ class pdf_sirocco extends ModelePDFDeliveryOrder $outputlangs->load('orders'); foreach($object->linked_object as $key => $val) { - if ($val['type'] == 'order') + if ($val['type'] == 'commande') { $newobject=new Commande($this->db); $result=$newobject->fetch($val['linkid']); diff --git a/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php b/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php index d7bab13f201..3c3e4025f2b 100644 --- a/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php +++ b/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php @@ -502,7 +502,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder $outputlangs->load('orders'); foreach($object->linked_object as $key => $val) { - if ($val['type'] == 'order') + if ($val['type'] == 'commande') { $newobject=new Commande($this->db); $result=$newobject->fetch($val['linkid']); diff --git a/htdocs/install/check.php b/htdocs/install/check.php index 80e5c19ab26..3323cb7f4db 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -234,7 +234,7 @@ else $allowinstall=0; } - // Si fichier pr�sent et peut etre modifi� + // Si fichier present et peut etre modifie else { if ($confexists) @@ -292,7 +292,7 @@ else $conf->setValues($db); // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE // Version to install is DOL_VERSION - $dolibarrlastupgradeversionarray=preg_split('/[.-]/',isset($conf->global->MAIN_VERSION_LAST_UPGRADE)?$conf->global->MAIN_VERSION_LAST_UPGRADE:$conf->global->MAIN_VERSION_LAST_INSTALL); + $dolibarrlastupgradeversionarray=preg_split('/[\.-]/',isset($conf->global->MAIN_VERSION_LAST_UPGRADE)?$conf->global->MAIN_VERSION_LAST_UPGRADE:$conf->global->MAIN_VERSION_LAST_INSTALL); $dolibarrversiontoinstallarray=versiondolibarrarray(); } @@ -375,8 +375,8 @@ else { if (sizeof($dolibarrlastupgradeversionarray) >= 2) // If a database access is available and a version x.y already available { - $dolibarrversionfromarray=preg_split('/[.-]/',$versionfrom); - $dolibarrversiontoarray=preg_split('/[.-]/',$versionto); + $dolibarrversionfromarray=preg_split('/[\.-]/',$versionfrom); + $dolibarrversiontoarray=preg_split('/[\.-]/',$versionto); // Now we check if this is the first qualified choice if ($allowupgrade && empty($foundrecommandedchoice) && versioncompare($dolibarrversiontoarray,$dolibarrlastupgradeversionarray) > 0) { diff --git a/htdocs/install/mysql/tables/llx_co_fa.key.sql b/htdocs/install/mysql/tables/llx_co_fa.key.sql deleted file mode 100644 index 88b78f8679a..00000000000 --- a/htdocs/install/mysql/tables/llx_co_fa.key.sql +++ /dev/null @@ -1,24 +0,0 @@ --- =================================================================== --- Copyright (C) 2003 Rodolphe Quiedeville --- Copyright (C) 2008 Regis Houssin --- Copyright (C) 2009 Laurent Destailleur --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --- --- $Id$ --- =================================================================== - -ALTER TABLE llx_co_fa ADD INDEX idx_co_fa_fk_commande (fk_commande); -ALTER TABLE llx_co_fa ADD INDEX idx_co_fa_fk_facture (fk_facture); diff --git a/htdocs/install/mysql/tables/llx_co_fa.sql b/htdocs/install/mysql/tables/llx_co_fa.sql deleted file mode 100644 index 8f1c15d6355..00000000000 --- a/htdocs/install/mysql/tables/llx_co_fa.sql +++ /dev/null @@ -1,26 +0,0 @@ --- =================================================================== --- Copyright (C) 2003 Rodolphe Quiedeville --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --- --- $Id$ --- =================================================================== - -create table llx_co_fa -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_commande integer NOT NULL, - fk_facture integer NOT NULL -)type=innodb; diff --git a/htdocs/install/mysql/tables/llx_co_pr.key.sql b/htdocs/install/mysql/tables/llx_co_pr.key.sql deleted file mode 100644 index 9b1b5f16c0f..00000000000 --- a/htdocs/install/mysql/tables/llx_co_pr.key.sql +++ /dev/null @@ -1,24 +0,0 @@ --- =================================================================== --- Copyright (C) 2003 Rodolphe Quiedeville --- Copyright (C) 2008 Regis Houssin --- Copyright (C) 2009 Laurent Destailleur --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --- --- $Id$ --- =================================================================== - -ALTER TABLE llx_co_pr ADD INDEX idx_co_pr_fk_commande (fk_commande); -ALTER TABLE llx_co_pr ADD INDEX idx_co_pr_fk_propale (fk_propale); diff --git a/htdocs/install/mysql/tables/llx_co_pr.sql b/htdocs/install/mysql/tables/llx_co_pr.sql deleted file mode 100644 index 77cddeff3c6..00000000000 --- a/htdocs/install/mysql/tables/llx_co_pr.sql +++ /dev/null @@ -1,26 +0,0 @@ --- =================================================================== --- Copyright (C) 2003 Rodolphe Quiedeville --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --- --- $Id$ --- =================================================================== - -create table llx_co_pr -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_commande integer, - fk_propale integer -)type=innodb; diff --git a/htdocs/install/mysql/tables/llx_fa_pr.sql b/htdocs/install/mysql/tables/llx_fa_pr.sql deleted file mode 100644 index 24de92c9c97..00000000000 --- a/htdocs/install/mysql/tables/llx_fa_pr.sql +++ /dev/null @@ -1,27 +0,0 @@ --- =================================================================== --- Copyright (C) 2001-2002 Rodolphe Quiedeville --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --- --- $Id$ --- =================================================================== - - -create table llx_fa_pr -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_facture integer, - fk_propal integer -)type=innodb; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 09613ab4235..7bd0e7dfc09 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -159,6 +159,9 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) ***************************************************************************************/ if (! $error) { + // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE + // Version to install is DOL_VERSION + $dolibarrlastupgradeversionarray=preg_split('/[\.-]/',isset($conf->global->MAIN_VERSION_LAST_UPGRADE)?$conf->global->MAIN_VERSION_LAST_UPGRADE:$conf->global->MAIN_VERSION_LAST_INSTALL); $db->begin(); @@ -230,22 +233,26 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) migrate_directories($db,$langs,$conf,'/societe','/mycompany'); - - // Script pour V2.7 -> V2.8 - migrate_relationship_tables($db,$langs,$conf,'co_exp','fk_commande','commande','fk_expedition','shipping'); - - migrate_relationship_tables($db,$langs,$conf,'pr_exp','fk_propal','propal','fk_expedition','shipping'); - - migrate_relationship_tables($db,$langs,$conf,'pr_liv','fk_propal','propal','fk_livraison','delivery'); - - migrate_relationship_tables($db,$langs,$conf,'co_liv','fk_commande','commande','fk_livraison','delivery'); - - //migrate_relationship_tables($db,$langs,$conf,'co_pr','fk_propale','propal','fk_commande','commande'); - - //migrate_relationship_tables($db,$langs,$conf,'fa_pr','fk_propal','propal','fk_facture','facture'); - - //migrate_relationship_tables($db,$langs,$conf,'co_fa','fk_commande','commande','fk_facture','facture'); + // Script pour V2.7 -> V2.8 + $toversionarray=array('2.8.0'); + //$dolibarrlastupgradeversionarray=array('2.7.0'); + if (versioncompare($toversionarray,$dolibarrlastupgradeversionarray) > 0) + { + migrate_relationship_tables($db,$langs,$conf,'co_exp','fk_commande','commande','fk_expedition','shipping'); + + migrate_relationship_tables($db,$langs,$conf,'pr_exp','fk_propal','propal','fk_expedition','shipping'); + + migrate_relationship_tables($db,$langs,$conf,'pr_liv','fk_propal','propal','fk_livraison','delivery'); + + migrate_relationship_tables($db,$langs,$conf,'co_liv','fk_commande','commande','fk_livraison','delivery'); + + migrate_relationship_tables($db,$langs,$conf,'co_pr','fk_propale','propal','fk_commande','commande'); + + migrate_relationship_tables($db,$langs,$conf,'fa_pr','fk_propal','propal','fk_facture','facture'); + + migrate_relationship_tables($db,$langs,$conf,'co_fa','fk_commande','commande','fk_facture','facture'); + } // On commit dans tous les cas. // La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation. diff --git a/htdocs/lib/admin.lib.php b/htdocs/lib/admin.lib.php index a434f53f159..4c3384664fc 100644 --- a/htdocs/lib/admin.lib.php +++ b/htdocs/lib/admin.lib.php @@ -55,8 +55,8 @@ function versioncompare($versionarray1,$versionarray2) { $operande1=isset($versionarray1[$level])?$versionarray1[$level]:0; $operande2=isset($versionarray2[$level])?$versionarray2[$level]:0; - if (preg_match('/beta|alpha/i',$operande1)) $operande1=-1; - if (preg_match('/beta|alpha/i',$operande2)) $operande2=-1; + if (preg_match('/beta|alpha|dev/i',$operande1)) $operande1=-1; + if (preg_match('/beta|alpha|dev/i',$operande2)) $operande2=-1; $level++; //print 'level '.$level.' '.$operande1.'-'.$operande2.'
'; if ($operande1 < $operande2) { $ret = -$level; break; } diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 30b3eeb8b64..0cf6b064946 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -1388,16 +1388,20 @@ class Propal extends CommonObject } /** - * \brief Renvoie un tableau contenant les num�ros de commandes associ�es + * \brief Renvoie un tableau contenant les numeros de commandes associees * \remarks Fonction plus light que associated_orders * \sa loadOrders + * \TODO doublon avec loadOrders() ? */ function getOrderArrayList() { $ga = array(); - $sql = "SELECT fk_commande FROM ".MAIN_DB_PREFIX."co_pr"; - $sql .= " WHERE fk_propale = " . $this->id; + $sql = "SELECT fk_target FROM ".MAIN_DB_PREFIX."element_element"; + $sql.= " WHERE fk_source = ".$this->id; + $sql.= " AND sourcetype = '".$this->element."'"; + $sql.= " AND targettype = 'commande'"; + if ($this->db->query($sql) ) { $nump = $this->db->num_rows(); @@ -1409,7 +1413,7 @@ class Propal extends CommonObject { $obj = $this->db->fetch_object(); - $ga[$i] = $obj->fk_commande; + $ga[$i] = $obj->fk_target; $i++; } } @@ -1422,18 +1426,23 @@ class Propal extends CommonObject } /** - * \brief Charge tableau contenant les commandes associ�es + * \brief Charge tableau contenant les commandes associees * \remarks Fonction plus lourde que getOrderArrayList * \return int <0 si ko, >0 si ok * \sa getOrdersArrayList + * \TODO doublon avec getOrderArrayList() ? */ function loadOrders() { $this->commandes = array(); $ga = array(); - $sql = "SELECT fk_commande FROM ".MAIN_DB_PREFIX."co_pr"; - $sql.= " WHERE fk_propale = " . $this->id; + + $sql = "SELECT fk_target FROM ".MAIN_DB_PREFIX."element_element"; + $sql.= " WHERE fk_source = " . $this->id; + $sql.= " AND sourcetype = '".$this->element."'"; + $sql.= " AND targettype = 'commande'"; + $result=$this->db->query($sql); if ($result) { @@ -1447,9 +1456,9 @@ class Propal extends CommonObject $obj = $this->db->fetch_object($result); $order=new Commande($this->db); - if ($obj->fk_commande) + if ($obj->fk_target) { - $order->fetch($obj->fk_commande); + $order->fetch($obj->fk_target); $ga[$i] = $order; } $i++; @@ -1482,29 +1491,35 @@ class Propal extends CommonObject function InvoiceArrayList($id) { $ga = array(); + $linkedInvoices = array(); + + $this->load_object_linked($id,$this->element); + foreach($this->linked_object as $key => $object) + { + // Cas des factures liees directement + if ($object['type'] == 'facture') + { + $linkedInvoices[] = $object['linkid']; + } + // Cas des factures liees via la commande + else + { + $this->load_object_linked($object['linkid'],$object['type']); + foreach($this->linked_object as $key => $object) + { + $linkedInvoices[] = $object['linkid']; + } + } + } + + $sql= "SELECT rowid as facid, facnumber, total,".$this->db->pdate("datef")." as df, fk_user_author, fk_statut, paye"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $sql.= " WHERE rowid IN (".implode(',',$linkedInvoices).")"; - $sql = "SELECT f.rowid, f.facnumber"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql.= ", ".MAIN_DB_PREFIX."fa_pr as fp"; - $sql.= " WHERE fp.fk_facture = f.rowid AND fp.fk_propal = ".$id; - //$sql.= " UNION "; - // Cas des factures liees via la commande - $sql2= "SELECT f.rowid, f.facnumber"; - $sql2.= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql2.= ", ".MAIN_DB_PREFIX."co_pr as cp, ".MAIN_DB_PREFIX."co_fa as cf"; - $sql2.= " WHERE cp.fk_propale = ".$id." AND cf.fk_commande = cp.fk_commande AND cf.fk_facture = f.rowid"; - - //$sql = "SELECT fk_facture FROM ".MAIN_DB_PREFIX."fa_pr as fp"; - //$sql .= " WHERE fk_propal = " . $id; dol_syslog("Propal::InvoiceArrayList sql=".$sql); $resql=$this->db->query($sql); - $resql2=null; + if ($resql) - { - dol_syslog("Propal::InvoiceArrayList sql2=".$sql2); - $resql2=$this->db->query($sql2); - } - if ($resql2) { $tab_sqlobj=array(); $nump = $this->db->num_rows($resql); @@ -1512,21 +1527,9 @@ class Propal extends CommonObject { $sqlobj = $this->db->fetch_object($resql); $tab_sqlobj[] = $sqlobj; - //$tab_sqlobjOrder[]= $sqlobj->dc; } $this->db->free($resql); - $nump = $this->db->num_rows($resql2); - for ($i = 0;$i < $nump;$i++) - { - $sqlobj = $this->db->fetch_object($resql2); - $tab_sqlobj[] = $sqlobj; - //$tab_sqlobjOrder[]= $sqlobj->dc; - } - $this->db->free($resql2); - //array_multisort ($tab_sqlobjOrder,$tab_sqlobj); - - //$nump = $this->db->num_rows($resql); $nump = sizeOf($tab_sqlobj); if ($nump) @@ -1534,10 +1537,10 @@ class Propal extends CommonObject $i = 0; while ($i < $nump) { - //$obj = $this->db->fetch_object($resql); $obj = array_shift($tab_sqlobj); - $ga[$obj->rowid] = $obj->facnumber; + $ga[$i] = $obj; + $i++; } }