<?php
$permission  = explode(',',$_SESSION['permission_id']);
if(!in_array(5,$permission) && !in_array(1,$permission) ){

?>
<script>
window.location="starter.php";
</script>
<?php
}
?>
<style >
	tfoot {
    display: table-header-group !important;
}

td{
	text-align: center !important;
}
th{
	text-align: center !important;
}

textarea{
	height: 38px !important;
	resize: none;
}

.table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td {
    padding: 10px 5px;

    }

    .badge:empty{
    	display: initial;
    }

    .btn_add_item{
    	padding: 0px 0px;
    }

    .bootstrap-select.btn-group .btn .filter-option{
    	text-align: center;
    }

    .purchase_table {
    	width: 96% !important;
    }
</style>

<div id="add-form-cont" class="panel-collapse collapse panel" aria-expanded="false" style="height: 0px; position: relative; top:-3px; width:98%; margin:0px auto;">
	<div class="panel-body">
		<form class="form-horizontal" method="post" id="add_form" enctype="multipart/form-data">
			<div>
			<input type="hidden" id="access_token" name="access_token"  value="">
			<input type="hidden" id="total_quantity_old" name="total_quantity_old" >
			<input type="hidden" id="total_rows" name="total_rows" value="1">
				<div class="col-sm-12">

					<div class="form-group">


						<div class="form-group has-feedback has-feedback-left form-group-material col-sm-3">
							<label class="control-label multi_lang">رقم وصل الشراء</label>
							<input type="text" id="purchase_number" name="purchase_number" class="form-control multi_lang" placeholder="رقم وصل الشراء" >
							<div class="form-control-feedback">
								<i class="icon-coins text-muted"></i>
							</div>
						</div>

						<div class="form-group has-feedback has-feedback-left form-group-material col-sm-2">
							<label class="control-label multi_lang">التاريخ</label>
								<input type="text" id="purchase_date" name="purchase_date" class="form-control multi_lang daterange-single" placeholder="التاريخ" >
								<div class="form-control-feedback">
									<i class=" icon-calendar52 text-muted"></i>
								</div>
						</div>

						<div class="form-group has-feedback has-feedback-left  col-sm-2">
							<label class="control-label multi_lang">اختيار المخزن</label>
							
							<select class="form-control multi_lang" name="stock_id_fk" id="stock_id_fk" data-width="100%" placeholder="المخزن">

							</select>
							<div class="form-control-feedback">
								<i class="icon-store text-muted"></i>
							</div>
						</div>

						<div class="form-group has-feedback has-feedback-left  col-sm-2">
							<label class="control-label multi_lang">المورد</label>
							
							<select class="form-control multi_lang" name="supplier_id_fk" id="supplier_id_fk" data-width="100%" data-live-search="true" placeholder="المورد" required="required">

							</select>
							<div class="form-control-feedback">
								<i class="icon-truck text-muted"></i>
							</div>
						</div>

						<div class="form-group has-feedback has-feedback-left form-group-material col-sm-3">
							<label class="control-label multi_lang">ملاحظات</label>
							<textarea type="text" id="purchase_note" name="purchase_note" class="form-control multi_lang" placeholder="ملاحظات" > </textarea> 
							<div class="form-control-feedback">
								<i class="icon-notebook text-muted"></i>
							</div>
						</div>
						


					</div>

					<div class="form-group">
						<div class="table-responsive1">
							<table class="table col-sm-12 table-bordered .table-sm">
								<thead>
									<tr class="bg-blue ">
										<th>#</th>
										<th class="multi_lang">الرمز المحلي</th>
										<th class="multi_lang">الرمز الاجنبي</th>
										<th class="multi_lang">الكمية</th>
										<th class="multi_lang">اطوال المواد</th>
										<th class="multi_lang">الطول الكلي</th>
										<th class="multi_lang">سعر الشراء</th>
										<th class="multi_lang">الكلفة الاجمالية</th>
										<th class="multi_lang">ملاحظات</th>
										<th></th>
									</tr>
								</thead>
								<tbody id="purchase_item_body" >
									<tr  id="item_row_1" >
										<td width="5%" id="num_1">1</td>
										<td width="12%">
											
											<select class="form-control multi_lang" name="product_id_fk_1" id="product_id_fk_1" data-width="100%" placeholder="رمز المادة"  data-live-search="true">

											</select>
										</td>
										<td width="12%" id="forign_id_1"></td>
										<td width="8%">
											<input type="number" id="purchase_quantity_1" name="purchase_quantity_1"  class="form-control multi_lang" placeholder="الكمية" value="1"  >
										</td>
										<td id="products_1"></td>
										<td width="7%" >
											<input id="total_length_1" name="total_length_1" type="text" class="form-control" readonly >
										</td>
										<td width="8%">
											<input id="buy_price_per_meter_1" name="buy_price_per_meter_1" type="text" class="form-control multi_lang" placeholder="سعر شراء المتر" onchange="calc_total_item_cost(this.id);" >
										</td>
										<td width="9%" id="total_item_cost_1"> 0 $</td>
										<td width="10%">
											<textarea type="text" id="purchase_item_note_1" name="purchase_item_note_1" class="form-control multi_lang" placeholder="ملاحظات" > </textarea>
										</td>
										<td width="6%">
											<button class="btn btn-link btn_add_item" onclick="Add_Rows();" id="">
												<i  class="icon-add text-blue"></i>
											</button>
											
										</td>
									</tr>
									
									
								</tbody>
								<tfoot>
									<tr class="bg-teal-400">
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th></th>
										<th id="purchase_total">$ 0</th>
										<th></th>
										<th></th>
									</tr>
								</tfoot>
							</table>
						</div>



					</div>

					

					



				</div>
			</div>

			<div class="text-right">
				<button type="submit" id="submit_add_btn" class="btn btn-primary btn-labeled btn-labeled-left">
					<span class="multi_lang">حفظ</span> <b><i class="icon-floppy-disk"></i></b>
				</button>
				<a href="#add-form-cont" id="add_form_cancel" class="btn btn-labeled btn-labeled-left bg-danger heading-btn" data-toggle="collapse">
					<span class="multi_lang">اغلاق</span>  <b><i class="icon-cross"></i></b>
				</a>
			</div>
		</form>
	</div>
