| Server IP : 14.225.204.176 / Your IP : 216.73.216.6 Web Server : nginx/1.24.0 System : Linux nodejs-ybgk 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024 x86_64 User : root ( 0) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/php/thanhphuong/resources/views/return_purchase/ |
Upload File : |
@extends('layout.main') @section('content')
@if(session()->has('not_permitted'))
<div class="alert alert-danger alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>{{ session()->get('not_permitted') }}</div>
@endif
<section class="forms">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header d-flex align-items-center">
<h4>{{trans('file.Import Lend')}}</h4>
</div>
<div class="card-body">
<p class="italic"><small>{{trans('file.The field labels marked with * are required input fields')}}.</small></p>
{!! Form::open(['route' => 'return-purchase.store', 'method' => 'post', 'files' => true, 'class' => 'payment-form']) !!}
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>{{trans('file.Warehouse')}} *</label>
<br>
<select required name="warehouse_id" id="warehouse_id" class="form-control" style="width: 100%;">
<option></option>
@foreach($lims_warehouse_list as $warehouse)
<option value="{{$warehouse->id}}">{{$warehouse->name}}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>{{trans('file.Inventory Lend Voucher')}}</label>
<br>
<input type="text" name="inventory_receiving_voucher" class="form-control"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>{{trans('file.Supplier')}}</label>
<br>
<select name="supplier_id" id="supplier_id" class="form-control-select2" style="width: 100%;">
<option></option>
@foreach($lims_supplier_list as $supplier)
<option value="{{$supplier->id}}">{{$supplier->name .' ('. $supplier->company_name .')'}}</option>
@endforeach
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>{{trans('file.Lend Date')}} *</label>
<input type="text" name="updated_at" id="purchase_date" class="form-control" title="{{trans('file.This field is required')}}" required />
<span class="validation-msg"></span>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>{{trans('file.Lend Status')}}</label>
<select name="status" class="form-control">
<option value="1">{{trans('file.Recieved')}}</option>
<option value="2">{{trans('file.Partial')}}</option>
<option value="3">{{trans('file.Pending')}}</option>
<option value="4">{{trans('file.Ordered')}}</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>{{trans('file.Attach Document')}}</label> <i class="dripicons-question" data-toggle="tooltip" title="Only jpg, jpeg, png, gif, pdf, csv, docx, xlsx and txt file is supported"></i>
<input type="file" name="document" class="form-control" >
@if($errors->has('extension'))
<span>
<strong>{{ $errors->first('extension') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>{{trans('file.Currency')}}</label>
<br>
<select name="currency_id" id="select-field-currency" class="form-control" style="width: 100%;">
<option></option>
@foreach($lims_currency_list as $currency)
<option value="{{$currency->id}}">{{$currency->code}}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label> {{trans('file.Exchange Rate')}} </label>
<input type="number" name="exchange_rate_amount" class="form-control" value='0' step="any"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>{{trans('file.Content')}}</label>
<textarea name="note" class="form-control" rows="1"></textarea>
</div>
</div>
<div class="col-md-12 mt-3">
<label>{{trans('file.Select Product')}}</label>
<div class="search-box input-group">
<button class="btn btn-secondary"><i class="fa fa-barcode"></i></button>
<input type="text" name="product_code_name" id="lims_productCodeSearch" placeholder="Please type product code and select..." class="form-control" />
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-12">
<h5>{{trans('file.Product Lend Table')}} *</h5>
<div class="table-responsive mt-3">
<table id="myTable" class="table table-hover order-list">
<thead>
<tr>
<th>{{trans('file.name')}}</th>
<th>{{trans('file.Code')}}</th>
<th>{{trans('file.Quantity')}}</th>
<th>{{trans('file.Currency')}}</th>
<th class="recieved-product-qty d-none">{{trans('file.Recieved')}}</th>
<th>{{trans('file.Unit Cost')}}</th>
<th>{{trans('file.Total Cost')}}</th>
<th>{{trans('file.Tax')}} VAT</th>
<th>{{trans('file.Tax Import')}}</th>
<th>{{trans('file.Allocation Costs')}}</th>
<th>{{trans('file.Subtotal')}}</th>
<th>{{trans('file.Lot Number')}}</th>
<th>{{trans('file.Serial Number')}}</th>
<th>{{trans('file.Batch Number')}}</th>
<th>{{trans('file.Made in')}}</th>
<th>{{trans('file.Manufacturing Date')}}</th>
<th>{{trans('file.Expiry Date')}}</th>
<th>{{trans('file.Manufacturer')}}</th>
<th>{{trans('file.Manufacturer Address')}}</th>
<th>{{trans('file.Invoice Number')}}</th>
<th>{{trans('file.Invoice Date')}}</th>
<th>{{trans('file.OC Number')}}</th>
<th>{{trans('file.TR Number')}}</th>
<th><i class="dripicons-trash"></i></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot class="tfoot active">
<th colspan="2">{{trans('file.Total')}}</th>
<th id="total-qty">0</th>
<th class="recieved-product-qty d-none"></th>
<th></th>
<th></th>
<th></th>
<th id="total-tax">0</th>
<th id="total-tax-import">0</th>
<th></th>
<th id="total" colspan="10">0</th>
</tfoot>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<input type="hidden" name="total_qty" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="hidden" name="total_currency_cost" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="hidden" name="total_discount" value="0" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="hidden" name="total_tax" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="hidden" name="total_tax_import" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="hidden" name="total_cost" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="hidden" name="item" />
<input type="hidden" name="order_tax" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="hidden" name="grand_total" />
<input type="hidden" name="paid_amount" value="0" />
<input type="hidden" name="payment_status" value="1" />
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-md-3">
<div class="form-group">
<label>{{trans('file.Lend Tax')}}</label>
<select class="form-control" name="order_tax_rate">
<option value="0">{{trans('file.No Tax')}}</option>
@foreach($lims_tax_list as $tax)
<option value="{{$tax->rate}}">{{$tax->name}}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>
{{trans('file.Discount')}}
</label>
<input type="number" name="order_discount" value="0" class="form-control" step="any" />
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>
{{trans('file.Shipping Cost')}}
</label>
<input type="number" name="shipping_cost" value="0" class="form-control" step="any" />
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>
{{trans('file.Total Allocation Costs')}}
</label>
<input type="number" name="total_allocation_cost" value="0" class="form-control" step="any" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>{{trans('file.Note')}}</label>
<textarea rows="5" class="form-control" name="note"></textarea>
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" id="submit-btn">{{trans('file.submit')}}</button>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<table class="table table-bordered table-condensed totals">
<td><strong>{{trans('file.Items')}}</strong>
<span class="pull-right" id="item">0</span>
</td>
<td><strong>{{trans('file.Total')}}</strong>
<span class="pull-right" id="subtotal">0</span>
</td>
<td><strong>{{trans('file.Lend Tax')}}</strong>
<span class="pull-right" id="order_tax">0</span>
</td>
<td><strong>{{trans('file.Discount')}}</strong>
<span class="pull-right" id="order_discount">0</span>
</td>
<td><strong>{{trans('file.Shipping Cost')}}</strong>
<span class="pull-right" id="shipping_cost">0</span>
</td>
<td><strong>{{trans('file.grand total')}}</strong>
<span class="pull-right" id="grand_total">0</span>
</td>
</table>
</div>
<div id="editModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
<div role="document" class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 id="modal-header" class="modal-title"></h5>
<button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true"><i class="dripicons-cross"></i></span></button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label>{{trans('file.Quantity')}}</label>
<input type="number" name="edit_qty" class="form-control" step="any">
</div>
<div class="form-group">
<label>{{trans('file.Unit Cost')}}</label>
<input type="number" name="edit_unit_cost" class="form-control" step="any">
</div>
<div class="form-group">
<label>{{trans('file.Product Unit')}}</label>
<select name="edit_unit" class="form-control selectpicker">
</select>
</div>
<button type="button" name="update_btn" class="btn btn-primary">{{trans('file.update')}}</button>
</form>
</div>
</div>
</div>
</div>
</section>
<script type="text/javascript">
$("ul#inventory").siblings('a').attr('aria-expanded','true');
$("ul#inventory").addClass("show");
$("ul#return").siblings('a').attr('aria-expanded','true');
$("ul#return").addClass("show");
$("ul#return #purchase-return-menu").addClass("active");
$('#supplier_id').select2({
placeholder: "Select supplier..."
});
$('#warehouse_id').select2({
placeholder: "Select warehouse..."
});
$('#select-field-currency').select2({
placeholder: "Select currency..."
});
$( "span.selection" ).css( "width", "100%" );
$( ".select2-container .select2-selection--single" ).css({"height":"38px", "padding": "4px 0 6px" });
$( ".select2-selection__arrow" ).css( "top", "5px" );
$( ".select2-container--default .select2-selection--single").css({"borderColor": "#e4e6fc", "backgroundColor": "#fdfdff"});
$( ".select2-selection__placeholder").css({"fontSize": "14px"});
// array data depend on warehouse
var lims_product_array = [];
var product_code = [];
var product_name = [];
var product_qty = [];
// array data with selection
var product_cost = [];
var tax_rate = [];
var tax_name = [];
var tax_method = [];
var unit_name = [];
var unit_operator = [];
var unit_operation_value = [];
// temporary array
var temp_unit_name = [];
var temp_unit_operator = [];
var temp_unit_operation_value = [];
var currency_exchange_rate;
var currency_code;
var tax_import = [];
var tax_VAT = [];
var rowindex;
var customer_group_rate;
var row_product_cost;
$('.selectpicker').selectpicker({
style: 'btn-link',
});
$('[data-toggle="tooltip"]').tooltip();
$('select[name="status"]').on('change', function () {
var status = parseInt($('select[name="status"]').val());
var currentRow = $('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')');
if (status === 2) {
$(".recieved-product-qty").removeClass("d-none");
$(".qty").each(function () {
rowindex = $(this).closest('tr').index();
currentRow.find('.recieved').val($(this).val());
});
} else if (status === 3 || status === 4) {
$(".recieved-product-qty").addClass("d-none");
$(".recieved").each(function () {
$(this).val(0);
});
} else {
$(".recieved-product-qty").addClass("d-none");
$(".qty").each(function () {
rowindex = $(this).closest('tr').index();
currentRow.find('.recieved').val($(this).val());
});
}
});
$('select[name="currency_id"]').on("change", function() {
var currency_id = $(this).val();
if (currency_id) {
$.get('getcurrency/' + currency_id, function(currency) {
currency_exchange_rate = currency.exchange_rate;
currency_code = currency.code;
$('input[name="exchange_rate_amount"]').val(currency_exchange_rate.toFixed(0));
});
}
});
$('input[name="exchange_rate_amount"]').on("change", function() {
var currency_value = $(this).val();
if (currency_value > 0) {
currency_exchange_rate = currency_value;
} else {
$('input[name="exchange_rate_amount"]').val(0)
alert("Exchange rate can't be less than 0");
}
});
$('#lims_productCodeSearch').on('input', function(){
var supplier_id = $('#supplier_id').val();
var warehouse_id = $('#warehouse_id').val();
var currency_id = $('#select-field-currency').val();
temp_data = $('#lims_productCodeSearch').val();
if(!warehouse_id){
$('#lims_productCodeSearch').val(temp_data.substring(0, temp_data.length - 1));
alert('Please select Warehouse!');
}
else if(!supplier_id){
$('#lims_productCodeSearch').val(temp_data.substring(0, temp_data.length - 1));
alert('Please select Supplier!');
}
else if(!currency_id){
$('#lims_productCodeSearch').val(temp_data.substring(0, temp_data.length - 1));
alert('Please select Currency!');
}
});
var lims_product_code = [
@foreach($lims_product_list_without_variant as $product)
<?php
$productArray[] = htmlspecialchars($product->code . ' (' . $product->name . ')');
?>
@endforeach
@foreach($lims_product_list_with_variant as $product)
<?php
$productArray[] = htmlspecialchars($product->item_code . ' (' . $product->name . ')');
?>
@endforeach
<?php
echo '"' . implode('","', $productArray) . '"';
?>
];
$('#lims_productCodeSearch').autocomplete({
source: function (request, response) {
var matcher = new RegExp(".?" + $.ui.autocomplete.escapeRegex(request.term), "i");
response($.grep(lims_product_code, function (item) {
return matcher.test(item);
}));
},
response: function (event, ui) {
if (ui.content.length == 1) {
var data = ui.content[0].value;
$(this).autocomplete("close");
productSearch(data);
}
},
select: function (event, ui) {
var data = ui.item.value;
productSearch(data);
}
});
// Change quantity
$("#myTable").on('input', '.qty', function () {
rowindex = $(this).closest('tr').index();
if (parseInt($(this).val()) < 1) {
$('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ') .qty').val(1);
alert("Quantity can't be less than 1");
}
checkQuantity($(this).val());
});
// Change tax import
$("#myTable").on('input', '.tax_import', function () {
rowindex = $(this).closest('tr').index();
var currentRow = $('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')');
var tax_import = parseInt(currentRow.find('.tax_import').val());
var purchase_qty = parseInt(currentRow.find('.qty').val());
if (parseFloat($(this).val()) < 0) {
currentRow.find('.tax_import').val(0);
alert("Fee purchase can't be less than 0");
}
checkTaxImport(purchase_qty, parseFloat($(this).val()));
});
// Change tax VAT
$("#myTable").on('input', '.tax_VAT', function () {
rowindex = $(this).closest('tr').index();
var currentRow = $('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')');
var tax = parseInt(currentRow.find('.tax_VAT').val());
var purchase_qty = parseInt(currentRow.find('.qty').val());
if (parseFloat($(this).val()) < 0) {
currentRow.find('.tax_VAT').val(0);
alert("Tax VAT can't be less than 0");
}
checkTaxVAT(purchase_qty, parseFloat($(this).val()));
});
$('#purchase_date').datepicker({
format: "{{$date_format->js_format ?? 'dd/mm/yyyy'}}",
autoclose: true,
todayHighlight: true
});
$('#purchase_date').datepicker({ format: "{{$date_format->js_format ?? 'dd/mm/yyyy'}}" }).datepicker('setDate', new Date());
$('#purchase_date').on("change", function(){
$(this).val();
});
//Delete product
$("table.order-list tbody").on("click", ".ibtnDel", function (event) {
rowindex = $(this).closest('tr').index();
product_cost.splice(rowindex, 1);
tax_import.splice(rowindex, 1);
tax_VAT.splice(rowindex, 1);
tax_rate.splice(rowindex, 1);
tax_name.splice(rowindex, 1);
tax_method.splice(rowindex, 1);
unit_name.splice(rowindex, 1);
unit_operator.splice(rowindex, 1);
unit_operation_value.splice(rowindex, 1);
$(this).closest("tr").remove();
calculateTotal();
});
//Edit product
$("table.order-list").on("click", ".edit-product", function () {
rowindex = $(this).closest('tr').index();
var currentRow = $('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')');
var row_product_name = currentRow.find('td:nth-child(1)').text();
var row_product_code = currentRow.find('td:nth-child(2)').text();
$('#modal-header').text(row_product_name + '(' + row_product_code + ')');
var qty = $(this).closest('tr').find('.qty').val();
$('input[name="edit_qty"]').val(qty);
unitConversion();
$('input[name="edit_unit_cost"]').val(row_product_cost.toFixed(0));
temp_unit_name = (unit_name[rowindex]).split(',');
temp_unit_name.pop();
temp_unit_operator = (unit_operator[rowindex]).split(',');
temp_unit_operator.pop();
temp_unit_operation_value = (unit_operation_value[rowindex]).split(',');
temp_unit_operation_value.pop();
$('select[name="edit_unit"]').empty();
$.each(temp_unit_name, function (key, value) {
$('select[name="edit_unit"]').append('<option value="' + key + '">' + value + '</option>');
});
$('.selectpicker').selectpicker('refresh');
});
//Update product
$('button[name="update_btn"]').on("click", function () {
var edit_qty = parseInt($('input[name="edit_qty"]').val());
var edit_unit_cost = parseFloat($('input[name="edit_unit_cost"]').val());
var currentRow = $('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')');
if (edit_qty < 1) {
$('input[name="edit_qty"]').val(1);
edit_qty = 1;
alert("Quantity can't be less than 1");
}
var row_unit_operator = unit_operator[rowindex].slice(0, unit_operator[rowindex].indexOf(","));
var row_unit_operation_value = unit_operation_value[rowindex].slice(0, unit_operation_value[rowindex].indexOf(","));
row_unit_operation_value = parseFloat(row_unit_operation_value);
if (row_unit_operator == '*') {
product_cost[rowindex] = $('input[name="edit_unit_cost"]').val() / row_unit_operation_value;
} else {
product_cost[rowindex] = $('input[name="edit_unit_cost"]').val() * row_unit_operation_value;
}
var position = $('select[name="edit_unit"]').val();
var temp_operator = temp_unit_operator[position];
var temp_operation_value = temp_unit_operation_value[position];
currentRow.find('.purchase-unit').val(temp_unit_name[position]);
temp_unit_name.splice(position, 1);
temp_unit_operator.splice(position, 1);
temp_unit_operation_value.splice(position, 1);
temp_unit_name.unshift($('select[name="edit_unit"] option:selected').text());
temp_unit_operator.unshift(temp_operator);
temp_unit_operation_value.unshift(temp_operation_value);
unit_name[rowindex] = temp_unit_name.toString() + ',';
unit_operator[rowindex] = temp_unit_operator.toString() + ',';
unit_operation_value[rowindex] = temp_unit_operation_value.toString() + ',';
checkQuantity(edit_qty);
});
function productSearch(data) {
$.ajax({
type: 'GET',
url: '{{route('product_purchase.search')}}',
data: {
data: data
},
success: function (data) {
$("input[name='product_code_name']").val('');
var newRow = $("<tr>");
var cols = '';
temp_unit_name = (data[6]).split(',');
cols += '<td>' + data[0] + '<button type="button" class="edit-product btn btn-link" data-toggle="modal" data-target="#editModal"> <i class="dripicons-document-edit"></i></button></td>';
cols += '<td>' + data[1] + '</td>';
cols += '<td><input type="number" class="form-control no-border qty" name="qty[]" value="1" step="any" required/></td>';
if ($('select[name="status"]').val() == 1)
cols += '<td class="recieved-product-qty d-none"><input type="number" class="form-control recieved" name="recieved[]" value="1" step="any"/></td>';
else if ($('select[name="status"]').val() == 2)
cols += '<td class="recieved-product-qty"><input type="number" class="form-control recieved" name="recieved[]" value="1" step="any"/></td>';
else
cols += '<td class="recieved-product-qty d-none"><input type="number" class="form-control recieved" name="recieved[]" value="0" step="any"/></td>';
cols += '<td class="currency_code">' + currency_code + '</td>';
cols += '<td class="net_unit_cost"></td>';
cols += '<td class="total_cost"></td>';
cols += '<td><input type="number" class="form-control no-border tax_VAT" name="tax[]" value="0" required/></td>';
cols += '<td><input type="number" class="form-control no-border tax_import" name="tax_import[]" value="0" required/></td>';
cols += '<td class="allocation_cost">0</td>';
cols += '<td class="sub-total"></td>';
cols += '<td><input type="text" class="form-control no-border" name="lot_number[]"/></td>';
cols += '<td><input type="text" class="form-control no-border" name="serial_number[]"/></td>';
cols += '<td><input type="text" class="form-control no-border" name="batch_number[]"/></td>';
cols += '<td><input type="text" class="form-control no-border" name="made_in[]"/></td>';
cols += '<td><input type="text" class="form-control no-border manufacturing_date" name="manufacturing_date[]"/></td>';
cols += '<td><input type="text" class="form-control no-border expiry_date" name="expiry_date[]"/></td>';
cols += '<td><input type="text" class="form-control no-border" name="manufacturer[]"/></td>';
cols += '<td><input type="text" class="form-control no-border" name="address_manufacturer[]"/></td>';
cols += '<td><input type="text" class="form-control no-border" name="invoice_number[]"/></td>';
cols += '<td><input type="text" class="form-control no-border invoice_date" name="invoice_date[]"/></td>';
cols += '<td><input type="text" class="form-control no-border" name="oc_number[]"/></td>';
cols += '<td><input type="text" class="form-control no-border" name="tr_number[]"/></td>';
cols += '<td><button type="button" class="ibtnDel btn btn-md btn-danger">{{trans("file.delete")}}</button></td>';
cols += '<input type="hidden" class="product-code" name="product_code[]" value="' + data[1] + '"/>';
cols += '<input type="hidden" class="product-id" name="product_id[]" value="' + data[9] + '"/>';
cols += '<input type="hidden" class="purchase-unit" name="purchase_unit[]" value="' + temp_unit_name[0] + '"/>';
cols += '<input type="hidden" class="net_unit_cost" name="net_unit_cost[]" />';
cols += '<input type="hidden" class="tax-rate" name="tax_rate[]" value="' + data[3] + '"/>';
cols += '<input type="hidden" class="discount" name="discount[]" value="0" />';
cols += '<input type="hidden" class="subtotal-value" name="subtotal[]" />';
cols += '<input type="hidden" class="allocation_cost-value" name="allocation_cost[]" />';
cols += '<input type="hidden" class="total_cost_unit" name="total_cost_unit[]" />';
newRow.append(cols);
$("table.order-list tbody").append(newRow);
$('.manufacturing_date').datepicker({
format: "{{$date_format->js_format ?? 'dd/mm/yyyy'}}",
autoclose: true,
todayHighlight: true
});
$('.expiry_date').datepicker({
format: "{{$date_format->js_format ?? 'dd/mm/yyyy'}}",
autoclose: true,
todayHighlight: true
});
$('.invoice_date').datepicker({
format: "{{$date_format->js_format ?? 'dd/mm/yyyy'}}",
autoclose: true,
todayHighlight: true
});
product_cost.push(parseFloat(data[2]));
tax_import.push('0');
tax_VAT.push('0');
tax_rate.push(parseFloat(data[3]));
tax_name.push(data[4]);
tax_method.push(data[5]);
unit_name.push(data[6]);
unit_operator.push(data[7]);
unit_operation_value.push(data[8]);
rowindex = newRow.index();
calculateRowProductData(1);
}
});
}
function checkQuantity(purchase_qty) {
var currentRow = $('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')');
var operator = unit_operator[rowindex].split(',');
var operation_value = unit_operation_value[rowindex].split(',');
if (operator[0] == '*')
total_qty = purchase_qty * operation_value[0];
else if (operator[0] == '/')
total_qty = purchase_qty / operation_value[0];
$('#editModal').modal('hide');
currentRow.find('.qty').val(purchase_qty);
var status = parseInt($('select[name="status"]').val());
if (status === 1 || status === 2)
currentRow.find('.recieved').val(purchase_qty);
calculateRowProductData(purchase_qty);
}
function checkTaxImport(purchase_qty, fee) {
tax_import[rowindex] = fee
checkQuantity(purchase_qty);
}
function checkTaxVAT(purchase_qty, taxVAT) {
tax_VAT[rowindex] = taxVAT;
checkQuantity(purchase_qty);
}
function calculateRowProductData(quantity) {
unitConversion();
var currentRow = $('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')');
var fee_import = parseFloat(tax_import[rowindex]);
var fee_VAT= parseFloat(tax_VAT[rowindex]);
var net_unit_cost = row_product_cost;
var total_cost_currency = net_unit_cost * quantity;
var sub_total = (total_cost_currency * currency_exchange_rate) + fee_import + fee_VAT;
currentRow.find('.net_unit_cost').text(net_unit_cost.toLocaleString('de-DE', { minimumFractionDigits: 2 })).val(net_unit_cost.toFixed(2));
currentRow.find('.total_cost').text(total_cost_currency.toLocaleString('de-DE', { minimumFractionDigits: 2 })).val(total_cost_currency.toFixed(2));
currentRow.find('.sub-total').text(sub_total.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
currentRow.find('.subtotal-value').val(sub_total.toFixed(0));
currentRow.find('.total_cost_unit').val(total_cost_currency.toFixed(2));
calculateTotal();
}
function calculateAllocation() {
$(".sub-total").each(function (index) {
var subtotal = parseFloat($(this).text().replace(/\./g, ''));
var allocation = parseFloat($('.allocation_cost').eq(index).text().replace(/\./g, ''))
var calc = subtotal + allocation
$('.sub-total').eq(index).text(calc.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('.subtotal-value').eq(index).val(calc.toFixed(0));
$('.allocation_cost-value').eq(index).val(allocation.toFixed(0));
});
calculateTotal();
}
function unitConversion() {
var row_unit_operator = unit_operator[rowindex].slice(0, unit_operator[rowindex].indexOf(","));
var row_unit_operation_value = unit_operation_value[rowindex].slice(0, unit_operation_value[rowindex].indexOf(","));
row_unit_operation_value = parseFloat(row_unit_operation_value);
if (row_unit_operator == '*') {
row_product_cost = product_cost[rowindex] * row_unit_operation_value;
} else {
row_product_cost = product_cost[rowindex] / row_unit_operation_value;
}
}
function calculateTotal() {
//Sum of quantity
var total_qty = 0;
$(".qty").each(function () {
if ($(this).val() == '') {
total_qty += 0;
} else {
total_qty += parseFloat($(this).val());
}
});
$("#total-qty").text(total_qty);
$('input[name="total_qty"]').val(total_qty);
//Sum of currency cost
var total_currency_cost = 0;
$(".total_cost").each(function () {
if ($(this).val() == '') {
total_currency_cost += 0;
} else {
total_currency_cost += parseFloat($(this).val());
}
});
$("#total-currency-cost").text(total_currency_cost.toLocaleString('de-DE', { minimumFractionDigits: 2 }));
$('input[name="total_currency_cost"]').val(total_currency_cost.toFixed(2));
//Sum of tax import
var total_tax_import = 0;
$(".tax_import").each(function () {
if ($(this).val() == '') {
total_tax_import += 0;
} else {
total_tax_import += parseFloat($(this).val());
}
});
$("#total-tax-import").text(total_tax_import.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('input[name="total_tax_import"]').val(total_tax_import.toFixed(0));
//Sum of tax
var total_tax_VAT = 0;
$(".tax_VAT").each(function () {
if ($(this).val() == '') {
total_tax_VAT += 0;
} else {
total_tax_VAT += parseFloat($(this).val());
}
});
$("#total-tax").text(total_tax_VAT.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('input[name="total_tax"]').val(total_tax_VAT.toFixed(0));
//Sum of subtotal
var total = 0;
$(".sub-total").each(function () {
total += parseFloat($(this).text().replace(/\./g, ''));
});
$("#total").text(total.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('input[name="total_cost"]').val(total.toFixed(0));
calculateGrandTotal();
}
function calculateGrandTotal() {
var item = $('table.order-list tbody tr:last').index();
var total_qty = parseFloat($('#total-qty').text().replace(/\./g, ''));
var subtotal = parseFloat($('#total').text().replace(/\./g, ''));
var order_tax = parseFloat($('select[name="order_tax_rate"]').val());
var order_discount = parseFloat($('input[name="order_discount"]').val());
var shipping_cost = parseFloat($('input[name="shipping_cost"]').val());
if (!order_discount) order_discount = 0;
if (!shipping_cost) shipping_cost = 0;
item = ++item + '(' + total_qty + ')';
order_tax = (subtotal - order_discount) * (order_tax / 100);
var grand_total = subtotal + order_tax + shipping_cost - order_discount;
$('#item').text(item);
$('input[name="item"]').val($('table.order-list tbody tr:last').index() + 1);
$('#subtotal').text(subtotal.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('#order_tax').text(order_tax.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('input[name="order_tax"]').val(order_tax.toFixed(0));
$('#order_discount').text(order_discount.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('#shipping_cost').text(shipping_cost.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('#grand_total').text(grand_total.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('input[name="grand_total"]').val(grand_total.toFixed(0));
}
$('input[name="total_allocation_cost"]').on("change", function() {
var total_allocation_cost = parseFloat($(this).val());
if( isNaN(total_allocation_cost) || total_allocation_cost < 0){
$('input[name="total_allocation_cost"]').val(0)
alert("Total allocation costs can't be less than 0");
total_allocation_cost = 0;
}
$(".sub-total").each(function (index) {
var total_sub = parseFloat($(this).text().replace(/\./g, ''));
var old_allocation_cost = parseFloat($('.allocation_cost').eq(index).text().replace(/\./g, ''));
var calc_sub = total_sub - old_allocation_cost
$('.allocation_cost').eq(index).text(0);
$(".sub-total").eq(index).text(calc_sub.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
$('input[name="subtotal"]').eq(index).val(calc_sub.toFixed(0));
$('input[name="allocation_cost"]').eq(index).val(0);
});
calculateAllocation()
var total_cost = parseFloat($('input[name="total_cost"]').val())
$(".sub-total").each(function (index) {
var total_sub = parseFloat($(this).text().replace(/\./g, ''));
var calc_sub = 0;
if(total_cost > 0){
calc_sub = (total_sub / total_cost) * total_allocation_cost
}
$('.allocation_cost').eq(index).text(calc_sub.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."));
});
calculateAllocation()
});
$('input[name="order_discount"]').on("input", function () {
calculateGrandTotal();
});
$('input[name="shipping_cost"]').on("input", function () {
calculateGrandTotal();
});
$('select[name="order_tax_rate"]').on("change", function () {
calculateGrandTotal();
});
$(window).keydown(function (e) {
if (e.which == 13) {
var $targ = $(e.target);
if (!$targ.is("textarea") && !$targ.is(":button,:submit")) {
var focusNext = false;
$(this).find(":input:visible:not([disabled],[readonly]), a").each(function () {
if (this === e.target) {
focusNext = true;
} else if (focusNext) {
$(this).focus();
return false;
}
});
return false;
}
}
});
$('#purchase-form').on('submit', function (e) {
var rownumber = $('table.order-list tbody tr:last').index();
if (rownumber < 0) {
alert("Please insert product to order table!")
e.preventDefault();
} else if ($('select[name="status"]').val() != 1) {
flag = 0;
$(".qty").each(function () {
rowindex = $(this).closest('tr').index();
quantity = $(this).val();
recieved = $('table.order-list tbody tr:nth-child(' + (rowindex + 1) + ')').find('.recieved').val();
if (quantity != recieved) {
flag = 1;
return false;
}
});
if (!flag) {
alert('Quantity and Recieved value is same! Please Change Purchase Status or Recieved value');
e.preventDefault();
}
}
});
</script>
@endsection