<div class="row">
	<div class="col-sm-1"></div>
	<div class="col-sm-10">
		<h6>توريدات الفروع</h6>
		<table class="table table-bordered table-hover">
			<thead>
				<tr>
					<th class="text-center" width="5%">م</th>
					<th class="text-center" width="10%">المبلغ</th>
					<th class="text-center" width="16%">مسئول الفرع</th>
					<th class="text-center" width="8%">كود</th>
					<th class="text-center" width="15%">الفرع</th>
					<th class="text-center" width="12%">التاريخ</th>
					<th class="text-center" width="15%">المستلم</th>
					<th class="text-center" width="14%">طريقة الدفع</th>
				</tr>
			</thead>
			<tbody>
				<?php
				$output = '';
				$sql = $conn->prepare("SELECT boxmoney.box_id,boxmoney.money_box,boxmoney.month_date,boxmoney.receipt ,boxmoney.pay_method, branches.b_name ,users.realName
                      FROM `boxmoney`,`branches` ,`users`
                      WHERE boxmoney.branch = branches.branchID AND boxmoney.father = users.user_Id
                        ORDER BY box_id DESC LIMIT 17 ");
				$sql->execute();
				if ($sql->rowCount() > 0) {
					$ss = 1;
					while ($row = $sql->fetch()) {
						$box_id = $row['box_id'];
						$bb = $row['pay_method'];
						switch ($bb) {
							case "1":
								$pay =  "كاش";
								$options = '<option selected value="1">كاش</option><option value="4" >فواتير</option>';
								break;
							case "4":
								$pay = "فواتير";
								$options = '<option value="1">كاش</option><option selected value="4" >فواتير</option>';
								break;
						}
						$output .= '<tr>
								<td style="padding:0px;margin:0px;"><button id="' . $box_id . '" style="font-weight:bold ;font-size:14px; padding:2;" class="btn btn-primary btn-ms btn-block box_edit ">' . $ss . '</button></td>
								<td id="mon' . $box_id . '" contenteditable="true">' . $row['money_box'] . '</td>
								<td>' . $row['realName'] . '</td>
								<td><a href="rent/print/boxPrint.php?box=' . $box_id . '"target="_blank">' . $box_id . '</td>
								<td>' . $row['b_name'] . '</td>
                <td>' . $row['month_date'] . '</td>
                <td>' . $row['receipt'] . '</td>
								<td style="padding:0px;margin:0px;" contenteditable="true"><select id="pay' . $box_id . '" class="form-control payMM" style="background-color:transparent;padding:3px;margine:0px;" >
								 	' . $options . '	</select></td></tr>  ';
						$ss = $ss + 1;
					}
				} else {
					$output .= '<tr><td colspan="7">لا يوجد سجلات ...</td></tr>';
				}
				echo $output;
				?>
			</tbody>
			<tfoot></tfoot>
		</table>
	</div>
	<div class="col-sm-1"></div>
</div>
<script>
	$(document).ready(function() {
		$(".box_edit").click(function(event) {
			event.preventDefault();
			if (confirm("هل تريد تحديث قيمة  و طريقة دفع هذا السند؟")) {
				var id = $(this).attr('id');
				var money_box = $("#mon" + id).html();
				var pay_method = $("#pay" + id).val();
				$.ajax({
					url: "acc/money_box_update.php",
					method: "POST",
					data: {
						id: id,
						money_box: money_box,
						pay_method: pay_method
					},
					success: function(data) {
						$('#site').load("includes/day_acc.php");
					}
				});
			} else {
				return false;
			}
		}); //
	});
</script>