function withDecimal(n) {
    var nums = n.toString().split('.')
    var whole = convertNumberToWords(nums[0])
    if (nums.length == 2) {
        var fraction = convertNumberToWords(nums[1])
        return whole + 'and ' + fraction + ' Fils Only';
    } else {
        return whole;
    }
}

function PrintthisBillSalesCopy(Rowlen) {

    $('#DosPrint').html('');
    var Line = "";
    var Currency = $('#select_crncy option:selected').html()

    var AmountinWords = Currency + " " + convertNumberToWords($('#GrandTotal').val())
    var terms = ''

    var Space = '                                                                                            ';
    var Leftalign = '';
    var Break = '------------------------------------------------------------------------------'

    if ($('#txtmsg').val() == '') {
        terms = ($('#txtmsg').val() + Space).substring(0, 24)
    }
    else {
        terms = Space.substring(0, 24)
    }


    Line = "<tr><th></th></tr>";
    //Line += '<tr><td>' + String.fromCharCode(18) + "E" + '</td></tr>'; compressed font 
    //Line += '<tr><td>'+String.fromCharCode(15) + "E" +'</td></tr>';
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + ("Customer Details:-" + Space).substring(0, 30) + String.fromCharCode(27) + "E" + '    TAX INVOICE         ' + String.fromCharCode(27) + "F" + 'Invoice No:' + $('#txtBillSlNocopy').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + ($('#txtcustomer').val() + Space).substring(0, 30) + String.fromCharCode(27) + "E" + 'TRN:100375634100003     ' + String.fromCharCode(27) + "F" + 'Date      :' + $('#txtivdate').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + ($("#PhoneNo").val() + Space).substring(0, 30) + terms + 'S.Man     :' + $('#select_salesman option:selected').html().substring(0,12) + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'No  ChasisNo   Vechile Name                  Stock No Qty  Price    Amount' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
    var Adv = 0; var RowCo = Rowlen;

    for (var i = 1; i < Rowlen; i++) {
        var Id = parseInt(i);


        var ItemCode = $('#txtproduct' + Id).val(); var ItemName = $('#ProductDesc' + Id).val() + Space; var StockNo = $('#LotNo' + Id).val() + Space; var Qty = $('#txtquantity' + Id).val() + Space; var Unitprice = $('#txtrate' + Id).val() + Space; var Amount = $('#txtamnt' + Id).val() + Space;
        if (ItemCode != undefined) {
            var str = '', item = '';
            str = $('#txtproduct' + Id).val();
            item = str.substring(str.length - 6, str.length);
            ItemCode = item + Space;
            if (i > 9) {
                Line += '<tr><td>' + Leftalign + '</td><td>' + '' + i + '   ' + ItemCode.substring(0, 10) + ItemName.substring(0, 29) + " " + StockNo.substring(0, 10) + Qty.substring(0, 4) + Unitprice.substring(0, 9) + Amount.substring(0, 10) + '</td></tr>';
            }
            else {
                Line += '<tr><td>' + Leftalign + '</td><td>' + ' ' + i + '   ' + ItemCode.substring(0, 10) + ItemName.substring(0, 29) + " " + StockNo.substring(0, 10) + Qty.substring(0, 4) + Unitprice.substring(0, 9) + Amount.substring(0, 10) + '</td></tr>';
            }

            if (i == 7 || i == 13) {
                Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
                Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'


                Line += '<tr><td>' + Leftalign + '</td><td>' + ("Customer Details:-" + Space).substring(0, 30) + String.fromCharCode(27) + "E" + '    TAX INVOICE         ' + String.fromCharCode(27) + "F" + 'Invoice No  :' + $('#txtivdate').val() + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + ($('#txtcustomer').val() + Space).substring(0, 30) + String.fromCharCode(27) + "E" + 'TRN:100375634100003     ' + String.fromCharCode(27) + "F" + 'Date        :' + $('#txtivdate').val() + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + ($("#PhoneNo").val() + Space).substring(0, 30) + terms + 'S.Man     :' + $('#select_salesman option:selected').html() + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'No  ChasisNo   Vechile Name                  Stock No Qty  Price    Amount' + String.fromCharCode(27) + "F" + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
                RowCo = Rowlen - 7
            }



        }
        Adv += parseFloat($('#txtAdvance' + i).val() || 0)
    }

    for (var i = 0; i < 8 - RowCo; i++) {
        Line += '<tr><td>.</td></tr>';
    }
    Adv = Adv.toFixed(2)
    Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
    Leftalign = '                                                   ';
    var gndtotal = parseFloat($('#GrandTotal').val() || 0).toFixed(20);
    var Dis = parseFloat($('#TotalDiscount').text() || 0);
    gndtotal = (gndtotal - Dis - Adv).toFixed(2)


    var TotalLine1 = String.fromCharCode(27) + "E" + ' Total      :' + (Leftalign + $('#GrandTotal').val()).substr((Leftalign + $('#GrandTotal').val()).length - 10);
    var TotalLine2 = 'DISCOUNT   :' + (Leftalign + $('#TotalDiscount').val()).substr((Leftalign + $('#TotalDiscount').val()).length - 10) + '';
    var TotalLine3 = 'TAMOUNT    :' + (Leftalign + $('#TotalTaxable').val()).substr((Leftalign + $('#TotalTaxable').val()).length - 10) + '';
    var TotalLine4 = 'VAT 5%     :' + (Leftalign + $('#TotalTax').val()).substr((Leftalign + $('#TotalTax').val()).length - 10) + '';
    var TotalLine5 = 'ADVANCE    :' + (Leftalign + Adv).substr((Leftalign + Adv).length - 10) + '';
    var TotalLine6 = 'BALANCE ' + Currency.substr(0, 3) + ':' + (Leftalign + gndtotal).substr((Leftalign + gndtotal).length - 10) + '' + String.fromCharCode(27) + "E";
    var Spliter = '----------------------'

    Line += '<tr><td>' + (AmountinWords + ' Only' + Leftalign).substr(0, Leftalign.length - 1) + '</td><td>' + TotalLine1 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine2 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine3 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine4 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine5 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine6 + '</td></tr>'

    $('#DosPrint').append(Line);
    PrintDosPrint();

}
function PrintthisBillForFazal(Rowlen, flg) {

    var BillNo = '';
    if (flg == 'copy')
        BillNo = $('#txtBillSlNocopy').val();
    else if (flg == 'save')
        BillNo = $('#savedbillno').val(); 

    $('#DosPrintFazal').html('');
    var Line = "";
    var Currency = $('#select_crncy option:selected').html()
    var bal = 'Party TRN : '+$('#txtlpono').val();
   
  
    
    var AmountinWords = '    ' + convertNumberToWords($('#GrandTotal').val())
   
    var sspace = '               ';
    var Space = '                                                                                            ';
    var Leftalign = '';

    var spacebal = Space ;
    var strbal = spacebal.substring(spacebal.length - 27, spacebal.length);

    Line = "<tr><th></th></tr>";

    Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 18) + String.fromCharCode(27) + "E"  +($('#txtcustomer').val() + Space).substring(0, 82) + String.fromCharCode(27) + "F"  + '</td><td>' + String.fromCharCode(27) + "E" + BillNo + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr>' + Space + '</tr>'
    Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 11) + ($('#txtaddress').val() + Space).substring(0, 88) + '</td><td>' + String.fromCharCode(27) + "E" + $('#txtivdate').val() + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr>' + Space + '</tr>'
    Line += '<tr>' + Space + '</tr>'
    Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 1) + ('Chassis#  : ' + $('#ChassisNo').val() + Space).substring(0, 30) + '</td></tr>'
    Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 1) + ('Party TRN : ' + $('#txtlpono').val() + Space).substring(0, 30) + '</td></tr>'
    Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 50) + 'BAL : ' + ($('#OutStanding').text() + Space).substring(0, 70) + '</td></tr>'
    Line += '<tr>' + Space + '</tr>'
    Line += '<tr>' + Space + '</tr>'
  
    var RowCo = Rowlen;
   
    for (var i = 1; i < Rowlen; i++) {
        var Id = parseInt(i);


        var ItemCode = $('#txtproduct' + Id).val(); var ItemName = $('#ProductDesc' + Id).val(); var Location = $('#select_location' + Id + ' option:selected').html(); var Qty = $('#txtquantity' + Id).val(); var unit = $('#select_unit' + Id + ' option:selected').html() + '  '; var Unitprice = $('#txtrate' + Id).val(); var Amount =$('#txtamnt' + Id).val();
        if (ItemCode != undefined) {
            var spaceunit = Space + Unitprice;
            var strunit = spaceunit.substring(spaceunit.length - 22, spaceunit.length);

            var spaceamt = Space + Amount;
            var stramt = spaceamt.substring(spaceamt.length - 18, spaceamt.length);

            var str = '', item = '';
            str = $('#txtproduct' + Id).val();
            item = str.substring(str.length - 6, str.length);
          
            if (i > 9) {
               
                Line += '<tr><td>' + (Leftalign).substring(0, 7) + (Id + Space).substring(0, 9) + '</td><td>' + (ItemCode + Space).substring(0, 21) + '</td><td>' + (ItemName + Space).substring(0, 50) + '</td><td text-align="center">' + (Qty + sspace).substring(0, 5) + '</td><td align="right">' + strunit + '</td><td align="right">' + stramt + '</td></tr>';
            }
            else {
                Line += '<tr><td>' + (Leftalign).substring(0, 7) + (Id + Space).substring(0, 9) + '</td><td>' + (ItemCode + Space).substring(0, 21) + '</td><td>' + (ItemName + Space).substring(0, 50) + '</td><td text-align="center">' + (Qty + sspace).substring(0, 5) + '</td><td align="right">' + strunit + '</td><td align="right">' + stramt + '</td></tr>';
            }
            if (i % 28 == 0 && Rowlen > i+1) {

                for (var d = 0; d < 28; d++) {
                    Line += '<tr><td>.</td></tr>';
                }
                Line += '<tr>' + Space + '</tr>'
                Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 18)  +String.fromCharCode(27) + "E" + ($('#txtcustomer').val() + Space).substring(0, 82) + String.fromCharCode(27) + "F" + '</td><td>' + String.fromCharCode(27) + "E" + BillNo + String.fromCharCode(27) + "F" + '</td></tr>'
                Line += '<tr>' + Space + '</tr>'
                Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 11) + ($('#txtaddress').val() + Space).substring(0, 88) + '</td><td>' + String.fromCharCode(27) + "E" + $('#txtivdate').val() + String.fromCharCode(27) + "F" + '</td></tr>'
                Line += '<tr>' + Space + '</tr>'
                Line += '<tr>' + Space + '</tr>'
                Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 1) + ('Chassis#  : ' + $('#ChassisNo').val() + Space).substring(0, 30) + '</td></tr>'
                Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 1) + ('Party TRN : ' + $('#txtlpono').val() + Space).substring(0, 30) + '</td></tr>'
                Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space).substring(0, 50) + 'BAL : ' + ($('#OutStanding').text() + Space).substring(0, 70) + '</td></tr>'
                Line += '<tr>' + Space + '</tr>'
                Line += '<tr>' + Space + '</tr>'
             
                RowCo = Rowlen - 28

            }


        }
      
    }
   
    for (var i = 0; i < 31-RowCo; i++) {
        Line += '<tr><td>.</td></tr>';
    }
    
   
    var gndtotal = parseFloat($('#GrandTotal').val() || 0).toFixed(20);
    var Dis = parseFloat($('#TotalDiscount').text() || 0);
  
    var TotalLine5 = ($('#TotalTaxable').val()).substring(0, 22) ;
    var TotalLine4 = ($('#TotalTax').val()).substring(0, 22);
    var TotalLine1 = String.fromCharCode(27) + "E" + ($('#gndtotal').text()).substring(0, 22) + String.fromCharCode(27) + "F";

    Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space + Space).substring(0, 110) + TotalLine5 + '</td></tr>'
    Line += '<tr>' + Space + '</tr>'
    Line += '<tr><td>' + (Leftalign).substring(0, 7) + '</td><td>' + (Space + Space).substring(0, 110) + TotalLine4 + '</td></tr>'
    Line += '<tr>' + Space + '</tr>'
    Line += '<tr><td>' + (Leftalign).substring(0, 12) + '</td><td>' + (AmountinWords+ ' Only' +Space).substring(0, 110)+  TotalLine1 + '</td></tr>'
    Line += '<tr>' + Space + '</tr>'
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'


    
    $('#DosPrintFazal').append(Line);
    PrintDosPrintFazal();

}

