Merge pull request #7569 from Dolibarr/scrutinizer-patch-3

Scrutinizer Auto-Fixes
This commit is contained in:
Laurent Destailleur 2017-10-06 12:41:52 +02:00 committed by GitHub
commit 304828c37f
4 changed files with 1544 additions and 1544 deletions

View File

@ -100,9 +100,9 @@ $sql .= " WHERE f.fk_statut > 0"; // TODO Facture annulée ?
$sql .= " AND fd.fk_code_ventilation > 0"; $sql .= " AND fd.fk_code_ventilation > 0";
$sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy $sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_SITUATION . ")"; $sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_SITUATION . ")";
} else { } else {
$sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_DEPOSIT . "," . FactureFournisseur::TYPE_SITUATION . ")"; $sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_DEPOSIT . "," . FactureFournisseur::TYPE_SITUATION . ")";
} }
if ($date_start && $date_end) if ($date_start && $date_end)
$sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'"; $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
@ -277,7 +277,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->doc_type = 'supplier_invoice'; $bookkeeping->doc_type = 'supplier_invoice';
$bookkeeping->fk_doc = $key; $bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
$bookkeeping->thirdparty_code = $companystatic->code_fournisseur; $bookkeeping->thirdparty_code = $companystatic->code_fournisseur;
$bookkeeping->subledger_account = ''; $bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = ''; $bookkeeping->subledger_label = '';
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;

View File

