static function archiverPropale(&$ATMdb, &$object) { global $langs; TPropaleHist::archivePDF($object); $newVersionPropale = new TPropaleHist(); $newVersionPropale->serialized_parent_propale = serialize($object); $newVersionPropale->date_version = dol_now(); $newVersionPropale->fk_propale = $object->id; $newVersionPropale->total = $object->total_ht; $newVersionPropale->save($ATMdb); ?> <script language="javascript"> document.location.href="<?php echo $_SERVER['PHP_SELF']; ?> ?id=<?php echo $_REQUEST['id']; ?> &mesg=<?php echo $langs->transnoentities('HistoryVersionSuccessfullArchived'); ?> "; </script> <?php /*if($_REQUEST['actionATM'] == 'createVersion') { setEventMessage('Version sauvegardée avec succès.', 'mesgs'); }*/ }
/** * Return server timezone int. * * @param string $refgmtdate Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer') * @return int An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer) */ function getServerTimeZoneInt($refgmtdate = 'now') { global $conf; if (method_exists('DateTimeZone', 'getOffset')) { // Method 1 (include daylight) $gmtnow = dol_now('gmt'); $yearref = dol_print_date($gmtnow, '%Y'); $monthref = dol_print_date($gmtnow, '%m'); $dayref = dol_print_date($gmtnow, '%d'); if ($refgmtdate == 'now') { $newrefgmtdate = $yearref . '-' . $monthref . '-' . $dayref; } elseif ($refgmtdate == 'summer') { $newrefgmtdate = $yearref . '-08-01'; } else { $newrefgmtdate = $yearref . '-01-01'; } $newrefgmtdate .= 'T00:00:00+00:00'; $localtz = new DateTimeZone(getServerTimeZoneString()); $localdt = new DateTime($newrefgmtdate, $localtz); $tmp = -1 * $localtz->getOffset($localdt); //print $refgmtdate.'='.$tmp; } else { $tmp = 0; dol_print_error('', 'PHP version must be 5.3+'); } $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600)); return $tz; }
/** * Create bank information record * * @return int <0 if KO, >= 0 if OK */ function create() { $now = dol_now(); // Correct default_rib to be sure to have always one default $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "societe_rib where fk_soc = " . $this->socid . " AND default_rib = 1"; $result = $this->db->query($sql); if ($result) { $numrows = $this->db->num_rows($result); if ($this->default_rib && $numrows > 0) { $this->default_rib = 0; } if (empty($this->default_rib) && $numrows == 0) { $this->default_rib = 1; } } $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_rib (fk_soc, datec)"; $sql .= " VALUES (" . $this->socid . ", '" . $this->db->idate($now) . "')"; $resql = $this->db->query($sql); if ($resql) { if ($this->db->affected_rows($resql)) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "societe_rib"); return 1; } } else { print $this->db->error(); return 0; } }
/** * Insert accountancy system name into database * * @param User $user making insert * @return int if KO, Id of line if OK */ function create($user) { $now = dol_now(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_system"; $sql .= " (date_creation, fk_user_author, numero, label)"; $sql .= " VALUES (" . $this->db->idate($now) . "," . $user->id . ",'" . $this->numero . "','" . $this->label . "')"; dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_system"); if ($id > 0) { $this->rowid = $id; $result = $this->rowid; } else { $result = -2; $this->error = "AccountancySystem::Create Erreur {$result}"; dol_syslog($this->error, LOG_ERR); } } else { $result = -1; $this->error = "AccountancySystem::Create Erreur {$result}"; dol_syslog($this->error, LOG_ERR); } return $result; }
/** * Create promotion * * @param User $user Object user * @param int $pid Pid * @param int $percent Percent * @return int <0 if KO, >0 if OK */ function create($user, $pid, $percent) { global $conf; $sql = "SELECT products_price "; $sql .= " FROM " . $conf->global->OSC_DB_NAME . "." . $conf->global->OSC_DB_TABLE_PREFIX . "products as p"; $sql .= " WHERE p.products_id = " . $pid; $result = $this->db->query($sql); if ($result) { $result = $this->db->fetch_array($result); $this->price_init = $result["products_price"]; } $newprice = $percent * $this->price_init; $date_exp = "2003-05-01"; // TODO ???? $now = dol_now(); $sql = "INSERT INTO " . $conf->global->OSC_DB_NAME . "." . $conf->global->OSC_DB_TABLE_PREFIX . "specials "; $sql .= " (products_id, specials_new_products_price, specials_date_added, specials_last_modified, expires_date, date_status_change, status) "; $sql .= " VALUES ({$pid}, {$newprice}, '" . $this->db->idate($now) . "', NULL, '" . $this->db->idate($now + 3600 * 24 * 365) . "', NULL, 1)"; if ($this->db->query($sql)) { $id = $this->db->last_insert_id(OSC_DB_NAME . ".specials"); return $id; } else { print $this->db->error() . ' in ' . $sql; } }
/** * Load data into info_box_contents array to show array later. * * @param int $max of records to load * * @return void */ public function loadBox($max = 5) { global $conf, $user, $langs, $db; $this->max = $max; dol_include_once('/lead/class/lead.class.php'); $lead = new Lead($db); $lead->fetch_all('DESC', 't.date_closure', $max, 0, array('t.date_closure<' => dol_now())); $text = $langs->trans("LeadLate", $max); $this->info_box_head = array('text' => $text, 'limit' => dol_strlen($text)); $i = 0; foreach ($lead->lines as $line) { // FIXME: line is an array, not an object $line->fetch_thirdparty(); // Ref $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => dol_buildpath('/lead/lead/card.php', 1) . '?id=' . $line->id); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $line->ref, 'url' => dol_buildpath('/lead/lead/card.php', 1) . '?id=' . $line->id); $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $line->fk_soc); $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => dol_trunc($line->thirdparty->name, 40), 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $line->fk_soc); // Amount Guess $this->info_box_contents[$i][4] = array('td' => 'align="left"', 'text' => price($line->amount_prosp, 'HTML') . $langs->getCurrencySymbol($conf->currency)); // Amount real $this->info_box_contents[$i][5] = array('td' => 'align="left"', 'text' => $line->getRealAmount() . $langs->getCurrencySymbol($conf->currency)); $i++; } }
/** * Load data for box to show them later * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $user, $langs, $db, $conf; $this->max = $max; include_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; $contractstatic = new Contrat($db); $this->info_box_head = array('text' => $langs->trans("BoxTitleLastContracts", $max)); if ($user->rights->contrat->lire) { $sql = "SELECT s.nom, s.rowid as socid,"; $sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.fin_validite, c.date_cloture"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "contrat as c"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE c.fk_soc = s.rowid"; $sql .= " AND c.entity = " . $conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id; } $sql .= " ORDER BY c.date_contrat DESC, c.ref DESC "; $sql .= $db->plimit($max, 0); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $now = dol_now(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($resql); $datec = $db->jdate($objp->datec); $dateterm = $db->jdate($objp->fin_validite); $dateclose = $db->jdate($objp->date_cloture); $late = ''; $contractstatic->statut = $objp->fk_statut; $contractstatic->id = $objp->rowid; $result = $contractstatic->fetch_lines(); // fin_validite is no more on contract but on services // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); } $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/contrat/fiche.php?id=" . $objp->rowid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->ref ? $objp->ref : $objp->rowid, 'text2' => $late, 'url' => DOL_URL_ROOT . "/contrat/fiche.php?id=" . $objp->rowid); $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => dol_trunc($objp->nom, 40), 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => dol_print_date($datec, 'day')); $this->info_box_contents[$i][5] = array('td' => 'align="right" class="nowrap"', 'text' => $contractstatic->getLibStatut(6), 'asis' => 1); $i++; } if ($num == 0) { $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoRecordedContracts")); } $db->free($resql); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Load data into info_box_contents array to show array later. * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $user, $langs, $db, $conf; $this->max = $max; include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; $propalstatic = new Propal($db); $this->info_box_head = array('text' => $langs->trans("BoxTitleLastPropals", $max)); if ($user->rights->propale->lire) { $sql = "SELECT s.nom, s.rowid as socid,"; $sql .= " p.rowid, p.ref, p.fk_statut, p.datep as dp, p.datec, p.fin_validite, p.date_cloture"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= ", " . MAIN_DB_PREFIX . "propal as p"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE p.fk_soc = s.rowid"; $sql .= " AND p.entity = " . $conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id; } $sql .= " ORDER BY p.datep DESC, p.ref DESC "; $sql .= $db->plimit($max, 0); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $now = dol_now(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); $datec = $db->jdate($objp->datec); $dateterm = $db->jdate($objp->fin_validite); $dateclose = $db->jdate($objp->date_cloture); $late = ''; if ($objp->fk_statut == 1 && $dateterm < $now - $conf->propal->cloture->warning_delay) { $late = img_warning($langs->trans("Late")); } $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/comm/propal.php?id=" . $objp->rowid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->ref, 'text2' => $late, 'url' => DOL_URL_ROOT . "/comm/propal.php?id=" . $objp->rowid); $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => dol_trunc($objp->nom, 40), 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => dol_print_date($datec, 'day')); $this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"', 'text' => $propalstatic->LibStatut($objp->fk_statut, 3)); $i++; } if ($num == 0) { $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoRecordedProposals")); } $db->free($result); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Load data for box to show them later * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 10) { global $user, $langs, $db, $conf; $this->max = $max; include_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php'; $ficheinterstatic = new Fichinter($db); $this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter", $max)); if ($user->rights->ficheinter->lire) { $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut,"; $sql .= " f.datec,"; $sql .= " f.date_valid as datev,"; $sql .= " f.tms as datem,"; $sql .= " s.nom, s.rowid as socid, s.client"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; if (!$user->rights->societe->client->voir) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= ", " . MAIN_DB_PREFIX . "fichinter as f"; $sql .= " WHERE f.fk_soc = s.rowid "; $sql .= " AND f.entity = " . $conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id; } $sql .= " ORDER BY f.tms DESC"; $sql .= $db->plimit($max, 0); dol_syslog(get_class($this) . '::loadBox sql=' . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $now = dol_now(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($resql); $datec = $db->jdate($objp->datec); $ficheinterstatic->statut = $objp->fk_statut; $ficheinterstatic->id = $objp->rowid; $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/fichinter/fiche.php?id=" . $objp->rowid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->ref ? $objp->ref : $objp->rowid, 'url' => DOL_URL_ROOT . "/fichinter/fiche.php?id=" . $objp->rowid); $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => dol_trunc($objp->nom, 40), 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => dol_print_date($datec, 'day')); $this->info_box_contents[$i][5] = array('td' => 'align="right" class="nowrap"', 'text' => $ficheinterstatic->getLibStatut(6), 'asis' => 1); $i++; } if ($num == 0) { $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoRecordedInterventions")); } $db->free($resql); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Load data for box to show them later * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $user, $langs, $db, $conf; $this->max = $max; $now = dol_now(); $this->info_box_head = array('text' => $langs->trans("BoxLastExpiredServices", $max)); if ($user->rights->contrat->lire) { // Select contracts with at least one expired service $sql = "SELECT "; $sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat,"; $sql .= " s.nom as name, s.rowid as socid,"; $sql .= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services"; $sql .= " FROM " . MAIN_DB_PREFIX . "contrat as c, " . MAIN_DB_PREFIX . "societe s, " . MAIN_DB_PREFIX . "contratdet as cd"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '" . $db->idate($now) . "'"; $sql .= " AND c.fk_soc=s.rowid AND cd.fk_contrat=c.rowid AND c.statut > 0"; if ($user->societe_id) { $sql .= ' AND c.fk_soc = ' . $user->societe_id; } if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, s.nom, s.rowid"; $sql .= " ORDER BY date_line ASC"; $sql .= $db->plimit($max, 0); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $late = ''; $objp = $db->fetch_object($resql); $dateline = $db->jdate($objp->date_line); if ($dateline + $conf->contrat->services->expires->warning_delay < $now) { $late = img_warning($langs->trans("Late")); } $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/contrat/card.php?id=" . $objp->rowid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->ref ? $objp->ref : $objp->rowid, 'url' => DOL_URL_ROOT . "/contrat/card.php?id=" . $objp->rowid); $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/comm/card.php?socid=" . $objp->socid); $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => dol_trunc($objp->name, 40), 'url' => DOL_URL_ROOT . "/comm/card.php?socid=" . $objp->socid); $this->info_box_contents[$i][4] = array('td' => 'align="center"', 'text' => dol_print_date($dateline, 'day'), 'text2' => $late); $this->info_box_contents[$i][5] = array('td' => 'align="right"', 'text' => $objp->nb_services); $i++; } if ($num == 0) { $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoExpiredServices")); } $db->free($resql); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Create object in database * * @param User $user User making creation * @return int <0 if KO, >0 if OK */ function create($user) { global $conf, $langs; $error = 0; $ret = 0; $now = dol_now(); // Clean parameters $this->address = $this->address > 0 ? $this->address : $this->address; $this->zip = $this->zip > 0 ? $this->zip : $this->zip; $this->town = $this->town > 0 ? $this->town : $this->town; $this->country_id = $this->country_id > 0 ? $this->country_id : $this->country_id; $this->db->begin(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "establishment ("; $sql .= "name"; $sql .= ", address"; $sql .= ", zip"; $sql .= ", town"; $sql .= ", status"; $sql .= ", fk_country"; $sql .= ", entity"; $sql .= ", datec"; $sql .= ", fk_user_author"; $sql .= ") VALUES ("; $sql .= " '" . $this->db->escape($this->name) . "'"; $sql .= ", '" . $this->db->escape($this->address) . "'"; $sql .= ", '" . $this->db->escape($this->zip) . "'"; $sql .= ", '" . $this->db->escape($this->town) . "'"; $sql .= ", " . $this->country_id; $sql .= ", " . $this->status; $sql .= ", " . $conf->entity; $sql .= ", '" . $this->db->idate($now) . "'"; $sql .= ", " . $user->id; $sql .= ")"; dol_syslog(get_class($this) . "::create", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } if (!$error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "establishment"); } // Commit or rollback if ($error) { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR); $this->error .= $this->error ? ', ' . $errmsg : $errmsg; } $this->db->rollback(); return -1 * $error; } else { $this->db->commit(); return $this->id; } }
/** * Create object in database * TODO Add ref number * * @param User $user User that creates * @return int <0 if KO, >0 if OK */ function create($user) { global $conf; // Check parameters if (empty($this->type) || $this->type < 0) { $this->error = 'ErrorBadParameter'; return -1; } if (empty($this->fk_user) || $this->fk_user < 0) { $this->error = 'ErrorBadParameter'; return -1; } $now = dol_now(); $this->db->begin(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "deplacement ("; $sql .= "datec"; //$sql.= ", dated"; $sql .= ", entity"; $sql .= ", fk_user_author"; $sql .= ", fk_user"; $sql .= ", type"; $sql .= ", note"; $sql .= ", note_public"; $sql .= ", fk_projet"; $sql .= ", fk_soc"; $sql .= ") VALUES ("; $sql .= " '" . $this->db->idate($now) . "'"; $sql .= ", " . $conf->entity; $sql .= ", " . $user->id; $sql .= ", " . $this->fk_user; $sql .= ", '" . $this->type . "'"; $sql .= ", " . ($this->note_private ? "'" . $this->db->escape($this->note_private) . "'" : "null"); $sql .= ", " . ($this->note_public ? "'" . $this->db->escape($this->note_public) . "'" : "null"); $sql .= ", " . ($this->fk_project > 0 ? $this->fk_project : 0); $sql .= ", " . ($this->fk_soc > 0 ? $this->fk_soc : "null"); $sql .= ")"; dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "deplacement"); $result = $this->update($user); if ($result > 0) { $this->db->commit(); return $this->id; } else { $this->error = $this->db->error(); $this->db->rollback(); return $result; } } else { $this->error = $this->db->error() . " sql=" . $sql; $this->db->rollback(); return -1; } }
/** * Return server timezone int. * * @param string $refgmtdate Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer') * @return int An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer) */ function getServerTimeZoneInt($refgmtdate = 'now') { global $conf; if (method_exists('DateTimeZone', 'getOffset')) { // Method 1 (include daylight) $gmtnow = dol_now('gmt'); $yearref = dol_print_date($gmtnow, '%Y'); $monthref = dol_print_date($gmtnow, '%m'); $dayref = dol_print_date($gmtnow, '%d'); if ($refgmtdate == 'now') { $newrefgmtdate = $yearref . '-' . $monthref . '-' . $dayref; } elseif ($refgmtdate == 'summer') { $newrefgmtdate = $yearref . '-08-01'; } else { $newrefgmtdate = $yearref . '-01-01'; } $localtz = new DateTimeZone(getServerTimeZoneString()); $localdt = new DateTime($newrefgmtdate, $localtz); $tmp = -1 * $localtz->getOffset($localdt); //print $refgmtdate.'='.$tmp; } else { dol_print_error('', 'PHP version must be 5.3+'); /* // Method 2 (does not include daylight, not supported by adodb) if ($refgmtdate == 'now') { if (ini_get("date.timezone")=='UTC') return 0; // We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client but this may be a bug. $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d'); if (dol_stringtotime($_SESSION['dol_dst_first']) <= $gmtnow && $gmtnow < dol_stringtotime($_SESSION['dol_dst_second'])) $daylight=1; else $daylight=0; $tmp=dol_mktime(0,0,0,$monthref,$dayref,$yearref,false,0)-dol_mktime(0,0,0,$monthref,$dayref,$yearref,true,0)-($daylight*3600); return 'unknown'; // For true result } elseif ($refgmtdate == 'summer') { if (ini_get("date.timezone")=='UTC') return 0; // We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client but this may be a bug. $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref='08'; $dayref='01'; if (dol_stringtotime($_SESSION['dol_dst_first']) <= dol_stringtotime($yearref.'-'.$monthref.'-'.$dayref) && dol_stringtotime($yearref.'-'.$monthref.'-'.$dayref) < dol_stringtotime($_SESSION['dol_dst_second'])) $daylight=1; else $daylight=0; $tmp=dol_mktime(0,0,0,$monthref,$dayref,$yearref,false,0)-dol_mktime(0,0,0,$monthref,$dayref,$yearref,true,0)-($daylight*3600); return 'unknown'; // For true result } else $tmp=dol_mktime(0,0,0,1,1,1970); */ } $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600)); return $tz; }
/** * Create bank information record * * @param Object $user User * @return int <0 if KO, >= 0 if OK */ function create($user = '') { $now = dol_now(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_rib (fk_user, datec)"; $sql .= " VALUES (" . $this->userid . ", '" . $this->db->idate($now) . "')"; $resql = $this->db->query($sql); if ($resql) { if ($this->db->affected_rows($resql)) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "user_rib"); return 1; } } else { print $this->db->error(); return 0; } }
/** * Create bank information record * * @return int <0 if KO, >= 0 if OK */ function create() { $now=dol_now(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, datec) values ($this->socid, '".$this->db->idate($now)."')"; $resql=$this->db->query($sql); if ($resql) { if ($this->db->affected_rows($resql)) { return 1; } } else { print $this->db->error(); return 0; } }
/** * Create object in database * * @param User $user User making creation * @return int <0 if KO, >0 if OK */ function create($user) { global $conf; $error = 0; $now = dol_now(); $this->db->begin(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_fiscalyear ("; $sql .= "label"; $sql .= ", date_start"; $sql .= ", date_end"; $sql .= ", statut"; $sql .= ", entity"; $sql .= ", datec"; $sql .= ", fk_user_author"; $sql .= ") VALUES ("; $sql .= " '" . $this->label . "'"; $sql .= ", '" . $this->db->idate($this->date_start) . "'"; $sql .= ", " . ($this->date_end ? "'" . $this->db->idate($this->date_end) . "'" : "null"); $sql .= ", " . $this->statut; $sql .= ", " . $conf->entity; $sql .= ", '" . $this->db->idate($now) . "'"; $sql .= ", " . $user->id; $sql .= ")"; dol_syslog(get_class($this) . "::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_fiscalyear"); $result = $this->update($user); if ($result > 0) { $this->db->commit(); return $this->id; } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return $result; } } else { $this->error = $this->db->lasterror() . " sql=" . $sql; $this->db->rollback(); return -1; } }
/** * Create address into database * * @param int $socid Company socid * @param User $user Object user making creation * @return int 0 if OK, < 0 if KO */ function create($socid, $user = '') { global $langs, $conf; // Nettoyage parametres $this->name = trim($this->name); $this->label = trim($this->label); dol_syslog(get_class($this) . "::create label=" . $this->label); $this->db->begin(); $result = $this->verify(); if ($result >= 0) { $now = dol_now(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_address (label, fk_soc, name, datec, fk_user_creat) "; $sql .= " VALUES ('" . $this->db->escape($this->label) . "', '" . $socid . "', '" . $this->db->escape($this->name) . "', '" . $this->db->idate($now) . "', '" . $user->id . "')"; $result = $this->db->query($sql); if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "societe_address"); $ret = $this->update($this->id, $socid, $user); if ($ret >= 0) { dol_syslog(get_class($this) . "::create success id=" . $this->id); $this->db->commit(); return 0; } else { dol_syslog(get_class($this) . "::create echec update"); $this->db->rollback(); return -3; } } else { if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->nom); } else { dol_syslog(get_class($this) . "::create echec insert sql={$sql}"); } $this->db->rollback(); return -2; } } else { $this->db->rollback(); dol_syslog(get_class($this) . "::create echec verify sql={$sql}"); return -1; } }
/** * Fonction qui permet de creer la cotisation * * @param int $userid userid de celui qui insere * @return int <0 if KO, Id subscription created if OK */ function create($userid) { global $langs; $now = dol_now(); // Check parameters if ($this->datef <= $this->dateh) { $this->error = $langs->trans("ErrorBadValueForDate"); return -1; } $sql = "INSERT INTO " . MAIN_DB_PREFIX . "cotisation (fk_adherent, datec, dateadh, datef, cotisation, note)"; $sql .= " VALUES (" . $this->fk_adherent . ", '" . $this->db->idate($now) . "',"; $sql .= " '" . $this->db->idate($this->dateh) . "',"; $sql .= " '" . $this->db->idate($this->datef) . "',"; $sql .= " " . $this->amount . ",'" . $this->db->escape($this->note) . "')"; dol_syslog(get_class($this) . "::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { return $this->db->last_insert_id(MAIN_DB_PREFIX . "cotisation"); } else { $this->error = $this->db->lasterror(); return -1; } }
/** * Insert account into database * * @param User $user User making add * @return int <0 if KO, Id line added if OK */ function create($user) { $now = dol_now(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accountingaccount"; $sql .= " (date_creation, fk_user_author, numero,intitule)"; $sql .= " VALUES (" . $this->db->idate($now) . "," . $user->id . ",'" . $this->numero . "','" . $this->intitule . "')"; $resql = $this->db->query($sql); if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accountingaccount"); if ($id > 0) { $this->id = $id; $result = $this->id; } else { $result = -2; $this->error = "AccountancyAccount::Create Erreur {$result}"; dol_syslog($this->error, LOG_ERR); } } else { $result = -1; $this->error = "AccountancyAccount::Create Erreur {$result}"; dol_syslog($this->error, LOG_ERR); } return $result; }
/** * Update object into database * * @param User $user that modifies * @param int $notrigger triggers after, 1=disable triggers * @param int $forceupdateaffiliate update price on each soc child * @return int <0 if KO, >0 if OK */ function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0) { global $conf, $langs; $error = 0; // Clean parameters if (isset($this->entity)) { $this->entity = trim($this->entity); } if (isset($this->fk_product)) { $this->fk_product = trim($this->fk_product); } if (isset($this->fk_soc)) { $this->fk_soc = trim($this->fk_soc); } if (isset($this->price)) { $this->price = trim($this->price); } if (isset($this->price_ttc)) { $this->price_ttc = trim($this->price_ttc); } if (isset($this->price_min)) { $this->price_min = trim($this->price_min); } if (isset($this->price_min_ttc)) { $this->price_min_ttc = trim($this->price_min_ttc); } if (isset($this->price_base_type)) { $this->price_base_type = trim($this->price_base_type); } if (isset($this->tva_tx)) { $this->tva_tx = trim($this->tva_tx); } if (isset($this->recuperableonly)) { $this->recuperableonly = trim($this->recuperableonly); } if (isset($this->localtax1_tx)) { $this->localtax1_tx = trim($this->localtax1_tx); } if (isset($this->localtax2_tx)) { $this->localtax2_tx = trim($this->localtax2_tx); } if (isset($this->fk_user)) { $this->fk_user = trim($this->fk_user); } if (isset($this->import_key)) { $this->import_key = trim($this->import_key); } // Check parameters // Put here code to add a control on parameters values if ($this->price != '' || $this->price == 0) { if ($this->price_base_type == 'TTC') { $this->price_ttc = price2num($this->price, 'MU'); $this->price = price2num($this->price) / (1 + $this->tva_tx / 100); $this->price = price2num($this->price, 'MU'); if ($this->price_min != '' || $this->price_min == 0) { $this->price_min_ttc = price2num($this->price_min, 'MU'); $this->price_min = price2num($this->price_min) / (1 + $this->tva_tx / 100); $this->price_min = price2num($this->price_min, 'MU'); } else { $this->price_min = 0; $this->price_min_ttc = 0; } } else { $this->price = price2num($this->price, 'MU'); $this->price_ttc = $this->recuperableonly != 1 ? price2num($this->price) * (1 + $this->tva_tx / 100) : $this->price; $this->price_ttc = price2num($this->price_ttc, 'MU'); if ($this->price_min != '' || $this->price_min == 0) { $this->price_min = price2num($this->price_min, 'MU'); $this->price_min_ttc = price2num($this->price_min) * (1 + $this->tva_tx / 100); $this->price_min_ttc = price2num($this->price_min_ttc, 'MU'); // print 'X'.$newminprice.'-'.$price_min; } else { $this->price_min = 0; $this->price_min_ttc = 0; } } } // Do a copy of current record into log table // Insert request $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_customer_price_log("; $sql .= "entity,"; $sql .= "datec,"; $sql .= "fk_product,"; $sql .= "fk_soc,"; $sql .= "price,"; $sql .= "price_ttc,"; $sql .= "price_min,"; $sql .= "price_min_ttc,"; $sql .= "price_base_type,"; $sql .= "tva_tx,"; $sql .= "recuperableonly,"; $sql .= "localtax1_tx,"; $sql .= "localtax2_tx,"; $sql .= "fk_user,"; $sql .= "import_key"; $sql .= ") \t\t"; $sql .= "SELECT"; $sql .= " t.entity,"; $sql .= " t.datec,"; $sql .= " t.fk_product,"; $sql .= " t.fk_soc,"; $sql .= " t.price,"; $sql .= " t.price_ttc,"; $sql .= " t.price_min,"; $sql .= " t.price_min_ttc,"; $sql .= " t.price_base_type,"; $sql .= " t.tva_tx,"; $sql .= " t.recuperableonly,"; $sql .= " t.localtax1_tx,"; $sql .= " t.localtax2_tx,"; $sql .= " t.fk_user,"; $sql .= " t.import_key"; $sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t"; $sql .= " WHERE t.rowid = " . $this->id; $this->db->begin(); dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } // Update request $sql = "UPDATE " . MAIN_DB_PREFIX . "product_customer_price SET"; $sql .= " entity=" . $conf->entity . ","; $sql .= " datec='" . $this->db->idate(dol_now()) . "',"; $sql .= " tms=" . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : 'null') . ","; $sql .= " fk_product=" . (isset($this->fk_product) ? $this->fk_product : "null") . ","; $sql .= " fk_soc=" . (isset($this->fk_soc) ? $this->fk_soc : "null") . ","; $sql .= " price=" . (isset($this->price) ? $this->price : "null") . ","; $sql .= " price_ttc=" . (isset($this->price_ttc) ? $this->price_ttc : "null") . ","; $sql .= " price_min=" . (isset($this->price_min) ? $this->price_min : "null") . ","; $sql .= " price_min_ttc=" . (isset($this->price_min_ttc) ? $this->price_min_ttc : "null") . ","; $sql .= " price_base_type=" . (isset($this->price_base_type) ? "'" . $this->db->escape($this->price_base_type) . "'" : "null") . ","; $sql .= " tva_tx=" . (isset($this->tva_tx) ? $this->tva_tx : "null") . ","; $sql .= " recuperableonly=" . (isset($this->recuperableonly) ? $this->recuperableonly : "null") . ","; $sql .= " localtax1_tx=" . (isset($this->localtax1_tx) ? $this->localtax1_tx : "null") . ","; $sql .= " localtax2_tx=" . (isset($this->localtax2_tx) ? $this->localtax2_tx : "null") . ","; $sql .= " fk_user="******","; $sql .= " import_key=" . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . ""; $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } if (!$error) { if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. // // Call triggers // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; // $interface=new Interfaces($this->db); // $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); // if ($result < 0) { $error++; $this->errors=$interface->errors; } // // End call triggers } } if (!$error) { $result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate); if ($result < 0) { $error++; } } // Commit or rollback if ($error) { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR); $this->error .= $this->error ? ', ' . $errmsg : $errmsg; } $this->db->rollback(); return -1 * $error; } else { $this->db->commit(); return 1; } }
$year_start = $year_current; } else { $year_current = $year; $year_start = $year; } $date_start = dol_mktime(0, 0, 0, $_REQUEST["date_startmonth"], $_REQUEST["date_startday"], $_REQUEST["date_startyear"]); $date_end = dol_mktime(23, 59, 59, $_REQUEST["date_endmonth"], $_REQUEST["date_endday"], $_REQUEST["date_endyear"]); // Quarter if (empty($date_start) || empty($date_end)) { $q = GETPOST("q"); if (empty($q)) { if (isset($_REQUEST["month"])) { $date_start = dol_get_first_day($year_start, $_REQUEST["month"], false); $date_end = dol_get_last_day($year_start, $_REQUEST["month"], false); } else { $month_current = strftime("%m", dol_now()); if ($month_current >= 10) { $q = 4; } elseif ($month_current >= 7) { $q = 3; } elseif ($month_current >= 4) { $q = 2; } else { $q = 1; } } } if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
/** * Return next value * * @param Societe $objsoc Object third party * @param int $type Client ou fournisseur (1:client, 2:fournisseur) * @return string Value if OK, '' if module not configured, <0 if KO */ function getNextValue($objsoc = 0, $type = -1) { global $db, $conf, $mc; $return = '000001'; $field = ''; $where = ''; if ($type == 0) { $field = 'code_client'; //$where = ' AND client in (1,2)'; } else { if ($type == 1) { $field = 'code_fournisseur'; //$where = ' AND fournisseur = 1'; } else { return -1; } } if ($type == 0) { $prefix = $this->prefixcustomer; } if ($type == 1) { $prefix = $this->prefixsupplier; } // D'abord on recupere la valeur max (reponse immediate car champ indexe) $posindice = 8; $sql = "SELECT MAX(CAST(SUBSTRING(" . $field . " FROM " . $posindice . ") AS SIGNED)) as max"; // This is standard SQL $sql .= " FROM " . MAIN_DB_PREFIX . "societe"; $sql .= " WHERE " . $field . " LIKE '" . $prefix . "____-%'"; $sql .= " AND entity IN (" . getEntity('societe', 1) . ")"; dol_syslog(get_class($this) . "::getNextValue", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); if ($obj) { $max = intval($obj->max); } else { $max = 0; } } else { return -1; } $date = dol_now(); $yymm = strftime("%y%m", $date); if ($max >= pow(10, 4) - 1) { $num = $max + 1; } else { $num = sprintf("%04s", $max + 1); } dol_syslog(get_class($this) . "::getNextValue return " . $prefix . $yymm . "-" . $num); return $prefix . $yymm . "-" . $num; }
/** * Return next free value * * @param Societe $objsoc Object thirdparty * @param Object $object Object we need next value for * @return string Value if KO, <0 if KO */ function getNextValue($objsoc, $object) { global $db, $conf; // D'abord on recupere la valeur max $posindice = 8; $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM " . $posindice . ") AS SIGNED)) as max"; // This is standard SQL $sql .= " FROM " . MAIN_DB_PREFIX . "livraison"; $sql .= " WHERE ref LIKE '" . $this->prefix . "____-%'"; $sql .= " AND entity = " . $conf->entity; $resql = $db->query($sql); dol_syslog("mod_livraison_jade::getNextValue", LOG_DEBUG); if ($resql) { $obj = $db->fetch_object($resql); if ($obj) { $max = intval($obj->max); } else { $max = 0; } } else { return -1; } $date = $object->date_delivery; if (empty($date)) { $date = dol_now(); } $yymm = strftime("%y%m", $date); if ($max >= pow(10, 4) - 1) { $num = $max + 1; } else { $num = sprintf("%04s", $max + 1); } dol_syslog("mod_livraison_jade::getNextValue return " . $this->prefix . $yymm . "-" . $num); return $this->prefix . $yymm . "-" . $num; }
print '<td>' . dol_print_date($db->jdate($obj->datec), 'day') . '</td>'; print '<td align="right">' . $supplier_proposalstatic->LibStatut($obj->fk_statut, 5) . '</td>'; print '</tr>'; $i++; } } print "</table><br>"; } else { dol_print_error($db); } /* * Opened askprice */ if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire) { $langs->load("supplier_proposal"); $now = dol_now(); $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, p.rowid as supplier_proposalid, p.total as total_ttc, p.total_ht, p.ref, p.fk_statut, p.datec as dp"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= ", " . MAIN_DB_PREFIX . "supplier_proposal as p"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE p.fk_soc = s.rowid"; $sql .= " AND p.entity = " . $conf->entity; $sql .= " AND p.fk_statut = 1"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $socid; }
/** * Adds cronjobs * * @return int Error count (0 if OK) */ function insert_cronjobs() { require_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php'; global $conf; $err = 0; if (is_array($this->cronjobs)) { foreach ($this->cronjobs as $key => $value) { $label = isset($this->cronjobs[$key]['label']) ? $this->cronjobs[$key]['label'] : ''; $jobtype = isset($this->cronjobs[$key]['jobtype']) ? $this->cronjobs[$key]['jobtype'] : ''; $class = isset($this->cronjobs[$key]['class']) ? $this->cronjobs[$key]['class'] : ''; $method = isset($this->cronjobs[$key]['method']) ? $this->cronjobs[$key]['method'] : ''; $command = isset($this->cronjobs[$key]['command']) ? $this->cronjobs[$key]['command'] : ''; $parameters = isset($this->cronjobs[$key]['parameters']) ? $this->cronjobs[$key]['parameters'] : ''; $comment = isset($this->cronjobs[$key]['comment']) ? $this->cronjobs[$key]['comment'] : ''; $frequency = isset($this->cronjobs[$key]['frequency']) ? $this->cronjobs[$key]['frequency'] : ''; $unitfrequency = isset($this->cronjobs[$key]['unitfrequency']) ? $this->cronjobs[$key]['unitfrequency'] : ''; // Search if boxes def already present $sql = "SELECT count(*) as nb FROM " . MAIN_DB_PREFIX . "cronjob"; $sql .= " WHERE module_name = '" . $this->db->escape($this->rights_class) . "'"; if ($class) { $sql .= " AND classesname = '" . $this->db->escape($class) . "'"; } if ($method) { $sql .= " AND methodename = '" . $this->db->escape($method) . "'"; } if ($command) { $sql .= " AND command = '" . $this->db->escape($command) . "'"; } $sql .= " AND entity = " . $conf->entity; $now = dol_now(); dol_syslog(get_class($this) . "::insert_cronjobs", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); if ($obj->nb == 0) { $this->db->begin(); if (!$err) { $sql = "INSERT INTO " . MAIN_DB_PREFIX . "cronjob (module_name, datec, label, jobtype, classesname, methodename, command, params, note, frequency, unitfrequency, entity)"; $sql .= " VALUES ("; $sql .= "'" . $this->db->escape($this->rights_class) . "', "; $sql .= "'" . $this->db->idate($now) . "', "; $sql .= "'" . $this->db->escape($label) . "', "; $sql .= "'" . $this->db->escape($jobtype) . "', "; $sql .= ($class ? "'" . $this->db->escape($class) . "'" : "null") . ","; $sql .= ($method ? "'" . $this->db->escape($method) . "'" : "null") . ","; $sql .= ($command ? "'" . $this->db->escape($command) . "'" : "null") . ","; $sql .= ($parameters ? "'" . $this->db->escape($parameters) . "'" : "null") . ","; $sql .= ($comment ? "'" . $this->db->escape($comment) . "'" : "null") . ","; $sql .= "'" . $this->db->escape($frequency) . "', "; $sql .= "'" . $this->db->escape($unitfrequency) . "', "; $sql .= $conf->entity; $sql .= ")"; print $sql; dol_syslog(get_class($this) . "::insert_cronjobs", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $err++; } } if (!$err) { $this->db->commit(); } else { $this->error = $this->db->lasterror(); $this->db->rollback(); } } // else box already registered into database } else { $this->error = $this->db->lasterror(); $err++; } } } return $err; }
/** * getListOfProductsOrServices * * @param array $authentication Array of authentication information * @param array $filterproduct Filter fields * @return array Array result */ function getListOfProductsOrServices($authentication, $filterproduct) { global $db, $conf, $langs; $now = dol_now(); dol_syslog("Function: getListOfProductsOrServices login="******"SELECT rowid, ref, ref_ext"; $sql .= " FROM " . MAIN_DB_PREFIX . "product"; $sql .= " WHERE entity=" . $conf->entity; foreach ($filterproduct as $key => $val) { if ($key == 'type' && $val >= 0) { $sql .= " AND fk_product_type = " . $db->escape($val); } if ($key == 'tosell') { $sql .= " AND to_sell = " . $db->escape($val); } if ($key == 'tobuy') { $sql .= " AND to_buy = " . $db->escape($val); } } $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); $arrayproducts[] = array('id' => $obj->rowid, 'ref' => $obj->ref, 'ref_ext' => $obj->ref_ext); $i++; } } else { $error++; $errorcode = $db->lasterrno(); $errorlabel = $db->lasterror(); } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel), 'products' => $arrayproducts); } else { $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'products' => $arrayproducts); } return $objectresp; }
/** * Return next value * * @param Product $objproduct Object product * @param string $type type of barcode (EAN, ISBN, ...) * @return string Value if OK, '' if module not configured, <0 if KO */ function getNextValue($objproduct, $type = '') { global $db, $conf; require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; // TODO // Get Mask value $mask = ''; if (!empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) { $mask = $conf->global->BARCODE_STANDARD_PRODUCT_MASK; } if (empty($mask)) { $this->error = 'NotConfigured'; return ''; } $field = 'barcode'; $where = ''; $now = dol_now(); $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); return $numFinal; }
/** * Return label of this contract line status * @param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * @return string Libelle */ function getLibStatut($mode) { return $this->LibStatut($this->statut,$mode,(isset($this->date_fin_validite)?($this->date_fin_validite < dol_now('tzref')?1:0):-1)); }
/** Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone * @param int $project_id Id of project to attach clone task * @param int $parent_task_id Id of task to attach clone task * @param bool $clone_change_dt recalculate date of task regarding new project start date * @param bool $clone_affectation clone affectation of project * @param bool $clone_time clone time of project * @param bool $clone_file clone file of project * @param bool $clone_note clone note of project * @param bool $clone_prog clone progress of project * @return int New id of clone */ function createFromClone($fromid, $project_id, $parent_task_id, $clone_change_dt = false, $clone_affectation = false, $clone_time = false, $clone_file = false, $clone_note = false, $clone_prog = false) { global $user, $langs, $conf; $error = 0; //Use 00:00 of today if time is use on task. $now = dol_mktime(0, 0, 0, dol_print_date(dol_now(), '%m'), dol_print_date(dol_now(), '%d'), dol_print_date(dol_now(), '%Y')); $datec = $now; $clone_task = new Task($this->db); $origin_task = new Task($this->db); $clone_task->context['createfromclone'] = 'createfromclone'; $this->db->begin(); // Load source object $clone_task->fetch($fromid); $origin_task->fetch($fromid); $defaultref = ''; $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON; if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . ".php")) { require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . '.php'; $modTask = new $obj(); $defaultref = $modTask->getNextValue(0, $clone_task); } $ori_project_id = $clone_task->fk_project; $clone_task->id = 0; $clone_task->ref = $defaultref; $clone_task->fk_project = $project_id; $clone_task->fk_task_parent = $parent_task_id; $clone_task->date_c = $datec; $clone_task->planned_workload = $origin_task->planned_workload; $clone_task->rang = $origin_task->rang; //Manage Task Date if ($clone_change_dt) { $projectstatic = new Project($this->db); $projectstatic->fetch($ori_project_id); //Origin project strat date $orign_project_dt_start = $projectstatic->date_start; //Calcultate new task start date with difference between origin proj start date and origin task start date if (!empty($clone_task->date_start)) { $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start; } //Calcultate new task end date with difference between origin proj end date and origin task end date if (!empty($clone_task->date_end)) { $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start; } } if (!$clone_prog) { $clone_task->progress = 0; } // Create clone $result = $clone_task->create($user); // Other options if ($result < 0) { $this->error = $clone_task->error; $error++; } // End if (!$error) { $clone_task_id = $clone_task->id; $clone_task_ref = $clone_task->ref; //Note Update if (!$clone_note) { $clone_task->note_private = ''; $clone_task->note_public = ''; } else { $this->db->begin(); $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_public, ENT_QUOTES), '_public'); if ($res < 0) { $this->error .= $clone_task->error; $error++; $this->db->rollback(); } else { $this->db->commit(); } $this->db->begin(); $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_private, ENT_QUOTES), '_private'); if ($res < 0) { $this->error .= $clone_task->error; $error++; $this->db->rollback(); } else { $this->db->commit(); } } //Duplicate file if ($clone_file) { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; //retreive project origin ref to know folder to copy $projectstatic = new Project($this->db); $projectstatic->fetch($ori_project_id); $ori_project_ref = $projectstatic->ref; if ($ori_project_id != $project_id) { $projectstatic->fetch($project_id); $clone_project_ref = $projectstatic->ref; } else { $clone_project_ref = $ori_project_ref; } $clone_task_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($clone_project_ref) . "/" . dol_sanitizeFileName($clone_task_ref); $ori_task_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($ori_project_ref) . "/" . dol_sanitizeFileName($fromid); $filearray = dol_dir_list($ori_task_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', '', SORT_ASC, 1); foreach ($filearray as $key => $file) { if (!file_exists($clone_task_dir)) { if (dol_mkdir($clone_task_dir) < 0) { $this->error .= $langs->trans('ErrorInternalErrorDetected') . ':dol_mkdir'; $error++; } } $rescopy = dol_copy($ori_task_dir . '/' . $file['name'], $clone_task_dir . '/' . $file['name'], 0, 1); if (is_numeric($rescopy) && $rescopy < 0) { $this->error .= $langs->trans("ErrorFailToCopyFile", $ori_task_dir . '/' . $file['name'], $clone_task_dir . '/' . $file['name']); $error++; } } } // clone affectation if ($clone_affectation) { $origin_task = new Task($this->db); $origin_task->fetch($fromid); foreach (array('internal', 'external') as $source) { $tab = $origin_task->liste_contact(-1, $source); $num = count($tab); $i = 0; while ($i < $num) { $clone_task->add_contact($tab[$i]['id'], $tab[$i]['code'], $tab[$i]['source']); if ($clone_task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); $error++; } else { if ($clone_task->error != '') { $this->error .= $clone_task->error; $error++; } } $i++; } } } if ($clone_time) { //TODO clone time of affectation } } unset($clone_task->context['createfromclone']); if (!$error) { $this->db->commit(); return $clone_task_id; } else { $this->db->rollback(); dol_syslog(get_class($this) . "::createFromClone nbError: " . $error . " error : " . $this->error, LOG_ERR); return -1; } }
/** * Load data into info_box_contents array to show array later. * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $conf, $user, $langs, $db; $this->max = $max; $refreshaction = 'refresh_' . $this->boxcode; include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; $text = $langs->trans("BoxSuppliersInvoicesPerMonth", $max); $this->info_box_head = array('text' => $text, 'limit' => dol_strlen($text), 'graph' => 1, 'sublink' => '', 'subtext' => $langs->trans("Filter"), 'subpicto' => 'filter.png', 'subclass' => 'linkobject', 'target' => 'none'); $dir = ''; // We don't need a path because image file will not be saved into disk $prefix = ''; $socid = 0; if ($user->societe_id) { $socid = $user->societe_id; } if (!$user->rights->societe->client->voir || $socid) { $prefix .= 'private-' . $user->id . '-'; } // If user has no permission to see all, output dir is specific to user if ($user->rights->fournisseur->facture->lire) { $param_year = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_year'; $param_shownb = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_shownb'; $param_showtot = 'DOLUSERCOOKIE_box_' . $this->boxcode . '_showtot'; include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facturestats.class.php'; $autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE')); if (in_array('DOLUSERCOOKIE_box_' . $this->boxcode, $autosetarray)) { $endyear = GETPOST($param_year, 'int'); $shownb = GETPOST($param_shownb, 'alpha'); $showtot = GETPOST($param_showtot, 'alpha'); } else { $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_box_' . $this->boxcode], true); $endyear = $tmparray['year']; $shownb = $tmparray['shownb']; $showtot = $tmparray['showtot']; } if (empty($shownb) && empty($showtot)) { $showtot = 1; } $nowarray = dol_getdate(dol_now(), true); if (empty($endyear)) { $endyear = $nowarray['year']; } $startyear = $endyear - 1; $mode = 'supplier'; $WIDTH = $shownb && $showtot || !empty($conf->dol_optimize_smallscreen) ? '256' : '320'; $HEIGHT = '192'; $stats = new FactureStats($this->db, $socid, $mode, 0); // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) if ($shownb) { $data1 = $stats->getNbByMonthWithPrevYear($endyear, $startyear, GETPOST('action') == $refreshaction ? -1 : 3600 * 24); $filenamenb = $dir . "/" . $prefix . "invoicessuppliernbinyear-" . $year . ".png"; if ($mode == 'customer') { $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=billstats&file=invoicesnbinyear-' . $year . '.png'; } if ($mode == 'supplier') { $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=billstatssupplier&file=invoicessuppliernbinyear-' . $year . '.png'; } $px1 = new DolGraph(); $mesg = $px1->isGraphKo(); if (!$mesg) { $px1->SetData($data1); unset($data1); $px1->SetPrecisionY(0); $i = $startyear; $legend = array(); while ($i <= $endyear) { $legend[] = $i; $i++; } $px1->SetLegend($legend); $px1->SetMaxValue($px1->GetCeilMaxValue()); $px1->SetWidth($WIDTH); $px1->SetHeight($HEIGHT); $px1->SetYLabel($langs->trans("NumberOfBills")); $px1->SetShading(3); $px1->SetHorizTickIncrement(1); $px1->SetPrecisionY(0); $px1->SetCssPrefix("cssboxes"); $px1->mode = 'depth'; $px1->SetTitle($langs->trans("NumberOfBillsByMonth")); $px1->draw($filenamenb, $fileurlnb); } } // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) if ($showtot) { $data2 = $stats->getAmountByMonthWithPrevYear($endyear, $startyear, GETPOST('action') == $refreshaction ? -1 : 3600 * 24); $filenamenb = $dir . "/" . $prefix . "invoicessupplieramountinyear-" . $year . ".png"; if ($mode == 'customer') { $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=billstats&file=invoicesamountinyear-' . $year . '.png'; } if ($mode == 'supplier') { $fileurlnb = DOL_URL_ROOT . '/viewimage.php?modulepart=billstatssupplier&file=invoicessupplieramountinyear-' . $year . '.png'; } $px2 = new DolGraph(); $mesg = $px2->isGraphKo(); if (!$mesg) { $px2->SetData($data2); unset($data2); $px2->SetPrecisionY(0); $i = $startyear; $legend = array(); while ($i <= $endyear) { $legend[] = $i; $i++; } $px2->SetLegend($legend); $px2->SetMaxValue($px2->GetCeilMaxValue()); $px2->SetWidth($WIDTH); $px2->SetHeight($HEIGHT); $px2->SetYLabel($langs->trans("AmountOfBillsHT")); $px2->SetShading(3); $px2->SetHorizTickIncrement(1); $px2->SetPrecisionY(0); $px2->SetCssPrefix("cssboxes"); $px2->mode = 'depth'; $px2->SetTitle($langs->trans("AmountOfBillsByMonthHT")); $px2->draw($filenamenb, $fileurlnb); } } if (empty($conf->use_javascript_ajax)) { $langs->load("errors"); $mesg = $langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs"); } if (!$mesg) { $stringtoshow = ''; $stringtoshow .= '<script type="text/javascript" language="javascript"> jQuery(document).ready(function() { jQuery("#idsubimg' . $this->boxcode . '").click(function() { jQuery("#idfilter' . $this->boxcode . '").toggle(); }); }); </script>'; $stringtoshow .= '<div class="center hideobject" id="idfilter' . $this->boxcode . '">'; // hideobject is to start hidden $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="' . $_SERVER["PHP_SELF"] . '">'; $stringtoshow .= '<input type="hidden" name="action" value="' . $refreshaction . '">'; $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_' . $this->boxcode . ':year,shownb,showtot">'; $stringtoshow .= '<input type="checkbox" name="' . $param_shownb . '"' . ($shownb ? ' checked' : '') . '> ' . $langs->trans("NumberOfBillsByMonth"); $stringtoshow .= ' '; $stringtoshow .= '<input type="checkbox" name="' . $param_showtot . '"' . ($showtot ? ' checked' : '') . '> ' . $langs->trans("AmountOfBillsByMonthHT"); $stringtoshow .= '<br>'; $stringtoshow .= $langs->trans("Year") . ' <input class="flat" size="4" type="text" name="' . $param_year . '" value="' . $endyear . '">'; $stringtoshow .= '<input type="image" alt="' . $langs->trans("Refresh") . '" src="' . img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1) . '">'; $stringtoshow .= '</form>'; $stringtoshow .= '</div>'; if ($shownb && $showtot) { $stringtoshow .= '<div class="fichecenter">'; $stringtoshow .= '<div class="fichehalfleft">'; } if ($shownb) { $stringtoshow .= $px1->show(); } if ($shownb && $showtot) { $stringtoshow .= '</div>'; $stringtoshow .= '<div class="fichehalfright">'; } if ($showtot) { $stringtoshow .= $px2->show(); } if ($shownb && $showtot) { $stringtoshow .= '</div>'; $stringtoshow .= '</div>'; } $this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"', 'textnoformat' => $stringtoshow); } else { $this->info_box_contents[0][0] = array('td' => 'align="left" class="nohover"', 'maxlength' => 500, 'text' => $mesg); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }