Works on migration of relationship tables

This commit is contained in:
Regis Houssin
2009-12-12 20:41:27 +00:00
parent 30ad725fb5
commit 432dc7a009
25 changed files with 209 additions and 635 deletions

View File

@@ -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 */; /*!40000 ALTER TABLE `llx_chargesociales` ENABLE KEYS */;
UNLOCK TABLES; 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`; DROP TABLE IF EXISTS `llx_commande`;
SET @saved_cs_client = @@character_set_client; SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8; SET character_set_client = utf8;
@@ -2730,30 +2676,6 @@ LOCK TABLES `llx_export_model` WRITE;
/*!40000 ALTER TABLE `llx_export_model` ENABLE KEYS */; /*!40000 ALTER TABLE `llx_export_model` ENABLE KEYS */;
UNLOCK TABLES; 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` -- Table structure for table `llx_facture`
-- --

View File

@@ -2286,86 +2286,6 @@
</INDEX> </INDEX>
</INDICES> </INDICES>
</TABLE> </TABLE>
<TABLE ID="1043" Tablename="llx_co_fa" PrevTableName="" XPos="2288" YPos="1890" TableType="1" TablePrefix="0" nmTable="0" Temporary="0" UseStandardInserts="0" StandardInserts="\n" TableOptions="DelayKeyTblUpdates=0\nPackKeys=0\nRowChecksum=0\nRowFormat=0\nUseRaid=0\nRaidType=0\n" Comments="" Collapsed="0" IsLinkedObject="0" IDLinkedModel="-1" Obj_id_Linked="-1" OrderPos="45" >
<COLUMNS>
<COLUMN ID="1481" ColName="fk_commande" PrevColName="" Pos="2" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="0" NotNull="1" AutoInc="0" IsForeignKey="1" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="0" />
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
<COLUMN ID="3457" ColName="fk_facture" PrevColName="" Pos="2" idDatatype="5" DatatypeParams="(11)" Width="-1" Prec="-1" PrimaryKey="0" NotNull="1" AutoInc="0" IsForeignKey="1" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="0" />
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
</COLUMNS>
<RELATIONS_END>
<RELATION_END ID="3432" />
<RELATION_END ID="3435" />
</RELATIONS_END>
<INDICES>
<INDEX ID="1484" IndexName="fk_commande" IndexKind="1" FKRefDef_Obj_id="-1">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="1481" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
<INDEX ID="3468" IndexName="llx_co_fa_FKIndex1" IndexKind="1" FKRefDef_Obj_id="3432">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="1481" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
<INDEX ID="3469" IndexName="llx_co_fa_FKIndex2" IndexKind="1" FKRefDef_Obj_id="3435">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="3457" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
</INDICES>
</TABLE>
<TABLE ID="1044" Tablename="llx_co_pr" PrevTableName="" XPos="2552" YPos="1098" TableType="0" TablePrefix="0" nmTable="0" Temporary="0" UseStandardInserts="0" StandardInserts="" TableOptions="" Comments="" Collapsed="1" IsLinkedObject="0" IDLinkedModel="-1" Obj_id_Linked="-1" OrderPos="46" >
<COLUMNS>
<COLUMN ID="1486" ColName="rowid" PrevColName="" Pos="1" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="1" NotNull="1" AutoInc="0" IsForeignKey="0" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="0" />
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
<COLUMN ID="3431" ColName="fk_commande" PrevColName="" Pos="1" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="0" NotNull="1" AutoInc="0" IsForeignKey="1" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="0" />
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
<COLUMN ID="1488" ColName="fk_propale" PrevColName="" Pos="3" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="0" NotNull="1" AutoInc="0" IsForeignKey="1" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="0" />
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
</COLUMNS>
<RELATIONS_END>
<RELATION_END ID="3427" />
<RELATION_END ID="3429" />
</RELATIONS_END>
<INDICES>
<INDEX ID="1489" IndexName="PRIMARY" IndexKind="0" FKRefDef_Obj_id="-1">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="1486" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
<INDEX ID="3470" IndexName="llx_co_pr_FKIndex1" IndexKind="1" FKRefDef_Obj_id="3427">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="1488" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
<INDEX ID="3471" IndexName="llx_co_pr_FKIndex2" IndexKind="1" FKRefDef_Obj_id="3429">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="3431" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
</INDICES>
</TABLE>
<TABLE ID="1045" Tablename="llx_commande" PrevTableName="" XPos="2912" YPos="1080" TableType="0" TablePrefix="0" nmTable="0" Temporary="0" UseStandardInserts="0" StandardInserts="\n" TableOptions="DelayKeyTblUpdates=0\nPackKeys=0\nRowChecksum=0\nRowFormat=0\nUseRaid=0\nRaidType=0\n" Comments="" Collapsed="0" IsLinkedObject="0" IDLinkedModel="-1" Obj_id_Linked="-1" OrderPos="47" > <TABLE ID="1045" Tablename="llx_commande" PrevTableName="" XPos="2912" YPos="1080" TableType="0" TablePrefix="0" nmTable="0" Temporary="0" UseStandardInserts="0" StandardInserts="\n" TableOptions="DelayKeyTblUpdates=0\nPackKeys=0\nRowChecksum=0\nRowFormat=0\nUseRaid=0\nRaidType=0\n" Comments="" Collapsed="0" IsLinkedObject="0" IDLinkedModel="-1" Obj_id_Linked="-1" OrderPos="47" >
<COLUMNS> <COLUMNS>
<COLUMN ID="1490" ColName="rowidc" PrevColName="rowid" Pos="1" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="1" NotNull="1" AutoInc="0" IsForeignKey="0" DefaultValue="" Comments=""> <COLUMN ID="1490" ColName="rowidc" PrevColName="rowid" Pos="1" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="1" NotNull="1" AutoInc="0" IsForeignKey="0" DefaultValue="" Comments="">
@@ -4449,43 +4369,6 @@
</INDEX> </INDEX>
</INDICES> </INDICES>
</TABLE> </TABLE>
<TABLE ID="1078" Tablename="llx_fa_pr" PrevTableName="" XPos="1960" YPos="1516" TableType="0" TablePrefix="0" nmTable="0" Temporary="0" UseStandardInserts="0" StandardInserts="" TableOptions="" Comments="" Collapsed="0" IsLinkedObject="0" IDLinkedModel="-1" Obj_id_Linked="-1" OrderPos="80" >
<COLUMNS>
<COLUMN ID="1845" ColName="rowid" PrevColName="" Pos="1" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="1" NotNull="1" AutoInc="0" IsForeignKey="1" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="0" />
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
<COLUMN ID="1847" ColName="fk_propal" PrevColName="" Pos="3" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="0" NotNull="1" AutoInc="0" IsForeignKey="1" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="0" />
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
</COLUMNS>
<RELATIONS_END>
<RELATION_END ID="3437" />
<RELATION_END ID="3439" />
</RELATIONS_END>
<INDICES>
<INDEX ID="1848" IndexName="PRIMARY" IndexKind="0" FKRefDef_Obj_id="-1">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="1845" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
<INDEX ID="3480" IndexName="llx_fa_pr_FKIndex1" IndexKind="1" FKRefDef_Obj_id="3437">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="1845" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
<INDEX ID="3481" IndexName="llx_fa_pr_FKIndex2" IndexKind="1" FKRefDef_Obj_id="3439">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="1847" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
</INDICES>
</TABLE>
<TABLE ID="1079" Tablename="llx_facture" PrevTableName="" XPos="1954" YPos="1864" TableType="0" TablePrefix="0" nmTable="0" Temporary="0" UseStandardInserts="0" StandardInserts="\n" TableOptions="DelayKeyTblUpdates=0\nPackKeys=0\nRowChecksum=0\nRowFormat=0\nUseRaid=0\nRaidType=0\n" Comments="" Collapsed="0" IsLinkedObject="0" IDLinkedModel="-1" Obj_id_Linked="-1" OrderPos="81" > <TABLE ID="1079" Tablename="llx_facture" PrevTableName="" XPos="1954" YPos="1864" TableType="0" TablePrefix="0" nmTable="0" Temporary="0" UseStandardInserts="0" StandardInserts="\n" TableOptions="DelayKeyTblUpdates=0\nPackKeys=0\nRowChecksum=0\nRowFormat=0\nUseRaid=0\nRaidType=0\n" Comments="" Collapsed="0" IsLinkedObject="0" IDLinkedModel="-1" Obj_id_Linked="-1" OrderPos="81" >
<COLUMNS> <COLUMNS>
<COLUMN ID="1849" ColName="rowid" PrevColName="" Pos="1" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="1" NotNull="1" AutoInc="0" IsForeignKey="0" DefaultValue="" Comments=""> <COLUMN ID="1849" ColName="rowid" PrevColName="" Pos="1" idDatatype="5" DatatypeParams="(11)" Width="0" Prec="0" PrimaryKey="1" NotNull="1" AutoInc="0" IsForeignKey="0" DefaultValue="" Comments="">

View File

@@ -604,8 +604,15 @@ class Commande extends CommonObject
{ {
if ($this->id && $this->propale_id) if ($this->id && $this->propale_id)
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_pr (fk_commande, fk_propale) VALUES ('.$this->id.','.$this->propale_id.')'; // Add proposal link
$this->db->query($sql); // 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 // On recupere les differents contact interne et externe
$prop = New Propal($this->db, $this->socid, $this->propale_id); $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.= ', 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.= ', 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.= ', 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.= ' 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.'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.'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; $sql.= " WHERE c.entity = ".$conf->entity;
if ($ref) $sql.= " AND c.ref='".$ref."'"; if ($ref) $sql.= " AND c.ref='".$ref."'";
else $sql.= " AND c.rowid=".$id; else $sql.= " AND c.rowid=".$id;
@@ -978,7 +985,7 @@ class Commande extends CommonObject
$this->date_livraison = $obj->date_livraison; $this->date_livraison = $obj->date_livraison;
$this->adresse_livraison_id = $obj->fk_adresse_livraison; // TODO obsolete $this->adresse_livraison_id = $obj->fk_adresse_livraison; // TODO obsolete
$this->fk_delivery_address = $obj->fk_adresse_livraison; $this->fk_delivery_address = $obj->fk_adresse_livraison;
$this->propale_id = $obj->fk_propale; $this->propale_id = $obj->fk_source;
$this->lignes = array(); $this->lignes = array();
if ($this->statut == 0) $this->brouillon = 1; if ($this->statut == 0) $this->brouillon = 1;
@@ -1878,7 +1885,9 @@ class Commande extends CommonObject
$err++; $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) ) if (! $this->db->query($sql) )
{ {
$err++; $err++;

View File

@@ -2081,9 +2081,12 @@ else
/* /*
* Liste des factures * Liste des factures
*/ */
$sql = 'SELECT f.rowid,f.facnumber, f.total_ttc, '.$db->pdate('f.datef').' as df'; $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.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= ' WHERE f.rowid = cf.fk_facture AND cf.fk_commande = '. $commande->id; $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); $result = $db->query($sql);
if ($result) if ($result)

View File

@@ -868,15 +868,20 @@ class CommonObject
/** /**
* Load array of objects linked to current object. Links are loaded into this->linked_object array. * 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(); $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 // Links beetween objects are stored in this table
$sql = 'SELECT fk_source, sourcetype, fk_target, targettype'; $sql = 'SELECT fk_source, sourcetype, fk_target, targettype';
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element';
$sql.= " WHERE (fk_source = '".$this->id."' AND sourcetype = '".$this->origin."')"; $sql.= " WHERE (fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."')";
$sql.= " OR (fk_target = '".$this->id."' AND targettype = '".$this->element."')"; $sql.= " OR (fk_target = '".$targetid."' AND targettype = '".$targettype."')";
dol_syslog("CommonObject::load_object_linked sql=".$sql); dol_syslog("CommonObject::load_object_linked sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@@ -887,11 +892,11 @@ class CommonObject
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $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); $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); $this->linked_object[]=array('linkid'=>$obj->fk_source, 'type'=>$obj->sourcetype);
} }
@@ -902,96 +907,6 @@ class CommonObject
{ {
dol_print_error($this->db); 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++;
}
}
}
} }
} }

View File

@@ -283,7 +283,7 @@ if ($id > 0 || ! empty($ref))
print '</td></tr>'; print '</td></tr>';
} }
// Conditions et modes de r<>glement // Conditions et modes de r<>glement
print '<tr><td height="10">'; print '<tr><td height="10">';
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('PaymentConditionsShort'); print $langs->trans('PaymentConditionsShort');
@@ -537,7 +537,7 @@ if ($id > 0 || ! empty($ref))
/* /*
* Documents g<EFBFBD>n<EFBFBD>r<EFBFBD>s * Documents generes
* *
*/ */
$comref = dol_sanitizeFileName($commande->ref); $comref = dol_sanitizeFileName($commande->ref);
@@ -554,8 +554,11 @@ if ($id > 0 || ! empty($ref))
* Liste des factures * Liste des factures
*/ */
$sql = "SELECT f.rowid,f.facnumber, f.total_ttc, ".$db->pdate("f.datef")." as df"; $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.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE f.rowid = cf.fk_facture AND cf.fk_commande = ". $commande->id; $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); $result = $db->query($sql);
if ($result) if ($result)
@@ -605,7 +608,7 @@ if ($id > 0 || ! empty($ref))
} }
else else
{ {
// Commande non trouv<EFBFBD>e // Commande non trouvee
print "Commande inexistante"; print "Commande inexistante";
} }
} }

