PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/opensourcepos/application/controllers/products.php

https://bitbucket.org/jit_bec/shopifine
PHP | 768 lines | 553 code | 108 blank | 107 comment | 60 complexity | c3c9ce89640a20c4ea37704a8f0910be MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. require_once ("secure_area.php");
  3. class Products extends Secure_area
  4. {
  5. const ID = "id";
  6. const PRODUCT_NAME = "product_name";
  7. const SYSTEM_NAME = "system_name";
  8. const DESC = "description";
  9. const BARCODE = "barcode";
  10. const MFR = "manufacturer";
  11. const MODEL = "model";
  12. const SUPPLIER = "supplier";
  13. function __construct()
  14. {
  15. parent::__construct('products');
  16. $this->load->model('Unitofmeasure');
  17. // $this->load->model('Category');
  18. $this->load->model('Packaging');
  19. $this->load->model('Manufacturer');
  20. $this->load->model('Mfr_model');
  21. // $this->load->model('Product');
  22. $this->load->model('Product_stock');
  23. $this->load->model('Product_price');
  24. $this->load->helper('grid_helper');
  25. $this->load->library('barcode-library/Barcode_lib','','barcode');
  26. }
  27. // function index()
  28. // {
  29. // $packageTypes = $this->Packaging->getAllPackageDetails();
  30. // $pkgOptions = null;
  31. //
  32. //
  33. // foreach($packageTypes as $packageType) {
  34. // $pkg_id=$packageType["package_id"];
  35. // $pkg_name=$packageType["package_name"];
  36. // $pkgOptions.="<OPTION VALUE=\"$pkg_id\">".$pkg_name;
  37. //
  38. // }
  39. //// $mfrs = $this->Manufacturer->getAllMfrs();
  40. ////
  41. //// foreach ($mfrs as &$mfr){
  42. //// $mfr = "\"".$mfr['manufacturer_name']."\"";
  43. //// }
  44. //// //$values = array_map('array_pop', $mfrs);
  45. //// $imploded = implode(",",$mfrs);
  46. //// $data['mfrs'] = $imploded;
  47. //
  48. // $mfrs = $this->Manufacturer->getAll();
  49. // $autoData = array();
  50. // foreach ($mfrs as $mfr){
  51. // $data = array('label' => $mfr['manufacturer_name'], 'value' => $mfr['id']);
  52. // array_push($autoData,$data);
  53. // }
  54. // $values = json_encode($autoData);
  55. // //$imploded = implode(",",$mfrs);
  56. // $data['mfrs'] = $values;
  57. //
  58. // $data['pkgOptions'] = $pkgOptions;
  59. // $this->load->view('products/product_details',$data);
  60. // }
  61. function index()
  62. {
  63. $packageTypes = $this->Packaging->getAllPackageDetails();
  64. $pkgOptions = null;
  65. $setOptions = null;
  66. foreach($packageTypes as $packageType) {
  67. $pkg_id=$packageType["package_id"];
  68. $pkg_name=$packageType["package_name"];
  69. $pkgOptions.="<OPTION VALUE=\"$pkg_id\">".$pkg_name;
  70. }
  71. //$values = json_encode($autoData);
  72. //$imploded = implode(",",$mfrs);
  73. $mfrArray = $this->Manufacturer->getAll();
  74. foreach ($mfrArray as $mfr){
  75. $mfr_id=$mfr["id"];
  76. $mfr_name=$mfr["manufacturer_name"];
  77. $mfrOptions.="<OPTION VALUE=\"$mfr_id\">".trim($mfr_name)."</OPTION>";
  78. }
  79. $data['mfrOptions'] = $mfrOptions;
  80. $attributeSets = $this->Attribute_set->getAll();
  81. foreach ($attributeSets as $set){
  82. // $mfr_id=$set["id"];
  83. $set_name=$set["attribute_set_name"];
  84. $setOptions.="<OPTION VALUE=\"$set_name\">".trim($set_name)."</OPTION>";
  85. }
  86. $data['attributeSetOptions'] = $setOptions;
  87. $data['pkgOptions'] = $pkgOptions;
  88. $this->load->view('products/products_grid',$data);
  89. }
  90. function populateMfrs(){
  91. $mfrs = $this->Manufacturer->getAll();
  92. foreach ($mfrs as $mfr){
  93. $mfr_id=$mfr["id"];
  94. $mfr_name=$mfr["manufacturer_name"];
  95. $mfrOptions.="<OPTION VALUE=\"$mfr_id\">".trim($mfr_name)."</OPTION>";
  96. }
  97. echo $mfrOptions;
  98. }
  99. function populatePackages(){
  100. $packageTypes = $this->Packaging->getAllPackageDetails();
  101. $pkgOptions = null;
  102. //$mfrOptions = null;
  103. foreach($packageTypes as $packageType) {
  104. $pkg_id=$packageType["package_id"];
  105. $pkg_name=$packageType["package_name"];
  106. $pkgOptions.="<OPTION VALUE=\"$pkg_id\">".$pkg_name;
  107. }
  108. echo $pkgOptions;
  109. }
  110. function populateMeasurementDropDowns(){
  111. $package_id = $_POST[pkgId];
  112. if (!empty($package_id)){
  113. $htmlUom = $this->getUOMDetails($package_id);
  114. echo $htmlUom;
  115. }
  116. }
  117. function populateMeasurementDropDownsByName(){
  118. $package_name = $_POST[pkgName];
  119. $package_id = $this->Packaging->getIdByPkgName($package_name);
  120. if (!empty($package_id)){
  121. $htmlUom = $this->getUOMDetails($package_id);
  122. echo $htmlUom;
  123. }
  124. }
  125. private function getUOMDetails($package_id){
  126. $uomJson = $this->Packaging->getJsonById($package_id);
  127. $uomArray = json_decode($uomJson,true);
  128. $uomList = array();
  129. $uomSizeMap = array();
  130. $htmlUom = null;
  131. foreach ($uomArray as $uomDetails){
  132. $thisUom = $uomDetails['uom'];
  133. //$uomId =
  134. $denom = $uomDetails['denom'];
  135. if (!in_array($thisUom, $uomList)){
  136. array_push($uomList, $thisUom);
  137. $htmlUom.="<OPTION VALUE=\"$thisUom\">".$thisUom;
  138. $uomSizeMap[$thisUom] = array(array('denom' => $denom));
  139. }
  140. else {
  141. array_push($uomSizeMap[$thisUom], array('denom' => $denom));
  142. }
  143. }
  144. session_start();
  145. $_SESSION['denomJson'] = json_encode($uomSizeMap);
  146. return $htmlUom;
  147. }
  148. function populateModel(){
  149. $mfr = $_POST[mfr];
  150. $models = $this->Mfr_model->getAllByMfrId($mfr);
  151. $htmlData= null;
  152. foreach ($models as $model){
  153. //$data = array('label' => $model['model_name'], 'value' => $model['id']);
  154. //array_push($autoData,$data);
  155. $id = $model['id'];
  156. $name = $model['model_name'];
  157. $htmlData.="<OPTION VALUE=\"$id\">".$name;
  158. }
  159. //$values = json_encode($autoData);
  160. echo $htmlData;
  161. }
  162. function populateBarcodesForStock(){
  163. $barcodeData = $this->Product_stock->getAll(false,null,1);
  164. $barcodeArray = array();
  165. foreach ($barcodeData as $barcoderow){
  166. array_push($barcodeArray,$barcoderow['barcode']);
  167. }
  168. return $barcodeArray;
  169. //echo json_encode($barcodeArray);
  170. }
  171. //hack for jqgrid dataUrl
  172. function doNothing (){
  173. }
  174. function populateDenomDropdown (){
  175. session_start();
  176. $uom = $_POST[uom];
  177. $htmlSize = null;
  178. if (isset($_SESSION['denomJson'])) {
  179. $allUomSizeMap = json_decode($_SESSION['denomJson'],true);
  180. //unset($_SESSION['denomJson']); //done. Now unset. very important
  181. $uomSizeMap = $allUomSizeMap[$uom];
  182. if (!empty($uomSizeMap)) {
  183. asort($uomSizeMap);
  184. foreach ($uomSizeMap as $validSize){
  185. $size = $validSize['denom'];
  186. $htmlSize.= "<OPTION VALUE=\"$size\">".$size;
  187. }
  188. }
  189. echo $htmlSize;
  190. }
  191. }
  192. function createBarcodeAndProduct(){
  193. $barCodedata = $_POST['barcodeData'];
  194. $barcode = null;
  195. $mfrCode =100;
  196. $modelCode = 100;
  197. $categoryCode = 100;
  198. // $supplierCode = 100;
  199. $uomCode = 10;
  200. $sizeCode = 10;
  201. $packageCode = 10;
  202. $modelName = null;
  203. $mfrName = null;
  204. $modelId = null;
  205. $mfrId = null;
  206. $systemName = null;
  207. $scannedBarcode = $barCodedata['scannedBarcode'];
  208. $name = $barCodedata['name'];
  209. $desc = $barCodedata['desc'];
  210. $mfrOp = $barCodedata['mfrOp'];
  211. $mfrIp = $barCodedata['mfrIp'];
  212. $modelOp = $barCodedata['modelOp'];
  213. $modelIp = $barCodedata['modelIp'];
  214. $newModelIp = $barCodedata['newModelIp'];
  215. $categoryArray = json_decode($barCodedata['category']);
  216. //$categoryIp = $barCodedata['categoryIp'];
  217. $supplierOp = $barCodedata['supplierOp'];
  218. $uomOp = $barCodedata['uomOp'];
  219. $sizeOp = $barCodedata['sizeOp'];
  220. $packageOp = $barCodedata['packageOp'];
  221. $reorderLevel = $barCodedata['reorderLevel'];
  222. $costPrice = $barCodedata['costPrice'];
  223. $price = $barCodedata['price'];
  224. $attributeSet = $barCodedata['attributeSet'];
  225. if (empty($reorderLevel)){
  226. $reorderLevel = 0;
  227. }
  228. if (!empty($mfrOp)){
  229. $mfrId = $mfrOp;
  230. $mfrCode += $mfrOp;
  231. if (!empty($modelOp)){
  232. $modelId = $modelOp;
  233. $modelCode += $modelOp;
  234. $modelName = $this->Mfr_model->getName($modelOp);
  235. }
  236. else {
  237. if (!empty($modelIp)){
  238. $modelData = array('manufacturer_id'=>$mfrId,'model_name' => $modelIp);
  239. $modelInsertId = $this->Mfr_model->insert($modelData);
  240. $modelId = $modelInsertId;
  241. $modelCode += $modelInsertId;
  242. $modelName = $modelIp;
  243. }
  244. }
  245. $mfrName = $this->Manufacturer->getName($mfrOp);
  246. }
  247. if (empty($mfrOp) && !empty($mfrIp)){
  248. $mfrData = array ('manufacturer_name'=>trim($mfrIp));
  249. $mfrName = $mfrIp;
  250. $mfrInsertId = $this->Manufacturer->insert($mfrData);
  251. $mfrCode += $mfrInsertId;
  252. $mfrId = $mfrInsertId;
  253. if ($mfrInsertId != 0 && $newModelIp!=""){
  254. $modelData = array('manufacturer_id'=>$mfrInsertId,'model_name' => trim($newModelIp));
  255. $modelInsertId = $this->Mfr_model->insert($modelData);
  256. $modelId = $modelInsertId;
  257. $modelCode += $modelInsertId;
  258. $modelName = $newModelIp;
  259. }
  260. }
  261. $categorymapping = array();
  262. if (!empty($categoryArray)){
  263. foreach($categoryArray as $category){
  264. $categoryCode += $category;
  265. $categoryDetails = $this->Category->getById($category);
  266. array_push($categorymapping,array('id'=>$category,'name'=> $categoryDetails['category_name']));
  267. }
  268. }
  269. //print_r(json_en$categorymapping);
  270. log_message('debug', json_encode($categorymapping));
  271. //
  272. // if (!empty($supplierOp)){
  273. // $supplierCode += $supplierOp;
  274. // }
  275. if (!empty($uomOp)){
  276. $uomCode += $uomOp;
  277. }
  278. if (!empty($sizeOp)){
  279. $sizeCode += $sizeOp;
  280. }
  281. if (!empty($packageOp)){
  282. $packageCode +=$packageOp;
  283. }
  284. $productid = $this->Product->lastIdPresent() + 1;
  285. if (empty($scannedBarcode)){
  286. $barcode = "1".$mfrCode. $modelCode.$packageCode .$uomCode.$sizeCode.$productid;
  287. }
  288. else {
  289. $barcode = $scannedBarcode;
  290. }
  291. //$ifexist = false;
  292. // if (empty($barcode)){
  293. // if (!empty($mfrId) && !empty($modelId)){
  294. // $where_clause_if_exist = array(
  295. //
  296. // 'manufacturer_id'=>$mfrId,
  297. // // 'category_id'=>$category,
  298. // 'model_id'=>$modelId,
  299. // 'package_id'=>$packageOp,
  300. // 'uom'=>$uomOp,
  301. // 'measurement_denomination'=>$sizeOp);
  302. // $barcodeExist = $this->Product->getBarcode($where_clause_if_exist);
  303. // if (!empty($barcodeExist)){
  304. // $response['status'] = 'error';
  305. // $response['message'] = 'The Product Your Are Trying To Add
  306. // Looks Like Already Exists.Please Check Barcode '.$barcodeExist;
  307. // echo json_encode($response);
  308. // return;
  309. // }
  310. // }
  311. // $where_clause_if_exist = array(
  312. //
  313. // 'product_name'=>$name);
  314. // $barcodeExist = $this->Product->getBarcode($where_clause_if_exist);
  315. // if (!empty($barcodeExist)){
  316. // $response['status'] = 'error';
  317. // $response['message'] = 'The Product Your Are Trying To Add
  318. // Looks Like Already Exists.Please Check Barcode '.$barcodeExist;
  319. // echo json_encode($response);
  320. // return;
  321. // }
  322. // }
  323. // else {
  324. $ifexist = $this->Product->ifExistsByBarcode($barcode);
  325. if ($ifexist){
  326. $response['status'] = 'error';
  327. $response['message'] = $barcode.' Already Exists';
  328. echo json_encode($response);
  329. return;
  330. }
  331. // }
  332. // $systemName = $name."-".$mfrName."-".$modelName."-".uom."-".$sizeOp;
  333. $this->db->trans_start();
  334. $productData = array('barcode'=>$barcode,
  335. 'product_name'=>$name,
  336. // 'system_name'=>$systemName,
  337. 'description'=>$desc,
  338. 'manufacturer'=>$mfrName,
  339. 'manufacturer_id'=>$mfrId,
  340. // 'category_id'=>$category,
  341. // 'category_name' => $categoryName,
  342. 'model'=>$modelName,
  343. 'model_id'=>$modelId,
  344. 'package_id'=>$packageOp,
  345. 'reorder_level'=>$reorderLevel,
  346. 'uom'=>$uomOp,
  347. 'attribute_set'=>$attributeSet,
  348. 'measurement_denomination'=>$sizeOp);
  349. $insertedProductId = $this->Product->insert($productData);
  350. $product_stock_data = array ('product_id'=>$insertedProductId,'barcode'=>$barcode);
  351. $this->Product_stock->insert($product_stock_data);
  352. $product_price_data = array ('product_id'=>$insertedProductId,'barcode'=>$barcode);
  353. if (!empty($costPrice)){
  354. $product_price_data['cost_price'] = $costPrice;
  355. }
  356. if (!empty($price)){
  357. $product_price_data['price'] = $price;
  358. }
  359. $this->Product_price->insert($product_price_data);
  360. foreach ($categorymapping as $mapping){
  361. $this->Category->saveProductCategoryMapping($mapping['id'],$insertedProductId,$mapping['name'],$barcode);
  362. }
  363. $this->db->trans_complete();
  364. if ($this->db->trans_status() === FALSE)
  365. {
  366. log_message('Product Insertion Failed');
  367. }
  368. $response['status'] = 'success';
  369. $response['message'] = 'Item '.$name. ' Has Been Successfully Added. The Barcode Is '.$barcode;
  370. echo json_encode($response);
  371. }
  372. function editProduct (){
  373. $mfrName = null;
  374. $modelName = null;
  375. $id = $_REQUEST[Products::ID];
  376. $mfrId = $_REQUEST[Products::MFR];
  377. $modelId = $_REQUEST[Products::MODEL];
  378. if (!empty($mfrId)) {
  379. $mfrName = $this->Manufacturer->getName($mfrId);
  380. }
  381. if (!empty($modelId)) {
  382. $modelName = $this->Mfr_model->getName($modelId);
  383. }
  384. $productData = array(
  385. Products::PRODUCT_NAME=>$_REQUEST[Products::PRODUCT_NAME],
  386. Products::DESC=>$_REQUEST[Products::DESC],
  387. 'manufacturer'=>$mfrName,
  388. 'manufacturer_id'=>$mfrId,
  389. 'model'=>$modelName,
  390. 'model_id'=>$modelId
  391. );
  392. $this->Product->update($id,$productData);
  393. }
  394. function populateProductsInGrid (){
  395. session_start();
  396. $searchOn = strip($_REQUEST['_search']);
  397. $page = $_REQUEST['page'];
  398. $limit = $_REQUEST['rows'];
  399. $sidx = $_REQUEST['sidx'];
  400. $sord = $_REQUEST['sord'];
  401. $loadAll = false;
  402. if (!empty($_REQUEST['loadall'])){
  403. $loadAll = $_REQUEST['loadall'];
  404. $_SESSION['load'] = true;
  405. }
  406. $productsdata = array();
  407. $count = $this->Product->totalNoOfRows();
  408. if( $count > 0 && $limit > 0) {
  409. $total_pages = ceil($count/$limit);
  410. } else {
  411. $total_pages = 0;
  412. }
  413. if ($page > $total_pages) $page=$total_pages;
  414. $start = $limit*$page - $limit;
  415. // if for some reasons start position is negative set it to 0
  416. // typical case is that the user type 0 for the requested page
  417. if($start <0) $start = 0;
  418. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  419. $data['total'] = $total_pages;
  420. $data['page'] = $page;
  421. $data['records'] = $count;
  422. if($searchOn=='true') {
  423. $sessionLoadAll = $_SESSION['load'];
  424. $filters = json_decode($_REQUEST['filters'],true);
  425. $groupOp = $filters['groupOp'];
  426. $rules = $filters['rules'];
  427. $where_condition = array();
  428. foreach ($rules as $rule){
  429. $field = $rule['field'];
  430. $op= $rule['op'];
  431. $input = $rule['data'];
  432. //$
  433. $where_condition[$field] = $input;
  434. }
  435. if ($sessionLoadAll){
  436. $products = $this->Product->getAllFlattenedByLike($where_condition,false,$clauses);
  437. }
  438. else {
  439. $products = $this->Product->getAllFlattenedByLike($where_condition,false,$clauses,1);
  440. }
  441. }
  442. else {
  443. if (empty($_REQUEST['loadall'])) {
  444. $_SESSION['load'] = false;
  445. }
  446. if ($loadAll){
  447. $products = $this->Product->getAllFlattened(false,$clauses);
  448. }
  449. else {
  450. $products = $this->Product->getAllFlattened(false,$clauses,1);
  451. }
  452. }
  453. //$dp['system_name']
  454. foreach ($products as $dp){
  455. array_push($productsdata, array('id'=> $dp['id'],'dprow' => array($dp['barcode'],/*$dp['system_name'],*/$dp['product_name'],$dp['description'],$dp['manufacturer_id'],$dp['model_id'],$dp['manufacturer'],$dp['model'],$dp['supplier'],$dp['package_id'],$dp['package_name'],/*$dp['category_name'],*/$dp['uom'],$dp['measurement_denomination'],'Print Barcode')));
  456. }
  457. $data['productdata'] = $productsdata;
  458. //$export = $_REQUEST['oper'];
  459. echo json_encode($data);
  460. }
  461. function deactivate(){
  462. $ids = $_POST[ids];
  463. $this->Product->deactivate($ids);
  464. }
  465. function activate(){
  466. $ids = $_POST[ids];
  467. $this->Product->activate($ids);
  468. }
  469. function exportProductsInGrid (){
  470. $export = $_REQUEST['oper'];
  471. if ($export =='csv')
  472. $searchOn = strip($_REQUEST['_search']);
  473. $productsdata = array();
  474. if($searchOn=='true') {
  475. $filters = json_decode($_REQUEST['filters'],true);
  476. $groupOp = $filters['groupOp'];
  477. $rules = $filters['rules'];
  478. $where_condition = array();
  479. foreach ($rules as $rule){
  480. $field = $rule['field'];
  481. $op= $rule['op'];
  482. $input = $rule['data'];
  483. //$
  484. $where_condition[$field] = $input;
  485. }
  486. $products = $this->Product->getAllFlattenedByLike($where_condition,true);
  487. }
  488. else {
  489. $products = $this->Product->getAllFlattened(true);
  490. }
  491. header("Content-type: application/octet-stream");
  492. header("Content-description: File Transfer");
  493. header("Content-disposition: attachment; filename=\"thefilename.csv\"");
  494. header("Pragma: public");
  495. header("Cache-control: max-age=0");
  496. header("Expires: 0");
  497. echo $products;
  498. }
  499. function loadInventory (){
  500. $data['barcodes'] = json_encode($this->populateBarcodesForStock());
  501. $this->load->view('products/product_stock_details',$data);
  502. }
  503. function populateProductStocksInGrid (){
  504. //session_start();
  505. $searchOn = strip($_REQUEST['_search']);
  506. $page = $_REQUEST['page'];
  507. $limit = $_REQUEST['rows'];
  508. $sidx = $_REQUEST['sidx'];
  509. $sord = $_REQUEST['sord'];
  510. $productsdata = array();
  511. $count = $this->Product_stock->totalNoOfRows();
  512. if( $count > 0 && $limit > 0) {
  513. $total_pages = ceil($count/$limit);
  514. } else {
  515. $total_pages = 0;
  516. }
  517. if ($page > $total_pages) $page=$total_pages;
  518. $start = $limit*$page - $limit;
  519. // if for some reasons start position is negative set it to 0
  520. // typical case is that the user type 0 for the requested page
  521. if($start <0) $start = 0;
  522. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  523. $data['total'] = $total_pages;
  524. $data['page'] = $page;
  525. $data['records'] = $count;
  526. if($searchOn=='true') {
  527. $filters = json_decode($_REQUEST['filters'],true);
  528. $groupOp = $filters['groupOp'];
  529. $rules = $filters['rules'];
  530. $where_condition = array();
  531. foreach ($rules as $rule){
  532. $field = $rule['field'];
  533. $op= $rule['op'];
  534. $input = $rule['data'];
  535. $where_condition[$field] = $input;
  536. }
  537. $products = $this->Product_stock->getAllByLike($where_condition,false,$clauses,1);
  538. }
  539. else {
  540. $products = $this->Product_stock->getAll(false,$clauses,1);
  541. }
  542. //$dp['system_name']
  543. foreach ($products as $dp){
  544. array_push($productsdata, array('id'=> $dp['id'],'dprow' => array($dp['product_id'],$dp['barcode'],$dp['system_name'],$dp['stock'],0,$dp['isactive'])));
  545. }
  546. $data['productdata'] = $productsdata;
  547. echo json_encode($data);
  548. }
  549. function updateStocks (){
  550. $id = strip($_REQUEST['id']);
  551. $oper = strip($_REQUEST['oper']);
  552. $stockAdd = strip($_REQUEST['stock_add']);
  553. $lastaction = 'added';
  554. $stockLevel = $this->Product_stock->getStockLevel('id',$id);
  555. $stockLevel += $stockAdd;
  556. $stock_data = array ('stock' => $stockLevel,'stock_added'=>$stockAdd,'last_action'=>$lastaction);
  557. $this->Product_stock->update($id,$stock_data);
  558. }
  559. function updateStocksByBarcode (){
  560. $barcode = strip($_REQUEST['barcode']);
  561. //$oper = strip($_REQUEST['oper']);
  562. $stockAdd = strip($_REQUEST['stock_add']);
  563. $lastaction = 'added';
  564. $stockLevel = $this->Product_stock->getStockLevel('barcode',$barcode);
  565. $stockLevel += $stockAdd;
  566. $stock_data = array ('stock' => $stockLevel,'stock_added'=>$stockAdd,'last_action'=>$lastaction);
  567. $this->Product_stock->updateByBarcode($barcode,$stock_data);
  568. }
  569. function printBarcode(){
  570. $id =$_REQUEST['id'];
  571. $barcodeArray = $this->Product->getValues(array("id"=>$id),array("barcode"));
  572. $barcode = $barcodeArray[0]["barcode"];
  573. $filename = IMAGEPATH.'temp/barcodefinal.png';
  574. $this->load->helper('file');
  575. delete_files($filename);
  576. if ( ! write_file($filename, ''))
  577. {
  578. echo 'Unable to write the file';
  579. }
  580. $this->barcode->generateBarcode($barcode,$filename);
  581. $data['filename'] = $filename;
  582. $this->load->view("utilities/barcode",$data);
  583. }
  584. function addcategoryToProduct () {
  585. log_message('debug','productop '. $_REQUEST['productOp']);
  586. log_message('debug','productIp '.$_REQUEST['productIp']);
  587. log_message('debug', 'category '.$_REQUEST['category']);
  588. $categoryArray = json_decode($_REQUEST['category']);
  589. if (!empty($categoryArray)){
  590. foreach($categoryArray as $category){
  591. $this->Category->saveProductCategoryMapping($category,$_REQUEST['productOp']);
  592. }
  593. }
  594. }
  595. function populateProductCategoryMapping () {
  596. $searchOn = strip($_REQUEST['_search']);
  597. $page = $_REQUEST['page'];
  598. $limit = $_REQUEST['rows'];
  599. $sidx = $_REQUEST['sidx'];
  600. $sord = $_REQUEST['sord'];
  601. $productcategorydata = array();
  602. $count = $this->Category->totalNoOfRowsInProductCategoryMapping();
  603. if( $count > 0 && $limit > 0) {
  604. $total_pages = ceil($count/$limit);
  605. } else {
  606. $total_pages = 0;
  607. }
  608. if ($page > $total_pages) $page=$total_pages;
  609. $start = $limit*$page - $limit;
  610. // if for some reasons start position is negative set it to 0
  611. // typical case is that the user type 0 for the requested page
  612. if($start <0) $start = 0;
  613. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  614. $data['total'] = $total_pages;
  615. $data['page'] = $page;
  616. $data['records'] = strval($count);
  617. if($searchOn=='true') {
  618. $filters = json_decode($_REQUEST['filters'],true);
  619. $groupOp = $filters['groupOp'];
  620. $rules = $filters['rules'];
  621. $like_condition = array();
  622. foreach ($rules as $rule){
  623. $field = $rule['field'];
  624. $op= $rule['op'];
  625. $input = $rule['data'];
  626. $like_condition[$field] = $input;
  627. }
  628. $productcategories = $this->Category->getAllProductCategoryMapping(false,null,$clauses,$like_condition);
  629. }
  630. else {
  631. $productcategories = $this->Category->getAllProductCategoryMapping(false,null,$clauses);
  632. }
  633. foreach ($productcategories as $dp){
  634. array_push($productcategorydata, array('id'=> $dp['id'],'dprow' => array($this->Product->getByProductId($dp['product_id'])->product_name,$dp['barcode'],$dp['product_id'],$dp['category_id'],$dp['category_name'])));
  635. }
  636. $data['productcategorydata'] = $productcategorydata;
  637. echo json_encode($data);
  638. }
  639. function loadProductCategoryMapping () {
  640. $productArray = $this->Product->getValues();
  641. foreach ($productArray as $product){
  642. //$data = array('label' => $model['model_name'], 'value' => $model['id']);
  643. //array_push($autoData,$data);
  644. $id = $product['id'];
  645. $name = $product['product_name'].'->'.$product['barcode'];
  646. $productOptions.="<OPTION VALUE=\"$id\">".$name;
  647. }
  648. $data['productOptions'] = $productOptions;
  649. $this->load->view("products/product_category_grid",$data);
  650. }
  651. function deleteProductCategoryMapping(){
  652. $ids = $_REQUEST['id'];
  653. $idAraay = explode(",", $ids);
  654. log_message('debug', explode(",", $idAraay));
  655. foreach ($idAraay as $id){
  656. $this->Category->deleteProductCategoryMapping($id);
  657. }
  658. }
  659. }
  660. ?>