Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/public_html/public/themes/admin/assets/admin/invoices/ |
/**
* Created by Concept24Online
*/
var Proforma = function () {
var CSRF_TOKEN = $('input[name="_token"]').val();
var handleFormElements = function(){
if ($('.select2').length>0)
$('.select2').select2();
if ($('.select2filter').length>0)
$(".select2filter").select2({
placeholder: 'Status'
});
$('.date-picker').datepicker({
orientation: "left",
autoclose: true,
format: 'dd-mm-yyyy',
});
if ($('.wysihtml5').size() > 0) {
$('.wysihtml5').wysihtml5({
"stylesheets": ["../../assets/global/plugins/bootstrap-wysihtml5/wysiwyg-color.css"]
});
}
};
var handleSettings = function(){
if ($("#invoice_settings").length>0){
$("#modal_sett_error").hide();
$("#invoice_settings").modal({ keyboard: false });
}
$("#form_inv_sett").submit(function(e){
e.preventDefault();
var url = $(this).attr('action');
$.ajax({
url: url,
type: 'post',
dataType: 'json',
data: $(this).serialize(),
beforeSend : function(){
$("#modal_sett_error").text('');
$("#modal_sett_error").hide();
},
error: function(data) {
var response = jQuery.parseJSON(data.responseText);
$("#modal_sett_error").text('');
$.each(response,function(index,value){
$("#modal_sett_error").append(value[0]);
});
$("#modal_sett_error").show();
},
success: function(data) {
$("#modal_sett_error").hide();
window.location.reload(true);
}
});
})
};
var handleInvoice = function(){
var $company = $("#company");
var $contract = $("#contract");
var $ccy = $("#currency");
var $in_ccy = $("#display_currency");
var $invoice_date = $("#invoice_date");
var $invoice_duedate = $("#invoice_duedate");
var $inv_exchange_rate = $("#inv_exchange_rate");
var $exchange_rate = $(".exchange_rate");
var $tax = $("#tax");
var $locale = $("#locale");
var $col_ex_rate = $('.col_ex_rate');
var $top_ex_rate = $('.top_ex_rate');
//show/hide element on page load
if ($ccy.val()>0 && $in_ccy.val()==0)
$col_ex_rate.hide();
if (($in_ccy.val()==0 && parseFloat($inv_exchange_rate.val())==1) || ($ccy.val()==$in_ccy.val()) ){
$top_ex_rate.hide();
$col_ex_rate.hide();
}
//end show/hide element on page load
//select company
$company.change(function(){
var el = $(this);
if ($(this).val()==0){
$contract.find('option').remove();
$contract.attr('disabled','disabled');
return;
}
$.ajax({
url: "selectcompany",
type: 'get',
dataType: 'json',
data: {_token: CSRF_TOKEN,'company':el.val()},
beforeSend: function() {
$contract.find('option').remove();
},
complete: function() {},
success: function(data) {
$contract.find('option').remove();
$contract.removeAttr('disabled');
$.each(data, function(key, value) {
$('<option>').val(key).text(value).appendTo($contract);
});
sortSelectOptionByText($contract);
}
});
});
//end select company
//select contract
$contract.change(function(){
var el = $(this);
if ($(this).val()==0){
return;
}
$.ajax({
url: "selectcontract",
type: 'get',
dataType: 'json',
data: {_token: CSRF_TOKEN,'contract':el.val(),'date':$invoice_date.val()},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
$invoice_duedate.val(data.due_date);
$ccy.val(data.currency_id).attr('selected','selected');
$in_ccy.val(data.display_currency_id).attr('selected','selected');
$inv_exchange_rate.val(data.exchange_rate);
$exchange_rate.val(data.exchange_rate);
remove_cart_contents();
//update_cart_ex_rate($inv_exchange_rate.val());
}
});
});
//end select contract
//change invoice date
$("#invoice_date").datepicker().on('changeDate', function(e) {
var $new_date = e.format('dd-mm-yyyy');
change_date($new_date);
});
function change_date($new_date){
$.ajax({
url: "selectinvoicedate",
type: 'get',
dataType: 'json',
data: {_token: CSRF_TOKEN,'contract':$contract.val(),'date':$new_date,'currency':$ccy.val()},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
$invoice_duedate.val(data.due_date);
$ccy.val(data.currency_id).attr('selected','selected');
$inv_exchange_rate.val(data.exchange_rate);
}
});
}
//end change date
//change currency
$ccy.change(function(){
var el = $(this);
if ($(this).val()==0){
return;
}
$.ajax({
url: "selectccy",
type: 'get',
dataType: 'json',
data: {_token: CSRF_TOKEN,'contract':$contract.val(),'date':$invoice_date.val(),'currency':el.val()},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
$in_ccy.val(data.display_currency_id).attr('selected','selected');
$inv_exchange_rate.val(data.exchange_rate);
if (data.is_local==1){
$('.top_ex_rate').hide();
}
else
$('.top_ex_rate').show();
if (data.exchange_rate<=1){
$(".col_ex_rate" ).hide();
remove_cart_contents();
}
else
{
$(".col_ex_rate" ).show();
remove_cart_contents();
}
}
});
});
//end change currency
//change display currency
$in_ccy.change(function() {
var el = $(this);
if (el.val()==0) {
$(".col_ex_rate" ).hide();
}
else{
$(".col_ex_rate" ).show();
}
//empty cart
remove_cart_contents();
});
//end display in ccy
//change locale
$locale.change(function() {
var el = $(this);
$.ajax({
url: "proformachangelocale",
type: 'post',
dataType: 'html',
data: {_token: CSRF_TOKEN,'locale':$locale.val()},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
display_cart();
}
});
//empty cart
});
//end locale
//add new item
$('#add_item').click(function(){
var $item = $("#new_item");
$item.closest('.row').removeClass('alert-danger').removeClass('alert-success').removeClass('alert');
if ($item.val()==0){
$item.closest('.row').addClass('alert alert-danger');
return;
}
$.ajax({
url: "proformacart/add",
type: 'post',
dataType: 'json',
data: {_token: CSRF_TOKEN,'id':$item.val(),'tax_id':$tax.val(),'exchange_rate':$inv_exchange_rate.val(),'currency_id':$ccy.val(),'in_ccy_id':$in_ccy.val()},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
display_cart();
}
});
});
//end add new item
//update item
$(document).on('blur', '.item_update',function(event){
var $item = $(this);
var $item_id = $item.attr('id');
if ($item_id==0){
return;
}
$update=1;
if ($item.attr('name').indexOf('description') >-1 || $item.attr('name').indexOf('um')>-1 || $item.attr('name').indexOf('name_trans')>-1)
$update=0;
update_cart_pos($item_id,$update);
});
$(document).on('paste', '.item_update', function(e)
{
var $item = $(this);
var $item_id = $item.attr('id');
if ($item_id==0){
return;
}
$update=1;
if ($item.attr('name').indexOf('description') >-1 || $item.attr('name').indexOf('um')>-1 || $item.attr('name').indexOf('name_trans')>-1)
$update=0;
$item.text($(e.currentTarget).val());
update_cart_pos($item_id,$update);
});
//end update item
/**
* Update cart position
* @param $item_id
*/
function update_cart_pos($item_id,$update)
{
var name_trans = $("#item_"+$item_id).find('input[name="name_trans"]').val();
var desc = $("#item_"+$item_id).find('input[name="description"]').val();
var desc_trans = $("#item_"+$item_id).find('input[name="description_trans"]').val();
var um = $("#item_"+$item_id).find('input[name="um"]').val();
var um_trans = $("#item_"+$item_id).find('input[name="um_trans"]').val();
var qty = $("#item_"+$item_id).find('input[name="quantity"]').val();
var price = $("#item_"+$item_id).find('input[name="price"]').val();
var ex_rate = $("#item_"+$item_id).find('input[name="exchange_rate"]').val();
$.ajax({
url: "proformacart/edit",
type: 'post',
dataType: 'json',
data: {
_token: CSRF_TOKEN,
'id':$item_id,
'name_trans':name_trans,
'desc':desc,
'desc_trans':desc_trans,
'um':um,
'um_trans':um_trans,
'price':price,
'quantity':qty,
'ex_rate':ex_rate,
},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
if ($update==1)
display_cart();
}
});
}
//end method update cart position
/**
* Update cart items with exchange rate
* @param $value
*/
function update_cart_ex_rate($value)
{
$.ajax({
url: "proformacart/update_field_value",
type: 'post',
dataType: 'json',
data: {
_token: CSRF_TOKEN,
'field':'exchange_rate',
'value':$value,
},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
display_cart();
}
});
} //end methoid update cart exchange rate
/**
* Remove all cart content
*/
function remove_cart_contents()
{
$.ajax({
url: "proformacart/clear",
type: 'post',
dataType: 'json',
data: {_token: CSRF_TOKEN},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
display_cart();
}
});
}
//delete item
$(document).on("click", '.del_item', function(event) {
var $item = $(this);
var $item_id = $item.attr('id');
if ($item_id==0){
return;
}
$.ajax({
url: "proformacart/delete",
type: 'post',
dataType: 'json',
data: {_token: CSRF_TOKEN,'id':$item_id},
beforeSend: function() {
},
complete: function() {},
success: function(data) {
$("#item_"+$item_id).remove();
display_cart();
}
});
});
//end delete item
//display cart contents
function display_cart()
{
//get contents with ajax request
$.ajax({
url: "proformacart/contents",
type: 'get',
dataType: 'json',
complete: function() {},
success: function(data) {
var $el = $("#invoice_contents tbody");
$el.html(data.html);
}
});
}
//end display cart contents
};
var handlePayments = function(){
$(document).on('click', '.add_payment',function(event) {
var $item = $(this);
var $item_id = $item.attr('invoice_id');
var $amount = $item.attr('payment-amount');
var $date = $item.attr('payment-date');
console.log($amount+'|'+$date);
if ($item_id == 0) {
return;
}
$("#modal_sett_error").text('');
$("#modal_sett_error").hide();
$("#add_payment_modal").find('input[name="proforma_id"]').val($item_id);
$("#add_payment_modal").find('input[name="amount"]').val($amount);
$("#add_payment_modal").find('input[name="payment_date"]').val($date);
$("#add_payment_modal").modal({ keyboard: false });
});
if ($("#add_payment_modal").length>0){
$("#modal_sett_error").hide();
}
$("#cancel_add_payment").click(function(){
$("#add_payment_modal").modal('hide');
$("#add_payment_modal").find('input[name="proforma_id"]').val(0);
$("#modal_sett_error").text('');
$("#modal_sett_error").hide();
});
$("#form_add_payment").submit(function(e){
e.preventDefault();
var url = $(this).attr('action');
$.ajax({
url: url,
type: 'post',
dataType: 'json',
data: $(this).serialize(),
beforeSend : function(){
$("#modal_sett_error").text('');
$("#modal_sett_error").hide();
},
error: function(data) {
var response = jQuery.parseJSON(data.responseText);
$("#modal_sett_error").text('');
$.each(response,function(index,value){
$("#modal_sett_error").append("<div>"+value[0]+"</div>");
});
$("#modal_sett_error").show();
},
success: function(data) {
$("#modal_sett_error").hide();
//$("#add_payment_modal").find('input[name="invoice_id"]').val(0);
window.location.reload(true);
}
});
})
/*display payments modal*/
$(document).on('click', '.openmodal',function(event) {
var $target = $(this).attr('data-target');
$("#"+$target).modal();
});
};
return {
//main function to initiate the module
init: function () {
handleFormElements();
handleInvoice();
handleSettings();
handlePayments();
}
};
}();