示例#1
0
 public static function saveGLtransaction($cb_trans, $data, &$errors)
 {
     $desc = $cb_trans->description;
     $gl_data = $data;
     $gl_data['comment'] = !empty($desc) ? $desc : $cb_trans->reference;
     $gl_data['docref'] = $cb_trans->reference;
     $gl_data['reference'] = $cb_trans->ext_reference;
     $gl_data['control_docref'] = $cb_trans->control_reference;
     $glperiod = GLPeriod::getPeriod($cb_trans->transaction_date);
     if (!$glperiod || count($glperiod) == 0) {
         $errors[] = 'No period exists for this date';
         return false;
     }
     $db = DB::Instance();
     $db->StartTrans();
     $gl_data['glperiods_id'] = $glperiod['id'];
     $gl_trans = GLTransaction::makeFromCashbookTransaction($gl_data, $errors);
     if ($gl_trans === false) {
         $errors[] = 'Invalid GL transaction';
     }
     if (count($errors) == 0 && !GLTransaction::saveTransactions($gl_trans, $errors)) {
         $errors[] = 'Error saving GL transaction';
         $db->FailTrans();
         $gl_trans = FALSE;
     }
     $db->CompleteTrans();
     return $gl_trans;
 }