public static function Factory($data, &$errors = array(), $do_name = null) { if ($data['debit'] > 0) { $data['value'] = BCADD($data['debit'], 0); } elseif ($data['credit'] > 0) { $data['value'] = BCMUL($data['credit'], -1); } return parent::Factory($data, $errors, $do_name); }
public static function makeFromJournalEntry($gl_data, $lines_data, &$errors = array()) { $db = DB::Instance(); $glperiod = GLPeriod::getPeriod(fix_date($gl_data['transaction_date'])); if (!$glperiod || count($glperiod) == 0) { $errors[] = 'No period exists for this date'; return array(); } $gl_data['docref'] = $db->GenID('gl_transactions_docref_seq'); $gl_transactions = array(); foreach ($lines_data as $line) { if ($line['debit'] < 0 || $line['credit'] < 0) { $errors[] = 'Credit/Debit values cannot be negative'; } elseif ($line['debit'] == 0 && $line['credit'] == 0) { $errors[] = 'Can\'t enter a journal line without either a credit or a debit'; } elseif ($line['debit'] > 0 && $line['credit'] > 0) { $errors[] = 'A journal line cannot have both a credit and a debit'; } else { $gl_data['value'] = 0; if ($line['debit'] > 0) { $gl_data['value'] = BCADD($line['debit'], 0); } elseif ($line['credit'] > 0) { $gl_data['value'] = BCMUL($line['credit'], -1); } $gl_data['glperiods_id'] = $glperiod['id']; $gl_data['glaccount_id'] = $line['glaccount_id']; $gl_data['glcentre_id'] = $line['glcentre_id']; $gl_data['comment'] = $line['comment']; GLTransaction::setTwinCurrency($gl_data); $gl_transaction = GLTransaction::Factory($gl_data, $errors); $gl_transactions[] = $gl_transaction; if (isset($gl_data['accrual'])) { $gl_data['glperiods_id'] = $gl_data['accrual_period_id']; $gl_data['twinvalue'] *= -1; $gl_data['value'] *= -1; $gl_data['comment'] = 'Reverse ' . $gl_data['comment']; $gl_transaction = GLTransaction::Factory($gl_data, $errors); $gl_transactions[] = $gl_transaction; } } } return $gl_transactions; }