...

View Full Version : delete the 4 zeros in the description code



scott_white85
09-15-2011, 06:58 AM
how can i delete the 4 zeros in the description code? see the image below with the red highlight. code also included:

http://www.flotech.com.sg/delete/quote.jpg







<?php

$pdf->SetY($Y_Table_Position);
$pdf->SetX(6);
$num = $i + 1;
$pdf->MultiCell(9,6,$num,1,'C', '1');

$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);

$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->SetFillColor( 240, 240, 240 );
$pdf->Rect( 15, $Y_Table_Position, 83, 6,'F');

$attrcode=tep_db_query("SELECT orders_id, products_options_values_code FROM `orders_products_attributes` where orders_products_id = '".$order->products[$i]['jid']."'");


while($attrcodex = tep_db_fetch_array($attrcode)) {
if($attrcodex['products_options_values_code'] !=""){
$pdf->Write(6,$attrcodex['products_options_values_code']);
}
}




$attrcode2=tep_db_query("SELECT p.products_id, p.inv_code, p.products_jdesc, desc_line1, desc_line2, desc_line3, desc_line4, desc_line5, desc_line6, desc_line7, desc_line8, desc_line9, desc_line10, desc_line11, desc_line12, desc_line13, o.products_id FROM `products` p, `orders_products` o where orders_products_id = '".$order->products[$i]['jid']."' and o.products_id = p.products_id");
$attrcodex2 = tep_db_fetch_array($attrcode2);

if($attrcodex['products_options_values_code'] == ""){
$pdf->Write(6,$attrcodex2['inv_code']);
}


$pdf->SetY($Y_Table_Position);
$pdf->SetX(98);

$pdf->MultiCell(9,6,tep_display_tax_value($order->products[$i]['qty']),1,'C', '1');

$pdf->SetY($Y_Table_Position);
$pdf->SetX(107);


$wtotal = tep_db_query("SELECT * FROM `orders_products` WHERE orders_id='".$order->products[$i]['id']."'");
$countwtotal = tep_db_fetch_array($wtotal);

$computer = $order->products[$i]['total']+$order->products[$i]['weight'];

$weight = $computer*$order->products[$i]['qty'];

$pdf->MultiCell(20,6,$weight,1,'C', '1');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(127);


$jspecials = tep_db_query("SELECT p.deltime, count(p.products_id), s.products_id FROM `specials` s, `products` p WHERE s.products_id = '".$order->products[$i]['id']."' and p.products_id = '".$order->products[$i]['id']."'");
$jcountspec = tep_db_fetch_array($jspecials);
// Check first if X stock
if($jcountspec['count(p.products_id)'] == "1"){
$deltime = 'Ex-Stock';
} elseif ($jcountspec['deltime'] != "") {
$deltime = $jcountspec['deltime'];
} else {
$deltime = '6 - 8';
}


$pdf->MultiCell(23,6,$deltime,1,'C', '1');

$pdf->SetY($Y_Table_Position);
$pdf->SetX(150);
//$pdf->SetFont('Arial','',10);
$pdf->SetFont(PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);

$pdf->MultiCell(25,6,substr($order->products[$i]['final_price'], 0,-2),1,'C', '1');

