<?php $this->load->view("common/header"); ?>
<!-- end: HEAD -->
<link rel="stylesheet" href="<?php echo asset_url();?>css/buttons.dataTables.min.css" type="text/css" />
<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->
<!-- end: HEAD -->
<!-- start: BODY -->
<style type="text/css">
   .dt-button-collection {
   font-size: 1.4em;
   }
   .dt-button-collection .active span:after {
   font-family: FontAwesome;
   content: " \f00c";
   text-align: right
   }
   a.dt-button, button.dt-button, div.dt-button, .dt-buttons {
   font-size: .83em;
   float: right!important;
   /*  background-color:#e9e9e9;
   background-image:linear-gradient(to bottom,#fff 0,#e9e9e9 100%);*/
   margin-left: .3em;
   }
</style>
<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 -->
            <?php $this->load->view("common/logo"); ?>
            <!-- 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="#"> DASHBOARD </a> </li>
                     <li> <a href=""> DELIVEY </a> </li>
                     <li class="active">DELIVERY 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">
                     <h3>DELIVERY DETAILS</h3>
                  </div>
               </div>
            </div>
            <!-- end: PAGE HEADER --> 
            <!-- start: PAGE CONTENT 
               <!-- start grid -->
            <div class="row">
               <div clas="col-md-12">
                  <div class="form-group">
                     <div class="col-md-12">
                        <div class="well well-sm">
                           <div class="col-xs-4 border-right">
                              <div class="col-xs-2"><i class="fa fa-3x fa-truck padding010 text-muted"></i></div>
                              <div class="col-xs-10">
                                 <h4 class="">DELIVERY NO : <?php echo $details['d_ref_no'];?></h4>
                                 VEHICLE NO : <?php echo $details['vehicle_code'];?> <br>
                                 DATE : <?php  echo $details['added_date_time'];?><br>STATUS  <span >: <?php  echo $details['ds_name'];?></span><br>
                                 </p>
                              </div>
                              <div class="clearfix"></div>
                           </div>
                           <div class="col-xs-4 border-right">
                              <div class="col-xs-2"><i class="fa fa-3x fa-user padding010 text-muted"></i></div>
                              <div class="col-xs-10">
                                 <h4 class=""> DRIVER : <?php echo $details['user_first_name']." ".$details['user_last_name'];; ?></h4>
                                 <p>NOTE : <?php echo $details['d_note'];?> </p>
                              </div>
                              <div class="clearfix"></div>
                           </div>
                           <div class="col-xs-4">
                              <div class="col-xs-2"><i class="fa fa-3x fa-building-o padding010 text-muted"></i></div>
                              <div class="col-xs-10">
                                 <h4 class=""><?php echo $details['name']; ?></h4>
                                 <p>APPROVAL STATUS  <span > : <?php echo $details['mas_name']; ?> </span><br>APPROVAL BY : <?php echo $details['approval_user_first_name']." ".$details['approval_user_last_name']; ?>
                                 </p>
                              </div>
                              <div class="clearfix"></div>
                           </div>
                           <div class="clearfix"></div>
                        </div>
                        <!--col-xs-4-->
                     </div>
                  </div>
                  <div class="form-group">
                     <div class="col-md-12">
                        <!-- start: DYNAMIC TABLE PANEL -->
                        <div class="panel panel-default">
                           <div class="panel-heading" > DISPATCH NOTES</div>
                           <div class="panel-body">
                              <table class="table items table-striped table-bordered table-condensed table-hover"  width="100%" style="text-align:left">
                                 <thead>
                                    <tr>
                                       <th style="" class="col-md-1">DIS. NO</th>
                                       <th style="" class="col-md-1">CUS CODE</th>
                                       <th >CUSTOMER NAME</th>
                                       <th >CUSTOMER ADDRESS</th>
                                       <th >CONTACT NO</th>
                                       <th >VALUE</th>
                                       <th style="" class="col-md-1">ACTION</th>
                                    </tr>
                                 </thead>
                                 <tbody>
                                    <?php foreach($dispatch_note_list as $dnl){ ?>
                                    <tr>
                                       <td><?php echo $dnl['dpn_ref_no']; ?></td>
                                       <td><?php echo $dnl['cus_code']; ?></td>
                                       <td><?php echo $dnl['cus_name']; ?></td>
                                       <td><?php echo $dnl['cus_address']; ?></td>
                                       <td><?php echo $dnl['cus_phone']; ?></td>
                                       <td><?php echo $dnl['total_dpn_value']; ?></td>
                                       <td>
                                          <div class="btn-group text-left">
                                             <button data-toggle="dropdown" class="btn btn-default btn-xs  dropdown-toggle" type="button">Actions <span class="caret"></span></button>
                                             <ul role="menu" class="dropdown-menu pull-right">
                                                <li><a href="<?php echo base_url('dispatch/dispatch_note_details?id='). $dnl['dpn_id']; ?>"  target="_blank"><i class="fa fa-file-text-o"></i> DETAILS</a></li>
                                                <li><a href="#"  onClick="dispatch_note_print(<?php echo $dnl['dpn_id'];?>)" ><i class="fa fa-print"></i> PRINT</a></li>
                                                <?php if($dnl['invoice_status']==0 && $details['d_status']==2 ){ ?>
                                                <li><a href="<?php echo base_url('dispatch/add_dispatch_invoice?id='). $dnl['dpn_id']; ?>"  ><i class="fa fa-pencil-square-o"></i> INVOICE </a></li>
                                                <?php } ?>
                                             </ul>
                                          </div>
                                          <?php if($dnl['invoice_status']==1){ ?>
                                          <span class="btn btn-xs btn-success"> <i class="fa fa-check"></i></span>
                                          <?php } ?>
                                       </td>
                                    </tr>
                                    <?php } ?>
                                 </tbody>
                                 <tfoot>
                                    <tr class="tfoot active" id="tfoot">
                                       <th style="" class="col-md-1">DIS. NO</th>
                                       <th style="" class="col-md-1">CUS CODE</th>
                                       <th>CUSTOMER NAME</th>
                                       <th >CUSTOMER ADDRESS</th>
                                       <th >CONTACT NO</th>
                                       <th >VALUE</th>
                                       <th style="" class="col-md-1">ACTION</th>
                                    </tr>
                                 </tfoot>
                              </table>
                           </div>
                        </div>
                        <div class="panel panel-default">
                           <div class="panel-heading">RETURN NOTE</div>
                           <div class="panel-body">
                              <table class="table items table-striped table-bordered table-condensed table-hover"  width="100%" style="text-align:left">
                                 <thead>
                                    <tr class="tfoot active" id="tfoot">
                                       <th class="col-md-1">RETURN NOTE NO</th>
                                       <th class="col-md-1">DATE</th>
                                       <th class="col-md-1">CUS CODE</th>
                                       <th >CUS NAME</th>
                                       <th class="col-md-1">ITEM AMOUNT</th>
                                       <th class="col-md-1">DELIVERY CHARGE</th>
                                       <th class="col-md-1">RETURN AMOUNT</th>
                                       <th class="col-md-1">ACTION</th>
                                    </tr>
                                 </thead>
                                 <tbody>
                                    <?php foreach($return_note_list as $rl){ ?>
                                    <tr>
                                       <td><?php echo $rl->rtn_ref_no; ?> </td>
                                       <td><?php echo $rl->added_date_time ;?> </td>
                                       <td><?php echo $rl->cus_code ;?> </td>
                                       <td><?php echo $rl->cus_name; ?> </td>
                                       <td><?php echo $rl->rtn_total_value; ?> </td>
                                       <td><?php echo $rl->rtn_delivery_charge; ?> </td>
                                       <td><?php echo $rl->return_note_amount; ?> </td>
                                       <?php if($details['d_status']==2){ ?>
                                       <td>
                                            <div class="btn-group text-left">
                                             <button data-toggle="dropdown" class="btn btn-default btn-xs  dropdown-toggle" type="button">Actions <span class="caret"></span></button>
                                             <ul role="menu" class="dropdown-menu pull-right">
                                                <?php if($details['d_status']==2 ){ ?>
                                                <li><a href="#"  onClick="return_forward(<?php echo $dnl['dpn_id'];?>)" ><i class="fa fa fa-mail-forward"></i> FORWARD</a></li>
                                                <li><a href="#"  onClick="return_collecte(<?php echo $dnl['dpn_id'];?>)" ><i class="fa fa fa-check"></i> MARK AS COLLECTED</a></li>
                                               <?php } ?>
                                             </ul>
                                          </div>
                                           
                                           
                                       </td>
                                       
                                       <?php } ?>
                                    </tr>
                                    <?php } ?> 
                                 </tbody>
                                 <tfoot>
                                    <tr class="tfoot active" id="tfoot">
                                       <th class="col-md-1">RETURN NOTE NO</th>
                                       <th class="col-md-1">DATE</th>
                                       <th class="col-md-1">CUS CODE</th>
                                       <th >CUS NAME</th>
                                       <th class="col-md-1">ITEM AMOUNT</th>
                                       <th class="col-md-1">DELIVERY CHARGE</th>
                                       <th class="col-md-1">RETURN AMOUNT</th>
                                       <th class="col-md-1">ACTION</th>
                                    </tr>
                                 </tfoot>
                              </table>
                           </div>
                        </div>
                        <div class="panel panel-default">
                           <div class="panel-heading" > DISPATCH NOTES ITEMS SUMMARY</div>
                           <div class="panel-body">
                              <table class="table items table-striped table-bordered table-condensed table-hover"  width="100%" style="text-align:left">
                                 <thead>
                                    <tr>
                                       <th style="" class="col-md-1">PRODUCT CODE</th>
                                       <th >PRODUCT NAME</th>
                                       <th class="col-md-1">QUANTITY</th>
                                       <th class="col-md-1">INVOICED</th>
                                       <th class="col-md-1">RETURNED</th>
                                       <th class="col-md-1">PHYSICAL</th>
                                       <th style="" class="col-md-1">VARIANCE</th>
                                    </tr>
                                 </thead>
                                 <tbody>
                                    <?php foreach($product_list as $pl){ ?>
                                    <tr>
                                       <td><?php echo $pl->product_code; ?> </td>
                                       <td><?php echo $pl->product_name ?> </td>
                                       <td><?php echo $pl->issued_qty ?> </td>
                                       <td><?php echo $pl->invoice_qty ?> </td>
                                       <td><?php echo $pl->return_qy ?> </td>
                                       <td>0</td>
                                       <td><?php echo $pl->return_qy-0 ?></td>
                                    </tr>
                                    <?php } ?>
                                 </tbody>
                                 <tfoot>
                                    <tr class="tfoot active" id="tfoot">
                                       <th style="" class="col-md-1">PRODUCT CODE</th>
                                       <th >PRODUCT NAME</th>
                                       <th class="col-md-1">QUANTITY</th>
                                       <th class="col-md-1">INVOICED</th>
                                       <th class="col-md-1">RETURNED</th>
                                       <th class="col-md-1">PHYSICAL</th>
                                       <th style="" class="col-md-1">VARIANCE</th>
                                    </tr>
                                 </tfoot>
                              </table>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
            <div class="modal-footer">
               <div class="col-md-12">
                  <div class="col-md-2 pull-right">
                     <div class="form-group">
                        <a onClick="delivery_sheet_print(<?php echo $details['d_id'] ?>)" class="form-control col-md-1 btn btn-info pull-right"> DELIVERY SHEET</a>
                     </div>
                  </div>
                  <div class="col-md-2 pull-right ">
                     <div class="form-group">
                        <a onClick="loading_sheet_print(<?php echo $details['d_id'] ?>)" class="form-control col-md-1 btn btn-info "> LOADING SHEET</a>
                     </div>
                  </div>
                  <?php if($details['d_status']==1) {?>
                  <div class="col-md-3 pull-right">
                     <div class="form-group">
                        <a onClick="create_issue_note(<?php echo $details['d_id'] ?>)" class="form-control col-md-1 btn btn-success pull-right"> MARK AS LOADED</a>
                     </div>
                  </div>
                  <?php } ?>
                  <div class="col-md-2 pull-right">
                     <div class="form-group">
                        <a class="btn btn-primary" href="<?php echo base_url('delivery_administration/dispatch_delivery_allocated_map').'?id=' . $details['d_id']  ?>" target="_blank" ><i class="fa fa-map-marker"></i> SHOW ROAD MAP</a>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </div>
   </div>
   </div>
   <!--col-md-8-->
   <div class="col-md-12"> </div>
   </form>
   <!-- end: DYNAMIC TABLE PANEL --> 
   </div>
   </div>
   <span style="font-family: 'Times New Roman'; font-size:14px; " > </span> 
   <!-- end grid --> 
   </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>
   <input name="tmpVal" type="hidden" id="tmpVal" value="0" >
   <input name="" id="type_sale" type="hidden" value="22">
   <!-- 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 type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.js"></script> 
   <script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.min.js"></script> 
   <script type="text/javascript" src="<?php echo asset_url(); ?>js/jquery.dataTables.min.js"></script> 
   <script type="text/javascript" src="<?php echo asset_url(); ?>js/dataTables.bootstrap.min.js"></script> 
   <script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/dataTables.buttons.min.js"></script> 
   <script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/buttons.print.min.js"></script> 
   <script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/buttons.flash.min.js"></script> 
   <script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/jszip.min.js"></script> 
   <script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/pdfmake.min.js"></script> 
   <script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/vfs_fonts.js"></script> 
   <script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/buttons.html5.min.js"></script> 
   <script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/buttons.print.min.js"></script> 
   <script type="text/javascript" src="<?php echo base_url('thems/js/bootbox.min.js'); ?>"></script>
   <script>
      //----------------------------------------------------------------------------	
      jQuery(document).ready(function() {
         
      	
      });
      //----------------------------------------------------------------------------	
      
      //----------------------------------------------------------------------------	
      function loading_sheet_print(id) 
      {
      	u=location.href;
      	t=document.title;
      	window.open('<?php echo base_url() ?>delivery/loding_sheet_print?id='+id,'sharer','toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');return false;
      }
      //----------------------------------------------------------------------------		
      
      
      //----------------------------------------------------------------------------	
      function delivery_sheet_print(id)
      {
      	u=location.href;
      	t=document.title;
      	window.open('<?php echo base_url().'delivery/delivery_sheet_print?id='?>'+id,'sharer','toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');return false;
      }
      //----------------------------------------------------------------------------		
      
      function dispatch_note_print(id)
      {
      	u=location.href;
      	t=document.title;
      	window.open('<?php echo base_url().'dispatch/dispatch_note_print?id='?>'+id,'sharer','toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');return false;
      }
      
      
      
      
      //----------------------------------------------------------------------------		
      function create_issue_note(id) {
          bootbox.confirm({
              title: "Are You Sure ?",
              message: "Do you want to this dlivery  mark as loaded delivery.",
              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().'delivery/auto_issue_batch_items?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.validation,
                                      size: 'small'
                                  });
                                  location.reload();
                              }
      						//location.reload();
                              //loadGrid();
                          }
                      });
                  }
              }
          });
      }
      //----------------------------------------------------------------------------		
      function return_collecte(id) {
          bootbox.confirm({
              title: "Are You Sure ?",
              message: "Do you want mark as collected?.",
              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().'delivery/auto_issue_batch_items?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.validation,
                                      size: 'small'
                                  });
                                  location.reload();
                              }
      						//location.reload();
                              //loadGrid();
                          }
                      });
                  }
              }
          });
      }
      //----------------------------------------------------------------------------		
      		
      
      
   </script>
</body>
<!-- end: BODY -->
</html>