function PrintthisBillSalesNew(Rowlen,flg) {

    var BillNo = '';
    if (flg == 'save')
    { BillNo = $('#savedbillno').val(); }
    else
    { BillNo = $('#txtBillSlNocopy').val(); }

    $('#DosPrintNew').html('');
    var Line = "";
    var Rowcount = 0;

    var AmountinWords = convertNumberToWords($('#GrandTotal').val())
    var terms = ''

    var Space = '                                                                                            ';
    var Space1 = '                         ';
    var Leftalign = '';
    var Break = '------------------------------------------------------------------------------'


    Line = "<tr><th></th></tr>";
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
    Line += '<tr><td>' + String.fromCharCode(27) + "E" + '</td><td>' + '       ' + (window.CompanySettingsArray.TRNNo + Space).substring(0, 30) + '                           ' + $('#txtlpono').val() + '</td></tr>'
    Line += '<tr><td>.</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + '                ' + ($('#txtcustomer').val() + Space).substring(0, 30) + '                  ' + BillNo + '</td></tr>'
    Line += '<tr><td>.</td><tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + '          ' + ($("#PhoneNo").val() + Space).substring(0, 30) + '                        ' + $('#txtivdate').val() + '</td></tr>'
    Line += '<tr><td>.</td></tr><tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + '         ' + ($("#txtaddress").val() + Space).substring(0, 30) + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    var Adv = 0; var RowCo = Rowlen;

    for (var i = 1; i < Rowlen; i++) {
        var Id = parseInt(i);



        var ItemCode = $('#txtproduct' + Id).val(); var ItemName = $('#ProductDesc' + Id).val() + Space; var Unit = $('#select_unit' + Id + ' option:selected').html() + Space; var Qty = $('#txtquantity' + Id).val() + Space; var Unitprice = Space + $('#txtrate' + Id).val(); var Amount = Space + $('#txtamnt' + Id).val();
        if (ItemCode != undefined) {
            var str = '', item = '';
            str = $('#txtproduct' + Id).val();
            item = str.substring(str.length - 10, str.length);
            ItemCode = item + Space;
            if (i > 9) {
                Line += '<tr><td>' + Leftalign + '</td><td>' + ' ' + i + '  ' + ItemCode.substring(0, 10) + ' ' + ItemName.substring(0, 31) + '  ' + Unit.substring(0, 4) + '   ' + Qty.substring(0, 4) + '' + Unitprice.substr(Unitprice.length - 8) + '  ' + Amount.substr(Amount.length - 8) + '</td></tr>';
            }
            else {
                Line += '<tr><td>' + Leftalign + '</td><td>' + '  ' + i + '  ' + ItemCode.substring(0, 10) + ' ' + ItemName.substring(0, 31) + '  ' + Unit.substring(0, 4) + '   ' + Qty.substring(0, 4) + '' + Unitprice.substr(Unitprice.length - 8) + '  ' + Amount.substr(Amount.length - 8) + '</td></tr>';
            }

            if (i%28==0) {
                //Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
                
                Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

                Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
                Line += '<tr><td>' + String.fromCharCode(27) + "E" + '</td><td>' + '       ' + (window.CompanySettingsArray.TRNNo + Space).substring(0, 30) + '                           ' + $('#txtlpono').val() + '</td></tr>'
                Line += '<tr><td>.</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + '                ' + ($('#txtcustomer').val() + Space).substring(0, 30) + '                  ' + BillNo + '</td></tr>'
                Line += '<tr><td>.</td><tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + '          ' + ($("#PhoneNo").val() + Space).substring(0, 30) + '                        ' + $('#txtivdate').val() + '</td></tr>'
                Line += '<tr><td>.</td></tr><tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + '         ' + ($("#txtaddress").val() + Space).substring(0, 30) + String.fromCharCode(27) + "F" + '</td></tr>'
                Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
                RowCo = Rowlen - 32;
            }

        }
        Adv += parseFloat($('#txtAdvance' + i).val() || 0)
    }

    for (var i = 0; i < 32 - RowCo; i++) {
        Line += '<tr><td>.</td></tr>';
    }


    //Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
    Leftalign = '              ';
    var gndtotal = parseFloat($('#GrandTotal').val() || 0).toFixed(20);
    var Dis = parseFloat($('#disc').text() || 0);

    var TotalLine1 = (Leftalign + $('#GrandTotal').val()).substr((Leftalign + $('#GrandTotal').val()).length - 10);
    var TotalLine2 = (Leftalign + $('#TotalTax').val()).substr((Leftalign + $('#TotalTax').val()).length - 10) + '';
    var TotalLine3 = (Leftalign + $('#disc').val()).substr((Leftalign + $('#disc').val()).length - 10) + '';
    var TotalLine4 = (Leftalign + $('#TotalTaxable').val()).substr((Leftalign + $('#TotalTaxable').val()).length - 10) + '';




    Line += '<tr><td>' + String.fromCharCode(27) + "E" + '</td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + '                                                     ' + TotalLine4 + '</td></tr>'
    Line += '<tr><td>' + (AmountinWords + 'Only.                                                      ').substring(0, 67) + '</td><td>' + '' + TotalLine2 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + '                                                     ' + TotalLine3 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + '                                                     ' + TotalLine1 + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td></tr>'; Line += '<tr><td>.</td></tr>'; Line += '<tr><td>.</td></tr>'; Line += '<tr><td>.</td></tr>';
    Line += '<tr><td>.</td></tr>'; Line += '<tr><td>.</td></tr>'; Line += '<tr><td>Powered By www.eumierp.com</td></tr>'; Line += '<tr><td>.</td></tr>';
    $('#DosPrintNew').append(Line);
    PrintDosPrintNew();

}



