<?php
   $today_date                         = date('Y-m-d');    
    $monthly_start_date                 = date('Y-m-01');    
    $monthly_end_date                   = date('Y-m-t');
    $yearly_start_date                  = date('Y-01-01');    
    $yearly_end_date                    = date('Y-12-t');        
 ?>


<div id="order" >
<div class="heading"><span>MTD</span></div>
<br>
<span><b>On Quantity</b></span>
<br><br>  
    <div class="row">
        
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Sales Group
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="order_chart"></figure>
                </div>
            </section>
        </div>
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Lead Owner
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="order_lo_chart"></figure>
                </div>
            </section>
        </div>
         <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Country
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="order_country_chart"></figure>
                </div>
            </section>
         </div>
    </div>

<span><b>On Value</b></span>
<br><br>
    <div class="row">
        
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Sales Group
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="order_val_chart"></figure>
                </div>
            </section>
        </div>
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Lead Owner
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="order_lo_val_chart"></figure>
                </div>
            </section>
        </div>
         <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Country
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="order_country_val_chart"></figure>
                </div>
            </section>
        </div>
    </div>

<div class="heading"><span>YTD</span></div>
<br>
<span><b>On Quantity</b></span>
<br><br>  
    <div class="row">
        
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Sales Group
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="ytd_order_chart"></figure>
                </div>
            </section>
        </div>
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Lead Owner
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="ytd_order_lo_chart"></figure>
                </div>
            </section>
        </div>
         <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Country
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="ytd_order_country_chart"></figure>
                </div>
            </section>
         </div>
    </div>

<span><b>On Value</b></span>
<br><br>
    <div class="row">
        
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Sales Group
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="ytd_order_val_chart"></figure>
                </div>
            </section>
        </div>
        
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Lead Owner
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="ytd_order_lo_val_chart"></figure>
                </div>
            </section>
        </div>
        <div class="col-md-4">
            <section class="panel">
                <header class="panel-heading">
                    Order- Country
                </header>
                <div class="panel-body">
                    <figure class="demo-xchart" id="ytd_order_country_val_chart"></figure>
                </div>
            </section>
        </div>
         
    </div>


