Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1933

Přidáno uživatelem Jan Dubina před více než 11 roky(ů)

Upravy:
fixes #570: Moznost povoleni/zakazani preruseni clenstvi
fixes #571: Chybi knihovny spojene s fakturami

Zobrazit rozdíly:

freenetis/branches/1.1/application/helpers/guid.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Helper for generating GUIDs
*
* @author Jan Dubina
*/
class guid {
public static function getGUID() {
mt_srand((double)microtime()*10000);
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
return $uuid;
}
}
?>
freenetis/branches/1.1/application/helpers/address.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Helper for working with addresses
*
* @author Jan Dubina
*/
class address {
/**
* Splits street to street name and street number
*
* @author Jan Dubina
* @param string street
* @return array
*/
public static function street_split($street_arg)
{
$street_arr = explode (' ', $street_arg);
$street = array();
$street_number = '';
foreach ($street_arr as $str)
{
if (preg_match("/^(\d+).*/", $str) === 0)
$street[] = $str;
else
{
$street_number = $str;
break;
}
}
$street = implode(' ', $street);
return array(
'street' => $street,
'street_number' => $street_number
);
}
/**
* Joins street name and street number
*
* @author Jan Dubina
* @param string street
* @param string street number
* @return string
*/
public static function street_join($street, $street_number)
{
if (!empty($street) && !empty($street_number))
return $street . ' ' . $street_number;
elseif (!empty($street))
return $street;
elseif (!empty($street_number))
return $street_number;
else
return '';
}
}
?>
freenetis/branches/1.1/application/libraries/dbase/Dbase_Column.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* DBase column
*
* @author Jan Dubina
*
*/
class Dbase_Column {
//DBase field types
const DBFFIELD_TYPE_CHAR = 'C';
const DBFFIELD_TYPE_NUMERIC = 'N';
const DBFFIELD_TYPE_FLOATING = 'F';
const DBFFIELD_TYPE_DATE = 'D';
const DBFFIELD_TYPE_LOGICAL = 'L';
//Maximum field name length
const DBFIELD_MAX_NAME_LENGTH = 10;
protected $name;
protected $type;
protected $length;
protected $precision;
protected $trans = array(
'ä'=>'a',
'Ä'=>'A',
'á'=>'a',
'Á'=>'A',
'à'=>'a',
'À'=>'A',
'ã'=>'a',
'Ã'=>'A',
'â'=>'a',
'Â'=>'A',
'č'=>'c',
'Č'=>'C',
'ć'=>'c',
'Ć'=>'C',
'ď'=>'d',
'Ď'=>'D',
'ě'=>'e',
'Ě'=>'E',
'é'=>'e',
'É'=>'E',
'ë'=>'e',
'Ë'=>'E',
'è'=>'e',
'È'=>'E',
'ê'=>'e',
'Ê'=>'E',
'í'=>'i',
'Í'=>'I',
'ï'=>'i',
'Ï'=>'I',
'ì'=>'i',
'Ì'=>'I',
'î'=>'i',
'Î'=>'I',
'ľ'=>'l',
'Ľ'=>'L',
'ĺ'=>'l',
'Ĺ'=>'L',
'ń'=>'n',
'Ń'=>'N',
'ň'=>'n',
'Ň'=>'N',
'ñ'=>'n',
'Ñ'=>'N',
'ó'=>'o',
'Ó'=>'O',
'ö'=>'o',
'Ö'=>'O',
'ô'=>'o',
'Ô'=>'O',
'ò'=>'o',
'Ò'=>'O',
'õ'=>'o',
'Õ'=>'O',
'ő'=>'o',
'Ő'=>'O',
'ř'=>'r',
'Ř'=>'R',
'ŕ'=>'r',
'Ŕ'=>'R',
'š'=>'s',
'Š'=>'S',
'ś'=>'s',
'Ś'=>'S',
'ť'=>'t',
'Ť'=>'T',
'ú'=>'u',
'Ú'=>'U',
'ů'=>'u',
'Ů'=>'U',
'ü'=>'u',
'Ü'=>'U',
'ù'=>'u',
'Ù'=>'U',
'ũ'=>'u',
'Ũ'=>'U',
'û'=>'u',
'Û'=>'U',
'ý'=>'y',
'Ý'=>'Y',
'ž'=>'z',
'Ž'=>'Z',
'ź'=>'z',
'Ź'=>'Z'
);
function __construct($name, $type, $length = 1, $precision = 0) {
if ($this->check_name($name))
$this->name = $name;
else
throw new Exception('Invalid column name.');
$this->type = $type;
$this->precision = $precision;
$this->length = $length;
}
function get_length() {
switch ($this->type) {
//Boolean - length 1B
case self::DBFFIELD_TYPE_LOGICAL:
return 1;
//Date - length 8B (8 digits, YYYYMMDD format)
case self::DBFFIELD_TYPE_DATE:
return 8;
default:
return $this->length;
}
}
function get_name() {
return $this->name;
}
function get_name_padded() {
return str_pad(iconv(Dbase_Table::ENC_UTF, Dbase_Table::ENC_CP852, $this->name),
self::DBFIELD_MAX_NAME_LENGTH + 1, chr(0));
}
function get_type() {
return $this->type;
}
function get_precision() {
return $this->precision;
}
protected function check_name($name) {
$name2 = iconv(Dbase_Table::ENC_UTF, Dbase_Table::ENC_CP852, $name);
if (strlen($name2) > self::DBFIELD_MAX_NAME_LENGTH)
return false;
$name = strtr($name, $this->trans);
return preg_match ("/^[a-zA-Z0-9_]+$/", $name);
}
}
?>
freenetis/branches/1.1/application/libraries/dbase/Dbase_Table.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreenetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* DBase table
*
* @author Jan Dubina
*
*/
class Dbase_Table {
const ENC_UTF = 'UTF-8';
const ENC_CP852 = 'CP852';
protected $file;
protected $filesize;
protected $filename;
protected $columns;
protected $records;
protected $num_rows; //number of records
protected $b_header; //number of bytes in header
protected $b_record; //number of bytes in record
protected $version; //Dbase version
protected $last_update; //date of last update
protected $mdx_flag; //MDX file exists
protected $lang_id; //language driver id
protected $num_col; //number of columns
function create_table($columns, $records) {
$this->columns = array();
if ($columns && is_array($columns) &&
$records && is_array($records))
foreach ($columns as $column) {
if ($column && is_array($column) && count($column)>1)
$this->columns[] = new Dbase_Column($column[0],
$column[1],
isset($column[2]) ? $column[2] : 0,
isset($column[3]) ? $column[3] : 0
);
else
throw new Exception('Wrong arguments.');
}
else
throw new Exception('Wrong arguments.');
//flag preceding every record
$this->b_record = 1;
foreach ($this->columns as $column)
$this->b_record += $column->get_length();
$this->file = fopen('php://temp', 'w');
$this->records = $records;
$this->version = 3;
$this->num_rows = count($records);
//33B dbf header length + field terminator, 32B field descriptor length
$this->b_header = 33 + 32 * count($columns);
$this->create_header();
$this->write_records();
$contents = $this->get_file_contents();
fclose($this->file);
return $contents;
}
function read_table($filename) {
$this->file = fopen($filename, 'r');
if (!$this->file)
throw new Exception('Cannot open file.');
$this->filesize = filesize($filename);
$this->filename = $filename;
$this->read_header();
$records = $this->read_records();
fclose($this->file);
return $records;
}
protected function read_header() {
$this->version = $this->read_char(); //version
$this->last_update = $this->read_date(); //date of last update
$this->num_rows = $this->read_int(); //number of records
$this->b_header = $this->read_short(); //number of bytes in header
//filesize is smaller than header size
if ($this->filesize < $this->b_header)
throw new Exception('Wrong file format.');
$this->b_record = $this->read_short(); //number of bytes in record
$this->read_bytes(2); //reserved
//encryption flag + flag indicating incomplete transaction
if ($this->read_char() != 0 || $this->read_char() != 0)
throw new Exception('Wrong file format.');
$this->read_bytes(12); //reserved
$this->mdx_flag = $this->read_bytes(); //mdx flag
$this->lang_id = $this->read_bytes(); //language driver id
$this->read_bytes(2); //reserver
$dbf_size = $this->b_header + $this->b_record * $this->num_rows + 1;
//checks if filesize is correct
if ($this->filesize != $dbf_size)
throw new Exception('Wrong file format.');
$this->num_col = ($this->b_header - 33) / 32;
//reads field descriptor bytes
$this->columns = array();
for ($i = 0; $i < $this->num_col; $i++) {
$name = $this->read_column_name();
$this->read_bytes();
$type = $this->read_bytes();
$this->read_bytes(4);
$length = $this->read_char();
$precision = $this->read_char();
$this->read_bytes(14);
$column = new Dbase_Column($name, $type, $length, $precision);
$this->columns[] = $column;
}
//field terminator 0Dh
if ($this->read_char() != 13)
throw new Exception('Wrong file format.');
}
protected function create_header() {
$this->write_char($this->version); //version
$this->write_date(time()); //last update
$this->write_int($this->num_rows); //number of rows
$this->write_short($this->b_header); //number of bytes in header
$this->write_short($this->b_record); //number of bytes in record
$this->write_n_bytes(chr(0), 2); //reserved
$this->write_char(0); //indication of incomplete trasaction
$this->write_char(0); //encryption flag;
$this->write_n_bytes(chr(0), 12); //reserved for multi-user processing
$this->write_char(0); //no MDX file exists
$this->write_char(0); //language driver id
$this->write_n_bytes(chr(0), 2); //reserved
$unique = array();
//field description bytes
foreach ($this->columns as $column) {
if (!in_array($column->get_name(), $unique))
$unique[] = $column->get_name();
else
throw new Exception('Column names must be unique.');
$this->write_bytes($column->get_name_padded()); //zero filled column name
$this->write_bytes($column->get_type()); //type
$this->write_n_bytes(chr(0), 4); //reserved
$this->write_char($column->get_length()); //collumn length in binary
$this->write_char($column->get_precision()); //decimal count in binary
$this->write_n_bytes(chr(0), 2); //reserved
$this->write_char(0); //work area ID
$this->write_n_bytes(chr(0), 10); //reserved
$this->write_char(0); //field not indexed
}
$this->write_char(13); //field terminator 0Dh
}
protected function read_records() {
$records = array();
for ($i = 0; $i < $this->num_rows; $i++) {
$record = array();
//every record starts with space (20h)
if ($this->read_bytes() != ' ')
throw new Exception('Wrong file format.');
foreach ($this->columns as $column) {
$value = null;
switch ($column->get_type()) {
case Dbase_Column::DBFFIELD_TYPE_CHAR:
$value = $this->read_string($column->get_length());
break;
case Dbase_Column::DBFFIELD_TYPE_DATE:
$value = $this->read_date_long();
break;
case Dbase_Column::DBFFIELD_TYPE_LOGICAL:
$bool = strtolower($this->read_bytes());
if ($bool == 1 || $bool == 't' || $bool == 'y')
$value = true;
elseif ($bool == 0 || $bool == 'f' || $bool == 'n')
$value = false;
break;
case Dbase_Column::DBFFIELD_TYPE_NUMERIC:
case Dbase_Column::DBFFIELD_TYPE_FLOATING:
$value = floatval($this->read_bytes($column->get_length()));
default:
break;
}
$record[$column->get_name()] = $value;
}
$records[] = $record;
}
//eof 1Ah
if ($this->read_char() != 26)
throw new Exception('Wrong file format.');
return $records;
}
protected function write_records() {
foreach ($this->records as $record) {
//space 20h preceding record
$this->write_char(32);
foreach ($this->columns as $column) {
if (isset($record[$column->get_name()]))
switch ($column->get_type()) {
case Dbase_Column::DBFFIELD_TYPE_CHAR:
$this->write_string($record[$column->get_name()],
$column->get_length());
break;
case Dbase_Column::DBFFIELD_TYPE_DATE:
$this->write_date_long($this->my_check_date($record[$column->get_name()]) ?
$record[$column->get_name()] :
'0000-00-00');
break;
case Dbase_Column::DBFFIELD_TYPE_LOGICAL:
$this->write_bytes($record[$column->get_name()] ? 'T' : 'F');
break;
case Dbase_Column::DBFFIELD_TYPE_NUMERIC:
case Dbase_Column::DBFFIELD_TYPE_FLOATING:
$this->write_number($record[$column->get_name()],
$column->get_length(),
$column->get_precision());
break;
default:
break;
}
else
$this->write_n_bytes (chr(32), $column->get_length ());
}
}
//eof 1Ah
$this->write_char(26);
}
protected function get_file_contents() {
rewind($this->file);
return stream_get_contents($this->file);
}
protected function my_check_date($date) {
@list($y,$m,$d)=explode("-",$date);
if (is_numeric($y) && is_numeric($m) && is_numeric($d))
{
return checkdate($m,$d,$y);
}
return false;
}
protected function write_number($number, $length, $precision) {
$n = str_pad(number_format($number, $precision, '.', ''), $length, ' ', STR_PAD_LEFT);
return fwrite($this->file, $n);
}
protected function write_string($string, $length) {
$s = str_pad(iconv(self::ENC_UTF, self::ENC_CP852, $string), $length, ' ');
return fwrite($this->file, $s);
}
protected function write_bytes($b) {
return fwrite($this->file, $b);
}
protected function write_n_bytes($b, $n = 1) {
$r = 0;
if ($n > 1) {
for ($i = 0; $i < $n; $i++)
$r += fwrite($this->file, $b);
return $r;
} else
return false;
}
protected function write_date($tstamp) {
$d = getdate($tstamp);
return $this->write_char($d['year'] % 100) +
$this->write_char($d['mon']) +
$this->write_char($d['mday']);
}
protected function write_date_long($date) {
$tstamp = strtotime($date);
$date_arr = str_split(date('Ymd',$tstamp));
$r = 0;
foreach ($date_arr as $c)
$r += $this->write_bytes($c);
return $r;
}
protected function write_short($short) {
$b = pack('S', $short);
return $this->write_bytes($b);
}
protected function write_int($int) {
$b = pack('I', $int);
return $this->write_bytes($b);
}
protected function write_char($char) {
$b = pack('C', $char);
return $this->write_bytes($b);
}
protected function read_bytes($length = 1) {
return fread($this->file, $length);
}
protected function read_char() {
$char = unpack('C', $this->read_bytes(1));
return $char[1];
}
protected function read_short() {
$short = unpack('S', $this->read_bytes(2));
return $short[1];
}
protected function read_int() {
$int = unpack('I', $this->read_bytes(4));
return $int[1];
}
protected function read_string($length) {
return iconv(Dbase_Table::ENC_CP852, Dbase_Table::ENC_UTF, rtrim($this->read_bytes($length), ' '));
}
protected function read_column_name() {
return iconv(Dbase_Table::ENC_CP852, Dbase_Table::ENC_UTF, rtrim($this->read_bytes(Dbase_Column::DBFIELD_MAX_NAME_LENGTH), chr(0)));
}
protected function read_date() {
$y = unpack('C',$this->read_bytes());
$m = unpack('C',$this->read_bytes());
$d = unpack('C',$this->read_bytes());
return date('Y-m-d', mktime(0, 0, 0, $m[1], $d[1],
$y[1]>69 ? 1900+$y[1] : 2000+$y[1]));
}
protected function read_date_long() {
$y = intval($this->read_bytes(4));
$m = intval($this->read_bytes(2));
$d = intval($this->read_bytes(2));
$tstamp = mktime(0,0,0,$m,$d,$y);
if ($tstamp == false)
$tstamp = 0;
return date('Y-m-d', $tstamp);
}
}
?>
freenetis/branches/1.1/application/views/export/export_eform.php
<?php
echo '<?xml version="' . $const['version'] .
'" encoding="' . $const['encoding'] . '"?>';
echo '<eform version="' . $const['eform_version'] . '">';
echo '<invoice version="' . $const['invoice_version'] . '">';
$con_sym = !empty($invoice->con_sym) ? $invoice->con_sym : '';
$var_sym = !empty($invoice->var_sym) ? $invoice->var_sym : '';
$order_nr = !empty($invoice->order_nr) ? $invoice->order_nr : '';
echo '<documenttax number="' . $invoice->invoice_nr .
'" date="' . $invoice->date_inv .
'" datetax="' . $invoice->date_vat .
'" datedue="' . $invoice->date_due .
'" symvar="' . $var_sym .
'" symconst="' . $con_sym .
'" numberorder="' . $order_nr .
'" >' . iconv($enc['in'], $enc['out'], $invoice->note) . '</documenttax>';
$price_none = 0;
$price_low = 0;
$price_low_vat = 0;
$price_high = 0;
$price_high_vat = 0;
$vat_rate = 0;
foreach ($invoice->invoice_items as $item) {
$item_price = $item->price * $item->quantity;
$item_price_vat = $item->price * $item->quantity * (1 + $item->vat);
$vat_value = intval($item->vat * 1000);
if (array_key_exists($vat_value, $vat_var['export'])) {
$vat_rate = $vat_var['export'][$vat_value];
switch ($vat_rate) {
case 'low':
$price_low += $item_price;
$price_low_vat += $item_price_vat;
break;
case 'high':
$price_high += $item_price;
$price_high_vat += $item_price_vat;
break;
default:
$price_none += $item_price;
break;
}
}
else
$price_none += $item_price;
$vat = $invoice->vat ? 'yes' : 'no';
echo '<invoiceitem code="' . iconv($enc['in'], $enc['out'], $item->code) .
'" quantity="' . iconv($enc['in'], $enc['out'], $item->quantity) .
'" price="' . round($item->price, 2) .
'" payvat="' . $vat .
'" ratevat="' . iconv($enc['in'], $enc['out'], $vat_rate) .
'" pricesum="' . round($item_price, 2) .
'" pricesumvat="' . round($item_price_vat, 2) .
'">' . iconv($enc['in'], $enc['out'], $item->name) . '</invoiceitem>';
}
echo '<pricestax pricehigh="' . round($price_high, 2) .
'" pricehighvat="' . round($price_high_vat, 2) .
'" pricelow="' . round($price_low, 2) .
'" pricelowvat="' . round($price_low_vat, 2) .
'" pricenone="' . round($price_none, 2) .
'" priceround="' . round(ceil($price_none + $price_low_vat + $price_high_vat) -
($price_none + $price_low_vat + $price_high_vat), 2) .
'" roundingdocument="up2one"' .
' priceRoundSum="' . ceil($price_none + $price_low + $price_high) .
'" priceRoundSumVAT="' . ceil($price_none + $price_low_vat + $price_high_vat) .
'">';
?>
<supplier>
<?php if (!empty($supplier)) { ?>
<company></company>
<name><?php echo iconv($enc['in'], $enc['out'], $supplier->name) ?></name>
<street><?php
$street = address::street_join(!empty($supplier->address_point->street_id) ?
$supplier->address_point->street->street : '',
$supplier->address_point->street_number);
echo iconv($enc['in'], $enc['out'], $street); ?></street>
<city><?php echo iconv($enc['in'], $enc['out'], $supplier->address_point->town->town) ?></city>
<psc><?php echo $supplier->address_point->town->zip_code ?></psc>
<ico><?php echo $supplier->organization_identifier ?></ico>
<dic></dic>
<?php
$phone = null;
$email = null;
$contact_model = new Contact_Model();
$contacts = $contact_model->find_all_users_contacts($supplier->id);
foreach ($contacts as $contact) {
if ( $contact->type == Contact_Model::TYPE_PHONE )
$phone = $contact->value;
if ( $contact->type == Contact_Model::TYPE_EMAIL )
$email = $contact->value;
} ?>
<tel><?php echo $phone ?></tel>
<fax></fax>
<email><?php echo $email ?></email>
<remark></remark>
<?php } else { ?>
<company><?php echo iconv($enc['in'], $enc['out'], $invoice->partner_company) ?></company>
<name><?php echo iconv($enc['in'], $enc['out'], $invoice->partner_name) ?></name>
<street><?php echo iconv($enc['in'], $enc['out'],
address::street_join($invoice->partner_street, $invoice->partner_street_number)) ?></street>
<city><?php echo iconv($enc['in'], $enc['out'], $invoice->partner_town) ?></city>
<psc><?php echo $invoice->partner_zip_code ?></psc>
<ico><?php echo $invoice->organization_identifier ?></ico>
<dic></dic>
<tel><?php echo $invoice->phone_number ?></tel>
<fax></fax>
<email><?php echo $invoice->email ?></email>
<remark></remark>
<?php } ?>
</supplier>
<customer>
<?php if (!empty($customer)) { ?>
<company></company>
<name><?php echo iconv($enc['in'], $enc['out'], $customer->name) ?></name>
<street><?php
$street = address::street_join(!empty($customer->address_point->street_id) ?
$customer->address_point->street->street : '',
$customer->address_point->street_number);
echo iconv($enc['in'], $enc['out'], $street); ?></street>
<city><?php echo iconv($enc['in'], $enc['out'], $customer->address_point->town->town) ?></city>
<psc><?php echo $customer->address_point->town->zip_code ?></psc>
<ico><?php echo $customer->organization_identifier ?></ico>
<dic></dic>
<?php
$phone = null;
$email = null;
$contact_model = new Contact_Model();
$contacts = $contact_model->find_all_users_contacts($customer->id);
foreach ($contacts as $contact) {
if ( $contact->type == Contact_Model::TYPE_PHONE )
$phone = $contact->value;
if ( $contact->type == Contact_Model::TYPE_EMAIL )
$email = $contact->value;
} ?>
<tel><?php echo $phone ?></tel>
<fax></fax>
<email><?php echo $email ?></email>
<remark></remark>
<?php } else { ?>
<company><?php echo iconv($enc['in'], $enc['out'], $invoice->partner_company) ?></company>
<name><?php echo iconv($enc['in'], $enc['out'], $invoice->partner_name) ?></name>
<street><?php echo iconv($enc['in'], $enc['out'],
address::street_join($invoice->partner_street, $invoice->partner_street_number)) ?></street>
<city><?php echo iconv($enc['in'], $enc['out'], $invoice->partner_town) ?></city>
<psc><?php echo $invoice->partner_zip_code ?></psc>
<ico><?php echo $invoice->organization_identifier ?></ico>
<dic></dic>
<tel><?php echo $invoice->phone_number ?></tel>
<fax></fax>
<email><?php echo $invoice->email ?></email>
<remark></remark>
<?php } ?>
</customer>
<?php
$account_nr = null;
$bank_code = null;
if (!empty($supplier)) {
if ($supplier->bank_accounts->count() != 0 ) {
$bank_accounts = $supplier->bank_accounts->as_array();
$account_nr = $bank_accounts[0]->account_nr;
$bank_code = $bank_accounts[0]->bank_nr;
}
} elseif (!empty($invoice->account_nr))
@list($account_nr, $bank_code) = explode('/', $invoice->account_nr);
?>
<?php
$pay_vat = $invoice->vat ? 'yes' : 'no';
echo '<payment paytype="draft"' .
' payvat="' . $pay_vat .
'" accountno="' . $account_nr .
'" bankcode="' . $bank_code .
'"></payment>';
?>
</pricestax>
</invoice>
</eform>
freenetis/branches/1.1/application/views/export/export_xml.php
<?php
echo '<?xml version="' . $const['version'] . '" encoding="' . $const['encoding'] . '"?>';
echo '<dat:dataPack id="' . $const['id'] .
'" ico="' . $const['org_id'] .
'" application="' . $const['application'] .
'" version="' . $const['invoice_ver'] .
'" note="Imported from ' . $const['application'] .
'" xmlns:dat="' . $const['data_ns'] .
'" xmlns:inv="' . $const['invoice_ns'] .
'" xmlns:typ="' . $const['type_ns'] .
'" >';
?>
<?php
foreach ($invoices as $invoice) { ?>
<dat:dataPackItem <?php echo 'id="DP' . $invoice->invoice_nr . '" version="' . $const['invoice_ver'] . '" '?>>
<inv:invoice <?php echo 'version="' . $const['invoice_ver'] . '" '?>>
<inv:invoiceHeader>
<inv:invoiceType><?php echo $invoice->invoice_type ?
'receivedInvoice' :
'issuedInvoice' ?></inv:invoiceType>
<inv:number>
<typ:numberRequested><?php echo $invoice->invoice_nr ?></typ:numberRequested>
</inv:number>
<inv:symVar><?php if(!empty($invoice->var_sym))echo $invoice->var_sym; ?></inv:symVar>
<inv:date><?php echo $invoice->date_inv ?></inv:date>
<inv:dateTax><?php echo $invoice->date_vat ?></inv:dateTax>
<inv:dateDue><?php echo $invoice->date_due ?></inv:dateDue>
<inv:partnerIdentity>
<typ:address>
<typ:company><?php echo $invoice->company ?></typ:company>
<typ:name><?php echo $invoice->partner ?></typ:name>
<typ:city><?php echo $invoice->town ?></typ:city>
<typ:street><?php echo address::street_join($invoice->street, $invoice->street_number) ?></typ:street>
<typ:zip><?php echo $invoice->zip_code ?></typ:zip>
<typ:ico><?php echo $invoice->organization_identifier ?></typ:ico>
<typ:country>
<typ:ids><?php echo $invoice->country ?></typ:ids>
</typ:country>
<typ:phone><?php echo $invoice->phone ?></typ:phone>
<typ:email><?php echo $invoice->email ?></typ:email>
</typ:address>
</inv:partnerIdentity>
<inv:numberOrder><?php if(!empty($invoice->order_nr)) echo $invoice->order_nr; ?></inv:numberOrder>
<inv:symConst><?php if(!empty($invoice->con_sym)) echo $invoice->con_sym; ?></inv:symConst>
<?php
$account_nr = null;
$bank_code = null;
if (!empty($invoice->account_nr)) {
@list($account_nr, $bank_code) =
explode('/', $invoice->account_nr);
?>
<inv:account>
<typ:accountNo><?php echo $account_nr ?></typ:accountNo>
<typ:bankCode><?php echo $bank_code ?></typ:bankCode>
</inv:account>
<?php } ?>
<inv:note><?php echo $invoice->note ?></inv:note>
</inv:invoiceHeader>
<inv:invoiceDetail>
<?php
$price_none = 0;
$price_low = 0;
$price_low_vat = 0;
$price_high = 0;
$price_high_vat = 0;
$foreign_curr = $invoice->currency != $const['currency'];
$invoice_item_model = new Invoice_item_Model();
$invoice_items = $invoice_item_model->get_items_of_invoice($invoice->id);
$item_price = 0;
$item_price_vat = 0;
$vat_rate = 0;
foreach ($invoice_items as $item) {
$item_price = $item->quantity * $item->price;
$item_price_vat = $item->quantity * $item->price * (1 + $item->vat); ?>
<inv:invoiceItem>
<inv:text><?php echo $item->name ?></inv:text>
<inv:quantity><?php echo $item->quantity ?></inv:quantity>
<?php $vat_value = intval($item->vat * 1000);
if (array_key_exists($vat_value, $vat_var['export'])) {
$vat_rate = $vat_var['export'][$vat_value];
switch ($vat_rate) {
case 'low':
$price_low += $item_price;
$price_low_vat += $item_price_vat;
break;
case 'high':
$price_high += $item_price;
$price_high_vat += $item_price_vat;
break;
default:
$price_none += $item_price;
break;
} ?>
<inv:rateVAT><?php echo $vat_rate ?></inv:rateVAT>
<?php } else {?>
<inv:percentVAT><?php echo $item->vat * 100 ?></inv:percentVAT>
<?php }
if ($foreign_curr) {?>
<inv:foreignCurrency>
<?php } else { ?>
<inv:homeCurrency>
<?php } ?>
<typ:unitPrice><?php echo round($item->price, 2) ?></typ:unitPrice>
<typ:price><?php echo round($item_price, 2) ?></typ:price>
<typ:priceVAT><?php echo round($item_price_vat - $item_price, 2) ?></typ:priceVAT>
<typ:priceSum><?php echo round($item_price_vat, 2) ?></typ:priceSum>
<?php if ($foreign_curr) {?>
</inv:foreignCurrency>
<?php } else { ?>
</inv:homeCurrency>
<?php } ?>
<inv:code><?php echo $item->code ?></inv:code>
</inv:invoiceItem>
<?php } ?>
</inv:invoiceDetail>
<inv:invoiceSummary>
<?php if ($foreign_curr) {?>
<inv:roundingDocument>none</inv:roundingDocument>
<inv:foreignCurrency>
<typ:currency>
<typ:ids><?php echo $invoice->currency ?></typ:ids>
</typ:currency>
<typ:priceSum><?php echo round($price_high_vat + $price_low_vat + $price_none, 2) ?></typ:priceSum>
</inv:foreignCurrency>
<?php } else { ?>
<inv:roundingDocument>math2one</inv:roundingDocument>
<inv:homeCurrency>
<typ:priceNone><?php echo round($price_none, 2) ?></typ:priceNone>
<typ:priceLow><?php echo round($price_low, 2) ?></typ:priceLow>
<typ:priceLowVAT><?php echo round($price_low_vat - $price_low , 2) ?></typ:priceLowVAT>
<typ:priceLowSum><?php echo round($price_low_vat, 2) ?></typ:priceLowSum>
<typ:priceHigh><?php echo round($price_high, 2) ?></typ:priceHigh>
<typ:priceHighVAT><?php echo round($price_high_vat - $price_high, 2) ?></typ:priceHighVAT>
<typ:priceHighSum><?php echo round($price_high_vat, 2) ?></typ:priceHighSum>
<typ:round>
<typ:priceRound><?php echo round(ceil($price_none + $price_low_vat + $price_high_vat) -
($price_none + $price_low_vat + $price_high_vat), 2) ?></typ:priceRound>
</typ:round>
</inv:homeCurrency>
<?php } ?>
</inv:invoiceSummary>
</inv:invoice>
</dat:dataPackItem>
<?php } ?>
</dat:dataPack>
freenetis/branches/1.1/application/views/export/export_isdoc.php
<?php
echo '<?xml version="' . $const['version'] . '" encoding="' . $const['encoding'] . '"?>';
echo '<Invoice xmlns="' . $const['namespace'] . '" version="' . $const['isdoc_version'] . '">';
?>
<DocumentType>1</DocumentType>
<ID><?php echo $invoice->invoice_nr ?></ID>
<UUID><?php echo $const['guid'] ?></UUID>
<IssuingSystem><?php echo Settings::get('title') ?></IssuingSystem>
<IssueDate><?php echo $invoice->date_inv ?></IssueDate>
<TaxPointDate><?php echo $invoice->date_vat ?></TaxPointDate>
<VATApplicable><?php echo $invoice->vat ? 'true' : 'false' ?></VATApplicable>
<Note><?php echo $invoice->note; ?></Note>
<LocalCurrencyCode><?php echo $invoice->currency ?></LocalCurrencyCode>
<CurrRate>1</CurrRate>
<RefCurrRate>1</RefCurrRate>
<AccountingSupplierParty>
<Party>
<?php if (!empty($supplier)) { ?>
<PartyIdentification>
<ID><?php echo $supplier->organization_identifier ?></ID>
</PartyIdentification>
<PartyName>
<Name><?php echo $supplier->name ?></Name>
</PartyName>
<PostalAddress>
<StreetName><?php if (!empty($supplier->address_point->street_id))
echo $supplier->address_point->street->street; ?></StreetName>
<BuildingNumber><?php if (!empty($supplier->address_point->street_number))
echo $supplier->address_point->street_number; ?></BuildingNumber>
<CityName><?php echo $supplier->address_point->town->town ?></CityName>
<PostalZone><?php echo $supplier->address_point->town->zip_code ?></PostalZone>
<Country>
<IdentificationCode><?php echo $supplier->address_point->country
->country_iso ?></IdentificationCode>
<Name><?php echo $supplier->address_point->country->country_name ?></Name>
</Country>
</PostalAddress>
<?php if ($invoice->vat) { ?>
<PartyTaxScheme>
<CompanyID></CompanyID>
<TaxScheme>VAT</TaxScheme>
</PartyTaxScheme>
<?php } ?>
<Contact>
<?php $phone = null;
$email = null;
$contact_model = new Contact_Model();
$contacts = $contact_model->find_all_users_contacts($supplier->id);
foreach ($contacts as $contact) {
if ( $contact->type == Contact_Model::TYPE_PHONE )
$phone = $contact->value;
if ( $contact->type == Contact_Model::TYPE_EMAIL )
$email = $contact->value;
}
?>
<Telephone><?php echo $phone ?></Telephone>
<ElectronicMail><?php echo $email ?></ElectronicMail>
</Contact>
<?php } else { ?>
<PartyIdentification>
<ID><?php echo $invoice->organization_identifier; ?></ID>
</PartyIdentification>
<PartyName>
<Name><?php echo !empty($invoice->partner_company) ?
$invoice->partner_company :
$invoice->partner_name ?></Name>
</PartyName>
<PostalAddress>
<StreetName><?php echo $invoice->partner_street ?></StreetName>
<BuildingNumber><?php echo $invoice->partner_street_number ?></BuildingNumber>
<CityName><?php echo $invoice->partner_town ?></CityName>
<PostalZone><?php echo $invoice->partner_zip_code ?></PostalZone>
<Country>
<IdentificationCode></IdentificationCode>
<Name><?php echo $invoice->partner_country ?></Name>
</Country>
</PostalAddress>
<?php if ($invoice->vat) { ?>
<PartyTaxScheme>
<CompanyID></CompanyID>
<TaxScheme>VAT</TaxScheme>
</PartyTaxScheme>
<?php } ?>
<Contact>
<?php if (!empty($invoice->partner_company)) {?>
<Name><?php echo $invoice->partner_name ?></Name>
<?php } ?>
<Telephone><?php echo $invoice->phone_number ?></Telephone>
<ElectronicMail><?php echo $invoice->email ?></ElectronicMail>
</Contact>
<?php } ?>
</Party>
</AccountingSupplierParty>
<AccountingCustomerParty>
<Party>
<?php if (!empty($customer)) {?>
<PartyIdentification>
<ID><?php echo $customer->organization_identifier; ?></ID>
</PartyIdentification>
<PartyName>
<Name><?php echo $customer->name ?></Name>
</PartyName>
<PostalAddress>
<StreetName><?php if (!empty($customer->address_point->street_id))
echo $customer->address_point->street->street; ?></StreetName>
<BuildingNumber><?php if (!empty($customer->address_point->street_number))
echo $customer->address_point->street_number; ?></BuildingNumber>
<CityName><?php echo $customer->address_point->town->town ?></CityName>
<PostalZone><?php echo $customer->address_point->town->zip_code ?></PostalZone>
<Country>
<IdentificationCode><?php echo $customer->address_point->country
->country_iso ?></IdentificationCode>
<Name><?php echo $customer->address_point->country->country_name ?></Name>
</Country>
</PostalAddress>
<?php if ($invoice->vat) {?>
<PartyTaxScheme>
<CompanyID></CompanyID>
<TaxScheme>VAT</TaxScheme>
</PartyTaxScheme>
<?php } ?>
<Contact>
<?php $phone = null;
$email = null;
$contact_model = new Contact_Model();
$contacts = $contact_model->find_all_users_contacts($customer->id);
foreach ($contacts as $contact) {
if ( $contact->type == Contact_Model::TYPE_PHONE )
$phone = $contact->value;
if ( $contact->type == Contact_Model::TYPE_EMAIL )
$email = $contact->value;
}
?>
<Telephone><?php echo $phone ?></Telephone>
<ElectronicMail><?php echo $email ?></ElectronicMail>
</Contact>
<?php } else { ?>
<PartyIdentification>
<ID><?php echo $invoice->organization_identifier; ?></ID>
</PartyIdentification>
<PartyName>
<Name><?php echo !empty($invoice->partner_company) ?
$invoice->partner_company :
$invoice->partner_name ?></Name>
</PartyName>
<PostalAddress>
<StreetName><?php echo $invoice->partner_street ?></StreetName>
<BuildingNumber><?php echo $invoice->partner_street_number ?></BuildingNumber>
<CityName><?php echo $invoice->partner_town ?></CityName>
<PostalZone><?php echo $invoice->partner_zip_code ?></PostalZone>
<Country>
<IdentificationCode></IdentificationCode>
<Name><?php echo $invoice->partner_country ?></Name>
</Country>
</PostalAddress>
<?php if ($invoice->vat) {?>
<PartyTaxScheme>
<CompanyID></CompanyID>
<TaxScheme>VAT</TaxScheme>
</PartyTaxScheme>
<?php } ?>
<Contact>
<?php if (!empty($invoice->partner_company)) {?>
<Name><?php echo $invoice->partner_name ?></Name>
<?php } ?>
<Telephone><?php echo $invoice->phone_number ?></Telephone>
<ElectronicMail><?php echo $invoice->email ?></ElectronicMail>
</Contact>
<?php } ?>
</Party>
</AccountingCustomerParty>
<InvoiceLines>
<?php
$vat_cat = array();
$price = array();
$price_vat = array();
foreach ($invoice->invoice_items as $item) {
$item_price_vat = ($item->vat + 1) * $item->price;
if (!in_array($item->vat, $vat_cat)) {
$vat_cat[] = $item->vat;
$price[] = 0;
$price_vat[] = 0;
}
?>
<InvoiceLine>
<ID><?php echo $item->code ?></ID>
<InvoicedQuantity><?php echo $item->quantity ?></InvoicedQuantity>
<LineExtensionAmount><?php echo round($item->quantity * $item->price, 2) ?></LineExtensionAmount>
<LineExtensionAmountTaxInclusive><?php echo round($item->quantity * $item_price_vat, 2) ?></LineExtensionAmountTaxInclusive>
<LineExtensionTaxAmount><?php echo round($item->quantity * ($item_price_vat - $item->price), 2) ?></LineExtensionTaxAmount>
<UnitPrice><?php echo round($item->price, 2) ?></UnitPrice>
<UnitPriceTaxInclusive><?php echo round($item_price_vat, 2) ?></UnitPriceTaxInclusive>
<ClassifiedTaxCategory>
<Percent><?php echo $item->vat * 100 ?></Percent>
<VATCalculationMethod><?php echo $const['vat_method'] ?></VATCalculationMethod>
</ClassifiedTaxCategory>
<Item>
<Description><?php echo $item->name ?></Description>
</Item>
</InvoiceLine>
<?php
$index = array_search($item->vat, $vat_cat);
$price[$index] += $item->quantity * $item->price;
$price_vat[$index] += $item->quantity * $item_price_vat;
} ?>
</InvoiceLines>
<TaxTotal>
<?php array_multisort($vat_cat, $price, $price_vat);
for ($i = 0; $i < count($vat_cat); $i++) {
$price_r = round($price[$i], 2);
$price_vat_r = round($price_vat[$i], 2);
?>
<TaxSubTotal>
<TaxableAmount><?php echo $price_vat_r ?></TaxableAmount>
<TaxInclusiveAmount><?php echo $price_vat_r ?></TaxInclusiveAmount>
<TaxAmount><?php echo $price_vat_r - $price_r ?></TaxAmount>
<AlreadyClaimedTaxableAmount>0</AlreadyClaimedTaxableAmount>
<AlreadyClaimedTaxAmount>0</AlreadyClaimedTaxAmount>
<AlreadyClaimedTaxInclusiveAmount>0</AlreadyClaimedTaxInclusiveAmount>
<DifferenceTaxableAmount><?php echo $price_r ?></DifferenceTaxableAmount>
<DifferenceTaxAmount><?php echo $price_vat_r - $price_r ?></DifferenceTaxAmount>
<DifferenceTaxInclusiveAmount><?php echo $price_vat_r ?></DifferenceTaxInclusiveAmount>
<TaxCategory>
<Percent><?php echo $vat_cat[$i] * 100 ?></Percent>
</TaxCategory>
</TaxSubTotal>
<?php }
$total_price = round(array_sum($price), 2);
$total_price_vat = round(array_sum($price_vat), 2); ?>
<TaxAmount><?php echo $total_price_vat - $total_price ?></TaxAmount>
</TaxTotal>
<LegalMonetaryTotal>
<TaxExclusiveAmount><?php echo $total_price ?></TaxExclusiveAmount>
<TaxInclusiveAmount><?php echo $total_price_vat ?></TaxInclusiveAmount>
<AlreadyClaimedTaxExclusiveAmount>0</AlreadyClaimedTaxExclusiveAmount>
<AlreadyClaimedTaxInclusiveAmount>0</AlreadyClaimedTaxInclusiveAmount>
<DifferenceTaxExclusiveAmount><?php echo $total_price ?></DifferenceTaxExclusiveAmount>
<DifferenceTaxInclusiveAmount><?php echo $total_price_vat ?></DifferenceTaxInclusiveAmount>
<PayableRoundingAmount><?php echo round(ceil($total_price_vat) - $total_price_vat, 2) ?></PayableRoundingAmount>
<PaidDepositsAmount>0</PaidDepositsAmount>
<PayableAmount><?php echo ceil($total_price_vat) ?></PayableAmount>
</LegalMonetaryTotal>
<PaymentMeans>
<Payment>
<PaidAmount><?php echo ceil($total_price_vat) ?></PaidAmount>
<PaymentMeansCode>42</PaymentMeansCode>
<Details>
<PaymentDueDate><?php echo $invoice->date_due ?></PaymentDueDate>
<?php
$account_nr = null;
$bank_code = null;
if (!empty($supplier)) {
if ($supplier->bank_accounts->count() != 0 ) {
$bank_accounts = $supplier->bank_accounts->as_array();
$account_nr = $bank_accounts[0]->account_nr;
$bank_code = $bank_accounts[0]->bank_nr;
}
} elseif (!empty($invoice->account_nr))
@list($account_nr, $bank_code) = explode('/', $invoice->account_nr);
?>
<ID><?php echo $account_nr ?></ID>
<BankCode><?php echo $bank_code ?></BankCode>
<Name/>
<IBAN/>
<BIC/>
<VariableSymbol><?php if(!empty($invoice->var_sym))echo $invoice->var_sym ?></VariableSymbol>
<ConstantSymbol><?php if(!empty($invoice->con_sym)) echo $invoice->con_sym; ?></ConstantSymbol>
</Details>
</Payment>
</PaymentMeans>
</Invoice>
freenetis/branches/1.1/application/views/js/__pieces/invoice.php
<?php
/**
* Invoice contact information javascript view.
* Hides/Shows contact information in invoice form.
*
* @author Jan Dubina
*/
// IDE complementation
if (FALSE): ?><script type="text/javascript"><?php endif
?>
$('#member_id').change(function (){
var val = $(this).val();
if (val != 0) {
$('th.partner_company').parent().hide();
$('th.partner_name').parent().hide();
$('th.partner_street').parent().hide();
$('th.partner_street_number').parent().hide();
$('th.partner_town').parent().hide();
$('th.partner_zip_code').parent().hide();
$('th.partner_country').parent().hide();
$('th.organization_identifier').parent().hide();
$('th.phone_number').parent().hide();
$('th.email').parent().hide();
} else {
$('th.partner_company').parent().show();
$('th.partner_name').parent().show();
$('th.partner_street').parent().show();
$('th.partner_street_number').parent().show();
$('th.partner_town').parent().show();
$('th.partner_zip_code').parent().show();
$('th.partner_country').parent().show();
$('th.organization_identifier').parent().show();
$('th.phone_number').parent().show();
$('th.email').parent().show();
}
}).change();
freenetis/branches/1.1/application/views/js/__pieces/settings.php
<?php
/**
* Invoice contact information javascript view.
* Hides/Shows contact information in invoice form.
*
* @author Jan Dubina
*/
// IDE complementation
if (FALSE): ?><script type="text/javascript"><?php endif
?>
$('input[name=membership_interrupt_enabled]').change(function (){
var val = $('input[name=membership_interrupt_enabled]:checked').val();
if (val != 0) {
$('th.membership_interrupt_minimum').parent().prev().show();
$('th.membership_interrupt_minimum').parent().show();
$('th.membership_interrupt_maximum').parent().show();
} else {
$('th.membership_interrupt_minimum').parent().prev().hide();
$('th.membership_interrupt_minimum').parent().hide();
$('th.membership_interrupt_maximum').parent().hide();
}
}).change();

Také k dispozici: Unified diff