diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 761f68cde5d17..d378fafb52365 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -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 @@ -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 * diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index c609320a08a90..27380f6220793 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -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; } @@ -484,6 +488,8 @@ function cloture($user) if (! $error) { + $this->statut=3; + $this->db->commit(); return 1; } @@ -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'; @@ -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; @@ -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).'\''); @@ -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; } } @@ -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(); + } /** diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index b2be88816add8..2b055f2368f39 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -381,7 +381,7 @@ else if ($action == 'classifybilled' && $user->rights->commande->creer) { - $object->classer_facturee(); + $ret=$object->classifyBilled(); } // Positionne ref commande client @@ -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) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index ebcf705ff30d6..b37cfecbd2a1d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -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); @@ -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 { diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 83b41a8a0c3f9..c37c9d3926a8a 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -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); }