</div>
<?php
   //order salesgroup chart
  // print_r($monthly_start_date);die();
    $order_sg_graph_data = array();
    $order_sg_target_axis="";
    $model = MasSalesGroup::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = MasSalesGroup::model()->findAll();
             foreach ($model_project_type as $j=>$value) {   
                 $type = Order::model()->find(array('select'=>'COUNT(*) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND sales_group ='.$value->id));
               // $type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_order WHERE sales_group=" . $value->id . "")->queryScalar();                    
                // if(!empty($type)){ 

                       if($order_sg_target_axis=="")
                              $order_sg_target_axis= '{"y":'.$type->value.',"x":"'.$value->group_name.'"}';
                      else
                              $order_sg_target_axis.= ',{"y":'.$type->value.',"x":"'.$value->group_name.'"}';         
               //  }
           
           
           }
           $order_sg_graph_data[$i]	= $order_sg_target_axis;
           //print_r($order_sg_target_axis);die();
      }
     
     // order - leadowner chart 
      
    $order_lo_graph_data = array();
    $order_lo_target_axis="";
    $model = User::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = User::model()->findAll(array('condition'=>'isActive="Y"'));
             foreach ($model_project_type as $j=>$value) { 
                 $type = Order::model()->find(array('select'=>'COUNT(*) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND crm_user_id ='.$value->id));
               // $type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_order WHERE crm_user_id=" . $value->id . "")->queryScalar();                    
                 if(!empty($type)){ 

                       if($order_lo_target_axis=="")
                              $order_lo_target_axis= '{"y":'.$type->value.',"x":"'.$value->username.'"}';
                      else
                              $order_lo_target_axis.= ',{"y":'.$type->value.',"x":"'.$value->username.'"}';         
                 }
           
           
           }
           $order_lo_graph_data[$i] = $order_lo_target_axis;
           //print_r($order_sg_target_axis);die();
      }
      
      
      // order - country chart 
    //print_r($monthly_start_date);die();  
    $order_country_graph_data = array();
    $order_country_target_axis="";
    $model = MasCountry::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = MasCountry::model()->findAll(array('condition'=>'isActive="Y"'));
             foreach ($model_project_type as $j=>$value) {           
                //$type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_order WHERE crm_user_id=" . $value->id . "")->queryScalar();                    
                  $type = Order::model()->with('customer')->find(array('select'=>'COUNT(*) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND customer.customer_country ='.$value->id));
                 if(!empty($type)){ 

                       if($order_country_target_axis=="")
                              $order_country_target_axis= '{"y":'.$type->value.',"x":"'.$value->country_name.'"}';
                      else
                              $order_country_target_axis.= ',{"y":'.$type->value.',"x":"'.$value->country_name.'"}';         
                 }
                 else
                 {
                     $order_country_target_axis= '{"y":0,"x":"'.$value->country_name.'"}';
                 }
           
           
           }
           $order_country_graph_data[$i] = $order_country_target_axis;
           //print_r($order_sg_target_axis);die();
      }
      
      // order - sg by value     
    $order_sg_val_graph_data = array();
    $order_sg_val_target_axis="";
    $model = MasSalesGroup::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = MasSalesGroup::model()->findAll();
             foreach ($model_project_type as $j=>$value) { 
                $type =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="Y" AND sales_group ='.$value->id));
                $type_base =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total*currencyname.exchange_rate) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="N" AND sales_group ='.$value->id));
                $total= $type->value+$type_base->value;
                //$type = Lead::model()->find(array('select'=>'COUNT(*) as value','condition'=>'enq_date>="'.$monthly_start_date.'" AND enq_date<="'.$today_date.'" AND sales_group_id ='.$value->id));
               // $type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_lead WHERE sales_group_id=" . $value->id . "")->queryScalar();                    
                 if(!empty($type)){ 

                       if($order_sg_val_target_axis=="")
                              $order_sg_val_target_axis= '{"y":'.$total.',"x":"'.$value->group_name.'"}';
                      else
                              $order_sg_val_target_axis.= ',{"y":'.$total.',"x":"'.$value->group_name.'"}';         
                 }
                 else
                 {
                      $order_sg_val_target_axis= '{"y":0,"x":"'.$value->group_name.'"}';
                 }
           
           
           }
           $order_sg_val_graph_data[$i]	= $order_sg_val_target_axis;
          // print_r($order_sg_val_target_axis);die();
      }
     
     // order - leadowner by value 
      
    $order_lo_val_graph_data = array();
    $order_lo_val_target_axis="";
    $model = User::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = User::model()->findAll(array('condition'=>'isActive="Y"'));
             foreach ($model_project_type as $j=>$value) {  
                $type =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="Y" AND crm_user_id ='.$value->id));
                $type_base =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total*currencyname.exchange_rate) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="N" AND crm_user_id ='.$value->id));
                $total= $type->value+$type_base->value;
               
                // $type = Lead::model()->find(array('select'=>'COUNT(*) as value','condition'=>'enq_date>="'.$monthly_start_date.'" AND enq_date<="'.$today_date.'" AND crm_user_id ='.$value->id));
                //$type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_order WHERE crm_user_id=" . $value->id . "")->queryScalar();                    
                 if(!empty($total)){ 

                       if($order_lo_val_target_axis=="")
                              $order_lo_val_target_axis= '{"y":'.$total.',"x":"'.$value->username.'"}';
                      else
                              $order_lo_val_target_axis.= ',{"y":'.$total.',"x":"'.$value->username.'"}';         
                 }
                 else
                 {
                      $order_lo_val_target_axis= '{"y":0,"x":"'.$value->username.'"}';
                 }
           
           
           }
           $order_lo_val_graph_data[$i] = $order_lo_val_target_axis;
           //print_r($lead_sg_target_axis);die();
      }
      
    $order_country_val_graph_data = array();
    $order_country_val_target_axis="";
    $model = MasCountry::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = MasCountry::model()->findAll(array('condition'=>'isActive="Y"'));
             foreach ($model_project_type as $j=>$value) {           
                //$type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_lead WHERE crm_user_id=" . $value->id . "")->queryScalar();                    
                $type =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="Y" AND customer.customer_country ='.$value->id));
                $type_base =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total*currencyname.exchange_rate) as value','condition'=>'order_date>="'.$monthly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="N" AND customer.customer_country ='.$value->id));
                $total= $type->value+$type_base->value;
               
                // $type = Lead::model()->with('customer')->find(array('select'=>'COUNT(*) as value','condition'=>' customer.customer_country ='.$value->id));
                 if(!empty($total)){ 

                       if($order_country_val_target_axis=="")
                              $order_country_val_target_axis= '{"y":'.$total.',"x":"'.$value->country_name.'"}';
                      else
                              $order_country_val_target_axis.= ',{"y":'.$total.',"x":"'.$value->country_name.'"}';         
                 }
                  else
                 {
                      $order_country_val_target_axis= '{"y":0,"x":"'.$value->country_name.'"}';
                 }
           
           
           }
           $order_country_val_graph_data[$i] = $order_country_val_target_axis;
           //print_r($lead_sg_target_axis);die();
      }
      
 //YTD 
      
