/** Overloading the doActions function : replacing the parent's function with the one below * @param parameters meta datas of the hook (context, etc...) * @param object the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...) * @param action current action (if set). Generally create or edit or null * @return void */ function beforePDFCreation($parameters, &$object, &$action, $hookmanager) { // pour implementation dans Dolibarr 3.7 if (in_array('pdfgeneration', explode(':', $parameters['context']))) { define('INC_FROM_DOLIBARR', true); dol_include_once('/dispatch/config.php'); dol_include_once('/asset/class/asset.class.php'); dol_include_once('/dispatch/class/dispatchdetail.class.php'); global $conf; if (isset($parameters['object']) && get_class($object) == 'Expedition') { $PDOdb = new TPDOdb(); foreach ($object->lines as &$line) { $sql = 'SELECT DISTINCT(lot_number),rowid FROM ' . MAIN_DB_PREFIX . 'expeditiondet_asset WHERE fk_expeditiondet = ' . $line->line_id; $PDOdb->Execute($sql); $TRes = $PDOdb->Get_All(); if (count($TRes) > 0) { $line->desc .= "<br>Lot(s) expédié(s) : "; foreach ($TRes as $res) { $dispatchDetail = new TDispatchDetail(); $dispatchDetail->load($PDOdb, $res->rowid); $asset = new TAsset(); $asset->load($PDOdb, $dispatchDetail->fk_asset); $asset->load_asset_type($PDOdb); $unite = $asset->assetType->measuring_units == 'unit' ? 'unité(s)' : measuring_units_string($dispatchDetail->weight_reel_unit, $asset->assetType->measuring_units); $desc = "<br>- " . $res->lot_number . " x " . $dispatchDetail->weight_reel . " " . $unite; if (empty($conf->global->DISPATCH_HIDE_DLUO_PDF)) { $desc .= ' (DLUO : ' . $asset->get_date('dluo') . ')'; } $line->desc .= $desc; } } } } //pre($object,true);exit; } }
/** * Overloading the doActions function : replacing the parent's function with the one below * * @param array() $parameters Hook metadatas (context, etc...) * @param CommonObject &$object The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...) * @param string &$action Current action (if set). Generally create or edit or null * @param HookManager $hookmanager Hook manager propagated to allow calling another hook * @return int < 0 on error, 0 on success, 1 to replace standard code */ function blockRelated($parameters, &$object, &$action, $hookmanager, $moreStyle = '') { global $langs, $db, $user, $conf, $related_link_added; $error = 0; // Error counter //var_dump($objet); define('INC_FROM_DOLIBARR', true); dol_include_once('/related/config.php'); $PDOdb = new TPDOdb(); $langs->load('related@related'); if (GETPOST('action') == 'add_related_link' && !$related_link_added) { $type = GETPOST('type_related_object'); //var_dump($type);exit; if ($type == 'projet') { $type = 'project'; } else { if ($type == 'invoice') { $type = 'facture'; } else { if ($type == 'company') { $type = 'societe'; } else { if ($type == 'facture_fournisseur') { $type = 'invoice_supplier'; } else { if ($type == 'commande_fournisseur') { $type = 'order_supplier'; } } } } } $res = $object->add_object_linked($type, GETPOST('id_related_object')); $object->fetchObjectLinked(); if (empty($res)) { setEventMessage($langs->trans('RelationCantBeAdded'), 'errors'); } else { $related_link_added = true; global $langs, $conf; dol_include_once('/core/class/interfaces.class.php'); $interface = new Interfaces($db); $object->id_related_object = GETPOST('id_related_object'); $object->type_related_object = $type; $result = $interface->run_triggers('RELATED_ADD_LINK', $object, $user, $langs, $conf); if ($result < 0) { if (!empty($this->errors)) { $this->errors = array_merge($this->errors, $interface->errors); } else { $this->errors = $interface->errors; } } setEventMessage($langs->trans('RelationAdded')); } } elseif (GETPOST('action') == 'delete_related_link') { $idLink = GETPOST('id_link'); if ($idLink) { $PDOdb->Execute("DELETE FROM " . MAIN_DB_PREFIX . "element_element WHERE rowid = " . $idLink); $object->fetchObjectLinked(); } } else { //var_dump($object); if (empty($object->linkedObjects)) { $object->fetchObjectLinked(); } } //var_dump($object->linkedObjectsIds); ?> <div class="blockrelated_content" style="<?php echo $moreStyle; ?> "> <form name="formLinkObj" action="<?php echo $_SERVER['PHP_SELF']; ?> " method="post"> <input type="hidden" name="action" value="add_related_link" /> <input type="hidden" name="id" value="<?php echo GETPOST('id'); ?> " /> <input type="hidden" name="facid" value="<?php echo GETPOST('facid'); ?> " /> <br> <div class="titre"><?php echo $langs->trans('ElementToLink'); ?> </div> <input type="hidden" id="id_related_object" name="id_related_object" value="" /> <input type="hidden" id="type_related_object" name="type_related_object" value="" /> <table class="noborder allwidth"> <tr class="liste_titre"> <td><?php echo $langs->trans("Ref"); ?> <input type="text" id="add_related_object" name="add_related_object" value="" class="flat" /> <input type="submit" id="bt_add_related_object" name="bt_add_related_object" class="button" value="<?php echo $langs->trans('AddRelated'); ?> " style="display:none" /></td> <td align="center"><?php echo $langs->trans("Date"); ?> </td> <td align="center"><?php echo $langs->trans("Status"); ?> </td> <td align="center"><?php echo $langs->trans("Action"); ?> </td> </tr> <?php $class = 'pair'; foreach ($object->linkedObjectsIds as $objecttype => &$TSubIdObject) { //var_dump($objecttype); if (isset($object->linkedObjects[$objecttype]) && $objecttype != 'societe' && $objecttype != 'product' && $object->element != 'project') { continue; } // on affiche ici que les objects non géré en natif foreach ($TSubIdObject as $id_object) { $date_create = 0; $classname = ucfirst($objecttype); $statut = 'N/A'; if ($objecttype == 'task') { dol_include_once('/projet/class/task.class.php'); } else { if ($objecttype == 'event' || $objecttype == 'action') { dol_include_once('/comm/action/class/actioncomm.class.php'); $classname = 'ActionComm'; } else { if ($objecttype == 'project') { dol_include_once('/projet/class/project.class.php'); } else { if ($objecttype == 'ordre_fabrication') { dol_include_once('/of/class/ordre_fabrication_asset.class.php'); $classname = 'TAssetOf'; $abricot = true; } } } } if (!class_exists($classname)) { $link = 'CantInstanciateClass ' . $classname; } else { if (!empty($abricot)) { if (empty($PDOdb)) { $PDOdb = new TPDOdb(); } $subobject = new $classname(); $subobject->load($PDOdb, $id_object); if (method_exists($subobject, 'getNomUrl')) { $link = $subobject->getNomUrl(1); } else { $link = $id_object . '/' . $classname; } $class = $class == 'impair' ? 'pair' : 'impair'; $date_create = $subobject->date_cre; if (method_exists($subobject, 'getLibStatut')) { $statut = $subobject->getLibStatut(3); } } else { $subobject = new $classname($db); $subobject->fetch($id_object); if (method_exists($subobject, 'getNomUrl')) { $link = $subobject->getNomUrl(1); } else { $link = $id_object . '/' . $classname; } $class = $class == 'impair' ? 'pair' : 'impair'; if (!empty($subobject->date_creation)) { $date_create = $subobject->date_creation; } if (empty($date_create) && !empty($subobject->date_create)) { $date_create = $subobject->date_create; } if (empty($date_create) && !empty($subobject->date_c)) { $date_create = $subobject->date_c; } if (method_exists($subobject, 'getLibStatut')) { $statut = $subobject->getLibStatut(3); } } } $Tids = TRequeteCore::get_id_from_what_you_want($PDOdb, MAIN_DB_PREFIX . "element_element", array('fk_source' => $id_object, 'fk_target' => $object->id, 'sourcetype' => $objecttype, 'targettype' => $object->element)); ?> <tr class="<?php echo $class; ?> "> <td><?php echo $link; ?> </td> <td align="center"><?php echo !empty($date_create) ? dol_print_date($date_create, 'day') : ''; ?> </td> <td align="center"><?php echo $statut; ?> </td> <td align="center"><a href="?id=<?php echo $object->id; ?> &action=delete_related_link&id_link=<?php echo $Tids[0]; ?> "><?php print img_picto($langs->trans("Delete"), 'delete.png'); ?> </a></td> </tr> <?php } } ?> </table> </form> </div> <script type="text/javascript"> $(document).ready(function() { $('#add_related_object').autocomplete({ source: function( request, response ) { $.ajax({ url: "<?php echo dol_buildpath('/related/script/interface.php', 1); ?> ", dataType: "json", data: { key: request.term ,get:'search' } ,success: function( data ) { var c = []; $.each(data, function (i, cat) { var first = true; $.each(cat, function(j, label) { if(first) { c.push({value:i, label:i, object:'title'}); first = false; } c.push({ value: j, label:' '+label, object:i}); }); }); response(c); } }); }, minLength: 1, select: function( event, ui ) { if(ui.item.object == 'title') return false; else { $('#id_related_object').val(ui.item.value); $('#add_related_object').val(ui.item.label.trim()); $('#type_related_object').val(ui.item.object); $('#bt_add_related_object').css('display','inline'); return false; } }, open: function( event, ui ) { $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); }, close: function() { $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); } }); $( "#add_related_object" ).autocomplete( "instance" )._renderItem = function( ul, item ) { $li = $( "<li />" ) .attr( "data-value", item.value ) .append( item.label ) .appendTo( ul ); if(item.object=="title") $li.css("font-weight","bold"); return $li; }; var blockrelated = $('div.tabsAction .blockrelated_content'); if (blockrelated.length == 1) { if ($('.blockrelated_content').length > 1) { blockrelated.remove(); } else { $('div.tabsAction').after(blockrelated.clone()); blockrelated.remove(); } } }); </script> <?php if (!$error) { return 0; // or return 1 to replace standard code } else { $this->errors[] = 'Cant link related'; return -1; } }
<?php define('INC_FROM_DOLIBAR', true); require_once '../config.php'; dol_include_once('/ideabox/lib/ideabox.lib.php'); $langs->load('ideabox@ideabox'); $PDOdb = new TPDOdb(); $sql = 'SELECT DISTINCT(ib.rowid), ib.label, ib.fk_usergroup FROM ((' . MAIN_DB_PREFIX . 'usergroup ub RIGHT JOIN ' . MAIN_DB_PREFIX . 'ideabox ib on ib.fk_usergroup = ub.rowid) INNER JOIN ' . MAIN_DB_PREFIX . 'usergroup_user ubu on ub.rowid = ubu.fk_usergroup) WHERE ubu.fk_user = '******' UNION SELECT ib.rowid, ib.label, ib.fk_usergroup FROM ' . MAIN_DB_PREFIX . 'ideabox ib WHERE fk_usergroup = -1'; $PDOdb->Execute($sql); ?> $('document').ready(function(){ function openIdeaboxWidget(){ $ideabox = $('<div id="ideabox_widget"><div class="titre center">Ajouter une idée dans une boîte</div>Boîte : <select id="ideabox_widget_select"></select><br /></div>'); $ideabox.append('Titre : <br /><input id="ideabox_widget_label" type="text" id="ideabox_widget_label" placeholder="Titre de l\'idée" /><br />'); $ideabox.append('Description : <br /><textarea id="ideabox_widget_description" cols="10" rows="2" type="text" placeholder="Description de l\'idée" /><br />'); $ideabox.append('<div class="center" style="margin-top:5px;"><a id="ideabox_widget_valid" class="button" style="cursor:pointer;">Ajouter</a> ' + '<a id="ideabox_widget_cancel" class="button" style="cursor:pointer;">Annuler</a></div>'); $('body').append($ideabox); }
$nbVides = !empty($_REQUEST['startpos']) ? $_REQUEST['startpos'] - 1 : 0; $nbCopies = !empty($_REQUEST['copie']) ? $_REQUEST['copie'] : 1; $modele = $_REQUEST['modele']; $expedition = new Expedition($db); $expedition->fetch($_REQUEST['expedition']); $expedition->fetch_lines(); $TetiquettesVides = array(); $Tetiquettes = array(); //création des div vides for ($i = 0; $i < $nbVides; $i++) { $TetiquettesVides[$i] = array($i); } $TPDOdb = new TPDOdb(); //création des div pleines foreach ($expedition->lines as $ligne) { $TPDOdb->Execute("SELECT rowid FROM " . MAIN_DB_PREFIX . "expeditiondet_asset WHERE fk_expeditiondet = " . $ligne->rowid); $TidExepeditiondetAsset = array(); while ($TPDOdb->Get_line()) { $TidExepeditiondetAsset[] = $TPDOdb->Get_field('rowid'); } foreach ($TidExepeditiondetAsset as $idExpeditiondetAsset) { $sql = "SELECT p.ref, p.label as nom, p.note as descritpion, eda.tare as tare, a.serial_number as code, a.lot_number as lot, eda.weight_reel as poids, eda.weight_reel_unit as poids_unit, eda.tare_unit as tare_unit\n\t\t\t\t\tFROM " . MAIN_DB_PREFIX . "expeditiondet_asset as eda\n\t\t\t\t\t\tLEFT JOIN " . MAIN_DB_PREFIX . "asset as a ON (a.rowid = eda.fk_asset)\n\t\t\t\t\t\tLEFT JOIN " . MAIN_DB_PREFIX . "product as p ON (p.rowid = a.fk_product)\n\t\t\t\t\tWHERE eda.rowid = " . $idExpeditiondetAsset; $TPDOdb->Execute($sql); $TPDOdb->Get_line(); $tare_unit = _unit($TPDOdb->Get_field('tare_unit')); $poids_unit = _unit($TPDOdb->Get_field('poids_unit')); //On duplique l'étiquette autant de fois que demandé en paramètre for ($i = 0; $i < $nbCopies; $i++) { $Tetiquettes[] = array("ref" => $TPDOdb->Get_field('ref'), "nom" => $TPDOdb->Get_field('nom'), "description" => (int) $TPDOdb->Get_field('description') != 0 ? $TPDOdb->Get_field('description') : "", "tare" => number_format($TPDOdb->Get_field('tare'), 2, ',', ' '), "tare_unit" => $tare_unit, "code" => $TPDOdb->Get_field('code'), "lot" => $TPDOdb->Get_field('lot'), "poids" => number_format($TPDOdb->Get_field('poids'), 2, ',', ' '), "poids_unit" => $poids_unit); } }
<?php require "../config.php"; require DOL_DOCUMENT_ROOT . "/custom/asset/class/asset.class.php"; if (isset($_POST['id_detail'])) { $id_detail = $_POST['id_detail']; } else { return 0; } $ATMdb = new TPDOdb(); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "expeditiondet_asset WHERE rowid = " . $id_detail; $ATMdb->Execute($sql); return 1;
/** * Function called when a Dolibarrr business event is done. * All functions "run_trigger" are triggered if file * is inside directory core/triggers * * @param string $action Event action code * @param Object $object Object * @param User $user Object user * @param Translate $langs Object langs * @param conf $conf Object conf * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ public function run_trigger($action, $object, $user, $langs, $conf) { if ($action === 'ORDER_VALIDATE') { global $conf, $db; if ($conf->global->CREATE_OF_ON_ORDER_VALIDATE) { define('INC_FROM_DOLIBARR', true); dol_include_once('/product/class/product.class.php'); dol_include_once('/of/config.php'); dol_include_once('/of/class/ordre_fabrication_asset.class.php'); $PDOdb = new TPDOdb(); foreach ($object->lines as $line) { // Uniquement si c'est un produit if (!empty($line->fk_product) && $line->fk_product_type == 0) { // On charge le produit pour vérifier son stock $prod = new Product($db); $prod->fetch($line->fk_product); $prod->load_stock(); if ($prod->stock_reel < $line->qty) { $assetOF = new TAssetOF(); $assetOF->fk_commande = $_REQUEST['id']; $assetOF->fk_soc = $object->socid; $assetOF->addLine($PDOdb, $line->fk_product, 'TO_MAKE', $line->qty); $assetOF->save($PDOdb); } } } } } elseif ($action === 'ORDER_CANCEL') { if ($conf->global->DELETE_OF_ON_ORDER_CANCEL) { define('INC_FROM_DOLIBARR', true); dol_include_once('/of/config.php'); dol_include_once('/of/class/ordre_fabrication_asset.class.php'); $PDOdb = new TPDOdb(); // On récupère les identifiants des of créés à partir de cette commande $TID_OF_command = TAssetOF::getTID_OF_command($_REQUEST['id']); foreach ($TID_OF_command as $id_of) { $asset = new TAssetOF(); $asset->load($PDOdb, $id_of); if ($asset->status == "DRAFT" || $asset->status == "VALID") { $asset->delete($PDOdb); } } } } elseif ($action === 'TASK_TIMESPENT_CREATE') { if ($conf->workstation->enabled) { define('INC_FROM_DOLIBARR', true); dol_include_once('/of/config.php'); dol_include_once('/of/class/ordre_fabrication_asset.class.php'); $PDOdb = new TPDOdb(); $PDOdb->Execute("SELECT rowid \n\t\t\t\t\t\tFROM " . MAIN_DB_PREFIX . "asset_workstation_of \n\t\t\t\t\t\tWHERE fk_project_task=" . $object->id); if ($obj = $PDOdb->Get_line()) { $wsof = new TAssetWorkstationOF(); $wsof->load($PDOdb, $obj->rowid); $wsof->nb_hour_real = ($object->duration_effective + $object->timespent_duration) / 3600; // Parce que Dolibarr mets le THM à jour après la création de la tâche :/ $sql = "UPDATE " . MAIN_DB_PREFIX . "projet_task_time"; $sql .= " SET thm = (SELECT thm FROM " . MAIN_DB_PREFIX . "user WHERE rowid = " . $object->timespent_fk_user . ")"; // set average hour rate of user $sql .= " WHERE rowid = " . $object->timespent_id; $object->db->query($sql); $wsof->db =& $object->db; $wsof->save($PDOdb); } } } elseif ($action === 'ORDERSUPPLIER_ADD_LIVRAISON') { global $db; if ($conf->of->enabled) { define('INC_FROM_DOLIBARR', true); dol_include_once('/of/config.php'); dol_include_once('/of/class/ordre_fabrication_asset.class.php'); $resql = $db->query('SELECT fk_statut FROM llx_commande_fournisseur WHERE rowid = ' . $_REQUEST['id']); $res = $db->fetch_object($resql); if ($res->fk_statut == 5) { // La livraison est totale //On cherche l'OF lié $resql = $db->query("SELECT fk_source \n\t\t\t\t\t\t\t\t\t\t\tFROM " . MAIN_DB_PREFIX . "element_element \n\t\t\t\t\t\t\t\t\t\t\tWHERE fk_target = " . $_REQUEST['id'] . " \n\t\t\t\t\t\t\t\t\t\t\t\tAND sourcetype = 'ordre_fabrication' \n\t\t\t\t\t\t\t\t\t\t\t\tAND targettype = 'order_supplier'"); $res = $db->fetch_object($resql); $id_of = $res->fk_source; if ($id_of > 0) { $of = new TAssetOF(); $of->load($PDOdb, $id_of); if ($of->status != 'CLOSE') { $of->closeOF($PDOdb); setEventMessage($langs->trans('OFAttachedClosedAutomatically', '<a href="' . dol_buildpath('/of/fiche_of.php?id=' . $id_of, 2) . '">' . $of->numero . '</a>')); } } } } } return 0; }