Fix journalization protection

This commit is contained in:
Laurent Destailleur 2018-02-12 12:02:01 +01:00
parent 734bd4d2fb
commit 09dfd5eb9f
7 changed files with 183 additions and 129 deletions

View File

@ -730,7 +730,7 @@ if ($num > 0)
print "</table>"; print "</table>";
print '</div>'; print '</div>';
// TODO Replace this with mass action // TODO Replace this with mass delete action
print '<div class="tabsAction tabsActionNoBottom">' . "\n"; print '<div class="tabsAction tabsActionNoBottom">' . "\n";
print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear'.($param?'&'.$param:'').'">' . $langs->trans("DelBookKeeping") . '</a>'; print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear'.($param?'&'.$param:'').'">' . $langs->trans("DelBookKeeping") . '</a>';
print '</div>'; print '</div>';

View File

@ -163,7 +163,7 @@ print '<script type="text/javascript">
/* /*
* Customer Invoice lines * Customer Invoice lines
*/ */
$sql = "SELECT f.rowid, f.facnumber, f.type, f.datef, f.ref_client,"; $sql = "SELECT f.rowid as facid, f.facnumber, f.type, f.datef, f.ref_client,";
$sql .= " fd.rowid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.vat_src_code, fd.total_ttc,"; $sql .= " fd.rowid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.vat_src_code, fd.total_ttc,";
$sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.code_client,"; $sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.code_client,";
$sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number, aa.label as label_compte,"; $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number, aa.label as label_compte,";
@ -333,7 +333,7 @@ if ($result) {
$codecompta = length_accountg($objp->account_number) . ' - ' . $objp->label_compte; $codecompta = length_accountg($objp->account_number) . ' - ' . $objp->label_compte;
$facture_static->ref = $objp->facnumber; $facture_static->ref = $objp->facnumber;
$facture_static->id = $objp->rowid; $facture_static->id = $objp->facid;
$product_static->ref = $objp->product_ref; $product_static->ref = $objp->product_ref;
$product_static->id = $objp->product_id; $product_static->id = $objp->product_id;

View File

@ -634,7 +634,7 @@ if (! $error && $action == 'writebookkeeping') {
} }
} }
if ($totaldebit != $totalcredit) if (price2num($totaldebit) != price2num($totalcredit))
{ {
$error++; $error++;
$errorforline++; $errorforline++;

View File

@ -344,7 +344,8 @@ if ($action == 'writebookkeeping') {
} }
} }
if ($totaldebit != $totalcredit) // Protection against a bug on line before
if (price2num($totaldebit) != price2num($totalcredit))
{ {
$error++; $error++;
$errorforline++; $errorforline++;

View File

@ -222,6 +222,8 @@ if ($action == 'writebookkeeping') {
$companystatic = new Societe($db); $companystatic = new Societe($db);
$invoicestatic = new FactureFournisseur($db); $invoicestatic = new FactureFournisseur($db);
$errorforinvoice = array();
foreach ($tabfac as $key => $val) { // Loop on each invoice foreach ($tabfac as $key => $val) { // Loop on each invoice
$errorforline = 0; $errorforline = 0;
@ -257,9 +259,10 @@ if ($action == 'writebookkeeping') {
if ($alreadydispatched) $replacedinvoice = 2; if ($alreadydispatched) $replacedinvoice = 2;
} }
// If not already into bookkeeping, we won't add it, if yes, add the counterpart ???. // If not already into bookkeeping, we won't add it. If yes, do nothing (should not happen because creating replacement not possible if invoice is accounted)
if ($replacedinvoice == 1) if ($replacedinvoice == 1)
{ {
$db->rollback();
continue; continue;
} }
@ -267,7 +270,7 @@ if ($action == 'writebookkeeping') {
if (! $errorforline) if (! $errorforline)
{ {
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
if ($mt) { //if ($mt) {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
$bookkeeping->date_lim_reglement = $val["datereg"]; $bookkeeping->date_lim_reglement = $val["datereg"];
@ -298,16 +301,18 @@ if ($action == 'writebookkeeping') {
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
} }
else else
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
} //}
} }
} }
@ -315,7 +320,7 @@ if ($action == 'writebookkeeping') {
if (! $errorforline) if (! $errorforline)
{ {
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
if ($mt) { //if ($mt) {
// get compte id and label // get compte id and label
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
if ($accountingaccount->fetch(null, $k, true)) { if ($accountingaccount->fetch(null, $k, true)) {
@ -349,17 +354,19 @@ if ($action == 'writebookkeeping') {
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
} }
else else
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
} }
} //}
} }
} }
@ -406,12 +413,14 @@ if ($action == 'writebookkeeping') {
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
} }
else else
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
@ -456,12 +465,14 @@ if ($action == 'writebookkeeping') {
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
} }
else else
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
@ -469,13 +480,20 @@ if ($action == 'writebookkeeping') {
} }
} }
if ($totaldebit != $totalcredit) // Protection against a bug on line before
if (price2num($totaldebit) != price2num($totalcredit))
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors'); setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
} }
// Check totaldebit is also same than total of invoice. If not, some record are not yet ready to be journalized
if (! $errorforline) if (! $errorforline)
{ {
$db->commit(); $db->commit();
@ -567,7 +585,7 @@ if ($action == 'exportcsv') {
if ($alreadydispatched) $replacedinvoice = 2; if ($alreadydispatched) $replacedinvoice = 2;
} }
// If not already into bookkeeping, we won't add it, if yes, add the counterpart ???. // If not already into bookkeeping, we won't add it. If yes, do nothing (should not happen because creating replacement not possible if invoice is accounted)
if ($replacedinvoice == 1) if ($replacedinvoice == 1)
{ {
continue; continue;
@ -575,26 +593,28 @@ if ($action == 'exportcsv') {
// Third party // Third party
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
print '"' . $key . '"' . $sep; //if ($mt) {
print '"' . $date . '"' . $sep; print '"' . $key . '"' . $sep;
print '"' . $val["refsologest"] . '"' . $sep; print '"' . $date . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep; print '"' . $val["refsologest"] . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep;
print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep;
print '"' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . $langs->trans("Code_tiers") . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"'. $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
print '"' . $journal . '"' ; print '"' . ($mt >= 0 ? price($mt) : '') . '"'. $sep;
print "\n"; print '"' . $journal . '"' ;
print "\n";
//}
} }
// Product / Service // Product / Service
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true); $accountingaccount->fetch(null, $k, true);
if ($mt) { //if ($mt) {
print '"' . $key . '"' . $sep; print '"' . $key . '"' . $sep;
print '"' . $date . '"' . $sep; print '"' . $date . '"' . $sep;
print '"' . $val["refsologest"] . '"' . $sep; print '"' . $val["refsologest"] . '"' . $sep;
@ -608,7 +628,7 @@ if ($action == 'exportcsv') {
print '"' . ($mt < 0 ? price(- $mt) : '') . '"'. $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'. $sep;
print '"' . $journal . '"' ; print '"' . $journal . '"' ;
print "\n"; print "\n";
} //}
} }
// VAT // VAT
@ -787,37 +807,40 @@ if (empty($action) || $action == 'view') {
print '<td align="right"></td>'; print '<td align="right"></td>';
print '<td align="right"></td>'; print '<td align="right"></td>';
print "</tr>"; print "</tr>";
continue; continue;
} }
// Third party // Third party
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
print '<tr class="oddeven">'; //if ($mt) {
print "<td><!-- Thirdparty --></td>"; print '<tr class="oddeven">';
print "<td>" . $date . "</td>"; print "<td><!-- Thirdparty --></td>";
print "<td>" . $invoicestatic->getNomUrl(1) . "</td>"; print "<td>" . $date . "</td>";
// Account print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
print "<td>"; // Account
$accountoshow = length_accounta($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER); print "<td>";
if (empty($accountoshow) || $accountoshow == 'NotDefined') $accountoshow = length_accounta($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER);
{ if (empty($accountoshow) || $accountoshow == 'NotDefined')
print '<span class="error">'.$langs->trans("MainAccountForCustomersNotDefined").'</span>'; {
} print '<span class="error">'.$langs->trans("MainAccountForCustomersNotDefined").'</span>';
else print $accountoshow; }
print '</td>'; else print $accountoshow;
// Subledger account print '</td>';
print "<td>"; // Subledger account
$accountoshow = length_accounta($k); print "<td>";
if (empty($accountoshow) || $accountoshow == 'NotDefined') $accountoshow = length_accounta($k);
{ if (empty($accountoshow) || $accountoshow == 'NotDefined')
print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>'; {
} print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
else print $accountoshow; }
print '</td>'; else print $accountoshow;
print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("SubledgerAccount") . "</td>"; print '</td>';
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>"; print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("SubledgerAccount") . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>"; print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
print "</tr>"; print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
print "</tr>";
//}
} }
// Product / Service // Product / Service
@ -825,7 +848,7 @@ if (empty($action) || $action == 'view') {
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true); $accountingaccount->fetch(null, $k, true);
if ($mt) { //if ($mt) {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print "<td><!-- Product --></td>"; print "<td><!-- Product --></td>";
print "<td>" . $date . "</td>"; print "<td>" . $date . "</td>";
@ -848,7 +871,7 @@ if (empty($action) || $action == 'view') {
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>"; print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>"; print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
print "</tr>"; print "</tr>";
} //}
} }
// VAT // VAT
@ -890,27 +913,28 @@ if (empty($action) || $action == 'view') {
if (is_array($tabother[$key])) if (is_array($tabother[$key]))
{ {
foreach ( $tabother[$key] as $k => $mt ) { foreach ( $tabother[$key] as $k => $mt ) {
if ($mt) {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print "<td><!-- VAT counterpart NPR --></td>"; print "<td><!-- VAT counterpart NPR --></td>";
print "<td>" . $date . "</td>"; print "<td>" . $date . "</td>";
print "<td>" . $invoicestatic->getNomUrl(1) . "</td>"; print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
// Account // Account
print "<td>"; print "<td>";
$accountoshow = length_accountg($k); $accountoshow = length_accountg($k);
if (empty($accountoshow) || $accountoshow == 'NotDefined') if (empty($accountoshow) || $accountoshow == 'NotDefined')
{ {
print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("NPR counterpart").'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account'.'</span>'; print '<span class="error">'.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("NPR counterpart").'). Set ACCOUNTING_COUNTERPART_VAT_NPR to the subvention account'.'</span>';
}
else print $accountoshow;
print '</td>';
// Subledger account
print "<td>";
print '</td>';
print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("VAT") . " NPR (counterpart)</td>";
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
print "</tr>";
} }
else print $accountoshow;
print '</td>';
// Subledger account
print "<td>";
print '</td>';
print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->ref_supplier . ' - ' . $langs->trans("VAT") . " NPR (counterpart)</td>";
print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
print "</tr>";
} }
} }
} }

