<?php
session_start();
require_once('../../config/db_const.php');
require_once ('../../config/class.Database.php');

$page_title = "معامله پولی";
$db = new Database(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
$db->connect();

if (isset($_SESSION['username']) && isset($_SESSION['password'])) {							
?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8"/>
<title><?php echo $page_title;?></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta content="" name="description"/>
<meta content="" name="author"/>
<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="../../assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/global/plugins/bootstrap/css/bootstrap-rtl.min.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/global/plugins/bootstrap-switch/css/bootstrap-switch-rtl.min.css" rel="stylesheet" type="text/css"/>
<!-- END GLOBAL MANDATORY STYLES -->
<!-- BEGIN PAGE LEVEL PLUGIN STYLES -->
<link href="../../assets/global/plugins/bootstrap-daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css"/>
<!-- END PAGE LEVEL PLUGIN STYLES -->
<!-- BEGIN PAGE LEVEL PLUGIN STYLES -->
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/select2/select2.css"/>
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/datatables/extensions/Scroller/css/dataTables.scroller.min.css"/>
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/datatables/extensions/ColReorder/css/dataTables.colReorder.min.css"/>
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap-rtl.css"/>
<link href="../../assets/global/plugins/bootstrap-daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css"/>
<!-- END PAGE LEVEL PLUGIN STYLES -->
<!-- BEGIN PAGE LEVEL STYLES -->
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/select2/select2.css"/>
<!-- END PAGE LEVEL SCRIPTS -->
<!-- BEGIN THEME STYLES -->
<link href="../../assets/global/css/components-md-rtl.css" id="style_components" rel="stylesheet" type="text/css"/>
<link href="../../assets/global/css/plugins-md-rtl.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/admin/layout/css/layout-rtl.css" rel="stylesheet" type="text/css"/>
<link id="style_color" href="../../assets/admin/layout/css/themes/darkblue-rtl.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/admin/layout/css/custom-rtl.css" rel="stylesheet" type="text/css"/>
<link href="../../assets/admin/layout/css/calendar.css" rel="stylesheet" type="text/css"/>
<!-- END THEME STYLES -->
<link rel="shortcut icon" href="favicon.ico"/>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-md page-header-fixed page-quick-sidebar-over-content">

<?php require_once('header.php');?>

<div class="clearfix">
</div>
<!-- BEGIN CONTAINER -->
<div class="page-container">
	<!-- BEGIN SIDEBAR -->
	<?php
	$menu_selected="customers";
	require_once('sidebar.php');?>
	<!-- END SIDEBAR -->
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			<!-- BEGIN PAGE CONTENT-->
			<!--BEGIN PAGE HEADER-->
			<div class="page-bar">
				<ul class="page-breadcrumb">
					<li>
						<i class="fa fa-home"></i>
						<a href="index.php">صفحه اصلی</a>
						<i class="fa fa-angle-left"></i>
					</li>
					<li>
						<a href="transaction_in.php">آوردن پول</a>
					</li>
				</ul>
			</div>
			<!-- END PAGE HEADER-->
			<div class="row">
				<div class="col-md-12">
                <div class="portlet box blue">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-gift"></i>مشتری
							</div>
							<div class="tools">
								<a href="javascript:;" class="collapse">
								</a>
							</div>
						</div>
						<div class="portlet-body">
							<div class="tabbable-custom nav-justified">
                            <br />
								<ul class="nav nav-tabs nav-justified">
									<li class="active">
										<a href="#tab_1_1_1" data-toggle="tab">
                                            <span class="fa fa-retweet tab-title"></span>
    										<span class="tab-title">معامله پولی</span>
                                        </a>
									</li>
									<li>
										<a href="#tab_1_1_2" data-toggle="tab">
										<span class="fa fa-mail-forward tab-title"></span>
										<span class="tab-title">برده گی</span>
                                         </a>
									</li>
									<li>
										<a href="#tab_1_1_3" data-toggle="tab">
    										<span class="fa fa-mail-reply tab-title"></span>
    										<span class="tab-title">رسیده گی</span>
                                        </a>
									</li>
                                    <li>
										<a href="#tab_1_1_4" data-toggle="tab">
                                        	<span class="fa fa-money tab-title"></span>
    										<span class="tab-title">مفاد</span>
										</a>
									</li>
								</ul>
								<div class="tab-content">
									<div class="tab-pane active" id="tab_1_1_1">
                                        <form action="../../models/transact.php" class="form-horizontal" id="submit_form" method="POST">
										<h3 class="block">آوردن و بردن پول</h3><br />
                                                <div class="form-group">
													<label class="control-label col-md-2">تاریخ معامله <span class="required">
													</span>
													</label>
													<div class="col-md-4">
                                                        <input type="text" name="date" id="date" class="form-control" onclick="displayDatePicker('date',this);" />
                                                        
														<span class="help-block">
														</span>
													</div>
                                                </div>
												<div class="form-group">
													<label class="control-label col-md-2">نوع معامله <span class="required">
													</span>
													</label>
													<div class="col-md-4">
														<select class="form-control select2me" data-live-search="true" name="type">
                                                            <option value="">نوع معامله</option>
                                                            <option value="in">آوردن</option>
                                                            <option value="out">بردن</option>
                                                        </select>
														<span class="help-block">
														</span>
													</div>
												</div>
												<div class="form-group">
													<label class="control-label col-md-2">مبلغ<span class="required">
													</span>
													</label>
													<div class="col-md-4">
														<input type="text" placeholder="" class="form-control" name="amount" id="amount"/>
														<span class="help-block">
														</span>
													</div>
												</div>
                                                <div class="form-group">
													<label class="control-label col-md-2">واحد پولی <span class="required">
													</span>
													</label>
													<div class="col-md-4">
														<select class="form-control select2me" data-live-search="true" name="currency">
                                                        <?php
                                                            $db->select("currencies","*");
                                                            foreach($db->data as $val){
                                                                echo "<option value='{$val['id']}'>{$val['unit']}</option>";
                                                            }   
                                                            $db->data="";      
                                                        ?>
                                                        </select>
														<span class="help-block">
														</span>
													</div>
												</div>
                                                <div class="form-group">
													<label class="control-label col-md-2">نرخ دالر <span class="required">
													</span>
													</label>
													<div class="col-md-4">
														<input type="text" placeholder="" class="form-control" name="rate" id="rate"/>
														<span class="help-block">
														</span>
													</div>
												</div>
                                                
                                                <div class="form-group">
													<label class="control-label col-md-2">مجموعه دالر <span class="required">
													</span>
													</label>
													<div class="col-md-4">
														<input type="text" placeholder="" id="totalUSD" class="form-control" name="total_dollars"/>
														<span class="help-block">
														</span>
													</div>
												</div>
                                                <div class="form-group">
													<label class="control-label col-md-2">انتخاب مشتری <span class="required">
													</span>
													</label>
													<div class="col-md-4">
														<select class="form-control select2me" data-live-search="true" id="customer" name="customer">
                                                            <option value="">مشتری</option>
                                                        <?php
                                                            $db->select("customers","*");
                                                            foreach($db->data as $val){
                                                                echo "<option value='{$val['id']}'>{$val['name']}</option>";
                                                            } 
                                                            $db->data="";        
                                                        ?>
                                                        </select>
														<span class="help-block">
														</span>
													</div>
												</div>
                                                <div class="form-group">
													<label class="control-label col-md-2">انتخاب حساب پولی <span class="required">
													</span>
													</label>
													<div class="col-md-4" id="caccount">
														<select class="form-control select2me" data-live-search="true" name="caccount">
                                                        </select>
														<span class="help-block">
														</span>
													</div>
												</div>
                                                <div class="form-group">
													<label class="control-label col-md-2">تفصیل <span class="required">
													</span>
													</label>
													<div class="col-md-4">
														<textarea class="form-control" rows="6" name="desc" ></textarea>
														<span class="help-block">
														</span>
													</div>
												</div>
                                                <div class="form-actions">
            										<div class="row">
            											<div class="col-md-offset-3 col-md-4">
            												<input type="submit" value="&nbsp;&nbsp;ذخیره&nbsp;&nbsp;" class="btn green button-submit" name="submit"/>
            											</div>
            										</div>
            									</div>
                                        </form>
									</div>
									<div class="tab-pane" id="tab_1_1_2">
									   
									</div>
									<div class="tab-pane" id="tab_1_1_3">
									
									</div>
                                    <div class="tab-pane" id="tab_1_1_4">
									
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
            <!-- success notification -->
            <div style="text-align:center">
        		<div class="overlay">
        			<div style="width:305px;margin-left:auto;margin-right:auto;margin-top:-60px;border:3px solid red;">
        				<div id="payam" style="width:300px;box-shadow:1px 3px 5px #000;background-color:#fff;border-radius:5px;padding:10px;text-align:center; position: absolute;">
        				<button type="button" id="linki" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><br/>
        				<h3>به شکل موفقانه درسیستم ثبت شد</h3>
        				</div>
        			</div>
        		</div>
	       </div>
           <!-- END SUCCESS NOTIFICAION -->
		<!-- END PAGE CONTENT-->
		</div>
	</div>
<!-- BEGIN FOOTER -->
<?php
	require_once('footer.php');

?>
<!-- END FOOTER -->
</div>
<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
<!-- BEGIN CORE PLUGINS -->
<!--[if lt IE 9]>
<script src="../../assets/global/plugins/respond.min.js"></script>
<script src="../../assets/global/plugins/excanvas.min.js"></script> 
<![endif]-->
<script src="../../assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/jquery-migrate.min.js" type="text/javascript"></script>
<!-- IMPORTANT! Load jquery-ui.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->
<script src="../../assets/global/plugins/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/jquery.cokie.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
<script src="../../assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
<!-- END CORE PLUGINS -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script type="text/javascript" src="../../assets/global/plugins/select2/select2.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/extensions/Scroller/js/dataTables.scroller.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script type="text/javascript" src="../../assets/global/plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/jquery-validation/js/additional-methods.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script type="text/javascript" src="../../assets/global/plugins/select2/select2.min.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="../../assets/global/scripts/metronic.js" type="text/javascript"></script>
<script src="../../assets/admin/layout/scripts/layout.js" type="text/javascript"></script>
<script src="../../assets/admin/layout/scripts/demo.js" type="text/javascript"></script>
<script src="../../assets/admin/pages/scripts/table-advanced.js"></script>
<script src="../../assets/admin/pages/scripts/form-wizard.js"></script>
<script src="../../assets/admin/layout/scripts/JsFarsiCalendar.js"></script>
<!-- END PAGE LEVEL SCRIPTS -->
<?php
    if(isset($_GET['s'])){
?>
<script>
    jQuery(document).ready(function() {  
		$(".overlay").show().animate();
		$(".overlay").fadeIn(500);
		$("#payam").animate({"top":"50px"},500);
		});
		
		$("#linki").click(function () {
			$("#payam").animate({"top" : "-50px"},500);
			$(".overlay").fadeOut(500);
		});
		
		$(".overlay").click(function(e){
			if(!$(e.target).closest('#payam').length) {
			$("#payam").animate({"top" : "-50px"},500);
			$(".overlay").fadeOut(500);
		}
   });
</script>
<?php
    }
?>
<script>
jQuery(document).ready(function() {  
    
    $("#caccount").hide();
    $("#customer").change(function (){
		var cid = $("#customer").val();
		if(cid != ""){
		  var string_data = "id="+cid;
    		$.ajax({
    			type : "POST",
    			url  : "../../models/check_customer_account.php",
    			data : string_data,
    			cache: false,
    			success : function (data){
    				$("#caccount").show();
    				$("#caccount").html(data);
    			}
    		});
		}
	});
    
    $("#link").click(function (){
			
		$(".overlay").show().animate();
		$(".overlay").fadeIn(500);
		$("#payam").animate({"top":"50px"},500);
		});
		
		$("#linki").click(function () {
		$("#payam").animate({"top" : "-50px"},500);
		$(".overlay").fadeOut(500);
		});
		
		$(".overlay").click(function(e){
			if(!$(e.target).closest('#payam').length) {
			$("#payam").animate({"top" : "-50px"},500);
			$(".overlay").fadeOut(500);
		}
	});
       
   // initiate layout and plugins
   Metronic.init(); // init metronic core components
   Layout.init(); // init current layout
   Demo.init(); // init demo features
   TableAdvanced.init();
   FormWizard.init(); 
});
</script>
<script>
    //Currency Converter
    function init(){
        var total = document.getElementById('totalUSD');
        total.onfocus = function(){
		  	amount = document.getElementById('amount');
            rate   = document.getElementById('rate');
            if(amount.value != "" && rate.value != ""){
			 	var t = parseFloat(amount.value) / parseFloat(rate.value);
                total.value = t.toFixed(2);
            }
        };
    }
    window.onload = function(){
		init();
    };
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
<?php
}else{
	header("Location: login.php");
}
?>