EVOLUTION-NINJA
Edit File: project_edit.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="<?php echo base_url('public/assets/css/createproject.css');?>"> <link rel="stylesheet" href="<?php echo base_url('public/assets/css/font-awesome.min.css');?>"> <link rel="stylesheet" href="<?php echo base_url('public/assets/css/bootstrap.min.css');?>"> <link rel="stylesheet" href="<?php echo base_url('public/assets/css/sidebar.css');?>"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="<?php echo base_url('public/assets/images/constituency.png');?>"> <link rel="stylesheet" href="<?php echo base_url('public/assets/images/Logo.png');?>"> <link rel="stylesheet" href="<?php echo base_url('public/assets/images/employee.png');?>"> <link rel="stylesheet" href="<?php echo base_url('public/assets/images/project-management.png');?>"> <link rel="stylesheet" href="<?php echo base_url('public/assets/images/arrows-up.png');?>"> <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> <section class="home-section"> <div class="home-content"> <i class='bx bx-menu'></i> <!-- <span class="text">Drop Down Sidebar</span> --> </div> <div class="row m-0"> <div class="col-sm-12"> <h1 class="crt-pjt">EDIT Project</h1> </div> </div> <style> .inpfieldname { font-family: Poppins; font-size: 18px; font-weight: 500; text-align: left; color: #1F1F21; } .buttns-cnl { margin-left: 20px; } .plus { background-color: transparent !important; padding: 2px; margin: 15px 15px; } .fieldsbox { border-radius: 23px !important; padding: 5px 10px !important; height: 45px; width: 85% } .projdetail { margin-inline: auto; margin-top: 15px; } .constuency_page { width: 100%; padding: 20px 16px; } .textfields { border-radius: 14px; } .file-list { display: flex; flex-wrap: wrap; /* Allows items to wrap to the next line if needed */ margin-top: 10px; gap: 3px } .file-item { display: flex; align-items: center; margin-right: 10px; font-size: 14px; /* Space between items */ background: #fff; /* Background color for visibility */ padding: 5px 10px; border-radius: 5px; /* Rounded corners */ } .delete-icon { margin-left: 8px; cursor: pointer; /* Show pointer on hover */ } .mul { font-size: 14px; color: red } .projectinputs { width: 93%; } .totpag { width: 100% } .input-group { width: 93%; } /*.remarks{*/ /* margin-left:150px !important;*/ /*}*/ @media (min-width: 768px) and (max-width: 1024px) { .inpfieldname { font-size: 15px; } .fieldsbox { border-radius: 23px !important; padding: 5px 10px !important; height: 45px; width: 100%; } } @media only screen and (max-width:620px) { .fieldsbox { width: 100% } .home-section { height: 100% } } /* ----------------------header styles */ body { margin: 0px; padding: 0px; overflow-x: hidden; } /* CSS adjustments */ @media (max-width: 767px) { .logo-mobile { margin-right: auto; /* Align logo to the left */ } .navbar-toggler { margin-left: auto; /* Align hamburger menu to the right */ } } /* Logo styling */ .logo { width: 100%; height: auto; } /* Image styling */ .header-image { width: 100%; height: auto; } /* Center the search bar */ .search-container { flex: 1; display: flex; justify-content: center; } .search-bar { max-width: 500px; width: 100%; } /* Align items on the right side */ .right-side { display: flex; align-items: center; } /* Hide elements in mobile view for header */ @media (max-width: 767px) { .desktop-only { display: none; } .header-image { width: 50% !important; height: auto; } .navbar-nav { display: grid !important; grid-template-columns: auto auto auto !important; margin-left: 11px !important; } .navbar-nav .nav-item { margin-bottom: 10px; } .navbar-toggler { margin-left: auto; } .logo-mobile { display: block; margin-bottom: 10px; text-align: center; } .search-container { margin-bottom: 10px; } } @media (min-width: 768px) { .navbar-toggler { display: none; } .navbar-brand { margin-right: auto; } } .img-notf, .notify-number { position: absolute; } .notify-number { position: relative; left: 13px; font-size: 11px; top: -8px; } .notify-number { position: relative !important; top: -6px; left: -11px; font-size: small; border-radius: 50%; color: red; } .notify-number { position: relative; left: 14px; top: -6px; } .search-bar { border-radius: 18px !important; border: none; box-shadow: 1px 1px 6px 0px #00000040; height: 35px; } .lang { font-family: Poppins; font-size: 17px; font-weight: 600; line-height: 30px; text-align: left; position: relative; color: #464646; } .admin { font-family: Poppins; font-size: 17px; font-weight: 600; line-height: 30px; text-align: left; position: relative; color: #464646; } .lang:hover { color: #464646; } .searc-top { position: relative; top: 8px; left: -27px; font-size: 18px; } @media only screen and (max-width: 600px) { .header-image { width: 50% !important; height: auto; } } @media (min-width: 768px) and (max-width: 1024px) { .logo { width: 80% !important; height: auto; } } /* --------------------only for tablets-------------------------------- */ @media (min-width: 768px) and (max-width: 1024px) {} /* --------------------only for tablets-------------------------------- */ /* ---------------- header style end */ </style> <!-- forms --> <form id="project-edit-form"> <div class="createproject"> <div class="row projdetail"> <!------------------------------------------------------------------------------------------------------------------------> <!----------------------------------------------------------------------------------------------------> <input type="hidden" name="projectid" id="projectid" class="form-control fieldsbox projectinputs" value="<?= isset($project['id']) ? $project['id'] : '' ?>"> <div class="col-sm-4"> <label class="form-label inpfieldname" for="department">Project Name</label> <input type="text" name="projectName" id="projectName" class="form-control fieldsbox projectinputs" value="<?= isset($project['project_name']) ? $project['project_name'] : '' ?>"> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="department">Total Amount</label> <input type="text" name="total_amount" id="total_amount" class="form-control fieldsbox totpag" value="<?= isset($project['Total_amount']) ? $project['Total_amount'] : '' ?>"> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="department">Department</label> <select name="department" id="department" class="form-control fieldsbox"> <option value="">Select</option> <?php foreach ($departments as $department): ?> <option value="<?php echo $department['id']; ?>" <?php echo (isset($project['department']) && $project['department']==$department['id']) ? 'selected' : '' ; ?>> <?php echo $department['department_name']; ?> </option> <?php endforeach; ?> </select> </div> </div> </div> <!-- First Row --> <div class="row projdetail"> <div class="col-sm-4"> <label class="form-label inpfieldname" for="constituency">Constituency</label> <select name="constituency" id="constituency" class="form-control fieldsbox"> <option value="">Select</option> <?php foreach ($constituencies as $constituency): ?> <option value="<?= $constituency['id']; ?>" <?=(isset($project['Constituency']) && $project['Constituency']==$constituency['id']) ? 'selected' : '' ; ?>> <?= $constituency['constituency_name']; ?> </option> <?php endforeach; ?> </select> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="mla">MLA / MLC / MP</label> <select name="mla" id="mla" class="form-control fieldsbox"> <option value="">Select</option> <?php foreach ($mla as $mla): ?> <option value="<?= $mla['id']; ?>" <?=(isset($project['mla']) && $project['mla']==$mla['id']) ? 'selected' : '' ; ?>> <?= $mla['mla']; ?> </option> <?php endforeach; ?> </select> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="fundwise">Fund Wise</label> <select name="fundwise" id="fundwise" class="form-control fieldsbox"> <option value="">Select</option> <?php foreach ($funds as $fund): ?> <option value="<?= $fund['id']; ?>" <?=(isset($project['fund_wise']) && $project['fund_wise']==$fund['id']) ? 'selected' : '' ?>> <?= $fund['fund_name']; ?> </option> <?php endforeach; ?> </select> </div> </div> <!-- Second Row --> <div class="row projdetail"> <div class="col-sm-4"> <label class="form-label inpfieldname" for="slno">Serial Number</label> <input type="text" class="fieldsbox form-control" id="sl_no" name="sl_no" placeholder="Enter Serial Number" value="<?= isset($project['sl_no']) ? $project['sl_no'] : '' ?>" required> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="apm">APM</label> <select name="apm" id="apm" class="form-control fieldsbox"> <option value="">Select</option> <?php foreach ($apms as $apm): ?> <option value="<?= $apm['id']; ?>" <?=(isset($project['APM']) && $project['APM']==$apm['id']) ? 'selected' : '' ; ?>> <?= $apm['username']; ?> </option> <?php endforeach; ?> </select> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="engineer">Engineer</label> <select name="engineer" id="engineer" class="form-control fieldsbox"> <option value="">Select</option> <?php foreach ($engineers as $engineer): ?> <option value="<?= $engineer['id']; ?>" <?=(isset($project['engineer']) && $project['engineer']==$engineer['id']) ? 'selected' : '' ; ?>> <?= $engineer['username']; ?> </option> <?php endforeach; ?> </select> </div> </div> <!-- Third Row --> <div class="row projdetail"> <div class="col-sm-4"> <label class="form-label inpfieldname" for="engineer">Supervisor</label> <select name="supervisor" id="supervisor" class="form-control fieldsbox"> <option value="">Select</option> <?php foreach ($supervisors as $supervisor): ?> <option value="<?= $supervisor['id']; ?>" <?=(isset($project['supervisor']) && $project['supervisor']==$supervisor['id']) ? 'selected' : '' ; ?>> <?= $supervisor['username']; ?> </option> <?php endforeach; ?> </select> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="DateProposal">Date of Proposal</label> <input type="text" name="date_of_Proposal" class="form-control fieldsbox" id="DateProposal" placeholder="dd/mm/yy" value="<?= isset($project['date_of_Proposal']) && !empty($project['date_of_Proposal']) ? (new DateTime($project['date_of_Proposal']))->format('d/m/Y') : '' ?>"> </div> <!-- Proposal Documents --> <div class="col-sm-4"> <label class="form-label inpfieldname" for="documents">Proposal Documents</label> <div class="input-group"> <input type="file" name="proposal[]" class="form-control fieldsbox" id="more-files-upload" multiple> <span class="input-group-text plus"> <i class="fa fa-plus-square-o" aria-hidden="true" id="add-more-file" style="cursor: pointer;"></i> </span> </div> <div id="file-add-div"></div> <div id="existing-files"> <?php if (!empty($proposalDocuments)): ?> <?php foreach ($proposalDocuments as $index => $doc): ?> <div class="input-group mb-2" id="doc-<?= $index; ?>"> <span class="input-group-text"> <a href="<?= $doc['document_path']; ?>" target="_blank"> <?= $doc['document_name']; ?> </a> </span> <span class="remove-document proposalDocs" style="cursor: pointer;" data-id="<?= $doc['document_name']; ?>" data-index="<?= $index; ?>"> <i class="fa fa-minus-square" aria-hidden="true"></i> </span> </div> <?php endforeach; ?> <?php else: ?> <p>No proposal documents uploaded yet.</p> <?php endif; ?> </div> <!-- --> </div> </div> <!-- Fourth Row --> <div class="row projdetail"> <div class="col-sm-4"> <label class="form-label inpfieldname" for="financialyear">Financial Year</label> <select name="financial_year" id="financialyear" class="form-control fieldsbox"> <option value="">Select</option> <option value="2028-29" <?=(isset($project['financial_year']) && $project['financial_year']=='2028-29' ) ? 'selected' : '' ?>>2028-29</option> <option value="2027-28" <?=(isset($project['financial_year']) && $project['financial_year']=='2027-28' ) ? 'selected' : '' ?>>2027-28</option> <option value="2026-27" <?=(isset($project['financial_year']) && $project['financial_year']=='2026-27' ) ? 'selected' : '' ?>>2026-27</option> <option value="2025-26" <?=(isset($project['financial_year']) && $project['financial_year']=='2025-26' ) ? 'selected' : '' ?>>2025-26</option> <option value="2024-25" <?=(isset($project['financial_year']) && $project['financial_year']=='2024-25' ) ? 'selected' : '' ?>>2024-25</option> <option value="2023-24" <?=(isset($project['financial_year']) && $project['financial_year']=='2023-24' ) ? 'selected' : '' ?>>2023-24</option> <option value="2022-23" <?=(isset($project['financial_year']) && $project['financial_year']=='2022-23' ) ? 'selected' : '' ?>>2022-23</option> <option value="2021-22" <?=(isset($project['financial_year']) && $project['financial_year']=='2021-22' ) ? 'selected' : '' ?>>2021-22</option> <option value="2020-21" <?=(isset($project['financial_year']) && $project['financial_year']=='2020-21' ) ? 'selected' : '' ?>>2020-21</option> <option value="2019-20" <?=(isset($project['financial_year']) && $project['financial_year']=='2019-20' ) ? 'selected' : '' ?>>2019-20</option> <option value="2018-19" <?=(isset($project['financial_year']) && $project['financial_year']=='2018-19' ) ? 'selected' : '' ?>>2018-19</option> <option value="2017-18" <?=(isset($project['financial_year']) && $project['financial_year']=='2017-18' ) ? 'selected' : '' ?>>2017-18</option> </select> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="Dateofestimation">Date of Estimation Submission</label> <input type="text" name="est_sub_date" class="form-control fieldsbox" id="Dateofestimation" value="<?= isset($project['est_sub_date']) ? (new DateTime($project['est_sub_date']))->format('d/m/Y') : '' ?>"> </div> <!-- Estimation Documents --> <div class="col-sm-4"> <label class="form-label inpfieldname" for="documents1">Estimation Documents</label> <div class="input-group"> <input type="file" name="estimate[]" class="form-control fieldsbox" id="documents1" multiple> <span class="input-group-text plus"> <i class="fa fa-plus-square-o" aria-hidden="true" id="add-more-file1" style="cursor: pointer;"></i> </span> </div> <div id="file-add-div1"></div> <div id="existing-files"> <?php if (!empty($estimationDocuments)): ?> <?php foreach ($estimationDocuments as $index => $doc): ?> <div class="input-group mb-2" id="doc-<?= $index; ?>"> <span class="input-group-text"> <a href="<?= $doc['document_path']; ?>" target="_blank"> <?= $doc['document_name']; ?> </a> </span> <span class="remove-document estimateDocs" style="cursor: pointer;" data-id="<?= $doc['document_name']; ?>" data-index="<?= $index; ?>"> <i class="fa fa-minus-square" aria-hidden="true"></i> </span> </div> <?php endforeach; ?> <?php else: ?> <p>No approval documents uploaded yet.</p> <?php endif; ?> </div> </div> </div> <!-- Fifth Row --> <div class="row projdetail"> <div class="col-sm-4"> <label class="form-label inpfieldname" for="estimatedcost">Estimated Cost</label> <input type="text" class="fieldsbox form-control" id="estimatedcost" name="estimated_cost" placeholder="Enter Estimated Cost" value="<?= isset($project['estimated_cost']) ? $project['estimated_cost'] : '' ?>" required> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="Dateofeapproval">Date of Approval</label> <input type="text" name="date_of_approval" class="form-control fieldsbox" id="Dateofeapproval" value="<?= isset($project['date_of_approval']) ? (new DateTime($project['date_of_approval']))->format('d/m/Y') : '' ?>"> </div> <!-- Approval Documents--> <div class="col-sm-4"> <label class="form-label inpfieldname" for="documents2">Approval Documents</label> <div class="input-group"> <input type="file" name="approval[]" class="form-control fieldsbox" id="documents2" multiple> <span class="input-group-text plus"> <i class="fa fa-plus-square-o" aria-hidden="true" id="add-more-file2" style="cursor: pointer;"></i> </span> </div> <div id="file-add-div2"></div> <div id="existing-files"> <?php if (!empty($approvalDocuments)): ?> <?php foreach ($approvalDocuments as $index => $doc): ?> <div class="input-group mb-2" id="doc-<?= $index; ?>"> <span class="input-group-text"> <a href="<?= $doc['document_path']; ?>" target="_blank"> <?= $doc['document_name']; ?> </a> </span> <span class="remove-document approvalDoc" style="cursor: pointer;" data-id="<?= $doc['document_name']; ?>" data-index="<?= $index; ?>"> <i class="fa fa-minus-square" aria-hidden="true"></i> </span> </div> <?php endforeach; ?> <?php else: ?> <p>No approval documents uploaded yet.</p> <?php endif; ?> </div> </div> <!-- -------------------------- --> </div> <div class="row projdetail"> <div class="col-sm-4"> <label class="form-label inpfieldname" for="admamount">ADM Amount</label> <input type="text" name="adm_amount" class="fieldsbox form-control" id="admamount" placeholder="Enter Adm Amount" value="<?= isset($project['adm_amount']) ? $project['adm_amount'] : '' ?>" required> </div> <div class="col-sm-4"> <label class="form-label inpfieldname" for="startdate">Start Date</label> <input type="text" name="start_date" class="form-control fieldsbox" id="startdate" value="<?= isset($project['start_date']) ? (new DateTime($project['start_date']))->format('d/m/Y') : '' ?>"> </div> <div class="col-sm-4"> <label for="status" class="form-label inpfieldname">Status</label> <select name="status" id="Status" class="form-control fieldsbox"> <option value="">Select</option> <?php foreach ($statuses as $status): ?> <option value="<?= $status['status']; ?>" <?= (isset($project['status']) && $project['status'] == $status['status']) ? 'selected' : '' ?>> <?= $status['status_name']; ?> </option> <?php endforeach; ?> </select> </div> </div> <div class="projdetail row"> <div class="col-sm-4"> <label for="labourcontract" class="form-label inpfieldname">Labour Contract</label> <input type="text" name="labour_contract" class="form-control fieldsbox" id="labourcontract" value="<?= isset($project['labour_contract']) ? $project['labour_contract'] : '' ?>"> </div> <div class="col-sm-4"> <label for="labourcontract" class="form-label inpfieldname">Adm Date</label> <input type="text" name="admDate" class="form-control fieldsbox" id="admDate" value="<?= isset($project['adm_date']) ? (new DateTime($project['adm_date']))->format('d/m/Y') : '' ?>"> </div> <div class="col-sm-4"> <label for="Remarks" class="form-label inpfieldname">Remarks</label><br> <textarea name="remarks" id="Remarks" class="form-control textfields projectinputs" required><?= isset($project['remarks']) ? $project['remarks'] : '' ?></textarea> </div> </div> <div class="projdetail row"> <div class="col-sm-8"> <label class="form-label inpfieldname" for="documents">Progress Documents</label> <div class="input-group" id="file-inputs-container"> <!-- New file input --> <input type="file" name="progress[]" class="form-control fieldsbox" id="more-files-upload" multiple> <input type="text" name="progress_date[]" class="form-control fieldsbox progressdate" placeholder="dd/mm/yy"> <input type="text" name="progress_remarks[]" class="form-control fieldsbox remarks" placeholder="Enter remarks"> <!-- Add approval checkbox for APM --> <!--<div class="form-check" style="align-self: center; margin-left: 10px;">--> <!-- <input class="form-check-input" type="checkbox" name="progress_apm_approval[]" id="apm-approval">--> <!--</div>--> <span class="input-group-text plus"> <i class="fa fa-plus-square-o" aria-hidden="true" id="add-more-file3" style="cursor: pointer;"></i> </span> </div> <div id="file-add-div3"></div> <!-- Display existing files --> <div id="existing-files"> <?php if (!empty($progressDocuments)): ?> <?php foreach ($progressDocuments as $index => $doc): ?> <div class="input-group mb-2" id="doc-<?= $index; ?>" style="align-items: center;"> <span class="input-group-text" style="min-width: 200px;"> <a href="<?= htmlspecialchars($doc['document_path'], ENT_QUOTES, 'UTF-8'); ?>" target="_blank"> <?= htmlspecialchars($doc['document_name'], ENT_QUOTES, 'UTF-8'); ?> </a> </span> <input type="text" name="existing_dates[<?= $index; ?>]" class="form-control fieldsbox progressdate" placeholder="dd/mm/yy" value="<?= !empty($doc['created_at']) ? (new DateTime($doc['created_at']))->format('d/m/Y') : ''; ?>"> <input type="text" name="existing_remarks[<?= $index; ?>]" class="form-control fieldsbox remarks" placeholder="Enter remarks" style="max-width: 300px; margin-left: 10px;" value="<?= htmlspecialchars($doc['remarks'] ?? '', ENT_QUOTES, 'UTF-8'); ?>"> <input type="text" name="existing_remarks[<?= $index; ?>]" class="form-control fieldsbox remarks" placeholder="Enter remarks" style="max-width: 300px; margin-left: 10px;" value="<?= htmlspecialchars($doc['created_by'] ?? '', ENT_QUOTES, 'UTF-8'); ?>"> <!-- Add approval checkbox for existing documents --> <!--<div class="form-check" style="align-self: center;margin-left:10px;">--> <!-- <input class="form-check-input" --> <!-- type="checkbox" --> <!-- name="existing_apm_approval[<//?= $index; ?>]" --> <!-- id="existing-apm-approval-<//?= $index; ?>" --> <!-- <//?= !empty($doc['status']) && $doc['status'] == 1 ? 'checked' : ''; ?>>--> <!--</div>--> </div> <?php endforeach; ?> <?php else: ?> <p>No proposal documents uploaded yet.</p> <?php endif; ?> </div> </div> </div> <br><br> <div class="row"> <div class="col-sm-6 buttns-cnl"> <button type="submit" class="submit">Submit</button> <button type="button" id="btn-cancel" class="cancel">Cancel</button> </div> </div> </div> </form> <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 () { // Define the formatDate function to convert the date from dd/mm/yyyy to yyyy-mm-dd function formatDate(date) { if (date === '' || date === undefined) { return ''; // Return empty string if the date is empty } var dateParts = date.split('/'); // Split the date by '/' return dateParts[2] + '-' + dateParts[1] + '-' + dateParts[0]; // Return as yyyy-mm-dd } // Handle form submission $('#project-edit-form').submit(function (e) { e.preventDefault(); // Get the values from the input fields var startDate = $('#startdate').val(); var formattedStartDate = formatDate(startDate); var approvalDate = $('#Dateofeapproval').val(); var formattedApprovalDate = formatDate(approvalDate); var estDate = $('#Dateofestimation').val(); var formattedEstDate = formatDate(estDate); var proposal = $('#DateProposal').val(); var formattedProposal = formatDate(proposal); var admDate = $('#admDate').val(); var formattedAdmDate= formatDate(admDate); var progressDate = $('.progressdate').val(); var formattedprogressDate= formatDate(progressDate); console.log(formattedprogressDate); var formData = new FormData($(this)[0]); // Manually set the formatted dates into the formData object formData.set('start_date', formattedStartDate); formData.set('date_of_approval', formattedApprovalDate); formData.set('est_sub_date', formattedEstDate); formData.set('date_of_Proposal', formattedProposal); formData.set('admDate', formattedAdmDate); formData.set('progress_date[]', formattedprogressDate); // Submit the form data via AJAX $.ajax({ url: "<?php echo base_url('project-update/' . $project['id']) ?>", type: "POST", data: formData, processData: false, contentType: false, success: function (response) { if (response.result === 1) { Swal.fire({ icon: "success", title: response.message, showConfirmButton: false, timer: 2000 }); window.location.href = `<?php echo base_url('projectlist'); ?>`; } else { alert(response.message); } }, error: function (xhr, status, error) { alert('An error occurred: ' + xhr.responseText); } }); }); }); </script> <script> $(document).on('click', '.removeReleasedAmount', function () { var index = $(this).data('index'); var releasedAmountValue = $('#released-amount-' + index + ' input').val(); if (confirm('Are you sure you want to delete this released amount?')) { $.ajax({ url: '<?= base_url("project/delete_released_amount"); ?>', type: 'POST', data: { project_id: <?= $project['id'] ?>, released_amount: releasedAmountValue, '<?= csrf_token() ?>': '<?= csrf_hash() ?>' }, success: function (response) { if (response.success) { $('#released-amount-' + index).remove(); alert('Released amount deleted successfully.'); } else { alert('Error deleting released amount: ' + response.message); } }, error: function (xhr, status, error) { console.error('Error:', error); } }); } }); </script> <script> $(document).on('click', '.removeExpenditure', function () { var index = $(this).data('index'); var expenditureValue = $('#expenditure-' + index + ' input').val(); if (confirm('Are you sure you want to delete this expenditure amount?')) { $.ajax({ url: '<?= base_url("project/delete-expenditure-amount"); ?>', type: 'POST', data: { project_id: <?= $project['id'] ?>, expenditure_amount: expenditureValue, '<?= csrf_token() ?>': '<?= csrf_hash() ?>' }, success: function (response) { if (response.success) { $('#expenditure-' + index).remove(); alert('Expenditure amount deleted successfully.'); } else { console.log('Error deleting expenditure amount: ' + response.message); } }, error: function (xhr, status, error) { console.error('Error:', error); } }); } }); </script> <script> $(document).ready(function () { $('#btn-cancel').click(function (e) { e.preventDefault(); window.location.href = '<?php echo base_url("projectlist"); ?>'; }); }); </script> <script> // Grabbing the required DOM elements var project = document.getElementById('projectName'); var totalAmount = document.getElementById('total_amount'); var department = document.getElementById('department'); var constituency = document.getElementById('constituency'); var mla = document.getElementById('mla'); var fundwise = document.getElementById('fundwise'); var sl_no = document.getElementById('sl_no'); var apm = document.getElementById('apm'); var supervisor = document.getElementById('supervisor'); var engineer = document.getElementById('engineer'); var dateProposal = document.getElementById('DateProposal'); var moreFilesUpload = document.getElementById('more-files-upload'); var financialYear = document.getElementById('financialyear'); var dateOfEstimation = document.getElementById('Dateofestimation'); var estimateDoc = document.getElementById('documents1'); var estimatedCost = document.getElementById('estimatedcost'); var dateOfApproval = document.getElementById('Dateofeapproval'); var approvalDoc = document.getElementById('documents2'); var admAmount = document.getElementById('admamount'); var startDate = document.getElementById('startdate'); var Status = document.getElementById('Status'); var labour = document.getElementById('labourcontract'); var remarks = document.getElementById('Remarks'); // Server-side role check using embedded PHP <?php if (session()->get('role') == 2 || session()->get('role') == 3 || session()->get('role') == 5): ?> project.readOnly = true; totalAmount.readOnly = true; admAmount.readOnly = true; startDate.readOnly = true; // Apply disabled to select and file input fields department.disabled = true; constituency.disabled = true; mla.disabled = true; fundwise.disabled = true; sl_no.disabled = true; apm.disabled = true; engineer.disabled = true; supervisor.disabled = true; labour.disabled = true; financialYear.disabled = true; estimatedCost.disabled = true; // Keep document and date fields enabled estimateDoc.disabled = false; dateProposal.disabled = false; moreFilesUpload.disabled = false; dateOfEstimation.disabled = false; dateOfApproval.disabled = false; approvalDoc.disabled = false; remarks.disabled = false; Status.disabled = false; // Temporarily remove disabled attributes before form submission to ensure fields are submitted document.querySelector('form').addEventListener('submit', function() { department.disabled = false; constituency.disabled = false; mla.disabled = false; fundwise.disabled = false; sl_no.disabled = false; apm.disabled = false; engineer.disabled = false; supervisor.disabled = false; Status.disabled = false; labour.disabled = false; financialYear.disabled = false; estimatedCost.disabled = false; }); <?php endif; ?> </script> <script> // Grabbing the required DOM elements var project = document.getElementById('projectName'); var totalAmount = document.getElementById('total_amount'); var department = document.getElementById('department'); var constituency = document.getElementById('constituency'); var mla = document.getElementById('mla'); var fundwise = document.getElementById('fundwise'); var sl_no = document.getElementById('sl_no'); var apm = document.getElementById('apm'); var supervisor = document.getElementById('supervisor'); var engineer = document.getElementById('engineer'); var dateProposal = document.getElementById('DateProposal'); var moreFilesUpload = document.getElementById('more-files-upload'); var financialYear = document.getElementById('financialyear'); var dateOfEstimation = document.getElementById('Dateofestimation'); var estimateDoc = document.getElementById('documents1'); var estimatedCost = document.getElementById('estimatedcost'); var dateOfApproval = document.getElementById('Dateofeapproval'); var approvalDoc = document.getElementById('documents2'); var admAmount = document.getElementById('admamount'); var startDate = document.getElementById('startdate'); var Status = document.getElementById('Status'); var labour = document.getElementById('labourcontract'); var remarks = document.getElementById('Remarks'); <?php if (session()->get('role') == 4): ?> project.readOnly = true; totalAmount.readOnly = true; admAmount.readOnly = true; startDate.readOnly = true; department.disabled = true; constituency.disabled = true; mla.disabled = true; fundwise.disabled = true; sl_no.disabled = true; apm.disabled = true; engineer.disabled = true; supervisor.disabled = true; Status.readOnly = true; Status.disabled= true;; labour.disabled = true; financialYear.disabled = true; estimatedCost.disabled = true; estimateDoc.disabled = true; dateProposal.disabled = true; moreFilesUpload.disabled = true; dateOfEstimation.disabled = true; dateOfApproval.disabled = true; approvalDoc.disabled = true; remarks.readOnly = false; remarks.disabled = false; // Temporarily remove disabled attributes before form submission document.querySelector('form').addEventListener('submit', function() { department.disabled = false; constituency.disabled = false; mla.disabled = false; fundwise.disabled = false; sl_no.disabled = false; apm.disabled = false; engineer.disabled = false; supervisor.disabled = false; Status.disabled=false; labour.disabled = false; financialYear.disabled = false; estimatedCost.disabled = false; estimateDoc.disabled = false; dateProposal.disabled = false; moreFilesUpload.disabled = false; dateOfEstimation.disabled = false; dateOfApproval.disabled = false; approvalDoc.disabled = false; }); <?php endif; ?> </script> <script> let moreFile = document.querySelector("#add-more-file"); let fileDiv = document.querySelector("#file-add-div"); moreFile.addEventListener("click", function () { var inputContainer = document.createElement('div'); inputContainer.classList.add('input-group', 'mb-2'); var newInput = document.createElement('input'); newInput.classList.add('form-control', 'fieldsbox'); newInput.type = 'file'; newInput.name = 'proposal[]'; var removeIcon = document.createElement('i'); removeIcon.classList.add('fa', 'fa-minus-square', 'remove-file-icon'); removeIcon.style.marginLeft = '15px'; removeIcon.style.marginRight = '15px'; removeIcon.style.marginTop = '15px';; removeIcon.addEventListener("click", function () { fileDiv.removeChild(inputContainer); }); inputContainer.appendChild(newInput); inputContainer.appendChild(removeIcon); fileDiv.appendChild(inputContainer); }); </script> <script> let moreFile1 = document.querySelector("#add-more-file1"); let fileDiv1 = document.querySelector("#file-add-div1"); moreFile1.addEventListener("click", function () { var inputContainer1 = document.createElement('div'); inputContainer1.classList.add('input-group', 'mb-2'); var newInput1 = document.createElement('input'); newInput1.classList.add('form-control', 'fieldsbox'); newInput1.type = 'file'; newInput1.name = 'estimate[]'; var removeIcon1 = document.createElement('i'); removeIcon1.classList.add('fa', 'fa-minus-square', 'remove-file-icon'); removeIcon1.style.marginLeft = '15px'; removeIcon1.style.marginRight = '15px'; removeIcon1.style.marginTop = '15px'; removeIcon1.addEventListener("click", function () { fileDiv1.removeChild(inputContainer1); }); inputContainer1.appendChild(newInput1); inputContainer1.appendChild(removeIcon1); fileDiv1.appendChild(inputContainer1); }); </script> <script> let moreFile2 = document.querySelector("#add-more-file2"); let fileDiv2 = document.querySelector("#file-add-div2"); moreFile2.addEventListener("click", function () { var inputContainer2 = document.createElement('div'); inputContainer2.classList.add('input-group', 'mb-2'); var newInput2 = document.createElement('input'); newInput2.classList.add('form-control', 'fieldsbox'); newInput2.type = 'file'; newInput2.name = 'approval[]'; var removeIcon2 = document.createElement('i'); removeIcon2.classList.add('fa', 'fa-minus-square', 'remove-file-icon'); removeIcon2.style.cursor = 'pointer'; removeIcon2.style.marginLeft = '15px'; removeIcon2.style.marginRight = '15px'; removeIcon2.style.marginTop = '15px'; removeIcon2.addEventListener("click", function () { fileDiv2.removeChild(inputContainer2); }); inputContainer2.appendChild(newInput2); inputContainer2.appendChild(removeIcon2); fileDiv2.appendChild(inputContainer2); }); </script> <script> let arrow = document.querySelectorAll(".arrow"); for (var i = 0; i < arrow.length; i++) { arrow[i].addEventListener("click", (e) => { let arrowParent = e.target.parentElement.parentElement; arrowParent.classList.toggle("showMenu"); }); } let sidebar = document.querySelector(".sidebar"); let sidebarBtn = document.querySelector(".bx-menu"); console.log(sidebarBtn); sidebarBtn.addEventListener("click", () => { sidebar.classList.toggle("close"); }); </script> <script> $(document).ready(function () { $('#constituency').on('focus keydown', function () { if ($(this).find('option').length === 1) { $.ajax({ url: '<?php echo base_url("fetch-constituency"); ?>', method: 'GET', success: function (response) { if (response.length > 0) { var options = '<option value="">Select Constituency</option>'; $.each(response, function (key, value) { options += `<option value="${value.id}">${value.constituency_name}</option>`; }); $('#constituency').html(options); } else { console.log('No constituency found'); } }, error: function (xhr, status, error) { console.error("Error fetching constituency:", error); } }); } }); $('#constituency').change(function () { var constituencyId = $(this).val(); if (constituencyId !== '') { $.ajax({ url: '<?php echo base_url("fetch-mla-by-constituency"); ?>/' + constituencyId, method: 'GET', success: function (response) { if (response.length > 0) { var mlaOptions = '<option value="">Select </option>'; $.each(response, function (key, value) { mlaOptions += `<option value="${value.id}">${value.mla}</option>`; }); $('#mla').html(mlaOptions); } else { $('#mla').html('<option value="">Select MLA</option>'); } }, error: function (xhr, status, error) { console.error("Error fetching MLA:", error); } }); } else { $.ajax({ url: '<?php echo base_url("fetch-mla-without-constituency"); ?>', method: 'GET', success: function (response) { if (response.length > 0) { var mlaOptions = '<option value="">Select </option>'; $.each(response, function (key, value) { mlaOptions += `<option value="${value.id}">${value.mla}</option>`; }); $('#mla').html(mlaOptions); } else { $('#mla').html('<option value="">Select MLA</option>'); } }, error: function (xhr, status, error) { console.error("Error fetching MLAs without constituency:", error); } }); } }); }); </script> <script> $(document).ready(function () { $('.proposalDocs').on('click', function () { var docName = $(this).data('id'); var index = $(this).data('index'); var $docElement = $('#doc-' + index); if (confirm('Are you sure you want to delete this document?')) { $.ajax({ url: '<?php echo base_url("delete-proposal-document"); ?>', method: 'POST', data: { project_id: <?= $project['id'] ?>, document_name: docName }, success: function (response) { if (response.success) { $docElement.remove(); alert('Document deleted successfully.'); } else { console.log('Failed to delete the document: ' + response.message); } }, error: function (xhr, status, error) { console.error("Error deleting document:", error); alert('An error occurred while deleting the document.'); } }); } }); }); </script> <script> $(document).ready(function () { $('.approvalDoc').on('click', function () { var docName = $(this).data('id'); var index = $(this).data('index'); var $docElement = $('#doc-' + index); if (confirm('Are you sure you want to delete this document?')) { $.ajax({ url: '<?php echo base_url("delete-approval-document"); ?>', method: 'POST', data: { project_id: <?= $project['id'] ?>, document_name: docName }, success: function (response) { if (response.success) { $docElement.remove(); alert('Document deleted successfully.'); } else { console.log('Failed to delete the document: ' + response.message); } }, error: function (xhr, status, error) { console.error("Error deleting document:", error); alert('An error occurred while deleting the document.'); } }); } }); }); </script> <script> $(document).ready(function () { $('.estimateDocs').on('click', function () { var docName = $(this).data('id'); var index = $(this).data('index'); var $docElement = $('#doc-' + index); if (confirm('Are you sure you want to delete this document?')) { $.ajax({ url: '<?php echo base_url("delete-estimation-documents"); ?>', method: 'POST', data: { project_id: <?= $project['id'] ?>, document_name: docName }, success: function (response) { if (response.success) { $docElement.remove(); alert('Document deleted successfully.'); } else { console.log('Failed to delete the document: ' + response.message); } }, error: function (xhr, status, error) { console.error("Error deleting document:", error); alert('An error occurred while deleting the document.'); } }); } }); }); </script> <script> $(document).ready(function () { // Initialize Date of Estimation datepicker $('#Dateofestimation').datepicker({ dateFormat: 'dd/mm/yy', // Custom format: dd/mm/yy changeMonth: true, // Allow changing the month changeYear: true // Allow changing the year }); // Initialize Start Date datepicker $('#startdate').datepicker({ dateFormat: 'dd/mm/yy', // Custom format: dd/mm/yy changeMonth: true, // Allow changing the month changeYear: true // Allow changing the year }); // Initialize Date of Approval datepicker $('#DateProposal').datepicker({ dateFormat: 'dd/mm/yy', // Custom format: dd/mm/yy changeMonth: true, // Allow changing the month changeYear: true // Allow changing the year }); $('#Dateofeapproval').datepicker({ dateFormat: 'dd/mm/yy', // Custom format: dd/mm/yy changeMonth: true, // Allow changing the month changeYear: true // Allow changing the year }); $('#admDate').datepicker({ dateFormat: 'dd/mm/yy', // Custom format: dd/mm/yy changeMonth: true, // Allow changing the month changeYear: true // Allow changing the year }); $('.progressdate').datepicker({ dateFormat: 'dd/mm/yy', // Custom format: dd/mm/yy changeMonth: true, // Allow changing the month changeYear: true // Allow changing the year }); }); </script> <script> document.addEventListener("DOMContentLoaded", function () { const addMoreFile3 = document.getElementById("add-more-file3"); const fileAddDiv3 = document.getElementById("file-add-div3"); addMoreFile3.addEventListener("click", function () { // Create a container for the new input fields const inputContainer = document.createElement("div"); inputContainer.classList.add("input-group", "mb-2"); // File input field (allow multiple files) const newFileInput = document.createElement("input"); newFileInput.classList.add("form-control", "fieldsbox"); newFileInput.type = "file"; newFileInput.name = "progress[]"; // Note: You may also want to use an array to keep files grouped newFileInput.multiple = true; // Allows multiple file selection // Remarks input field const newRemarksInput = document.createElement("input"); newRemarksInput.classList.add("form-control", "fieldsbox"); newRemarksInput.type = "text"; newRemarksInput.name = "progress_remarks[]"; newRemarksInput.placeholder = "Enter remarks"; // Progress date input field const newProgressDate = document.createElement("input"); newProgressDate.classList.add("form-control", "fieldsbox", "progressdate"); newProgressDate.type = "text"; newProgressDate.name = "progress_date[]"; newProgressDate.placeholder = "dd/mm/yy"; // Remove button const removeButton = document.createElement("span"); removeButton.classList.add("input-group-text"); removeButton.style.cursor = "pointer"; removeButton.innerHTML = '<i class="fa fa-minus-square" aria-hidden="true"></i>'; removeButton.addEventListener("click", function () { inputContainer.remove(); }); // Checkbox for APM Approval const checkboxContainer = document.createElement("div"); checkboxContainer.classList.add("form-check"); checkboxContainer.style.alignSelf = "center"; checkboxContainer.style.marginLeft = "10px"; const newCheckbox = document.createElement("input"); newCheckbox.classList.add("form-check-input"); newCheckbox.type = "checkbox"; newCheckbox.name = "progress_apm_approval[]"; const checkboxLabel = document.createElement("label"); checkboxLabel.classList.add("form-check-label"); checkboxContainer.appendChild(newCheckbox); checkboxContainer.appendChild(checkboxLabel); // Append the elements inputContainer.appendChild(newFileInput); inputContainer.appendChild(newProgressDate); inputContainer.appendChild(newRemarksInput); inputContainer.appendChild(checkboxContainer); inputContainer.appendChild(removeButton); // Add the new container to the form fileAddDiv3.appendChild(inputContainer); // Initialize the date picker $(newProgressDate).datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true }); }); }); </script> <script> document.addEventListener("DOMContentLoaded", function () { document.addEventListener("change", function (event) { if (event.target.matches(".form-check-input")) { const checkbox = event.target; const isChecked = checkbox.checked; const docId = checkbox.id; // Get the document ID from the checkbox ID const url = "/project-edit/approve"; // Correct API endpoint const projectInput = document.getElementById("projectid"); const projectid = projectInput ? projectInput.value.trim() : null; // Debugging: Log the inputs console.log("Checkbox ID (Document ID):", docId); console.log("Project ID:", projectid); console.log("Approval Status:", isChecked); if (!projectid) { Swal.fire({ icon: 'error', title: 'Oops...', text: 'Project ID is missing!', }); return; } const data = { id: docId, approval: isChecked ? 1 : 0, projectid: projectid, }; // Send request to update the approval status fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }) .then((response) => response.json()) .then((responseData) => { console.log("Response:", responseData); if (responseData.status === "success") { Swal.fire({ icon: 'success', title: 'Success!', text: 'Approval updated successfully!', }); } else { Swal.fire({ icon: 'error', title: 'Failed', text: 'Failed to update approval: ' + responseData.message, }); } }) .catch((error) => { console.error("Error:", error); Swal.fire({ icon: 'error', title: 'Error', text: 'An error occurred while updating approval.', }); }); } }); }); </script> <?php echo view('includes/footer'); ?>