View File

@@ -3371,9 +3371,11 @@ else
* Propales rattachees * Propales rattachees
*/ */
$sql = 'SELECT '.$db->pdate('p.datep').' as dp, p.total_ht, p.ref, p.ref_client, p.rowid as propalid'; $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.= ' FROM '.MAIN_DB_PREFIX.'propal as p';
$sql .= ", ".MAIN_DB_PREFIX."fa_pr as fp"; $sql.= ", ".MAIN_DB_PREFIX."element_element as el";
$sql .= " WHERE fp.fk_propal = p.rowid AND fp.fk_facture = ".$fac->id; $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); dol_syslog("facture.php: sql=".$sql);
$resql = $db->query($sql); $resql = $db->query($sql);
@@ -3427,7 +3429,12 @@ else
if($conf->commande->enabled) 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 = '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); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {

View File

@@ -195,11 +195,11 @@ class FactureRec extends Facture
$sql.= ', f.fk_mode_reglement, f.fk_cond_reglement'; $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement';
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $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.= ', 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.= ' 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.'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.'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; $sql.= ' WHERE f.rowid='.$rowid;
if ($socid > 0) $sql.= ' AND f.fk_soc = '.$socid; if ($socid > 0) $sql.= ' AND f.fk_soc = '.$socid;

