From dedd7cd932b53dc8f238ace4a10c8fc53e0c76bc Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Thu, 11 Oct 2018 18:01:25 +0200
Subject: [PATCH] FEAT #8544 Fix color

---
 apps/maarch_entreprise/js/functions.js                   | 3 +++
 apps/maarch_entreprise/js/indexing.js                    | 3 +++
 .../my_contacts/get_last_contact_address.php             | 5 ++++-
 src/app/contact/controllers/ContactController.php        | 9 ++++++++-
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/apps/maarch_entreprise/js/functions.js b/apps/maarch_entreprise/js/functions.js
index 0636966c713..3cc461a14a7 100755
--- a/apps/maarch_entreprise/js/functions.js
+++ b/apps/maarch_entreprise/js/functions.js
@@ -2907,6 +2907,9 @@ function affiche_reference() {
 function erase_contact_external_id(id, erase_id) {
     if ($j('#' + id).val() == '') {
         $j('#' + erase_id).val('');
+        if (id == "contact") {
+            $j('#contact').css("background-color", "");
+        }
     }
 }
 
diff --git a/apps/maarch_entreprise/js/indexing.js b/apps/maarch_entreprise/js/indexing.js
index 3a62e11bd0d..6a7183678db 100755
--- a/apps/maarch_entreprise/js/indexing.js
+++ b/apps/maarch_entreprise/js/indexing.js
@@ -1717,6 +1717,9 @@ function set_new_contact_address(path_manage_script, id_div, close,transmission)
             } else if (parent.parent.$('contact')  && parent.parent.$('add_multi_contact_tr').style.display == 'none') {
                 parent.parent.$('contact').value = response.contactName;
             }
+            if (response.rateColor != "") {
+                parent.$j('#contact').css('background-color', response.rateColor);
+            }
             if (parent.$('email') && parent.$('add_multi_contact_tr').style.display != 'none') {
                 parent.$('email').value = response.contactName;
             } else if (parent.parent.$('email') && parent.parent.$('add_multi_contact_tr').style.display != 'none') {
diff --git a/apps/maarch_entreprise/my_contacts/get_last_contact_address.php b/apps/maarch_entreprise/my_contacts/get_last_contact_address.php
index 792391adf83..97ac05f07f5 100755
--- a/apps/maarch_entreprise/my_contacts/get_last_contact_address.php
+++ b/apps/maarch_entreprise/my_contacts/get_last_contact_address.php
@@ -128,5 +128,8 @@ if (!empty($trimed)) {
 $contactId = $res->contact_id;
 $addressId = $res->ca_id;
 
-echo "{ status: 1, contactName: '" . addslashes($contact) . "', contactId: '" . $contactId . "', addressId: '" . $addressId . "'}";
+$contactData = \Contact\models\ContactModel::getOnView(['select' => ['*'], 'where' => ['ca_id = ?'], 'data' => [$addressId]]);
+$rate = \Contact\controllers\ContactController::getFillingRate(['contact' => (array)$contactData[0]]);
+
+echo "{ status: 1, contactName: '" . addslashes($contact) . "', contactId: '" . $contactId . "', addressId: '" . $addressId . "', rateColor: '". $rate['color']."'}";
 exit;
\ No newline at end of file
diff --git a/src/app/contact/controllers/ContactController.php b/src/app/contact/controllers/ContactController.php
index 5e6e65c594a..230486fca7e 100644
--- a/src/app/contact/controllers/ContactController.php
+++ b/src/app/contact/controllers/ContactController.php
@@ -202,7 +202,6 @@ class ContactController
         }
 
         $data = $request->getParams();
-
         $check = Validator::boolType()->validate($data['enable']);
         $check = $check && Validator::arrayType()->validate($data['rating_columns']);
         $check = $check && Validator::intVal()->notEmpty()->validate($data['first_threshold']) && $data['first_threshold'] > 0 && $data['first_threshold'] < 99;
@@ -228,6 +227,14 @@ class ContactController
         $contactsFilling['rating_columns'] = json_decode($contactsFilling['rating_columns']);
 
         if ($contactsFilling['enable'] && !empty($contactsFilling['rating_columns'])) {
+            if ($aArgs['contact']['is_corporate_person'] == 'N') {
+                foreach ($contactsFilling['rating_columns'] as $key => $value) {
+                    if (in_array($value, ['firstname', 'lastname', 'title', 'function'])) {
+
+                        $contactsFilling['rating_columns'][$key] = 'contact_' . $value;
+                    }
+                }
+            }
             $percent = 0;
             foreach ($contactsFilling['rating_columns'] as $ratingColumn) {
                 if (!empty($aArgs['contact'][$ratingColumn])) {
-- 
GitLab