Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr.git in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
eldy committed Jul 8, 2012
2 parents 0d12536 + 680fd32 commit fad501d
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 89 deletions.
13 changes: 12 additions & 1 deletion htdocs/comm/propal/class/propal.class.php
Expand Up @@ -1560,12 +1560,13 @@ function cloture($user, $statut, $note)
*
* @return int <0 si ko, >0 si ok
*/
function classer_facturee()
function classifyBilled()
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = 4';
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;';
if ($this->db->query($sql) )
{
$this->statut=4;
return 1;
}
else
Expand All @@ -1574,6 +1575,16 @@ function classer_facturee()
}
}

/**
* Class invoiced the Propal
*
* @return int <0 si ko, >0 si ok
*/
function classer_facturee()
{
return $this->classifyBilled();
}

/**
* Set draft status
*
Expand Down
167 changes: 96 additions & 71 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -439,6 +439,10 @@ function set_reopen($user)

if (! $error)
{
$this->statut = 1;
$this->billed = 0;
$this->facturee = 0; // deprecated

$this->db->commit();
return 1;
}
Expand Down Expand Up @@ -484,6 +488,8 @@ function cloture($user)

if (! $error)
{
$this->statut=3;

$this->db->commit();
return 1;
}
Expand Down Expand Up @@ -1226,7 +1232,7 @@ function fetch($id, $ref='', $ref_ext='', $ref_int='')
$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_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.= ', 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';
Expand All @@ -1250,48 +1256,49 @@ function fetch($id, $ref='', $ref_ext='', $ref_int='')
$obj = $this->db->fetch_object($result);
if ($obj)
{
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->ref_client = $obj->ref_client;
$this->ref_ext = $obj->ref_ext;
$this->ref_int = $obj->ref_int;
$this->socid = $obj->fk_soc;
$this->statut = $obj->fk_statut;
$this->user_author_id = $obj->fk_user_author;
$this->total_ht = $obj->total_ht;
$this->total_tva = $obj->total_tva;
$this->total_localtax1 = $obj->total_localtax1;
$this->total_localtax2 = $obj->total_localtax2;
$this->total_ttc = $obj->total_ttc;
$this->date = $this->db->jdate($obj->date_commande);
$this->date_commande = $this->db->jdate($obj->date_commande);
$this->remise = $obj->remise;
$this->remise_percent = $obj->remise_percent;
$this->remise_absolue = $obj->remise_absolue;
$this->source = $obj->source;
$this->facturee = $obj->facturee;
$this->note = $obj->note_private; // deprecated
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
$this->fk_project = $obj->fk_projet;
$this->modelpdf = $obj->model_pdf;
$this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code;
$this->mode_reglement = $obj->mode_reglement_libelle;
$this->cond_reglement_id = $obj->fk_cond_reglement;
$this->cond_reglement_code = $obj->cond_reglement_code;
$this->cond_reglement = $obj->cond_reglement_libelle;
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
$this->availability_id = $obj->fk_availability;
$this->availability_code = $obj->availability_code;
$this->demand_reason_id = $obj->fk_demand_reason;
$this->demand_reason_code = $obj->demand_reason_code;
$this->date_livraison = $this->db->jdate($obj->date_livraison);
$this->fk_delivery_address = $obj->fk_adresse_livraison;

$this->extraparams = (array) json_decode($obj->extraparams, true);

$this->lines = array();
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->ref_client = $obj->ref_client;
$this->ref_ext = $obj->ref_ext;
$this->ref_int = $obj->ref_int;
$this->socid = $obj->fk_soc;
$this->statut = $obj->fk_statut;
$this->user_author_id = $obj->fk_user_author;
$this->total_ht = $obj->total_ht;
$this->total_tva = $obj->total_tva;
$this->total_localtax1 = $obj->total_localtax1;
$this->total_localtax2 = $obj->total_localtax2;
$this->total_ttc = $obj->total_ttc;
$this->date = $this->db->jdate($obj->date_commande);
$this->date_commande = $this->db->jdate($obj->date_commande);
$this->remise = $obj->remise;
$this->remise_percent = $obj->remise_percent;
$this->remise_absolue = $obj->remise_absolue;
$this->source = $obj->source;
$this->facturee = $obj->billed; // deprecated
$this->billed = $obj->billed;
$this->note = $obj->note_private; // deprecated
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
$this->fk_project = $obj->fk_projet;
$this->modelpdf = $obj->model_pdf;
$this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code;
$this->mode_reglement = $obj->mode_reglement_libelle;
$this->cond_reglement_id = $obj->fk_cond_reglement;
$this->cond_reglement_code = $obj->cond_reglement_code;
$this->cond_reglement = $obj->cond_reglement_libelle;
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
$this->availability_id = $obj->fk_availability;
$this->availability_code = $obj->availability_code;
$this->demand_reason_id = $obj->fk_demand_reason;
$this->demand_reason_code = $obj->demand_reason_code;
$this->date_livraison = $this->db->jdate($obj->date_livraison);
$this->fk_delivery_address = $obj->fk_adresse_livraison;

$this->extraparams = (array) json_decode($obj->extraparams, true);

$this->lines = array();

if ($this->statut == 0) $this->brouillon = 1;

Expand Down Expand Up @@ -2029,7 +2036,7 @@ function set_ref_client($user, $ref_client)
{
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.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\'');
Expand All @@ -2043,7 +2050,7 @@ function set_ref_client($user, $ref_client)
else
{
$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;
}
}
Expand All @@ -2053,34 +2060,52 @@ function set_ref_client($user, $ref_client)
}
}

/**
* Classify the order as invoiced
*
* @return int <0 if ko, >0 if ok
*/
function classifyBilled()
{
global $conf;

/**
* Classify the order as invoiced
*
* @return int <0 if ko, >0 if ok
*/
function classer_facturee()
{
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();
}
}
}

