Merge pull request #6804 from aspangaro/6.0-multijournal

New : Accountancy - Add a list to select the bank journal in bank card
This commit is contained in:
Laurent Destailleur 2017-05-10 22:46:30 +02:00 committed by GitHub
commit 1c7d9b9d9a
13 changed files with 324 additions and 143 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com> /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
* Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
* *
* 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
@ -28,9 +28,14 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
// Langs // Langs
$langs->load("accountancy"); $langs->load("accountancy");
$langs->load("bank");
$langs->load("bills");
$langs->load("trips");
// Security check // Security check
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
@ -211,6 +216,7 @@ llxHeader();
$html = new Form($db); $html = new Form($db);
$formventilation = new FormVentilation($db); $formventilation = new FormVentilation($db);
$formaccountancy = new FormAccounting($db);
/* /*
* Confirmation to delete the command * Confirmation to delete the command
@ -223,26 +229,6 @@ if ($action == 'delete') {
if ($action == 'create') { if ($action == 'create') {
print load_fiche_titre($langs->trans("CreateMvts")); print load_fiche_titre($langs->trans("CreateMvts"));
$code_journal_array = array (
$conf->global->ACCOUNTING_SELL_JOURNAL => $conf->global->ACCOUNTING_SELL_JOURNAL,
$conf->global->ACCOUNTING_PURCHASE_JOURNAL => $conf->global->ACCOUNTING_PURCHASE_JOURNAL,
$conf->global->ACCOUNTING_SOCIAL_JOURNAL => $conf->global->ACCOUNTING_SOCIAL_JOURNAL,
$conf->global->ACCOUNTING_MISCELLANEOUS_JOURNAL => $conf->global->ACCOUNTING_MISCELLANEOUS_JOURNAL,
$conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL => $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL
);
$sql = 'SELECT DISTINCT accountancy_journal FROM ' . MAIN_DB_PREFIX . 'bank_account WHERE clos=0';
$resql = $db->query($sql);
if (! $resql) {
setEventMessages($db->lasterror, null, 'errors');
} else {
while ( $obj_bank = $db->fetch_object($resql) ) {
if (! empty($obj_bank->accountancy_journal)) {
$code_journal_array[$obj_bank->accountancy_journal] = $obj_bank->accountancy_journal;
}
}
}
$book = new BookKeeping($db); $book = new BookKeeping($db);
$next_num_mvt = $book->getNextNumMvt(); $next_num_mvt = $book->getNextNumMvt();
if (empty($next_num_mvt)) if (empty($next_num_mvt))
@ -270,9 +256,10 @@ if ($action == 'create') {
print '</tr>'; print '</tr>';
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">' . $langs->trans("Codejournal") . '</td>'; print '<td class="fieldrequired">'.$langs->trans("AccountancyJournal").'</td>';
print '<td>' . $html->selectarray('code_journal', $code_journal_array) . '</td>'; print '<td>';
print '</tr>'; print $formaccountancy->select_journal('', 'code_journal', '', 0, '', 1, 1, 1, 1);
print '</td></tr>';
print '<tr>'; print '<tr>';
print '<td>' . $langs->trans("Docref") . '</td>'; print '<td>' . $langs->trans("Docref") . '</td>';
@ -308,25 +295,46 @@ if ($action == 'create') {
print '<div class="fichecenter">'; print '<div class="fichecenter">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr class="pair">'; print '<tr class="pair">';
print '<td class="titlefield">' . $langs->trans("NumMvts") . '</td>'; print '<td class="titlefield">' . $langs->trans("NumMvts") . '</td>';
print '<td>' . $book->piece_num . '</td>'; print '<td>' . $book->piece_num . '</td>';
print '</tr>'; print '</tr>';
print '<tr class="impair">'; print '<tr class="impair">';
print '<td>' . $langs->trans("Docdate") . '</td>'; print '<td>' . $langs->trans("Docdate") . '</td>';
print '<td>' . dol_print_date($book->doc_date, 'daytextshort') . '</td>'; print '<td>' . dol_print_date($book->doc_date, 'daytextshort') . '</td>';
print '</tr>'; print '</tr>';
print '<tr class="pair">'; print '<tr class="pair">';
print '<td>' . $langs->trans("Codejournal") . '</td>'; print '<td>' . $langs->trans("Codejournal") . '</td>';
print '<td>' . $book->code_journal . '</td>'; print '<td>';
print '</tr>'; $accountingjournal = new AccountingJournal($db);
$accountingjournal->fetch('',$book->code_journal);
print $accountingjournal->getNomUrl(0,1,1,'',1);
print '</td></tr>';
print '<tr class="impair">'; print '<tr class="impair">';
print '<td>' . $langs->trans("Docref") . '</td>'; print '<td>' . $langs->trans("Docref") . '</td>';
print '<td>' . $book->doc_ref . '</td>'; print '<td>' . $book->doc_ref . '</td>';
print '</tr>'; print '</tr>';
$typelabel = $book->doc_type;
if ($typelabel == 'bank') {
$typelabel = $langs->trans('Bank');
}
if ($typelabel == 'customer_invoice') {
$typelabel = $langs->trans('CustomerInvoice');
}
if ($typelabel == 'supplier_invoice') {
$typelabel = $langs->trans('SupplierInvoice');
}
if ($typelabel == 'expense_report') {
$typelabel = $langs->trans('ExpenseReport');
}
print '<tr class="pair">'; print '<tr class="pair">';
print '<td>' . $langs->trans("Doctype") . '</td>'; print '<td>' . $langs->trans("Doctype") . '</td>';
print '<td>' . $book->doc_type . '</td>'; print '<td>' . $typelabel . '</td>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com> /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
* Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
// Langs // Langs
$langs->load("accountancy"); $langs->load("accountancy");
@ -443,7 +444,11 @@ foreach ($object->lines as $line ) {
print '<td>' . $line->label_compte . '</td>'; print '<td>' . $line->label_compte . '</td>';
print '<td align="right">' . price($line->debit) . '</td>'; print '<td align="right">' . price($line->debit) . '</td>';
print '<td align="right">' . price($line->credit) . '</td>'; print '<td align="right">' . price($line->credit) . '</td>';
print '<td align="center">' . $line->code_journal . '</td>';
$accountingjournal = new AccountingJournal($db);
$accountingjournal->fetch('',$line->code_journal);
print '<td align="center">' . $accountingjournal->getNomUrl(0,0,0,'',0) . '</td>';
print '<td align="center">'; print '<td align="center">';
print '<a href="./card.php?piece_num=' . $line->piece_num . '">' . img_edit() . '</a>&nbsp;'; print '<a href="./card.php?piece_num=' . $line->piece_num . '">' . img_edit() . '</a>&nbsp;';
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delmouv&mvt_num=' . $line->piece_num . $param . '&page=' . $page . '">' . img_delete() . '</a>'; print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delmouv&mvt_num=' . $line->piece_num . $param . '&page=' . $page . '">' . img_delete() . '</a>';

View File

@ -50,22 +50,32 @@ class AccountingJournal extends CommonObject
/** /**
* Load an object from database * Load an object from database
* *
* @param int $id Id of record to load * @param int $rowid Id of record to load
* @return int <0 if KO, >0 if OK * @param string $journal_code Journal code
* @return int <0 if KO, Id of record if OK and found
*/ */
function fetch($id) function fetch($rowid = null, $journal_code = null)
{
if ($rowid || $journal_code)
{ {
$sql = "SELECT rowid, code, label, nature, active"; $sql = "SELECT rowid, code, label, nature, active";
$sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal";
$sql.= " WHERE rowid = ".$id; $sql .= " WHERE";
if ($rowid) {
$sql .= " rowid = '" . $rowid . "'";
} elseif ($journal_code) {
$sql .= " code = '" . $journal_code . "'";
}
dol_syslog(get_class($this)."::fetch sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=" . $sql, 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);
if ($obj) {
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->rowid = $obj->rowid;
$this->code = $obj->code; $this->code = $obj->code;
$this->ref = $obj->code; $this->ref = $obj->code;
@ -73,39 +83,79 @@ class AccountingJournal extends CommonObject
$this->nature = $obj->nature; $this->nature = $obj->nature;
$this->active = $obj->active; $this->active = $obj->active;
return 1; return $this->id;
} else {
return 0;
}
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error = "Error " . $this->db->lasterror();
return -1; $this->errors[] = "Error " . $this->db->lasterror();
} }
} }
return -1;
}
/** /**
* Return clicable name (with picto eventually) * Return clicable name (with picto eventually)
* *
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @return string Chaine avec URL * @param int $withlabel 0=No label, 1=Include label of journal
* @param int $nourl 1=Disable url
* @param string $moretitle Add more text to title tooltip
* @param int $notooltip 1=Disable tooltip
* @return string String with URL
*/ */
function getNomUrl($withpicto = 0) { function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle='',$notooltip=0)
global $langs; {
global $langs, $conf, $user;
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
$result = ''; $result = '';
$link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/journals_card.php?id=' . $this->id . '">'; $url = DOL_URL_ROOT . '/accountancy/admin/journals_list.php?id=35';
$linkend = '</a>';
$picto = 'billr'; $picto = 'billr';
$label='';
$label = $langs->trans("Show") . ': ' . $this->code . ' - ' . $this->label; $label = '<u>' . $langs->trans("ShowAccountingJournal") . '</u>';
if (! empty($this->code))
$label .= '<br><b>'.$langs->trans('Code') . ':</b> ' . $this->code;
if (! empty($this->label))
$label .= '<br><b>'.$langs->trans('Label') . ':</b> ' . $this->label;
if ($moretitle) $label.=' - '.$moretitle;
if ($withpicto) $linkclose='';
$result .= ($link . img_object($label, $picto) . $linkend); if (empty($notooltip))
if ($withpicto && $withpicto != 2) {
$result .= ' '; if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
if ($withpicto != 2) {
$result .= $link . $this->code . ' - ' . $this->label . $linkend; $label=$langs->trans("ShowAccoutingJournal");
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip"';
}
$linkstart='<a href="'.$url.'"';
$linkstart.=$linkclose.'>';
$linkend='</a>';
if ($nourl)
{
$linkstart = '';
$linkclose = '';
$linkend = '';
}
$label_link = $this->code;
if ($withlabel) $label_link .= ' - ' . $this->label;
if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
if ($withpicto && $withpicto != 2) $result .= ' ';
if ($withpicto != 2) $result.=$linkstart . $label_link . $linkend;
return $result; return $result;
} }
@ -136,19 +186,19 @@ class AccountingJournal extends CommonObject
if ($mode == 0) if ($mode == 0)
{ {
$prefix=''; $prefix='';
if ($nature == 9) return $langs->trans('AccountingJournalTypeHasNew'); if ($nature == 9) return $langs->trans('AccountingJournalType9');
if ($nature == 3) return $langs->trans('AccountingJournalTypeBank'); if ($nature == 4) return $langs->trans('AccountingJournalType4');
if ($nature == 2) return $langs->trans('AccountingJournalTypePurchase'); if ($nature == 3) return $langs->trans('AccountingJournalType3');
if ($nature == 1) return $langs->trans('AccountingJournalTypeSale'); if ($nature == 2) return $langs->trans('AccountingJournalType2');
if ($nature == 0) return $langs->trans('AccountingJournalTypeVariousOperation'); if ($nature == 1) return $langs->trans('AccountingJournalType1');
} }
if ($mode == 1) if ($mode == 1)
{ {
if ($nature == 9) return $langs->trans('AccountingJournalTypeHasNew'); if ($nature == 9) return $langs->trans('AccountingJournalType9');
if ($nature == 3) return $langs->trans('AccountingJournalTypeBank'); if ($nature == 4) return $langs->trans('AccountingJournalType4');
if ($nature == 2) return $langs->trans('AccountingJournalTypePurchase'); if ($nature == 3) return $langs->trans('AccountingJournalType3');
if ($nature == 1) return $langs->trans('AccountingJournalTypeSale'); if ($nature == 2) return $langs->trans('AccountingJournalType2');
if ($nature == 0) return $langs->trans('AccountingJournalTypeVariousOperation'); if ($nature == 1) return $langs->trans('AccountingJournalType1');
} }
} }
} }

