Revize 284
Přidáno uživatelem Jiří Sviták před asi 15 roky(ů)
freenetis/trunk/kohana/application/models/money_transfer.php | ||
---|---|---|
{
|
||
if ($order_by == 'amount')
|
||
$order_by = 'IF( mt.destination_id = '.$account_id.', amount, amount*-1 )';
|
||
/*
|
||
return self::$db->query("SELECT
|
||
mt.id AS mtid, mt.datetime, mt.text, mt.amount,
|
||
bi.variable_symbol AS varsym,
|
||
... | ... | |
ORDER BY ".$order_by." ".$order_by_direction."
|
||
LIMIT ".$limit_from." , ".$limit_results
|
||
);
|
||
*/
|
||
return self::$db->query("SELECT
|
||
mt.id AS mtid, mt.datetime, mt.text, mt.amount,
|
||
bi.variable_symbol AS varsym,
|
||
a.name AS aname, CONCAT(ba.account_nr, '/', ba.bank_nr) AS account_number,
|
||
IF( mt.destination_id = ".$account_id.", FALSE, TRUE ) AS trans_type
|
||
FROM money_transfers mt
|
||
LEFT JOIN accounts a ON a.id = IF( mt.origin_id = ".$account_id.", mt.destination_id, mt.origin_id )
|
||
LEFT JOIN bank_accounts ba ON a.id = ba.account_id
|
||
LEFT JOIN money_transfer_bank_infos bi ON mt.id = bi.transfer_id
|
||
LEFT JOIN account_attributes aa ON a.account_attribute_id = aa.id
|
||
WHERE (mt.origin_id = ".$account_id." OR mt.destination_id = ".$account_id.")
|
||
AND aa.id >= ".Account_attribute_Model::$bank." AND aa.id < ".Account_attribute_Model::$credit."
|
||
ORDER BY ".$order_by." ".$order_by_direction."
|
||
LIMIT ".$limit_from." , ".$limit_results
|
||
);
|
||
}
|
||
|
||
/**
|
||
... | ... | |
*/
|
||
public function count_bank_transfers($account_id)
|
||
{
|
||
/*
|
||
return self::$db->query("SELECT
|
||
mt.id AS mtid, mt.datetime, mt.text, mt.amount,
|
||
bi.variable_symbol AS varsym,
|
||
... | ... | |
JOIN enum_types e ON a.type_id = e.id
|
||
WHERE (mt.origin_id = ".$account_id." OR mt.destination_id = ".$account_id.") AND e.value = 'bank'"
|
||
)->count();
|
||
*/
|
||
return self::$db->query("SELECT
|
||
mt.id AS mtid, mt.datetime, mt.text, mt.amount,
|
||
bi.variable_symbol AS varsym,
|
||
a.name AS aname, CONCAT(ba.account_nr, '/', ba.bank_nr) AS account_number,
|
||
IF( mt.destination_id = ".$account_id.", FALSE, TRUE ) AS trans_type
|
||
FROM money_transfers mt
|
||
LEFT JOIN accounts a ON a.id = IF( mt.origin_id = ".$account_id.", mt.destination_id, mt.origin_id )
|
||
LEFT JOIN bank_accounts ba ON a.id = ba.account_id
|
||
LEFT JOIN money_transfer_bank_infos bi ON mt.id = bi.transfer_id
|
||
LEFT JOIN account_attributes aa ON a.account_attribute_id = aa.id
|
||
WHERE (mt.origin_id = ".$account_id." OR mt.destination_id = ".$account_id.")
|
||
AND aa.id >= ".Account_attribute_Model::$bank." AND aa.id < ".Account_attribute_Model::$credit
|
||
)->count();
|
||
}
|
||
|
||
/**
|
freenetis/trunk/kohana/application/models/member.php | ||
---|---|---|
*/
|
||
public function get_debtors($limit_from = 0, $limit_results = 50, $order_by = 'm.id', $order_by_direction = 'ASC')
|
||
{
|
||
// to do - correct this query...
|
||
/*return self::$db->query('SELECT aid, mid, mname, mstreet, mtown,
|
||
(IFNULL(SUM(amount), 0) - IFNULL(sel2.outbound, 0)) AS credit
|
||
FROM (SELECT
|
||
SUM(amount) AS outbound, aid, mid, mname, mstreet, mtown
|
||
FROM (SELECT a.id AS aid, m.id AS mid, m.name AS mname, m.street AS mstreet, m.town AS mtown
|
||
FROM members m
|
||
JOIN accounts a ON a.member_id = m.id
|
||
) sel1, money_transfers mt1
|
||
WHERE mt1.origin_id = sel1.aid
|
||
) sel2, money_transfers mt2
|
||
WHERE mt2.destination_id = sel2.aid AND credit < 0
|
||
ORDER BY '.$order_by.' '.$order_by_direction.'
|
||
LIMIT '.$limit_from.','.$limit_results);
|
||
*/
|
||
|
||
/*
|
||
return self::$db->query('SELECT members.id, members.name, members.street, members.town,
|
||
q3.credit FROM
|
||
(SELECT id, member_id, (inbound - outbound) as credit FROM
|
||
... | ... | |
LEFT JOIN members ON q3.member_id = members.id
|
||
ORDER BY '.$order_by.' '.$order_by_direction.'
|
||
LIMIT '.$limit_from.','.$limit_results);
|
||
*/
|
||
return self::$db->query('SELECT members.id, members.name, members.street, members.town,
|
||
q3.credit FROM
|
||
(SELECT id, member_id, (inbound - outbound) as credit FROM
|
||
(SELECT q1.id, q1.member_id, IFNULL(sum(amount),0) as inbound, outbound FROM
|
||
(SELECT a.id, member_id, IFNULL( sum( amount ) , 0 ) AS outbound
|
||
FROM accounts a
|
||
LEFT JOIN account_attributes aa ON a.account_attribute_id = aa.id
|
||
LEFT JOIN money_transfers mt ON a.id = mt.origin_id
|
||
WHERE aa.id = '.Account_attribute_Model::$credit.'
|
||
GROUP BY a.id) AS q1
|
||
LEFT JOIN money_transfers ON q1.id = money_transfers.destination_id GROUP BY q1.id) AS q2
|
||
WHERE (inbound - outbound) < 0) AS q3
|
||
LEFT JOIN members ON q3.member_id = members.id
|
||
ORDER BY '.$order_by.' '.$order_by_direction.'
|
||
LIMIT '.$limit_from.','.$limit_results);
|
||
}
|
||
|
||
/**
|
freenetis/trunk/kohana/application/models/account.php | ||
---|---|---|
*/
|
||
public function get_assoc_bank_accounts()
|
||
{
|
||
/*
|
||
return self::$db->query("SELECT
|
||
a.id, a.name, a.comment,
|
||
IFNULL(t.translated_term, e.value) AS type,
|
||
... | ... | |
LEFT JOIN bank_accounts ba ON a.id = ba.account_id
|
||
LEFT JOIN translations t ON t.original_term = e.value AND t.lang ='".Config::item('locale.lang')."'
|
||
WHERE e.value = 'bank' AND a.member_id = '1'");
|
||
*/
|
||
return self::$db->query("SELECT
|
||
a.id, a.name, a.comment,
|
||
aa.name AS type,
|
||
CONCAT(ba.account_nr, '/', ba.bank_nr) AS account_number
|
||
FROM accounts a
|
||
LEFT JOIN account_attributes aa ON aa.id = a.account_attribute_id
|
||
LEFT JOIN bank_accounts ba ON a.id = ba.account_id
|
||
WHERE aa.id >= ".Account_attribute_Model::$bank." AND aa.id < ".Account_attribute_Model::$credit."
|
||
AND a.member_id = '1'");
|
||
}
|
||
|
||
/**
|
||
... | ... | |
*/
|
||
public function get_doubleentry_accounts()
|
||
{
|
||
/*
|
||
return self::$db->query("SELECT a.id, a.name, a.comment, IFNULL(t.translated_term, e.value) AS type
|
||
FROM accounts a
|
||
JOIN enum_types e ON e.id = a.type_id
|
||
LEFT JOIN translations t ON t.original_term = e.value AND t.lang = '".Config::item('locale.lang')."'
|
||
WHERE e.value <> 'bank'");
|
||
*/
|
||
return self::$db->query("SELECT a.id, a.name, a.comment, aa.name AS type
|
||
FROM accounts a
|
||
LEFT JOIN account_attributes aa ON aa.id = a.account_attribute_id
|
||
WHERE aa.id >= ".Account_attribute_Model::$credit." AND aa.id < ".Account_attribute_Model::$bank_debts);
|
||
}
|
||
|
||
/**
|
||
... | ... | |
*/
|
||
public function get_credit_accounts()
|
||
{
|
||
/*
|
||
return self::$db->query("SELECT a.*, IFNULL(t.translated_term, e.value) AS type
|
||
FROM accounts a
|
||
JOIN enum_types e ON e.id = a.type_id
|
||
LEFT JOIN translations t ON t.original_term = e.value AND t.lang = '".Config::item('locale.lang')."'
|
||
WHERE e.value = 'credit'");
|
||
*/
|
||
return self::$db->query("SELECT a.*, aa.name AS type
|
||
FROM accounts a
|
||
JOIN account_attributes aa ON aa.id = a.account_attribute_id
|
||
WHERE aa.id = ".Account_attribute_Model::$credit);
|
||
}
|
||
|
||
/**
|
||
... | ... | |
SELECT SUM(amount) AS outbound
|
||
FROM money_transfers
|
||
WHERE `origin_id` = '".$account_id."'
|
||
) a, money_transfers mt
|
||
) a, money_transfers mt
|
||
WHERE mt.destination_id = '".$account_id."'"
|
||
)->current()->credit;
|
||
return $credit;
|
freenetis/trunk/kohana/application/models/account_attribute.php | ||
---|---|---|
<?php
|
||
class Account_attribute_Model extends ORM
|
||
{
|
||
public static $bank = '221000';
|
||
public static $first_ba = '221001';
|
||
public static $credit = '221100';
|
||
public static $operating = '221101';
|
||
public static $infrastructure = '221102';
|
||
public static $project = '221103';
|
||
public static $bank_debts = '231000';
|
||
public static $suppliers = '321000';
|
||
}
|
||
?>
|
freenetis/trunk/kohana/application/controllers/members.php | ||
---|---|---|
$account = new Account_Model();
|
||
$enum = new Enum_type_Model();
|
||
|
||
$account->type_id = $enum->get_type_id('credit');
|
||
//$account->type_id = $enum->get_type_id('credit');
|
||
$account->account_attribute_id = Account_attribute_Model::$credit;
|
||
$account->name = $form_data['surname'].' '.$form_data['name'];
|
||
|
||
//if ($this->acl_check_new(get_class($this),'current_credit'))
|
freenetis/trunk/kohana/application/controllers/money_transfers.php | ||
---|---|---|
|
||
$form = new Forge(url_lang::base().'money_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->group('')->label(url_lang::lang('texts.Payment'));
|
||
$form->dropdown('aname')->label(url_lang::lang('texts.Destination credit account').':')->rules('required')->options($arr_accounts);
|
||
$form->input('text')->label(url_lang::lang('texts.Text'));
|
||
$form->group('')->label(url_lang::lang('texts.Penalty'));
|
||
//$form->group('')->label(url_lang::lang('texts.Penalty'));
|
||
$form->input('penalty')->label(url_lang::lang('texts.Penalty'))->value('0');
|
||
$form->submit('submit')->value(url_lang::lang('texts.Assign'));
|
||
special::required_forge_style($form, ' *', 'required');
|
Také k dispozici: Unified diff
Predelany stavajici gridy a formulare, aby fungovaly s novou verzi db.