MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/.nvm/../public_html/invoice/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/.nvm/../public_html/invoice/get_customer_alreadyadress.php
<?php
header('Content-Type: application/json');
error_reporting(E_ALL);
ini_set('display_errors', 1);

require 'db.php';

if (isset($_GET['id'])) {
    $customerId = intval($_GET['id']);
    if ($customerId <= 0) {
        echo json_encode(['error' => 'Invalid Customer ID']);
        exit;
    }

    $query = "SELECT c.*, ca.address, ca.city, ca.pincode, ca.state, ca.is_billing, ca.id as caid
              FROM customers c
              LEFT JOIN customer_addresses ca ON c.id = ca.customer_id
              WHERE c.id = ?";
    
    $stmt = $con->prepare($query);
    if (!$stmt) {
        echo json_encode(['error' => 'SQL Prepare Failed: ' . $con->error]);
        exit;
    }

    $stmt->bind_param("i", $customerId);
    $stmt->execute();
    $result = $stmt->get_result();

    if (!$result) {
        echo json_encode(['error' => 'Query Execution Failed: ' . $stmt->error]);
        exit;
    }

    $customerHtml = "";
    $billingAddress = "";
    $shippingAddress = "";
    $defaultAddress = "";
    $billingAdd = '';
    $hasBilling = false; 

    while ($row = $result->fetch_assoc()) {
        $customerHtml = "
            <div class='form-group pt-5 row'>
                <h2 class='pb-4'>Bill Address</h2>
                <div class='col-md-6'>
                    <label class='form-label'>Name</label>
                    <input type='text' class='form-control mb-3' name='customer_name' value='{$row['name']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Email</label>
                    <input type='text' class='form-control mb-3' name='customer_email' value='{$row['email']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Phone</label>
                    <input type='text' class='form-control mb-3' name='customer_phone' value='{$row['phone']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Address</label>
                    <input type='text' class='form-control mb-3' name='customer_billing_address' value='{$row['billing_address']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>City</label>
                    <input type='text' class='form-control mb-3' name='customer_billing_city' value='{$row['billing_city']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>State</label>
                    <input type='text' class='form-control mb-3' name='customer_billing_state' value='{$row['billing_state']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Pincode</label>
                    <input type='text' class='form-control mb-3' name='customer_billing_pincode' value='{$row['billing_pincode']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>GST Number</label>
                    <input type='text' class='form-control mb-3' name='customer_gst' value='{$row['gst_number']}' >
                </div>
            </div>
            ";

        $addressHtml = "
            <div class='form-group pt-5 row'>
                <h2 class='pb-4'>Ship Address</h2>
                <div class='col-md-6'>
                    <label class='form-label'>Shipping Name</label>
                    <input type='text' class='form-control mb-3' required name='shipping_name' value='{$row['name']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Shipping City</label>
                    <input type='text' class='form-control mb-3' name='shipping_city' value='{$row['city']}' >
                </div>
                <div class='col-md-12'>
                    <label class='form-label'>Shipping Address</label>
                    <input type='text' class='form-control mb-3' name='shipping_address' value='{$row['address']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Shipping State</label>
                    <input type='text' class='form-control mb-3' name='shipping_state' value='{$row['state']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Shipping Pincode</label>
                    <input type='text' class='form-control mb-3' name='shipping_pincode' value='{$row['pincode']}' >
                </div>
                <div class='col-md-6'>
                    <input type='hidden' name='customer_add' value='{$row['caid']}'>
                </div>
            </div>
            ";

        $billingAdd = "
            <div class='form-group pt-5 row'>
                <h2 class='pb-4'>Ship Address</h2>
                <div class='col-md-6'>
                    <label class='form-label'>Shipping Name</label>
                    <input type='text' class='form-control mb-3' required name='shipping_name' value='{$row['name']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Shipping City</label>
                    <input type='text' class='form-control mb-3' name='shipping_city' value='{$row['billing_city']}' >
                </div>
                <div class='col-md-12'>
                    <label class='form-label'>Shipping Address</label>
                    <input type='text' class='form-control mb-3' name='shipping_address' value='{$row['billing_address']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Shipping State</label>
                    <input type='text' class='form-control mb-3' name='shipping_state' value='{$row['billing_state']}' >
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Shipping Pincode</label>
                    <input type='text' class='form-control mb-3' name='shipping_pincode' value='{$row['billing_pincode']}' >
                </div>
            </div>
            ";
        if ($row['is_billing'] == 1) {
            $billingAddress = $addressHtml;
            $hasBilling = true;
        }
        if (!$defaultAddress) {
            $defaultAddress = $customerHtml;
        }
    }

    if (!$hasBilling) {
        $billingAddress = $billingAdd;
    }
    
    if (!$shippingAddress) {
        $shippingAddress = $defaultAddress ?: "<p>No Shipping Address Found</p>";
    }
    if ($billingAddress == "<p>No Billing Address Found</p>" && $shippingAddress != "<p>No Shipping Address Found</p>") {
        $billingAddress = $shippingAddress;
    }

    echo json_encode([
        'bill_address' => $billingAddress,
        'ship_address' => $shippingAddress
    ]);
} else {
    echo json_encode(['error' => 'No customer ID provided']);
}
?>

MMCT - 2023