From 4332bce401e4727e2784204bb7149bb743e395aa Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Mon, 9 Feb 2015 18:08:46 +0100 Subject: [PATCH] Replace old code39 generator for receipts with new barcode_lib functionality --- application/controllers/receivings.php | 4 +- application/controllers/sales.php | 3 + application/libraries/Barcode_lib.php | 7 +- application/views/barcode.php | 362 ----------------------- application/views/receivings/receipt.php | 3 +- application/views/sales/receipt.php | 3 +- 6 files changed, 14 insertions(+), 368 deletions(-) delete mode 100644 application/views/barcode.php diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index 4b8f6a776..80d46e0d7 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -270,6 +270,7 @@ class Receivings extends Secure_area function receipt($receiving_id) { + $this->load->library('barcode_lib'); $receiving_info = $this->Receiving->get_info($receiving_id)->row_array(); $this->receiving_lib->copy_entire_receiving($receiving_id); $data['cart']=$this->receiving_lib->get_cart(); @@ -283,7 +284,8 @@ class Receivings extends Secure_area $emp_info=$this->Employee->get_info($receiving_info['employee_id']); $data['payment_type']=$receiving_info['payment_type']; $data['invoice_number']=$this->receiving_lib->get_invoice_number(); - + $barcode_config=array('barcode_type'=>1,'barcode_width'=>180, 'barcode_height'=>30, 'barcode_quality'=>100); + $data['barcode']=$this->barcode_lib->generate_barcode($receiving_id,$barcode_config); $data['employee']=$emp_info->first_name.' '.$emp_info->last_name; if($supplier_id!=-1) diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 1e16f0849..dbbf19a47 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -297,6 +297,7 @@ class Sales extends Secure_area function receipt($sale_id) { + $this->load->library('barcode_lib'); $sale_info = $this->Sale->get_info($sale_id)->row_array(); $this->sale_lib->copy_entire_sale($sale_id); $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); @@ -321,6 +322,8 @@ class Sales extends Secure_area $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; } $data['sale_id']='POS '.$sale_id; + $barcode_config=array('barcode_type'=>1,'barcode_width'=>180, 'barcode_height'=>30, 'barcode_quality'=>100); + $data['barcode']=$this->barcode_lib->generate_barcode($sale_id,$barcode_config); $this->load->view("sales/receipt",$data); $this->sale_lib->clear_all(); $this->_remove_duplicate_cookies(); diff --git a/application/libraries/Barcode_lib.php b/application/libraries/Barcode_lib.php index 2e07a6d96..efe08f139 100644 --- a/application/libraries/Barcode_lib.php +++ b/application/libraries/Barcode_lib.php @@ -37,7 +37,7 @@ class Barcode_lib return $data; } - private function generate_barcode($item, $barcode_config) + function generate_barcode($barcode_content, $barcode_config) { if ($barcode_config['barcode_type'] == '1') { @@ -47,8 +47,8 @@ class Barcode_lib { $barcode = new emberlabs\Barcode\Code128(); } - $barcode_content = $this->CI->Appconfig->get('barcode_content') === "id" ? $item['item_id'] : $item['item_number']; $barcode->setData($barcode_content); + $barcode->setQuality($barcode_config['barcode_quality']); $barcode->setDimensions($barcode_config['barcode_width'], $barcode_config['barcode_height']); $barcode->draw(); return $barcode->base64(); @@ -59,7 +59,8 @@ class Barcode_lib $display_table = ""; $display_table .= ""; - $barcode = $this->generate_barcode($item,$barcode_config); + $barcode_content=$this->CI->Appconfig->get('barcode_content') === "id" ? $item['item_id'] : $item['item_number']; + $barcode = $this->generate_barcode($barcode_content,$barcode_config); $display_table .= ""; $display_table .= ""; $display_table .= ""; diff --git a/application/views/barcode.php b/application/views/barcode.php deleted file mode 100644 index 0a7d772e3..000000000 --- a/application/views/barcode.php +++ /dev/null @@ -1,362 +0,0 @@ -=1 to enable - - - NOTE: You must have GD-1.8 or higher compiled into PHP - in order to use PNG and JPEG. GIF images only work with - GD-1.5 and lower. (http://www.boutell.com) - - - ANOTHER NOTE: If you actually intend to print the barcodes - and scan them with a scanner, I highly recommend choosing - JPEG with a quality of 100. Most browsers can't seem to print - a PNG without mangling it beyond recognition. - - - USAGE EXAMPLES FOR ANY PLAIN OLD HTML DOCUMENT: - ----------------------------------------------- - - - - - - - - -*/ -/*=============================================================================*/ - - -//----------------------------------------------------------------------------- -// Startup code -//----------------------------------------------------------------------------- - - -if(isset($_GET["text"])) $text=$_GET["text"]; -if(isset($_GET["format"])) $format=$_GET["format"]; -if(isset($_GET["quality"])) $quality=$_GET["quality"]; -if(isset($_GET["width"])) $width=$_GET["width"]; -if(isset($_GET["height"])) $height=$_GET["height"]; -if(isset($_GET["type"])) $type=$_GET["type"]; -if(isset($_GET["barcode"])) $barcode=$_GET["barcode"]; - - -if(isset($_POST["text"])) $text=$_POST["text"]; -if(isset($_POST["format"])) $format=$_POST["format"]; -if(isset($_POST["quality"])) $quality=$_POST["quality"]; -if(isset($_POST["width"])) $width=$_POST["width"]; -if(isset($_POST["height"])) $height=$_POST["height"]; -if(isset($_POST["type"])) $type=$_POST["type"]; -if(isset($_POST["barcode"])) $barcode=$_POST["barcode"]; - - -if (!isset ($text)) $text = ''; -if (!isset ($type)) $type = 1; -if (empty ($quality)) $quality = 100; -if (empty ($width)) $width = 160; -if (empty ($height)) $height = 80; -if (!empty ($format)) $format = strtoupper ($format); - else $format="PNG"; - - -switch ($type) -{ - default: - $type = 1; - case 1: - Barcode39 ($barcode, $width, $height, $quality, $format, $text); - break; -} - - -//----------------------------------------------------------------------------- -// Generate a Code 3 of 9 barcode -//----------------------------------------------------------------------------- -function Barcode39 ($barcode, $width, $height, $quality, $format, $text) -{ - switch ($format) - { - default: - $format = "JPEG"; - case "JPEG": - header ("Content-type: image/jpeg"); - break; - case "PNG": - header ("Content-type: image/png"); - break; - case "GIF": - header ("Content-type: image/gif"); - break; - } - - - $im = ImageCreate ($width, $height) - or die ("Cannot Initialize new GD image stream"); - $White = ImageColorAllocate ($im, 255, 255, 255); - $Black = ImageColorAllocate ($im, 0, 0, 0); - //ImageColorTransparent ($im, $White); - ImageInterLace ($im, 1); - - - - $NarrowRatio = 20; - $WideRatio = 55; - $QuietRatio = 35; - - - $nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio)); - $Pixels = $width / $nChars; - $NarrowBar = (int)(20 * $Pixels); - $WideBar = (int)(55 * $Pixels); - $QuietBar = (int)(35 * $Pixels); - - - $ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2); - - if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0)) - { - ImageString ($im, 1, 0, 0, "Image is too small!", $Black); - OutputImage ($im, $format, $quality); - exit; - } - - $CurrentBarX = (int)(($width - $ActualWidth) / 2); - $Color = $White; - $BarcodeFull = "*".strtoupper ($barcode)."*"; - settype ($BarcodeFull, "string"); - - $FontNum = 3; - $FontHeight = ImageFontHeight ($FontNum); - $FontWidth = ImageFontWidth ($FontNum); - if (!empty($text)) - { - $CenterLoc = (int)(($width) / 2) - (int)(($FontWidth * strlen($text)) / 2); - ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$text", $Black); - } - else - { - $FontHeight=-2; - } - - - for ($i=0; $i diff --git a/application/views/receivings/receipt.php b/application/views/receivings/receipt.php index b5ae89423..920a789b5 100644 --- a/application/views/receivings/receipt.php +++ b/application/views/receivings/receipt.php @@ -103,7 +103,8 @@ if (isset($error_message)) config->item('return_policy')); ?>
- "; ?> +
+
load->view("partial/footer"); ?> diff --git a/application/views/sales/receipt.php b/application/views/sales/receipt.php index d66b13875..ea955fd5e 100644 --- a/application/views/sales/receipt.php +++ b/application/views/sales/receipt.php @@ -110,7 +110,8 @@ if (isset($error_message)) config->item('return_policy')); ?>
- "; ?> +
+
load->view("partial/footer"); ?>
". $this->manage_display_layout($barcode_config['barcode_first_row'], $item, $barcode_config)."
". $this->manage_display_layout($barcode_config['barcode_second_row'], $item, $barcode_config)."
". $this->manage_display_layout($barcode_config['barcode_third_row'], $item, $barcode_config)."