function PrintthisBillSalesReturnDotMatrix(Rowlen) {
  
    $('#DosPrintSR').html('');
    var Line = "";
    var Currency = $('#select_crncy option:selected').html()
    
    var AmountinWords = Currency + " " + convertNumberToWords($('#GrandTotal').val())
    var terms = ''

    var Space = '                                                                                            ';
    var Leftalign = '';
    var Break = '------------------------------------------------------------------------------'

    if ($('#txtmsg').val() == '') {
        terms = ($('#txtmsg').val() + Space).substring(0, 24)
    }
    else {
        terms = Space.substring(0, 24)
    }

    Line = "<tr><th></th></tr>";
    //Line += '<tr><td>' + String.fromCharCode(18) + "E" + '</td></tr>'; compressed font 
    //Line += '<tr><td>'+String.fromCharCode(15) + "E" +'</td></tr>';
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + ("Customer Details:-" + Space).substring(0, 30) + String.fromCharCode(27) + "E" + '    TAX INVOICE         ' + String.fromCharCode(27) + "F" + 'Invoice No  :' + $('#txtBillSlNocopy').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + ($('#txtcustomer').val() + Space).substring(0, 30) + String.fromCharCode(27) + "E" + 'TRN:100375634100003     ' + String.fromCharCode(27) + "F" + 'Date        :' + $('#txtivdate').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + ('' + Space).substring(0, 30) + terms + 'S.Man     :' + $('#select_salesman option:selected').html() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + ' No  ChasisNo   Vechile Name                Stock No Qty  Price   Amount' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
    var Adv = 0; var RowCo = Rowlen;
    for (var i = 1; i <= Rowlen; i++) {

        var Id = parseInt(i);


        var ItemCode = $('#txtproduct' + Id).val(); var ItemName = $('#ProductDesc' + Id).val() + Space; var StockNo = '' + Space; var Qty = $('#txtquantity' + Id).val() + Space; var Unitprice = $('#txtrate' + Id).val() + Space; var Amount = $('#txtamnt' + Id).val() + Space;

        if (ItemCode != undefined) {
            var str = '', item = '';
            str = $('#txtproduct' + Id).val();
            item = str.substring(str.length - 6, str.length);
            ItemCode = item + Space;
            if (i > 9) {
                Line += '<tr><td>' + Leftalign + '</td><td>' + ' ' + i + '   ' + ItemCode.substring(0, 10) + ItemName.substring(0, 25) + " " + StockNo.substring(0, 10) + Qty.substring(0, 4) + Unitprice.substring(0, 9) + Amount.substring(0, 10) + '</td></tr>';
            }
            else {
                Line += '<tr><td>' + Leftalign + '</td><td>' + '  ' + i + '   ' + ItemCode.substring(0, 10) + ItemName.substring(0, 25) + " " + StockNo.substring(0, 10) + Qty.substring(0, 4) + Unitprice.substring(0, 9) + Amount.substring(0, 10) + '</td></tr>';
            }

            if (i == 7 || i == 13) {
                Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
                Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'


                Line += '<tr><td>' + Leftalign + '</td><td>' + ("Customer Details:-" + Space).substring(0, 30) + String.fromCharCode(27) + "E" + '    TAX INVOICE         ' + String.fromCharCode(27) + "F" + 'Invoice No  :' + $('#txtivdate').val() + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + ($('#txtcustomer').val() + Space).substring(0, 30) + String.fromCharCode(27) + "E" + 'TRN:100375634100003     ' + String.fromCharCode(27) + "F" + 'Date        :' + $('#txtivdate').val() + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + ('' + Space).substring(0, 30) + terms + 'S.Man     :' + $('#select_salesman option:selected').html() + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + ' No  ChasisNo   Vechile Name                Stock No Qty  Price   Amount' + String.fromCharCode(27) + "F" + '</td></tr>'
                Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
                RowCo = Rowlen - 7
            }



        }
        Adv += parseFloat($('#txtAdvance' + i).val() || 0)
    }

    for (var i = 0; i < 8 - RowCo; i++) {
        Line += '<tr><td>.</td></tr>';
    }
    Adv = Adv.toFixed(2)
    Line += '<tr><td>' + Leftalign + '</td><td>' + Break + '</td></tr>'
    Leftalign = '                                                   ';
    var gndtotal = parseFloat($('#GrandTotal').val() || 0).toFixed(20);
    var Dis = parseFloat($('#TotalDiscount').text() || 0);
    gndtotal = (gndtotal - Dis - Adv).toFixed(2)


    var TotalLine1 = String.fromCharCode(27) + "E" + ' Total      :' + (Leftalign + $('#GrandTotal').val()).substr((Leftalign + $('#GrandTotal').val()).length - 10);
    var TotalLine2 = 'DISCOUNT   :' + (Leftalign + $('#TotalDiscount').val()).substr((Leftalign + $('#TotalDiscount').val()).length - 10) + '';
    var TotalLine3 = 'TAMOUNT    :' + (Leftalign + $('#TotalTaxable').val()).substr((Leftalign + $('#TotalTaxable').val()).length - 10) + '';
    var TotalLine4 = 'VAT 5%     :' + (Leftalign + $('#TotalTax').val()).substr((Leftalign + $('#TotalTax').val()).length - 10) + '';
    var TotalLine5 = 'ADVANCE    :' + (Leftalign + Adv).substr((Leftalign + Adv).length - 10) + '';
    var TotalLine6 = 'BALANCE ' + Currency.substr(0, 3) + ':' + (Leftalign + gndtotal).substr((Leftalign + gndtotal).length - 10) + '' + String.fromCharCode(27) + "E";
    var Spliter = '----------------------'

    Line += '<tr><td>' + (AmountinWords + ' Only' + Leftalign).substr(0, Leftalign.length - 1) + '</td><td>' + TotalLine1 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine2 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine3 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine4 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine5 + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + TotalLine6 + '</td></tr>'

    $('#DosPrintSR').append(Line);
    PrintDosPrintSR();

}




function PrintthisReceiptVoucher(Rowlen) {
    $('#DosPrintRV').html('');
    var AmountinWords = ' ' + convertNumberToWords($('#Amount').val())

   
    var Space = '                                                                                            ';
    var Space1 = '              '
    var Leftalign = '     ';
    var Line = "<tr><th></th></tr>";
    var Amount = 'Amount :' + parseFloat($('#Amount').val() || 0).toFixed(2) + Space
    var Currency = $('#Currency option:selected').html();
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + String.fromCharCode(27) + "E" + '  RECEIPT VOUCHER    ' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td></tr>';
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + Amount.substring(0, 30) + String.fromCharCode(27) + "F" + Space1 + '    RV No  :' + $('#VoucherNo').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td> ' + Space.substring(0, 45) + '     Date   :' + $('#VoucherDate').val() + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Received with thanks from  ' + $('#AccountName').val() + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'The Sum of '+Currency +'   ' + AmountinWords + ' Only ' + String.fromCharCode(27) + "F" + '</td></tr>'
    //Line += '<tr><td>.</td><td></td><td></td></tr><tr><td>.</td><td></td><td></td></tr>'   

    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Balance :' + $("#CurrentBalance").val() + ' Only ' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
  
    var len = 0;   
    var InvNo = '';
    for (var j = 1; j <= Rowlen; j++) {        
        if ($('#SlNoCheck' + j).prop("checked")) {
            len = len + 1;            
            Line += '<tr><td>' + Leftalign + '</td><td>' + $('#VEDescription' + j).text() + '</td></tr>'
        }
    }    
    for (var j = 1; j <= 6 - len; j++) {
        Line += '<tr><td>.</td></tr>';
    }

    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    $('#DosPrintRV').append(Line);
    PrintDosPrintRV(); 
}



function PrintthisPaymentVoucher(Rowlen) {

    $('#DosPrintPV').html('');
    var AmountinWords = '       ' + convertNumberToWords($('#Amount').val())

    var Space = '                                                                                            ';
    var Leftalign = '    ';
    var Line = "<tr><th></th></tr>";
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + String.fromCharCode(27) + "E" + '  PAYMENT VOUCHER    ' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + '                     PV No     :' + $('#VoucherNo').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + '                     Date      :' + $('#VoucherDate').val() + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'PAY TO MR/MRS   ' + ($('#AccountName').val() + Space).substring(0, 30) + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'The Sum of ' + $('#Currency option:selected').html() + AmountinWords + ' Only' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'

    var len = 0;

    var InvNo = '';
    var InvDate = '';
    var InvAmount = 0;

    for (var i = 1; i <= Rowlen; i++) {
        if ($('#SlNoCheck' + i).prop("checked")) {
            InvAmount = parseInt(InvAmount) + parseInt($('#Amount' + i).text()); 
            console.log(InvAmount)
            len = len + 1;
            InvNo += $('#InvoNo' + i).text() + ',';
            var InvNo = InvNo;
            var InvDate = $('#InvoDate1').text();
           
            var RecAmount = ($('#Amount').val());
        }
    }
    var a = parseFloat(InvAmount).toFixed(Decimal); 

    Line += '<tr><td>' + Leftalign + '</td><td>' + 'Inv.Number     :  ' + InvNo.substring(0, 30) + '                      Inv.Date   : ' + InvDate + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + 'Inv.Amount     :  ' + a + '                   Amount     : ' + String.fromCharCode(27) + "E" + RecAmount + String.fromCharCode(27) + "F" + '</td></tr>'

    Line += '<tr><td>.</td><td></td><td></td></tr>'

    if ($('#AccountType').val() == 2 || $('#AccountType').val() == 3) {
        Line += '<tr><td>' + Leftalign + '</td><td>' + 'Cheque No : ' + ($('#ChequeNo').val()).substring(0, 30) + '       Cheque Date : ' + ($('#ChequeDate').val()) + '      Bank :' + (($('#Bank option:selected').html())) + '</td></tr>'
    }
    else
    {
        Line += '<tr><td>.</td><td></td><td></td></tr>'
    }
    for (var i = 1; i < 7 - len; i++) {
        Line += '<tr><td>.</td></tr>';
    }

    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'
    $('#DosPrintPV').append(Line);
    PrintDosPrintPV();
}



function PrintthisVoucherEntry(Rowlen) {
    $('#DosPrintVE').html('');
    var AmountinWords = '  ' + convertNumberToWords($('#Credittxt').val())

    var Space = '                                                                                            ';
    var Leftalign = '   ';
    var Break = '----------------------------------------------------------------------------------------------------'
    var Line = "<tr><th></th></tr>";
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + String.fromCharCode(27) + "E" + ($('#VoucherType option:selected').html().substring(4, 30)).substring(0, 30) + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + '                   VE No     :' + $('#VoucherNo').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + '                   Date      :' + $('#VoucherDate').val() + '</td></tr>'
    //Line += '<tr><td>' + Leftalign + '</td><td>' + 'Voucher Type  ' + ($('#VoucherType option:selected').html()).substring(0, 30) + '</td></tr>'

    Line += '<tr><td>.</td><td></td><td></td></tr>'




    if ($('#VoucherType').val() != 2) {
        var Prefix = 'PAY TO MR/MRS       '
        if ($('#VType2').val() == 'Debit') {
            var AccountName = $('#AccountId2').val();
        }
        else {
            var AccountName = $('#AccountId1').val();
        }


    }
    else {
        var Prefix = 'Received with thanks from  '
        if ($('#VType2').val() == 'Credit') {
            var AccountName = $('#AccountId2').val();
        }
        else {
            var AccountName = $('#AccountId1').val();
        }


    }

        var Desc = $('#VoucherEntryDescription' + (Rowlen - 1)).val();
        var InvDate = $('#VoucherDate').val();
        var Amount = $('#Credittxt').val();
        var TaxNo = $('#TaxNo' + (Rowlen - 2)).val();
        var RefNo = $('#ReferenceNo' + (Rowlen - 2)).val();

        Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + Prefix + (AccountName + Space).substring(0, 30) + String.fromCharCode(27) + "F" + '</td></tr>'
        Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'The Sum of '+ $('#Currency option:selected').html()  +' ' + AmountinWords + ' Only' + String.fromCharCode(27) + "F" + '</td></tr>'
        Line += '<tr><td>.</td><td></td><td></td></tr>'
        Line += '<tr><td>' + (Space).substring(0, 3) +(Desc) + '</td></tr>'


        Line += '<tr><td>.</td><td></td><td></td></tr>'
        Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Amount     :' + Amount + String.fromCharCode(27) + "F" + '            Tax No:  ' + (TaxNo).substring(0, 30) + '                Ref No :' + (RefNo) + '</td></tr>'

    

        Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    $('#DosPrintVE').append(Line);
    PrintDosPrintVE();
}
function PrintthisPettyCash(Rowlen) {
    console.log(Rowlen)
    $('#DosPrintPC').html('');
    var AmountinWords = '  ' + convertNumberToWords($('#Credittxt').val())
      var Totamnt = 0;
    var Space = '                                                                                            ';
    var Leftalign = '';
    var Break = '----------------------------------------------------------------------------------------------------'
    var Line = "<tr><th></th></tr>";
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + String.fromCharCode(27) + "E" + ($('#VoucherType option:selected').html())+''+(Space).substring(0, 30) + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + '                   VE No     :' + $('#VoucherNo').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + '                   Date      :' + $('#VoucherDate').val() + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'

    var Prefix = 'PAY TO MR/MRS             : '
  
         var AccountName = $('#BankAccountName').val();
    
         var Desc = $('#VoucherEntryDescription' + (Rowlen - (Rowlen-1))).val();
         var InvDate = $('#VoucherDate').val();
             Totamnt = parseFloat(Totamnt + ($('#Credittxt').val()) || 0);
        
         var Amount = parseFloat(Totamnt||0);
        
    var TaxNo = $('#TaxNo' + (Rowlen - (Rowlen - 1))).val();
    var RefNo = $('#ReferenceNo' + (Rowlen - (Rowlen - 1))).val();

    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'PAY TO MR/MRS     ' + (AccountName + Space).substring(0, 30) + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'The Sum of Dirhams  ' + AmountinWords + ' Only' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + (Desc) + '</td></tr>'


    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Amount     :' + Amount + String.fromCharCode(27) + "F" + '            Tax No:  ' + (TaxNo).substring(0, 30) + '                Ref No :' + (RefNo) + '</td></tr>'



    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    $('#DosPrintPC').append(Line);
    PrintDosPrintVC();

}

function PrintthisVoucherEntryModify(Rowlen) {
    $('#DosPrintVEM').html('');
    var AmountinWords = ' ' + convertNumberToWords($('#Credittxt').val())

    var Space = '                                                                                            ';
    var Leftalign = '   ';
    var Break = '----------------------------------------------------------------------------------------------------'
    var Line = "<tr><th></th></tr>";
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + String.fromCharCode(27) + "E" + ($('#VoucherType option:selected').html().substring(4, 30)).substring(0, 30) + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + '                 VE No     :' + $('#VoucherNo').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + '                 Date      :' + $('#VoucherDate').val() + '</td></tr>'
    //Line += '<tr><td>' + Leftalign + '</td><td>' + 'Voucher Type  ' + ($('#VoucherType option:selected').html()).substring(0, 30) + '</td></tr>'

    Line += '<tr><td>.</td><td></td><td></td></tr>'



    if ($('#VType2').val() == 'Credit') {
        var AccountName = $('#AccountId2').val();
    }
    else {
        var AccountName = $('#AccountId1').val();
    }
    var Description = $('#VoucherEntryDescription' + (Rowlen - 1)).val();
    var InvDate = $('#VoucherDate').val();
    var Amount = $('#Credittxt').val();
    var TaxNo = $('#TaxNo' + (Rowlen - 2)).val();
    var RefNo = $('#ReferenceNo' + (Rowlen - 2)).val();

    if ($('#VoucherType').val() != 2) {
        var Prefix = 'PAY TO MR/MRS             : '
        if ($('#VType2').val() == 'Debit') {
            var AccountName = $('#AccountId2').val();
        }
        else {
            var AccountName = $('#AccountId1').val();
        }


    }
    else {
        var Prefix = 'Received with thanks from : '
        if ($('#VType2').val() == 'Credit') {
            var AccountName = $('#AccountId2').val();
        }
        else {
            var AccountName = $('#AccountId1').val();
        }


    }

    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + Prefix + (AccountName) + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'The Sum of Dirhams        :' + AmountinWords + ' Only' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'

    Line += '<tr><td>.</td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + (Description) + '</td></tr>'


    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Amount     :' + Amount + String.fromCharCode(27) + "F" + '            Tax No:  ' + (TaxNo).substring(0, 30) + '                Ref No :' + (RefNo) + '</td></tr>'



    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'


    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    $('#DosPrintVEM').append(Line);
    PrintDosPrintVEM();
}








function convertNumberToWords(amount) {
    var words = new Array();
    words[0] = '';
    words[1] = 'One';
    words[2] = 'Two';
    words[3] = 'Three';
    words[4] = 'Four';
    words[5] = 'Five';
    words[6] = 'Six';
    words[7] = 'Seven';
    words[8] = 'Eight';
    words[9] = 'Nine';
    words[10] = 'Ten';
    words[11] = 'Eleven';
    words[12] = 'Twelve';
    words[13] = 'Thirteen';
    words[14] = 'Fourteen';
    words[15] = 'Fifteen';
    words[16] = 'Sixteen';
    words[17] = 'Seventeen';
    words[18] = 'Eighteen';
    words[19] = 'Nineteen';
    words[20] = 'Twenty';
    words[30] = 'Thirty';
    words[40] = 'Forty';
    words[50] = 'Fifty';
    words[60] = 'Sixty';
    words[70] = 'Seventy';
    words[80] = 'Eighty';
    words[90] = 'Ninety';
    amount = amount.toString();
    var atemp = amount.split(".");
    var number = atemp[0].split(",").join("");
    var n_length = number.length;
    var words_string = "";
    if (n_length <= 9) {
        var n_array = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
        var received_n_array = new Array();
        for (var i = 0; i < n_length; i++) {
            received_n_array[i] = number.substr(i, 1);
        }
        for (var i = 9 - n_length, j = 0; i < 9; i++, j++) {
            n_array[i] = received_n_array[j];
        }
        for (var i = 0, j = 1; i < 9; i++, j++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                if (n_array[i] == 1) {
                    n_array[j] = 10 + parseInt(n_array[j]);
                    n_array[i] = 0;
                }
            }
        }
        value = "";
        for (var i = 0; i < 9; i++) {
            if (i == 0 || i == 2 || i == 4 || i == 7) {
                value = n_array[i] * 10;
            } else {
                value = n_array[i];
            }
            if (value != 0) {
                words_string += words[value] + " ";
            }
            if ((i == 1 && value != 0) || (i == 0 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Crores ";
            }
            if ((i == 3 && value != 0) || (i == 2 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Lakhs ";
            }
            if ((i == 5 && value != 0) || (i == 4 && value != 0 && n_array[i + 1] == 0)) {
                words_string += "Thousand ";
            }
            if (i == 6 && value != 0 && (n_array[i + 1] != 0 && n_array[i + 2] != 0)) {
                words_string += "Hundred and ";
            } else if (i == 6 && value != 0) {
                words_string += "Hundred ";
            }
        }
        words_string = words_string.split("  ").join(" ");
    }
    return words_string;
}






function prepCSVRow(arr, columnCount, initial) {
    var row = ''; // this will hold data
    var delimeter = ''; // data slice separator, in excel it's `;`, in usual CSv it's `,`
    var newLine = '\r\n'; // newline separator for CSV row
    function splitArray(_arr, _count) {
        var splitted = [];
        var result = [];
        _arr.forEach(function (item, idx) {
            if ((idx + 1) % _count === 0) {
                splitted.push(item);
                result.push(splitted);
                splitted = [];
            } else {
                splitted.push(item);
            }
        });
        return result;
    }
    var plainArr = splitArray(arr, columnCount);
    plainArr.forEach(function (arrItem) {
        arrItem.forEach(function (item, idx) {
            row += item + ((idx + 1) === arrItem.length ? '' : delimeter);
        });
        row += newLine;
    });
    return initial + row;
}


function PrintDosPrintFazal() {

    var titles = [];
    var data = [];
    $('.dataTableFazal th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTableFazal tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
    $('#DosPrintFazal').html('');
}


function PrintDosPrint() {

    var titles = [];
    var data = [];
    $('.dataTable th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTable tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
    $('#DosPrint').html('');
}

function PrintDosPrintNew() {

    var titles = [];
    var data = [];
    $('.dataTableNew th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTableNew tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
    $('#DosPrintNew').html('');
}


function PrintDosPrintSR() {

    var titles = [];
    var data = [];
    $('.dataTableSR th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTableSR tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);

}


function PrintDosPrintRV() {

    var titles = [];
    var data = [];

    $('.dataTableRV th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTableRV tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);

}

function PrintDosPrintPV() {

    var titles = [];
    var data = [];

    $('.dataTablePV th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTablePV tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);

}
function PrintDosPrintVC() {

    var titles = [];
    var data = [];

    $('.dataTableVC th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTableVC tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);

}



function PrintDosPrintVE() {

    var titles = [];
    var data = [];

    $('.dataTableVE th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTableVE tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);

}

function PrintDosPrintVEM() {

    var titles = [];
    var data = [];

    $('.dataTableVEM th').each(function () {
        titles.push($(this).text());
    });
    $('.dataTableVEM tr').each(function () {
        data.push($(this).text());
    });
    var CSVString = prepCSVRow(titles, titles.length, '');
    CSVString = prepCSVRow(data, titles.length, CSVString);
    var downloadLink = document.createElement("a");
    var blob = new Blob(["\ufeff", CSVString]);
    var url = URL.createObjectURL(blob);
    downloadLink.href = url;
    downloadLink.download = "eumi_sales.txt";
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);

}

function PrintVCCSave(Rowlen) {
    $('#DosPrintRV').html('');
    var AmountinWords = '  ' + convertNumberToWords($('#amountid').val())

    var Space = '                                                                                            ';
    var Space1 = '              '
    var Leftalign = '';
    var Line = "<tr><th></th></tr>";
    var Cash = 'Cash';
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + String.fromCharCode(27) + "E" + '  RECEIPT VOUCHER    ' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Space1 + Space1 + Space1 + '   RV No     :' + $('#vccnoid').val()  + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Amount:  ' + ($('#amountid').val() + Space).substring(0, 30) + String.fromCharCode(27) + "F" + '   Date     :' + $('#date').val() + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Received with thanks from  ' + $('#txtcustomer').val() + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'The Sum of ' + $('#select_crncy option:selected').html() + ' ' + AmountinWords + 'Only' + String.fromCharCode(27) + "F" + '</td></tr>'

    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Cash + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'

    var Invo = $('#txtinvono1').val() + Space1; 
    var chasisnumber = $('#chassisnoid').val();
    var Desc = 'Deposit Received  Against :' + chasisnumber+' - ' + $('#prodesc1').val();

        
    Line += '<tr><td>.</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Desc + '</td></tr>'       
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    $('#DosPrintRV').append(Line);
    PrintDosPrintRV();
}



function PrintVCCPaymentSave(Rowlen) {
    $('#DosPrintPV').html('');
    var AmountinWords = ' ' + convertNumberToWords($('#amountid').val())

    var Space = '                                                                                            ';
    var Space1 = '              '
    var Leftalign = '';
    var Line = "<tr><th></th></tr>";
    var Cash = 'Cash';
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    Line += '<tr><td>' + Leftalign + '</td><td>' + (Space).substring(0, 30) + String.fromCharCode(27) + "E" + '  Payment Voucher  ' + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Space1 + Space1 + Space1 + ' PV No     :' + $('#vccnoid').val() + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Amount:  ' + ($('#amountid').val() + Space).substring(0, 30) + String.fromCharCode(27) + "F" + ' Date       :' + $('#date').val() + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'Pay To  MR/MRS   ' + $('#txtcustomer').val() + String.fromCharCode(27) + "F" + '</td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + String.fromCharCode(27) + "E" + 'The Sum of ' + $('#select_crncy option:selected').html() + ' ' + AmountinWords + 'Only' + String.fromCharCode(27) + "F" + '</td></tr>'

    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + Cash + '</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'


    var Invo = $('#txtinvono1').val() + Space1; var chasisnumber = $('#chassisnoid').val();
    var Desc = 'Deposit Received  Against :' + chasisnumber + ' - ' + $('#prodesc1').val();


    Line += '<tr><td>.</td></tr>'
    Line += '<tr><td>.</td><td></td><td></td></tr>'
    Line += '<tr><td>' + Leftalign + '</td><td>' + 'Description        :  ' + Desc + '</td></tr>'
    Line += '<tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr><tr><td>.</td></tr>'

    $('#DosPrintPV').append(Line);
    PrintDosPrintPV();
}