Fix: regression corrected

This commit is contained in:
Regis Houssin 2012-07-08 12:18:29 +02:00
parent 05b7dfd97b
commit 69ebda8ddb
4 changed files with 128 additions and 76 deletions

View File

@ -1560,12 +1560,13 @@ class Propal extends CommonObject
* *
* @return int <0 si ko, >0 si ok * @return int <0 si ko, >0 si ok
*/ */
function classer_facturee() function classifyBilled()
{ {
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = 4'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = 4';
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;';
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$this->statut=4;
return 1; return 1;
} }
else else
@ -1574,6 +1575,16 @@ class Propal extends CommonObject
} }
} }
/**
* Class invoiced the Propal
*
* @return int <0 si ko, >0 si ok
*/
function classer_facturee()
{
return $this->classifyBilled();
}
/** /**
* Set draft status * Set draft status
* *

View File

@ -439,6 +439,10 @@ class Commande extends CommonObject
if (! $error) if (! $error)
{ {
$this->statut = 1;
$this->billed = 0;
$this->facturee = 0; // deprecated
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
@ -484,6 +488,8 @@ class Commande extends CommonObject
if (! $error) if (! $error)
{ {
$this->statut=3;
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
@ -1226,7 +1232,7 @@ class Commande extends CommonObject
$sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_demand_reason'; $sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_demand_reason';
$sql.= ', c.date_commande'; $sql.= ', c.date_commande';
$sql.= ', c.date_livraison'; $sql.= ', c.date_livraison';
$sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as facturee'; $sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as billed';
$sql.= ', c.note as note_private, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_adresse_livraison, c.extraparams'; $sql.= ', c.note as note_private, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_adresse_livraison, c.extraparams';
$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_doc'; $sql.= ', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_doc';
@ -1269,7 +1275,8 @@ class Commande extends CommonObject
$this->remise_percent = $obj->remise_percent; $this->remise_percent = $obj->remise_percent;
$this->remise_absolue = $obj->remise_absolue; $this->remise_absolue = $obj->remise_absolue;
$this->source = $obj->source; $this->source = $obj->source;
$this->facturee = $obj->facturee; $this->facturee = $obj->billed; // deprecated
$this->billed = $obj->billed;
$this->note = $obj->note_private; // deprecated $this->note = $obj->note_private; // deprecated
$this->note_private = $obj->note_private; $this->note_private = $obj->note_private;
$this->note_public = $obj->note_public; $this->note_public = $obj->note_public;
@ -2029,7 +2036,7 @@ class Commande extends CommonObject
{ {
if ($user->rights->commande->creer) if ($user->rights->commande->creer)
{ {
dol_syslog('Commande::set_ref_client this->id='.$this->id.', ref_client='.$ref_client); dol_syslog(get_class($this).'::set_ref_client this->id='.$this->id.', ref_client='.$ref_client);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET';
$sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); $sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\'');
@ -2043,7 +2050,7 @@ class Commande extends CommonObject
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_syslog('Commande::set_ref_client Erreur '.$this->error.' - '.$sql, LOG_ERR); dol_syslog(get_class($this).'::set_ref_client Erreur '.$this->error.' - '.$sql, LOG_ERR);
return -2; return -2;
} }
} }
@ -2053,6 +2060,42 @@ class Commande extends CommonObject
} }
} }
/**
* Classify the order as invoiced
*
* @return int <0 if ko, >0 if ok
*/
function classifyBilled()
{
global $conf;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1';
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;';
if ($this->db->query($sql))
{
if (! empty($conf->global->PROPALE_CLASSIFIED_INVOICED_WITH_ORDER))
{
$this->fetchObjectLinked('','propal',$this->id,$this->element);
if (! empty($this->linkedObjects))
{
foreach($this->linkedObjects['propal'] as $element)
{
$element->classifyBilled();
}
}
}
$this->facturee=1; // deprecated
$this->billed=1;
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/** /**
* Classify the order as invoiced * Classify the order as invoiced
@ -2061,25 +2104,7 @@ class Commande extends CommonObject
*/ */
function classer_facturee() function classer_facturee()
{ {
global $conf; return $this->classifyBilled();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1';
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;';
if ($this->db->query($sql) )
{
if (($conf->global->PROPALE_CLASSIFIED_INVOICED_WITH_ORDER == 1) && $this->propale_id)
{
$propal = new Propal($this->db);
$propal->fetch($this->propale_id);
$propal->classer_facturee();
}
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
} }

View File

@ -381,7 +381,7 @@ else if ($action == 'add' && $user->rights->commande->creer)
else if ($action == 'classifybilled' && $user->rights->commande->creer) else if ($action == 'classifybilled' && $user->rights->commande->creer)
{ {
$object->classer_facturee(); $ret=$object->classifyBilled();
} }
// Positionne ref commande client // Positionne ref commande client
@ -2116,7 +2116,7 @@ else
} }
// Create bill and Classify billed // Create bill and Classify billed
if ($conf->facture->enabled && $object->statut > 0 && ! $object->facturee) if ($conf->facture->enabled && $object->statut > 0 && ! $object->billed)
{ {
if ($user->rights->facture->creer) if ($user->rights->facture->creer)
{ {

View File

@ -1641,8 +1641,16 @@ abstract class CommonObject
$justsource=false; $justsource=false;
$justtarget=false; $justtarget=false;
if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $justsource=true; if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid))
if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $justtarget=true; {
$justsource=true;
if (! empty($targettype)) $withtargettype=true;
}
if (! empty($targetid) && ! empty($targettype) && empty($sourceid))
{
$justtarget=true;
if (! empty($sourcetype)) $withsourcetype;
}
$sourceid = (! empty($sourceid) ? $sourceid : $this->id); $sourceid = (! empty($sourceid) ? $sourceid : $this->id);
$targetid = (! empty($targetid) ? $targetid : $this->id); $targetid = (! empty($targetid) ? $targetid : $this->id);
@ -1655,8 +1663,16 @@ abstract class CommonObject
$sql.= " WHERE "; $sql.= " WHERE ";
if ($justsource || $justtarget) if ($justsource || $justtarget)
{ {
if ($justsource) $sql.= "fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."'"; if ($justsource)
if ($justtarget) $sql.= "fk_target = '".$targetid."' AND targettype = '".$targettype."'"; {
$sql.= "fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."'";
if ($withtargettype) $sql.= " AND targettype = '".$targettype."'";
}
else if ($justtarget)
{
$sql.= "fk_target = '".$targetid."' AND targettype = '".$targettype."'";
if ($withsourcetype) $sql.= "AND sourcetype = '".$sourcetype."'";
}
} }
else else
{ {