Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2290

Přidáno uživatelem Ondřej Fibich před téměř 11 roky(ů)

Upravy:
- revize kodu transfers controlleru
- drobeckove menu pro add_voip
- closes #821: Pri pridani prevodu seskupovat podvojne ucty dle clena

Zobrazit rozdíly:

freenetis/branches/1.2/application/controllers/json.php
$origin_account = new Account_Model($origin_account_id);
if ($origin_account->id == 0)
{
Controller::error(RECORD);
}
if (!$this->acl_check_new('Accounts_Controller', 'transfers', $origin_account->member_id))
{
Controller::error(ACCESS);
}
$id = $this->input->get('id');
$accounts = ORM::factory('account')->get_some_doubleentry_account_names(
$accounts = $origin_account->get_some_doubleentry_account_names_grouped(
$origin_account_id, $id
);
$arr_accounts = array();
$arr_accounts = array();
foreach ($accounts as $account)
{ // convert the object into array (used for HTML select list)
$name = $account->name . ' ' . $account->id . ' (' . $account->addr . ')';
$arr_accounts[$name] = $account->id;
foreach ($accounts as $i => $account)
{ // hack fliping because of JSON order browser bug
$arr_accounts[$i] = array_flip($account);
}
echo json_encode($arr_accounts);
freenetis/branches/1.2/application/controllers/transfers.php
parent::__construct();
if (!Settings::get('finance_enabled'))
Controller::error (ACCESS);
{
self::error(ACCESS);
}
}
/**
......
$order_by_direction = 'desc', $page_word = null, $page = 1)
{
if (!$this->acl_check_view('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
{
self::error(ACCESS);
}
// get new selector
if (is_numeric($this->input->post('record_per_page')))
{
$limit_results = (int) $this->input->post('record_per_page');
}
// parameters control
$allowed_order_type = array
(
......
);
if (!in_array(strtolower($order_by), $allowed_order_type))
{
$order_by = 'id';
}
if (strtolower($order_by_direction) != 'desc')
{
$order_by_direction = 'desc';
}
// there are two groups of transfers
$arr_groups[Transfer_Model::OUTER_TRANSFERS] = __('Outer transfers');
$arr_groups[Transfer_Model::INNER_TRANSFERS] = __('Inner transfers');
......
);
if (($sql_offset = ($page - 1) * $limit_results) > $total_transfers)
{
$sql_offset = 0;
}
$alltransfers = $model_transfer->get_all_transfers(
$sql_offset, (int) $limit_results, $order_by,
$order_by_direction,
......
$variable_symbol_model = new Variable_Symbol_Model();
$variable_symbols = 0;
if ($account->member_id != 1)
if ($account->member_id != Member_Model::ASSOCIATION)
{
$variable_symbols = $variable_symbol_model->find_account_variable_symbols($account->id);
}
if (!$account->id)
Controller::error(RECORD);
{
self::error(RECORD);
}
if (!(
$this->acl_check_view('Accounts_Controller', 'transfers', $account->member_id) ||
$this->acl_check_view('Members_Controller', 'currentcredit')
))
{
Controller::error(ACCESS);
self::error(ACCESS);
}
// gets grid settings
if (is_numeric($this->input->post('record_per_page')))
{
$limit_results = (int) $this->input->post('record_per_page');
}
// allowed order type array
$allowed_order_type = array
(
......
);
if (!in_array(strtolower($order_by), $allowed_order_type))
{
$order_by = 'datetime';
}
if (strtolower($order_by_direction) != 'desc')
{
$order_by_direction = 'desc';
}
// creates fields for filtering
$arr_types[Transfer_Model::INBOUND] = __('Inbound');
$arr_types[Transfer_Model::OUTBOUND] = __('Outbound');
......
)),
$filter_form->as_array()
);
if (($sql_offset = ($page - 1) * $limit_results) > $total_transfers)
{
$sql_offset = 0;
}
$transfers = $transfer_model->get_transfers(
$account_id, $sql_offset, (int) $limit_results, $order_by,
$order_by_direction,
......
$view->content->transfers_grid = $transfers_grid;
if ($this->acl_check_view('Members_Controller', 'comment', $account->member_id))
{
$view->content->comments_grid = $comments_grid;
}
$view->render(TRUE);
} // end of show_by_account function
......
public function show($transfer_id = null)
{
if (!isset($transfer_id))
Controller::warning(PARAMETER);
{
self::warning(PARAMETER);
}
if (!is_numeric($transfer_id))
Controller::error(RECORD);
{
self::error(RECORD);
}
$transfer_model = new Transfer_Model();
$transfer = $transfer_model->get_transfer($transfer_id);
if (!is_object($transfer))
Controller::error(RECORD);
{
self::error(RECORD);
}
$oa = new Account_Model($transfer->oa_id);
$da = new Account_Model($transfer->da_id);
if ($oa->member_id != 1)
if ($oa->member_id != Member_Model::ASSOCIATION)
{
$member_id = $oa->member_id;
elseif ($da->member_id != 1)
}
elseif ($da->member_id != Member_Model::ASSOCIATION)
{
$member_id = $da->member_id;
}
else
$member_id = 1;
{
$member_id = Member_Model::ASSOCIATION;
}
if (!$this->acl_check_view('Accounts_Controller', 'transfers', $member_id))
Controller::error(ACCESS);
{
self::error(ACCESS);
}
// transfers dependent on this transfer, if this transfer is member fee payment
$dependent_transfers = $transfer_model->get_dependent_transfers($transfer->id);
// bank transfer is only assigned to transfer from member fees account to account of association
$member_fees = ORM::factory('account')->where(
'account_attribute_id', Account_attribute_Model::MEMBER_FEES
)->find();
// bt has to be first set to null, transfer need not to be of bank type
$bt = null;
......
)->find();
if ($bt_model->id)
{
$bt = $bt_model->get_bank_transfer($transfer_id);
}
$headline = __('Detail of transfer number') . ' ' . $transfer->id;
$view = new View('main');
$view->title = $headline;
......
public function add_from_account($origin_account_id = null)
{
if (!isset($origin_account_id) || !is_numeric($origin_account_id))
Controller::warning(PARAMETER);
{
self::warning(PARAMETER);
}
// save for callback function valid_amount_to_send
$this->origin = $origin_account_id;
$origin_account = new Account_Model($origin_account_id);
$oa = new Account_Model($origin_account_id);
if ($origin_account->id == 0)
Controller::error(RECORD);
if (!$this->acl_check_new('Accounts_Controller', 'transfers', $origin_account->member_id))
Controller::error(ACCESS);
if ($oa->id == 0)
{
self::error(RECORD);
}
if (!$this->acl_check_new('Accounts_Controller', 'transfers', $oa->member_id))
{
self::error(ACCESS);
}
// destination account, instead of origin one
$dst_account_model = new Account_Model();
$dst_accounts = $dst_account_model->get_some_doubleentry_account_names($origin_account_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->id . ' (' . $dst_account->addr . ')';
}
asort($arr_dst_accounts, SORT_LOCALE_STRING);
$dst_accounts = $oa->get_some_doubleentry_account_names_grouped($origin_account_id);
// default destination account
$operating = ORM::factory('account')->where(
'account_attribute_id', Account_attribute_Model::OPERATING
)->find();
// array with only one origin account
$arr_orig_accounts[$origin_account->id] = $origin_account->name . ' ' . $origin_account->id;
$arr_orig_accounts[$oa->id] = $oa->name . ' ' . $oa->id;
// account attributes for types of accounts
$aa_model = new Account_attribute_Model();
$account_attributes = $aa_model->get_account_attributes();
foreach ($account_attributes as $account_attribute)
foreach ($account_attributes as $aattr)
{
$arr_attributes[$account_attribute->id] = $account_attribute->id . ' ' . $account_attribute->name;
$arr_attributes[$aattr->id] = $aattr->id . ' ' . $aattr->name;
}
$arr_attributes = arr::merge(array
(
NULL => '----- ' . __('Select account type') . ' -----'), $arr_attributes
);
NULL => '----- ' . __('Select account type') . ' -----'
), $arr_attributes);
// form
$form = new Forge('transfers/add_from_account/' . $origin_account_id);
......
->label('Origin account (account name, account ID)')
->options($arr_orig_accounts)
->rules('required')
->style('width:600px');
->style('width:450px');
// destination account
$form->group('Destination account');
$form->dropdown('account_type')
->options($arr_attributes)
->style('width:600px');
->style('width:450px');
$form->dropdown('aname')
->label('Destination account (account name, account ID)')
->options($arr_dst_accounts)
->options($dst_accounts)
->rules('required')
->selected($operating->id)
->style('width:600px');
->style('width:450px');
// other information
$form->group('Transfer');
......
$member_model = new Member_Model();
$dst_account = new Account_Model($form_data['aname']);
$member_model->reactivate_messages($origin_account->member_id);
$member_model->reactivate_messages($oa->member_id);
$member_model->reactivate_messages($dst_account->member_id);
$db->transaction_commit();
......
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members')
)->disable_translation()
->link('members/show/' . $origin_account->member_id,
'ID ' . $origin_account->member->id . ' - ' . $origin_account->member->name,
->link('members/show/' . $oa->member_id,
'ID ' . $oa->member->id . ' - ' . $oa->member->name,
$this->acl_check_view(
'Members_Controller', 'members',
$origin_account->member_id
$oa->member_id
)
)->enable_translation()
->link('transfers/show_by_account/' . $origin_account->id, 'Transfers')
->link('transfers/show_by_account/' . $oa->id, 'Transfers')
->text('Add new transfer');
$headline = __('Add new transfer');
......
public function add()
{
if (!$this->acl_check_new('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
$account_model = new Account_Model();
$accounts = $account_model->get_some_doubleentry_account_names();
$origin_accounts = $accounts;
$dst_accounts = $accounts;
foreach ($dst_accounts as $dst_account)
{
$arr_dst_accounts[$dst_account->id] = $dst_account->name . ' '
. $dst_account->id . ' (' . $dst_account->addr . ')';
self::error(ACCESS);
}
asort($arr_dst_accounts);
$a_model = new Account_Model();
// array origin accounts for dropdown
$arr_orig_accounts = $arr_dst_accounts;
$arr_accounts = $a_model->get_some_doubleentry_account_names_grouped();
// default destination account
$operating = ORM::factory('account')->where(
'account_attribute_id', Account_attribute_Model::OPERATING
)->find();
// account attributes for types of accounts
$aa_model = new Account_attribute_Model();
$account_attributes = $aa_model->get_account_attributes();
foreach ($account_attributes as $account_attribute)
{
$arr_attributes[$account_attribute->id] = $dst_account->name . ' ' . $dst_account->id;
}
// form
$form = new Forge('transfers/add');
......
$form->group('Origin account');
$form->dropdown('oname')
->label(__('Origin account (account name, account ID)') . ':')
->options($arr_orig_accounts)
->rules('required');
->label('Origin account (account name, account ID)')
->options($arr_accounts)
->rules('required')
->style('width:450px');
// destination account
$form->group('Destination account');
$form->dropdown('aname')
->label(__('Destination account (account name, account ID)') . ':')
->options($arr_dst_accounts)
->label('Destination account (account name, account ID)')
->options($arr_accounts)
->rules('required')
->selected($operating->id);
->selected($operating->id)
->style('width:450px');
// other information
$form->group('Transfer');
$form->date('datetime')
->label(__('Date and time') . ':')
->label('Date and time')
->years(date('Y') - 20, date('Y'))
->rules('required');
// no amount on origin account is required, this arbitrary transfers
// should only admin or accountant of association who knows what is he doing
$form->input('amount')
->label(__('Amount') . ':')
->rules('required|valid_numeric')
->callback(array($this, 'valid_amount'));
$form->input('text')
->label(__('Text') . ':')
->rules('required');
$form->submit('Send');
......
{
$db->transaction_rollback();
Log::add_exception($e);
status::success('Transfer hasnot been successfully added');
status::success('Transfer has not been successfully added');
}
url::redirect('transfers/show_all');
}
......
public function add_voip($origin_account = NULL)
{
if (!isset($origin_account))
Controller::warning(PARAMETER);
{
self::warning(PARAMETER);
}
$account = ORM::factory('account')->where('id', $origin_account)->find();
$origin_acc = new Account_Model($origin_account);
if (!Billing::instance()->has_driver() ||
!Billing::instance()->get_account($account->member_id))
if (!$origin_acc->id)
{
Controller::error(RECORD);
self::error(RECORD);
}
if (isset($origin_account))
{ // transfer from specific account?
// save for callback function valid_amount_to_send
$this->origin = $origin_account;
$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);
}
// yes = create object of all accounts except the origin one
$dst_account_model = new Account_Model();
$dst_accounts = $dst_account_model->get_some_doubleentry_account_names($origin_account);
if (!$this->acl_check_new('Accounts_Controller', 'transfers', $origin_acc->member_id))
{ // does the user have rights for this?
self::error(ACCESS);
}
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);
}
// yes = create object of all accounts
$origin_acc = new Account_Model();
$dst_accounts = $origin_accounts = $origin_acc->get_some_doubleentry_account_names();
if (!Billing::instance()->has_driver() ||
!Billing::instance()->get_account($origin_acc->member_id))
{
self::error(RECORD);
}
$arr_orig_accounts[$origin_acc->id] =
"$origin_acc->name - " . __('Account ID') . " $origin_acc->name - "
. __('Member ID') . " $origin_acc->member_id";
$origin_acc->name . ' - ' . __('Account ID') . ' ' . $origin_acc->id .
' - ' . __('Member ID') . ' ' . $origin_acc->member_id;
// form
$form = new Forge('transfers/add_voip/' . $origin_account);
......
$form->group('Transfer');
$form->dropdown('oname')
->label(__('Origin account'))
->options($arr_orig_accounts);
->label('Origin account')
->options($arr_orig_accounts)
->style('width:450px');
$form->date('datetime')
->label(__('Date and time') . ':')
->label('Date and time')
->years(date('Y') - 20, date('Y'))
->rules('required');
$form->input('amount')
->label(__('Amount') . ':')
->label('Amount')
->rules('required|valid_numeric')
->callback(array($this, 'valid_amount_to_send'));
......
status::success('Transfer has not been successfully added');
}
url::redirect('transfers/show_by_account/' . $origin_account);
} if ($this->acl_check_view('Members_Controller', 'members', $account->member_id))
{
$links[] = html::anchor(
'members/show/' . $account->member_id, __('Back to the member')
);
}
$links[] = html::anchor(
'transfers/show_by_account/' . $origin_account,
__('Back to transfers of account')
);
$headline = __('Add new VoIP transfer');
$headline = __('Add new VoIP transfer');
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members')
)->disable_translation()
->link('members/show/' . $origin_acc->member->id,
'ID ' . $origin_acc->member->id . ' - ' . $origin_acc->member->name,
$this->acl_check_view(
'Members_Controller', 'members',
$origin_acc->member->id
)
)->enable_translation()
->link('transfers/show_by_account/' . $origin_account,
'Transfers', $origin_account)
->text($headline);
$info[] = __('Information') . ' : ' . __('Transfer will be effected within 15 minutes.');
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->breadcrumbs = $breadcrumbs->html();
$view->content->headline = $headline;
$view->content->form = $form->html();
$view->content->link_back = implode(' | ', $links);
$view->content->aditional_info = $info;
$view->render(TRUE);
}
......
public function edit($transfer_id = NULL)
{
if (!isset($transfer_id))
Controller::warning(PARAMETER);
{
self::warning(PARAMETER);
}
// access rights
if (!$this->acl_check_edit('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
{
self::error(ACCESS);
}
$transfer = new Transfer_Model($transfer_id);
$form = new Forge('transfers/edit/' . $transfer_id);
......
{
// access rights
if (!$this->acl_check_new('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
{
self::error(ACCESS);
}
// content of dropdown for months
for ($i = 1; $i <= 12; $i++)
{
$arr_months[$i] = $i;
}
$current_month = (int) date('n');
// association
......
{
// access rights
if (!$this->acl_check_new('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
{
self::error(ACCESS);
}
// content of dropdown for months
for ($i = 1; $i <= 12; $i++)
{
$arr_months[$i] = $i;
}
$current_month = (int) date('n');
// association
......
{
// access rights
if (!$this->acl_check_new('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
{
self::error(ACCESS);
}
// content of dropdown for months
for ($i = 1; $i <= 12; $i++)
{
$arr_months[$i] = $i;
}
$current_month = (int) date('n');
// association
......
{
// bad parameter
if (!isset($member_id))
Controller::warning(PARAMETER);
{
self::warning(PARAMETER);
}
$member = new Member_Model($member_id);
if ($member->id == 0)
Controller::error(RECORD);
{
self::error(RECORD);
}
if (!$this->acl_check_new('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
{
self::error(ACCESS);
}
$credit = ORM::factory('account')->where(array
(
'member_id' => $member_id,
......
$fee = $fee_model->get_by_date_type(date('Y-m-d'), 'transfer fee');
if (is_object($fee) && $fee->id)
{
$transfer_fee = $fee->fee;
}
else
{
$transfer_fee = 0;
}
$amount = num::decimal_point((float) $amount);
// form
......
->value(__('Member fee payment by cash'))
->rules('required');
$form->group('')
->label(__('Transfer fee'));
$form->group('Transfer fee');
$form->input('transfer_fee')
->label('Amount')
......
{
// bad parameter
if (!$account_id || !is_numeric($account_id))
Controller::warning(PARAMETER);
{
self::warning(PARAMETER);
}
$account = new Account_Model($account_id);
// account doesn't exist
if (!$account->id)
Controller::error(RECORD);
{
self::error(RECORD);
}
// access control
if (!$this->acl_check_view('Accounts_Controller', 'transfers', $account->member_id))
Controller::error(ACCESS);
{
self::error(ACCESS);
}
$fee_model = new Fee_Model();
$device_model = new Device_Model();
freenetis/branches/1.2/application/models/account.php
}
// query
return $this->db->query("
SELECT a.id, a.name, a.member_id, a.account_attribute_id,
SELECT a.id, a.name, a.member_id, m.name AS member_name, a.account_attribute_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
......
ORDER BY a.name
");
}
/**
* Returns gesult of get_some_doubleentry_account_names for
* dropdown but grouped.
*
* @author Ondřej Fibich
* @param integer $origin
* @param integer $account_attribute_id
* @return array
*/
public function get_some_doubleentry_account_names_grouped(
$origin = null, $account_attribute_id = null)
{
// keys
$keys = array(__('Association'), __('Members'));
// result
$grouped_accounts = array
(
$keys[0] => array(),
$keys[1] => array()
);
// get accounts
$accounts = $this->get_some_doubleentry_account_names(
$origin, $account_attribute_id);
// group them
foreach ($accounts as $account)
{
if ($account->member_id == Member_Model::ASSOCIATION)
{
$index = $keys[0];
}
else
{
$index = $keys[1];
}
if (!array_key_exists($index, $grouped_accounts))
{
$grouped_accounts[$index] = array();
}
$grouped_accounts[$index][$account->id] = $account->name
. ' ' . $account->id . ' (' . $account->addr . ')';
}
// done
return $grouped_accounts;
}
/**
* It gets balance of account.
freenetis/branches/1.2/application/views/js/transfers_add_from_account.php
{
var options = [];
$.each(data, function(key, val)
{ // val is ID and key is name of account
options.push('<option value="');
options.push(val);
{
options.push('<optgroup label="');
options.push(key);
options.push('">');
options.push(key);
options.push('</option>');
$.each(val, function(key, val)
{
options.push('<option value="');
options.push(val);
options.push('">');
options.push(key);
options.push('</option>');
});
options.push('</optgroup>');
});
$("#aname").html(options.join(''));
});

Také k dispozici: Unified diff