PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/magehelp/application/controllers/utilities.php

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