function revalue($data, &$errors = array()) { if (empty($data['transaction_date'])) { $data['transaction_date'] = date(DATE_FORMAT); } $glperiod = GLPeriod::getPeriod(fix_date($data['transaction_date'])); if (!$glperiod || count($glperiod) == 0) { $errors[] = 'No period exists for this date'; return false; } $data['value'] = bcsub($this->glbalance(), $data['new_balance']); $data['glperiods_id'] = $glperiod['id']; $data['source'] = 'C'; $data['type'] = 'V'; $data['glaccount_id'] = $this->currency_detail->writeoff_glaccount_id; $data['glcentre_id'] = $this->currency_detail->glcentre_id; GLTransaction::setTwinCurrency($data); $gl_trans[] = GLTransaction::Factory($data, $errors); $data['value'] = bcmul($data['value'], -1); $data['glaccount_id'] = $this->glaccount_id; $data['glcentre_id'] = $this->glcentre_id; GLTransaction::setTwinCurrency($data); $gl_trans[] = GLTransaction::Factory($data, $errors); $db = DB::Instance(); $db->StartTrans(); if (count($errors) == 0 && GLTransaction::saveTransactions($gl_trans, $errors)) { return $db->CompleteTrans(); } $errors[] = 'Failed to save GL Transaction'; $db->FailTrans(); $db->CompleteTrans(); return false; }
function loadJournals($data, &$errors = array(), &$warnings = array()) { $system = system::Instance(); $data_in = $this->convertData($data); if (is_array($data_in) && count($data_in) > 0) { $db = DB::Instance(); $docref = $db->GenID('gl_transactions_docref_seq'); $gl_transactions = array(); foreach ($data_in as $gl_data) { foreach ($gl_data as $model => $fields) { $glperiod = GLPeriod::getPeriod(fix_date($fields['transaction_date'])); if (!$glperiod || count($glperiod) == 0) { $errors[] = 'No period exists for this date'; break; } $fields['source'] = 'G'; $fields['type'] = 'J'; $fields['docref'] = $docref; $fields['glperiods_id'] = $glperiod['id']; GLTransaction::setTwinCurrency($fields); $gl_transaction = GLTransaction::Factory($fields, $errors); $gl_transactions[] = $gl_transaction; } } if (count($gl_transactions) > 0 && !GLTransaction::saveTransactions($gl_transactions, $errors)) { $errors[] = 'Failed to save journal import'; } } else { $errors[] = 'No data found or error converting data'; } if (count($errors) > 0) { return false; } return array('internal_id' => $gl_transaction->id, 'internal_identifier_field' => 'docref', 'internal_identifier_value' => $docref); }
function closePeriod($tax_period, $year, &$errors) { $db = DB::Instance(); $db->StartTrans(); foreach ($this->glperiod_ids as $glperiod_id) { $glperiod = DataObjectFactory::Factory('GLPeriod'); $glperiod->load($glperiod_id); if ($glperiod->isLoaded()) { $glperiod->tax_period_closed = true; if (!$glperiod->save()) { $errors[] = 'Error trying to close tax period'; break; } } else { $errors[] = 'Error trying to close tax period'; break; } } if (count($errors) == 0) { $this->tax_period_closed = true; $output_tax = $this->getVATSum(1); $input_tax = $this->getVATSum(4); $total_tax = bcsub($input_tax, $output_tax); $input_tax = bcmul($input_tax, -1); // $total_tax=$this->getVATSum(5); // if ($total_tax!=($output_tax-$input_tax)) { // $errors[]='Total VAT does not equal Output Tax minus Input Tax'; // } } if (count($errors) == 0) { $net_tax_element = array(); $glparams = DataObjectFactory::Factory('GLParams'); $net_tax_element['glcentre_id'] = $glparams->balance_sheet_cost_centre(); $glperiod = GLPeriod::getPeriod(date('Y-m-d')); if (!$glperiod || count($glperiod) == 0) { $errors[] = 'No period exists for this date'; } else { $net_tax_element['glperiods_id'] = $glperiod['id']; $net_tax_element['docref'] = $year . '-' . $tax_period; $net_tax_element['transaction_date'] = date(DATE_FORMAT); $net_tax_element['source'] = 'V'; // V = VAT Return $net_tax_element['type'] = 'N'; // N = Net Tax, P = Payment $net_tax_element['comment'] = 'VAT Return: ' . $year . ' - Tax Period ' . $tax_period; $net_tax_element['value'] = $input_tax; $net_tax_element['glaccount_id'] = $this->control_accounts['vat_input']; $this->setTwinCurrency($net_tax_element); $gltransactions[] = GLTransaction::Factory($net_tax_element, $errors, 'GLTransaction'); $net_tax_element['value'] = $output_tax; $net_tax_element['glaccount_id'] = $this->control_accounts['vat_output']; $this->setTwinCurrency($net_tax_element); $gltransactions[] = GLTransaction::Factory($net_tax_element, $errors, 'GLTransaction'); $net_tax_element['value'] = $total_tax; $net_tax_element['glaccount_id'] = $this->control_accounts['vat_control']; $this->setTwinCurrency($net_tax_element); $gltransactions[] = GLTransaction::Factory($net_tax_element, $errors, 'GLTransaction'); $this->saveTransactions($gltransactions, $errors); } } if (count($errors) > 0) { $db->FailTrans(); } return $db->CompleteTrans(); }
public function post($errors = array()) { $db = db::Instance(); // Check it hasn't been posted! if (!$this->isUnposted()) { $errors[] = 'Journal has already been posted'; return FALSE; } // Check it is a standard journal if (!$this->isStandardJournal()) { $errors[] = 'Template Journal cannot be posted'; return FALSE; } // Get all unposted transcations $this->NewTransactions(); $sh = new SearchHandler($this->transactions, false); $sh->addConstraint($this->childConstraint()); $unposted = $this->transactions->load($sh, null, RETURN_ROWS); // Save transactions to GL Transactions $db->startTrans(); foreach ($unposted as $transaction) { unset($transaction['id']); $transaction['transaction_date'] = un_fix_date($this->transaction_date); $transaction['glperiods_id'] = $this->glperiods_id; GLTransaction::setTwinCurrency($transaction); $gltransaction = GLTransaction::Factory($transaction); if (!$gltransaction->save()) { $errors[] = 'Error saving journal transaction : ' . $db->ErrorMsg(); } elseif (!$gltransaction->updateBalance($errors)) { $errors[] = 'Error updating GL balance : ' . $db->ErrorMsg(); } if ($this->accrual == 't') { $transaction['glperiods_id'] = $this->accrual_period_id; $transaction['comment'] = 'Reverse ' . $transaction['comment']; $transaction['value'] = bcmul($transaction['value'], -1); $gltransaction = GLTransaction::Factory($transaction); if (!$gltransaction->save()) { $errors[] = 'Error saving journal transaction : ' . $db->ErrorMsg(); } elseif (!$gltransaction->updateBalance($errors)) { $errors[] = 'Error updating GL balance : ' . $db->ErrorMsg(); } } } // Update the header status if no errors so far if (empty($errors) && !$this->update($this->{$this->idField}, 'status', $this->postedStatus())) { $errors[] = 'Error updating journal header status : ' . $db->ErrorMsg(); } // Delete the unposted transactions if posted OK if (count($errors) > 0 || !$this->transactions->delete($sh)) { $errors[] = 'Error updating posted journals : ' . $db->ErrorMsg(); $db->FailTrans(); } return $db->CompleteTrans(); }
public static function makeCBControl($transaction, &$errors = array()) { $mult = self::$multipliers[$transaction['source']][$transaction['type']]; $transaction['value'] = $mult * -1 * $transaction['base_gross_value']; $transaction['twinvalue'] = $mult * -1 * $transaction['twin_gross_value']; return GLTransaction::Factory($transaction, $errors); }