Try to debug the transfer in treasury mode. Move into DEBUG level.

Still some tests to do...
This commit is contained in:
ldestailleur
2025-04-11 20:12:16 +02:00
parent a18284b829
commit eadf6182e1
6 changed files with 141 additions and 87 deletions

View File

@@ -430,30 +430,32 @@ if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
print '<br>';
// case of the parameter ACCOUNTING_MODE
// Case of the parameter ACCOUNTING_MODE
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="updatemode">';
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="updatemode">';
print '<table class="noborder centpercent">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans('OptionMode').'</td>';
print "</tr>\n";
print '<tr class="oddeven"><td class="nowraponall"><input type="radio" id="accounting_mode_1" name="accounting_mode" value="RECETTES-DEPENSES"'.($accounting_mode != 'CREANCES-DETTES' ? ' checked' : '').'><label for="accounting_mode_1"> '.$langs->trans('OptionModeTrue').'</label></td>';
print '<td><span class="opacitymedium">'.nl2br($langs->trans('ACCOUNTING_USE_TREASURY_Desc')).'</span>';
print "</td></tr>\n";
print '<tr class="oddeven"><td class="nowraponall"><input type="radio" id="accounting_mode_2" name="accounting_mode" value="CREANCES-DETTES"'.($accounting_mode == 'CREANCES-DETTES' ? ' checked' : '').'><label for="accounting_mode_2"> '.$langs->trans('OptionModeVirtual').'</label></td>';
print '<td><span class="opacitymedium">'.nl2br($langs->trans('ACCOUNTING_USE_NON_TREASURY_Desc'))."</span></td></tr>\n";
print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans('OptionMode').'</td>';
print "</tr>\n";
print '<tr class="oddeven"><td class="nowraponall"><input type="radio" id="accounting_mode_1" name="accounting_mode" value="RECETTES-DEPENSES"'.($accounting_mode != 'CREANCES-DETTES' ? ' checked' : '').'><label for="accounting_mode_1"> '.$langs->trans('OptionModeTrue').'</label></td>';
print '<td><span class="opacitymedium">'.nl2br($langs->trans('ACCOUNTING_USE_TREASURY_Desc')).'</span>';
print "</td></tr>\n";
print '<tr class="oddeven"><td class="nowraponall"><input type="radio" id="accounting_mode_2" name="accounting_mode" value="CREANCES-DETTES"'.($accounting_mode == 'CREANCES-DETTES' ? ' checked' : '').'><label for="accounting_mode_2"> '.$langs->trans('OptionModeVirtual').'</label></td>';
print '<td><span class="opacitymedium">'.nl2br($langs->trans('ACCOUNTING_USE_NON_TREASURY_Desc'))."</span></td></tr>\n";
print "</table>\n";
print "</table>\n";
print '<div style="text-align:center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
print '</form>';
print '<div style="text-align:center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
print '</form>';
print '<br><br><br>';
print '<br><br><br>';
}
// Show form main options

View File

