<!-- Content Header (Page header) -->
<section class="content-header">
	<div class="container-fluid">
		<div class="row mb-2">
			<div class="col-sm-6">
				<h1>PESAN BARANG</h1>
			</div>

		</div>
	</div>
</section>
<div id="flash" data-flash="<?= $this->session->flashdata('success'); ?>"></div>

<section class="content">

	<div class="card">
		<div type="button" class="card-header" href="#collapseCard1" data-toggle="collapse" role="button" aria-expanded="true" aria-controls="collapseCard2">
			<h3 class=" fa-1x text-center font-bold">DAFTAR NAMA SUPLLIER</h3>
		</div>
		<div class="collapse" id="collapseCard1">
			<div class="card-body">
				<div class="row">
					<?php foreach ($invid->result() as $am => $data) : ?>
						<div class="col-12 col-lg-4 col-sm-6  align-items-stretch">
							<div class="card bg-light">
								<div class="card-header text-muted border-bottom-0">
									<span class="right badge badge-secondary"><?= $data->sup_acc ?></span> Supllier
								</div>
								<div class="card-body ">
									<div class="row">
										<div class="col-12">
											<h2 class="lead"><b><?= $data->nama_sup ?></b></h2>
											<ul class="ml-12 mb-0 fa-ul text-muted">
												<li class="small"><span class="fa-li"></span> <b>Address :</b> <?= $data->alamat_sup ?></li>
												<li class="small"><span class="fa-li"></span> <b>Phone #:</b> <?= $data->no_hpsup ?></li>
											</ul>
										</div>

									</div>
								</div>
							</div>
						</div>
					<?php endforeach ?>
				</div>
			</div>
		</div>
	</div>

	<div class="row">
		<div class="col-12 col-md-12 col-sm-12  ">

			<div class="card ">
				<div class="card-header">
					<h3 class="card-title">Data Pembelian Barang Hari ini</h3>

					<div class="card-tools">
						<button type="button" class="btn btn-tool" data-card-widget="collapse" data-toggle="tooltip" title="Collapse">
							<i class="fas fa-minus"></i></button>
						<button type="button" class="btn btn-tool" data-card-widget="remove" data-toggle="tooltip" title="Remove">
							<i class="fas fa-times"></i></button>
					</div>
				</div>
				<div class="card-body">
					<table class='table table-hover table-sm '>
						<tbody>
							<?php $i = 1; ?>
							<?php foreach ($rowpesanbrg->result() as $am => $data) : ?>
								<tr>
									<th scope="row"><?= $i; ?>.</th>
									<td>
										<b><?= $data->suplier ?> [ <?= $data->invoice_nobrg ?> ]</b>
									</td>
									<td>
										<a href="<?= site_url('/pesB/cetakbrg/' . $data->id_pesbrg) ?>" target="_blank">
											<i class="btn  btn-outline-primary w-100 btn-sm"><i class="fas fa-print"></i> print Struk</i>
										</a>
									</td>
								</tr>
								<?php $i++; ?>
							<?php endforeach ?>
						</tbody>
					</table>
				</div>

			</div>
		</div>
	</div>

	<div class="row">
		<div class="col-12 col-md-12 col-sm-12  ">
			<div class="card card-outline card-primary p-2">
				<form action="<?= base_url('pesB/addpesanbrgdetail'); ?>" method="post">


					<div class="row">
						<div class='col-lg-3 col-sm-6 mt-2'>
							<div class="input-group align-center">
								<div class="input-group-prepend">
									<span class="input-group-text"><i class="fas fa-calendar-alt"></i></span>
								</div>
								<input name="tanggal_brg" id="tanggal" type="text" class="form-control " value="<?php echo date('d / m / Y') ?>" readonly="on">
							</div>
						</div>
						<div class='col-lg-3 col-sm-6 mt-2 '>
							<div class="input-group align-center">
								<div class="input-group-prepend">
									<span class="input-group-text"><i class="fas fa-file-invoice"></i></span>
								</div>
								<input readonly="on" name="invoice_nobrg" id="tanggal" type="text" class="form-control " value="<?= $invoicea ?>">
							</div>
						</div>
						<div class='col-lg-4 col-sm-6 mt-2'>
							<div class="input-group align-center">
								<div class="input-group-prepend">
									<span class="input-group-text"><i class="fas fa-user-tie"></i> &nbsp;</span>
								</div>
								<select value="<?= set_value('suplier'); ?>" name="suplier" required id="costumer" class="form-control text-uppercase">
									<option value="">- Pilih Supllier -</option>
									<?php foreach ($invid->result() as $am => $data) : ?>
										<option value="<?= $data->nama_sup ?>"><?= $data->nama_sup ?></option>
									<?php endforeach ?>

								</select>
							</div>
						</div>
						<div class='col-lg-2 col-sm-6 ' style="font-size: 13px">

							<i class="btn btn-outline-primary w-100 mt-2" type="submit" data-toggle="modal" data-target="#exampleModalCenter1"><i class='fa fa-plus'></i> Barang</i>
						</div>



						<div class='col-lg-12'>
							<div class="table mt-2  ">
								<table class=" table-hover text-gray-900 text-center " style=" width:100% ">
									<tr>
										<th scope=" col ">No</th>
										<th class=" text-left" style="width: 15%" scope="col">Part number</th>
										<th class=" text-left" style="width: 40%" scope="col">Part Name</th>
										<th style="width: 50px  text-right" scope="col">Qty</th>
										<th scope="col">Unit Price</th>
										<th scope="col">Total</th>
									</tr>
									<tbody class=" table-sm">

										<?php $no = 1;

										if ($buysparepart->num_rows() > 0) {
											foreach ($buysparepart->result() as $c => $data) { ?>
												<tr>
													<td style="width: 50px" scope="row"><?= $no++ ?>.</td>
													<td class=" text-left " scope="col"> <?= $data->barcode_brg ?></td>
													<td class=" text-left " style="width: 40px;" scope="col"><?= $data->name_brg ?></td>
													<td style="width: 60px;" scope="col"><?= $data->stok_brg ?></td>
													<td scope="col"><?= $data->hargam_brg ?></td>

													<td scope="col"><?= $data->hargat_brg ?></td>
													<td scope="col">

														<a id="btn-hapus" href="<?= site_url('pesB/delpesananbrg/' . $data->id_pesbrg_cart) ?>">
															<button type="button" class="btn btn-warning btn-sm"><i class="fas fa-trash-alt"></i></button>
														</a>
													</td>

													</td>
												</tr>
										<?php
											}
										} else {
											echo '<tr>
										<td colspan="8" class="text-center"> Tidak Data Sparepart yang di catat </td>
									</tr>';
										} ?>
									</tbody>

								</table>

								<div class="col-lg-12 col-sm-12 mt-2">
									<div class="input-group align-center">
										<div class="input-group-prepend">
											<span class="input-group-text">Pembayaran</span>
										</div>
										<select required name="byr_brg" class="form-control text-uppercase">
											<option value="">- Pilih Pembayaran -</option>
											<option value="0">Tunai</option>
											<option value="1">Hutang</option>
										</select>
									</div>
								</div>

								<button class="btn btn-lg btn-primary w-100 mt-2" type="submit" data-toggle="modal" data-target="#exampleModalCenter">Proses Pesanan Barang</button>

							</div>
						</div>
				</form>
			</div>
		</div>
	</div>

	<!-- end isi konten -->

	<!-- Modal Pesan Barang-->
	<form action="<?= base_url('PesB/addpartpesan'); ?>" method="post">
		<div class="modal fade bd-example-modal-lg" id="exampleModalCenter1" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
			<div class="modal-dialog modal-dialog-centered modal-lg " role="document">
				<div class="modal-content">
					<div class="modal-body">

						<!-- <button class="btn btn-outline-primary w-100" data-toggle="modal" data-target="#exampleModal1">Cek Data Sparepart Gudang</button> -->
						<form action="<?= base_url('ssProses/addpart'); ?>" method="post">
							<div class='row'>

								<div class="col-12 col-lg-4 col-sm-12 mt-2 ">
									<div class="input-group align-center">
										<div class="input-group-prepend">
											<span class="input-group-text "><i class="fas fa-tools"></i></span>
										</div>
										<input id="barcodebrg" autocomplete="off" placeholder="Part Number" name="barcode_brg" type="text" class="form-control ">
									</div>
								</div>

								<div class="col-12 col-lg-8 col-sm-12 mt-2 ">
									<div class="input-group align-center">
										<div class="input-group-prepend">
											<span class="input-group-text "><i class="fas fa-archive"></i></span>
										</div>
										<input id="merekbrg" value="" autocomplete="off" placeholder="Part Name" name="name_brg" type="text" class="form-control ">
									</div>
								</div>

								<div class="col-12 col-lg-4 col-sm-12 mt-2 ">
									<div class="input-group">
										<div class="input-group-prepend">
											<span class="input-group-text"><i class="fas fa-box-open"></i></span>
										</div>
										<select name="stok_brg" class="custom-select" value="<?= set_value('stok_brg'); ?>" required>
											<?php $mer = $this->input->post('stok_brg') ?>
											<option value=''>- Jumlah -</option>
											<option value="1">1</option>
											<option value="2">2</option>
											<option value="3">3</option>
											<option value="4">4</option>
											<option value="5">5</option>
											<option value="6">6</option>
											<option value="7">7</option>
											<option value="8">8</option>
											<option value="9">9</option>
											<option value="10">10</option>
											<option value="11">11</option>
											<option value="12">13</option>
											<option value="13">13</option>
											<option value="14">14</option>
											<option value="15">15</option>

										</select>
									</div>
								</div>

								<div class="col-12 col-lg-8 col-sm-12 mt-2 ">
									<div class="input-group align-center">
										<div class="input-group-prepend">
											<span class="input-group-text mb-2"><i class="fas fa-money-bill-wave-alt"></i></span>
										</div>
										<input id="hargambrg" value="" autocomplete="off" placeholder="Harga Part" name="hargam_brg" type="text" class="form-control mb-2 ">

									</div>
								</div>
							</div>
							<form action="<?= base_url('ssProsesedit/addpart'); ?>" method="post">

								<input id="hargaubrg" value="" autocomplete="off" placeholder="modal Part" name="hargau_brg" type="hidden" class="form-control mb-2 ">
								<input id="idkatbrgstok" value="" autocomplete="off" placeholder="id Part" name="id_katbrgstok" type="hidden" class="form-control mb-2 ">
								<button type="submit" class="btn btn-secondary w-100">Tambah Item Perbaikan</button>
							</form>

					</div>
				</div>
			</div>
		</div>
	</form>

	<!-- Modal katalog perbaikan -->
	<div class="modal fade " id="exampleModal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
		<div class="modal-dialog modal-dialog-centered modal-xl " role="document">
			<div class="modal-content ">
				<div class="modal-body">

					<div class="table table-s p-1  ">
						<table style="font-size: 13px;" class=" table-hover  text-gray-900 table-responsive-lg w-100 " id="example1">
							<thead>
								<th class="text-left">Catalog</th>
								<th class="text-left">Part Number</th>
								<th class="text-left">Merek</th>
								<th class="text-left">Part name </th>
								<th class="text-left">Stok Awal</th>
								<th class="text-left">Harga M</th>
								<th style="width: 10px" scope="col">Status</th>
								</tr>
							</thead>
							<?php foreach ($getpart->result() as $am => $data) : ?>

								<tr class=" table-sm ">
									<td class="text-left text-uppercase"><?= $data->nama_katbrg ?></td>
									<td class="text-left text-uppercase"><?= $data->barcode_brg ?></td>
									<td class="text-left text-uppercase w-25"><?= $data->merek_brg ?></td>
									<td class="text-left text-uppercase"><?= $data->name_brg ?></td>

									<td class="text-left text-uppercase"><?= $data->stok_brg ?></td>
									<td class="text-left text-uppercase "><?= $data->hargam_brg ?></td>

									<td>
										<button type="button" class="btn btn-success" id="selectpart" data-merek_brg="<?= $data->merek_brg ?> <?= $data->name_brg ?>" data-hargam_brg="<?= $data->hargam_brg ?>" data-hargau_brg="<?= $data->hargau_brg ?>" data-barcode_brg="<?= $data->barcode_brg ?>" data-id_katbrgstok="<?= $data->id_katbrgstok ?>">
											<i class=" fas fa-cart-arrow-down"></i>
										</button>
									</td>
								</tr>

							<?php endforeach ?>
							</tbody>

						</table>

					</div>
				</div>
			</div>
		</div>
	</div>


