szollosil 1 年之前
父节点
当前提交
1fc4f31ee6

+ 2 - 6
custom/bbus/class/commissionhandler.class.php

@@ -232,20 +232,16 @@ class CommissionHandler
         $commissions = 0;
         $result = $this->db->query($sql);
         while ($factureRow = pg_fetch_assoc($result)) {
-            //if (is_null($factureRow['bbt_rowid']) || !is_null($factureRow['bbtip_rowid'])) {
             $commissions += $factureRow['multicurrency_total_ttc'];
-            //}
         }
         return $commissions;
     }
 
     function createSQL($from, $to, $currency, $code, $entity, $user_id, $allComissionInvoicesOfUserInTheGroupFromUserInvoice, $crossShoppingFactures, $crossShopping = false)
     {
-        $sql = "SELECT f.rowid, f.multicurrency_total_ttc, fe.commission, f.ref, bbt.rowid as bbt_rowid, bbtip.rowid as bbtip_rowid
+        $sql = "SELECT f.rowid, f.multicurrency_total_ttc, fe.commission, f.ref
         FROM llx_facture as f 
-        INNER JOIN llx_facture_extrafields as fe ON fe.fk_object = f.rowid
-        LEFT JOIN llx_bbus_bbticket as bbt ON bbt.fk_facture = f.rowid
-        LEFT JOIN llx_bbus_bbticketinvoiceprinting as bbtip ON bbtip.invoice_number = f.ref WHERE";
+        INNER JOIN llx_facture_extrafields as fe ON fe.fk_object = f.rowid WHERE ";
         if ($crossShopping && $crossShoppingFactures != "") {
             $sql .= " f.ref in ({$crossShoppingFactures}) AND";
         } else {

+ 6 - 0
custom/bbus/class/roller_handling.class.php

@@ -2,6 +2,8 @@
 
 require_once DOL_DOCUMENT_ROOT . '/custom/rollerstorage/class/rollerrenthistory.class.php';
 require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/roller_handling_helper.class.php';
+require_once DOL_DOCUMENT_ROOT . '/custom/rollerstorage/class/rollerhistory.class.php';
+
 
 use Luracast\Restler\RestException;
 
@@ -125,11 +127,15 @@ trait RollerHandling
 		if (!in_array($statuscode, $statuses)) {
 			throw new RestException(404, 'Status Not found.');
 		}
+		$inventoryObjFROM = new Inventory($this->db);
+		$resultFROM = $inventoryObjFROM->fetch($rowid);
+		$fromStatus = $inventoryObjFROM->status;
 		ApiBbusLog::ScooterRentLog("RENT_setScooterStatus: ___START___");
 		$sql = "UPDATE llx_inventory SET status = {$statuscode} WHERE rowid = {$rowid}";
 		$result = $this->db->query($sql);
 		$inventoryObj = new Inventory($this->db);
 		$resultupdated = $inventoryObj->fetch($rowid);
+		$this->createHistoryRecord($inventoryObj, $fromStatus);
 		ApiBbusLog::ScooterRentLog("Scooter status changed to {$inventoryObj->status}!");
 		ApiBbusLog::ScooterRentLog("RENT_setScooterStatus: ___END___");
 		return $inventoryObj->status;

+ 20 - 0
custom/bbus/class/roller_handling_helper.class.php

@@ -227,4 +227,24 @@ trait RollerHandligHelper
         }
         return $rollerrenthistory;
     }
+
+    public function createHistoryRecord($obj, $fromStatus){
+		global $user;
+		//print_r($obj);exit;
+
+		$statuses2 = new Statuses($this->db);
+        $status_id_from_statuses = $statuses2->getRowIdFromStatusId($this->db, $fromStatus);
+    	$status_id_to_statuses = $statuses2->getRowIdFromStatusId($this->db, $obj->status);
+		
+		$rollerhistory = new RollerHistory($this->db);
+		$rollerhistory->fk_inventory = $obj->id;
+		$rollerhistory->warehouse_from = $obj->fk_warehouse;
+		$rollerhistory->warehouse_to = $obj->fk_warehouse;
+		$rollerhistory->status_from = $status_id_from_statuses;
+		$rollerhistory->status_to = $status_id_to_statuses;
+		$rollerhistory->status = 0;
+		if ($rollerhistory->create($user) == -1) {
+			dol_syslog("Nem sikerult a rollerstorage_history mentese.");
+		}
+	}
 }

+ 1 - 1
custom/rollerstorage/core/modules/modRollerstorage.class.php

