Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 847

Přidáno uživatelem Jiří Sviták před více než 13 roky(ů)

Dokonceni predelavek na transakcni zpracovani, odladeno pridavani bankovnich prevodu, import vypisu. Potreba odladit strhavaci a prepocitavaci algoritmy, prevody u voipu a vykazu praci.

Zobrazit rozdíly:

freenetis/branches/account_transactions/application/i18n/cs_CZ/texts.php
'error - wrong arguments' => 'Chyba - špatné argumenty',
'error - wrong data' => 'Chyba - špatná data',
'error - amount has to be positive' => 'Chyba - částka musí být kladná.',
'error - cannot add bank transfer' => 'Chyba - nelze přidat bankovní převod.',
'error - cannot add message' => 'Chyba - nelze přidat zprávu.',
'error - cannot assign transfer' => 'Chyba - nelze přiřadit převod.',
'error - cannot delete bank statement' => 'Chyba - nelze smazat bankovní výpis.',
'error - cannot load intelligent selection' => 'Chyba - nelze načíst inteligentní výběr',
'error - cannot update message' => 'Chyba - nelze upravit zprávu.',
......
'execution time' => 'Doba provádění',
'executive counsil' => 'Správní rada',
'expenditure-earning' => 'Výdej-Příjem',
'expenses' => 'Výdaje',
'export of registration' => 'Export přihlášky',
'export to xls' => 'Exportovat do XLS',
'export to csv (utf-8)' => 'Exportovat do CSV (utf-8)',
......
'ignore whitelist' => 'Ignorovat whitelist',
'import dhcp export from mikrotik' => 'Import exportu DHCP z Mikrotiku',
'import has been successfully finished' => 'Import byl úspěšně dokončen.',
'import has failed' => 'Import selhal.',
'import new invoice' => 'Import nové faktury',
'import private contact' => 'Importovat soukromé kontakty',
'import contact from server funanbol' => 'Importovat kontakty ze serveru Funanbol',
......
'in hours' => 'V hodinách',
'inactive' => 'Neaktivní',
'inbound' => 'Příchozí',
'incomes' => 'Příjmy',
'incoming member payment' => 'Příchozí členské příspěvky',
'incoming member payment in the period' => 'Příchozí členské příspěvky v období',
'increase of members' => 'Přírůstek členů',
......
'specific symbol' => 'Specifický symbol',
'start amount' => 'Počáteční částka',
'static ip' => 'Statická IP',
'statistics' => 'Statistiky',
'state' => 'Stav',
'statement' => 'Výpis',
'statement number' => 'Číslo výpisu',
......
'suffix has to start with slash character and has to end with slash character' => 'Přípona musí začínat lomítkem a musí končit lomítkem.',
'suggest amount' => 'Navrhovaná částka',
'sum' => 'Součet',
'summary' => 'Sumarizace',
'summary' => 'Shrnutí',
'supplier' => 'Dodavatel',
'suppliers account' => 'Účet dodavatelů',
'surname' => 'Příjmení',
freenetis/branches/account_transactions/application/models/account.php
GROUP BY q2.aid
) q3
SET a.balance = (q3.inbound - q3.outbound)
WHERE a.id = $account_id
");
}
freenetis/branches/account_transactions/application/models/transfer.php
<?php
<?php
class Transfer_Model extends ORM
{
protected $belongs_to = array('origin' => 'account', 'destination' => 'account');
freenetis/branches/account_transactions/application/controllers/transfers.php
}
else
{
// find datetime of las deduct fee
// find datetime of last deduct fee
$transfer_model = new Transfer_Model();
$last_datetime = $transfer_model->find_last_transfer_datetime_by_type(Transfer_Model::$deduct_member_fee);
if ($last_datetime)
......
$db->transaction_start();
// deleting old deduct transfer of member
$account->delete_deduct_transfers_of_account($account_id);
$save_successful = true;
$max_date = date('Y-m-d', mktime(0, 0, 0, $max_month, 15, $max_year));
while (($date = date('Y-m-d', mktime(0, 0, 0, $month, 15, $year))) < $max_date)
while (($date = date('Y-m-d', mktime(0, 0, 0, $month, 15, $year))) <= $max_date)
{
$text = url_lang::lang('texts.Deduction of member fee');
// finds default regular member fee for this month
freenetis/branches/account_transactions/application/controllers/votes.php
{
// creates new transfer
$account_model = new Account_Model();
/*
$transfer = new Transfer_Model();
// finding of operating account
$operating_account = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$transfer->origin_id = $operating_account->id;
// findind of account of member
$member_account = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer->destination_id = $member_account->id;
$transfer->datetime = date('Y-m-d');
$transfer->creation_datetime = date('Y-m-d H:i:s');
$transfer->text = url_lang::lang('texts.Work approval');
$transfer->amount = $work->suggest_amount;
$transfer->user_id = $this->session->get('user_id');
$transfer->save();
*
*/
$operating = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$credit = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer_id = Transfer_Model::insert_transfer($operating->id, $credit->id, null, null,
$this->session->get('user_id'), null, date('Y-m-d'), date('Y-m-d H:i:s'), url_lang::lang('texts.Work approval'), $work->suggest_amount);
$work->transfer_id = $transfer->id;
$work->transfer_id = $transfer_id;
}
// saves work
......
{
// creates new transfer
$account_model = new Account_Model();
/*
$transfer = new Transfer_Model();
// finding of operating account
$operating_account = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$transfer->origin_id = $operating_account->id;
// findind of account of member
$member_account = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer->destination_id = $member_account->id;
$transfer->datetime = date('Y-m-d');
$transfer->creation_datetime = date('Y-m-d H:i:s');
$transfer->text = url_lang::lang('texts.Work approval');
$transfer->amount = $work->suggest_amount;
$transfer->user_id = $this->session->get('user_id');
$transfer->save();
*/
$operating = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$credit = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer_id = Transfer_Model::insert_transfer($operating->id, $credit->id, null, null,
$this->session->get('user_id'), null, date('Y-m-d'), date('Y-m-d H:i:s'), url_lang::lang('texts.Work approval'), $work->suggest_amount);
$work->transfer_id = $transfer->id;
$work->transfer_id = $transfer_id;
}
// saves work
freenetis/branches/account_transactions/application/controllers/bank_transfers.php
<?php
/**
* Handles bank transfers operations, assigning unidentified bank transfers and
* allows creating new bank transfers manually.
* @author Jiri Svitak
* @license GNU/GPLv3
*/
class Bank_transfers_Controller extends Controller
{
// static types of bank transfers
......
$member_id = $dst_acc->member_id;
$dst_id = $dst_acc->id;
}
// first we assign the first transfer to the selected member
$t = new Transfer_Model($trans_id);
$t->member_id = $member_id;
$t->save();
// 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->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 = $bt->amount;
$identified_saved = $t->save();
// assign also all subsequent transfers to the selected member
$next_ts = ORM::factory('transfer')->where('previous_transfer_id', $trans_id)->find_all();
foreach ($next_ts as $transfer)
try
{
$transfer->member_id=$member_id;
$transfer->save();
}
// also penalty should be generated
$pen_save = true;
$operating = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$operating)->find();
if ($form_data['penalty'] > 0)
{
$pen = new Transfer_Model();
$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();
$db = new Transfer_Model();
$db->transaction_start();
$creation_datetime = date("Y-m-d H:i:s", time());
$user_id = $this->session->get('user_id');
// first we assign the first transfer to the selected member
$t = new Transfer_Model($trans_id);
$t->member_id = $member_id;
if (!$t->save())
throw new ErrorException();
// then we create a new transfer to the selected member's account
/*
$t->clear();
$t->member_id = $member_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 = $bt->amount;
$identified_saved = $t->save();
*/
Transfer_Model::insert_transfer($bt->destination_id, $dst_id, $bt->id, $member_id,
$user_id, null, $bt->datetime, $creation_datetime, $form_data['text'], $bt->amount);
// assign also all subsequent transfers to the selected member
$next_ts = ORM::factory('transfer')->where('previous_transfer_id', $trans_id)->find_all();
foreach ($next_ts as $transfer)
{
$transfer->member_id = $member_id;
if (!$transfer->save())
throw new ErrorException();
}
// also penalty should be generated
$operating = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$operating)->find();
if ($form_data['penalty'] > 0)
{
/*
$pen = new Transfer_Model();
$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();
*/
Transfer_Model::insert_transfer($dst_id, $operating->id, $bt->id, null,
$user_id, null, $bt->datetime, $creation_datetime, $form_data['penalty_text'], $form_data['penalty']);
}
// transfer fee, if it has to be generated
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();
*/
Transfer_Model::insert_transfer($dst_id, $operating->id, $bt->id, null,
$user_id, null, $bt->datetime, $creation_datetime, $form_data['fee_text'], $form_data['transfer_fee']);
}
$db->transaction_commit();
$this->session->set_flash('message', url_lang::lang('texts.Payment has been successfully assigned.'));
}
// transfer fee, if it has to be generated
$tf_saved = true;
if ($form_data['transfer_fee'] > 0)
catch (ErrorException $e)
{
$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();
$db->transaction_rollback();
$this->session->set_flash('message', url_lang::lang('texts.Error - cannot assign transfer.'));
}
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');
}
url::redirect(url_lang::base().'bank_transfers/unidentified_transfers');
}
$view = new View('main');
$view->title = url_lang::lang('texts.Assign transfer');
......
/**
* Function enables adding of bank transfers manually.
* @author Jiri Svitak
* @param baa_id bank account of association
* @return unknown_type
*/
......
// origin bank account
$baa = new Bank_account_Model($baa_id);
if ($baa->id == 0 || $baa->member_id != 1)
Controller::error(RECORD);
// destination bank account
/*
$ba_model = new Bank_account_Model();
$bas = $ba_model->get_destination_bank_accounts($baa_id);
foreach ($bas as $ba)
{
$name = $ba->account_nr.'/'.$ba->bank_nr;
if (trim($ba->name) != '')
$name .= ' - '.$ba->name;
$arr_bas[$ba->id] = $name;
}
asort($arr_bas, SORT_LOCALE_STRING);
*/
Controller::error(RECORD);
// bank transfer type
$arr_bt_types[self::$member_fee] = url_lang::lang('texts.Member fee');
$arr_bt_types[self::$invoice] = url_lang::lang('texts.Invoice');
......
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
// counteraccount
$form->group('')->label(url_lang::lang('texts.Counteraccount'));
$form->input('counteraccount')->label(url_lang::lang('texts.Counteraccount').':')->rules('required');
$form->input('counteraccount')->label(url_lang::lang('texts.Counteraccount number').':')->rules('required');
$form->input('counteraccount_bc')->label(url_lang::lang('texts.Bank code').':')->rules('required');
$form->input('counteraccount_name')->label(url_lang::lang('texts.Account name').':');
// transfer
......
$form_data[$key] = htmlspecialchars($value);
}
// preparation
$time_now = date('Y-m-d H:i:s', time());
$creation_datetime = date('Y-m-d H:i:s', time());
$operating = ORM::factory('account')->
where('account_attribute_id', Account_attribute_Model::$operating)->find();
$member_fees = ORM::factory('account')->
......
$counter_ba = ORM::factory('bank_account')->
where(array('account_nr' => $form_data['counteraccount'],
'bank_nr' => $form_data['counteraccount_bc']))->find();
if (!$counter_ba->id)
// transaction
try
{
$counter_ba = new Bank_account_Model();
$counter_ba->name = $form_data['counteraccount_name'];
$counter_ba->account_nr = $form_data['counteraccount'];
$counter_ba->bank_nr = $form_data['counteraccount_bc'];
$counter_ba->save();
}
// this bank account
$account = $baa->get_related_account_by_attribute_id(
Account_attribute_Model::$bank);
$bank_fees = $baa->get_related_account_by_attribute_id(
Account_attribute_Model::$bank_fees);
// double-entry transfer
$transfer = new Transfer_Model();
if ($form_data['type'] == self::$member_fee)
{
$transfer->origin_id = $member_fees->id;
$transfer->destination_id = $account->id;
}
elseif ($form_data['type'] == self::$invoice)
{
$transfer->origin_id = $account->id;
$transfer->destination_id = $suppliers->id;
}
$transfer->user_id = $this->session->get('user_id');
$transfer->datetime = date('Y-m-d', $form_data['datetime']);
$transfer->creation_datetime = $time_now;
$transfer->text = $form_data['text'];
$transfer->amount = $form_data['amount'];
$transfer_saved = $transfer->save();
// bank transfer
$bt = new Bank_transfer_Model();
$bt->transfer_id = $transfer->id;
if ($form_data['type'] == self::$member_fee)
{
$bt->origin_id = $counter_ba->id;
$bt->destination_id = $baa->id;
}
elseif ($form_data['type'] == self::$invoice)
{
$bt->origin_id = $baa_id;
$bt->destination_id = $counter_ba->id;
}
$bt->constant_symbol = $form_data['constant_symbol'];
$bt->variable_symbol = $form_data['variable_symbol'];
$bt->specific_symbol = $form_data['specific_symbol'];
$bank_transfer_saved = $bt->save();
// bank transfer fee
$bank_transfer_fee_saved = true;
$btf_saved = true;
$btf2_saved = true;
$btf3_saved = true;
if ($form_data['bank_transfer_fee'] > 0)
{
// bank transfer fee - double-entry part
$btf = new Transfer_Model();
$btf->origin_id = $account->id;
$btf->destination_id = $bank_fees->id;
$btf->previous_transfer_id = $transfer->id;
$btf->user_id = $this->session->get('user_id');
$btf->datetime = date('Y-m-d', $form_data['datetime']);
$btf->creation_datetime = $time_now;
$btf->text = $form_data['fee_text'];
$btf->amount = $form_data['bank_transfer_fee'];
$btf_saved = $btf->save();
// bank transfer fee - bank part
$btf2 = new Bank_transfer_Model();
$btf2->transfer_id = $btf->id;
$btf2->origin_id = $baa->id;
$btf2->destination_account = null;
$btf2_saved = $btf2->save();
// accounting of fee - it is payed by association from operating account
$btf3 = new Transfer_Model();
$btf3->origin_id = $operating->id;
$btf3->destination_id = $account->id;
$btf3->previous_transfer_id = $transfer->id;
$btf3->user_id = $this->session->get('user_id');
$btf3->datetime = date('Y-m-d', $form_data['datetime']);
$btf3->creation_datetime = $time_now;
$btf3->text = $form_data['fee_text'];
$btf3->amount = $form_data['bank_transfer_fee'];
$btf3_saved = $btf3->save();
}
// identifying member fee
$identified_transfer_saved = true;
$transfer_fee_saved = true;
if ($form_data['type'] == self::$member_fee)
{
// searching member
$member = ORM::factory('member')->where('variable_symbol', $form_data['variable_symbol'])->find();
if ($member->id)
$db = new Transfer_Model();
$db->transaction_start();
if (!$counter_ba->id)
{
// finding credit account
$ca = ORM::factory('account')->where(array('member_id' => $member->id,
'account_attribute_id' => Account_attribute_Model::$credit))->find();
// identified transfer
$it = new Transfer_Model();
$it->origin_id = $account->id;
$it->destination_id = $ca->id;
$it->previous_transfer_id = $transfer->id;
$it->member_id = $member->id;
$it->user_id = $this->session->get('user_id');
$it->datetime = date('Y-m-d', $form_data['datetime']);
$it->creation_datetime = $time_now;
$it->text = url_lang::lang('texts.Assigning of transfer');
$it->amount = $form_data['amount'];
$identified_transfer_saved = $it->save();
// if there is transfer fee, then it is generated
$fee_model = new Fee_Model();
$fee = $fee_model->get_by_date_type(date('Y-m-d', $form_data['datetime']), 'transfer fee');
if (is_object($fee) && $fee->id)
$counter_ba = new Bank_account_Model();
$counter_ba->name = $form_data['counteraccount_name'];
$counter_ba->account_nr = $form_data['counteraccount'];
$counter_ba->bank_nr = $form_data['counteraccount_bc'];
if (!$counter_ba->save())
throw new ErrorException();
}
// this bank account
$account = $baa->get_related_account_by_attribute_id(
Account_attribute_Model::$bank);
$bank_fees = $baa->get_related_account_by_attribute_id(
Account_attribute_Model::$bank_fees);
// double-entry transfer
if ($form_data['type'] == self::$member_fee)
{
$t_origin_id = $member_fees->id;
$t_destination_id = $account->id;
}
elseif ($form_data['type'] == self::$invoice)
{
$t_origin_id = $account->id;
$t_destination_id = $suppliers->id;
}
$user_id = $this->session->get('user_id');
$datetime = date('Y-m-d', $form_data['datetime']);
$t_id = Transfer_Model::insert_transfer($t_origin_id, $t_destination_id, null, null,
$user_id, null, $datetime, $creation_datetime, $form_data['text'], $form_data['amount']);
// bank transfer
$bt = new Bank_transfer_Model();
$bt->transfer_id = $t_id;
if ($form_data['type'] == self::$member_fee)
{
$bt->origin_id = $counter_ba->id;
$bt->destination_id = $baa->id;
}
elseif ($form_data['type'] == self::$invoice)
{
$bt->origin_id = $baa_id;
$bt->destination_id = $counter_ba->id;
}
$bt->constant_symbol = $form_data['constant_symbol'];
$bt->variable_symbol = $form_data['variable_symbol'];
$bt->specific_symbol = $form_data['specific_symbol'];
if (!$bt->save())
throw new ErrorException();
// bank transfer fee
if ($form_data['bank_transfer_fee'] > 0)
{
// bank transfer fee - double-entry part
$btf_origin_id = $account->id;
$btf_destination_id = $bank_fees->id;
$btf_id = Transfer_Model::insert_transfer($btf_origin_id, $btf_destination_id, $t_id, null,
$user_id, null, $datetime, $creation_datetime, $form_data['fee_text'], $form_data['bank_transfer_fee']);
// bank transfer fee - bank part
$btf2 = new Bank_transfer_Model();
$btf2->transfer_id = $btf_id;
$btf2->origin_id = $baa->id;
$btf2->destination_id = null;
if (!$btf2->save())
throw new ErrorException();
// accounting of fee - it is payed by association from operating account
$btf3_id = Transfer_Model::insert_transfer($operating->id, $account->id, $t_id, null,
$user_id, null, $datetime, $creation_datetime, $form_data['fee_text'], $form_data['bank_transfer_fee']);
}
// identifying member fee
if ($form_data['type'] == self::$member_fee)
{
// searching member
$member = ORM::factory('member')->where('variable_symbol', $form_data['variable_symbol'])->find();
if ($member->id)
{
// transfer fee
$tf = new Transfer_Model();
$tf->origin_id = $ca->id;
$tf->destination_id = $operating->id;
$tf->previous_transfer_id = $transfer->id;
$tf->member_id = $member->id;
$tf->user_id = $this->session->get('user_id');
$tf->datetime = date('Y-m-d', $form_data['datetime']);
$tf->creation_datetime = $time_now;
$tf->text = url_lang::lang('texts.Transfer fee');
$tf->amount = $fee->fee;
$transfer_fee_saved = $tf->save();
// finding credit account
$ca = ORM::factory('account')->where(array('member_id' => $member->id,
'account_attribute_id' => Account_attribute_Model::$credit))->find();
// identified transfer
Transfer_Model::insert_transfer($account->id, $ca->id,
$t_id, $member->id, $user_id, null, $datetime,
$creation_datetime, url_lang::lang('texts.Assigning of transfer'),
$form_data['amount']);
// if there is transfer fee, then it is generated
$fee_model = new Fee_Model();
$fee = $fee_model->get_by_date_type(date('Y-m-d', $form_data['datetime']), 'transfer fee');
if (is_object($fee) && $fee->id)
{
// transfer fee
Transfer_Model::insert_transfer($ca->id, $operating->id,
$t_id, $member->id, $user_id, null, $datetime,
$creation_datetime, url_lang::lang('texts.Transfer fee'), $fee->fee);
}
// identification of transfer
$transfer = new Transfer_Model($t_id);
$transfer->member_id = $member->id;
if (!$transfer->save())
throw new ErrorException();
// identification of bank fee
if ($form_data['bank_transfer_fee'] > 0)
{
$btf = new Transfer_Model($btf_id);
$btf->member_id = $member->id;
if (!$btf->save())
throw new ErrorException();
$btf3 = new Transfer_Model($btf3_id);
$btf3->member_id = $member->id;
if (!$btf3->save())
throw new ErrorException();
}
// identification of origin bank account
if (empty($counter_ba->member_id))
{
$counter_ba->member_id = $member->id;
if (!$counter_ba->save())
throw new ErrorException();
}
}
// identification of transfer
$transfer->member_id = $member->id;
$transfer_saved = $transfer->save();
// identification of bank fee
if ($form_data['bank_transfer_fee'] > 0)
{
$btf->member_id = $member->id;
$btf_saved = $btf->save();
$btf3->member_id = $member->id;
$btf3_saved = $btf3->save();
}
// identification of origin bank account
if (empty($counter_ba->member_id))
{
$counter_ba->member_id = $member->id;
$counter_ba->save();
}
}
$db->transaction_commit();
$this->session->set_flash('message', url_lang::lang('texts.Bank transfer has been successfully added.'));
}
$bank_transfer_fee_saved = $btf_saved && $btf2_saved && $btf3_saved;
// everything successful
if ($transfer_saved && $bank_transfer_saved && $bank_transfer_fee_saved && $identified_transfer_saved && $transfer_fee_saved)
catch (ErrorException $e)
{
$this->session->set_flash('message', url_lang::lang('texts.Bank transfer has been successfully added'));
url::redirect(url_lang::base().'bank_transfers/show_by_bank_account/'.$baa_id);
$db->transaction_rollback();
$this->session->set_flash('message', url_lang::lang('texts.Error - cannot add bank transfer.'));
}
url::redirect(url_lang::base().'bank_transfers/show_by_bank_account/'.$baa_id);
}
$headline = url_lang::lang('texts.Add new bank transfer');
$view = new View('main');
......
$form_data[$key] = htmlspecialchars($value);
}
// preparation
$time_now = date('Y-m-d H:i:s', time());
$creation_datetime = date('Y-m-d H:i:s');
$datetime = date('Y-m-d', $form_data['datetime']);
$user_id = $this->session->get('user_id');
$account = $baa->get_related_account_by_attribute_id(
Account_attribute_Model::$bank);
$bank_fees = $baa->get_related_account_by_attribute_id(
......
$cash = ORM::factory('account')->
where('account_attribute_id', Account_attribute_Model::$cash)->find();
// transfer
$transfer = new Transfer_Model();
$transfer_saved = true;
if ($form_data['type'] == self::$bank_fee)
{
$transfer->origin_id = $account->id;
$transfer->destination_id = $bank_fees->id;
$t_origin_id = $account->id;
$t_destination_id = $bank_fees->id;
}
elseif ($form_data['type'] == self::$bank_interest)
{
$transfer->origin_id = $bank_interests->id;
$transfer->destination_id = $account->id;
$t_origin_id = $bank_interests->id;
$t_destination_id = $account->id;
}
elseif ($form_data['type'] == self::$deposit)
{
$transfer->origin_id = $cash->id;
$transfer->destination_id = $account->id;
$t_origin_id = $cash->id;
$t_destination_id = $account->id;
}
$transfer->user_id = $this->session->get('user_id');
$transfer->datetime = date('Y-m-d', $form_data['datetime']);
$transfer->creation_datetime = $time_now;
$transfer->text = $form_data['text'];
$transfer->amount = $form_data['amount'];
$transfer_saved = $transfer->save();
// bank transfer
$bt = new Bank_transfer_Model();
$bt_saved = true;
if ($form_data['type'] == self::$bank_fee)
try
{
$bt->origin_id = $baa->id;
$bt->destination_id = null;
$db = new Transfer_Model();
$db->transaction_start();
$t_id = Transfer_Model::insert_transfer($t_origin_id, $t_destination_id, null,
null, $user_id, null, $datetime, $creation_datetime, $form_data['text'],
$form_data['amount']);
// bank transfer
$bt = new Bank_transfer_Model();
if ($form_data['type'] == self::$bank_fee)
{
$bt->origin_id = $baa->id;
$bt->destination_id = null;
}
elseif ($form_data['type'] == self::$bank_interest || $form_data['type'] == self::$deposit)
{
$bt->origin_id = null;
$bt->destination_id = $baa->id;
}
$bt->transfer_id = $t_id;
if (!$bt->save())
throw new ErrorException();
$db->transaction_commit();
$this->session->set_flash('message', url_lang::lang('texts.Bank transfer has been successfully added.'));
}
elseif ($form_data['type'] == self::$bank_interest || $form_data['type'] == self::$deposit)
catch (ErrorException $e)
{
$bt->origin_id = null;
$bt->destination_id = $baa->id;
$db->transaction_rollback();
$this->session->set_flash('message', url_lang::lang('texts.Error - cannot add bank transfer.'));
}
$bt->transfer_id = $transfer->id;
$bank_transfer_saved = $bt->save();
if ($transfer_saved && $bank_transfer_saved)
{
$this->session->set_flash('message', url_lang::lang('texts.Bank transfer has been successfully added'));
url::redirect(url_lang::base().'bank_transfers/show_by_bank_account/'.$baa_id);
}
url::redirect(url_lang::base().'bank_transfers/show_by_bank_account/'.$baa_id);
}
$headline = url_lang::lang('texts.Add new bank transfer without counteraccount');
$view = new View('main');
freenetis/branches/account_transactions/application/controllers/bank_statements.php
<?php
/**
* Handles all bank statements operations.
* @author Jiri Svitak
* @license GNU/GPLv3
*/
class Bank_statements_Controller extends Controller
{
/**
......
$grid->action_field('id')->label(url_lang::lang('texts.Statement'))->url(url_lang::base().'bank_transfers/show_by_bank_statement')->action(url_lang::lang('texts.Show'));
if ($this->acl_check_edit('Accounts_Controller', 'bank_statements'))
$grid->action_field('id')->label(url_lang::lang('texts.Statement'))->url(url_lang::base().'bank_statements/edit')->action(url_lang::lang('texts.Edit'));
if ($this->acl_check_delete('Accounts_Controller', 'bank_statements'))
$grid->action_field('id')->label(url_lang::lang('texts.Statement'))->url(url_lang::base().'bank_statements/delete')->action(url_lang::lang('texts.Delete'));
//if ($this->acl_check_delete('Accounts_Controller', 'bank_statements'))
// $grid->action_field('id')->label(url_lang::lang('texts.Statement'))->url(url_lang::base().'bank_statements/delete')->action(url_lang::lang('texts.Delete'));
$grid->datasource($bank_statements);
$view = new View('main');
freenetis/branches/account_transactions/application/controllers/work_reports.php
// creates new transfer
$account_model = new Account_Model();
/*
$transfer = new Transfer_Model();
// finding of operating account
$operating_account = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$transfer->origin_id = $operating_account->id;
// findind of account of member
$member_account = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer->destination_id = $member_account->id;
$transfer->datetime = date('Y-m-d');
$transfer->creation_datetime = date('Y-m-d H:i:s');
$transfer->text = url_lang::lang('texts.Work report approval');
$transfer->amount = $amount;
$transfer->user_id = $this->session->get('user_id');
$transfer->save();
*/
$operating = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$credit = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer_id = Transfer_Model::insert_transfer($operating->id, $credit->id, null, null,
$this->session->get('user_id'), null, date('Y-m-d'), date('Y-m-d H:i:s'), url_lang::lang('texts.Work report approval'), $amount);
foreach ($approved_works_ids as $approved_work_id)
{
$approved_work = new Job_Model($approved_work_id);
$approved_work->transfer_id = $transfer->id;
$approved_work->transfer_id = $transfer_id;
$approved_work->save();
}
freenetis/branches/account_transactions/application/controllers/works.php
{
// creates new transfer
$account_model = new Account_Model();
/*
$transfer = new Transfer_Model();
// finding of operating account
$operating_account = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$transfer->origin_id = $operating_account->id;
// findind of account of member
$member_account = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer->destination_id = $member_account->id;
$transfer->datetime = date('Y-m-d');
$transfer->creation_datetime = date('Y-m-d H:i:s');
$transfer->text = url_lang::lang('texts.Work approval');
$transfer->amount = $work->suggest_amount;
$transfer->user_id = $this->session->get('user_id');
$transfer->save();
*
*/
$operating = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$credit = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer_id = Transfer_Model::insert_transfer($operating->id, $credit->id, null, null,
$this->session->get('user_id'), null, date('Y-m-d'), date('Y-m-d H:i:s'), url_lang::lang('texts.Work approval'), $work->suggest_amount);
$work->transfer_id = $transfer->id;
$work->transfer_id = $transfer_id;
}
$work->save();
......
{
// creates new transfer
$account_model = new Account_Model();
/*
$transfer = new Transfer_Model();
// finding of operating account
$operating_account = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$transfer->origin_id = $operating_account->id;
// findind of account of member
$member_account = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer->destination_id = $member_account->id;
$transfer->datetime = date('Y-m-d');
$transfer->creation_datetime = date('Y-m-d H:i:s');
$transfer->text = url_lang::lang('texts.Work approval');
$transfer->amount = $work->suggest_amount;
$transfer->user_id = $this->session->get('user_id');
$transfer->save();
*/
$work->transfer_id = $transfer->id;
$operating = $account_model->where('account_attribute_id', Account_attribute_Model::$operating)->find();
$credit = $account_model->where('member_id', $work->user->member_id)->where('account_attribute_id', Account_attribute_Model::$credit)->find();
$transfer_id = Transfer_Model::insert_transfer($operating->id, $credit->id, null, null,
$this->session->get('user_id'), null, date('Y-m-d'), date('Y-m-d H:i:s'), url_lang::lang('texts.Work approval'), $work->suggest_amount);
$work->transfer_id = $transfer_id;
}
$work->save();
freenetis/branches/account_transactions/application/controllers/import.php
}
}
/**
* Handles importing of all types of bank listings into the database.
* @author Tomas Dulik, Jiri Svitak
* @license GNU/GPLv3
*/
class Import_Controller extends Controller
{
......
$statement->from = date('Y-m-d', $form_data['from']);
$statement->to = date('Y-m-d', $form_data['to']);
$statement->opening_balance = $form_data['opening_balance'];
$statement->closing_balance = $form_data['closing_balance'];
switch($form_data['type'])
$statement->closing_balance = $form_data['closing_balance'];
try
{
case self::$html_ebanka:
$statement->extension = "html";
$statement->save();
$this->bank_statement_id = $statement->id;
$this->parse_ebank_account($id, $form->listing->value);
break;
case self::$csv_postovni_sporitelna:
//$this->parse_csv_file($id, $form_data['csv_template'], $form->listing->value);
$this->parse_csv_postovni_sporitelna($id, $form->listing->value);
break;
default:
break;
$db = new Transfer_Model();
$db->transaction_start();
switch($form_data['type'])
{
case self::$html_ebanka:
$statement->extension = "html";
if (!$statement->save())
throw new ErrorException();
$this->bank_statement_id = $statement->id;
$this->parse_ebank_account($id, $form->listing->value);
break;
case self::$csv_postovni_sporitelna:
//$this->parse_csv_file($id, $form_data['csv_template'], $form->listing->value);
$this->parse_csv_postovni_sporitelna($id, $form->listing->value);
break;
default:
break;
}
$db->transaction_commit();
}
catch (ErrorException $e)
{
$db->transaction_rollback();
$this->session->set_flash('message', url_lang::lang('texts.Import has failed.'));
url::redirect(url_lang::base().'bank_accounts/show_all');
}
}
else
{
......
* @param $bank_account_id
* @param $bank_template_id
* @return unknown_type
* @TODO not fully functional, CSV template imports found to be difficult task
* ALTER TABLE `bank_templates` ADD `has_header` TINYINT NOT NULL COMMENT '0=no header, 1=use the header, 2=header present, but use column numbers in the template' AFTER `string_separator`
* ALTER TABLE `bank_templates` CHANGE `datetime` `date` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL
ALTER TABLE `bank_templates` ADD `time` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL AFTER `date
......
/**
* Function parses csv bank listing file of czech bank Postovni sporitelna.
* @author Jiri Svitak
* @todo Not fully functional.
* @param $bank_account_id
* @param $url
* @return unknown_type
......
}
private function create_transfer($src, $dst, $amount, $datetime, $text,
$member_id=null, $prev_id=null) {
private function create_transfer($src, $dst, $amount, $datetime, $text, $member_id=null,$prev_id=null)
{
// old version, with recalculating account balance and without exception handling
/*
static $transfer; // static variable saves a little bit of memory & time
if (!isset($transfer)) $transfer=new Transfer_Model();
$transfer->clear();
......
$transfer->user_id = $this->session->get('user_id');
$transfer->save();
return $transfer->id;
*
*/
// safe transfer saving
return Transfer_Model::insert_transfer($src->id, $dst->id, $prev_id, $member_id,
$this->session->get('user_id'), null, $datetime, $this->time_now, $text, $amount);
}
private function create_transfers($src_acc, $dst_acc, $amount,
......
$member_id=null, $prev_id=null)
{
// static variable saves a little bit of memory & time
/*
static $transfer;
static $bank_transfer;
if (!isset($transfer)) {
$transfer=new Transfer_Model();
$bank_transfer=new Bank_transfer_Model();
}
// nejdriv zkontroluj, jestli uz tuto transakci nemame od minuleho importu
$dups=$bank_transfer->get_duplicities($data);
if ($dups->count() > 0) throw new Duplicity_Exception($dups);
$dups = $bank_transfer->get_duplicities($data);
if ($dups->count() > 0)
throw new Duplicity_Exception($dups);
*
*/
// duplicity check - in case of duplicity all already imported items are storned
$bank_transfer=new Bank_transfer_Model();
$dups = $bank_transfer->get_duplicities($data);
if ($dups->count() > 0)
throw new ErrorException();
// old version, with recalculating account balance and without exception handling
/*
$transfer->clear();
$transfer->amount = $amount;
$transfer->datetime = $data->date_time;
......
$transfer->member_id = $member_id;
$transfer->user_id = $this->session->get('user_id');
$transfer->save();
*/
// safe transfer saving
$transfer_id = Transfer_Model::insert_transfer($src_acc->id, $dst_acc->id, $prev_id, $member_id,
$this->session->get('user_id'), null, $data->date_time, $this->time_now, $data->comment, $amount);
// bank transfer saving
$bank_transfer->clear();
$bank_transfer->transfer_id = $transfer->id;
$bank_transfer->transfer_id = $transfer_id;
$bank_transfer->origin_id = isset($src_bank_acc)? $src_bank_acc->id : null;
$bank_transfer->destination_id = isset($dst_bank_acc)? $dst_bank_acc->id : null;
$bank_transfer->bank_statement_id = $this->bank_statement_id;
......
$bank_transfer->variable_symbol = $data->variable_symbol;
$bank_transfer->constant_symbol = $data->constant_symbol;
$bank_transfer->specific_symbol = $data->specific_symbol;
$bank_transfer->save();
return $transfer->id;
if (!$bank_transfer->save())
throw new ErrorException();
return $transfer_id;
}
/**
* @author Tomas Dulik
* @author Tomas Dulik, Jiri Svitak
* @param $url - URL containing the file to parse
* @param $account_id - ID of the account whose data will be parsed.
* @return void
......
// pokud z gridu dostáváme $account_id, pak si ho uložíme pro potřeby callback funkce
if (isset($bank_account_id))
$this->parsed_bank_acc=new Bank_account_Model($bank_account_id);
try {
// old version, does not support transactions,
// in case of duplicity part of listing is not imported, which is incorrect behaviour
/*
try
{
$duplicity_err='';
$parser->parse($url);
} catch (Duplicity_Exception $ex) {
}
catch (Duplicity_Exception $ex)
{
// v případě duplicity commitujeme vše do výskytu duplicity a hned skončíme
$duplicity=new View('table_n_columns'); // tabulka se všemi nalezenými duplicitami
$duplicity->set('table_data', $ex->duplicity);
$duplicity_err = "Končíme, právě importovaný záznam má již v databázi duplicitní záznam(y):\n"
.$duplicity;
}
*/
// safe import is done by transaction processing started in previous method
// in case of exception, no item is imported due to rollback in level above
$parser->parse($url);
$stats=$this->stats;
$stats_table = new View('table_2_columns');
$stats->memory_consumed=((memory_get_usage()-$mem)>>10) . " kB";
......
$arr_stats[url_lang::lang("texts.".ucfirst(strtr($key, "_", " ")))]=$val;
$stats_table->set('table_data', $arr_stats);
$summary=array(
"Příjmy" => $stats->interests + $stats->member_fees + $stats->time_deposits_drawn,
"Výdaje" => $stats->bank_fees + $stats->invoices + $stats->time_deposits + $stats->cash_drawn,
url_lang::lang('texts.Incomes') => $stats->interests + $stats->member_fees + $stats->time_deposits_drawn,
url_lang::lang('texts.Expenses') => $stats->bank_fees + $stats->invoices + $stats->time_deposits + $stats->cash_drawn,
);
$sum_table = new View('table_2_columns');
$sum_table->set('table_data', $summary);
......
$title = url_lang::lang('texts.Import results');
$view->title = $title;
$view->content = new View('show_all');
$view->content->table = $duplicity_err . "Shrnutí:".$sum_table."Statistiky:".$stats_table;
$view->content->table = url_lang::lang("texts.Summary").$sum_table.url_lang::lang("texts.Statistics").$stats_table;
$links = array();
$links[] = html::anchor(url_lang::base().'bank_accounts/show_all', url_lang::lang('texts.Back to bank accounts'));
$links[] = html::anchor(url_lang::base().'bank_transfers/show_by_bank_statement/'.$this->bank_statement_id, url_lang::lang('texts.Transfers of bank statement'));
freenetis/branches/account_transactions/application/views/bank_accounts/show_all.php
<h2><?php echo $baa_headline; ?></h2>
<?php
$message = $this->session->get('message');
echo empty($message) ? '' : '<div class="message">'.$message.'</div>';
?>
<br />
<?php echo $baa_grid; ?>
<br />

Také k dispozici: Unified diff