<?php $this->load->view("common/header"); ?>
<!-- end: HEAD -->

<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;
	}
</style>
<link rel="stylesheet" href="<?php echo asset_url(); ?>css/buttons.dataTables.min.css" type="text/css" />
<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>
<!-- 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 -->
				<?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="<?php echo base_url('dashboard'); ?>">
									Dashboard
								</a>
							</li>
							<li>
								<a href="#">
									Store
									<?php $cmn = new $this->Common_Model();
									if ($cmn->check_permission(113, $this->session->userdata('ss_group_id'), 1)) {
										echo " S";
									} ?>
								</a>
							</li>

							<li class="active">
								GTN 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>GTN Details</h1>
						</div>

						<p>Please use the table below to navigate or filter the results. </p>
					</div>
				</div>
				<!-- end: PAGE HEADER -->
				<!-- start: PAGE CONTENT 
                    <!-- start grid -->
				<div class="row">
					<div class="col-md-12">
						<!-- start: DYNAMIC TABLE PANEL -->
						<div class="panel panel-default">
							<div class="panel-heading">
								<i class="fa fa-external-link-square"></i>
								Estimate Details
							</div>
							<div class="panel-body">
								<div id="error"></div>
								<!-- <input type="button" onClick="printDiv('printableArea')" value="Print product block summary" class="pull-right"/>-->
								<div id="printableArea">
									<div id="printableArea">
										<!--<div class="page-header">
                  <h3>Product Block Summary  </h3>
                </div>-->
										<table class="table table-bordered table-condensed table-hover table-striped dataTable" id="">

											<tr>
												<th> Reference number</th>
												<td>
													<div id="no_of_products"><?php echo $details['pgrnm_ref_no']; ?></div>
												</td>
											</tr>
											<tr>
												<th> Request number</th>
												<td>
													<div id="no_of_products"><?php echo $details['pgrnm_doc_no']; ?></div>
												</td>
											</tr>
											<tr>
												<th> Created By</th>
												<td>
													<div id="no_of_products"><?php echo $details['user_first_name']; ?></div>
												</td>
											</tr>
											<tr>
												<th> Created On</th>
												<td>
													<div id="no_of_products"><?php echo $details['pgrnm_date_time']; ?></div>
												</td>
											</tr>

											<th>Warehouse</th>
											<td>
												<div id="sales-rtn-val-tbl"><?php echo $details['warehouse_name']; ?></div>
											</td>
											</tr>
											<tr>
												<th>GTN Status</th>
												<td>
													<div id="sales-rtn-val-tbl"><?php if ($details['pgrnm_pick_up_status'] == 1) {
																					echo "Completed";
																				} else {
																					echo "Pending";
																				} ?></div>
												</td>
											</tr>




										</table>
									</div>
								</div>
								<div class="form-group">
									<hr>
									<h3>Estimate batch summary</h3>
									<table class="table table-bordered table-condensed table-hover table-striped dataTable" id="products_table">
										<thead>
											<tr>
												<th>Product Code</th>
												<th>Product Name</th>
												<th>Btach No</th>
												<th> Unit price</th>
												<th>Quantity</th>
												<th>Packing Damage</th>
												<th>Estimated Total Cost (QTY)</th>
												<th>Actual Total cost</th>
												<th>Mark Packaging Damage</th>

											</tr>
										</thead>
										<tbody>
											<?php foreach ($item_list as $il) { ?>
												<tr>
													<td><?php echo $il['product_code']; ?></td>
													<td><?php echo $il['product_name']; ?></td>
													<td><?php echo $il['pbi_ref_no']; ?></td>
													<td><?php echo $il['pgrni_unit_cost']; ?></td>
													<td><?php echo $il['quantity']; ?></td>
													<td><?php echo $il['packing_damage']; ?></td>
													<td>Rs. <?php echo $il['pbi_estimate_cost']; ?> ( QTY : <?php echo $il['pbi_qty']; ?>)</td>
													<td>Rs. <?php echo $il['pgrni_total_cost']; ?></td>
													<td><button class="btn btn-sm btn-danger" onclick="mark_packing_damage(<?php echo $il['pgrnp_id']; ?>)"> MAKR DAAMGE</button></td>

												</tr>




											<?php } ?>



										</tbody>
										<tfoot>
											<tr>
												<th>Product Code</th>
												<th>Product Name</th>
												<th>Btach No</th>
												<th> Unit price</th>
												<th>Quantity</th>
												<th>Estimated Total Cost (QTY)</th>
												<th>Actual Total cost</th>
												<th>Mark Packaging Damage</th>
											</tr>
										</tfoot>
									</table>
									<br>
									<br>
									<br>
								</div>






								<!--	<div class="form-group">
            <h3>Raw materials and intermediate product as a bulk</h3>
									<table class="table table-bordered table-condensed table-hover table-striped dataTable" id="products_table_2">
										<thead>
								            <tr>
												<th>Product Code</th>
												<th>Product Name</th>
												<th>Required Quntity</th>
												<th>Total estimated cost</th>
												
										
								            </tr>
								        </thead>
								        <tfoot>
											 <tr>
											    	<th>Product Code</th>
												<th>Product Name</th>
												<th>Required Quntity</th>
											<th>Total estimated cost</th>
													
								            </tr>
								            </tr>
								        </tfoot>
									</table>
									<br>
									</div>-->


							</div>
						</div>
						<!-- end: DYNAMIC TABLE PANEL -->
					</div>
				</div>

				<!-- 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>

		<!-- 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="<?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>
			function mark_packing_damage(id) {
				var gtn_id = $("#master_id").val();
				var status = 2;
				bootbox.confirm({
					title: "Are You Sure? ",
					message: "Do you want to Mark as packaging damage ?",
					buttons: {
						cancel: {
							label: '<i class="fa fa-times"></i> Cancel'
						},
						confirm: {
							label: '<i class="fa fa-check"></i> Yse Confirm'
						}
					},
					callback: function(result) {
						//console.log('This was logged in the callback: ' + result);
						//-----------------------------------------------------------
						if (result == true) {
							bootbox.prompt({
								title: "Enter Damage Quntity",
								inputType: 'text',
								callback: function(result) {
								    var dmgQty = result;
								    bootbox.prompt({
                                        title: 'Select defect reason',
                                        message: '<p>Please select an option below:</p>',
                                        inputType: 'radio',
                                        inputOptions: [
                                            <?php foreach($defect_list as $l){
                						      ?>
                						        {
                                                    text: '<?php echo $l->defect_desc; ?>',
                                                    value: '<?php echo $l->defect_id; ?>'
                                                },
                						      <?php
                                                } 
                                              ?>
                                        ],
                                        callback: function (result) {
                                            if(result !== null){
                                                defect_reason = result;
                                                jQuery.ajax({
            										type: "POST",
            										url: "<?php echo base_url() . 'production_material_in_out/markPackingDamage?gtn_item_id=' ?>" + id,
            										cache: false,
            										data: {
            											gtn_item_id: id,
            											result: dmgQty,
            											gtn_id: gtn_id,
            											defect_reason: defect_reason
            										},
            										success: function(response) {
            
            											//*********************************************
            											var obj = jQuery.parseJSON(response);
            											if (obj.status == 0) {
            												bootbox.alert(obj.validation);
            											} else {
            												displayNotice('page', obj.validation);
            												location.reload();
            											}
            											//*************************************************
            										}
            									});
                                            }
                                        }
                                    });
								}
							});

						}
						//---------------------------------------------------------- 
					}
				});
			}
		</script>
</body>
<!-- end: BODY -->

</html>