<?php
function sa_member_invoice(){
	$html = "";
    global $wpdb;
    $wpdb_prefix = $wpdb->prefix;
    $invoice= $wpdb_prefix.'cip_member_invoice';
    $e_mail=$_SESSION['refAccount'];
	
// 	$uploads = wp_upload_dir(); 
// 	echo $uploads['baseurl'] . '/USER_PHOTOS/ronny/';
// 	echo $uploads['baseurl'];
	
	wp_enqueue_style( 'cip-css' );
	wp_enqueue_style( 'bs-table' );
	wp_enqueue_style( 'bs-sticky-header' );
	wp_enqueue_style( 'bs-datepicker' );
	wp_enqueue_script('bs-table');
	wp_enqueue_script('bs-sticky-header');
	wp_enqueue_script('bs-table-filter-control');
	wp_enqueue_script('tbl-ex-js');
	wp_enqueue_script('jspdf');
	wp_enqueue_script('pdf-autotable-js');
	wp_enqueue_script('ex-js');
	wp_enqueue_script('bs-datepicker');
	ob_start();
	?>

	<div class="scroll">
	<?php
		$updated = $wpdb->query(
			$wpdb->prepare(
				"UPDATE `$invoice`
					SET `ArchiveStatus` = 'Yes' 
					WHERE `ArchiveStatus` = 'No'
					AND `last_update` <= NOW() - INTERVAL 14 DAY"
			)
		);
	?>
	<script type="text/javascript">
		var selectToken = {
			"CSR": "CSR",
			"CSR25": "CSR25",
		};
	</script>
	<a class="btn btn-primary csr-archive-button" data-archive-status="false"><div class="archive">Archive</div> <div class="undo-archive">Back to orders</div></a>
	<table id="tokenholder_Orders_Invoices_table"  data-filter-control="true" data-show-search-clear-button="false" data-pagination="true" data-sortable="true" data-toggle="table" data-archive-toggle="true" data-show-columns="true" data-show-columns-toggle-all="true" data-show-toggle="false" data-show-export="false" data-export-types="['csv', 'pdf']" class="table table-bordered" data-side-pagination="server" data-page-size="20" data-page-list="[20, 30, 50, 100]">
		<thead>
			<tr>
				<th data-field="id" data-filter-control="input" data-sortable="true" class="id" data-switchable="false" data-width="50" data-width-unit="px"><?php _e('#', CIP_TXTDOMAIN); ?></th>
				<th data-field="ProformaInvoiceNumber" data-filter-control="input" data-sortable="true" class="pnumber"><?php _e('Order #', CIP_TXTDOMAIN); ?></th>
				<th data-field="Date" data-filter-control="input" data-sortable="true" class="date"><?php _e('Order Date', CIP_TXTDOMAIN); ?></th>
				<th data-field="InvoiceNumber" data-filter-control="input" data-sortable="true" class="inumber"><?php _e('Invoice #', CIP_TXTDOMAIN); ?></th>
				<th data-field="PaidDate" data-filter-control="input" data-sortable="true" class="pdate"><?php _e('Invoice Date', CIP_TXTDOMAIN); ?></th>
				<th data-field="Package" data-filter-control="input" data-filter-custom-search="BsTableFilterStatus" data-sortable="true" class="frequency"><?php _e('Frequency', CIP_TXTDOMAIN); ?></th>
				<th data-field="ProductPrice" data-filter-control="input" data-sortable="true" class="price"><?php _e('(€) Price', CIP_TXTDOMAIN); ?></th>																																																			
				<th data-field="Kgs" data-filter-control="input" data-sortable="true" class="kgs"><?php _e('Kgs', CIP_TXTDOMAIN); ?></th>
				<th data-field="Status" data-filter-control="select" data-filter-custom-search="BsTableFilterStatus" data-sortable="true" class="status"><?php _e('Status', CIP_TXTDOMAIN); ?></th>	
				
				<th data-field="Type" data-filter-control="input" data-sortable="true" data-visible="false" class="type"><?php _e('Type', CIP_TXTDOMAIN); ?></th>
				<th data-field="POVATAmount" data-filter-control="input" data-sortable="true" data-visible="false" class="poAmt"><?php _e('(€) Order VAT', CIP_TXTDOMAIN); ?></th>
				<th data-field="PONetAmount" data-filter-control="input" data-sortable="true" data-visible="false" class="ponetAmt"><?php _e('(€) Order Net', CIP_TXTDOMAIN); ?></th>
				<th data-field="POGrossAmount" data-filter-control="input" data-sortable="true" data-visible="false" class="pogrossAmt"><?php _e('(€) Order Gross', CIP_TXTDOMAIN); ?></th>
				<th data-field="PoVATPercentage" data-filter-control="input" data-sortable="true" data-visible="false" class="povatPer"><?php _e('Order VAT %', CIP_TXTDOMAIN); ?></th>
				<th data-field="VATAmount" data-filter-control="input" data-sortable="true" data-visible="false" class="vatAmt"><?php _e('(€) VAT', CIP_TXTDOMAIN); ?></th>
				<th data-field="NetAmount" data-filter-control="input" data-sortable="true" data-visible="false" class="netAmt"><?php _e('(€) Net Amount', CIP_TXTDOMAIN); ?></th>																																																			
				<th data-field="GrossAmount" data-filter-control="input" data-sortable="true" data-visible="false" class="grossAmt"><?php _e('(€) Gross Amount', CIP_TXTDOMAIN); ?></th>
				<th data-field="VATPercentage" data-filter-control="input" data-sortable="true" data-visible="false" class="vatPer"><?php _e('VAT %', CIP_TXTDOMAIN); ?></th>							
				<th data-field="Website" data-filter-control="input" data-sortable="true" data-visible="false" class="website"><?php _e('Website', CIP_TXTDOMAIN); ?></th>


				<th data-field="BusinessName" data-filter-control="input" data-sortable="true" data-visible="false" class="bname"><?php _e('Business Name', CIP_TXTDOMAIN); ?></th>							
				<th data-field="BusinessCategory" data-filter-control="input" data-sortable="true" data-visible="false" class="bcategory"><?php _e('Business Category', CIP_TXTDOMAIN); ?></th>
				<th data-field="Employees" data-filter-control="input" data-sortable="true" data-visible="false" class="employees"><?php _e('Employees', CIP_TXTDOMAIN); ?></th>
				<th data-field="PlasticWaste" data-filter-control="input" data-sortable="true" data-visible="false" class="pwaste"><?php _e('Plastic Waste', CIP_TXTDOMAIN); ?></th>					
				<th data-field="PlasticWasteFootprint" data-filter-control="input" data-sortable="true" data-visible="false" class="footprint"><?php _e('Plactic Waste Footprint', CIP_TXTDOMAIN); ?></th>					
				<th data-field="Username" data-filter-control="input" data-sortable="true" class="uname"><?php _e('Username', CIP_TXTDOMAIN); ?></th>							
				<th data-field="FirstName" data-filter-control="input" data-sortable="true" class="fname"><?php _e('First name', CIP_TXTDOMAIN); ?></th>							
				<th data-field="LastName" data-filter-control="input" data-sortable="true" class="lname"><?php _e('Last name', CIP_TXTDOMAIN); ?></th>	
				<th data-field="Email" data-filter-control="input" data-sortable="true" class="email"><?php _e('Email', CIP_TXTDOMAIN); ?></th>			
				<th data-field="IntroducedBy" data-filter-control="input" data-sortable="true" class="by"><?php _e('Sponsor', CIP_TXTDOMAIN); ?></th>						
				<th data-field="Address1" data-filter-control="input" data-sortable="true" data-visible="false" class="address1"><?php _e('Address Line 1', CIP_TXTDOMAIN); ?></th>														
				<th data-field="Address2" data-filter-control="input" data-sortable="true" data-visible="false" class="address2"><?php _e('Address Line 2', CIP_TXTDOMAIN); ?></th>							
				<th data-field="Number" data-filter-control="input" data-sortable="true" data-visible="false" class="number"><?php _e('Phone Number', CIP_TXTDOMAIN); ?></th>
				<th data-field="City" data-filter-control="input" data-sortable="true" data-visible="false" class="city"><?php _e('City', CIP_TXTDOMAIN); ?></th>							
				<th data-field="State" data-filter-control="input" data-sortable="true" data-visible="false" class="state"><?php _e('State', CIP_TXTDOMAIN); ?></th>
				<th data-field="Country" data-filter-control="input" data-sortable="true" data-visible="false" class="country"><?php _e('Country', CIP_TXTDOMAIN); ?></th>							
				<th data-field="Zipcode" data-filter-control="input" data-sortable="true" data-visible="false" class="zip"><?php _e('Zipcode', CIP_TXTDOMAIN); ?></th>
				<th data-field="token" data-filter-control="select" data-filter-data="var:selectToken" data-sortable="true" class="token"><?php _e('Token', CIP_TXTDOMAIN); ?></th>
				<th data-field="action" data-switchable="false"><?php _e('Action', CIP_TXTDOMAIN); ?></th>
			</tr>
		</thead>
	</table><br>
		<div class="modal fade" id="OrderProcessessRequestModal" tabindex="-1" role="dialog">
			<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
				<div class="modal-content">
					<div class="modal-body">
					<div class="container-fluid">
						<span class="order_prosess_close_btn close" data-dismiss="modal">&times;</span>
						<div class="row justify-content-center">
							<div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 text-center p-0 mt-0 mb-2">
								<div class="card-" id="order_prosess_body">
								<form name="order_prosess_request_wizard" class="order_prosess_request_wizard" id="msform">
								<!-- progressbar -->
								<ul id="progressbar" class="mb-3">
									<li class="active" id="fieldmapping"><strong><?php _e('Step-1','corsair-login') ?></strong></li>
									<li id="fieldmapping"><strong><?php _e('Step-2','corsair-login') ?></strong></li>
									<li id="fieldmapping"><strong><?php _e('Step-3','corsair-login') ?></strong></li>
									<li id="fieldmapping"><strong><?php _e('Step-4','corsair-login') ?></strong></li>
									<li id="fieldmapping"><strong><?php _e('Step-5','corsair-login') ?></strong></li>
								</ul>
								<div class="progress">
									<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: 20%;"></div>
								</div>
								<br> <!-- fieldsets -->
								<fieldset class="step_0">
									<input type="button" name="next" class="next_OI action-button" value="Next" />
								</fieldset>
								<fieldset class="step_1">
									<input type="button" name="next" class="next_OI action-button" value="Next" />
									<input type="button" name="previous" class="previous_OI action-button-previous" value="Previous" />
								</fieldset>
								<fieldset class="step_2">
								<input type="button" name="next" class="next_OI action-button" value="Next" />
								<input type="button" name="previous" class="previous_OI action-button-previous" value="Previous" />
								</fieldset>
								<fieldset class="step_3">
									<input type="button" name="next" class="next_OI action-button" value="Next" />
									<input type="button" name="previous" class="previous_OI action-button-previous" value="Previous" />
								</fieldset>
								<fieldset class="step_4">
									<div class="form-card">
										<div class="row">
											<div class="purchase_responce" style="height: 400px;">
											</div>
										</div>
									</div>
								</fieldset>
								<input type="hidden" name="action" value="sa_order_request_wizard_action" />
								<input type="hidden" name="id" id="order_id" value="" />
								<input type="hidden" name="_micro" value="<?php echo wp_create_nonce('_CIPorderRequestWizardCIP_'); ?>" />
							</form>
								</div>
							</div>
						</div>
					</div>
					</div>
				</div>
			</div>
		</div>
	</div>  
	<?php   
}
$Orders_Invoices_table_url = add_query_arg( [
	'action'	=>	'Orders_Invoices_table_loader',
	'pageid'	=>	get_the_ID(),
], admin_url( 'admin-ajax.php' ) );
?>
<script>
    jQuery(document).ready(function(){
		const swalOIToast = Swal.mixin({
			toast: true,
			animation: true,
			position: 'bottom',
			showConfirmButton: false,
			timer: 4000,
			timerProgressBar: true,
			didOpen: (toast) => {
			toast.addEventListener('mouseenter', Swal.stopTimer)
			toast.addEventListener('mouseleave', Swal.resumeTimer)
			}
		});
		if( $('table#tokenholder_Orders_Invoices_table').length > 0 ){
			$('[data-toggle-title="tooltip"]').tooltip();
			var Orders_Invoices_table_url = "<?php echo $Orders_Invoices_table_url ?>";
			var $OrdersInvoicesTable = $('#tokenholder_Orders_Invoices_table');
			$OrdersInvoicesTable.bootstrapTable({
				method: 'post',
				contentType: 'application/x-www-form-urlencoded',
				url: Orders_Invoices_table_url,
				queryParams: function (p) {
					return {
						search: p.search,
						columnfilter: p.filter,
						limit: p.limit,
						offset: p.offset,
						sort: p.sort,
						order: p.order,
						ArchiveStatus: $('.csr-archive-button').attr('data-archive-status'),
					};
				},
				stickyHeader: true,
				onPostBody: function (){
					if( $('body').find('.modelpop_notes').length > 0 ){
						$('[data-toggle-tt="tooltip"]').tooltip();
					}else if( $('[data-toggle-tt="tooltip"]').length > 0 ){
						$('[data-toggle-tt="tooltip"]').tooltip();
					}
				}
			});
		}
		$('.csr-archive-button').on('click', function() {
			const currentStatus = $(this).attr('data-archive-status');
			const newStatus = currentStatus === 'true' ? 'false' : 'true';
			$(this).attr('data-archive-status', newStatus);
			$('#tokenholder_Orders_Invoices_table').bootstrapTable('refresh');
		});
		$('body').on('click', '.archive_status_active', function(event){
			var selected_id = $(this).attr('archive-id');
			var this_toggle_status = $(this).parent().find('.archive_toggle_status');
			// alert(arch);
			var data = {id:selected_id, arch:'No',action:'archive_toggle_action'};
			var current_tr = $(this).closest('tr');
			var $thisCheck = $(this);
			
			current_tr.block( block_config );
			jQuery.ajax({ 
				type: "post",
				data: data,
				cache: false,
				url: cipscript.ajax_url,
				dataType: "html",
				success: function(response){
					var obj = JSON.parse( response );
					if( obj.error == 0 ){
						$('#tokenholder_Orders_Invoices_table').bootstrapTable('refresh');
					}
					current_tr.unblock();
				}
			});
		});
		$('body').on('click', '.order_process', function(event){
			var current_tr = $(this).closest('tr');
			var selected_id = $(this).attr('archive-id');
			var micro = $(this).attr('micro');
			var data = {id:selected_id, micro:micro,action:'cip_order_process_action'};
			current_tr.block( block_config );
			jQuery.ajax({ 
				type: "post",
				data: data,
				cache: false,
				url: cipscript.ajax_url,
				dataType: "html",
				success: function(response){
					var obj = JSON.parse( response );
					if( obj.error == 0 ){
						$('#OrderProcessessRequestModal').modal({backdrop: 'static',keyboard: false});
						current = 1;
						$("#order_prosess_body").html(obj.html);
					}else{
						swalOIToast({ type: 'error', title: obj.msg });
					}
					current_tr.unblock();
				}
			});
		});
		$('body').on('click', '.archive_status_deactive', function(event){
			var selected_id = $(this).attr('archive-id');
			var this_toggle_status = $(this).parent().find('.archive_toggle_status');
			// alert(arch);
			var data = {id:selected_id, arch:'Yes',action:'archive_toggle_action'};
			var current_tr = $(this).closest('tr');
			var $thisCheck = $(this);
			Swal({
				title: '',
				html: "<h5> You are about to mark the Archive Status as No <br/> Are you sure?</h5>",
				type: 'warning',
				showCancelButton: true,
				confirmButtonText: 'Confirm'
				}).then((result) => {
				if (result.value) {
					current_tr.block( block_config );
					jQuery.ajax({ 
						type: "post",
						data: data,
						cache: false,
						url: cipscript.ajax_url,
						dataType: "html",
						success: function(response){
							var obj = JSON.parse( response );
							if( obj.error == 0 ){
								$('#tokenholder_Orders_Invoices_table').bootstrapTable('refresh');
							}
							current_tr.unblock();
						}
					});
				}
			});
		});
		if( $('.order_prosess_request_wizard').length > 0 ){
			var block_config_spinner = { css: { backgroundColor: 'transparent', border: 'none' }, message: '<div class="blockUIspinner"></div>', baseZ: 1500, overlayCSS: { backgroundColor: '#FFFFFF', opacity: 0.8, cursor: 'wait' } };
			var current_fs, next_fs, previous_fs; //fieldsets
			var opacity;
			var current = 1;
			var steps = $('body').find(".order_prosess_request_wizard fieldset").length;
			setProgressBarOI(current);
			$('body').on("click",".next_OI", function(event){
				var this_next = $(this);
				current_fs = $(this).closest('fieldset');
				next_fs = $(this).closest('fieldset').next();
				var $form = $('body').find('.order_prosess_request_wizard');
				var data = $form.serialize();

				if( current == 1 ){
					if($('.order_prosess_request_wizard #phantom_user_check').length > 0){
						var phantom_user_checkisChecked = $('.order_prosess_request_wizard #phantom_user_check').is(':checked');;
						if( !phantom_user_checkisChecked ){
							swalOIToast( { type: 'error', title:'Please check the checkbox'} );
							return false;
						}
					}
					var user_uploaded_oca_checkisChecked = $('.order_prosess_request_wizard #user_uploaded_oca_check').is(':checked');;
					if( !user_uploaded_oca_checkisChecked ){
						swalOIToast( { type: 'error', title:'Please check the checkbox'} );
						return false;
					}
					var purchase_noteisChecked = $('.order_prosess_request_wizard #purchase-note').is(':checked');;
					if( !purchase_noteisChecked ){
						swalOIToast( { type: 'error', title:'Please check the checkbox'} );
						return false;
					}
					var gift_redeemisChecked = $('.order_prosess_request_wizard #gift_redeem').is(':checked');;
					if( !gift_redeemisChecked ){
						swalOIToast( { type: 'error', title:'Please check the checkbox'} );
						return false;
					}
					$(".order_prosess_request_wizard #progressbar li").eq( $(".order_prosess_request_wizard fieldset").index(next_fs) ).addClass("active");
					next_fs.show();
					current_fs.animate({opacity: 0}, {
						step: function(now) {
							opacity = 1 - now;

							current_fs.css({
								'display': 'none',
								'position': 'relative'
							});
							next_fs.css({'opacity': opacity});
						},
						duration: 500
					});
					setProgressBarOI(++current);
				}else if( current == 2 ){
					var ticket_raised_checkboxChecked = $('.order_prosess_request_wizard #ticket_raised_checkbox').is(':checked');;
					if( !ticket_raised_checkboxChecked ){
						swalOIToast( { type: 'error', title:'Please check the checkbox'} );
						return false;
					}
					$(".order_prosess_request_wizard #progressbar li").eq( $(".order_prosess_request_wizard fieldset").index(next_fs) ).addClass("active");
					next_fs.show();
					current_fs.animate({opacity: 0}, {
						step: function(now) {
							opacity = 1 - now;
							current_fs.css({
								'display': 'none',
								'position': 'relative'
							});
							next_fs.css({'opacity': opacity});
						},
						duration: 500
					});
					setProgressBarOI(++current);
				}else if( current == 3 ){
					var user_upline_notified_checked = $('.order_prosess_request_wizard #user_upline_notified_check').is(':checked');;
					if( !user_upline_notified_checked ){
						swalOIToast( { type: 'error', title:'Please check the checkbox'} );
						return false;
					}
					var user_po_marked_checked = $('.order_prosess_request_wizard #user_po_marked_check').is(':checked');;
					if( !user_po_marked_checked ){
						swalOIToast( { type: 'error', title:'Please check the checkbox'} );
						return false;
					}
					$(".order_prosess_request_wizard #progressbar li").eq( $(".order_prosess_request_wizard fieldset").index(next_fs) ).addClass("active");
					next_fs.show();
					current_fs.animate({opacity: 0}, {
						step: function(now) {
							opacity = 1 - now;
							current_fs.css({
								'display': 'none',
								'position': 'relative'
							});
							next_fs.css({'opacity': opacity});
						},
						duration: 500
					});
					setProgressBarOI(++current);
				}else if( current == 4 ){
					if($('.order_prosess_request_wizard #user_complate_po_process_check').length > 0){
						var user_complate_po_process_checkisChecked = $('.order_prosess_request_wizard #user_complate_po_process_check').is(':checked');;
						if( !user_complate_po_process_checkisChecked ){
							swalOIToast( { type: 'error', title:'Please check the checkbox'} );
							return false;
						}
						$(".order_prosess_request_wizard #progressbar li").eq( $(".order_prosess_request_wizard fieldset").index(next_fs) ).addClass("active");
						next_fs.show();
						current_fs.animate({opacity: 0}, {
							step: function(now) {
								opacity = 1 - now;

								current_fs.css({
									'display': 'none',
									'position': 'relative'
								});
								next_fs.css({'opacity': opacity});
							},
							duration: 500
						});
						setProgressBarOI(++current);
					}else{
						var user_ga_otp = $('.order_prosess_request_wizard #user_ga_otp').val();
						if( user_ga_otp == "" ){
							swalOIToast( { type: 'error', title:'Please enter the authentication code'} );
							return false;
						}
						$form.block( block_config_spinner );

						$.post(cipscript.ajax_url, data+'&step='+current, async function(response) {
							var obj = JSON.parse( response );
							if( obj.error == 0 ){
								$(".order_prosess_request_wizard #progressbar li").eq( $(".order_prosess_request_wizard fieldset").index(next_fs) ).addClass("active");
								next_fs.show();
								current_fs.animate({opacity: 0}, {
									step: function(now) {
										opacity = 1 - now;

										current_fs.css({
											'display': 'none',
											'position': 'relative'
										});
										next_fs.css({'opacity': opacity});
									},
									duration: 500
								});
								setProgressBarOI(++current);
								$form.unblock();
								let isComplete = false;
								do {
									const response = await $.post(cipscript.ajax_url,data+'&step='+current);
									const objca = JSON.parse(response);

									if (objca.error == 0) {
										const htmlContent = `${objca.message}`;
										$('.purchase_responce').append(htmlContent);
										if(objca.isComplete){
											$('#tokenholder_Orders_Invoices_table').bootstrapTable('refresh');
											setTimeout(function () {
												location.reload();
											}, 10000);
											isComplete = true;
										}
									} else {
										const htmlContent = `<div>${objca.message}</div>`;
										$('.purchase_responce').append(htmlContent);
										$('#tokenholder_Orders_Invoices_table').bootstrapTable('refresh');
										$('#close_op_process').show();
										return false; // Exit the function on error
									}
								} while (!isComplete);
							}else{
								swalOIToast({ type: 'error', title: obj.msg });
								$form.unblock();
							}
						});
					}
				}else{
					var user_ga_otp = $('.order_prosess_request_wizard #user_ga_otp').val();
					if( user_ga_otp == "" ){
						swalOIToast( { type: 'error', title:'Please enter the authentication code'} );
						return false;
					}
					$form.block( block_config_spinner );

					$.post(cipscript.ajax_url, data+'&step=check_authentication', async function(response) {
						var obj = JSON.parse( response );
						if( obj.error == 0 ){
							const htmlContent = `${obj.complated_process}`;
							$('.purchase_responce').append(htmlContent);
							$(".order_prosess_request_wizard #progressbar li").eq( $(".order_prosess_request_wizard fieldset").index(next_fs) ).addClass("active");
							next_fs.show();
							current_fs.animate({opacity: 0}, {
								step: function(now) {
									opacity = 1 - now;

									current_fs.css({
										'display': 'none',
										'position': 'relative'
									});
									next_fs.css({'opacity': opacity});
								},
								duration: 500
							});
							setProgressBarOI(++current);
							$form.unblock();
							let isComplete = false;
							do {
								const response = await $.post(cipscript.ajax_url,data+'&step=5');
								const objca = JSON.parse(response);

								if (objca.error == 0) {
									const htmlContent = `${objca.message}`;
									$('.purchase_responce').append(htmlContent);
									if(objca.isComplete){
										$('#tokenholder_Orders_Invoices_table').bootstrapTable('refresh');
										setTimeout(function () {
											location.reload();
										}, 10000);
										isComplete = true;										
									}
								} else {
									const htmlContent = `<div>${objca.message}</div>`;
									$('.purchase_responce').append(htmlContent);
									$('#tokenholder_Orders_Invoices_table').bootstrapTable('refresh');
									$('#close_op_process').show();
									return false; // Exit the function on error
								}
							} while (!isComplete);
						}else{
							swalOIToast({ type: 'error', title: obj.msg });
							$form.unblock();
						}
					});
				}
			});
			$('body').on("click",".previous_OI", function(){
				current_fs = $(this).closest('fieldset');
				previous_fs = $(this).closest('fieldset').prev();
				// console.log( current );
				$(".order_prosess_request_wizard #progressbar li").eq($(".order_prosess_request_wizard fieldset").index(current_fs)).removeClass("active");
				previous_fs.show();
				current_fs.animate({opacity: 0}, {
					step: function(now) {
						opacity = 1 - now;
						current_fs.css({
						'display': 'none',
						'position': 'relative'
						});
						previous_fs.css({'opacity': opacity});
					},
					duration: 500
				});
				setProgressBarOI(--current);
			});
			function setProgressBarOI(curStep){
				var steps = $('body').find(".order_prosess_request_wizard fieldset").length;
				var percent = parseFloat(100 / steps) * curStep;
				percent = percent.toFixed();
				$('body').find(".order_prosess_request_wizard .progress-bar").css("width",percent+"%")
			}
			$('#OrderProcessessRequestModal').on('hidden.bs.modal', function () {
				setProgressBarOI(1);
			});
			$('body').on("click",".close_OI", function(){
				$("#withdrawalRequestModal").modal('hide');
				window.location.reload();
			});
		}
    });
</script>