</div>

<div id="edit_form_cont" class="modal fade" style="display: none;">
	<div class="modal-dialog modal-lg">
		<form class="form-horizontal"  name="edit_form" method="post" id="edit_form" enctype="multipart/form-data">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"><i class="icon-cross"></i></button>
					<h4 class="modal-title multi_lang">تحرير المشتريات</h4>
				</div>

				<div class="modal-body">
						<input type="hidden" name="itemid" id="edit_objid" value="">
						<input type="hidden" id="edit_total_rows" name="edit_total_rows" value="1">

						<div class="form-group">

							<div class="form-group has-feedback has-feedback-left form-group-material col-sm-3">
								<label class="control-label multi_lang">رقم وصل الشراء</label>
								<input type="text" id="edit_purchase_number" name="edit_purchase_number" class="form-control multi_lang" placeholder="رقم وصل الشراء" >
								<div class="form-control-feedback">
									<i class="icon-coins text-muted"></i>
								</div>
							</div>

							<div class="form-group has-feedback has-feedback-left form-group-material col-sm-3">
								<label class="control-label multi_lang">التاريخ</label>
									<input type="text" id="edit_purchase_date" name="edit_purchase_date" class="form-control multi_lang daterange-single" placeholder="التاريخ" >
									<div class="form-control-feedback">
										<i class=" icon-calendar52 text-muted"></i>
									</div>
							</div>

							<div class="form-group has-feedback has-feedback-left  col-sm-3">
								<label class="control-label multi_lang">اختيار المخزن</label>
								
								<select class="form-control multi_lang" name="edit_stock_id_fk" id="edit_stock_id_fk" data-width="100%" placeholder="المخزن">

								</select>
								<div class="form-control-feedback">
									<i class="icon-store text-muted"></i>
								</div>
							</div>

							<div class="form-group has-feedback has-feedback-left form-group-material col-sm-3">
								<label class="control-label multi_lang">ملاحظات</label>
								<textarea type="text" id="edit_purchase_note" name="edit_purchase_note" class="form-control multi_lang" placeholder="ملاحظات" > </textarea> 
								<div class="form-control-feedback">
									<i class="icon-notebook text-muted"></i>
								</div>
							</div>
					</div>

					<div id="edited_purchase_contain">


					</div>

				</div>
				<div class="modal-footer">
					<button type="submit" class="btn btn-labeled btn-labeled-left heading-btn btn-primary"> <span class="multi_lang">حفظ</span> <b><i class="icon-floppy-disk"></i></b>
					</button>
					<button type="button" class="btn btn-warning" data-dismiss="modal"> <span class="multi_lang">اغلاق</span>
					</button>
				</div>
			</div>
		</form>
	</div>
