Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 485

Přidáno uživatelem Jiří Sviták před asi 15 roky(ů)

Oprava chyby v upgrade_sql_478, nesla kvuli tomu instalace, uz funguje. Na ostre db ale tento upgrade prosel bez problemu, pravdepodobne tam byla nesrovnalost s vyvojovou verzi. Rozdelana prace na novem systemu strhavani clenskych prispevku. Pridany zavislosti mezi prevody pri placeni hotove. Opravena chyba pri identifikaci plateb, castka zustane po identifikaci stejna, pokuta tedy neni hned odectena, ale vyresena dalsim prevodem pro ucetni uplnost. Upravy v instalaci a nejake vychytavky ve vypisu clenu a uzivatelu. Predelan system upgradu databaze v hlavnim kontroleru. Bohuzel to vypada, ze ani po mnohem ladeni nefunguje transakcni zpracovani MySQL, coz by melo.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php
'error - it is not possible to remove admin' => 'Chyba - nelze odebrat správce zařízení.',
'error - it is not possible to remove engineer' => 'Chyba - nelze odebrat technika zařízení.',
'error - not enough money on origin account' => 'Chyba - nedostatek peněz na zdrojovém účtě.',
'error - some fees have not been deducted' => 'Chyba - některé členské příspěvky nebyly strženy.',
'error - fees have not been deducted' => 'Chyba - členské příspěvky nebyly strženy.',
'error: parameter ID is required!' => 'Chyba: parametr ID je povinný!',
'example' => 'Příklad',
'execution time' => 'Doba provádění',
......
'member cannot left association before entrance' => 'Člen nemůže opustit sdružení před vstupem.',
'member cannot be former, if his membership was not ended' => 'Člen nemůže být bývalý, pokud jeho členství nebylo ukončeno.',
'member fee' => 'Členský příspěvek',
'member fee deduction' => 'Stržení členského příspěvku',
'member fees' => 'Členské příspěvky',
'member fees nr' => 'Počet členských příspěvků',
'member fee payment by cash' => 'Platba členského příspěvku hotově',
freenetis/trunk/kohana/application/helpers/date.php
}
/**
* Function is similar to round_month, except it gets date in date format.
* @author Jiri Svitak
* @param date
* @return unknown_type
*/
public static function month($date = '0000-00-00')
{
// parsed date
$pd = date_parse($date);
if ($pd['day'] > 15)
$pd['month']++;
$pd['day'] = 1;
if ($pd['month'] > 12)
{
$pd['year']++;
$pd['month'] = 1;
}
return $pd['year'].'-'.$pd['month'].'-'.$pd['day'];
}
/**
* Function to finding difference between 2 dates
* @param $date_a date in format 'YYYY-mm-dd'
* @param $date_b date in format 'YYYY-mm-dd'
freenetis/trunk/kohana/application/models/membership_interrupt.php
WHERE mi.member_id = $member_id
");
}
/**
* Function tries to find membership interrupt in given month, for example 2009-09-01.
* @param $member_id
* @param $month
* @return unknown_type
*/
function has_mi_in_month($member_id, $month)
{
$query = self::$db->query("SELECT mi.*
FROM membership_interrupts mi
WHERE mi.member_id = $member_id
AND mi.from <= '$month'
AND mi.to > '$month'
");
return (bool) count($query);
}
}
?>
freenetis/trunk/kohana/application/models/member.php
}
}
return self::$db->query("SELECT
m.id, m.registration, m.name, s.street, ap.street_number, t.town, t.quarter, m.variable_symbol
m.id, m.registration, m.name, s.street, ap.street_number, t.town, t.quarter, m.variable_symbol, a.id AS aid
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
$where
ORDER BY $order_by $order_by_direction
LIMIT $limit_from, $limit_results"
freenetis/trunk/kohana/application/models/user.php
parent::__construct($id);
}
public function get_all_users($limit_from = 0, $limit_results = 50, $order_by = 'devices.id', $order_by_direction = 'ASC', $filter_values = array(),$member_id=NULL)
public function get_all_users($limit_from = 0, $limit_results = 50, $order_by = 'id', $order_by_direction = 'ASC', $filter_values = array(), $member_id=NULL)
{
$where = '';
if(count($filter_values)>0) $where .= 'WHERE ';
......
else $where .= ' AND u.member_id = '.$member_id;
}
return self::$db->query('SELECT
u.id, u.name, u.surname, u.login, u.email, u.member_id
u.id, u.name, u.surname, u.login, u.email, u.phone, u.member_id
FROM users u
'.$where.'
ORDER BY '.$this->arr_sql[$order_by].' '.$order_by_direction.'
freenetis/trunk/kohana/application/models/transfer.php
}
/**
* Finding deducting fee.
* Finding deducting fee of given month and account.
* @param $year
* @param $origin_credit_account
* @return unknown_type
*/
public function get_deduct_transfer($year, $origin_credit_account)
public function get_deduct_transfer($month, $origin_credit_account)
{
return self::$db->query("SELECT * FROM transfers
WHERE type = ".Transfer_Model::$deduct_member_fee." AND datetime LIKE '%".$year."%'
WHERE type = ".Transfer_Model::$deduct_member_fee." AND datetime LIKE '%".$month."%'
AND origin_id = ".$origin_credit_account
)->current();
}
freenetis/trunk/kohana/application/controllers/members.php
$grid->action_field('id') ->label(url_lang::lang('texts.Member')) ->url(url_lang::base().'members/edit') ->action(url_lang::lang('texts.Edit'));
// member should never be deleted
//$grid->action_field('member_id') ->label(url_lang::lang('texts.Delete')) ->url(url_lang::base().'members/delete') ->action(url_lang::lang('texts.Delete'))->script('onclick="return potvrd(\''.url_lang::lang('texts.delete_member').'\');"');
if ($this->acl_check_edit(get_class($this), 'members'))
$grid->action_field('aid') ->label(url_lang::lang('texts.Transfers')) ->url(url_lang::base().'transfers/show_by_account')->action(url_lang::lang('texts.Show'));
$grid->datasource($query);
$view = new View('main');
......
if ($this->acl_check_edit(get_class($this),'organization_id', $member_id))
$form->input('organization_identifier')->label(url_lang::lang('texts.Organization identifier').':')->rules('length[3,20]')->value($member_data->organization_identifier);
if ($this->acl_check_edit('Members_Controller', 'var_sym', $member_id))
$form->input('variable_symbol')->label(url_lang::lang('texts.Variable symbol').':')->rules('required|length[9,10]')->value($member_data->variable_symbol)->callback(array($this, 'valid_var_sym'));
$form->input('variable_symbol')->label(url_lang::lang('texts.Variable symbol').':')->rules('required|length[1,10]')->value($member_data->variable_symbol)->callback(array($this, 'valid_var_sym'));
$form->group('')->label(url_lang::lang('texts.Address'));
if ($this->acl_check_edit(get_class($this),'address',$member_id))
......
$member_model = new Member_Model();
$members = $member_model->where(array('variable_symbol' => $value, 'id!=' => $this->member_id))->find_all();
$total = count($members);
if (!ereg("^[0-9]{9,10}$", $value))
if (!ereg("^[0-9]{1,10}$", $value))
{
$input->add_error('required', url_lang::lang('texts.Bad variable symbol format.'));
}
freenetis/trunk/kohana/application/controllers/installation.php
$form->input('email')->label(url_lang::lang('texts.email').':')->rules('length[3,50]');
// bank account
$form->group('')->label(url_lang::lang('texts.The first bank account information'));
$form->input('account_name')->label(url_lang::lang('texts.Account name'))->rules('required|length[3,50]');
$form->input('account_comment')->label(url_lang::lang('texts.Comment'));
$form->input('account_nr')->label(url_lang::lang('texts.Account number'))->rules('required|length[3,50]|valid_numeric');
$form->input('bank_nr')->label(url_lang::lang('texts.Bank code'))->rules('required|length[3,10]|valid_numeric');
$form->input('IBAN')->label(url_lang::lang('texts.IBAN'));
$form->input('SWIFT')->label(url_lang::lang('texts.SWIFT'));
$form->input('account_name')->label(url_lang::lang('texts.Account name').':')->rules('required|length[3,50]');
$form->input('account_nr')->label(url_lang::lang('texts.Account number').':')->rules('required|length[3,50]|valid_numeric');
$form->input('bank_nr')->label(url_lang::lang('texts.Bank code').':')->rules('required|length[3,10]|valid_numeric');
$form->input('IBAN')->label(url_lang::lang('texts.IBAN').':');
$form->input('SWIFT')->label(url_lang::lang('texts.SWIFT').':');
// fees
$form->group('')->label(url_lang::lang('texts.Fees'));
$form->input('entrance_fee')->label(url_lang::lang('texts.Entrance fee'))->rules('valid_numeric');
$form->input('regular_member_fee')->label(url_lang::lang('texts.Monthly member fee'))->rules('required|valid_numeric');
$form->input('transfer_fee')->label(url_lang::lang('texts.Transfer fee'))->rules('valid_numeric');
$form->input('penalty')->label(url_lang::lang('texts.Penalty'))->rules('valid_numeric');
$form->input('entrance_fee')->label(url_lang::lang('texts.Entrance fee').':')->rules('valid_numeric');
$form->input('regular_member_fee')->label(url_lang::lang('texts.Monthly member fee').':')->rules('valid_numeric');
$form->input('transfer_fee')->label(url_lang::lang('texts.Transfer fee').':')->rules('valid_numeric');
$form->input('penalty')->label(url_lang::lang('texts.Penalty').':')->rules('valid_numeric');
// system
$form->group('')->label(url_lang::lang('texts.System'));
$form->input('title')->label(url_lang::lang('texts.Page title').':')->value('Freenetis')->rules('required');
$form->input('currency')->label(url_lang::lang('texts.Currency').':')->rules('required');
// submit button
$form->submit('submit')->value(url_lang::lang('texts.Install'));
special::required_forge_style($form, ' *', 'required');
......
$penalty->to = $to;
$penalty->type_id = $enum_type->get_type_id('penalty');
$penalty->save();
// system settings
$config_model = new Config_Model();
$config_model->insert_variable('title', $form_data['title']);
$config_model->insert_variable('currency', $form_data['currency']);
// redirection to login screen
url::redirect(url_lang::base().'login');
die();
}
$view = new View('installation');
$view->title = url_lang::lang('texts.Installation');
freenetis/trunk/kohana/application/controllers/users.php
$grid->order_field('name')->label(url_lang::lang('texts.Name'));
$grid->order_field('surname')->label(url_lang::lang('texts.Surname'));
$grid->order_field('login')->label(url_lang::lang('texts.Username'));
$grid->order_field('email')->label('E-mail');
$grid->order_field('phone')->label(url_lang::lang('texts.Phone'));
if ($this->acl_check_view(get_class($this),'users'))
$grid->action_field('id') ->label(url_lang::lang('texts.User')) ->url(url_lang::base().'users/show') ->action(url_lang::lang('texts.Show'));
if ($this->acl_check_edit(get_class($this),'users'))
$grid->action_field('id') ->label(url_lang::lang('texts.User')) ->url(url_lang::base().'users/edit') ->action(url_lang::lang('texts.Edit'));
if ($this->acl_check_view(get_class($this),'users'))
$grid->action_field('member_id') ->label(url_lang::lang('texts.Member')) ->url(url_lang::base().'members/show') ->action(url_lang::lang('texts.Show'));
if ($this->acl_check_view('Devices_Controller','devices'))
$grid->action_field('id') ->label(url_lang::lang('texts.Devices')) ->url(url_lang::base().'devices/show_by_user')->action(url_lang::lang('texts.Show'));
if ($this->acl_check_view('Users_Controller','work'))
$grid->action_field('id') ->label(url_lang::lang('texts.Works')) ->url(url_lang::base().'works/show_by_user')->action(url_lang::lang('texts.Show'));
//if ($this->acl_check_delete(get_class($this),'users'))
// $grid->action_field('id')->label(url_lang::lang('texts.User'))->url(url_lang::base().'users/delete')->action(url_lang::lang('texts.Delete'))->script('onclick="return potvrd(\''.url_lang::lang('texts.delete_user').'\');"');
$grid->datasource($query);
freenetis/trunk/kohana/application/controllers/transfers.php
$dependent_transfers = $transfer_model->get_dependent_transfers($transfer->id);
$bt = null;
// bank transfer is only assigned to transfer from member fees account to account of association
if ($transfer->oa_id == $account_model->get_member_fees_account()->id)
$member_fees = ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$member_fees);
$bt_model = ORM::factory('bank_transfer')->find_by_transfer_id($transfer->id);
if ($transfer->oa_id == $member_fees->id && is_object($bt_model) && $bt_model->id != 0)
{
$bt_model = new Bank_transfer_Model();
$bt = $bt_model->get_bank_transfer($transfer_id);
}
$headline = url_lang::lang('texts.Detail of transfer number').' '.$transfer->id;
......
}
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;
// 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->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');
$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_to_send'));
......
$form->dropdown('month')->label(url_lang::lang('texts.Month from').':')->rules('required')->options($arr_months)->selected(1);
$form->dropdown('months')->label(url_lang::lang('texts.Number of months').':')->rules('required')->options($arr_months)->selected(1)->callback(array($this, 'valid_months'));
$form->input('fee')->label(url_lang::lang('texts.Monthly member fee').':')->rules('required|valid_numeric');
$form->input('text')->label(url_lang::lang('texts.Text').':');
$form->input('text')->label(url_lang::lang('texts.Text').':')->value(url_lang::lang('texts.Member fee deduction'));
$form->submit('submit')->value(url_lang::lang('texts.Deduct'));
special::required_forge_style($form, ' *', 'required');
// form validation
......
{
$form_data[$key] = htmlspecialchars($value);
}
$year = $arr_years[$form_data['year']];
$month = $form_data['month'];
$months = $form_data['months'];
$fee = $form_data['fee'];
$text = $form_data['text'];
// all transfers should have the same date and time of creation
// all transfer should have the same time of creation
$creation_datetime = date('Y-m-d H:i:s');
// and all transfers should have the same date of deduct start
$datetime = date('Y-m-d H:i:s', mktime(0, 0, 0, $month, 1, $year));
// database models
$transfer = new Transfer_Model();
$member_model = new Member_Model();
$account_model = new Account_Model();
$mi_model = new Membership_interrupt_Model();
$transfer_model = new Transfer_Model;
// it gets ids and member ids of all credit accounts
$credit_accounts = $account_model->get_accounts_of_regular_members();
//$account_model = new Account_Model();
//$credit_accounts = $account_model->get_accounts_of_regular_members();
$credit_accounts = ORM::factory('account')->find_all_by_account_attribute_id(Account_attribute_Model::$credit);
// it gets id of operating account, the only destination account
$oa = ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$operating);
// it supposes that everything will be ok, if a transfer couldn't be created, it sets to false
$operating = ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$operating);
// it is suppossed that thousands of transfers will be generated, transaction processing required
$save_successful = true;
// it is suppossed that thousands of transfers will be generated, transaction processing required
$db = new Database();
$db->query("BEGIN;");
// it goes through all credit accounts and it creates their outbound transfers to operating account
foreach($credit_accounts as $ca)
{
// starting month
$start = $month;
// finishing month
$finish = $month + $months - 1;
// member fee info includes entrance date, leaving date and member type
$member_fee_info = $member_model->get_fee_information($ca->id);
// for every account it gets entrance year and month of its owning member
$entrance = date_parse($member_fee_info->entrance_date);
// entrance date is rounded
$entrance = date_parse(date::round_month($entrance['day'], $entrance['month'], $entrance['year']));
$e_year = $entrance['year'];
$e_month = $entrance['month'];
$e_day = $entrance['day'];
// fee is deducted only if membership exists before upper date of deducting interval
$e_okay = ($e_year < $year) || ($e_year == $year && $e_month <= $finish);
// if member entered association after start of deducting interval
if ($e_year == $year && $e_month > $start)
// it goes through months of interval
for ($i = $form_data['month']; $i <= $form_data['months']; $i++)
{
$start = $e_month;
}
// for every account it gets leaving year and month of its owning member
$leaving_date = date_parse($member_fee_info->leaving_date);
// if leaving date was set
if ($leaving_date['year'] != '0')
{
// leaving date is rounded
$leaving_date = date_parse(date::round_month($leaving_date['day'], $leaving_date['month'], $leaving_date['year']));
$l_year = $leaving_date['year'];
$l_month = $leaving_date['month'];
$l_day = $leaving_date['day'];
// fee is deducted only if membership exists before upper date of deducting interval
$l_okay = ($l_year > $year) || ($l_year == $year && $l_month > $start);
// if member left before end of deducting interval
if ($l_year == $year && $l_month <= $finish)
//$month = $arr_years[$form_data['year']].'-'.$i.'-01';
$month = date('Y-m-d', mktime(0, 0, 0, $i, 1, $arr_years[$form_data['year']]));
if ($this->has_to_pay($ca->member_id, $month))
{
// leaving month is not included in deduction
$finish = $l_month - 1;
// trying to find existing transfer of given month
$existing = $transfer_model->get_deduct_transfer($month, $ca->id);
if (is_object($existing))
$transfer = new Transfer_Model($existing->id);
else
$transfer = new Transfer_Model();
$transfer->origin_id = $ca->id;
$transfer->destination_id = $operating->id;
$transfer->user_id = $this->session->get('user_id');
$transfer->type = Transfer_Model::$deduct_member_fee;
$transfer->datetime = $month;
$transfer->creation_datetime = $creation_datetime;
$transfer->text = $form_data['text'];
$transfer->amount = $form_data['fee'];
// money transfer is saved and checked
if (!$transfer->save())
$save_successful = false;
}
}
else
{
$l_okay = true;
}
// for every member it searches interrupts of membership
$mis = $mi_model->get_mi($ca->member_id);
// defualt number of months with interrupted membership
$interrupted = 0;
foreach ($mis as $mi)
{
$from = date_parse($mi->from);
$from = date_parse(date::round_month($from['day'], $from['month'], $from['year']));
$to = date_parse($mi->to);
$to = date_parse(date::round_month($to['day'], $to['month'], $to['year']));
// membership was interrupted before starting month and interrupt lasted after finishing one
if ((($from['year'] < $year) || ($from['year'] == $year && $from['month'] <= $start))
&& (($to['year'] > $year) || ($to['year'] == $year && $to['month'] >= $finish)))
{
// all months will be interrupted, no fee is deducted
$interrupted += $finish - $start;
}
// membership was interrupted before starting month,
// but interrupt ended after starting one and before finishing one
else if ((($from['year'] < $year) || ($from['year'] == $year && $from['month'] < $start))
&& ($to['year'] == $year && $to['month'] >= $start)
&& ($to['year'] == $year && $to['month'] < $finish))
{
$interrupted += $to['month'] - $start;
}
// membership was interrupted after starting month and before finishing month,
// and interrupt ended after finishing month
else if (($from['year'] == $year && $from['month'] > $start)
&& ($from['year'] == $year && $from['month'] <= $finish)
&& (($to['year'] > $year) || ($to['year'] == $year && $to['month'] > $finish)))
{
$interrupted += $finish - $from['month'];
}
// membership was interrupted after starting month and before finishing month
else if (($from['year'] == $year && $from['month'] >= $start)
&& ($to['year'] == $year && $to['month'] <= $finish))
{
$interrupted += $to['month'] - $from['month'];
}
}
// total months to deduct fees
$total_months = $finish - $start + 1 - $interrupted;
// if deducting interval is between entrance and leaving date, transfer will be generated
if ($e_okay && $l_okay && $total_months > 0)
{
// trying to find existing transfer of given year
$existing = $transfer->get_deduct_transfer($year, $ca->id);
if (is_object($existing))
$transfer = new Transfer_Model($existing->id);
else
$transfer = new Transfer_Model();
$transfer->origin_id = $ca->id;
$transfer->destination_id = $oa->id;
$transfer->user_id = $this->session->get('user_id');
$transfer->type = Transfer_Model::$deduct_member_fee;
$transfer->datetime = $datetime;
$transfer->creation_datetime = $creation_datetime;
$transfer->text = $text;
$transfer->amount = $total_months * $fee;
// money transfer is saved and checked
if (!$transfer->save())
$save_successful = false;
}
}
// end of transaction processing
if ($save_successful)
......
else
{
$db->query("ROLLBACK;");
$this->session->set_flash('message', url_lang::lang('texts.Error - some fees have not been deducted.'));
$this->session->set_flash('message', url_lang::lang('texts.Error - fees have not been deducted.'));
}
url::redirect(url_lang::base().'transfers/show_all');
}
......
if ($member->id == 0)
Controller::error(RECORD);
// entrance date
$entrance = $member->entrance_date <= $month;
$entrance = date::month($member->entrance_date) <= $month;
// leaving date
$leaving = $member->leaving_date > $month;
}
if ($member->leaving_date != '0000-00-00')
$leaving = date::month($member->leaving_date) > $month;
else
$leaving = true;
// membership interrupt
$mi_model = new Membership_interrupt_Model();
$mi = !($mi_model->has_mi_in_month($member_id, $month));
public function pokus()
{
echo '2009-08-07'<='2010-09-04';
// result
return $entrance && $leaving && $mi;
}
/**
* Function deducts member fees.
* @return unknown_type
......
$transfer2 = new Transfer_Model();
$transfer2->origin_id = $operating->id;
$transfer2->destination_id = $credit->id;
$transfer2->previous_transfer_id = $transfer1->id;
$transfer2->user_id = $this->session->get('user_id');
$transfer2->datetime = date('Y-m-d', $form_data['datetime']);
$transfer2->creation_datetime = date('Y-m-d H:i:s', time());
......
$tf = new Transfer_Model();
$tf->origin_id = $credit->id;
$tf->destination_id = $operating->id;
$tf->previous_transfer_id = $transfer1->id;
$tf->user_id = $this->session->get('user_id');
$tf->datetime = date('Y-m-d', $form_data['datetime']);
$tf->creation_datetime = date('Y-m-d H:i:s', time());
freenetis/trunk/kohana/application/controllers/bank_transfers.php
$bt_model = new Bank_transfer_Model();
$bt = $bt_model->get_bank_transfer($trans_id);
$fee_model = new Fee_Model();
$fee = $fee_model->get_by_date_type(date('Y-m-d'), 'penalty');
if (is_object($fee) && $fee->id)
$penalty_fee = $fee->fee;
// penalty
$fee1 = $fee_model->get_by_date_type(date('Y-m-d'), 'penalty');
if (is_object($fee1) && $fee1->id)
$penalty_fee = $fee1->fee;
else
$penalty_fee = 0;
// transfer fee
$fee2 = $fee_model->get_by_date_type(date('Y-m-d'), 'transfer fee');
if (is_object($fee2) && $fee2->id)
$transfer_fee = $fee2->fee;
else
$transfer_fee = 0;
// form
$form = new Forge(url_lang::base().'bank_transfers/assign_transfer/'.$trans_id, '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Payment'));
......
$form->input('correct_vs')->label(url_lang::lang('texts.Or enter correct variable symbol').':')->callback(array($this, 'valid_var_sym'));
$form->input('text')->label(url_lang::lang('texts.Text').':')->rules('required')->value(url_lang::lang('texts.Assigning of unidentified payment'));
$form->group('')->label(url_lang::lang('texts.Penalty'));
$form->input('penalty')->label(url_lang::lang('texts.Penalty').':')->value($penalty_fee)->rules('valid_numeric');
$form->input('penalty')->label(url_lang::lang('texts.Penalty').':')->value($penalty_fee)->rules('required|valid_numeric');
$form->input('penalty_text')->label(url_lang::lang('texts.Text').':')->value(url_lang::lang('texts.Penalty for unidentified transfer'));
$form->group('')->label(url_lang::lang('texts.Transfer fee'));
$form->input('transfer_fee')->label(url_lang::lang('texts.Amount').':')->value($transfer_fee)->rules('required|valid_numeric');
$form->input('fee_text')->label(url_lang::lang('texts.Text').':')->value(url_lang::lang('texts.Transfer fee'));
$form->submit('submit')->value(url_lang::lang('texts.Assign'));
special::required_forge_style($form, ' *', 'required');
special::required_forge_style($form, ' *', 'required');
// validation
if ($form->validate())
{
$form_data = $form->as_array();
......
$t->member_id = $member_id;
$t->save();
// new amount should be calculated, if association has fee for bank transfers
$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 = $bt->amount - $transfer_fee;
// then we create a new transfer to the selected member's account:
$t->clear();
$time_now = date("Y-m-d H:i:s", time());
$t->member_id = $member_id;
$t->user_id = $this->session->get('user_id');
$t->origin_id = $bt->destination_id;
$t->destination_id = $dst_id;
$t->previous_transfer_id = $bt->id;
$t->user_id = $this->session->get('user_id');
$t->datetime = $bt->datetime;
$t->creation_datetime = $time_now;
$t->text = $form_data['text'];
$t->amount = $amount;
$new_save = $t->save();
$t->amount = $bt->amount;
$identified_saved = $t->save();
// assign also all subsequent transfers to the selected member
$next_ts = ORM::factory('transfer')->find_all_by_previous_transfer_id($trans_id);
foreach ($next_ts as $transfer)
......
{
$operating = ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$operating);
$pen = new Transfer_Model();
$pen->user_id = $this->session->get('user_id');
$pen->origin_id = $dst_id;
$pen->destination_id = $operating->id;
$pen->previous_transfer_id = $bt->id;
$pen->user_id = $this->session->get('user_id');
$pen->datetime = $bt->datetime;
$pen->creation_datetime = $time_now;
$pen->text = $form_data['penalty_text'];
$pen->amount = $form_data['penalty'];
$pen_save = $pen->save();
}
if ($t->save() && $pen_save)
// transfer fee, if it has to be generated
$tf_saved = true;
if ($form_data['transfer_fee'] > 0)
{
$tf = new Transfer_Model();
$tf->origin_id = $dst_id;
$tf->destination_id = $operating->id;
$tf->previous_transfer_id = $bt->id;
$tf->user_id = $this->session->get('user_id');
$tf->datetime = $bt->datetime;
$tf->creation_datetime = $time_now;
$tf->text = $form_data['fee_text'];
$tf->amount = $form_data['transfer_fee'];
$tf_saved = $tf->save();
}
if ($identified_saved && $pen_save && $tf_saved)
{
$this->session->set_flash('message', url_lang::lang('texts.Payment has been successfully assigned.'));
url::redirect(url_lang::base().'bank_transfers/unidentified_transfers');
}
......
function valid_var_sym($input)
{
$member = ORM::factory('member')->find_by_variable_symbol(trim($input->value));
if (!is_object($member) || $member->id == 0)
if ($this->input->post('name') == 0)
{
$input->add_error('required', url_lang::lang('texts.Variable symbol has not been found in the database.'));
$member = ORM::factory('member')->find_by_variable_symbol(trim($input->value));
if (!is_object($member) || $member->id == 0)
{
$input->add_error('required', url_lang::lang('texts.Variable symbol has not been found in the database.'));
}
}
}
}
freenetis/trunk/kohana/application/upgrade_sql/upgrade_sql_478.php
VALUES (
'34', '29', '12', '13', 'VoIP admins', 'voip_admins');",
"DELETE FROM `acl` WHERE `acl`.`id` = 67 LIMIT 1",
"INSERT INTO `acl` (
`id` ,
`section_value` ,
......
`value`
)
VALUES (
'67', 'freenetis', 'view_all'
), (
'67', 'freenetis', 'edit_all'
), (
'67', 'freenetis', 'new_all'
freenetis/trunk/kohana/application/libraries/MY_Controller.php
public function __construct()
{
parent::__construct();
// database connection
if(!$this->test_db())
// testing database connection
try
{
Database::instance()->connect();
}
catch (Kohana_Database_Exception $e)
{
// this error message does not work
//$this->error(DATABASE);
echo url_lang::lang('states.Failed to connect to database');
......
die();
}
private function test_db()
{
try
{
Database::instance()->connect();
}
catch (Kohana_Database_Exception $e)
{
return FALSE;
}
return TRUE;
}
function get_current_svn_db_schema_info()
{
require_once("application/upgrade_sql/upgrade_sql.php");
......
function upgrade_sql($from_version = 0)
{
$ok = true;
$this->db = new Database();
$config = new Config_Model();
// database transaction
$this->db->query('BEGIN;');
try
for ($i = ($from_version+1); $i<($this->current_svn_db_schema_version); $i++)
{
for ($i = ($from_version+1); $i<($this->current_svn_db_schema_version); $i++)
if (file_exists("application/upgrade_sql/upgrade_sql_".$i.".php"))
{
if (file_exists("application/upgrade_sql/upgrade_sql_".$i.".php"))
require("application/upgrade_sql/upgrade_sql_".$i.".php");
// database transaction
$this->db->query('START TRANSACTION;');
try
{
require("application/upgrade_sql/upgrade_sql_".$i.".php");
foreach ($upgrade_sql[$i] as $query)
$this->db->query($query);
$config->set_db_schema_version($i);
}
catch (Kohana_Database_Exception $e)
{
$this->db->query('ROLLBACK;');
$this->profiler = new Profiler();
echo $this->profiler->render(true);
$this->error(UPGRADE, $query);
}
$config->set_db_schema_version($i);
$this->db->query('COMMIT;');
}
}
// database transaction
$this->db->query('START TRANSACTION;');
try
{
foreach ($this->upgrade_sql[$this->current_svn_db_schema_version] as $query)
$this->db->query($query);
$config->set_db_schema_version($this->current_svn_db_schema_version);
}
// catch exception, cancel database queries
catch (Kohana_Database_Exception $e)
{
$this->db->query('ROLLBACK;');
$this->profiler = new Profiler();
echo $this->profiler->render(true);
$this->error(UPGRADE, $query);
}
// everything ok, transaction commit
$config->set_db_schema_version($this->current_svn_db_schema_version);
$this->db->query('COMMIT;');
}

Také k dispozici: Unified diff