Fix pgsql compatibility

This commit is contained in:
Laurent Destailleur 2017-06-20 13:33:26 +02:00
parent f1701469e0
commit 302e086f99

View File

@ -50,7 +50,7 @@ class SupplierProposal extends CommonObject
public $fk_element='fk_supplier_proposal'; public $fk_element='fk_supplier_proposal';
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto='propal'; public $picto='propal';
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -140,7 +140,7 @@ class SupplierProposal extends CommonObject
var $multicurrency_total_ht; var $multicurrency_total_ht;
var $multicurrency_total_tva; var $multicurrency_total_tva;
var $multicurrency_total_ttc; var $multicurrency_total_ttc;
/** /**
* Draft status * Draft status
*/ */
@ -160,10 +160,10 @@ class SupplierProposal extends CommonObject
/** /**
* Billed or closed/processed quote * Billed or closed/processed quote
*/ */
const STATUS_CLOSE = 4; const STATUS_CLOSE = 4;
/** /**
* Constructor * Constructor
* *
@ -407,7 +407,7 @@ class SupplierProposal extends CommonObject
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];
@ -419,7 +419,7 @@ class SupplierProposal extends CommonObject
$multicurrency_total_ht = $tabprice[16]; $multicurrency_total_ht = $tabprice[16];
$multicurrency_total_tva = $tabprice[17]; $multicurrency_total_tva = $tabprice[17];
$multicurrency_total_ttc = $tabprice[18]; $multicurrency_total_ttc = $tabprice[18];
// Rang to use // Rang to use
$rangtouse = $rang; $rangtouse = $rang;
if ($rangtouse == -1) if ($rangtouse == -1)
@ -487,7 +487,7 @@ class SupplierProposal extends CommonObject
$this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_ht = $multicurrency_total_ht;
$this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_tva = $multicurrency_total_tva;
$this->line->multicurrency_total_ttc = $multicurrency_total_ttc; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
// Mise en option de la ligne // Mise en option de la ligne
if (empty($qty) && empty($special_code)) $this->line->special_code=3; if (empty($qty) && empty($special_code)) $this->line->special_code=3;
@ -583,7 +583,7 @@ class SupplierProposal extends CommonObject
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];
@ -595,7 +595,7 @@ class SupplierProposal extends CommonObject
$multicurrency_total_ht = $tabprice[16]; $multicurrency_total_ht = $tabprice[16];
$multicurrency_total_tva = $tabprice[17]; $multicurrency_total_tva = $tabprice[17];
$multicurrency_total_ttc = $tabprice[18]; $multicurrency_total_ttc = $tabprice[18];
// Anciens indicateurs: $price, $remise (a ne plus utiliser) // Anciens indicateurs: $price, $remise (a ne plus utiliser)
$price = $pu; $price = $pu;
if ($remise_percent > 0) if ($remise_percent > 0)
@ -662,7 +662,7 @@ class SupplierProposal extends CommonObject
if (is_array($array_option) && count($array_option)>0) { if (is_array($array_option) && count($array_option)>0) {
$this->line->array_options=$array_option; $this->line->array_options=$array_option;
} }
// Multicurrency // Multicurrency
$this->line->multicurrency_subprice = price2num($pu * $this->multicurrency_tx); $this->line->multicurrency_subprice = price2num($pu * $this->multicurrency_tx);
$this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_ht = $multicurrency_total_ht;
@ -1180,7 +1180,7 @@ class SupplierProposal extends CommonObject
$this->multicurrency_total_ht = $obj->multicurrency_total_ht; $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
$this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
$this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
if ($obj->fk_statut == 0) if ($obj->fk_statut == 0)
{ {
$this->brouillon = 1; $this->brouillon = 1;
@ -1271,7 +1271,7 @@ class SupplierProposal extends CommonObject
$line->multicurrency_total_tva = $objp->multicurrency_total_tva; $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
$line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
$line->fk_unit = $objp->fk_unit; $line->fk_unit = $objp->fk_unit;
$this->lines[$i] = $line; $this->lines[$i] = $line;
$i++; $i++;
@ -1653,7 +1653,7 @@ class SupplierProposal extends CommonObject
{ {
$trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED'; $trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED';
} }
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{ {
// Define output language // Define output language
@ -1704,7 +1704,7 @@ class SupplierProposal extends CommonObject
$productsupplier = new ProductFournisseur($this->db); $productsupplier = new ProductFournisseur($this->db);
dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG); dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG);
foreach ($this->lines as $product) foreach ($this->lines as $product)
{ {
if ($product->subprice <= 0) continue; if ($product->subprice <= 0) continue;
@ -1721,7 +1721,7 @@ class SupplierProposal extends CommonObject
$this->createPriceFournisseur($product, $user); $this->createPriceFournisseur($product, $user);
} }
} }
return 1; return 1;
} }
@ -2149,7 +2149,7 @@ class SupplierProposal extends CommonObject
$response->label = $label; $response->label = $label;
$response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$statut; $response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$statut;
$response->img = img_object('',"propal"); $response->img = img_object('',"propal");
// This assignment in condition is not a bug. It allows walking the results. // This assignment in condition is not a bug. It allows walking the results.
while ($obj=$this->db->fetch_object($resql)) while ($obj=$this->db->fetch_object($resql))
{ {
@ -2187,7 +2187,7 @@ class SupplierProposal extends CommonObject
global $user,$langs,$conf; global $user,$langs,$conf;
// Load array of products prodids // Load array of products prodids
$num_prods = 0; $num_prods = 0;
$prodids = array(); $prodids = array();
$sql = "SELECT rowid"; $sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " FROM ".MAIN_DB_PREFIX."product";
@ -2250,7 +2250,7 @@ class SupplierProposal extends CommonObject
$prodid = mt_rand(1, $num_prods); $prodid = mt_rand(1, $num_prods);
$line->fk_product=$prodids[$prodid]; $line->fk_product=$prodids[$prodid];
} }
$this->lines[$xnbp]=$line; $this->lines[$xnbp]=$line;
$this->total_ht += $line->total_ht; $this->total_ht += $line->total_ht;
@ -2375,10 +2375,10 @@ class SupplierProposal extends CommonObject
global $langs, $conf, $user; global $langs, $conf, $user;
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
$url=''; $url='';
$result=''; $result='';
$label='<u>'.$langs->trans("ShowSupplierProposal").'</u>'; $label='<u>'.$langs->trans("ShowSupplierProposal").'</u>';
if (! empty($this->ref)) if (! empty($this->ref))
$label.= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref; $label.= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
@ -2396,7 +2396,7 @@ class SupplierProposal extends CommonObject
if ($option == 'document') { if ($option == 'document') {
$url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id. $get_params; $url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id. $get_params;
} }
$linkclose=''; $linkclose='';
if (empty($notooltip) && $user->rights->propal->lire) if (empty($notooltip) && $user->rights->propal->lire)
{ {
@ -2408,7 +2408,7 @@ class SupplierProposal extends CommonObject
$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip"'; $linkclose.=' class="classfortooltip"';
} }
$linkstart = '<a href="'.$url.'"'; $linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>'; $linkstart.=$linkclose.'>';
$linkend='</a>'; $linkend='</a>';
@ -2432,14 +2432,14 @@ class SupplierProposal extends CommonObject
function getLinesArray() function getLinesArray()
{ {
// For other object, here we call fetch_lines. But fetch_lines does not exists on supplier proposal // For other object, here we call fetch_lines. But fetch_lines does not exists on supplier proposal
$sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,'; $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,';
$sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
$sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,'; $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
$sql.= ' pt.product_type, pt.rang, pt.fk_parent_line,'; $sql.= ' pt.product_type, pt.rang, pt.fk_parent_line,';
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,'; $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
$sql.= ' p.description as product_desc, pt.ref_fourn as ref_produit_fourn'; $sql.= ' p.description as product_desc, pt.ref_fourn as ref_produit_fourn,';
$sql.= ' ,pt.fk_multicurrency, pt.multicurrency_code, pt.multicurrency_subprice, pt.multicurrency_total_ht, pt.multicurrency_total_tva, pt.multicurrency_total_ttc, pt.fk_unit'; $sql.= ' pt.fk_multicurrency, pt.multicurrency_code, pt.multicurrency_subprice, pt.multicurrency_total_ht, pt.multicurrency_total_tva, pt.multicurrency_total_ttc, pt.fk_unit';
$sql.= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pt'; $sql.= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pt';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
$sql.= ' WHERE pt.fk_supplier_proposal = '.$this->id; $sql.= ' WHERE pt.fk_supplier_proposal = '.$this->id;
@ -2486,7 +2486,7 @@ class SupplierProposal extends CommonObject
$this->lines[$i]->rang = $obj->rang; $this->lines[$i]->rang = $obj->rang;
$this->lines[$i]->ref_fourn = $obj->ref_produit_fourn; $this->lines[$i]->ref_fourn = $obj->ref_produit_fourn;
// Multicurrency // Multicurrency
$this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency; $this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency;
$this->lines[$i]->multicurrency_code = $obj->multicurrency_code; $this->lines[$i]->multicurrency_code = $obj->multicurrency_code;
@ -2541,7 +2541,7 @@ class SupplierProposal extends CommonObject
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
} }
/** /**
* Function used to replace a thirdparty id with another one. * Function used to replace a thirdparty id with another one.
* *
@ -2555,10 +2555,10 @@ class SupplierProposal extends CommonObject
$tables = array( $tables = array(
'supplier_proposal' 'supplier_proposal'
); );
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
} }
} }
@ -2669,7 +2669,7 @@ class SupplierProposalLine extends CommonObjectLine
var $skip_update_total; // Skip update price total for special lines var $skip_update_total; // Skip update price total for special lines
var $ref_fourn; var $ref_fourn;
// Multicurrency // Multicurrency
var $fk_multicurrency; var $fk_multicurrency;
var $multicurrency_code; var $multicurrency_code;
@ -2750,7 +2750,7 @@ class SupplierProposalLine extends CommonObjectLine
$this->product_desc = $objp->product_desc; $this->product_desc = $objp->product_desc;
$this->ref_fourn = $objp->ref_produit_forun; $this->ref_fourn = $objp->ref_produit_forun;
// Multicurrency // Multicurrency
$this->fk_multicurrency = $objp->fk_multicurrency; $this->fk_multicurrency = $objp->fk_multicurrency;
$this->multicurrency_code = $objp->multicurrency_code; $this->multicurrency_code = $objp->multicurrency_code;
@ -2798,11 +2798,11 @@ class SupplierProposalLine extends CommonObjectLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->fk_fournprice)) $this->fk_fournprice=0; if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
if (empty($this->fk_unit)) $this->fk_unit=0; if (empty($this->fk_unit)) $this->fk_unit=0;
if (empty($this->pa_ht)) $this->pa_ht=0; if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin // if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0) if ($this->pa_ht == 0)
{ {
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{ {
@ -2826,8 +2826,8 @@ class SupplierProposalLine extends CommonObjectLine
$sql.= ' subprice, remise_percent, '; $sql.= ' subprice, remise_percent, ';
$sql.= ' info_bits, '; $sql.= ' info_bits, ';
$sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,'; $sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
$sql.= ' ref_fourn'; $sql.= ' ref_fourn,';
$sql.= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc, fk_unit)'; $sql.= ' fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc, fk_unit)';
$sql.= " VALUES (".$this->fk_supplier_proposal.","; $sql.= " VALUES (".$this->fk_supplier_proposal.",";
$sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").","; $sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").",";
$sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").","; $sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
@ -2860,7 +2860,7 @@ class SupplierProposalLine extends CommonObjectLine
$sql.= ", ".$this->multicurrency_total_ht; $sql.= ", ".$this->multicurrency_total_ht;
$sql.= ", ".$this->multicurrency_total_tva; $sql.= ", ".$this->multicurrency_total_tva;
$sql.= ", ".$this->multicurrency_total_ttc; $sql.= ", ".$this->multicurrency_total_ttc;
$sql.= ", fk_unit=".($this->fk_unit?$this->fk_unit:'null'); $sql.= ", ".($this->fk_unit?$this->fk_unit:'null');
$sql.= ')'; $sql.= ')';
dol_syslog(get_class($this).'::insert', LOG_DEBUG); dol_syslog(get_class($this).'::insert', LOG_DEBUG);
@ -2869,7 +2869,7 @@ class SupplierProposalLine extends CommonObjectLine
{ {
$this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet'); $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');
$this->id=$this->rowid; $this->id=$this->rowid;
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$this->insertExtraFields(); $result=$this->insertExtraFields();
@ -2982,11 +2982,11 @@ class SupplierProposalLine extends CommonObjectLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->fk_fournprice)) $this->fk_fournprice=0; if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
if (empty($this->fk_unit)) $this->fk_unit=0; if (empty($this->fk_unit)) $this->fk_unit=0;
if (empty($this->pa_ht)) $this->pa_ht=0; if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin // if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0) if ($this->pa_ht == 0)
{ {
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{ {
@ -3031,13 +3031,13 @@ class SupplierProposalLine extends CommonObjectLine
if (! empty($this->rang)) $sql.= ", rang=".$this->rang; if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql.= " , ref_fourn=".(! empty($this->ref_fourn)?"'".$this->db->escape($this->ref_fourn)."'":"null"); $sql.= " , ref_fourn=".(! empty($this->ref_fourn)?"'".$this->db->escape($this->ref_fourn)."'":"null");
$sql.= " , fk_unit=".($this->fk_unit?$this->fk_unit:'null'); $sql.= " , fk_unit=".($this->fk_unit?$this->fk_unit:'null');
// Multicurrency // Multicurrency
$sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
$sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
$sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql.= " WHERE rowid = ".$this->rowid; $sql.= " WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::update", LOG_DEBUG); dol_syslog(get_class($this)."::update", LOG_DEBUG);