View File

@ -36,7 +36,9 @@ require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.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/html.formventilation.class.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
$langs->load("banks"); $langs->load("banks");
$langs->load("bills"); $langs->load("bills");
@ -99,7 +101,7 @@ if ($action == 'add')
$account_number = GETPOST('account_number','alpha'); $account_number = GETPOST('account_number','alpha');
if ($account_number <= 0) { $object->account_number = ''; } else { $object->account_number = $account_number; } if ($account_number <= 0) { $object->account_number = ''; } else { $object->account_number = $account_number; }
$object->accountancy_journal = trim($_POST["accountancy_journal"]); $object->fk_accountancy_journal = trim($_POST["fk_accountancy_journal"]);
$object->solde = $_POST["solde"]; $object->solde = $_POST["solde"];
$object->date_solde = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $object->date_solde = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
@ -197,7 +199,7 @@ if ($action == 'update')
$account_number = GETPOST('account_number', 'int'); $account_number = GETPOST('account_number', 'int');
if ($account_number <= 0) { $object->account_number = ''; } else { $object->account_number = $account_number; } if ($account_number <= 0) { $object->account_number = ''; } else { $object->account_number = $account_number; }
$object->accountancy_journal = trim($_POST["accountancy_journal"]); $object->fk_accountancy_journal = trim($_POST["fk_accountancy_journal"]);
$object->currency_code = trim($_POST["account_currency_code"]); $object->currency_code = trim($_POST["account_currency_code"]);
@ -278,6 +280,7 @@ $form = new Form($db);
$formbank = new FormBank($db); $formbank = new FormBank($db);
$formcompany = new FormCompany($db); $formcompany = new FormCompany($db);
if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db); if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
if (! empty($conf->accounting->enabled)) $formaccountancy2 = New FormAccounting($db);
$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
@ -534,7 +537,9 @@ if ($action == 'create')
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>'; print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
print '<td colspan="3"><input type="text" name="accountancy_journal" value="'.(GETPOST("accountancy_journal")?GETPOST('accountancy_journal', 'alpha'):$object->accountancy_journal).'"></td></tr>'; print '<td>';
print $formaccountancy2->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, '', 1, 1);
print '</td></tr>';
} }
print '</table>'; print '</table>';
@ -677,7 +682,14 @@ else
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>'; print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
print '<td>'.$object->accountancy_journal.'</td></tr>'; print '<td>';
$accountingjournal = new AccountingJournal($db);
$accountingjournal->fetch($object->fk_accountancy_journal);
print $accountingjournal->getNomUrl(0,1,1,'',1);
print '</td></tr>';
} }
// Other attributes // Other attributes
@ -981,7 +993,9 @@ else
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>'; print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
print '<td><input type="text" name="accountancy_journal" value="'.(isset($_POST["accountancy_journal"])?GETPOST("accountancy_journal"):$object->accountancy_journal).'"></td></tr>'; print '<td>';
print $formaccountancy2->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, '', 1, 1);
print '</td></tr>';
} }
print '</table>'; print '</table>';

