41 include_once
'inc.php';
42 if (!file_exists($conffile)) {
43 print
'Error: Dolibarr config file was not found. This may means that Dolibarr is not installed yet. Please call the page "/install/index.php" instead of "/install/upgrade.php").';
45 require_once $conffile;
46 require_once $dolibarr_main_document_root.
'/compta/facture/class/facture.class.php';
47 require_once $dolibarr_main_document_root.
'/comm/propal/class/propal.class.php';
48 require_once $dolibarr_main_document_root.
'/contrat/class/contrat.class.php';
49 require_once $dolibarr_main_document_root.
'/commande/class/commande.class.php';
50 require_once $dolibarr_main_document_root.
'/fourn/class/fournisseur.commande.class.php';
51 require_once $dolibarr_main_document_root.
'/core/lib/price.lib.php';
52 require_once $dolibarr_main_document_root.
'/core/class/menubase.class.php';
53 require_once $dolibarr_main_document_root.
'/core/lib/files.lib.php';
64 $err = error_reporting();
66 if (!empty($conf->global->MAIN_OVERRIDE_TIME_LIMIT)) {
67 @set_time_limit((
int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
71 error_reporting($err);
73 $setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
74 $langs->setDefaultLang($setuplang);
75 $versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
76 $versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
77 $enablemodules =
GETPOST(
"enablemodules",
'alpha', 3) ?
GETPOST(
"enablemodules",
'alpha', 3) : (empty($argv[3]) ?
'' : $argv[3]);
79 $langs->loadLangs(array(
"admin",
"install",
"bills",
"suppliers"));
81 if ($dolibarr_main_db_type ==
'mysqli') {
84 if ($dolibarr_main_db_type ==
'pgsql') {
87 if ($dolibarr_main_db_type ==
'mssql') {
92 dolibarr_install_syslog(
"--- upgrade2: entering upgrade2.php page ".$versionfrom.
" ".$versionto.
" ".$enablemodules);
93 if (!is_object($conf)) {
103 if ((!$versionfrom || preg_match(
'/version/', $versionfrom)) && (!$versionto || preg_match(
'/version/', $versionto))) {
104 print
'Error: Parameter versionfrom or versionto missing or having a bad format.'.
"\n";
105 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
107 $sapi_type = php_sapi_name();
108 $script_file = basename(__FILE__);
110 if (substr($sapi_type, 0, 3) ==
'cli') {
111 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
116 pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
119 if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
120 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
121 print
'<span class="inline-block">'.$langs->trans(
'DataMigration').
'</span></h3>';
123 print
'<table border="0" width="100%">';
126 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
127 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
128 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
129 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
130 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
131 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
133 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
138 $conf->db->type = $dolibarr_main_db_type;
139 $conf->db->host = $dolibarr_main_db_host;
140 $conf->db->port = $dolibarr_main_db_port;
141 $conf->db->name = $dolibarr_main_db_name;
142 $conf->db->user = $dolibarr_main_db_user;
143 $conf->db->pass = $dolibarr_main_db_pass;
145 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
147 if (!$db->connected) {
148 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase", $conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
149 dolibarr_install_syslog(
'upgrade2: failed to connect to database :'.$conf->db->name.
' on '.$conf->db->host.
' for user '.$conf->db->user, LOG_ERR);
154 if ($db->database_selected) {
161 if (empty($dolibarr_main_db_encryption)) {
162 $dolibarr_main_db_encryption = 0;
164 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
165 if (empty($dolibarr_main_db_cryptkey)) {
166 $dolibarr_main_db_cryptkey =
'';
168 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
171 $conf->setValues($db);
174 $listofentities = array(1);
177 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
179 $hookmanager->initHooks(array(
'upgrade2'));
181 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
182 $object =
new stdClass();
184 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters, $object, $action);
185 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
187 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
198 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
200 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
202 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
204 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
206 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
208 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
210 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
212 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
214 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
216 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
218 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
224 foreach ($listofentities as $entity) {
226 $conf->setEntityValues($db, $entity);
228 if (defined(
'SYSLOG_FILE')) {
229 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
231 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
234 if (count($listofentities) > 1) {
235 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
240 $dolibarrlastupgradeversionarray = preg_split(
'/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL :
''));
246 $versiontoarray = explode(
'.', $versionto);
247 $versionranarray = explode(
'.', DOL_VERSION);
250 $afterversionarray = explode(
'.',
'2.0.0');
251 $beforeversionarray = explode(
'.',
'2.7.9');
312 $afterversionarray = explode(
'.',
'2.7.9');
313 $beforeversionarray = explode(
'.',
'2.8.9');
338 $afterversionarray = explode(
'.',
'2.8.9');
339 $beforeversionarray = explode(
'.',
'2.9.9');
351 $afterversionarray = explode(
'.',
'2.9.9');
352 $beforeversionarray = explode(
'.',
'3.0.9');
358 $afterversionarray = explode(
'.',
'3.0.9');
359 $beforeversionarray = explode(
'.',
'3.1.9');
367 $afterversionarray = explode(
'.',
'3.1.9');
368 $beforeversionarray = explode(
'.',
'3.2.9');
378 $afterversionarray = explode(
'.',
'3.2.9');
379 $beforeversionarray = explode(
'.',
'3.3.9');
388 $afterversionarray = explode(
'.',
'3.6.9');
389 $beforeversionarray = explode(
'.',
'3.7.9');
395 $afterversionarray = explode(
'.',
'3.7.9');
396 $beforeversionarray = explode(
'.',
'3.8.9');
402 $afterversionarray = explode(
'.',
'3.9.9');
403 $beforeversionarray = explode(
'.',
'4.0.9');
409 $afterversionarray = explode(
'.',
'4.0.9');
410 $beforeversionarray = explode(
'.',
'5.0.9');
420 $afterversionarray = explode(
'.',
'5.0.9');
421 $beforeversionarray = explode(
'.',
'6.0.9');
424 global $multicompany_transverse_mode;
427 if (empty($multicompany_transverse_mode)) {
438 $afterversionarray = explode(
'.',
'6.0.9');
439 $beforeversionarray = explode(
'.',
'7.0.9');
448 $afterversionarray = explode(
'.',
'7.0.9');
449 $beforeversionarray = explode(
'.',
'8.0.9');
455 $afterversionarray = explode(
'.',
'8.0.9');
456 $beforeversionarray = explode(
'.',
'9.0.9');
462 $afterversionarray = explode(
'.',
'10.0.9');
463 $beforeversionarray = explode(
'.',
'11.0.9');
472 $afterversionarray = explode(
'.',
'13.0.9');
473 $beforeversionarray = explode(
'.',
'14.0.9');
480 $afterversionarray = explode(
'.',
'15.0.9');
481 $beforeversionarray = explode(
'.',
'16.0.9');
488 $afterversionarray = explode(
'.',
'16.0.9');
489 $beforeversionarray = explode(
'.',
'17.0.9');
499 $listofmodule = array(
500 'MAIN_MODULE_ACCOUNTING'=>
'newboxdefonly',
501 'MAIN_MODULE_AGENDA'=>
'newboxdefonly',
502 'MAIN_MODULE_BOM'=>
'menuonly',
503 'MAIN_MODULE_BANQUE'=>
'menuonly',
504 'MAIN_MODULE_BARCODE'=>
'newboxdefonly',
505 'MAIN_MODULE_CRON'=>
'newboxdefonly',
506 'MAIN_MODULE_COMMANDE'=>
'newboxdefonly',
507 'MAIN_MODULE_BLOCKEDLOG'=>
'noboxes',
508 'MAIN_MODULE_DEPLACEMENT'=>
'newboxdefonly',
509 'MAIN_MODULE_DON'=>
'newboxdefonly',
510 'MAIN_MODULE_ECM'=>
'newboxdefonly',
511 'MAIN_MODULE_EXTERNALSITE'=>
'newboxdefonly',
512 'MAIN_MODULE_EXPENSEREPORT'=>
'newboxdefonly',
513 'MAIN_MODULE_FACTURE'=>
'newboxdefonly',
514 'MAIN_MODULE_FOURNISSEUR'=>
'newboxdefonly',
515 'MAIN_MODULE_HOLIDAY'=>
'newboxdefonly',
516 'MAIN_MODULE_MARGIN'=>
'menuonly',
517 'MAIN_MODULE_MRP'=>
'menuonly',
518 'MAIN_MODULE_OPENSURVEY'=>
'newboxdefonly',
519 'MAIN_MODULE_PAYBOX'=>
'newboxdefonly',
520 'MAIN_MODULE_PRINTING'=>
'newboxdefonly',
521 'MAIN_MODULE_PRODUIT'=>
'newboxdefonly',
522 'MAIN_MODULE_RECRUITMENT'=>
'menuonly',
523 'MAIN_MODULE_RESOURCE'=>
'noboxes',
524 'MAIN_MODULE_SALARIES'=>
'newboxdefonly',
525 'MAIN_MODULE_SERVICE'=>
'newboxdefonly',
526 'MAIN_MODULE_SYSLOG'=>
'newboxdefonly',
527 'MAIN_MODULE_SOCIETE'=>
'newboxdefonly',
528 'MAIN_MODULE_STRIPE'=>
'menuonly',
529 'MAIN_MODULE_TICKET'=>
'newboxdefonly',
530 'MAIN_MODULE_TAKEPOS'=>
'newboxdefonly',
531 'MAIN_MODULE_USER'=>
'newboxdefonly',
532 'MAIN_MODULE_VARIANTS'=>
'newboxdefonly',
533 'MAIN_MODULE_WEBSITE'=>
'newboxdefonly',
549 if (!$error && $enablemodules) {
551 $listofmodules = array();
552 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
553 $tmplistofmodules = explode(
',', $enablemodules);
554 foreach ($tmplistofmodules as $value) {
555 $listofmodules[$value] =
'forceactivate';
559 if ($resultreloadmodules < 0) {
567 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf'=>$conf);
568 $object =
new stdClass();
570 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters, $object, $action);
571 if ($hookmanager->resNbOfHooks > 0) {
573 print
'<tr><td colspan="4">';
574 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
575 print $hookmanager->error;
576 print
"<!-- (".$reshook.
") -->";
579 print
'<tr class="trforrunsql"><td colspan="4">';
580 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
581 print
"<!-- (".$reshook.
") -->";
586 if (!empty($conf->modules_parts[
'hooks'])) {
587 print
'<tr class="trforrunsql"><td colspan="4">';
588 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
599 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
614 foreach ($listofentities as $entity) {
616 $conf->setEntityValues($db, $entity);
618 if (defined(
'SYSLOG_FILE')) {
619 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
621 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
625 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
626 $destroot = DOL_DATA_ROOT.
'/medias';
639 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf'=>$conf);
640 $object =
new stdClass();
642 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters, $object, $action);
643 if ($hookmanager->resNbOfHooks > 0) {
645 print
'<tr><td colspan="4">';
646 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
647 print $hookmanager->error;
648 print
"<!-- (".$reshook.
") -->";
651 print
'<tr class="trforrunsql"><td colspan="4">';
652 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
653 print
"<!-- (".$reshook.
") -->";
658 if (!empty($conf->modules_parts[
'hooks'])) {
659 print
'<tr class="trforrunsql"><td colspan="4">';
660 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
670 print
'<table width="100%">';
671 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
672 print
'<td class="right">';
676 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
680 print
'<script type="text/javascript">
681 jQuery(document).ready(function() {
682 function init_trrunsql()
684 console.log("toggle .trforrunsql");
685 jQuery(".trforrunsql").toggle();
688 jQuery(".trforrunsqlshowhide").click(function() {
693 print
'<a class="trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
696 print
'</td></tr>'.
"\n";
702 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
707 if ($error && isset($argv[1])) {
713 pFooter($error ? 2 : 0, $setuplang);
715 if ($db->connected) {
736 print
'<tr><td colspan="4">';
739 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
741 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
742 $obj = $db->fetch_object($result);
744 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
745 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
746 $sql .=
" WHERE p.fk_facture > 0";
748 $resql = $db->query($sql);
754 $num = $db->num_rows(
$resql);
757 $obj = $db->fetch_object(
$resql);
758 $row[$i][0] = $obj->rowid;
759 $row[$i][1] = $obj->fk_facture;
760 $row[$i][2] = $obj->amount;
768 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
772 for ($i = 0; $i < $num; $i++) {
773 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
774 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((
float) $row[$i][2]).
")";
776 $res += $db->query($sql);
778 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
780 $res += $db->query($sql);
782 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
786 if ($res == (2 * count($row))) {
788 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
791 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
794 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
797 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
815 print
'<tr><td colspan="4">';
818 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
820 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
821 $obj = $db->fetch_object($result);
824 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
825 $sql .=
" bu2.url_id as socid";
826 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
827 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
828 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
829 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
830 $sql .=
" AND b.rappro = 1";
831 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
833 $resql = $db->query($sql);
839 $num = $db->num_rows(
$resql);
842 $obj = $db->fetch_object(
$resql);
843 if ($obj->pamount == $obj->bamount && $obj->socid) {
844 $row[$j][
'paymentid'] = $obj->rowid;
845 $row[$j][
'pamount'] = $obj->pamount;
846 $row[$j][
'fk_bank'] = $obj->fk_bank;
847 $row[$j][
'bamount'] = $obj->bamount;
848 $row[$j][
'socid'] = $obj->socid;
849 $row[$j][
'datec'] = $obj->datec;
859 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
864 for ($i = 0; $i < $num; $i++) {
865 if ($conf->global->MAIN_FEATURES_LEVEL == 2) {
866 print
'* '.$row[$i][
'datec'].
' paymentid='.$row[$i][
'paymentid'].
' pamount='.$row[$i][
'pamount'].
' fk_bank='.$row[$i][
'fk_bank'].
' bamount='.$row[$i][
'bamount'].
' socid='.$row[$i][
'socid'].
'<br>';
870 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
871 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
872 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((
float) $row[$i][
'pamount']);
873 $sql .=
" AND pf.fk_facture IS NULL";
874 $sql .=
" ORDER BY f.fk_statut";
876 $resql = $db->query($sql);
878 $num = $db->num_rows(
$resql);
881 $obj = $db->fetch_object(
$resql);
882 $facid = $obj->rowid;
884 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
885 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((
float) $row[$i][
'pamount']).
")";
887 $res += $db->query($sql);
889 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
897 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
899 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
904 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
907 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
925 print
'<tr><td colspan="4">';
928 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
930 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
931 $obj = $db->fetch_object($result);
934 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
935 $sql .=
" bu2.url_id as socid";
936 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
937 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
938 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
939 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
940 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
942 $resql = $db->query($sql);
948 $num = $db->num_rows(
$resql);
951 $obj = $db->fetch_object(
$resql);
952 if ($obj->pamount == $obj->bamount && $obj->socid) {
953 $row[$j][
'paymentid'] = $obj->rowid;
954 $row[$j][
'pamount'] = $obj->pamount;
955 $row[$j][
'fk_bank'] = $obj->fk_bank;
956 $row[$j][
'bamount'] = $obj->bamount;
957 $row[$j][
'socid'] = $obj->socid;
958 $row[$j][
'datec'] = $obj->datec;
971 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
975 for ($i = 0; $i < $num; $i++) {
976 if ($conf->global->MAIN_FEATURES_LEVEL == 2) {
977 print
'* '.$row[$i][
'datec'].
' paymentid='.$row[$i][
'paymentid'].
' pamount='.$row[$i][
'pamount'].
' fk_bank='.$row[$i][
'fk_bank'].
' '.$row[$i][
'bamount'].
' socid='.$row[$i][
'socid'].
'<br>';
981 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
982 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
983 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((
float) $row[$i][
'pamount']);
984 $sql .=
" AND pf.fk_facture IS NULL";
985 $sql .=
" ORDER BY f.fk_statut";
987 $resql = $db->query($sql);
989 $num = $db->num_rows(
$resql);
992 $obj = $db->fetch_object(
$resql);
993 $facid = $obj->rowid;
995 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
996 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((
float) $row[$i][
'pamount']).
")";
998 $res += $db->query($sql);
1000 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1009 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1011 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1016 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1022 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1032 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1049 print
'<tr><td colspan="4">';
1054 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1056 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1057 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1058 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1059 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1060 $sql .=
" ON c.fk_product = p.rowid";
1061 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1062 $sql .=
" ON c.rowid=cd.fk_contrat";
1063 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1064 $resql = $db->query($sql);
1070 $num = $db->num_rows(
$resql);
1073 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1077 $obj = $db->fetch_object(
$resql);
1079 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1080 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1081 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1082 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1083 $sql .=
" VALUES (";
1084 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1086 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1087 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1090 $sql .= ((
float) $obj->tva_tx).
", 1, ";
1091 $sql .= ((
float) $obj->price).
", ".((
float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1095 if ($db->query($sql)) {
1096 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1108 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1111 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1114 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1117 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1134 print
'<tr><td colspan="4">';
1139 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1141 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1142 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1143 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1144 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1145 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1146 $sql .=
" AND bu.fk_bank IS NULL";
1147 $resql = $db->query($sql);
1153 $num = $db->num_rows(
$resql);
1156 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1160 $obj = $db->fetch_object(
$resql);
1162 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1163 $sql .=
"fk_bank, url_id, url, label, type";
1165 $sql .=
" VALUES (";
1166 $sql .= $obj->barowid.
",".$obj->bbrowid.
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1172 if (!$db->query($sql)) {
1183 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1186 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1189 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1208 print
'<tr><td colspan="4">';
1211 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1213 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1215 $resql = $db->query($sql);
1219 if ($db->affected_rows(
$resql) > 0) {
1220 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1222 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1225 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1227 $resql = $db->query($sql);
1231 if ($db->affected_rows(
$resql) > 0) {
1232 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1234 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1250 print
'<tr><td colspan="4">';
1255 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1257 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1259 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1260 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1261 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1262 $resql = $db->query($sql);
1268 $num = $db->num_rows(
$resql);
1271 $nbcontratsmodifie = 0;
1275 $obj = $db->fetch_object(
$resql);
1276 if ($obj->date_contrat > $obj->datemin) {
1277 $datemin = $db->jdate($obj->datemin);
1279 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1280 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1281 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1282 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1283 $resql2 = $db->query($sql);
1288 $nbcontratsmodifie++;
1295 if ($nbcontratsmodifie) {
1296 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1298 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1318 print
'<tr><td colspan="4">';
1321 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1323 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1325 $resql = $db->query($sql);
1329 if ($db->affected_rows(
$resql) > 0) {
1330 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1332 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1348 print
'<tr><td colspan="4">';
1351 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1353 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1354 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1356 $resql = $db->query($sql);
1360 if ($db->affected_rows(
$resql) > 0) {
1363 $num = $db->num_rows(
$resql);
1366 $nbcontratsmodifie = 0;
1370 $obj = $db->fetch_object(
$resql);
1372 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1373 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1374 $sql .=
" SET statut = 1";
1375 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1376 $resql2 = $db->query($sql);
1381 $nbcontratsmodifie++;
1388 if ($nbcontratsmodifie) {
1389 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1391 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1395 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1413 print
'<tr><td colspan="4">';
1415 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1418 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1419 $obj = $db->fetch_object($result);
1424 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1425 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1426 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1429 $select_resql = $db->query($select_sql);
1430 if ($select_resql) {
1431 $select_num = $db->num_rows($select_resql);
1435 while (($i < $select_num) && (!$error)) {
1436 $select_obj = $db->fetch_object($select_resql);
1439 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1440 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1441 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1442 $check_resql = $db->query($check_sql);
1444 $check_num = $db->num_rows($check_resql);
1445 if ($check_num == 0) {
1449 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1450 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1453 print
'<tr class="oddeven">';
1454 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1456 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1457 $insert_sql .=
' fk_paiementfourn = \''.$select_obj->rowid.
'\',
';
1458 $insert_sql .= ' fk_facturefourn = \
''.$select_obj->fk_facture_fourn.
'\',
';
1459 $insert_sql .= ' amount = \
''.$select_obj->amount.
'\'';
1460 $insert_resql = $db->query($insert_sql);
1462 if ($insert_resql) {
1464 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1466 print
'<td><span class="error">Error on insert</span></td>';
1482 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1486 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1489 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1493 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1510 $tmpmysoc->setMysoc($conf);
1514 print
'<tr><td colspan="4">';
1517 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1520 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1521 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1522 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1523 $sql .=
" WHERE fd.fk_facture = f.rowid";
1524 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1528 $resql = $db->query($sql);
1530 $num = $db->num_rows(
$resql);
1534 $obj = $db->fetch_object(
$resql);
1536 $rowid = $obj->rowid;
1538 $pu = $obj->subprice;
1539 $vatrate = $obj->vatrate;
1540 $remise_percent = $obj->remise_percent;
1541 $remise_percent_global = $obj->remise_percent_global;
1542 $total_ttc_f = $obj->total_ttc_f;
1543 $info_bits = $obj->info_bits;
1547 $facligne->fetch($rowid);
1549 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1550 $total_ht = $result[0];
1551 $total_tva = $result[1];
1552 $total_ttc = $result[2];
1554 $facligne->total_ht = $total_ht;
1555 $facligne->total_tva = $total_tva;
1556 $facligne->total_ttc = $total_ttc;
1558 dolibarr_install_syslog(
"upgrade2: line ".$rowid.
": facid=".$obj->facid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1560 $facligne->update_total();
1564 if (!$total_ttc_f) {
1566 $facture->id = $obj->facid;
1568 if ($facture->fetch($facture->id) >= 0) {
1569 if ($facture->update_price() > 0) {
1572 print
"Error id=".$facture->id;
1585 print $langs->trans(
"AlreadyDone");
1591 print
"Error #1 ".$db->error();
1613 $tmpmysoc->setMysoc($conf);
1617 print
'<tr><td colspan="4">';
1620 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1623 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1624 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1625 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1626 $sql .=
" WHERE pd.fk_propal = p.rowid";
1627 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1630 $resql = $db->query($sql);
1632 $num = $db->num_rows(
$resql);
1636 $obj = $db->fetch_object(
$resql);
1638 $rowid = $obj->rowid;
1640 $pu = $obj->subprice;
1641 $vatrate = $obj->vatrate;
1642 $remise_percent = $obj->remise_percent;
1643 $remise_percent_global = $obj->remise_percent_global;
1644 $info_bits = $obj->info_bits;
1648 $propalligne->fetch($rowid);
1650 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1651 $total_ht = $result[0];
1652 $total_tva = $result[1];
1653 $total_ttc = $result[2];
1655 $propalligne->total_ht = $total_ht;
1656 $propalligne->total_tva = $total_tva;
1657 $propalligne->total_ttc = $total_ttc;
1659 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
": propalid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1661 $propalligne->update_total();
1686 print $langs->trans(
"AlreadyDone");
1693 print
"Error #1 ".$db->error();
1716 $tmpmysoc->setMysoc($conf);
1717 if (empty($tmpmysoc->country_id)) {
1718 $tmpmysoc->country_id = 0;
1721 print
'<tr><td colspan="4">';
1724 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1727 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1728 $sql .=
" c.rowid as contratid";
1729 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1730 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1731 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1734 $resql = $db->query($sql);
1736 $num = $db->num_rows(
$resql);
1740 $obj = $db->fetch_object(
$resql);
1742 $rowid = $obj->rowid;
1744 $pu = $obj->subprice;
1745 $vatrate = $obj->vatrate;
1746 $remise_percent = $obj->remise_percent;
1747 $info_bits = $obj->info_bits;
1752 $contratligne->fetch($rowid);
1754 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1755 $total_ht = $result[0];
1756 $total_tva = $result[1];
1757 $total_ttc = $result[2];
1759 $contratligne->total_ht = $total_ht;
1760 $contratligne->total_tva = $total_tva;
1761 $contratligne->total_ttc = $total_ttc;
1763 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
": contratdetid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" -> ".$total_ht.
", ".$total_tva.
" , ".$total_ttc);
1765 $contratligne->update_total();
1770 print $langs->trans(
"AlreadyDone");
1777 print
"Error #1 ".$db->error();
1800 $tmpmysoc->setMysoc($conf);
1802 print
'<tr><td colspan="4">';
1805 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1808 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1809 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1810 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
1811 $sql .=
" WHERE cd.fk_commande = c.rowid";
1812 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1815 $resql = $db->query($sql);
1817 $num = $db->num_rows(
$resql);
1821 $obj = $db->fetch_object(
$resql);
1823 $rowid = $obj->rowid;
1825 $pu = $obj->subprice;
1826 $vatrate = $obj->vatrate;
1827 $remise_percent = $obj->remise_percent;
1828 $remise_percent_global = $obj->remise_percent_global;
1829 $info_bits = $obj->info_bits;
1833 $commandeligne->fetch($rowid);
1835 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1836 $total_ht = $result[0];
1837 $total_tva = $result[1];
1838 $total_ttc = $result[2];
1840 $commandeligne->total_ht = $total_ht;
1841 $commandeligne->total_tva = $total_tva;
1842 $commandeligne->total_ttc = $total_ttc;
1844 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
" : commandeid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1846 $commandeligne->update_total();
1870 print $langs->trans(
"AlreadyDone");
1887 print
"Error #1 ".$db->error();
1910 $tmpmysoc->setMysoc($conf);
1912 print
'<tr><td colspan="4">';
1915 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
1918 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1919 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1920 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
1921 $sql .=
" WHERE cd.fk_commande = c.rowid";
1922 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1925 $resql = $db->query($sql);
1927 $num = $db->num_rows(
$resql);
1931 $obj = $db->fetch_object(
$resql);
1933 $rowid = $obj->rowid;
1935 $pu = $obj->subprice;
1936 $vatrate = $obj->vatrate;
1937 $remise_percent = $obj->remise_percent;
1938 $remise_percent_global = $obj->remise_percent_global;
1939 $info_bits = $obj->info_bits;
1943 $commandeligne->fetch($rowid);
1945 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpsoc);
1946 $total_ht = $result[0];
1947 $total_tva = $result[1];
1948 $total_ttc = $result[2];
1950 $commandeligne->total_ht = $total_ht;
1951 $commandeligne->total_tva = $total_tva;
1952 $commandeligne->total_ttc = $total_ttc;
1954 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
": commandeid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1956 $commandeligne->update_total();
1980 print $langs->trans(
"AlreadyDone");
1997 print
"Error #1 ".$db->error();
2023 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
2025 if (count($modellist) == 0) {
2027 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
2028 $resql = $db->query($sql);
2036 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2038 if (count($modellist) == 0) {
2040 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2041 $resql = $db->query($sql);
2049 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2050 $modellist = ModelePDFExpedition::liste_modeles($db);
2051 if (count($modellist) == 0) {
2053 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2054 $resql = $db->query($sql);
2077 print
'<tr><td colspan="4">';
2080 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2082 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2083 $obj = $db->fetch_object($result);
2089 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2090 $resql = $db->query($sql);
2093 $num = $db->num_rows(
$resql);
2097 $obj = $db->fetch_object(
$resql);
2099 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2100 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2101 $resql2 = $db->query($sql);
2114 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2115 print $langs->trans(
'FieldRenamed').
"<br>\n";
2125 print $langs->trans(
'AlreadyDone').
"<br>\n";
2142 print
'<tr><td colspan="4">';
2145 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2147 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2148 $obj = $db->fetch_object($result);
2154 $sql =
"SELECT l.rowid, l.fk_commande,";
2155 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2157 $sql .=
" WHERE c.rowid = l.fk_commande";
2158 $resql = $db->query($sql);
2161 $num = $db->num_rows(
$resql);
2165 $obj = $db->fetch_object(
$resql);
2167 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2168 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2169 $resql2 = $db->query($sql);
2172 $delivery_date = $db->jdate($obj->delivery_date);
2174 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2175 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2176 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2177 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2178 $resql3 = $db->query($sqlu);
2194 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2195 print $langs->trans(
'FieldRenamed').
"<br>\n";
2205 print $langs->trans(
'AlreadyDone').
"<br>\n";
2222 print
'<tr><td colspan="4">';
2225 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2229 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2230 $obj = $db->fetch_object($result);
2236 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2237 $sql .=
", ld.fk_livraison";
2238 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2239 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2240 $resql = $db->query($sql);
2243 $num = $db->num_rows(
$resql);
2247 $obj = $db->fetch_object(
$resql);
2249 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2250 $sql .=
" fk_product = ".((int) $obj->fk_product);
2251 $sql .=
",description = '".$db->escape($obj->description).
"'";
2252 $sql .=
",subprice = ".price2num($obj->subprice);
2253 $sql .=
",total_ht = ".price2num($obj->total_ht);
2254 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2255 $resql2 = $db->query($sql);
2258 $sql =
"SELECT total_ht";
2259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2260 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2261 $resql3 = $db->query($sql);
2264 $obju = $db->fetch_object($resql3);
2265 $total_ht = $obju->total_ht + $obj->total_ht;
2267 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2268 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2269 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2270 $resql4 = $db->query($sqlu);
2290 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2291 print $langs->trans(
'FieldRenamed').
"<br>\n";
2301 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2302 $obj = $db->fetch_object($result);
2304 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2307 print $langs->trans(
'AlreadyDone').
"<br>\n";
2324 print
'<tr><td colspan="4">';
2327 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2333 $sql =
"SELECT SUM(reel) as total, fk_product";
2334 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2335 $sql .=
" GROUP BY fk_product";
2336 $resql = $db->query($sql);
2339 $num = $db->num_rows(
$resql);
2343 $obj = $db->fetch_object(
$resql);
2345 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2346 $sql .=
" stock = ".price2num($obj->total,
'MS');
2347 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2349 $resql2 = $db->query($sql);
2386 print
'<tr><td colspan="4">';
2389 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2393 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2396 $sql =
"SELECT m.rowid, mc.action";
2397 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2398 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2399 $sql .=
" AND m.enabled = '1'";
2400 $resql = $db->query($sql);
2403 $num = $db->num_rows(
$resql);
2406 $obj = $db->fetch_object(
$resql);
2408 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2409 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2410 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2411 $sql .=
" AND enabled = '1'";
2413 $resql2 = $db->query($sql);
2434 print $langs->trans(
'AlreadyDone').
"<br>\n";
2453 print
'<tr><td colspan="4">';
2456 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2460 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2463 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2464 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2465 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2466 $sql .=
" WHERE c.rowid = ce.fk_commande";
2467 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2469 $resql = $db->query($sql);
2472 $num = $db->num_rows(
$resql);
2476 $obj = $db->fetch_object(
$resql);
2478 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2479 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2480 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2482 $resql2 = $db->query($sql);
2491 print $langs->trans(
'AlreadyDone').
"<br>\n";
2504 print $langs->trans(
'AlreadyDone').
"<br>\n";
2523 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2525 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2529 print
'<tr><td colspan="4">';
2532 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2538 $table1 =
'facturedet'; $field1 =
'fk_remise_except';
2539 $table2 =
'societe_remise_except'; $field2 =
'fk_facture_line';
2543 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2544 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2545 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2546 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2547 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2550 $resql = $db->query($sql);
2553 $num = $db->num_rows(
$resql);
2557 $obj = $db->fetch_object(
$resql);
2559 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2560 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2561 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2562 $sql .=
" WHERE rowid = ".((int) $obj->field);
2564 $resql2 = $db->query($sql);
2573 print $langs->trans(
'AlreadyDone').
"<br>\n";
2589 print
'<tr><td colspan="4">';
2592 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2595 $table2 =
'facturedet'; $field2 =
'fk_remise_except';
2596 $table1 =
'societe_remise_except'; $field1 =
'fk_facture_line';
2600 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2601 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2602 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2603 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2604 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2607 $resql = $db->query($sql);
2610 $num = $db->num_rows(
$resql);
2614 $obj = $db->fetch_object(
$resql);
2616 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2617 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2618 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2619 $sql .=
" WHERE rowid = ".((int) $obj->field);
2621 $resql2 = $db->query($sql);
2630 print $langs->trans(
'AlreadyDone').
"<br>\n";
2658 print
'<tr><td colspan="4">';
2661 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2663 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2664 $obj = $db->fetch_object($result);
2670 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2671 $resql = $db->query($sql);
2674 $num = $db->num_rows(
$resql);
2678 $obj = $db->fetch_object(
$resql);
2680 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2681 $sql2 .=
"datecreate";
2682 $sql2 .=
", statut";
2683 $sql2 .=
", element_id";
2684 $sql2 .=
", fk_c_type_contact";
2685 $sql2 .=
", fk_socpeople";
2686 $sql2 .=
") VALUES (";
2687 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2689 $sql2 .=
", ".$obj->rowid;
2691 $sql2 .=
", ".$obj->fk_user_resp;
2694 if ($obj->fk_user_resp > 0) {
2695 $resql2 = $db->query($sql2);
2708 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2709 if ($db->query($sqlDrop)) {
2722 print $langs->trans(
'AlreadyDone').
"<br>\n";
2739 print
'<tr><td colspan="4">';
2742 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2744 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2749 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2750 $resql = $db->query($sql);
2753 $num = $db->num_rows(
$resql);
2757 $obj = $db->fetch_object(
$resql);
2759 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2760 $sql2 .=
"datecreate";
2761 $sql2 .=
", statut";
2762 $sql2 .=
", element_id";
2763 $sql2 .=
", fk_c_type_contact";
2764 $sql2 .=
", fk_socpeople";
2765 $sql2 .=
") VALUES (";
2766 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2768 $sql2 .=
", ".$obj->fk_project_task;
2770 $sql2 .=
", ".$obj->fk_user;
2773 $resql2 = $db->query($sql2);
2785 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2786 if ($db->query($sqlDrop)) {
2799 print $langs->trans(
'AlreadyDone').
"<br>\n";
2819 print
'<tr><td colspan="4">';
2822 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2826 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2831 $sqlSelect =
"SELECT ".$fk_source.
", ".$fk_target;
2832 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2834 $resql = $db->query($sqlSelect);
2837 $num = $db->num_rows(
$resql);
2841 $obj = $db->fetch_object(
$resql);
2843 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
2844 $sqlInsert .=
"fk_source";
2845 $sqlInsert .=
", sourcetype";
2846 $sqlInsert .=
", fk_target";
2847 $sqlInsert .=
", targettype";
2848 $sqlInsert .=
") VALUES (";
2849 $sqlInsert .= $obj->$fk_source;
2850 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
2851 $sqlInsert .=
", ".$obj->$fk_target;
2852 $sqlInsert .=
", '".$db->escape($targettype).
"'";
2855 $result = $db->query($sqlInsert);
2864 print $langs->trans(
'AlreadyDone').
"<br>\n";
2868 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$table;
2869 if ($db->query($sqlDrop)) {
2882 print $langs->trans(
'AlreadyDone').
"<br>\n";
2900 print
'<tr><td colspan="4">';
2903 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
2909 $sql =
"SELECT rowid, fk_task, task_duration";
2910 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time";
2911 $resql = $db->query($sql);
2914 $num = $db->num_rows(
$resql);
2917 $totaltime = array();
2921 $obj = $db->fetch_object(
$resql);
2923 if ($obj->task_duration > 0) {
2926 list($hour, $min) = explode(
'.', $obj->task_duration);
2927 $hour = $hour * 60 * 60;
2928 $min = ($min / 100) * 60 * 60;
2929 $newtime = $hour + $min;
2931 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time SET";
2932 $sql2 .=
" task_duration = ".((int) $newtime);
2933 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
2935 $resql2 = $db->query($sql2);
2942 if (!empty($totaltime[$obj->fk_task])) {
2943 $totaltime[$obj->fk_task] += $newtime;
2945 $totaltime[$obj->fk_task] = $newtime;
2948 if (!empty($totaltime[$obj->fk_task])) {
2949 $totaltime[$obj->fk_task] += $obj->task_duration;
2951 $totaltime[$obj->fk_task] = $obj->task_duration;
2960 foreach ($totaltime as $taskid => $total_duration) {
2961 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
2962 $sql .=
" duration_effective = ".((int) $total_duration);
2963 $sql .=
" WHERE rowid = ".((int) $taskid);
2965 $resql = $db->query($sql);
2972 print $langs->trans(
'AlreadyDone').
"<br>\n";
2978 print $langs->trans(
'AlreadyDone').
"<br>\n";
3003 print
'<tr><td colspan="4">';
3006 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
3010 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
3011 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
3012 $obj1 = $db->fetch_object($result1);
3013 $obj2 = $db->fetch_object($result2);
3014 if (!$obj1 && !$obj2) {
3019 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3020 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3022 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3023 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3024 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3025 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3026 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3027 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3028 $sqlSelect .=
" AND el.targettype = 'shipping'";
3030 $resql = $db->query($sqlSelect);
3033 $num = $db->num_rows(
$resql);
3037 $obj = $db->fetch_object(
$resql);
3039 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3040 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3041 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3042 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3044 $result = $db->query($sqlUpdate);
3053 print $langs->trans(
'AlreadyDone').
"<br>\n";
3071 print $langs->trans(
'AlreadyDone').
"<br>\n";
3087 print
'<tr><td colspan="4">';
3090 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3094 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3095 $obj = $db->fetch_object($result);
3101 $sqlSelect =
"SELECT rowid, fk_expedition";
3102 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3103 $sqlSelect .=
" WHERE fk_expedition is not null";
3105 $resql = $db->query($sqlSelect);
3108 $num = $db->num_rows(
$resql);
3112 $obj = $db->fetch_object(
$resql);
3114 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3115 $sqlInsert .=
"fk_source";
3116 $sqlInsert .=
", sourcetype";
3117 $sqlInsert .=
", fk_target";
3118 $sqlInsert .=
", targettype";
3119 $sqlInsert .=
") VALUES (";
3120 $sqlInsert .= $obj->fk_expedition;
3121 $sqlInsert .=
", 'shipping'";
3122 $sqlInsert .=
", ".$obj->rowid;
3123 $sqlInsert .=
", 'delivery'";
3126 $result = $db->query($sqlInsert);
3128 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3129 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3131 $result = $db->query($sqlUpdate);
3144 print $langs->trans(
'AlreadyDone').
"<br>\n";
3148 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3149 $db->query($sqlDelete);
3154 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3155 $db->query($sqlDrop);
3165 print $langs->trans(
'AlreadyDone').
"<br>\n";
3182 print
'<tr><td colspan="4">';
3185 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3193 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3194 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3195 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3196 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3197 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3198 $sqlSelect .=
" AND el.targettype = 'delivery'";
3199 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3200 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3202 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3203 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3205 $resql = $db->query($sqlSelect);
3208 $num = $db->num_rows(
$resql);
3212 $obj = $db->fetch_object(
$resql);
3214 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3215 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3216 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3217 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3219 $result = $db->query($sqlUpdate);
3228 print $langs->trans(
'AlreadyDone').
"<br>\n";
3255 print
'<tr><td colspan="4">';
3258 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3261 'propal' =>
'propalrowid',
3262 'order' =>
'fk_commande',
3263 'invoice' =>
'fk_facture',
3264 'contract' =>
'fk_contract',
3265 'order_supplier' =>
'fk_supplier_order',
3266 'invoice_supplier' =>
'fk_supplier_invoice'
3269 foreach ($elements as $type => $field) {
3270 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3271 $obj = $db->fetch_object($result);
3277 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3278 $sql .=
"fk_element = ".$field.
", elementtype = '".$db->escape($type).
"'";
3279 $sql .=
" WHERE ".$field.
" IS NOT NULL";
3280 $sql .=
" AND fk_element IS NULL";
3281 $sql .=
" AND elementtype IS NULL";
3283 $resql = $db->query($sql);
3297 print $langs->trans(
'AlreadyDone').
"<br>\n";
3314 print
'<tr><td colspan="4">';
3317 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3320 'old_id' => array(5, 8, 9, 10, 11),
3321 'new_id' => array(50, 51, 52, 53, 54),
3322 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3323 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3327 foreach ($elements[
'old_id'] as $key => $old_id) {
3332 $sqlSelect =
"SELECT id";
3333 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3334 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3335 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3337 $resql = $db->query($sqlSelect);
3339 $num = $db->num_rows(
$resql);
3345 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3346 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3347 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3348 $sqla .=
" AND fk_paiement IN (SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement WHERE id = ".((int) $old_id).
" AND code = '".$db->escape($elements[
'code'][$key]).
"')";
3349 $resqla = $db->query($sqla);
3351 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3352 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3353 $sql .=
" WHERE id = ".((int) $old_id);
3354 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3355 $resql = $db->query($sql);
3358 foreach ($elements[
'tables'] as $table) {
3359 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table.
" SET ";
3360 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3361 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3363 $resql = $db->query($sql);
3386 print $langs->trans(
'AlreadyDone').
"<br>\n";
3404 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3406 $obj = $db->fetch_object($result);
3410 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3411 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3413 $resql = $db->query($sql);
3415 $num = $db->num_rows(
$resql);
3416 while ($obj = $db->fetch_object(
$resql)) {
3417 if (!isset($filles[$obj->fk_categorie_fille])) {
3418 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3419 $filles[$obj->fk_categorie_fille] = 1;
3420 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere'=>$obj->fk_categorie_mere,
'fille'=>$obj->fk_categorie_fille);
3428 if (count($couples) > 0 && $num > count($couples)) {
3434 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3436 $resqld = $db->query($sql);
3439 foreach ($couples as $key => $val) {
3440 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3441 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3443 $resqli = $db->query($sql);
3451 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3452 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3455 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3456 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3461 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3462 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3479 print
'<tr><td colspan="4">';
3482 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3486 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3491 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3492 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3494 $resql = $db->query($sqlSelect);
3497 $num = $db->num_rows(
$resql);
3501 $obj = $db->fetch_object(
$resql);
3503 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3504 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3505 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3507 $result = $db->query($sqlUpdate);
3516 print $langs->trans(
'AlreadyDone').
"<br>\n";
3529 print $langs->trans(
'AlreadyDone').
"<br>\n";
3545 print
'<tr><td colspan="4">';
3548 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3556 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3557 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3558 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'user' AND ar.fk_element = a.fk_user_action";
3559 $sqlSelect .=
" WHERE fk_user_action > 0 AND fk_user_action NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX.
"actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'user')";
3560 $sqlSelect .=
" ORDER BY a.id";
3563 $resql = $db->query($sqlSelect);
3566 $num = $db->num_rows(
$resql);
3570 $obj = $db->fetch_object(
$resql);
3572 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3573 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3575 $result = $db->query($sqlUpdate);
3584 print $langs->trans(
'AlreadyDone').
"<br>\n";
3611 print
'<tr><td colspan="4">';
3614 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3622 $sqlSelect =
"SELECT a.id, a.fk_contact";
3623 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3624 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'socpeople' AND ar.fk_element = a.fk_contact";
3625 $sqlSelect .=
" WHERE fk_contact > 0 AND fk_contact NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX.
"actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'socpeople')";
3626 $sqlSelect .=
" ORDER BY a.id";
3629 $resql = $db->query($sqlSelect);
3632 $num = $db->num_rows(
$resql);
3636 $obj = $db->fetch_object(
$resql);
3638 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3639 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3641 $result = $db->query($sqlUpdate);
3650 print $langs->trans(
'AlreadyDone').
"<br>\n";
3680 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3682 print
'<tr><td colspan="4">';
3685 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3693 $sqlSelect =
"SELECT DISTINCT entity";
3694 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3698 $resql = $db->query($sqlSelect);
3701 $num = $db->num_rows(
$resql);
3705 $obj = $db->fetch_object(
$resql);
3707 print
'Process entity '.$obj->entity;
3709 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3710 $resqlSearch = $db->query($sqlSearch);
3712 $objSearch = $db->fetch_object($resqlSearch);
3714 if ($objSearch && $objSearch->nb == 0) {
3715 print
' - Record for entity must be reset...';
3717 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3718 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3719 $resqlUpdate = $db->query($sqlUpdate);
3720 if (!$resqlUpdate) {
3725 $object =
new stdClass();
3727 $object->element =
'module';
3728 $object->ref =
'systemevent';
3729 $object->entity = $obj->entity;
3733 $b->setObjectData($object,
'MODULE_SET', 0);
3735 $res = $b->create($user);
3741 print
' - '.$langs->trans(
'AlreadyInV7').
'<br>';
3750 print $langs->trans(
'NothingToDo').
"<br>\n";
3777 print
'<tr><td colspan="4">';
3780 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3788 $sqlSelect =
"SELECT sr.rowid, s.entity";
3789 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3790 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3794 $resql = $db->query($sqlSelect);
3797 $num = $db->num_rows(
$resql);
3801 $obj = $db->fetch_object(
$resql);
3803 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3804 $sqlUpdate .=
" entity = ".$obj->entity;
3805 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3807 $result = $db->query($sqlUpdate);
3817 print $langs->trans(
'AlreadyDone').
"<br>\n";
3843 print
'<tr><td colspan="4">';
3846 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
3854 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3855 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
3858 $resql = $db->query($sqlSelect);
3861 $num = $db->num_rows(
$resql);
3865 $obj = $db->fetch_object(
$resql);
3867 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3868 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3870 $sqlSelect2 =
"SELECT f.entity";
3871 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
3872 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
3873 } elseif (!empty($obj->fk_facture_line)) {
3874 $sqlSelect2 =
"SELECT f.entity";
3875 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
3876 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3877 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
3879 $sqlSelect2 =
"SELECT s.entity";
3880 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3881 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
3884 $resql2 = $db->query($sqlSelect2);
3886 if ($db->num_rows($resql2) > 0) {
3887 $obj2 = $db->fetch_object($resql2);
3889 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
3890 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
3891 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3893 $result = $db->query($sqlUpdate);
3908 print $langs->trans(
'AlreadyDone').
"<br>\n";
3935 print
'<tr><td colspan="4">';
3937 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
3945 $sqlSelect =
"SELECT u.rowid, u.entity";
3946 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3947 $sqlSelect .=
" WHERE u.entity > 1";
3950 $resql = $db->query($sqlSelect);
3953 $num = $db->num_rows(
$resql);
3957 $obj = $db->fetch_object(
$resql);
3959 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
3960 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3961 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
3963 $result = $db->query($sqlUpdate);
3973 print $langs->trans(
'AlreadyDone').
"<br>\n";
4000 print
'<tr><td colspan="4">';
4002 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
4010 $sqlSelect =
"SELECT u.rowid, u.entity";
4011 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
4012 $sqlSelect .=
" WHERE u.entity > 1";
4015 $resql = $db->query($sqlSelect);
4018 $num = $db->num_rows(
$resql);
4022 $obj = $db->fetch_object(
$resql);
4024 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4025 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4026 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4028 $result = $db->query($sqlUpdate);
4038 print $langs->trans(
'AlreadyDone').
"<br>\n";
4069 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4070 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4071 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4091 $filetodeletearray = array(
4092 '/core/triggers/interface_demo.class.php',
4093 '/core/menus/barre_left/default.php',
4094 '/core/menus/barre_top/default.php',
4095 '/core/modules/modComptabiliteExpert.class.php',
4096 '/core/modules/modCommercial.class.php',
4097 '/core/modules/modProduit.class.php',
4098 '/core/modules/modSkype.class.php',
4099 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4100 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4101 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4102 '/core/triggers/interface_modCommande_Ecotax.class.php',
4103 '/core/triggers/interface_modCommande_fraisport.class.php',
4104 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4105 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4106 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4107 '/core/menus/smartphone/iphone.lib.php',
4108 '/core/menus/smartphone/iphone_backoffice.php',
4109 '/core/menus/smartphone/iphone_frontoffice.php',
4110 '/core/menus/standard/auguria_backoffice.php',
4111 '/core/menus/standard/auguria_frontoffice.php',
4112 '/core/menus/standard/eldy_backoffice.php',
4113 '/core/menus/standard/eldy_frontoffice.php',
4114 '/core/modules/mailings/contacts2.modules.php',
4115 '/core/modules/mailings/contacts3.modules.php',
4116 '/core/modules/mailings/contacts4.modules.php',
4117 '/core/modules/mailings/framboise.modules.php',
4118 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4119 '/core/modules/mailings/peche.modules.php',
4120 '/core/modules/mailings/poire.modules.php',
4121 '/core/modules/mailings/kiwi.modules.php',
4122 '/core/modules/facture/pdf_crabe.modules.php',
4123 '/core/modules/facture/pdf_oursin.modules.php',
4124 '/core/modules/export/export_excel.modules.php',
4125 '/core/modules/export/export_excel2007new.modules.php',
4126 '/core/boxes/box_members.php',
4128 '/api/class/api_generic.class.php',
4129 '/asterisk/cidlookup.php',
4130 '/categories/class/api_category.class.php',
4131 '/categories/class/api_deprecated_category.class.php',
4132 '/compta/facture/class/api_invoice.class.php',
4133 '/commande/class/api_commande.class.php',
4134 '/user/class/api_user.class.php',
4135 '/product/class/api_product.class.php',
4136 '/societe/class/api_contact.class.php',
4137 '/societe/class/api_thirdparty.class.php',
4138 '/support/online.php',
4139 '/takepos/class/actions_takepos.class.php',
4141 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4142 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4143 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4144 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4145 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4146 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4149 foreach ($filetodeletearray as $filetodelete) {
4152 if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4153 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0,
null,
true,
false);
4155 $langs->load(
"errors");
4156 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4157 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4181 $filetodeletearray = array(
4182 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4183 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4187 if (!empty($_SERVER[
"WINDIR"])) {
4188 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4191 foreach ($filetodeletearray as $filetodelete) {
4193 if (file_exists($filetodelete)) {
4197 $langs->load(
"errors");
4198 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4199 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4222 if (count($listofmodule) == 0) {
4226 if (!is_object($user)) {
4227 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4228 $user =
new User($db);
4231 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".join(
',', array_keys($listofmodule)));
4233 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4234 if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
4240 if ($moduletoreload ==
'MAIN_MODULE_AGENDA') {
4242 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modAgenda.class.php';
4245 $mod->remove(
'noboxes');
4246 $mod->init($reloadmode);
4248 } elseif ($moduletoreload ==
'MAIN_MODULE_API') {
4250 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modApi.class.php';
4254 $mod->init($reloadmode);
4256 } elseif ($moduletoreload ==
'MAIN_MODULE_BARCODE') {
4258 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modBarcode.class.php';
4261 $mod->remove(
'noboxes');
4262 $mod->init($reloadmode);
4264 } elseif ($moduletoreload ==
'MAIN_MODULE_BLOCKEDLOG') {
4266 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modBlockedLog.class.php';
4270 $mod->delete_menus();
4271 $mod->insert_menus();
4273 } elseif ($moduletoreload ==
'MAIN_MODULE_CRON') {
4275 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modCron.class.php';
4278 $mod->remove(
'noboxes');
4279 $mod->init($reloadmode);
4281 } elseif ($moduletoreload ==
'MAIN_MODULE_EXTERNALSITE') {
4283 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modExternalSite.class.php';
4286 $mod->remove(
'noboxes');
4287 $mod->init($reloadmode);
4289 } elseif ($moduletoreload ==
'MAIN_MODULE_SOCIETE') {
4291 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modSociete.class.php';
4294 $mod->remove(
'noboxes');
4295 $mod->init($reloadmode);
4297 } elseif ($moduletoreload ==
'MAIN_MODULE_PRODUIT') {
4299 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modProduct.class.php';
4303 $mod->init($reloadmode);
4305 } elseif ($moduletoreload ==
'MAIN_MODULE_SERVICE') {
4307 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modService.class.php';
4311 $mod->init($reloadmode);
4313 } elseif ($moduletoreload ==
'MAIN_MODULE_COMMANDE') {
4315 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modCommande.class.php';
4319 $mod->init($reloadmode);
4321 } elseif ($moduletoreload ==
'MAIN_MODULE_FACTURE') {
4323 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modFacture.class.php';
4327 $mod->init($reloadmode);
4329 } elseif ($moduletoreload ==
'MAIN_MODULE_FOURNISSEUR') {
4331 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modFournisseur.class.php';
4335 $mod->init($reloadmode);
4337 } elseif ($moduletoreload ==
'MAIN_MODULE_HOLIDAY') {
4339 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modHoliday.class.php';
4342 $mod->remove(
'noboxes');
4343 $mod->init($reloadmode);
4345 } elseif ($moduletoreload ==
'MAIN_MODULE_DEPLACEMENT') {
4347 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modDeplacement.class.php';
4351 $mod->init($reloadmode);
4353 } elseif ($moduletoreload ==
'MAIN_MODULE_EXPENSEREPORT') {
4355 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modExpenseReport.class.php';
4359 $mod->init($reloadmode);
4361 } elseif ($moduletoreload ==
'MAIN_MODULE_DON') {
4363 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modDon.class.php';
4367 $mod->init($reloadmode);
4369 } elseif ($moduletoreload ==
'MAIN_MODULE_ECM') {
4371 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modECM.class.php';
4374 $mod->remove(
'noboxes');
4375 $mod->init($reloadmode);
4377 } elseif ($moduletoreload ==
'MAIN_MODULE_KNOWLEDGEMANAGEMENT') {
4379 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modKnowledgeManagement.class.php';
4382 $mod->remove(
'noboxes');
4383 $mod->init($reloadmode);
4385 } elseif ($moduletoreload ==
'MAIN_MODULE_EVENTORGANIZATION') {
4387 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modEventOrganization.class.php';
4390 $mod->remove(
'noboxes');
4391 $mod->init($reloadmode);
4393 } elseif ($moduletoreload ==
'MAIN_MODULE_PAYBOX') {
4395 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modPaybox.class.php';
4397 $mod =
new modPaybox($db);
4398 $mod->remove(
'noboxes');
4399 $mod->init($reloadmode);
4401 } elseif ($moduletoreload ==
'MAIN_MODULE_SUPPLIERPROPOSAL') {
4403 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modSupplierProposal.class.php';
4406 $mod->remove(
'noboxes');
4407 $mod->init($reloadmode);
4409 } elseif ($moduletoreload ==
'MAIN_MODULE_OPENSURVEY') {
4411 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modOpenSurvey.class.php';
4414 $mod->remove(
'noboxes');
4415 $mod->init($reloadmode);
4417 } elseif ($moduletoreload ==
'MAIN_MODULE_PRODUCTBATCH') {
4419 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modProductBatch.class.php';
4422 $mod->remove(
'noboxes');
4423 $mod->init($reloadmode);
4425 } elseif ($moduletoreload ==
'MAIN_MODULE_TAKEPOS') {
4427 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modTakePos.class.php';
4430 $mod->remove(
'noboxes');
4431 $mod->init($reloadmode);
4435 $tmp = preg_match(
'/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4436 if (!empty($reg[1])) {
4437 if (strtoupper($moduletoreload) == $moduletoreload) {
4438 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4441 $moduletoreloadshort = $reg[1];
4444 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode);
4445 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4447 $classname =
'mod'.$moduletoreloadshort;
4448 $mod =
new $classname($db);
4451 $mod->delete_menus();
4452 $mod->init($reloadmode);
4454 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4456 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4458 $classname =
'mod'.$moduletoreloadshort;
4459 $mod =
new $classname($db);
4460 $mod->init($reloadmode);
4462 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4463 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4469 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4474 if (!empty($mod) && is_object($mod)) {
4475 print
'<tr class="trforrunsql"><td colspan="4">';
4476 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4477 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4478 print
"<!-- (".$reloadmode.
") -->";
4503 $listofmenuhandler = array();
4504 if ($conf->global->MAIN_MENU_STANDARD ==
'auguria_menu' || $conf->global->MAIN_MENU_SMARTPHONE ==
'auguria_menu'
4505 || $conf->global->MAIN_MENUFRONT_STANDARD ==
'auguria_menu' || $conf->global->MAIN_MENUFRONT_SMARTPHONE ==
'auguria_menu') {
4506 $listofmenuhandler[
'auguria'] = 1;
4509 foreach ($listofmenuhandler as $key => $val) {
4510 print
'<tr class="trforrunsql"><td colspan="4">';
4514 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4517 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4518 $file =
'init_menu_'.$key.
'.sql';
4519 if (file_exists($dir.$file)) {
4520 $result =
run_sql($dir.$file, 1,
'', 1, $key);
4536 global $conf, $db, $langs, $user;
4538 print
'<tr><td colspan="4">';
4540 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4542 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4543 $fuser =
new User($db);
4544 if (!is_object($user)) {
4548 $sql =
"SELECT rowid as uid from ".MAIN_DB_PREFIX.
"user";
4549 $resql = $db->query($sql);
4551 while ($obj = $db->fetch_object(
$resql)) {
4552 $fuser->fetch($obj->uid);
4554 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4556 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4558 $dir = $conf->user->multidir_output[$entity];
4563 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4564 $destin = $dir.
'/'.$fuser->id;
4572 $handle = opendir($origin_osencoded);
4573 if (is_resource($handle)) {
4574 while (($file = readdir($handle)) !==
false) {
4575 if ($file ==
'.' || $file ==
'..') {
4580 $thumbs = opendir($origin_osencoded.
'/'.$file);
4581 if (is_resource($thumbs)) {
4583 while (($thumb = readdir($thumbs)) !==
false) {
4585 if ($thumb ==
'.' || $thumb ==
'..') {
4591 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4601 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4622 global $conf, $db, $langs, $user;
4624 print
'<tr><td colspan="4">';
4626 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4628 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4629 $fuser =
new User($db);
4630 if (!is_object($user)) {
4634 $sql =
"SELECT rowid as uid from ".MAIN_DB_PREFIX.
"user";
4635 $resql = $db->query($sql);
4637 while ($obj = $db->fetch_object(
$resql)) {
4638 $fuser->fetch($obj->uid);
4640 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4642 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4644 $dir = DOL_DATA_ROOT.
'/users';
4649 $origin = $dir.
'/'.$fuser->id;
4650 $destin = $dir.
'/'.$fuser->id.
'/photos';
4658 $handle = opendir($origin_osencoded);
4659 if (is_resource($handle)) {
4660 while (($file = readdir($handle)) !==
false) {
4661 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4664 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4669 $thumbs = opendir($origin_osencoded.
'/'.$file);
4670 if (is_resource($thumbs)) {
4672 while (($thumb = readdir($thumbs)) !==
false) {
4674 if ($thumb ==
'.' || $thumb ==
'..') {
4680 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4689 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4726 print
'<tr><td colspan="4">';
4727 $sql =
'SELECT rowid, socialnetworks';
4728 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
4729 $sql .=
" skype IS NOT NULL OR skype <> ''";
4730 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4731 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4732 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4733 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4734 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4735 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4736 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4737 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4739 $resql = $db->query($sql);
4741 while ($obj = $db->fetch_object(
$resql)) {
4742 $arraysocialnetworks = array();
4743 if (!empty($obj->skype)) {
4744 $arraysocialnetworks[
'skype'] = $obj->skype;
4746 if (!empty($obj->twitter)) {
4747 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4749 if (!empty($obj->facebook)) {
4750 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4752 if (!empty($obj->linkedin)) {
4753 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4755 if (!empty($obj->instagram)) {
4756 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4758 if (!empty($obj->snapchat)) {
4759 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4761 if (!empty($obj->googleplus)) {
4762 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4764 if (!empty($obj->youtube)) {
4765 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4767 if (!empty($obj->whatsapp)) {
4768 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4770 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4771 $obj->socialnetworks =
'[]';
4773 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4774 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4775 $sqlupd .=
', skype=null';
4776 $sqlupd .=
', twitter=null';
4777 $sqlupd .=
', facebook=null';
4778 $sqlupd .=
', linkedin=null';
4779 $sqlupd .=
', instagram=null';
4780 $sqlupd .=
', snapchat=null';
4781 $sqlupd .=
', googleplus=null';
4782 $sqlupd .=
', youtube=null';
4783 $sqlupd .=
', whatsapp=null';
4784 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4786 $resqlupd = $db->query($sqlupd);
4801 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
4815 print
'<tr><td colspan="4">';
4818 print
'<tr><td colspan="4">';
4819 $sql =
'SELECT rowid, socialnetworks';
4820 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
4821 $sql .=
" skype IS NOT NULL OR skype <> ''";
4822 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4823 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4824 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4825 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4826 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4827 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4828 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4829 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4831 $resql = $db->query($sql);
4833 while ($obj = $db->fetch_object(
$resql)) {
4834 $arraysocialnetworks = array();
4835 if (!empty($obj->skype)) {
4836 $arraysocialnetworks[
'skype'] = $obj->skype;
4838 if (!empty($obj->twitter)) {
4839 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4841 if (!empty($obj->facebook)) {
4842 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4844 if (!empty($obj->linkedin)) {
4845 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4847 if (!empty($obj->instagram)) {
4848 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4850 if (!empty($obj->snapchat)) {
4851 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4853 if (!empty($obj->googleplus)) {
4854 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4856 if (!empty($obj->youtube)) {
4857 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4859 if (!empty($obj->whatsapp)) {
4860 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4862 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4863 $obj->socialnetworks =
'[]';
4865 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4866 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4867 $sqlupd .=
', skype=null';
4868 $sqlupd .=
', twitter=null';
4869 $sqlupd .=
', facebook=null';
4870 $sqlupd .=
', linkedin=null';
4871 $sqlupd .=
', instagram=null';
4872 $sqlupd .=
', snapchat=null';
4873 $sqlupd .=
', googleplus=null';
4874 $sqlupd .=
', youtube=null';
4875 $sqlupd .=
', whatsapp=null';
4876 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4878 $resqlupd = $db->query($sqlupd);
4893 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
4909 print
'<tr><td colspan="4">';
4910 $sql =
'SELECT rowid, socialnetworks';
4911 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
4912 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
4913 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
4914 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4915 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4916 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4917 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4918 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4919 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4920 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4921 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4923 $resql = $db->query($sql);
4925 while ($obj = $db->fetch_object(
$resql)) {
4926 $arraysocialnetworks = array();
4927 if (!empty($obj->jabberid)) {
4928 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
4930 if (!empty($obj->skype)) {
4931 $arraysocialnetworks[
'skype'] = $obj->skype;
4933 if (!empty($obj->twitter)) {
4934 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4936 if (!empty($obj->facebook)) {
4937 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4939 if (!empty($obj->linkedin)) {
4940 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4942 if (!empty($obj->instagram)) {
4943 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4945 if (!empty($obj->snapchat)) {
4946 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4948 if (!empty($obj->googleplus)) {
4949 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4951 if (!empty($obj->youtube)) {
4952 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4954 if (!empty($obj->whatsapp)) {
4955 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4957 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4958 $obj->socialnetworks =
'[]';
4960 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4961 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4962 $sqlupd .=
', jabberid=null';
4963 $sqlupd .=
', skype=null';
4964 $sqlupd .=
', twitter=null';
4965 $sqlupd .=
', facebook=null';
4966 $sqlupd .=
', linkedin=null';
4967 $sqlupd .=
', instagram=null';
4968 $sqlupd .=
', snapchat=null';
4969 $sqlupd .=
', googleplus=null';
4970 $sqlupd .=
', youtube=null';
4971 $sqlupd .=
', whatsapp=null';
4972 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4974 $resqlupd = $db->query($sqlupd);
4989 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
5005 print
'<tr><td colspan="4">';
5006 $sql =
'SELECT rowid, socialnetworks';
5007 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
5008 $sql .=
" skype IS NOT NULL OR skype <> ''";
5009 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5010 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5011 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5012 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5013 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5014 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5015 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5016 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5018 $resql = $db->query($sql);
5020 while ($obj = $db->fetch_object(
$resql)) {
5021 $arraysocialnetworks = array();
5022 if (!empty($obj->skype)) {
5023 $arraysocialnetworks[
'skype'] = $obj->skype;
5025 if (!empty($obj->twitter)) {
5026 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5028 if (!empty($obj->facebook)) {
5029 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5031 if (!empty($obj->linkedin)) {
5032 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5034 if (!empty($obj->instagram)) {
5035 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5037 if (!empty($obj->snapchat)) {
5038 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5040 if (!empty($obj->googleplus)) {
5041 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5043 if (!empty($obj->youtube)) {
5044 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5046 if (!empty($obj->whatsapp)) {
5047 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5049 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5050 $obj->socialnetworks =
'[]';
5052 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5053 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
5054 $sqlupd .=
', skype=null';
5055 $sqlupd .=
', twitter=null';
5056 $sqlupd .=
', facebook=null';
5057 $sqlupd .=
', linkedin=null';
5058 $sqlupd .=
', instagram=null';
5059 $sqlupd .=
', snapchat=null';
5060 $sqlupd .=
', googleplus=null';
5061 $sqlupd .=
', youtube=null';
5062 $sqlupd .=
', whatsapp=null';
5063 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5065 $resqlupd = $db->query($sqlupd);
5080 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
5100 print
'<tr class="trforrunsql"><td colspan="4">';
5101 $sql =
'SELECT rowid, field';
5102 if ($mode ==
'export') {
5105 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
5106 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5108 $resql = $db->query($sql);
5110 while ($obj = $db->fetch_object(
$resql)) {
5111 $oldfield = $obj->field;
5112 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
5114 if ($mode ==
'export') {
5115 $oldfilter = $obj->filter;
5116 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
5122 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5123 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
5124 if ($mode ==
'export') {
5125 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
5127 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5128 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
5129 $resqlupd = $db->query($sqlupd);
5145 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5148 if ($resultstring) {
5149 print $resultstring;
5151 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5169 print
'<tr class="trforrunsql"><td colspan="4">';
5170 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5172 $sql =
"SELECT c.rowid as cid ,cd.rowid as cdid,cd.rang FROM ".$db->prefix().
"contratdet as cd INNER JOIN ".$db->prefix().
"contrat as c ON c.rowid=cd.fk_contrat AND cd.rang=0";
5173 $sql .=
" ORDER BY c.rowid,cd.rowid";
5175 $resql = $db->query($sql);
5178 $current_contract=0;
5179 while ($obj = $db->fetch_object(
$resql)) {
5180 if (empty($current_contract) || $current_contract==$obj->cid) {
5186 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5187 $resultstring =
'.';
5188 print $resultstring;
5189 $resqlUpd = $db->query($sqlUpd);
5195 $current_contract = $obj->cid;
5208 if (!$resultstring) {
5209 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
run_sql($sqlfile, $silent=1, $entity='', $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0)
Launch a sql file.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Class to manage Blocked Log.
Class to manage line orders.
Class to manage lines of contracts.
Class to manage invoices.
Class to manage invoice lines.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage order lines.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Class to describe and enable/disable module Agenda.
Description and activation class for module Api.
Class to describe Barcode.
Class to describe a BlockedLog module.
Class to describe module Sales Orders.
Class to describe a Cron module.
Class to describe and enable module Deplacement.
Class to describe and enable module Donation.
Description and activation class for module ECM.
Description and activation class for module EventOrganization This module is base on this specificati...
Description and activation class for module ExpenseReport.
Description and activation class for module ExternalSite.
Class to describe module customer invoices.
Description and activation class for module Fournisseur.
Description and activation class for module holiday.
Description and activation class for module KnowledgeManagement.
Description and activation class for module opensurvey.
Description and activation class for module productdluo.
Class descriptor of Product module.
Class to describe and enable module Service.
Class to describe and enable module Societe.
Class to describe and enable module SupplierProposal.
Class to describe and enable module TakePos.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_file($pathoffile)
Return if path is a file.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null)
Copy a dir to another dir.
dol_is_dir($folder)
Test if filename is a directory.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
div float
Buy price without taxes.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
migrate_links_transfert($db, $langs, $conf)
Function to migrate links into llx_bank_url.
migrate_paiements_orphelins_1($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_user_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_user_rights.
migrate_reload_modules($db, $langs, $conf, $listofmodule=array(), $force=0)
Disable/Reenable features modules.
migrate_project_task_time($db, $langs, $conf)
Migrate duration in seconds.
migrate_contracts_date3($db, $langs, $conf)
Mise a jour des dates de creation de contrat.
migrate_restore_missing_links($db, $langs, $conf)
Migration du champ fk_remise_except dans llx_facturedet doit correspondre a lien dans llx_societe_rem...
migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
Migration directory.
migrate_project_task_actors($db, $langs, $conf)
Migration de la table llx_projet_task_actors vers llx_element_contact.
migrate_commande_deliveryaddress($db, $langs, $conf)
Migration du champ fk_adresse_livraison dans expedition 2.6 -> 2.7.
migrate_project_user_resp($db, $langs, $conf)
Migration du champ fk_user_resp de llx_projet vers llx_element_contact.
migrate_contracts_open($db, $langs, $conf)
Reouverture des contrats qui ont au moins une ligne non fermee.
migrate_shipping_delivery($db, $langs, $conf)
Migrate link stored into fk_expedition into llx_element_element.
migrate_delete_old_dir($db, $langs, $conf)
Remove deprecated directories.
if($db->connected) if($ret) migrate_paiements($db, $langs, $conf)
Reporte liens vers une facture de paiements sur table de jointure (lien n-n paiements factures)
migrate_price_propal($db, $langs, $conf)
Update total of proposal lines.
migrate_stocks($db, $langs, $conf)
Migration du champ stock dans produits.
migrate_paiementfourn_facturefourn($db, $langs, $conf)
Factures fournisseurs.
migrate_contacts_socialnetworks()
Migrate contacts fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_customerorder_shipping($db, $langs, $conf)
Migrate order ref_customer and date_delivery fields to llx_expedition.
migrate_detail_livraison($db, $langs, $conf)
Migration des details commandes dans les details livraisons.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_price_contrat($db, $langs, $conf)
Update total of contract lines.
migrate_users_socialnetworks()
Migrate users fields facebook and co to socialnetworks.
migrate_user_photospath2()
Migrate file from old path users/99/file.jpg into users/99/photos/file.jpg.
migrate_contracts_det($db, $langs, $conf)
Mise a jour des contrats (gestion du contrat + detail de contrat)
migrate_price_facture($db, $langs, $conf)
Update total of invoice lines.
migrate_usergroup_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_usergroup_rights.
migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
Migration des tables de relation.
migrate_modeles($db, $langs, $conf)
Mise a jour des modeles selectionnes.
migrate_reset_blocked_log($db, $langs, $conf)
Migrate to reset the blocked log for V7+ algorithm.
migrate_mode_reglement($db, $langs, $conf)
Migrate link stored into fk_mode_reglement.
migrate_export_import_profiles($mode='export')
Migrate export and import profiles to fix field name that was renamed.
migrate_contracts_date2($db, $langs, $conf)
Update contracts with date min real if service date is lower.
migrate_commande_expedition($db, $langs, $conf)
Correspondance des expeditions et des commandes clients dans la table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_user_photospath()
Migrate file from old path to new one for users.
migrate_thirdparties_socialnetworks()
Migrate thirdparties fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_event_assignement($db, $langs, $conf)
Migrate event assignement to owner.
migrate_clean_association($db, $langs, $conf)
Delete duplicates in table categorie_association.
migrate_commande_livraison($db, $langs, $conf)
Correspondance des livraisons et des commandes clients dans la table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignement to owner.
migrate_contracts_date1($db, $langs, $conf)
Mise a jour des date de contrats non renseignees.
migrate_remise_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise.
migrate_contractdet_rank()
Migrate Rank into contract line.
migrate_menus($db, $langs, $conf)
Migration of menus (use only 1 table instead of 3) 2.6 -> 2.7.
migrate_categorie_association($db, $langs, $conf)
Migrate categorie association.
migrate_delete_old_files($db, $langs, $conf)
Delete deprecated files.
migrate_price_commande_fournisseur($db, $langs, $conf)
Update total of purchase order lines.
migrate_members_socialnetworks()
Migrate members fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_reload_menu($db, $langs, $conf)
Reload SQL menu file (if dynamic menus, if modified by version)
migrate_price_commande($db, $langs, $conf)
Update total of sales order lines.
migrate_shipping_delivery2($db, $langs, $conf)
We try to complete field ref_customer and date_delivery that are empty into llx_livraison.