Heray-Was-Here
Server : Apache
System : Linux mail.lomejor.cr 6.8.0-1059-azure #65~22.04.1-Ubuntu SMP Thu May 28 16:59:19 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.2.31
Disable Function : NONE
Directory :  /var/www/erp/htdocs/custom/paiedolibarr/class/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/erp/htdocs/custom/paiedolibarr/class/paiedolibarr.class.php
<?php 
dol_include_once('/core/lib/admin.lib.php');
dol_include_once('/paiedolibarr/class/paiedolibarr_paies.class.php');
require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
class paiedolibarr
{
    public function __construct($db)
    {   
        global $langs;

        $this->db = $db;
        $this->paiedolibarrels = [
            'cote_d_ivoire'     => $langs->trans('paieCote_d_ivoireModel'),
            'france'            => $langs->trans('paieFranceModel'),
            'cameroun'          => $langs->trans('paieCamerounModel'),
        ];
    }
    
    public function upgradeTheModule()
    {
        global $conf, $langs;

        dol_include_once('/paiedolibarr/core/modules/modpaiedolibarr.class.php');
        $modpaiedolibarr = new modpaiedolibarr($this->db);

        $lastversion    = $modpaiedolibarr->version;
        $currentversion = dolibarr_get_const($this->db, 'PAIEDOLIBARR_LAST_VERSION_OF_MODULE', 0);

        // echo "lastversion : ".$lastversion."<br>";
        // echo "currentversion : ".$currentversion."<br>";
        if (!$currentversion || ($currentversion && $lastversion != $currentversion)){
            $res = $this->initpaiedolibarrModule($lastversion);
            $error += $modpaiedolibarr->delete_menus();
            $error += $modpaiedolibarr->insert_menus();
            if($res)
                dolibarr_set_const($this->db, 'PAIEDOLIBARR_LAST_VERSION_OF_MODULE', $lastversion, 'chaine', 0, '', 0);
            return 1;
        }
        return 0;
    }
    
    public function initpaiedolibarrModule($lastversion = '')
    {
        global $conf, $langs;

        // if (!dolibarr_get_const($this->db,'PAIE_FIRST_USE_NEW_VERSION',$conf->entity)){
        //     $error = 0;
        //     $sql = "DROP TABLE `".MAIN_DB_PREFIX."paiedolibarr_paies`";
        //     $resql = $this->db->query($sql);
        //     if(!$resql) $error++;

        //     $sql = "DROP TABLE `".MAIN_DB_PREFIX."paiedolibarr_rules`";
        //     $resql = $this->db->query($sql);
        //     if(!$resql) $error++;
            
        //     $sql = "DROP TABLE `".MAIN_DB_PREFIX."paiedolibarr_paiesrules`";
        //     $resql = $this->db->query($sql);
        //     if(!$resql) $error++;

        //     dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIREBRUT','SALAIRE_BASE + IND_LOG + ALL_FAM' ,'chaine',0,'',$conf->entity);
        //     dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIRENET','(SALAIRE_BASE + IND_LOG + ALL_FAM) - MFP_EMPLOYE - INSS_EMPLOYE - BHB - IRE - AUTRES_RETENUS' ,'chaine',0,'',$conf->entity);
        //     dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_NETAPAYER','(SALAIRE_BASE + IND_LOG + ALL_FAM) - MFP_EMPLOYE - INSS_EMPLOYE - BHB - IRE - AUTRES_RETENUS' ,'chaine',0,'',$conf->entity);

        //     dolibarr_set_const($this->db,'PAIE_NUMBER_OF_DIGITS_AFTER_THE_DECIMAL_POINT','0' ,'chaine',0,'',$conf->entity);

        //     if(!$error){
        //         dolibarr_set_const($this->db,'PAIE_FIRST_USE_NEW_VERSION','1' ,'chaine',0,'',$conf->entity);
        //     } else {
        //         return false;
        //     }
        // }

        $sql = "CREATE TABLE IF NOT EXISTS `".MAIN_DB_PREFIX."paiedolibarr_paies` (
          `rowid` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
          ,`fk_user` int(11) DEFAULT '0'
          ,`ref` varchar(255) DEFAULT NULL
          ,`label` varchar(255) DEFAULT NULL
          ,`period` date DEFAULT NULL
          ,`salairebrut` DOUBLE(24,4) NULL DEFAULT '0'
          ,`salairenet` DOUBLE(24,4) NULL DEFAULT '0'
          ,`netapayer` DOUBLE(24,4) NULL DEFAULT '0'
          ,`comment` varchar(755) NULL
          ,`entity` int(11) NOT NULL DEFAULT ".$conf->entity."
        )";
        $resql = $this->db->query($sql);
        $resql = $this->db->query("ALTER TABLE `".MAIN_DB_PREFIX."paiedolibarr_paies` ADD `salairebrut` DOUBLE(24,4) NULL DEFAULT '0' AFTER `period`");
        $resql = $this->db->query("ALTER TABLE `".MAIN_DB_PREFIX."paiedolibarr_paies` ADD `salairenet` DOUBLE(24,4) NULL DEFAULT '0' AFTER `salairebrut`");

