Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/Dolibarr/5.0' into 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fappels committed Mar 7, 2017
2 parents b88d66e + d38818f commit 277f9d3
Show file tree
Hide file tree
Showing 289 changed files with 55,743 additions and 1,692 deletions.
26 changes: 11 additions & 15 deletions htdocs/accountancy/admin/account.php
Expand Up @@ -145,13 +145,13 @@

$pcgver = $conf->global->CHARTOFACCOUNTS;



$sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.pcg_subtype, aa.account_number, aa.account_parent , aa.label, aa.active, ";
$sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON aa.account_parent = a2.rowid";
// Dirty hack wainting that foreign key account_parent is an integer to be compared correctly with rowid
if ($db->type == 'pgsql') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = CAST(aa.account_parent AS INTEGER)";
else $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = CAST(aa.account_parent AS UNSIGNED)";
$sql .= " WHERE asy.rowid = " . $pcgver;

if (strlen(trim($search_account))) {
Expand Down Expand Up @@ -196,10 +196,12 @@
if ($search_pcgsubtype != "") $params.= '&search_pcgsubtype='.urlencode($search_pcgsubtype);
if ($optioncss != '') $param.='&optioncss='.$optioncss;

print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy');

print '<form method="GET" action="' . $_SERVER["PHP_SELF"] . '">';

$htmlbuttonadd = '<a class="butAction" href="./card.php?action=create">' . $langs->trans("Addanaccount") . '</a>';

print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $htmlbuttonadd);

// Box to select active chart of account
$var = ! $var;
print $langs->trans("Selectchartofaccounts") . " : ";
Expand Down Expand Up @@ -227,13 +229,7 @@
print "</select>";
print '<input type="submit" class="button" name="change_chart" value="'.dol_escape_htmltag($langs->trans("ChangeAndLoad")).'">';
print '<br>';
print "<br>\n";

print '<a class="butAction" href="./card.php?action=create">' . $langs->trans("Addanaccount") . '</a>';
print '<a class="butAction" href="./categories.php">' . $langs->trans("ApplyMassCategories") . '</a>';
// print '<a class="butAction" href="./importaccounts.php">' . $langs->trans("ImportAccount") . '</a>';
// print '<a class="butAction" href="./productaccount.php">' . $langs->trans("CheckProductAccountancyCode") . '</a>';
print '<br><br>';
print '<br>';

print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
Expand Down Expand Up @@ -305,12 +301,12 @@

