HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/unbox/uc-live/admin-dash/add-invoice.php
<?php
include('header.php');
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
session_start();

date_default_timezone_set('Asia/Calcutta');
$curDateTime = date('Y-m-d H:i:s'); // add 5 hrs 30 min in curr time

if (date('m') < 4) { //Upto April
    $financial_year = date('Y');
} else { //After April 
    $financial_year = (date('Y') + 1);
}

// $month = date('m');
// $day = date('d');
// $year = date('Y');
// $today = $year . '-' . $month . '-' . $day . 'T' . date("h:i:a");
// update all data
if (isset($_POST['submitData'])) {
    // print_r($_POST);
    $domain = $_POST['i_domain'];
    $vendor = $_POST['i_vendor'];
    $paymenType = $_POST['i_paytype'];
    $paytype_new = $_POST['i_paytype_new'];
    $gateway = $_POST['i_gateway'];
    $orderId = $_POST['i_orderId'];
    $txn = $_POST['i_txn'];
    $invc_date = date("Y-m-d H:i:s", strtotime($_POST['i_invc_date']));
    $txn_date = date("Y-m-d H:i:s", strtotime($_POST['i_txn_date']));
    $name = $_POST['i_name'];
    $email = $_POST['i_email'];
    $mobile = $_POST['i_mobile'];
    $state = $_POST['i_state'];
    $address = $_POST['i_address'];
    $gst_name = $_POST['i_gst_name'];
    $gstin = $_POST['i_gstin'];
    $remark = $_POST['i_remark'];
    $product_mrp = $_POST['i_product_mrp'];
    $product_desc = $_POST['i_product_desc'];    
    $txn_type = $_POST['i_txn_type'];;
    $transaction_type = ($txn_type != '') ? $txn_type : $product_desc;
    $orderType = $_POST['i_order_type'];
    $gst = $_POST['i_gst'];
    $igst_amnt = $_POST['i_igst_amnt'];
    $cgst_amnt = $_POST['i_cgst_amnt'];
    $sgst_amnt = $_POST['i_sgst_amnt'];
    $disc_amnt = ($_POST['i_disc_amnt'] != '') ? $_POST['i_disc_amnt'] : 0;
    $paytype = ($paymenType == '1') ? $paytype_new : $paymenType;
    $payment_for = '';

    if (empty($domain)) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Domain Required.</strong></div>';
    } else if (empty($vendor)) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Vendor Required.</strong></div>';
    } else if (empty($paytype)) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Payment Type Required.</strong></div>';
    } else if (empty($txn_date)) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Transaction Date Required.</strong></div>';
    } else if (empty($invc_date)) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Invoice Date Required.</strong></div>';
    } else if (empty($name)) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Customer Name Required.</strong></div>';
    } else if (empty($mobile)) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Customer Mobile Required.</strong></div>';
    } else if ($state == '' || $state == '0') {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Customer State Required.</strong></div>';
    } else if ($product_mrp == '' || $product_mrp == 0) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Amount Rate Required.</strong></div>';
    } else if (empty($product_desc)) {
        $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Product Description Required.</strong></div>';
    } else {
        $checkExist = $wpdb->get_var("SELECT invoice_id from unbox_invoice where customer_name='$name' and customer_mobile= '$mobile' and customer_state_id='$state' and invoice_status='2' and from_domain='$domain' and if_vendor='$vendor' and product_mrp='$product_mrp'");
        if ($checkExist == '') {
            if ($igst_amnt == '' || $igst_amnt == 0) {
                if ($orderType == 'bulk') {
                    $taxable_amount = $product_mrp;
                    $net_amount = $product_mrp + $cgst_amnt + $sgst_amnt;
                } else if ($orderType == 'retail') {
                    $taxable_amount =  $product_mrp * (100 / (100 + $gst));
                    $net_amount = $product_mrp;
                }
                // echo '1gst_amnt' . $taxable_amount . ' = ' . $product_mrp . ' = ' . $cgst_amnt . ' = ' . $sgst_amnt . ' = ' . $net_amount . '<br/>';
            } else if ($igst_amnt != '' || $igst_amnt != 0) {
                if ($orderType == 'bulk') {
                    $taxable_amount = $product_mrp;
                    $net_amount = $product_mrp + $igst_amnt;
                } else if ($orderType == 'retail') {
                    $taxable_amount = $product_mrp * (100 / (100 + $gst));
                    $net_amount = $product_mrp;
                }
                // echo '2gst_amnt' . $taxable_amount . ' = ' . $product_mrp . ' = ' . $igst_amnt . ' = ' . ' = ' . $net_amount . '<br/>';
            }

            $stateQry = $wpdb->get_row("SELECT state_code, state_name FROM uc_states WHERE state_id='$state'");
            $insertQry = "INSERT INTO unbox_invoice SET from_domain='$domain', if_vendor='$vendor', payment_type='$paytype', payment_for='$payment_for', transaction_type='$transaction_type',order_id='$orderId', payment_gateway_name='$gateway', product_mrp='$product_mrp', gst_rate='$gst', igst_amount='$igst_amnt', cgst_amount='$cgst_amnt', sgst_amount='$sgst_amnt', taxable_amount='$taxable_amount', discount_amount='$disc_amnt', net_amount='$net_amount', customer_name='$name', customer_address='$address', customer_mobile= '$mobile', customer_email='$email', customer_gst_name='$gst_name', customer_gstin='$gstin', customer_state_code ='$stateQry->state_code', customer_state_name='$stateQry->state_name', customer_state_id='$state', transaction_id1='$txn', invoice_status='2', transaction_date='$txn_date', invoice_issue_date='$invc_date', year_extn='$financial_year', system_datetime='$curDateTime', ref_name1='if_any_remark', ref_id1= '$remark', ref_name2='order_type',ref_id2='$orderType', ref_name3='product description', ref_id3='$product_desc', last_update_date='$curDateTime', source='M'";
            // echo $insertQry;
            if ($wpdb->query($insertQry)) {
                $msg = '<div class="alert alert-success alert-dismissible show"><strong>Data Insert Successfully</strong></div>';
            } else {
                $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Data Not Insert Successfully</strong></div>';
            }
        } else {
            $msg = '<div class="alert alert-danger alert-dismissible show"><strong>Data Already Inserted</strong></div>';
        }
    }
}