View File

@@ -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 = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc,";
$sql.= " s.nom, s.rowid as socid,"; $sql.= " s.nom, s.rowid as socid,";
$sql.= " p.rowid, p.ref, p.facture, p.fk_statut, p.total_ht, p.total_ttc"; $sql.= " c.rowid, c.ref, c.facture, c.fk_statut, c.total_ht, c.total_ttc";
$sql.= " FROM ".MAIN_DB_PREFIX."societe AS s"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ", ".MAIN_DB_PREFIX."commande AS p"; $sql.= ", ".MAIN_DB_PREFIX."commande as c";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid"; $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 co_fa.fk_facture = f.rowid"; $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.= " WHERE p.fk_soc = s.rowid";
$sql.= " AND p.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 (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;

View File

@@ -541,62 +541,12 @@ if ($id > 0 || ! empty($ref))
/* /*
* Factures associees * Factures associees
*/ */
// Cas des factures lies directement $linkedInvoices = $propal->getInvoiceArrayList();
$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;
dol_syslog("propal.php::liste factures sql=".$sql); if (is_array($linkedInvoices))
$resql=$db->query($sql);
$resql2=null;
if ($resql)
{ {
dol_syslog("propal.php::liste factures sql2=".$sql2); $num_fac_asso = sizeOf($linkedInvoices);
$resql2=$db->query($sql2);
}
if ($resql2)
{
$tab_sqlobj=array();
$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; $i = 0; $total = 0;
if ($somethingshown) { print '<br>'; $somethingshown=1; } if ($somethingshown) { print '<br>'; $somethingshown=1; }
if ($num_fac_asso > 1) print_titre($langs->trans("RelatedBills")); if ($num_fac_asso > 1) print_titre($langs->trans("RelatedBills"));
@@ -613,25 +563,22 @@ if ($id > 0 || ! empty($ref))
$staticfacture=new Facture($db); $staticfacture=new Facture($db);
$var=True; $var=True;
while ($i < $num_fac_asso) foreach($linkedInvoices as $key => $invoice)
{ {
//$objp = $db->fetch_object($resql);
$objp = array_shift($tab_sqlobj);
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td><a href="../compta/facture.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber.'</a></td>'; print '<td><a href="../compta/facture.php?facid='.$invoice->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$invoice->facnumber.'</a></td>';
print '<td align="center">'.dol_print_date($objp->df,'day').'</td>'; print '<td align="center">'.dol_print_date($invoice->df,'day').'</td>';
print '<td align="right">'.price($objp->total).'</td>'; print '<td align="right">'.price($invoice->total).'</td>';
print '<td align="right">'.$staticfacture->LibStatut($objp->paye,$objp->fk_statut,3).'</td>'; print '<td align="right">'.$staticfacture->LibStatut($invoice->paye,$invoice->fk_statut,3).'</td>';
print "</tr>"; print "</tr>";
$total = $total + $objp->total; $total = $total + $invoice->total;
$i++; $i++;
} }
print "<tr class=\"liste_total\"><td align=\"right\" colspan=\"2\">".$langs->trans("TotalHT")."</td>"; print "<tr class=\"liste_total\"><td align=\"right\" colspan=\"2\">".$langs->trans("TotalHT")."</td>";
print "<td align=\"right\">".price($total)."</td>"; print "<td align=\"right\">".price($total)."</td>";
print "<td>&nbsp;</td></tr>\n"; print "<td>&nbsp;</td></tr>\n";
print "</table>"; print "</table>";
//$db->free();
} }
@@ -673,7 +620,7 @@ else
$sql.= ", ".MAIN_DB_PREFIX."propal as p"; $sql.= ", ".MAIN_DB_PREFIX."propal as p";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE p.fk_soc = s.rowid"; $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 (!$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 ($socid) $sql.= " AND s.rowid = ".$socid;
if ($viewstatut <> '') $sql.= " AND p.fk_statut in ($viewstatut)"; // viewstatut peut etre combinaisons separe par virgules if ($viewstatut <> '') $sql.= " AND p.fk_statut in ($viewstatut)"; // viewstatut peut etre combinaisons separe par virgules

