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

View File

@ -1,20 +1,20 @@
<?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) 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) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2006 Auguria SARL <info@auguria.org>
* Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com>
* 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-2015 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* 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
* 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->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->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/accountingaccount.class.php';
$langs->load("products");
$langs->load("other");
@ -272,7 +272,7 @@ if (empty($reshook))
$object->volume_units = GETPOST('volume_units');
$object->finished = GETPOST('finished');
$object->fk_unit = GETPOST('units');
$accountancy_code_sell = GETPOST('accountancy_code_sell');
$accountancy_code_buy = GETPOST('accountancy_code_buy');
@ -399,7 +399,7 @@ if (empty($reshook))
$accountancy_code_sell = GETPOST('accountancy_code_sell');
$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_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }
@ -1107,7 +1107,7 @@ else
// Accountancy codes
print '<table class="border" width="100%">';
if (! empty($conf->accounting->enabled))
{
// Accountancy_code_sell
@ -1121,7 +1121,7 @@ else
print '<td>';
print $formaccountancy->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, '');
print '</td></tr>';
}
}
else // For external software
{
// Accountancy_code_sell
@ -1414,7 +1414,7 @@ else
print '<td>';
print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
print '</td></tr>';
}
}
else // For external software
{
// Accountancy_code_sell
@ -1531,8 +1531,12 @@ else
print '<tr><td class="nowrap">';
print $langs->trans("ProductAccountancySellCode");
print '</td><td colspan="2">';
if (! empty($conf->accounting->enabled)) {
print length_accountg($object->accountancy_code_sell);
if (! empty($conf->accounting->enabled))
{
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('',$object->accountancy_code_sell);
print $accountingaccount->getNomUrl(0,1,1,'',1);
} else {
print $object->accountancy_code_sell;
}
@ -1542,8 +1546,12 @@ else
print '<tr><td class="nowrap">';
print $langs->trans("ProductAccountancyBuyCode");
print '</td><td colspan="2">';
if (! empty($conf->accounting->enabled)) {
print length_accountg($object->accountancy_code_buy);
if (! empty($conf->accounting->enabled))
{
$accountingaccount2 = new AccountingAccount($db);
$accountingaccount2->fetch('',$object->accountancy_code_buy);
print $accountingaccount2->getNomUrl(0,1,1,'',1);
} else {
print $object->accountancy_code_buy;
}