$pdf->SetY($Y_Table_Position);
$pdf->SetX(175);
$pdf->MultiCell(22,6,str_replace('S$', '', $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty'])),1,'C', '1');

$item_count += 1 ;
$Y_Table_Position += 7;
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(150,6,'MODEL: '.strtoupper($order->products[$i]['name']),1,'L', '0');


//$Y_Table_Position += 7;
//$pdf->SetY($Y_Table_Position);
//$pdf->SetX(15);
//$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
//PDF_INV_PRODUCTS_TEXT_EFFECT,
// PDF_INV_PRODUCTS_TEXT_HEIGHT);
// show desc and brand
// $jorder = tep_db_query("SELECT products_id FROM `orders_products` WHERE orders_id ='".$HTTP_GET_VARS['order_id']."'");
// $jxorders = tep_db_fetch_array($jorder);

// $jproducts = tep_db_query("SELECT * FROM `products` WHERE products_id ='".$order->products[$i]['id']."'");
// $jxproducts = tep_db_fetch_array($jproducts);
// if($jxproducts['products_jbrand'] ==""){
// $jxout = '';
// $jyout = '';
// } else {
//$jxout = $jxproducts['products_jbrand'];
// $jyout = $jxproducts['products_jdesc'];
//}
// $pdf->MultiCell(69,6,'Brand: '.$jxout,1,'L', '');

//$Y_Table_Position += 7;
//$pdf->SetY($Y_Table_Position);
//$pdf->SetX(15);
//$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
// PDF_INV_PRODUCTS_TEXT_EFFECT,
// PDF_INV_PRODUCTS_TEXT_HEIGHT);
//$pdf->MultiCell(300,6,'Description: '."\n". $jyout,1,'L', '');
$item_count += 1 ;
$Y_Table_Position += 7;
$pdf->SetY($Y_Table_Position);
//get attribs
if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {

for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {

$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
if($order->products[$i]['attributes'][$j]['option'] !="Model"){

$pdf->MultiCell(150,4," - " .strtoupper($order->products[$i]['attributes'][$j]['option']) . ': ' . strtoupper($order->products[$i]['attributes'][$j]['value']), '0');


$Y_Table_Position += 4;
//Check for product line overflow
$item_count++;
if ( $item_count > 30) {
$pdf->AddPage();
//Fields Name position
$Y_Fields_Name_position = 120;
//Table position, under Fields Name
$Y_Table_Position = 109;
output_table_heading($Y_Table_Position);
$item_count = 1;
$text_color=explode(",",PDF_INV_PRODUCTS_TEXT_COLOR );
$pdf->SetTextColor(0, 0, 0);

$text_color=explode(",",PDF_INV_PRODUCTS_LINE_COLOR );
$pdf->SetDrawColor( 0, 0, 0 );
}
}
}


}



$attrcode=tep_db_query("SELECT p.products_id, p.inv_code, p.products_jdesc, desc_line1, desc_line2, desc_line3, desc_line4, desc_line5, desc_line6, desc_line7, desc_line8, desc_line9, desc_line10, desc_line11, desc_line12, desc_line13, o.products_id FROM `products` p, `orders_products` o where orders_products_id = '".$order->products[$i]['jid']."' and o.products_id = p.products_id");
$attrcodex = tep_db_fetch_array($attrcode);
if($attrcodex['products_jdesc'] == "1"){

if($attrcodex['desc_line1'] != ""){
$item_count += 1 ;
$Y_Table_Position += 0;
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'- '.strtoupper($attrcodex['desc_line1']), '0');
}

if($attrcodex['desc_line2'] != ""){
if(strlen($attrcodex['desc_line1']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line1']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'- '.strtoupper($attrcodex['desc_line2']), '0');
}

if($attrcodex['desc_line3'] != ""){
if(strlen($attrcodex['desc_line2']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line2']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line3']), '0');
}

if($attrcodex['desc_line4'] != ""){
if(strlen($attrcodex['desc_line3']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line3']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line4']), '0');
}

if($attrcodex['desc_line5'] != ""){
if(strlen($attrcodex['desc_line4']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line4']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line5']), '0');
}

if($attrcodex['desc_line6'] != ""){
if(strlen($attrcodex['desc_line5']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line5']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line6']), '0');
}

if($attrcodex['desc_line7'] != ""){
if(strlen($attrcodex['desc_line6']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line6']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line7']), '0');
}

if($attrcodex['desc_line8'] != ""){
if(strlen($attrcodex['desc_line7']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line7']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line8']), '0');
}

if($attrcodex['desc_line9'] != ""){
if(strlen($attrcodex['desc_line8']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line8']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line9']), '0');
}

if($attrcodex['desc_line10'] != ""){
if(strlen($attrcodex['desc_line9']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line9']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line10']), '0');
}

if($attrcodex['desc_line11'] != ""){
if(strlen($attrcodex['desc_line10']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line10']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line11']), '0');
}

if($attrcodex['desc_line12'] != ""){
if(strlen($attrcodex['desc_line11']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line11']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line12']), '0');
}


if($attrcodex['desc_line13'] != ""){
if(strlen($attrcodex['desc_line12']) > 150 ){
$item_count += 2 ;
$Y_Table_Position += 8;
} elseif(strlen($attrcodex['desc_line12']) > 300 ){
$item_count += 3 ;
$Y_Table_Position += 12;
} else {
$item_count += 1 ;
$Y_Table_Position += 4;
}
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->MultiCell(170,4,'-'.strtoupper($attrcodex['desc_line13']), '0');
}

}

$item_count += 1 ;
$Y_Table_Position += 7;
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->MultiCell(150,4,'', '0');
//$pdf->MultiCell(150,4,$order->products[$i]['jid'], '0');
//testing
//$Y_Table_Position += 7;
//$pdf->SetY($Y_Table_Position);
//$pdf->SetX(15);
//$pdf->MultiCell(150,4,$order->products[$i]['jid'], '0');
// end









//Check for product line overflow
$item_count += 1;
// if ((is_long($item_count / 32) && $i >= 20) || ($i == 20)){
if ( $item_count > 30 ) {
$pdf->AddPage();

//Fields Name position
$Y_Fields_Name_position = 120;
//Table position, under Fields Name
$Y_Table_Position = 109;
output_table_heading($Y_Table_Position);
//if ($i == 20)

$text_color=explode(",",PDF_INV_PRODUCTS_TEXT_COLOR );
$pdf->SetTextColor(0, 0, 0);
$item_count = 1;
$text_color=explode(",",PDF_INV_PRODUCTS_LINE_COLOR );
$pdf->SetDrawColor( 0, 0, 0 );

}
}
$item_count = 1;
$pdf->SetFont( PDF_INV_ORDERTOTAL1_TEXT_FONT,
PDF_INV_ORDERTOTAL1_TEXT_EFFECT,
PDF_INV_ORDERTOTAL1_TEXT_HEIGHT);