View File

@@ -255,17 +255,27 @@ class Facture extends CommonObject
// Mise a jour lien avec propal ou commande // Mise a jour lien avec propal ou commande
if (! $error && $this->id && $this->propalid) if (! $error && $this->id && $this->propalid)
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fa_pr (fk_facture, fk_propal) VALUES ('.$this->id.','.$this->propalid.')'; // TODO normaliser ?
dol_syslog("Facture::Create sql=".$sql); $this->origin_id = $this->propalid;
$resql=$this->db->query($sql); $this->origin = "propal";
if (! $resql) $error++; $ret = $this->add_object_linked();
if (! $ret)
{
dol_print_error($this->db);
$error++;
}
} }
if (! $error && $this->id && $this->commandeid) if (! $error && $this->id && $this->commandeid)
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_fa (fk_facture, fk_commande) VALUES ('.$this->id.','.$this->commandeid.')'; // TODO normaliser ?
dol_syslog("Facture::Create sql=".$sql); $this->origin_id = $this->commandeid;
$resql=$this->db->query($sql); $this->origin = "commande";
if (! $resql) $error++; $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.= ', 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.= ', 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.= ', 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.= ' 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.'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.'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; $sql.= ' WHERE f.entity = '.$conf->entity;
if ($ref) $sql.= " AND f.facnumber='".$ref."'"; if ($ref) $sql.= " AND f.facnumber='".$ref."'";
else $sql.= " AND f.rowid=".$rowid; else $sql.= " AND f.rowid=".$rowid;
@@ -964,10 +974,10 @@ class Facture extends CommonObject
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'fa_pr WHERE fk_facture = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'element_element';
if ($this->db->query($sql)) $sql.= ' WHERE fk_target = '.$rowid;
{ $sql.= ' AND targettype = '.$this->element;
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'co_fa WHERE fk_facture = '.$rowid;
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
// On met a jour le lien des remises // On met a jour le lien des remises
@@ -979,7 +989,7 @@ class Facture extends CommonObject
$list_rowid_det[]=$obj->rowid; $list_rowid_det[]=$obj->rowid;
} }
// On d<EFBFBD>saffecte de la facture les remises li<EFBFBD>es // On desaffecte de la facture les remises liees
if (sizeof($list_rowid_det)) if (sizeof($list_rowid_det))
{ {
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
@@ -1030,14 +1040,6 @@ class Facture extends CommonObject
} }
} }
else else
{
$this->error=$this->db->error()." sql=".$sql;
dol_syslog("Facture.class::delete ".$this->error, LOG_ERR);
$this->db->rollback();
return -3;
}
}
else
{ {
$this->error=$this->db->error()." sql=".$sql; $this->error=$this->db->error()." sql=".$sql;
dol_syslog("Facture.class::delete ".$this->error, LOG_ERR); dol_syslog("Facture.class::delete ".$this->error, LOG_ERR);

View File

@@ -399,7 +399,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'order') if ($val['type'] == 'commande')
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val['linkid']);

View File

@@ -1034,7 +1034,7 @@ class pdf_crabe extends ModelePDFFactures
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'order') if ($val['type'] == 'commande')
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val['linkid']);

View File

@@ -1037,7 +1037,7 @@ class pdf_oursin extends ModelePDFFactures
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'order') if ($val['type'] == 'commande')
{ {
$newobject=new Propal($this->db); $newobject=new Propal($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val['linkid']);

View File

@@ -481,7 +481,7 @@ class pdf_sirocco extends ModelePDFDeliveryOrder
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'order') if ($val['type'] == 'commande')
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val['linkid']);

View File

@@ -502,7 +502,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
$outputlangs->load('orders'); $outputlangs->load('orders');
foreach($object->linked_object as $key => $val) foreach($object->linked_object as $key => $val)
{ {
if ($val['type'] == 'order') if ($val['type'] == 'commande')
{ {
$newobject=new Commande($this->db); $newobject=new Commande($this->db);
$result=$newobject->fetch($val['linkid']); $result=$newobject->fetch($val['linkid']);

View File

@@ -234,7 +234,7 @@ else
$allowinstall=0; $allowinstall=0;
} }
// Si fichier pr<EFBFBD>sent et peut etre modifi<EFBFBD> // Si fichier present et peut etre modifie
else else
{ {
if ($confexists) if ($confexists)
@@ -292,7 +292,7 @@ else
$conf->setValues($db); $conf->setValues($db);
// Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
// Version to install is DOL_VERSION // 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(); $dolibarrversiontoinstallarray=versiondolibarrarray();
} }
@@ -375,8 +375,8 @@ else
{ {
if (sizeof($dolibarrlastupgradeversionarray) >= 2) // If a database access is available and a version x.y already available if (sizeof($dolibarrlastupgradeversionarray) >= 2) // If a database access is available and a version x.y already available
{ {
$dolibarrversionfromarray=preg_split('/[.-]/',$versionfrom); $dolibarrversionfromarray=preg_split('/[\.-]/',$versionfrom);
$dolibarrversiontoarray=preg_split('/[.-]/',$versionto); $dolibarrversiontoarray=preg_split('/[\.-]/',$versionto);
// Now we check if this is the first qualified choice // Now we check if this is the first qualified choice
if ($allowupgrade && empty($foundrecommandedchoice) && versioncompare($dolibarrversiontoarray,$dolibarrlastupgradeversionarray) > 0) if ($allowupgrade && empty($foundrecommandedchoice) && versioncompare($dolibarrversiontoarray,$dolibarrlastupgradeversionarray) > 0)
{ {

View File

@@ -1,24 +0,0 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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);

View File

@@ -1,26 +0,0 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
--
-- 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;

View File

@@ -1,24 +0,0 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2008 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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);

View File

@@ -1,26 +0,0 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
--
-- 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;

View File

@@ -1,27 +0,0 @@
-- ===================================================================
-- Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
--
-- 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;

View File

@@ -159,6 +159,9 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"]))
***************************************************************************************/ ***************************************************************************************/
if (! $error) 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(); $db->begin();
@@ -232,6 +235,10 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"]))
// Script pour V2.7 -> V2.8 // 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,'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_exp','fk_propal','propal','fk_expedition','shipping');
@@ -240,12 +247,12 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"]))
migrate_relationship_tables($db,$langs,$conf,'co_liv','fk_commande','commande','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,'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,'fa_pr','fk_propal','propal','fk_facture','facture');
//migrate_relationship_tables($db,$langs,$conf,'co_fa','fk_commande','commande','fk_facture','facture');
migrate_relationship_tables($db,$langs,$conf,'co_fa','fk_commande','commande','fk_facture','facture');
}
// On commit dans tous les cas. // On commit dans tous les cas.
// La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation. // La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation.

View File

@@ -55,8 +55,8 @@ function versioncompare($versionarray1,$versionarray2)
{ {
$operande1=isset($versionarray1[$level])?$versionarray1[$level]:0; $operande1=isset($versionarray1[$level])?$versionarray1[$level]:0;
$operande2=isset($versionarray2[$level])?$versionarray2[$level]:0; $operande2=isset($versionarray2[$level])?$versionarray2[$level]:0;
if (preg_match('/beta|alpha/i',$operande1)) $operande1=-1; if (preg_match('/beta|alpha|dev/i',$operande1)) $operande1=-1;
if (preg_match('/beta|alpha/i',$operande2)) $operande2=-1; if (preg_match('/beta|alpha|dev/i',$operande2)) $operande2=-1;
$level++; $level++;
//print 'level '.$level.' '.$operande1.'-'.$operande2.'<br>'; //print 'level '.$level.' '.$operande1.'-'.$operande2.'<br>';
if ($operande1 < $operande2) { $ret = -$level; break; } if ($operande1 < $operande2) { $ret = -$level; break; }

View File

@@ -1388,16 +1388,20 @@ class Propal extends CommonObject
} }
/** /**
* \brief Renvoie un tableau contenant les num<EFBFBD>ros de commandes associ<EFBFBD>es * \brief Renvoie un tableau contenant les numeros de commandes associees
* \remarks Fonction plus light que associated_orders * \remarks Fonction plus light que associated_orders
* \sa loadOrders * \sa loadOrders
* \TODO doublon avec loadOrders() ?
*/ */
function getOrderArrayList() function getOrderArrayList()
{ {
$ga = array(); $ga = array();
$sql = "SELECT fk_commande FROM ".MAIN_DB_PREFIX."co_pr"; $sql = "SELECT fk_target FROM ".MAIN_DB_PREFIX."element_element";
$sql .= " WHERE fk_propale = " . $this->id; $sql.= " WHERE fk_source = ".$this->id;
$sql.= " AND sourcetype = '".$this->element."'";
$sql.= " AND targettype = 'commande'";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$nump = $this->db->num_rows(); $nump = $this->db->num_rows();
@@ -1409,7 +1413,7 @@ class Propal extends CommonObject
{ {
$obj = $this->db->fetch_object(); $obj = $this->db->fetch_object();
$ga[$i] = $obj->fk_commande; $ga[$i] = $obj->fk_target;
$i++; $i++;
} }
} }
@@ -1422,18 +1426,23 @@ class Propal extends CommonObject
} }
/** /**
* \brief Charge tableau contenant les commandes associ<EFBFBD>es * \brief Charge tableau contenant les commandes associees
* \remarks Fonction plus lourde que getOrderArrayList * \remarks Fonction plus lourde que getOrderArrayList
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
* \sa getOrdersArrayList * \sa getOrdersArrayList
* \TODO doublon avec getOrderArrayList() ?
*/ */
function loadOrders() function loadOrders()
{ {
$this->commandes = array(); $this->commandes = array();
$ga = 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); $result=$this->db->query($sql);
if ($result) if ($result)
{ {
@@ -1447,9 +1456,9 @@ class Propal extends CommonObject
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$order=new Commande($this->db); $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; $ga[$i] = $order;
} }
$i++; $i++;
@@ -1482,29 +1491,35 @@ class Propal extends CommonObject
function InvoiceArrayList($id) function InvoiceArrayList($id)
{ {
$ga = array(); $ga = array();
$linkedInvoices = array();
$sql = "SELECT f.rowid, f.facnumber"; $this->load_object_linked($id,$this->element);
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; foreach($this->linked_object as $key => $object)
$sql.= ", ".MAIN_DB_PREFIX."fa_pr as fp"; {
$sql.= " WHERE fp.fk_facture = f.rowid AND fp.fk_propal = ".$id; // Cas des factures liees directement
//$sql.= " UNION "; if ($object['type'] == 'facture')
{
$linkedInvoices[] = $object['linkid'];
}
// Cas des factures liees via la commande // Cas des factures liees via la commande
$sql2= "SELECT f.rowid, f.facnumber"; else
$sql2.= " FROM ".MAIN_DB_PREFIX."facture as f"; {
$sql2.= ", ".MAIN_DB_PREFIX."co_pr as cp, ".MAIN_DB_PREFIX."co_fa as cf"; $this->load_object_linked($object['linkid'],$object['type']);
$sql2.= " WHERE cp.fk_propale = ".$id." AND cf.fk_commande = cp.fk_commande AND cf.fk_facture = f.rowid"; 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 fk_facture FROM ".MAIN_DB_PREFIX."fa_pr as fp";
//$sql .= " WHERE fk_propal = " . $id;
dol_syslog("Propal::InvoiceArrayList sql=".$sql); dol_syslog("Propal::InvoiceArrayList sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
$resql2=null;
if ($resql) if ($resql)
{
dol_syslog("Propal::InvoiceArrayList sql2=".$sql2);
$resql2=$this->db->query($sql2);
}
if ($resql2)
{ {
$tab_sqlobj=array(); $tab_sqlobj=array();
$nump = $this->db->num_rows($resql); $nump = $this->db->num_rows($resql);
@@ -1512,21 +1527,9 @@ class Propal extends CommonObject
{ {
$sqlobj = $this->db->fetch_object($resql); $sqlobj = $this->db->fetch_object($resql);
$tab_sqlobj[] = $sqlobj; $tab_sqlobj[] = $sqlobj;
//$tab_sqlobjOrder[]= $sqlobj->dc;
} }
$this->db->free($resql); $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); $nump = sizeOf($tab_sqlobj);
if ($nump) if ($nump)
@@ -1534,10 +1537,10 @@ class Propal extends CommonObject
$i = 0; $i = 0;
while ($i < $nump) while ($i < $nump)
{ {
//$obj = $this->db->fetch_object($resql);
$obj = array_shift($tab_sqlobj); $obj = array_shift($tab_sqlobj);
$ga[$obj->rowid] = $obj->facnumber; $ga[$i] = $obj;
$i++; $i++;
} }
} }