FIX use setEntity() to move code in multicompany module

This commit is contained in:
Regis Houssin 2019-06-03 11:37:04 +02:00
parent 38246b4088
commit fc83585574
4 changed files with 20 additions and 21 deletions

View File

@ -380,7 +380,6 @@ if (empty($reshook))
}
} else {
$object->ref = GETPOST('ref');
$object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
$object->ref_client = GETPOST('ref_client');
$object->datep = $datep;
$object->date_livraison = $date_delivery;

View File

@ -890,7 +890,6 @@ class Propal extends CommonObject
$now=dol_now();
// Clean parameters
if (empty($this->entity)) $this->entity = $conf->entity;
if (empty($this->date)) $this->date=$this->datep;
$this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
if (empty($this->availability_id)) $this->availability_id=0;
@ -1000,7 +999,7 @@ class Propal extends CommonObject
$sql.= ", ".($this->fk_project?$this->fk_project:"null");
$sql.= ", ".(int) $this->fk_incoterms;
$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
$sql.= ", ".$this->entity;
$sql.= ", ".setEntity($this);
$sql.= ", ".(int) $this->fk_multicurrency;
$sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
$sql.= ", ".(double) $this->multicurrency_tx;
@ -1091,7 +1090,7 @@ class Propal extends CommonObject
$vatrate = $line->tva_tx;
if ($line->vat_src_code && ! preg_match('/\(.*\)/', $vatrate)) $vatrate.=' ('.$line->vat_src_code.')';
$result = $this->addline(
$result = $this->addline(
$line->desc,
$line->subprice,
$line->qty,
@ -1138,7 +1137,7 @@ class Propal extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET fk_delivery_address = ".$this->fk_delivery_address;
$sql.= " WHERE ref = '".$this->db->escape($this->ref)."'";
$sql.= " AND entity = ".$this->entity;
$sql.= " AND entity = ".setEntity($this);
$result=$this->db->query($sql);
}

View File

@ -912,7 +912,6 @@ if (empty($reshook))
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
$object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
// Proprietes particulieres a facture de remplacement
$object->fk_facture_source = $_POST['fac_replacement'];
@ -946,7 +945,7 @@ if (empty($reshook))
if (! $error)
{
if(!empty($originentity)){
if (!empty($originentity)) {
$object->entity = $originentity;
}
$object->socid = GETPOST('socid', 'int');
@ -968,7 +967,6 @@ if (empty($reshook))
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
$object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
// Proprietes particulieres a facture avoir
$object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : '';
@ -1150,7 +1148,6 @@ if (empty($reshook))
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
$object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
// Source facture
$object->fac_rec = GETPOST('fac_rec', 'int');
@ -1201,7 +1198,6 @@ if (empty($reshook))
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
$object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
if (GETPOST('type') == Facture::TYPE_SITUATION)
{

View File

@ -303,7 +303,6 @@ class Facture extends CommonInvoice
if (! $this->cond_reglement_id) $this->cond_reglement_id = 0;
if (! $this->mode_reglement_id) $this->mode_reglement_id = 0;
$this->brouillon = 1;
if (empty($this->entity)) $this->entity = $conf->entity;
// Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate)
if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
@ -474,7 +473,7 @@ class Facture extends CommonInvoice
$sql.= ")";
$sql.= " VALUES (";
$sql.= "'(PROV)'";
$sql.= ", ".$this->entity;
$sql.= ", ".setEntity($this);
$sql.= ", ".($this->ref_ext?"'".$this->db->escape($this->ref_ext)."'":"null");
$sql.= ", '".$this->db->escape($this->type)."'";
$sql.= ", '".$socid."'";
@ -913,8 +912,8 @@ class Facture extends CommonInvoice
$facture->remise_absolue = $this->remise_absolue;
$facture->remise_percent = $this->remise_percent;
$facture->origin = $this->origin;
$facture->origin_id = $this->origin_id;
$facture->origin = $this->origin;
$facture->origin_id = $this->origin_id;
$facture->lines = $this->lines; // Tableau des lignes de factures
$facture->products = $this->lines; // Tant que products encore utilise
@ -1582,7 +1581,11 @@ class Facture extends CommonInvoice
$this->tab_previous_situation_invoice = array();
$this->tab_next_situation_invoice = array();
$sql = 'SELECT rowid, situation_counter FROM '.MAIN_DB_PREFIX.'facture WHERE rowid <> '.$this->id.' AND entity = '.$conf->entity.' AND situation_cycle_ref = '.(int) $this->situation_cycle_ref.' ORDER BY situation_counter ASC';
$sql = 'SELECT rowid, situation_counter FROM '.MAIN_DB_PREFIX.'facture';
$sql.= ' WHERE rowid <> '.$this->id;
$sql.= ' AND entity = '.$this->entity;
$sql.= ' AND situation_cycle_ref = '.(int) $this->situation_cycle_ref;
$sql.= ' ORDER BY situation_counter ASC';
dol_syslog(get_class($this).'::fetchPreviousNextSituationInvoice ', LOG_DEBUG);
$result = $this->db->query($sql);
@ -3648,11 +3651,11 @@ class Facture extends CommonInvoice
$sql.= " AND ff.type IS NULL"; // Renvoi vrai si pas facture de remplacement
$sql.= " AND f.type != ".self::TYPE_CREDIT_NOTE; // Type non 2 si facture non avoir
if($conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE){
if (! empty($conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE)) {
// Select the last situation invoice
$sqlSit = 'SELECT MAX(fs.rowid)';
$sqlSit.= " FROM ".MAIN_DB_PREFIX."facture as fs";
$sqlSit.= " WHERE fs.entity = ".$conf->entity;
$sqlSit.= " WHERE fs.entity IN (".getEntity('invoice').")";
$sqlSit.= " AND fs.type = ".self::TYPE_SITUATION;
$sqlSit.= " AND fs.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")";
$sqlSit.= " GROUP BY fs.situation_cycle_ref";
@ -4178,7 +4181,7 @@ class Facture extends CommonInvoice
public function newCycle()
{
$sql = 'SELECT max(situation_cycle_ref) FROM ' . MAIN_DB_PREFIX . 'facture as f';
$sql.= " WHERE f.entity in (".getEntity('invoice', 0).")";
$sql.= " WHERE f.entity IN (".getEntity('invoice', 0).")";
$resql = $this->db->query($sql);
if ($resql) {
if ($resql->num_rows > 0)
@ -4222,8 +4225,8 @@ class Facture extends CommonInvoice
global $conf;
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'facture';
$sql .= ' where situation_cycle_ref = ' . $this->situation_cycle_ref;
$sql .= ' and situation_counter < ' . $this->situation_counter;
$sql .= ' WHERE situation_cycle_ref = ' . $this->situation_cycle_ref;
$sql .= ' AND situation_counter < ' . $this->situation_counter;
$sql .= ' AND entity = '. ($this->entity > 0 ? $this->entity : $conf->entity);
$resql = $this->db->query($sql);
$res = array();
@ -4304,7 +4307,9 @@ class Facture extends CommonInvoice
if (!empty($this->situation_cycle_ref)) {
// No point in testing anything if we're not inside a cycle
$sql = 'SELECT max(situation_counter) FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_cycle_ref = ' . $this->situation_cycle_ref . ' AND entity = ' . ($this->entity > 0 ? $this->entity : $conf->entity);
$sql = 'SELECT max(situation_counter) FROM ' . MAIN_DB_PREFIX . 'facture';
$sql.= ' WHERE situation_cycle_ref = ' . $this->situation_cycle_ref;
$sql.= ' AND entity = ' . ($this->entity > 0 ? $this->entity : $conf->entity);
$resql = $this->db->query($sql);
if ($resql && $resql->num_rows > 0) {