Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 608

Přidáno uživatelem Tomáš Dulík před téměř 15 roky(ů)

Pridana moznost prevadet penize ze svych kreditnich uctu i pro radne cleny. Pro adminy pridana moznost prevadet penize z libovolneho uctu na libovolny ucet.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/models/account.php
* Function gets some double-entry accounts. Used in dropdown to select destination account.
* @return unknown_type
*/
public function get_some_doubleentry_account_names($origin)
public function get_some_doubleentry_account_names($origin=null)
{
return self::$db->query("SELECT a.id, a.name, a.member_id
FROM accounts a
WHERE (a.account_attribute_id = ".Account_attribute_Model::$credit."
OR a.account_attribute_id = ".Account_attribute_Model::$operating."
OR a.account_attribute_id = ".Account_attribute_Model::$project.")
AND a.id <> ".$origin
if ($origin !== null) $cond_origin="AND a.id <> $origin ";
else $cond_origin="";
return self::$db->query("SELECT a.id, a.name, a.member_id,
IF(t.quarter IS NULL, concat(t.town, ' ', p.street_number),
concat(t.town, '-', t.quarter, ' ', p.street_number)) AS addr
FROM accounts a
JOIN members m ON
a.member_id=m.id
AND (a.account_attribute_id = ".Account_attribute_Model::$credit."
OR a.account_attribute_id = ".Account_attribute_Model::$operating."
OR a.account_attribute_id = ".Account_attribute_Model::$project.")
$cond_origin
JOIN address_points p ON m.address_point_id=p.id
JOIN towns t ON t.id=p.town_id"
);
}
freenetis/trunk/kohana/application/controllers/transfers.php
'query_string' => $query_string,
'filter' => $filter->view
));
if ($this->acl_check_edit('Accounts_Controller', 'transfers'))
if ($this->acl_check_edit('Accounts_Controller', 'transfers')) {
$grid->add_new_button(url_lang::base().'transfers/add', url_lang::lang('texts.Add'));
$grid->add_new_button(url_lang::base().'transfers/deduct_fees', url_lang::lang('texts.Deduction of member fees'));
if ($this->acl_check_edit('Accounts_Controller', 'transfers'))
$grid->add_new_button(url_lang::base().'transfers/deduct_entrance_fees', url_lang::lang('texts.Deduction of entrance fees'), array('onclick' => 'return potvrd(\''.url_lang::lang('texts.Are you sure you want to deduct all entrance fees').'\')'));
}
$grid->order_field('id')->label('ID');
$grid->field('origin')->label(url_lang::lang('texts.Origin account'));
$grid->order_field('o_attribute')->label(url_lang::lang('texts.Type'));
......
));
if ($this->acl_check_view('Accounts_Controller', 'accounts'))
$grid->add_new_button(url_lang::base().'members/show/'.$account->member_id, url_lang::lang('texts.Back to the member'));
if ($this->acl_check_new('Accounts_Controller', 'transfers'))
if ($this->acl_check_new('Accounts_Controller', 'transfers', $account->member_id))
$grid->add_new_button(url_lang::base().'transfers/add/'.$account_id, url_lang::lang('texts.Send money to other account'));
if ($account->account_attribute_id == Account_attribute_Model::$credit)
{
......
/**
* Function adds transfers. Transfer can be send only.
* @author Jiri Svitak
* @author Jiri Svitak, Tomas Dulik
* @param $origin_account
* @return unknown_type
*/
function add($origin_account = NULL)
{
if (!isset($origin_account))
Controller::warning(PARAMETER);
$account = new Account_Model($origin_account);
if ($account->id == 0)
Controller::error(RECORD);
if (!$this->acl_check_new('Accounts_Controller', 'transfers', $account->member_id))
Controller::error(ACCESS);
$account_model = new Account_Model();
$accounts = $account_model->get_some_doubleentry_account_names($origin_account);
foreach ($accounts as $account)
{
$arr_accounts[$account->id] = $account->name.' - '.url_lang::lang('texts.Account ID').' '.$account->id.' - '.url_lang::lang('texts.Member ID').' '.$account->member_id;
if (isset($origin_account)) { // transfer from specific account ?
$this->origin = $origin_account; // save for callback function valid_amount_to_send
$origin_acc = new Account_Model($origin_account);
if ($origin_acc->id == 0)
Controller::error(RECORD);
if (!$this->acl_check_new('Accounts_Controller', 'transfers', $origin_acc->member_id)) // does the user have rights for this?
Controller::error(ACCESS);
$dst_account_model = new Account_Model(); // yes = create object of all accounts except the origin one
$dst_accounts = $dst_account_model->get_some_doubleentry_account_names($origin_account);
} else { // transfer from any (arbitrary) account
if (!$this->acl_check_new('Accounts_Controller', 'transfers')) // Does the user have the rights for this?
Controller::error(ACCESS);
$origin_acc = new Account_Model(); // yes = create object of all accounts
$dst_accounts = $origin_accounts = $origin_acc->get_some_doubleentry_account_names();
}
asort($arr_accounts);
$this->origin = $origin_account;
$origin_acc = new Account_Model($origin_account);
$options[$origin_acc->id] = $origin_acc->name.' - '.url_lang::lang('texts.Account ID').' '.$origin_acc->name.' - '.url_lang::lang('texts.Member ID').' '.$origin_acc->member_id;
foreach ($dst_accounts as $dst_account) { // convert the object into array (used for HTML select list)
$arr_dst_accounts[$dst_account->id] =
"$dst_account->name, $dst_account->addr - ".url_lang::lang('texts.Account ID')." $dst_account->id - "
.url_lang::lang('texts.Member ID')." $dst_account->member_id";
}
asort($arr_dst_accounts);
if (!isset($origin_account)) // for transfer from any account, use the same array for origin account list
$arr_orig_accounts=$arr_dst_accounts;
else
$arr_orig_accounts[$origin_acc->id] =
"$origin_acc->name - ".url_lang::lang('texts.Account ID')." $origin_acc->name - "
.url_lang::lang('texts.Member ID')." $origin_acc->member_id";
// default destination account
$operating = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$operating)->find();
// form
$form = new Forge(url_lang::base().'transfers/add/'.$origin_account, '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Transfer'));
$form->dropdown('oname')->label(url_lang::lang('texts.Origin account'))->options($options);
$form->dropdown('aname')->label(url_lang::lang('texts.Destination credit account').':')->options($arr_accounts)->rules('required')->selected($operating->id);
$form->dropdown('oname')->label(url_lang::lang('texts.Origin account'))->options($arr_orig_accounts);
$form->dropdown('aname')->label(url_lang::lang('texts.Destination credit account').':')->options($arr_dst_accounts)->rules('required')->selected($operating->id);
$form->date('datetime')->label(url_lang::lang('texts.Date and time').':')->years(date('Y')-20, date('Y'))->rules('required');
$form->input('amount')->label(url_lang::lang('texts.Amount').':')->rules('required|valid_numeric')->callback(array($this, 'valid_amount'));
$form->input('text')->label(url_lang::lang('texts.Text'))->rules('required');
......
$form_data[$key] = htmlspecialchars($value);
}
$transfer = new Transfer_Model();
$transfer->origin_id = $origin_account;
$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']);

Také k dispozici: Unified diff