/
home
/
efamember
/
domains
/
efa-member.com
/
public_html
/
main
/
jobs
/
up file
home
<?php require('header.php'); @include('../config/main_function.php'); $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); $password = 'sd32f43q5we'; $originalMessage = "CXgvsdf542sdfg"; $encryptedMessage = encryptMessage($originalMessage, $password); ?> <form id="form_add" method="post" enctype="multipart/form-data"> <div class="row"> <div class="col-lg-3 col-md-6 col-sm-12"> <div class="form-group"> <label><strong>ราคาประมูล </strong> <span class="text-danger">**</span></label> <input type="text" class="form-control text-right comma" name="contract_price" id="contract_price" maxlength="15" onchange="calculate()"> </div> </div> <div class="col-3 mb-4"> <label for=""><strong>วันที่เริ่มโครงการ </strong><span class="text-danger">**</span></label> <div class="input-group date"> <span class="input-group-addon"> <i class="fa fa-calendar"></i> </span> <input type="text" class="form-control datepicker" name="start_date" id="start_date" value="<?php echo date('d/m/Y'); ?>" onchange="datetime()"> </div> </div> <div class="col-lg-3 col-md-6 col-sm-12"> <div class="form-group"> <label><strong>ระยะเวลาโครงการ (วัน) </strong><span class="text-danger">**</span></label> <input type="number" class="form-control text-right" name="period_time" id="period_time" onchange="datetime()"> </div> </div> <div class="col-3 mb-4"> <label for=""><strong>กำหนดการแล้วเสร็จ </strong><span class="text-danger">**</span></label> <div class="input-group date"> <span class="input-group-addon"> <i class="fa fa-calendar"></i> </span> <input type="text" class="form-control datepicker" name="plan_finish_date" id="plan_finish_date" value="" disabled> </div> </div> </div> <div class="row"> <div class="col-lg-3 col-md-6 col-sm-12"> <div class="form-group"> <label><strong>รวมงบประมาณ </strong></label> <input type="text" class="form-control text-right" name="sum_butget" id="sum_butget" readonly> </div> </div> <div class="col-lg-3 col-md-6 col-sm-12"> <div class="form-group"> <label><strong>กำไรที่คาดหวัง </strong></label> <input type="text" class="form-control text-right" name="expected_profit" id="expected_profit" readonly> </div> </div> <div class="col-lg-3 col-md-6 col-sm-12"> <div class="form-group"> <label><strong>กำไรที่คาดหวัง(%) </strong></label> <input type="text" class="form-control text-right" name="total" id="total" readonly> </div> </div> <div class="col-lg-3 mt-4"> <div class="d-flex justify-content-end"> <button type="button" class="btn btn-primary px-5" onclick="AddProject()">บันทึก</button> </div> </div> </div> </form> <?php require('footer.php') ?> <script> $(".datepicker").datepicker({ todayBtn: "linked", keyboardNavigation: false, forceParse: false, calendarWeeks: false, format: 'dd/mm/yyyy', thaiyear: false, language: 'th', //Set เป็นปี พ.ศ. autoclose: true }); $('.select2').select2( ); function datetime() { // ดึงค่าวันที่เริ่มโครงการ let startDateStr = $('#start_date').val(); let startDate = moment(startDateStr, 'DD/MM/YYYY'); // ดึงค่าระยะเวลาโครงการ (วัน) let periodTime = parseInt($('#period_time').val()) || 0; // คำนวณวันที่กำหนดการแล้วเสร็จ let planFinishDate = startDate.add(periodTime, 'days').format('DD/MM/YYYY'); // แสดงผลใน input ของกำหนดการแล้วเสร็จ (ที่ disabled) $('#plan_finish_date').val(planFinishDate); } function AddProject() { let project_no = $('#project_no').val(); let project_name = $('#project_name').val(); let contract_price = $('#contract_price').val(); let start_date = $('#start_date').val(); let period_time = $('#period_time').val(); let customer_id = $('#customer_id').val(); let Mat = $('#Mat').val(); let Wage = $('#Wage').val(); if (project_no == '' || project_name == '' || contract_price == '' || start_date == '' || period_time == '' || customer_id == '0') { swal({ title: 'แจ้งเตือน', text: 'กรุณากรอกข้อมูลให้ครบถ้วน *', type: "warning", showConfirmButton: false }); setTimeout(function() { swal.close(); }, 1500); return false; } swal({ title: "แจ้งเตือน", text: "ยืนยัน การเพิ่มโปรเจกต์หรือไม่ ?", type: "warning", showCancelButton: true, confirmButtonColor: "#1AB394", confirmButtonText: "ยืนยัน", cancelButtonText: "ตรวจสอบอีกครั้ง", closeOnConfirm: false }, function() { let myForm = document.getElementById('form_add'); let formData = new FormData(myForm); formData.append("user_id", localStorage.getItem("user_id")); $.ajax({ url: 'ajax/project/AddProject.php', type: 'POST', dataType: 'json', contentType: false, cache: false, processData: false, data: formData, success: function(data) { if (data.result == 1) { // $('#myModal').modal('hide'); // LoadData(); swal({ title: "บันทึกสำเร็จ", text: "เพิ่มโปรเจกต์สำเร็จ", type: "success", showConfirmButton: false }); setTimeout(function() { window.location = 'project.php'; swal.close(); }, 2000); } else if (data.result == 0) { swal({ title: "บันทึกไม่สำเร็จ", text: "เพิ่มโปรเจกต์ไม่สำเร็จ", type: "error", showConfirmButton: false }); setTimeout(function() { swal.close(); }, 2000); } else if (data.result == 9) { swal({ title: "บันทึกไม่สำเร็จ", text: "Session หมดอายุ หรือ ไม่สามารถเชื่อมต่อฐานข้อมูลได้", type: "error", showConfirmButton: false }); setTimeout(function() { localStorage.clear(); window.location.assign("../index.php"); swal.close(); }, 2000); } else { swal({ title: "บันทึกไม่สำเร็จ", text: "ไม่สามารถติดต่อเซิฟเวอร์ได้ กรุณาลองใหม่อีกครั้ง!!", type: "error", showConfirmButton: true }); } }, error: function(jqXHR, exception) { var msg = ''; if (jqXHR.status === 0) { msg = 'Not connect. Verify Network.'; } else if (jqXHR.status == 404) { msg = 'Requested page not found. [404]'; } else if (jqXHR.status == 500) { msg = 'Internal Server Error [500].'; } else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.'; } else if (exception === 'timeout') { msg = 'Time out error.'; } else if (exception === 'abort') { msg = 'Ajax request aborted.'; } else { msg = 'Uncaught Error. ' + jqXHR.responseText; } swal({ title: "แจ้งเตือน", text: "พบปัญหาการบันทึก กรุณาติดต่อผู้ดูแลระบบ" + msg, type: "error", showConfirmButton: true }); } }); }); } function calculate() { // รวมงบประมาณ Mat และ Wage let Mat = parseFloat($('#Mat').val()) || 0; let Wage = parseFloat($('#Wage').val()) || 0; // รวมค่าใช้จ่ายอื่น ๆ let sum_other_expenses = 0; $('[id^="oth_group_"]').each(function() { let expense_value = parseFloat($(this).val()) || 0; sum_other_expenses += expense_value; }); // รวมงบประมาณทั้งหมด let total_budget = Mat + Wage + sum_other_expenses; // แสดงผลรวมงบประมาณทั้งหมด $('#sum_butget').val(addCommas(total_budget.toFixed(2))); // คำนวณกำไรคาดหวัง let contract_price = $('#contract_price').val() || 0; contract_price = parseFloat(contract_price.replaceAll(',','')) let expected_profit = contract_price - total_budget; // แสดงผลกำไรคาดหวัง // $('#expected_profit').val(expected_profit.toFixed(2)); $('#expected_profit').val(addCommas(expected_profit.toFixed(2))); let total = 0; total = expected_profit * 100 / contract_price; $('#total').val(addCommas(total.toFixed(2))); } // เรียกใช้ฟังก์ชัน calculate เมื่อมีการเปลี่ยนแปลงใน input fields ที่เกี่ยวข้อง $('#Mat, #Wage, [id^="oth_group_"]').on('input', function() { calculate(); }); $(document).ready(function() { $(".comma").on('input', function() { formatNumber(this) }) $('.comma').on('blur', function() { addTrailingZeros(this) }) }); function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } function formatNumber(input) { let value = input.value.replace(/[^0-9.]/g, ''); // Remove all non-numeric characters except for periods const parts = value.split('.'); if (parts.length > 2) { parts.length = 2; } if (parts[1] !== undefined) { parts[1] = parts[1].slice(0, 2); } parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); input.value = parts.join('.'); } function addTrailingZeros(input) { let value = input.value.replace(/,/g, ''); // Remove commas for easier manipulation if (value === '') return; if (!value.includes('.')) { value += '.00'; } else { const parts = value.split('.'); parts[1] = (parts[1] + '00').slice(0, 2); value = parts.join('.'); } const parts = value.split('.'); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); // Add commas back to the integer part input.value = parts.join('.'); } </script>