Fix trans

This commit is contained in:
Laurent Destailleur 2022-05-09 16:51:31 +02:00
parent 720a09dacb
commit 0cac14c82f
3 changed files with 34 additions and 19 deletions

View File

@ -1843,8 +1843,8 @@ class BookKeeping extends CommonObject
/** /**
* Transform transaction * Transform transaction
* *
* @param number $direction If 0 tmp => real, if 1 real => tmp * @param number $direction If 0: tmp => real, if 1: real => tmp
* @param string $piece_num Piece num * @param string $piece_num Piece num = Transaction ref
* @return int int <0 if KO, >0 if OK * @return int int <0 if KO, >0 if OK
*/ */
public function transformTransaction($direction = 0, $piece_num = '') public function transformTransaction($direction = 0, $piece_num = '')
@ -1862,27 +1862,42 @@ class BookKeeping extends CommonObject
if ($next_piecenum < 0) { if ($next_piecenum < 0) {
$error++; $error++;
} }
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' (doc_date, doc_type,';
$sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,'; // Delete if there is an empty line
$sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity)." AND numero_compte IS NULL AND debit = 0 AND credit = 0";
$sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
$sql .= ' SELECT doc_date, doc_type,';
$sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
$sql .= ' numero_compte, label_compte, label_operation, debit, credit,';
$sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).", '".$this->db->idate($now)."'";
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { if (!$resql) {
$error++; $error++;
$this->errors[] = 'Error '.$this->db->lasterror(); $this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
} }
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);
$resql = $this->db->query($sql); if (!$error) {
if (!$resql) { $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' (doc_date, doc_type,';
$error++; $sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
$this->errors[] = 'Error '.$this->db->lasterror(); $sql .= ' numero_compte, label_compte, label_operation, debit, credit,';
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
$sql .= ' SELECT doc_date, doc_type,';
$sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
$sql .= ' numero_compte, label_compte, label_operation, debit, credit,';
$sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).", '".$this->db->idate($now)."'";
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
}
}
if (!$error) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
}
} }
} elseif ($direction == 1) { } elseif ($direction == 1) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);

View File

@ -289,7 +289,7 @@ ValidateHistory=Bind Automatically
AutomaticBindingDone=Automatic bindings done (%s) - Automatic binding not possible for some record (%s) AutomaticBindingDone=Automatic bindings done (%s) - Automatic binding not possible for some record (%s)
ErrorAccountancyCodeIsAlreadyUse=Error, you cannot delete this accounting account because it is used ErrorAccountancyCodeIsAlreadyUse=Error, you cannot delete this accounting account because it is used
MvtNotCorrectlyBalanced=Movement not correctly balanced. Debit = %s | Credit = %s MvtNotCorrectlyBalanced=Movement not correctly balanced. Debit = %s & Credit = %s
Balancing=Balancing Balancing=Balancing
FicheVentilation=Binding card FicheVentilation=Binding card
GeneralLedgerIsWritten=Transactions are written in the Ledger GeneralLedgerIsWritten=Transactions are written in the Ledger

View File

@ -289,7 +289,7 @@ ValidateHistory=Lier automatiquement
AutomaticBindingDone=Liaisons automatiques effectuées (%s) - Liaison automatique impossible pour certains enregistrements (%s) AutomaticBindingDone=Liaisons automatiques effectuées (%s) - Liaison automatique impossible pour certains enregistrements (%s)
ErrorAccountancyCodeIsAlreadyUse=Erreur, vous ne pouvez pas détruire de compte comptable car il est utilisé ErrorAccountancyCodeIsAlreadyUse=Erreur, vous ne pouvez pas détruire de compte comptable car il est utilisé
MvtNotCorrectlyBalanced=Mouvement non équilibré. Débit = %s| Crédit = %s MvtNotCorrectlyBalanced=Mouvement non équilibré. Débit = %s & Crédit = %s
Balancing=Équilibrage Balancing=Équilibrage
FicheVentilation=Fiche lien FicheVentilation=Fiche lien
GeneralLedgerIsWritten=Les transactions sont enregistrées dans le grand livre GeneralLedgerIsWritten=Les transactions sont enregistrées dans le grand livre