Revize 872
Přidáno uživatelem Ondřej Fibich před více než 13 roky(ů)
freenetis/branches/testing/application/models/bank_transfer.php | ||
---|---|---|
<?php
|
||
class Bank_transfer_Model extends ORM
|
||
{
|
||
|
||
public function __construct($id = NULL)
|
||
{
|
||
parent::__construct($id);
|
||
|
||
// disable action log
|
||
$this->set_logger(FALSE);
|
||
}
|
||
|
||
/**
|
||
* @author Jiri Svitak
|
||
* It gets all bank transfers of given bank account.
|
freenetis/branches/testing/application/models/bank_account.php | ||
---|---|---|
//protected $belongs_to_many = array();
|
||
protected $has_and_belongs_to_many = array('accounts');
|
||
|
||
public function __construct($id = NULL)
|
||
{
|
||
parent::__construct($id);
|
||
|
||
// disable action log
|
||
$this->set_logger(FALSE);
|
||
}
|
||
|
||
/**
|
||
* @author Tomas Dulik
|
||
* @param $name - name of the bank account
|
freenetis/branches/testing/application/models/bank_statement.php | ||
---|---|---|
protected $belongs_to = array("bank_account", "user");
|
||
protected $has_many = array("bank_transfers");
|
||
|
||
public function __construct($id = NULL)
|
||
{
|
||
parent::__construct($id);
|
||
|
||
// disable action log
|
||
$this->set_logger(FALSE);
|
||
}
|
||
|
||
/**
|
||
* Counts bank statements of given bank account.
|
||
* @author Jiri Svitak
|
freenetis/branches/testing/application/models/account.php | ||
---|---|---|
//protected $belongs_to_many = array();
|
||
protected $has_and_belongs_to_many = array('bank_accounts');
|
||
|
||
public function __construct($id = NULL)
|
||
{
|
||
parent::__construct($id);
|
||
|
||
$this->set_logger(FALSE);
|
||
}
|
||
|
||
/**
|
||
* It gets double-entry accounts of given group. Groups are all credit, all project and other accounts
|
||
* of association.
|
||
... | ... | |
foreach ($transfers as $transfer)
|
||
{
|
||
$transfers_count++;
|
||
if (!$transfer->delete())
|
||
throw new ErrorException();
|
||
$transfer->delete_trowable();
|
||
}
|
||
// recalculate balance of current credit account
|
||
if (!$this->recalculate_account_balance_of_account($account_id))
|
||
throw new ErrorException();
|
||
throw new Exception();
|
||
// recalculate balance of operating account
|
||
$operating = ORM::factory('account')->where(array('account_attribute_id' => Account_attribute_Model::$operating))->find();
|
||
if (!$this->recalculate_account_balance_of_account($operating->id))
|
||
throw new ErrorException();
|
||
throw new Exception();
|
||
return $transfers_count;
|
||
}
|
||
|
||
... | ... | |
foreach ($transfers as $transfer)
|
||
{
|
||
$transfers_count++;
|
||
if (!$transfer->delete())
|
||
throw new ErrorException();
|
||
$transfer->delete_trowable();
|
||
}
|
||
// recalculate balance of current credit account
|
||
if (!$this->recalculate_account_balance_of_account($account_id))
|
||
throw new ErrorException();
|
||
throw new Exception();
|
||
// recalculate balance of operating account
|
||
$operating = ORM::factory('account')->where(array('account_attribute_id' => Account_attribute_Model::$infrastructure))->find();
|
||
if (!$this->recalculate_account_balance_of_account($operating->id))
|
||
throw new ErrorException();
|
||
throw new Exception();
|
||
return $transfers_count;
|
||
}
|
||
|
freenetis/branches/testing/application/models/transfer.php | ||
---|---|---|
public static $inbound = 2;
|
||
public static $outbound = 3;
|
||
|
||
public function __construct($id = NULL)
|
||
{
|
||
parent::__construct($id);
|
||
|
||
// disable action log
|
||
$this->set_logger(FALSE);
|
||
}
|
||
|
||
|
||
/**
|
||
* Function gets all double-entry transfer. They are shown in day book.
|
||
... | ... | |
* @param <type> $creation_datetime datetime of transfer creation
|
||
* @param <type> $text transfer text
|
||
* @param <type> $amount amount of transfer
|
||
* @throws ErrorException when failed transfer insert, origin or destination account update
|
||
* @throws Kohana_Databse_Exception when failed transfer insert, origin or destination account update
|
||
*/
|
||
public static function insert_transfer($origin_id, $destination_id, $previous_transfer_id,
|
||
$member_id, $user_id, $type, $datetime, $creation_datetime, $text, $amount)
|
||
... | ... | |
$transfer->creation_datetime = $creation_datetime;
|
||
$transfer->text = $text;
|
||
$transfer->amount = $amount;
|
||
if (!$transfer->save())
|
||
throw new ErrorException();
|
||
$transfer->save_throwable();
|
||
// update balance of origin account
|
||
$oa = new Account_Model($origin_id);
|
||
$oa->balance -= $amount;
|
||
if (!$oa->save())
|
||
throw new ErrorException();
|
||
$oa->save_throwable();
|
||
// update balance of destination account
|
||
$da = new Account_Model($destination_id);
|
||
$da->balance += $amount;
|
||
if (!$da->save())
|
||
throw new ErrorException();
|
||
$da->save_throwable();
|
||
|
||
return $transfer->id;
|
||
}
|
||
|
||
... | ... | |
* @param <type> $id
|
||
* @param <type> $text
|
||
* @param <type> $amount
|
||
* @throws Kohana_Databse_Exception
|
||
*/
|
||
public static function edit_transfer($id, $text, $amount)
|
||
{
|
||
... | ... | |
$transfer = new Transfer_Model($id);
|
||
$transfer->text = $text;
|
||
$transfer->amount = $amount;
|
||
if (!$transfer->save())
|
||
throw new ErrorException();
|
||
$transfer->save_throwable();
|
||
// update balance of origin account
|
||
$oa = new Account_Model($transfer->origin_id);
|
||
$oa->balance -= $amount;
|
||
if (!$oa->save())
|
||
throw new ErrorException();
|
||
$oa->save_throwable();
|
||
// update balance of destination account
|
||
$da = new Account_Model($transfer->destination_id);
|
||
$da->balance += $amount;
|
||
if (!$da->save())
|
||
throw new ErrorException();
|
||
$da->save_throwable();
|
||
}
|
||
|
||
/**
|
||
* Safely deletes transfer.
|
||
* @author Jiri Svitak
|
||
* @param <type> $id
|
||
* @throws Kohana_Databse_Exception
|
||
*/
|
||
public static function delete_transfer($id)
|
||
{
|
||
... | ... | |
// update balance of origin account
|
||
$oa = new Account_Model($transfer->origin_id);
|
||
$oa->balance += $transfer->amount;
|
||
if (!$oa->save())
|
||
throw new ErrorException();
|
||
$oa->save_throwable();
|
||
// update balance of destination account
|
||
$da = new Account_Model($transfer->destination_id);
|
||
$da->balance -= $transfer->amount;
|
||
if (!$da->save())
|
||
throw new ErrorException();
|
||
$da->save_throwable();
|
||
// delete transfer
|
||
if (!$transfer->delete())
|
||
throw new ErrorException();
|
||
$transfer->delete_trowable();
|
||
}
|
||
}
|
||
|
freenetis/branches/testing/application/controllers/transfers.php | ||
---|---|---|
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully added.'));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cannot add new transfer.'));
|
||
... | ... | |
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully added.'));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully added'));
|
||
... | ... | |
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully added.'));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully added'));
|
||
... | ... | |
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully updated.'));
|
||
url::redirect(url_lang::base().'transfers/show/'.$transfer_id);
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cant update transfer.'));
|
||
... | ... | |
// single query for inserting transfers
|
||
$sql_insert .= implode(",", $values);
|
||
if (!$database->query($sql_insert))
|
||
throw new ErrorException();
|
||
throw new Exception();
|
||
// single query for updating credit account balances
|
||
$ids_with_commas = implode(",", $ids);
|
||
$sql_update .= "END WHERE id IN ($ids_with_commas)";
|
||
if (!$database->query($sql_update))
|
||
throw new ErrorException();
|
||
throw new Exception();
|
||
// update also balance of operating account
|
||
if (!$account_model->recalculate_account_balance_of_account($operating->id))
|
||
throw new ErrorException();
|
||
throw new Exception();
|
||
}
|
||
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Fees have been successfully deducted, %d new transfers created.', $created_transfers_count));
|
||
}
|
||
catch(ErrorException $e)
|
||
catch(Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - some fees have not been deducted.'));
|
||
... | ... | |
if ($fee && $fee->id)
|
||
$default_fee = $fee->fee;
|
||
else
|
||
throw new ErrorException(url_lang::lang('texts.Fatal error'), url_lang::lang('texts.Fees have not been set!'));
|
||
throw new Exception(url_lang::lang('texts.Fatal error'), url_lang::lang('texts.Fees have not been set!'));
|
||
// finds regular member fee for this member and this month
|
||
$fee = $fee_model->get_fee_by_member_date_type($account->member_id, $date, 'regular member fee');
|
||
// it exists
|
||
... | ... | |
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Fees have been successfully recalculated, %d deleted transfers, %d created new transfers.', array(0 => $deleted_transfers_count, 1=> $created_transfers_count)));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - some fees have not been recounted.'));
|
||
... | ... | |
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Entrance fees have been successfully deducted, %d new transfers created.', $created_transfers_count));
|
||
}
|
||
catch(ErrorException $e)
|
||
catch(Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cant deduct entrance fee.'));
|
||
... | ... | |
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Entrance fees have been successfully recalculated, %d transfers deleted, %d new transfers created.', array(1=>$deleted_transfers_count, 2=>$created_transfers_count)));
|
||
}
|
||
catch(ErrorException $e)
|
||
catch(Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cant deduct entrance fee.'));
|
||
... | ... | |
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Device fees have been successfully deducted, %d new transfers created.', $created_transfers_count));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cant deduct device fee.'));
|
||
... | ... | |
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Transfer has been successfully added.'));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cant add new transfer.'));
|
freenetis/branches/testing/application/controllers/bank_transfers.php | ||
---|---|---|
// 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();
|
||
$t->save_throwable();
|
||
// then we create a new transfer to the selected member's account
|
||
/*
|
||
$t->clear();
|
||
... | ... | |
foreach ($next_ts as $transfer)
|
||
{
|
||
$transfer->member_id = $member_id;
|
||
if (!$transfer->save())
|
||
throw new ErrorException();
|
||
$transfer->save_trowable();
|
||
}
|
||
// also penalty should be generated
|
||
$operating = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$operating)->find();
|
||
... | ... | |
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Payment has been successfully assigned.'));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cannot assign transfer.'));
|
||
... | ... | |
$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();
|
||
$counter_ba->save_throwable();
|
||
}
|
||
// this bank account
|
||
$account = $baa->get_related_account_by_attribute_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();
|
||
$bt->save_throwable();
|
||
// bank transfer fee
|
||
if ($form_data['bank_transfer_fee'] > 0)
|
||
{
|
||
... | ... | |
$btf2->transfer_id = $btf_id;
|
||
$btf2->origin_id = $baa->id;
|
||
$btf2->destination_id = null;
|
||
if (!$btf2->save())
|
||
throw new ErrorException();
|
||
$btf2->save_throwable();
|
||
// 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']);
|
||
... | ... | |
// identification of transfer
|
||
$transfer = new Transfer_Model($t_id);
|
||
$transfer->member_id = $member->id;
|
||
if (!$transfer->save())
|
||
throw new ErrorException();
|
||
$transfer->save_trowable();
|
||
// 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();
|
||
$btf->save_trowable();
|
||
$btf3 = new Transfer_Model($btf3_id);
|
||
$btf3->member_id = $member->id;
|
||
if (!$btf3->save())
|
||
throw new ErrorException();
|
||
$btf3->save_throwable();
|
||
}
|
||
// identification of origin bank account
|
||
if (empty($counter_ba->member_id))
|
||
{
|
||
$counter_ba->member_id = $member->id;
|
||
if (!$counter_ba->save())
|
||
throw new ErrorException();
|
||
$counter_ba->save_throwable();
|
||
}
|
||
}
|
||
}
|
||
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Bank transfer has been successfully added.'));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cannot add bank transfer.'));
|
||
... | ... | |
$bt->destination_id = $baa->id;
|
||
}
|
||
$bt->transfer_id = $t_id;
|
||
if (!$bt->save())
|
||
throw new ErrorException();
|
||
$bt->save_throwable();
|
||
$db->transaction_commit();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Bank transfer has been successfully added.'));
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Error - cannot add bank transfer.'));
|
freenetis/branches/testing/application/controllers/import.php | ||
---|---|---|
{
|
||
case self::$html_ebanka:
|
||
$statement->extension = "html";
|
||
if (!$statement->save())
|
||
throw new ErrorException();
|
||
$statement->save_throwable();
|
||
$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);
|
||
//$this->parse_csv_postovni_sporitelna($id, $form->listing->value);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
$db->transaction_commit();
|
||
}
|
||
catch (ErrorException $e)
|
||
catch (Duplicity_Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Import has failed.'));
|
||
$this->session->set_flash('message', url_lang::lang('texts.Import has failed.').' '.
|
||
url_lang::lang('texts.Bank statement contains items that were already imported.'));
|
||
url::redirect(url_lang::base().'bank_accounts/show_all');
|
||
}
|
||
catch (Duplicity_Exception $e)
|
||
catch (Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
$this->session->set_flash('message', url_lang::lang('texts.Import has failed.').' '.
|
||
url_lang::lang('texts.Bank statement contains items that were already imported.'));
|
||
$this->session->set_flash('message', url_lang::lang('texts.Import has failed.'));
|
||
url::redirect(url_lang::base().'bank_accounts/show_all');
|
||
}
|
||
}
|
||
... | ... | |
$view->render(TRUE);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @author Jiri Svitak
|
||
* Function prepares import of listing file. Certain double-entry accounts are created.
|
||
* @return unknown_type
|
||
*/
|
||
private function init_import($bank_account_id = null)
|
||
{
|
||
$this->time_now = date("Y-m-d H:i:s");
|
||
$this->t = new Transfer_Model();
|
||
$this->bt = new Bank_transfer_Model();
|
||
$this->member_model = new Member_Model();
|
||
$this->acc_model = new Account_Model();
|
||
$this->bank_acc_model = new Bank_account_Model();
|
||
$this->fee_model = new Fee_Model();
|
||
|
||
$this->parsed_bank_acc = new Bank_account_Model($bank_account_id);
|
||
$this->parsed_acc = $this->parsed_bank_acc->get_related_account_by_attribute_id(Account_attribute_Model::$bank);
|
||
if ($this->parsed_acc===FALSE)
|
||
{
|
||
// tohle by normálně nemělo nastat.
|
||
// může se to stát pouze pokud někdo smaže vazbu bank. účet sdružení
|
||
// s podvojným účtem přes tabulku accounts_bank_accounts
|
||
throw new Kohana_User_Exception('Kritická chyba', 'V tabulce accounts_bank_accounts chybí vazba bankovního a podvojného účtu sdružení');
|
||
}
|
||
|
||
$bank_interests = $this->parsed_bank_acc->get_related_account_by_attribute_id(Account_attribute_Model::$bank_interests);
|
||
if ($bank_interests===FALSE)
|
||
{ // pokud ucet uroku neexistuje, pak si jej vytvorime
|
||
$bank_interests = Account_Model::create(Account_attribute_Model::$bank_interests, "Úroky z $parsed_acc->name", 1);
|
||
$bank_interests->add($this->parsed_bank_acc);
|
||
}
|
||
$bank_fees = $this->parsed_bank_acc->get_related_account_by_attribute_id(Account_attribute_Model::$bank_fees);
|
||
if ($bank_fees===FALSE) { // pokud ucet poplatku neexistuje, pak jej vytvorime
|
||
$bank_fees = Account_Model::create(Account_attribute_Model::$bank_fees, "Poplatky z $parsed_acc->name", 1);
|
||
$bank_fees->add($this->parsed_bank_acc);
|
||
}
|
||
|
||
$this->suppliers = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$suppliers)->find();
|
||
$this->member_fees = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$member_fees)->find();
|
||
$this->operating = ORM::factory('account')->where('account_attribute_id', Account_attribute_Model::$operating)->find();
|
||
if (!$this->suppliers->id || !$this->member_fees->id || !$this->operating->id)
|
||
throw new Kohana_User_Exception('Kritická chyba', 'V DB chybí účet member_fees, suppliers nebo operating');
|
||
}
|
||
|
||
/**
|
||
* Function parses csv file with bank listing.
|
||
* It uses predefined bank template to identify columns in csv file.
|
||
* @author Jiri Svitak, Tomas Dulik
|
||
* @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
|
||
|
||
*
|
||
*
|
||
*/
|
||
private function parse_csv_file($bank_account_id = null, $bank_template_id = null, $url = "")
|
||
{
|
||
if (!isset($bank_account_id) || !isset($bank_template_id) || $url == "")
|
||
Controller::warning(PARAMETER);
|
||
$bank_account = new Bank_account_Model($bank_account_id);
|
||
$bank_template = new Bank_template_Model($bank_template_id);
|
||
if ($bank_account->id == 0 || $bank_template->id == 0)
|
||
Controller::error(RECORD);
|
||
// preparation
|
||
//$this->init_import();
|
||
$first = true;
|
||
$template = $bank_template->as_array();
|
||
// associatiove array - keys are template column names and values are column numbers in csv file
|
||
$headers = array();
|
||
$items = array();
|
||
// file to import
|
||
$file = fopen($url, 'r');
|
||
while (($line = fgetcsv($file, 0, $bank_template->item_separator, $bank_template->string_separator)) !== false)
|
||
{
|
||
// column headers
|
||
if ($first)
|
||
{
|
||
// goes through every header of csv file
|
||
for ($i = 0; $i < count($line); $i++)
|
||
{
|
||
// goes through every header specified by template
|
||
foreach ($template as $key => $value)
|
||
{
|
||
if (trim($value) == trim($line[$i]))
|
||
{
|
||
$headers[$key] = $i;
|
||
}
|
||
}
|
||
}
|
||
$first = false;
|
||
}
|
||
// import of line
|
||
else
|
||
{
|
||
// loads the items array with proper values
|
||
for ($i = 0; $i < count($line); $i++)
|
||
{
|
||
foreach ($headers as $key => $value)
|
||
{
|
||
if ($value == $i)
|
||
$items[$key] = $line[$i];
|
||
}
|
||
}
|
||
print_r($items);
|
||
echo '<br>';
|
||
}
|
||
}
|
||
fclose($file);
|
||
die();
|
||
}
|
||
|
||
/**
|
||
* 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 parse_csv_postovni_sporitelna($bank_account_id = null, $url = "")
|
||
{
|
||
if (!isset($bank_account_id) || $url == "")
|
||
Controller::warning(PARAMETER);
|
||
$bank_account = new Bank_account_Model($bank_account_id);
|
||
if ($bank_account->id == 0)
|
||
Controller::error(RECORD);
|
||
echo "Memory usage: ".($mem=memory_get_usage()). "<p>\n";
|
||
echo "parse - start: ".($start=microtime(true))."<p>\n";
|
||
// preparation
|
||
$this->init_import($bank_account_id);
|
||
$data = new StdClass();
|
||
$first = true;
|
||
// file to import
|
||
$file = fopen($url, 'r');
|
||
while (($line = fgetcsv($file, 0, ';', '"')) !== false)
|
||
{
|
||
if ($first)
|
||
{
|
||
$first = false;
|
||
continue;
|
||
}
|
||
$data->amount = (double)$line[13];
|
||
$data->comment = $line[23];
|
||
$data->variable_symbol = $line[15];
|
||
$data->specific_symbol = $line[16];
|
||
$data->constant_symbol = $line[17];
|
||
// counteraccount
|
||
$data->account_nr = (int)$line[10];
|
||
$data->account_bank_nr = (int)$line[11];
|
||
$data->name = $line[21];
|
||
$datetime = explode('.', trim($line[20]));
|
||
$data->date_time = $datetime[2].'-'.$datetime[1].'-'.$datetime[0];
|
||
|
||
// vydej
|
||
if ($line[14] == 1)
|
||
{
|
||
// poplatek
|
||
if (trim($line[21]) == 'Zuctovanipoplatku')
|
||
{
|
||
|
||
}
|
||
}
|
||
// prijem
|
||
else
|
||
{
|
||
$this->member_model->clear();
|
||
$member = $this->member_model;
|
||
$vs = trim($data->variable_symbol);
|
||
if ($data->amount > 0 && !empty($vs))
|
||
{
|
||
// členský příspěvek: uvedl člen u teto platby jako variabilni symbol (VS) svůj telefon ?
|
||
$member = $this->member_model->find_member_by_phone($vs);
|
||
|
||
if ($member === FALSE )
|
||
{ // find_member_by_phone vrací false, pokud nic nenajde
|
||
|
||
// ne? zkusime, zda jako VS nezadal svoje member_id + crc16(member_id)
|
||
// $member=$member_model->get_member_by_crc_id($vs); // this function has bugs!!! needs rewrite!!!
|
||
$member = $this->member_model;
|
||
}
|
||
// pokud se to nepovedlo, pak $member->id nastavíme na null
|
||
} // else { // platba přijaté faktury - majitele účtu najdeme dle VS na faktuře, až budeme mít modul přijatých faktur}
|
||
// ***Tady si vytvorime instanci účtu clena (nebo dodavatele) z prave nacteneho vypisu:
|
||
$bank_acc = $this->bank_acc_model->where(array('account_nr' => $data->account_nr, 'bank_nr' => $data->account_bank_nr))->find();
|
||
|
||
if (!$bank_acc->id) { // bank. ucet clena neexistuje, tak si ho vytvorime
|
||
$bank_acc->set_logger(FALSE);
|
||
$bank_acc->clear();
|
||
$bank_acc->member_id = $member->id;
|
||
$bank_acc->name = $data->name;
|
||
$bank_acc->account_nr = $data->account_nr;
|
||
$bank_acc->bank_nr = $data->account_bank_nr;
|
||
$bank_acc->save();
|
||
$this->stats->new_bank_accounts++;
|
||
// $bank_acc->add_account($member_fees); //tuto vazbu bych tvořil jen pokud bych chtěl evidovat pohyby na bank. účtech členů
|
||
}
|
||
// členský příspěvek - vytvoříme:
|
||
// - podvojnou transakci z 684000 na 221000
|
||
// - bankovní transakci z bank. účtu člena na bank. účet sdružení
|
||
$id = $this->create_transfers($this->member_fees, $this->parsed_acc, $data->amount,
|
||
$bank_acc, $this->parsed_bank_acc, $data, $member->id);
|
||
if ($member->id)
|
||
{ // našli jsme plátce?
|
||
// **** převedeme peníze členovi na jeho účet s kreditem
|
||
// ten účet ale musíme najít nebo vytvořit:
|
||
$credit_acc = $this->acc_model->where(array('member_id' => $member->id, 'account_attribute_id' => Account_attribute_Model::$credit))->find();
|
||
if (!$credit_acc->id)
|
||
{
|
||
$credit_acc->clear();
|
||
$credit_acc->set_logger(FALSE);
|
||
$credit_acc->account_attribute_id = Account_attribute_Model::$credit;
|
||
$credit_acc->member_id = $member->id;
|
||
$credit_acc->name = $member->name;
|
||
$credit_acc->save();
|
||
}
|
||
$this->create_transfer($this->parsed_acc, $this->acc_model,
|
||
$data->amount, $data->date_time, "Přiřazení platby", $member->id, $id);
|
||
// **** teď se podíváme, jestli v té době sdružení účtovalo poplatek za zpracování platby:
|
||
$fee = $fee_model->get_by_date_type($data->date_time, 'transfer fee');
|
||
if (is_object($fee) && $fee->id) // ano? Pak poplatek strhneme z účtu
|
||
$this->create_transfer($credit_acc, $this->operating,
|
||
$fee->fee, $data->date_time, "Transakční poplatek",
|
||
$member->id, $id);
|
||
} // if (is_object($member) && $member->id)
|
||
$this->stats->member_fees_nr++;
|
||
$this->stats->member_fees+=$data->amount;
|
||
}
|
||
//print_r($line);
|
||
}
|
||
fclose($file);
|
||
echo html::anchor(url_lang::base().'bank_accounts/show_all', url_lang::lang('texts.Back to bank accounts'));
|
||
}
|
||
|
||
|
||
/**
|
||
* @author Tomas Dulik
|
||
* Funkce store_transfers_ebanka se používá jako callback funkce pro Parser_Ebanka.
|
||
* Třída Parser_Ebanka tuto funkci volá s každou načtenou položkou výpisu.
|
||
... | ... | |
$bank_transfer->variable_symbol = $data->variable_symbol;
|
||
$bank_transfer->constant_symbol = $data->constant_symbol;
|
||
$bank_transfer->specific_symbol = $data->specific_symbol;
|
||
if (!$bank_transfer->save())
|
||
throw new ErrorException();
|
||
$bank_transfer->save_throwable();
|
||
return $transfer_id;
|
||
}
|
||
|
freenetis/branches/testing/system/libraries/ORM.php | ||
---|---|---|
}
|
||
|
||
/**
|
||
* Deletes the current object from the database. This does NOT destroy
|
||
* relationships that have been created with other objects.
|
||
*
|
||
* @author Ondřej Fibich
|
||
* @chainable
|
||
* @return ORM
|
||
* @throws Kohana_Database_Exception If save was not successful.
|
||
*/
|
||
public function delete_trowable($id = NULL)
|
||
{
|
||
if ($id === NULL AND $this->loaded)
|
||
{
|
||
// Use the the primary key value
|
||
$id = $this->object[$this->primary_key];
|
||
}
|
||
|
||
// Delete this object
|
||
$result = $this->db->where($this->primary_key, $id)
|
||
->delete($this->table_name);
|
||
|
||
if (!$result || count($result) != 1)
|
||
{
|
||
throw new Kohana_Database_Exception('ORM - Cannot delete object.');
|
||
}
|
||
|
||
// add log for deleting
|
||
if ($this->is_logger_on['delete'])
|
||
{
|
||
$this->log_action(Log_Model::ACTION_DELETE, $id);
|
||
}
|
||
|
||
return $this->clear();
|
||
}
|
||
|
||
/**
|
||
* Checks if action logger is ON, or if action is not specified,
|
||
* check if all logger actions are set to ON
|
||
* @author Ondřej Fibich
|
Také k dispozici: Unified diff
Prepracovani vyjimek v bynkovnich vecech. Nelogovani v bankovnich vecech. Do ORM pridana metoda save_trowable()