<link href="css/cssicon/style.css" rel="stylesheet" type="text/css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script type='text/javascript' src='js/charts.js'></script>

<script>
$(document).ready(function(){
	deliveryOrders();
	supplierInvoices();
 		/*$.ajax({
  			type: "POST",
  			dataType: "json",
			url: "<?php echo base_url()?>SalesOrder/SalesByCustomer",
  			success: function(content){
				var data = [];
				for (var i=0; i<content.message.length; i++){
					data[i] = { label: '<a href="" title="'+ accounting.formatMoney(content.message[i].customerTotal,"MYR",2) +'">' 
						+ content.message[i].label+'</a>', data: content.message[i].data };
				}
       				 $.plot($("#salesbycust"), data, {
           				series: {
                			pie: { show: true }
           				},
            			legend: { show: false }
					});
			}
		});*/        // Here your ajax action after delete confirmed

		loadItemSalesPie();
 		       // Here your ajax action after delete confirmed
});
</script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
/*function drawChart() {
	// Create the data table.
	var pieData = new google.visualization.DataTable();
	pieData.addColumn('string', 'Topping');
	pieData.addColumn('number', 'Slices');

	$.ajax({
		type: "POST",
		dataType: "json",
		url: "<?php echo base_url()?>SalesOrder/SalesByItems",
		success: function(content){
            var data = [];
			//series = 8;//Math.floor(Math.random() * 6) + 3;
			var total = 0;
			for (var i = 0; i < content.message.length; i++) {
				var label = content.message[i].item;
				data[i] = [
					label,
					content.message[i].data
				]
			}
			
			pieData.addRows(data);
            
			// Set chart options
			var options = {
					'legend': 'none',
					is3D: true,
				};

			// Instantiate and draw our chart, passing in some options.
			var chart = new google.visualization.PieChart(document.getElementById('salesbyitem'));
			chart.draw(pieData, options);
		}
	});

	

	

	/*data.addRows([
	  ['Mushrooms', 4],
	  ['Onions', 1],
	  ['Olives', 1],
	  ['Zucchini', 1],
	  ['Pepperoni', 2]
	]);

	// Set chart options
	var options = {'title':'Sales By Items'};

	// Instantiate and draw our chart, passing in some options.
	var chart = new google.visualization.PieChart(document.getElementById('salesbyitem'));
	chart.draw(data, options);
}*/
	function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales'],
          <?php
		  	if(!empty($itemSale)){
				foreach($itemSale as $v){
					echo "['".$v->name."', ".$v->itemTotal."],";
				}
			}
			else{
				echo "[test,0]";
			}
		  ?>
		  /*['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]*/
        ]);

        var options = {
          title: '<?php 
		  				if(!empty($itemSale)){
							echo $this->lang->line('salesByItemPerYear');
						}
				?>',
          is3D: true,
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
        chart.draw(data, options);
      }


    google.load("visualization", "1", {packages:["corechart"]});
    google.setOnLoadCallback(drawChart2);
    function drawChart2() {
      var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales'],
          <?php
		  	if(!empty($customerSale)){
		  		foreach($customerSale as $v){
					echo "['".$v->customerName."', ".$v->totalAmountByCust."],";
				}
			}
			else{
				echo "[test,0]";
			}
		  ?>
		  /*
		  ['2014', 1000],
          ['2015', 1170],
          ['2016', 660],
          ['2017', 1030]*/
        ]);

        var options = {
          chart: {
			width: 400,
        	height: 300,
          }
        };


      var view = new google.visualization.DataView(data);
      view.setColumns([0, 1,
                       { calc: "stringify",
                         sourceColumn: 1,
                         type: "string",
                         role: "annotation" }]);

      
      var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
      chart.draw(view, options);
  }


