| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- <?php
- require_once DOL_DOCUMENT_ROOT . '/product/inventory/class/inventory.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/utils/globalconst.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/utils/emailtemplatehandler.php';
- include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
- class StorageInventory extends Inventory
- {
- public $statuses = [];
- const EMAIL_TEMPLATE = 'ScrapOrfaultyDeviceTemplate';
- const GLOBAL_CONF_SEND_TO_EMAIL = 'DEVICE_ALERT_EMAIL';
- const GLOBAL_CONF_EMAIL_FROM = 'BBUS_INVOICE_PRINTING_ALERT_EMAIL_FROM';
- function sendMail($status, $ticket_id): void
- {
- $const = new GlobalConst;
- $recipients = $const->load(self::GLOBAL_CONF_SEND_TO_EMAIL);
- $emailFrom = $const->load(self::GLOBAL_CONF_EMAIL_FROM);
- if (!empty($recipients) && !empty($emailFrom)) {
- $emailTemplateHandler = new EmailTemplateHandler;
- $template = $emailTemplateHandler->load(self::EMAIL_TEMPLATE);
- $templateObject = new stdClass();
- foreach ($template as $key => $value) {
- $templateObject->$key = $value;
- }
- if ($templateObject) {
- $vars = [
- '__STATUS__ ' => $status,
- '__TICKETID__' => $ticket_id,
- ];
- $template = $emailTemplateHandler->prepareTemplate($templateObject, $vars);
- $mail = new CMailFile(
- $template->topic,
- $recipients,
- $emailFrom,
- $template->content,
- null,
- null,
- null,
- '',
- '',
- 0,
- 1
- );
- // Send Email
- $mail->sendfile();
- if ($mail->error) {
- print_r($mail->error);
- exit;
- // do something...
- dol_syslog('CRON ALERT EMAIL ERROR: ' . $mail->error, LOG_ERR);
- }
- }
- }
- }
- /**
- * Load object in memory from the database
- *
- * @param int $id Id object
- * @param string $ref Ref
- * @param string $morewhere More SQL filters (' AND ...')
- * @return int <0 if KO, 0 if not found, >0 if OK
- */
- public function fetchByWarehouse($id, $ref = null, $morewhere = '')
- {
- $result = $this->fetchCommon($id, $ref, $morewhere);
- return $result;
- }
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
- /**
- * Return the status
- *
- * @param int $status Id status
- * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto, 6=Long label + Picto
- * @return string Label of status
- */
- public static function LibStatut($status, $mode = 0)
- {
- // phpcs:enable
- global $langs;
- global $db;
- $statusObj = new Statuses($db);
- $statuses = $statusObj::getStatusids($db);
- $labelStatus = array();
- $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
- $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('InventoryStartedShort').')';
- $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
- $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
- foreach($statuses as $key => $val){
- $labelStatus[$key] = $val;
- $labelStatusShort[$key] = $val;
- }
- $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
- $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InventoryStartedShort');
- $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
- $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
- $statusType = 'status'.$status;
- if ($status == self::STATUS_RECORDED) {
- $statusType = 'status6';
- }
- return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode);
- }
- /**
- * Function to show lines of extrafields with output datas.
- * This function is responsible to output the <tr> and <td> according to correct number of columns received into $params['colspan'] or <div> according to $display_type
- *
- * @param Extrafields $extrafields Extrafield Object
- * @param string $mode Show output ('view') or input ('create' or 'edit') for extrafield
- * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan)
- * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names)
- * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names)
- * @param string $onetrtd All fields in same tr td. Used by objectline_create.tpl.php for example.
- * @param string $display_type "card" for form display, "line" for document line display (extrafields on propal line, order line, etc...)
- * @return string String with html content to show
- */
- public function showOptionalsRollerstorage($inventory_id, $extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0, $display_type = 'card')
- {
- global $db, $conf, $langs, $action, $form, $hookmanager;
- if (!is_object($form)) {
- $form = new Form($db);
- }
- if (!is_object($extrafields)) {
- dol_syslog('Bad parameter extrafields for showOptionals', LOG_ERR);
- return 'Bad parameter extrafields for showOptionals';
- }
- if (!is_array($extrafields->attributes[$this->table_element])) {
- dol_syslog("extrafields->attributes was not loaded with extrafields->fetch_name_optionals_label(table_element);", LOG_WARNING);
- }
- $out = '';
- $parameters = array();
- $reshook = $hookmanager->executeHooks('showOptionals', $parameters, $this, $action); // Note that $action and $object may have been modified by hook
- if (empty($reshook)) {
- if (is_array($extrafields->attributes[$this->table_element]) && key_exists('label', $extrafields->attributes[$this->table_element]) && is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) {
- $out .= "\n";
- $out .= '<!-- commonobject:showOptionals --> ';
- $out .= "\n";
- $extrafields_collapse_num = '';
- $e = 0;
- foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $label) {
- // Show only the key field in params
- if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) {
- continue;
- }
- // Test on 'enabled' ('enabled' is different than 'list' = 'visibility')
- $enabled = 1;
- if ($enabled && isset($extrafields->attributes[$this->table_element]['enabled'][$key])) {
- $enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1, 1, '1');
- }
- if (empty($enabled)) {
- continue;
- }
- $visibility = 1;
- if ($visibility && isset($extrafields->attributes[$this->table_element]['list'][$key])) {
- $visibility = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1, 1, '1');
- }
- $perms = 1;
- if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) {
- $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1, 1, '1');
- }
- if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) {
- continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
- } elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) {
- continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation
- } elseif ($mode == 'view' && empty($visibility)) {
- continue;
- }
- if (empty($perms)) {
- continue;
- }
- // Load language if required
- if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
- $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
- }
- $colspan = 0;
- if (is_array($params) && count($params) > 0 && $display_type == 'card') {
- if (array_key_exists('cols', $params)) {
- $colspan = $params['cols'];
- } elseif (array_key_exists('colspan', $params)) { // For backward compatibility. Use cols instead now.
- $reg = array();
- if (preg_match('/colspan="(\d+)"/', $params['colspan'], $reg)) {
- $colspan = $reg[1];
- } else {
- $colspan = $params['colspan'];
- }
- }
- }
- $colspan = intval($colspan);
- switch ($mode) {
- case "view":
- $value = ((!empty($this->array_options) && array_key_exists("options_" . $key . $keysuffix, $this->array_options)) ? $this->array_options["options_" . $key . $keysuffix] : null); // Value may be cleaned or formated later
- break;
- case "create":
- case "edit":
- // We get the value of property found with GETPOST so it takes into account:
- // default values overwrite, restore back to list link, ... (but not 'default value in database' of field)
- $check = 'alphanohtml';
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text'))) {
- $check = 'restricthtml';
- }
- $getposttemp = GETPOST($keyprefix . 'options_' . $key . $keysuffix, $check, 3); // GETPOST can get value from GET, POST or setup of default values overwrite.
- // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
- if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix)) {
- if (is_array($getposttemp)) {
- // $getposttemp is an array but following code expects a comma separated string
- $value = implode(",", $getposttemp);
- } else {
- $value = $getposttemp;
- }
- } else {
- $value = (!empty($this->array_options["options_" . $key]) ? $this->array_options["options_" . $key] : ''); // No GET, no POST, no default value, so we take value of object.
- }
- //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value);
- break;
- }
- // Output value of the current field
- if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') {
- $extrafields_collapse_num = '';
- $extrafield_param = $extrafields->attributes[$this->table_element]['param'][$key];
- if (!empty($extrafield_param) && is_array($extrafield_param)) {
- $extrafield_param_list = array_keys($extrafield_param['options']);
- if (count($extrafield_param_list) > 0) {
- $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
- if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
- $extrafields_collapse_num = $extrafields->attributes[$this->table_element]['pos'][$key];
- }
- }
- }
- // if colspan=0 or 1, the second column is not extended, so the separator must be on 2 columns
- $out .= $extrafields->showSeparator($key, $this, ($colspan ? $colspan + 1 : 2), $display_type, $mode);
- } else {
- $class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
- $csstyle = '';
- if (is_array($params) && count($params) > 0) {
- if (array_key_exists('class', $params)) {
- $class .= $params['class'] . ' ';
- }
- if (array_key_exists('style', $params)) {
- $csstyle = $params['style'];
- }
- }
- // add html5 elements
- $domData = ' data-element="extrafield"';
- $domData .= ' data-targetelement="' . $this->element . '"';
- $domData .= ' data-targetid="' . $this->id . '"';
- $html_id = (empty($this->id) ? '' : 'extrarow-' . $this->element . '_' . $key . '_' . $this->id);
- if ($display_type == 'card') {
- if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) {
- $colspan = 0;
- }
- if ($action == 'selectlines') {
- $colspan++;
- }
- }
- // Convert date into timestamp format (value in memory must be a timestamp)
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date'))) {
- $datenotinstring = null;
- if (array_key_exists('options_' . $key, $this->array_options)) {
- $datenotinstring = $this->array_options['options_' . $key];
- if (!is_numeric($this->array_options['options_' . $key])) { // For backward compatibility
- $datenotinstring = $this->db->jdate($datenotinstring);
- }
- }
- $datekey = $keyprefix . 'options_' . $key . $keysuffix;
- $value = (GETPOSTISSET($datekey)) ? dol_mktime(12, 0, 0, GETPOST($datekey . 'month', 'int', 3), GETPOST($datekey . 'day', 'int', 3), GETPOST($datekey . 'year', 'int', 3)) : $datenotinstring;
- }
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('datetime'))) {
- $datenotinstring = null;
- if (array_key_exists('options_' . $key, $this->array_options)) {
- $datenotinstring = $this->array_options['options_' . $key];
- if (!is_numeric($this->array_options['options_' . $key])) { // For backward compatibility
- $datenotinstring = $this->db->jdate($datenotinstring);
- }
- }
- $timekey = $keyprefix . 'options_' . $key . $keysuffix;
- $value = (GETPOSTISSET($timekey)) ? dol_mktime(GETPOST($timekey . 'hour', 'int', 3), GETPOST($timekey . 'min', 'int', 3), GETPOST($timekey . 'sec', 'int', 3), GETPOST($timekey . 'month', 'int', 3), GETPOST($timekey . 'day', 'int', 3), GETPOST($timekey . 'year', 'int', 3), 'tzuserrel') : $datenotinstring;
- }
- // Convert float submited string into real php numeric (value in memory must be a php numeric)
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double'))) {
- if (GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix) || $value) {
- $value = price2num($value);
- } elseif (isset($this->array_options['options_' . $key])) {
- $value = $this->array_options['options_' . $key];
- }
- }
- // HTML, text, select, integer and varchar: take into account default value in database if in create mode
- if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text', 'varchar', 'select', 'int', 'boolean'))) {
- if ($action == 'create') {
- $value = (GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix) || $value) ? $value : $extrafields->attributes[$this->table_element]['default'][$key];
- }
- }
- $labeltoshow = $langs->trans($label);
- $helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]);
- if ($display_type == 'card') {
- $out .= '<tr ' . ($html_id ? 'id="' . $html_id . '" ' : '') . $csstyle . ' class="field_options_' . $key . ' ' . $class . $this->element . '_extras_' . $key . ' trextrafields_collapse' . $extrafields_collapse_num . (!empty($this->id) ? '_' . $this->id : '') . '" ' . $domData . ' >';
- if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER) && ($action == 'view' || $action == 'valid' || $action == 'editline' || $action == 'confirm_valid' || $action == 'confirm_cancel')) {
- $out .= '<td></td>';
- }
- $out .= '<td class="titlefieldcreate wordbreak';
- } elseif ($display_type == 'line') {
- $out .= '<div ' . ($html_id ? 'id="' . $html_id . '" ' : '') . $csstyle . ' class="fieldline_options_' . $key . ' ' . $class . $this->element . '_extras_' . $key . ' trextrafields_collapse' . $extrafields_collapse_num . (!empty($this->id) ? '_' . $this->id : '') . '" ' . $domData . ' >';
- $out .= '<div style="display: inline-block; padding-right:4px" class="titlefieldcreate wordbreak';
- }
- //$out .= "titlefield";
- //if (GETPOST('action', 'restricthtml') == 'create') $out.='create';
- // BUG #11554 : For public page, use red dot for required fields, instead of bold label
- $tpl_context = isset($params["tpl_context"]) ? $params["tpl_context"] : "none";
- if ($tpl_context != "public") { // Public page : red dot instead of fieldrequired characters
- if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) {
- $out .= ' fieldrequired';
- }
- }
- $out .= '">';
- if ($tpl_context == "public") { // Public page : red dot instead of fieldrequired characters
- if (!empty($extrafields->attributes[$this->table_element]['help'][$key])) {
- $out .= $form->textwithpicto($labeltoshow, $helptoshow);
- } else {
- $out .= $labeltoshow;
- }
- if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) {
- $out .= ' <span style="color: red">*</span>';
- }
- } else {
- if (!empty($extrafields->attributes[$this->table_element]['help'][$key])) {
- $out .= $form->textwithpicto($labeltoshow, $helptoshow);
- } else {
- $out .= $labeltoshow;
- }
- }
- $out .= ($display_type == 'card' ? '</td>' : '</div>');
- $html_id = !empty($this->id) ? $this->element . '_extras_' . $key . '_' . $this->id : '';
- if ($display_type == 'card') {
- // a first td column was already output (and may be another on before if MAIN_VIEW_LINE_NUMBER set), so this td is the next one
- $out .= '<td ' . ($html_id ? 'id="' . $html_id . '" ' : '') . ' class="valuefieldcreate ' . $this->element . '_extras_' . $key . '" ' . ($colspan ? ' colspan="' . $colspan . '"' : '') . '>';
- } elseif ($display_type == 'line') {
- $out .= '<div ' . ($html_id ? 'id="' . $html_id . '" ' : '') . ' style="display: inline-block" class="valuefieldcreate ' . $this->element . '_extras_' . $key . ' extra_inline_' . $extrafields->attributes[$this->table_element]['type'][$key] . '">';
- }
- switch ($mode) {
- case "view":
- $out .= $extrafields->showOutputField($key, $value, '', $this->table_element);
- break;
- case "create":
- if ($key == 'assigned_device') {
- $out .= $extrafields->showInputField($key, $value, ' AND main.fk_warehouse = ' . $inventory_id, $keysuffix, '', 0, $this->id, $this->table_element);
- } else {
- $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id, $this->table_element);
- }
- break;
- case "edit":
- if ($key == 'assigned_device') {
- $out .= $extrafields->showInputField($key, $value, ' AND main.fk_warehouse = ' . $inventory_id, $keysuffix, '', 0, $this->id, $this->table_element);
- } else {
- $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id, $this->table_element);
- }
- break;
- }
- $out .= ($display_type == 'card' ? '</td>' : '</div>');
- if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) {
- $out .= ($display_type == 'card' ? '</tr>' : '</div>');
- } else {
- $out .= ($display_type == 'card' ? '</tr>' : '</div>');
- }
- $e++;
- }
- }
- $out .= "\n";
- // Add code to manage list depending on others
- if (!empty($conf->use_javascript_ajax)) {
- $out .= $this->getJSListDependancies();
- }
- $out .= '<!-- commonobject:showOptionals end --> ' . "\n";
- }
- }
- $out .= $hookmanager->resPrint;
- return $out;
- }
- /**
- * @param string $type Type for prefix
- * @return string Javacript code to manage dependency
- */
- public function getJSListDependancies($type = '_extra')
- {
- $out = '
- <script>
- jQuery(document).ready(function() {
- function showOptions' . $type . '(child_list, parent_list, orig_select)
- {
- var val = $("select[name=\""+parent_list+"\"]").val();
- var parentVal = parent_list + ":" + val;
- if(typeof val == "string"){
- if(val != "") {
- var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
- $("select[name=\""+child_list+"\"] option[parent]").remove();
- $("select[name=\""+child_list+"\"]").append(options);
- } else {
- var options = orig_select.find("option[parent]").clone();
- $("select[name=\""+child_list+"\"] option[parent]").remove();
- $("select[name=\""+child_list+"\"]").append(options);
- }
- } else if(val > 0) {
- var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
- $("select[name=\""+child_list+"\"] option[parent]").remove();
- $("select[name=\""+child_list+"\"]").append(options);
- } else {
- var options = orig_select.find("option[parent]").clone();
- $("select[name=\""+child_list+"\"] option[parent]").remove();
- $("select[name=\""+child_list+"\"]").append(options);
- }
- }
- function setListDependencies' . $type . '() {
- jQuery("select option[parent]").parent().each(function() {
- var orig_select = {};
- var child_list = $(this).attr("name");
- orig_select[child_list] = $(this).clone();
- var parent = $(this).find("option[parent]:first").attr("parent");
- var infos = parent.split(":");
- var parent_list = infos[0];
- //Hide daughters lists
- if ($("#"+child_list).val() == 0 && ($("#"+parent_list).val() == 0 || $("#"+parent_list).val() == undefined)){
- $("#"+child_list).hide();
- //Show mother lists
- } else if ($("#"+parent_list).val() != 0){
- $("#"+parent_list).show();
- }
- //Show the child list if the parent list value is selected
- $("select[name=\""+parent_list+"\"]").click(function() {
- if ($(this).val() != 0){
- $("#"+child_list).show()
- }
- });
- //When we change parent list
- $("select[name=\""+parent_list+"\"]").change(function() {
- showOptions' . $type . '(child_list, parent_list, orig_select[child_list]);
- //Select the value 0 on child list after a change on the parent list
- $("#"+child_list).val(0).trigger("change");
- //Hide child lists if the parent value is set to 0
- if ($(this).val() == 0){
- $("#"+child_list).hide();
- }
- });
- });
- }
- setListDependencies' . $type . '();
- });
- </script>' . "\n";
- return $out;
- }
-
- }
|