        $sql = "CREATE TABLE IF NOT EXISTS `".MAIN_DB_PREFIX."paiedolibarr_rules` (
          `rowid` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
          ,`code` varchar(255) DEFAULT NULL
          ,`label` varchar(255) DEFAULT NULL
          ,`category` varchar(40) DEFAULT NULL
          ,`amounttype` varchar(10) NULL DEFAULT 'FIX'
          ,`amount` DOUBLE(24,4) NULL DEFAULT '0'
          ,`ordercalcul` int(11) DEFAULT '0'
          ,`formule` varchar(500) DEFAULT '0'
          ,`total` DOUBLE(24,4) NULL DEFAULT '0'
          ,`entity` int(11) NOT NULL DEFAULT ".$conf->entity."
        )";
        $resql = $this->db->query($sql);

        $sql = "CREATE TABLE IF NOT EXISTS `".MAIN_DB_PREFIX."paiedolibarr_paiesrules` (
          `rowid` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
          ,`fk_paie` int(11) DEFAULT NULL
          ,`code` varchar(255) DEFAULT NULL
          ,`label` varchar(255) DEFAULT NULL
          ,`category` varchar(40) DEFAULT NULL
          ,`amounttype` varchar(10) NULL DEFAULT 'FIX'
          ,`formule` varchar(500) DEFAULT '0'
          ,`total` DOUBLE(24,4) NULL DEFAULT '0'
        )";
        $resql = $this->db->query($sql);
        $resql = $this->db->query("ALTER TABLE `".MAIN_DB_PREFIX."paiedolibarr_rules` ADD UNIQUE (code);");

        require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
        $extrafields = new ExtraFields($this->db);

        $extrafields->addExtraField('paiedolibarrparts', 'paieParts', "varchar", "988", 40, "user");
        // $arr = array('options'=>array('M'=>$langs->trans('paieMarie'),'C'=>$langs->trans('paieCelibataire'),'CPLE'=>$langs->trans('paieCouple')));
        // $extrafields->addExtraField('paiedolibarrunderline1', 'paiedolibarr', "separate", "987", 500, "user");
        
        // $extrafields->addExtraField('paiedolibarrsituation_f', 'paiesituation_f', "select", "988", '', "user",0,0,'',$arr,1);
        // $extrafields->addExtraField('paiedolibarrnbrenfants', 'paienbrenfants', "varchar", "988", 5, "user");
        // $extrafields->addExtraField('paiedolibarrpartigr', 'paiePart_IGR', "varchar", "988", 40, "user");
        // $extrafields->addExtraField('paiecnss', 'paiecnss', "varchar", "988", 40, "user");
        // $extrafields->addExtraField('paiedolibarrcategorie', 'paiecategorie', "varchar", "988", 40, "user");
        // $extrafields->addExtraField('paiedolibarrqualification', 'paieQualification', "varchar", "988", 40, "user");
        // $extrafields->addExtraField('paiedolibarrzone', 'paiezone', "varchar", "988", 40, "user");
        // $extrafields->addExtraField('paiedolibarrechelon', 'paieechelon', "varchar", "988", 40, "user");
        // $extrafields->addExtraField('paieniveau', 'paieNiveau', "varchar", "988", 40, "user");









        $sql = "INSERT INTO `".MAIN_DB_PREFIX."paiedolibarr_rules` (`rowid`, `code`, `label`, `category`, `amounttype`, `amount`, `ordercalcul`, `formule`, `total`, `entity`) VALUES
            (1, 'SALAIRE_BASE', 'Salaire de base', 'BRUT', 'CALCULATED', 0.0000, 1, 'USER_SALARY', 0.0000, ".$conf->entity."),
            (22, 'IND_LOG', 'Ind. log', 'BRUT', 'CALCULATED', 0.0000, 2, 'SALAIRE_BASE * (60/100)', 0.0000, ".$conf->entity."),
            (23, 'IND_DEPLAC', 'Ind. Déplacement', 'BRUT', 'CALCULATED', 0.0000, 3, 'SALAIRE_BASE * (15/100)', 0.0000, ".$conf->entity."),
            (33, 'ALL_FAM', 'ALL FAM', 'BRUT', 'FIX', 0.0000, 4, '0', 0.0000, ".$conf->entity."),
            (55, 'MFP_EMPLOYE', 'MFP employé 4%', 'RETENUES', 'CALCULATED', 0.0000, 5, 'SALAIRE_BASE * (4/100)', 0.0000, ".$conf->entity."),
            (66, 'MFP_PATRONAL', 'MFP Patronal 6%', 'RETENUES', 'CALCULATED', 0.0000, 6, 'SALAIRE_BASE * (6/100)', 0.0000, ".$conf->entity."),
            (77, 'INSS_EMPLOYE', 'INSS employé 4%', 'RETENUES', 'FIX', 100.0000, 7, '0', 0.0000, ".$conf->entity."),
            (88, 'INSS_PENSION', 'INSS Pension part patronale 6%', 'RETENUES', 'CALCULATED', 27000.0000, 8, '(SALAIRE_BASE + IND_LOG + ALL_FAM)>450000 ? 27000 : (SALAIRE_BASE + IND_LOG + ALL_FAM)*6/100', 0.0000, ".$conf->entity."),
            (99, 'INSS_RISK', 'INSS risq prof part patronale 3%', 'RETENUES', 'CALCULATED', 2400.0000, 9, '((SALAIRE_BASE + IND_LOG + ALL_FAM)>80000) ? 2400 : (SALAIRE_BASE + IND_LOG + ALL_FAM)*3/100', 0.0000, ".$conf->entity."),
            (100, 'BHB', 'Pension complémentaire BHB', 'RETENUES', 'FIX', 0.0000, 10, '0', 0.0000, ".$conf->entity."),
            (110, 'BASE_IMPO', 'BASE imposable', 'RETENUES', 'CALCULATED', 0.0000, 11, '(SALAIRE_BASE + IND_LOG + ALL_FAM) - IND_LOG - MFP_EMPLOYE - INSS_EMPLOYE - BHB', 0.0000, ".$conf->entity."),
            (120, 'IRE', 'IRE', 'RETENUES', 'CALCULATED', 0.0000, 12, '(BASE_IMPO>300000) ? ( (BASE_IMPO-300000)*0.3+30000 ) : ( (BASE_IMPO>150000) ? ( (BASE_IMPO-150000)*0.2 ) : (BASE_IMPO<150000 ? 0 : 0) )', 0.0000, ".$conf->entity."),
            (131, 'AUTRES_RETENUS', 'Autres retenues', 'AUTRESRETENUES', 'FIX', 0.0000, 13, '0', 0.0000, ".$conf->entity.");";
        $resql = $this->db->query($sql);
        $resql = $this->db->query($sql);

        if (!dolibarr_get_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIREBRUT',$conf->entity))
            dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIREBRUT','SALAIRE_BASE + IND_LOG + ALL_FAM' ,'chaine',0,'',$conf->entity);
        if (!dolibarr_get_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIRENET',$conf->entity))
            dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIRENET','(SALAIRE_BASE + IND_LOG + ALL_FAM) - MFP_EMPLOYE - INSS_EMPLOYE - BHB - IRE - AUTRES_RETENUS' ,'chaine',0,'',$conf->entity);
        if (!dolibarr_get_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_NETAPAYER',$conf->entity))
            dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_NETAPAYER','(SALAIRE_BASE + IND_LOG + ALL_FAM) - MFP_EMPLOYE - INSS_EMPLOYE - BHB - IRE - AUTRES_RETENUS' ,'chaine',0,'',$conf->entity);
        if (!dolibarr_get_const($this->db,'PAIE_NUMBER_OF_DIGITS_AFTER_THE_DECIMAL_POINT',$conf->entity))
            dolibarr_set_const($this->db,'PAIE_NUMBER_OF_DIGITS_AFTER_THE_DECIMAL_POINT','2' ,'chaine',0,'',$conf->entity);







        // // Version 1
        // $sql = "INSERT INTO `".MAIN_DB_PREFIX."paiedolibarr_rules` (`rowid`, `code`, `label`, `category`, `amounttype`, `amount`, `ordercalcul`, `formule`, `total`, `entity`) VALUES
        // (1, 'SALAIRE_BASE', 'Salaire de base', 'BRUT', 'CALCULATED', 0.0000, 1, 'USER_SALARY', 0.0000, ".$conf->entity."),
        // (22, 'ANCIENNETE', 'Ancienneté', 'BRUT', 'CALCULATED', 0.0000, 2, 'SALAIRE_BASE * (YEARS_IN_COMPANY/100)', 0.0000, ".$conf->entity."),
        // (23, 'PRIME_CAISSE', 'Prime de caisse', 'BRUT', 'FIX', 0.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (33, 'DIPLOME', 'Prime de DiplĂŽme ', 'BRUT', 'FIX', 8000.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (44, 'P_ENCOURAGEMENT', 'Prime d’encouragement', 'BRUT', 'FIX', 70104.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (45, 'CONGES', 'Congés', 'BRUT', 'FIX', 0.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (55, 'CNSS', 'CNSS (Caisse nationale de sécurité sociale)', 'RETENUES', 'CALCULATED', 0.0000, 3, '0.04 * (SALAIRE_BASE + ANCIENNETE + DIPLOME + P_ENCOURAGEMENT + PRIME_CAISSE + CONGES)', 0.0000, ".$conf->entity."),
        // (66, 'BASE_IMPOSABLE', 'Base imposable', 'RETENUES', 'CALCULATED', 0.0000, 4, '((SALAIRE_BASE + ANCIENNETE + DIPLOME + P_ENCOURAGEMENT + PRIME_CAISSE + CONGES) - CNSS) * 0.8', 0.0000, ".$conf->entity."),
        // (77, 'IRPP', 'IRPP', 'RETENUES', 'FIX', 10731.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (88, 'INDE_TRANSPORT', 'Indemnité de transport', 'INDEMNITES', 'FIX', 25000.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (99, 'INDE_PANIER', 'Indemnité de panier', 'INDEMNITES', 'FIX', 60000.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (100, 'AUTRES_PRIMES', 'Autres primes', 'INDEMNITES', 'FIX', 90000.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (110, 'AVANCES', 'Avances', 'AUTRESRETENUES', 'FIX', 0.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (120, 'ACOMPTES', 'Acomptes', 'AUTRESRETENUES', 'FIX', 0.0000, 0, '0', 0.0000, ".$conf->entity."),
        // (130, 'PRET', 'PrĂȘt', 'AUTRESRETENUES', 'FIX', 0.0000, 0, '0', 0.0000, ".$conf->entity.");";
        // $resql = $this->db->query($sql);

        // if (!dolibarr_get_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIREBRUT',$conf->entity))
        //     dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIREBRUT','SALAIRE_BASE + ANCIENNETE + DIPLOME + P_ENCOURAGEMENT + PRIME_CAISSE + CONGES' ,'chaine',0,'',$conf->entity);
        // if (!dolibarr_get_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIRENET',$conf->entity))
        //     dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_SALAIRENET','SALAIRE_BASE + ANCIENNETE + DIPLOME + P_ENCOURAGEMENT + PRIME_CAISSE + CONGES' ,'chaine',0,'',$conf->entity);
        // if (!dolibarr_get_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_NETAPAYER',$conf->entity))
        //     dolibarr_set_const($this->db,'PAIEDOLIBARR_FORM_CALCUL_NETAPAYER','((SALAIRE_BASE + ANCIENNETE + DIPLOME + P_ENCOURAGEMENT + PRIME_CAISSE + CONGES) + INDE_TRANSPORT + INDE_PANIER + AUTRES_PRIMES) - CNSS - IRPP - AVANCES - ACOMPTES - PRET' ,'chaine',0,'',$conf->entity);


        return 1;
    }

    public function showNavigations($object, $linkback, $paramid = 'id', $fieldid = 'rowid', $moreparam = '')
    {

        global $langs, $conf;

        $ret = $result = '';
        $previous_ref = $next_ref = '';

        $fieldref = $fieldid;

        $oldref = ''; if($object->ref) $oldref = $object->ref;

        $object->ref = $object->rowid;

        $object->load_previous_next_ref(' AND entity ='.$conf->entity, $fieldid, 0);

        $navurl = $_SERVER["PHP_SELF"];

        $page = GETPOST('page');

        $stringforfirstkey = '';
        // // accesskey is for Windows or Linux:  ALT + key for chrome, ALT + SHIFT + KEY for firefox
        // // accesskey is for Mac:               CTRL + key for all browsers
        // $stringforfirstkey = $langs->trans("KeyboardShortcut");
        // if ($conf->browser->name == 'chrome')
        // {
        //     $stringforfirstkey .= ' ALT +';
        // }
        // elseif ($conf->browser->name == 'firefox')
        // {
        //     $stringforfirstkey .= ' ALT + SHIFT +';
        // }
        // else
        // {
        //     $stringforfirstkey .= ' CTL +';
        // }
        // $stringforfirstkeyp .= $stringforfirstkey.' p';
        // $stringforfirstkeyn .= $stringforfirstkey.' n';

        $previous_ref = $object->ref_previous ? '<a accesskey="p" title="'.$stringforfirstkeyp.'" class="classfortooltip" href="'.$navurl.'?'.$paramid.'='.urlencode($object->ref_previous).$moreparam.'"><i class="fa fa-chevron-left"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>';
        
        $next_ref     = $object->ref_next ? '<a accesskey="n" title="'.$stringforfirstkeyn.'" class="classfortooltip" href="'.$navurl.'?'.$paramid.'='.urlencode($object->ref_next).$moreparam.'"><i class="fa fa-chevron-right"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>';

        $ret = '';
        // print "xx".$previous_ref."x".$next_ref;
        $ret .= '<!-- Start banner content --><div style="vertical-align: middle;width:100%;display:inline-block;">';


        if ($previous_ref || $next_ref || $linkback)
        {
            $ret .= '<div class="pagination paginationref"><ul class="right">';
        }
        if ($linkback)
        {
            $ret .= '<li class="noborder litext">'.$linkback.'</li>';
        }
        if (($previous_ref || $next_ref))
        {
            $ret .= '<li class="pagination">'.$previous_ref.'</li>';
            $ret .= '<li class="pagination">'.$next_ref.'</li>';
        }
        if ($previous_ref || $next_ref || $linkback)
        {
            $ret .= '</ul></div>';
        }

        // $result .= '<div>';
        $result .= $ret;
        // $result .= '</div>';
        $result .= '</div>';

        if($oldref) $object->ref = $oldref;

        return $result;
    }

    
    public function getSelectPaieDolibarrels($slctd='',$name='paiedolibarrel', $showempty=0, $disabled='')
    {
        global $langs;
        $paiedolibarrels = $this->paiedolibarrels;
        $select ='<select class="select_'.$name.'" name="'.$name.'" '.$disabled.'>';
            // if($showempty) $select .='<option value="0"></option>';
            foreach ($paiedolibarrels as $keyr => $namer) {

                $slctdt = ($keyr == $slctd) ? 'selected' : '';
                $select .='<option value="'.$keyr.'" '.$slctdt.'>'.$namer.'</option>';
            }
        $select .='</select>';

        return $select;
    }

    function number_format($number, $aftercomma=2, $comma=',',$space=' ')
    {
        global $conf;

        $aftercomma = $conf->global->PAIE_NUMBER_OF_DIGITS_AFTER_THE_DECIMAL_POINT;
        $nbrform = number_format($number, $aftercomma, $comma, $space);

        return $nbrform;
    }

    function employeeinfo($fk_paie, $lastday=null)
    {
        global $langs;

        $paie  = new paiedolibarr_paies($this->db);
        $paie->fetch($fk_paie);

        $employee = new User($this->db);
        $employee->fetch($paie->fk_user);

        $account = new UserBankAccount($this->db);
        $account->fetch(0, '', $paie->fk_user);

        $results = array();

        $results['matricule']    = $paie->matricule;
        $results['situation_f']  = $paie->situation_f;
        $results['nbrenfants']   = $paie->nbrenfants;
        $results['partigr']      = $paie->partigr;
        $results['cnss']         = $paie->cnss;
        $results['categorie']    = $paie->categorie;
        $results['qualification']= $paie->qualification;
        $results['zone']         = $paie->zone;
        $results['echelon']      = $paie->echelon;
        $results['niveau']       = $paie->niveau;

        $results['ibanrib']     = '';
        $results['anciennete']  = '';
        $results['job']         = '';
        $results['adresse']     = '';
        

        $results['name'] = $employee->lastname.' '.$employee->firstname;
        $results['birth'] = $employee->birth;
        $results['dateemployment'] = $employee->dateemployment;

        if ($account->id > 0)
            $results['ibanrib'] = $account->iban;

        $results['adresse'] = $langs->convToOutputCharset(dol_format_address($employee, 1, "<br>", $langs));

        $results['entree'] = date('d/m/Y');

        if($employee->dateemployment){

            $date1 = strtotime($lastday);  
            $date2 = $employee->dateemployment;  
              
            $diff = abs($date2 - $date1);
            $years = floor($diff / (365*60*60*24));
            $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
            $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); 

     
            $ancie = '';
            $ancie .= $years.' ';

            $yt = strtolower($langs->trans('Years'));
            $ancie .= substr(($yt), 0, 2).'(s)';

            if($months > 0){
                $ancie .= ', '.$months.' ';
                if($months > 1)
                    $ancie .= strtolower($langs->trans('Months'));
                else
                    $ancie .= strtolower($langs->trans('Month'));
            }

            if($days > 0){
                $ancie .= ', '.$days.' ';
                if($days > 1)
                    $ancie .= strtolower($langs->trans('Days'));
                else
                    $ancie .= strtolower($langs->trans('Day'));
            }

            $results['anciennete'] = $ancie;
        }

        if($employee->job)
            $results['job'] = $employee->job;

        return $results;
    }

    function employeeinfo_old($fk_user, $lastday=null)
    {
        global $langs;
        $employee = new User($this->db);
        $employee->fetch($fk_user);


        $account = new UserBankAccount($this->db);
        $account->fetch(0, '', $fk_user);


        $results = array();
        $results['matricule'] = $results['zone'] = $results['categorie'] = $results['situation_f'] = $results['echelon'] = $results['cnss'] = $results['niveau'] = $results['anciennete'] = $results['job'] = $results['adresse'] = $results['nbrenfants'] = $results['partigr'] = $results['qualification'] = $results['ibanrib'] = '';
        $results['name'] = $employee->lastname.' '.$employee->firstname;
        $results['birth'] = $employee->birth;
        $results['dateemployment'] = $employee->dateemployment;

        $results['situation_f'] = 'C';
        if($employee->array_options){
            $dt = $employee->array_options;
            if(isset($dt['options_paiedolibarrmatricule'])){
                $results['matricule'] = $dt['options_paiedolibarrmatricule'];
            }
            if(isset($dt['options_paiedolibarrzone'])){
                $results['zone'] = $dt['options_paiedolibarrzone'];
            }
            if(isset($dt['options_paiedolibarrcategorie'])){
                $results['categorie'] = $dt['options_paiedolibarrcategorie'];
            }
            if(isset($dt['options_paiedolibarrechelon'])){
                $results['echelon'] = $dt['options_paiedolibarrechelon'];
            }
            if(isset($dt['options_paiecnss'])){
                $results['cnss'] = $dt['options_paiecnss'];
            }
            if(isset($dt['options_paieniveau'])){
                $results['niveau'] = $dt['options_paieniveau'];
            }
            if(isset($dt['options_paiedolibarrsituation_f']) && !empty($dt['options_paiedolibarrsituation_f'])){
                $results['situation_f'] = $dt['options_paiedolibarrsituation_f'];
            }
            if(isset($dt['options_paiedolibarrnbrenfants'])){
                $results['nbrenfants'] = $dt['options_paiedolibarrnbrenfants'];
            }
            if(isset($dt['options_paiedolibarrpartigr'])){
                $results['partigr'] = $dt['options_paiedolibarrpartigr'];
            }
            if(isset($dt['options_paiedolibarrqualification'])){
                $results['qualification'] = $dt['options_paiedolibarrqualification'];
            }
        }

        if ($account->id > 0)
            $results['ibanrib'] = $account->iban;

        $results['adresse'] = $langs->convToOutputCharset(dol_format_address($employee, 1, "<br>", $langs));


        $results['entree'] = date('d/m/Y');


        if($employee->dateemployment){

            $date1 = strtotime($lastday);  
            $date2 = $employee->dateemployment;  
              
            $diff = abs($date2 - $date1);
            $years = floor($diff / (365*60*60*24));
            $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
            $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); 

     
            $ancie = '';
            $ancie .= $years.' ';

            $yt = strtolower($langs->trans('Years'));
            $ancie .= substr(($yt), 0, 2).'(s)';

            if($months > 0){
                $ancie .= ', '.$months.' ';
                if($months > 1)
                    $ancie .= strtolower($langs->trans('Months'));
                else
                    $ancie .= strtolower($langs->trans('Month'));
            }

            if($days > 0){
                $ancie .= ', '.$days.' ';
                if($days > 1)
                    $ancie .= strtolower($langs->trans('Days'));
                else
                    $ancie .= strtolower($langs->trans('Day'));
            }

            $results['anciennete'] = $ancie;
        }

        if($employee->job)
            $results['job'] = $employee->job;





        // print_r($employee);die;

        return $results;
    }

    public function getExcludedUsers($period)
    {
      global $conf;
        $sql = "SELECT * FROM ".MAIN_DB_PREFIX."paiedolibarr_paies WHERE 1>0";
        $sql .= " AND period = '".$period."'";
        $sql .= " AND entity = '".$conf->entity."'";
        $resql = $this->db->query($sql);
        // echo $sql;
        $users = array();
        if($resql){
            while ($obj = $this->db->fetch_object($resql)) {
                if($obj->fk_user)
                    $users[] = $obj->fk_user;
            }
        }

        
        return $users;
    }

    /**
     *      Return a string with full address formated for output on documents
     *
     *      @param  Translate             $outputlangs          Output langs object
     *      @param  Societe               $sourcecompany        Source company object
     *      @param  Societe|string|null   $targetcompany        Target company object
     *      @param  Contact|string|null   $targetcontact        Target contact object
     *      @param  int                   $usecontact           Use contact instead of company
     *      @param  string                $mode                 Address type ('source', 'target', 'targetwithdetails', 'targetwithdetails_xxx': target but include also phone/fax/email/url)
     *      @param  Object                $object               Object we want to build document for
     *      @return string                                      String with full address
     */
    function pdf_build_address($outputlangs, $sourcecompany, $targetcompany = '', $targetcontact = '', $usecontact = 0, $mode = 'source', $object = null)
    {
        global $conf, $hookmanager;

        $outputlangs->loadLangs(array("main", "propal", "companies", "bills"));

        if ($mode == 'source' && !is_object($sourcecompany)) return -1;
        if ($mode == 'target' && !is_object($targetcompany)) return -1;

        if (!empty($sourcecompany->state_id) && empty($sourcecompany->state))             $sourcecompany->state = getState($sourcecompany->state_id);
        if (!empty($targetcompany->state_id) && empty($targetcompany->state))             $targetcompany->state = getState($targetcompany->state_id);

        $reshook = 0;
        $stringaddress = '';
        
        if ($mode == 'source')
        {
            $withCountry = 0;
            if (!empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) $withCountry = 1;

            $stringaddress .= ($stringaddress ? "<br>" : '').$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, ", ", $outputlangs))."<br>";

            // if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS))
            // {
            //     // Phone
            //     if ($sourcecompany->phone) $stringaddress .= ($stringaddress ? "<br>" : '').$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
            //     // Fax
            //     if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "<br>") : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
            //     // EMail
            //     if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "<br>" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
            //     // Web
            //     if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "<br>" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
            // }
            // Intra VAT
            // if (!empty($conf->global->MAIN_TVAINTRA_IN_SOURCE_ADDRESS))
            // {
                if ($sourcecompany->tva_intra) $stringaddress .= ($stringaddress ? "<br>" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($sourcecompany->tva_intra);
            // }
            // Professionnal Ids
            $reg = array();
            if ((!empty($conf->global->MAIN_PROFID1_IN_SOURCE_ADDRESS) || 1>0) && !empty($sourcecompany->idprof1))
            {
                $tmp = $outputlangs->transcountrynoentities("ProfId1", $sourcecompany->country_code);
                if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
                $stringaddress .= ($stringaddress ? "<br>" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof1);
            }
            if ((!empty($conf->global->MAIN_PROFID2_IN_SOURCE_ADDRESS) || 1>0) && !empty($sourcecompany->idprof2))
            {
                $tmp = $outputlangs->transcountrynoentities("ProfId2", $sourcecompany->country_code);
                if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
                $stringaddress .= ($stringaddress ? "<br>" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof2);
            }
            if ((!empty($conf->global->MAIN_PROFID3_IN_SOURCE_ADDRESS) || 1>0) && !empty($sourcecompany->idprof3))
            {
                $tmp = $outputlangs->transcountrynoentities("ProfId3", $sourcecompany->country_code);
                if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
                $stringaddress .= ($stringaddress ? "<br>" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof3);
            }
            if ((!empty($conf->global->MAIN_PROFID4_IN_SOURCE_ADDRESS) || 1>0) && !empty($sourcecompany->idprof4))
            {
                $tmp = $outputlangs->transcountrynoentities("ProfId4", $sourcecompany->country_code);
                if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
                $stringaddress .= ($stringaddress ? "<br>" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof4);
            }
            if ((!empty($conf->global->MAIN_PROFID5_IN_SOURCE_ADDRESS) || 1>0) && !empty($sourcecompany->idprof5))
            {
                $tmp = $outputlangs->transcountrynoentities("ProfId5", $sourcecompany->country_code);
                if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
                $stringaddress .= ($stringaddress ? "<br>" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof5);
            }
            if ((!empty($conf->global->MAIN_PROFID6_IN_SOURCE_ADDRESS) || 1>0) && !empty($sourcecompany->idprof6))
            {
                $tmp = $outputlangs->transcountrynoentities("ProfId6", $sourcecompany->country_code);
                if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
                $stringaddress .= ($stringaddress ? "<br>" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof6);
            }
            if (!empty($conf->global->PDF_ADD_MORE_AFTER_SOURCE_ADDRESS)) {
                $stringaddress .= ($stringaddress ? "<br>" : '').$conf->global->PDF_ADD_MORE_AFTER_SOURCE_ADDRESS;
            }
        }

        return $stringaddress;
    }
   


    public function getDataToSend2($link, $token, $decodejsn = true){
        $ch = curl_init();
        $link = trim($link, '/');
        curl_setopt($ch, CURLOPT_URL, $link.'/api/index.php/dolibarrmobileapi/'.$toget);
        // print_r($result);die();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
        $headers = array();
        $headers[] = 'Accept: application/json';
        $headers[] = 'Dolapikey: '.$token;
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $result = curl_exec($ch);
        // if (curl_errno($ch)) return -1;
        if($decodejsn) $result = json_decode($result, true);
        // print_r($result);die();
        curl_close($ch);
        return $result;
    }

}
?>

Hry