Использовав данное решение, обнаружилась ошибка, если цена 100 000 или 10 000 000 то прописью выводит "Итого: Сто рублей 00 копеек"
<?php
/**
* @version 4.0.0 19.09.2012
* @author MAXXmarketing GmbH
* @package Jshopping
* [member=126442]copyright[/member] Copyright (C) 2010 webdesigner-profi.de. All rights reserved.
* @license GNU/GPL
*/
include(JPATH_SITE."/components/com_jshopping/lib/pdf_config.php");
include(JPATH_SITE."/components/com_jshopping/lib/tcpdf/tcpdf.php");
class JorderPDF extends TCPDF{
function addNewPage(){
$this->addPage();
$this->addTitleHead();
}
function addTitleHead(){
$jshopConfig = JSFactory::getConfig();
$vendorinfo = $this->_vendorinfo;
$this->Image($jshopConfig->path.'images/header.jpg',1,1,$jshopConfig->pdf_header_width,$jshopConfig->pdf_header_height);
/*$this->Image($jshopConfig->path.'images/footer.jpg',1,160,$jshopConfig->pdf_footer_width,$jshopConfig->pdf_footer_height);*/
}
}
class num2str {
var $nums = array(
1 => array( 'один', 'одна' ),
2 => array( 'два', 'две' ),
3 => 'три',
4 => 'четыре',
5 => 'пять',
6 => 'шесть',
7 => 'семь',
8 => 'восемь',
9 => 'девять',
10 => 'десять',
11 => 'одиннадцать',
12 => 'двенадцать',
13 => 'тринадцать',
14 => 'четырнадцать',
15 => 'пятнадцать',
16 => 'шестнадцать',
17 => 'семнадцать',
18 => 'восемнадцать',
19 => 'девятнадцать',
20 => 'двадцать',
30 => 'тридцать',
40 => 'сорок',
50 => 'пятьдесят',
60 => 'шестьдесят',
70 => 'семьдесят',
80 => 'восемьдесят',
90 => 'девяносто',
100 => 'сто',
200 => 'двести',
300 => 'триста',
400 => 'четыреста',
500 => 'пятьсот',
600 => 'шестьсот',
700 => 'семьсот',
800 => 'восемьсот',
900 => 'девятьсот',
);
var $names = array(
1000 => array( 'тысяча', 'тысячи', 'тысяч', '', 'sem' => 1 ),
1000000 => array( 'миллион', 'миллиона', 'миллионов', '', 'sem' => 0 ),
1000000000 => array( 'миллиард', 'миллиарда', 'миллиардов', '', 'sem' => 0 )
);
var $out = array();
function semantic( $num, $words ) {
$des = false;
$num = $num % 100;
if( $num > 20 ) {
$num = $num % 10;
if( !$num ) {
$des= true;
}
}
if ( 1 == $num ){
return $words[0];
}elseif( $des ){
return $words[2];
}elseif( !$num ){
return $words[3];
}elseif( $num <= 4 ){
return $words[1];
}else{
return $words[2];
}
}
function small_nums( $num, $sem ) {
if( $num < 21 ) {
if( $num <= 2 ) {
$this->out[] = $this->nums[$num][$sem];
}else{
$this->out[] = $this->nums[$num];
}
}else{
$this->out[] = $this->nums[$num - ( $num % 10 )];
if( ( $num % 10 ) <= 2 ) {
$this->out[] = $this->nums[$num % 10][$sem];
}else{
$this->out[] = $this->nums[$num % 10];
}
}
}
function work( $num, $all_sem ) {
foreach( array( 1000000000, 1000000, 1000 ) as $order ) {
$temp = floor( $num / $order );
if( ( $temp - ( $temp % 100 ) ) > 0 ){
$this->out[] = $this->nums[$temp - ( $temp % 100 )];
}
$this->small_nums( $temp % 100, $this->names[$order]['sem'] );
$this->out[] = $this->semantic( $temp, $this->names[$order] );
$num -= $temp * $order;
}
$temp = $num;
if( ( $temp - ( $temp % 100 ) ) > 0 ){
$this->out[] = $this->nums[$temp - ( $temp % 100 )];
}
$this->small_nums( $temp % 100, $all_sem );
$temp = implode( ' ', $this->out );
$this->out = array();
return $temp;
}
}
class money2str {
var $names = array(
1 => array( 'рубль', 'рубля', 'рублей', 'рублей', 'sem' => 0 ),
2 => array( 'копейка', 'копейки', 'копеек', 'копеек', 'sem' => 1 )
);
var $out = array();
function money2str() {
$this->num2str = new num2str();
}
function work( $money, $kopnum = false ) {
$kop = substr( $money, -2 );
$rub = substr( $money, 0, -3 );
if( !$rub ) {
$this->out[] = 'ноль';
}else{
$this->out[] = $this->num2str->work( $rub, $this->names[1]['sem'] );
}
$this->out[] = $this->num2str->semantic( $rub, $this->names[1] );
if( !$kopnum ) {
if( !$kop ) {
$this->out[] = 'ноль';
}else{
$this->out[] = $this->num2str->work( $kop, $this->names[2]['sem'] );
}
}else{
$this->out[] = $kop;
}
$this->out[] = $this->num2str->semantic( $kop, $this->names[2] );
$temp = implode( ' ', $this->out );
$this->out = array();
return $temp;
}
}
function generatePDF($order){
$jshopConfig = JSFactory::getConfig();
$vendorinfo = $order->getVendorInfo();
JPluginHelper::importPlugin('jshoppingorder');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onBeforeCreatePdfOrder', array(&$order, &$vendorinfo));
$pdf = new JorderPDF();
$pdf->_vendorinfo = $vendorinfo;
$pdf->SetFont('freesans','',8); /*$pdf->SetFont('freesans','',8);*/
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetMargins(0, 0, 0);
$pdf->addNewPage();
/************************* Начало тела PDF *****************************/
$pdf->SetXY(32,7);
$pdf->setfontsize(8);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(150, 0, '');
$pdf->SetXY(32,11);
$pdf->Cell(150, 0, '');
$pdf->SetXY(32,15);
$pdf->Cell(150, 0, '');
$pdf->setfontsize(10);
$pdf->SetXY(20,20);
$pdf->Cell(95,15,'','1','L');
$pdf->SetXY(115,20);
$pdf->Cell(15,5,'','1','L');
$pdf->SetXY(115,20);
$pdf->Cell(15,5,'','1','L');
$pdf->SetXY(130,20);
$pdf->Cell(60,15,'','1','L');
$pdf->SetXY(20,35);
$pdf->Cell(48,5,'','1','L');
$pdf->SetXY(68,35);
$pdf->Cell(47,5,'','1','L');
$pdf->SetXY(20,40);
$pdf->Cell(95,15,'','1','L');
$pdf->SetXY(130,35);
$pdf->Cell(60,20,'','1','L');
$pdf->SetXY(115,35);
$pdf->Cell(15,20,'','1','L');
$pdf->SetXY(20,20);
$pdf->Cell(95,10,$vendorinfo->benef_bank_info,'0','L');//Наименование банка
$pdf->SetXY(20,30);
$pdf->Cell(95,5,'Банк получателя','0','L');
$pdf->SetXY(115,20);
$pdf->Cell(15,5,'БИК','0','L');
$pdf->SetXY(130,20);
$pdf->Cell(60,5,$vendorinfo->benef_bic,'0','L');// БИК
$pdf->SetXY(115,25);
$pdf->Cell(15,5,'Сч.N','0','L');
$pdf->SetXY(130,25);
$pdf->Cell(60,5,$vendorinfo->benef_conto,'0','L');// Кор. сч.
$pdf->SetXY(20,35);
$pdf->Cell(48,5,'ИНН','0','L');
$pdf->SetXY(30,35);
$pdf->Cell(38,5,$vendorinfo->benef_swift,'0','L'); // ИНН
$pdf->SetXY(68,35);
$pdf->Cell(47,5,'КПП','0','L');
$pdf->SetXY(78,35);
$pdf->Cell(47,5,$vendorinfo->benef_iban,'0','L'); //КПП
$pdf->SetXY(20,40);
$pdf->Cell(90,10,$vendorinfo->company_name,'0','L');// Получатель платежа
$pdf->SetXY(20,50);
$pdf->Cell(90,5,'Получатель','0','L');
$pdf->SetXY(115,35);
$pdf->Cell(15,5,'Сч.N','0','L');
$pdf->SetXY(130,35);
$pdf->Cell(60,5,$vendorinfo->identification_number,'0','L');//Р.сч
$pdf->SetXY(19,60);
$pdf->SetFont('freesansb','',11);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(60,6,'Счет',0,'R');
$pdf->SetXY(65,60);
$pdf->MultiCell(65,60," N".$order->order_number." от ".$order->order_date,0,'R');
if ($jshopConfig->date_invoice_in_invoice){
$pdf->SetXY(40,60);
$pdf->MultiCell(65,90,_JSHOP_INVOICE_DATE." ".strftime($jshopConfig->store_date_format, strtotime(date("Y-m-d H:i:s"))), 0, 'R');
}
$pdf->SetXY(19,70);
$pdf->Cell(170,.2,'',1,'L');
$pdf->SetXY(19,75);
$pdf->SetFont('freesans','',10);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(20,5,'Поставщик:',0,'R');
$pdf->SetXY(19,100);
$pdf->Cell(20,5,'Покупатель:',0,'R');
$pdf->SetFont('freesansb','',10);
$pdf->SetXY(40,75);
$pdf->MultiCell(150,30, $vendorinfo->company_name.", ИНН / КПП ".$vendorinfo->benef_swift." / 0, ",0,'L');
$pdf->SetXY(40,79);
$pdf->MultiCell(200,3,"", 0,'L');
$pdf->SetXY(40,83);
$pdf->MultiCell(150,3,"",", 0,'L');
$pdf->SetXY(40,87);
$pdf->MultiCell(150,6,"", 0,'L');
$pdf->SetXY(40,91);
$pdf->MultiCell(150,3, $vendorinfo->zip." ".$vendorinfo->city.", ".$vendorinfo->adress, 0,'L');
$pdf->SetXY(40,95);
$pdf->MultiCell(150,3, "",0,'L');
$pdf->SetXY(40,100);
if ($order->l_name) {$myl_name = " ";}
if ($order->f_name && $order->m_name) {$myf_name = " ";} else {$myf_name = ", ";}
if ($order->f_name && !$order->m_name) {$mym_name = "";} else {$mym_name = ", ";}
if ($order->state){$mystate = ", ";}
$client = $order->l_name.$myl_name.$order->f_name.$myf_name.$order->m_name.$mym_name.$order->zip." ".$order->state.$mystate."г. ".$order->city.", ".$order->street.", тел.: ".$order->phone.", ".$order->email;
$pdf->MultiCell(150,3, $client, 0,'L');
$pdf->SetDrawColor(0,0,0);
$pdf->SetFont('freesans','',7);
if ($vendorinfo->tax_number){
$pdf->SetXY(115,106);
$pdf->MultiCell(35, 4, _JSHOP_TAX_NUMBER, 1, 'L');
$pdf->SetXY(150,106);
$pdf->MultiCell(40, 4, $vendorinfo->tax_number, 1, 'R');
}
$pdf->setfillcolor(200,200,200);
$pdf->SetFont('freesansb','',7.5);
$pdf->SetXY(20,116);
$pdf->MultiCell(8, 4, 'N', 1, 'C');
$pdf->SetXY(50,116);
$pdf->MultiCell(79, 4, 'Товары (работы, услуги)', 1, 'C');
if ($jshopConfig->show_product_code_in_order){
$pdf->SetXY(28,116);
$pdf->MultiCell(22, 4, _JSHOP_EAN_PRODUCT, 1, 'C');
}
$pdf->SetXY(129,116);
$pdf->MultiCell(18, 4, _JSHOP_QUANTITY, 1, 'C');
$pdf->SetXY(147,116);
$pdf->MultiCell(25, 4, _JSHOP_SINGLEPRICE, 1, 'C');
$pdf->SetXY(172,116);
$pdf->MultiCell(18, 4,_JSHOP_TOTAL, 1,'C');
$y = 120;
$prodtot = 0;
$pn = 1;
foreach($order->products as $prod){
$pdf->SetFont('freesans','',8);
$pdf->SetXY(20, $y + 2);
$pdf->MultiCell(8, 4, $pn, 0, 'C');
$pn = $pn + 1;
$pdf->SetXY(50, $y + 2);
$pdf->MultiCell(79, 4, $prod->product_name, 0, 'L');
if ($prod->manufacturer!=''){
$pdf->SetXY(50, $pdf->getY());
$pdf->MultiCell(79, 4, _JSHOP_MANUFACTURER.": ".$prod->manufacturer, 0, 'L');
}
if ($prod->product_attributes!="" || $prod->product_freeattributes!="" || $prod->delivery_time || $prod->extra_fields!=''){
if ($prod->delivery_time){
$pdt = _JSHOP_DELIVERY_TIME.": ".$prod->delivery_time;
}else{
$pdt = "";
}
$pdf->SetXY(28, $pdf->getY());
$pdf->SetFont('freesans','',6);
$attribute = sprintAtributeInOrder($prod->product_attributes, "pdf");
$attribute .= sprintFreeAtributeInOrder($prod->product_freeattributes, "pdf");
$attribute .= sprintExtraFiledsInOrder($prod->extra_fields,"pdf");
$attribute .= $pdt;
$pdf->MultiCell(62, 4, $attribute, 0, 'L');
$pdf->SetFont('freesans','',7);
}
$y2 = $pdf->getY() + 2;
if ($jshopConfig->show_product_code_in_order){
$pdf->SetXY(28, $y + 2);
$pdf->MultiCell(22, 4, $prod->product_ean, 0, 'C');
$y3 = $pdf->getY() + 2;
}else{
$y3 = $pdf->getY();
}
$pdf->SetXY(129, $y + 2);
$pdf->MultiCell(18, 4, formatqty($prod->product_quantity).' '.$prod->product_qty_unit, 0 , 'C');
$y4 = $pdf->getY() + 2;
$pdf->SetXY(147, $y + 2);
$price = number_format($prod->product_item_price, 0, ',', ' ');
$pdf->MultiCell(25, 4, $price, 0 , 'C');
if ($jshopConfig->show_tax_product_in_cart && $prod->product_tax>0){
$pdf->SetXY(125, $y + 6);
$pdf->SetFont('freesans','',6);
$text = productTaxInfo($prod->product_tax, $order->display_price);
$pdf->MultiCell(25, 4, $text, 0 , 'L');
}
$y5 = $pdf->getY() + 2;
$pdf->SetFont('freesans','',7);
$pdf->SetXY(172, $y + 2);
$pdf->MultiCell(18, 4, formatprice($prod->product_quantity * $prod->product_item_price, $order->currency_code), 0 , 'C');
if ($jshopConfig->show_tax_product_in_cart && $prod->product_tax>0){
$pdf->SetXY(150, $y + 6);
$pdf->SetFont('freesans','',6);
$text = productTaxInfo($prod->product_tax, $order->display_price);
$pdf->MultiCell(40, 4, $text, 0 , 'R');
}
$y6 = $pdf->getY() + 2;
$yn = max($y2, $y3, $y4, $y5, $y6);
$pdf->Rect(20, $y, 170, $yn - $y );
//$pdf->Rect(20, $y, 170, $yn - $y );
//$pdf->Rect(20, $y, 130, $yn - $y );
//if ($jshopConfig->show_product_code_in_order){
//$pdf->line(85, $y, 85, $yn);
//}
$pdf->line(28, $y, 28, $yn);
$pdf->line(50, $y, 50, $yn);
$pdf->line(129, $y, 129, $yn);
$pdf->line(147, $y, 147, $yn);
$pdf->line(172, $y, 172, $yn);
$y = $yn;
if ($y > 260){
$pdf->addNewPage();
$y = 10;
}
$prodtot = $prodtot + 1;
}
if ($y > 240){
$pdf->addNewPage();
$y = 10;
}
$pdf->SetFont('freesans','',8);
if (($jshopConfig->hide_tax || count($order->order_tax_list)==0) && $order->order_discount==0 && $order->order_payment==0 && $jshopConfig->without_shipping) $hide_subtotal = 1; else $hide_subtotal = 0;
if (!$hide_subtotal){
$pdf->SetXY(20,$y);
/*$pdf->Rect(20,$y,170,5,'F');*/
$pdf->MultiCell(130,5,_JSHOP_SUBTOTAL,'0','R');
$pdf->SetXY(150,$y);
$pdf->MultiCell(40,5,formatprice($order->order_subtotal, $order->currency_code),'0','R');
}else{
$y = $y - 5;
}
if ($order->order_discount > 0){
$y = $y + 5;
$pdf->SetXY(20,$y);
/*$pdf->Rect(20,$y,170,5,'F');*/
$pdf->MultiCell(130,5,_JSHOP_RABATT_VALUE,'0','R');
$pdf->SetXY(150,$y);
$pdf->MultiCell(40,5, "-".formatprice($order->order_discount, $order->currency_code),'0','R');
}
if (!$jshopConfig->without_shipping){
$pdf->SetXY(20,$y + 5);
/*$pdf->Rect(20,$y + 5,170,5,'F');*/
$pdf->MultiCell(130,5,_JSHOP_SHIPPING_PRICE,'0','R');
$pdf->SetXY(150,$y + 5);
$pdf->MultiCell(40,5,formatprice($order->order_shipping, $order->currency_code),'0','R');
}else{
$y = $y - 5;
}
if ($order->order_payment != 0){
$y = $y + 5;
$pdf->SetXY(20,$y+5);
/*$pdf->Rect(20,$y+5,170,5,'F');*/
$pdf->MultiCell(130,5, $order->payment_name,'0','R');
$pdf->SetXY(150,$y+5);
$pdf->MultiCell(40,5, formatprice($order->order_payment, $order->currency_code), '0','R');
}
$show_percent_tax = 0;
if (count($order->order_tax_list)>1 || $jshopConfig->show_tax_in_product) $show_percent_tax = 1;
if ($jshopConfig->hide_tax) $show_percent_tax = 0;
//if (!$jshopConfig->hide_tax){
//foreach($order->order_tax_list as $percent=>$value){
$pdf->SetXY(20,$y + 10);
/*$pdf->Rect(20,$y + 10,170,5,'F');*/
$text = displayTotalCartTaxName($order->display_price);
//if ($show_percent_tax) $text = $text." ".formattax($percent)."%";
$pdf->MultiCell(130,5, 'НДС не облагается (НК ГЛ. 26.2 СТ. 346.11 П.3).','0','R');
$pdf->SetXY(150,$y + 10);
$pdf->MultiCell(40,5,formatprice($value, $order->currency_code),'0','R');
$y = $y + 5;
//}
// }
$pdf->SetXY(20 , $y+20);
$pdf->Cell(50 , 5 , 'Всего наименований ' .$prodtot. ' на сумму: ' .formatprice($order->order_total, $order->currency_code), '0' , 'L');
$m = new money2str();
$m = $m->work( $order->order_total , true );
$afm = mb_substr(trim($m),0,1,'UTF-8' ) ;
switch ($afm) {
case 'о':
$afm = 'О';
break;
case 'д':
$afm = 'Д';
break;
case 'т':
$afm = 'Т';
break;
case 'ч':
$afm = 'Ч';
break;
case 'п':
$afm = 'П';
break;
case 'ш':
$afm = 'Ш';
break;
case 'с':
$afm = 'С';
break;
case 'в':
$afm = 'В';
break;
case 'м':
$afm = 'М';
break;
default:
$afm = '';
}
$pdf->SetXY (20, $y+25);
$text_summa = substr_replace (trim($m), $afm, 0, 2);
$pdf->MultiCell(170,5, 'Итого: '.$text_summa , '0','');
$text_total = _JSHOP_ENDTOTAL;
if (($jshopConfig->show_tax_in_product || $jshopConfig->show_tax_product_in_cart) && (count($order->order_tax_list)>0)){
$text_total = _JSHOP_ENDTOTAL_INKL_TAX;
}
$pdf->SetFont('freesansb','',10);
$pdf->SetXY(20,$y + 10);
/*$pdf->Rect(20,$y + 10,170, 5.1,'F');*/
$pdf->MultiCell(130, 5 , $text_total,'0','R');
$pdf->SetXY(150,$y + 10);
$pdf->MultiCell(40,5,formatprice($order->order_total, $order->currency_code),'0','R');
if ($jshopConfig->display_tax_id_in_pdf && $order->tax_number){
//$y = $y+5.2;
$pdf->SetFont('freesans','',7);
$pdf->SetXY(20,$y + 10);
$pdf->MultiCell(170, 4 , _JSHOP_TAX_NUMBER.": ".$order->tax_number,'1','L');
}
if ($y > 240){
$pdf->addNewPage();
$y = 10;
}
$pdf->SetXY(20,$y + 30);
$pdf->MultiCell(170,5,'','0','L');
$pdf->SetFont('freesans','',9);
$pdf->SetXY(20,$y + 34);
$pdf->MultiCell(170,5,'','0','L');
/*********************************** Конец тела PDF ****************************************/
$name_pdf = $order->order_id."_".md5(uniqid(rand(0,100))).".pdf";
$dispatcher->trigger('onBeforeCreatePdfOrderEnd', array(&$order, &$pdf, &$name_pdf));
$pdf->Output($jshopConfig->pdf_orders_path."/".$name_pdf ,'F');
return $name_pdf;
}
?>