@@ -109,7 +109,7 @@ class modRollerstorage extends DolibarrModules
 			'theme' => 0,
 			// Set this to relative path of css file if module has its own css file
 			'css' => array(
-				'/rollerstorage/css/rollerstorage.css.php',
+				//'/rollerstorage/css/rollerstorage.css.php',
 			),
 			// Set this to relative path of js file if module must load a js on all pages
 			'js' => array(

+ 127 - 0
custom/voucher/class/voucerhistory_assistant.class.php

@@ -0,0 +1,127 @@
+<?php
+$res = 0;
+// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+    $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
+}
+// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
+$tmp2 = realpath(__FILE__);
+$i = strlen($tmp) - 1;
+$j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+    $i--;
+    $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
+    $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
+    $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
+}
+// Try main.inc.php using relative path
+if (!$res && file_exists("../main.inc.php")) {
+    $res = @include "../main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+    $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+    $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+    die("Include of main fails");
+}
+$product_id = GETPOST('product_id', 'alpha');
+$function  = GETPOST('function', 'alpha');
+$selectedDate  = GETPOST('selectedDate', 'alpha');
+
+function checkEvent($product_id, $db)
+{
+    $sql = "SELECT bbbs.is_event FROM public.llx_product_extrafields as pre 
+    INNER JOIN llx_bbus_basicservices as bbbs ON CAST(bbbs.rowid AS VARCHAR) = pre.basic_service
+    WHERE pre.fk_object = {$product_id}";
+    $result = $db->query($sql);
+    if ($db->num_rows($result) > 0) {
+        while ($row = $db->fetch_object($result)) {
+            print $row->is_event == 1 ? 'true' : 'false';
+        }
+    }
+}
+
+function GetAllEventsOfTheSelectedProduct($product_id, $db)
+{
+    $date_from = date("Y-m-d", dol_now());
+    $sql = "SELECT 
+		ac.id, 
+		ac.datep, 
+		ace.max_num, 
+		ace.participants,
+		ace.buffer
+		FROM llx_actioncomm as ac 
+		LEFT JOIN llx_actioncomm_extrafields as ace ON ace.fk_object = ac.id
+		INNER JOIN llx_eventwizard_eventdetails as ed ON ac.fk_element = ed.rowid
+		INNER JOIN llx_eventwizard_eventproduct as ep ON ep.fk_eventdetails = ac.fk_element
+		WHERE ac.code = 'AC_EVENT'
+		AND ep.fk_product = {$product_id}
+		AND ac.datep > '{$date_from} 00:00:00' 
+		ORDER BY ac.datep ASC";
+    $result = $db->query($sql);
+    $datesArray = [];
+    if ($db->num_rows($result) > 0) {
+        while ($row = $db->fetch_object($result)) {
+            $date = [];
+            $date = explode(' ', $row->datep);
+            $datesArray[] = $date[0];
+            //print $row->datep;
+        }
+        if(!empty($datesArray)){
+            print json_encode($datesArray);
+        }else{
+            print '';
+        } 
+    }
+}
+
+function GetAllTimesOfTheSelectedEvent($product_id, $selectedDate, $db)
+{
+    $date = new DateTime($selectedDate);
+    $date->modify('+1 day');
+    $date_to = $date->format('Y-m-d');
+        $sql = "SELECT 
+		ac.id, 
+		ac.datep, 
+		ace.max_num, 
+		ace.participants,
+		ace.buffer
+		FROM llx_actioncomm as ac 
+		LEFT JOIN llx_actioncomm_extrafields as ace ON ace.fk_object = ac.id
+		INNER JOIN llx_eventwizard_eventdetails as ed ON ac.fk_element = ed.rowid
+		INNER JOIN llx_eventwizard_eventproduct as ep ON ep.fk_eventdetails = ac.fk_element
+		WHERE ac.code = 'AC_EVENT'
+		AND ep.fk_product = {$product_id}
+		AND ac.datep > '{$selectedDate} 00:00:00' 
+		AND ac.datep2 < '{$date_to} 00:00:00'
+		ORDER BY ac.datep ASC";
+    $result = $db->query($sql);
+    if ($db->num_rows($result) > 0) {
+        $datesArray = [];
+        while ($row = $db->fetch_object($result)) {
+            $date = [];
+            $date = explode(' ', $row->datep);
+            $time = explode(':', $date[1]);
+            $datesArray[$row->id] = $time[0] . ':' . $time[1];
+        }
+        print json_encode($datesArray);
+    }
+}
+
+if ($function == 'checkEvent') {
+    checkEvent($product_id, $db);
+}
+if ($function == 'GetAllEventsOfTheSelectedProduct') {
+    GetAllEventsOfTheSelectedProduct($product_id, $db);
+}
+if ($function == 'GetAllTimesOfTheSelectedEvent') {
+    GetAllTimesOfTheSelectedEvent($product_id, $selectedDate, $db);
+}