View File

@ -101,9 +101,9 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
$sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
//$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON ((fd.vat_src_code <> '' AND fd.vat_src_code = ct.code) OR (fd.vat_src_code = '' AND fd.tva_tx = ct.taux)) AND ct.fk_pays = '" . $idpays . "'"; //$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON ((fd.vat_src_code <> '' AND fd.vat_src_code = ct.code) OR (fd.vat_src_code = '' AND fd.tva_tx = ct.taux)) AND ct.fk_pays = '" . $idpays . "'";
$sql .= " WHERE fd.fk_code_ventilation > 0"; $sql .= " WHERE fd.fk_code_ventilation > 0";
$sql .= " AND f.entity IN (".getEntity('facture', 0).')'; // We don't share object for accountancy $sql .= " AND f.entity IN (".getEntity('facture', 0).')'; // We don't share object for accountancy, we use source object sharing
$sql .= " AND f.fk_statut > 0"; // TODO Facture annulée ? $sql .= " AND f.fk_statut > 0"; // TODO Facture annulée ?
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { // Non common setup
$sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
} else { } else {
$sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
@ -226,6 +226,8 @@ if ($action == 'writebookkeeping') {
$companystatic = new Societe($db); $companystatic = new Societe($db);
$invoicestatic = new Facture($db); $invoicestatic = new Facture($db);
$errorforinvoice = array();
foreach ($tabfac as $key => $val) { // Loop on each invoice foreach ($tabfac as $key => $val) { // Loop on each invoice
$errorforline = 0; $errorforline = 0;
@ -259,9 +261,10 @@ if ($action == 'writebookkeeping') {
if ($alreadydispatched) $replacedinvoice = 2; if ($alreadydispatched) $replacedinvoice = 2;
} }
// If not already into bookkeeping, we won't add it, if yes, add the counterpart ???. // If not already into bookkeeping, we won't add it. If yes, do nothing (should not happen because creating replacement not possible if invoice is accounted)
if ($replacedinvoice == 1) if ($replacedinvoice == 1)
{ {
$db->rollback();
continue; continue;
} }
@ -269,7 +272,7 @@ if ($action == 'writebookkeeping') {
if (! $errorforline) if (! $errorforline)
{ {
foreach ( $tabttc[$key] as $k => $mt ) { foreach ( $tabttc[$key] as $k => $mt ) {
if ($mt) { //if ($mt) {
$bookkeeping = new BookKeeping($db); $bookkeeping = new BookKeeping($db);
$bookkeeping->doc_date = $val["date"]; $bookkeeping->doc_date = $val["date"];
$bookkeeping->date_lim_reglement = $val["datereg"]; $bookkeeping->date_lim_reglement = $val["datereg"];
@ -300,16 +303,18 @@ if ($action == 'writebookkeeping') {
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
} }
else else
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
} //}
} }
} }
@ -317,7 +322,7 @@ if ($action == 'writebookkeeping') {
if (! $errorforline) if (! $errorforline)
{ {
foreach ( $tabht[$key] as $k => $mt ) { foreach ( $tabht[$key] as $k => $mt ) {
if ($mt) { //if ($mt) {
// get compte id and label // get compte id and label
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
if ($accountingaccount->fetch(null, $k, true)) { if ($accountingaccount->fetch(null, $k, true)) {
@ -351,22 +356,23 @@ if ($action == 'writebookkeeping') {
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
} }
else else
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
} }
} //}
} }
} }
// VAT // VAT
// var_dump($tabtva);
if (! $errorforline) if (! $errorforline)
{ {
$listoftax=array(0, 1, 2); $listoftax=array(0, 1, 2);
@ -408,12 +414,14 @@ if ($action == 'writebookkeeping') {
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
//setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
} }
else else
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
} }
} }
@ -422,13 +430,28 @@ if ($action == 'writebookkeeping') {
} }
} }
if ($totaldebit != $totalcredit) // Protection against a bug on line before
if (price2num($totaldebit) != price2num($totalcredit))
{ {
$error++; $error++;
$errorforline++; $errorforline++;
$errorforinvoice[$key]=1;
setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors'); setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors');
} }
// Check totaldebit is also same than total of invoice. If not, some record are not yet ready to be journalized,
// so we refuse to journalize any lines of the invoice.
/*$tmpinvoice = new Facture($db);
$tmpinvoice->fetch($key);
//var_dump($key); var_dump($tmpinvoice->ref); var_dump(price2num($tmpinvoice->total_ttc,'MT')); var_dump($totaldebit);
if (price2num($tmpinvoice->total_ttc,'MT') != price2num($totaldebit))
{
$error++;
$errorforline++;
$errorforinvoice[$key]=1;
setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $tmpinvoice->ref), null, 'errors');
}*/
if (! $errorforline) if (! $errorforline)
{ {
$db->commit(); $db->commit();
@ -522,7 +545,7 @@ if ($action == 'exportcsv') {
if ($alreadydispatched) $replacedinvoice = 2; if ($alreadydispatched) $replacedinvoice = 2;
} }
// If not already into bookkeeping, we won't add it, if yes, add the counterpart ???. // If not already into bookkeeping, we won't add it. If yes, do nothing (should not happen because creating replacement not possible if invoice is accounted)
if ($replacedinvoice == 1) if ($replacedinvoice == 1)
{ {
continue; continue;
@ -530,26 +553,28 @@ if ($action == 'exportcsv') {
// Third party // Third party
foreach ($tabttc[$key] as $k => $mt) { foreach ($tabttc[$key] as $k => $mt) {
print '"' . $key . '"' . $sep; //if ($mt) {
print '"' . $date . '"' . $sep; print '"' . $key . '"' . $sep;
print '"' . $val["ref"] . '"' . $sep; print '"' . $date . '"' . $sep;
print '"' . utf8_decode(dol_trunc($companystatic->name, 32)) . '"' . $sep; print '"' . $val["ref"] . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . utf8_decode(dol_trunc($companystatic->name, 32)) . '"' . $sep;
print '"' . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; print '"' . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . '"' . $sep;
print '"' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . $langs->trans("Code_tiers") . '"' . $sep;
print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
print '"' . $journal . '"'; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
print "\n"; print '"' . $journal . '"';
print "\n";
//}
} }
// Product / Service // Product / Service
foreach ($tabht[$key] as $k => $mt) { foreach ($tabht[$key] as $k => $mt) {
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true); $accountingaccount->fetch(null, $k, true);
if ($mt) { //if ($mt) {
print '"' . $key . '"' . $sep; print '"' . $key . '"' . $sep;
print '"' . $date . '"' . $sep; print '"' . $date . '"' . $sep;
print '"' . $val["ref"] . '"' . $sep; print '"' . $val["ref"] . '"' . $sep;
@ -563,7 +588,7 @@ if ($action == 'exportcsv') {
print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
print '"' . $journal . '"'; print '"' . $journal . '"';
print "\n"; print "\n";
} //}
} }
// VAT // VAT
@ -719,38 +744,41 @@ if (empty($action) || $action == 'view') {
print '<td align="right"></td>'; print '<td align="right"></td>';
print '<td align="right"></td>'; print '<td align="right"></td>';
print "</tr>"; print "</tr>";
continue; continue;
} }
// Third party // Third party
foreach ($tabttc[$key] as $k => $mt) foreach ($tabttc[$key] as $k => $mt)
{ {
print '<tr class="oddeven">'; //if ($mt) {
print "<td><!-- Thirdparty --></td>"; print '<tr class="oddeven">';
print "<td>" . $date . "</td>"; print "<td><!-- Thirdparty --></td>";
print "<td>" . $invoicestatic->getNomUrl(1) . "</td>"; print "<td>" . $date . "</td>";
// Account print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
print "<td>"; // Account
$accountoshow = length_accounta($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER); print "<td>";
if (empty($accountoshow) || $accountoshow == 'NotDefined') $accountoshow = length_accounta($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER);
{ if (empty($accountoshow) || $accountoshow == 'NotDefined')
print '<span class="error">'.$langs->trans("MainAccountForCustomersNotDefined").'</span>'; {
} print '<span class="error">'.$langs->trans("MainAccountForCustomersNotDefined").'</span>';
else print $accountoshow; }
print '</td>'; else print $accountoshow;
// Subledger account print '</td>';
print "<td>"; // Subledger account
$accountoshow = length_accounta($k); print "<td>";
if (empty($accountoshow) || $accountoshow == 'NotDefined') $accountoshow = length_accounta($k);
{ if (empty($accountoshow) || $accountoshow == 'NotDefined')
print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>'; {
} print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
else print $accountoshow; }
print '</td>'; else print $accountoshow;
print "<td>" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("SubledgerAccount") . "</td>"; print '</td>';
print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>"; print "<td>" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("SubledgerAccount") . "</td>";
print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>"; print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
print "</tr>"; print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
print "</tr>";
//}
} }
// Product / Service // Product / Service
@ -759,7 +787,7 @@ if (empty($action) || $action == 'view') {
$accountingaccount = new AccountingAccount($db); $accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true); $accountingaccount->fetch(null, $k, true);
if ($mt) { //if ($mt) {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print "<td><!-- Product --></td>"; print "<td><!-- Product --></td>";
print "<td>" . $date . "</td>"; print "<td>" . $date . "</td>";
@ -782,7 +810,7 @@ if (empty($action) || $action == 'view') {
print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>"; print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>"; print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
print "</tr>"; print "</tr>";
} //}
} }
// VAT // VAT

View File

@ -220,7 +220,7 @@ ErrorAccountancyCodeIsAlreadyUse=Error, you cannot delete this accounting accoun
MvtNotCorrectlyBalanced=Movement not correctly balanced. Credit = %s. Debit = %s MvtNotCorrectlyBalanced=Movement not correctly balanced. Credit = %s. Debit = %s
FicheVentilation=Binding card FicheVentilation=Binding card
GeneralLedgerIsWritten=Transactions are written in the Ledger GeneralLedgerIsWritten=Transactions are written in the Ledger
GeneralLedgerSomeRecordWasNotRecorded=Some of the transactions could not be dispatched. If there is no other error message, this is probably because they were already dispatched. GeneralLedgerSomeRecordWasNotRecorded=Some of the transactions could not be journalized. If there is no other error message, this is probably because they were already journalized.
NoNewRecordSaved=No more record to journalize NoNewRecordSaved=No more record to journalize
ListOfProductsWithoutAccountingAccount=List of products not bound to any accounting account ListOfProductsWithoutAccountingAccount=List of products not bound to any accounting account
ChangeBinding=Change the binding ChangeBinding=Change the binding
@ -284,6 +284,7 @@ Formula=Formula
## Error ## Error
SomeMandatoryStepsOfSetupWereNotDone=Some mandatory steps of setup was not done, please complete them SomeMandatoryStepsOfSetupWereNotDone=Some mandatory steps of setup was not done, please complete them
ErrorNoAccountingCategoryForThisCountry=No accounting account group available for country %s (See Home - Setup - Dictionaries) ErrorNoAccountingCategoryForThisCountry=No accounting account group available for country %s (See Home - Setup - Dictionaries)
ErrorInvoiceContainsLinesNotYetBounded=You try to journalize some lines of the invoice <strong>%s</strong>, but some other lines are not yet bounded to accounting account. Journalization of all invoice lines for this invoice are refused.
ExportNotSupported=The export format setuped is not supported into this page ExportNotSupported=The export format setuped is not supported into this page
BookeppingLineAlreayExists=Lines already existing into bookeeping BookeppingLineAlreayExists=Lines already existing into bookeeping
NoJournalDefined=No journal defined NoJournalDefined=No journal defined