View File

@ -160,7 +160,7 @@ class Account extends CommonObject
* @var string * @var string
*/ */
public $account_number; public $account_number;
public $accountancy_journal; public $fk_accountancy_journal;
/** /**
* Currency code * Currency code
@ -545,7 +545,7 @@ class Account extends CommonObject
$sql.= ", label"; $sql.= ", label";
$sql.= ", entity"; $sql.= ", entity";
$sql.= ", account_number"; $sql.= ", account_number";
$sql.= ", accountancy_journal"; $sql.= ", fk_accountancy_journal";
$sql.= ", bank"; $sql.= ", bank";
$sql.= ", code_banque"; $sql.= ", code_banque";
$sql.= ", code_guichet"; $sql.= ", code_guichet";
@ -569,7 +569,7 @@ class Account extends CommonObject
$sql.= ", '".$this->db->escape($this->label)."'"; $sql.= ", '".$this->db->escape($this->label)."'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", '".$this->db->escape($this->account_number)."'"; $sql.= ", '".$this->db->escape($this->account_number)."'";
$sql.= ", '".$this->db->escape($this->accountancy_journal)."'"; $sql.= ", '".$this->db->escape($this->fk_accountancy_journal)."'";
$sql.= ", '".$this->db->escape($this->bank)."'"; $sql.= ", '".$this->db->escape($this->bank)."'";
$sql.= ", '".$this->code_banque."'"; $sql.= ", '".$this->code_banque."'";
$sql.= ", '".$this->code_guichet."'"; $sql.= ", '".$this->code_guichet."'";
@ -702,7 +702,7 @@ class Account extends CommonObject
$sql.= ",rappro = ".$this->rappro; $sql.= ",rappro = ".$this->rappro;
$sql.= ",url = ".($this->url?"'".$this->url."'":"null"); $sql.= ",url = ".($this->url?"'".$this->url."'":"null");
$sql.= ",account_number = '".$this->account_number."'"; $sql.= ",account_number = '".$this->account_number."'";
$sql.= ",accountancy_journal = '".$this->accountancy_journal."'"; $sql.= ",fk_accountancy_journal = '".$this->fk_accountancy_journal."'";
$sql.= ",bank = '".$this->db->escape($this->bank)."'"; $sql.= ",bank = '".$this->db->escape($this->bank)."'";
$sql.= ",code_banque='".$this->code_banque."'"; $sql.= ",code_banque='".$this->code_banque."'";
@ -847,7 +847,7 @@ class Account extends CommonObject
$sql = "SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,"; $sql = "SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
$sql.= " ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,"; $sql.= " ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
$sql.= " ba.domiciliation, ba.proprio, ba.owner_address, ba.state_id, ba.fk_pays as country_id,"; $sql.= " ba.domiciliation, ba.proprio, ba.owner_address, ba.state_id, ba.fk_pays as country_id,";
$sql.= " ba.account_number, ba.accountancy_journal, ba.currency_code,"; $sql.= " ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
$sql.= " ba.min_allowed, ba.min_desired, ba.comment,"; $sql.= " ba.min_allowed, ba.min_desired, ba.comment,";
$sql.= " ba.datec as date_creation, ba.tms as date_update,"; $sql.= " ba.datec as date_creation, ba.tms as date_update,";
$sql.= ' c.code as country_code, c.label as country,'; $sql.= ' c.code as country_code, c.label as country,';
@ -897,7 +897,7 @@ class Account extends CommonObject
$this->country = $obj->country; $this->country = $obj->country;
$this->account_number = $obj->account_number; $this->account_number = $obj->account_number;
$this->accountancy_journal = $obj->accountancy_journal; $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
$this->currency_code = $obj->currency_code; $this->currency_code = $obj->currency_code;
$this->account_currency_code = $obj->currency_code; $this->account_currency_code = $obj->currency_code;
@ -1259,7 +1259,7 @@ class Account extends CommonObject
include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
$langs->load("accountancy"); $langs->load("accountancy");
$label .= '<br><b>' . $langs->trans('AccountAccounting') . ':</b> ' . length_accountg($this->account_number); $label .= '<br><b>' . $langs->trans('AccountAccounting') . ':</b> ' . length_accountg($this->account_number);
$label .= '<br><b>' . $langs->trans('AccountancyJournal') . ':</b> ' . $this->accountancy_journal; $label .= '<br><b>' . $langs->trans('AccountancyJournal') . ':</b> ' . $this->fk_accountancy_journal;
} }
$linkclose = '" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; $linkclose = '" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';

View File

@ -29,6 +29,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
$langs->load("banks"); $langs->load("banks");
$langs->load("categories"); $langs->load("categories");
@ -88,7 +90,7 @@ $arrayfields=array(
'b.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1), 'b.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
'b.number'=>array('label'=>$langs->trans("AccountIdShort"), 'checked'=>1), 'b.number'=>array('label'=>$langs->trans("AccountIdShort"), 'checked'=>1),
'b.account_number'=>array('label'=>$langs->trans("AccountAccounting"), 'checked'=>$conf->accountancy->enabled), 'b.account_number'=>array('label'=>$langs->trans("AccountAccounting"), 'checked'=>$conf->accountancy->enabled),
'b.accountancy_journal'=>array('label'=>$langs->trans("AccountancyJournal"), 'checked'=>$conf->accountancy->enabled), 'b.fk_accountancy_journal'=>array('label'=>$langs->trans("AccountancyJournal"), 'checked'=>$conf->accountancy->enabled),
'toreconcile'=>array('label'=>$langs->trans("TransactionsToConciliate"), 'checked'=>1), 'toreconcile'=>array('label'=>$langs->trans("TransactionsToConciliate"), 'checked'=>1),
'b.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), 'b.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
'b.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), 'b.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
@ -141,7 +143,7 @@ $title=$langs->trans('BankAccounts');
// Load array of financial accounts (opened by default) // Load array of financial accounts (opened by default)
$accounts = array(); $accounts = array();
$sql = "SELECT rowid, label, courant, rappro, account_number, accountancy_journal, datec as date_creation, tms as date_update"; $sql = "SELECT rowid, label, courant, rappro, account_number, fk_accountancy_journal, datec as date_creation, tms as date_update";
// Add fields from extrafields // Add fields from extrafields
foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
// Add fields from hooks // Add fields from hooks
@ -323,7 +325,7 @@ if (! empty($arrayfields['b.account_number']['checked']))
print '</td>'; print '</td>';
} }
// Accountancy journal // Accountancy journal
if (! empty($arrayfields['b.accountancy_journal']['checked'])) if (! empty($arrayfields['b.fk_accountancy_journal']['checked']))
{ {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '</td>'; print '</td>';
@ -403,7 +405,7 @@ if (! empty($arrayfields['b.label']['checked'])) print_liste_field_titr
if (! empty($arrayfields['accountype']['checked'])) print_liste_field_titre($arrayfields['accountype']['label'],$_SERVER["PHP_SELF"],'','',$param,'',$sortfield,$sortorder); if (! empty($arrayfields['accountype']['checked'])) print_liste_field_titre($arrayfields['accountype']['label'],$_SERVER["PHP_SELF"],'','',$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['b.number']['checked'])) print_liste_field_titre($arrayfields['b.number']['label'],$_SERVER["PHP_SELF"],'b.number','',$param,'',$sortfield,$sortorder); if (! empty($arrayfields['b.number']['checked'])) print_liste_field_titre($arrayfields['b.number']['label'],$_SERVER["PHP_SELF"],'b.number','',$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['b.account_number']['checked'])) print_liste_field_titre($arrayfields['b.account_number']['label'],$_SERVER["PHP_SELF"],'b.account_number','',$param,'',$sortfield,$sortorder); if (! empty($arrayfields['b.account_number']['checked'])) print_liste_field_titre($arrayfields['b.account_number']['label'],$_SERVER["PHP_SELF"],'b.account_number','',$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['b.accountancy_journal']['checked'])) print_liste_field_titre($arrayfields['b.accountancy_journal']['label'],$_SERVER["PHP_SELF"],'b.accountancy_journal','',$param,'',$sortfield,$sortorder); if (! empty($arrayfields['b.fk_accountancy_journal']['checked'])) print_liste_field_titre($arrayfields['b.fk_accountancy_journal']['label'],$_SERVER["PHP_SELF"],'b.fk_accountancy_journal','',$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['toreconcile']['checked'])) print_liste_field_titre($arrayfields['toreconcile']['label'],$_SERVER["PHP_SELF"],'','',$param,'align="center"',$sortfield,$sortorder); if (! empty($arrayfields['toreconcile']['checked'])) print_liste_field_titre($arrayfields['toreconcile']['label'],$_SERVER["PHP_SELF"],'','',$param,'align="center"',$sortfield,$sortorder);
// Extra fields // Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
@ -488,15 +490,22 @@ foreach ($accounts as $key=>$type)
if (! empty($arrayfields['b.account_number']['checked'])) if (! empty($arrayfields['b.account_number']['checked']))
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
print '<td>'.length_accountg($acc->account_number).'</td>';
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('',$acc->account_number);
print '<td>'.length_accountg($accountingaccount->getNomUrl(0,1,1,'',1)).'</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
// Accountancy journal // Accountancy journal
if (! empty($arrayfields['b.accountancy_journal']['checked'])) if (! empty($arrayfields['b.fk_accountancy_journal']['checked']))
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; $accountingjournal = new AccountingJournal($db);
print '<td>'.length_accountg($acc->accountancy_journal).'</td>'; $accountingjournal->fetch($acc->fk_accountancy_journal);
print '<td>'.$accountingjournal->getNomUrl(0,1,1,'',1).'</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }

View File

@ -89,7 +89,7 @@ $variousstatic = new PaymentVarious($db);
$accountstatic = new Account($db); $accountstatic = new Account($db);
$sql = "SELECT v.rowid, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank,"; $sql = "SELECT v.rowid, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank,";
$sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.accountancy_journal, ba.label as blabel,"; $sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,";
$sql.= " pst.code as payment_code"; $sql.= " pst.code as payment_code";
$sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
@ -217,7 +217,7 @@ if ($result)
$accountstatic->ref=$obj->bref; $accountstatic->ref=$obj->bref;
$accountstatic->number=$obj->bnumber; $accountstatic->number=$obj->bnumber;
$accountstatic->accountancy_number=$obj->account_number; $accountstatic->accountancy_number=$obj->account_number;
$accountstatic->accountancy_journal=$obj->accountancy_journal; $accountstatic->fk_accountancy_journal=$obj->fk_accountancy_journal;
$accountstatic->label=$obj->blabel; $accountstatic->label=$obj->blabel;
print $accountstatic->getNomUrl(1); print $accountstatic->getNomUrl(1);
} }

View File

@ -25,12 +25,14 @@
/** /**
* Class to manage generation of HTML components for accounting management * Class to manage generation of HTML components for accounting management
*/ */
class FormAccounting class FormAccounting extends Form
{ {
private $options_cache = array();
var $db; var $db;
var $error; var $error;
/** /**
* Constructor * Constructor
* *
@ -41,6 +43,89 @@ class FormAccounting
$this->db = $db; $this->db = $db;
} }
/**
* Return list of journals with label by nature
*
* @param string $selectid Preselected pcg_type
* @param string $htmlname Name of field in html form
* @param int $nature Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new)
* @param int $showempty Add an empty field
* @param array $event Event options
* @param int $select_in 0=selectid value is the journal rowid (default) or 1=selectid is journal code
* @param int $select_out Set value returned by select. 0=rowid (default), 1=code
* @param string $morecss More css non HTML object
* @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache.
*
* @return string String with HTML select
*/
function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='')
{
global $conf;
$out = '';
$options = array();
if ($usecache && ! empty($this->options_cache[$usecache]))
{
$options = $this->options_cache[$usecache];
$selected=$selectid;
}
else
{
$sql = "SELECT rowid, code, label, nature, entity, active";
$sql.= " FROM " . MAIN_DB_PREFIX . "accounting_journal";
$sql.= " WHERE active = 1";
$sql.= " AND entity = ".$conf->entity;
//if ($nature && is_numeric($nature)) $sql .= " AND nature = ".$nature;
$sql.= " ORDER BY code";
dol_syslog(get_class($this) . "::select_journal", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$this->error = "Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::select_journal ".$this->error, LOG_ERR);
return -1;
}
$out = ajax_combobox($htmlname, $event);
$selected = 0;
while ($obj = $this->db->fetch_object($resql))
{
$label = $obj->code . ' - ' . $obj->label;
$select_value_in = $obj->rowid;
$select_value_out = $obj->rowid;
// Try to guess if we have found default value
if ($select_in == 1) {
$select_value_in = $obj->code;
}
if ($select_out == 1) {
$select_value_out = $obj->code;
}
// Remember guy's we store in database llx_accounting_bookkeeping the code of accounting_journal and not the rowid
if ($selectid != '' && $selectid == $select_value_in) {
//var_dump("Found ".$selectid." ".$select_value_in);
$selected = $select_value_out;
}
$options[$select_value_out] = $label;
}
$this->db->free($resql);
if ($usecache)
{
$this->options_cache[$usecache] = $options;
}
}
$out .= Form::selectarray($htmlname, $options, $select, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
return $out;
}
/** /**
* Return list of accounting category. * Return list of accounting category.
* Use mysoc->country_id or mysoc->country_code so they must be defined. * Use mysoc->country_id or mysoc->country_code so they must be defined.

View File

@ -264,4 +264,11 @@ UPDATE llx_accounting_journal SET nature = 3 where code = 'AC' and nature = 2;
UPDATE llx_accounting_journal SET nature = 4 where (code = 'BK' or code = 'BQ') and nature = 3; UPDATE llx_accounting_journal SET nature = 4 where (code = 'BK' or code = 'BQ') and nature = 3;
ALTER TABLE llx_bank_account CHANGE COLUMN accountancy_journal fk_accountancy_journal integer;
--ALTER TABLE llx_bank_account ADD CONSTRAINT bank_fk_accountancy_journal FOREIGN KEY (fk_accountancy_journal) REFERENCES llx_accounting_journal (rowid);

View File

@ -23,6 +23,6 @@ create table llx_accounting_journal
entity integer DEFAULT 1, entity integer DEFAULT 1,
code varchar(32) NOT NULL, code varchar(32) NOT NULL,
label varchar(128) NOT NULL, label varchar(128) NOT NULL,
nature smallint DEFAULT 0 NOT NULL, -- type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new) nature smallint DEFAULT 1 NOT NULL, -- type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new)
active smallint DEFAULT 0 active smallint DEFAULT 0
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -19,3 +19,5 @@
ALTER TABLE llx_bank_account ADD UNIQUE uk_bank_account_label (label,entity); ALTER TABLE llx_bank_account ADD UNIQUE uk_bank_account_label (label,entity);
-- ALTER TABLE llx_bank_account ADD CONSTRAINT bank_fk_accountancy_journal FOREIGN KEY (fk_accountancy_journal) REFERENCES llx_accounting_journal (rowid);

View File

@ -51,7 +51,7 @@ create table llx_bank_account
rappro smallint DEFAULT 1, rappro smallint DEFAULT 1,
url varchar(128), url varchar(128),
account_number varchar(32), -- bank accountancy number account_number varchar(32), -- bank accountancy number
accountancy_journal varchar(16) DEFAULT NULL, -- bank accountancy journal fk_accountancy_journal integer, -- bank accountancy journal
currency_code varchar(3) NOT NULL, currency_code varchar(3) NOT NULL,
min_allowed integer DEFAULT 0, min_allowed integer DEFAULT 0,
min_desired integer DEFAULT 0, min_desired integer DEFAULT 0,

View File

@ -61,7 +61,8 @@ ChangeAndLoad=Change and load
Addanaccount=Add an accounting account Addanaccount=Add an accounting account
AccountAccounting=Accounting account AccountAccounting=Accounting account
AccountAccountingShort=Account AccountAccountingShort=Account
ShowAccoutingAccount=Show accounting account ShowAccountingAccount=Show accounting account
ShowAccountingJournal=Show accounting journal
AccountAccountingSuggest=Accounting account suggested AccountAccountingSuggest=Accounting account suggested
MenuDefaultAccounts=Default accounts MenuDefaultAccounts=Default accounts
MenuVatAccounts=Vat accounts MenuVatAccounts=Vat accounts