</div>


	<div id="add_new_product" class="modal fade" >
			<div class="modal-dialog modal-lg">
			<form class="form-horizontal" method="post" id="add_new_product_form" enctype="multipart/form-data">

				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><i class="icon-cross"></i></button>
						<h4 class="modal-title multi_lang">تحديد الاطوال</h4>
					</div>

					<div class="modal-body">

						<div>
						<input type="hidden" id="fields_count" name="fields_count"  value="">
						<input type="hidden" id="rows_count" name="rows_count"  value="">
						<input type="hidden" id="part_qty" name="part_qty"  value="1"> <!-- for apply defrent length not on all  -->
							<div class="col-sm-12">
								

								

								<div class="form-group col-sm-6">
									<label class="control-label col-sm-4 multi_lang">القيمة العامة</label>
									<div class="">
										<div class="input-group">
											<input type="text" id="default_val" class="form-control multi_lang" placeholder="القيمة العامة">
											<span class="input-group-btn">
												<button id="default_val_btn" class="btn btn-warning multi_lang" type="button">تطبيق على الكل</button>
											</span>
										</div>
									</div>
								</div>

								<div class="form-group col-sm-6">
									<label class="control-label col-sm-2 multi_lang">الكمية</label>
									<div class="">
										<div class="input-group">
											<input type="number" id="default_val_qty" class="form-control multi_lang" placeholder="الكمية" value="1">
											<span class="input-group-btn">
												<button id="default_val_btn_qty" class="btn btn-primary multi_lang" type="button">تطبيق على الكمية المحددة</button>
											</span>
										</div>
									</div>
								</div>
								
							</div>

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

								<div class="form-group" id="input_box_array">

									

								</div>


							</div>
						</div>
				</div>
				<div class="modal-footer">
				<div class="text-right">
					<button type="submit" id="submit_add_prod_btn" class="btn btn-primary btn-labeled btn-labeled-left">
						<span class="multi_lang">حفظ</span> <b><i class="icon-floppy-disk"></i></b>
					</button>
					<button type="button" class="btn btn-warning" data-dismiss="modal"> <span class="multi_lang">اغلاق</span>
						</button>
				</div>
				</div>
			  </div>
			</form>

		</div>
	</div>



	<div id="edit_add_new_product" class="modal fade" >
			<div class="modal-dialog modal-lg">
			<form class="form-horizontal" method="post" id="edit_add_new_product_form" enctype="multipart/form-data">

				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><i class="icon-cross"></i></button>
						<h4 class="modal-title multi_lang">تحديد الاطوال</h4>
					</div>

					<div class="modal-body">

						<div>
						<input type="hidden" id="edit_fields_count" name="edit_fields_count"  value="">
						<input type="hidden" id="edit_rows_count" name="edit_rows_count"  value="">
							<div class="col-sm-12">
								

								

								<div class="form-group">
									<label class="control-label col-lg-1 multi_lang">القيمة العامة</label>
									<div class="col-lg-5">
										<div class="input-group">
											<input type="text" id="edit_default_val" class="form-control multi_lang" placeholder="القيمة العامة">
											<!-- <input type="number" id="edit_default_val_qty" class="form-control multi_lang" placeholder="الكمية"> -->
											<span class="input-group-btn">
												<button id="edit_default_val_btn" class="btn btn-primary multi_lang" type="button">تطبيق على الكل</button>
											</span>
										</div>
									</div>
								</div>
								
							</div>

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

								<div class="form-group" id="edit_input_box_array">

									

								</div>


							</div>
						</div>
				</div>
				<div class="modal-footer">
				<div class="text-right">
					<button type="submit" id="edit_submit_add_prod_btn" class="btn btn-primary btn-labeled btn-labeled-left">
						<span class="multi_lang">حفظ</span> <b><i class="icon-floppy-disk"></i></b>
					</button>
					<button type="button" class="btn btn-warning" data-dismiss="modal"> <span class="multi_lang">اغلاق</span>
						</button>
				</div>
				</div>
			  </div>
			</form>

		</div>
	</div>