$ytd_order_sg_graph_data = array();
    $order_sg_target_axis="";
    $model = MasSalesGroup::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = MasSalesGroup::model()->findAll();
             foreach ($model_project_type as $j=>$value) {   
                 $type = Order::model()->find(array('select'=>'COUNT(*) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND sales_group ='.$value->id));
               // $type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_order WHERE sales_group=" . $value->id . "")->queryScalar();                    
                // if(!empty($type)){ 

                       if($ytd_order_sg_target_axis=="")
                              $ytd_order_sg_target_axis= '{"y":'.$type->value.',"x":"'.$value->group_name.'"}';
                      else
                              $ytd_order_sg_target_axis.= ',{"y":'.$type->value.',"x":"'.$value->group_name.'"}';         
               //  }
           
           
           }
           $ytd_order_sg_graph_data[$i]	= $ytd_order_sg_target_axis;
           //print_r($order_sg_target_axis);die();
      }
     
     // order - leadowner chart 
      
    $ytd_order_lo_graph_data = array();
    $ytd_order_lo_target_axis="";
    $model = User::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = User::model()->findAll(array('condition'=>'isActive="Y"'));
             foreach ($model_project_type as $j=>$value) { 
                 $type = Order::model()->find(array('select'=>'COUNT(*) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND crm_user_id ='.$value->id));
               // $type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_order WHERE crm_user_id=" . $value->id . "")->queryScalar();                    
                 if(!empty($type)){ 

                       if($ytd_order_lo_target_axis=="")
                              $ytd_order_lo_target_axis= '{"y":'.$type->value.',"x":"'.$value->username.'"}';
                      else
                              $ytd_order_lo_target_axis.= ',{"y":'.$type->value.',"x":"'.$value->username.'"}';         
                 }
                 else
                 {
                      $ytd_order_lo_target_axis= '{"y":0,"x":"'.$value->username.'"}';
                 }
           
           
           }
           $ytd_order_lo_graph_data[$i] = $ytd_order_lo_target_axis;
           //print_r($order_sg_target_axis);die();
      }
      
      
      // order - country chart 
    //print_r($monthly_start_date);die();  
    $ytd_order_country_graph_data = array();
    $ytd_order_country_target_axis="";
    $model = MasCountry::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = MasCountry::model()->findAll(array('condition'=>'isActive="Y"'));
             foreach ($model_project_type as $j=>$value) {           
                //$type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_order WHERE crm_user_id=" . $value->id . "")->queryScalar();                    
                  $type = Order::model()->with('customer')->find(array('select'=>'COUNT(*) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND customer.customer_country ='.$value->id));
                 if(!empty($type)){ 

                       if($ytd_order_country_target_axis=="")
                              $ytd_order_country_target_axis= '{"y":'.$type->value.',"x":"'.$value->country_name.'"}';
                      else
                              $ytd_order_country_target_axis.= ',{"y":'.$type->value.',"x":"'.$value->country_name.'"}';         
                 }
                 
           
           
           }
           $ytd_order_country_graph_data[$i] = $ytd_order_country_target_axis;
           //print_r($order_sg_target_axis);die();
      }
      
      // order - sg by value     
    $ytd_order_sg_val_graph_data = array();
    $ytd_order_sg_val_target_axis="";
    $model = MasSalesGroup::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = MasSalesGroup::model()->findAll();
             foreach ($model_project_type as $j=>$value) { 
                $type =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="Y" AND sales_group ='.$value->id));
                $type_base =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total*currencyname.exchange_rate) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="N" AND sales_group ='.$value->id));
                $total= $type->value+$type_base->value;
                //$type = Lead::model()->find(array('select'=>'COUNT(*) as value','condition'=>'enq_date>="'.$monthly_start_date.'" AND enq_date<="'.$today_date.'" AND sales_group_id ='.$value->id));
               // $type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_lead WHERE sales_group_id=" . $value->id . "")->queryScalar();                    
               //  if(!empty($total)){ 

                       if($ytd_order_sg_val_target_axis=="")
                              $ytd_order_sg_val_target_axis= '{"y":'.$total.',"x":"'.$value->group_name.'"}';
                      else
                              $ytd_order_sg_val_target_axis.= ',{"y":'.$total.',"x":"'.$value->group_name.'"}';         
