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

</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-full">
		<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="">
			<input type="hidden" name="invoice_id_pay" id="invoice_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  panel" aria-expanded="true" >
	<div class="panel-body">
		<form class="form-horizontal" method="post" id="add_form" enctype="multipart/form-data">
			
			
			<!-- <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-4">
						<label class="control-label  multi_lang">اسم الزبون</label>
						
						<select class="form-control multi_lang stop_enter" data-live-search="true" name="customer_id_fk" id="customer_id_fk" data-width="100%" required="required" tabindex="">

						</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">اسم المشتري</label>
						
						<input type="text" class="form-control multi_lang stop_enter"  name="author" id="author" data-width="100%" placeholder="اسم المشتري"  tabindex="">

						
						<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-4">
						<label class="control-label multi_lang">تاريخ الطلب</label>
							<input type="text" id="invoice_date" name="invoice_date" class="form-control multi_lang daterange-single stop_enter" placeholder="التاريخ" required="required" tabindex="" disabled="disabled" >
							<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-4">
						<label class="control-label multi_lang">نوع الوصل</label>
						
						<select class="form-control multi_lang stop_enter" data-live-search="true" name="invoice_type" id="invoice_type" data-width="100%"  tabindex="">
							<option class="multi_lang" selected="selected" value="0">وصل بيع</option>
							<option class="multi_lang" value="4">Offer</option>
						</select>
						<div class="form-control-feedback">
							<i class="icon-coins text-muted"></i>
						</div>
					</div>
					
					
				</div>

				<div class="form-group">

					


					<div class="form-group has-feedback has-feedback-left col-sm-3" style="display: none;">
						<label class="control-label multi_lang">نوع الوصل</label>
						
						<select class="form-control multi_lang stop_enter" name="invoice_transaction" id="invoice_transaction" data-width="100%"   tabindex="">
							<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" style="display: none;">
						<label class="control-label multi_lang">الوصل الاصلي</label>
						
						<select class="form-control multi_lang stop_enter" data-live-search="true" name="original_invoice_id_fk" id="original_invoice_id_fk" data-width="100%"   tabindex="">

						</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-4">
						<label class="control-label  multi_lang">الفرع</label>
						
						<select class="form-control multi_lang stop_enter" data-live-search="true" name="branch_id_fk" id="branch_id_fk" data-width="100%" required="required" tabindex="">

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

					<!-- <div class="form-group has-feedback has-feedback-left col-sm-3" style="display: none;">
						<label class="control-label  multi_lang">المخزن</label>
						
						<select class="form-control multi_lang stop_enter" data-live-search="true" name="stock_id_fk" id="stock_id_fk" data-width="100%" required="required" tabindex="">

						</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-4">
						<label class="control-label  multi_lang">اسم المندوب</label>
						
						<select class="form-control multi_lang stop_enter" data-live-search="true" name="saleman_id_fk" id="saleman_id_fk" data-width="100%" >

						</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-4">
						<label class="control-label multi_lang">ملاحظات</label>
						<input type="text" id="invoice_note" name="invoice_note" class="form-control multi_lang stop_enter" placeholder="ملاحظات"  tabindex=""> 
						<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="alpha-success ">
									<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></th>
								</tr>
							</thead>
							<tbody id="purchase_item_body" >
								<tr  id="item_row_1" >
									<td width="5%" id="num_1">1</td>

									<td width="10%" id="ttt">
										

										<select class="form-control multi_lang stop_enter" name="product_id_fk_1" id="product_id_fk_1" data-width="100%"  data-live-search="true"  required="required" tabindex="">

										</select>

									</td>


									<td width="6%">
										<input type="number" id="purchase_quantity_1" name="purchase_quantity_1"  class="form-control text-center multi_lang stop_enter" placeholder="QNTY" value="1" onchange="calc_total_item_cost(this.value,1);" required="required" tabindex="">
									</td>

									<td width="9%" >
										<input id="sell_price_1" name="sell_price_1" type="text" class="form-control multi_lang text-center " placeholder="PRICE" onchange="calc_total_item_cost(this.value,1);" required="required">
									</td>

									<td width="10%">
										<input id="discount_1" name="discount_1" type="text" value="" class="form-control text-center text-black text-size-large stop_enter" data-discount-type="" data-discount-actual=""  onchange="calc_total_item_cost(this.value,1);">
									</td>

									

									<td width="9%" >
										<input id="total_item_cost_1" name="total_item_cost_1" type="text" class="form-control multi_lang text-center stop_enter" placeholder="الكلفة الاجمالية" disabled="disabled" tabindex="">
									</td>

									



									

									<td width="8%">
										<input id="sell_item_note_1" name="sell_item_note_1" type="text" class="form-control multi_lang stop_enter" placeholder="ملاحظة" tabindex="">
									</td>

							
									
									
									
									<td width="6%">
										<button class="btn btn-link btn_add_item" id="" tabindex="">
											<i  class="icon-add text-blue"></i>
										</button>
										
									</td>
								</tr>

								
								

								
								
							</tbody>
							<tfoot>
								
								<tr class="alpha-teal">
									<th colspan="2" class="multi_lang">TOTAL</th>
									<!-- <th></th> -->
									
									
									<th></th>
									<th></th>
									<th></th>
									<th>
										<input id="invoice_total_no_disc" name="invoice_total_no_disc" type="text" value="0 $" class="form-control text-center text-black text-size-large stop_enter" disabled="disabled" style="height: 25px;">
									</th>
									
									<th></th>
									
									<th><i  class="icon-sigma "></i></th>
								</tr>

								<tr class="alpha-orange">
									<th colspan="2" class="multi_lang">DISCOUNT</th>
									
									<th></th>
									<th></th>
									
									<th>
										<input id="repeated_discount" name="repeated_discount" type="text" value="" placeholder="تكرار التخفيضات" class="form-control text-center text-black text-size-large stop_enter" style="height: 25px;" onchange="repeat_discount();" >
									</th>
									<th >
										<input id="discount_total" name="discount_total" type="text" value="" class="form-control text-center text-black text-size-large stop_enter" data-discount-type="" data-discount-actual="" style="height: 25px;" onchange1="calc_total_invoice_price();" disabled="disabled">
									</th>
									<th></th>
									
									
									<th><i  class="icon-minus3 "></i></th>
								</tr>

								<tr class="alpha-primary">
									<th colspan="2" class="multi_lang">GRAND TOTAL</th>
									
									<th></th>
									<th></th>
									<th></th>
									<th >
										<input id="grand_total" name="grand_total" type="text" value="0 $" class="form-control text-center text-black text-size-large " disabled="disabled" style="height: 25px;">
									</th>
									<th></th>
									
									<th><i  class="icon-cash "></i></th>
								</tr>

								<!-- <tr class="alpha-danger">
									<th colspan="2" class="multi_lang">PAYMENT</th>
									
									<th></th>
									<th></th>
									<th></th>
									<th >
										<input id="payment_total" name="payment_total" type="text" value="" class="form-control text-center text-black text-size-large submit_enter"  style="height: 25px;" onchange="calc_payments();">
									</th>
									<th></th>
									
									<th><i  class="icon-credit-card "></i></th>
								</tr> -->
							</tfoot>
						</table>
					</div>

				</div>

				<!-- <div class="form-group">
							
					<div class="col-lg-12">
						<input type="file" class="file-input-ajax" id="files_upload" name="files_upload[]" multiple="multiple" tabindex="-3">
						<span class="help-block multi_lang">  تحميل  الصور </span>
					</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 class="form-group">

						<div class="form-group has-feedback has-feedback-left col-sm-4">
							<label class="control-label  multi_lang">اسم الزبون</label>
							
							<select class="form-control multi_lang stop_enter" data-live-search="true" name="edit_customer_id_fk" id="edit_customer_id_fk" data-width="100%" required="required" tabindex="11">

							</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">اسم المشتري</label>
							
							<input type="text" class="form-control multi_lang stop_enter"  name="edit_author" id="edit_author" data-width="100%" placeholder="اسم المشتري"  tabindex="12">

							
							<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-4">
							<label class="control-label multi_lang">تاريخ الطلب</label>
								<input type="text" id="edit_invoice_date" name="edit_invoice_date" class="form-control multi_lang daterange-single stop_enter" placeholder="التاريخ" required="required" tabindex="13" disabled="disabled" >
								<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-4">
							<label class="control-label multi_lang">نوع الوصل</label>
							
							<select class="form-control multi_lang stop_enter" data-live-search="true" name="edit_invoice_type" id="edit_invoice_type" data-width="100%"  tabindex="16">
								<option class="multi_lang" selected="selected" value="0">وصل بيع</option>
								<option class="multi_lang" value="4">Offer</option>
							</select>
							<div class="form-control-feedback">
								<i class="icon-coins text-muted"></i>
							</div>
						</div>
						
						
					</div>

					<div class="form-group">

						


						<div class="form-group has-feedback has-feedback-left col-sm-4" style="display: none;">
							<label class="control-label multi_lang">نوع الوصل</label>
							
							<select class="form-control multi_lang stop_enter" name="edit_invoice_transaction" id="edit_invoice_transaction" data-width="100%"   tabindex="15">
								<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-4" style="display: none;">
							<label class="control-label multi_lang">الوصل الاصلي</label>
							
							<select class="form-control multi_lang stop_enter" data-live-search="true" name="edit_original_invoice_id_fk" id="edit_original_invoice_id_fk" data-width="100%"   tabindex="16">

							</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-4">
							<label class="control-label  multi_lang">الفرع</label>
							
							<select class="form-control multi_lang stop_enter" data-live-search="true" name="edit_branch_id_fk" id="edit_branch_id_fk" data-width="100%" required="required" tabindex="11">

							</select>
							<div class="form-control-feedback">
								<i class="icon-office 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 stop_enter" data-live-search="true" name="edit_stock_id_fk" id="edit_stock_id_fk" data-width="100%" required="required" tabindex="11">

							</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-4">
							<label class="control-label  multi_lang">اسم المندوب</label>
							
							<select class="form-control multi_lang stop_enter" data-live-search="true" name="edit_saleman_id_fk" id="edit_saleman_id_fk" data-width="100%" >

							</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-4">
							<label class="control-label multi_lang">ملاحظات</label>
							<input type="text" id="edit_invoice_note" name="edit_invoice_note" class="form-control multi_lang stop_enter" placeholder="ملاحظات"  tabindex="17"> 
							<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" 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">الملاحظات</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>
				                <td></td>
				                <td></td>
				                <td></td>
				                <td></td>
				            </tr>
						</tfoot>
					</table>
				</div>
				<!-- /individual column searching (text inputs) -->



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