function loadItemSalesPie(){
	/*$.ajax({
		type: "POST",
		dataType: "json",
		url: "<?php echo base_url()?>SalesOrder/SalesByItems",
		success: function(content){
            var data = [];
			//series = 8;//Math.floor(Math.random() * 6) + 3;
			var total = 0;
			for (var i = 0; i < content.message.length; i++) {
				var label = content.message[i].item;
				data[i] = {
					label: '<a href="" title="'+ accounting.formatMoney(content.message[i].customerTotal,"MYR",2) +'">'+label+'</a>',//content.message[i].label,
					data: content.message[i].data
				}
				total = total + content.message[i].data;
			}
			
            
			$.plot($("#salesbyitem"), data, {
   				series: {
        			pie: { show: true }
   				},
    			legend: { show: false }
			});
		}
	});*/ 
}
function deliveryOrders(){
 	$("#doSupply tbody tr").remove(); 	
	$.ajax({
		type: "POST",
       	url: '<?php echo base_url();?>sotransaction/SalesOrderSearch1',
		dataType:"json",
		success: function(content){
			if(content.status == "success") {
				$("#doCount").html("+"+content.message.length);
				if(content.message.length > 5){
					var lengthRec = 5;
				}else{
					var lengthRec = content.message.length;
				}
				for ( var i = 0; i < lengthRec; i++) {
    					$("#doSupply tbody").append(
						"<tr><td style='display:none'>"+content.message[i].ID+"</td>" +
        					"<td><a href='sotransaction/salesOrder/"+ content.message[i].ID +"'>"+(content.message[i].salesOrderDate).substr(8, 2) + 
							"-" + (content.message[i].salesOrderDate).substr(5, 2) +
							"-" + (content.message[i].salesOrderDate).substr(0, 4) + "</a></td>" +
        				"<td>"+content.message[i].customerName+"</td>" +
        				"<td>"+content.message[i].phoneNumber1+"</td>" +
        				"<td class='tar'>"+content.message[i].fldcurr_code + ' ' + accounting.formatNumber(content.message[i].totalAmount,2)+"</td>" +
				        "</tr>");
				}
			}
		}
	});
}



function supplierInvoices(){
 	$("#invoicesAp tbody tr").remove(); 	
	$.ajax({
		type: "POST",
       	url: '<?php echo base_url();?>home/openPurchaseInvoice',
		dataType:"json",
		success: function(content){
			if(content.status == "success") {
				$("#invCount").html("+"+content.message.length);
				if(content.message.length > 5){
					var lengthRec = 5;
				}else{
					var lengthRec = content.message.length;
				}
				for ( var i = 0; i < lengthRec; i++) {
    					$("#invoicesAp tbody").append(
						"<tr><td style='display:none'>"+content.message[i].ID+"</td>" +
        					"<td><a href='<?php echo base_url(); ?>apreports/purchaseInvoiceDetail/"+ content.message[i].ID +"' target='_blank'>"+(content.message[i].invoiceDate).substr(8, 2) + 
							"-" + (content.message[i].invoiceDate).substr(5, 2) +
							"-" + (content.message[i].invoiceDate).substr(0, 4) + "</a></td>" +
        				"<td>"+content.message[i].supplierName+' ['+content.message[i].formNo+"]</td>" +
        				"<td>"+content.message[i].phoneNumber1+' ['+content.message[i].attention+"]</td>" +
        				"<td class='tar'>"+content.message[i].fldcurr_code + ' ' + accounting.formatNumber(content.message[i].totalPayable,2)+"</td>" +
				        "</tr>");
				}
			}
		}
	});
}
function soList(){
	var urls = "<?php echo base_url();?>sotransaction/SalesOrderList";
		window.location = urls;
}
function invList(){
	var urls = "<?php echo base_url();?>apreports/purchaseinvoicelist";
		window.location = urls;
}
</script>


<script type="text/javascript">
$(document).ready(function() {
   $('select').select2();
}); 
 
function changeList(){
	var addyear = $('#add_year option:selected').val();
	var addper = $('#add_period option:selected').val();
	var acctNo = $('#acctNo option:selected').val();
	var urls = "<?php echo base_url();?>glreports/accountBalanceSummary/"+addyear+"/"+addper+"/"+acctNo;
		window.location = urls;
}

function do_print(){
	var addyear = $('#add_year option:selected').val();
	var addper = $('#add_period option:selected').val();
	var acctNo = $('#acctNo option:selected').val();
	window.open("<?php echo base_url() ?>glreports/accountBalanceSummary_print/"+addyear+"/"+addper+"/"+acctNo);
}