+ 565 - 0
custom/voucher/core/actions_addupdatedelete.inc.php

@@ -0,0 +1,565 @@
+<?php
+/* Copyright (C) 2017-2019 Laurent Destailleur  <eldy@users.sourceforge.net>
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ * or see https://www.gnu.org/
+ */
+
+/**
+ *	\file			htdocs/custom/voucher/core/actions_addupdatedelete.inc.php
+ *  \brief			Code for common actions cancel / add / update / update_extras / delete / deleteline / validate / cancel / reopen / clone
+ */
+
+
+// $action or $cancel must be defined
+// $object must be defined
+// $permissiontoadd must be defined
+// $permissiontodelete must be defined
+// $backurlforlist must be defined
+// $backtopage may be defined
+// $noback may be defined
+// $triggermodname may be defined
+
+$hidedetails = isset($hidedetails) ? $hidedetails : '';
+$hidedesc = isset($hidedesc) ? $hidedesc : '';
+$hideref = isset($hideref) ? $hideref : '';
+
+
+if (!empty($permissionedit) && empty($permissiontoadd)) {
+	$permissiontoadd = $permissionedit; // For backward compatibility
+}
+
+if ($cancel) {
+	/*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
+	if (!empty($backtopageforcancel)) {
+		header("Location: ".$backtopageforcancel);
+		exit;
+	} elseif (!empty($backtopage)) {
+		header("Location: ".$backtopage);
+		exit;
+	}
+	$action = '';
+}
+
+
+// Action to add record
+if ($action == 'add' && !empty($permissiontoadd)) {
+	foreach ($object->fields as $key => $val) {
+		if ($object->fields[$key]['type'] == 'duration') {
+			if (GETPOST($key.'hour') == '' && GETPOST($key.'min') == '') {
+				continue; // The field was not submited to be saved
+			}
+		} else {
+			if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type'])) {
+				continue; // The field was not submited to be saved
+			}
+		}
+		// Ignore special fields
+		if (in_array($key, array('rowid', 'entity', 'import_key'))) {
+			continue;
+		}
+		if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
+			if (!in_array(abs($val['visible']), array(1, 3))) {
+				continue; // Only 1 and 3 that are case to create
+			}
+		}
+
+		// Set value to insert
+		if (in_array($object->fields[$key]['type'], array('text', 'html'))) {
+			$value = GETPOST($key, 'restricthtml');
+		} elseif ($object->fields[$key]['type'] == 'date') {
+			$value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt
+		} elseif ($object->fields[$key]['type'] == 'datetime') {
+			$value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel');
+		} elseif ($object->fields[$key]['type'] == 'duration') {
+			$value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');
+		} elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
+			$value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup
+		} elseif ($object->fields[$key]['type'] == 'boolean') {
+			$value = ((GETPOST($key) == '1' || GETPOST($key) == 'on') ? 1 : 0);
+		} elseif ($object->fields[$key]['type'] == 'reference') {
+			$tmparraykey = array_keys($object->param_list);
+			$value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2');
+		} elseif (preg_match('/^chkbxlst:(.*)/', $object->fields[$key]['type'])) {
+			$value = '';
+			$values_arr = GETPOST($key, 'array');
+			if (!empty($values_arr)) {
+				$value = implode(',', $values_arr);
+			}
+		} else {
+			if ($key == 'lang') {
+				$value = GETPOST($key, 'aZ09') ?GETPOST($key, 'aZ09') : "";
+			} else {
+				$value = GETPOST($key, 'alphanohtml');
+			}
+		}
+		if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
+			$value = ''; // This is an implicit foreign key field
+		}
+		if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') {
+			$value = ''; // This is an explicit foreign key field
+		}
+
+		//var_dump($key.' '.$value.' '.$object->fields[$key]['type']);
+		$object->$key = $value;
+		if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && isset($val['default']) && $val['default'] == '(PROV)') {
+			$object->$key = '(PROV)';
+		}
+		if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && !isset($val['default'])) {
+			$error++;
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
+		}
+
+		// Validation of fields values
+		if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
+			if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) {
+				if (!$object->validateField($object->fields, $key, $value)) {
+					$error++;
+				}
+			}
+		}
+	}
+
+	// Fill array 'array_options' with data from add form
+	if (!$error) {
+		$ret = $extrafields->setOptionalsFromPost(null, $object, '', 1);
+		if ($ret < 0) {
+			$error++;
+		}
+	}
+
+	if (!$error) {
+		$db->begin();
+
+		$result = $object->create($user);
+		if ($result > 0) {
+			// Creation OK
+			if (isModEnabled('categorie') && method_exists($object, 'setCategories')) {
+				$categories = GETPOST('categories', 'array:int');
+				$object->setCategories($categories);
+			}
+
+			$urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
+			$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
+
+			$db->commit();
+
+			if (empty($noback)) {
+				header("Location: " . $urltogo);
+				exit;
+			}
+		} else {
+			$db->rollback();
+
+			$error++;
+			// Creation KO
+			if (!empty($object->errors)) {
+				setEventMessages(null, $object->errors, 'errors');
+			} else {
+				setEventMessages($object->error, null, 'errors');
+			}
+			$action = 'create';
+		}
+	} else {
+		$action = 'create';
+	}
+}
+
+// Action to update record
+if ($action == 'update' && !empty($permissiontoadd)) {
+	foreach ($object->fields as $key => $val) {
+		// Check if field was submited to be edited
+		if ($object->fields[$key]['type'] == 'duration') {
+			if (!GETPOSTISSET($key.'hour') || !GETPOSTISSET($key.'min')) {
+				continue; // The field was not submited to be saved
+			}
+		} elseif ($object->fields[$key]['type'] == 'boolean') {
+			if (!GETPOSTISSET($key)) {
+				$object->$key = 0; // use 0 instead null if the field is defined as not null
+				continue;
+			}
+		} else {
+			if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type'])) {
+				continue; // The field was not submited to be saved
+			}
+		}
+		// Ignore special fields
+		if (in_array($key, array('rowid', 'entity', 'import_key'))) {
+			continue;
+		}
+		if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
+			if (!in_array(abs($val['visible']), array(1, 3, 4))) {
+				continue; // Only 1 and 3 and 4, that are cases to update
+			}
+		}
+
+		// Set value to update
+		if (preg_match('/^(text|html)/', $object->fields[$key]['type'])) {
+			$tmparray = explode(':', $object->fields[$key]['type']);
+			if (!empty($tmparray[1])) {
+				$value = GETPOST($key, $tmparray[1]);
+			} else {
+				$value = GETPOST($key, 'restricthtml');
+			}
+		} elseif ($object->fields[$key]['type'] == 'date') {
+			$value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt
+		} elseif ($object->fields[$key]['type'] == 'datetime') {
+			$value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel');
+		} elseif ($object->fields[$key]['type'] == 'duration') {
+			if (GETPOST($key.'hour', 'int') != '' || GETPOST($key.'min', 'int') != '') {
+				$value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');
+			} else {
+				$value = '';
+			}
+		} elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
+			$value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup
+		} elseif ($object->fields[$key]['type'] == 'boolean') {
+			$value = ((GETPOST($key, 'aZ09') == 'on' || GETPOST($key, 'aZ09') == '1') ? 1 : 0);
+		} elseif ($object->fields[$key]['type'] == 'reference') {
+			$value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2');
+		} elseif (preg_match('/^chkbxlst:/', $object->fields[$key]['type'])) {
+			$value = '';
+			$values_arr = GETPOST($key, 'array');
+			if (!empty($values_arr)) {
+				$value = implode(',', $values_arr);
+			}
+		} else {
+			if ($key == 'lang') {
+				$value = GETPOST($key, 'aZ09');
+			} else {
+				$value = GETPOST($key, 'alphanohtml');
+			}
+		}
+		if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
+			$value = ''; // This is an implicit foreign key field
+		}
+		if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') {
+			$value = ''; // This is an explicit foreign key field
+		}
+
+		$object->$key = $value;
+		if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) {
+			$error++;
+			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors');
+		}
+
+		// Validation of fields values
+		if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
+			if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) {
+				if (!$object->validateField($object->fields, $key, $value)) {
+					$error++;
+				}
+			}
+		}
+
+		if (isModEnabled('categorie')) {
+			$categories = GETPOST('categories', 'array');
+			if (method_exists($object, 'setCategories')) {
+				$object->setCategories($categories);
+			}
+		}
+	}
+
+	// Fill array 'array_options' with data from add form
+	if (!$error) {
+		$ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
+		if ($ret < 0) {
+			$error++;
+		}
+	}
+
+	if (!$error) {
+		$result = $object->update($user);
+		if ($result > 0) {
+			$action = 'view';
+			$urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
+			$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
+			if ($urltogo && empty($noback)) {
+				header("Location: " . $urltogo);
+				exit;
+			}
+		} else {
+			$error++;
+			// Creation KO
+			setEventMessages($object->error, $object->errors, 'errors');
+			$action = 'edit';
+		}
+	} else {
+		$action = 'edit';
+	}
+}
+
+// Action to update one modulebuilder field
+$reg = array();
+if (preg_match('/^set(\w+)$/', $action, $reg) && GETPOST('id', 'int') > 0 && !empty($permissiontoadd)) {
+	$object->fetch(GETPOST('id', 'int'));
+
+	$keyforfield = $reg[1];
+	if (property_exists($object, $keyforfield)) {
+		if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield]['type'], array('date', 'datetime', 'timestamp'))) {
+			$object->$keyforfield = dol_mktime(GETPOST($keyforfield.'hour'), GETPOST($keyforfield.'min'), GETPOST($keyforfield.'sec'), GETPOST($keyforfield.'month'), GETPOST($keyforfield.'day'), GETPOST($keyforfield.'year'));
+		} else {
+			$object->$keyforfield = GETPOST($keyforfield);
+		}
+
+		$result = $object->update($user);
+
+		if ($result > 0) {
+			setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
+			$action = 'view';
+		} else {
+			$error++;
+			setEventMessages($object->error, $object->errors, 'errors');
+			$action = 'edit'.$reg[1];
+		}
+	}
+}
+
+// Action to update one extrafield
+if ($action == "update_extras" && GETPOST('id', 'int') > 0 && !empty($permissiontoadd)) {
+	$object->fetch(GETPOST('id', 'int'));
+
+	$attributekey = GETPOST('attribute', 'alpha');
+	$attributekeylong = 'options_'.$attributekey;
+
+	if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) {
+		// This is properties of a date
+		$object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int'));
+		//var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
+	} else {
+		$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha');
+	}
+
+	$result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
+	if ($result > 0) {
+		setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
+		$action = 'view';
+	} else {
+		$error++;
+		setEventMessages($object->error, $object->errors, 'errors');
+		$action = 'edit_extras';
+	}
+}
+
+// Action to delete
+if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
+	if (!($object->id > 0)) {
+		dol_print_error('', 'Error, object must be fetched before being deleted');
+		exit;
+	}
+
+	$result = $object->delete($user);
+
+	if ($result > 0) {
+		// Delete OK
+		setEventMessages("RecordDeleted", null, 'mesgs');
+
+		if (empty($noback)) {
+			header("Location: " . $backurlforlist);
+			exit;
+		}
+	} else {
+		$error++;
+		if (!empty($object->errors)) {
+			setEventMessages(null, $object->errors, 'errors');
+		} else {
+			setEventMessages($object->error, null, 'errors');
+		}
+	}
+
+	$action = '';
+}
+
+// Remove a line
+if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd)) {
+	if (method_exists($object, 'deleteline')) {
+		$result = $object->deleteline($user, $lineid); // For backward compatibility
+	} else {
+		$result = $object->deleteLine($user, $lineid);
+	}
+	if ($result > 0) {
+		// Define output language
+		$outputlangs = $langs;
+		$newlang = '';
+		if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
+			$newlang = GETPOST('lang_id', 'aZ09');
+		}
+		if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
+			$newlang = $object->thirdparty->default_lang;
+		}
+		if (!empty($newlang)) {
+			$outputlangs = new Translate("", $conf);
+			$outputlangs->setDefaultLang($newlang);
+		}
+		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+			if (method_exists($object, 'generateDocument')) {
+				$ret = $object->fetch($object->id); // Reload to get new records
+				$object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+			}
+		}
+
+		setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
+
+		if (empty($noback)) {
+			header('Location: '.((empty($backtopage)) ? $_SERVER["PHP_SELF"].'?id='.$object->id : $backtopage));
+			exit;
+		}
+	} else {
+		$error++;
+		setEventMessages($object->error, $object->errors, 'errors');
+	}
+	$action = '';
+}
+
+// Action validate object
+if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
+	$result = $object->validate($user);
+	if ($result >= 0) {
+		// Define output language
+		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+			if (method_exists($object, 'generateDocument')) {
+				$outputlangs = $langs;
+				$newlang = '';
+				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
+					$newlang = GETPOST('lang_id', 'aZ09');
+				}
+				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
+					$newlang = !empty($object->thirdparty->default_lang) ? $object->thirdparty->default_lang : "";
+				}
+				if (!empty($newlang)) {
+					$outputlangs = new Translate("", $conf);
+					$outputlangs->setDefaultLang($newlang);
+				}
+
+				$ret = $object->fetch($id); // Reload to get new records
+
+				$model = $object->model_pdf;
+
+				$retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
+				if ($retgen < 0) {
+					setEventMessages($object->error, $object->errors, 'warnings');
+				}
+			}
+		}
+	} else {
+		$error++;
+		setEventMessages($object->error, $object->errors, 'errors');
+	}
+	$action = '';
+}
+
+// Action close object
+if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) {
+	$result = $object->cancel($user);
+	if ($result >= 0) {
+		// Define output language
+		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+			if (method_exists($object, 'generateDocument')) {
+				$outputlangs = $langs;
+				$newlang = '';
+				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
+					$newlang = GETPOST('lang_id', 'aZ09');
+				}
+				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
+					$newlang = $object->thirdparty->default_lang;
+				}
+				if (!empty($newlang)) {
+					$outputlangs = new Translate("", $conf);
+					$outputlangs->setDefaultLang($newlang);
+				}
+				$model = $object->model_pdf;
+				$ret = $object->fetch($id); // Reload to get new records
+
+				$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
+			}
+		}
+	} else {
+		$error++;
+		setEventMessages($object->error, $object->errors, 'errors');
+	}
+	$action = '';
+}
+
+// Action setdraft object
+if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) {
+	$result = $object->setDraft($user);
+	if ($result >= 0) {
+		// Nothing else done
+	} else {
+		$error++;
+		setEventMessages($object->error, $object->errors, 'errors');
+	}
+	$action = '';
+}
+
+// Action reopen object
+if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) {
+	$result = $object->reopen($user);
+	if ($result >= 0) {
+		// Define output language
+		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+			if (method_exists($object, 'generateDocument')) {
+				$outputlangs = $langs;
+				$newlang = '';
+				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
+					$newlang = GETPOST('lang_id', 'aZ09');
+				}
+				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
+					$newlang = $object->thirdparty->default_lang;
+				}
+				if (!empty($newlang)) {
+					$outputlangs = new Translate("", $conf);
+					$outputlangs->setDefaultLang($newlang);
+				}
+				$model = $object->model_pdf;
+				$ret = $object->fetch($id); // Reload to get new records
+
+				$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
+			}
+		}
+	} else {
+		$error++;
+		setEventMessages($object->error, $object->errors, 'errors');
+	}
+	$action = '';
+}
+
+// Action clone object
+if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) {
+	if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
+		setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
+	} else {
+		$objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use native clone to keep this->db valid.
+		//$objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int'));
+		// ...
+		$result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
+		if (is_object($result) || $result > 0) {
+			$newid = 0;
+			if (is_object($result)) {
+				$newid = $result->id;
+			} else {
+				$newid = $result;
+			}
+
+			if (empty($noback)) {
+				header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $newid); // Open record of new object
+				exit;
+			}
+		} else {
+			$error++;
+			setEventMessages($objectutil->error, $objectutil->errors, 'errors');
+			$action = '';
+		}
+	}
+}

+ 3 - 2
custom/voucher/core/tpl/commonfields_add.tpl.php

@@ -93,7 +93,7 @@ foreach ($object->fields as $key => $val) {
 		} elseif ($key == 'fk_product') {
 			print $VoucherHelper->showInputField($fk_product);
 			print '<!-- ' . $key . ' JS for SELECT input -->';
-			print $VoucherHelper->JSGeneratorForSelectInput($key);
+			//print $VoucherHelper->JSGeneratorForSelectInput($key);
 		} else {
 			print $VoucherHelper->showInputField($fk_product);
 		}
@@ -102,12 +102,13 @@ foreach ($object->fields as $key => $val) {
 	//print_r($_REQUEST);
 	//var_dump($fk_product);
 	$display = $fk_product == '' || $fk_product == -1 ? 'TDhideClass' : '';
+	$today = date("Y-m-d", dol_now());
 	print '</td>';
 	print '</tr>';
 	print '<tr id="eventDateSelector" class="' . $display . '">
 		<td class="titlefieldcreate fieldrequired">Dátum</td>
 		
-		<td class="valuefieldcreateflat"><input type="date" id="date" name="date">
+		<td class="valuefieldcreateflat"><input type="date" id="date" name="date"  min="' . $today . '">
     	<p class="error-message" id="error-message">Ez a dátum nem választható!</p></td>
 		</tr>';
 	print '<tr id="eventTimeSelector" class="TDhideClass">

+ 47 - 0
custom/voucher/css/voucher.css

@@ -0,0 +1,47 @@
+    td.in-range:not(.end-date) {
+        background-color: #c8e4f1 !important;
+    }
+
+    .hide {
+        display: none;
+    }
+
+    .timeSelectBox {
+        display: inline-block;
+        width: 150px;
+        margin: 0 10px 0 0;
+        vertical-align: top;
+        border: 1px silver solid;
+        padding: 5px 10px;
+    }
+
+    input#date-range {
+        padding: 0 10px;
+    }
+
+    .time_slider {
+        display: none !important;
+        height: 0px !important;
+    }
+
+    .TDhideClass {
+        display: none !important;
+    }
+
+    /* Alapértelmezett stílusok a dátumválasztóhoz */
+    .date-container {
+        margin: 20px;
+    }
+    
+    .date-container input {
+        width: 250px;
+        padding: 10px;
+        font-size: 16px;
+    }
+
+    /* Hibaüzenet stílus */
+    .error-message {
+        color: red;
+        font-size: 14px;
+        display: none;
+    }

+ 118 - 0
custom/voucher/scripts/voucher.js

@@ -0,0 +1,118 @@
+
+$(document).ready(function () {
+    checkEvent($('#fk_product').val());
+    $('#fk_product').on('change', function () {
+        checkEvent($(this).val());
+    })
+});
+function checkEvent(value) {
+    console.log('checkEvent');
+    if (value == -1) {
+        $('#eventDateSelector').addClass("TDhideClass");
+        $('#eventTimeSelector').addClass("TDhideClass");
+    } else {
+        $("#date").val("");
+        $('#eventTimeSelector').addClass("TDhideClass");
+        var xhr = new XMLHttpRequest();
+        xhr.open("GET", "class/voucerhistory_assistant.class.php?product_id=" + value + "&function=checkEvent", true);
+        xhr.onreadystatechange = function () {
+            if (xhr.readyState === 4 && xhr.status === 200) {
+                if (xhr.responseText == 'true') {
+                    GetAllEventsOfTheSelectedProduct(value, function (allowedDates) {
+                        console.log(allowedDates);
+                        const dateInput = document.getElementById('date');
+                        const errorMessage = document.getElementById('error-message');
+                        dateInput.addEventListener('change', function () {
+                            const selectedDate = dateInput.value;
+                            if (!allowedDates.includes(selectedDate)) {
+                                errorMessage.style.display = 'block';
+                                dateInput.value = '';
+                                $("#eventTimeSelector").addClass("TDhideClass");
+                            } else {
+                                errorMessage.style.display = 'none';
+                                generateTimeOptions(value, dateInput.value);
+                                $("#eventTimeSelector").removeClass("TDhideClass");
+                            }
+                        });
+                        if(allowedDates !== '' ){
+                            $("#eventDateSelector").removeClass("TDhideClass");
+                        }
+                    });
+                } else {
+                    $("#eventDateSelector").val("");
+                    $("#date-range").attr("disabled", true);
+                    $('#eventDateSelector').addClass("TDhideClass");
+                    $('#eventTimeSelector').addClass("TDhideClass");
+                }
+            }
+        };
+        xhr.send();
+    }
+
+}
+
+function generateTimeOptions(value, selectedDate) {
+    var eventId = document.getElementById("eventId");
+    eventId.innerHTML = '';
+    GetAllTimesOfTheSelectedEvent(value, selectedDate, function (timeSlots) {
+        console.log(timeSlots);
+        Object.entries(timeSlots).forEach(function ([key, time]) {
+            var option = document.createElement("option");
+            option.value = key;
+            option.text = time;
+            eventId.appendChild(option);
+        });
+    });
+}
+
+function GetAllTimesOfTheSelectedEvent(value, selectedDate, callback) {
+    if (value == -1) {
+        $('#eventDateSelector').addClass("TDhideClass");
+    } else {
+        var xhr = new XMLHttpRequest();
+        xhr.open("GET", "class/voucerhistory_assistant.class.php?product_id=" + value + "&selectedDate=" + selectedDate + "&function=GetAllTimesOfTheSelectedEvent", true);
+        xhr.onreadystatechange = function () {
+            if (xhr.readyState === 4 && xhr.status === 200) {
+                try {
+                    var responseArray = JSON.parse(xhr.responseText);
+                    if (typeof callback === "function") {
+                        callback(responseArray);
+                    } else {
+                        console.error("A callback nem függvény.");
+                    }
+                } catch (error) {
+                    console.error("Hiba a válasz feldolgozása során:", error);
+                }
+            }
+        };
+        xhr.send();
+    }
+}
+
+function GetAllEventsOfTheSelectedProduct(value, callback) {
+    if (value == -1) {
+        $('#eventDateSelector').addClass("TDhideClass");
+    } else {
+        var xhr = new XMLHttpRequest();
+        xhr.open("GET", "class/voucerhistory_assistant.class.php?product_id=" + value + "&function=GetAllEventsOfTheSelectedProduct", true);
+        xhr.onreadystatechange = function () {
+            if (xhr.readyState === 4 && xhr.status === 200) {
+                try {
+                    if (xhr.responseText != '') {
+                        var responseArray = JSON.parse(xhr.responseText);
+                        if (typeof callback === "function") {
+                            callback(responseArray);
+                        } else {
+                            console.error("A callback nem függvény.");
+                        }
+                    }else{
+                        $('#eventDateSelector').addClass("TDhideClass");
+                    }
+                } catch (error) {
+                    console.error("Hiba a válasz feldolgozása során:", error);
+                }
+            }
+        };
+        xhr.send();
+    }
+}

+ 13 - 11
custom/voucher/voucherhistory_card.php

@@ -106,6 +106,8 @@ $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
 $fk_product = GETPOST('fk_product', 'int');
 $eventId = GETPOST('eventId', 'int');
 
+//print_r($_REQUEST);exit;
+
 // Initialize technical objects
 $object = new Voucherhistory($db);
 $extrafields = new ExtraFields($db);
@@ -193,11 +195,10 @@ if (empty($reshook)) {
 
 	$triggermodname = 'VOUCHER_VOUCHERHISTORY_MODIFY'; // Name of trigger action code to execute when we modify record
 
-	if ($action == 'add') {
+	/* if ($action == 'add') {
 		# Search Product
 		$productObj = new Product($db);
 		$productResult = $productObj->fetch($product_id);
-		print_r($productResult);exit;
 		# Search bundle
 		# Create BBTicket
 		$newticket = new BbTicket($db);
@@ -221,9 +222,10 @@ if (empty($reshook)) {
 		$object->pdf_path = 'asd';
 		$object->date_creation = dol_now();
 		$object->status = "0";
-	}
+	} */
 
 	// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
+	//include DOL_DOCUMENT_ROOT . '/custom/voucher/core/actions_addupdatedelete.inc.php';
 	include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
 
 	// Actions when linking object each other
@@ -288,6 +290,10 @@ if ($action == 'create') {
 		print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
 	}
 
+	print $_SESSION['token'];
+	print '<br>';
+	print $_SESSION['newtoken'];
+
 	print dol_get_fiche_head(array(), '');
 
 	// Set some default values
@@ -296,8 +302,8 @@ if ($action == 'create') {
 	print '<table class="border centpercent tableforfieldcreate">' . "\n";
 
 	// Common attributes
-	include DOL_DOCUMENT_ROOT . '/custom/voucher/core/tpl/commonfields_add.tpl.php';
-	//include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
+	//include DOL_DOCUMENT_ROOT . '/custom/voucher/core/tpl/commonfields_add.tpl.php';
+	include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
 
 	// Other attributes
 	include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
@@ -647,9 +653,5 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
 // End of page
 llxFooter();
 $db->close();
-echo '<link rel="stylesheet" type="text/css" href="' . dol_buildpath('/custom/voucher/css/voucher.css', 1) . '">';
-echo '<script type="text/javascript" src="' . dol_buildpath('/custom/voucher/scripts/voucher.js', 1) . '"></script>';
-?>
-<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
-<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
-<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css">
+//echo '<link rel="stylesheet" type="text/css" href="' . dol_buildpath('/custom/voucher/css/voucher.css', 1) . '">';
+//echo '<script type="text/javascript" src="' . dol_buildpath('/custom/voucher/scripts/voucher.js', 1) . '"></script>';