// Action
print '<td align="center">';
if ($user->admin) {
print '<a href="./card.php?action=update&id=' . $obj->rowid . '">';
if ($user->rights->accounting->chartofaccount) {
print '<a href="./card.php?action=update&id=' . $obj->rowid . '&backtopage='.urlencode($_SERVER["PHP_SELF"].'?chartofaccounts='.$object->id).'">';
print img_edit();
print '</a>';
print '&nbsp;';
print '<a href="./card.php?action=delete&id=' . $obj->rowid . '">';
print '<a href="./card.php?action=delete&id=' . $obj->rowid . '&backtopage='.urlencode($_SERVER["PHP_SELF"].'?chartofaccounts='.$object->id). '">';
print img_delete();
print '</a>';
}
Expand Down
40 changes: 29 additions & 11 deletions htdocs/accountancy/admin/card.php
Expand Up @@ -26,6 +26,7 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancysystem.class.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';

Expand Down Expand Up @@ -159,13 +160,15 @@
$result = $object->update($user);

if ($result > 0) {
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
$urltogo=$backtopage?$backtopage:($_SERVER["PHP_SELF"]."?id=".$id);
header("Location: " . $urltogo);
exit();
} else {
$mesg = $object->error;
}
} else {
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
$urltogo=$backtopage?$backtopage:($_SERVER["PHP_SELF"]."?id=".$id);
header("Location: " . $urltogo);
exit();
}
} else if ($action == 'delete' && $user->rights->accounting->chartofaccount) {
Expand Down Expand Up @@ -196,6 +199,9 @@
$htmlacc = new FormVentilation($db);
$formaccounting = new FormAccounting($db);

$accountsystem = new AccountancySystem($db);
$accountsystem->fetch($conf->global->CHARTOFACCOUNTS);

// Create mode
if ($action == 'create') {
print load_fiche_titre($langs->trans('NewAccountingAccount'));
Expand All @@ -208,36 +214,45 @@

print '<table class="border" width="100%">';

// Chart of account
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">' . $langs->trans("Chartofaccounts") . '</span></td>';
print '<td>';
print $accountsystem->ref;
print '</td></tr>';


// Account number
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
print '<td><input name="account_number" size="30" value="' . $object->account_number . '"</td></tr>';
print '<td><input name="account_number" size="30" value="' . $object->account_number . '"></td></tr>';

// Label
print '<tr><td><span class="fieldrequired">' . $langs->trans("Label") . '</span></td>';
print '<td><input name="label" size="70" value="' . $object->label . '"</td></tr>';
print '<td><input name="label" size="70" value="' . $object->label . '"></td></tr>';

// Account parent
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
print '<td>';
print $htmlacc->select_account($object->account_parent, 'account_parent', 1);
print $htmlacc->select_account($object->account_parent, 'account_parent', 1, null, 0, 0, 'minwidth200');
print '</td></tr>';

// Category
print '<tr><td>' . $langs->trans("AccountingCategory") . '</td>';
print '<td>';
$formaccounting->select_accounting_category($object->account_category, 'account_category', 1);
$formaccounting->select_accounting_category($object->account_category, 'account_category', 1, 0, 1);
print '</td></tr>';

// Chart of accounts type
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
print '<td>';
print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type');
print '<input type="text" name="pcg_type" value="'.dol_escape_htmltag(isset($_POST['pcg_type'])?GETPOST('pcg_type','alpha'):$object->pcg_type).'">';
//print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type', 1);
print '</td></tr>';

// Chart of acounts subtype
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
print '<td>';
print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype');
print '<input type="text" name="pcg_subtype" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$object->pcg_subtype).'">';
//print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype', 1);
print '</td></tr>';

print '</table>';
Expand Down Expand Up @@ -268,7 +283,8 @@
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="edit">';
print '<input type="hidden" name="id" value="' . $id . '">';

print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';

print '<table class="border" width="100%">';

// Account number
Expand All @@ -294,13 +310,15 @@
// Chart of accounts type
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
print '<td>';
print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type');
//print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type', 1);
print '<input type="text" name="pcg_type" value="'.dol_escape_htmltag(isset($_POST['pcg_type'])?GETPOST('pcg_type','alpha'):$object->pcg_type).'">';
print '</td></tr>';

// Chart of accounts subtype
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
print '<td>';
print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype');
print '<input type="text" name="pcg_subtype" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$object->pcg_subtype).'">';
//print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype', 1);
print '</td></tr>';

print '</table>';
Expand Down
10 changes: 7 additions & 3 deletions htdocs/accountancy/admin/categories.php
Expand Up @@ -106,8 +106,9 @@
print '<input class="button" type="submit" value="' . $langs->trans("Select") . '">';
print '</td></tr>';

if (! empty($cat_id)) {
$return = $AccCat->getCptBK($cat_id);
if (! empty($cat_id))
{
$return = $AccCat->getAccountsWithNoCategory($cat_id);
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
}
Expand Down Expand Up @@ -149,7 +150,10 @@
print '<td>' . length_accountg($cpt->account_number) . '</td>';
print '<td>' . $cpt->label . '</td>';
print $form->formconfirm($_SERVER["PHP_SELF"] . "?account_category=$cat_id&cptid=" . $cpt->rowid, $langs->trans("DeleteCptCategory"), $langs->trans("ConfirmDeleteCptCategory"), "delete", '', 0, "action-delete" . $j);
print '<td><input class="button" type="button" id="action-delete' . $j . '" value="' . $langs->trans("Delete") . '"></td>';
print '<td>';
//print img_delete();
print '<input class="button" type="button" id="action-delete' . $j . '" value="' . $langs->trans("Delete") . '">';
print '</td>';
print "</tr>\n";
$j ++;
}
Expand Down
43 changes: 42 additions & 1 deletion htdocs/accountancy/class/accountancycategory.class.php
Expand Up @@ -84,7 +84,7 @@ public function display($id) {
}

/**
* Function to select accountiing category of an accounting account present in chart of accounts
* Function to select accounting category of an accounting account present in chart of accounts
*
* @param int $id Id category
*
Expand Down Expand Up @@ -130,6 +130,47 @@ public function getCptBK($id) {
}
}

/**
* Function to select accounting category of an accounting account present in chart of accounts
*
* @param int $id Id category
*
* @return int <0 if KO, 0 if not found, >0 if OK
*/
public function getAccountsWithNoCategory($id) {
global $conf;

$sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
$sql .= " WHERE (aa.fk_accounting_category != ".$id." OR aa.fk_accounting_category IS NULL)";
$sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
$sql .= " AND aa.active = 1";
$sql .= " GROUP BY aa.account_number, aa.label";
$sql .= " ORDER BY aa.account_number, aa.label";

$this->lines_CptBk = array ();

dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num) {
while ( $obj = $this->db->fetch_object($resql) ) {
$this->lines_cptbk[] = $obj;
}
}

return $num;
} else {
$this->error = "Error " . $this->db->lasterror();
$this->errors[] = $this->error;
dol_syslog(__METHOD__ . " " . implode(',' . $this->errors), LOG_ERR);

return - 1;
}
}