@@ -74,7 +74,7 @@ require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
// Load translation files required by the page
$langs->loadLangs(array("companies", "other", "compta", "banks", "bills", "donations", "loan", "accountancy", "trips", "salaries", "hrm", "members"));
// Multi journal&search_status=-1
// Multi journal
$id_journal = GETPOSTINT('id_journal');
$date_startmonth = GETPOSTINT('date_startmonth');
@@ -144,6 +144,8 @@ if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))
$date_end = dol_get_last_day((int) $pastmonthyear, (int) $pastmonth, false);
}
// Get all bank lines
//-------------------------------------
$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.amount_main_currency, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account,";
$sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
$sql .= " soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,";
@@ -161,19 +163,19 @@ if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
$sql .= " u.accountancy_code_user_general, u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,";
$sql .= " bu2.type as typeop_user,";
$sql .= " bu3.type as typeop_payment, bu4.type as typeop_payment_supplier";
$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'";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as soc on bu1.url_id=soc.rowid";
$sql .= " FROM ".$db->prefix()."bank as b";
$sql .= " JOIN ".$db->prefix()."bank_account as ba on b.fk_account = ba.rowid";
$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'";
$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='payment'";
$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu4 ON bu4.fk_bank = b.rowid AND bu4.type='payment_supplier'";
$sql .= " LEFT JOIN ".$db->prefix()."societe as soc on bu1.url_id=soc.rowid";
if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
$sql .= " LEFT JOIN " . $db->prefix() . "societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity);
}
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on bu2.url_id=u.rowid";
$sql .= " LEFT JOIN ".$db->prefix()."user as u on bu2.url_id=u.rowid";
$sql .= " WHERE ba.fk_accountancy_journal=".((int) $id_journal);
$sql .= ' AND b.amount <> 0 AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy
$sql .= " AND b.amount <> 0 AND ba.entity IN (".getEntity('bank_account', 0).")"; // We don't share object for accountancy
if ($date_start && $date_end) {
$sql .= " AND b.dateo >= '".$db->idate($date_start)."' AND b.dateo <= '".$db->idate($date_end)."'";
}
@@ -183,10 +185,10 @@ if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
}
// Already in bookkeeping or not
if ($in_bookkeeping == 'already') {
$sql .= " AND (b.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
$sql .= " AND (b.rowid IN (SELECT fk_doc FROM ".$db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
}
if ($in_bookkeeping == 'notyet') {
$sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
$sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM ".$db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
}
if ($only_rappro == 2) {
$sql .= " AND (b.rappro = '1')";

View File

@@ -38,10 +38,16 @@ 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.formaccounting.class.php';
global $conf, $db, $mysoc, $langs, $user;
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
// Load translation files required by the page
$langs->loadLangs(array("compta", "accountancy", "banks", "other"));
$langs->loadLangs(array("companies", "other", "compta", "banks", "bills", "donations", "loan", "accountancy", "trips", "salaries", "hrm", "members"));
// Multi journal
$id_journal = GETPOSTINT('id_journal');
@@ -53,19 +59,32 @@ $date_endmonth = GETPOSTINT('date_endmonth');
$date_endday = GETPOSTINT('date_endday');
$date_endyear = GETPOSTINT('date_endyear');
$in_bookkeeping = GETPOST('in_bookkeeping', 'aZ09');
if ($in_bookkeeping == '') {
$in_bookkeeping = 'notyet';
$only_rappro = GETPOSTINT('only_rappro');
if ($only_rappro == 0) {
//GET page for the first time, use default settings
$only_rappro = getDolGlobalInt('ACCOUNTING_BANK_CONCILIATED');
}
$now = dol_now();
$action = GETPOST('action', 'aZ09');
$socid = 0;
if ($in_bookkeeping == '') {
$in_bookkeeping = 'notyet';
}
// Security check
if ($user->socid > 0 && empty($id_journal)) {
if (!isModEnabled('accounting')) {
accessforbidden();
}
if ($user->socid > 0) {
accessforbidden();
}
if (!$user->hasRight('accounting', 'bind', 'write')) {
accessforbidden();
}
/*
* Actions
@@ -73,41 +92,61 @@ if ($user->socid > 0 && empty($id_journal)) {
$error = 0;
$pastmonth = '';
$pastmonthyear = '';
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
if (empty($date_startmonth) || empty($date_endmonth)) {
$pastmonth = null; // Initialise for static analysis (could be really unseg)
$pastmonthyear = null;
if (empty($date_startmonth)) {
// Period by default on transfer
$dates = getDefaultDatesForTransfer();
$date_start = $dates['date_start'];
$pastmonthyear = $dates['pastmonthyear'];
$pastmonth = $dates['pastmonth'];
}
if (empty($date_endmonth)) {
// Period by default on transfer
$dates = getDefaultDatesForTransfer();
$date_end = $dates['date_end'];
$pastmonthyear = $dates['pastmonthyear'];
$pastmonth = $dates['pastmonth'];
}
if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) {
// We define date_start and date_end, only if we did not submit the form
$date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
$date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form
$date_start = dol_get_first_day((int) $pastmonthyear, (int) $pastmonth, false);
$date_end = dol_get_last_day((int) $pastmonthyear, (int) $pastmonth, false);
}
// Get all bank lines
//-------------------------------------
$sql = "SELECT b.rowid, b.dateo as do, b.label, b.fk_type, b.fk_account,";
$sql .= " ba.ref as baref, ba.account_number,";
$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.amount_main_currency, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account,";
$sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,";
$sql .= " bu.type as bu_type";
$sql .= " FROM ".$db->prefix()."bank as b";
$sql .= " LEFT JOIN ".$db->prefix()."bank_account as ba on b.fk_account = ba.rowid";
$sql .= " JOIN ".$db->prefix()."bank_account as ba on b.fk_account = ba.rowid";
$sql .= " LEFT JOIN ".$db->prefix()."bank_url as bu ON bu.fk_bank = b.rowid";
$sql .= " WHERE ba.fk_accountancy_journal = ".((int) $id_journal);
$sql .= " AND ba.entity IN (".getEntity('bank_account').')'; // We don't share object for accountancy, we use source object sharing
// Filter by dates
$sql .= " AND b.amount <> 0 AND ba.entity IN (".getEntity('bank_account').")"; // We don't share object for accountancy, we use source object sharing
if ($date_start && $date_end) {
$sql .= " AND b.dateo >= '".$db->idate($date_start)."' AND b.dateo <= '".$db->idate($date_end)."'";
}
// Define begin binding date
if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
$sql .= " AND b.dateo >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
}
// Already in bookkeeping or not
if ($in_bookkeeping == 'already') {
$sql .= " AND (b.rowid IN (SELECT fk_doc FROM ".$db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
}
if ($in_bookkeeping == 'notyet') {
$sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM ".$db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='bank') )";
}
if ($only_rappro == 2) {
$sql .= " AND (b.rappro = '1')";
}
$sql .= " ORDER BY b.dateo";
//print $sql;
$result_lines = array();
@@ -171,7 +210,7 @@ if ($resql) {
$sql .= " aa.account_number as accountancy_code, aa.label as accountancy_code_label,";
$sql .= " bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
$sql .= " FROM ".$db->prefix()."facturedet as fd";
$sql .= " LEFT JOIN ".$db->prefix()."facture as f ON f.rowid = fd.fk_facture";
$sql .= " INNER JOIN ".$db->prefix()."facture as f ON f.rowid = fd.fk_facture";
$sql .= " INNER JOIN ".$db->prefix()."paiement_facture as pf ON pf.fk_facture = f.rowid";
$sql .= " INNER JOIN ".$db->prefix()."bank_url as bu ON bu.url_id = pf.fk_paiement AND bu.type = '".$db->escape($type)."'";
$sql .= " LEFT JOIN ".$db->prefix()."product as p ON p.rowid = fd.fk_product";
@@ -192,7 +231,7 @@ if ($resql) {
$sql .= " AND fd.product_type IN (0,1)";
$sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".(!getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS') ? Facture::TYPE_DEPOSIT."," : "").Facture::TYPE_SITUATION.")";
$sql .= " AND bu.fk_bank IN (".$db->sanitize(implode(',', $ids)).")";
$sql .= " GROUP BY fd.rowid, bu.fk_bank, pf.amount, bu.url_id";
$sql .= " GROUP BY fd.rowid, bu.fk_bank, pf.amount, bu.url_id"; // TODO Must never have a GROUP BY on a field if field is not inside an aggregate function.
$sql .= " ORDER BY aa.account_number";
$resql = $db->query($sql);
@@ -205,6 +244,10 @@ if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$object_key = $obj->bu_type.'_'.$obj->rowid;
// To check...
// If 1 invoice has 2 payments at 2 different date, seems ok, we have 2 record $tabpay because $obj->fk_bank is different (obj->fk_bank is ID of payment in bank record table).
// If 2 invoices are paid in the same payment, we have 2 $tabobject but also 2 $tabpay (because $object_key has 2 different values) when we should have 1.
// Add object in payment
if (!isset($tabpay[$obj->fk_bank]['objects'][$object_key])) {
$tabpay[$obj->fk_bank]['objects'][$object_key] = array(
@@ -224,7 +267,7 @@ if ($resql) {
$static_invoice->ref = $obj->ref;
$tabobject[$object_key] = array(
'id' => $obj->rowid,
'ref' => $obj->ref,
'ref' => $obj->ref, // It would be better to have a doc_ref that is 'BankId '.$obj->fk_bank.' - Facture FAzzz' and not just 'FAzzz' to be protected against duplicate, where xxx = $obj->fk_bank
'total_ht' => $obj->invoice_total_ht,
'total_ttc' => $obj->invoice_total_ttc,
'url' => $static_invoice->getNomUrl(1),
@@ -284,7 +327,7 @@ if ($resql) {
$sql .= " aa.account_number as accountancy_code, aa.label as accountancy_code_label,";
$sql .= " bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
$sql .= " FROM ".$db->prefix()."facture_fourn_det as ffd";
$sql .= " LEFT JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
$sql .= " INNER JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
$sql .= " INNER JOIN ".$db->prefix()."paiementfourn_facturefourn as pff ON pff.fk_facturefourn = ff.rowid";
$sql .= " INNER JOIN ".$db->prefix()."bank_url as bu ON bu.url_id = pff.fk_paiementfourn AND bu.type = '".$db->escape($type)."'";
$sql .= " LEFT JOIN ".$db->prefix()."product as p ON p.rowid = ffd.fk_product";
@@ -337,7 +380,7 @@ if ($resql) {
$static_supplier_invoice->ref = $obj->ref;
$tabobject[$object_key] = array(
'id' => $obj->rowid,
'ref' => $obj->ref,
'ref' => $obj->ref, // It would be better to have a doc_ref that is 'BankId '.$obj->fk_bank.' - Facture FAzzz' and not just 'FAzzz' to be protected against duplicate, where xxx = $obj->fk_bank
'total_ht' => -$obj->supplier_invoice_total_ht,
'total_ttc' => -$obj->supplier_invoice_total_ttc,
'url' => $static_supplier_invoice->getNomUrl(1),
@@ -398,7 +441,7 @@ if ($resql) {
$sql .= " aa.label as accountancy_code_label,";
$sql .= " bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
$sql .= " FROM ".$db->prefix()."expensereport_det as erf";
$sql .= " LEFT JOIN ".$db->prefix()."expensereport as er ON er.rowid = erf.fk_expensereport";
$sql .= " INNER JOIN ".$db->prefix()."expensereport as er ON er.rowid = erf.fk_expensereport";
$sql .= " INNER JOIN ".$db->prefix()."payment_expensereport as per ON per.fk_expensereport = er.rowid";
$sql .= " INNER JOIN ".$db->prefix()."bank_url as bu ON bu.url_id = per.rowid AND bu.type = '".$db->escape($type)."'";
$sql .= " LEFT JOIN ".$db->prefix()."c_type_fees as ctf ON ctf.id = erf.fk_c_type_fees";
@@ -572,7 +615,7 @@ if ($resql) {
$sql .= " bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
$sql .= " FROM ".$db->prefix()."paiementcharge as pc";
$sql .= " INNER JOIN ".$db->prefix()."bank_url as bu ON bu.url_id = pc.rowid AND bu.type = '".$db->escape($type)."'";
$sql .= " LEFT JOIN ".$db->prefix()."chargesociales AS cs ON cs.rowid = pc.fk_charge";
$sql .= " INNER JOIN ".$db->prefix()."chargesociales AS cs ON cs.rowid = pc.fk_charge";
$sql .= " LEFT JOIN ".$db->prefix()."c_chargesociales as ccs ON ccs.id = cs.fk_type";
// Already in bookkeeping or not
if ($in_bookkeeping == 'already') {
@@ -706,7 +749,7 @@ if ($resql) {
$sql .= " pd.amount AS amount_payment,";
$sql .= " bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
$sql .= " FROM ".$db->prefix()."payment_donation as pd";
$sql .= " LEFT JOIN ".$db->prefix()."don as d ON pd.fk_donation = d.rowid";
$sql .= " INNER JOIN ".$db->prefix()."don as d ON pd.fk_donation = d.rowid";
$sql .= " INNER JOIN ".$db->prefix()."bank_url as bu ON bu.url_id = pd.rowid AND bu.type = '".$db->escape($type)."'";
// Already in bookkeeping or not
if ($in_bookkeeping == 'already') {
@@ -773,7 +816,7 @@ if ($resql) {
$sql .= " pl.amount_capital, pl.amount_interest, pl.amount_insurance,";
$sql .= " bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
$sql .= " FROM ".$db->prefix()."payment_loan as pl";
$sql .= " LEFT JOIN ".$db->prefix()."loan as l ON pl.fk_loan = l.rowid";
$sql .= " INNER JOIN ".$db->prefix()."loan as l ON pl.fk_loan = l.rowid";
$sql .= " INNER JOIN ".$db->prefix()."bank_url as bu ON bu.url_id = pl.rowid AND bu.type = '".$db->escape($type)."'";
// Already in bookkeeping or not
if ($in_bookkeeping == 'already') {
@@ -930,7 +973,7 @@ if ($resql) {
$sql .= " adh.lastname, adh.firstname,";
$sql .= " bu.fk_bank, bu.url_id AS bu_url_id, bu.type AS bu_type";
$sql .= " FROM ".$db->prefix()."subscription as su";
$sql .= " LEFT JOIN ".$db->prefix()."adherent as adh ON adh.rowid = su.fk_adherent";
$sql .= " INNER JOIN ".$db->prefix()."adherent as adh ON adh.rowid = su.fk_adherent";
$sql .= " INNER JOIN ".$db->prefix()."bank_url as bu ON bu.url_id = su.rowid AND bu.type = '".$db->escape($type)."'";
// Already in bookkeeping or not
if ($in_bookkeeping == 'already') {
@@ -1103,7 +1146,7 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
}
$error_for_line = 0;
$errorforline = 0;
$db->begin();
foreach ($payment['objects'] as $object_key => $object_data) {
@@ -1117,9 +1160,14 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
$total_check += $amount;
$bookkeepingToCreate = new BookKeeping($db);
$result = $bookkeepingToCreate->createFromValues($payment["date"], $objectInfos['ref'], 'bank', $payment_id, $objectInfos['id'], $accountInfos['account_number'], $tabaccountingaccount[$accountInfos['account_number']]['label'], $accountInfos['account_ref'], $amount, $journal, $journal_label, '');
// Unique key is on couple: $payment_id, $objectInfos['id']
// For record in llx_accountaing_bookkeeping, for record with doc_type = 'bank', the value of fk_doc is ID in llx_bank and fk_docdet too. Wetry a fix this way;
//$result = $bookkeepingToCreate->createFromValues($payment["date"], $objectInfos['ref'], 'bank', $payment_id, $objectInfos['id'], $accountInfos['account_number'], $tabaccountingaccount[$accountInfos['account_number']]['label'], $accountInfos['account_ref'], $amount, $journal, $journal_label, '');
$result = $bookkeepingToCreate->createFromValues($payment["date"], $objectInfos['ref'], 'bank', $payment_id, $payment_id, $accountInfos['account_number'], $tabaccountingaccount[$accountInfos['account_number']]['label'], $accountInfos['account_ref'], $amount, $journal, $journal_label, '');
if ($result < 0) {
$error_for_line++;
$errorforline++;
if (!empty($bookkeepingToCreate->warnings)) {
setEventMessages(null, $bookkeepingToCreate->warnings, 'warnings');
@@ -1144,7 +1192,7 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
if ($result < 0) {
setEventMessages($accountingaccount->error, $accountingaccount->errors, 'errors');
$accountancy_code_label = $accountingaccount->errorsToString();
$error_for_line++;
$errorforline++;
} elseif ($result > 0) {
$accountancy_code_label = $accountingaccount->label;
} else {
@@ -1164,7 +1212,7 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
$bookkeepingToCreate = new BookKeeping($db);
$result = $bookkeepingToCreate->createFromValues($payment["date"], $objectInfos['ref'], 'bank', $payment_id, $objectInfos['id'], $accountancy_code, $accountingAccountInfos['label'], (!empty($operation['label']) ? $operation['label'] : $accountingAccountInfos['label']), -$amount, $journal, $journal_label, '');
if ($result < 0) {
$error_for_line++;
$errorforline++;
if (!empty($bookkeepingToCreate->warnings)) {
setEventMessages(null, $bookkeepingToCreate->warnings, 'warnings');
@@ -1196,7 +1244,7 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
if ($result < 0) {
setEventMessages($accountingaccount->error, $accountingaccount->errors, 'errors');
$accountancy_code_label = $accountingaccount->errorsToString();
$error_for_line++;
$errorforline++;
} elseif ($result > 0) {
$accountancy_code_label = $accountingaccount->label;
} else {
@@ -1212,7 +1260,7 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
$bookkeepingToCreate = new BookKeeping($db);
$result = $bookkeepingToCreate->createFromValues($payment["date"], $objectInfos['ref'], 'bank', $payment_id, $objectInfos['id'], $accountancy_code, $accountingAccountInfos['label'], $langs->trans('VAT').' '.price($vat_infos['tva_tx']).'%', -$amount, $journal, $journal_label, '');
if ($result < 0) {
$error_for_line++;
$errorforline++;
if (!empty($bookkeepingToCreate->warnings)) {
setEventMessages(null, $bookkeepingToCreate->warnings, 'warnings');
@@ -1234,7 +1282,7 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
$bookkeepingToCreate = new BookKeeping($db);
$result = $bookkeepingToCreate->createFromValues($payment["date"], $objectInfos['ref'], 'bank', $payment_id, $objectInfos['id'], $accountInfos['account_number'], $tabaccountingaccount[$accountInfos['account_number']]['label'], $accountInfos['account_ref'], $amount, $journal, $journal_label, '');
if ($result < 0) {
$error_for_line++;
$errorforline++;
if (!empty($bookkeepingToCreate->warnings)) {
setEventMessages(null, $bookkeepingToCreate->warnings, 'warnings');
@@ -1247,26 +1295,28 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
$total_check = price2num($total_check, 'MT');
if (!empty($total_check)) {
$error_for_line++;
$errorforline++;
setEventMessages($langs->trans('ErrorBookkeepingTryInsertNotBalancedTransactionAndCanceled', $objectInfos['ref'], $object_data['bu_url_id']), null, 'errors');
}
if ($error_for_line) {
if ($errorforline) {
$error++;
if ($error >= $MAXNBERRORS) {
setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped").' (>'.$MAXNBERRORS.')', null, 'errors');
break; // Break in the foreach
}
}
}
if (!$error_for_line) {
if (!$errorforline) {
$db->commit();
} else {
//print 'KO for line '.$key.' '.$error.'<br>';
$db->rollback();
$MAXNBERRORS = 5;
if ($error >= $MAXNBERRORS) {
setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped").' (>'.$MAXNBERRORS.')', null, 'errors');
break; // Break in the foreach
}
}
@@ -1292,7 +1342,7 @@ if ($action == 'writebookkeeping' && $user->hasRight('accounting', 'bind', 'writ
$param .= '&date_endmonth='.$date_endmonth;
$param .= '&date_endyear='.$date_endyear;
$param .= '&in_bookkeeping='.$in_bookkeeping;
header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
exit;
}
}
@@ -1384,17 +1434,17 @@ if (empty($action) || $action == 'view') {
$i = 0;
print '<div class="div-table-responsive">';
print '<table class="noborder" width="100%">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td></td>';
print '<td>'.$langs->trans('Date').'</td>';
print '<td>'.$langs->trans('Piece').' ('.$langs->trans('ObjectsRef').')</td>';
print '<td>'.$langs->trans('AccountAccounting').'</td>';
print '<td>'.$langs->trans('LabelOperation').'</td>';
print '<td>'.$langs->trans('PaymentMode').'</td>';
print '<td align="right">'.$langs->trans('Debit').'</td>';
print '<td align="right">'.$langs->trans('Credit').'</td>';
print '</tr>';
print "<td></td>";
print "<td>".$langs->trans("Date")."</td>";
print "<td>".$langs->trans("Piece").' ('.$langs->trans("ObjectsRef").')</td>';
print "<td>".$langs->trans("AccountAccounting")."</td>";
print "<td>".$langs->trans("LabelOperation")."</td>";
print '<td class="center">'.$langs->trans("PaymentMode")."</td>";
print "<td class="right">".$langs->trans("AccountingDebit")."</td>";
print "<td class="right">".$langs->trans("AccountingCredit")."</td>";
print "</tr>\n";
$r = '';
@@ -1465,7 +1515,7 @@ if (empty($action) || $action == 'view') {
}
}
print '</table>';
print "</table>";
print '</div>';
llxFooter();

View File

@@ -24,5 +24,5 @@ ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_nume
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_code_journal (code_journal, entity);
ALTER TABLE llx_accounting_bookkeeping ADD INDEX idx_accounting_bookkeeping_piece_num (piece_num, entity);
-- Current unicity is tested by the journalize page on couple (fk_doc, doc_type)
-- Current unicity is tested by the "transfer in accountancy"" page on couple (fk_doc, doc_type)
-- TODO Add a key for unicity (not so easy as fk_doc, doc_type may have several lines for one piece)

View File

@@ -27,13 +27,13 @@ create table llx_bank
amount double(24,8) NOT NULL default 0, -- amount in the currency of the bank account
amount_main_currency double(24,8) NULL, -- amount in the main currency of the company when payment done in a bank account with a different currency
label varchar(255),
fk_account integer,
fk_account integer, -- ID of bank account
fk_user_author integer,
fk_user_rappro integer,
fk_type varchar(6), -- TIP,VIR,PRE,CB,CHQ,... (Code in llx_c_paiement)
num_releve varchar(50),
num_chq varchar(50),
numero_compte varchar(32) NULL, -- FEC:CompteNum | account number
numero_compte varchar(32) NULL, -- FEC:CompteNum | account number
rappro tinyint default 0,
note text,
fk_bordereau integer DEFAULT 0,

View File

@@ -20,8 +20,8 @@
create table llx_bank_url
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_bank integer,
url_id integer,
fk_bank integer, -- ID in llx_bank
url_id integer, -- ID of object (invoice, payment, customer, ...). Type is in type field.
url varchar(255),
label varchar(255),
type varchar(24) NOT NULL