Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 326

Přidáno uživatelem Michal Kliment před více než 15 roky(ů)

Dalsi zmeny na pridavani polozek faktur.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php
'add new invoice' => 'Přidat novou fakturu',
'add new invoice item' => 'Přidat novou položku faktury',
'add new ip address' => 'Přidat novou IP adresu',
'add new items' => 'Přidat nové položky',
'add new member' => 'Přidat nového člena',
'add new port' => 'Přidat nový port',
'add new project account' => 'Přidat nový projektový účet',
freenetis/trunk/kohana/application/controllers/invoice_items.php
/**
* @author Michal Kliment
* Add nee item to invoice
* @param $invoice_id
* Adds new invoice items (more than one)
* @param $invoice_id id of invoice which belongs to added items
* @param $item_count count of items to addd
*/
function add($invoice_id = NULL, $item_count = 1)
{
......
$invoice_model = new Invoice_Model();
$invoices = $invoice_model->find_all_by_id($invoice_id);
// if invoice doesn't exist redirects to list of all invoices
if (!count($invoices)) url::redirect(url_lang::base().'invoices/show_all');
// transforms array of objects to classic array
$arr_invoices = arr::from_objects($invoices, 'invoice_nr');
// creates form
......
$this->form->input('price_0')->label(url_lang::lang('texts.Price').':')->rules('length[1,40]|valid_numeric');
$this->form->input('price_vat_0')->label(url_lang::lang('texts.Price vat').':')->rules('length[1,40]|valid_numeric')->callback(array($this,'valid_prices'));
// next, only optional, with javascript function
for ($i=1;$i<$item_count;$i++)
{
$this->form->group('')->label(url_lang::lang('texts.Item number').' '.($i+1).' - '.url_lang::lang('texts.optional'));
......
if ($this->form->validate())
{
$form_data = $this->form->as_array();
// counter of successfully saved items
$count_saved = 0;
for ($i=0;$i<$item_count;$i++)
{
// if (inore checkbox has been posted AND it has not been checked (optional items)) OR inore checkbox has not been posted (first, required item)
if ((isset($form_data['ignore_'.$i]) && !$form_data['ignore_'.$i]) || !isset($form_data['ignore_'.$i]))
{
// creates new Invoice
// creates new invoice item
$invoice_item = new Invoice_item_Model();
$invoice_item->invoice_id = $form_data['invoice_id'];
$invoice_item->name = $form_data['name_'.$i];
......
$invoice_item->price = (double) $form_data['price_'.$i];
$invoice_item->price_vat = (double) $form_data['price_vat_'.$i];
// if price/price_vat is null, counts it from price_vat/price
if (!$invoice_item->price || !$invoice_item->price_vat)
{
$invoice = new Invoice_Model($invoice_id);
......
$invoice_item->price = round($invoice_item->price_vat / $vat,2);
}
}
// success
if ($invoice_item->save()) $count_saved++;
}
}
// succes
if ($invoice_item->save())
if ($count_saved)
{
$this->session->set_flash('message', $count_saved.' '.url_lang::lang('texts.item(s) have been successfully added.'));
}
freenetis/trunk/kohana/application/controllers/invoices.php
$invoice_item_model = new Invoice_item_Model();
$invoice_items = $invoice_item_model->where('invoice_id',$invoice->id)->find_all();
// redirect to adding new invoice items
if ($_POST)
{
url::redirect(url_lang::base().'invoice_items/add/'.$invoice_id.'/'. (int) $_POST['item_count']);
}
// create grid
$grid = new Grid(url_lang::base().'devices', NULL, array(
'use_paginator' => false,
......
));
// access control
if ($this->acl_check_new('Accounts_Controller','invoices'))
$grid->add_new_button(url_lang::base().'invoice_items/add/'.$invoice->id, url_lang::lang('texts.Add new invoice item'));
//if ($this->acl_check_new('Accounts_Controller','invoices'))
// $grid->add_new_button(url_lang::base().'invoice_items/add/'.$invoice->id, url_lang::lang('texts.Add new invoice item'));
$grid->order_field('id')->label(url_lang::lang('texts.Id'));
$grid->order_field('name')->label(url_lang::lang('texts.Name'));
freenetis/trunk/kohana/application/views/invoices/show.php
</table><br />
<h3><?php echo url_lang::lang('texts.Invoice items') ?></h3>
| <?php echo url_lang::lang('texts.Add new items').':' ?>
<?php echo form::open(url_lang::base().'invoices/show/'.$invoice->id, array('style' => 'display: inline')) ?>
<?php echo form::input('item_count','1',' style="width: 35px"') ?>
<?php echo form::submit('submit', url_lang::lang('texts.Add'), ' class=submit style="width: 50px"') ?>
<?php echo form::close() ?> |
<br /><br />
<?php echo $grid ?>

Také k dispozici: Unified diff