<?php $this->load->view("common/header");?>
<!-- end: HEAD -->
<!-- start: CSS REQUIRED FOR THIS PAGE ONLY -->
<style type="text/css">
   .table> thead:first-child> tr:first-child> th,
   .table> thead:first-child> tr:first-child> td,
   .table-striped thead tr.primary:nth-child(2n+1) th {
   background-color: #428bca;
   border-color: #357ebd;
   border-top: 1px solid #357ebd;
   color: white;
   text-align: center;
   }
   .box .box-content {
   background: white none repeat scroll 0 0;
   padding: 20px;
   }
</style>
<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->
<!-- end: HEAD -->
<!-- start: BODY -->
<body>
   <!-- start: HEADER -->
   <div class="navbar navbar-inverse navbar-fixed-top">
      <!-- start: TOP NAVIGATION CONTAINER -->
      <div class="container">
         <div class="navbar-header">
            <!-- start: RESPONSIVE MENU TOGGLER -->
            <button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button">
            <span class="clip-list-2"></span>
            </button>
            <!-- end: RESPONSIVE MENU TOGGLER -->
            <!-- start: LOGO -->
            <a class="navbar-brand" href="../index.html">
            Viable<i class="clip-clip"></i>2020
            </a>
            <!-- end: LOGO -->
         </div>
         <div class="navbar-tools">
            <!-- start: TOP NAVIGATION MENU -->
            <?php $this->load->view("common/notifications.php"); ?>
            <!-- end: TOP NAVIGATION MENU -->
         </div>
      </div>
      <!-- end: TOP NAVIGATION CONTAINER -->
   </div>
   <!-- end: HEADER -->
   <!-- start: MAIN CONTAINER -->
   <div class="main-container">
   <div class="navbar-content">
      <!-- start: SIDEBAR -->
      <?php $this->load->view("common/navigation"); ?>
      <!-- end: SIDEBAR -->
   </div>
   <!-- start: PAGE -->
   <div class="main-content">
      <!-- end: SPANEL CONFIGURATION MODAL FORM -->
      <div class="container">
         <!-- start: PAGE HEADER -->
         <div class="row">
            <div class="col-sm-12">
               <!-- start: PAGE TITLE & BREADCRUMB -->
               <ol class="breadcrumb">
                  <li>
                     <a href="<?php echo base_url('dashboard'); ?>">
                     Dashboard 
                     </a>
                  </li>
                  <li>
                     <a href="<?php echo base_url('products'); ?>">
                     Product 
                     </a>
                  </li>
                  <li class="active">
                     Item Details
                  </li>
                  <li class="search-box">
                     <form class="sidebar-search">
                        <div class="form-group">
                           <input type="text" placeholder="Start Searching...">
                           <button class="submit">
                           <i class="clip-search-3"></i>
                           </button>
                        </div>
                     </form>
                  </li>
               </ol>
               <div class="page-header">
                  <h1>Item</h1>
               </div>
            </div>
         </div>
         <!-- end: PAGE HEADER -->
         <!-- start: PAGE CONTENT -->
         <div class="row">
            <div class="col-sm-12">
               <div class="tabbable">
                  <ul class="nav nav-tabs tab-padding tab-space-3 tab-blue" id="myTab4">
                     <li class="active">
                        <a data-toggle="tab" href="#panel_overview">
                        Item Details
                        </a>
                     </li>
                  </ul>
                  <div class="tab-content">
                     <div id="panel_overview" class="tab-pane in active">
                        <div class="panel panel-default">
                           <div class="panel-heading">Summary</div>
                           <div class="panel-body">
                              <div class="box-content">
                                 <div class="row">
                                    <div class="col-lg-12">
                                       <div class="row">
                                          <div class="col-sm-5">
                                             <img class="img-responsive img-thumbnail" alt="<?php echo $product_details->product_mat_name; ?>" src="<?php echo asset_url().'uploads/'.$product_details->product_mat_image; ?>">
                                             <div class="padding10" id="multiimages">
                                                <div class="clearfix"></div>
                                             </div>
                                          </div>
                                          <div class="col-sm-7">
                                             <div class="table-responsive">
                                                <table class="table table-borderless table-striped dfTable table-right-left">
                                                   <tbody>
                                                      <tr>
                                                         <td style="width:30%;">Barcode</td>
                                                         <td style="width:70%;">
                                                            <img class="pull-left" alt="<?php echo $product_details->product_mat_code; ?>" src="<?php echo base_url().'products/gen_barcode/'.$product_details->product_mat_code.'/40'; ?>">
                                                         </td>
                                                      </tr>
                                                      <tr>
                                                         <td>Brand</td>
                                                         <td>
                                                            <?php echo $product_details->brand_name; ?>
                                                         </td>
                                                      </tr>
                                                      <tr>
                                                         <td>Item Name</td>
                                                         <td>
                                                            <?php echo $product_details->product_mat_name; ?>
                                                         </td>
                                                      </tr>
                                                      <tr>
                                                         <td>Item Code</td>
                                                         <td>
                                                            <?php echo ucfirst($product_details->product_mat_code); ?>
                                                         </td>
                                                      </tr>
                                                      <tr>
                                                         <td>Category</td>
                                                         <td>
                                                            <?php echo $product_details->cat_name; ?>
                                                         </td>
                                                      </tr>
                                                      <tr>
                                                         <td>Item Unit</td>
                                                         <td>
                                                            <?php echo $product_details->unit_name; ?>
                                                         </td>
                                                      </tr>
                                                      <?php
                                                         if ( $this->session->userdata( 'ss_group_id' ) == 1||$this->session->userdata( 'ss_group_id' ) == 2 ) {
                                                         	?>
                                                      <tr>
                                                         <td>Item Cost</td>
                                                         <td>
                                                            <?php echo $product_details->product_mat_cost; ?>
                                                         </td>
                                                      </tr>
                                                      <?php }?>
                                                      <tr>
                                                         <td>Alert Quantity</td>
                                                         <td>
                                                            <?php echo $product_details->product_mat_alert_qty; ?>
                                                         </td>
                                                      </tr>
                                                   </tbody>
                                                </table>
                                             </div>
                                          </div>
                                          <div class="clearfix"></div>
                                          <div class="col-sm-12">
                                             <div class="row">
                                                <div class="col-sm-12">
                                                   <h3 class="bold">All Warehouses Quantity : <?php echo $available_qty; ?></h3>
                                                   <hr>
                                                   <?php foreach ($warehouses as $row) {?>
                                                   <div class="col-sm-5">
                                                      <div class="table-responsive">
                                                         <h5 class="bold"><?php echo $row->name; ?></h5>
                                                         <table class="table table-bordered table-striped table-condensed dfTable two-columns">
                                                            <thead>
                                                               <tr>
                                                                  <th>Batch Code</th>
                                                                  <th>Unit Price</th>
                                                                  <th>Quantity</th>
                                                               </tr>
                                                            </thead>
                                                            <tbody>
                                                               <?php $ware_tot=0; foreach ($warehouse_batch_qty_array as $wbqa) {
                                                                  if($row->id!=$wbqa['warehouse_id'] ){continue;}
                                                                  if($wbqa['batch_stock']==0 ){continue;}
                                                                  $ware_tot+=$wbqa['batch_stock'];
                                                                  ?>
                                                               <tr>
                                                                  <th><?php echo $wbqa['batch_ref_number'] ?></th>
                                                                  <th><?php echo $wbqa['product_cost'] ?></th>
                                                                  <th >
                                                                     <div class="pull-right"><?php echo $wbqa['batch_stock'] ?></div>
                                                                  </th>
                                                               </tr>
                                                               <?php } ?>
                                                               <tr>
                                                                  <th></th>
                                                                  <th></th>
                                                                  <th >
                                                                     <div class="pull-right" style="border-top:1px solid gray; border-bottom:4px double gray;"><?php echo $ware_tot; ?></div>
                                                                  </th>
                                                               </tr>
                                                            </tbody>
                                                         </table>
                                                      </div>
                                                   </div>
                                                   <?php } ?>
                                                   <div class="col-sm-10">
                                                      <h5 class="bold">Item Batch</h5>
                                                      <div class="table-responsive">
                                                         <table class="table table-bordered table-striped table-condensed dfTable two-columns">
                                                            <thead>
                                                               <tr>
                                                                  <th>Batch Code</th>
                                                                  <!--<th>Distribution Cash Price</th>
                                                                     <th>Distribution Credit Price</th>
                                                                     <th>Distribution Wholesale Price</th>-->
                                                                  <th> Batch Unit Price</th>
                                                                  <!--	<th> Batch Retail Cash Price</th>
                                                                     <th>Retail Wholesale Price</th>-->
                                                                  <th> Qty</th>
                                                                  <!--<th>Retail Credit Price</th>
                                                                     <th>Retail Wholesale Price</th>-->
                                                                  <th>Action</th>
                                                               </tr>
                                                            </thead>
                                                            <tbody>
                                                               <?php
                                                                  foreach ($batch_list as $key) { ?>
                                                               <tr>
                                                                  <td><?php echo $key['batch_ref_number'] ?></td>
                                                                  <td><?php echo $key['product_cost'] ?></td>
                                                                  <!-- <td><?php echo $key['retail_cash'] ?></td>
                                                                     <td><?php echo $key['retail_wholesale'] ?></td>-->
                                                                  <td><?php echo $key['batch_stock'] ?></td>
                                                                  <?php if($key['batch_status']==1){?>
                                                                  <td><button type="button" onClick="update_batch(<?php echo $key['batch_id']?>,0)" >Disable</button> <button type="button" onClick="etit_batch(<?php echo $key['batch_id']?>,1)" >Edit</button></td>
                                                                  <?php }else {?>
                                                                  <td><button type="button" onClick="update_batch(<?php echo $key['batch_id']?>,1)" >Enable</button> <button type="button" onClick="etit_batch(<?php echo $key['batch_id']?>,1)" >Edit</button></td>
                                                                  <?php } ?>
                                                               </tr>
                                                               <?php	}?>
                                                            </tbody>
                                                         </table>
                                                      </div>
                                                   </div>
                                                </div>
                                                <div class="col-sm-7">
                                                </div>
                                             </div>
                                          </div>
                                          <div class="col-sm-12">
                                             <div class="panel panel-default">
                                                <div class="panel-heading">Product Details</div>
                                                <div class="panel-body">
                                                   <p>
                                                      <?php echo $product_details->product_mat_details; ?>
                                                   </p>
                                                </div>
                                             </div>
                                          </div>
                                       </div>
                                       <?php if ( $this->session->userdata( 'ss_user_id' ) == 1 ) { ?>
                                       <button class="collapse" type="button" onClick="adjustment_batch_qty(<?php echo $product_details->product_mat_id?>)" >Adjustment</button>
                                       <?php } ?>
                                       <div class="buttons">
                                          <div class="btn-group btn-group-justified">
                                             <div class="btn-group ">
                                                <a title="" class="tip btn btn-primary collapse" href="#" onClick="print_barcode(<?php echo $product_details->product_mat_id; ?>); return false;" data-original-title="Barcode">
                                                <i class="fa fa-print"></i> <span class="hidden-sm hidden-xs">Print Barcodex</span>
                                                </a>
                                             </div>
                                             <?php
                                                if ( $this->session->userdata( 'ss_group_id' ) == 1 ) {
                                                	?>
                                             <div class="btn-group">
                                                <a title="" class="tip btn btn-warning tip" href="<?php echo base_url(); ?>product_material/loadEditProductMaterial?pid=<?php echo $product_details->product_mat_id; ?>" data-original-title="Edit Product">
                                                <i class="fa fa-edit"></i> <span class="hidden-sm hidden-xs">Edit</span>
                                                </a>
                                             </div>
                                             <?php }?>
                                          </div>
                                       </div>
                                    </div>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
         <!-- end: PAGE CONTENT-->
      </div>
      <!-- end: PAGE -->
   </div>
   <!-- end: MAIN CONTAINER -->
   <!-- start: FOOTER -->
   <div class="footer clearfix">
      <div class="footer-inner">
         2014 &copy; clip-one by cliptheme.
      </div>
      <div class="footer-items">
         <span class="go-top"><i class="clip-chevron-up"></i></span>
      </div>
   </div>
   <!-- end: FOOTER -->
   <!-- start: RIGHT SIDEBAR -->
   <!-- end: RIGHT SIDEBAR -->
   <div id="event-management" class="modal fade" tabindex="-1" data-width="760" style="display: none;">
      <div class="modal-dialog">
         <div class="modal-content">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
               &times;
               </button>
               <h4 class="modal-title">Event Management</h4>
            </div>
            <div class="modal-body"></div>
            <div class="modal-footer">
               <button type="button" data-dismiss="modal" class="btn btn-light-grey">
               Close
               </button>
               <button type="button" class="btn btn-danger remove-event no-display">
               <i class='fa fa-trash-o'></i> Delete Event
               </button>
               <button type='submit' class='btn btn-success save-event'>
               <i class='fa fa-check'></i> Save
               </button>
            </div>
         </div>
      </div>
   </div>
   <!-- start ajax model -->
   <div id="ajax-modal" class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
   <!-- end ajax model -->
   <!-- start: MAIN JAVASCRIPTS -->
   <?php $this->load->view("common/footer"); ?>
   <!-- end: MAIN JAVASCRIPTS -->
   <script type="text/javascript" src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
   <script type="text/javascript" src="https://cdn.datatables.net/1.10.10/js/dataTables.bootstrap.min.js"></script>
   <script>
      jQuery( document ).ready( function () {
      	//TableData.init();
      	//products_load();
      } );
      
      
      function print_barcode( product_id ) {
      	window.open( '<?php echo base_url() ?>products/single_barcode/' + product_id, 'sma_popup', 'width=900,height=600,scrollbars=yes,menubar=yes,status=no,resizable=yes,screenx=0,screeny=0' );
      }
      
      function edit_discount(discount_id) {
                var $modal = $('#ajax-modal');    
      
                    $('body').modalmanager('loading');
                    setTimeout(function () {
                        $modal.load('<?php echo base_url("product_discount/edit_discount/'+discount_id+'"); ?>', '', function () { 
                            $modal.modal();
                        });
                    }, 1000);
      
               }
      
      
      
      function enable_discount(id) {
       bootbox.confirm({
           title: "Are You Sure ?",
           message: "Do you  want to enable discount?.",
           buttons: {
               cancel: {
                   label: '<i class="fa fa-times"></i> No Cancel'
               },
               confirm: {
                   label: '<i class="fa fa-check"></i> Yes Confirm'
               }
           },
           callback: function(result) {
               if (result == true) {
                   jQuery.ajax({
                       type: "POST", 
                       url: "<?php echo base_url().'product_discount/enable_discount?id='?>" + id,
                       //       data: 'id='+id,
                       cache: false,
                       success: function(response) {
                           var obj = JSON.parse(response);
                           if (obj.status == 1) {location.reload()} else {
                               bootbox.alert({
                                   message: obj.message,
                                   size: 'small'
                               });
      				location.reload()
                           }
                           
                       }
                   });
               }
           }
       });
      }
      
      function update_batch(id,status) {
       bootbox.confirm({
           title: "Are You Sure ?",
           message: "Do you  want to do this action ?.",
           buttons: {
               cancel: {
                   label: '<i class="fa fa-times"></i> No Cancel'
               },
               confirm: {
                   label: '<i class="fa fa-check"></i> Yes Confirm'
               }
           },
           callback: function(result) {
               if (result == true) {
                   jQuery.ajax({
                       type: "POST", 
                       url: "<?php echo base_url().'batch_process/update_batch?id='?>" + id+'&status='+status,
                       //       data: 'id='+id,
                       cache: false,
                       success: function(response) {
                           var obj = JSON.parse(response);
                           if (obj.status == 1) {location.reload()} else {
                               bootbox.alert({
                                   message: obj.message,
                                   size: 'small'
                               });
      				location.reload()
                           }
                           
                       }
                   });
               }
           }
       });
      }
      
      
      function etit_batch(batch_id){		
      var $modal = $('#ajax-modal');
      $('body').modalmanager('loading');
      setTimeout(function () {
      	$modal.load('<?php echo base_url("batch_process/edit_batch?batch_id="); ?>'+batch_id, '', function () {
      		$modal.modal();
      		/*$(".search-select").select2({
      	         placeholder: "Select a State",
      	         allowClear: true
      	    });*/
      	});
      }, 1000);
      }
      
      
      function enable_broker_discount(id) {
       bootbox.confirm({
           title: "Are You Sure ?",
           message: "Do you  want to enable BROKER discount?.",
           buttons: {
               cancel: {
                   label: '<i class="fa fa-times"></i> No Cancel'
               },
               confirm: {
                   label: '<i class="fa fa-check"></i> Yes Confirm'
               }
           },
           callback: function(result) {
               if (result == true) {
                   jQuery.ajax({
                       type: "POST", 
                       url: "<?php echo base_url().'broker/enable_discount?id='?>" + id,
                       //       data: 'id='+id,
                       cache: false,
                       success: function(response) {
                           var obj = JSON.parse(response);
                           if (obj.status == 1) {location.reload()} else {
                               bootbox.alert({
                                   message: obj.message,
                                   size: 'small'
                               });
      				location.reload()
                           }
                           
                       }
                   });
               }
           }
       });
      }
      
      
      function edit_broker_discount(discount_id) {
                var $modal = $('#ajax-modal');    
      
                    $('body').modalmanager('loading');
                    setTimeout(function () {
                        $modal.load('<?php echo base_url("broker/edit_discount/'+discount_id+'"); ?>', '', function () { 
                            $modal.modal();
                        });
                    }, 1000);
      
               }
               
           function  adjustment_batch_qty(product_id)   {
               var $modal = $('#ajax-modal');    
                    $('body').modalmanager('loading');
                    setTimeout(function () {
                        $modal.load('<?php echo base_url("batch_process/batch_qty_adjustment?product_id="); ?>'+product_id, '', function () { 
                            $modal.modal();
                        });
                    }, 1000);
                
            }
            
             function  add_free_issue(product_id)   {
               var $modal = $('#ajax-modal');    
                    $('body').modalmanager('loading');
                    setTimeout(function () {
                        $modal.load('<?php echo base_url("free_issue_process/add_new_free_issue_block?product_id="); ?>'+product_id, '', function () { 
                            $modal.modal();
                        });
                    }, 1000);
                
            }
            
             function  update_free_issue(free_issue_id)   {
               var $modal = $('#ajax-modal');    
                    $('body').modalmanager('loading');
                    setTimeout(function () {
                        $modal.load('<?php echo base_url("free_issue_process/update_free_issue_block?free_issue_id="); ?>'+free_issue_id, '', function () { 
                            $modal.modal();
                        });
                    }, 1000);
                
            }
            
            
            
            function remove_free_block(id) {
       bootbox.confirm({
           title: "Are You Sure ?",
           message: "Do you  want to remove free issue?.",
           buttons: {
               cancel: {
                   label: '<i class="fa fa-times"></i> No Cancel'
               },
               confirm: {
                   label: '<i class="fa fa-check"></i> Yes Confirm'
               }
           },
           callback: function(result) {
               if (result == true) {
                   jQuery.ajax({
                       type: "POST", 
                       url: "<?php echo base_url().'free_issue_process/update_free_issue_product?id='?>" + id,
                       //       data: 'id='+id,
                       cache: false,
                       success: function(response) {
                           var obj = JSON.parse(response);
                           if (obj.status == 1) {location.reload()} else {
                               bootbox.alert({
                                   message: obj.message,
                                   size: 'small'
                               });
      				location.reload()
                           }
                           
                       }
                   });
               }
           }
       });
      }
               
      
      
      
   </script>
</body>
<!-- end: BODY -->
</html>