@ -295,7 +295,7 @@ if ($action == 'writebookkeeping') {
$bookkeeping->doc_type = 'customer_invoice'; $bookkeeping->doc_type = 'customer_invoice';
$bookkeeping->fk_doc = $key; $bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add
$bookkeeping->thirdparty_code = $companystatic->code_client; $bookkeeping->thirdparty_code = $companystatic->code_client;
$bookkeeping->subledger_account = ''; $bookkeeping->subledger_account = '';
$bookkeeping->subledger_label = ''; $bookkeeping->subledger_label = '';
$bookkeeping->numero_compte = $k; $bookkeeping->numero_compte = $k;
@ -550,12 +550,12 @@ if (empty($action) || $action == 'view') {
// Button to write into Ledger // Button to write into Ledger
if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>'); print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>');
} }
print '<div class="tabsAction tabsActionNoBottom">'; print '<div class="tabsAction tabsActionNoBottom">';
if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
print '<input type="button" class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="' . $langs->trans("WriteBookKeeping") . '" />'; print '<input type="button" class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="' . $langs->trans("WriteBookKeeping") . '" />';
} }
else { else {
print '<input type="button" class="butAction" name="writebookkeeping" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />'; print '<input type="button" class="butAction" name="writebookkeeping" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';

View File

@ -33,49 +33,49 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
class Documents extends DolibarrApi class Documents extends DolibarrApi
{ {
/** /**
* @var array $DOCUMENT_FIELDS Mandatory fields, checked when create and update object * @var array $DOCUMENT_FIELDS Mandatory fields, checked when create and update object
*/ */
static $DOCUMENT_FIELDS = array( static $DOCUMENT_FIELDS = array(
'modulepart' 'modulepart'
); );
/** /**
* Constructor * Constructor
*/ */
function __construct() function __construct()
{ {
global $db; global $db;
$this->db = $db; $this->db = $db;
} }
/** /**
* Returns a document. Note that, this API is similar to using the wrapper link "documents.php" to download * Returns a document. Note that, this API is similar to using the wrapper link "documents.php" to download
* a file (used for internal HTML links of documents into application), but with no need to be into a logged session (no need to post the session cookie). * a file (used for internal HTML links of documents into application), but with no need to be into a logged session (no need to post the session cookie).
* *
* @param string $module_part Name of module or area concerned by file download ('facture', ...) * @param string $module_part Name of module or area concerned by file download ('facture', ...)
* @param string $original_file Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf) * @param string $original_file Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf)
* @param int $regeneratedoc If requested document is the main document of an object, setting this to 1 ask API to regenerate document before returning it (supported for some module_part only). It is no effect in other cases. * @param int $regeneratedoc If requested document is the main document of an object, setting this to 1 ask API to regenerate document before returning it (supported for some module_part only). It is no effect in other cases.
* Also, note that setting this to 1 nead write access on object. * Also, note that setting this to 1 nead write access on object.
* @return array List of documents * @return array List of documents
* *
* @throws 500 * @throws 500
* @throws 501 * @throws 501
* @throws 400 * @throws 400
* @throws 401 * @throws 401
* @throws 200 * @throws 200
*/ */
public function index($module_part, $original_file='', $regeneratedoc=0) public function index($module_part, $original_file='', $regeneratedoc=0)
{ {
global $conf; global $conf;
if (empty($module_part)) { if (empty($module_part)) {
throw new RestException(400, 'bad value for parameter modulepart'); throw new RestException(400, 'bad value for parameter modulepart');
}
if (empty($original_file)) {
throw new RestException(400, 'bad value for parameter ref or subdir');
} }
if (empty($original_file)) {
throw new RestException(400, 'bad value for parameter ref or subdir');
}
//--- Finds and returns the document //--- Finds and returns the document
$entity=$conf->entity; $entity=$conf->entity;
@ -183,37 +183,37 @@ class Documents extends DolibarrApi
$entity = $user->entity; $entity = $user->entity;
if ($ref) if ($ref)
{ {
if ($modulepart == 'facture' || $modulepart == 'invoice') if ($modulepart == 'facture' || $modulepart == 'invoice')
{ {
$modulepart='facture'; $modulepart='facture';
$object=new Facture($db); $object=new Facture($db);
$result = $object->fetch('', $ref); $result = $object->fetch('', $ref);
} }
if (! ($object->id > 0)) if (! ($object->id > 0))
{ {
throw new RestException(500, 'The object '.$modulepart." with ref '".$ref."' was not found."); throw new RestException(500, 'The object '.$modulepart." with ref '".$ref."' was not found.");
} }
$tmp = dol_check_secure_access_document($modulepart, $tmpreldir.$object->ref, $entity, DolibarrApiAccess::$user, $ref, 'write'); $tmp = dol_check_secure_access_document($modulepart, $tmpreldir.$object->ref, $entity, DolibarrApiAccess::$user, $ref, 'write');
$upload_dir = $tmp['original_file']; $upload_dir = $tmp['original_file'];
if (empty($upload_dir) || $upload_dir == '/') if (empty($upload_dir) || $upload_dir == '/')
{ {
throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
} }
} }
else else
{ {
if ($modulepart == 'invoice') $modulepart ='facture'; if ($modulepart == 'invoice') $modulepart ='facture';
$tmp = dol_check_secure_access_document($modulepart, $subdir, $entity, DolibarrApiAccess::$user, '', 'write'); $tmp = dol_check_secure_access_document($modulepart, $subdir, $entity, DolibarrApiAccess::$user, '', 'write');
$upload_dir = $tmp['original_file']; $upload_dir = $tmp['original_file'];
if (empty($upload_dir) || $upload_dir == '/') if (empty($upload_dir) || $upload_dir == '/')
{ {
throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
} }
} }
@ -223,46 +223,46 @@ class Documents extends DolibarrApi
$destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file; $destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file;
dol_delete_file($destfiletmp); dol_delete_file($destfiletmp);
if (!dol_is_dir($upload_dir)) { if (!dol_is_dir($upload_dir)) {
throw new RestException(401,'Directory not exists : '.$upload_dir); throw new RestException(401,'Directory not exists : '.$upload_dir);
} }
if (! $overwriteifexists && dol_is_file($destfile)) if (! $overwriteifexists && dol_is_file($destfile))
{ {
throw new RestException(500, "File with name '".$original_file."' already exists."); throw new RestException(500, "File with name '".$original_file."' already exists.");
} }
$fhandle = @fopen($destfiletmp, 'w'); $fhandle = @fopen($destfiletmp, 'w');
if ($fhandle) if ($fhandle)
{ {
$nbofbyteswrote = fwrite($fhandle, $newfilecontent); $nbofbyteswrote = fwrite($fhandle, $newfilecontent);
fclose($fhandle); fclose($fhandle);
@chmod($destfiletmp, octdec($conf->global->MAIN_UMASK)); @chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
} }
else else
{ {
throw new RestException(500, "Failed to open file '".$destfiletmp."' for write"); throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
} }
$result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1); $result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1);
return $result; return $result;
} }
/** /**
* Validate fields before create or update object * Validate fields before create or update object
* *
* @param array $data Array with data to verify * @param array $data Array with data to verify
* @return array * @return array
* @throws RestException * @throws RestException
*/ */
function _validate_file($data) { function _validate_file($data) {
$result = array(); $result = array();
foreach (Documents::$DOCUMENT_FIELDS as $field) { foreach (Documents::$DOCUMENT_FIELDS as $field) {
if (!isset($data[$field])) if (!isset($data[$field]))
throw new RestException(400, "$field field missing"); throw new RestException(400, "$field field missing");
$result[$field] = $data[$field]; $result[$field] = $data[$field];
} }
return $result; return $result;
} }
} }

File diff suppressed because it is too large Load Diff