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