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

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

	.dataTable {
        font-size: 11.5px;
	}

	.thumb img:not(.media-preview) {
    height: 100px;
	}

	

</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="">

					<div class="row">
						<div class="col-sm-3">
							<div class="alert alert-info alert-styled-right alert-arrow-right alert-bordered">
								<span class="text-semibold multi_lang" > المبلغ الكلي للزبون : </span>
								<span class="text-semibold" data-original-amount="" id="total_customer_account"></span>
						    </div>
						</div>

						<div class="col-sm-3">
							<div class="alert alert-warning alert-styled-right alert-arrow-right alert-bordered">
								<span class="text-semibold multi_lang" > خصومات الحساب : </span>
								<span class="text-semibold" data-original-amount="" id="total_customer_discount"></span>
						    </div>
						</div>

						<div class="col-sm-3">
							<div class="alert alert-success alert-styled-right alert-arrow-right alert-bordered ">
								<span class="text-semibold multi_lang" >المبلغ المدفوع : </span>
								<span class="text-semibold" data-original-amount="" id="total_customer_paid"></span>
						    </div>
						</div>

						<div class="col-sm-3">
							<div class="alert alert-danger alert-styled-right alert-arrow-right alert-bordered ">
								<span class="text-semibold multi_lang" > المبلغ المتبقي : </span>
								<span class="text-semibold" data-original-amount="" id="total_customer_remaind"></span>
						    </div>
						</div>

					</div>

					<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 animate multi_lang">اسم المدين</label>
								
								<select name="payment_gived_to_id_fk" id="payment_gived_to_id_fk" class="form-control" required="required" data-live-search="true">
								

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

							<div class="form-group has-feedback has-feedback-left  col-sm-4">
								<label class="control-label animate multi_lang">Saleman</label>
								
								<select name="saleman_id" id="saleman_id" class="form-control"  data-live-search="true">
								

								</select>
								<div class="form-control-feedback">
									<i class="icon-user-tie 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="payment_withdraw_amount" name="payment_withdraw_amount" class="form-control multi_lang" placeholder=" مبلغ الدفعة " required="required" onchange="compute_remain_price(this.value,this.id);">
								<div class="form-control-feedback">
									<i class="icon-wallet text-muted"></i>
								</div>
							</div>


							

						</div>

						<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="paid_date" name="paid_date" class="form-control daterange-single multi_lang" 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 form-group-material col-sm-3">
								<label class="control-label multi_lang">رقم الوصل الورقي</label>
								<input type="text" id="paper_number" name="paper_number" class="form-control multi_lang" placeholder="رقم الوصل الورقي"  required="required">
								<div class="form-control-feedback">
									<i class="icon-hash text-muted"></i>
								</div>
							</div>

							<div class="form-group form-group-material col-sm-2" >

								<label class="control-label animate">الفرع</label>
								<select name="branch_id_fk" id="branch_id_fk" class="form-control" required="required" data-live-search="true">
									
								</select>
							</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="payment_note" name="payment_note" class="form-control multi_lang" placeholder="الملاحظات" >
								<div class="form-control-feedback">
									<i class="icon-info22 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>
								<select name="expenses_currency" id="expenses_currency" class="form-control" required="required">
										<option class="multi_lang" value="" selected="selected">نوع العملة</option>
										<option class="multi_lang"  value="1" >دولار</option>
										<option class="multi_lang"  value="0" >عراقي</option>
								</select>
								<div class="form-control-feedback">
									<i class="icon-coin-dollar text-muted"></i>
								</div>
							</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: 80%;">
			<form class="form-horizontal"  name="edit_form" method="post" id="edit_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 class="modal-body">
							<input type="hidden" name="itemid" id="edit_objid" value="">
							<input type="hidden" name="transaction_" id="transaction_" value="">
							
							<div class="row">
								<div class="col-sm-12">
									<div class="alert alert-primary alert-styled-right alert-arrow-right alert-bordered" id="transaction_type_alert">
										<span class="text-semibold multi_lang" > نوع الوصل : </span>
										<span class="text-semibold"  id="transaction_type"></span>
								    </div>
								</div>

							</div>
							<div class="row">
								<div class="col-sm-3">
									<div class="alert alert-info alert-styled-right alert-arrow-right alert-bordered">
										<span class="text-semibold multi_lang" > المبلغ الكلي : </span>
										<span class="text-semibold" data-original-amount="" id="edit_total_customer_account"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-warning alert-styled-right alert-arrow-right alert-bordered">
										<span class="text-semibold multi_lang" > خصومات الحساب : </span>
										<span class="text-semibold" data-original-amount="" id="edit_total_customer_discount"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-success alert-styled-right alert-arrow-right alert-bordered ">
										<span class="text-semibold multi_lang" >المبلغ المدفوع : </span>
										<span class="text-semibold" data-original-amount="" id="edit_total_customer_paid"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-danger alert-styled-right alert-arrow-right alert-bordered ">
										<span class="text-semibold multi_lang" > المبلغ المتبقي : </span>
										<span class="text-semibold" data-original-amount="" id="edit_total_customer_remaind"></span>
								    </div>
								</div>

							</div>
							<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 name="edit_payment_gived_to_id_fk" id="edit_payment_gived_to_id_fk" class="form-control" required="required" data-live-search="true">
										

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

									<div class="form-group has-feedback has-feedback-left  col-sm-4">
										<label class="control-label animate multi_lang">Saleman</label>
										
										<select name="edit_saleman_id" id="edit_saleman_id" class="form-control"  data-live-search="true">
										

										</select>
										<div class="form-control-feedback">
											<i class="icon-user-tie 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_payment_withdraw_amount" name="edit_payment_withdraw_amount" class="form-control multi_lang" placeholder=" المبلغ " data-value="" required="required" onchange="edit_compute_remain_price(this.value,this.id);">
										<div class="form-control-feedback">
											<i class="icon-wallet text-muted"></i>
										</div>
									</div>


									

								</div>

								<div class="form-group">

									

									<div class="form-group has-feedback has-feedback-left  col-sm-6">
										<label class="control-label multi_lang">التاريخ</label>
										
										<input type="text" id="edit_payment_withdraw_date" name="edit_payment_withdraw_date" class="form-control daterange-single multi_lang" 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-6">
										<label class="control-label multi_lang">الملاحظات</label>
										<input type="text" id="edit_payment_withdraw_note" name="edit_payment_withdraw_note" class="form-control multi_lang" placeholder="الملاحظات" >
										<div class="form-control-feedback">
											<i class="icon-info22 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>
										<select name="expenses_currency" id="expenses_currency" class="form-control" required="required">
												<option class="multi_lang" value="" selected="selected">نوع العملة</option>
												<option class="multi_lang"  value="1" >دولار</option>
												<option class="multi_lang"  value="0" >عراقي</option>
										</select>
										<div class="form-control-feedback">
											<i class="icon-coin-dollar text-muted"></i>
										</div>
									</div> -->



								</div>


							</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="discount_form_cont" class="modal fade" style="display: none;">
		<div class="modal-dialog modal-lg" style="width: 80%;">
			<form class="form-horizontal"  name="discount_form" method="post" id="discount_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 class="modal-body">
							<div class="row">
								<div class="col-sm-3">
									<div class="alert alert-info alert-styled-right alert-arrow-right alert-bordered">
										<span class="text-semibold multi_lang" > المبلغ الكلي : </span>
										<span class="text-semibold" data-original-amount="" id="discount_total_customer_account"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-warning alert-styled-right alert-arrow-right alert-bordered">
										<span class="text-semibold multi_lang" > خصومات الحساب : </span>
										<span class="text-semibold" data-original-amount="" id="discount_total_customer_discount"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-success alert-styled-right alert-arrow-right alert-bordered ">
										<span class="text-semibold multi_lang" >المبلغ المدفوع : </span>
										<span class="text-semibold" data-original-amount="" id="discount_total_customer_paid"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-danger alert-styled-right alert-arrow-right alert-bordered ">
										<span class="text-semibold multi_lang" > المبلغ المتبقي : </span>
										<span class="text-semibold" data-original-amount="" id="discount_total_customer_remaind"></span>
								    </div>
								</div>

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

								<div class="form-group">


									<div class="form-group has-feedback has-feedback-left  col-sm-6">
										<label class="control-label  multi_lang">اسم الزبون</label>
										
										<select name="discount_payment_gived_to_id_fk" id="discount_payment_gived_to_id_fk" class="form-control" required="required">
										

										</select>
										<div class="form-control-feedback">
											<i class="icon-user-tie text-muted"></i>
										</div>
									</div>
									
									<div class="form-group has-feedback has-feedback-left form-group-material col-sm-6">
										<label class="control-label multi_lang">مبلغ الخصم</label>
										<input type="text" id="discount_payment_withdraw_amount" name="discount_payment_withdraw_amount" class="form-control multi_lang" placeholder=" مبلغ الخصم " data-value="" required="required" onchange="compute_remain_price(this.value,this.id);">
										<div class="form-control-feedback">
											<i class="icon-wallet text-muted"></i>
										</div>
									</div>


									

								</div>

								<div class="form-group">

									

									<div class="form-group has-feedback has-feedback-left form-group-material col-sm-6">
										<label class="control-label multi_lang">التاريخ</label>
										
										<input type="text" id="discount_payment_withdraw_date" name="discount_payment_withdraw_date" class="form-control daterange-single multi_lang" 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 form-group-material col-sm-6">
										<label class="control-label multi_lang">الملاحظات</label>
										<input type="text" id="discount_payment_withdraw_note" name="discount_payment_withdraw_note" class="form-control multi_lang" placeholder="الملاحظات" >
										<div class="form-control-feedback">
											<i class="icon-info22 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>
										<select name="expenses_currency" id="expenses_currency" class="form-control" required="required">
												<option class="multi_lang" value="" selected="selected">نوع العملة</option>
												<option class="multi_lang"  value="1" >دولار</option>
												<option class="multi_lang"  value="0" >عراقي</option>
										</select>
										<div class="form-control-feedback">
											<i class="icon-coin-dollar text-muted"></i>
										</div>
									</div> -->



								</div>


							</div>
					</div>
					<div class="modal-footer">
						<button type="submit" id="discount_form_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="return_form_cont" class="modal fade" style="display: none;">
		<div class="modal-dialog modal-lg" style="width: 80%;">
			<form class="form-horizontal"  name="return_form" method="post" id="return_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 class="modal-body">
							<div class="row">
								<div class="col-sm-3">
									<div class="alert alert-info alert-styled-right alert-arrow-right alert-bordered">
										<span class="text-semibold multi_lang" > المبلغ الكلي : </span>
										<span class="text-semibold" data-original-amount="" id="return_total_customer_account"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-warning alert-styled-right alert-arrow-right alert-bordered">
										<span class="text-semibold multi_lang" > خصومات الحساب : </span>
										<span class="text-semibold" data-original-amount="" id="return_total_customer_discount"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-success alert-styled-right alert-arrow-right alert-bordered ">
										<span class="text-semibold multi_lang" >المبلغ المدفوع : </span>
										<span class="text-semibold" data-original-amount="" id="return_total_customer_paid"></span>
								    </div>
								</div>

								<div class="col-sm-3">
									<div class="alert alert-danger alert-styled-right alert-arrow-right alert-bordered ">
										<span class="text-semibold multi_lang" > المبلغ المتبقي : </span>
										<span class="text-semibold" data-original-amount="" id="return_total_customer_remaind"></span>
								    </div>
								</div>

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

								<div class="form-group">


									<div class="form-group has-feedback has-feedback-left  col-sm-6">
										<label class="control-label  multi_lang">اسم الزبون</label>
										
										<select name="return_payment_gived_to_id_fk" id="return_payment_gived_to_id_fk" class="form-control" required="required">
										

										</select>
										<div class="form-control-feedback">
											<i class="icon-user-tie text-muted"></i>
										</div>
									</div>
									
									<div class="form-group has-feedback has-feedback-left form-group-material col-sm-6">
										<label class="control-label multi_lang">المبلغ المسترجع</label>
										<input type="text" id="return_payment_withdraw_amount" name="return_payment_withdraw_amount" class="form-control multi_lang" placeholder=" المبلغ المسترجع " data-value="" required="required" onchange="compute_return_price(this.value,this.id);">
										<div class="form-control-feedback">
											<i class="icon-wallet text-muted"></i>
										</div>
									</div>


									

								</div>

								<div class="form-group">

									

									<div class="form-group has-feedback has-feedback-left form-group-material col-sm-6">
										<label class="control-label multi_lang">التاريخ</label>
										
										<input type="text" id="return_payment_withdraw_date" name="return_payment_withdraw_date" class="form-control daterange-single multi_lang" 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 form-group-material col-sm-6">
										<label class="control-label multi_lang">الملاحظات</label>
										<input type="text" id="return_payment_withdraw_note" name="return_payment_withdraw_note" class="form-control multi_lang" placeholder="الملاحظات" >
										<div class="form-control-feedback">
											<i class="icon-info22 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>
										<select name="expenses_currency" id="expenses_currency" class="form-control" required="required">
												<option class="multi_lang" value="" selected="selected">نوع العملة</option>
												<option class="multi_lang"  value="1" >دولار</option>
												<option class="multi_lang"  value="0" >عراقي</option>
										</select>
										<div class="form-control-feedback">
											<i class="icon-coin-dollar text-muted"></i>
										</div>
									</div> -->



								</div>


							</div>
					</div>
					<div class="modal-footer">
						<button type="submit" id="return_form_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_bills_modal" class="modal fade" style="display: none;">
		<div class="modal-dialog modal-lg">
			<form class="form-horizontal"  name="show_bills_form" method="post" id="show_bills_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 id="invoce_html_pay">
						<div class="modal-body" >
								<input type="hidden" name="bill_id" id="bill_id">
								<div id="bills_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 class="row">
					<div class="col-sm-6 col-md-4">
						<div class="panel panel-body panel-body-accent">
							<div class="media no-margin">
								<div class="media-left media-middle">
									<i class="icon-coins icon-3x text-success-400"></i>
								</div>

								<div class="media-body text-right">
									<h3 class="no-margin text-semibold" id="total_amount">0 $</h3>
									<span class="text-uppercase text-size-mini text-muted multi_lang">مجموع الدفعات الكلية</span>
								</div>
							</div>
						</div>
					</div>

					<div class="col-sm-6 col-md-4">
						<div class="panel panel-body">
							<div class="media no-margin">
								<div class="media-left media-middle">
									<i class="icon-price-tag icon-3x text-indigo-400"></i>
								</div>

								<div class="media-body text-right">
									<h3 class="no-margin text-semibold" id="total_paid">0 $</h3>
									<span class="text-uppercase text-size-mini text-muted multi_lang">مجموع الخصومات على الحسابات</span>
								</div>
							</div>
						</div>
					</div>

					<div class="col-sm-6 col-md-4">
						<div class="panel panel-body">
							<div class="media no-margin">
								<div class="media-body">
									<h3 class="no-margin text-semibold" id="total_unpaid">0 $</h3>
									<span class="text-uppercase text-size-mini text-muted multi_lang">مجموع المبالغ المسترجعة</span>
								</div>

								<div class="media-right media-middle">
									<i class="icon-reset icon-3x text-danger-400"></i>
								</div>
							</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>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">Transaction</th>
								<th class="multi_lang">الملاحظات</th>
								<th class="multi_lang">رقم الوصل الورقي</th>
								<th class="multi_lang">Saleman</th>
				        		<th class="multi_lang" width="8%">العمليات</th>
				      </tr>
						</thead>
						<tbody>
							
						</tbody>
						<tfoot>
							<tr>
				                <td></td>
				                <td>username</td>
				                <td>full_name</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/payment.js?random=<?php echo uniqid(); ?>"></script>