Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/application/classes/cms.php |
<?php defined('SYSPATH') or die('No direct script access.');
class Cms {
public static function bottleName($params) {
if( $params == 'zubrowka' ) return "zubrówka";
}
public static function getTemplateEmail($id=null, $params, $html = true) {
$email_template = array();
$input = array(
'%USERNAME%','%FIRSTNAME%','%LASTNAME%','%NAME%','%AUCTION_ID%', '%CODE%'
);
$output = array(
$params['user']->username,$params['user']->firstname,$params['user']->lastname, $params['auction']['title'], $params['auction']['id'], $params['code']
);
$template = ORM::Factory('user_template', $id);
if( $template->loaded() ) {
$email_template['subject'] = $template->subject;
$email_template['text'] = nl2br($template->welcome_text)."\n\n";
$email_template['text'] = str_replace( $input, $output, $email_template['text']);
}
return $email_template;
}
/**
* Returns unique user hash with login prefix
*
* @param string $login
* @param string $email
* @return string
*/
public static function getCountry2IP() {
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_URL, "http://api.wipmania.com/".$_SERVER['REMOTE_ADDR']);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$response = curl_exec($ch);
$info = curl_getinfo($ch,CURLINFO_HTTP_CODE);
return $response;
// close cURL resource, and free up system resources
curl_close($ch);
}
public static function front_banner($data=null, $count=1) {
$data = ORM::Factory('banner')->where('type','=', $data)->limit($count)->find_all();
return View::Factory('_partials/banner')->bind('_data', $data)->bind('count', $count)->render();
}
public static function advancement() {
foreach( ORM::Factory('User')->find_all() as $partner ) {
$points = $partner->points;
if( $points > 0 ) {
$level_q = "SELECT id FROM levels WHERE '$points' BETWEEN points_from AND points_to ORDER by id DESC LIMIT 1";
echo "Przetwarzanie dla ID: $partner->id<br/>";
$level = DB::Query(Database::SELECT, $level_q)->as_object()->execute();
if( $level->count() > 0 ) {
$level_id = $level[0]->id;
echo $partner->id." =>>> ".$level_id."<br/>";
$partner->level_commission = $level_id;
$partner->save();
}
}
}
}
public static function confirmAdmin( $c, $a) {
$message = "Wymagana moderacja administratora w kontrolerze: $c , akcja: $a <br/>";
$message .= "Proszę zalogować się do panelu administracyjnego i dokonać akceptacji danych!";
aurora::standardEmail(Kohana::$config->load('site.email_business'), 'Wymagana moderacja', $message);
}
public static function Add_Commission( $seller_id, $product_id, $order_id) {
$product = ORM::Factory('item', $product_id);
$order_item = ORM::Factory('order_item')
->where('orders_id','=', $order_id)
->where('items_id','=', $product_id)->find();
if( $order_item->loaded() ) {
$level_commission = ORM::Factory('User', $seller_id)->level_commission;
$amount_percentage = 0;
if( $level_commission == 1 ) {
$amount_percentage = 10; // 10 % dla sprzedawcy, autora
}
if( $amount_percentage > 0 ) {
// Bez kosztu dostawy - nie liczmy do prowizji
$amount = $order_item->price*($amount_percentage/100);
$uc = ORM::Factory('User_commission');
$uc->date = date('Y-m-d');
$uc->status = 2;
$uc->amount = $amount;
$uc->user_id = $seller_id;
$uc->print = $order_item->print;
$uc->product_id = $product_id;
$uc->order_id = $order_id;
$uc->save();
}
}
}
public static function getPointActionName( $type) {
if( $type == "REGISTER" ) {
return "Rejestracja";
} elseif( $type == "ADD_ITEM" ) {
return "Dodanie pracy";
} elseif( $type == "SHARE_FB" ) {
return "Udostępnienie FB";
} elseif( $type == "INVITE_TO_REGISTER" ) {
return "Zaproszenie do rejestracji";
} elseif( $type == "BUY" ) {
return "Zakup";
} elseif( $type == "SELL" ) {
return "Sprzedaż";
}
}
public static function Add_Affiliate( $user_id, $type) {
$user = ORM::Factory('User', $user_id);
$moderator_user = ORM::Factory('moderator_user', $user_id);
if( $type == "REGISTER" ) {
$points = 50;
} elseif( $type == "ADD_ITEM" ) {
$points = 25;
} elseif( $type == "SHARE_FB" ) {
$points = 5;
} elseif( $type == "INVITE_TO_REGISTER" ) {
$points = 250;
} elseif( $type == "BUY" ) {
$points = 150;
} elseif( $type == "SELL" ) {
$points = 100;
}
$s = ORM::Factory('Stat');
$s->keyname = $type;
$s->value = $points;
$s->user_id = $user_id;
$s->save();
$user->points += $points;
$user->save();
$moderator_user->points += $points;
$moderator_user->save();
self::advancement();
}
public static function Delete_Affiliate( $user_id, $type) {
$user = ORM::Factory('User', $user_id);
$moderator_user = ORM::Factory('moderator_user', $user_id);
if( $type == "REGISTER" ) {
$points = 50;
} elseif( $type == "ADD_ITEM" ) {
$points = 25;
} elseif( $type == "SHARE_FB" ) {
$points = 5;
} elseif( $type == "INVITE_TO_REGISTER" ) {
$points = 250;
} elseif( $type == "BUY" ) {
$points = 150;
} elseif( $type == "SELL" ) {
$points = 100;
}
$s = ORM::Factory('Stat')->where('user_id','=', $user_id)
->where('value','=', $points)
->where('keyname', '=', $type)->find();
$s->delete();
$user->points -= $points;
$user->save();
$moderator_user->points += $points;
$moderator_user->save();
self::advancement();
}
public static function _no_pl($tekst)
{
$tabela = Array(
//WIN
"xb9" => "a", "xa5" => "A", "xe6" => "c", "xc6" => "C",
"xea" => "e", "xca" => "E", "xb3" => "l", "xa3" => "L",
"xf3" => "o", "xd3" => "O", "x9c" => "s", "x8c" => "S",
"x9f" => "z", "xaf" => "Z", "xbf" => "z", "xac" => "Z",
"xf1" => "n", "xd1" => "N",
//UTF
"xc4x85" => "a", "xc4x84" => "A", "xc4x87" => "c", "xc4x86" => "C",
"xc4x99" => "e", "xc4x98" => "E", "xc5x82" => "l", "xc5x81" => "L",
"xc3xb3" => "o", "xc3x93" => "O", "xc5x9b" => "s", "xc5x9a" => "S",
"xc5xbc" => "z", "xc5xbb" => "Z", "xc5xba" => "z", "xc5xb9" => "Z",
"xc5x84" => "n", "xc5x83" => "N",
//ISO
"xb1" => "a", "xa1" => "A", "xe6" => "c", "xc6" => "C",
"xea" => "e", "xca" => "E", "xb3" => "l", "xa3" => "L",
"xf3" => "o", "xd3" => "O", "xb6" => "s", "xa6" => "S",
"xbc" => "z", "xac" => "Z", "xbf" => "z", "xaf" => "Z",
"xf1" => "n", "xd1" => "N");
$out = strtr($tekst,$tabela);
return str_replace(" ","-", $out);
}
public static function uniqueUserLink($login,$email) {
//$login= str_replace('@','-malpa-',$login);
//$login= str_replace('.','-kropka-',$login);
return $login.'/'.Auth::instance()->hash($email);
}
public static function uniqueCompanyLink($id,$email) {
//$login= str_replace('@','-malpa-',$login);
//$login= str_replace('.','-kropka-',$login);
return $id.'/'.Auth::instance()->hash($email);
}
public static function isMember( $id ) {
$test = ORM::Factory('user_member')->where('user_id','=', $id)->find_all();
if( $test->count() > 0 ) return array( $test[0]->has_friend, Users::getFirstname($test[0]->has_friend)); else return 0;
}
static public function getSelectionCount($type_id, $type ) {
$selection = ORM::Factory('selection')->where('type_id','=', $type_id)->where('type','=',$type)->find_all();
return $selection->count();
}
static public function addmission($text, $limit=165) {
$text = stripslashes( $text );
$text = substr($text, 0, $limit);
return $text."...";
}
static public function putShortDescription($text) {
/*
$text = substr($text, 0, 255);
$first = strstr($text, 'http');
$url = substr($first, 0, strpos($first, " "));
$link = "<a href='".$url."' target='_blank'>".$url."</a>";
return str_replace($url, $link, $text);
*/
$text = stripslashes( $text );
$text = preg_replace('"\b(http://\S+)"', '<a href="$1" target="_blank">$1</a>', $text);
$text = preg_replace('"\b^(www\S+)"', '<a href="http://$1" target="_blank">$1</a>', $text);
return $text;
}
static public function putDescription($text) {
//$first = strstr($text, 'http');
//$url = substr($first, 0, strpos($first, " "));
$text = stripslashes( $text );
$text = preg_replace('"\b(http://\S+)"', '<a href="$1" target="_blank">$1</a>', $text);
$text = preg_replace('"\b^(www\S+)"', '<a href="http://$1" target="_blank">$1</a>', $text);
return $text;
//$link = "<a href='".$url."' target='_blank'>".$url."</a>";
//return str_replace($url, $link, $text);
}
public static function addSelection( $user_id, $type_id, $type ) {
$selection = ORM::Factory('selection');
$selection->type = $type;
$selection->user_id = $user_id;
$selection->type_id = $type_id;
$selection->save();
return self::getSelectionCount($type_id, $type);
}
public static function prevProfile( $user_id ) {
$user = ORM::Factory('user')->where('id','<', $user_id)->order_by('id','desc')->limit(1)->find_all();
if( $user->count() == 0 ) return $user_id;
else return $user[0]->id;
}
public static function nextProfile( $user_id ) {
$user = ORM::Factory('user')->where('id','>', $user_id)->limit(1)->find_all();
if( $user->count() == 0 ) return $user_id;
else return $user[0]->id;
}
public static function getProfileName($what) {
switch( $what ) {
case 1:
return 'Model';
break;
case 2:
return 'Modelka';
break;
case 3:
return 'Fotomodelka';
break;
case 4:
return 'Hostessa';
break;
case 5:
return 'Fotograf';
break;
case 6:
return 'Wizażysta';
break;
case 7:
return 'Stylista';
break;
case 8:
return 'Fryzjer';
break;
case 9:
return 'Projektant';
break;
case 10:
return 'Scenograf';
break;
case 11:
return 'Firma';
break;
case 12:
return 'Agencja modelek';
break;
case 13:
return 'Organizacja';
break;
default:
return 'Ogólny';
break;
}
}
public static function addPoints($id_user, $what) {
$user = ORM::Factory('user', $id_user);
$user->points += 1;
$user->save();
}
/**
* Sends standard email message. (with standard layout)
*
* @param string $to
* @param string $subject
* @param View $message
* @param bool $html
* @param array $from
* @return bool
*/
public static function standardEmail($to, $subject, $message, $html=TRUE, $from = null, $attachments=array()) {
Mailer::instance()
->to($to)
->from(array( !is_null( $from ) ? $from['from_email'] : Kohana::$config->load('site.emailnoreply') => !is_null( $from ) ? $from['from_name'] : Kohana::$config->load('site.appName')))
->subject($subject)
->html($message)
->attachments($attachments)
->send();
}
/**
* Wyslanie emaila o nowym komentarzu
* @param string $to adresat
* @return boolean
*/
public static function new_art_comment_email($art_id, $content)
{
$subject = __t('Sprungle - nowy komentarz dla Twojej pracy');
$art = new Model_Art($art_id);
$user = new Model_User(Auth::instance()->get_user()->id);
$message = View::factory('email/art_comment')
->bind('content',$content)
->bind('art', $art)
->bind('user', $user);
$to = $art->users->find()->email;
//echo("self::standardEmail($to, $subject, $message);");exit;
self::standardEmail($to, $subject, $message);
}
public static function partial($path, $data=array()) {
return View::factory((strpos($path,'/'))? $path : '/_partials/'.$path)
->bind('data', $data);
}
/**
* Zwraca widok listy stron z określonej sekcji
* @param integer $sectionId
* @return View
*/
public static function getPages($sectionId) {
$section=ORM::factory('section',$sectionId);
$pages= $section->pages->order_by('order')->find_all();
$langID= $_SESSION['lang_id'];
return View::factory('_partials/pages')
->bind('section',$section)
->bind('langID',$langID)
->bind('pages',$pages);
}
/**
* Zwraca stringa klasy aktywnego elementy górnej nawigacji
* @param string $controller
* @param string $action
* @return string
*/
public static function __top_menu($c, $a) {
$controller = Request::current()->controller;
$action = Request::current()->action;
$css = 'active';
if ($c == $controller) {
if ($a == 'index' || $a == $action)
return $css;
}
}
public static function __check_menu($c, $a) {
$controller = Request::current()->controller;
$action = Request::current()->action;
$return= false;
if ($a == $action) {
$return= true;
}
return $return;
}
/**
* Zwraca liste obiektow COLOR
* @return <type>
*/
public static function getColors(){
return ORM::factory('color')->find_all();
}
/**
* Zwraca liste obiektow STYLE
* @return <type>
*/
public static function getStyles(){
return ORM::factory('style')->find_all();
}
/**
* Zwraca obiekt 'Style_Name' na podstawie obiektu Style
* @param <type> $style
*/
public static function getStyleName($style){
return $style->style_names->where('language_id','=',Kohana::config('site.language_id'))->find();
}
public static function countStyleArts($styleId, $isShop)
{
$art_status_id = 3;
if ($isShop == 1){
$art_status_id = 3;
} else {
$art_status_id = 2;
}
return ORM::factory('art')->where('art_status_id','=', $art_status_id)->where('style_id','=',$styleId)->count_all();
}
public static function newsletterLink($userID,$userEmail){
$link;
$hash = Auth::instance()->hash($userEmail);
$webpage = Kohana::config('site.domain');
$link = 'http://'.$webpage.'/newsletter/unsubscribe/'.$userID.'/'.$hash;
return $link;
}
public static function seoLink($link){
$link = str_replace(" ","_", $link);
//$link = strtolower($link);
return $link;
}
public static function words2pay($kw) {
$kw_w = '';
$kw_slow = '';
$l_pad = '';
$t_a = array('',__t('sto'),__t('dwieście'),__t('trzysta'),__t('czterysta'),__t('pięćset'),__t('sześćset'),__t('siedemset'),__t('osiemset'),__t('dziewięćset'));
#
$t_b = array('',__t('dziesięć'),__t('dwadzieścia'),__t('trzydzieści'),__t('czterdzieści'),__t('pięćdziesiąt'),__t('sześćdziesiąt'),__t('siedemdziesiąt'),__t('osiemdziesiąt'),__t('dziewięćdziesiąt'));
#
$t_c = array('',__t('jeden'),__t('dwa'),__t('trzy'),__t('cztery'),__t('pięć'),__t('sześć'),__t('siedem'),__t('osiem'),__t('dziewięć'));
#
$t_d = array(__t('dziesięć'),__t('jedenaście'),__t('dwanaście'),__t('trzynaście'),__t('czternaście'),__t('piętnaście'),__t('szesnaście'),__t('siednaście'),__t('osiemnaście'),__t('dziewiętnaście'));
#
#
$t_kw_15 = array('septyliard','septyliardów','septyliardy');
#
$t_kw_14 = array('septylion','septylionów','septyliony');
#
$t_kw_13 = array('sekstyliard','sekstyliardów','sekstyliardy');
#
$t_kw_12 = array('sekstylion','sekstylionów','sepstyliony');
#
$t_kw_11 = array('kwintyliard','kwintyliardów','kwintyliardy');
#
$t_kw_10 = array('kwintylion','kwintylionów','kwintyliony');
#
$t_kw_9 = array('kwadryliard','kwadryliardów','kwaryliardy');
#
$t_kw_8 = array('kwadrylion','kwadrylionów','kwadryliony');
#
$t_kw_7 = array('tryliard','tryliardów','tryliardy');
#
$t_kw_6 = array('trylion','trylionów','tryliony');
#
$t_kw_5 = array('biliard','biliardów','biliardy');
#
$t_kw_4 = array('bilion','bilionów','bilony');
#
$t_kw_3 = array('miliard','miliardów','miliardy');
#
$t_kw_2 = array('milion','milionów','miliony');
#
$t_kw_1 = array('tysiąc','tysięcy','tysiące');
#
$t_kw_0 = array('euro','euro','euro');
#
$tmp = array();
#
if ($kw!='') {
#
$kw=(substr_count($kw,',')==0) ? $kw.',00':$kw;
#
$tmp=explode(",",$kw);
#
$ln=strlen($tmp[0]);
#
$tmp_a=($ln%3==0) ? (floor($ln/3)*3):((floor($ln/3)+1)*3);
#
for($i = $ln; $i < $tmp_a; $i++) {
#
$l_pad .= '0';
#
$kw_w = $l_pad . $tmp[0];
#
}
#
$kw_w=($kw_w=='') ? $tmp[0]:$kw_w;
#
$paczki=(strlen($kw_w)/3)-1;
#
$p_tmp=$paczki;
#
for($i=0;$i<=$paczki;$i++) {
#
$t_tmp='t_kw_'.$p_tmp;
#
$p_tmp--;
#
$p_kw=substr($kw_w,($i*3),3);
#
@$kw_w_s=($p_kw{1}!=1) ? $t_a[$p_kw{0}].' '.$t_b[$p_kw{1}].' '.$t_c[$p_kw{2}]:$t_a[$p_kw{0}].' '.$t_d[$p_kw{2}];
#
if(($p_kw{0}==0)&&($p_kw{2}==1)&&($p_kw{1}<1)) $ka=${$t_tmp}[0]; //możliwe że $p_kw{1}!=1
#
else if (($p_kw{2}>1 && $p_kw{2}<5)&&$p_kw{1}!=1) $ka=${$t_tmp}[2];
#
else $ka=${$t_tmp}[1];
#
$kw_slow.=$kw_w_s.' '.$ka.' ';
#
}
#
}
#
$text = $kw_slow.' '.@$tmp[1].'/100';
#
return $text;
}
static public function createInvoice($order_id, $preview = false) {
$order = ORM::Factory('order', $order_id);
@define('FPDF_FONTPATH','modules/fpdf/font/');
$height = 10;
require_once('modules/fpdf/fpdf.php');
$invoice_count = 1;
$faktura = new FPDF();
$faktura->SetUTF8(true);
$faktura->SetDisplayMode('real', 'single');
$faktura->Open();
$faktura->AddPage();
$faktura->AddFont('arial_ce', "", "arial_ce.php");
$faktura->SetCompression(false); //włącza kompresję dokumentu
/* a poniższe tylko dla ambitnych */
$faktura->SetAuthor('Pozwolenie'); //ustawia autora dokumentu
$faktura->SetCreator('Pozwolenie'); //ustawia generator dokumentu
$faktura->SetSubject('Pozwolenie'); //ustawia temat dokumentu
$faktura->SetTitle('Pozwolenie'); //ustawia tytuł dokumentu
$faktura->SetDisplayMode(200); //domyślne powiększenie dokumentu w przeglądarce
//$faktura->SetMargins(10, 10 , 10); //ustawia marginesy dla dokumentu
//$faktura->Image('images/logo.jpg', 28, 15,127,77);
//if( !empty( $user->logo ) ) {
// $faktura->Image($user->logo, 10, 6, 193, 59);
//}
$invoice = ORM::Factory('Order', $order_id);
$invoice_count = $invoice->id;
$user = $invoice->customer;
$customer = $invoice->seller;
defined('FPDF_FONTPATH') OR define('FPDF_FONTPATH','modules/fpdf/font/');
$height = 10;
require_once('modules/fpdf/fpdf.php');
$faktura = new FPDF();
$faktura->SetUTF8(true);
$faktura->SetDisplayMode('real', 'single');
$faktura->Open();
$faktura->AddPage();
$faktura->AddFont('arial_ce', "", "arial_ce.php");
$faktura->SetCompression(false); //włącza kompresję dokumentu
/* a poniższe tylko dla ambitnych */
$faktura->SetAuthor('Faktura VAT'); //ustawia autora dokumentu
$faktura->SetCreator('Faktura VAT'); //ustawia generator dokumentu
$faktura->SetSubject('Faktura VAT'); //ustawia temat dokumentu
$faktura->SetTitle('Faktura VAT'); //ustawia tytuł dokumentu
$faktura->SetDisplayMode(200); //domyślne powiększenie dokumentu w przeglądarce
//$faktura->SetMargins(10, 10 , 10); //ustawia marginesy dla dokumentu
//$faktura->Image('images/logo.jpg', 28, 15,127,77);
$z_x = 237;
$y = 20;
$faktura->SetFont('arial_ce','',11);
$faktura->MultiCell(0, $height-10, 'Data wystawienia: '.$invoice->date, 0, 'R', 0);
$faktura->MultiCell(0, $height+20, 'Data sprzedaży: '.$invoice->date, 0, 'R', 0);
$y += 30;
if( !empty( $user->logo ) ) {
//$faktura->Image($user->logo, 10, 20, 193, 59);
}
$faktura->SetFont('arial_ce','',22);
$faktura->MultiCell(0, $height+15, 'FAKTURA VAT', 0, 'C', 0);
$y += 5;
$faktura->SetFont('arial_ce','',12);
$faktura->MultiCell(0, $height, 'F/'.$invoice_count, 0, 'C', 0);
$y += 5;
$faktura->SetFont('arial_ce','',6);
$faktura->MultiCell(0, $height, __t('oryginał/kopia'), 0, 'C', 0);
$faktura->SetFont('arial_ce','',11);
$faktura->SetXY(28, 112);
$faktura->SetFillColor(170,170,170);
$faktura->MultiCell(260, 20, __t('Sprzedawca'), 1, 'C', 1);
$faktura->MultiCell(260, 20, $user->company, 'LRT', 'L', 0);
$faktura->MultiCell(260, 20, $user->street, 'LR', 'L', 0);
$faktura->MultiCell(260, 20, $user->postcode.' '.$user->city, 'LR', 'L', 0);
$faktura->MultiCell(260, 20, $user->nip, 'LRB', 'L', 0);
$faktura->SetXY(305, 112);
$faktura->MultiCell(260, 20, __t('Nabywca'), 1, 'C', 1);
$faktura->SetXY(305, 132);
$faktura->MultiCell(260, 20, !empty( $customer->company ) ? $customer->company : $customer->firstname.' '.$customer->lastname, 'LRT', 'L', 0);
$faktura->SetFont('arial_ce','',12);
$faktura->SetXY(305, 152);
$faktura->MultiCell(260, 20, $customer->street, 'LR', 'L', 0);
$faktura->SetXY(305, 172);
$faktura->MultiCell(260, 20, $customer->postcode.' '.$customer->city, 'LR', 'L', 0);
$faktura->SetXY(305, 192);
$faktura->MultiCell(260, 20, @$customer->nip, 'LRB', 'L', 0);
$faktura->SetFillColor(255,255,255);
$faktura->SetXY(28, 230);
$faktura->SetFont('arial_ce','',6);
$faktura->MultiCell(15, 25, __t("Lp"), 1, 'C', 0);
$faktura->SetXY(43, 230);
$faktura->MultiCell(280, 25, __t("Nazwa"), 1, 'L', 0);
$faktura->SetXY(323, 230);
$faktura->MultiCell(30, 25, __t("PKWiU"), 1, 'C', 0);
$faktura->SetXY(353, 230);
$faktura->MultiCell(20, 25, __t("Ilość"), 1, 'C', 0);
$faktura->SetXY(373, 230);
$faktura->MultiCell(50, 25, __t("Cena jedn. netto"), 1, 'C', 0);
$faktura->SetXY(423, 230);
$faktura->MultiCell(40, 25, __t("Wart. netto"), 1, 'C', 0);
$faktura->SetXY(463, 230);
$faktura->MultiCell(60, 25, __t("Podatek"), 1, 'C', 0);
$faktura->SetXY(523, 230);
$faktura->MultiCell(42, 25, __t("Wart. brutto"), 1, 'C', 0);
// $faktura->SetFont('arial_ce','',6);
$Y_POS = 255;
$wartosc_netto = 0;
$podatek = 0;
$wartosc_brutto = 0;
$suma_wartosc_netto = 0;
$suma_podatek = 0;
$suma_wartosc_brutto = 0;
$suma_wartosc_netto23 = 0;
$suma_podatek23 = 0;
$suma_wartosc_brutto23 = 0;
$suma_wartosc_netto8 = 0;
$suma_podatek8 = 0;
$suma_wartosc_brutto8 = 0;
$suma_wartosc_netto3 = 0;
$suma_podatek3 = 0;
$suma_wartosc_brutto3 = 0;
$suma_wartosc_netto0 = 0;
$suma_podatek0 = 0;
$suma_wartosc_brutto0 = 0;
$suma_wartosc_nettozw = 0;
$suma_podatekzw = 0;
$suma_wartosc_bruttozw = 0;
$data['titleposition_1'] = __t($invoice->title);
$data['jmposition_1'] = __t('szt.');
$data['pkwiu_1'] = '';
$data['amountposition_1'] = 1;
$data['priceposition_1'] = $invoice->price;
$data['rateposition_1'] = $invoice->tax;
for( $i = 1; $i < 2; $i++ ) {
$titleposition = $data['titleposition_'.$i];
$jmposition = $data['jmposition_'.$i];
$pkwiu = $data['pkwiu_'.$i];
$amountposition = $data['amountposition_'.$i];
$priceposition = $data['priceposition_'.$i];
$rateposition = $data['rateposition_'.$i];
if( !empty( $titleposition ) ) {
$wartosc_brutto = $invoice->price;
$wartosc_netto = $invoice->netto;
$podatek = $invoice->tax;
$suma_wartosc_brutto += $wartosc_brutto;
$suma_wartosc_netto += $wartosc_netto;
$suma_podatek += $podatek;
$faktura->SetXY(28, $Y_POS);
$faktura->MultiCell(15, 25, $i.".", 1, 'C', 0);
$faktura->SetXY(43, $Y_POS);
$faktura->MultiCell(280, 25, $titleposition, 1, 'L', 0);
$faktura->SetXY(323, $Y_POS);
$faktura->MultiCell(30, 25, $pkwiu, 1, 'C', 0);
$faktura->SetXY(353, $Y_POS);
$faktura->MultiCell(20, 25, $amountposition, 1, 'C', 0);
$faktura->SetXY(373, $Y_POS);
$faktura->MultiCell(50, 25, number_format($wartosc_netto, 2, ',', ' '), 1, 'C', 0);
$faktura->SetXY(423, $Y_POS);
$faktura->MultiCell(40, 25, number_format($wartosc_netto, 2, ',', ' '), 1, 'C', 0);
$faktura->SetXY(463, $Y_POS);
$faktura->MultiCell(20, 25, $user->tax."%", 1, 'C', 0);
$faktura->SetXY(483, $Y_POS);
$faktura->MultiCell(40, 25, number_format($podatek, 2, ',', ' '), 1, 'C', 0);
$faktura->SetXY(523, $Y_POS);
$faktura->MultiCell(42, 25, number_format($wartosc_brutto, 2, ',', ' '), 1, 'C', 0);
$Y_POS = $Y_POS+25;
}
}
//$suma_wartosc_brutto = number_format($invoice->price, 2, ',', ' ');
$faktura->SetXY(323, $Y_POS);
$faktura->MultiCell(30, 25, __t("Razem"), 1, 'C', 0);
$faktura->SetXY(353, $Y_POS);
$faktura->MultiCell(20, 25, "", 1, 'C', 0);
$faktura->SetXY(373, $Y_POS);
$faktura->MultiCell(50, 25, "", 1, 'C', 0);
$faktura->SetXY(423, $Y_POS);
$faktura->MultiCell(40, 25, number_format($suma_wartosc_netto, 2, ',', ' '), 1, 'C', 0);
$faktura->SetXY(463, $Y_POS);
$faktura->MultiCell(20, 25, "X", 1, 'C', 0);
$faktura->SetXY(483, $Y_POS);
$faktura->MultiCell(40, 25, number_format($suma_podatek, 2, ',', ' '), 1, 'C', 0);
$faktura->SetXY(523, $Y_POS);
$faktura->MultiCell(42, 25, number_format($invoice->price, 2, ',', ' '), 1, 'C', 0);
$Y_POS = $Y_POS+25;
$Y = $faktura->getY()+20;
//$slownie = cms::words2pay($suma_wartosc_brutto);
$slownie = 'ghgf';
$faktura->SetXY(28, $Y);
$payment_method = __t('przelew');
$faktura->MultiCell(0, 15, __t("Termin płatności").": ".date('d-m-Y', strtotime($invoice->date)+300*24*Kohana::$config->load('site.maturity'))."\n".__t("Sposób płatności").": ".$payment_method."\n".__t("Zapłacono").": 0,00 zł\n".__t("Wartosc brutto").": ".$suma_wartosc_brutto." zł\n".__t("Słownie").": ".$slownie."\n".__t("Nazwa banku").": ".$user->billing_bank."\n".__t("Numer konta").": ".$user->billing_bank_account , 1, 'L', 0);
//$faktura->SetXY(415, $Y);
//$faktura->MultiCell(150, 25, "Całkowita kwota: 10 000,00 PLN\nZapłacono: 10 000,00 PLN\nDo zapłaty: 10 000,00 PLN" , 1, 'R', 0);
$Y += 145;
$faktura->SetXY(28, $Y);
$faktura->SetFont('arial_ce','',6);
$faktura->MultiCell(300, 10, "--------------------------\nPodpis osoby upoważnionej do\nwystawienia faktury" , 0, 'L', 0);
$faktura->SetXY(365, $Y);
$faktura->MultiCell(200, 10, "--------------------------\nPodpis osoby upoważnionej do\nodbioru faktury" , 0, 'R', 0);
$Y += 75;
$faktura->SetXY(28, $Y);
$faktura->MultiCell(0, 10, " " , 0, 'C', 0);
$Y += 25;
$faktura->SetXY(28, $Y);
$rand = rand(1,100);
$file_name = 'uploads/pdf/fv_'.md5($order->id).'.pdf';
if( $preview ) {
$faktura->Output();
return 1;
} else {
$faktura->Output($file_name,'F');
$order->file_name = $file_name;
$order->save();
return $order->file_name;
}
}
}