PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/opensourcepos/application/controllers/utilities.php

https://bitbucket.org/jit_bec/shopifine
PHP | 1018 lines | 685 code | 173 blank | 160 comment | 93 complexity | a55974ffe45306b7003172badee503a5 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. //delete after test
  3. //require_once BASEPATH .'libraries/Zend/Acl.php';
  4. //require_once BASEPATH .'libraries/Zend/Exception.php';
  5. //require_once BASEPATH .'libraries/Zend/Acl/Role/Interface.php';
  6. //require_once BASEPATH .'libraries/Zend/Acl/Role.php';
  7. //require_once BASEPATH .'libraries/Zend/Acl/Resource/Interface.php';
  8. //require_once BASEPATH .'libraries/Zend/Acl/Resource.php';
  9. //require_once BASEPATH .'libraries/Zend/Acl/Exception.php';
  10. //require_once BASEPATH .'libraries/Zend/Acl/Role/Registry.php';
  11. //require_once BASEPATH .'libraries/Zend/Acl/Role/Registry/Exception.php';
  12. //require_once BASEPATH .'libraries/Zend/Acl/Assert/Interface.php';
  13. //delete
  14. require_once ("secure_area.php");
  15. class Utilities extends Secure_area
  16. {
  17. private $user;
  18. private $username;
  19. const SIZE ='size';
  20. const UOM ='uom';
  21. function __construct()
  22. {
  23. parent::__construct('utilities');
  24. //$this->load->model('Invoice_master');
  25. //$this->load->model('Invoice_item');
  26. $this->load->model('Delivery_vehicle');
  27. $this->load->model('Delivery_point');
  28. $this->load->model('Unitofmeasure');
  29. $this->load->model('Packaging');
  30. $this->load->model('Manufacturer');
  31. $this->load->model('Mfr_model');
  32. $this->load->model('Product');
  33. $this->load->helper('grid_helper');
  34. $this->load->model('Invoice_master');
  35. $this->load->model('Invoice_item');
  36. $this->load->model('acl/Permission','Permission');
  37. $this->load->model('acl/User','Userview');
  38. $this->load->model('acl/Role','Role');
  39. // require_once('class/BCGFontFile.php');
  40. // require_once('class/BCGColor.php');
  41. // require_once('class/BCGDrawing.php');
  42. //
  43. // // Including the barcode technology
  44. // require_once('class/BCGcode39.barcode.php');
  45. $this->load->library('barcode-library/Barcode_lib','','barcode');
  46. $param = array('user' => 'admin');
  47. $this->load->library('acl-library/Acl',$param,'acl');
  48. //$this->load->model('Shipment_master');
  49. // $this->user= $this->Employee->get_logged_in_employee_info();
  50. // $this->username = $this->user->last_name." ".$this->user->first_name;
  51. //$param = array('user' => 'admin');
  52. //$this->load->library('Acl',$param);
  53. // $this->load->library('sale_lib');
  54. }
  55. function index (){
  56. $data['numdp'] = $this->Delivery_point->totalNoOfRows();
  57. $data['nummfr']= $this->Manufacturer->totalNoOfRows();
  58. $data['nummodel'] = $this->Mfr_model->totalNoOfRows();
  59. $data['numuom']= $this->Unitofmeasure->totalNoOfRows();
  60. $data['numpkg']= $this->Packaging->totalNoOfRows();
  61. $this->load->view("utilities/dashboard",$data);
  62. }
  63. function createDeliveryPoint (){
  64. $name = $_POST['name'];
  65. $delivery_point_data = array ('name'=> $name,
  66. 'address'=> $_POST['address'],
  67. 'city'=> $_POST['city'],
  68. 'postcode'=> $_POST['pin'],
  69. 'contact_number'=> $_POST['contactNumber']);
  70. $status = $this->Delivery_point->insert($delivery_point_data);
  71. if ($status) {
  72. $data['message'] = "Delivery Point $name is successfully created ";
  73. $this->load->view("common/message",$data);
  74. }
  75. }
  76. function createMeasurementUnits (){
  77. $name = $_POST['name'];
  78. $denom = $_POST['denom'];
  79. $status = $this->createMeasurementUnitsGeneric($name,$denom);
  80. $data['message'] = $status['message'];
  81. $this->load->view("common/message",$data);
  82. }
  83. private function createMeasurementUnitsGeneric($name,$denom){
  84. $error = false;
  85. if ($this->Unitofmeasure->exists($name)){
  86. $json = $this->Unitofmeasure->getJson($name);
  87. $array = json_decode($json,true);
  88. if (!in_array(array(Utilities::SIZE => $denom), $array)){
  89. array_push($array,array(Utilities::SIZE => $denom));
  90. $encoded_denom = json_encode($array);
  91. $data = array ('denom_json' => $encoded_denom);
  92. $status = $this->Unitofmeasure->update($name,$data);
  93. if ($status ){
  94. $message = "This denomination $denom for $name is updated";
  95. }
  96. else {
  97. $message = "Error in updating denomination $denom for $name";
  98. $error = true;
  99. }
  100. }
  101. else {
  102. $message = "This denomination $denom for $name already exists";
  103. }
  104. }
  105. else {
  106. $encoded_denom = json_encode(array(array(Utilities::SIZE => $denom)));
  107. $data = array ('unit_of_measure' =>$name,'denom_json' => $encoded_denom);
  108. $status = $this->Unitofmeasure->insert($data);
  109. if ($status){
  110. $message = "This denomination $denom for $name is successfully created";
  111. }
  112. else {
  113. $message = "Error in creating denomination";
  114. $error = true;
  115. }
  116. }
  117. return array('message'=>$message,'error'=> $error);
  118. }
  119. function loadDeliveryPoint (){
  120. //$data['invoiceListSession'] =$_SESSION['invoiceList'];
  121. // = $this->Delivery_point->getmagentotest();
  122. $data['total']=$total;
  123. $this->load->view("utilities/add_delivery_point",$data);
  124. }
  125. function loadPackage (){
  126. //$data['invoiceListSession'] =$_SESSION['invoiceList'];
  127. $packageTypes = $this->Packaging->getAllPackageDetails();
  128. $options = null;
  129. foreach($packageTypes as $packageType) {
  130. $name=$packageType["package_name"];
  131. $thing=$packageType["package_type"];
  132. $options.="<OPTION VALUE=\"$name\">".$name;
  133. $arr[$name] = $thing;
  134. }
  135. $data['options'] = $options;
  136. $data['packageMap'] = json_encode($arr);
  137. $denoms = $this->Unitofmeasure->getAll();
  138. foreach($denoms as $denom) {
  139. $uom=$denom["unit_of_measure"];
  140. //$value = $denom["denom_json"];
  141. if (!empty($uom)){
  142. $uomOptions.="<OPTION VALUE=\"$uom\">".$uom;
  143. }
  144. }
  145. $data['uomOptions'] = $uomOptions;
  146. $typeOptions = null;
  147. $types = $this->Packaging->getAllPackageTypes();
  148. foreach($types as $type) {
  149. $thing=$type["package_type"];
  150. if (!empty($thing)){
  151. $typeOptions.="<OPTION VALUE=\"$thing\">".$thing;
  152. }
  153. }
  154. $data['typeOptions'] = $typeOptions;
  155. $this->load->view("utilities/add_packaging",$data);
  156. }
  157. function loadSize ($uomOp){
  158. $htmlSize = null;
  159. $uomSizeMap = json_decode($this->Unitofmeasure->getJson($uomOp),true);
  160. if (!empty($uomSizeMap)){
  161. asort($uomSizeMap);
  162. $htmlSize = "<OPTION VALUE=\"0\">"."Choose";
  163. foreach ($uomSizeMap as $validSize){
  164. $size = $validSize['size'];
  165. if (!empty($size)){
  166. $htmlSize.= "<OPTION VALUE=\"$size\">".$size;
  167. }
  168. }
  169. }
  170. echo $htmlSize;
  171. }
  172. function loadMeasurementUnit (){
  173. //$data['invoiceListSession'] =$_SESSION['invoiceList'];
  174. $this->load->view("utilities/add_measurement_units");
  175. }
  176. function loadMfrModel (){
  177. $mfrTypes = $this->Manufacturer->getAll();
  178. $options = null;
  179. foreach($mfrTypes as $mfrType) {
  180. $id=$mfrType["id"];
  181. $name=$mfrType["manufacturer_name"];
  182. $options.="<OPTION VALUE=\"$id\">".$name;
  183. }
  184. $data['options'] = $options;
  185. $this->load->view("utilities/add_manufacturer_model",$data);
  186. }
  187. function createPackagingUnits (){
  188. //$isnewPackage = $_POST['newPkHidden'];
  189. //$isnewUOM = $_POST['newUnitHidden'];
  190. $name = $_POST['packageOptions'];
  191. if (empty($name)){
  192. $name = $_POST['namePkg'];
  193. }
  194. $uom= $_POST['uomOp'];
  195. $denom = $_POST['sizeOp'];
  196. if (empty($uom) || empty($denom)){
  197. $uom = $_POST['uomIp'];
  198. $denom = $_POST['denomIp'];
  199. $status= $this->createMeasurementUnitsGeneric($uom,$denom);
  200. $error = $status['error'];
  201. $message = $status['message'];
  202. if ($error){
  203. $data['message'] = $message;
  204. $this->load->view("common/message",$data);
  205. return;
  206. }
  207. }
  208. $desc = $_POST['desc'];
  209. $type = $_POST['typeOp'];
  210. if ($this->Packaging->exists($name)){
  211. $json = $this->Packaging->getJson($name);
  212. $array = json_decode($json,true);
  213. if (!in_array(array('uom' => $uom,
  214. 'denom' => $denom), $array)){
  215. array_push($array,array('uom' => $uom,
  216. 'denom' => $denom));
  217. $encoded_denom = json_encode($array);
  218. $data = array ('applicable_uom_json' => $encoded_denom,'package_description'=>$desc);
  219. $status = $this->Packaging->update($name,$data);
  220. if ($status ){
  221. $message = "This package $name is updated";
  222. }
  223. else {
  224. $message = "Error in updating $name package";
  225. }
  226. }
  227. else {
  228. $message = "This denomination $denom for $name already exists";
  229. }
  230. }
  231. else {
  232. $encoded_denom = json_encode(array(array('uom' => $uom,
  233. 'denom' => $denom)));
  234. $data = array ('package_name' =>$name,'applicable_uom_json' => $encoded_denom,'package_description'=>$desc,'package_type' =>$type);
  235. $status = $this->Packaging->insert($data);
  236. if ($status){
  237. $message = "This denomination $denom for $name is successfully created";
  238. }
  239. else {
  240. $message = "Error in creating denomination";
  241. }
  242. }
  243. $data['message'] = $message;
  244. $this->load->view("common/message",$data);
  245. }
  246. function createMfrModel (){
  247. //$isnewPackage = $_POST['newPkHidden'];
  248. //$isnewUOM = $_POST['newUnitHidden'];
  249. $newMfr = false;
  250. $mfrId = $_POST['mfrOptions'];
  251. if (empty($mfrId)){
  252. $mfrName = $_POST['nameMfr'];
  253. $descMfr= $_POST['mfrDesc'];
  254. $newMfr = true;
  255. }
  256. $modelName = $_POST['modelName'];
  257. $modelDesc = $_POST['modelDesc'];
  258. $this->db->trans_start();
  259. if ($newMfr){
  260. $mfrData = array ('manufacturer_name' =>$mfrName,'description'=>$descMfr);
  261. $mfrId = $this->Manufacturer->insert($mfrData);
  262. }
  263. $modelData = array('manufacturer_id' => $mfrId,'model_name'=>$modelName,'description'=> $modelDesc);
  264. $this->Mfr_model->insert($modelData);
  265. $this->db->trans_complete();
  266. if ($this->db->trans_status() === FALSE)
  267. {
  268. //echo $this->db->_error_message();
  269. $message= 'Model and manufacturer could not be added. Database Opearation Failed';
  270. }
  271. else {
  272. $message= 'Model and manufacturer successfully added';
  273. }
  274. $data['message'] = $message;
  275. $this->load->view("common/message",$data);
  276. }
  277. function test(){
  278. //$data['invoiceListSession'] =$_SESSION['invoiceList'];
  279. $this->load->view("utilities/test");
  280. // $uomJson = $this->Packaging->getJsonById('6');
  281. // $uomArray = json_decode($uomJson,true);
  282. // //var_dump($uomArray);
  283. // $uomList = array();
  284. // $uomSizeMap = array();
  285. // $htmlUom = null;
  286. //
  287. // foreach ($uomArray as $uomDetails){
  288. // $thisUom = $uomDetails['uom'];
  289. // $denom = $uomDetails['denom'];
  290. // if (!in_array($thisUom, $uomList)){
  291. // array_push($uomList, $thisUom);
  292. // $htmlUom.="<OPTION VALUE=\"$thisUom\">".$thisUom;
  293. // $uomSizeMap[$thisUom] = array(array('denom' => $denom));
  294. // }
  295. // else {
  296. // array_push($uomSizeMap[$thisUom], array('denom' => $denom));
  297. // }
  298. // }
  299. // //var_dump ($uomList);
  300. // //var_dump ($htmlUom);
  301. // var_dump (json_encode($uomSizeMap));
  302. }
  303. function populateDeliveryPoint (){
  304. // standard request parameters
  305. $searchOn = strip($_REQUEST['_search']);
  306. $page = $_REQUEST['page'];
  307. $limit = $_REQUEST['rows'];
  308. $sidx = $_REQUEST['sidx'];
  309. $sord = $_REQUEST['sord'];
  310. //standard response parameters
  311. $deliverypointdata = array();
  312. $count = $this->Delivery_point->totalNoOfRows();
  313. if( $count > 0 && $limit > 0) {
  314. $total_pages = ceil($count/$limit);
  315. } else {
  316. $total_pages = 0;
  317. }
  318. if ($page > $total_pages) $page=$total_pages;
  319. $start = $limit*$page - $limit;
  320. // if for some reasons start position is negative set it to 0
  321. // typical case is that the user type 0 for the requested page
  322. if($start <0) $start = 0;
  323. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  324. $data['total'] = $total_pages;
  325. $data['page'] = $page;
  326. $data['records'] = $count;
  327. $searchOn = strip($_REQUEST['_search']);
  328. if($searchOn=='true') {
  329. $filters = json_decode($_REQUEST['filters'],true);
  330. $groupOp = $filters['groupOp'];
  331. $rules = $filters['rules'];
  332. $where_condition = array();
  333. foreach ($rules as $rule){
  334. $field = $rule['field'];
  335. $op= $rule['op'];
  336. $input = $rule['data'];
  337. $where_condition[$field]=$input;
  338. }
  339. $deliveryPoints = $this->Delivery_point->getAll(false,$clauses,$where_condition);
  340. }
  341. else {
  342. $deliveryPoints = $this->Delivery_point->getAll();
  343. }
  344. foreach ($deliveryPoints as $dp){
  345. array_push($deliverypointdata, array('id'=> $dp['id'],'dprow' => array($dp['name'],$dp['address'],$dp['city'],$dp['postcode'],$dp['contact_number'])));
  346. }
  347. $data['deliverypointdata'] = $deliverypointdata;
  348. echo json_encode($data);
  349. }
  350. function updateDeliverypoints (){
  351. $id = strip($_REQUEST['id']);
  352. $oper = strip($_REQUEST['oper']);
  353. $name = strip($_REQUEST['name']);
  354. $address = strip($_REQUEST['address']);
  355. $city = strip($_REQUEST['city']);
  356. $postcode = strip($_REQUEST['postcode']);
  357. $contact_number = strip($_REQUEST['contact_number']);
  358. $dp_data = array ('name' => $name,'address'=>$address,'city'=>$city,'postcode'=>$postcode,'contact_number'=>$contact_number);
  359. $this->Delivery_point->update($id,$dp_data);
  360. }
  361. function populateMfrs (){
  362. // standard request parameters
  363. $searchOn = strip($_REQUEST['_search']);
  364. $page = $_REQUEST['page'];
  365. $limit = $_REQUEST['rows'];
  366. $sidx = $_REQUEST['sidx'];
  367. $sord = $_REQUEST['sord'];
  368. //standard response parameters
  369. $mfrsdata = array();
  370. $count = $this->Manufacturer->totalNoOfRows();
  371. if( $count > 0 && $limit > 0) {
  372. $total_pages = ceil($count/$limit);
  373. } else {
  374. $total_pages = 0;
  375. }
  376. if ($page > $total_pages) $page=$total_pages;
  377. $start = $limit*$page - $limit;
  378. // if for some reasons start position is negative set it to 0
  379. // typical case is that the user type 0 for the requested page
  380. if($start <0) $start = 0;
  381. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  382. $data['total'] = $total_pages;
  383. $data['page'] = $page;
  384. $data['records'] = $count;
  385. $searchOn = strip($_REQUEST['_search']);
  386. if($searchOn=='true') {
  387. $filters = json_decode($_REQUEST['filters'],true);
  388. $groupOp = $filters['groupOp'];
  389. $rules = $filters['rules'];
  390. $where_condition = array();
  391. foreach ($rules as $rule){
  392. $field = $rule['field'];
  393. $op= $rule['op'];
  394. $input = $rule['data'];
  395. $where_condition[$field]=$input;
  396. }
  397. $mfrs = $this->Manufacturer->getAll(false,$clauses,$where_condition);
  398. }
  399. else {
  400. $mfrs = $this->Manufacturer->getAll();
  401. }
  402. foreach ($mfrs as $dp){
  403. array_push($mfrsdata, array('id'=> $dp['id'],'dprow' => array($dp['manufacturer_name'],$dp['description'])));
  404. }
  405. $data['mfrdata'] = $mfrsdata;
  406. echo json_encode($data);
  407. }
  408. function updateMfrs (){
  409. $id = strip($_REQUEST['id']);
  410. $oper = strip($_REQUEST['oper']);
  411. $name = strip($_REQUEST['manufacturer_name']);
  412. $desc = strip($_REQUEST['description']);
  413. $mfr_data = array ('manufacturer_name' => $name,'description'=>$desc);
  414. $this->Manufacturer->update($id,$mfr_data);
  415. }
  416. function populateModels (){
  417. // standard request parameters
  418. $searchOn = strip($_REQUEST['_search']);
  419. $page = $_REQUEST['page'];
  420. $limit = $_REQUEST['rows'];
  421. $sidx = $_REQUEST['sidx'];
  422. $sord = $_REQUEST['sord'];
  423. //standard response parameters
  424. $mfrsdata = array();
  425. $count = $this->Mfr_model->totalNoOfRows();
  426. if( $count > 0 && $limit > 0) {
  427. $total_pages = ceil($count/$limit);
  428. } else {
  429. $total_pages = 0;
  430. }
  431. if ($page > $total_pages) $page=$total_pages;
  432. $start = $limit*$page - $limit;
  433. // if for some reasons start position is negative set it to 0
  434. // typical case is that the user type 0 for the requested page
  435. if($start <0) $start = 0;
  436. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  437. $data['total'] = $total_pages;
  438. $data['page'] = $page;
  439. $data['records'] = $count;
  440. $searchOn = strip($_REQUEST['_search']);
  441. if($searchOn=='true') {
  442. $filters = json_decode($_REQUEST['filters'],true);
  443. $groupOp = $filters['groupOp'];
  444. $rules = $filters['rules'];
  445. $where_condition = array();
  446. foreach ($rules as $rule){
  447. $field = $rule['field'];
  448. $op= $rule['op'];
  449. $input = $rule['data'];
  450. $where_condition[$field]=$input;
  451. }
  452. $mfrs = $this->Mfr_model->getAll(false,$clauses,$where_condition);
  453. }
  454. else {
  455. $mfrs = $this->Mfr_model->getAll();
  456. }
  457. foreach ($mfrs as $dp){
  458. array_push($mfrsdata, array('id'=> $dp['id'],'dprow' => array($dp['model_name'],$dp['description'],$dp['manufacturer_id'],$dp['manufacturer_name'])));
  459. }
  460. $data['modeldata'] = $mfrsdata;
  461. echo json_encode($data);
  462. }
  463. function updateModels (){
  464. $id = strip($_REQUEST['id']);
  465. $oper = strip($_REQUEST['oper']);
  466. $name = strip($_REQUEST['model_name']);
  467. $desc = strip($_REQUEST['description']);
  468. $mfr_id = strip($_REQUEST['manufacturer']);
  469. $model_data = array ('model_name' => $name,'description'=>$desc,'manufacturer_id'=>$mfr_id);
  470. $this->Mfr_model->update($id,$model_data);
  471. }
  472. function populatePackageInGrid (){
  473. // standard request parameters
  474. $searchOn = strip($_REQUEST['_search']);
  475. $page = $_REQUEST['page'];
  476. $limit = $_REQUEST['rows'];
  477. $sidx = $_REQUEST['sidx'];
  478. $sord = $_REQUEST['sord'];
  479. //standard response parameters
  480. $pkgsdata = array();
  481. $count = $this->Packaging->totalNoOfRows();
  482. if( $count > 0 && $limit > 0) {
  483. $total_pages = ceil($count/$limit);
  484. } else {
  485. $total_pages = 0;
  486. }
  487. if ($page > $total_pages) $page=$total_pages;
  488. $start = $limit*$page - $limit;
  489. // if for some reasons start position is negative set it to 0
  490. // typical case is that the user type 0 for the requested page
  491. if($start <0) $start = 0;
  492. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  493. $data['total'] = $total_pages;
  494. $data['page'] = $page;
  495. $data['records'] = $count;
  496. $searchOn = strip($_REQUEST['_search']);
  497. if($searchOn=='true') {
  498. $filters = json_decode($_REQUEST['filters'],true);
  499. $groupOp = $filters['groupOp'];
  500. $rules = $filters['rules'];
  501. $where_condition = array();
  502. foreach ($rules as $rule){
  503. $field = $rule['field'];
  504. $op= $rule['op'];
  505. $input = $rule['data'];
  506. $where_condition[$field]=$input;
  507. }
  508. $pkgs = $this->Packaging->getAll(false,$clauses,$where_condition);
  509. }
  510. else {
  511. $pkgs = $this->Packaging->getAll();
  512. }
  513. foreach ($pkgs as $dp){
  514. array_push($pkgsdata, array('package_id'=> $dp['package_id'],'dprow' => array($dp['package_name'],$dp['package_description'],$dp['package_type'])));
  515. }
  516. $data['packagingdata'] = $pkgsdata;
  517. echo json_encode($data);
  518. }
  519. function populateUomInSubgrid(){
  520. //$searchOn = strip($_REQUEST['_search']);
  521. $page = $_REQUEST['page'];
  522. $limit = $_REQUEST['rows'];
  523. $id= $_REQUEST['id'];
  524. //standard response parameters
  525. $uomsdata = array();
  526. $uomsarray = $this->Packaging->getAllUoms($id);
  527. $count = count($uomsarray);
  528. if( $count > 0 && $limit > 0) {
  529. $total_pages = ceil($count/$limit);
  530. } else {
  531. $total_pages = 0;
  532. }
  533. if ($page > $total_pages) $page=$total_pages;
  534. //$start = $limit*$page - $limit;
  535. // if for some reasons start position is negative set it to 0
  536. // typical case is that the user type 0 for the requested page
  537. //if($start <0) $start = 0;
  538. //$clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  539. $data['total'] = $total_pages;
  540. $data['page'] = $page;
  541. $data['records'] = $count;
  542. $count = 1;
  543. foreach ($uomsarray as $dp){
  544. array_push($uomsdata, array('id'=> $count++,'dprow' => array($dp['denom'],$dp['uom'])));
  545. }
  546. $data['uomdata'] = $uomsdata;
  547. echo json_encode($data);
  548. }
  549. function updatePackages (){
  550. $id = strip($_REQUEST['id']);
  551. $oper = strip($_REQUEST['oper']);
  552. $name = strip($_REQUEST['package_name']);
  553. $desc = strip($_REQUEST['package_description']);
  554. $type = strip($_REQUEST['package_type']);
  555. $dp_data = array ('package_description'=>$desc,'package_type'=>$type);
  556. $this->Packaging->updateById($id,$dp_data);
  557. }
  558. function populatePackageTypesEdit (){
  559. $typeOptions = null;
  560. $types = $this->Packaging->getAllPackageTypes();
  561. foreach($types as $type) {
  562. $thing=$type["package_type"];
  563. if (!empty($thing)){
  564. $typeOptions.="<OPTION VALUE=\"$thing\">".$thing;
  565. }
  566. }
  567. echo $typeOptions;
  568. }
  569. function populateUoms (){
  570. $page = $_REQUEST['page'];
  571. $limit = $_REQUEST['rows'];
  572. $id= $_REQUEST['id'];
  573. $uomsdata = array();
  574. $uoms = $this->Unitofmeasure->getAll();
  575. $count = 0;
  576. foreach ($uoms as $uom){
  577. $uomName = $uom['unit_of_measure'];
  578. $denoms = json_decode($uom['denom_json'],true);
  579. foreach ($denoms as $dp){
  580. array_push($uomsdata, array('id'=> ++$count,'dprow' => array($dp['size'],$uomName)));
  581. }
  582. }
  583. if( $count > 0 && $limit > 0) {
  584. $total_pages = ceil($count/$limit);
  585. } else {
  586. $total_pages = 0;
  587. }
  588. if ($page > $total_pages) $page=$total_pages;
  589. $data['total'] = $total_pages;
  590. $data['page'] = $page;
  591. $data['records'] = $count;
  592. $data['uomdata'] = $uomsdata;
  593. echo json_encode($data);
  594. }
  595. function edittest (){
  596. // $invoices = $this->Invoice_master->getUnprocessedInvoicesFromMagento();
  597. // //var_dump($invoices) ;
  598. // foreach ($invoices as $inv){
  599. // $inv_entity_id = $inv['entity_id'];
  600. // $inv_increment_id = $inv['invoice_increment_id'];
  601. // $order_id = $inv['order_id'];
  602. // $order_increment_id = $inv['order_increment_id'];
  603. // $items = $this->Invoice_item->getUnprocessedInvoiceItemsFromMagento($inv_entity_id);
  604. // var_dump($items);
  605. // echo 'next'.'<br/>';
  606. // }
  607. // $filename = $this->barcode->generateBarcode('test');
  608. $filename = '/var/www/opensourcepos/images/temp/barcode5.png';
  609. $this->load->helper('file');
  610. delete_files($filename);
  611. if ( ! write_file($filename, ''))
  612. {
  613. echo 'Unable to write the file';
  614. }
  615. $this->barcode->generateBarcode('18000012020303030',$filename);
  616. //$searchOn = $this->Strip($_REQUEST['_search']);
  617. //echo $this->Product->lastIdPresent();
  618. //$csv = $this->Delivery_point->getAllCsv();
  619. //$data = 'Some file data';
  620. //header("Content-Type: image/png");
  621. // header("Content-description: File Transfer");
  622. // header("Content-disposition: attachment; filename=\"thefilename.csv\"");
  623. // header("Pragma: public");
  624. // header("Cache-control: max-age=0");
  625. // header("Expires: 0");
  626. //$output = fopen('php://output','w');
  627. //fputcsv($output,$csv);
  628. //echo $csv;
  629. $this->load->view("utilities/test",$data);
  630. //echo $csv;
  631. }
  632. function roleTest (){
  633. //$this->acl->listRoles();
  634. //$this->load->view("acl/user_grid");
  635. $this->load->view("utilities/test");
  636. // var_dump($acl);
  637. // $acl = new Zend_Acl();
  638. // $acl->addRole('abc');
  639. // $acl->addRole('abc', 'xyz');
  640. // if (empty($acl->getRoles())) {
  641. // echo 'empty';
  642. // }
  643. // else {
  644. // echo 'ne';
  645. // }
  646. // //var_dump(count());
  647. }
  648. function populateUser(){
  649. $searchOn = strip($_REQUEST['_search']);
  650. $page = $_REQUEST['page'];
  651. $limit = $_REQUEST['rows'];
  652. $sidx = $_REQUEST['sidx'];
  653. $sord = $_REQUEST['sord'];
  654. $usersdata = array();
  655. $count = $this->Userview->totalNoOfRowsUsersView();
  656. if( $count > 0 && $limit > 0) {
  657. $total_pages = ceil($count/$limit);
  658. } else {
  659. $total_pages = 0;
  660. }
  661. if ($page > $total_pages) $page=$total_pages;
  662. $start = $limit*$page - $limit;
  663. // if for some reasons start position is negative set it to 0
  664. // typical case is that the user type 0 for the requested page
  665. if($start <0) $start = 0;
  666. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  667. $data['total'] = $total_pages;
  668. $data['page'] = $page;
  669. $data['records'] = $count;
  670. if($searchOn=='true') {
  671. $filters = json_decode($_REQUEST['filters'],true);
  672. $groupOp = $filters['groupOp'];
  673. $rules = $filters['rules'];
  674. $like_condition = array();
  675. foreach ($rules as $rule){
  676. $field = $rule['field'];
  677. $op= $rule['op'];
  678. $input = $rule['data'];
  679. $like_condition[$field] = $input;
  680. }
  681. $users = $this->Userview->getAllUsersView(false,null,$clauses,$like_condition);
  682. }
  683. else {
  684. $users = $this->Userview->getAllUsersView(false,null,$clauses);
  685. }
  686. //$dp['system_name']
  687. foreach ($users as $dp){
  688. array_push($usersdata, array('id'=> $dp['person_id'],'dprow' => array($dp['username'],$dp['role_name'],$dp['first_name'],$dp['last_name'],$dp['phone_number'],$dp['email'])));
  689. }
  690. $data['userdata'] = $usersdata;
  691. echo json_encode($data);
  692. }
  693. function populateRolesEdit (){
  694. $roleOptions = null;
  695. $roles = $this->Role->getAll();
  696. foreach($roles as $role) {
  697. $name=$role["role_name"];
  698. $id=$role["id"];
  699. if (!empty($name)){
  700. $roleOptions.="<OPTION VALUE=\"$id\">".$name;
  701. }
  702. }
  703. echo $roleOptions;
  704. }
  705. public function testSelect(){
  706. $test = $_REQUEST['test'] ;
  707. define('FPDF_FONTPATH',$this->config->item('fonts_path'));
  708. $this->load->library('fpdf','','pdf');
  709. // $this->load->library('rotation');
  710. // $this->load->library('pdf','','pdf');
  711. $this->pdf->AddPage();
  712. $this->pdf->SetFont('Arial','B',16);
  713. $this->pdf->Cell(40,10,'Hello World!');
  714. $this->pdf->Output('/tmp/test.pdf', 'F');
  715. }
  716. // public function importCategories(){
  717. // $status = $this->Category->importCategories();
  718. // log_message('debug', 'status of import '.$status);
  719. // }
  720. public function loadCat(){
  721. $this->load->view("utilities/add_category");
  722. }
  723. public function renderParents(){
  724. /* [
  725. {
  726. "data" : "Search engines",
  727. "attr": {id:"23"},
  728. "children" :[
  729. {"data":"Yahoo", "metadata":{"href":"http://www.yahoo.com"}},
  730. {"data":"Bing", "metadata":{"href":"http://www.bing.com"}},
  731. {"data":"Google",
  732. "children":[{"data":"Youtube", "metadata":{"href":"http://youtube.com"}},{"data":"Gmail", "metadata":{"href":"http://www.gmail.com"}},{"data":"Orkut","metadata":{"href":"http://www.orkut.com"}}], "metadata" : {"href":"http://youtube.com"}}
  733. ]
  734. },
  735. {
  736. "data" : "Networking sites",
  737. "children" :[
  738. {"data":"Facebook", "metadata":{"href":"http://www.fb.com","id":"fb"}},
  739. {"data":"Twitter", "metadata":{"href":"http://twitter.com"}}
  740. ]
  741. }
  742. ]*/
  743. //$this->load->view("utilities/add_category",$data);ge
  744. $result = $this->Category->getAll(2);
  745. $final = array();
  746. foreach ($result as $res){
  747. $cat['data'] = $res['category_name'];
  748. $cat['attr']['id']= $res['magento_entity_id'];
  749. $cat['state'] = 'closed';
  750. array_push($final,$cat);
  751. }
  752. $result_json = json_encode($final);
  753. echo $result_json;
  754. //$data['treedata'] = $result_json;
  755. //$this->load->view("utilities/add_category",$data);
  756. }
  757. public function renderChildren(){
  758. $id = $_REQUEST['nodeid'];
  759. $result = $this->Category->getChildren($id);
  760. $final = array();
  761. foreach ($result as $res){
  762. $cat['data'] = $res['category_name'];
  763. $cat['attr']['id']= $res['magento_entity_id'];
  764. $cat['state'] = 'closed';
  765. array_push($final,$cat);
  766. }
  767. $result_json = json_encode($final);
  768. echo $result_json;
  769. //$data['treedata'] = $result_json;
  770. //$this->load->view("utilities/add_category",$data);
  771. }
  772. /* Supplier */
  773. public function loadSupplersGrid(){
  774. $this->load->view('utilities/suppliers_grid',$data);
  775. }
  776. function populateSuppliersInGrid (){
  777. // standard request parameters
  778. $searchOn = strip($_REQUEST['_search']);
  779. $page = $_REQUEST['page'];
  780. $limit = $_REQUEST['rows'];
  781. $sidx = $_REQUEST['sidx'];
  782. $sord = $_REQUEST['sord'];
  783. //standard response parameters
  784. $suppliersdata = array();
  785. $count = $this->Supplier->totalNoOfRows();
  786. if( $count > 0 && $limit > 0) {
  787. $total_pages = ceil($count/$limit);
  788. } else {
  789. $total_pages = 0;
  790. }
  791. if ($page > $total_pages) $page=$total_pages;
  792. $start = $limit*$page - $limit;
  793. // if for some reasons start position is negative set it to 0
  794. // typical case is that the user type 0 for the requested page
  795. if($start <0) $start = 0;
  796. $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
  797. $data['total'] = $total_pages;
  798. $data['page'] = $page;
  799. $data['records'] = $count;
  800. if($searchOn=='true') {
  801. $filters = json_decode($_REQUEST['filters'],true);
  802. $groupOp = $filters['groupOp'];
  803. $rules = $filters['rules'];
  804. $where_condition = array();
  805. foreach ($rules as $rule){
  806. $field = $rule['field'];
  807. $op= $rule['op'];
  808. $input = $rule['data'];
  809. $where_condition[$field]=$input;
  810. }
  811. $suppliers = $this->Supplier->getAll(false,$clauses,$where_condition);
  812. }
  813. else {
  814. $suppliers = $this->Supplier->getAll();
  815. }
  816. foreach ($suppliers as $dp){
  817. array_push($suppliersdata, array('id'=> $dp['id'],'dprow' => array($dp['supplier_name'],$dp['registration_number'],$dp['contact_person'],$dp['address'],$dp['city'],$dp['state'],$dp['email'],$dp['contact_number'])));
  818. }
  819. $data['supplierdata'] = $suppliersdata;
  820. echo json_encode($data);
  821. }
  822. public function modifySuppliers(){
  823. $oper = $_REQUEST['oper'];
  824. $id= $_REQUEST['id'];
  825. $data['supplier_name'] = $_REQUEST['supplier_name'];
  826. $data['registration_number'] = $_REQUEST['registration_number'];
  827. $data['contact_person'] = $_REQUEST['contact_person'];
  828. $data['address'] = $_REQUEST['address'];
  829. $data['city'] = $_REQUEST['city'];
  830. $data['state'] = $_REQUEST['state'];
  831. $data['email'] = $_REQUEST['email'];
  832. $data['contact_number'] = $_REQUEST['contact_number'];
  833. if ($oper== 'add'){
  834. $this->Supplier->save($data);
  835. }
  836. else if ($oper== 'edit'){
  837. $this->Supplier->save($data,$id);
  838. }
  839. else if ($oper== 'del'){
  840. $this->Supplier->delete($id);
  841. }
  842. }
  843. }
  844. ?>