@extend('admin.layout')
@section('headerinclude')
<title>Para Birimi Ekle</title>
@endsection
@section('content')
<div class="post d-flex flex-column-fluid" id="kt_post">
    <div id="kt_content_container" class="container-xxl">
        <div class="card mb-10">
            <div class="card-header">
                <div class="card-title">
                    Para Birimi Ekle
                </div>
            </div>
            <div class="card-body">
                <form id="currencyForm">
                    <div class="row">
                        <div class="col-4 mb-9">
                            <label class="fs-6 fw-semibold mb-2">Birim Adı</label>
                            <input type="text" class="form-control" name="cname">
                        </div>
                        <div class="col-4 mb-9">
                            <label class="fs-6 fw-semibold mb-2">Birim Kodu</label>
                            <input type="text" class="form-control" name="ccode">
                        </div>
                        <div class="col-4 mb-9">
                            <label class="fs-6 fw-semibold mb-2">Birim İkonu</label>
                            <input type="text" class="form-control" name="cicon">
                        </div>
                        <div class="col-6 mb-9">
                            <label class="fs-6 fw-semibold mb-2">Temel Çevirim Oranı</label>
                            <input type="text" class="form-control" name="crate">
                        </div>
                        <div class="col-6 mb-9">
                            <label class="fs-6 fw-semibold mb-2">Birim Vergi Oranı</label>
                            <input type="text" class="form-control" name="ctaxrate">
                        </div>
                        <div class="col-12">
                            <button class="btn btn-success d-block m-auto addCurrency">Kaydet</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
@section('js')
<script>
    var wait = false;
    $(".addCurrency").on("click",function(){
        if(!wait){
            $(".addCurrency").html('Bekleyin <span class="spinner-border spinner-border-sm align-middle ms-2"></span>');
            wait = true;
            $.ajax({
                url: "{{ beGetRoute('admin.currency.add.post') }}",
                type: "post",
                async: true,
                data: $("#currencyForm").serialize(),
                dataType: "json",
                crossDomain: true,
                success: function(response){
                    wait = false;
                    $(".addCurrency").html("Kaydet");
                    if(response.status){
                        Swal.fire("Başarılı",response.message,"success");
                    }
                    else{
                        Swal.fire("Bir Hata Oluştu",response.message,"error");
                        wait = false;
                    }
                }
            });	
        }	
        else{
            Swal.fire("Bir Hata Oluştu","Lütfen işlemin tamamlanmasını bekleyin","error");
        }
        return false;
    });
</script>
@endsection