Maxi debug of accountancy expert module

This commit is contained in:
Laurent Destailleur 2016-10-04 19:31:05 +02:00
parent 1e3038d634
commit 31ce725d73
8 changed files with 370 additions and 183 deletions

View File

@ -210,11 +210,16 @@ if ($action == 'delbookkeepingyearconfirm') {
$deljournal=0;
}
if (! empty($delyear) || ! empty($deljournal)) {
if (! empty($delyear) || ! empty($deljournal))
{
$result = $object->deleteByYearAndJournal($delyear,$deljournal);
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
setEventMessages("RecordDeleted", null, 'mesgs');
}
Header("Location: list.php");
exit;
}

View File

@ -116,7 +116,6 @@ class BookKeeping extends CommonObject
$error = 0;
// Clean parameters
if (isset($this->doc_type)) {
$this->doc_type = trim($this->doc_type);
}
@ -163,6 +162,14 @@ class BookKeeping extends CommonObject
$this->piece_num = trim($this->piece_num);
}
// Check parameters
if (empty($this->numero_compte))
{
$this->errors[]='ErrorFieldAccountNotDefined';
return -1;
}
$this->db->begin();
$this->piece_num = 0;
@ -174,7 +181,6 @@ class BookKeeping extends CommonObject
$sql .= " AND fk_docdet = " . $this->fk_docdet;
$sql .= " AND numero_compte = '" . $this->numero_compte . "'";
dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
@ -274,11 +280,11 @@ class BookKeeping extends CommonObject
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
}
} else {
$result = - 3;
$error ++;
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
} else { // Already exists
$result = -3;
$error++;
$this->errors[] = 'Error Transaction for ('.$this->doc_type.', '.$this->doc_ref.', '.$this->fk_docdet.') were already recorded';
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_WARNING);
}
} else {
$result = - 5;
@ -1012,7 +1018,7 @@ class BookKeeping extends CommonObject
/**
* Delete bookkepping by importkey
*
* @param string $importkey Import key
* @param string $importkey Import key
* @return int Result
*/
function deleteByImportkey($importkey) {
@ -1027,10 +1033,7 @@ class BookKeeping extends CommonObject
if (! $resql) {
$this->errors[] = "Error " . $this->db->lasterror();
foreach ( $this->errors as $errmsg ) {
dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
}
dol_syslog(get_class($this)."::delete Error " . $this->db->lasterror(), LOG_ERR);
$this->db->rollback();
return - 1;
}
@ -1042,17 +1045,24 @@ class BookKeeping extends CommonObject
/**
* Delete bookkepping by year
*
* @param string $delyear year to delete
* @return int Result
* @param string $delyear Year to delete
* @param string $journal Journal to delete
* @return int Result
*/
function deleteByYear($delyear) {
function deleteByYearAndJournal($delyear='', $journal='') {
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 YEAR(doc_date) = " . $delyear;
$sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql.= " WHERE 1 = 1";
if ($delyear) $sql.= " AND YEAR(doc_date) = " . $delyear; // FIXME Must use between
if ($journal) $sql.= " AND code_journal = ".$journal;
$resql = $this->db->query($sql);
if (! $resql) {
@ -1062,7 +1072,7 @@ class BookKeeping extends CommonObject
$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
}
$this->db->rollback();
return - 1;
return -1;
}
$this->db->commit();

View File

@ -42,6 +42,7 @@ require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT . '/don/class/paymentdonation.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/salaries/class/paymentsalary.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php';
@ -73,9 +74,13 @@ $now = dol_now();
if ($user->societe_id > 0 && empty($id_bank_account))
accessforbidden();
/*
* View
*/
$error = 0;
$year_current = strftime("%Y", dol_now());
$pastmonth = strftime("%m", dol_now()) - 1;
$pastmonthyear = $year_current;
@ -96,8 +101,9 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
$p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
$idpays = $p[0];
$sql = "SELECT b.rowid , b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, soc.code_compta, ba.courant,";
$sql .= " soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, ba.account_number, bu1.type as typeop";
$sql = "SELECT b.rowid , b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, soc.code_compta,";
$sql .= " ba.courant, ba.ref as baref, ba.account_number,";
$sql .= " soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop";
$sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
@ -138,28 +144,33 @@ if ($result) {
$account_pay_donation = (! empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT : $langs->trans("CodeNotDef"));
$account_transfer = (! empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH : $langs->trans("CodeNotDef"));
$tabcompany = array();
$tabpay = array ();
$tabbq = array ();
$tabtp = array ();
$tabtype = array ();
// Loop on each line into bank account. For each line, we should get:
// on line tabpay = line into bank
// one line for bank jounral = tabbq
// one line for thirdparty journal = tabtp
$i = 0;
while ( $i < $num ) {
$obj = $db->fetch_object($result);
$tabcompany[$obj->rowid] = array (
'id' => $obj->socid,
'name' => $obj->name,
'code_client' => $obj->code_compta
);
// Controls
// Set accountancy code (for bank and thirdparty)
$compta_bank = $obj->account_number;
if ($obj->label == '(SupplierInvoicePayment)')
$compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $account_supplier);
if ($obj->label == '(CustomerInvoicePayment)')
$compta_soc = (! empty($obj->code_compta) ? $obj->code_compta : $account_customer);
$tabcompany[$obj->rowid] = array (
'id' => $obj->socid,
'name' => $obj->name,
'code_compta' => $compta_soc,
);
// Variable bookkeeping
$tabpay[$obj->rowid]["date"] = $obj->do;
$tabpay[$obj->rowid]["type_payment"] = $obj->fk_type;
@ -174,16 +185,24 @@ if ($result) {
// get_url may return -1 which is not traversable
if (is_array($links)) {
// Now loop on each link of record in bank.
foreach ( $links as $key => $val ) {
$tabtype[$obj->rowid] = $links[$key]['type'];
if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat'))) // So we excluded 'company' here
{
// We save tabtype for a future use, to remember what kind of payment it is
$tabtype[$obj->rowid] = $links[$key]['type'];
}
if ($links[$key]['type'] == 'payment') {
$paymentstatic->id = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2);
$tabpay[$obj->rowid]["paymentid"] = $paymentstatic->id;
} else if ($links[$key]['type'] == 'payment_supplier') {
$paymentsupplierstatic->id = $links[$key]['url_id'];
$paymentsupplierstatic->ref = $links[$key]['url_id'];
$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
$tabpay[$obj->rowid]["paymentsupplierid"] = $paymentsupplierstatic->id;
} else if ($links[$key]['type'] == 'company') {
$societestatic->id = $links[$key]['url_id'];
$societestatic->name = $links[$key]['label'];
@ -248,6 +267,26 @@ if ($result) {
$tabbq[$obj->rowid][$compta_bank] += $obj->amount;
// Check account number is ok
/*if ($action == 'writebookkeeping') // Make test now in such a case
{
reset($tabbq[$obj->rowid]);
$first_key_tabbq = key($tabbq[$obj->rowid]);
if (empty($first_key_tabbq))
{
$error++;
setEventMessages($langs->trans('ErrorAccountancyCodeOnBankAccountNotDefined', $obj->baref), null, 'errors');
}
reset($tabtp[$obj->rowid]);
$first_key_tabtp = key($tabtp[$obj->rowid]);
if (empty($first_key_tabtp))
{
$error++;
setEventMessages($langs->trans('ErrorAccountancyCodeOnThirdPartyNotDefined'), null, 'errors');
}
}*/
// if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
$i ++;
@ -256,150 +295,182 @@ if ($result) {
dol_print_error($db);
}
/*
var_dump($tabpay);
var_dump($tabbq);
var_dump($tabtp);
*/
/*
* Actions
*/
// Write bookkeeping
if ($action == 'writebookkeeping') {
if (! $error && $action == 'writebookkeeping') {
$now = dol_now();
$error = 0;
foreach ( $tabpay as $key => $val ) {
foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank
$errorforline = 0;
$db->begin();
// Bank
foreach ( $tabbq[$key] as $k => $mt ) {
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"];
$bookkeeping->doc_type = 'bank';
$bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_bank"];
$bookkeeping->code_tiers = $tabcompany[$key]['code_client'];
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $compte->label;
$bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
$bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
$bookkeeping->debit = ($mt >= 0 ? $mt : 0);
$bookkeeping->credit = ($mt < 0 ? - $mt : 0);
$bookkeeping->code_journal = $journal;
$bookkeeping->fk_user_author = $user->id;
$bookkeeping->date_create = $now;
if ($tabtype[$key] == 'payment') {
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sqlmid .= " WHERE pay.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
} else if ($tabtype[$key] == 'payment_supplier') {
$sqlmid = 'SELECT facf.ref_supplier,facf.ref';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
$sqlmid .= " WHERE payf.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')';
}
}
$result = $bookkeeping->create($user);
if ($result < 0) {
$error ++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
if (! $errorforline)
{
// Line into bank account
foreach ( $tabbq[$key] as $k => $mt ) {
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"];
$bookkeeping->doc_type = 'bank';
$bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_bank"];
$bookkeeping->numero_compte = $k;
$bookkeeping->label_compte = $compte->label;
$bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
$bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
$bookkeeping->debit = ($mt >= 0 ? $mt : 0);
$bookkeeping->credit = ($mt < 0 ? - $mt : 0);
$bookkeeping->code_journal = $journal;
$bookkeeping->fk_user_author = $user->id;
$bookkeeping->date_create = $now;
if ($tabtype[$key] == 'payment') {
$bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sqlmid .= " WHERE pay.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber; // Ref of invoice
}
} else if ($tabtype[$key] == 'payment_supplier') {
$bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
$sqlmid = 'SELECT facf.ref_supplier, facf.ref';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
$sqlmid .= " WHERE payf.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; // Ref on invoice
}
}
$result = $bookkeeping->create($user);
if ($result < 0) {
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
}
// Third party
foreach ( $tabtp[$key] as $k => $mt ) {
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"];
$bookkeeping->doc_type = 'bank';
$bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_bank"];
$bookkeeping->label_compte = $tabcompany[$key]['name'];
$bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
$bookkeeping->debit = ($mt < 0 ? - $mt : 0);
$bookkeeping->credit = ($mt >= 0) ? $mt : 0;
$bookkeeping->code_journal = $journal;
$bookkeeping->fk_user_author = $user->id;
$bookkeeping->date_create = $now;
if ($tabtype[$key] == 'sc') {
$bookkeeping->code_tiers = '';
$bookkeeping->numero_compte = $k;
} else if ($tabtype[$key] == 'payment') {
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sqlmid .= " WHERE pay.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
$bookkeeping->code_tiers = $k;
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
} else if ($tabtype[$key] == 'payment_supplier') {
$sqlmid = 'SELECT facf.ref_supplier,facf.ref';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
$sqlmid .= " WHERE payf.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')';
}
$bookkeeping->code_tiers = $k;
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
} else if ($tabtype[$key] == 'company') {
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sqlmid .= " WHERE pay.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
$bookkeeping->code_tiers = $k;
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
} else {
$bookkeeping->doc_ref = $k;
$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
}
$result = $bookkeeping->create($user);
if ($result < 0) {
$error ++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
if (! $errorforline)
{
// Line into thirdparty account
foreach ( $tabtp[$key] as $k => $mt ) {
$bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"];
$bookkeeping->doc_ref = $val["ref"];
$bookkeeping->doc_type = 'bank';
$bookkeeping->fk_doc = $key;
$bookkeeping->fk_docdet = $val["fk_bank"];
$bookkeeping->label_compte = $tabcompany[$key]['name'];
$bookkeeping->montant = ($mt < 0 ? - $mt : $mt);
$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
$bookkeeping->debit = ($mt < 0 ? - $mt : 0);
$bookkeeping->credit = ($mt >= 0) ? $mt : 0;
$bookkeeping->code_journal = $journal;
$bookkeeping->fk_user_author = $user->id;
$bookkeeping->date_create = $now;
if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution
$bookkeeping->code_tiers = '';
$bookkeeping->numero_compte = $k;
} else if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid";
$sqlmid .= " WHERE pay.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->facnumber;
}
// FIXME Should be
//$bookkeeping->code_tiers = $k;
//$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
$bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
$bookkeeping->numero_compte = $k;
} else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice
$sqlmid = 'SELECT facf.ref_supplier,facf.ref';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid";
$sqlmid .= " WHERE payf.fk_bank=" . $key;
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')';
}
// FIXME Should be
//$bookkeeping->code_tiers = $k;
//$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
$bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
$bookkeeping->numero_compte = $k;
} else {
// FIXME Should be a temporary account
$bookkeeping->doc_ref = $k;
//$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
$bookkeeping->numero_compte = 'CodeNotDef';
}
$result = $bookkeeping->create($user);
if ($result < 0) {
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
}
if (! $errorforline)
{
$db->commit();
}
else
{
$db->rollback();
}
}
if (empty($error)) {
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
}
elseif (count($tabpay) == $error)
{
setEventMessages($langs->trans("NoRecordSaved"), null, 'warnings');
}
else
{
setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
}
}
// Export
@ -437,7 +508,6 @@ if ($action == 'export_csv') {
$companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name'];
$companystatic->client = $tabcompany[$key]['code_client'];
// Bank
foreach ( $tabbq[$key] as $k => $mt ) {
@ -564,7 +634,9 @@ if ($action == 'export_csv') {
}
else {
$form = new Form($db);
$invoicestatic = new Facture($db);
$invoicesupplierstatic = new FactureFournisseur($db);
llxHeader('', $langs->trans("FinanceJournal"));
$nom = $langs->trans("FinanceJournal") . ' - ' . $bank_code_journal->getNomUrl(1);
@ -609,7 +681,7 @@ else {
print "<tr class=\"liste_titre\">";
print "<td>" . $langs->trans("Date") . "</td>";
print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
print "<td>" . $langs->trans("Account") . "</td>";
print "<td>" . $langs->trans("AccountAccounting") . "</td>";
print "<td>" . $langs->trans("Type") . "</td>";
print "<td>" . $langs->trans("PaymentMode") . "</td>";
print "<td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>";
@ -618,9 +690,9 @@ else {
$var = true;
$r = '';
foreach ( $tabpay as $key => $val ) {
foreach ( $tabpay as $key => $val ) { // $key is rowid in llx_bank
$date = dol_print_date($db->jdate($val["date"]), 'day');
$reflabel = $val["ref"];
if ($reflabel == '(SupplierInvoicePayment)') {
$reflabel = $langs->trans('Supplier');
@ -637,10 +709,45 @@ else {
if ($reflabel == '(SubscriptionPayment)') {
$reflabel = $langs->trans('SubscriptionPayment');
}
$ref=$reflabel;
if ($tabtype[$key] == 'payment')
{
$sqlmid = 'SELECT payfac.fk_facture as id';
$sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac";
$sqlmid .= " WHERE payfac.fk_paiement=" . $val["paymentid"];
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$invoicestatic->fetch($objmid->id);
$ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
}
else dol_print_error($db);
}
elseif ($tabtype[$key] == 'payment_supplier')
{
$sqlmid = 'SELECT payfac.fk_facturefourn as id';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfac";
$sqlmid .= " WHERE payfac.fk_paiementfourn=" . $val["paymentsupplierid"];
dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
$resultmid = $db->query($sqlmid);
if ($resultmid) {
$objmid = $db->fetch_object($resultmid);
$invoicesupplierstatic->fetch($objmid->id);
$ref=$langs->trans("SupplierInvoice").' '.$invoicesupplierstatic->getNomUrl(1);
}
else dol_print_error($db);
}
/*$invoicestatic->id = $key;
$invoicestatic->ref = $val["ref"];
$invoicestatic->type = $val["type"];*/
// Bank
foreach ( $tabbq[$key] as $k => $mt ) {
print "<tr " . $bc[$var] . ">";
print "<tr " . $bc[$var] . ">";
print "<td>" . $date . "</td>";
print "<td>" . $ref . "</td>";
print "<td>" . length_accountg($k) . "</td>";
@ -690,4 +797,5 @@ else {
llxFooter();
}
$db->close();

View File

@ -168,6 +168,10 @@ if ($action == 'writebookkeeping') {
foreach ($tabfac as $key => $val)
{
$errorforline = 0;
$db->begin();
$companystatic = new Societe($db);
$invoicestatic = new FactureFournisseur($db);
@ -203,8 +207,9 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user);
if ($result < 0) {
$error ++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
@ -235,7 +240,8 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user);
if ($result < 0) {
$error ++;
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
@ -266,15 +272,36 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user);
if ($result < 0) {
$error ++;
$error++;
$errorforline++;
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
if (! $errorforline)
{
$db->commit();
}
else
{
$db->rollback();
}
}
if (empty($error)) {
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
}
elseif (count($tabpay) == $error)
{
setEventMessages($langs->trans("NoRecordSaved"), null, 'warnings');
}
else
{
setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
}
}
@ -458,7 +485,7 @@ if ($action == 'export_csv') {
// /print "<td>".$langs->trans("JournalNum")."</td>";
print "<td>" . $langs->trans("Date") . "</td>";
print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
print "<td>" . $langs->trans("Account") . "</td>";
print "<td>" . $langs->trans("AccountAccounting") . "</td>";
print "<t><td>" . $langs->trans("Type") . "</td><td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>";
print "</tr>\n";

View File

@ -198,7 +198,11 @@ if ($action == 'writebookkeeping') {
$error = 0;
foreach ( $tabfac as $key => $val ) {
$errorforline = 0;
$db->begin();
$companystatic = new Societe($db);
$invoicestatic = new Facture($db);
@ -230,7 +234,8 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user);
if ($result < 0) {
$error ++;
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
@ -260,7 +265,8 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user);
if ($result < 0) {
$error ++;
$error++;
$errorforline++;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
}
}
@ -290,15 +296,35 @@ if ($action == 'writebookkeeping') {
$result = $bookkeeping->create($user);
if ($result < 0) {
$error ++;
$error++;
$errorforline++;
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
if (! $errorforline)
{
$db->commit();
}
else
{
$db->rollback();
}
}
if (empty($error)) {
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
}
elseif (count($tabpay) == $error)
{
setEventMessages($langs->trans("NoRecordSaved"), null, 'warnings');
}
else
{
setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
}
}
@ -475,7 +501,7 @@ if ($action == 'export_csv') {
print "<tr class=\"liste_titre\">";
print "<td>" . $langs->trans("Date") . "</td>";
print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
print "<td>" . $langs->trans("Account") . "</td>";
print "<td>" . $langs->trans("AccountAccounting") . "</td>";
print "<td>" . $langs->trans("Type") . "</td>";
print "<td align='right'>" . $langs->trans("Debit") . "</td>";
print "<td align='right'>" . $langs->trans("Credit") . "</td>";

View File

@ -1183,14 +1183,18 @@ class Account extends CommonObject
*/
function getNomUrl($withpicto=0, $mode='')
{
global $langs;
global $conf, $langs;
$result='';
$label = '<u>' . $langs->trans("ShowAccount") . '</u>';
if (! empty($this->label))
$label .= '<br><b>' . $langs->trans('Account') . ':</b> ' . $this->label;
if (! empty($this->number))
$label .= '<br><b>' . $langs->trans('AccountNumber') . ':</b> ' . $this->number;
$label .= '<br><b>' . $langs->trans('BankAccount') . ':</b> ' . $this->label;
$label .= '<br><b>' . $langs->trans('AccountNumber') . ':</b> ' . $this->number;
if (! empty($conf->accounting->enabled))
{
$langs->load("accountancy");
$label .= '<br><b>' . $langs->trans('AccountAccounting') . ':</b> ' . $this->account_number;
$label .= '<br><b>' . $langs->trans('AccountancyJournal') . ':</b> ' . $this->accountancy_journal;
}
$linkclose = '" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
if (empty($mode))

View File

@ -121,6 +121,10 @@ create table llx_product_warehouse_properties
)ENGINE=innodb;
ALTER TABLE llx_accounting_bookkeeping ADD COLUMN entity integer DEFAULT 1 NOT NULL;
ALTER TABLE llx_accounting_bookkeeping ADD COLUMN fk_user_modif integer;
ALTER TABLE llx_accounting_bookkeeping ADD COLUMN date_creation datetime;
ALTER TABLE llx_accounting_bookkeeping ADD COLUMN tms timestamp;
ALTER TABLE llx_accounting_account ADD INDEX uk_accounting_account (account_number, entity);

View File

@ -33,7 +33,10 @@ CREATE TABLE llx_accounting_bookkeeping
credit double NOT NULL,
montant double NOT NULL,
sens varchar(1) DEFAULT NULL,
fk_user_author integer NOT NULL,
fk_user_author integer NOT NULL, -- user creating
fk_user_modif integer, -- user making last change
date_creation datetime, -- date de creation
tms timestamp, -- date last modification
import_key varchar(14),
code_journal varchar(10) DEFAULT NULL,
piece_num integer NOT NULL,