Merge pull request #6872 from aspangaro/6.0-pcard

Use getNomUrl for accounting account in product card
This commit is contained in:
Laurent Destailleur 2017-05-29 10:05:06 +02:00 committed by GitHub
commit 4474fc8014
2 changed files with 79 additions and 71 deletions

View File

@ -1053,23 +1053,23 @@ class BookKeeping extends CommonObject
*/ */
function deleteByYearAndJournal($delyear='', $journal='') { function deleteByYearAndJournal($delyear='', $journal='') {
global $conf; global $conf;
if (empty($delyear) && empty($journal)) if (empty($delyear) && empty($journal))
{ {
return -1; return -1;
} }
$this->db->begin(); $this->db->begin();
// first check if line not yet in bookkeeping // first check if line not yet in bookkeeping
$sql = "DELETE"; $sql = "DELETE";
$sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql.= " WHERE 1 = 1"; $sql.= " WHERE 1 = 1";
if (! empty($delyear)) $sql.= " AND YEAR(doc_date) = " . $delyear; // FIXME Must use between if (! empty($delyear)) $sql.= " AND YEAR(doc_date) = " . $delyear; // FIXME Must use between
if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'"; if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'";
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { if (! $resql) {
$this->errors[] = "Error " . $this->db->lasterror(); $this->errors[] = "Error " . $this->db->lasterror();
foreach ( $this->errors as $errmsg ) { foreach ( $this->errors as $errmsg ) {
@ -1083,7 +1083,7 @@ class BookKeeping extends CommonObject
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
/** /**
* Delete bookkepping by piece number * Delete bookkepping by piece number
* *
@ -1092,17 +1092,17 @@ class BookKeeping extends CommonObject
*/ */
function deleteMvtNum($piecenum) { function deleteMvtNum($piecenum) {
global $conf; global $conf;
$this->db->begin(); $this->db->begin();
// first check if line not yet in bookkeeping // first check if line not yet in bookkeeping
$sql = "DELETE"; $sql = "DELETE";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE piece_num = " . $piecenum; $sql .= " WHERE piece_num = " . $piecenum;
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { if (! $resql) {
$this->errors[] = "Error " . $this->db->lasterror(); $this->errors[] = "Error " . $this->db->lasterror();
foreach ( $this->errors as $errmsg ) { foreach ( $this->errors as $errmsg ) {
@ -1116,7 +1116,7 @@ class BookKeeping extends CommonObject
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
/** /**
* Load an object from its id and create a new one in database * Load an object from its id and create a new one in database
* *
@ -1130,27 +1130,27 @@ class BookKeeping extends CommonObject
global $user; global $user;
$error = 0; $error = 0;
$object = new Accountingbookkeeping($this->db); $object = new Accountingbookkeeping($this->db);
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
$object->fetch($fromid); $object->fetch($fromid);
// Reset object // Reset object
$object->id = 0; $object->id = 0;
// Clear fields // Clear fields
// ... // ...
// Create clone // Create clone
$result = $object->create($user); $result = $object->create($user);
// Other options // Other options
if ($result < 0) { if ($result < 0) {
$error ++; $error ++;
$this->errors = $object->errors; $this->errors = $object->errors;
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
} }
// End // End
if (! $error) { if (! $error) {
$this->db->commit(); $this->db->commit();
@ -1158,11 +1158,11 @@ class BookKeeping extends CommonObject
return $object->id; return $object->id;
} else { } else {
$this->db->rollback(); $this->db->rollback();
return - 1; return - 1;
} }
} }
/** /**
* Initialise object with example values * Initialise object with example values
* Id must be 0 if object instance is a specimen * Id must be 0 if object instance is a specimen
@ -1171,9 +1171,9 @@ class BookKeeping extends CommonObject
*/ */
public function initAsSpecimen() { public function initAsSpecimen() {
global $user; global $user;
$now=dol_now(); $now=dol_now();
$this->id = 0; $this->id = 0;
$this->doc_date = $now; $this->doc_date = $now;
$this->doc_type = ''; $this->doc_type = '';
@ -1192,7 +1192,7 @@ class BookKeeping extends CommonObject
$this->code_journal = ''; $this->code_journal = '';
$this->piece_num = ''; $this->piece_num = '';
} }
/** /**
* Load an accounting document into memory from database * Load an accounting document into memory from database
* *
@ -1201,17 +1201,17 @@ class BookKeeping extends CommonObject
*/ */
public function fetchPerMvt($piecenum) { public function fetchPerMvt($piecenum) {
global $conf; global $conf;
$sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE piece_num = " . $piecenum; $sql .= " WHERE piece_num = " . $piecenum;
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->piece_num = $obj->piece_num; $this->piece_num = $obj->piece_num;
$this->code_journal = $obj->code_journal; $this->code_journal = $obj->code_journal;
$this->doc_date = $this->db->jdate($obj->doc_date); $this->doc_date = $this->db->jdate($obj->doc_date);
@ -1222,10 +1222,10 @@ class BookKeeping extends CommonObject
dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
return - 1; return - 1;
} }
return 1; return 1;
} }
/** /**
* Return next number movement * Return next number movement
* *
@ -1233,8 +1233,8 @@ class BookKeeping extends CommonObject
*/ */
public function getNextNumMvt() public function getNextNumMvt()
{ {
global $conf; global $conf;
$sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
@ -1243,16 +1243,16 @@ class BookKeeping extends CommonObject
if ($result) { if ($result) {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
if ($obj) $result = $obj->max; if ($obj) $result = $obj->max;
if (empty($result)) $result = 1; if (empty($result)) $result = 1;
return $result; return $result;
} else { } else {
$this->error = "Error " . $this->db->lasterror(); $this->error = "Error " . $this->db->lasterror();
dol_syslog(get_class($this) . "::getNextNumMvt " . $this->error, LOG_ERR); dol_syslog(get_class($this) . "::getNextNumMvt " . $this->error, LOG_ERR);
return - 1; return - 1;
} }
} }
/** /**
* Load all informations of accountancy document * Load all informations of accountancy document
* *
@ -1260,26 +1260,26 @@ class BookKeeping extends CommonObject
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function fetch_all_per_mvt($piecenum) { function fetch_all_per_mvt($piecenum) {
global $conf; global $conf;
$sql = "SELECT rowid, doc_date, doc_type,"; $sql = "SELECT rowid, doc_date, doc_type,";
$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,"; $sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
$sql .= " numero_compte, label_compte, debit, credit,"; $sql .= " numero_compte, label_compte, debit, credit,";
$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE piece_num = " . $piecenum; $sql .= " WHERE piece_num = " . $piecenum;
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
while ( $obj = $this->db->fetch_object($result) ) { while ( $obj = $this->db->fetch_object($result) ) {
$line = new BookKeepingLine(); $line = new BookKeepingLine();
$line->id = $obj->rowid; $line->id = $obj->rowid;
$line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_date = $this->db->jdate($obj->doc_date);
$line->doc_type = $obj->doc_type; $line->doc_type = $obj->doc_type;
$line->doc_ref = $obj->doc_ref; $line->doc_ref = $obj->doc_ref;
@ -1294,7 +1294,7 @@ class BookKeeping extends CommonObject
$line->sens = $obj->sens; $line->sens = $obj->sens;
$line->code_journal = $obj->code_journal; $line->code_journal = $obj->code_journal;
$line->piece_num = $obj->piece_num; $line->piece_num = $obj->piece_num;
$this->linesmvt[] = $line; $this->linesmvt[] = $line;
} }
} else { } else {
@ -1302,10 +1302,10 @@ class BookKeeping extends CommonObject
dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
return - 1; return - 1;
} }
return 1; return 1;
} }
/** /**
* Export bookkeping * Export bookkeping
* *
@ -1313,28 +1313,28 @@ class BookKeeping extends CommonObject
* @return int Result * @return int Result
*/ */
function export_bookkeping($model = 'ebp') { function export_bookkeping($model = 'ebp') {
global $conf; global $conf;
$sql = "SELECT rowid, doc_date, doc_type,"; $sql = "SELECT rowid, doc_date, doc_type,";
$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,"; $sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
$sql .= " numero_compte, label_compte, debit, credit,"; $sql .= " numero_compte, label_compte, debit, credit,";
$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG); dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
$this->linesexport = array (); $this->linesexport = 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 BookKeepingLine(); $line = new BookKeepingLine();
$line->id = $obj->rowid; $line->id = $obj->rowid;
$line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_date = $this->db->jdate($obj->doc_date);
$line->doc_type = $obj->doc_type; $line->doc_type = $obj->doc_type;
$line->doc_ref = $obj->doc_ref; $line->doc_ref = $obj->doc_ref;
@ -1349,11 +1349,11 @@ class BookKeeping extends CommonObject
$line->sens = $obj->sens; $line->sens = $obj->sens;
$line->code_journal = $obj->code_journal; $line->code_journal = $obj->code_journal;
$line->piece_num = $obj->piece_num; $line->piece_num = $obj->piece_num;
$this->linesexport[] = $line; $this->linesexport[] = $line;
} }
$this->db->free($resql); $this->db->free($resql);
return $num; return $num;
} else { } else {
$this->error = "Error " . $this->db->lasterror(); $this->error = "Error " . $this->db->lasterror();

View File

@ -1,20 +1,20 @@
<?php <?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2006 Auguria SARL <info@auguria.org> * Copyright (C) 2006 Auguria SARL <info@auguria.org>
* Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr> * Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2011-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2014 Cédric Gross <c.gross@kreiz-it.fr> * Copyright (C) 2014 Cédric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2014-2015 Ferran Marcet <fmarcet@2byte.es> * Copyright (C) 2014-2015 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com> * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
* Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr> * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -51,8 +51,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.php';
if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
$langs->load("products"); $langs->load("products");
$langs->load("other"); $langs->load("other");
@ -272,7 +272,7 @@ if (empty($reshook))
$object->volume_units = GETPOST('volume_units'); $object->volume_units = GETPOST('volume_units');
$object->finished = GETPOST('finished'); $object->finished = GETPOST('finished');
$object->fk_unit = GETPOST('units'); $object->fk_unit = GETPOST('units');
$accountancy_code_sell = GETPOST('accountancy_code_sell'); $accountancy_code_sell = GETPOST('accountancy_code_sell');
$accountancy_code_buy = GETPOST('accountancy_code_buy'); $accountancy_code_buy = GETPOST('accountancy_code_buy');
@ -399,7 +399,7 @@ if (empty($reshook))
$accountancy_code_sell = GETPOST('accountancy_code_sell'); $accountancy_code_sell = GETPOST('accountancy_code_sell');
$accountancy_code_buy = GETPOST('accountancy_code_buy'); $accountancy_code_buy = GETPOST('accountancy_code_buy');
if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; } if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; }
if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; } if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }
@ -1107,7 +1107,7 @@ else
// Accountancy codes // Accountancy codes
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
// Accountancy_code_sell // Accountancy_code_sell
@ -1121,7 +1121,7 @@ else
print '<td>'; print '<td>';
print $formaccountancy->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, ''); print $formaccountancy->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, '');
print '</td></tr>'; print '</td></tr>';
} }
else // For external software else // For external software
{ {
// Accountancy_code_sell // Accountancy_code_sell
@ -1414,7 +1414,7 @@ else
print '<td>'; print '<td>';
print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1); print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
print '</td></tr>'; print '</td></tr>';
} }
else // For external software else // For external software
{ {
// Accountancy_code_sell // Accountancy_code_sell
@ -1531,8 +1531,12 @@ else
print '<tr><td class="nowrap">'; print '<tr><td class="nowrap">';
print $langs->trans("ProductAccountancySellCode"); print $langs->trans("ProductAccountancySellCode");
print '</td><td colspan="2">'; print '</td><td colspan="2">';
if (! empty($conf->accounting->enabled)) { if (! empty($conf->accounting->enabled))
print length_accountg($object->accountancy_code_sell); {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('',$object->accountancy_code_sell);
print $accountingaccount->getNomUrl(0,1,1,'',1);
} else { } else {
print $object->accountancy_code_sell; print $object->accountancy_code_sell;
} }
@ -1542,8 +1546,12 @@ else
print '<tr><td class="nowrap">'; print '<tr><td class="nowrap">';
print $langs->trans("ProductAccountancyBuyCode"); print $langs->trans("ProductAccountancyBuyCode");
print '</td><td colspan="2">'; print '</td><td colspan="2">';
if (! empty($conf->accounting->enabled)) { if (! empty($conf->accounting->enabled))
print length_accountg($object->accountancy_code_buy); {
$accountingaccount2 = new AccountingAccount($db);
$accountingaccount2->fetch('',$object->accountancy_code_buy);
print $accountingaccount2->getNomUrl(0,1,1,'',1);
} else { } else {
print $object->accountancy_code_buy; print $object->accountancy_code_buy;
} }