<section class="container" style="padding-bottom: 2rem;">
		<div class="row">
			<div class="col-sm-12">
				<div class="tab-content" id="tabContent">
					<div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="profile-tab">
						<div class="card bg-light-transparent">
							<div class="card-header bg-light">
								<h4 class="card-title float-left">Meeting Report Form</h4>
							</div>

							<div class="card-body">
								<div class="card no-shadow">
									<div class="card-body">
										<?php if(!empty($ID)){ ?>
											<form id="meetingcrmForm" class="form" action="<?php echo base_url('hr/serviceform/edit_meeting_crm') ?>" method="post">
										<?php } else { ?>
											<form id="meetingcrmForm" class="form" action="<?php echo base_url('hr/serviceform/add_new_meeting_crm') ?>" method="post">
										<?php } ?>

										<input type="text" class="form-control" name="meetingCrmID" id="meetingCrmID" value="<?php echo $ID; ?>" hidden>

											<div class="form-row">
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>Name</label>
														<input type="text" class="form-control" name="name" id="name" value="<?php echo $_SESSION['user']['name']; ?>" disabled>	
														<input type="text" class="form-control" name="name_id" id="name_id" value="<?php echo $_SESSION['user']['id']; ?>" hidden>
													</div>
												</div>

												<div class="col-12 col-sm-3">
													<div class="form-group">
														<label for="department">Department</label>
														<input type="text" class="form-control" name="department" id="department" value="<?php echo $_SESSION['user']['department_name']; ?>" readonly>

														<input type="text" class="form-control" name="department_id" id="department_id" value="<?php echo $_SESSION['user']['department_id']; ?>" hidden>
													</div>
												</div>

												<div class="col-12 col-sm-3">
													<div class="form-group">
														<label for="reqDate">Date Request </label>
														<?php if(!empty($ID)){ ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
															<input type="" class="form-control" name="reqDate" id="reqDate" value="<?php echo (!empty($ID))?date('d-m-Y',strtotime($row['createdTS'])):''; ?>" readonly required>
															<?php endforeach;endif; } else { ?>
																<input type="" class="form-control" name="reqDate" id="reqDate" value="<?php echo date("d-m-Y"); ?>" readonly required>
															<?php } ?>
													</div>
												</div>
											</div>

											<?php// debug($companyList); ?>
											<div class="form-row">
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label for="compname">Company Name</label>
														<select class="form-control" id="compname" name="compname" required>
															<?php if(!empty($ID)){ ?>
																<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																	<option value="<?php echo (!empty($ID))?$row['company_name']:'--Please Select--'; ?>" selected required><?php echo (!empty($ID))?$row['company_name']:''; ?></option>

																	<?php if(!empty($companyList)): foreach($companyList as $rows): ?>
																		<option value="<?php echo $rows['id']; ?>"><?php echo $rows['name']; ?></option>
																	<?php endforeach;endif; ?>

																<?php endforeach;endif; } else { ?>

																	<option value="" disabled selected required>--Please Select--</option>

																	<?php if(!empty($companyList)): foreach($companyList as $rows): ?>
																		<option value="<?php echo $rows['id']; ?>"><?php echo $rows['name']; ?></option>
																	<?php endforeach;endif; ?>

															<?php } ?>
														</select>
													</div>
												</div>
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label for="contact">Contact Person</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<input type="text" class="form-control" name="contact" id="contact" value="<?php echo $row['contact_person']; ?>" required>
															<?php endforeach;endif; } else { ?>
																<input type="text" class="form-control" name="contact" id="contact" value="" required>
														<?php } ?>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label for="contactno">Contact Number</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<input type="number" class="form-control" name="contactno" id="contactno" value="<?php echo $row['contact_number']; ?>" minlength="10" maxlength="11" required>
															<?php endforeach;endif; } else { ?>
																<input type="number" class="form-control" name="contactno" id="contactno" value="" minlength="10" maxlength="11" required>
														<?php } ?>
													</div>
												</div>

												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label for="contactemail">Contact Email</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<input type="text" class="form-control" name="contactemail" id="contactemail" value="<?php echo $row['contact_email']; ?>" required>
															<?php endforeach;endif; } else { ?>
																<input type="text" class="form-control" name="contactemail" id="contactemail" value="" required>
														<?php } ?>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12">
													<div class="form-group">
														<label for="info">Director(s) brief info</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<textarea type="text" class="form-control" name="info" id="info" value="" style="height: 150px;" required><?php echo $row['director_info']; ?></textarea>
															<?php endforeach;endif; } else { ?>
																<textarea type="text" class="form-control" name="info" id="info" value="" style="height: 150px;" required></textarea>
														<?php } ?>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12 col-sm-4">
													<div class="form-group">
														<label for="prepare">Prepared by</label><?php //debug($meetingCrmListByID); ?>
														<select class="form-control" id="prepare" name="prepare" required>
															<?php if(!empty($ID)){ ?>
																<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																	<option value="<?php echo (!empty($ID))?$row['prepared_by']:'--Please Select--'; ?>" selected required><?php echo (!empty($ID))?$row['preparedByName']:''; ?></option>
                                                                    
																	<?php if(!empty($listNames)): foreach($listNames as $rows): ?>
																		<option value="<?php echo $rows['user_id']; ?>" required><?php echo $rows['name']; ?></option>
																	<?php endforeach;endif; ?>

																<?php endforeach;endif; } else { ?>

																	<option value="" disabled selected required>--Please Select--</option>
																	
																	<?php if(!empty($listNames)): foreach($listNames as $rows): ?>
																		<option value="<?php echo $rows['user_id']; ?>" required><?php echo $rows['name']; ?></option>
																	<?php endforeach;endif; ?>

															<?php } ?>
														</select>
													</div>
												</div>
												<div class="col-12 col-sm-5">
													<div class="form-group">
														<label for="attend">Attended by</label><?php //debug($meetingCrmListByID); ?>
														<?php //debug($listNames) ?>
														<select class="form-control selectric" id="attend" name="attend[]" multiple required>
															<?php if(!empty($ID)){ ?>
                                                                <option value="" disabled selected required>--Please Select--</option>
                                                                
                                                                <?php if(!empty($listNames)): foreach($listNames as $rows): ?>
                                                                    <option value="<?php echo $rows['user_id']; ?>" required><?php echo $rows['name']; ?></option>
                                                                <?php endforeach;endif; ?>

																<?php } else { ?>

																	<option value="" disabled selected required>--Please Select--</option>
																	
																	<?php if(!empty($listNames)): foreach($listNames as $rows): ?>
																		<option value="<?php echo $rows['user_id']; ?>" required><?php echo $rows['name']; ?></option>
																	<?php endforeach;endif; ?>
															<?php } ?>
														</select>

                                                        <hr>

                                                            <?php if(!empty($meetingCrmListByID)){ foreach($meetingCrmListByID as $row){ ?>
                                                                    
                                                                <ol id="attend_by_ordered_list">
                                                                    <?php if(!empty($row['attended_by'])): ?>
                                                                        <?php foreach($row['attended_by'] as $key => $person): ?>
                                                                            <li><?php echo $person['attendedName']; echo ($person['attended_by'])?'('.$person['attended_by'].')':''; ?></li>
                                                                        <?php endforeach; ?>
                                                                    <?php endif;?>
                                                                </ol>

                                                            <?php } } ?>
													</div>
												</div>
												<div class="col-12 col-sm-3">
													<div class="form-group">
														<label for="princip">Principle Business</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<input type="text" class="form-control" name="princip" id="princip" value="<?php echo $row['principle_business']; ?>" required>
															<?php endforeach;endif; } else { ?>
																<input type="text" class="form-control" name="princip" id="princip" value="" required> 
														<?php } ?>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12">
													<div class="form-group">
														<label for="obj">Objective of Meeting</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<textarea type="text" class="form-control" name="obj" id="obj" value="" style="height: 150px;" required><?php echo $row['objective_meeting']; ?></textarea>
															<?php endforeach;endif; } else { ?>
																<textarea type="text" class="form-control" name="obj" id="obj" value="" style="height: 150px;" required></textarea>
															<?php } ?>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12">
													<div class="form-group">
														<label for="result">Meeting Result</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<textarea type="text" class="form-control" name="result" id="result" value="" style="height: 150px;" required><?php echo $row['meeting_result']; ?></textarea>
															<?php endforeach;endif; } else { ?>
																<textarea type="text" class="form-control" name="result" id="result" value="" style="height: 150px;" required></textarea>
														<?php } ?>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12">
													<div class="form-group">
														<label for="recommended">Recommended Direction in Response to the Meeting</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<input type="text" class="form-control" name="recommended" id="recommended" value="<?php echo $row['recommended_direction']; ?>" required>
															<?php endforeach;endif; } else { ?>
																<input type="text" class="form-control" name="recommended" id="recommended" value="" required>
														<?php } ?>
													</div>
												</div>
											</div>

                      						<div class="form-row">
												<div class="col-12 col-md-6">
													<label>Engagement</label>
													<?php// debug($meetingCrmListByID); ?>
													<select name="engagements1" id="engagements2" class="form-control form-control" required>
															<option value="" disabled selected required>--Please Select--</option>
															<option value="1"> Audit</option>
															<option value="2"> Accounting</option>
															<option value="3"> Company Secretary</option>
															<option value="4"> Corporate Finance /Transaction Services</option>
															<option value="5"> Indirect Tax</option>
															<option value="6"> Direct Tax</option>
															<option value="7"> Shariah</option>
															<option value="8">IT & Digital Consultancy</option>
															<option value="9"> Training & Education</option>
															<option value="amount">Other Engagement</option>
													</select>
												</div>
												<div class="col-12 col-md-6 mx-auto text-left mb-3">
													<label><p></p></label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
															<input type="text" id="engagements3" name="engagements4" value="<?php if(!empty($row['engagement_service'])){ echo $row['engagement_service']; }else{ echo $row['engagement'];} ?>" class="form-control form-control-md" disabled onkeyup="changeEngagements(this)" required>
															<input type="text" name="engagements3" value="<?php if(!empty($row['engagement_service'])){ echo $row['engagement_service']; }else{ echo $row['engagement'];} ?>" id="other_engagements_write" class="form-control form-control" hidden required>
													<?php endforeach;endif; } else { ?>
															<input type="text" id="engagements3" name="engagements4" value="--Please Select--" class="form-control form-control-md" disabled onkeyup="changeEngagements(this)" required>
															<input type="text" name="engagements3" value="--Please Select--" id="other_engagements_write" class="form-control form-control" hidden required>
													<?php } ?>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12 col-md-6">
													<label>Potential Services</label>
													<?php// debug($meetingCrmListByID); ?>
													<select name="potentialServices1" id="potentialServices2" class="form-control form-control" required>
														<option value="" disabled selected>--Please Select--</option>
														<option value="1"> Audit</option>
														<option value="2"> Accounting</option>
														<option value="3"> Company Secretary</option>
														<option value="4"> Corporate Finance /Transaction Services</option>
														<option value="5"> Indirect Tax</option>
														<option value="6"> Direct Tax</option>
														<option value="7"> Shariah</option>
														<option value="8">IT & Digital Consultancy</option>
														<option value="9"> Training & Education</option>
														<option value="amount">Other Potential Services</option>
													</select>
												</div>
												<div class="col-12 col-md-6 mx-auto text-left mb-3">
													<?php //debug($meetingCrmListByID); ?>
													<label><p></p></label>
													<?php if(!empty($ID)){ ?>
														<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
															<input type="text" id="potentialServices3" name="potentialServices4" value="<?php if(!empty($row['potential_service'])){ echo $row['potential_service']; }else{ echo $row['potential_services'];} ?>" class="form-control form-control-md" disabled onkeyup="changePotentialServices(this)" required>
															<input type="text" name="potentialServices3" value="<?php if(!empty($row['potential_service'])){ echo $row['potential_service']; }else{ echo $row['potential_services'];} ?>" id="other_potentialServices_write" class="form-control form-control" hidden required>
													<?php endforeach;endif; } else { ?>
															<input type="text" id="potentialServices3" name="potentialServices4" value="--Please Select--" class="form-control form-control-md" disabled onkeyup="changePotentialServices(this)" required>
															<input type="text" name="potentialServices3" value="--Please Select--" id="other_potentialServices_write" class="form-control form-control" hidden required>
													<?php } ?>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label for="fees">Current/Expected Fee</label>
															<?php if(!empty($ID)) { ?>
																<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																	<input type="number" class="form-control" name="fees" id="fees" value="<?php echo $row['fee']; ?>" required>
																<?php endforeach;endif; } else { ?>
																	<input type="number" class="form-control" name="fees" id="fees" value="" required>
															<?php } ?>
													</div>
												</div>
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label for="actionReq">Action Required</label>
														<?php if(!empty($ID)) { ?>
															<?php if(!empty($meetingCrmListByID)): foreach($meetingCrmListByID as $row): ?>
																<textarea type="text" class="form-control" name="actionReq" id="actionReq" value="" style="height: 150px;" required><?php echo $row['action_required']; ?></textarea>
															<?php endforeach;endif; } else { ?>
																<textarea type="text" class="form-control" name="actionReq" id="actionReq" value="" style="height: 150px;" required></textarea>
														<?php } ?>
													</div>
												</div>
											</div>

											<div class="form-row">
                                                <div class="col-12">
                                                    <div class="float-right" style="padding-top: 2rem;">
                                                        <a class="btn btn-light" href="<?php echo base_url('hr/serviceform/meeting_crm_list/'.$ID); ?>">Cancel</a>
                                                        <button type="submit" class="btn btn-primary">Submit</button>
                                                    </div> 
                                                </div>
                                            </div> 
										</form>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
