100 if (isset($listfields[
'b.debit']) && isset($listfields[
'b.credit'])) {
101 $debit_index = $listfields[
'b.debit'];
103 $debitFloat = (float)
price2num($arrayrecord[$debit_index][
'val']);
104 if (!empty($debitFloat)) {
105 $amount = $debitFloat;
107 $credit_index = $listfields[
'b.credit'];
108 $amount = (float)
price2num($arrayrecord[$credit_index][
'val']);
111 return "'" . $this->db->escape(abs($amount)) .
"'";
156 $pieceNum = trim($arrayrecord[$record_key][
'val']);
159 if ($pieceNum ==
'') {
160 if (isset($listfields[
'b.code_journal']) && isset($listfields[
'b.doc_date'])) {
162 if (!isset($conf->cache[
'accounting'])) {
163 $conf->cache[
'accounting'] = array(
164 'lastRecordCompareValues' => array(),
168 $codeJournalIndex = $listfields[
'b.code_journal'];
169 $docDateIndex = $listfields[
'b.doc_date'];
170 $atLeastOneLastRecordChanged =
false;
171 if (empty($conf->cache[
'accounting'][
'lastRecordCompareValues'])) {
172 $atLeastOneLastRecordChanged =
true;
174 if ($arrayrecord[$codeJournalIndex][
'val'] != $conf->cache[
'accounting'][
'lastRecordCompareValues'][
'b.code_journal']
175 || $arrayrecord[$docDateIndex][
'val'] != $conf->cache[
'accounting'][
'lastRecordCompareValues'][
'b.doc_date']
177 $atLeastOneLastRecordChanged =
true;
182 if ($atLeastOneLastRecordChanged ===
true) {
184 if (empty($conf->cache[
'accounting'][
'nextPieceNum'])) {
186 $sql =
"SELECT MAX(piece_num) as last_piece_num";
187 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping";
188 $sql .=
" WHERE entity IN (".getEntity(
'accountingbookkeeping').
")";
189 $res = $this->db->query($sql);
191 $this->errors[] = $this->db->lasterror();
194 if ($obj = $this->db->fetch_object($res)) {
195 $lastPieceNum = (int) $obj->last_piece_num;
197 $this->db->free($res);
200 if (empty($conf->cache[
'accounting'][
'nextPieceNum'])) {
201 $conf->cache[
'accounting'][
'nextPieceNum'] = $lastPieceNum;
203 $conf->cache[
'accounting'][
'nextPieceNum']++;
206 $conf->cache[
'accounting'][
'lastRecordCompareValues'] = array(
207 'b.code_journal' => $arrayrecord[$codeJournalIndex][
'val'],
208 'b.doc_date' => $arrayrecord[$docDateIndex][
'val'],
211 $pieceNum = (string) $conf->cache[
'accounting'][
'nextPieceNum'];