<aside class="right-side">
    <section class="content-header">
        <div class="title_bar">
            <h1 class="major_txt_color">Purchase Received Item</h1>
            <div class="breadcrumb_container"><?php echo breadcrumb_links();?></div>
        </div>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box box-primary">
                    <div class="box-body table-responsive">
                    <?php if(!empty($success)) {?>
                        <div class="alert alert-success alert-dismissable">
                            <i class="fa fa-thumbs-o-up"></i>
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><?php echo $success;?></h4>
                        </div>
                    <?php }
                    else if(!empty($error)) {?>
                        <div class="alert alert-danger alert-dismissable">
                            <i class="fa fa-thumbs-o-down"></i>
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><?php echo $error;?></h4>
                        </div>
                    <?php }?>
                        <div class="row">
                            <div class="left-col action-left-col">
                                <?php if (in_array(2, $permission)) {?>
                                    <a href="<?php echo $add_link?>">
                                        <input type="button" class="btn btn-success btn-sm" value="<?php echo $add_btn?>" />
                                    </a>
                                <?php }?>
                            </div>
                        </div>      
                    </div>
                    <div class="box-body table-responsive">
                        <table class="table table-bordered table-striped data_table">  <!--data_table-->
                            <thead>
                                <tr>
                                    <th width="10%">S.No</th>
                                    <th width="15%">Purchase Date</th>
                                    <th width="15%">Purchase Ref</th>
                                    <th width="20%">Supplier</th>
                                    <th width="10%">Purchase Qty</th>
                                    <th width="10%">Received Qty</th>
                                    <th width="10%">Status</th>
                                    <th width="10%">Action</th>
                                </tr>
                            </thead>
                            <tbody>    
                                <?php foreach ($results as $key => $row) :?>
                                <?php $purChase		= $this->purchase_management_model->get_purchase_order($row->purchase_Id); //echo "<pre>"; print_r($purChase); echo "</pre>";?>
                                <?php $supplierData	= $this->purchase_management_model->get_supplier_data($row->purchase_Id); //echo "<pre>"; print_r($supplierData); echo "</pre>";?>
                                    <tr>
                                        <td><?php echo ++ $key;?></td>
                                        <td><?php echo date("d-m-Y", strtotime($purChase->po_date));?></td>
                                        <td><?php echo text($row->purchase_ref);?></td>
                                        <td><?php echo text($supplierData->supplier);?></td>
                                        <td><?php echo text($purChase->total_qty);?></td>
                                        <td><?php echo text($row->received_qty);?></td>
                                        <td><?php echo (($purChase->total_qty == $row->received_qty)? '<span style="color:green; font-weight:bold;">Received</span>': '<span style="color:red; font-weight:bold;">Received</span>');?></td>
                                        <td class="td_action">
                                            <a class="label btn btn-warning view" href="<?php echo $view_link . $row->purchase_Id?>">
                                                <span>View</span>
                                            </a>
                                        </td>
                                    </tr>   
                                    <!-- <tr class="received_data_<?php echo $row->item_Id; ?>" style="display:none;"></tr>  -->                              
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div>
        </div>
        
        <!-- Start Modal -->
        <div class="modal fade" id="otp-dialog" role="dialog">
            <div class="modal-dialog">
                <!-- Modal content-->
                <div class="modal-content">

                    <div class="modal-header" style="background-color: #337AB7;">
                        <button type="button" class="close cancel_popup" data-dismiss="modal" style="color: #FFF;">x</button>
                        <h4 class="modal-title" style="color: #FFF;">OTP</h4>
                    </div>
                    <div class="modal-body col-xs-12" style="margin-bottom: 30px; border-bottom: 1px dotted #1ba;">
                        <form name="m">
                            <input type="hidden" class="hidden_id" />
                            <input type="hidden" class="edit_link" data-edit-link="<?php echo (!empty($edit_link)) ? $edit_link : '';?>" />
                            <ul class="error_container" style="display:block;padding-left: 50%;"></ul>
                            <div class="col-xs-12">
                                <div class="col-xs-3">&nbsp;</div>                        
                                <div class="col-xs-1">
                                    <label style="padding-top: 31%;">OTP</label>
                                </div>
                                <div class="col-xs-6">
                                    <input type="text" class="form-control otp_no" name="otp_no" value="" />
                                </div>
                                <div class="col-xs-3">&nbsp;</div>
                            </div>
                        </form>
                    </div>

                    <div class="modal-footer" style="padding-right: 30px;">
                        <button type="button" class="btn btn-primary otp_btn_cancel" data-dismiss="modal"><i class="fa fa-play-circle-o"></i> Later</button>
                        <button type="submit" id="sbmt-btn" class="btn btn-danger"><i class="fa fa-send"></i> Send</button>
                    </div>
                </div>   <!-- Modal Content -->     
            </div> 
        </div> <!-- OTP Dialog -->
        
        <!-- Start Modal -->
        <div class="modal fade" id="warning-dialog" role="dialog">
            <div class="modal-dialog">
                <!-- Modal content-->
                <div class="modal-content">

                    <div class="modal-header" style="background-color: #337AB7;">
                        <button type="button" class="close cancel_popup" data-dismiss="modal" style="color: #FFF;">x</button>
                        <h4 class="modal-title" style="color: #FFF;">Warning: Mis-match module is found</h4>
                    </div>
                    <div class="modal-body col-xs-12" style="margin-bottom: 30px; border-bottom: 1px dotted #1ba;">
                        <form name="m">
                            <input type="hidden" class="correct_url" name="correct_url" /> 
                            <div class="col-xs-12 warning_content"></div>
                        </form>
                    </div>

                    <div class="modal-footer" style="padding-right: 30px;">
                        <button type="submit" id="sbmt-btn" class="btn btn-danger"><i class="fa fa-history"></i> Redirect Now</button>
                        <button type="button" class="btn btn-primary redirect_btn_cancel" data-dismiss="modal"><i class="fa fa-play-circle-o"></i> Later</button>                        
                    </div>
                </div>   <!-- Modal Content -->     
            </div> 
        </div> <!-- Dialog -->
        
    </section><!-- /.content -->