</section>

<script>
    $('#engagements2').change(function(){

        let engagementName = $("#engagements2 option:selected").text(); //ni kita ambik yg dah selected dari select dropdown tu. Tapi kita ambik text dia. Perkataan. Bukan value. .text() ni js punya function mcm .html() or .val()
        //console.log(engagementName);
        let engagements2 = $('#engagements2').val();

            if(engagements2 != 'amount')
            {
                /**
                    check value for the backup frequency
                    if the value for the backup frequency is one time automatically the value for the amounttext is the value for 
                    sizedb * 10 number format 2
                */
                $('#engagements3').val(engagementName); //then dah dapat text tu kita masukkan kat sini. Jadikan as value.
                $('#other_engagements_write').val(engagements2);

                $( "#engagements3" ).prop( "disabled", true );
            }else{
                $('#engagements3').val(''); //sini kita kosongkan value ni nak bagi dia always 0 after select yg lain ni 
                $('#other_engagements_write').val();

                $( "#engagements3" ).prop( "disabled", false ); // dia display val kat sini
            }
    });

    function changeEngagements(elem) 
    {
    $('#other_engagements_write').val($(elem).val());    
    }

    $('#potentialServices2').change(function(){
        let potentialServicesName   = $("#potentialServices2 option:selected").text(); 
        let potentialServices2      = $('#potentialServices2').val();

            if(potentialServices2 != 'amount')
            {
                $('#potentialServices3').val(potentialServicesName);
                $('#other_potentialServices_write').val(potentialServices2);

                $( "#potentialServices3" ).prop( "disabled", true );
            }else{
                $('#potentialServices3').val(''); 
                $('#other_potentialServices_write').val();

                $( "#potentialServices3" ).prop( "disabled", false );
            }
        });

        function changePotentialServices(elem) 
        {
        $('#other_potentialServices_write').val($(elem).val());    
        }
</script>