PageRenderTime 32ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/fannie/admin/labels/pdf_layouts/WFC_Dark_ServiceCase_12UP.php

https://github.com/CORE-POS/IS4C
PHP | 348 lines | 275 code | 42 blank | 31 comment | 51 complexity | e7cfa99f23c70bdcc2e92092195ade6f MD5 | raw file
  1. <?php
  2. use COREPOS\Fannie\API\FanniePlugin;
  3. if (!class_exists('FpdfWithBarcode')) {
  4. include(dirname(__FILE__) . '/../FpdfWithBarcode.php');
  5. }
  6. if (!class_exists('FannieAPI')) {
  7. include(__DIR__ . '/../../classlib2.0/FannieAPI.php');
  8. }
  9. class WFC_Dark_ServiceCase_12UP_PDF extends FpdfWithBarcode
  10. {
  11. private $tagdate;
  12. public function setTagDate($str){
  13. $this->tagdate = $str;
  14. }
  15. public function barcodeText($x, $y, $h, $barcode, $len)
  16. {
  17. $this->SetFont('Arial','',8);
  18. $this->Text($x,$y-$h+(17/$this->k),substr($barcode,-$len).' '.$this->tagdate);
  19. }
  20. static public function stringToLines($string) {
  21. $length = strlen($string);
  22. $lines = array();
  23. // return 1 to 4 lines based on $desc size
  24. if ($length < 21) {
  25. $lines[] = $string;
  26. } else if ($length < 38) {
  27. $wrp = wordwrap($string, 19, "*", false);
  28. $lines = explode('*', $wrp);
  29. } else if ($length < 56) {
  30. $wrp = wordwrap($string, 19, "*", false);
  31. $lines = explode('*', $wrp);
  32. } else {
  33. $wrp = wordwrap($string, 19, "*", false);
  34. $lines = explode('*', $wrp);
  35. }
  36. return $lines;
  37. }
  38. }
  39. function WFC_Dark_ServiceCase_12UP ($data,$offset=0)
  40. {
  41. $dbc = FannieDB::get(FannieConfig::config('OP_DB'));
  42. $pdf = new WFC_Dark_ServiceCase_12UP_PDF('L','mm','Letter');
  43. $pdf->AddPage();
  44. $pdf->SetFillColor(0, 0, 0);
  45. $pdf->SetTextColor(255, 255, 255);
  46. define('FPDF_FONTPATH', __DIR__ . '/../../../modules/plugins2.0/CoopDealsSigns/noauto/fonts/');
  47. $pdf->AddFont('Gill', '', 'GillSansMTPro-Medium.php');
  48. $pdf->AddFont('Gill', 'B', 'GillSansMTPro-Heavy.php');
  49. $pdf->SetFont('Gill', 'B', 16);
  50. $width = 68;
  51. $height = 68;
  52. $left = 3;
  53. $top = 3;
  54. $guide = 0.3;
  55. $x = $left+$guide; $y = $top+$guide;
  56. $pdf->SetTopMargin($top);
  57. $pdf->SetLeftMargin($left);
  58. $pdf->SetRightMargin($left);
  59. $pdf->SetAutoPageBreak(False);
  60. $i = 0;
  61. foreach($data as $k => $row){
  62. if ($i % 12 == 0 && $i != 0) {
  63. $pdf->AddPage('L');
  64. $x = $left;
  65. $y = $top;
  66. $i = 0;
  67. }
  68. if ($i == 0) {
  69. $pdf = generateServiceCaseTag($x, $y, $guide, $width, $height, $pdf, $row, $dbc);
  70. } else if ($i % 4 == 0 && $i != 0) {
  71. $x = $left+$guide;
  72. $y += $height+$guide;
  73. } else {
  74. $x += $width+$guide;
  75. }
  76. $pdf = generateServiceCaseTag($x, $y, $guide, $width, $height, $pdf, $row, $dbc);
  77. $i++;
  78. }
  79. /*
  80. Print additional mirror images for back side of tags
  81. */
  82. $i = 0;
  83. $x = $left+$guide; $y = $top+$guide;
  84. if (count($data) % 4 != 0) {
  85. for ($j=count($data) % 4; $j<4; $j++) {
  86. $data[] = '';
  87. }
  88. }
  89. $data = arrayMirrorRowsServiceCase($data, 4);
  90. $pdf->AddPage('L');
  91. foreach($data as $k => $row){
  92. if ($i % 12 == 0 && $i != 0) {
  93. $pdf->AddPage('L');
  94. $x = $left;
  95. $y = $top;
  96. $i = 0;
  97. }
  98. if ($i == 0) {
  99. $pdf = generateMirrorTagServiceCase12($x, $y, $guide, $width, $height, $pdf, $row, $dbc);
  100. } else if ($i % 4 == 0 && $i != 0) {
  101. $x = $left+$guide;
  102. $y += $height+$guide;
  103. } else {
  104. $x += $width+$guide;
  105. }
  106. $pdf = generateMirrorTagServiceCase12($x, $y, $guide, $width, $height, $pdf, $row, $dbc);
  107. $i++;
  108. }
  109. $pdf = $pdf->Output();
  110. }
  111. function generateMirrorTagServiceCase12($x, $y, $guide, $width, $height, $pdf, $row, $dbc)
  112. {
  113. $upc = isset($row['upc']) ? $row['upc'] : '';
  114. $desc = isset($row['description']) ? $row['description'] : '';
  115. $size = isset($row['size']) ? $row['size'] : '';
  116. $pdf->SetFillColor(255, 255, 255);
  117. $pdf->SetTextColor(0, 0, 0);
  118. $pdf->SetFont('Gill','', 22); //Set the font
  119. $args = array($upc);
  120. $prep = $dbc->prepare("
  121. SELECT text
  122. FROM scaleItems
  123. WHERE plu = ?");
  124. $res = $dbc->execute($prep, $args);
  125. $array = $dbc->fetchRow($res);
  126. $ingr = $array ? $array['text'] : '';
  127. $lines = WFC_Dark_ServiceCase_12UP_PDF::stringToLines($desc);
  128. if (strstr($desc, "\r\n")) {
  129. $lines = explode ("\r\n", $desc);
  130. }
  131. $ingr = strtolower($ingr);
  132. $ingr = explode('contains', $ingr);
  133. $allergens = (isset($ingr[1])) ? ucfirst($ingr[1]) : '';
  134. $allergens = str_replace("\r\n", "", $allergens);
  135. $allergens = str_replace("\r", "", $allergens);
  136. $allergens = str_replace("\n", "", $allergens);
  137. $allergens = str_replace("\t", "", $allergens);
  138. $allergens = str_replace("\0", "", $allergens);
  139. $allergens = str_replace("\x0B", "", $allergens);
  140. $allergens = str_replace(":", "", $allergens);
  141. $allergens = "*".$allergens;
  142. // prep tag canvas
  143. $pdf->SetXY($x,$y);
  144. $pdf->Cell($width, $height, '', 0, 1, 'C', true);
  145. /*
  146. Add UPC Text
  147. */
  148. $pdf->SetXY($x,$y+4);
  149. $pdf->Cell($width, 8, substr($upc,3,4), 0, 1, 'C', true);
  150. /*
  151. Add Description Text
  152. */
  153. $pdf->SetFont('Gill','', 12); //Set the font
  154. $lineCount = count($lines);
  155. $temp_y = $y;
  156. $y = $y+15;
  157. foreach ($lines as $k => $line)
  158. $lines[$k] = strtoupper($line);
  159. if ($lineCount == 2) {
  160. $pdf->SetXY($x,$y+12);
  161. $pdf->Cell($width, 5, $lines[0], 0, 1, 'C', true);
  162. $pdf->SetXY($x, $y+19);
  163. $pdf->Cell($width, 5, $lines[1], 0, 1, 'C', true);
  164. } elseif ($lineCount == 3) {
  165. $pdf->SetXY($x,$y+8);
  166. $pdf->Cell($width, 5, $lines[0], 0, 1, 'C', true);
  167. $pdf->SetXY($x, $y+15);
  168. $pdf->Cell($width, 5, $lines[1], 0, 1, 'C', true);
  169. $pdf->SetXY($x, $y+22);
  170. $pdf->Cell($width, 5, $lines[2], 0, 1, 'C', true);
  171. } elseif ($lineCount == 4) {
  172. $pdf->SetXY($x,$y+4);
  173. $pdf->Cell($width, 5, $lines[0], 0, 1, 'C', true);
  174. $pdf->SetXY($x, $y+11);
  175. $pdf->Cell($width, 5, $lines[1], 0, 1, 'C', true);
  176. $pdf->SetXY($x, $y+18);
  177. $pdf->Cell($width, 5, $lines[2], 0, 1, 'C', true);
  178. $pdf->SetXY($x, $y+25);
  179. $pdf->Cell($width, 5, $lines[3], 0, 1, 'C', true);
  180. } else {
  181. $pdf->SetXY($x,$y+15);
  182. $pdf->Cell($width, 5, $lines[0], 0, 1, 'C', true);
  183. }
  184. $y = $temp_y;
  185. /*
  186. Add Allergens
  187. */
  188. if ($allergens != '*') {
  189. $pdf->SetXY($x,$y+45);
  190. $pdf->Cell($width, 5, $allergens, 0, 1, 'C', true);
  191. }
  192. /*
  193. Create Guide-Lines
  194. */
  195. $pdf->SetFillColor(155, 155, 155);
  196. // vertical
  197. $pdf->SetXY($width+$x, $y);
  198. $pdf->Cell($guide, $height+$guide, '', 0, 1, 'C', true);
  199. $pdf->SetXY($x-$guide, $y-$guide);
  200. $pdf->Cell($guide, $height+$guide, '', 0, 1, 'C', true);
  201. // horizontal
  202. $pdf->SetXY($x, $y-$guide);
  203. $pdf->Cell($width+$guide, $guide, '', 0, 1, 'C', true);
  204. $pdf->SetXY($x, $y+$height);
  205. $pdf->Cell($width+$guide, $guide, '', 0, 1, 'C', true);
  206. $pdf->SetFillColor(0, 0, 0);
  207. return $pdf;
  208. }
  209. function generateServiceCaseTag($x, $y, $guide, $width, $height, $pdf, $row, $dbc)
  210. {
  211. $upc = $row['upc'];
  212. $desc = $row['description'];
  213. $showPrice = FormLib::get('showPrice', false);
  214. $args = array($row['upc']);
  215. $prep = $dbc->prepare("
  216. SELECT pu.description, p.scale
  217. FROM productUser AS pu
  218. INNER JOIN products AS p ON pu.upc=p.upc
  219. WHERE pu.upc = ?");
  220. $res = $dbc->execute($prep, $args);
  221. $desc = $dbc->fetchRow($res);
  222. $desc = $desc['description'];
  223. $price = $row['normal_price'];
  224. $updateUpcs = FormLib::get('update_upc');
  225. $manualDescs = FormLib::get('update_desc');
  226. $MdescKey = array_search($upc, $updateUpcs);
  227. $Mdesc = $manualDescs[$MdescKey];
  228. $desc = $Mdesc;
  229. // prep tag canvas
  230. $pdf->SetXY($x,$y);
  231. $pdf->Cell($width, $height, '', 0, 1, 'C', true);
  232. $lines = WFC_Dark_ServiceCase_12UP_PDF::stringToLines($desc);
  233. if (strstr($desc, "\r\n")) {
  234. $lines = explode ("\r\n", $desc);
  235. }
  236. /*
  237. Add Description Text
  238. */
  239. $pdf->SetFont('Gill','B', 16); //Set the font
  240. $lineCount = count($lines);
  241. $temp_y = $y;
  242. $y = $y+15;
  243. if ($lineCount == 2) {
  244. $pdf->SetXY($x,$y+12);
  245. $pdf->Cell($width, 5, $lines[0], 0, 1, 'C', true);
  246. $pdf->SetXY($x, $y+19);
  247. $pdf->Cell($width, 5, $lines[1], 0, 1, 'C', true);
  248. } elseif ($lineCount == 3) {
  249. $pdf->SetXY($x,$y+8);
  250. $pdf->Cell($width, 5, $lines[0], 0, 1, 'C', true);
  251. $pdf->SetXY($x, $y+15);
  252. $pdf->Cell($width, 5, $lines[1], 0, 1, 'C', true);
  253. $pdf->SetXY($x, $y+22);
  254. $pdf->Cell($width, 5, $lines[2], 0, 1, 'C', true);
  255. } elseif ($lineCount == 4) {
  256. $pdf->SetXY($x,$y+4);
  257. $pdf->Cell($width, 5, $lines[0], 0, 1, 'C', true);
  258. $pdf->SetXY($x, $y+11);
  259. $pdf->Cell($width, 5, $lines[1], 0, 1, 'C', true);
  260. $pdf->SetXY($x, $y+18);
  261. $pdf->Cell($width, 5, $lines[2], 0, 1, 'C', true);
  262. $pdf->SetXY($x, $y+25);
  263. $pdf->Cell($width, 5, $lines[3], 0, 1, 'C', true);
  264. } else {
  265. $pdf->SetXY($x,$y+15);
  266. $pdf->Cell($width, 5, $lines[0], 0, 1, 'C', true);
  267. }
  268. $y = $temp_y;
  269. /*
  270. Add Price
  271. */
  272. if ($showPrice == 1) {
  273. $pdf->SetFont('Gill', 'B', 26);
  274. $pdf->SetXY($x,$y+47);
  275. $pdf->Cell($width, 5, "$".$price."/lb", 0, 1, 'C', true);
  276. $pdf->SetFont('Gill', 'B', 16);
  277. }
  278. /*
  279. Create Guide-Lines
  280. */
  281. $pdf->SetFillColor(155, 155, 155);
  282. // vertical
  283. $pdf->SetXY($width+$x, $y);
  284. $pdf->Cell($guide, $height+$guide, '', 0, 1, 'C', true);
  285. $pdf->SetXY($x-$guide, $y-$guide);
  286. $pdf->Cell($guide, $height+$guide, '', 0, 1, 'C', true);
  287. // horizontal
  288. $pdf->SetXY($x, $y-$guide);
  289. $pdf->Cell($width+$guide, $guide, '', 0, 1, 'C', true);
  290. $pdf->SetXY($x, $y+$height);
  291. $pdf->Cell($width+$guide, $guide, '', 0, 1, 'C', true);
  292. $pdf->SetFillColor(0, 0, 0);
  293. return $pdf;
  294. }
  295. function arrayMirrorRowsServiceCase($array, $cols)
  296. {
  297. $newArray = array();
  298. $chunks = array_chunk($array, $cols);
  299. foreach ($chunks as $chunk) {
  300. $chunk = array_reverse($chunk);
  301. foreach ($chunk as $v) {
  302. $newArray[] = $v;
  303. }
  304. }
  305. return $newArray;
  306. }