codesniffer
This commit is contained in:
parent
d242f4930d
commit
4cbdf32ae6
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2012-2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -24,9 +24,10 @@
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
|
||||
|
||||
/**
|
||||
* Put here description of your class
|
||||
* File of class to manage predefined price products or services by customer
|
||||
*/
|
||||
class Productcustomerprice extends CommonObject {
|
||||
class Productcustomerprice extends CommonObject
|
||||
{
|
||||
var $db; // !< To store db handler
|
||||
var $error; // !< To return error code (or message)
|
||||
var $errors = array (); // !< To return several error codes (or messages)
|
||||
@ -77,61 +78,61 @@ class Productcustomerprice extends CommonObject {
|
||||
|
||||
// Clean parameters
|
||||
|
||||
if (isset ( $this->entity ))
|
||||
$this->entity = trim ( $this->entity );
|
||||
if (isset ( $this->fk_product ))
|
||||
$this->fk_product = trim ( $this->fk_product );
|
||||
if (isset ( $this->fk_soc ))
|
||||
$this->fk_soc = trim ( $this->fk_soc );
|
||||
if (isset ( $this->price ))
|
||||
$this->price = trim ( $this->price );
|
||||
if (isset ( $this->price_ttc ))
|
||||
$this->price_ttc = trim ( $this->price_ttc );
|
||||
if (isset ( $this->price_min ))
|
||||
$this->price_min = trim ( $this->price_min );
|
||||
if (isset ( $this->price_min_ttc ))
|
||||
$this->price_min_ttc = trim ( $this->price_min_ttc );
|
||||
if (isset ( $this->price_base_type ))
|
||||
$this->price_base_type = trim ( $this->price_base_type );
|
||||
if (isset ( $this->tva_tx ))
|
||||
$this->tva_tx = trim ( $this->tva_tx );
|
||||
if (isset ( $this->recuperableonly ))
|
||||
$this->recuperableonly = trim ( $this->recuperableonly );
|
||||
if (isset ( $this->localtax1_tx ))
|
||||
$this->localtax1_tx = trim ( $this->localtax1_tx );
|
||||
if (isset ( $this->localtax2_tx ))
|
||||
$this->localtax2_tx = trim ( $this->localtax2_tx );
|
||||
if (isset ( $this->fk_user ))
|
||||
$this->fk_user = trim ( $this->fk_user );
|
||||
if (isset ( $this->import_key ))
|
||||
$this->import_key = trim ( $this->import_key );
|
||||
if (isset($this->entity))
|
||||
$this->entity = trim($this->entity);
|
||||
if (isset($this->fk_product))
|
||||
$this->fk_product = trim($this->fk_product);
|
||||
if (isset($this->fk_soc))
|
||||
$this->fk_soc = trim($this->fk_soc);
|
||||
if (isset($this->price))
|
||||
$this->price = trim($this->price);
|
||||
if (isset($this->price_ttc))
|
||||
$this->price_ttc = trim($this->price_ttc);
|
||||
if (isset($this->price_min))
|
||||
$this->price_min = trim($this->price_min);
|
||||
if (isset($this->price_min_ttc))
|
||||
$this->price_min_ttc = trim($this->price_min_ttc);
|
||||
if (isset($this->price_base_type))
|
||||
$this->price_base_type = trim($this->price_base_type);
|
||||
if (isset($this->tva_tx))
|
||||
$this->tva_tx = trim($this->tva_tx);
|
||||
if (isset($this->recuperableonly))
|
||||
$this->recuperableonly = trim($this->recuperableonly);
|
||||
if (isset($this->localtax1_tx))
|
||||
$this->localtax1_tx = trim($this->localtax1_tx);
|
||||
if (isset($this->localtax2_tx))
|
||||
$this->localtax2_tx = trim($this->localtax2_tx);
|
||||
if (isset($this->fk_user))
|
||||
$this->fk_user = trim($this->fk_user);
|
||||
if (isset($this->import_key))
|
||||
$this->import_key = trim($this->import_key);
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add control on parameters values
|
||||
|
||||
if ($this->price != '' || $this->price == 0) {
|
||||
if ($this->price_base_type == 'TTC') {
|
||||
$this->price_ttc = price2num ( $this->price, 'MU' );
|
||||
$this->price = price2num ( $this->price ) / (1 + ($this->tva_tx / 100));
|
||||
$this->price = price2num ( $this->price, 'MU' );
|
||||
$this->price_ttc = price2num($this->price, 'MU');
|
||||
$this->price = price2num($this->price) / (1 + ($this->tva_tx / 100));
|
||||
$this->price = price2num($this->price, 'MU');
|
||||
|
||||
if ($this->price_min != '' || $this->price_min == 0) {
|
||||
$this->price_min_ttc = price2num ( $this->price_min, 'MU' );
|
||||
$this->price_min = price2num ( $this->price_min ) / (1 + ($this->tva_tx / 100));
|
||||
$this->price_min = price2num ( $this->price_min, 'MU' );
|
||||
$this->price_min_ttc = price2num($this->price_min, 'MU');
|
||||
$this->price_min = price2num($this->price_min) / (1 + ($this->tva_tx / 100));
|
||||
$this->price_min = price2num($this->price_min, 'MU');
|
||||
} else {
|
||||
$this->price_min = 0;
|
||||
$this->price_min_ttc = 0;
|
||||
}
|
||||
} else {
|
||||
$this->price = price2num ( $this->price, 'MU' );
|
||||
$this->price_ttc = ($this->recuperableonly != 1) ? price2num ( $this->price ) * (1 + ($this->tva_tx / 100)) : $this->price;
|
||||
$this->price_ttc = price2num ( $this->price_ttc, 'MU' );
|
||||
$this->price = price2num($this->price, 'MU');
|
||||
$this->price_ttc = ($this->recuperableonly != 1) ? price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price;
|
||||
$this->price_ttc = price2num($this->price_ttc, 'MU');
|
||||
|
||||
if ($this->price_min != '' || $this->price_min == 0) {
|
||||
$this->price_min = price2num ( $this->price_min, 'MU' );
|
||||
$this->price_min_ttc = price2num ( $this->price_min ) * (1 + ($this->tva_tx / 100));
|
||||
$this->price_min_ttc = price2num ( $this->price_min_ttc, 'MU' );
|
||||
$this->price_min = price2num($this->price_min, 'MU');
|
||||
$this->price_min_ttc = price2num($this->price_min) * (1 + ($this->tva_tx / 100));
|
||||
$this->price_min_ttc = price2num($this->price_min_ttc, 'MU');
|
||||
// print 'X'.$newminprice.'-'.$price_min;
|
||||
} else {
|
||||
$this->price_min = 0;
|
||||
@ -162,34 +163,34 @@ class Productcustomerprice extends CommonObject {
|
||||
$sql .= ") VALUES (";
|
||||
|
||||
$sql .= " " . $conf->entity . ",";
|
||||
$sql .= " '" . $this->db->idate ( dol_now () ) . "',";
|
||||
$sql .= " " . (! isset ( $this->fk_product ) ? 'NULL' : "'" . $this->fk_product . "'") . ",";
|
||||
$sql .= " " . (! isset ( $this->fk_soc ) ? 'NULL' : "'" . $this->fk_soc . "'") . ",";
|
||||
$sql .= " " . (empty ( $this->price ) ? '0' : "'" . $this->price . "'") . ",";
|
||||
$sql .= " " . (empty ( $this->price_ttc ) ? '0' : "'" . $this->price_ttc . "'") . ",";
|
||||
$sql .= " " . (empty ( $this->price_min ) ? '0' : "'" . $this->price_min . "'") . ",";
|
||||
$sql .= " " . (empty ( $this->price_min_ttc ) ? '0' : "'" . $this->price_min_ttc . "'") . ",";
|
||||
$sql .= " " . (! isset ( $this->price_base_type ) ? 'NULL' : "'" . $this->db->escape ( $this->price_base_type ) . "'") . ",";
|
||||
$sql .= " " . (! isset ( $this->tva_tx ) ? 'NULL' : "'" . $this->tva_tx . "'") . ",";
|
||||
$sql .= " " . (! isset ( $this->recuperableonly ) ? 'NULL' : "'" . $this->recuperableonly . "'") . ",";
|
||||
$sql .= " " . (! isset ( $this->localtax1_tx ) ? 'NULL' : "'" . $this->localtax1_tx . "'") . ",";
|
||||
$sql .= " " . (! isset ( $this->localtax2_tx ) ? 'NULL' : "'" . $this->localtax2_tx . "'") . ",";
|
||||
$sql .= " '" . $this->db->idate(dol_now()) . "',";
|
||||
$sql .= " " . (! isset($this->fk_product) ? 'NULL' : "'" . $this->fk_product . "'") . ",";
|
||||
$sql .= " " . (! isset($this->fk_soc) ? 'NULL' : "'" . $this->fk_soc . "'") . ",";
|
||||
$sql .= " " . (empty($this->price) ? '0' : "'" . $this->price . "'") . ",";
|
||||
$sql .= " " . (empty($this->price_ttc) ? '0' : "'" . $this->price_ttc . "'") . ",";
|
||||
$sql .= " " . (empty($this->price_min) ? '0' : "'" . $this->price_min . "'") . ",";
|
||||
$sql .= " " . (empty($this->price_min_ttc) ? '0' : "'" . $this->price_min_ttc . "'") . ",";
|
||||
$sql .= " " . (! isset($this->price_base_type) ? 'NULL' : "'" . $this->db->escape($this->price_base_type) . "'") . ",";
|
||||
$sql .= " " . (! isset($this->tva_tx) ? 'NULL' : "'" . $this->tva_tx . "'") . ",";
|
||||
$sql .= " " . (! isset($this->recuperableonly) ? 'NULL' : "'" . $this->recuperableonly . "'") . ",";
|
||||
$sql .= " " . (! isset($this->localtax1_tx) ? 'NULL' : "'" . $this->localtax1_tx . "'") . ",";
|
||||
$sql .= " " . (! isset($this->localtax2_tx) ? 'NULL' : "'" . $this->localtax2_tx . "'") . ",";
|
||||
$sql .= " " . $user->id . ",";
|
||||
$sql .= " " . (! isset ( $this->import_key ) ? 'NULL' : "'" . $this->db->escape ( $this->import_key ) . "'") . "";
|
||||
$sql .= " " . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . "";
|
||||
|
||||
$sql .= ")";
|
||||
|
||||
$this->db->begin ();
|
||||
$this->db->begin();
|
||||
|
||||
dol_syslog ( get_class ( $this ) . "::create sql=" . $sql, LOG_DEBUG );
|
||||
$resql = $this->db->query ( $sql );
|
||||
dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) {
|
||||
$error ++;
|
||||
$this->errors [] = "Error " . $this->db->lasterror ();
|
||||
$this->errors [] = "Error " . $this->db->lasterror();
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
$this->id = $this->db->last_insert_id ( MAIN_DB_PREFIX . "product_customer_price" );
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "product_customer_price");
|
||||
|
||||
if (! $notrigger) {
|
||||
// Uncomment this and change MYOBJECT to your own tag if you
|
||||
@ -205,7 +206,7 @@ class Productcustomerprice extends CommonObject {
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
$result = $this->setPriceOnAffiliateThirdparty ($user, $forceupdateaffiliate );
|
||||
$result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate);
|
||||
if ($result < 0) {
|
||||
$error ++;
|
||||
}
|
||||
@ -214,13 +215,13 @@ class Productcustomerprice extends CommonObject {
|
||||
// Commit or rollback
|
||||
if ($error) {
|
||||
foreach ( $this->errors as $errmsg ) {
|
||||
dol_syslog ( get_class ( $this ) . "::create " . $errmsg, LOG_ERR );
|
||||
dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR);
|
||||
$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
|
||||
}
|
||||
$this->db->rollback ();
|
||||
$this->db->rollback();
|
||||
return - 1 * $error;
|
||||
} else {
|
||||
$this->db->commit ();
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
@ -257,17 +258,17 @@ class Productcustomerprice extends CommonObject {
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t";
|
||||
$sql .= " WHERE t.rowid = " . $id;
|
||||
|
||||
dol_syslog ( get_class ( $this ) . "::fetch sql=" . $sql, LOG_DEBUG );
|
||||
$resql = $this->db->query ( $sql );
|
||||
dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
if ($this->db->num_rows ( $resql )) {
|
||||
$obj = $this->db->fetch_object ( $resql );
|
||||
if ($this->db->num_rows($resql)) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
|
||||
$this->entity = $obj->entity;
|
||||
$this->datec = $this->db->jdate ( $obj->datec );
|
||||
$this->tms = $this->db->jdate ( $obj->tms );
|
||||
$this->datec = $this->db->jdate($obj->datec);
|
||||
$this->tms = $this->db->jdate($obj->tms);
|
||||
$this->fk_product = $obj->fk_product;
|
||||
$this->fk_soc = $obj->fk_soc;
|
||||
$this->price = $obj->price;
|
||||
@ -282,27 +283,23 @@ class Productcustomerprice extends CommonObject {
|
||||
$this->fk_user = $obj->fk_user;
|
||||
$this->import_key = $obj->import_key;
|
||||
}
|
||||
$this->db->free ( $resql );
|
||||
$this->db->free($resql);
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
$this->error = "Error " . $this->db->lasterror ();
|
||||
dol_syslog ( get_class ( $this ) . "::fetch " . $this->error, LOG_ERR );
|
||||
$this->error = "Error " . $this->db->lasterror();
|
||||
dol_syslog(get_class($this) . "::fetch " . $this->error, LOG_ERR);
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* Load all objects in memory from database
|
||||
*
|
||||
* @param string $sortorder order
|
||||
* @param string $sortfield field
|
||||
* @param int $limit page
|
||||
* @param int $offset
|
||||
* @param int $arch archive or not
|
||||
* @param int $offset offset
|
||||
* @param array $filter output
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
@ -335,12 +332,12 @@ class Productcustomerprice extends CommonObject {
|
||||
$sql .= " ," . MAIN_DB_PREFIX . "societe as soc ";
|
||||
$sql .= " WHERE soc.rowid=t.fk_soc ";
|
||||
$sql .= " AND prod.rowid=t.fk_product ";
|
||||
$sql .= " AND prod.entity IN (" . getEntity ( 'product', 1 ) . ")";
|
||||
$sql .= " AND prod.entity IN (" . getEntity('product', 1) . ")";
|
||||
|
||||
// Manage filter
|
||||
if (count ( $filter ) > 0) {
|
||||
if (count($filter) > 0) {
|
||||
foreach ( $filter as $key => $value ) {
|
||||
if (strpos ( $key, 'date' )) // To allow $filter['YEAR(s.dated)']=>$year
|
||||
if (strpos($key, 'date')) // To allow $filter['YEAR(s.dated)']=>$year
|
||||
{
|
||||
$sql .= ' AND ' . $key . ' = \'' . $value . '\'';
|
||||
} elseif ($key == 'soc.nom') {
|
||||
@ -351,29 +348,29 @@ class Productcustomerprice extends CommonObject {
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty ( $sortfield )) {
|
||||
if (! empty($sortfield)) {
|
||||
$sql .= " ORDER BY " . $sortfield . ' ' . $sortorder;
|
||||
}
|
||||
if (! empty ( $limit )) {
|
||||
$sql .= ' ' . $this->db->plimit ( $limit + 1, $offset );
|
||||
if (! empty($limit)) {
|
||||
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
||||
}
|
||||
|
||||
dol_syslog ( get_class ( $this ) . "::fetch_all sql=" . $sql, LOG_DEBUG );
|
||||
$resql = $this->db->query ( $sql );
|
||||
dol_syslog(get_class($this) . "::fetch_all sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
|
||||
$this->lines = array ();
|
||||
$num = $this->db->num_rows ( $resql );
|
||||
$num = $this->db->num_rows($resql);
|
||||
|
||||
while ( $obj = $this->db->fetch_object ( $resql ) ) {
|
||||
while ( $obj = $this->db->fetch_object($resql) ) {
|
||||
|
||||
$line = new PriceByCustomerLine ();
|
||||
$line = new PriceByCustomerLine();
|
||||
|
||||
$line->id = $obj->rowid;
|
||||
|
||||
$line->entity = $obj->entity;
|
||||
$line->datec = $this->db->jdate ( $obj->datec );
|
||||
$line->tms = $this->db->jdate ( $obj->tms );
|
||||
$line->datec = $this->db->jdate($obj->datec);
|
||||
$line->tms = $this->db->jdate($obj->tms);
|
||||
$line->fk_product = $obj->fk_product;
|
||||
$line->fk_soc = $obj->fk_soc;
|
||||
$line->price = $obj->price;
|
||||
@ -392,26 +389,23 @@ class Productcustomerprice extends CommonObject {
|
||||
|
||||
$this->lines [] = $line;
|
||||
}
|
||||
$this->db->free ( $resql );
|
||||
$this->db->free($resql);
|
||||
|
||||
return $num;
|
||||
} else {
|
||||
$this->error = "Error " . $this->db->lasterror ();
|
||||
dol_syslog ( get_class ( $this ) . "::fetch_all " . $this->error, LOG_ERR );
|
||||
$this->error = "Error " . $this->db->lasterror();
|
||||
dol_syslog(get_class($this) . "::fetch_all " . $this->error, LOG_ERR);
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Load all objects in memory from database
|
||||
*
|
||||
* @param string $sortorder order
|
||||
* @param string $sortfield field
|
||||
* @param int $limit page
|
||||
* @param int $offset
|
||||
* @param int $arch archive or not
|
||||
* @param int $offset offset
|
||||
* @param array $filter output
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
@ -443,12 +437,12 @@ class Productcustomerprice extends CommonObject {
|
||||
$sql .= " ," . MAIN_DB_PREFIX . "societe as soc ";
|
||||
$sql .= " WHERE soc.rowid=t.fk_soc ";
|
||||
$sql .= " AND prod.rowid=t.fk_product ";
|
||||
$sql .= " AND prod.entity IN (" . getEntity ( 'product', 1 ) . ")";
|
||||
$sql .= " AND prod.entity IN (" . getEntity('product', 1) . ")";
|
||||
|
||||
// Manage filter
|
||||
if (count ( $filter ) > 0) {
|
||||
if (count($filter) > 0) {
|
||||
foreach ( $filter as $key => $value ) {
|
||||
if (strpos ( $key, 'date' )) // To allow $filter['YEAR(s.dated)']=>$year
|
||||
if (strpos($key, 'date')) // To allow $filter['YEAR(s.dated)']=>$year
|
||||
{
|
||||
$sql .= ' AND ' . $key . ' = \'' . $value . '\'';
|
||||
} elseif ($key == 'soc.nom') {
|
||||
@ -459,29 +453,29 @@ class Productcustomerprice extends CommonObject {
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty ( $sortfield )) {
|
||||
if (! empty($sortfield)) {
|
||||
$sql .= " ORDER BY " . $sortfield . ' ' . $sortorder;
|
||||
}
|
||||
if (! empty ( $limit )) {
|
||||
$sql .= ' ' . $this->db->plimit ( $limit + 1, $offset );
|
||||
if (! empty($limit)) {
|
||||
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
||||
}
|
||||
|
||||
dol_syslog ( get_class ( $this ) . "::fetch_all_log sql=" . $sql, LOG_DEBUG );
|
||||
$resql = $this->db->query ( $sql );
|
||||
dol_syslog(get_class($this) . "::fetch_all_log sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
|
||||
$this->lines = array ();
|
||||
$num = $this->db->num_rows ( $resql );
|
||||
$num = $this->db->num_rows($resql);
|
||||
|
||||
while ( $obj = $this->db->fetch_object ( $resql ) ) {
|
||||
while ( $obj = $this->db->fetch_object($resql) ) {
|
||||
|
||||
$line = new PriceByCustomerLine ();
|
||||
$line = new PriceByCustomerLine();
|
||||
|
||||
$line->id = $obj->rowid;
|
||||
|
||||
$line->entity = $obj->entity;
|
||||
$line->datec = $this->db->jdate ( $obj->datec );
|
||||
$line->tms = $this->db->jdate ( $obj->tms );
|
||||
$line->datec = $this->db->jdate($obj->datec);
|
||||
$line->tms = $this->db->jdate($obj->tms);
|
||||
$line->fk_product = $obj->fk_product;
|
||||
$line->fk_soc = $obj->fk_soc;
|
||||
$line->price = $obj->price;
|
||||
@ -500,12 +494,12 @@ class Productcustomerprice extends CommonObject {
|
||||
|
||||
$this->lines [] = $line;
|
||||
}
|
||||
$this->db->free ( $resql );
|
||||
$this->db->free($resql);
|
||||
|
||||
return $num;
|
||||
} else {
|
||||
$this->error = "Error " . $this->db->lasterror ();
|
||||
dol_syslog ( get_class ( $this ) . "::fetch_all_log " . $this->error, LOG_ERR );
|
||||
$this->error = "Error " . $this->db->lasterror();
|
||||
dol_syslog(get_class($this) . "::fetch_all_log " . $this->error, LOG_ERR);
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
@ -525,61 +519,61 @@ class Productcustomerprice extends CommonObject {
|
||||
|
||||
// Clean parameters
|
||||
|
||||
if (isset ( $this->entity ))
|
||||
$this->entity = trim ( $this->entity );
|
||||
if (isset ( $this->fk_product ))
|
||||
$this->fk_product = trim ( $this->fk_product );
|
||||
if (isset ( $this->fk_soc ))
|
||||
$this->fk_soc = trim ( $this->fk_soc );
|
||||
if (isset ( $this->price ))
|
||||
$this->price = trim ( $this->price );
|
||||
if (isset ( $this->price_ttc ))
|
||||
$this->price_ttc = trim ( $this->price_ttc );
|
||||
if (isset ( $this->price_min ))
|
||||
$this->price_min = trim ( $this->price_min );
|
||||
if (isset ( $this->price_min_ttc ))
|
||||
$this->price_min_ttc = trim ( $this->price_min_ttc );
|
||||
if (isset ( $this->price_base_type ))
|
||||
$this->price_base_type = trim ( $this->price_base_type );
|
||||
if (isset ( $this->tva_tx ))
|
||||
$this->tva_tx = trim ( $this->tva_tx );
|
||||
if (isset ( $this->recuperableonly ))
|
||||
$this->recuperableonly = trim ( $this->recuperableonly );
|
||||
if (isset ( $this->localtax1_tx ))
|
||||
$this->localtax1_tx = trim ( $this->localtax1_tx );
|
||||
if (isset ( $this->localtax2_tx ))
|
||||
$this->localtax2_tx = trim ( $this->localtax2_tx );
|
||||
if (isset ( $this->fk_user ))
|
||||
$this->fk_user = trim ( $this->fk_user );
|
||||
if (isset ( $this->import_key ))
|
||||
$this->import_key = trim ( $this->import_key );
|
||||
if (isset($this->entity))
|
||||
$this->entity = trim($this->entity);
|
||||
if (isset($this->fk_product))
|
||||
$this->fk_product = trim($this->fk_product);
|
||||
if (isset($this->fk_soc))
|
||||
$this->fk_soc = trim($this->fk_soc);
|
||||
if (isset($this->price))
|
||||
$this->price = trim($this->price);
|
||||
if (isset($this->price_ttc))
|
||||
$this->price_ttc = trim($this->price_ttc);
|
||||
if (isset($this->price_min))
|
||||
$this->price_min = trim($this->price_min);
|
||||
if (isset($this->price_min_ttc))
|
||||
$this->price_min_ttc = trim($this->price_min_ttc);
|
||||
if (isset($this->price_base_type))
|
||||
$this->price_base_type = trim($this->price_base_type);
|
||||
if (isset($this->tva_tx))
|
||||
$this->tva_tx = trim($this->tva_tx);
|
||||
if (isset($this->recuperableonly))
|
||||
$this->recuperableonly = trim($this->recuperableonly);
|
||||
if (isset($this->localtax1_tx))
|
||||
$this->localtax1_tx = trim($this->localtax1_tx);
|
||||
if (isset($this->localtax2_tx))
|
||||
$this->localtax2_tx = trim($this->localtax2_tx);
|
||||
if (isset($this->fk_user))
|
||||
$this->fk_user = trim($this->fk_user);
|
||||
if (isset($this->import_key))
|
||||
$this->import_key = trim($this->import_key);
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add a control on parameters values
|
||||
|
||||
if ($this->price != '' || $this->price == 0) {
|
||||
if ($this->price_base_type == 'TTC') {
|
||||
$this->price_ttc = price2num ( $this->price, 'MU' );
|
||||
$this->price = price2num ( $this->price ) / (1 + ($this->tva_tx / 100));
|
||||
$this->price = price2num ( $this->price, 'MU' );
|
||||
$this->price_ttc = price2num($this->price, 'MU');
|
||||
$this->price = price2num($this->price) / (1 + ($this->tva_tx / 100));
|
||||
$this->price = price2num($this->price, 'MU');
|
||||
|
||||
if ($this->price_min != '' || $this->price_min == 0) {
|
||||
$this->price_min_ttc = price2num ( $this->price_min, 'MU' );
|
||||
$this->price_min = price2num ( $this->price_min ) / (1 + ($this->tva_tx / 100));
|
||||
$this->price_min = price2num ( $this->price_min, 'MU' );
|
||||
$this->price_min_ttc = price2num($this->price_min, 'MU');
|
||||
$this->price_min = price2num($this->price_min) / (1 + ($this->tva_tx / 100));
|
||||
$this->price_min = price2num($this->price_min, 'MU');
|
||||
} else {
|
||||
$this->price_min = 0;
|
||||
$this->price_min_ttc = 0;
|
||||
}
|
||||
} else {
|
||||
$this->price = price2num ( $this->price, 'MU' );
|
||||
$this->price_ttc = ($this->recuperableonly != 1) ? price2num ( $this->price ) * (1 + ($this->tva_tx / 100)) : $this->price;
|
||||
$this->price_ttc = price2num ( $this->price_ttc, 'MU' );
|
||||
$this->price = price2num($this->price, 'MU');
|
||||
$this->price_ttc = ($this->recuperableonly != 1) ? price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price;
|
||||
$this->price_ttc = price2num($this->price_ttc, 'MU');
|
||||
|
||||
if ($this->price_min != '' || $this->price_min == 0) {
|
||||
$this->price_min = price2num ( $this->price_min, 'MU' );
|
||||
$this->price_min_ttc = price2num ( $this->price_min ) * (1 + ($this->tva_tx / 100));
|
||||
$this->price_min_ttc = price2num ( $this->price_min_ttc, 'MU' );
|
||||
$this->price_min = price2num($this->price_min, 'MU');
|
||||
$this->price_min_ttc = price2num($this->price_min) * (1 + ($this->tva_tx / 100));
|
||||
$this->price_min_ttc = price2num($this->price_min_ttc, 'MU');
|
||||
// print 'X'.$newminprice.'-'.$price_min;
|
||||
} else {
|
||||
$this->price_min = 0;
|
||||
@ -630,41 +624,41 @@ class Productcustomerprice extends CommonObject {
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t";
|
||||
$sql .= " WHERE t.rowid = " . $this->id;
|
||||
|
||||
$this->db->begin ();
|
||||
dol_syslog ( get_class ( $this ) . "::update sql=" . $sql, LOG_DEBUG );
|
||||
$resql = $this->db->query ( $sql );
|
||||
$this->db->begin();
|
||||
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) {
|
||||
$error ++;
|
||||
$this->errors [] = "Error " . $this->db->lasterror ();
|
||||
$this->errors [] = "Error " . $this->db->lasterror();
|
||||
}
|
||||
|
||||
// Update request
|
||||
$sql = "UPDATE " . MAIN_DB_PREFIX . "product_customer_price SET";
|
||||
|
||||
$sql .= " entity=" . $conf->entity . ",";
|
||||
$sql .= " datec='" . $this->db->idate ( dol_now () ) . "',";
|
||||
$sql .= " tms=" . (dol_strlen ( $this->tms ) != 0 ? "'" . $this->db->idate ( $this->tms ) . "'" : 'null') . ",";
|
||||
$sql .= " fk_product=" . (isset ( $this->fk_product ) ? $this->fk_product : "null") . ",";
|
||||
$sql .= " fk_soc=" . (isset ( $this->fk_soc ) ? $this->fk_soc : "null") . ",";
|
||||
$sql .= " price=" . (isset ( $this->price ) ? $this->price : "null") . ",";
|
||||
$sql .= " price_ttc=" . (isset ( $this->price_ttc ) ? $this->price_ttc : "null") . ",";
|
||||
$sql .= " price_min=" . (isset ( $this->price_min ) ? $this->price_min : "null") . ",";
|
||||
$sql .= " price_min_ttc=" . (isset ( $this->price_min_ttc ) ? $this->price_min_ttc : "null") . ",";
|
||||
$sql .= " price_base_type=" . (isset ( $this->price_base_type ) ? "'" . $this->db->escape ( $this->price_base_type ) . "'" : "null") . ",";
|
||||
$sql .= " tva_tx=" . (isset ( $this->tva_tx ) ? $this->tva_tx : "null") . ",";
|
||||
$sql .= " recuperableonly=" . (isset ( $this->recuperableonly ) ? $this->recuperableonly : "null") . ",";
|
||||
$sql .= " localtax1_tx=" . (isset ( $this->localtax1_tx ) ? $this->localtax1_tx : "null") . ",";
|
||||
$sql .= " localtax2_tx=" . (isset ( $this->localtax2_tx ) ? $this->localtax2_tx : "null") . ",";
|
||||
$sql .= " datec='" . $this->db->idate(dol_now()) . "',";
|
||||
$sql .= " tms=" . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : 'null') . ",";
|
||||
$sql .= " fk_product=" . (isset($this->fk_product) ? $this->fk_product : "null") . ",";
|
||||
$sql .= " fk_soc=" . (isset($this->fk_soc) ? $this->fk_soc : "null") . ",";
|
||||
$sql .= " price=" . (isset($this->price) ? $this->price : "null") . ",";
|
||||
$sql .= " price_ttc=" . (isset($this->price_ttc) ? $this->price_ttc : "null") . ",";
|
||||
$sql .= " price_min=" . (isset($this->price_min) ? $this->price_min : "null") . ",";
|
||||
$sql .= " price_min_ttc=" . (isset($this->price_min_ttc) ? $this->price_min_ttc : "null") . ",";
|
||||
$sql .= " price_base_type=" . (isset($this->price_base_type) ? "'" . $this->db->escape($this->price_base_type) . "'" : "null") . ",";
|
||||
$sql .= " tva_tx=" . (isset($this->tva_tx) ? $this->tva_tx : "null") . ",";
|
||||
$sql .= " recuperableonly=" . (isset($this->recuperableonly) ? $this->recuperableonly : "null") . ",";
|
||||
$sql .= " localtax1_tx=" . (isset($this->localtax1_tx) ? $this->localtax1_tx : "null") . ",";
|
||||
$sql .= " localtax2_tx=" . (isset($this->localtax2_tx) ? $this->localtax2_tx : "null") . ",";
|
||||
$sql .= " fk_user=" . $user->id . ",";
|
||||
$sql .= " import_key=" . (isset ( $this->import_key ) ? "'" . $this->db->escape ( $this->import_key ) . "'" : "null") . "";
|
||||
$sql .= " import_key=" . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . "";
|
||||
|
||||
$sql .= " WHERE rowid=" . $this->id;
|
||||
|
||||
dol_syslog ( get_class ( $this ) . "::update sql=" . $sql, LOG_DEBUG );
|
||||
$resql = $this->db->query ( $sql );
|
||||
dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) {
|
||||
$error ++;
|
||||
$this->errors [] = "Error " . $this->db->lasterror ();
|
||||
$this->errors [] = "Error " . $this->db->lasterror();
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
@ -682,7 +676,7 @@ class Productcustomerprice extends CommonObject {
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
$result = $this->setPriceOnAffiliateThirdparty ($user, $forceupdateaffiliate );
|
||||
$result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate);
|
||||
if ($result < 0) {
|
||||
$error ++;
|
||||
}
|
||||
@ -691,112 +685,106 @@ class Productcustomerprice extends CommonObject {
|
||||
// Commit or rollback
|
||||
if ($error) {
|
||||
foreach ( $this->errors as $errmsg ) {
|
||||
dol_syslog ( get_class ( $this ) . "::update " . $errmsg, LOG_ERR );
|
||||
dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR);
|
||||
$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
|
||||
}
|
||||
$this->db->rollback ();
|
||||
$this->db->rollback();
|
||||
return - 1 * $error;
|
||||
} else {
|
||||
$this->db->commit ();
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Force update price on child price
|
||||
*
|
||||
*
|
||||
* @param User $user that modifies
|
||||
* @param int $forceupdateaffiliate update price on each soc child
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function setPriceOnAffiliateThirdparty($user,$forceupdateaffiliate) {
|
||||
|
||||
$error=0;
|
||||
function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate) {
|
||||
|
||||
$error = 0;
|
||||
|
||||
// Find all susidiaries
|
||||
$sql = "SELECT s.rowid";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
|
||||
$sql .= " WHERE s.parent = " . $this->fk_soc;
|
||||
$sql .= " AND s.entity IN (" . getEntity ( 'societe', 1 ) . ")";
|
||||
$sql .= " AND s.entity IN (" . getEntity('societe', 1) . ")";
|
||||
|
||||
dol_syslog ( get_class ( $this ) . "::setPriceOnAffiliateThirdparty sql=" . $sql, LOG_DEBUG );
|
||||
$resql = $this->db->query ( $sql );
|
||||
dol_syslog(get_class($this) . "::setPriceOnAffiliateThirdparty sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
if ($resql) {
|
||||
|
||||
$this->lines = array ();
|
||||
$num = $this->db->num_rows ( $resql );
|
||||
$num = $this->db->num_rows($resql);
|
||||
|
||||
while ( ($obj = $this->db->fetch_object ( $resql )) && (empty($error))) {
|
||||
while ( ($obj = $this->db->fetch_object($resql)) && (empty($error)) ) {
|
||||
|
||||
//find if there is an existing line for the product and the subsidiaries
|
||||
$prodsocprice=new Productcustomerprice($this->db);
|
||||
// find if there is an existing line for the product and the subsidiaries
|
||||
$prodsocprice = new Productcustomerprice($this->db);
|
||||
|
||||
$filter = array (
|
||||
't.fk_product' => $this->fk_product,
|
||||
't.fk_soc'=> $obj->rowid
|
||||
);
|
||||
|
||||
$result=$prodsocprice->fetch_all ( '', '', 0, 0, $filter );
|
||||
't.fk_product' => $this->fk_product,'t.fk_soc' => $obj->rowid
|
||||
);
|
||||
|
||||
$result = $prodsocprice->fetch_all('', '', 0, 0, $filter);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$this->error=$prodsocprice->error;
|
||||
$error ++;
|
||||
$this->error = $prodsocprice->error;
|
||||
} else {
|
||||
|
||||
//There is one line
|
||||
if (count($prodsocprice->lines)>0) {
|
||||
//If force update => Update
|
||||
if (!empty($forceupdateaffiliate)) {
|
||||
// There is one line
|
||||
if (count($prodsocprice->lines) > 0) {
|
||||
// If force update => Update
|
||||
if (! empty($forceupdateaffiliate)) {
|
||||
|
||||
$prodsocpriceupd=new Productcustomerprice($this->db);
|
||||
$prodsocpriceupd->fetch($prodsocprice->lines[0]->id);
|
||||
$prodsocpriceupd = new Productcustomerprice($this->db);
|
||||
$prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
|
||||
|
||||
$prodsocpriceupd->price=$this->price;
|
||||
$prodsocpriceupd->price_min=$this->price_min;
|
||||
$prodsocpriceupd->price_base_type=$this->price_base_type;
|
||||
$prodsocpriceupd->tva_tx=$this->tva_tx;
|
||||
$prodsocpriceupd->recuperableonly=$this->recuperableonly;
|
||||
|
||||
$resultupd=$prodsocpriceupd->update($user,0,$forceupdateaffiliate);
|
||||
$prodsocpriceupd->price = $this->price;
|
||||
$prodsocpriceupd->price_min = $this->price_min;
|
||||
$prodsocpriceupd->price_base_type = $this->price_base_type;
|
||||
$prodsocpriceupd->tva_tx = $this->tva_tx;
|
||||
$prodsocpriceupd->recuperableonly = $this->recuperableonly;
|
||||
|
||||
$resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$this->error=$prodsocpriceupd->error;
|
||||
$error ++;
|
||||
$this->error = $prodsocpriceupd->error;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//If line do not exits then create it
|
||||
$prodsocpricenew=new Productcustomerprice($this->db);
|
||||
$prodsocpricenew->fk_soc=$obj->rowid;
|
||||
$prodsocpricenew->fk_product=$this->fk_product;
|
||||
$prodsocpricenew->price=$this->price;
|
||||
$prodsocpricenew->price_min=$this->price_min;
|
||||
$prodsocpricenew->price_base_type=$this->price_base_type;
|
||||
$prodsocpricenew->tva_tx=$this->tva_tx;
|
||||
$prodsocpricenew->recuperableonly=$this->recuperableonly;
|
||||
} else {
|
||||
// If line do not exits then create it
|
||||
$prodsocpricenew = new Productcustomerprice($this->db);
|
||||
$prodsocpricenew->fk_soc = $obj->rowid;
|
||||
$prodsocpricenew->fk_product = $this->fk_product;
|
||||
$prodsocpricenew->price = $this->price;
|
||||
$prodsocpricenew->price_min = $this->price_min;
|
||||
$prodsocpricenew->price_base_type = $this->price_base_type;
|
||||
$prodsocpricenew->tva_tx = $this->tva_tx;
|
||||
$prodsocpricenew->recuperableonly = $this->recuperableonly;
|
||||
|
||||
$resultupd=$prodsocpricenew->create($user,0,$forceupdateaffiliate);
|
||||
$resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$this->error=$prodsocpriceupd->error;
|
||||
$error ++;
|
||||
$this->error = $prodsocpriceupd->error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$this->db->free ( $resql );
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
if (empty($error)) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
return - 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->error = "Error " . $this->db->lasterror ();
|
||||
dol_syslog ( get_class ( $this ) . "::setPriceOnAffiliateThirdparty " . $this->error, LOG_ERR );
|
||||
$this->error = "Error " . $this->db->lasterror();
|
||||
dol_syslog(get_class($this) . "::setPriceOnAffiliateThirdparty " . $this->error, LOG_ERR);
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
@ -813,7 +801,7 @@ class Productcustomerprice extends CommonObject {
|
||||
global $conf, $langs;
|
||||
$error = 0;
|
||||
|
||||
$this->db->begin ();
|
||||
$this->db->begin();
|
||||
|
||||
if (! $error) {
|
||||
if (! $notrigger) {
|
||||
@ -833,24 +821,24 @@ class Productcustomerprice extends CommonObject {
|
||||
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_customer_price";
|
||||
$sql .= " WHERE rowid=" . $this->id;
|
||||
|
||||
dol_syslog ( get_class ( $this ) . "::delete sql=" . $sql );
|
||||
$resql = $this->db->query ( $sql );
|
||||
dol_syslog(get_class($this) . "::delete sql=" . $sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if (! $resql) {
|
||||
$error ++;
|
||||
$this->errors [] = "Error " . $this->db->lasterror ();
|
||||
$this->errors [] = "Error " . $this->db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
// Commit or rollback
|
||||
if ($error) {
|
||||
foreach ( $this->errors as $errmsg ) {
|
||||
dol_syslog ( get_class ( $this ) . "::delete " . $errmsg, LOG_ERR );
|
||||
dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
|
||||
$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
|
||||
}
|
||||
$this->db->rollback ();
|
||||
$this->db->rollback();
|
||||
return - 1 * $error;
|
||||
} else {
|
||||
$this->db->commit ();
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -867,12 +855,12 @@ class Productcustomerprice extends CommonObject {
|
||||
|
||||
$error = 0;
|
||||
|
||||
$object = new Productcustomerprice ( $this->db );
|
||||
$object = new Productcustomerprice($this->db);
|
||||
|
||||
$this->db->begin ();
|
||||
$this->db->begin();
|
||||
|
||||
// Load source object
|
||||
$object->fetch ( $fromid );
|
||||
$object->fetch($fromid);
|
||||
$object->id = 0;
|
||||
$object->statut = 0;
|
||||
|
||||
@ -880,7 +868,7 @@ class Productcustomerprice extends CommonObject {
|
||||
// ...
|
||||
|
||||
// Create clone
|
||||
$result = $object->create ( $user );
|
||||
$result = $object->create($user);
|
||||
|
||||
// Other options
|
||||
if ($result < 0) {
|
||||
@ -893,10 +881,10 @@ class Productcustomerprice extends CommonObject {
|
||||
|
||||
// End
|
||||
if (! $error) {
|
||||
$this->db->commit ();
|
||||
$this->db->commit();
|
||||
return $object->id;
|
||||
} else {
|
||||
$this->db->rollback ();
|
||||
$this->db->rollback();
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
@ -930,7 +918,11 @@ class Productcustomerprice extends CommonObject {
|
||||
}
|
||||
}
|
||||
|
||||
class PriceByCustomerLine {
|
||||
/**
|
||||
* File of class to manage predefined price products or services by customer lines
|
||||
*/
|
||||
class PriceByCustomerLine
|
||||
{
|
||||
var $id;
|
||||
var $entity;
|
||||
var $datec = '';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user