//                 }
//                 else
//                 {
//                      $ytd_order_sg_val_target_axis= '{"y":0,"x":"'.$value->group_name.'"}';
//                 }
//           
           
           }
           $ytd_order_sg_val_graph_data[$i]	= $ytd_order_sg_val_target_axis;
          // print_r($order_sg_val_target_axis);die();
      }
     
     // order - leadowner by value 
      
    $ytd_order_lo_val_graph_data = array();
    $ytd_order_lo_val_target_axis="";
    $model = User::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = User::model()->findAll(array('condition'=>'isActive="Y"'));
             foreach ($model_project_type as $j=>$value) {  
                $type =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="Y" AND crm_user_id ='.$value->id));
                $type_base =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total*currencyname.exchange_rate) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="N" AND crm_user_id ='.$value->id));
                $total= $type->value+$type_base->value;
               
                // $type = Lead::model()->find(array('select'=>'COUNT(*) as value','condition'=>'enq_date>="'.$monthly_start_date.'" AND enq_date<="'.$today_date.'" AND crm_user_id ='.$value->id));
                //$type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_order WHERE crm_user_id=" . $value->id . "")->queryScalar();                    
                 if(!empty($total)){ 

                       if($ytd_order_lo_val_target_axis=="")
                              $ytd_order_lo_val_target_axis= '{"y":'.$total.',"x":"'.$value->username.'"}';
                      else
                              $ytd_order_lo_val_target_axis.= ',{"y":'.$total.',"x":"'.$value->username.'"}';         
                 }
                  else
                 {
//                      $ytd_order_lo_val_target_axis= '{"y":0,"x":"'.$value->username.'"}';
                    continue;
                 }
           
           
           }
           $ytd_order_lo_val_graph_data[$i] = $ytd_order_lo_val_target_axis;
           //print_r($lead_sg_target_axis);die();
      }
      
    $ytd_order_country_val_graph_data = array();
    $ytd_order_country_val_target_axis="";
    $model = MasCountry::model()->findAll(array('condition'=>'isActive="Y"'));
    foreach ($model as $i=>$val) {   
             $model_project_type = MasCountry::model()->findAll(array('condition'=>'isActive="Y"'));
             foreach ($model_project_type as $j=>$value) {           
                //$type = Yii::app()->db->createCommand("SELECT COUNT(*) FROM crm_lead WHERE crm_user_id=" . $value->id . "")->queryScalar();                    
//                $type =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="Y" AND customer.customer_country ='.$value->id));//AND customer.customer_country ='.$value->id
//                $type_base =  Order::model()->with('currencyname','customer')->find(array('select'=>'SUM(grand_total*currencyname.exchange_rate) as value','condition'=>'order_date>="'.$yearly_start_date.'" AND order_date<="'.$today_date.'" AND currencyname.IsBaseCurrency="N" AND customer.customer_country ='.$value->id));
//                $total= $type->value+$type_base->value;
               // print_r($type);die();
//                 $type = Lead::model()->with('customer')->find(array('select'=>'COUNT(*) as value','condition'=>' customer.customer_country ='.$value->id));
                 if(!empty($total)){ 

                       if($ytd_order_country_val_target_axis=="")
                              $ytd_order_country_val_target_axis= '{"y":'.$total.',"x":"'.$value->country_name.'"}';
                      else
                              $ytd_order_country_val_target_axis.= ',{"y":'.$total.',"x":"'.$value->country_name.'"}';         
                 }
                  else
                 {
                      //$ytd_order_country_val_target_axis= '{"y":0,"x":"'.$value->country_name.'"}';
                      continue;
                 }
           
           
           }
           $ytd_order_country_val_graph_data[$i] = $ytd_order_country_val_target_axis;
//           print_r($ytd_order_country_val_graph_data);die();
      }
            
      
    ?>
    