<div id="show_payments_modal" class="modal fade" style="display: none;">
		<div class="modal-dialog modal-lg">
		<form class="form-horizontal"  name="show_payments_form" method="post" id="show_payments_form" enctype="multipart/form-data">
			<input type="hidden" id="access_token" name="access_token"  value="">

			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"><i class="icon-cross"></i></button>
					<h4 class="modal-title multi_lang">عرض تفاصيل وصل الشراء</h4>
				</div>
				<div id="invoce_html_pay">
					<div class="modal-body" >
							<input type="hidden" name="inv_numb" id="inv_numb">
							<div id="invoice_show">
								<!-- Borderless table -->


								<!-- /borderless table -->
							</div>
					</div>
				</div>
				<div class="modal-footer">
					<div id="link_pdf_pay"></div>
					<button type="submit" class="btn btn-labeled btn-labeled-left heading-btn btn-primary" id="pdf_pay"> <span class="multi_lang">توليد  PDF</span>  <b><i class="icon-file-pdf"></i></b>
					</button>
					<button type="submit" class="btn btn-labeled btn-labeled-left heading-btn btn-success" id="print_pay"><span class="multi_lang">طباعة</span>  <b><i class=" icon-printer2"></i></b>
					</button>
					<button type="button" class="btn btn-warning" data-dismiss="modal"> <span class="multi_lang">اغلاق</span>
					</button>
				</div>
			</div>
		</form>
	</div>
</div>

				<!-- Individual column searching (text inputs) -->
				<div class="panel panel-flat">
					
					<table class="table datatable-column-search-inputs">
						<thead>
							<tr>
				                <th>ID</th>
								<th class="multi_lang">رقم قائمة الشراء</th>
								<th class="multi_lang">رقم وصل الشراء</th>
			                	<th class="multi_lang">التاريخ</th>
			                	<th class="multi_lang">المخزن</th>
								<th class="multi_lang">الكلفة الكلية</th>
								<th class="multi_lang">المورد</th>
								<th class="multi_lang">الملاحظات</th>
			                	<th class="text-center multi_lang">العمليات</th>
				            </tr>
						</thead>
						<tbody>
							
						</tbody>
						<tfoot>
							<tr>
				                <td></td>
				                <td>username</td>
				                <td>full_name</td>
				                <td>EMail</td>
				                <td>Phone</td>
				                <td></td>
				                <td></td>
				                <td></td>
				                <td></td>
				            </tr>
						</tfoot>
					</table>
				</div>
				<!-- /individual column searching (text inputs) -->



<script type="text/javascript" src="controllers/purchase.js?random=<?php echo uniqid(); ?>"></script>