<!DOCTYPE html>
<html lang="en" class="h-100">


<head>
     <!-- meta and links start -->
     <%- include('templet/meta')-%> 
    
</head>
<body>

 
    
    <%- include('templet/preloder_topbar_sidebar',{titel: accessdata?.topbardata?.name })-%> 
       
            <!--********** Content body start **********-->
     
        <div class="content-body">
            
            <div class="container-fluid" style="min-height: 100vh;">
                <div class="row">
                    <div class="col-12">
                       <div class="card ">
                            <div class="card-header">
                               <h3 class="card-title"><%= language.Customer_List %> </h3>
                                <button class="btn btn-rounded btn-primary <%= login == "customer" ||  !accessdata?.roll?.customers?.includes('write') ? 'd-none': '' %>" data-bs-toggle="modal" data-bs-target="#addcoustomer" ><span class="btn-icon-start text-primary"><i class="fa fa-plus color-info"></i></span><%= language.Add_Customer %> </button>         
                            </div>
                            <div class="card-body ">
                                <div class="table-responsive">
                                    <table id="example3" class="display table-responsive-lg" style="width: 100%;">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th><%= language.Customer_Name %> </th>
                                                <th><%= language.Contect %> </th>
                                                <th><%= language.Address %>  </th>
                                                <th class="<%= ismulty  && login == "master" ? '': 'd-none' %>"><%= language.Store_Name %>  </th>
												<th><%= language.Status %>  </th>
												<!-- <th>Ledger</th> -->
                                                <th><%= language.Action %> </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <% coustormdata.forEach(function(data, i){ %>
                                                <% if (data.name != "Walk in customer") { %>
                                                    <tr>
                                                        <td><%= i + 1 %></td>
                                                        <td><%=data.name %></td>
                                                        <td><p><%=data.number %></p><span><%=data.email %></span></td>
                                                        <td><%=data.address %></td>
                                                        <td class="<%= ismulty  && login == "master" ? '': 'd-none' %>"><%=data.store %></td>
                                                        <td>
                                                            <%if( data.approved === 1){ %>
                                                                <span class="badge light badge-success">Approved</span>
                                                            <% }else{ %>
                                                                <span class="badge light badge-warning">pending</span>
                                                            <% } %>
                                                        </td> 
                                                        <!-- <td>
                                                            <% if(data.tot_ledger != "0"){ %>
                                                            <a href="/coustomer/ledger/<%=data.id %>" class="btn btn-primary shadow sharp me-1"><i class="fa-solid fa-eye"></i></a>
                                                            <% }; %>  
                                                        </td> -->
                                                        <td>
</a>

                                                            <a href="#" class="btn btn-primary shadow sharp me-1 <%=  (accessdata.logas ='custmor' && accessdata.roll.customer?.includes('edit') ) || accessdata.roll.customers?.includes('edit') ? '': 'd-none' %>" id="action"
                                                                data-bs-toggle="modal" data-bs-target="#coustomer"
                                                                data-name="<%=data.name %>", data-number="<%=data.number %>", data-email="<%=data.email %>", data-addresh="<%=data.address %>"
                                                                data-tax="<%=data.taxnumber %>" , data-approved="<%=data.approved %>", data-active="<%=data.delet_flage %>" data-id="<%=data.id %>"
                                                                data-roll="<%=data.roll_id %>">
                                                                <i class="fas fa-pencil-alt"></i></a>   
                                                            <% if(data.transiction>0){%>     
                                                             <a href="/coustomer/ledger/<%=data.id %>" class="btn btn-success shadow sharp me-1"><i class="fas fa-eye"></i></a>
                                                             <% } %>
                                                             <a href="/coustomer/delete/<%=data.id %>" class="btn btn-danger shadow sharp me-1 <%= !accessdata?.roll?.customers?.includes('delete') ?'d-none':'' %>"><i class="fas fa-trash"></i> </a>

                                                        </td>
                                                    </tr>
                                                <% } %>
                                           <% }) %>
   
                                        </tbody>
                                    </table>
                                </div>
                            
                            
                            </div>
                       </div>
                    </div>
                </div>
            </div>


        
      
            <!--********** Content body end **********-->

            <!-- Modal update -->
            <div class="modal fade" id="coustomer">
                <div class="modal-dialog  modal-dialog-scrollable" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title"><%= language.Customer_Detail %> </h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                        </div>
                        <div class="modal-body">
                            <form action="/coustomer/update/" id="coustomer_form" method="post" class="need-validation">
                                
                                    <div class="row g-1 align-items-center">
                                        <div class="col-md-12 mb-1">
                                            <label class="form-label"><%= language.Customer_Name %> <span class="text-danger">*</span></label>
                                            <input type="text"  class="form-control" name="name" id="name" value="" required>
                                        </div>

                                        <div class="col-md-12 mb-1">
                                            <label class="form-label"><%= language.Phone_Number %>  <span class="text-danger">*</span></label>
                                            <input type="number" class="form-control" name="number" id="number" value="" required>
                                        </div>
                                        <div class="col-md-12 mb-1">
                                            <label class="form-label"><%= language.Email %> </label>
                                            <input type="text" class="form-control" name="email" value="" id="email" required>
                                        </div>
                                        <div class="col-md-12 mb-1">
                                            <label class="form-label"><%= language.Tax_Number %> </label>
                                            <input type="text" class="form-control" name="tax" value="" id="tax" >
                                                                        </div>
                                        <div class="col-md-12 mb-3">
                                            <label class="form-label"><%= language.Address %> </label>
                                            <input type="text" class="form-control" name="address" value="" id="address" >
                                        </div>
                                    
                                        <div class="col-md-12 mb-1 d-inline-flex justify-content-between <%= login == "customer" ? 'd-none': '' %>">
                                            <div class="form-check form-switch">
                                                <input class="form-check-input" type="checkbox" id="Approved" name="approved" value="1" >
                                                <label class="form-check-label"
                                                    for="Approved  "><%= language.Is_Approved %>  ?</label>
                                            </div>
                                                 <!-- <div class="form-check form-switch">
                                                <input class="form-check-input" type="checkbox" id="active" name="active" value="0" >
                                                <label class="form-check-label"
                                                    for="employee"><%= language.Is_Active %>  ?</label>
                                            </div> -->
                                        </div>
                                    </div>
                        </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-sm btn-secondary"
                                            data-bs-dismiss="modal"><%= language.Cancel %></button>
                                        <button type="submit" class="btn btn-sm  btn-primary"><%= language.Save %> </button>
                                    </div>
                            </form>
                    </div>
                </div>
            </div>

            <!-- Modal add -->
            <div class="modal fade" id="addcoustomer">
                <div class="modal-dialog  modal-dialog-scrollable" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title"><%= language.Customer_Detail %> </h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                        </div>
                        <div class="modal-body">
                            <form action="/coustomer/register" method="post" class="need-validation">
                                
                                    <div class="row g-1 align-items-center">
                                        <div class="form-group">
                                            <label><strong><%= language.Name %> </strong></label>
                                            <input type="text" class="form-control " name="name" required>
                                        </div>
                                        <div class="form-group">
                                            <label><strong><%= language.Phone_Number %> </strong></label>
                                            <input type="number" class="form-control" name="number"  required>
                                        </div>
                                        <div class="form-group">
                                            <label><strong><%= language.Email %> </strong></label>
                                            <input type="email" class="form-control" name="email" required>
                                        </div>
                                           <div class="col-md-12 mb-3 <%= ismulty && login == "master" ? '': 'd-none' %>">
                                            <div class="form-group">
                                                <label class="form-label"><strong> <%= language.Store_List %> </strong><span class="text-danger">*</span></label>
                                                <select class=" form-control wide mb-3" name="storeid"
                                                    id="Customer_add" >
                                                    <option value="" selected  > Select Store </option>
                                                    <% storeList.forEach(function(x){ %>
                                                        <option value="<%= x.id %>"><%= x.name %></option>
                                                    <% }) %>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label><strong><%= language.Tax_Number %> </strong></label>
                                            <input type="text" class="form-control"name="taxnumber" >
                                        </div>
                                        <div class="form-group">
                                            <label><strong><%= language.Address %> </strong></label>
                                            <input type="text" class="form-control" name="address">
                                        </div>

                                     
                                        
                                        <div class="form-group">
                                            <label><strong><%= language.Username %> </strong></label>
                                            <input type="text" class="form-control" name="username">
                                        </div>
                                        <div class="form-group">
                                            <label><strong><%= language.Password %> </strong></label>
                                            <input type="text" class="form-control" name="password">
                                        </div>
                                        
                                    </div>
                        </div>
                               
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-sm btn-secondary"
                                        data-bs-dismiss="modal"><%= language.Cancel %></button>
                                    <button type="submit" class="btn btn-sm  btn-primary"><%= language.Save %> </button>
                                </div>
                            </form>


                        
                    </div>
                </div>
            </div>
            </div>
        <!--**********************************
            Footer start
        ***********************************-->
          <%- include('templet/footer')-%>

        <!--**********************************
            Footer end
        ***********************************-->

    </div>

        <!--********** Main wrapper end **********-->
        <%- include('templet/script')-%>
<script>
  $('#addcoustomer').on('shown.bs.modal', function () {
    
    $('#Customer_add').select2({
      dropdownParent: $('#addcoustomer'),
      placeholder: 'Select Store(s)',
      width: '100%',
      allowClear: true
    });
  });
</script>  
</body>


</html>