<?php
$permission  = explode(',',$_SESSION['permission_id']);
if(!in_array(40,$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;
    }

    input[type="checkbox"] {
    	margin: -8px 0 0;
    	
    	line-height: normal;
	}

	.radio label, .checkbox label {
    	padding-right: 85px;
	}

	.radio label, .checkbox label {
    	min-height: 20px;
    	/*padding-right: 20px;*/
    	margin-bottom: 20px;
    	font-weight: normal;
    	cursor: pointer;
	}

	.sp-container {
		z-index: 1000000;
	}

	.dropdown-menu {
    	min-width: 275px;
	}

</style>



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


<div id="add_payments_modal" class="modal fade" >
		<div class="modal-dialog modal-lg">
		<form class="form-horizontal"  name="add_payments_form" method="post" id="add_payments_form" enctype="multipart/form-data">
			<input type="hidden" id="access_token" name="access_token"  value="">
			<input type="hidden" name="customer_id_pay" id="customer_id_pay" 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"> <i class="icon-bag"></i> <span class="multi_lang">اضافة دفعة على الحساب الكلي للزبون</span>  </h4>
				</div>

				<div class="modal-body">
						<div id="invoice_pay_add">
							
							
							
						</div>
				</div>
				<div class="modal-footer">
					<button type="submit" id="submit_add_pay_btn" 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="edit_payments_modal" class="modal fade" >
		<div class="modal-dialog modal-lg">
		<form class="form-horizontal"  name="edit_payments_form" method="post" id="edit_payments_form" enctype="multipart/form-data">
			<input type="hidden" id="access_token" name="access_token"  value="">
			<input type="hidden" name="itemid_payment" id="itemid_payment" value="">
			<input type="hidden" name="edit_pay_inv_id" id="edit_pay_inv_id" 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"> <i class="icon-pencil15"></i> <span class="multi_lang">تحرير الدفوعات</span>  </h4>
				</div>

				<div class="modal-body">
							<div class="col-sm-12" id="edit_payments_fields">


							</div>
				</div>
				<div class="modal-footer">

					</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-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="invoice_type" name="invoice_type" value="0">
			<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 col-sm-3">
							<label class="control-label  multi_lang">اسم الزبون</label>
							
							<select class="form-control multi_lang" data-live-search="true" name="customer_id_fk" id="customer_id_fk" data-width="100%" placeholder="اسم الزبون" required="required">

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

						<div class="form-group has-feedback has-feedback-left col-sm-3">
							<label class="control-label  multi_lang">Author</label>
							
							<input type="text" class="form-control multi_lang"  name="author" id="author" data-width="100%" placeholder="Author" >

							
							<div class="form-control-feedback">
								<i class="icon-user 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="invoice_date" name="invoice_date" class="form-control multi_lang daterange-single" placeholder="التاريخ" required="required">
								<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>
							
							<input type="text" id="delivery_time" name="delivery_time" class="form-control multi_lang daterange-single" placeholder="تاريخ التسليم" >
								
							<div class="form-control-feedback">
								<i class="icon-location4 text-muted"></i>
							</div>
						</div>


						
					</div>

					<div class="form-group">

						<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" data-live-search="true" name="price_profile_id" id="price_profile_id" data-width="100%" placeholder="ملف الاسعار" >

							</select>
							<div class="form-control-feedback">
								<i class="icon-coins 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="invoice_transaction" id="invoice_transaction" data-width="100%" placeholder="نوع الوصل" >
								<option class="multi_lang" selected="selected" value="Invoice">وصل جديد</option>
								<option class="multi_lang" value="Return">وصل معاد من وصل اخر</option>
							</select>
							<div class="form-control-feedback">
								<i class="icon-coins 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" data-live-search="true" name="original_invoice_id_fk" id="original_invoice_id_fk" data-width="100%" placeholder="الوصل الاصلي" >

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

					

						<div class="form-group has-feedback has-feedback-left  col-sm-3">
							<label class="control-label multi_lang">ملاحظات</label>
							<textarea type="text" id="invoice_note" name="invoice_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-success ">
									<th>#</th>
									<!-- <th class="multi_lang">Product Name</th> -->
									<th class="multi_lang">Model</th>
									<th class="multi_lang">الكمية</th>
									<th class="multi_lang">الارتفاع (ملم)</th>
									<th class="multi_lang">العرض (ملم)</th>
									<th class="multi_lang">المساحة (م<sup>2</sup>)</th>
									
									<th class="multi_lang">اللون</th>
									<th class="multi_lang">Comment</th>
									<th class="multi_lang">اخر سعر بيع</th>
									<!-- <th class="multi_lang">Comment</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="10%">
										

										<select class="form-control multi_lang" name="product_id_fk_1" id="product_id_fk_1" data-width="100%" placeholder="اسم المادة"  data-live-search="true" required="required">

										</select>

									</td>

									<td width="6%">
										<input type="number" id="purchase_quantity_1" name="purchase_quantity_1"  class="form-control text-center multi_lang" placeholder="العدد" value="1" required="required" >
									</td>

									<td width="7%" >
										<input type="number" id="sell_item_height_1" name="sell_item_height_1"  class="form-control text-center multi_lang" placeholder="الارتفاع" required="required" onchange="calc_area(1);">
									</td>

									<td width="7%">
										
										<input type="number" id="sell_item_width_1" name="sell_item_width_1"  class="form-control text-center multi_lang" placeholder="العرض" required="required" onchange="calc_area(1);">

									</td>
									<td width="5%" >
											
											<span dir="ltr" class="label btn-block bg-orange text-semibold multi_lang" id="total_area_1"></span>

									</td>
									
									
									<td width="7%" >
										<select class="form-control multi_lang" name="color_product_id_fk_1" id="color_product_id_fk_1" data-width="100%" placeholder="اللون"  data-live-search="true" required="required">

										</select>
									</td>
									<td width="8%">
										<input id="sell_item_comment_1" name="sell_item_comment_1" type="text" class="form-control multi_lang" placeholder="Comment" >
									</td>
									<td width="6%">
										<input id="last_sell_price_1" name="last_sell_price_1" type="text" class="form-control multi_lang" placeholder="اخر سعر بيع" readonly >
									</td>
									
									<td width="9%" >
										<input id="buy_price_per_meter_1" name="buy_price_per_meter_1" type="text" class="form-control multi_lang text-center" placeholder="سعر البيع" onchange="calc_total_invoice_price();" required="required">
									</td>
									<td width="9%">
										<textarea type="text" id="purchase_item_note_1" name="purchase_item_note_1" class="form-control multi_lang" placeholder="ملاحظات" > </textarea>
									</td>
									<!-- <td width="7%" >
										<input id="product_pay_1" name="product_pay_1" type="text"  class="form-control multi_lang text-center" placeholder="المبلغ المدفوع" onchange="calc_payments(1);">
									
									</td> -->
									<td width="6%">
										<button class="btn btn-link btn_add_item" id="">
											<i  class="icon-add text-blue"></i>
										</button>
										
									</td>
								</tr>

								
								

								
								
							</tbody>
							<tfoot>
								
								<tr class="bg-teal-400">
									<th colspan="2" class="multi_lang">مجموع</th>
									<!-- <th></th> -->
									<th></th>
									<th></th>
									<th></th>
									<th></th>
									<th></th>
									<!-- <th></th>
									<th></th> -->
									<th></th>
									<th></th>
									<!-- <th></th> -->
									
									<th >
										<input id="purchase_total_no_disc" name="purchase_total_no_disc" type="text" value="0 $" class="form-control text-center" readonly style="height: 25px;">
									</th>
									<th></th>
									<!-- <th>
										<input id="total_paid" name="total_paid" type="text" value="0 $" class="form-control text-center" readonly >
									</th> -->
									<th><i  class="icon-sigma "></i></th>
								</tr>

								<tr class="bg-orange-400">
									<th colspan="2" class="multi_lang">تنزيلات</th>
									<!-- <th></th> -->
									<th></th>
									<th></th>
									<th></th>
									<th></th>
									<th></th>
									<!-- <th></th>
									<th></th> -->
									<th></th>
									<th></th>
									<!-- <th></th> -->
									
									<th >
										<input id="discount_total" name="discount_total" type="text" value="" class="form-control text-center" data-discount-type="" data-discount-actual="" style="height: 25px;" onchange="calc_total_invoice_price();">
									</th>
									<th></th>
									<!-- <th>
										<input id="total_paid" name="total_paid" type="text" value="0 $" class="form-control text-center" readonly >
									</th> -->
									<th><i  class="icon-minus3 "></i></th>
								</tr>

								<tr class="bg-primary-400">
									<th colspan="2" class="multi_lang">سعر نهائي</th>
									<!-- <th></th> -->
									<th></th>
									<th></th>
									<th></th>
									<th></th>
									<th></th>
									<!-- <th></th>
									<th></th> -->
									<th></th>
									<th></th>
									<!-- <th></th> -->
									
									<th >
										<input id="purchase_total" name="purchase_total" type="text" value="0 $" class="form-control text-center" readonly style="height: 25px;">
									</th>
									<th></th>
									<!-- <th>
										<input id="total_paid" name="total_paid" type="text" value="0 $" class="form-control text-center" readonly >
									</th> -->
									<th><i  class="icon-cash "></i></th>
								</tr>

								<tr class="bg-pink-400">
									<th colspan="2" class="multi_lang">المبلغ المدفوع</th>
									<!-- <th></th> -->
									<th></th>
									<th></th>
									<th></th>
									<th></th>
									<th></th>
									<!-- <th></th>
									<th></th> -->
									<th></th>
									<th></th>
									<!-- <th></th> -->
									
									<th >
										<input id="payment_total" name="payment_total" type="text" value="" class="form-control text-center"  style="height: 25px;" onchange="calc_payments();">
									</th>
									<th></th>
									<!-- <th>
										<input id="total_paid" name="total_paid" type="text" value="0 $" class="form-control text-center" readonly >
									</th> -->
									<th><i  class="icon-credit-card "></i></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" style="width: 92%;">
		<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="edit_objid" id="edit_objid" value="">
					<input type="hidden" id="edit_total_rows" name="edit_total_rows" value="1">
					<input type="hidden" id="update_type" name="update_type" value="update">

					


					
						

					<div id="edited_purchase_contain">


					</div>

				</div>
				<div class="modal-footer">
					<button type="submit" id="submit_edit_btn" 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="show_files" class="modal fade" >
	<div class="modal-dialog modal-lg" >

		<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 class="row" id="file_attach">

				</div>

			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-labeled btn-labeled-left heading-btn btn-primary"  data-dismiss="modal"> OK
				</button>
				<button type="button" class="btn btn-warning" data-dismiss="modal"> <span class="multi_lang">اغلاق</span>
				</button>
			</div>
		</div>

	</div>
</div>
	
				<!-- Individual column searching (text inputs) -->
				<div class="panel panel-flat">
					
					<table class="table datatable-column-search-inputs table-bordered table-hover datatable-highlight datatable-row-full datatable-key-class">
						<thead>
							<tr>
				        		<th width="5%">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">C. Company</th>
								<th class="multi_lang">BarCode</th>
								<th class="multi_lang">الحالة</th>
								<th class="multi_lang">ملاحظات</th>
			          			<th width="12%" 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>
				                <td></td>
				                <td></td>
				                <td></td>
				            </tr>
						</tfoot>
					</table>
				</div>
				<!-- /individual column searching (text inputs) -->



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