</aside><!-- /.right-side -->
<!-- ./wrapper -->
<script type="text/javascript">
    $(document).on('ready', function(){
       /* $('a.delete').on('click', function(){
            
            var redirectURL = $(this).attr('data-href');//$('[name="redirect_url"]').val() || "";
            
            if( redirectURL != '' ) {
                msgBox("Please wait ... Checking for able to delete!", -1, 'info');
                
                var s   = redirectURL.split('/')
                ,   data = {
                    'act' : 'chk-rm',
                    'pid' : s[s.length-1],  

                };
                $.post( baseURL + controller + '/ajax', data, function(){
                    $(this).addClass('pop_up_confirm').trigger('click');
                });
            }else {
                $(this).addClass('pop_up_confirm');
            }
            
        });*/
		$('.received_item').on('click', function (){
			var itemID	= $(this).attr("data-item");
			
			if($(this).hasClass('fa-minus')) {
				//$(this).closest('.nav-column').siblings('div.home').toggleClass("off");
				$('.received_data_'+itemID).hide();
				$(this).addClass("fa-plus").removeClass("fa-minus");
				$('.received_data_'+itemID).html('');
			}else{
				$(this).addClass("fa-minus").removeClass("fa-plus");
				$('.received_data_'+itemID).show();
				
				$.ajax({
					url: base_url + 'inventory_purchase_receive/get_received_items',
					async: false,
					data: {itemID: itemID},
					type: 'post',
					success: function (output) {
						console.log(output);						
						$('.received_data_'+itemID).html(output);
					}
				});
			}
			//alert(itemID);
			return false;
		});
    })

</script>