return comment

This commit is contained in:
Frédéric FRANCE 2018-08-14 12:23:10 +02:00
parent 7c6f41e04f
commit a0a6afc224
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
23 changed files with 286 additions and 243 deletions

View File

@ -218,9 +218,9 @@
<severity>5</severity>
</rule>
<rule ref="PEAR.Commenting.FunctionComment.MissingReturn">
<!--<rule ref="PEAR.Commenting.FunctionComment.MissingReturn">
<severity>0</severity>
</rule>
</rule>-->
<rule ref="PEAR.Commenting.FunctionComment.Missing">
<severity>0</severity>
</rule>

View File

@ -2454,6 +2454,7 @@ class Adherent extends CommonObject
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
* @return void
*/
public function setCategories($categories)
{

View File

@ -82,6 +82,7 @@ class PrestaShopWebservice
* Take the status code and throw an exception if the server didn't return 200 or 201 code
*
* @param int $status_code Status code of an HTTP return
* @return void
*/
protected function checkStatusCode($status_code)
{

View File

@ -217,6 +217,7 @@ class DolibarrApi
* @param string $feature2 Feature to check, second level of permission (optional). Can be or check with 'level1|level2'.
* @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional)
* @param string $dbt_select Field name for select if not rowid. Not used if objectid is null (optional)
* @return bool
* @throws RestException
*/
static function _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid') {

View File

@ -188,6 +188,7 @@ class Setup extends DolibarrApi
* @param int $id ID of country
* @param string $lang Code of the language the name of the
* country must be translated to
* @return array Array of cleaned object properties
*
* @url GET dictionary/countries/{id}
*
@ -293,6 +294,7 @@ class Setup extends DolibarrApi
* @param Ccountry $country Country
* @param string $lang Code of the language the name of the
* country must be translated to
* @return void
*/
private function translateLabel($country, $lang)
{

View File

@ -28,6 +28,7 @@ class Status
{
/**
* Get status (Dolibarr version)
* @return array
*/
function index() {
global $conf;

View File

@ -105,7 +105,8 @@ class BlockedLogAuthority
/**
* Add a new block to the chain
*
* @param string $block new block to chain
* @param string $block new block to chain
* @return void
*/
public function addBlock($block) {

View File

@ -18,9 +18,6 @@
* See https://medium.com/@lhartikk/a-blockchain-in-200-lines-of-code-963cc1cc0e54
*/
/*ini_set('unserialize_callback_func', 'mycallback');
function mycallback($classname)
@ -171,6 +168,7 @@ class BlockedLog
/**
* Try to retrieve source object (it it still exists)
* @return string
*/
public function getObjectLink()
{
@ -286,6 +284,7 @@ class BlockedLog
/**
* try to retrieve user author
* @return string
*/
public function getUser()
{
@ -1029,6 +1028,7 @@ class BlockedLog
* Check if module was already used or not for at least one recording.
*
* @param int $ignoresystem Ignore system events for the test
* @return bool
*/
function alreadyUsed($ignoresystem=0)
{
@ -1055,4 +1055,3 @@ class BlockedLog
}
}

View File

@ -1334,6 +1334,7 @@ class Contact extends CommonObject
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
* @return void
*/
public function setCategories($categories)
{

View File

@ -6810,6 +6810,7 @@ abstract class CommonObject
* Function to load data from a SQL pointer into properties of current object $this
*
* @param stdClass $obj Contain data of object from database
* @return void
*/
protected function setVarsFromFetchObj(&$obj)
{

View File

@ -1594,6 +1594,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
* @param string $langkey Translation key
* @param string $fieldkey Key of the html select field the text refers to
* @param int $fieldrequired 1=Field is mandatory
* @return string
* @deprecated Form::editfieldkey
*/
function fieldLabel($langkey, $fieldkey, $fieldrequired=0)
@ -7431,6 +7432,7 @@ function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param=''
*
* @param string $htmlname Id of html object
* @param string $addlink Add a 'link to' after
* @return string
*/
function ajax_autoselect($htmlname, $addlink='')
{
@ -7568,6 +7570,7 @@ function dol_mimetype($file, $default='application/octet-stream', $mode=0)
* @param int $id id of line
* @param bool $checkentity add filter on entity
* @param string $rowidfield name of the column rowid
* @return string
*/
function getDictvalue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
{

View File

@ -21,12 +21,12 @@
* \brief A set of functions for Dolibarr
* This file contains all frequently used functions.
*/
/**
* Function to return number in text.
*
*
*
*
* @param float $num Number to convert
* @param Lang $langs Language
* @param boolean $currency 0=number to translate | 1=currency to translate
@ -36,7 +36,7 @@
function dol_convertToWord($num, $langs, $currency=false, $centimes=false)
{
global $conf;
$num = str_replace(array(',', ' '), '', trim($num));
if(! $num) {
return false;
@ -48,49 +48,49 @@ function dol_convertToWord($num, $langs, $currency=false, $centimes=false)
$num = (int) $TNum[0];
$words = array();
$list1 = array(
'',
$langs->transnoentitiesnoconv('one'),
$langs->transnoentitiesnoconv('two'),
$langs->transnoentitiesnoconv('three'),
$langs->transnoentitiesnoconv('four'),
$langs->transnoentitiesnoconv('five'),
$langs->transnoentitiesnoconv('six'),
$langs->transnoentitiesnoconv('seven'),
$langs->transnoentitiesnoconv('eight'),
$langs->transnoentitiesnoconv('nine'),
$langs->transnoentitiesnoconv('ten'),
'',
$langs->transnoentitiesnoconv('one'),
$langs->transnoentitiesnoconv('two'),
$langs->transnoentitiesnoconv('three'),
$langs->transnoentitiesnoconv('four'),
$langs->transnoentitiesnoconv('five'),
$langs->transnoentitiesnoconv('six'),
$langs->transnoentitiesnoconv('seven'),
$langs->transnoentitiesnoconv('eight'),
$langs->transnoentitiesnoconv('nine'),
$langs->transnoentitiesnoconv('ten'),
$langs->transnoentitiesnoconv('eleven'),
$langs->transnoentitiesnoconv('twelve'),
$langs->transnoentitiesnoconv('thirteen'),
$langs->transnoentitiesnoconv('fourteen'),
$langs->transnoentitiesnoconv('fifteen'),
$langs->transnoentitiesnoconv('sixteen'),
$langs->transnoentitiesnoconv('seventeen'),
$langs->transnoentitiesnoconv('eighteen'),
$langs->transnoentitiesnoconv('twelve'),
$langs->transnoentitiesnoconv('thirteen'),
$langs->transnoentitiesnoconv('fourteen'),
$langs->transnoentitiesnoconv('fifteen'),
$langs->transnoentitiesnoconv('sixteen'),
$langs->transnoentitiesnoconv('seventeen'),
$langs->transnoentitiesnoconv('eighteen'),
$langs->transnoentitiesnoconv('nineteen')
);
$list2 = array(
'',
$langs->transnoentitiesnoconv('ten'),
$langs->transnoentitiesnoconv('twenty'),
$langs->transnoentitiesnoconv('thirty'),
$langs->transnoentitiesnoconv('forty'),
$langs->transnoentitiesnoconv('fifty'),
$langs->transnoentitiesnoconv('sixty'),
$langs->transnoentitiesnoconv('seventy'),
$langs->transnoentitiesnoconv('eighty'),
$langs->transnoentitiesnoconv('ninety'),
'',
$langs->transnoentitiesnoconv('ten'),
$langs->transnoentitiesnoconv('twenty'),
$langs->transnoentitiesnoconv('thirty'),
$langs->transnoentitiesnoconv('forty'),
$langs->transnoentitiesnoconv('fifty'),
$langs->transnoentitiesnoconv('sixty'),
$langs->transnoentitiesnoconv('seventy'),
$langs->transnoentitiesnoconv('eighty'),
$langs->transnoentitiesnoconv('ninety'),
$langs->transnoentitiesnoconv('hundred')
);
$list3 = array(
'',
$langs->transnoentitiesnoconv('thousand'),
$langs->transnoentitiesnoconv('million'),
$langs->transnoentitiesnoconv('billion'),
$langs->transnoentitiesnoconv('trillion'),
'',
$langs->transnoentitiesnoconv('thousand'),
$langs->transnoentitiesnoconv('million'),
$langs->transnoentitiesnoconv('billion'),
$langs->transnoentitiesnoconv('trillion'),
$langs->transnoentitiesnoconv('quadrillion')
);
$num_length = strlen($num);
$levels = (int) (($num_length + 2) / 3);
$max_length = $levels * 3;
@ -120,11 +120,11 @@ function dol_convertToWord($num, $langs, $currency=false, $centimes=false)
$concatWords = implode(' ', $words);
// Delete multi whitespaces
$concatWords = trim(preg_replace('/[ ]+/', ' ', $concatWords));
if(!empty($currency)) {
$concatWords .= ' '.$currency;
}
// If we need to write cents call again this function for cents
if(!empty($TNum[1])) {
if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and');
@ -133,11 +133,11 @@ function dol_convertToWord($num, $langs, $currency=false, $centimes=false)
}
return $concatWords;
}
/**
* Function to return number or amount in text.
*
*
* @deprecated
* @param float $numero Number to convert
* @param Lang $langs Language
@ -164,7 +164,7 @@ function dolNumberToWord($numero, $langs, $numorcurrency='number')
/*In dolibarr 3.6.2 (my current version) doesn't have $langs->default and
in case exist why ask $lang like a parameter?*/
if (((is_object($langs) && $langs->default == 'es_MX') || (! is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency')
{
{
if ($numero>=1 && $numero<2) {
return ("UN PESO ".$parte_decimal." / 100 M.N.");
}
@ -229,10 +229,11 @@ function dolNumberToWord($numero, $langs, $numorcurrency='number')
/**
* hundreds2text
*
*
* @param integer $hundreds Hundreds
* @param integer $tens Tens
* @param integer $units Units
* @return string
*/
function hundreds2text($hundreds, $tens, $units)
{

View File

@ -263,6 +263,7 @@ function pdf_getHeightForLogo($logo, $url = false)
*
* @param TCPDF $pdf PDF initialized object
* @param string $htmlcontent HTML Contect
* @return number
* @see getStringHeight
*/
function pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
@ -2120,4 +2121,3 @@ function pdf_getSizeForImage($realpath)
}
return array('width'=>$width,'height'=>$height);
}

View File

@ -50,7 +50,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
'fontsize' => 8,
'stretchtext' => 4
);
// set style for 2d barcode
private $_style2d = array(
'border' => false,
@ -61,24 +61,25 @@ class pdf_tcpdflabel extends CommonStickerGenerator
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
private $_align2d = 'N';
private $_xres = 0.4;
/**
* write barcode to pdf
*
*
* @param PDF $pdf PDF reference
* @param string $code code to print
* @param string $encoding type of barcode
* @param boolean $is2d true if 2d barcode
* @param int $x x position in user units
* @param int $x x position in user units
* @param int $y y position in user units
* @param int $w width in user units
* @param int $h height in user units
*/
private function writeBarcode(&$pdf, $code, $encoding, $is2d, $x, $y, $w, $h)
* @return void
*/
private function writeBarcode(&$pdf, $code, $encoding, $is2d, $x, $y, $w, $h)
{
if ($is2d) {
$pdf->write2DBarcode($code, $encoding, $x, $y, $w, $h, $this->_style2d, $this->_align2d);
@ -86,7 +87,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
$pdf->write1DBarcode($code, $encoding, $x, $y, $w, $h, $this->_xres, $this->_style1d);
}
}
/**
* Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
*
@ -95,10 +96,10 @@ class pdf_tcpdflabel extends CommonStickerGenerator
* @param array $param Associative array containing label content and optional parameters
* @return void
*/
function addSticker(&$pdf,$outputlangs,$param)
function addSticker(&$pdf,$outputlangs,$param)
{
global $mysoc,$conf;
$textleft = $param['textleft'];
$header = $param['textheader'];
$footer = $param['textfooter'];
@ -106,8 +107,8 @@ class pdf_tcpdflabel extends CommonStickerGenerator
$code = $param['code'];
$encoding = $param['encoding'];
$is2d = $param['is2d'];
// We are in a new page, then we must add a page
if (($this->_COUNTX ==0) && ($this->_COUNTY==0) and (!$this->_First==1)) {
@ -132,7 +133,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
}
}
$xleft = 2;
$xleft = 2;
$ytop = 2;
// Top
@ -154,7 +155,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
$heighttouse = $maxheighttouse;
$logoHeight = $heighttouse;
$logoWidth = $heighttouse;
//var_dump($this->_Width.'x'.$this->_Height.' with border and scale '.$imgscale.' => max '.$maxwidthtouse.'x'.$maxheighttouse.' => We use '.$widthtouse.'x'.$heighttouse);exit;
// Center
@ -162,7 +163,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
{
// Output left area
if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, 0, $logoHeight);
else if ($code && !empty($encoding))
else if ($code && !empty($encoding))
{
$this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse, $heighttouse);
}
@ -177,7 +178,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
if (($textleft == '%LOGO%' || $textleft == '%PHOTO%' || $textleft == '%BARCODE%') && !strstr($textright, '%') ) // left part logo/barcode right part text
{
if ($textleft == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$xleft, $_PosY+$ytop, $widthtouse/2, 0);
else if ($code && !empty($encoding))
else if ($code && !empty($encoding))
{
$this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$xleft, $_PosY+$ytop, $widthtouse/2, $heighttouse);
}
@ -187,7 +188,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
else if (($textright == '%LOGO%' || $textright == '%PHOTO%' || $textright == '%BARCODE%') && !strstr($textleft, '%')) // right part logo/barcode left part text
{
if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+($widthtouse/2), $_PosY+$ytop, $widthtouse/2, 0);
else if ($code && !empty($encoding))
else if ($code && !empty($encoding))
{
$this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+($widthtouse/2), $_PosY+$ytop, $widthtouse/2, $heighttouse);
}
@ -203,7 +204,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
} else {
$pdf->SetXY($_PosX+$xleft+$logoWidth+1, $_PosY+$ytop);
$pdf->MultiCell($widthtouse-$logoWidth1-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright),0,'R');
}
}
}
else if ($textright == '%LOGO%') // right part logo left part text/barcode
{
@ -214,7 +215,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
} else {
$pdf->SetXY($_PosX+$xleft, $_PosY+$ytop);
$pdf->MultiCell($widthtouse-$logoWidth-1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft),0,'L');
}
}
}
else // text on halft left and text on half right
{
@ -228,7 +229,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
{
// Output right area
if ($textright == '%LOGO%' && $logo) $pdf->Image($logo, $_PosX+$this->_Width-$widthtouse-$xleft, $_PosY+$ytop, 0, $logoHeight);
else if ($code && !empty($encoding))
else if ($code && !empty($encoding))
{
$this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX+$this->_Width-$widthtouse-$xleft, $_PosY+$ytop, $widthtouse, $heighttouse);
}
@ -295,7 +296,7 @@ class pdf_tcpdflabel extends CommonStickerGenerator
if (! is_object($outputlangs)) $outputlangs=$langs;
// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
// Load traductions files requiredby by page
$outputlangs->loadLangs(array("main", "dict", "companies", "admin"));

View File

@ -1297,6 +1297,7 @@ class ExpenseReport extends CommonObject
* @param User $fuser User
* @param Details $details Details
* @param int $notrigger Disable triggers
* @return int
*/
function setDeny($fuser,$details,$notrigger=0)
{

View File

@ -99,6 +99,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
/**
* Global test setup
* @return void
*/
public static function setUpBeforeClass()
{
@ -106,6 +107,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
/**
* Unit test setup
* @return void
*/
public function setUp()
{
@ -115,6 +117,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
/**
* Verify pre conditions
* @return void
*/
protected function assertPreConditions()
{
@ -122,6 +125,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
/**
* Handle Dolibarr authentication
* @return void
*/
private function authenticate()
{
@ -142,6 +146,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
/**
* Test enabling developer mode
* @return bool
*/
public function testEnableDeveloperMode()
{
@ -161,6 +166,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
* Test enabling the module
*
* @depends testEnableDeveloperMode
* @return bool
*/
public function testModuleEnabled()
{
@ -186,6 +192,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
* Test access to the configuration page
*
* @depends testModuleEnabled
* @return bool
*/
public function testConfigurationPage()
{
@ -198,6 +205,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
* Test access to the about page
*
* @depends testConfigurationPage
* @return bool
*/
public function testAboutPage()
{
@ -210,6 +218,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
* Test about page is rendering Markdown
*
* @depends testAboutPage
* @return bool
*/
public function testAboutPageRendersMarkdownReadme()
{
@ -226,6 +235,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
* Test box is properly declared
*
* @depends testModuleEnabled
* @return bool
*/
public function testBoxDeclared()
{
@ -238,6 +248,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
* Test trigger is properly enabled
*
* @depends testModuleEnabled
* @return bool
*/
public function testTriggerDeclared()
{
@ -254,6 +265,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
* Test trigger is properly declared
*
* @depends testTriggerDeclared
* @return bool
*/
public function testTriggerEnabled()
{
@ -268,6 +280,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
/**
* Verify post conditions
* @return void
*/
protected function assertPostConditions()
{
@ -275,6 +288,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
/**
* Unit test teardown
* @return void
*/
public function tearDown()
{
@ -282,6 +296,7 @@ class MyModuleFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
/**
* Global test teardown
* @return void
*/
public static function tearDownAfterClass()
{

View File

@ -32,6 +32,7 @@ class MyObjectTest extends \PHPUnit_Framework_TestCase
{
/**
* Global test setup
* @return void
*/
public static function setUpBeforeClass()
{
@ -40,6 +41,7 @@ class MyObjectTest extends \PHPUnit_Framework_TestCase
/**
* Unit test setup
* @return void
*/
protected function setUp()
{
@ -48,6 +50,7 @@ class MyObjectTest extends \PHPUnit_Framework_TestCase
/**
* Verify pre conditions
* @return void
*/
protected function assertPreConditions()
{
@ -56,6 +59,7 @@ class MyObjectTest extends \PHPUnit_Framework_TestCase
/**
* A sample test
* @return bool
*/
public function testSomething()
{
@ -66,6 +70,7 @@ class MyObjectTest extends \PHPUnit_Framework_TestCase
/**
* Verify post conditions
* @return void
*/
protected function assertPostConditions()
{
@ -74,6 +79,7 @@ class MyObjectTest extends \PHPUnit_Framework_TestCase
/**
* Unit test teardown
* @return void
*/
protected function tearDown()
{
@ -82,6 +88,7 @@ class MyObjectTest extends \PHPUnit_Framework_TestCase
/**
* Global test teardown
* @return void
*/
public static function tearDownAfterClass()
{
@ -92,6 +99,7 @@ class MyObjectTest extends \PHPUnit_Framework_TestCase
* Unsuccessful test
*
* @param Exception $e Exception
* @return void
* @throws Exception
*/
protected function onNotSuccessfulTest(Exception $e)

View File

@ -93,7 +93,7 @@ class MultiCurrency extends CommonObject
public function __construct(DoliDB $db)
{
$this->db = &$db;
return 1;
}
@ -108,21 +108,21 @@ class MultiCurrency extends CommonObject
public function create(User $user, $trigger = true)
{
global $conf,$langs;
dol_syslog('Currency::create', LOG_DEBUG);
$error = 0;
if (self::checkCodeAlreadyExists($this->code))
{
$error++;
$this->errors[] = $langs->trans('multicurrency_code_already_added');
return -1;
}
if (empty($this->entity) || $this->entity <= 0) $this->entity = $conf->entity;
$now=date('Y-m-d H:i:s');
// Insert request
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
$sql .= ' code,';
@ -152,7 +152,7 @@ class MultiCurrency extends CommonObject
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
$this->date_create = $now;
$this->fk_user = $user->id;
if ($trigger) {
$result=$this->call_trigger('CURRENCY_CREATE', $user);
if ($result < 0) $error++;
@ -181,7 +181,7 @@ class MultiCurrency extends CommonObject
public function fetch($id, $code = null)
{
dol_syslog('Currency::fetch', LOG_DEBUG);
global $conf;
$sql = 'SELECT';
@ -192,7 +192,7 @@ class MultiCurrency extends CommonObject
dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$numrows = $this->db->num_rows($resql);
if ($numrows) {
@ -204,7 +204,7 @@ class MultiCurrency extends CommonObject
$this->entity = $obj->entity;
$this->date_create = $obj->date_create;
$this->fk_user = $obj->fk_user;
$this->fetchAllCurrencyRate();
$this->getRate();
}
@ -234,7 +234,7 @@ class MultiCurrency extends CommonObject
$sql.= ' FROM ' . MAIN_DB_PREFIX . $this->table_element_line. ' as cr';
$sql.= ' WHERE cr.fk_multicurrency = '.$this->id;
$sql.= ' ORDER BY cr.date_sync DESC';
$this->rates = array();
dol_syslog(__METHOD__,LOG_DEBUG);
@ -245,7 +245,7 @@ class MultiCurrency extends CommonObject
while ($obj = $this->db->fetch_object($resql)) {
$rate = new CurrencyRate($this->db);
$rate->fetch($obj->rowid);
$this->rates[] = $rate;
}
$this->db->free($resql);
@ -272,19 +272,19 @@ class MultiCurrency extends CommonObject
$error = 0;
dol_syslog('Currency::update', LOG_DEBUG);
// Clean parameters
$this->name = trim($this->name);
$this->code = trim($this->code);
// Check parameters
if (empty($this->code)) {
$error++;
dol_syslog('Currency::update $this->code can not be empty', LOG_ERR);
return -1;
}
// Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
$sql .= ' name=\''.$this->db->escape($this->name).'\'';
@ -328,7 +328,7 @@ class MultiCurrency extends CommonObject
public function delete($trigger = true)
{
global $user;
dol_syslog('Currency::delete', LOG_DEBUG);
$error = 0;
@ -347,7 +347,7 @@ class MultiCurrency extends CommonObject
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog('Currency::delete ' . join(',', $this->errors), LOG_ERR);
}
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
$sql .= ' WHERE rowid=' . $this->id;
@ -371,7 +371,7 @@ class MultiCurrency extends CommonObject
return 1;
}
}
/**
* Delete rates in database
*
@ -386,137 +386,137 @@ class MultiCurrency extends CommonObject
return false;
}
}
return true;
}
/**
* Delete rate in database
*
* Delete rate in database
*
* @param double $rate rate value
*
*
* @return int -1 if KO, 1 if OK
*/
public function addRate($rate)
{
public function addRate($rate)
{
$currencyRate = new CurrencyRate($this->db);
$currencyRate->rate = $rate;
if ($currencyRate->create($this->id) > 0)
if ($currencyRate->create($this->id) > 0)
{
$this->rate = $currencyRate;
return 1;
}
else
else
{
$this->rate = null;
return -1;
}
}
/**
* Try get label of code in llx_currency then add rate
*
* @param string $code currency code
* @param double $rate new rate
*
* @return int -1 if KO, 1 if OK, 2 if label found and OK
*/
}
/**
* Try get label of code in llx_currency then add rate
*
* @param string $code currency code
* @param double $rate new rate
*
* @return int -1 if KO, 1 if OK, 2 if label found and OK
*/
function addRateFromDolibarr($code, $rate)
{
global $db, $user;
$currency = new MultiCurrency($db);
$currency->code = $code;
$currency->name = $code;
$sql = 'SELECT label FROM '.MAIN_DB_PREFIX.'c_currencies WHERE code_iso = \''.$db->escape($code).'\'';
dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql && ($line = $db->fetch_object($resql)))
{
$currency->name = $line->label;
}
if ($currency->create($user) > 0)
{
$currency->addRate($rate);
if (!empty($line)) return 2;
else return 1;
}
return -1;
return -1;
}
/**
/**
* Add new entry into llx_multicurrency_rate to historise
*
*
* @param double $rate rate value
*
*
* @return int <0 if KO, >0 if OK
*/
public function updateRate($rate)
{
public function updateRate($rate)
{
return $this->addRate($rate);
}
}
/**
* Fetch CurrencyRate object in $this->rate
*
* Fetch CurrencyRate object in $this->rate
*
* @return int <0 if KO, 0 if not found, >0 if OK
*/
public function getRate()
{
public function getRate()
{
$sql = 'SELECT cr.rowid';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as cr';
$sql.= ' WHERE cr.fk_multicurrency = '.$this->id;
$sql.= ' AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM '.MAIN_DB_PREFIX.$this->table_element_line.' AS cr2 WHERE cr2.fk_multicurrency = '.$this->id.')';
dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql && ($obj = $this->db->fetch_object($resql))) {
$this->rate = new CurrencyRate($this->db);
return $this->rate->fetch($obj->rowid);
}
}
/**
* Get id of currency from code
}
/**
* Get id of currency from code
*
* @param DoliDB $db object db
* @param string $code code value search
*
*
* @return 0 if not found, >0 if OK
*/
public static function getIdFromCode(&$db, $code)
{
public static function getIdFromCode(&$db, $code)
{
global $conf;
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE code = \''.$db->escape($code).'\' AND entity = '.$conf->entity;
dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql && $obj = $db->fetch_object($resql)) return $obj->rowid;
else return 0;
}
/**
* Get id and rate of currency from code
*
}
/**
* Get id and rate of currency from code
*
* @param DoliDB $db object db
* @param string $code code value search
* @param date $date_document date from document (propal, order, invoice, ...)
*
*
* @return array [0] => id currency
* [1] => rate
*/
public static function getIdAndTxFromCode(&$db, $code, $date_document='')
{
public static function getIdAndTxFromCode(&$db, $code, $date_document='')
{
global $conf;
$sql1 = 'SELECT m.rowid, mc.rate FROM '.MAIN_DB_PREFIX.'multicurrency m';
$sql1.= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)';
$sql1.= ' WHERE m.code = \''.$db->escape($code).'\'';
@ -524,10 +524,10 @@ class MultiCurrency extends CommonObject
$sql2= '';
if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE) && !empty($date_document)) $sql2.= ' AND DATE_FORMAT(mc.date_sync, "%Y-%m-%d") = "'.date('Y-m-d', $date_document).'"';
$sql3.= ' ORDER BY mc.date_sync DESC LIMIT 1';
dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql1.$sql2.$sql3);
if ($resql && $obj = $db->fetch_object($resql)) return array($obj->rowid, $obj->rate);
else
{
@ -536,67 +536,68 @@ class MultiCurrency extends CommonObject
$resql = $db->query($sql1.$sql3);
if ($resql && $obj = $db->fetch_object($resql)) return array($obj->rowid, $obj->rate);
}
return array(0, 1);
}
}
/**
* Get the conversion of amount with invoice rate
*
* @param int $fk_facture id of facture
* @param double $amount amount to convert
* @param string $way dolibarr mean the amount is in dolibarr currency
* @param string $table facture or facture_fourn
*
* @return double amount converted
*/
public static function getAmountConversionFromInvoiceRate($fk_facture, $amount, $way='dolibarr', $table='facture')
{
global $db;
$multicurrency_tx = self::getInvoiceRate($fk_facture, $table);
if ($multicurrency_tx)
{
}
/**
* Get the conversion of amount with invoice rate
*
* @param int $fk_facture id of facture
* @param double $amount amount to convert
* @param string $way dolibarr mean the amount is in dolibarr currency
* @param string $table facture or facture_fourn
*
* @return double amount converted
*/
public static function getAmountConversionFromInvoiceRate($fk_facture, $amount, $way='dolibarr', $table='facture')
{
global $db;
$multicurrency_tx = self::getInvoiceRate($fk_facture, $table);
if ($multicurrency_tx)
{
if ($way == 'dolibarr') return $amount * $multicurrency_tx;
else return $amount / $multicurrency_tx;
}
else return $amount;
}
/**
* Get current invoite rate
*
* @param int $fk_facture id of facture
* @param string $table facture or facture_fourn
*/
public static function getInvoiceRate($fk_facture, $table='facture')
{
global $db;
$sql = 'SELECT multicurrency_tx FROM '.MAIN_DB_PREFIX.$table.' WHERE rowid = '.$fk_facture;
dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql && ($line = $db->fetch_object($resql)))
{
}
else return $amount;
}
/**
* Get current invoite rate
*
* @param int $fk_facture id of facture
* @param string $table facture or facture_fourn
* @return bool
*/
public static function getInvoiceRate($fk_facture, $table='facture')
{
global $db;
$sql = 'SELECT multicurrency_tx FROM '.MAIN_DB_PREFIX.$table.' WHERE rowid = '.$fk_facture;
dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql && ($line = $db->fetch_object($resql)))
{
return $line->multicurrency_tx;
}
return false;
}
}
return false;
}
/**
* With free account we can't set source then recalcul all rates to force another source
*
* @param stdClass $TRate Object containing all currencies rates
*
* @param stdClass $TRate Object containing all currencies rates
* @return -1 if KO, 0 if nothing, 1 if OK
*/
public static function recalculRates(&$TRate)
{
global $conf;
if (!empty($conf->global->MULTICURRENCY_ALTERNATE_SOURCE))
{
$alternate_source = 'USD'.$conf->global->MULTICURRENCY_ALTERNATE_SOURCE;
@ -607,38 +608,39 @@ class MultiCurrency extends CommonObject
{
$rate *= $coef;
}
return 1;
}
return -1; // Alternate souce not found
}
return 0; // Nothing to do
}
/**
* Sync rates from api
*
*
* @param array $response array of reponse from api to sync dolibarr rates
* @return void
*/
public static function syncRates($response)
{
global $db,$conf;
$ch = curl_init('http://apilayer.net/api/live?access_key='.$key.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response);
if ($response->success)
{
$ch = curl_init('http://apilayer.net/api/live?access_key='.$key.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response);
if ($response->success)
{
$TRate = $response->quotes;
$timestamp = $response->timestamp;
if (self::recalculRates($TRate) >= 0)
if (self::recalculRates($TRate) >= 0)
{
foreach ($TRate as $currency_code => $rate)
{
@ -648,11 +650,11 @@ class MultiCurrency extends CommonObject
{
$obj->updateRate($rate);
}
else
else
{
self::addRateFromDolibarr($code, $rate);
}
}
}
}
}
else
@ -660,21 +662,21 @@ class MultiCurrency extends CommonObject
setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors');
}
}
/**
* Check in database if the current code already exists
*
*
* @param string $code current code to search
* @return boolean True if exists, false if not exists
*/
public static function checkCodeAlreadyExists($code)
{
public static function checkCodeAlreadyExists($code)
{
global $db;
$currency = new MultiCurrency($db);
if ($currency->fetch('', $code) > 0) return true;
else return false;
}
}
}
/**
@ -710,7 +712,7 @@ class CurrencyRate extends CommonObjectLine
* @var int Id of entity
*/
public $entity;
/**
* Constructor
*
@ -719,10 +721,10 @@ class CurrencyRate extends CommonObjectLine
public function __construct(DoliDB $db)
{
$this->db = &$db;
return 1;
}
/**
* Create object into database
*
@ -734,14 +736,14 @@ class CurrencyRate extends CommonObjectLine
public function create($fk_multicurrency, $trigger = true)
{
global $conf, $user;
dol_syslog('CurrencyRate::create', LOG_DEBUG);
$error = 0;
$this->rate = price2num($this->rate);
if (empty($this->entity) || $this->entity <= 0) $this->entity = $conf->entity;
$now=date('Y-m-d H:i:s');
// Insert request
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
$sql .= ' rate,';
@ -769,7 +771,7 @@ class CurrencyRate extends CommonObjectLine
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
$this->fk_multicurrency = $fk_multicurrency;
$this->date_sync = $now;
if ($trigger) {
$result=$this->call_trigger('CURRENCYRATE_CREATE', $user);
if ($result < 0) $error++;
@ -829,7 +831,7 @@ class CurrencyRate extends CommonObjectLine
return - 1;
}
}
/**
* Update object into database
*
@ -840,13 +842,13 @@ class CurrencyRate extends CommonObjectLine
public function update($trigger = true)
{
global $user;
$error = 0;
dol_syslog('CurrencyRate::update', LOG_DEBUG);
$this->rate = price2num($this->rate);
// Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
$sql .= ' rate='.$this->rate;
@ -878,7 +880,7 @@ class CurrencyRate extends CommonObjectLine
return 1;
}
}
/**
* Delete object in database
*
@ -889,7 +891,7 @@ class CurrencyRate extends CommonObjectLine
public function delete($trigger = true)
{
global $user;
dol_syslog('CurrencyRate::delete', LOG_DEBUG);
$error = 0;
@ -925,5 +927,5 @@ class CurrencyRate extends CommonObjectLine
return 1;
}
}
}

View File

@ -4504,6 +4504,7 @@ class Product extends CommonObject
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
* @return void
*/
public function setCategories($categories) {
// Handle single category

View File

@ -1904,6 +1904,7 @@ class Project extends CommonObject
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
* @return void
*/
public function setCategories($categories)
{
@ -1972,4 +1973,3 @@ class Project extends CommonObject
}
}

View File

@ -63,6 +63,7 @@ class ActionsStripeconnect
* @param array $parameters Parameters
* @param Object $object Object
* @param string $action Action
* @return bool
*/
function formObjectOptions($parameters, &$object, &$action)
{

View File

@ -910,6 +910,7 @@ class User extends CommonObject
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
* @return void
*/
public function setCategories($categories)
{
@ -2304,13 +2305,13 @@ class User extends CommonObject
//Check user's rights to see an other user
if((!$user->rights->user->user->lire && $this->id !=$user->id)) $option='nolink';
if ($option == 'xxx')
{
$linkstart = '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$this->id.'">';
$linkend='</a>';
}
if ($option == 'nolink')
{
$linkstart = '';
@ -3147,4 +3148,3 @@ class User extends CommonObject
}
}

View File

@ -94,6 +94,7 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase
/**
* Init phpunit tests.
* @return void
*/
protected function setUp()
{
@ -125,6 +126,7 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase
/**
* End phpunit tests.
* @return void
*/
protected function tearDown()
{