/**
* Function to add an accounting account in an accounting category
*
Expand Down
49 changes: 49 additions & 0 deletions htdocs/accountancy/class/accountancysystem.class.php
Expand Up @@ -47,6 +47,55 @@ function __construct($db) {
$this->db = $db;
}


/**
* Load record in memory
*
* @param int $rowid Id
* @param string $ref ref
* @return int <0 if KO, Id of record if OK and found
*/
function fetch($rowid = 0, $ref = '')
{
global $conf;

if ($rowid > 0 || $ref)
{
$sql = "SELECT a.pcg_version, a.label, a.active";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_system as a";
$sql .= " WHERE";
if ($rowid) {
$sql .= " a.rowid = '" . $rowid . "'";
} elseif ($ref) {
$sql .= " a.pcg_version = '" . $ref . "'";
}

dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
$obj = $this->db->fetch_object($result);

if ($obj) {
$this->id = $obj->rowid;
$this->rowid = $obj->rowid;
$this->pcg_version = $obj->pcg_version;
$this->ref = $obj->pcg_version;
$this->label = $obj->label;
$this->active = $obj->active;

return $this->id;
} else {
return 0;
}
} else {
$this->error = "Error " . $this->db->lasterror();
$this->errors[] = "Error " . $this->db->lasterror();
}
}
return - 1;
}


/**
* Insert accountancy system name into database
*
Expand Down
35 changes: 25 additions & 10 deletions htdocs/accountancy/class/accountingaccount.class.php
Expand Up @@ -150,12 +150,19 @@ function create($user, $notrigger = 0) {
if (isset($this->active))
$this->active = trim($this->active);

// Check parameters
// Put here code to add control on parameters values
if (empty($this->pcg_type) || $this->pcg_type == '-1')
{
$this->pcg_type = 'XXXXXX';
}
if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1')
{
$this->pcg_subtype = 'XXXXXX';
}
// Check parameters
// Put here code to add control on parameters values

// Insert request
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account(";

$sql .= "datec";
$sql .= ", entity";
$sql .= ", fk_pcg_version";
Expand All @@ -167,9 +174,7 @@ function create($user, $notrigger = 0) {
$sql .= ", fk_accounting_category";
$sql .= ", fk_user_author";
$sql .= ", active";

$sql .= ") VALUES (";

$sql .= " '" . $this->db->idate($now) . "'";
$sql .= ", " . $conf->entity;
$sql .= ", " . (empty($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'");
Expand Down Expand Up @@ -225,11 +230,22 @@ function create($user, $notrigger = 0) {
/**
* Update record
*
* @param User $user Use making update
* @return int <0 if KO, >0 if OK
* @param User $user Use making update
* @return int <0 if KO, >0 if OK
*/
function update($user) {
$this->db->begin();
function update($user)
{
// Check parameters
if (empty($this->pcg_type) || $this->pcg_type == '-1')
{
$this->pcg_type = 'XXXXXX';
}
if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1')
{
$this->pcg_subtype = 'XXXXXX';
}

$this->db->begin();

$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
$sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null");
Expand All @@ -241,7 +257,6 @@ function update($user) {
$sql .= " , fk_accounting_category = '" . $this->account_category . "'";
$sql .= " , fk_user_modif = " . $user->id;
$sql .= " , active = '" . $this->active . "'";

$sql .= " WHERE rowid = " . $this->id;

dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
Expand Down

0 comments on commit 277f9d3

Please sign in to comment.