Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 425

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

Prace na csv importu dat, rozsirovani csv sablon, uprava presmerovani vlastni ip adresy.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php
'error - not enough money on origin account' => 'Chyba - nedostatek peněz na zdrojovém účtě.',
'error - some fees have not been deducted' => 'Chyba - některé členské příspěvky nebyly strženy.',
'error: parameter ID is required!' => 'Chyba: parametr ID je povinný!',
'expenditure-earning' => 'Výdej-Příjem',
'export to xls' => 'Exportovat do XLS',
'export to csv (utf-8)' => 'Exportovat do CSV (utf-8)',
'export to csv (windows-1250)' => 'Exportovat do CSV (windows-1250)',
......
'ip addresses' => 'IP adresy',
'it is possible to deduct fees only in one year' => 'Členské příspěvky je možné strhávat jen v rámci jednoho roku.',
'item number' => 'Položka č.',
'item separator' => 'Oddělovač položek',
'item(s) have been successfully added' => 'položka(ek) bylo úspěšně přidáno',
'language' => 'Jazyk',
'last time login' => 'Poslední čas přihlášení',
......
'street number' => 'č.p.',
'street_number' => 'č.p.',
'street' => 'Ulice',
'string separator' => 'Oddělovač řetězců',
'subject' => 'Předmět',
'submit' => 'Odeslat',
'subnet is successfully saved' => 'Podsíť byla úspěšně uložena.',
......
'users in group' => 'Uživatelé ve skupině',
'vacating member' => 'Přerušené členství',
'value' => 'Hodnota',
'value for earning' => 'Hodnota pro příjem',
'value has not been entered' => 'Hodnota nebyla zadána.',
'variable symbol' => 'Variabilní symbol',
'vat' => 'DPH',
......
'year' => 'Rok',
'yes' => 'ano',
'you have been successfully logged out' => 'Byl jste úspěšně odhlášen.',
'your ip address has not been found in database' => 'Vaše IP adresa nebyla nalezena v databázi.',
'zip code' => 'PSČ',
'zip_code' => 'PSČ'
);
freenetis/trunk/kohana/application/controllers/bank_templates.php
'limit_results' => $limit_results,
'message' => $this->session->get_once('message')
));
$grid->add_new_button(url_lang::base().'bank_accounts/show_all', url_lang::lang('texts.Back to bank accounts'));
$grid->add_new_button(url_lang::base().'bank_templates/add', url_lang::lang('texts.Add new template'));
$grid->order_field('id')->label(url_lang::lang('texts.ID'));
$grid->order_field('template_name')->label(url_lang::lang('texts.Template name'));
......
$form = new Forge(url_lang::base().'bank_templates/add', '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Template name'));
$form->input('template_name')->label(url_lang::lang('texts.Template name').':')->rules('required|length[1,50]');
$form->input('template_name')->label(url_lang::lang('texts.Template name').':')->rules('required|length[1,50]');
$form->input('item_separator')->label(url_lang::lang('texts.Item separator').':')->rules('required|length[1,1]')->value(';');
$form->input('string_separator')->label(url_lang::lang('texts.String separator').':')->rules('required|length[1,1]')->value('"');
$form->group('')->label(url_lang::lang('texts.Column headers'));
$form->input('account_name')->label(url_lang::lang('texts.Account name').':')->rules('required|length[1,30]');
$form->input('account_number')->label(url_lang::lang('texts.Account number').':')->rules('required|length[1,30]');
......
$form->input('counteraccount_bank_code')->label(url_lang::lang('texts.Counteraccount bank code').':')->rules('required|length[1,30]');
$form->input('text')->label(url_lang::lang('texts.Text').':')->rules('required|length[1,30]');
$form->input('amount')->label(url_lang::lang('texts.Amount').':')->rules('required|length[1,30]');
$form->input('expenditure_earning')->label(url_lang::lang('texts.Expenditure-earning').':')->rules('length[1,30]');
$form->input('value_for_earning')->label(url_lang::lang('texts.Value for earning').':')->rules('length[1,10]');
$form->input('datetime')->label(url_lang::lang('texts.Date and time').':')->rules('required|length[1,30]');
$form->submit('submit')->value(url_lang::lang('texts.Add'));
special::required_forge_style($form, ' *', 'required');
......
if ($template->save())
{
$this->session->set_flash('message', url_lang::lang('texts.Template has been successfully added.'));
url::redirect(url_lang::base().'bank_templates/show'.$template->id);
url::redirect(url_lang::base().'bank_templates/show/'.$template->id);
}
else
{
$this->session->set_flash('message', url_lang::lang('texts.Error - cant add new template.'));
url::redirect(url_lang::base().'bank_templates/show'.$template->id);
url::redirect(url_lang::base().'bank_templates/show_all');
}
}
else
......
}
$form = new Forge(url_lang::base().'bank_templates/edit/'.$template_id, '', 'POST', array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->group('')->label(url_lang::lang('texts.Template name'));
$form->group('')->label(url_lang::lang('texts.Basic information'));
$form->input('template_name')->label(url_lang::lang('texts.Template name').':')->rules('required|length[1,50]')->value($template->template_name);
$form->input('item_separator')->label(url_lang::lang('texts.Item separator').':')->rules('required|length[1,1]')->value($template->item_separator);
$form->input('string_separator')->label(url_lang::lang('texts.String separator').':')->rules('required|length[1,1]')->value($template->string_separator);
$form->group('')->label(url_lang::lang('texts.Column headers'));
$form->input('account_name')->label(url_lang::lang('texts.Account name').':')->rules('required|length[1,30]')->value($template->account_name);
$form->input('account_number')->label(url_lang::lang('texts.Account number').':')->rules('required|length[1,30]')->value($template->account_number);
......
$form->input('counteraccount_bank_code')->label(url_lang::lang('texts.Counteraccount bank code').':')->rules('required|length[1,30]')->value($template->counteraccount_bank_code);
$form->input('text')->label(url_lang::lang('texts.Text').':')->rules('required|length[1,30]')->value($template->text);
$form->input('amount')->label(url_lang::lang('texts.Amount').':')->rules('required|length[1,30]')->value($template->amount);
$form->input('expenditure_earning')->label(url_lang::lang('texts.Expenditure-earning').':')->rules('length[1,30]')->value($template->expenditure_earning);
$form->input('value_for_earning')->label(url_lang::lang('texts.Value for earning').':')->rules('length[1,10]')->value($template->value_for_earning);
$form->input('datetime')->label(url_lang::lang('texts.Date and time').':')->rules('required|length[1,30]')->value($template->datetime);
$form->submit('submit')->value(url_lang::lang('texts.Edit'));
special::required_forge_style($form, ' *', 'required');
......
$form_data = $form->as_array();
foreach($form_data as $key => $value)
{
$template->$key = htmlspecialchars($value);
if ($key != 'string_separator')
$template->$key = htmlspecialchars($value);
else
$template->$key = $value;
}
if ($template->save())
{
......
}
else
{
$this->session->set_flash('message', url_lang::lang('texts.Error - cant edit new template.'));
url::redirect(url_lang::base().'bank_templates/show'.$template->id);
$this->session->set_flash('message', url_lang::lang('texts.Error - cant update template.'));
url::redirect(url_lang::base().'bank_templates/show/'.$template->id);
}
}
else
freenetis/trunk/kohana/application/controllers/redirect.php
function ip_info($ip_address = NULL)
{
if (!$ip_address) $ip_address = server::remote_addr();
if (!$ip_address)
$ip_address = server::remote_addr();
$ip_address_model = new Ip_address_Model();
$this_ip = $ip_address_model->where('IP_address',$ip_address)->find();
......
$engineer_names = implode(', ',$arr_engineers);
$user_name = $this_ip->iface->device->user->name.' '.$this_ip->iface->device->user->surname;
}
}
$ip = ip2long($ip_address);
$subnet_model = new Subnet_Model();
......
}
if (count($arr_subnets)==0) url::redirect(url::base());
if (count($arr_subnets) == 0)
{
$this->session->set_flash('message', url_lang::lang('texts.Your IP address has not been found in database.'));
url::redirect(url_lang::base().'members/show/'.$this->session->get('member_id'));
}
$subnet = $arr_subnets[0];
$arr_ip = explode('.', $subnet->net_str);
freenetis/trunk/kohana/application/controllers/accounts.php
<?php
class Duplicity_Exception extends Exception {}
class Accounts_Controller extends Controller {
protected $owner_id = NULL;
protected $editation = FALSE;
protected $acc_id = NULL;
protected $sel_member;
class Accounts_Controller extends Controller
{
// private variables for importing bank listings
// accounts
private $acc_model;
private $bank_acc_model;
private $member_model;
private $fee_model;
private $parsed_acc;
private $bank_interests;
private $bank_fees;
private $suppliers;
private $operating;
private $member_fees;
// all created transfers in database should have the same time
private $current_time;
/**
* @var object $parsed_bank_acc obsahuje data o parsovaném bank. účtu (z tabluky bank_accounts)
* Používá se v callback funkci store_transfer
......
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
'query_string' => $query_string,
'message' => $this->session->get_once('message')
'message' => $this->session->get_once('message'),
'filter' => $filter->view
));
if ($filter_values['group'] == Account_Model::$project && $this->acl_check_new('Accounts_Controller', 'accounts'))
$grid->add_new_button(url_lang::base().'accounts/add_project', url_lang::lang('texts.Add new project account'));
......
$view->header = new View('base/header');
$view->header->title = $headline;
$view->header->menu = Controller::render_menu();
$view->content = $filter->view.'<br />'.$grid;
$view->content = $grid;
$view->footer = new View('base/footer');
$view->render(TRUE);
}
......
* @param $id
* @return unknown_type
*/
public function upload_bank_file($id=null)
public function upload_bank_file($id = null)
{
if (!isset($id))
Controller::warning(PARAMETER);
......
Controller::error(RECORD);
// file types of bank listings
$types = array();
$types[0] = 'HTML eBanka';
$types[1] = 'texts.CSV';
$types[1] = 'CSV';
$types[2] = 'HTML eBanka';
// csv templates
$template_model = new Bank_template_Model();
$templates = $template_model->find_all();
foreach ($templates as $template)
{
$arr_templates[$template->id] = $template->template_name;
}
// form
$form = new Forge(url_lang::base()."accounts/upload_bank_file/$id", '','POST',array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->dropdown('type')->label(url_lang::lang('texts.File type'))->options($types)->rules('required');
$form->dropdown('csv_template')->label(url_lang::lang('texts.CSV file template'));
$form->upload('listing', TRUE)->label(url_lang::lang('texts.File with bank transfer listing'))
->rules('required|allow[htm,html]');
$form->dropdown('csv_template')->label(url_lang::lang('texts.CSV file template'))->options($arr_templates);
$form->upload('listing', TRUE)->label(url_lang::lang('texts.File with bank transfer listing'))->rules('required');
$form->submit(url_lang::lang('texts.Submit'));
special::required_forge_style($form, ' *', 'required');
// validation
if($form->validate())
{
if ($form['type'] == 0)
$form_data = $form->as_array();
if ($form_data['type'] == 2)
{
$this->parse_ebank_account(null, $form->listing->value);
}
else
{
echo 'CSV import still not supported';
die();
$this->parse_csv_file($id, $form_data['csv_template'], $form->listing->value);
}
}
else
......
$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()
{
$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->suppliers = ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$suppliers);
$this->member_fees = ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$member_fees);
$this->operating = ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$operating);
if (!$suppliers->id || !$member_fees->id || !$operating->id)
throw new Kohana_User_Exception('Kritická chyba', 'V DB chybí účet member_fees, suppliers nebo operating');
}
/**
* @author Jiri Svitak
* Function parses csv file with bank listing.
* It uses predefined bank template to identify columns in csv file.
* @param $bank_account_id
* @param $bank_template_id
* @return unknown_type
*/
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();
}
/**
* @author Tomas Dulik
freenetis/trunk/kohana/application/upgrade_sql/upgrade_sql.php
// array of sql queries that upgrade database
$upgrade_sql[get_SVN_rev()] = array(
"ALTER TABLE `streets` CHANGE `street` `street` VARCHAR( 30 ) NOT NULL ",
"ALTER TABLE `bank_templates` CHANGE `bank_name` `template_name` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL ",
"ALTER TABLE `bank_templates`
CHANGE `bank_code` `bank_code` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `account_name` `account_name` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `account_number` `account_number` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `constant_symbol` `constant_symbol` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `variable_symbol` `variable_symbol` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,
CHANGE `specific_symbol` `specific_symbol` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `counteraccount_name` `counteraccount_name` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `counteraccount_number` `counteraccount_number` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,
CHANGE `counteraccount_bank_code` `counteraccount_bank_code` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,
CHANGE `text` `text` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `amount` `amount` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `datetime` `datetime` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL"
ADD `item_separator` VARCHAR( 1 ) NOT NULL AFTER `template_name` ,
ADD `string_separator` VARCHAR( 1 ) NOT NULL AFTER `item_separator` ,
ADD `expenditure_earning` VARCHAR( 30 ) NULL DEFAULT NULL AFTER `amount` ,
ADD `value_for_earning` VARCHAR( 10 ) NULL DEFAULT NULL AFTER `expenditure_earning` "
);
?>
freenetis/trunk/kohana/application/upgrade_sql/upgrade_sql_424.php
<?php
$upgrade_sql[424] = array(
"ALTER TABLE `streets` CHANGE `street` `street` VARCHAR( 30 ) NOT NULL ",
"ALTER TABLE `bank_templates` CHANGE `bank_name` `template_name` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL ",
"ALTER TABLE `bank_templates`
CHANGE `bank_code` `bank_code` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `account_name` `account_name` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `account_number` `account_number` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `constant_symbol` `constant_symbol` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `variable_symbol` `variable_symbol` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,
CHANGE `specific_symbol` `specific_symbol` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `counteraccount_name` `counteraccount_name` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `counteraccount_number` `counteraccount_number` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,
CHANGE `counteraccount_bank_code` `counteraccount_bank_code` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,
CHANGE `text` `text` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `amount` `amount` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL,
CHANGE `datetime` `datetime` VARCHAR(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NULL DEFAULT NULL"
);
?>
freenetis/trunk/kohana/application/libraries/MY_Controller.php
*/
public function error($message, $content = NULL)
{
switch ($message)
{
case ACCESS:
$message = url_lang::lang('states.Access denied');
$this->showbox( $message, $this->ICON_ERROR, $content);
break;
case EMAIL:
$message = url_lang::lang('states.Failed to send e-mail').'<br />'.url_lang::lang('states.Please check settings.');
$this->showbox( $message, $this->ICON_ERROR, $content);
break;
case DATABASE:
$message = url_lang::lang('states.Failed to connect to database').'<br />'.url_lang::lang('states.Please check settings.');
$this->showbox($message, $this->ICON_ERROR, $content);
break;
case RECORD:
$message = url_lang::lang('states.This record does not exist');
$this->showbox( $message, $this->ICON_ERROR, $content);
break;
case PAGE:
$message = url_lang::lang('states.Page not found');
$this->showbox( $message, $this->ICON_ERROR, $content);
}
switch ($message)
{
case ACCESS:
$message = url_lang::lang('states.Access denied');
$this->showbox( $message, $this->ICON_ERROR, $content);
break;
case EMAIL:
$message = url_lang::lang('states.Failed to send e-mail').'<br />'.url_lang::lang('states.Please check settings.');
$this->showbox( $message, $this->ICON_ERROR, $content);
break;
case DATABASE:
$message = url_lang::lang('states.Failed to connect to database').'<br />'.url_lang::lang('states.Please check settings.');
$this->showbox($message, $this->ICON_ERROR, $content);
break;
case RECORD:
$message = url_lang::lang('states.This record does not exist');
$this->showbox( $message, $this->ICON_ERROR, $content);
break;
case PAGE:
$message = url_lang::lang('states.Page not found');
$this->showbox( $message, $this->ICON_ERROR, $content);
break;
}
}
/**
......
$myMenu .= '<li>'.html::anchor(url_lang::base().'devices/show_by_user/'.$this->session->get('user_id'), url_lang::lang('texts.My devices')).'</li>';
if ($this->acl_check_2D('menu', 'my_works'))
$myMenu .= '<li>'.html::anchor(url_lang::base().'works/show_by_user/'.$this->session->get('user_id'), url_lang::lang('texts.My works')).'</li>';
$myMenu .= '<li>'.html::anchor(url_lang::base().'redirect/ip_info/', url_lang::lang('texts.My IP address')).'</li>';
$myMenu .= ' </ul>
</li>';
freenetis/trunk/kohana/application/views/members/show.php
$links[] = html::anchor(url_lang::base().'members/edit/'.$member_data->member_id,url_lang::lang('texts.Edit member'));
if ($this->acl_check_view('Accounts_Controller', 'transfers', $member_data->member_id) && $member_data->member_id <> 1)
$links[] = html::anchor(url_lang::base().'transfers/show_by_member/'.$member_data->member_id,url_lang::lang('texts.Show his transfers'));
$links[] = html::anchor(url_lang::base().'redirect/ip_info/', url_lang::lang('texts.My IP address'));
if ($member_data->member_id != 1 && $member_data->entrance_fee_left != 0 && $this->acl_check_edit('Members_Controller', 'en_fee_left', $member_data->member_id))
$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').'\')'));
echo implode (' | ', $links)
freenetis/trunk/kohana/application/views/bank_templates_show.php
<th><?php echo url_lang::lang('texts.Template name') ?></th>
<td><?php echo $template->template_name ?></td>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Item separator') ?></th>
<td><?php echo $template->item_separator ?></td>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.String separator') ?></th>
<td><?php echo $template->string_separator ?></td>
</tr>
</table>
<br />
<table class="extended">
......
<td><?php echo $template->amount ?></td>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Expenditure-earning') ?></th>
<td><?php echo $template->expenditure_earning ?></td>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Value for earning') ?></th>
<td><?php echo $template->value_for_earning ?></td>
</tr>
<tr>
<th><?php echo url_lang::lang('texts.Date and time') ?></th>
<td><?php echo $template->datetime ?></td>
</tr>

Také k dispozici: Unified diff