$text_color=explode(",",PDF_INV_ORDERTOTAL1_TEXT_COLOR );
$pdf->SetTextColor(0, 0, 0);




?>

gvre
09-15-2011, 08:10 AM
Use
substr($description, 0, -4); You should change $description with your real variable name.

scott_white85
09-15-2011, 08:15 AM
where can i insert that code? kindly see the attach code. the variable name is products_options_values_code.

morongo47
09-15-2011, 09:03 AM
If you know what string your char data is in, you could shorten it by X chars like this:


//take 4 chars off the end
$string = substr($string, 0, -4);

Conversely, if 4 is positive, it takes the chars off the start.

If all you need is a shortened display for the pdf, this would do it, however if you need this format to persist in a db table, you need to re-write your product codes (from what I can gather).

(I see gvre beat me to it)

scott_white85
09-15-2011, 09:18 AM
can you look at the code to where i can insert that one. the variable name is products_options_values_code



$pdf->SetFont( PDF_INV_PRODUCTS_TEXT_FONT,
PDF_INV_PRODUCTS_TEXT_EFFECT,
PDF_INV_PRODUCTS_TEXT_HEIGHT);
$pdf->SetFillColor( 240, 240, 240 );
$pdf->Rect( 15, $Y_Table_Position, 83, 6,'F');

$attrcode=tep_db_query("SELECT orders_id, products_options_values_code FROM `orders_products_attributes` where orders_products_id = '".$order->products[$i]['jid']."'");


while($attrcodex = tep_db_fetch_array($attrcode)) {
if($attrcodex['products_options_values_code'] !=""){
$pdf->Write(6,$attrcodex['products_options_values_code']);
}
}




$attrcode2=tep_db_query("SELECT p.products_id, p.inv_code, p.products_jdesc, desc_line1, desc_line2, desc_line3, desc_line4, desc_line5, desc_line6, desc_line7, desc_line8, desc_line9, desc_line10, desc_line11, desc_line12, desc_line13, o.products_id FROM `products` p, `orders_products` o where orders_products_id = '".$order->products[$i]['jid']."' and o.products_id = p.products_id");
$attrcodex2 = tep_db_fetch_array($attrcode2);

if($attrcodex['products_options_values_code'] == ""){
$pdf->Write(6,$attrcodex2['inv_code']);
}


$pdf->SetY($Y_Table_Position);
$pdf->SetX(98);

$pdf->MultiCell(9,6,tep_display_tax_value($order->products[$i]['qty']),1,'C', '1');

morongo47
09-15-2011, 09:21 AM
Around line 23, save the the array value $attrcodex['products_options_values_code'] to a string:


$string=$attrcodex['products_options_values_code'];

Now perform the substr() on $string.
Next write it to the pdf invoice.


$pdf->Write(6,$string);


Try it before you use it on customers.

scott_white85
09-15-2011, 09:49 AM
it doesnt work, i tried to insert the code based on your suggestion. see the bold text below.



$attrcode=tep_db_query("SELECT orders_id, products_options_values_code FROM `orders_products_attributes` where orders_products_id = '".$order->products[$i]['jid']."'");


while($attrcodex = tep_db_fetch_array($attrcode)) {
if($attrcodex['products_options_values_code'] !=""){
$pdf->Write(6,$attrcodex['products_options_values_code']);
}
}




$attrcode2=tep_db_query("SELECT p.products_id, p.inv_code, p.products_jdesc, desc_line1, desc_line2, desc_line3, desc_line4, desc_line5, desc_line6, desc_line7, desc_line8, desc_line9, desc_line10, desc_line11, desc_line12, desc_line13, o.products_id FROM `products` p, `orders_products` o where orders_products_id = '".$order->products[$i]['jid']."' and o.products_id = p.products_id");
$attrcodex2 = tep_db_fetch_array($attrcode2);

$string=$attrcodex['products_options_values_code'];
$string = substr($string, 0, -4);

if($attrcodex['products_options_values_code'] == ""){
$pdf->Write(6,$attrcodex2['inv_code']);
$pdf->Write(6,$string);
}

morongo47
09-15-2011, 07:13 PM
Scott, you're still writing the original array value to the invoice, but I messed up too, it looks like we need to work on $attrcodex2['inv_code'], so...



if($attrcodex['products_options_values_code'] == ""){

//you don't want to write this anymore...$workstring replaces it
//$pdf->Write(6,$attrcodex2['inv_code']);

//instead, copy this value to our own string
$string=$attrcodex2['inv_code'];

//now, knock 4 chars off the end...
$workstring = substr($string, 0, -4);

//write our work-string out...
$pdf->Write(6,$workstring);

}//if



Try that...

Delete the other stuff you copied in, it's not doing anything except cluttering your code.

To avoid further confusion, the above code -replaces- the last 'if(){}' statement in your previous post.
.

.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum