<%@ Page Title="Sales Invoice Page" Language="C#" MasterPageFile="~/SunMaster.Master" AutoEventWireup="true" CodeBehind="SalesInvoice.aspx.cs" Inherits="SUNWEB.SalesInvoice" %>

<%@ Register Assembly="AjaxControlToolkit" TagPrefix="asp" Namespace="AjaxControlToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">

    <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.3.0/crypto-js.min.js" integrity="sha512-e2c+O0PvytekkdJLc82DHfa6La8TPKzO2/DFA97YeHTbiDCwKMzloupJM6Llf/W4K19+N21gFyplVkvzL4pZxQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <style type="text/css">
        .thclass {
            font-size: 18px;
        }

        input[type="search"]::-webkit-search-cancel-button {
            /* Remove default */
            -webkit-appearance: none;
            /* Now your own custom styles */
            height: 14px;
            width: 14px;
            display: block;
            background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAn0lEQVR42u3UMQrDMBBEUZ9WfQqDmm22EaTyjRMHAlM5K+Y7lb0wnUZPIKHlnutOa+25Z4D++MRBX98MD1V/trSppLKHqj9TTBWKcoUqffbUcbBBEhTjBOV4ja4l4OIAZThEOV6jHO8ARXD+gPPvKMABinGOrnu6gTNUawrcQKNCAQ7QeTxORzle3+sDfjJpPCqhJh7GixZq4rHcc9l5A9qZ+WeBhgEuAAAAAElFTkSuQmCC);
            /* setup all the background tweaks for our custom icon */
            background-repeat: no-repeat;
            /* icon size */
            background-size: 14px;
        }

        input[type="checkbox"] {
            width: 25px; /*Desired width*/
            height: 25px; /*Desired height*/
        }

        tblheaderfontsize {
            font-size: 16px;
        }
    </style>

    <asp:UpdatePanel runat="server" ID="updatepanel1" UpdateMode="Conditional">

        <ContentTemplate>

            <%--  <table style="margin-left: 1%; width: 98%;">
                <tr>
                    <td style="font-size: large; width: 50%; font-family: 'Open Sans', sans-serif; font-weight: bolder;">SALES INVOICE PAGE 
                    </td>
                </tr>
            </table>--%>

            <div class="row d-none">
                <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="form-row">
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <caption>
                                        <label for="validationCustom03">
                                            FROM DATE
                                        </label>
                                        <asp:TextBox ID="txtStartDt" class="form-control" runat="server"></asp:TextBox>
                                        <asp:CalendarExtender ID="calFirstDueDate" Format="yyyy-MM-dd" runat="server" TargetControlID="txtStartDt" PopupPosition="BottomLeft" FirstDayOfWeek="Sunday"></asp:CalendarExtender>
                                    </caption>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <label for="validationCustom03">
                                        TO DATE
                                    </label>

                                    <asp:TextBox ID="txtEndDt" class="form-control" runat="server"></asp:TextBox>
                                    <asp:CalendarExtender ID="CalendarExtender1" Format="yyyy-MM-dd" runat="server" TargetControlID="txtEndDt" PopupPosition="BottomLeft" FirstDayOfWeek="Sunday"></asp:CalendarExtender>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <label for="validationCustom03">
                                        <asp:Label ID="lblBranchAliasName" ForeColor="Gray" runat="server" Text="Branch Name"></asp:Label></label>
                                    <asp:DropDownList ID="cmbBranches" CssClass="custom-select"
                                        runat="server" AutoPostBack="true"
                                        OnSelectedIndexChanged="cmbBranches_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </div>

                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <asp:Button ID="btnGetReports" runat="server" Text="Apply"
                                        CssClass="btn btn-primary" OnClick="btnGetReports_Click" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="container-fluid bg-white p-2 font-14">
                <div class="row">
                    <form>
                        <div class="col-sm-2 col-md-3 ">
                            <label for="input-date" class="form-label">Date</label>
                            <input type="date" class="form-control" id="input-date" readonly>
                        </div>

                        <div class=" col-sm-2  col-md-3">
                            <label for="input-due" class="form-label">Due Date</label>
                            <input type="date" class="form-control" id="input-due">
                        </div>
                        <div class=" col-sm-2  col-md-3">
                            <label for="input-customer" class="form-label">Customer Name</label>
                            <div class="row align-items-center">
                                <div class="col-9">
                                    <input type="search" class="form-control" id="input-customer">
                                </div>
                                <div class="col px-0">
                                    <button type="button" id="button-search-customer" class="btn btn-primary btn-sm">...</button>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-2 col-md-3">
                            <label for="input-invoiceno" class="form-label">Invoice #</label>
                            <input type="text" class="form-control" id="input-invoiceno">
                        </div>
                    </form>
                </div>
                <div class="row my-3">
                    <div class="col-sm-2 col-md-3">
                        <label for="button-paymenttype" class="form-label">Select Payment Type</label>
                        <div class="dropdown">
                            <button id="button-paymenttype" type="button" class="btn btn-primary btn-sm dropdown-toggle w-100 text-justify" data-bs-toggle="dropdown">
                            </button>
                            <ul id="ddpaymenttype" class="dropdown-menu w-100 dropdown-menu-end">
                            </ul>
                        </div>
                    </div>
                    <div class=" col-sm-2  col-md-3">
                        <label for="input-referenceno" class="form-label">Reference #</label>
                        <div class="row align-items-center">
                            <%--<div class="col-9">--%>
                            <input type="search" class="form-control" id="input-referenceno">
                            <%-- </div>--%>
                            <%-- <div class="col px-0">
                                    <button type="button" id="button-search-customer" class="btn btn-primary btn-sm">...</button>
                                </div>--%>
                        </div>
                    </div>
                </div>

                <hr />

                <div class="container-fluid navigation-horizontal mx-1">
                    <div class="container-fluid p-0 m-0 text-right">
                        <button type="button" id="button-preview" class="btn btn-primary btn-sm my-2" style="width: 110px">Preview</button>
                    </div>
                    <table class="table table-bordered" id="table-selecteditems">
                        <div class="container py-2 px-0 mx-0">
                            <div class="row">
                                <div class="col-sm-2 col-md-3">
                                    <label for="input-search" class="form-label">Scan Barcode</label>
                                    <input type="search" class="form-control" id="input-scan" />
                                </div>
                            </div>
                        </div>

                        <thead>
                            <tr>
                                <th class="col-2 px-2" style="font-size: 16px; text-align: left;">Barcode</th>
                                <th class="col-3 px-2" style="font-size: 16px; text-align: left;">Name</th>
                                <th class="col-4 px-2" style="font-size: 16px; text-align: left;">Description</th>
                                <th class="col-1 px-2" style="font-size: 16px; text-align: right;">Qty</th>
                                <th class="col-1 px-2" style="font-size: 16px; text-align: right; white-space: nowrap;">Unit Price</th>
                                <th class="col-2 px-2" style="font-size: 16px; text-align: right;">Disc(%)</th>
                                <th class="col-2 px-2" style="font-size: 16px; text-align: right;">Disc(amount)</th>
                                <th class="col-2 px-2" style="font-size: 16px; text-align: right;">DiscValue</th>
                                <th class="col-2 px-2" style="font-size: 16px; text-align: right;">DiscType</th>
                                <th class="col-2 px-2" style="font-size: 16px; text-align: right; white-space: nowrap;">Disc Amount</th>
                                <th class="col-1 px-2" style="font-size: 16px; text-align: right;">Amount</th>
                            </tr>
                        </thead>
                        <tbody id="tbody-item">
                            <%-- <tr style="height: 32px;">
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr style="height: 32px;">
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr style="height: 32px;">
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>--%>
                        </tbody>
                    </table>

                    <div class="container-fluid p-1">
                        <div class="row">
                            <div class="col">
                                <button type="button" id="button-additem" class="btn btn-primary btn-sm my-2" style="width: 110px">Add Item</button>
                            </div>
                            <%--subtotal--%>
                            <div class="col p-4">
                                <div class=" row">
                                    <div class="col-3">
                                    </div>
                                    <div class="col">
                                        <div class="row">
                                            <div class="col font-20">
                                                Subtotal
                                            </div>
                                            <label id="label-subtotal" class="col text-right font-20">
                                                0.00
                                            </label>
                                        </div>
                                        <div class="row">
                                            <div class="col font-20">
                                                GST
                                            </div>
                                            <label id="label-gst" class="col text-right font-20">
                                                0.00
                                            </label>
                                        </div>
                                        <%--             <div class="row">
                                            <div class="col">
                                                Total
                                            </div>
                                            <div class="col text-right">
                                                0.00
                                            </div>
                                        </div>--%>

                                        <hr style="border-bottom: 1px solid #333;" />

                                        <div class="col p-0">
                                            <div class="row">
                                                <div class="col">
                                                    <label class="font-24">Total</label>
                                                </div>
                                                <div class="col text-right">
                                                    <label id="label-total" class="font-24">0.00</label>
                                                </div>
                                            </div>

                                        </div>
                                        <hr class="my-1" style="border-bottom: 1px solid #333;" />
                                        <hr class="my-1" style="border-bottom: 1px solid #333;" />
                                        <div>
                             <%--               <div class="row">
                                                <div class="col">

                                                    <label for="button-paymenttype" class="form-label">Select Payment Type</label>
                                                    <div class="dropdown">
                                                        <button id="button-paymenttype" type="button" class="btn btn-primary btn-sm dropdown-toggle w-100 text-justify" data-bs-toggle="dropdown">
                                                        </button>
                                                        <ul id="ddpaymenttype" class="dropdown-menu w-100 dropdown-menu-end">
                                                        </ul>
                                                    </div>

                                                </div>
                                                 <div class="col">

                                                    <label for="button-paymenttype" class="form-label">Select Payment Type</label>
                                                    <div class="dropdown">
                                                        <button id="button-paymenttype" type="button" class="btn btn-primary btn-sm dropdown-toggle w-100 text-justify" data-bs-toggle="dropdown">
                                                        </button>
                                                        <ul id="ddpaymenttype" class="dropdown-menu w-100 dropdown-menu-end">
                                                        </ul>
                                                    </div>

                                                </div>

                                            </div>--%>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="card-footer p-2">
                <div class="row">
                    <div class="col">
                        <button type="button" id="button-save" class="btn btn-primary btn-sm my-2" style="width: 110px">Save</button>
                        <button type="button" id="button-confirm" class="btn btn-primary btn-sm my-2" style="width: 110px">Confirm</button>
                    </div>
                    <div class="col text-right">
                        <button type="button" id="button-approve" class="btn btn-primary btn-sm my-2 d-none" style="width: 110px">Approve</button>
                        <button type="button" id="button-cancel" class="btn btn-primary btn-sm my-2" style="width: 110px">Cancel</button>
                    </div>
                </div>
            </div>

            <!--Modal Add Item-->
            <div class="modal" id="modal-additem">
                <div class="modal-dialog modal-lg  modal-dialog-centered">
                    <div class="modal-content p-1" style="height: calc(100vh - 115px);">
                        <div class="modal-header">
                            <h5 class="modal-title">Search Item</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col">
                                    <select id="selectedsearch" class="form-select rounded-0" aria-label="size 3 select example">

                                        <option value="1">Category</option>
                                        <option value="2">Barcode</option>
                                        <option value="3">Name</option>
                                        <option value="4">Description</option>
                                    </select>
                                    <%-- <div class="dropdown">
                                        <button class="btn dropdown-toggle w-100 border" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
                                            Search
                                        </button>
                                        <ul class="dropdown-menu w-100" aria-labelledby="dropdownMenuButton1">
                                            <li><a class="dropdown-item">Category</a></li>
                                            <li><a class="dropdown-item">Barcode</a></li>
                                            <li><a class="dropdown-item">Name</a></li>
                                            <li><a class="dropdown-item">Description</a></li>
                                        </ul>
                                    </div>--%>
                                </div>
                                <div class="col">
                                    <div class="input-group mb-3">
                                        <input id="input-search" type="search" class="form-control">
                                        <%-- <span class="input-group-text" id="basic-addon2"><span class="bi-search"></span></span>--%>
                                    </div>
                                </div>
                            </div>
                            <div style="height: calc(75vh - 150px); overflow-x: auto">
                                <table class="table table table-bordered">
                                    <thead>
                                        <tr>
                                            <th scope="col" class="tblheaderfontsize"></th>
                                            <th scope="col" style="font-size: 16px">Barcode</th>
                                            <th scope="col" style="font-size: 16px">Name</th>
                                            <th scope="col" style="font-size: 16px">Description</th>
                                            <th scope="col" style="font-size: 16px">Category</th>
                                            <!--<th scope="col" style="font-size: 16px">Quantity</th>-->
                                        </tr>
                                    </thead>

                                    <tbody id="table_body_items" class="font-16">
                                    </tbody>
                                </table>
                            </div>
                            <div class="modal-footer px-0">
                                <button type="button" id="btn-selecteditem" class="btn btn-primary">Select</button>
                                <button type="button" id="btn-searchitem-close" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!--Modal Add Customer-->
            <div class="modal" id="modal-add-customer">
                <div class="modal-dialog modal-lg  modal-dialog-centered">
                    <div class="modal-content p-1" style="height: calc(100vh - 115px);">
                        <div class="modal-header">
                            <h5 class="modal-title">Search Customer</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col">
                                    <select id="selectedcustomer" class="form-select rounded-0" aria-label="size 3 select example">

                                        <option value="1">All</option>
                                        <option value="2">ID</option>
                                        <option value="3">Name</option>
                                        <option value="4">Contact No.</option>
                                    </select>

                                </div>
                                <div class="col">
                                    <div class="input-group mb-3">
                                        <input id="input-searchcustomer" type="search" class="form-control">
                                        <%-- <span class="input-group-text" id="basic-addon2"><span class="bi-search"></span></span>--%>
                                    </div>
                                </div>
                            </div>
                            <div style="height: calc(75vh - 150px); overflow-x: auto">
                                <table class="table table table-bordered">
                                    <thead>
                                        <tr>
                                            <th scope="col" class="tblheaderfontsize"></th>
                                            <th scope="col" style="font-size: 16px">ID</th>
                                            <th scope="col" style="font-size: 16px">Name</th>
                                            <th scope="col" style="font-size: 16px">Address</th>
                                            <th scope="col" style="font-size: 16px">Contact No.</th>

                                        </tr>
                                    </thead>

                                    <tbody id="table-body-customer" class="font-16">
                                    </tbody>
                                </table>
                            </div>
                            <div class="modal-footer px-0">
                                <button type="button" id="btn-selected-customer" class="btn btn-primary">Select</button>
                                <button type="button" id="btn-search-customer-close" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!--Modal Add Discount-->
            <div class="modal" id="modal-add-discount">
                <div class="modal-dialog modal-md  modal-dialog-centered">
                    <div class="modal-content p-1">
                        <div class="modal-header">
                            <h5 class="modal-title">Discount</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <label id="label-rowindex"></label>
                            <div class="dropdown my-3">
                                <button id="button-discount-type" type="button" class="btn btn-primary btn-sm dropdown-toggle w-50 text-left" data-bs-toggle="dropdown" aria-expanded="false">Percent(%)</button>
                                <ul id="ddalarm" class="dropdown-menu" style="">
                                    <li><a class="dropdown-item">Percent(%)</a></li>
                                    <li><a class="dropdown-item">Amount</a></li>
                                </ul>
                            </div>
                            <input type="search" class="form-control" id="input-value">
                        </div>
                        <div class="modal-footer px-0">
                            <button type="button" id="button-apply-discount" class="btn btn-primary">Apply</button>
                            <button type="button" id="btn-discount-close" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
                        </div>
                    </div>
                </div>
            </div>

        </ContentTemplate>
    </asp:UpdatePanel>
    <script src="https://cdn.jsdelivr.net/npm/table-to-json@1.0.0/lib/jquery.tabletojson.min.js"></script>
    <script type="text/javascript" src="sunScript/SItransaction.js"></script>
    <script type="text/javascript">
        let selecteditems = [];
        $(document).ready(function () {
            
            let AllTax = GET_AllTax();
            let currentdate = getDateTime();
        
          //  $("#input-invoiceno").val( generateInvoiceNumber())
            $('#input-date').val(currentdate.substring(0,10));
            $('#input-due').val(currentdate.substring(0,10));
            

            let itemlist = JSON.parse(getInventory());                     
            //console.log(itemlist)
            let sessionselecteditems = JSON.parse(sessionStorage.getItem('selecteditems'));
        
            if(sessionselecteditems != null){
                loaditems(sessionselecteditems)
                
            }

          
           /* $("#input-scan").on("keypress", function (e) {
                AllTax = GET_AllTax();                
                if (e.key === "Enter") {                       
                    e.preventDefault();
                    //let table = document.getElementById("table-selecteditems");
                    let categorylist = JSON.parse(getCategory())
                    let scanneditem = itemlist.filter((e) => e['Barcode'].toLowerCase().trim() ==  $('#input-scan').val().toLowerCase().trim());
                    
                    let category = categorylist.filter((e) => e['CategoryID'] == scanneditem[0]["CategoryID"])

                    //selecteditems.push(scanneditem[0])
                                       
                    if(scanneditem.length == 0){
                        Swal.fire({
                            icon: "warning",
                            text: "Item Not Found",
                            timer: 1500
                        }).then(function () {
                            $('#input-scan').val('')                           
                        });
                        return;
                    }
                                                                                          
                    let taxinfo = "";
                    AllTax.forEach(function(x){
                        let addon = x['addon'];
                        let taxontax = x['taxontax'];
                        let tax = x['tax'];
                        taxinfo = taxinfo  + addon + "," + taxontax + "," + tax + ":";
                       
                    })             
                                       
                    let item = {
                        "Barcode":scanneditem[0]['Barcode'],
                        "Name":scanneditem[0]['InventoryName'],
                        "Description":scanneditem[0]['Description'],
                        "Qty":1,
                        "Unit Price":scanneditem[0]['Price'],                        
                        "Amount":scanneditem[0]['Price'],
                        "taxinfo":taxinfo,
                        
                    }

                    AddItemProc(item)
                    loaditems([item]);

                    

                    var table = $('#table-selecteditems').tableToJSON();       
                    
                

                    var table = $('#table-selecteditems').tableToJSON();                           
                    let items = [];
                    table.forEach(function (tbl) {   
                        let x = 1;                                                
                      
                        let item = {
                            "Barcode":tbl["Barcode"],
                            "Name":tbl['Name'],
                            "Description":tbl['Description'],
                            "Qty":$('#table-selecteditems').find("tr:eq(" + x + ")").find("td:eq(3)").find("input").val(),
                            "Unit Price":tbl['Unit Price'],
                            "Amount":$('#table-selecteditems').find("tr:eq(" + x + ")").find("td:eq(5)").find("input").val(),
                            "taxinfo":taxinfo
                        }
                        items.push(item)    
                        x++
                    });
                    sessionStorage.setItem('selecteditems', JSON.stringify(items))

                    calculate();
                    $('#input-scan').val('');
                    return false;
                }


            });*/

            $(document).on("click", "#button-save", function () {  

                

                Swal.fire({
                //title: "Are you sure you want to stock in with zero cost?",
                    text: "Are you sure you want to save this transaction?",
                    icon: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#3085d6",
                    cancelButtonColor: "#d33",
                    confirmButtonText: "Yes"
                }).then((result) => {
                    if (result.isConfirmed) {
                        let transstatus = 3;
                       
                        if(POST_DATA(transstatus).toString().toLowerCase() == "true"){
                             Swal.fire({
                                position: "center",
                                icon: "success",
                                text: "Transaction saved",
                                showConfirmButton: true,
  
                        timer: 1500
                            }).then((result) => {
                                let tbody = document.getElementById("tbody-item");
                                tbody.innerHTML = "";
                                sessionStorage.removeItem('transactioncollection');
                                $("#input-customer").val('');
                                $("#label-subtotal").text('0.00');
                                $("#label-gst").text('0.00')
                                $("#label-total").text('0.00');
                                $('#input-invoiceno').val(generateInvoiceNumber());
                            });
                        }
                     }
                });               
            });


            $(document).on("click", "#button-confirm", function () {        

                if(document.getElementById('button-paymenttype').innerText.toLowerCase() == "select payment"){
                    Swal.fire({
                    //title: "Are you sure you want to stock in with zero cost?",
                        text: "Please Select Payment?",
                        icon: "info",                        
                        confirmButtonColor: "#3085d6",
                        cancelButtonColor: "#d33",
                                           
                    }).then((result) => {
                       
                    });
                    return;
                }

                Swal.fire({
                //title: "Are you sure you want to stock in with zero cost?",
                    text: "Are you sure you want to confirm this transaction?",
                    icon: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#3085d6",
                    cancelButtonColor: "#d33",
                    confirmButtonText: "Yes"
                }).then((result) => {
                    if (result.isConfirmed) {
                        let transstatus = 2;                       
                        if(POST_DATA(transstatus).toString().toLowerCase() == "true"){
                             Swal.fire({
                                position: "center",
                                icon: "success",
                                text: "Transaction completed",
                                showConfirmButton: true,
  
                        timer: 1500
                            }).then((result) => {
                                let tbody = document.getElementById("tbody-item");
                                tbody.innerHTML = "";
                                sessionStorage.removeItem('transactioncollection');
                                $("#input-customer").val('');
                                $("#label-subtotal").text('0.00');
                                $("#label-gst").text('0.00')
                                $("#label-total").text('0.00');
                                $('#input-invoiceno').val(generateInvoiceNumber());
                            });
                        }
                     }
                });               
            });


            $(document).on("click", "#button-cancel", function () {
              
                Swal.fire({
                //title: "Are you sure you want to stock in with zero cost?",
                    text: "Are you sure you want to cancel transaction?",
                    icon: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#3085d6",
                    cancelButtonColor: "#d33",
                    confirmButtonText: "Yes"
                }).then((result) => {
                    if (result.isConfirmed) {
                        let tbody = document.getElementById("tbody-item");
                        tbody.innerHTML = "";
                        sessionStorage.removeItem('transactioncollection');
                        $("#input-customer").val('');
                        $("#label-gst").text('0.00')
                        $("#label-subtotal").text('0.00');
                        $("#label-total").text('0.00');
                     }
                });
            });

      
            /*$('table').on('focusout input', 'td[contenteditable]', function() {
                let qty =   parseInt($(this).closest("tr").find('td:eq(3)').find("input").val());
                                
                let price = parseFloat($(this).closest("tr").find('td:eq(4)').text());
                let amount = qty * price;

                $(this).closest("tr").find('td:eq(6)').find("input").val(amount.toFixed(2))
                   
                var table = $('#table-selecteditems').tableToJSON();                           
                let items = [];
                let x = 1; 
                table.forEach(function (tbl) {                                                                                      
                    let item = {
                        "Barcode":tbl["Barcode"],
                        "Name":tbl['Name'],
                        "Description":tbl['Description'],
                        "Qty":$('#table-selecteditems').find("tr:eq(" + x + ")").find("td:eq(3)").find("input").val(),
                        "Unit Price":tbl['Unit Price'],
                        "Amount":$('#table-selecteditems').find("tr:eq(" + x + ")").find("td:eq(6)").find("input").val(),
                    }
                    items.push(item)    
                    x++
                });
                sessionStorage.setItem('selecteditems', JSON.stringify(items))
                calculate();
            });*/

            $("#button-additem").on('click', function (event) {
                //console.log(InventoryWithCostDetail());
                loadSearchItem(InventoryWithCostDetail())
                $('#modal-additem').modal('show')
            });

            $('#input-search').on("keyup", function () {
                var value = $(this).val().toLowerCase();
                var searchby = $('#selectedsearch').find(":selected").text().toLowerCase().trim();
                if (searchby.toLowerCase() == 'searchby') {
                    return;
                }
                
                let inventorydetaildata = InventoryWithCostDetail();
                //console.log(inventorydetaildata)
                let searcheddata = inventorydetaildata.filter(function (obj) {
                    for (key in obj) {
                        if (obj[searchby].toLowerCase().trim().includes(value)) {
                            return obj;
                        }
                    }
                });              
                //loadSearchItem(searcheddata)
                loadSearchItem(searcheddata)                 
            })


            /*$(window).on('beforeunload', function() {
              // Your jQuery code to be executed before leaving the page goes here
              // For example, you might want to save data or perform some cleanup tasks
                sessionStorage.clear();
              // Optional: Display a confirmation message to the user
              return "Are you sure you want to leave this page?";
            });*/

            function calculate(){
               
                var table = $('#table-selecteditems').tableToJSON();                           
                let subtotal = 0;
                let disc = 0;
                let total = 0;
                let x = 1; 
                table.forEach(function (tbl) {                                                                                                       
                    subtotal = subtotal + parseFloat($('#table-selecteditems').find("tr:eq(" + x + ")").find("td:eq(6)").find("input").val());
                    x++

                });
                
                //$("#label-subtotal").text(subtotal.toFixed(2))
                //$("#label-total").text(subtotal.toFixed(2))
            }

          

            function calculateAmountProc(){
            }

            function ProcessTotalProc(){
                let cAmount = 0;
                let cTaxAmount = 0;
                let selecteditems = JSON.parse(sessionStorage.getItem('selecteditems'));

                selecteditems.forEach(function(item){
                    
                })
                
            }

            function CalcItemTax(itemstatus){
                let itemTaxableAmount=0;
                let taxableAmount = 0;
                let cAmount = 0;

                
            }

            function loaditems(items){
                //console.log(items);
                let tbody = document.getElementById("tbody-item");
              //  tbody.innerHTML = "";
                $.each(items, function (key, detail) {
                    let tr = document.createElement("tr");

                    let tdbarcode = document.createElement("td");
                    tdbarcode.className = 'border-start border-end border-bottom  text-left px-1 py-1 align-content-center';
                    let barcode = document.createTextNode(detail['Barcode'].toString().trim())

                    let tdname = document.createElement("td");                
                    tdname.className = 'border-start border-end border-bottom  text-left px-1 py-1 align-content-center';
                    let name = document.createTextNode(detail['Name'].toString().trim())

                    let tddesc = document.createElement("td");                
                    tddesc.className = 'border-start border-end border-bottom  text-left px-1 py-1 align-content-center';
                    let desc = document.createTextNode(detail['Description'].toString().trim())

                    let tdqty = document.createElement("td");                
                    tdqty.className = 'border-start border-end border-bottom  text-right px-1 py-1 align-content-center ';
                    tdqty.setAttribute('contenteditable','true');  
                      
                    //let qty = document.createTextNode("1");
                    let inputqty = document.createElement("input");
                    inputqty.id = "input-qty";
                    inputqty.className = "form-control text-right font-14"; 
                    inputqty.type= "text";
                    inputqty.setAttribute('required','true');    
                    inputqty.value =  detail['Qty'];
                    if(detail['Qty'] == undefined){
                        inputqty.value =  "1";
                    }
                        
                    let tdunitprice = document.createElement("td");                
                    tdunitprice.className = 'border-start border-end border-bottom  text-right px-1 py-1 align-content-center';
                    let unitprice = document.createTextNode(parseFloat(detail['Unit Price']).toFixed(2))
                   
                    let tddisc = document.createElement("td");
                    tddisc.classname = 'border-start border-end border-bottom  text-right px-1 py-1 align-content-center';

                    let inputdisc = document.createElement("input");
                    inputdisc.id = "input-disc";
                    inputdisc.className = "form-control text-right font-14"; 
                    inputdisc.type= "text";
                    //inputdisc.setAttribute('required','true');    
                    inputdisc.value = 0.00;


                    let tdamount = document.createElement("td");                
                    tdamount.className = 'border-start border-end border-bottom  text-right px-1 py-1 align-content-center';
                    //let amount = document.createTextNode(detail['Amount'])
                    let inputamount = document.createElement("input");
                    inputamount.className = "form-control border-0 text-right font-14"; 
                    inputamount.type= "text";
                    inputamount.value = parseFloat(detail['Amount']).toFixed(2);


                    tdbarcode.appendChild(barcode);
                    tdname.appendChild(name);
                    tddesc.appendChild(desc);
                    tdqty.appendChild(inputqty);
                    tdunitprice.appendChild(unitprice);
                    tddisc.appendChild(inputdisc)
                    tdamount.appendChild(inputamount)

                    tr.appendChild(tdbarcode);
                    tr.appendChild(tdname);
                    tr.appendChild(tddesc);
                    tr.appendChild(tdqty);
                    tr.appendChild(tdunitprice);
                    tr.appendChild(tddisc)
                    tr.appendChild(tdamount);
                    tbody.appendChild(tr);
                })
                calculate();
            }

            $(document).on("click", ".sev_check", function () {
                $('.sev_check').not(this).prop('checked', false);
                
            });

            $('#btn-selecteditem').click(function () {
                let hasSelected = false;
                $('#table_body_items tr').each(function () {
                    $(this).find('td input:checked').each(function () {
                        hasSelected = true;
                    });
                });

                if (hasSelected == false) {
                    Swal.fire({
                        position: "center",
                        icon: "info",
                        text: "Please select item",
                        showConfirmButton: false,
                        timer: 1500
                    }).then((result) => {
                        return;
                    });
                }

                $("input.sev_check:checked").each(function () {
                    let barcode = $(this).closest('tr').find('td:eq(1)').text();
                    let name = $(this).closest('tr').find('td:eq(2)').text();
                    let description = $(this).closest('tr').find('td:eq(3)').text();
                    let itemlist = JSON.parse(getInventory())       
                    let product = itemlist.filter((e) => e['Barcode'].toLowerCase().trim() ==  barcode.toLowerCase().trim());
                    product = product[0];

                    let storedtransactioncollection = JSON.parse(sessionStorage.getItem('transactioncollection'))

                    if (storedtransactioncollection != null) {
                        let trans = storedtransactioncollection;
                        sessionStorage.setItem('currentsession', JSON.stringify(trans));
                    }
                    let item = {
                        "barcode": product["Barcode"].trim(),
                        "name": product["InventoryName"].trim(),
                        "inventorydesc": product["Description"].trim(),
                        "stockcode": "",
                        "price": product['Price'],
                        "price2": product['Price2'],
                        "price3": product['Price3'],
                        "price4": product['Price4'],
                        "nopriceshift": 0,
                        "categorynumber": parseInt(product["CategoryID"]),
                        "group1": product['Group1'],
                        "group2": product['Group2'],
                        "group3": product['Group3'],
                        "group4": product['Group4'],
                        "group5": product['Group5'],
                        "itemclass": 0,
                        "qty": 1,
                        "unit": "PCS",
                        "disctype": 0,
                        "discvalue": 0.00,
                        "manualdisc": 0.00,
                    }
                    AddItemProc(item);
                    sessionStorage.removeItem('currentsession');
                    /*let item = {
                        "Barcode":barcode,
                        "Name":name,
                        "Description":description,
                        "Qty":"1",
                        "Unit Price":selecteditem[0]['Price'],
                        "Amount":selecteditem[0]['Price'],
                    }
                    
                    //console.log(item)
                    loaditems([item]);
                    //calculate();*/
                    $('#modal-additem').modal('hide')
                   
                });
            });

            function loadSearchItem(inventories) {
               
                const tblbody = document.getElementById('table_body_items')
                tblbody.innerHTML = "";
                //console.log(inventories);

                inventories.sort(function(a, b) {
                    const barcodeA = a.barcode.toUpperCase(); // Ignore case
                    const barcodeB = b.barcode.toUpperCase(); // Ignore case
                    if (barcodeA < barcodeB) {
                        return -1; // nameA comes first
                    }

                    if (barcodeA > barcodeB) {
                        return 1; // nameB comes first
                    }

                    return 0;  // na
                })
                      
                $.each(inventories, function (key, detail) {
                    if (detail['qoh'] <= 0) {
                        return;
                    }
                    let tr = document.createElement("tr");

                    let tdchkitem = document.createElement("td");
                    tdchkitem.className = 'border-start border-end border-bottom  text-left px-1 py-1 align-content-center';

                    let divchkitem = document.createElement("div");
                    divchkitem.className = "checkbox text-center";

                    let labelchkitem = document.createElement("label")
                    labelchkitem.className = "form-checkbox form-icon";
                    labelchkitem.setAttribute("for", "s_fac")

                    let inputchkitem = document.createElement("input")
                    inputchkitem.id = "s_fac";
                    inputchkitem.className = "sev_check";
                    inputchkitem.type = "checkbox"

                    let tdbarcode = document.createElement("td");
                    tdbarcode.className = 'border-start border-end border-bottom  text-left px-1 py-1 align-content-center';
                    let barcode = document.createTextNode(detail['barcode'].toString().trim())
                    //let barcode = document.createTextNode(detail['Barcode'].toString().trim())

                    let tdname = document.createElement("td");
                    tdname.className = "border-start border-end border-bottom  text-left px-1 py-1 align-content-center";
                    let name = document.createTextNode(detail['name']);
                    //let name = document.createTextNode(detail['InventoryName']);

                    let tddesc = document.createElement("td")
                    tddesc.className = "border-start border-end border-bottom  text-left px-1 py-1 align-content-center";
                    let desc = document.createTextNode(detail['description']);
                    //let desc = document.createTextNode(detail['Description']);

                    let tdcategory = document.createElement("td")
                    tdcategory.className = "border-start border-end border-bottom  text-left px-1 py-1 align-content-center";
                    let category = document.createTextNode(detail['category'])

                    /*let tdprice = document.createElement("td");
                    tdprice.className = "border-start border-end border-bottom  text-left px-1 py-1 align-content-center";
                    let price = document.createTextNode(detail['price']);*/

                    tdchkitem.appendChild(divchkitem);
                    divchkitem.appendChild(labelchkitem);
                    labelchkitem.appendChild(inputchkitem);

                    tdbarcode.appendChild(barcode);
                    tdname.appendChild(name)
                    tddesc.appendChild(desc);
                    tdcategory.appendChild(category);
                    //tdprice.appendChild(price);

                    tr.appendChild(tdchkitem);
                    tr.appendChild(tdbarcode);
                    tr.appendChild(tdname);
                    tr.appendChild(tddesc);
                    tr.appendChild(tdcategory);
                    //tr.appendChild(tdprice);

                    tblbody.appendChild(tr);

                })

            }

            function getDateTime() {
                var now = new Date();
                var year = now.getFullYear();
                var month = now.getMonth() + 1;
                var day = now.getDate();
                var hour = now.getHours();
                var minute = now.getMinutes();
                var second = now.getSeconds();
                if (month.toString().length == 1)

                {
                    month = '0' + month;
                }

                if (day.toString().length == 1) {
                    day = '0' + day;
                }

                if (hour.toString().length == 1) {
                    hour = '0' + hour;
                }

                if (minute.toString().length == 1) {
                    minute = '0' + minute;
                }

                if (second.toString().length == 1) {
                    second = '0' + second;
                }

                var dateTime = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
                return dateTime;
            }

            function getInventory() {
                var responseVal;
                var response = $.ajax({
                    type: "POST",
                    url: "SalesInvoice.aspx/getInventories",
                    async: false,
                    contentType: 'application/json;charset=utf8',
                    beforeSend: function () {
                        //modalLoad.style.display = "block";
                    },
                    complete: function (result) {
                        // modalLoad.style.display = "none";
                    },
                    dataType: 'json',
                    error: function (jqXHR, textStatus, errorThrown) {
                        console.log(errorThrown);
                    },
                    success: function (result) {
                       responseVal = result.d;
                    }
                });
                return responseVal;
            };

            function getCategory() {
                var responseVal;
                var response = $.ajax({
                    type: "POST",
                    url: "SalesInvoice.aspx/getCategories",
                    async: false,
                    contentType: 'application/json;charset=utf8',
                    beforeSend: function () { },
                    complete: function (result) {
                        // modalLoad.style.display = "none";

                    },
                    dataType: 'json',
                    error: function (jqXHR, textStatus, errorThrown) {
                        console.log(errorThrown);
                    },
                    success: function (result) {
                        responseVal = result.d;
                        // sessionStorage.setItem('category', result.d);
                    }
                });
                return responseVal;
            }

            function getInventoryCostAverage() {
                var responseVal;
                var response = $.ajax({
                    type: "POST",
                    url: "SalesInvoice.aspx/getInventoryCostAverage",
                    async: false,
                    contentType: 'application/json;charset=utf8',
                    beforeSend: function () {
                        //modalLoad.style.display = "block";
                    },
                    complete: function (result) {
                      
                    },
                    dataType: 'json',
                    error: function (jqXHR, textStatus, errorThrown) { console.log(errorThrown); },
                    success: function (result) { 
                          responseVal = result.d;
                    }
                });
                return responseVal;
            }

            function getInventoryStockAdjustDetail() {
                 var responseVal;
                var response = $.ajax({
                    type: "POST",
                    url: "SalesInvoice.aspx/getInventoryCostAverageDetail",
                    async: false,
                    contentType: 'application/json;charset=utf8',
                    beforeSend: function () {
                        //modalLoad.style.display = "block";
                    },
                    complete: function (result) {
                        // modalLoad.style.display = "none";

                    },
                    dataType: 'json',
                    error: function (jqXHR, textStatus, errorThrown) {
                        console.log(errorThrown);
                    },
                    success: function (result) {
                        responseVal = result.d;
                    }
                });
                return responseVal;
            }

            function GET_LASTSITrans(){
                var responseVal;
                $.ajax({
                    type: "POST",
                    url: "SalesInvoice.aspx/GET_LASTSITrans",
                    async: false,
                    contentType: 'application/json;charset=utf8',
                    beforeSend: function () {
                        //modalLoad.style.display = "block";
                    },
                    complete: function (result) {
                        // modalLoad.style.display = "none";
                    },
                    dataType: 'json',
                    error: function (jqXHR, textStatus, errorThrown) {
                        console.log(errorThrown);
                    },
                    success: function (result) {
                        if(JSON.parse(result.d) == null){
                            responseVal = 0;
                        }else{
                            responseVal = JSON.parse(result.d)['transid']
                        }
                        
                    }                            
                });
                return responseVal;
            }

            function GET_AllTax(){
                var responseVal;
                $.ajax({
                    type: "POST",
                    url: "SalesInvoice.aspx/GET_AllTax",
                    async: false,
                    contentType: 'application/json;charset=utf8',
                    beforeSend: function () {
                        //modalLoad.style.display = "block";
                    },
                    complete: function (result) {
                        // modalLoad.style.display = "none";
                    },
                    dataType: 'json',
                    error: function (jqXHR, textStatus, errorThrown) {
                        console.log(errorThrown);
                    },
                    success: function (result) {                       
                        responseVal = JSON.parse(result.d);                                             
                    }                            
                });
                return responseVal;
            }

            function POST_SITransaction(db,json){
                console.log(JSON.stringify(json))
                var returnvalue;
                $.ajax({
                    type: "POST",
                    url: "SalesInvoice.aspx/POST_SITransaction",
                    data: "{'db':'" + db + "', 'jsondata':'" + JSON.stringify(json) + "'}",
                    async: false,
                    contentType: 'application/json;charset=utf8',
                    dataType: 'json',
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                    // console.log("error")
                    },
                    success: function (result) {
                        returnvalue = result.d;
                    }
                });
                
                return returnvalue;
            }

            function InventoryWithCostDetail() {
  
                let sessioncategory = getCategory();
                let sessionitem = getInventory();
        
                let sessionica = getInventoryCostAverage();
                let sessionicadetail =getInventoryStockAdjustDetail();
                
                //console.log(sessionicadetail)
                let ica = JSON.parse(sessionica);
    
                let inventory = JSON.parse(sessionitem).filter((e) => e['Active'] != 0 && e['Barcode'].toLowerCase() != 'round' && e['Class'] == '0');
                let category = JSON.parse(sessioncategory).filter((e) => e['Active'] != 0 && e['CategoryName'].toLowerCase() != 'round');
                let icadetail = JSON.parse(sessionicadetail);
                let arrinventory = [];
                let arricadetail = [];
                
                category.forEach(function (category) {
                    inventory.forEach(function (inventory) {
                        if (category['CategoryID'] == inventory['CategoryID']) {
                            ica.forEach(function (ica) {
                                if (ica['InventoryID'] == inventory['InventoryID']) {
                                    /*arricadetail = [];
                                    icadetail.forEach(function (detail) {
                                        if (detail['inventoryid'] == ica['InventoryID']) {
                                            let icadetail = {
                                                'stockid': detail['stockid'],
                                                'inventoryid': detail['inventoryid'],
                                                'batchid': detail['batchid'].trim(),
                                                'inqty': detail['inqty'],
                                                'outqty': detail['outqty'],
                                                'unitcost': detail['unitcost'],
                                                'stockdate': detail['stockdate'].trim(),
                                                'notes': detail['notes'].trim(),
                                                'expirydate': detail['expirydate'].trim(),
                                                'expiryalarm': detail['expiryalarm']
                                            }
                                            arricadetail.push(icadetail);
                                        }
                                    });

                                    let inqty = 0;
                                    let outqty = 0;

                                    arricadetail.forEach(function (x) {
                                        inqty = inqty + x.inqty;
                                        outqty = outqty + x.outqty;

                                    });*/

                                    let item = {
                                        'inventoryid': inventory['InventoryID'],
                                        'barcode': inventory['Barcode'].trim(),
                                        'name': inventory['InventoryName'].trim(),
                                        'description': inventory['Description'].trim(),
                                        'categoryid': category['CategoryID'],
                                        'category': category['CategoryName'].trim(),
                                        //'categoryflag'
                                        //'pquantity': ica['PQuantity'],
                                        //'retailqty': ica['RetailQTY'],
                                        //'qoh': parseFloat(ica['PQuantity']) - parseFloat(ica['RetailQTY']),
                                        //'totalinqty': inqty,
                                        //'totaloutqty': outqty,
                                        //'qoh': parseFloat(inqty) - parseFloat(outqty),
                                        //'icadetail': arricadetail
                                    }
                                    arrinventory.push(item);
                                }
                            });
                        }
                    });
                });

                return arrinventory;
            }

           /* function POST_DATA(transstatus){               
                let currentdate = getDateTime();
                let transid = parseInt(GET_LASTSITrans()) + 1;;
                //if(GET_LASTSITrans() == null){
                //    transid = 1;
                //}else{
                //    transid = parseInt(GET_LASTSITrans()) + 1;
                //}
                
                //console.log(transid)
                let transno =transid;

                var table = $('#table-selecteditems').tableToJSON();  
                let transdetailArr = [];
                let itemlist = JSON.parse(getInventory());
                let categorylist = JSON.parse(getCategory())
                let subtotal = 0.00;
                let total = 0.00;
                let x = 1; 
                let selecteditems = JSON.parse(sessionStorage.getItem('selecteditems'));

                
                selecteditems.forEach(function (tbl) { 
                    let itemtaxablemaount = 0.00;
                    let taxablemaount = 0.00;
                    //let amount =0.00;

                    let barcode  = tbl["Barcode"];
                    //console.log(itemlist)
                    let item = itemlist.filter((e) => e['Barcode'].toLowerCase().trim() == barcode.toLowerCase().trim());
                    //let item = itemlist.filter((e) => e['Barcode'].toLowerCase().trim() ==  $('#input-scan').val().toLowerCase().trim());
                    let category = categorylist.filter((e) => e['CategoryID'] == item[0]["CategoryID"])
                                                                  
                    //let qty = $('#table-selecteditems').find("tr:eq(" + x + ")").find("td:eq(3)").find("input").val();
                    let qty = tbl['Qty'];
                    //let unitprice = tbl['Unit Price'];
                    let unitprice = item[0]['Price'];
                    //let amount = $('#table-selecteditems').find("tr:eq(" + x + ")").find("td:eq(5)").find("input").val();
                    let amount = parseInt(qty) * parseFloat(unitprice);
                    //subtotal = subtotal + parseFloat($('#table-selecteditems').find("tr:eq(" + x + ")").find("td:eq(6)").find("input").val());
                    let taxableamount = amount;

                    
                    //console.log(category)
                    let taxflag = category[0]['Flag1'].substring(2,category[0]['Flag1'].length)
                    for(i=0;i<6;i++){
                        console.log(taxflag.charAt(i))
                    }


                    let transdetail =   {
                            "transid": transid,
                            "itemid": x,
                            "barcode": item[0]["Barcode"].trim(),
                            "name": item[0]["InventoryName"].trim(),
                            "inventorydesc": item[0]["Description"].trim(),
                            "stockcode": "",
                            "nopriceshift": 0,
                            "categorynumber": parseInt(item[0]["CategoryID"]),
                            "group1": "",
                            "group2": "",
                            "group3": "",
                            "group4": "",
                            "group5": "",
                            "itemclass": 0,
                            "qty": parseInt(qty),
                            "unit": "PCS",
                            "pricetype": 0,
                            "price": parseFloat(unitprice),
                            "actualprice": parseFloat(unitprice),
                            "amount": parseFloat(amount),
                            "shiftmixedflag": 0,
                            "quantityshifttype": 0,
                            "shiftvalue": 0,
                            "odddisc": 0,
                            "realprice": 0,
                            "quantityfrom": 0,
                            "description": "",
                            "discqty": 0,
                            "psdiscamount": 0,
                            "psdiscvalue": 0,
                            "actualpsdiscamount": 0,
                            "qtyremain": 0,
                            "totalsoldqty": 0,
                            "totaldiscqty": 0,
                            "disctype": 0,
                            "discvalue": 0,
                            "manualdisc": 0,
                            "points": 0,
                            "checkout": 0,
                            "takeaway": 0,
                            "memberdisc": 0,
                            "salesman": 0,
                            "ordertime": 0,
                            "printed": 0,
                            "bufferprinted": 0,
                            "priceid": 0,
                            "condimented": 0,
                            "kitchenprint": 0,
                            "kitchenprintflag": category[0]['Flag2'],
                            "taxamount1": 0,
                            "taxamount2": 0,
                            "taxamount3": 0,
                            "taxamount4": 0,
                            "taxamount5": 0,
                            "taxamount6": 0,
                            "itemstatus": 0,
                            "taxableamount": parseFloat(taxableamount),
                            "taxflag":taxflag,
                            "taxinfo": tbl['taxinfo'],
                            "parentid": 0,
                            "printedvoid": 0,
                            "voiddate": currentdate,
                            "allowdecimalvalue": 0,
                            "totaldisc": 0,
                            "totalmemberdisc": 0,
                            "totalpsdisc": 0,
                            "rdpoints": 0,
                            "itemscdiscamount": 0,
                            "itemscdiscvalue": 0,
                            "itemsccovers": 0,
                            "itemscrettaxamount": 0,
                            "warranty": 0,
                            "unitcost": 0,
                            "managerid": 0,
                            "managername": "",
                            "kitchenstatus": 0,
                            "firequantity": 0,
                            "commission": 0,
                            "commissionvalue": 0,
                            "kdsitemstatus": 0,
                            "kdsdoneqty": 0,
                            "kdsitempriority": 0,
                            "kdsitemcmpttime": "",
                            "mparentid": 0,
                            "mchildid": 0,
                            "marginrate": 0,
                            "siTransdetailCondimentList":[]
                    }
                    //console.log(transdetail)
                    transdetailArr.push(transdetail);
                    x = x +1;
                });
                 
                transdetailArr.forEach((item) => {
                    subtotal = subtotal + parseFloat(item['amount']);
                    total = subtotal;
                });
                
                let trans = {
                    "siTransdetailList": transdetailArr,
                    "transid": transid,
                    "transno": transno,
                    "termid": 0,
                    "transdate": currentdate,
                    "lastdate":currentdate,
                    "transtime": currentdate,
                    "customernumber": "",
                    "cashierid": 0,
                    "cashiername": "",
                    "salespersonid": 0,
                    "salespersonname": "",
                    "hassalesman": 0,
                    "subtotal": subtotal,
                    "taxamount1": 0,
                    "taxamount2": 0,
                    "taxamount3": 0,
                    "taxamount4": 0,
                    "taxamount5": 0,
                    "taxamount6": 0,
                    "total": subtotal,
                    "disctype": 0,
                    "discamount": 0,
                    "discvalue": 0,
                    "points": 0,
                    "transstatus": transstatus,
                    "manualkey": "",
                    "checkout": 0,
                    "round": 0,
                    "memberdiscamount": 0,
                    "memberdiscvalue": 0,
                    "birthdaydiscamount": 0,
                    "birthdaydiscvalue": 0,
                    "scdiscamount": 0,
                    "scdiscvalue": 0,
                    "sccovers": 0,
                    "screttaxamount": 0,
                    "asdiscamount": 0,
                    "asdiscvalue": 0,
                    "printed": 0,
                    "covers": 0,
                    "notes": "",
                    "paidtotal": 0,
                    "timestampid": 0,
                    "businessdate": currentdate,
                    "vouchertotal": 0,
                    "rdpointstotal": 0,
                    "rdflag": 0,
                    "rdpointsamount": 0,
                    "rdpointvalue": 0,
                    "tablemenuid": "",
                    "delivercustno": "",
                    "pddiscamount": 0,
                    "pddiscvalue": 0,
                    "pdcovers": 0,
                    "gerettaxamount": 0,
                    "gecovers": 0,
                    "managerid": 0,
                    "managername": "",
                    "sendflag": 0,
                    "edittransid": 0,
                    "orderid": 0,
                    "kioskorderno": "",
                    "splitbill": 0,
                    "duedays": 0,
                    "duetype": "",
                    "previouspoints": 0,
                    "kdsorderstatus": 0,
                    "kdspriority": 0,
                    "kdscmpttime":  currentdate,
                    "pdrettaxamount": 0,
                    "doaddress": "",
                    "printhold": 0,
                    "advcustomerid": "",
                    "advcountrycode": "",
                    "advsvbal": 0,
                    "advvbal": 0,
                    "advlpoints": 0,
                    "advllpoints": 0,
                    "advlpid": "",
                    "advlprid": "",
                    "advskurid": "",
                    "advcashback": 0,
                    "advlcashback": 0,
                    "advcbid": "",
                    "advcbrid": "",
                    "stbcpprev": 0,
                    "stbcpbal": 0,
                    "kiosktakeaway": 0,
                    "advvourid": "",
                    "kdsprinttimes": 0,
                    "stbcporderno": "",
                    "depprevbal": 0,
                    "depbal": 0,
                    "webtransid": "",
                    "issync": 0,
                    "navsync": 0,
                    "rsgid": "",
                    "rsgvoucher": "",
                    "rsgvalue": 0,
                    "rsgforfeit": 0,
                    "rsgstatus": 0   
                }        
         
                return POST_SITransaction("da1",trans)
             }    */   

    });
    </script>
    <%--PDF Generator--%>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
    <script src="https://unpkg.com/jspdf"></script>
    <script src="https://unpkg.com/jspdf-autotable"></script>
    <script src="https://unpkg.com/jspdf-autotable@3.5.22/dist/jspdf.plugin.autotable.js"></script>
</asp:Content>

