Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 829

Přidáno uživatelem Jiří Sviták před téměř 14 roky(ů)

Zacatek transakci. Pridana metoda pro bezpecne pridani prevodu, obsahuje jak samotne vytvoreni prevodu, tak prepocet zdrojoveho a ciloveho uctu.

Zobrazit rozdíly:

freenetis/branches/account_transactions/application/models/member.php
m.id, m.registration, m.name,
s.street, ap.street_number, t.town, t.quarter,
m.variable_symbol, a.id AS aid,
(q2.inbound - q2.outbound) AS balance,
a.balance,
m.redirect
FROM members m
LEFT JOIN address_points ap ON m.address_point_id = ap.id
LEFT JOIN streets s ON ap.street_id = s.id
LEFT JOIN towns t ON ap.town_id = t.id
LEFT JOIN accounts a ON a.member_id = m.id AND m.id <> 1
LEFT JOIN
(
SELECT q1.id, q1.inbound, IFNULL(SUM(t.amount),0) AS outbound
FROM
(
SELECT a.id, IFNULL(SUM(t.amount),0) AS inbound
FROM accounts a
LEFT JOIN transfers t ON t.destination_id = a.id
GROUP BY a.id
) q1
LEFT JOIN transfers t ON t.origin_id = q1.id
GROUP BY q1.id
) q2 ON q2.id = a.id
$where
ORDER BY $order_by $order_by_direction
LIMIT $limit_from, $limit_results"
freenetis/branches/account_transactions/application/models/transfer.php
else
return NULL;
}
/**
* @author Jiri Svitak
* @param <type> $origin_id origin account id
* @param <type> $destination_id destination account id
* @param <type> $previous_transfer_id previous transfer id, useful for transfer groups
* @param <type> $member_id transaction owner id
* @param <type> $user_id id of user who added transfer
* @param <type> $type type of transfer, see Transfer_Model
* @param <type> $datetime accounting datetime of transfer
* @param <type> $creation_datetime datetime of transfer creation
* @param <type> $text transfer text
* @param <type> $amount amount of transfer
* @throws ErrorException when failed transfer insert, origin or destination account update
*/
public static function insert_transfer($origin_id, $destination_id, $previous_transfer_id,
$member_id, $user_id, $type, $datetime, $creation_datetime, $text, $amount)
{
try
{
// start transaction
$this->transaction_start();
// insert new transfer
$transfer = new Transfer_Model();
$transfer->origin_id = $origin_id;
$transfer->destination_id = $destination_id;
$transfer->previous_transfer_id = $previous_transfer_id;
$transfer->member_id = $member_id;
$transfer->user_id = $user_id;
$transfer->type = $type;
$transfer->datetime = $datetime;
$transfer->creation_datetime = $creation_datetime;
$transfer->text = $text;
$transfer->amount = $amount;
if (!$transfer->save())
throw new ErrorException();
// update balance of origin account
$oa = new Account_Model($origin_id);
$oa->balance -= $amount;
if (!$oa->save())
throw new ErrorException();
// update balance of destination account
$da = new Account_Model($destination_id);
$da->balance += $amount;
if (!$da->save())
throw new ErrorException();
// commit transaction
$this->transaction_commit();
}
catch (ErrorException $e)
{
$this->transaction_rollback();
throw $e;
}
}
}
?>
freenetis/branches/account_transactions/application/controllers/transfers.php
*/
class Transfers_Controller extends Controller
{
// used for storing id of origin account for callback function
protected $origin;
/**
* @author Jiri Svitak
* By default, it redirects user to day book - list of all double-entry transfers.
......
{
$form_data[$key] = htmlspecialchars($value);
}
$transfer = new Transfer_Model();
$transfer->origin_id = $form_data['oname'];
$transfer->destination_id = $form_data['aname'];
$transfer->user_id = $this->session->get('user_id');
$transfer->datetime = date('Y-m-d', $form_data['datetime']);
$transfer->creation_datetime = date('Y-m-d H:i:s');
$transfer->text = $form_data['text'];
$transfer->amount = $form_data['amount'];
if ($transfer->save())
try
{
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully added'));
Transfer_Model::insert_transfer($form_data['oname'], $form_data['aname'], null,
null, $this->session->get('user_id'), null, date('Y-m-d', $form_data['datetime']),
date('Y-m-d H:i:s'), $form_data['text'], $form_data['amount']);
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully added.'));
url::redirect(url_lang::base().'transfers/show_by_account/'.$origin_account_id);
}
catch (ErrorException $e)
{
$this->session->set_flash('message', url_lang::lang('texts.Error - cannot add new transfer.'));
url::redirect(url_lang::base().'transfers/show_by_account/'.$origin_account_id);
}
}
//if ($this->acl_check_view('Members_Controller','members', $origin_account->member_id))
freenetis/branches/account_transactions/application/controllers/accounts.php
$view->render(TRUE);
}
} // end of edit function
/**
* Goes through all double-entry accounts and calculates their balance from their transfers.
* All transfers are primary information about cash flow. Calculating balance of account
* is creating redundant information, but it speeds up all money calculating operations in system.
* This method should be used only in special cases, like changing version of Freenetis
* to version containing this method, or when some data are corrupted.
* The user is familiar with result, when no change to balance is made, then everything ok.
* In other case user is informed about count of accounts, which transfers are not corresponding
* to its balance
* @author Jiri Svitak
*/
public function recalculate_account_balances()
{
if (!$this->acl_check_edit('Accounts_Controller', 'account'))
Controller::error(ACCESS);
$account_model = new Account_Model();
}
}
?>
freenetis/branches/account_transactions/application/views/members_show.php
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Current credit').'&nbsp;'.help::hint('current_credit') ?></th>
<td><?php echo number_format((float) $account->get_account_balance($account->id), 2, ',', ' ').' '.$this->settings->get('currency') ?></td>
<td><?php echo number_format((float) $account->balance, 2, ',', ' ').' '.$this->settings->get('currency') ?></td>
</tr>
<?php if (isset($expiration_date)) { ?>
<tr>

Také k dispozici: Unified diff