PageRenderTime 47ms CodeModel.GetById 11ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

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