101 if (isset($listfields[
'b.debit']) && isset($listfields[
'b.credit'])) {
102 $debit_index = $listfields[
'b.debit'];
104 $debitFloat = (float)
price2num($arrayrecord[$debit_index][
'val']);
105 if (!empty($debitFloat)) {
106 $amount = $debitFloat;
108 $credit_index = $listfields[
'b.credit'];
109 $amount = (float)
price2num($arrayrecord[$credit_index][
'val']);
112 return "'" . $this->db->escape(abs($amount)) .
"'";
157 $pieceNum = trim($arrayrecord[$record_key][
'val']);
160 if ($pieceNum ==
'') {
161 if (isset($listfields[
'b.code_journal']) && isset($listfields[
'b.doc_date'])) {
163 if (!isset($conf->cache[
'accounting'])) {
164 $conf->cache[
'accounting'] = array(
165 'lastRecordCompareValues' => array(),
169 $codeJournalIndex = $listfields[
'b.code_journal'];
170 $docDateIndex = $listfields[
'b.doc_date'];
171 $atLeastOneLastRecordChanged =
false;
172 if (empty($conf->cache[
'accounting'][
'lastRecordCompareValues'])) {
173 $atLeastOneLastRecordChanged =
true;
175 if ($arrayrecord[$codeJournalIndex][
'val'] != $conf->cache[
'accounting'][
'lastRecordCompareValues'][
'b.code_journal']
176 || $arrayrecord[$docDateIndex][
'val'] != $conf->cache[
'accounting'][
'lastRecordCompareValues'][
'b.doc_date']
178 $atLeastOneLastRecordChanged =
true;
183 if ($atLeastOneLastRecordChanged) {
185 if (empty($conf->cache[
'accounting'][
'nextPieceNum'])) {
187 $sql =
"SELECT MAX(piece_num) as last_piece_num";
188 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
189 $sql .=
" WHERE entity IN (".getEntity(
'accountingbookkeeping').
")";
190 $res = $this->db->query($sql);
192 $this->errors[] = $this->db->lasterror();
195 if ($obj = $this->db->fetch_object($res)) {
196 $lastPieceNum = (int) $obj->last_piece_num;
198 $this->db->free($res);
201 if (empty($conf->cache[
'accounting'][
'nextPieceNum'])) {
202 $conf->cache[
'accounting'][
'nextPieceNum'] = $lastPieceNum;
204 $conf->cache[
'accounting'][
'nextPieceNum']++;
207 $conf->cache[
'accounting'][
'lastRecordCompareValues'] = array(
208 'b.code_journal' => $arrayrecord[$codeJournalIndex][
'val'],
209 'b.doc_date' => $arrayrecord[$docDateIndex][
'val'],
212 $pieceNum = (string) $conf->cache[
'accounting'][
'nextPieceNum'];