
<?php $__env->startSection('title'); ?>
<?php echo e($JournalType); ?> Invoice
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<?php
$PermissionsAddBanks = App\Models\PermissionsUserModel::getPermission('Add Banks', Auth::user()->id);
$PermissionsEditBanks = App\Models\PermissionsUserModel::getPermission('Edit Banks', Auth::user()->id);
$PermissionsDeletBanks = App\Models\PermissionsUserModel::getPermission('Delete Banks', Auth::user()->id);
?>

                    <!-- Page Heading -->
                    <div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800"><?php echo e($JournalType); ?>  Invoice</h1>
                      </div>

                      
                      <div class="row">

                      <!-- Donut Chart -->
                      <div class="col-xl-4 col-lg-5">
                            <div class="card shadow mb-4">
                                <!-- Card Header - Dropdown -->
                                <div class="card-header py-3" style="height: 70px;">
                                    <h6 class="m-0 font-weight-bold text-primary"  id="formHeader">Process Invoice</h6>
                               
                                   
                                </div>
                                <!-- Card Body -->
                                <div class="card-body">
                                <?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; ?>
                            <form class="card-body" action="<?php echo e(route('savetransaction')); ?>" method="post" id="accountTypeForm">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" id="accountId" name="id" value="">
                            <input type="hidden" id="source" name="source" value="<?php echo e($JournalType); ?>">
                            <div class="form-group">
                            <input type="hidden" class="form-control form-control-user" id="AccCode" placeholder="Control Account" name="AccCode"  value="<?php echo e($journal); ?>" required readonly>
                             </div>
                             <div class="form-group">
                            <input type="text" class="form-control form-control-user" id="batch" placeholder="Invoice" name="batch"  value="<?php echo e($batch); ?>" required <?php echo e($batch == 'SUP' ? '' : 'readonly'); ?>  onkeydown="preventRemoval(event)" oninput="enforcePrefixAndUpdateURL(this)">
                             </div>

                                <div class="form-group">
                                        <input type="date" class="form-control form-control-user" id="date" placeholder="Entry Date" name="date"  value="<?php echo e(old('date', \Carbon\Carbon::now()->format('Y-m-d'))); ?>" required>
                                   
                                </div>
                                <div class="form-group">
                                <input type="text" class="form-control form-control-user" id="mdes" placeholder="Main Description" name="mdes"  value="<?php echo e($mdes); ?>" required>
                                   
                                </div>
                                <div class="form-group">
                                <select class="form-control form-control-user" id="account" name="account"  value="<?php echo e(old('account')); ?>"  required>
                                        <option value="" disabled selected>Select <?php echo e($JournalType); ?> Account</option>

                                        <?php $__currentLoopData = $Accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $Account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        
                                        <option value="<?php echo e($Account->Code); ?>"><?php echo e($Account->Code.'/'.$Account->Name); ?></option>
                                          
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="form-group">
                                        <input type="text" class="form-control form-control-user" id="narr" placeholder="Narration" name="narr"  value="<?php echo e(old('narr')); ?>" required>
                                   
                                </div>
                                
                                <div class="form-group">
                                        <input type="text" class="form-control form-control-user" id="reff" placeholder="Refference" name="reff"  value="<?php echo e(old('reff')); ?>" required>
                                   
                                </div>
                                <div class="form-group">
                                <select class="form-control form-control-user" id="gl" name="gl"  value="<?php echo e(old('gl')); ?>"  required>
                                        <option value="" disabled selected>Select Account</option>

                                        <?php $__currentLoopData = $gls; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $gl): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        
                                        <option value="<?php echo e($gl->AccCode); ?>"><?php echo e($gl->AccCode.'/'.$gl->AccName); ?></option>
                                          
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="form-group">
                                <select class="form-control form-control-user" id="tax" name="tax"  value="<?php echo e(old('tax')); ?>"  required>
                                        <option value="" disabled selected>Select Tax</option>

                                        <?php $__currentLoopData = $taxs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tax): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        
                                        <option value="<?php echo e($tax->ID.':'.$tax->Rate); ?>"><?php echo e($tax->Rate.'% '.$tax->Name); ?></option>
                                          
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="form-group">
                                        <input type="text" class="form-control form-control-user" id="disc" placeholder="Discount %" name="disc"  value="<?php echo e(old('disc')); ?>" required>
                                   
                                </div>

                                <div class="form-group">
                                        <input type="text" class="form-control form-control-user" id="price" placeholder="Price" name="price"  value="<?php echo e(old('price')); ?>" required>
                                   
                                </div>

                                <div class="form-group">
                                <input type="text" class="form-control form-control-user" id="qty" placeholder="Quantity" name="qty"  value="<?php echo e(old('qty')); ?>" required>
                                   
                                </div>

                                <div class="form-group">
                                <select class="form-control form-control-user" id="curr" name="curr"  value="<?php echo e(old('curr')); ?>"  required>
                                        <option value="" disabled selected>Select Currency</option>

                                        <?php $__currentLoopData = $currencys; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $currency): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        
                                        <option value="<?php echo e($currency->ID); ?>"><?php echo e($currency->Name); ?></option>
                                          
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="form-group">
                                            <div class="custom-control custom-checkbox small">
                                                <input type="checkbox" class="custom-control-input" id="customCheck" name="customCheck">
                                                <label class="custom-control-label" for="customCheck">Operation Cost</label>
                                            </div>
                                        </div>
                               
                               <div style="display: flex;">
                               <input type="submit" style="width: 100px;height: 40px; margin-right: 10px; margin-top: 6px" value="Save" 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>
                                </div>
                            </div>
                        </div>

                        <div class="col-xl-8 col-lg-7">

                            <div class="card shadow mb-4">
                                <div class="card-header py-3">
                                    <h6 style="float: left;" class="m-0 font-weight-bold text-primary"><?php echo e($JournalType); ?> Transactions </h6>
                                    <?php if(!empty($PermissionsAddTenantsInvoice)): ?>

                                    <a id="process" href="<?php echo e(route('printinvoice',['type'=>$JournalType,'invoice'=>$batch])); ?>" style="float: right; margin-top: -5px;" class="btn btn-success btn-icon-split">
                                        <span class="icon text-white-50">
                                            <i class="fas fa-check"></i>
                                        </span>
                                        <span class="text">Process</span>
                                    </a>
                                    <?php endif; ?>
                                </div>
                                <div class="card-body">
                                <div class="table-responsive">
                                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0" style="font-size: 13px;">
                                    <thead>
                                        <tr>

                                        <th style="padding: 4px;">Entry Date</th>
                                            <th style="padding: 4px;">Description</th>
                                            <th style="padding: 4px;">Account</th>
                                            <th style="padding: 4px;">Reference</th>
                                            <th style="padding: 4px;">Qty</th>
                                            <th style="padding: 4px;">Price</th>
                                            <th style="padding: 4px;">Disc %</th>
                                            <th style="padding: 4px;">Tax %</th>
                                            <th style="padding: 4px;">Tax Amt</th>
                                            <th style="padding: 4px;">Total</th>
                                            <th style="padding: 4px;">Action</th>
                                        </tr>
                                    </thead>
                                    <tfoot>
                                        <tr>
                                           
                                        <th style="padding: 4px;">Entry Date</th>
                                        <th style="padding: 4px;">Description</th>
                                        <th style="padding: 4px;">Account</th>
                                        <th style="padding: 4px;">Reference</th>
                                        <th style="padding: 4px;">Qty</th>
                                        <th style="padding: 4px;">Price</th>
                                        <th style="padding: 4px;">Disc %</th>
                                        <th style="padding: 4px;">Tax %</th>
                                        <th style="padding: 4px;">Tax Amt</th>
                                        <th style="padding: 4px;">Total</th>
                                        <th style="padding: 4px;">Action</th>

                                        </tr>
                                    </tfoot>
                                    <tbody>    
                                      
                                    <?php $__currentLoopData = $Jts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $Jt): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                        
                                                <td><?php echo e($Jt->EntryDate); ?></td>
                                                <td><?php echo e($Jt->Narration); ?></td>
                                                <?php
                                                 $contractCode = $Jt->ContraCode;
                                                 if (!empty($Jt->ContraSubCode)) {
                                                 $contractCode .= '/' . $Jt->ContraSubCode;
                                                 }
                                                 ?>
                                                <td><?php echo e($contractCode); ?></td>
                                                <td><?php echo e($Jt->Refference); ?></td> 
                                                <td><?php echo e(number_format($Jt->Qnty, 2)); ?></td>
                                                <td><?php echo e(number_format($Jt->Price * $Jt->Rate, 2)); ?></td>
                                                <td><?php echo e(number_format((($Jt->Price * ($Jt->Discount / 100)) * $Jt->Qnty) * $Jt->Rate, 2)); ?></td>
                                                <td><?php echo e(number_format($Jt->Tax, 2)); ?></td>
                                                <td><?php echo e(number_format(($Jt->Qnty * ($Jt->Price - ($Jt->Price * ($Jt->Discount / 100)))) * ($Jt->Tax / 100) * $Jt->Rate, 2)); ?></td>
                                                <td><?php echo e(number_format(($Jt->Qnty * $Jt->Price) * $Jt->Rate, 2)); ?></td>

                                                <td style="justify-content: center; align-items: center; ">
                                                    
                                                    <a href=""  class="btn btn-primary btn-circle" style="height: 25px; width: 15px;"  onclick="editAccountType(event,'<?php echo e($Jt->ID); ?>', '<?php echo e($Jt->AccSubCode); ?>', '<?php echo e($Jt->Narration); ?>', '<?php echo e($Jt->Refference); ?>','<?php echo e($Jt->Price); ?>',   '<?php echo e($contractCode); ?>', '<?php echo e($Jt->Qnty); ?>', '<?php echo e($Jt->Discount); ?>',  '<?php echo e($Jt->TaxID.':'.$Jt->Tax); ?>','<?php echo e($Jt->Currency); ?>')">
                                                    <i class="fas fa-edit" style="font-size: 0.75em;"></i>
                                                    </a>
                                                    <a href="<?php echo e(route('deleteinvoice', ['ID' => $Jt->ID,'type'=>$JournalType])); ?>" style="height: 25px; width: 15px;"  class="btn btn-danger btn-circle" onclick="return confirmDelete('<?php echo e($Jt->Narration .' => '.$Jt->Refference); ?>');">
                                                        <i class="fas fa-trash" style="font-size: 0.75em;"></i>
                                                    </a>
                                                </td>
                                                
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>

                                <div style="margin-top: 20px; font-weight: bold; text-align: right;">
                                    <div style="display: flex; justify-content: flex-end;">
                                        <div style="text-align: right; margin-right: 10px;">
                                            <p>Total (Exc):</p>
                                            <p>Total (Tax):</p>
                                            <p>Total (Dis):</p>
                                            <p>Total (Inc):</p>
                                        </div>
                                        <div style="text-align: left;">
                                            <p><?php echo e($symbol.' '.number_format($totalExcludingTax, 2)); ?></p>
                                            <p><?php echo e($symbol.' '.number_format($totalTaxAmount, 2)); ?></p>
                                            <p><?php echo e($symbol.' '.number_format($totalDiscounts, 2)); ?></p>
                                            <p><?php echo e($symbol.' '.number_format($totalIncludingTax, 2)); ?></p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                                
                        </div>
                            
                    </div>


                           

                        
                </div>

                        
                        
            </div>

                        <script>
                             function editAccountType(event,id, account, narr, reff, price, gl, qty, disc,tax,Currency) 
                             {
                                event.preventDefault();
                                document.getElementById('accountId').value = id;
                                document.getElementById('account').value = account;
                                document.getElementById('narr').value = narr;
                                document.getElementById('reff').value = reff;
                                document.getElementById('price').value = price;
                                document.getElementById('gl').value = gl;
                                document.getElementById('qty').value = qty;
                                document.getElementById('disc').value = disc;
                                document.getElementById('tax').value = tax;
                                document.getElementById('curr').value = Currency;
                                document.getElementById('formHeader').innerText = 'Edit Invoice';
                                document.getElementById('submitButton').value = 'Edit';
                                document.getElementById('accountTypeForm').action = '<?php echo e(route("edittransaction")); ?>';
                            }
                
                            function refreshAccountType(id, account, narr, reff, price, gl, qty, disc,tax,Currency) 
                            {
                                document.getElementById('accountId').value = id;
                                document.getElementById('account').value = account;
                                document.getElementById('narr').value = narr;
                                document.getElementById('reff').value = reff;
                                document.getElementById('price').value = price;
                                document.getElementById('gl').value = gl;
                                document.getElementById('qty').value = qty;
                                document.getElementById('disc').value = disc;
                                document.getElementById('tax').value = tax;
                                document.getElementById('curr').value = Currency;
                                document.getElementById('formHeader').innerText = 'Process Invoice';
                                document.getElementById('submitButton').value = 'Save';
                                document.getElementById('accountTypeForm').action = '<?php echo e(route("savetransaction")); ?>';
                                hideMessages();
                            
                            }

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

                          

                            function preventRemoval(event) {
                                const input = event.target;
                                if (input.selectionStart <= 3 && (event.key === 'Backspace' || event.key === 'Delete')) {
                                    event.preventDefault();
                                }
                            }

                            // Ensure the input starts with SUP when the page loads
                            document.addEventListener('DOMContentLoaded', (event) => {
                                const batchInput = document.getElementById('batch');
                                enforcePrefix(batchInput);
                            });

                            function enforcePrefixAndUpdateURL(input) {
                          
                            updateURL(input.value);
                        }

                        function updateURL(batchValue) {
                            const type = "<?php echo e($JournalType); ?>"; // Ensure $JournalType is available in the Blade template
                            const url = `<?php echo e(route('printinvoice', ['type' => ':type', 'invoice' => ':batch'])); ?>`.replace(':type', type).replace(':batch', batchValue);
                            document.getElementById('process').href = url;
                        }

                        // Ensure the input starts with SUP when the page loads
                        document.addEventListener('DOMContentLoaded', (event) => {
                            const batchInput = document.getElementById('batch');
                          
                            updateURL(batchInput.value);
                        });


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