Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 512

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

Dodelano strhavani clenskych prispevku. Podstatne zrychleno. Vylepseno a zrychleno bylo take strhavani vstupnich prispevku. Sloupec entrance_fee_left (nedoplatek vstupniho prispevku) uz neni potreba, problem vyresen bez nej. Nelze strhavat vstupni prispevek jednotlive pro clena. Oba druhy strhavani se ovladaji z ucetniho deniku. Strzeni lze vzdy prepocitat. Takze to je naprosto chybovzdorne a "jowakovzdorne" :)

Zobrazit rozdíly:

freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php
'display member' => 'Zobraz člena',
'display user' => 'Zobraz uživatele',
'do transfer' => 'Proveď transakci',
'do you want to deduct this member\'s entrance fee' => 'Chcete strhnout vstupní příspěvek tohoto člena',
'do you want to delete this address point' => 'Chcete smazat tento adresní bod',
'do you want to delete this device' => 'Chcete smazat toto zařízení',
'do you want to delete this interface' => 'Chcete smazat toto rozhraní',
......
'entrance fee' => 'Vstupní příspěvek',
'entrance fee has been successfully deducted' => 'Vstupní příspěvek byl úspěšně stržen.',
'entrance fee have to be a number' => 'Vstupní příspěvk musí být číslo',
'entrance fee left' => 'Nedoplatek vstupního příspěvku',
'entrance fees have been successfully deducted' => 'Vstupní příspěvky byly úspěšně strženy.',
'enum type has been successfully added' => 'Výčet byl úspěšně přidán',
'enum type has been successfully deleted' => 'Výčet byl úspěšně smazán',
freenetis/trunk/kohana/application/models/member.php
LEFT JOIN (SELECT * FROM translations WHERE lang = '".Config::item('locale.lang')."') f ON e.value = f.original_term");
}
/**
* Function gets all members to deduct entrance fees.
* @return unknown_type
*/
public function get_all_members_to_deduct_entrance_fees()
{
return self::$db->query("SELECT m.id, a.id AS aid
FROM members m
JOIN accounts a ON a.member_id = m.id
AND a.account_attribute_id = ".Account_attribute_Model::$credit."
WHERE m.entrance_fee_left <> 0
");
}
public function get_members_of_subnet($subnet_id)
{
return self::$db->query("SELECT DISTINCT m.id
......
array('members.registration', 'members.name as namem', 'members.address_point_id',
'members.variable_symbol',
'members.type as typem', 'members.organization_identifier', 'members.qos_ceil', 'members.qos_rate',
'members.entrance_fee', 'members.debt_payment_rate', 'members.entrance_fee_left',
'members.entrance_fee', 'members.debt_payment_rate',
'members.entrance_date', 'members.comment',
'enum_types.value as member_type',
'users.id', 'member_id',
freenetis/trunk/kohana/application/models/account.php
}
/**
* Function gets credit accounts of regular members.
* Function gets credit accounts of regular members and number of months to deduct.
* And it founds deducting transfer if already exists.
* @return unknown_type
*/
// old
/*
public function get_accounts_of_regular_members()
public function get_accounts_to_deduct_fees($start_date, $finish_date, $year)
{
return self::$db->query("SELECT a.id, a.member_id
FROM accounts a
JOIN members m ON a.member_id = m.id
LEFT JOIN enum_types e ON m.type = e.id
WHERE a.account_attribute_id = ".Account_attribute_Model::$credit."
AND e.value = 'Regular member'
");
}
*/
/**
* Function gets credit accounts of regular members.
* @return unknown_type
*/
public function get_accounts_of_regular_members($start_date, $finish_date)
{
/*
return self::$db->query("
SELECT q3.id, q3.member_id, q3.entrance_date, q3.leaving_date, q3.days1, q3.days2, q3.days3, m.mi_days, m.mi_days % 30 as mim,
MONTH(ADDDATE('$start_date', INTERVAL (q3.days3 - IF(DAY(ADDDATE('$start_date', m.mi_days)) > 15, m.mi_days + (30 - (m.mi_days % 30)), m.mi_days - (m.mi_days % 30)) - 15) DAY)) AS months
FROM
SELECT q2.id, q2.member_id, q2.start_date, q2.finish_date, q2.mi_days,
ROUND(
(
SELECT q2.id, q2.member_id, q2.entrance_date, q2.leaving_date, q2.finish_date, q2.days1, q2.days2,
IF(q2.finish_date < q2.leaving_date, q2.days2, q2.days2 - DATEDIFF(q2.finish_date, q2.leaving_date)) AS days3
FROM
(
SELECT q1.id, q1.member_id, q1.entrance_date, q1.leaving_date, q1.finish_date, q1.days1,
IF(q1.entrance_date <= '$start_date', q1.days1, q1.days1 - DATEDIFF(q1.entrance_date, '$start_date')) AS days2
FROM
(
SELECT a.id, a.member_id, m.entrance_date,
IF(m.leaving_date IS NULL OR m.leaving_date = '0000-00-00', '9999-01-01', m.leaving_date) AS leaving_date,
DATEDIFF(ADDDATE('$finish_date', INTERVAL 1 MONTH), '$start_date') AS days1,
SUBDATE(ADDDATE('$finish_date', INTERVAL 1 MONTH), INTERVAL 1 DAY) AS finish_date
FROM accounts a
JOIN members m ON a.member_id = m.id
JOIN enum_types e ON m.type = e.id
WHERE a.account_attribute_id = ".Account_attribute_Model::$credit."
AND (e.value = 'Regular member' OR e.value = 'Former member')
) q1
) q2
) q3
LEFT JOIN
(
SELECT m.id,
SUM(IF(mi.to IS NULL OR mi.from IS NULL, 0,
IF(
DATEDIFF(q2.finish_date, q2.start_date) < 0,
0,
DATEDIFF(q2.finish_date, q2.start_date)
)
-
IF(
q2.mi_days < 0,
0,
q2.mi_days
)
)
/
30
) AS months,
t.id AS transfer_id, t.amount
FROM
(
SELECT q1.id, q1.member_id, q1.start_date, q1.finish_date,
SUM(
IF(
mi.to IS NULL OR mi.from IS NULL,
0,
DATEDIFF(
IF(mi.to < SUBDATE(ADDDATE('$finish_date', INTERVAL 1 MONTH), INTERVAL 1 DAY), mi.to, SUBDATE(ADDDATE('$finish_date', INTERVAL 1 MONTH), INTERVAL 1 DAY)),
IF('$start_date' < mi.from, mi.from, '$start_date')
IF(mi.to <= q1.finish_date, mi.to, q1.finish_date),
IF(q1.start_date <= mi.from, mi.from, q1.start_date)
)
)) AS mi_days
FROM members m
LEFT JOIN membership_interrupts mi ON m.id = mi.member_id
GROUP BY m.id
) m ON q3.member_id = m.id
");
*/
return self::$db->query("
SELECT q4.id, q4.member_id, q4.entrance_date, q4.leaving_date, q4.days1, q4.days2, q4.days3, q4.mi_days,
ADDDATE('$start_date', q4.days1 - 1) AS d1, ADDDATE('$start_date', q4.days2 - 1) AS d2, ADDDATE('$start_date', q4.days3 - 1) AS d3,
MONTH(ADDDATE('$start_date', q4.days3 - q4.mi_days)) AS months
FROM
(
SELECT q3.id, q3.member_id, q3.entrance_date, q3.leaving_date, q3.days1, q3.days2, q3.days3,
SUM(IF(mi.to IS NULL OR mi.from IS NULL, 0,
DATEDIFF(
)
) AS mi_days
FROM
(
SELECT a.id, a.member_id,
IF(
IF(
IF(DAY(mi.to) > 15, SUBDATE(ADDDATE(mi.to, INTERVAL 1 MONTH), 1), SUBDATE(mi.to, DAY(mi.to) - 1)) <= q3.finish_date,
IF(DAY(mi.to) > 15, SUBDATE(ADDDATE(mi.to, INTERVAL 1 MONTH), 1), SUBDATE(mi.to, DAY(mi.to) - 1)),
q3.finish_date
DAY(m.entrance_date) > 15,
SUBDATE(ADDDATE(m.entrance_date, INTERVAL 1 MONTH), DAY(m.entrance_date) - 1),
SUBDATE(m.entrance_date, DAY(m.entrance_date) - 1)
)
<=
'$start_date',
'$start_date',
IF(
DAY(m.entrance_date) > 15,
SUBDATE(ADDDATE(m.entrance_date, INTERVAL 1 MONTH), DAY(m.entrance_date) - 1),
SUBDATE(m.entrance_date, DAY(m.entrance_date) - 1)
)
) AS start_date,
IF(
ADDDATE('$finish_date', INTERVAL 1 MONTH)
<=
IF(
m.leaving_date IS NULL OR m.leaving_date = '0000-00-00', '9999-01-01',
IF(
DAY(m.leaving_date) > 15,
SUBDATE(ADDDATE(m.leaving_date, INTERVAL 1 MONTH), DAY(m.leaving_date) - 1),
SUBDATE(m.leaving_date, DAY(m.leaving_date) - 1)
)
),
ADDDATE('$finish_date', INTERVAL 1 MONTH),
IF(
'$start_date' <= IF(DAY(mi.from) > 15, SUBDATE(ADDDATE(mi.from, INTERVAL 1 MONTH), 1), SUBDATE(mi.from, DAY(mi.from) - 1)),
IF(DAY(mi.from) > 15, SUBDATE(ADDDATE(mi.from, INTERVAL 1 MONTH), 1), SUBDATE(mi.from, DAY(mi.from) - 1)),
'$start_date'
m.leaving_date IS NULL OR m.leaving_date = '0000-00-00',
'9999-01-01',
IF(
DAY(m.leaving_date) > 15,
SUBDATE(ADDDATE(m.leaving_date, INTERVAL 1 MONTH), DAY(m.leaving_date) - 1),
SUBDATE(m.leaving_date, DAY(m.leaving_date) - 1)
)
)
)
)) AS mi_days
FROM
(
SELECT q2.id, q2.member_id, q2.entrance_date, q2.leaving_date, q2.finish_date, q2.days1, q2.days2,
IF(q2.finish_date <= q2.leaving_date, q2.days2, q2.days2 - DATEDIFF(q2.finish_date, q2.leaving_date)) AS days3
FROM
(
SELECT q1.id, q1.member_id, q1.entrance_date, q1.leaving_date, q1.finish_date, q1.days1,
IF(q1.entrance_date <= '$start_date', q1.days1, q1.days1 - DATEDIFF(q1.entrance_date, '$start_date')) AS days2
FROM
(
SELECT a.id, a.member_id,
IF(DAY(m.entrance_date) > 15, SUBDATE(ADDDATE(m.entrance_date, INTERVAL 1 MONTH), DAY(m.entrance_date) - 1), SUBDATE(m.entrance_date, DAY(m.entrance_date) - 1)) AS entrance_date,
IF(m.leaving_date IS NULL OR m.leaving_date = '0000-00-00', '9999-01-01',
IF(DAY(m.leaving_date) > 15, SUBDATE(ADDDATE(m.leaving_date, INTERVAL 1 MONTH), DAY(m.leaving_date) - 1), SUBDATE(m.leaving_date, DAY(m.leaving_date) - 1))
) AS leaving_date,
DATEDIFF(SUBDATE(ADDDATE('$finish_date', INTERVAL 1 MONTH), 1), '$start_date') + 1 AS days1,
SUBDATE(ADDDATE('$finish_date', INTERVAL 1 MONTH), 1) AS finish_date
FROM accounts a
JOIN members m ON a.member_id = m.id
JOIN enum_types e ON m.type = e.id
WHERE a.account_attribute_id = ".Account_attribute_Model::$credit."
AND (e.value = 'Regular member' OR e.value = 'Former member')
) q1
) q2
) q3
LEFT JOIN membership_interrupts mi ON q3.member_id = mi.member_id
GROUP BY q3.member_id
) q4
) AS finish_date
FROM accounts a
JOIN members m ON a.member_id = m.id
JOIN enum_types e ON m.type = e.id
WHERE a.account_attribute_id = ".Account_attribute_Model::$credit."
AND (e.value = 'Regular member' OR e.value = 'Former member')
) q1
LEFT JOIN membership_interrupts mi ON q1.member_id = mi.member_id
AND (YEAR(mi.from) = $year OR YEAR(mi.to) = $year)
GROUP BY q1.member_id
) q2
LEFT JOIN transfers t ON q2.id = t.origin_id
AND t.type = ".Transfer_Model::$deduct_member_fee."
AND t.datetime LIKE '%".$year."%' COLLATE utf8_general_ci
");
}
/**
* Function gets all members to deduct entrance fees.
* @return unknown_type
*/
public function get_accounts_to_deduct_entrance_fees()
{
return self::$db->query("
SELECT a.id, m.entrance_fee, m.entrance_date, t.id AS transfer_id, t.amount
FROM accounts a
JOIN members m ON a.member_id = m.id AND m.id <> 1
LEFT JOIN transfers t ON t.origin_id = a.id AND t.type = ".Transfer_Model::$deduct_entrance_fee."
WHERE a.account_attribute_id = ".Account_attribute_Model::$credit."
");
}
}
?>
freenetis/trunk/kohana/application/models/transfer.php
");
}
/**
* Finding deducting fee of given month and account.
* @param $year
* @param $origin_credit_account
* @return unknown_type
*/
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 '%".$month."%'
AND origin_id = ".$origin_credit_account
)->current();
}
/**
* Finds entrance fee transfer from member's credit account to infrastructure account.
* @param $member_id
* @return unknown_type
*/
public function get_entrance_fee_transfer($member_id)
{
return self::$db->query("SELECT *
FROM transfers t
JOIN accounts a1 ON t.origin_id = a1.id
JOIN accounts a2 ON t.destination_id = a2.id
WHERE a1.member_id = $member_id AND a2.account_attribute_id = ".Account_attribute_Model::$infrastructure
);
}
}
?>
freenetis/trunk/kohana/application/controllers/members.php
$limit_results = (int) $this->input->get('record_per_page');
// parameters control
$allowed_order_type = array('id', 'name', 'street', 'street_number', 'town', 'quarter', 'ZIP_code', 'qos_ceil', 'qos_rate', 'entrance_fee', 'debt_payment_rate', 'entrance_fee_left', 'current_credit', 'entrance_date', 'comment');
$allowed_order_type = array('id', 'name', 'street', 'street_number', 'town', 'quarter', 'ZIP_code', 'qos_ceil', 'qos_rate', 'entrance_fee', 'debt_payment_rate', 'current_credit', 'entrance_date', 'comment');
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'id';
if (strtolower($order_by_direction) != 'asc' && strtolower($order_by_direction) != 'desc')
......
Controller::error(ACCESS);
$enum_types = new Enum_type_Model();
$types = $enum_types->get_values(Enum_type_Model::$member_type_id);
//$types[0] = '----- '.url_lang::lang('texts.select type').' -----';
asort($types);
// cannot add former member
unset($types[$enum_types->get_type_id('Former member')]);
......
$member->qos_ceil = $form_data['qos_ceil'];
$member->qos_rate = $form_data['qos_rate'];
$member->entrance_fee = $form_data['entrance_fee'];
$member->entrance_fee_left = $form_data['entrance_fee'];
$member->debt_payment_rate = $form_data['debt_payment_rate'];
$member_saved = $member->save();
......
$form->dropdown('town_id')->label(url_lang::lang('texts.town').':')->rules('required')->options($arr_towns)->selected($address_point->town_id);
}
// trying to find transfer of entrance fee to infrastructure account
$transfer_model = new Transfer_Model();
$entrance_transfer = $transfer_model->get_entrance_fee_transfer($member_id);
if (count($entrance_transfer) == 0)
{
$form->group('')->label(url_lang::lang('texts.Account information'));
if ($this->acl_check_edit(get_class($this),'en_fee',$member_id))
$form->input('entrance_fee')->label(url_lang::lang('texts.Entrance fee').':')->rules('valid_numeric')->value($member_data->entrance_fee);
if ($this->acl_check_edit(get_class($this),'debit',$member_id))
$form->input('debt_payment_rate')->label(url_lang::lang('texts.Debit payment rate').':')->rules('valid_numeric')->value($member_data->debt_payment_rate);
}
$form->group('')->label(url_lang::lang('texts.Account information'));
if ($this->acl_check_edit(get_class($this),'en_fee',$member_id))
$form->input('entrance_fee')->label(url_lang::lang('texts.Entrance fee').':')->rules('valid_numeric')->value($member_data->entrance_fee);
if ($this->acl_check_edit(get_class($this),'debit',$member_id))
$form->input('debt_payment_rate')->label(url_lang::lang('texts.Debit payment rate').':')->rules('valid_numeric')->value($member_data->debt_payment_rate);
// additional information
$form->group('')->label(url_lang::lang('texts.Additional information'));
......
if ($this->acl_check_edit(get_class($this),'name',$member_id))
$member_data->name = $form_data['membername'];
if ($this->acl_check_edit(get_class($this),'address',$member_id)) {
if ($this->acl_check_edit(get_class($this),'address',$member_id))
$member_data->address_point_id = $address_point->id;
}
if ($this->acl_check_edit(get_class($this),'qos_ceil',$member_id))
$member_data->qos_ceil = $form_data['qos_ceil'];
if ($this->acl_check_edit(get_class($this),'qos_rate',$member_id))
$member_data->qos_rate = $form_data['qos_rate'];
// entrance fee can be edit if entrance fee has not been deducted
if (count($entrance_transfer) == 0)
{
if ($this->acl_check_edit(get_class($this),'en_fee',$member_id))
$member_data->entrance_fee = $form_data['entrance_fee'];
if ($this->acl_check_edit(get_class($this),'en_fee_left',$member_id))
$member_data->entrance_fee_left = $form_data['entrance_fee'];
if ($this->acl_check_edit(get_class($this),'debit',$member_id))
$member_data->debt_payment_rate = $form_data['debt_payment_rate'];
}
if ($this->acl_check_edit(get_class($this),'en_fee',$member_id))
$member_data->entrance_fee = $form_data['entrance_fee'];
if ($this->acl_check_edit(get_class($this),'debit',$member_id))
$member_data->debt_payment_rate = $form_data['debt_payment_rate'];
$member_saved = $member_data->save();
freenetis/trunk/kohana/application/controllers/transfers.php
$form_data[$key] = htmlspecialchars($value);
}
$year = $arr_years[$form_data['year']];
// all transfers should have the same date and time of creation
$creation_datetime = date('Y-m-d H:i:s');
// and all transfers should have the same date of deduct start
$start_date = date('Y-m-d', mktime(0, 0, 0, $form_data['month'], 1, $year));
$finish_date = date('Y-m-d', mktime(0, 0, 0, $form_data['months'], 1, $year));
// database models
$transfer = new Transfer_Model();
$finish_date = date('Y-m-d', mktime(0, 0, 0, $form_data['month'] + $form_data['months'] -1, 1, $year));
$account_model = new Account_Model();
// it gets ids and member ids of all credit accounts
$credit_accounts = $account_model->get_accounts_of_regular_members($start_date, $finish_date);
// it gets credit accounts, count of months to deduct and deducting transfer if already exists
$credit_accounts = $account_model->get_accounts_to_deduct_fees($start_date, $finish_date, $year);
// it gets id of operating account, the only destination account
$operating = ORM::factory('account')->
where('account_attribute_id', Account_attribute_Model::$operating)->find();
// it supposes that everything will be ok, if a transfer couldn't be created, it sets to false
$save_successful = true;
// it is suppossed that thousands of transfers will be generated, transaction processing required
//$db = new Database();
//$db->query("BEGIN;");
$db = new Database();
$db->query("START TRANSACTION;");
// it goes through all credit accounts and it creates their outbound transfers to operating account
$this->profiler = new Profiler();
echo $this->profiler->render(true);
echo '<table rules="all">';
// debugging
/*
$grid = new Grid(url_lang::base().'transfers/deduct_fees', null, array());
$first = true;
*/
foreach($credit_accounts as $ca)
{
echo '<tr><td>'.$ca->member_id.'</td><td>'.$ca->entrance_date.'</td><td>'.$ca->leaving_date.'</td><td>'.$ca->days1.'</td><td>'.$ca->days2.'</td><td>'.$ca->days3.
'</td><td>'.$ca->d1.'</td><td>'.$ca->d2.'</td><td>'.$ca->d3.'</td><td>'.$ca->mi_days.'</td><td>'.$ca->months.'</td></tr>';
if (false)
// debugging
/*
foreach ($ca as $key => $value)
{
// 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 = $operating->id;
$transfer->user_id = $this->session->get('user_id');
$transfer->type = Transfer_Model::$deduct_member_fee;
$transfer->datetime = $start_date;
$transfer->creation_datetime = $creation_datetime;
$transfer->text = $form_data['text'];
$transfer->amount = $total_months * $form_data['fee'];
// money transfer is saved and checked
if (!$transfer->save())
$save_successful = false;
if ($first)
$grid->field($key)->label($key);
}
}
echo '</table>';
die();
// end of transaction processing
if ($save_successful)
{
$db->query("COMMIT;");
$this->session->set_flash('message', url_lang::lang('texts.Fees have been successfully deducted.'));
}
else
{
$db->query("ROLLBACK;");
$this->session->set_flash('message', url_lang::lang('texts.Error - some fees have not been deducted.'));
}
url::redirect(url_lang::base().'transfers/show_all');
}
else
{
$headline = url_lang::lang('texts.Deduction of member fees');
$view = new View('main');
$view->title = $headline;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->form = $form->html();
$view->content->link_back = html::anchor(url_lang::base().'transfers/show_all',url_lang::lang('texts.Back to day book'));
$view->render(TRUE);
}
}
$first = false;
continue;
*/
/**
* Function deducts member fees. This version creates one deducting transfer per year and its value
* can be recalculated (for example every month).
* Functional and debugged version.
* @author Jiri Svitak
* @return unknown_type
*/
/*
function deduct_fees()
{
// access rights
if (!$this->acl_check_new('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
// content of dropdown for months
for ($i = 1; $i <= 12; $i++)
$arr_months[$i] = $i;
// content of dropdown for years
$year_from = date('Y') - 20;
for ($i = 1; $i <= 20; $i++)
$arr_years[$i] = $year_from + $i;
// prefilled member fee
$fee_model = new Fee_Model();
$fee = $fee_model->get_by_date_type(date('Y-m-d'), 'regular member fee');
if ($fee->id)
$member_fee = $fee->fee;
else
$member_fee = 0;
$form = new Forge(url_lang::base().'transfers/deduct_fees', '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->dropdown('year')->label(url_lang::lang('texts.Year').':')->rules('required')->options($arr_years)->selected(20);
$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')->value($member_fee);
$form->input('text')->label(url_lang::lang('texts.Text').':')->value(url_lang::lang('texts.Deduction of member fee'));
$form->submit('submit')->value(url_lang::lang('texts.Deduct'));
special::required_forge_style($form, ' *', 'required');
// form validation
if ($form->validate())
{
$form_data = $form->as_array();
foreach($form_data as $key => $value)
{
$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
$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();
// it gets ids and member ids of all credit accounts
$credit_accounts = $account_model->get_accounts_of_regular_members();
// it gets id of operating account, the only destination account
$oa = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$operating)->find();
// it supposes that everything will be ok, if a transfer couldn't be created, it sets to false
$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)
if (empty($ca->transfer_id))
{
$start = $e_month;
if ($ca->months == 0)
continue;
$transfer = new Transfer_Model();
}
// 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)
{
// leaving month is not included in deduction
$finish = $l_month - 1;
}
}
else
{
$l_okay = true;
if ($ca->amount == $ca->months * $form_data['fee'])
continue;
$transfer = new Transfer_Model($ca->transfer_id);
}
// 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;
}
$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 = $start_date;
$transfer->creation_datetime = $creation_datetime;
$transfer->text = $form_data['text'];
$transfer->amount = $ca->months * $form_data['fee'];
// money transfer is saved and checked
if (!$transfer->save())
$save_successful = false;
}
// debugging
/*
$grid->datasource($credit_accounts);
echo $grid;
$this->profiler = new Profiler();
echo $this->profiler->render(true);
die();
*/
// end of transaction processing
if ($save_successful)
{
......
$view->content->link_back = html::anchor(url_lang::base().'transfers/show_all',url_lang::lang('texts.Back to day book'));
$view->render(TRUE);
}
}
*/
}
/**
* Function deducts entrance fees. This fee is deducted only one once to each member.
* It checks each member if his fee was deducted, and if it is not, then
......
if (!$this->acl_check_new('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
// preparation
$transfer = new Transfer_Model();
$creation_datetime = date('Y-m-d H:i:s');
$infrastructure = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$infrastructure)->find();
$creation_datetime = date('Y-m-d H:i:s');
$text = url_lang::lang('texts.Entrance fee');
$account_model = new Account_Model();
$credit_accounts = $account_model->get_accounts_to_deduct_entrance_fees();
// large amount of database inserts, transaction processing is necessary
$db = new Database();
$db->query("START TRANSACTION;");
$save_successful = true;
// if member id has been set, then entrance fee will be deducted for this member
if (isset($member_id))
foreach($credit_accounts as $ca)
{
$member = new Member_Model($member_id);
$ca = ORM::factory('account')->where(array('member_id' => $member_id,
'account_attribute_id' => Account_attribute_Model::$credit))->find();
if (empty($ca->transfer_id))
{
if ($ca->entrance_fee == 0)
continue;
$transfer = new Transfer_Model();
}
else
{
if ($ca->entrance_fee == $ca->amount)
continue;
$transfer = new Transfer_Model($ca->transfer_id);
}
$transfer->origin_id = $ca->id;
$transfer->destination_id = $infrastructure->id;
$transfer->datetime = $member->entrance_date;
$transfer->user_id = $this->session->get('user_id');
$transfer->type = Transfer_Model::$deduct_entrance_fee;
$transfer->datetime = $ca->entrance_date;
$transfer->creation_datetime = $creation_datetime;
$transfer->text = $text;
$transfer->amount = $member->entrance_fee_left;
$transfer->text = url_lang::lang('texts.Entrance fee');
$transfer->amount = $ca->entrance_fee;
if (!$transfer->save())
$save_successful = false;
$member->entrance_fee_left = 0;
if (!$member->save())
$save_successful = false;
if ($save_successful)
{
$this->session->set_flash('message', url_lang::lang('texts.Entrance fee has been successfully deducted.'));
}
else
{
$this->session->set_flash('message', url_lang::lang('texts.Error - cant deduct entrance fee.'));
}
url::redirect(url_lang::base()."members/show/$member_id");
}
// entrance fees of all members will be deducted
if ($save_successful)
{
$db->query("COMMIT;");
$this->session->set_flash('message', url_lang::lang('texts.Entrance fees have been successfully deducted.'));
}
else
{
$member_model = new Member_Model();
$members = $member_model->get_all_members_to_deduct_entrance_fees();
$db = new Database();
// large amount of database inserts, transaction processing is necessary
$db->query("BEGIN;");
foreach($members as $m)
{
unset($member);
$member = new Member_Model($m->id);
$transfer->clear();
$transfer->origin_id = $m->aid;
$transfer->destination_id = $infrastructure->id;
$transfer->type = Transfer_Model::$deduct_entrance_fee;
$transfer->datetime = $member->entrance_date;
$transfer->creation_datetime = $creation_datetime;
$transfer->text = $text;
$transfer->amount = $member->entrance_fee_left;
if (!$transfer->save())
$save_successful = false;
$member->entrance_fee_left = 0;
if (!$member->save())
$save_successful = false;
}
if ($save_successful)
{
$db->query("COMMIT;");
$this->session->set_flash('message', url_lang::lang('texts.Entrance fees have been successfully deducted.'));
}
else
{
$db->query("ROLLBACK;");
$this->session->set_flash('message', url_lang::lang('texts.Error - cant deduct entrance fee.'));
}
url::redirect(url_lang::base().'transfers/show_all');
}
$db->query("ROLLBACK;");
$this->session->set_flash('message', url_lang::lang('texts.Error - cant deduct entrance fee.'));
}
url::redirect(url_lang::base().'transfers/show_all');
}
/**
freenetis/trunk/kohana/application/controllers/registration.php
$member->type = $enum_type->get_type_id('Applicant');
$member->organization_identifier = $form_data['organization_identifier'];
$member->entrance_fee = $entrance_fee;
$member->entrance_fee_left = $entrance_fee;
$member_saved = $member->save();
$user->member_id = $member->id;
$user_saved = $user->save();
freenetis/trunk/kohana/application/views/members_show.php
{
if ($this->acl_check_edit('Accounts_Controller', 'transfers', $member_data->member_id))
$links[] = html::anchor(url_lang::base().'transfers/add_member_fee_payment_by_cash/'.$member_data->member_id, url_lang::lang('texts.Payment by cash'));
if ($member_data->entrance_fee_left != 0 && $this->acl_check_new('Accounts_Controller', 'transfers'))
$links[] = html::anchor(url_lang::base().'transfers/deduct_entrance_fees/'.$member_data->member_id, url_lang::lang('texts.Deduct entrance fee'), array('onclick' => 'return potvrd(\''.url_lang::lang('texts.Do you want to deduct this member\'s entrance fee').'\')'));
if ($this->acl_check_edit('Members_Controller', 'members'))
$links[] = html::anchor(url_lang::base().'members/end_membership/'.$member_data->member_id, url_lang::lang('texts.End membership'), array('onclick' => 'return potvrd(\''.url_lang::lang('texts.Do you want to end membership of this member').'\')'));
}
......
<th colspan="2"><?php echo url_lang::lang('texts.Account information') ?></th>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Current credit') ?></th>
<th><?php echo url_lang::lang('texts.Current credit') ?></th>
<td><?php echo number_format((float) $account->get_account_balance($account->id), 2, ',', ' ').' '.$this->setting->currency ?></td>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Entrance fee') ?></th>
<td><?php echo number_format((float)$member_data->entrance_fee, 2, ',', ' ').' '.$this->setting->currency ?></td>
<th><?php echo url_lang::lang('texts.Entrance fee') ?></th>
<td><?php echo number_format((float)$member_data->entrance_fee, 2, ',', ' ').' '.$this->setting->currency ?></td>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Entrance fee left') ?></th>
<td><?php echo number_format((float)$member_data->entrance_fee_left, 2, ',', ' ').' '.$this->setting->currency ?></td>
<th><?php echo url_lang::lang('texts.Debit payment rate') ?></th>
<td><?php echo number_format((float)$member_data->debt_payment_rate, 2, ',', ' ').' '.$this->setting->currency ?></td>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Debit payment rate') ?></th>
<td><?php echo number_format((float)$member_data->debt_payment_rate, 2, ',', ' ').' '.$this->setting->currency ?></td>
</tr>
<?php } ?>
<?php if ($this->acl_check_view('Members_Controller', 'qos_ceil', $member_data->member_id) ||
$this->acl_check_view('Members_Controller', 'qos_rate', $member_data->member_id) ||

Také k dispozici: Unified diff