$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;
}
}
$this->facturee=1; // deprecated
$this->billed=1;

return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}

/**
* Classify the order as invoiced
*
* @return int <0 if ko, >0 if ok
*/
function classer_facturee()
{
return $this->classifyBilled();
}


/**
Expand Down
4 changes: 2 additions & 2 deletions htdocs/commande/fiche.php
Expand Up @@ -381,7 +381,7 @@

else if ($action == 'classifybilled' && $user->rights->commande->creer)
{
$object->classer_facturee();
$ret=$object->classifyBilled();
}

// Positionne ref commande client
Expand Down Expand Up @@ -2116,7 +2116,7 @@
}

// 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)
{
Expand Down
26 changes: 22 additions & 4 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -1640,9 +1640,19 @@ function fetchObjectLinked($sourceid='',$sourcetype='',$targetid='',$targettype=

$justsource=false;
$justtarget=false;
$withtargettype=false;
$withsourcetype=false;

if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $justsource=true;
if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $justtarget=true;
if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid))
{
$justsource=true;
if (! empty($targettype)) $withtargettype=true;
}
if (! empty($targetid) && ! empty($targettype) && empty($sourceid))
{
$justtarget=true;
if (! empty($sourcetype)) $withsourcetype=true;
}

$sourceid = (! empty($sourceid) ? $sourceid : $this->id);
$targetid = (! empty($targetid) ? $targetid : $this->id);
Expand All @@ -1655,8 +1665,16 @@ function fetchObjectLinked($sourceid='',$sourcetype='',$targetid='',$targettype=
$sql.= " WHERE ";
if ($justsource || $justtarget)
{
if ($justsource) $sql.= "fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."'";
if ($justtarget) $sql.= "fk_target = '".$targetid."' AND targettype = '".$targettype."'";
if ($justsource)
{
$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
{
Expand Down
22 changes: 11 additions & 11 deletions htdocs/core/class/html.formother.class.php
Expand Up @@ -450,17 +450,17 @@ private function _pLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0,
}
}

/**
* Output a HTML code to select a color
*
* @param string $set_color Pre-selected color
* @param string $prefix Name of HTML field
* @param string $form_name Name of form
* @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
* @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
* @return void
*/
function select_color($set_color='', $prefix='f_color', $form_name='objForm', $showcolorbox=1, $arrayofcolors='')
/**
* Output a HTML code to select a color
*
* @param string $set_color Pre-selected color
* @param string $prefix Name of HTML field
* @param string $form_name Name of form
* @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
* @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
* @return void
*/
function select_color($set_color='', $prefix='f_color', $form_name='objForm', $showcolorbox=1, $arrayofcolors='')
{
print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
}
Expand Down

0 comments on commit fad501d

Please sign in to comment.