</section>

<script src="<?php echo base_url(); ?>/assets/dist/js/jquery-2.1.1.js"></script>
<script>
	$(document).ready(function() {
		$(document).on('click', '#select', function() {
			var katalok = $(this).data('katalok');
			var merek = $(this).data('merek');
			var stok = $(this).data('stok');
			var idstok = $(this).data('idstok');
			var koderakbrg = $(this).data('koderakbrg');
			var hargam_brg = $(this).data('hargam_brg');


			$('#hargambrg').val(hargam_brg);
			$('#nama_katbrg').val(katalok);
			$('#merek_brg').val(merek);
			$('#stok_brg').val(stok);
			$('#id_katbrgstok').val(idstok);
			$('#koderak_brg').val(koderakbrg);
			$('#exampleModalCenter2').modal('hide');
		})
	})

	$(document).ready(function() {
		$(document).on('click', '#selectpart', function() {
			var id_katbrgstok = $(this).data('id_katbrgstok');
			var merek_brg = $(this).data('merek_brg');
			var hargam_brg = $(this).data('hargam_brg');
			var hargau_brg = $(this).data('hargau_brg');
			var barcode_brg = $(this).data('barcode_brg');
			var koderak_brg = $(this).data('koderak_brg');

			$('#idkatbrgstok').val(id_katbrgstok);
			$('#merekbrg').val(merek_brg);
			$('#hargambrg').val(hargam_brg);
			$('#hargaubrg').val(hargau_brg);
			$('#barcodebrg').val(barcode_brg);
			$('#exampleModal1').modal('hide');
		})
	})
</script>