
<?php $__env->startSection('title'); ?>
Suppliers
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>               

<?php
$PermissionsAddSuppliers = App\Models\PermissionsUserModel::getPermission('Add Suppliers', Auth::user()->id);
$PermissionsEditSuppliers = App\Models\PermissionsUserModel::getPermission('Edit Suppliers', Auth::user()->id);
$PermissionsDeleteSuppliers = App\Models\PermissionsUserModel::getPermission('Delete Suppliers', Auth::user()->id);
?>


<div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800">System Suppliers</h1>
                      </div>

                  
                    <div class="card shadow mb-4">
                        <div class="card-header py-3">
                            <h6 class="m-0 font-weight-bold text-primary"   id="formHeader">Add Suppliers</h6>
                        </div>
                        <?php if(session('success')): ?>
                            <div class="alert alert-success" id="successMessage"  style="margin: 20px;">
                                <?php echo e(session('success')); ?>

                            </div>
                        <?php endif; ?>
                      
                        <?php if($errors->any()): ?>

                                    <div class="form-group"  id="successMessage"  style="margin: 20px;">
                                        <div class="card bg-warning text-white shadow">
                                            <div class="card-body">
                                        
                                                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <div style="color: red; "><?php echo e($error); ?></div>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        
                                            </div>
                                        </div>
                                    </div>
                                    <?php endif; ?>
                                    <?php if(!empty($PermissionsAddSuppliers)): ?>
                            <form class="card-body" action="<?php echo e(route('addsuppliers')); ?>" method="post"  id="accountTypeForm">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" id="accountId" name="id" value="">
                                
                            <div class="form-group row">
                                   <div class="col-sm-4 mb-3 mb-sm-0">
                                        <input type="text" class="form-control form-control-user" id="AccCode" placeholder="Account Code" name="AccCode"  value="<?php echo e($account); ?>" required readonly>
                                    </div>
                                    <div class="col-sm-4 mb-3 mb-sm-0">
                                        <input type="text" class="form-control form-control-user" id="AccName" placeholder="Supplier Account" name="AccName" value="Supplier Account" required readonly>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control form-control-user" id="code" placeholder="Supplier Code" name="code"  value="<?php echo e(old('code')); ?>" required>
                                    </div>
                                </div>
                               
                                <div class="form-group row">
                                <div class="col-sm-4 mb-3 mb-sm-0">
                                        <input type="text" class="form-control form-control-user" id="name" placeholder="Supplier Name" name="name"  value="<?php echo e(old('name')); ?>" required>
                                    </div>
                                    <div class="col-sm-4 mb-3 mb-sm-0">
                                        <input type="text" class="form-control form-control-user" id="contactperson" placeholder="Contact Person" name="contactperson"  value="<?php echo e(old('contactperson')); ?>" required>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control form-control-user" id="contact1" placeholder="Contact 1" name="contact1"  value="<?php echo e(old('contact1')); ?>" required>
                                    </div>
                                </div>
                               
                                <div class="form-group row">
                                    <div class="col-sm-4 mb-3 mb-sm-0">
                                    <input type="text" class="form-control form-control-user" id="contact2" placeholder="Contact 2" name="contact2"  value="<?php echo e(old('contact2')); ?>" required>
                                    
                                    </div>
                                    <div class="col-sm-4 mb-3 mb-sm-0">
                                        <input type="text" class="form-control form-control-user" id="email" placeholder="Email" name="email"  value="<?php echo e(old('email')); ?>" required>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control form-control-user" id="Address" placeholder="Address" name="Address"  value="<?php echo e(old('Address')); ?>" required>
                                    </div>
                                </div>

                               <div style="display: flex;">
                               <input type="submit" style="width: 100px;height: 40px; margin-right: 10px; margin-top: 6px" value="Create" class="btn btn-primary btn-user btn-block" id="submitButton"/>

                                <input style="width: 100px;"  onclick="refreshAccountType('','', '','', '','', '')"   type="reset" value="Refresh" class="btn btn-secondary btn-user btn-block"  onclick="hideMessages()"/>
                                    
                               </div>
                                
                                <hr>
                             </form>
                             <?php endif; ?>
                   
                        
                        
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                                    <thead>
                                        <tr>
                                            <th>Entry Date</th>
                                            <th>Supplier Code</th>
                                            <th>Name</th>
                                            <th>Contact Person</th>
                                            <th>Contact 1</th>
                                            <th>Contact 2</th>
                                            <th>Email</th>
                                            <th>Address</th>
                                            <th>Action</th>
                                         
                                        </tr>
                                    </thead>
                                    <tfoot>
                                        <tr>
                                        
                                        
                                        <th>Entry Date</th>
                                            <th>Supplier Code</th>
                                            <th>Name</th>
                                            <th>Contact Person</th>
                                            <th>Contact 1</th>
                                            <th>Contact 2</th>
                                            <th>Email</th>
                                            <th>Address</th>
                                            <th>Action</th>
                                            

                                        </tr>
                                    </tfoot>
                                    <tbody>
                                      
                                    <?php $__currentLoopData = $suppliers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supplier): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                        
                                                <td><?php echo e($supplier->EntryDate); ?></td> 
                                                <td><?php echo e($supplier->SupplierCode); ?></td>
                                                <td><?php echo e($supplier->Name); ?></td> 
                                                <td><?php echo e($supplier->ContactPerson); ?></td>
                                                <td><?php echo e($supplier->Contact1); ?></td> 
                                                <td><?php echo e($supplier->Contact2); ?></td>
                                                <td><?php echo e($supplier->Email); ?></td> 
                                                <td><?php echo e($supplier->Address); ?></td>
                                                <td style="justify-content: center; align-items: center;">
                                                  <?php if(!empty($PermissionsEditSuppliers)): ?>
                                                  <a href="" onclick="editAccountType(event,'<?php echo e($supplier->ID); ?>', '<?php echo e($supplier->SupplierCode); ?>', '<?php echo e($supplier->Name); ?>', '<?php echo e($supplier->ContactPerson); ?>', '<?php echo e($supplier->Contact1); ?>', '<?php echo e($supplier->Contact2); ?>', '<?php echo e($supplier->Email); ?>', '<?php echo e($supplier->Address); ?>')"  class="btn btn-primary btn-circle" >
                                                  <i class="fas fa-edit"></i>
                                                  </a>
                                                  <?php endif; ?>
                                                  <?php if(!empty($PermissionsDeleteSuppliers)): ?>
                                                  <a href="<?php echo e(route('deletesuppliers',['id'=>$supplier->ID])); ?>" class="btn btn-danger btn-circle"   onclick="return confirmDelete('<?php echo e($supplier->Name. ' => '.$supplier->ContactPerson); ?>');" >
                                                      <i class="fas fa-trash"></i>
                                                  </a>
                                                  <?php endif; ?>
                                              </td>
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                        
                    </div>

                    <script>
                           function editAccountType(event,id,code,name,contactperson,contact1,contact2,email,Address) 
                             {
                                event.preventDefault();
                                
                                document.getElementById('accountId').value = id;
                                document.getElementById('code').value = code;
                                document.getElementById('name').value = name;
                                document.getElementById('contactperson').value = contactperson;
                                document.getElementById('contact1').value = contact1;
                                document.getElementById('contact2').value = contact2;
                                document.getElementById('email').value = email;
                                document.getElementById('Address').value = Address;
                                document.getElementById('formHeader').innerText = 'Edit Supplier';
                                document.getElementById('submitButton').value = 'Update';
                                document.getElementById('accountTypeForm').action = '<?php echo e(route("editsuppliers")); ?>';
                            }
                
                            function refreshAccountType(id,code,name,contactperson,contact1,contact2,email,Address) 
                             {
                                
                                document.getElementById('accountId').value = id;
                                document.getElementById('code').value = code;
                                document.getElementById('name').value = name;
                                document.getElementById('contactperson').value = contactperson;
                                document.getElementById('contact1').value = contact1;
                                document.getElementById('contact1').value = contact2;
                                document.getElementById('email').value = email;
                                document.getElementById('Address').value = Address;
                                document.getElementById('formHeader').innerText = 'Create Supplier';
                                document.getElementById('submitButton').value = 'Create';
                                document.getElementById('accountTypeForm').action = '<?php echo e(route("addsuppliers")); ?>';
                                hideMessages();
                            
                            }

                            function confirmDelete(Name) {
                                return confirm("Are you sure you want to delete the Supplier: " + Name + "?");
                            }

                          


                
                </script>

                    <?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.nav', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/melsoftrealestat/public_html/re.pro/resources/views//Suppliers.blade.php ENDPATH**/ ?>