// $getDomain = $wpdb->get_results("SELECT DISTINCT from_domain FROM unbox_invoice");
// $getVendor = $wpdb->get_results("SELECT DISTINCT if_vendor FROM unbox_invoice");
// $geTransaction = $wpdb->get_results("SELECT DISTINCT transaction_type FROM unbox_invoice");
$getPayment = $wpdb->get_results("SELECT DISTINCT payment_type FROM unbox_invoice WHERE payment_type != ''");
$getState = $wpdb->get_results("SELECT state_id, state_name FROM uc_states");

include('sidebar.php'); ?>
<style>
    input[type=number]::-webkit-inner-spin-button,
    input[type=number]::-webkit-outer-spin-button {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        margin: 0;
    }

    .boxShodow {
        margin-bottom: 2em;
    }

    .table-responsive {
        box-shadow: 0 0 10px 0 rgba(183, 192, 206, 0.2);
        padding: 20px;
        border-radius: 4px;
    }

    table {
        width: 100%;
        border: 1px solid #d6d9db;
        text-align: center;
    }

    .table> :not(caption)>*>* {
        padding: 8px !important;
    }

    table th,
    table td {
        border: 1px solid #d6d9db;
        font-size: 13px !important;
    }

    .table th {
        color: #000 !important;
    }

    table td input,
    table td select {
        font-size: 13px !important;
    }

    .submit_formBtn {
        font-size: 14px;
        font-weight: 500;
        border-radius: 4px;
        border: none;
        background-color: #5660d9;
        color: #fff;
        padding: 10px;
        margin-top: 16px;
        float: right;
    }

    .add_product {
        font-size: 13px;
        font-weight: 500;
        border-radius: 4px;
        border: none;
        background-color: #0ebb0e;
        color: #fff;
        padding: 4px 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

    .stretch-card .card-titles {
        text-align: center;
        font-size: 20px;
        margin-bottom: 1em;
        text-decoration: underline;
    }

    .form-control,
    .typeahead.tt-input,
    .typeahead.tt-hint,
    .select2-container--default .select2-search--dropdown .select2-search__field,
    .form-select,
    .form-label {
        font-size: 13px !important;
    }
</style>
<div class="page-wrapper">
    <?php include('navbar.php'); ?>

    <div class="page-content">
        <nav class="page-breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="add-invoice.php">Invoice</a></li>
                <li class="breadcrumb-item active" aria-current="page">Add Invoice</li>
            </ol>
        </nav>

        <div class="row">
            <div class="col-md-12 stretch-card">
                <div class="card">
                    <div class="card-body">
                        <div class="col-lg-12">
                            <h6 class="card-titles">Add Invoice</h6>
                            <?php if (isset($msg)) {
                                echo $msg;
                            } ?>
                        </div>
                        <form method="post">
                            <div class="row">
                                <div class="row boxShodow">
                                    <div class="col-md-12">
                                        <h6 class="card-title">Bill By</h6>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Domain Name<span style="color:red;">*</span></label>
                                            <select class="form-select mb-3" name="i_domain" id="i_domain">
                                                <option value="0" selected="">Select Domain Name</option>
                                                <option value="https://selfanalyse.com/">https://selfanalyse.com/</option>
                                                <option value="https://unboxcatalysts.com/">https://unboxcatalysts.com/</option>
                                                <option value="https://mereyram.com/">https://mereyram.com/</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Vendor<span style="color:red;">*</span></label>
                                            <select class="form-select mb-3" name="i_vendor" id="i_vendor">
                                                <option value="0" selected="">Select Vendor</option>
                                                <option value="SA">SA</option>
                                                <option value="Unbox">Unbox</option>
                                                <option value="MR">MR</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Payment Gateway Name</label>
                                            <input type="text" class="form-control" name="i_gateway" id="i_gateway" placeholder="like cash, paytm, csc, credit-card, credit">
                                        </div>
                                    </div>
                                    <div class="col-sm-3">
                                        <div class="mb-3">
                                            <label class="form-label">Payment Type<span style="color:red;">*</span></label>
                                            <select class="form-select mb-3" name="i_paytype" id="i_paytype" style="display:block;">
                                                <option value="0" selected>Select Payment Type</option>
                                                <?php foreach ($getPayment as $p) { ?>
                                                    <option value="<?php echo $p->payment_type; ?>"><?php echo $p->payment_type; ?></option>
                                                <?php } ?>
                                                <option value="1">Add More</option>
                                            </select>
                                            <input type="text" class="form-control" name="i_paytype_new" id="i_paytype_new" placeholder="Enter Payment Type" style="display:none;">
                                        </div>
                                    </div>                                    
                                    <div class="col-sm-3">
                                        <div class="mb-3">
                                            <label class="form-label">Transaction Type</label>
                                            <input type="text" class="form-control" name="i_txn_type" id="i_txn_type" placeholder="Enter Transaction Type" value="<?php echo $getInvoice->transaction_type; ?>">
                                        </div>
                                    </div>
                                    <div class="col-sm-3">
                                        <div class="mb-3">
                                            <label class="form-label">Order Id </label>
                                            <input type="text" class="form-control" name="i_orderId" id="i_orderId" placeholder="Enter Order Id">
                                        </div>
                                    </div>
                                    <div class="col-sm-3">
                                        <div class="mb-3">
                                            <label class="form-label">Transaction Id</label>
                                            <input type="text" class="form-control" name="i_txn" id="i_txn" placeholder="Enter Transaction Id">
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Transaction Date<span style="color:red;">*</span></label>
                                            <input type="datetime-local" class="form-control" name="i_txn_date" id="i_txn_date">
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Invoice Issue Date<span style="color:red;">*</span></label>
                                            <input type="datetime-local" class="form-control" name="i_invc_date" id="i_invc_date">
                                        </div>
                                    </div>

                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Order Type</label>
                                            <select class="form-select" name="i_order_type" id="i_order_type">
                                                <option value="bulk" selected>Bulk</option>
                                                <option value="retail">Retail</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="row boxShodow">
                                    <div class="col-md-12">
                                        <h6 class="card-title">Bill To</h6>
                                    </div>

                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Name <span style="color:red;">*</span></label>
                                            <input type="text" class="form-control" name="i_name" id="i_name" placeholder="Enter Name">
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Mobile <span style="color:red;">*</span></label>
                                            <input type="text" class="form-control" name="i_mobile" id="i_mobile" placeholder="Enter Mobile">
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">Email</label>
                                            <input type="email" class="form-control" name="i_email" id="i_email" placeholder="Enter Email">
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">State <span style="color:red;">*</span></label>
                                            <select class="form-select mb-3" name="i_state" id="i_state">
                                                <option value="0" selected>Select State</option>
                                                <?php foreach ($getState as $s) { ?>
                                                    <option value="<?php echo $s->state_id; ?>"><?php echo $s->state_name; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">GST Name</label>
                                            <input type="text" class="form-control" name="i_gst_name" id="i_gst_name" placeholder="Enter GST Name">
                                        </div>
                                    </div>

                                    <div class="col-sm-4">
                                        <div class="mb-3">
                                            <label class="form-label">GSTIN</label>
                                            <input type="text" class="form-control" name="i_gstin" id="i_gstin" placeholder="Enter GSTIN">
                                        </div>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="mb-3">
                                            <label class="form-label">Remark</label>
                                            <input type="text" class="form-control" name="i_remark" id="i_remark" placeholder="Remark">
                                        </div>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="mb-3">
                                            <label for="i_address" class="form-label">Address</label>
                                            <input type="text" class="form-control" name="i_address" id="i_address" placeholder="Enter Address">
                                        </div>
                                    </div>
                                </div>
                                <div class="table-responsive">
                                    <div class="col-md-12">
                                        <h6 class="card-title">Product Details</h6>
                                    </div>
                                    <table class="table table-striped">
                                        <thead>
                                            <tr>
                                                <th>DESCRIPTION<span style="color:red;">*</span></th>
                                                <th style="width:8%;">AMOUNT<span style="color:red;">*</span></th>
                                                <th style="width:8%;">GST RATE</th>
                                                <th style="width:8%;">IGST</th>
                                                <th style="width:8%;">SGST</th>
                                                <th style="width:8%;">CGST</th>
                                                <th style="width:10%;">DISCOUNT AMT</th>
                                                <th style="width:10%;">TAXABLE Amt</th>
                                                <th>Amount</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td><input type="text" class="form-control" name="i_product_desc" id="i_product_desc" placeholder="Enter Product"></td>
                                                <td><input type="number" class="form-control" name="i_product_mrp" id="i_product_mrp" placeholder="Amount" oninput="getTotal()"></td>
                                                <td>
                                                    <select class="form-select" name="i_gst" id="i_gst">
                                                        <option value="5">5</option>
                                                        <option value="12">12</option>
                                                        <option value="18" selected>18</option>
                                                        <option value="28">28</option>
                                                    </select>
                                                </td>
                                                <td><input type="number" step="0.01" class="form-control" name="i_igst_amnt" id="i_igst_amnt" placeholder="IGST"></td>
                                                <td><input type="number" step="0.01" class="form-control" name="i_sgst_amnt" id="i_sgst_amnt" placeholder="SGST"></td>
                                                <td><input type="number" step="0.01" class="form-control" name="i_cgst_amnt" id="i_cgst_amnt" placeholder="CGST"></td>
                                                <td><input type="number" step="0.01" class="form-control" name="i_disc_amnt" id="i_disc_amnt" placeholder="Discount Amount"></td>
                                                <td style="font-weight: 700;"><input type="number" class="form-control" name="i_tax_amnt" id="i_tax_amnt" placeholder="Taxable Amount" readonly></td>
                                                <td style="font-weight: 700;"><input type="number" class="form-control" name="total_amnt" id="total_amnt" placeholder="Total Amount" readonly></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <!-- <div><button class="add_product"><span style="font-size: 22px;">+</span> Add Product</button></div> -->
                                </div>
                            </div>
                            <button type="submit" name="submitData" class="submit_formBtn">Submit form</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <?php include('footer.php'); ?>

    <script>
        function blankValue() {
            document.getElementById("i_igst_amnt").value = '';
            document.getElementById("i_sgst_amnt").value = '';
            document.getElementById("i_cgst_amnt").value = '';
            document.getElementById("i_tax_amnt").value = '';
            document.getElementById("i_disc_amnt").value = '';
            document.getElementById("total_amnt").value = '';
            document.getElementById("i_product_mrp").value = '';
        }
        /************ on change event for state to get city ***********/
        jQuery(document).on('change', '#i_state', function() {
            // var state_id = jQuery(this).val();
            blankValue();
        });

        /************ on change event for payment typ to get input field       ***********/
        jQuery(document).on('change', '#i_paytype', function() {
            blankValue();
            var order_id = jQuery(this).val();
            if (order_id == "1") {
                $("#i_paytype").hide();
                $("#i_paytype_new").show();
            } else {
                $("#i_paytype").show();
                $("#i_paytype_new").hide();
            }
        });

        /************ on change event for ordertype to get section ***********/
        jQuery(document).on('change', '#i_order_type', function() {
            var order_id = jQuery(this).val();
            blankValue();
            // if (order_id == "retail") {
            //     // $(".gst_head").hide();
            //     // $(".gst_body").hide();
            //     blankValue();
            // } else if (order_id == "bulk") {
            //     // $(".gst_head").show();
            //     // $(".gst_body").show();
            //     blankValue();
            // }
        });

        /************ on change event for gst to get gst rate ***********/
        jQuery(document).on('change', '#i_gst', function() {
            var gst_val = jQuery(this).val();
            getTotal();
        });

        // to get total oninput of rate
        function getTotal() {
            var total = 0;
            var gstAmount = 0;
            var state = document.getElementById("i_state").value;
            var gst = Number(document.getElementById("i_gst").value);
            var order_type = document.getElementById("i_order_type").value;
            var amount = Number(document.getElementById("i_product_mrp").value);
            // console.log(typeof gst + ' = ' + typeof amount + ' = ' + typeof gstAmount);

            if (state == 0 || state == '') {
                blankValue();
                alert('Select State First');
                document.getElementById("i_state").style.border = "#e66262 1px solid";
                document.getElementById("i_state").focus();
            } else {
                if (order_type == "bulk") {
                    gstAmount = amount * (gst / 100);
                    if (state == 36) {
                        var tax_amount = amount;
                        var igst_amount = 0;
                        var cgst_amount = amount * ((gst / 2) / 100);
                        var sgst_amount = amount * ((gst / 2) / 100);
                        total = amount + cgst_amount + sgst_amount;
                    } else {
                        var tax_amount = amount;
                        var cgst_amount = 0;
                        var sgst_amount = 0;
                        var igst_amount = gstAmount;
                        total = amount + gstAmount;
                        // console.log(state + ' =2= ' + gst + ' = ' + amount + ' = ' + tax_amount + ' = ' + cgst_amount + ' = ' + sgst_amount + ' = ' + igst_amount + ' = ' + total + ' = ' + gstAmount);
                    }
                } else if (order_type == "retail") {
                    var tax_amount = amount * (100 / (100 + gst));
                    gstAmount = amount - tax_amount;
                    if (state == 36) {
                        var igst_amount = 0;
                        var cgst_amount = tax_amount * ((gst / 2) / 100);
                        var sgst_amount = tax_amount * ((gst / 2) / 100);
                        total = tax_amount + cgst_amount + sgst_amount;
                    } else {
                        var cgst_amount = 0;
                        var sgst_amount = 0;
                        var igst_amount = gstAmount;
                        total = tax_amount + gstAmount;
                        // console.log(state + ' =2= ' + gst + ' = ' + amount + ' = ' + tax_amount + ' = ' + cgst_amount + ' = ' + sgst_amount + ' = ' + igst_amount + ' = ' + total + ' = ' + gstAmount);
                    }
                }
            }
            document.getElementById("i_igst_amnt").value = parseFloat(igst_amount).toFixed(2);
            document.getElementById("i_sgst_amnt").value = parseFloat(sgst_amount).toFixed(2);
            document.getElementById("i_cgst_amnt").value = parseFloat(cgst_amount).toFixed(2);
            document.getElementById("total_amnt").value = parseFloat(total).toFixed(2);
            document.getElementById("i_tax_amnt").value = parseFloat(tax_amount).toFixed(2);
        }
    </script>
    </body>

    </html>