EVOLUTION-NINJA
Edit File: createCustomer.php
<?php echo view('includes/sidebar'); ?> <script type="text/javascript" src="<?php echo base_url('public/assets/js/jquery-3.6.0.min.js'); ?>"></script> <script src="<?php echo base_url('public/assets/toastr/toastr.min.js');?>"></script> <link rel="stylesheet" href="<?php echo base_url('public/assets/toastr/toastr.min.css');?>"> <link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> <section class="home-section"> <div class="home-content"> <!--<i class='bx bx-menu'></i>--> </div> <div class="row m-0"> <div class="col-sm-12"> <h1 class="crt-pjt">Create Customer</h1> </div> </div> <style> .select2-container .select2-selection--single { height: 40px; border-radius: 50px !important; border: 1px solid #ccc; padding: 6px 15px; } .select2-container--default .select2-selection--single .select2-selection__rendered { line-height: 26px; } .select2-container--default .select2-selection--single .select2-selection__arrow { height: 100%; right: 10px; } #mlc.select2-hidden-accessible + .select2, #mp.select2-hidden-accessible + .select2 { width: 500px !important; } .inpfieldname { font-family: Poppins; font-size: 18px; font-weight: 500; text-align: left; color: #1F1F21; } .fieldsbox { border-radius: 23px !important; padding: 5px 10px !important; height: 45px; width: 85% } .projdetail { margin-inline: auto; margin-top: 15px; } .textfields { border-radius: 14px; } .projectinputs, .input-group { width: 93% !important; } .plus { background-color: transparent !important; padding: 2px; margin: 15px 15px; } .required-star::after { content: " *"; color: red; font-weight: bold; } @media (min-width: 768px) and (max-width: 1024px) { .fieldsbox, .projectinputs, .input-group { width: 100% !important; } } @media only screen and (max-width:620px) { .fieldsbox, .projectinputs, .input-group { width: 100% !important; } } </style> <form id="customer-form"> <div class="createproject"> <div class="row projdetail"> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">FARMER NAME</label> <input type="text" name="farmer_name" id="farmer_name" class="form-control fieldsbox" placeholder="Enter Farmer Name" oninput="this.value=this.value.replace(/[^A-Za-z\s]/g,'')" required> </div> <!--<div class="col-sm-4">--> <!-- <label class="form-label inpfieldname">FARMER SHARE AMT</label>--> <!-- <input type="number" name="share_amount" id="share_amount" class="form-control fieldsbox" placeholder="Enter Amount" required>--> <!--</div>--> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">TALUK</label> <input type="text" name="taluk" id="taluk" class="form-control fieldsbox" placeholder="Enter Taluk" required> </div> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">FARMER ADDRESS</label> <input type="text" name="address" id="address" class="form-control fieldsbox" placeholder="Enter Farmer Address" required> </div> </div> <div class="row projdetail"> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">DEALER</label> <select name="dealer_id" id="dealer_id" class="form-control fieldsbox"> <option value="">Select Dealer</option> <?php if (!empty($dealers)) : ?> <?php foreach ($dealers as $dealer): ?> <option value="<?= $dealer['id'] ?>"> <?= $dealer['name'] ?> </option> <?php endforeach; ?> <?php endif; ?> </select> </div> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">CATEGORY</label> <select name="category" id="category" class="form-control fieldsbox"> <option value="">Select Category</option> <option value="SC">SC</option> <option value="ST">ST</option> <option value="OBC">OBC</option> <option value="General">General</option> </select> </div> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">FID NO.</label> <input type="text" name="fid_no" id="fid_no" class="form-control fieldsbox" placeholder="Enter FID No"> </div> <!-- <div class="col-sm-4">--> <!-- <label class="form-label inpfieldname required-star">Farmer ID</label>--> <!--<input type="text" id="farmer_id" class="form-control fieldsbox" readonly>--> <!-- <input type="text" name="farmer_id" id="farmer_id" class="form-control fieldsbox" readonly>--> <!--</div>--> </div> <div class="row projdetail"> <!-- PRODUCT TYPE --> <div class="col-sm-4"> <label class="form-label inpfieldname required-star"> PRODUCT TYPE </label> <select name="product_type" id="product_type" class="form-control fieldsbox"> <option value=""> Select Product Type </option> </select> </div> <!-- PRODUCT MODEL --> <div class="col-sm-4"> <label class="form-label inpfieldname required-star"> PRODUCT MODEL </label> <select name="product_id" id="product_id" class="form-control fieldsbox"> <option value="">Select Product Model</option> </select> </div> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">Farmer ID</label> <!--<input type="text" id="farmer_id" class="form-control fieldsbox" readonly>--> <input type="text" name="farmer_id" id="farmer_id" class="form-control fieldsbox" readonly> </div> </div> <div class="row projdetail"> <!--<div class="col-sm-4">--> <!-- <label class="form-label inpfieldname">Unique code no.</label>--> <!--<input type="text" name="unique_code" id="unique_code" class="form-control fieldsbox" placeholder="Enter Unique code">--> <!-- <input type="text" name="unique_code" id="unique_code" class="form-control fieldsbox" readonly>--> <!--</div>--> <!-- <div class="col-sm-4">--> <!-- <label class="form-label inpfieldname required-star">AADHAAR NO.</label>--> <!-- <input type="text" name="aadhar_no" id="aadhar_no" class="form-control fieldsbox" placeholder="Enter 12 digit Aadhaar" maxlength="12"--> <!-- minlength="12"--> <!-- pattern="[0-9]{12}"--> <!-- oninput="this.value=this.value.replace(/[^0-9]/g,'')">--> <!--</div>--> </div> <div class="row projdetail"> <!--<div class="col-sm-4">--> <!-- <label class="form-label inpfieldname required-star">FARMER SHARE UTR NO.</label>--> <!-- <input type="text" name="utr_no" id="utr_no" class="form-control fieldsbox" placeholder="Enter UTR No">--> <!--</div>--> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">AADHAAR NO.</label> <input type="text" name="aadhar_no" id="aadhar_no" class="form-control fieldsbox" placeholder="Enter 12 digit Aadhaar" maxlength="12" minlength="12" pattern="[0-9]{12}" oninput="this.value=this.value.replace(/[^0-9]/g,'')"> </div> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">Chasis No.</label> <input type="text" name="chasis_no" id="chasis_no" class="form-control fieldsbox" placeholder="Enter Chasis No."> </div> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">Engine No.</label> <input type="text" name="engine_no" id="engine_no" class="form-control fieldsbox" placeholder="Enter Engine No."> </div> <!-- <div class="col-sm-4">--> <!-- <label class="form-label inpfieldname required-star">Farmer ID</label>--> <!--<input type="text" id="farmer_id" class="form-control fieldsbox" readonly>--> <!-- <input type="text" name="farmer_id" id="farmer_id" class="form-control fieldsbox" readonly>--> <!--</div>--> </div> <!-- <div class="col-sm-4"> <label class="form-label inpfieldname">FARMER SHARE UTR NO.</label> <input type="text" name="utr_no" id="utr_no" class="form-control fieldsbox" placeholder="Enter UTR No"> </div> <div class="col-sm-4"> <label class="form-label inpfieldname">Chasis No.</label> <input type="text" name="chasis_no" id="chasis_no" class="form-control fieldsbox" placeholder="Enter Chasis No."> </div> --> <div class="row projdetail"> <!-- RC PRICE --> <div class="col-sm-4"> <label class="form-label inpfieldname"> RC PRICE </label> <input type="text" name="rc_price" id="rc_price" class="form-control fieldsbox" readonly> </div> <!-- GST --> <div class="col-sm-4"> <label class="form-label inpfieldname"> GST % </label> <input type="text" name="gst_percent" id="gst_percent" class="form-control fieldsbox" readonly> </div> <!-- BASIC PRICE --> <div class="col-sm-4"> <label class="form-label inpfieldname"> BASE PRICE </label> <input type="text" name="basic_price" id="basic_price" class="form-control fieldsbox" readonly> </div> </div> <div class="row projdetail"> <!-- Aadhaar Number --> <!--<div class="col-sm-4">--> <!-- <label class="form-label inpfieldname required-star">AADHAAR NO.</label>--> <!-- <input type="text" name="aadhar_no" id="aadhar_no" class="form-control fieldsbox" placeholder="Enter 12 digit Aadhaar" maxlength="12"--> <!-- minlength="12"--> <!-- pattern="[0-9]{12}"--> <!-- oninput="this.value=this.value.replace(/[^0-9]/g,'')">--> <!--</div>--> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">Phone No</label> <input type="text" name="phone_no" id="phone_no" class="form-control fieldsbox" placeholder="Enter Mobile Number" maxlength="10" minlength="10" pattern="[0-9]{10}" oninput="this.value=this.value.replace(/[^0-9]/g,'')" required> </div> <!-- Photo Upload --> <div class="col-sm-4"> <label class="form-label inpfieldname required-star">UPLOAD PHOTO</label> <input type="file" name="photo" id="photo" class="form-control fieldsbox" accept="image/*"> </div> <div class="col-sm-4"> <label class="form-label inpfieldname"> UPLOAD INVOICE </label> <input type="file" name="invoice_file" id="invoice_file" class="form-control fieldsbox" accept=".pdf,.jpg,.jpeg,.png"> </div> </div> <div class="col-sm-6 buttns-cnl mt-4"> <button type="submit" class="submit">Submit</button> <button type="button" id="btn-cancel" class="cancel">Cancel</button> </div> </div> </form> </section> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.10.8/dist/sweetalert2.all.min.js"></script> <link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.10.8/dist/sweetalert2.min.css" rel="stylesheet"> <script> $(document).ready(function() { $('#customer-form').on('submit', function(e) { e.preventDefault(); let formData = new FormData(this); $.ajax({ url: "<?php echo base_url('create-customer-submit'); ?>", type: "POST", data: formData, processData: false, contentType: false, dataType: "JSON", // success: function(response) { // if (response.result === 1) { // Swal.fire("Success", response.message, "success").then(() => { // window.location.href = "<?php echo base_url('customer-list'); ?>"; // }); // } else { // Swal.fire("Error", response.message, "error"); // } // } success: function(response) { console.log(response); // ✅ DEBUG (check in console) if (response.result === 1) { // ✅ SET farmer_id from backend $('#farmer_id').val(response.farmer_id); Swal.fire({ title: "Success", text: "Farmer ID: " + response.farmer_id, // ✅ SHOW IT icon: "success" }).then(() => { window.location.href = "<?php echo base_url('customer-list'); ?>"; }); } else { Swal.fire("Error", response.message, "error"); } } }); }); }); </script> <script> $(document).ready(function() { // $('#dealer_id').on('change', function() { // let dealer_id = $(this).val(); // if (dealer_id === '') { // $('#farmer_id').val(''); // return; // } // $.ajax({ // url: "<?= base_url('get-dealer-code'); ?>", // type: "POST", // data: { dealer_id: dealer_id }, // dataType: "JSON", // success: function(res) { // console.log(res); // 👈 ADD THIS (debug) // if (res.status == 1) { // let dealer_code = res.dealer_code; // let today = new Date(); // let month = String(today.getMonth() + 1).padStart(2, '0'); // let year = String(today.getFullYear()).slice(-2); // let farmer_id = dealer_code + month + year + "001"; // $('#farmer_id').val(farmer_id); // } // }, // error: function(err) { // console.log(err); // 👈 IMPORTANT // } // }); // }); $('#dealer_id').on('change', function() { let dealer_id = $(this).val(); if (dealer_id === '') { $('#farmer_id').val(''); return; } $.ajax({ url: "<?= base_url('get-next-farmer-id'); ?>", type: "POST", data: { dealer_id: dealer_id }, dataType: "JSON", success: function(res) { console.log(res); if (res.status == 1) { $('#farmer_id').val(res.farmer_id); // ✅ REAL ID } } }); }); }); </script> <script> $(document).ready(function () { $.ajax({ url: "<?= base_url('get-unique-code'); ?>", type: "POST", dataType: "JSON", success: function (res) { if (res.status == 1) { $('#unique_code').val(res.unique_code); } } }); }); </script> <script> $(document).ready(function () { $('#btn-cancel').click(function () { window.location.href = "<?= base_url('customer-list'); ?>"; }); }); </script> <script> $(document).ready(function () { $.getJSON("<?= base_url('public/assets/json/taluks.json') ?>", function (data) { let allTaluks = []; // Convert district-wise object into single array $.each(data, function (district, taluks) { allTaluks = allTaluks.concat(taluks); }); console.log(allTaluks); $("#taluk").autocomplete({ source: allTaluks, minLength: 1 }); }); }); </script> <script> $(document).ready(function () { $('#product_type').change(function () { let product_type = $(this).val(); $('#product_id').html( '<option value="">Loading...</option>' ); $.ajax({ url: "<?= base_url('get-products-by-type') ?>", type: "POST", data: { product_type: product_type }, dataType: "JSON", success: function (products) { console.log(products); let options = '<option value="">Select Product Model</option>'; $.each(products, function (index, product) { options += ` <option value="${product.product_id}"> ${product.model_name} </option> `; }); $('#product_id').html(options); } }); }); }); </script> <script> $(document).ready(function () { $('#product_id').change(function () { let product_id = $(this).val(); $.ajax({ url: "<?= base_url('get-product-details-far') ?>", type: "POST", data: { product_id: product_id }, dataType: "JSON", success: function (product) { console.log(product); $('#rc_price').val(product.rc_price); $('#gst_percent').val(product.gst_percent); $('#basic_price').val(product.basic_price); } }); }); }); </script> <script> $(document).ready(function () { // =================================== // LOAD PRODUCT TYPES // =================================== $.ajax({ url: "<?= base_url('get-product-types') ?>", type: "POST", dataType: "JSON", success: function (response) { console.log(response); let options = '<option value="">Select Product Type</option>'; $.each(response, function(index, row){ options += ` <option value="${row.product_type}"> ${row.product_type} </option> `; }); $('#product_type').html(options); } }); }); </script>