function selectYearPeriod(obj){
		var year = obj.value;
//		alert(year);
			
			$.ajax({
  				type: "POST",
	  			dataType: "json",
				url: "<?php echo base_url()?>glreports/get_TrialBalance_year/"+year,
				data: year,
	  			async: false,
  				success: function(content){
					if(content.status == "success") {
					var items = [];
					//items.push('<option>-Please Select-</option>');
					for ( var i = 0; i < content.message.length; i++) {
					items.push('<option value="'+content.message[i].ID+'">'
						+ content.message[i].financialPeriod + '</option>');
					}  //end for
					jQuery("#add_period").empty();
					jQuery("#add_period").append(items.join('</br>'));
				} else {
					$("#error").html('<p>'+content.message+'</p>');
				} //end if
			} //end success
				
			}); //end ajax
//	window.location.reload(true); 
}

</script>
	<div id="content">                        
        <div class="wrap">
            <div class="head"><!-- head --> 
                <div class="info">
                	<!--
					<h1>
						<?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
						<?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]
          			</h1>
                    -->
					<ul class="breadcrumb">
						<li class="active"><?php echo $this->lang->line('dashboard') ?></li>
					</ul>
                </div>                        
                <div class="search">
					<form action="<?php echo base_url() ?>admin/search" method="post">
						<input name="search_text" type="text" placeholder="search..."/>                                
						<button type="submit"><span class="i-magnifier"></span></button>
					</form>
                </div>                        
            </div>                    
            <div class="content">
				<div class="row-fluid">
					<div class="span12">
						<div class="widgets">
							<div class="tile tile-item icodshbrd-tile-dashboard">
								<a href="<?php echo base_url()?>home" class="ascensorLink tile-nav ">
									<p>Dashboard</p>	
								</a>
							</div>   
							<div class="tile tile-item icodshbrd-tile-gl">
								<a href="<?php echo base_url()?>GeneralLedger" class="ascensorLink tile-nav">
									<p>General Ledger</p>	
								</a>
							</div>
							<div class="tile tile-item icodshbrd-tile-accountreceivables">
								<a href="<?php echo base_url()?>AccountReceivables" class="ascensorLink tile-nav">
									<p>Account Receivables</p>	
								</a>
							</div>
							<div class="tile tile-item icodshbrd-tile-accountpayables">
								<a href="<?php echo base_url()?>AccountPayables" class="ascensorLink tile-nav">
									<p>Account Payables</p>	
								</a>
							</div>
							<div class="tile tile-item icodshbrd-tile-inventorycontrol">
								<a href="<?php echo base_url()?>inventoryControl" class="ascensorLink tile-nav">
									<p>Inventory Control</p>	
								</a>
							</div>
							<div class="tile tile-item icodshbrd-tile-Purchasing">
								<a href="<?php echo base_url()?>purchasing" class="ascensorLink tile-nav">
									<p>Purchasing</p>	
								</a>
							</div> 
							<div class="tile tile-item icodshbrd-tile-sales">
								<a href="<?php echo base_url()?>SalesOrder" class="ascensorLink tile-nav">
									<p>Sales Order</p>	
								</a>
							</div>
							<div class="tile tile-item icodshbrd-tile-zktwkf">
								<a href="<?php echo base_url()?>zakat" class="ascensorLink tile-nav">
									<p>Zakat &amp; Wakaf</p>	
								</a>
							</div>
							<div class="tile tile-item icodshbrd-tile-gst">
								<a href="<?php echo base_url()?>gst" class="ascensorLink tile-nav">
									<p>Goods &amp; Services Tax</p>	
								</a>
							</div>
							<div class="tile tile-item icodshbrd-tile-setup">
								<a href="<?php echo base_url()?>setting/companyList" class="ascensorLink tile-nav">
									<p>General Setup</p>	
								</a>
							</div>
							<div class="tile tile-item icodshbrd-tile-admin">								
                                <a href="<?php echo base_url()?>admin/usermasterlist" class="ascensorLink tile-nav">                     
									<p>Admin</p>	
								</a>
							</div>
						    <div class="tile tile-item icodshbrd-tile-userguide">								
                                <a href="<?php echo base_url()?>userguide" class="ascensorLink tile-nav">                          
									<p>User Guide</p>	
								</a>
							</div>
                       </div>                     
                    </div><!-- end metro design -->
					
					<!-- Sales By Items -->
                    <div class="row-fluid">
						<div class="span6">
							<div class="block">
								<div class="head">                                        
									<h2><?php echo $this->lang->line('salesByItem')?></h2>
									<ul class="buttons">
										<li><a href="#" class="block_loading" onclick="drawChart()"><span class="i-cycle"></span></a></li>
										<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
									</ul>
                                </div>
                                <div class="content">
									<div id="piechart_3d" style="height: 300px; width: 300px; margin: 0px auto;"></div>
                                    <!--<div id="salesbyitem" style="height: 300px; width: 300px; margin: 0px auto;"></div>-->
                                </div>
                            </div>
                        </div>						
						<!--Account Balance -->                   
                        <div class="span6">
							<div class="block">
								<div class="head">                                        
									<h2><?php echo $this->lang->line('salesByCust')?></h2>
									<ul class="buttons">
										<li><a href="#" class="block_loading"><span class="i-cycle"></span></a></li>
										<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
									</ul>
								</div>
								<div class="content">
									<div id="columnchart_values" style="width: 300px; height: 300px; margin: 0px auto;"></div>
                                </div>
                            </div>
                        </div>
					</div>        
					<div class="row-fluid">
						<div class="span12">
							<div class="block">
								<div class="head">                                   
									<h2>Invoices</h2>                                        
                                        <ul class="buttons">
                                            <li><a href="#" class="block_loading"><span class="i-cycle"></span></a></li>
                                            <li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
                                            <li><a href="#" class="block_remove"><span class="i-cancel-2"></span></a></li>
                                        </ul>                                        
                                        <div class="side fr">
                                            <span class="label label-important" id="invCount"></span>
                                        </div>                                        
                                </div>                                                                    
								<div class="content np">
									<table cellpadding="0" cellspacing="0" width="100%" class="list" id="invoicesAp">
										<thead>
											<tr>
												<th width="10%">Date</th>
                                                <th width="25%">Suppliers</th>
                                                <th width="25%">Contact</th>
                                                <th width="15%">Amount</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        </tbody>
										<tfoot>
											<tr>
												<td colspan="4" align="right"><button class="btn-form btn-info-form" onclick="invList()">More...</button></td>
											</tr>
                                        </tfoot>
									</table>
                                </div>
                               	
                                                                                
							</div>                                
						</div>
					</div>
				</div><!-- row -->                
			</div><!-- content -->
		</div><!-- wrap -->  
  </div><!-- content --> 		  
  
		<!-- Stacked Charts 
			<div class="row-fluid">
				<div class="span12">
					<div class="block">
						<div class="head">                                    
							<h2>Stacked charts</h2>
						</div>
                        <div class="content">                                   
							<p class="blocktext">
								<div class="blocktext">
									<div class="drobe clr row-1"><a href="#"><strong>Goods & Service Tax</strong></a></div>	
										<div class="drobe v3 col-1a"><a href="#"><strong>Purchasing</strong></a></div>
										<div class="drobe v4 col-1b"><a href="#"><strong>Inventory Control</strong></a></div>
										<div class="drobe v5 col-1c"><a href="#"><strong>Sales Order</strong></a></div>	
										<div class="drobe v1 col-2a"><a href="#"><strong>Account Receivables</strong></a></div>			
										<div class="drobe v2 col-2b"><a href="#"><strong>Account Payables</strong></a></div>
										<div class="drobe v4 col-3"><a href="#"><strong>General <br />Ledger</strong></a></div>	
										<div class="drobe v3 row-2"><a href="#"><strong>Zakat & Wakaf</strong></a></div>
										<div class="drobe clr row-3"><a href="#"><strong>Setup</strong></a></div>
										<div class="drobe clr row-4"><a href="#"><strong>Admin</strong></a></div>			
								</div>
							</p>                          
                         </div>
                   	</div>
				</div>
			</div> -->
                   
            <!-- start slider -->
						<!--<div class="slider">
							<div id="da-slider" class="da-slider">
								<div class="da-slide">
								<h2>Flat Design websites</h2>
								<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
							</div>
							<div class="da-slide">
								<h2>Clean & Flat Design</h2>
								<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
							</div>
							<div class="da-slide">
								<h2>Clean & Flat Design</h2>
								<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
							</div>
							<div class="da-slide">
								<h2>Flat Design websites</h2>
								<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
							</div>
							<nav class="da-arrows">
								<span class="da-arrows-prev"></span>
								<span class="da-arrows-next"></span>
							</nav>
							</div>
						</div>
			<!-- end slider -->					
        