<script type="text/javascript">
(function() {
        
 //-------------------------------------MTD-----------------------------------------
 //---------Qty-----------
       

var order_sg_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($order_sg_graph_data[0])) {echo $order_sg_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
                
  var order_lo_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($order_lo_graph_data[0])) {echo $order_lo_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
     
  var order_country_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($order_country_graph_data[0])) {echo $order_country_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
                
var order_sg_val_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($order_sg_val_graph_data[0])) {echo $order_sg_val_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
                
  var order_lo_val_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($order_lo_val_graph_data[0])) {echo $order_lo_val_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
     
  var order_country_val_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($order_country_val_graph_data[0])) {echo $order_country_val_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
 //YTD
 
var ytd_order_sg_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($ytd_order_sg_graph_data[0])) {echo $ytd_order_sg_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
                
  var ytd_order_lo_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($ytd_order_lo_graph_data[0])) {echo $ytd_order_lo_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
     
  var ytd_order_country_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($ytd_order_country_graph_data[0])) {echo $ytd_order_country_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
                
var ytd_order_sg_val_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($ytd_order_sg_val_graph_data[0])) {echo $ytd_order_sg_val_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
                
  var ytd_order_lo_val_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($ytd_order_lo_val_graph_data[0])) {echo $ytd_order_lo_val_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];
     
  var ytd_order_country_val_data = [{
                "xScale": "ordinal",
                "comp": [],
                "main": [{
                        "className": ".main.l2",
                        "data": [
                        
                             <?php if(isset($ytd_order_country_val_graph_data[0])) {echo $ytd_order_country_val_graph_data[0];}?>
                           
                                ]}
                ],
                "type": "bar",
                "yScale": "linear"}, ];                

//================================================== MTD ==================================
//Qty
  
        
        
    order_chart = new xChart('bar', order_sg_data[0], '#order_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });
        
    order_lo_chart = new xChart('bar', order_lo_data[0], '#order_lo_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });
    order_country_chart = new xChart('bar', order_country_data[0], '#order_country_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });   
        
 order_val_chart = new xChart('bar', order_sg_val_data[0], '#order_val_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });
        
    order_lo_val_chart = new xChart('bar', order_lo_val_data[0], '#order_lo_val_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });
    order_country_val_chart = new xChart('bar', order_country_val_data[0], '#order_country_val_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });   
        
    ytd_order_chart = new xChart('bar', ytd_order_sg_data[0], '#ytd_order_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });
        
    ytd_order_lo_chart = new xChart('bar', ytd_order_lo_data[0], '#ytd_order_lo_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });
    ytd_order_country_chart = new xChart('bar', ytd_order_country_data[0], '#ytd_order_country_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });   
        
    ytd_order_val_chart = new xChart('bar', ytd_order_sg_val_data[0], '#ytd_order_val_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });
        
    ytd_order_lo_val_chart = new xChart('bar', ytd_order_lo_val_data[0], '#ytd_order_lo_val_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });
    ytd_order_country_val_chart = new xChart('bar', ytd_order_country_val_data[0], '#ytd_order_country_val_chart', {
            axisPaddingTop: 5,
            dataFormatX: function (x) {
                return x;
            },
            dataFormatY: function (y) {
                return y;
            },
        });         
            
    
           /*  tickFormatX: function(x) {
                return xFormat(x);
            } */
       // });
}());
</script>