2005-10-28 22:26:33 +02:00
< ? php
/* Copyright ( C ) 2005 Marc Barilley / Oc<EFBFBD> bo < marc @ ocebo . com >
2006-06-04 01:25:56 +02:00
* Copyright ( C ) 2005 - 2006 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-10-28 22:26:33 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
* $Id $
* $Source $
*/
/**
2006-06-17 03:53:32 +02:00
\file htdocs / install / upgrade2 . php
\brief Effectue la migration de donn<EFBFBD> es diverses
2005-10-28 22:26:33 +02:00
\version $Revision $
*/
include_once ( './inc.php' );
2006-06-17 03:53:32 +02:00
include_once ( '../facture.class.php' );
include_once ( '../propal.class.php' );
include_once ( '../commande/commande.class.php' );
2006-06-17 16:13:49 +02:00
include_once ( '../lib/price.lib.php' );
2005-10-28 22:26:33 +02:00
$grant_query = '' ;
$etape = 2 ;
$error = 0 ;
// Cette page peut etre longue. On augmente le d<> lai par d<> faut de 30 <20> 60.
// Ne fonctionne que si on est pas en safe_mode.
$err = error_reporting ();
error_reporting ( 0 );
set_time_limit ( 60 );
error_reporting ( $err );
2006-01-04 17:22:38 +01:00
$setuplang = isset ( $_POST [ 'selectlang' ]) ? $_POST [ 'selectlang' ] : ( isset ( $_GET [ 'selectlang' ]) ? $_GET [ 'selectlang' ] : 'auto' );
2005-10-30 02:07:00 +01:00
$langs -> setDefaultLang ( $setuplang );
2005-10-28 22:26:33 +02:00
$langs -> load ( 'admin' );
$langs -> load ( 'install' );
$langs -> load ( " bills " );
$langs -> load ( " suppliers " );
2006-06-17 16:13:49 +02:00
dolibarr_install_syslog ( " Entering upgrade2.php page " );
2005-10-28 22:26:33 +02:00
pHeader ( $langs -> trans ( 'DataMigration' ), 'etape5' , 'upgrade' );
if ( file_exists ( $conffile ))
{
include_once ( $conffile );
if ( ! isset ( $dolibarr_main_db_prefix ) || ! $dolibarr_main_db_prefix ) $dolibarr_main_db_prefix = 'llx_' ;
define ( 'MAIN_DB_PREFIX' , $dolibarr_main_db_prefix );
}
if ( $dolibarr_main_db_type == 'mysql' )
{
require_once ( $dolibarr_main_document_root . '/lib/mysql.lib.php' );
$choix = 1 ;
}
else
{
require_once ( $dolibarr_main_document_root . '/lib/pgsql.lib.php' );
require_once ( $dolibarr_main_document_root . '/lib/grant.postgres.php' );
$choix = 2 ;
}
require_once ( $dolibarr_main_document_root . '/conf/conf.class.php' );
if ( isset ( $_POST [ 'action' ]) && $_POST [ 'action' ] == 'upgrade' )
{
print '<h2>' . $langs -> trans ( 'DataMigration' ) . '</h2>' ;
print '<table cellspacing="0" cellpadding="1" border="0" width="100%">' ;
$conf = new Conf (); // on pourrait s'en passer
$conf -> db -> type = $dolibarr_main_db_type ;
$conf -> db -> host = $dolibarr_main_db_host ;
$conf -> db -> name = $dolibarr_main_db_name ;
$conf -> db -> user = $dolibarr_main_db_user ;
$conf -> db -> pass = $dolibarr_main_db_pass ;
$db = new DoliDb ( $conf -> db -> type , $conf -> db -> host , $conf -> db -> user , $conf -> db -> pass , $conf -> db -> name );
if ( $db -> connected != 1 )
{
2006-06-17 16:13:49 +02:00
print '<tr><td colspan="4">' . $langs -> trans ( " ErrorFailedToConnectToDatabase " , $dolibarr_main_db_name ) . '</td><td align="right">' . $langs -> trans ( 'Error' ) . '</td></tr>' ;
2005-10-28 22:26:33 +02:00
$error ++ ;
}
if ( ! $error )
{
if ( $db -> database_selected == 1 )
{
2006-06-17 16:13:49 +02:00
dolibarr_install_syslog ( 'Database connection successfull : ' . $dolibarr_main_db_name );
2005-10-28 22:26:33 +02:00
}
else
{
$error ++ ;
}
}
2006-06-03 01:20:36 +02:00
// Chargement config
define ( 'DOL_DOCUMENT_ROOT' , $dolibarr_main_document_root );
$conf -> setValues ( $db );
/*
* Pour utiliser d ' autres versions des librairies externes que les
* versions embarqu<EFBFBD> es dans Dolibarr , d<EFBFBD> finir les constantes adequates :
* Pour FPDF : FPDF_PATH
* Pour PEAR : PEAR_PATH
* Pour PHP_WriteExcel : PHP_WRITEEXCEL_PATH
* Pour PHPlot : PHPLOT_PATH
* Pour MagpieRss : MAGPIERSS_PATH
*/
if ( ! defined ( 'FPDF_PATH' )) { define ( 'FPDF_PATH' , DOL_DOCUMENT_ROOT . '/includes/fpdf/fpdf/' ); }
if ( ! defined ( 'PEAR_PATH' )) { define ( 'PEAR_PATH' , DOL_DOCUMENT_ROOT . '/includes/pear/' ); }
if ( ! defined ( 'PHP_WRITEEXCEL_PATH' )) { define ( 'PHP_WRITEEXCEL_PATH' , DOL_DOCUMENT_ROOT . '/includes/php_writeexcel/' ); }
if ( ! defined ( 'PHPLOT_PATH' )) { define ( 'PHPLOT_PATH' , DOL_DOCUMENT_ROOT . '/includes/phplot/' ); }
if ( ! defined ( 'MAGPIERSS_PATH' )) { define ( 'MAGPIERSS_PATH' , DOL_DOCUMENT_ROOT . '/includes/magpierss/' ); }
if ( ! defined ( 'JPGRAPH_PATH' )) { define ( 'JPGRAPH_PATH' , DOL_DOCUMENT_ROOT . '/includes/jpgraph/' ); }
define ( 'FPDF_FONTPATH' , FPDF_PATH . 'font/' );
define ( 'MAGPIE_DIR' , MAGPIERSS_PATH );
2005-10-28 22:26:33 +02:00
/***************************************************************************************
*
* Migration des donn<EFBFBD> es
*
***************************************************************************************/
if ( ! $error )
{
$db -> begin ();
print '<tr><td colspan="4" nowrap="nowrap"> </td></tr>' ;
2006-06-03 01:20:36 +02:00
2005-10-28 22:26:33 +02:00
// Chaque action de migration doit renvoyer une ligne sur 4 colonnes avec
// dans la 1ere colonne, la description de l'action a faire
// dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error'
migrate_paiements ( $db , $langs , $conf );
migrate_contracts_det ( $db , $langs , $conf );
migrate_contracts_date1 ( $db , $langs , $conf );
migrate_contracts_date2 ( $db , $langs , $conf );
migrate_contracts_date3 ( $db , $langs , $conf );
migrate_contracts_open ( $db , $langs , $conf );
migrate_paiementfourn_facturefourn ( $db , $langs , $conf );
2006-06-03 01:20:36 +02:00
migrate_modeles ( $db , $langs , $conf );
2006-06-23 00:00:23 +02:00
migrate_price_propal ( $db , $langs , $conf );
2006-06-17 03:53:32 +02:00
2006-06-23 00:00:23 +02:00
migrate_price_commande ( $db , $langs , $conf );
2006-06-17 03:53:32 +02:00
2006-06-23 00:00:23 +02:00
migrate_price_facture ( $db , $langs , $conf );
2006-06-03 01:20:36 +02:00
2005-10-28 22:26:33 +02:00
// On commit dans tous les cas.
2006-06-03 01:20:36 +02:00
// La proc<6F> dure etant con<6F> ue pour pouvoir passer plusieurs fois quelquesoit la situation.
2005-10-28 22:26:33 +02:00
$db -> commit ();
$db -> close ();
}
print '</table>' ;
}
else
{
print '<div class="error">' . $langs -> trans ( 'ErrorWrongParameters' ) . '</div>' ;
$error ++ ;
}
2005-10-30 02:07:00 +01:00
pFooter ( $error , $setuplang );
2005-10-28 22:26:33 +02:00
/**
* Mise a jour des paiements ( lien n - n paiements factures )
*/
function migrate_paiements ( $db , $langs , $conf )
{
print '<br>' ;
2006-05-14 20:32:45 +02:00
print '<b>' . $langs -> trans ( 'MigrationPaymentsUpdate' ) . " </b><br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " SELECT p.rowid, p.fk_facture, p.amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " paiement as p " ;
$sql .= " WHERE p.fk_facture > 0 " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$i = 0 ;
$row = array ();
$num = $db -> num_rows ( $resql );
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
$row [ $i ][ 0 ] = $obj -> rowid ;
$row [ $i ][ 1 ] = $obj -> fk_facture ;
$row [ $i ][ 2 ] = $obj -> amount ;
$i ++ ;
}
}
else {
dolibarr_print_error ( $db );
}
if ( $num )
{
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationPaymentsNumberToUpdate' , $num ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
if ( $db -> begin ())
{
$res = 0 ;
for ( $i = 0 ; $i < sizeof ( $row ) ; $i ++ )
{
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " paiement_facture (fk_facture, fk_paiement, amount) " ;
$sql .= " VALUES ( " . $row [ $i ][ 1 ] . " , " . $row [ $i ][ 0 ] . " , " . $row [ $i ][ 2 ] . " ) " ;
$res += $db -> query ( $sql );
$sql = " UPDATE " . MAIN_DB_PREFIX . " paiement SET fk_facture = 0 WHERE rowid = " . $row [ $i ][ 0 ];
$res += $db -> query ( $sql );
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationProcessPaymentUpdate' , $row [ $i ]) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
}
if ( $res == ( 2 * sizeof ( $row )))
{
$db -> commit ();
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationSuccessfullUpdate' ) . " <br> " ;
2005-10-28 22:26:33 +02:00
}
else
{
$db -> rollback ();
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationUpdateFailed' ) . '<br>' ;
2005-10-28 22:26:33 +02:00
}
}
else
{
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationPaymentsNothingToUpdate' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
}
/*
* Mise a jour des contrats ( gestion du contrat + detail de contrat )
*/
function migrate_contracts_det ( $db , $langs , $conf )
{
$nberr = 0 ;
print '<br>' ;
2006-05-14 20:32:45 +02:00
print '<b>' . $langs -> trans ( 'MigrationContractsUpdate' ) . " </b><br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " SELECT c.rowid as cref, c.date_contrat, c.statut, c.mise_en_service, c.fin_validite, c.date_cloture, c.fk_product, c.fk_facture, c.fk_user_author, " ;
$sql .= " p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " contrat as c " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p " ;
$sql .= " ON c.fk_product = p.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " contratdet as cd " ;
$sql .= " ON c.rowid=cd.fk_contrat " ;
$sql .= " WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$i = 0 ;
$row = array ();
$num = $db -> num_rows ( $resql );
if ( $num )
{
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationContractsNumberToUpdate' , $num ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
$db -> begin ();
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " contratdet ( " ;
$sql .= " fk_contrat, fk_product, statut, label, description, " ;
$sql .= " date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty, " ;
$sql .= " subprice, price_ht, fk_user_author, fk_user_ouverture) " ;
$sql .= " VALUES ( " ;
$sql .= $obj -> cref . " , " . ( $obj -> fk_product ? $obj -> fk_product : 0 ) . " , " ;
$sql .= ( $obj -> mise_en_service ? " 4 " : " 0 " ) . " , " ;
$sql .= " ' " . addslashes ( $obj -> label ) . " ', null, " ;
$sql .= ( $obj -> mise_en_service ? " ' " . $obj -> mise_en_service . " ' " : ( $obj -> date_contrat ? " ' " . $obj -> date_contrat . " ' " : " null " )) . " , " ;
$sql .= ( $obj -> mise_en_service ? " ' " . $obj -> mise_en_service . " ' " : " null " ) . " , " ;
$sql .= ( $obj -> fin_validite ? " ' " . $obj -> fin_validite . " ' " : " null " ) . " , " ;
$sql .= " ' " . $obj -> tva_tx . " ', 1, " ;
$sql .= " ' " . $obj -> price . " ', ' " . $obj -> price . " ', " . $obj -> fk_user_author . " , " ;
$sql .= ( $obj -> mise_en_service ? $obj -> fk_user_author : " null " );
$sql .= " ) " ;
if ( $db -> query ( $sql ))
{
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationContractsLineCreation' , $obj -> cref ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
else
{
dolibarr_print_error ( $db );
$nberr ++ ;
}
$i ++ ;
}
if ( ! $nberr )
{
// $db->rollback();
$db -> commit ();
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationSuccessfullUpdate' ) . " <br> " ;
2005-10-28 22:26:33 +02:00
}
else
{
$db -> rollback ();
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationUpdateFailed' ) . '<br>' ;
2005-10-28 22:26:33 +02:00
}
}
else {
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationContractsNothingToUpdate' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
}
else
{
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationContractsFieldDontExist' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
// dolibarr_print_error($db);
}
}
/*
* Mise a jour des date de contrats non renseign<EFBFBD> es
*/
function migrate_contracts_date1 ( $db , $langs , $conf )
{
print '<br>' ;
2006-05-14 20:32:45 +02:00
print '<b>' . $langs -> trans ( 'MigrationContractsEmptyDatesUpdate' ) . " </b><br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " update llx_contrat set date_contrat=tms where date_contrat is null " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) dolibarr_print_error ( $db );
2006-06-17 03:53:32 +02:00
if ( $db -> affected_rows ( $resql ) > 0 )
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationContractsEmptyDatesUpdateSuccess' ) . " <br> \n " ;
else
print $langs -> trans ( 'MigrationContractsEmptyDatesNothingToUpdate' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " update llx_contrat set datec=tms where datec is null " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) dolibarr_print_error ( $db );
2006-06-17 03:53:32 +02:00
if ( $db -> affected_rows ( $resql ) > 0 )
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationContractsEmptyCreationDatesUpdateSuccess' ) . " <br> \n " ;
else
print $langs -> trans ( 'MigrationContractsEmptyCreationDatesNothingToUpdate' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
/*
* Mise a jour date contrat avec date min effective mise en service si inf<EFBFBD> rieur
*/
function migrate_contracts_date2 ( $db , $langs , $conf )
{
$nberr = 0 ;
print '<br>' ;
2006-05-14 20:32:45 +02:00
print '<b>' . $langs -> trans ( 'MigrationContractsInvalidDatesUpdate' ) . " </b><br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " contrat as c, " ;
$sql .= " " . MAIN_DB_PREFIX . " contratdet as cd " ;
$sql .= " WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL " ;
$sql .= " GROUP BY c.rowid, c.date_contrat " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$i = 0 ;
$row = array ();
$num = $db -> num_rows ( $resql );
if ( $num )
{
$nbcontratsmodifie = 0 ;
$db -> begin ();
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj -> date_contrat > $obj -> datemin )
{
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationContractsInvalidDateFix' , $obj -> cref , $obj -> date_contrat , $obj -> datemin ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " contrat " ;
$sql .= " SET date_contrat=' " . $obj -> datemin . " ' " ;
$sql .= " WHERE rowid= " . $obj -> cref ;
$resql2 = $db -> query ( $sql );
if ( ! $resql2 ) dolibarr_print_error ( $db );
$nbcontratsmodifie ++ ;
}
$i ++ ;
}
$db -> commit ();
2006-05-14 20:32:45 +02:00
if ( $nbcontratsmodifie )
print $langs -> trans ( 'MigrationContractsInvalidDatesNumber' , $nbcontratsmodifie ) . " <br> \n " ;
else
print $langs -> trans ( 'MigrationContractsInvalidDatesNothingToUpdate' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
}
else
{
dolibarr_print_error ( $db );
}
}
/*
* Mise a jour des dates de cr<EFBFBD> ation de contrat
*/
function migrate_contracts_date3 ( $db , $langs , $conf )
{
print '<br>' ;
2006-05-14 20:32:45 +02:00
print '<b>' . $langs -> trans ( 'MigrationContractsIncoherentCreationDateUpdate' ) . " </b><br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " update llx_contrat set datec=date_contrat where datec is null or datec > date_contrat " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) dolibarr_print_error ( $db );
2006-05-14 20:32:45 +02:00
if ( $db -> affected_rows () > 0 )
print $langs -> trans ( 'MigrationContractsIncoherentCreationDateUpdateSuccess' ) . " <br> \n " ;
else
print $langs -> trans ( 'MigrationContractsIncoherentCreationDateNothingToUpdate' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
/*
* Reouverture des contrats qui ont au moins une ligne non ferm<EFBFBD> e
*/
function migrate_contracts_open ( $db , $langs , $conf )
{
print '<br>' ;
2006-05-14 20:32:45 +02:00
print '<b>' . $langs -> trans ( 'MigrationReopeningContracts' ) . " </b><br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " SELECT c.rowid as cref FROM llx_contrat as c, llx_contratdet as cd " ;
$sql .= " WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) dolibarr_print_error ( $db );
if ( $db -> affected_rows () > 0 ) {
$i = 0 ;
$row = array ();
$num = $db -> num_rows ( $resql );
if ( $num )
{
$nbcontratsmodifie = 0 ;
$db -> begin ();
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
2006-05-14 20:32:45 +02:00
print $langs -> trans ( 'MigrationReopenThisContract' , $obj -> cref ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " contrat " ;
$sql .= " SET statut=1 " ;
$sql .= " WHERE rowid= " . $obj -> cref ;
$resql2 = $db -> query ( $sql );
if ( ! $resql2 ) dolibarr_print_error ( $db );
$nbcontratsmodifie ++ ;
$i ++ ;
}
$db -> commit ();
2006-05-14 20:32:45 +02:00
if ( $nbcontratsmodifie )
print $langs -> trans ( 'MigrationReopenedContractsNumber' , $nbcontratsmodifie ) . " <br> \n " ;
else
print $langs -> trans ( 'MigrationReopeningContractsNothingToUpdate' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
}
2006-05-14 20:32:45 +02:00
else print $langs -> trans ( 'MigrationReopeningContractsNothingToUpdate' ) . " <br> \n " ;
2005-10-28 22:26:33 +02:00
}
/**
* Factures fournisseurs
*/
function migrate_paiementfourn_facturefourn ( $db , $langs , $conf )
{
2005-11-04 02:28:28 +01:00
global $bc ;
2005-10-28 22:26:33 +02:00
$error = 0 ;
$nb = 0 ;
$select_sql = 'SELECT rowid, fk_facture_fourn, amount ' ;
$select_sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiementfourn ' ;
$select_sql .= ' WHERE fk_facture_fourn IS NOT NULL ;' ;
$select_resql = $db -> query ( $select_sql );
if ( $select_resql )
{
$select_num = $db -> num_rows ( $select_resql );
$i = 0 ;
2005-11-04 02:28:28 +01:00
$var = true ;
2005-10-28 22:26:33 +02:00
// Pour chaque paiement fournisseur, on ins<6E> re une ligne dans paiementfourn_facturefourn
while ( $i < $select_num && ! $error )
{
$var = ! $var ;
$select_obj = $db -> fetch_object ( $select_resql );
// V<> rifier si la ligne est d<> j<EFBFBD> dans la nouvelle table. On ne veut pas ins<6E> rer de doublons.
$check_sql = 'SELECT fk_paiementfourn, fk_facturefourn' ;
$check_sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn' ;
$check_sql .= ' WHERE fk_paiementfourn = ' . $select_obj -> rowid . ' AND fk_facturefourn = ' . $select_obj -> fk_facture_fourn . ';' ;
$check_resql = $db -> query ( $check_sql );
if ( $check_resql )
{
$check_num = $db -> num_rows ( $check_resql );
if ( $check_num === 0 )
{
if ( $nb == 0 )
{
print '<tr><td colspan="4" nowrap="nowrap"><b>' . $langs -> trans ( 'SuppliersInvoices' ) . '</b></td></tr>' ;
print '<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>' . $langs -> trans ( 'Amount' ) . '</td><td> </td></tr>' ;
}
2005-11-04 02:25:40 +01:00
print '<tr ' . $bc [ $var ] . '>' ;
2005-10-28 22:26:33 +02:00
print '<td>' . $select_obj -> rowid . '</td><td>' . $select_obj -> fk_facture_fourn . '</td><td>' . $select_obj -> amount . '</td>' ;
$insert_sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn SET ' ;
$insert_sql .= ' fk_paiementfourn = \'' . $select_obj -> rowid . '\',' ;
$insert_sql .= ' fk_facturefourn = \'' . $select_obj -> fk_facture_fourn . '\',' ;
$insert_sql .= ' amount = \'' . $select_obj -> amount . '\';' ;
$insert_resql = $db -> query ( $insert_sql );
if ( $insert_resql )
{
$nb ++ ;
print '<td><span style="color:green">' . $langs -> trans ( " OK " ) . '</span></td>' ;
}
else
{
print '<td><span style="color:red">Error on insert</span></td>' ;
$error ++ ;
}
print '</tr>' ;
}
}
else
{
$error ++ ;
}
$i ++ ;
}
}
else
{
$error ++ ;
}
if ( ! $nb && ! $error )
{
2005-11-04 02:25:40 +01:00
print '<tr><td colspan="3" nowrap="nowrap"><b>' . $langs -> trans ( 'SuppliersInvoices' ) . '</b></td><td align="right">' . $langs -> trans ( " AlreadyDone " ) . '</td></tr>' ;
2005-10-28 22:26:33 +02:00
}
if ( $error )
{
print '<tr><td colspan="3" nowrap="nowrap"><b>' . $langs -> trans ( 'SuppliersInvoices' ) . '</b></td><td align="right">' . $langs -> trans ( " Error " ) . '</td></tr>' ;
}
}
2006-06-03 01:20:36 +02:00
2006-06-17 01:55:20 +02:00
/*
2006-06-17 16:13:49 +02:00
* Mise a jour des totaux lignes de facture
2006-06-17 01:55:20 +02:00
*/
function migrate_price_facture ( $db , $langs , $conf )
{
if ( $conf -> facture -> enabled )
{
2006-06-17 16:13:49 +02:00
$db -> begin ();
2006-06-17 03:53:32 +02:00
2006-06-17 16:13:49 +02:00
dolibarr_install_syslog ( " Upgrade data for invoice " );
2006-06-17 03:53:32 +02:00
2006-06-17 16:13:49 +02:00
print '<br>' ;
print '<b>' . $langs -> trans ( 'MigrationInvoice' ) . " </b><br> \n " ;
// Liste des lignes facture non a jour
$sql = " SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_taux, " ;
$sql .= " f.rowid as facid, f.remise_percent as remise_percent_global " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facturedet as fd, " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " WHERE fd.fk_facture = f.rowid " ;
2006-06-23 00:00:23 +02:00
$sql .= " AND ((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) " ;
2006-06-17 03:53:32 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2006-06-17 01:55:20 +02:00
{
2006-06-17 03:53:32 +02:00
$num = $db -> num_rows ( $resql );
2006-06-17 01:55:20 +02:00
$i = 0 ;
2006-06-17 16:13:49 +02:00
if ( $num )
2006-06-17 01:55:20 +02:00
{
2006-06-17 16:13:49 +02:00
while ( $i < $num )
2006-06-17 01:55:20 +02:00
{
2006-06-17 16:13:49 +02:00
$obj = $db -> fetch_object ( $resql );
$rowid = $obj -> rowid ;
$qty = $obj -> qty ;
$pu = $obj -> subprice ;
$txtva = $obj -> tva_taux ;
$remise_percent = $obj -> remise_percent ;
$remise_percent_global = $obj -> remise_percent_global ;
// On met a jour les 3 nouveaux champs
$facligne = new FactureLigne ( $db );
$facligne -> fetch ( $rowid );
$result = calcul_price_total ( $qty , $pu , $remise_percent , $txtva , $remise_percent_global );
$total_ht = $result [ 0 ];
$total_tva = $result [ 1 ];
$total_ttc = $result [ 2 ];
$facligne -> total_ht = $total_ht ;
$facligne -> total_tva = $total_tva ;
$facligne -> total_ttc = $total_ttc ;
dolibarr_install_syslog ( " Line $rowid : facid= $obj->facid pu= $pu qty= $qty tva_taux= $txtva remise_percent= $remise_percent remise_global= $remise_percent_global -> $total_ht , $total_tva , $total_ttc " );
print " . " ;
2006-06-23 00:00:23 +02:00
$facligne -> update_total ();
2006-06-17 16:13:49 +02:00
/* On touche pas a facture mere
$facture = new Facture ( $db );
$facture -> id = $obj -> facid ;
if ( $facture -> fetch ( $facture -> id ) >= 0 )
2006-06-17 01:55:20 +02:00
{
2006-06-17 16:13:49 +02:00
if ( $facture -> update_price ( $facture -> id ) > 0 )
{
print " . " ;
}
else
{
print " Error id= " . $facture -> id ;
$err ++ ;
}
2006-06-17 01:55:20 +02:00
}
else
{
2006-06-17 16:13:49 +02:00
print " Error #3 " ;
2006-06-17 01:55:20 +02:00
$err ++ ;
}
2006-06-17 16:13:49 +02:00
*/
$i ++ ;
2006-06-17 01:55:20 +02:00
}
2006-06-17 16:13:49 +02:00
}
else
{
print $langs -> trans ( " AlreadyDone " );
2006-06-17 01:55:20 +02:00
}
$db -> free ();
2006-06-17 16:13:49 +02:00
$db -> rollback ();
2006-06-17 01:55:20 +02:00
}
else
{
2006-06-17 16:13:49 +02:00
print " Error #1 " . $db -> error ();
2006-06-17 01:55:20 +02:00
$err ++ ;
2006-06-17 16:13:49 +02:00
$db -> rollback ();
2006-06-17 01:55:20 +02:00
}
2006-06-17 03:53:32 +02:00
print '<br>' ;
2006-06-17 16:13:49 +02:00
2006-06-17 01:55:20 +02:00
}
}
2006-06-17 03:53:32 +02:00
/*
2006-06-17 16:13:49 +02:00
* Mise a jour des totaux lignes de propal
2006-06-17 03:53:32 +02:00
*/
function migrate_price_propal ( $db , $langs , $conf )
{
if ( $conf -> propal -> enabled )
{
2006-06-17 16:13:49 +02:00
$db -> begin ();
dolibarr_install_syslog ( " Upgrade data for propal " );
2006-06-17 03:53:32 +02:00
print '<br>' ;
print '<b>' . $langs -> trans ( 'MigrationProposal' ) . " </b><br> \n " ;
2006-06-17 16:13:49 +02:00
// Liste des lignes propal non a jour
$sql = " SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as tva_taux, " ;
$sql .= " p.rowid as propalid, p.remise_percent as remise_percent_global " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " propaldet as pd, " . MAIN_DB_PREFIX . " propal as p " ;
$sql .= " WHERE pd.fk_propal = p.rowid " ;
2006-06-23 00:00:23 +02:00
$sql .= " AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL) " ;
2006-06-17 03:53:32 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
2006-06-17 16:13:49 +02:00
if ( $num )
2006-06-17 03:53:32 +02:00
{
2006-06-17 16:13:49 +02:00
while ( $i < $num )
2006-06-17 03:53:32 +02:00
{
2006-06-17 16:13:49 +02:00
$obj = $db -> fetch_object ( $resql );
$rowid = $obj -> rowid ;
$qty = $obj -> qty ;
$pu = $obj -> subprice ;
$txtva = $obj -> tva_taux ;
$remise_percent = $obj -> remise_percent ;
$remise_percent_global = $obj -> remise_percent_global ;
// On met a jour les 3 nouveaux champs
$propalligne = new PropaleLigne ( $db );
$propalligne -> fetch ( $rowid );
$result = calcul_price_total ( $qty , $pu , $remise_percent , $txtva , $remise_percent_global );
$total_ht = $result [ 0 ];
$total_tva = $result [ 1 ];
$total_ttc = $result [ 2 ];
$propalligne -> total_ht = $total_ht ;
$propalligne -> total_tva = $total_tva ;
$propalligne -> total_ttc = $total_ttc ;
dolibarr_install_syslog ( " Line $rowid : propalid= $obj->facid pu= $pu qty= $qty tva_taux= $txtva remise_percent= $remise_percent remise_global= $remise_percent_global -> $total_ht , $total_tva , $total_ttc " );
print " . " ;
2006-06-23 00:00:23 +02:00
$propalligne -> update_total ( $rowid );
2006-06-17 16:13:49 +02:00
/* On touche pas a propal mere
$propal = new Propal ( $db );
$propal -> id = $obj -> rowid ;
if ( $propal -> fetch ( $propal -> id ) >= 0 )
2006-06-17 03:53:32 +02:00
{
2006-06-17 16:13:49 +02:00
if ( $propal -> update_price ( $propal -> id ) > 0 )
{
print " . " ;
}
else
{
print " Error id= " . $propal -> id ;
$err ++ ;
}
2006-06-17 03:53:32 +02:00
}
else
{
2006-06-17 16:13:49 +02:00
print " Error #3 " ;
2006-06-17 03:53:32 +02:00
$err ++ ;
}
2006-06-17 16:13:49 +02:00
*/
$i ++ ;
2006-06-17 03:53:32 +02:00
}
}
2006-06-17 16:13:49 +02:00
else
{
print $langs -> trans ( " AlreadyDone " );
}
2006-06-17 03:53:32 +02:00
$db -> free ();
2006-06-17 16:13:49 +02:00
$db -> rollback ();
2006-06-17 03:53:32 +02:00
}
else
{
2006-06-17 16:13:49 +02:00
print " Error #1 " . $db -> error ();
2006-06-17 03:53:32 +02:00
$err ++ ;
2006-06-17 16:13:49 +02:00
$db -> rollback ();
2006-06-17 03:53:32 +02:00
}
print '<br>' ;
}
}
/*
2006-06-17 16:13:49 +02:00
* Mise a jour des totaux lignes de commande
2006-06-17 03:53:32 +02:00
*/
function migrate_price_commande ( $db , $langs , $conf )
{
if ( $conf -> facture -> enabled )
{
2006-06-17 16:13:49 +02:00
$db -> begin ();
2006-06-17 03:53:32 +02:00
2006-06-17 16:13:49 +02:00
dolibarr_install_syslog ( " Upgrade data for order " );
2006-06-17 03:53:32 +02:00
2006-06-17 16:13:49 +02:00
print '<br>' ;
print '<b>' . $langs -> trans ( 'MigrationOrder' ) . " </b><br> \n " ;
2006-06-17 03:53:32 +02:00
2006-06-17 16:13:49 +02:00
// Liste des lignes commande non a jour
$sql = " SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as tva_taux, " ;
$sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " commandedet as cd, " . MAIN_DB_PREFIX . " commande as c " ;
$sql .= " WHERE cd.fk_commande = c.rowid " ;
2006-06-23 00:00:23 +02:00
$sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL) " ;
2006-06-17 03:53:32 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
2006-06-17 16:13:49 +02:00
if ( $num )
2006-06-17 03:53:32 +02:00
{
2006-06-17 16:13:49 +02:00
while ( $i < $num )
2006-06-17 03:53:32 +02:00
{
2006-06-17 16:13:49 +02:00
$obj = $db -> fetch_object ( $resql );
$rowid = $obj -> rowid ;
$qty = $obj -> qty ;
$pu = $obj -> subprice ;
$txtva = $obj -> tva_taux ;
$remise_percent = $obj -> remise_percent ;
$remise_percent_global = $obj -> remise_percent_global ;
// On met a jour les 3 nouveaux champs
$commandeligne = new CommandeLigne ( $db );
$commandeligne -> fetch ( $rowid );
$result = calcul_price_total ( $qty , $pu , $remise_percent , $txtva , $remise_percent_global );
$total_ht = $result [ 0 ];
$total_tva = $result [ 1 ];
$total_ttc = $result [ 2 ];
$commandeligne -> total_ht = $total_ht ;
$commandeligne -> total_tva = $total_tva ;
$commandeligne -> total_ttc = $total_ttc ;
dolibarr_install_syslog ( " Line $rowid : commandeid= $obj->facid pu= $pu qty= $qty tva_taux= $txtva remise_percent= $remise_percent remise_global= $remise_percent_global -> $total_ht , $total_tva , $total_ttc " );
print " . " ;
2006-06-23 00:00:23 +02:00
$commandeligne -> update_total ( $rowid );
2006-06-17 16:13:49 +02:00
/* On touche pas a facture mere
$commande = new Commande ( $db );
$commande -> id = $obj -> rowid ;
if ( $commande -> fetch ( $commande -> id ) >= 0 )
2006-06-17 03:53:32 +02:00
{
2006-06-17 16:13:49 +02:00
if ( $commande -> update_price ( $commande -> id ) > 0 )
{
print " . " ;
}
else
{
print " Error id= " . $commande -> id ;
$err ++ ;
}
2006-06-17 03:53:32 +02:00
}
else
{
2006-06-17 16:13:49 +02:00
print " Error #3 " ;
2006-06-17 03:53:32 +02:00
$err ++ ;
}
2006-06-17 16:13:49 +02:00
*/
$i ++ ;
2006-06-17 03:53:32 +02:00
}
}
2006-06-17 16:13:49 +02:00
else
{
print $langs -> trans ( " AlreadyDone " );
}
2006-06-17 03:53:32 +02:00
$db -> free ();
2006-06-17 16:13:49 +02:00
2006-06-23 00:07:44 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " commandedet " ;
$sql .= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 " ;
$resql = $db -> query ( $sql );
if ( ! $resql )
{
dolibarr_print_error ( $db );
}
2006-06-17 16:13:49 +02:00
$db -> rollback ();
2006-06-17 03:53:32 +02:00
}
else
{
2006-06-17 16:13:49 +02:00
print " Error #1 " . $db -> error ();
2006-06-17 03:53:32 +02:00
$err ++ ;
2006-06-17 16:13:49 +02:00
$db -> rollback ();
2006-06-17 03:53:32 +02:00
}
print '<br>' ;
}
}
2006-06-03 01:20:36 +02:00
/*
* Mise a jour des modeles selectionnes
*/
function migrate_modeles ( $db , $langs , $conf )
{
//print '<br>';
//print '<b>'.$langs->trans('UpdateModelsTable')."</b><br>\n";
if ( $conf -> facture -> enabled )
{
include_once ( DOL_DOCUMENT_ROOT . '/includes/modules/facture/modules_facture.php' );
$model = new ModelePDFFactures ();
$modellist = $model -> liste_modeles ( $db );
if ( sizeof ( $modellist ) == 0 )
{
// Aucun model par defaut.
$sql = " insert into llx_document_model(nom,type) values('crabe','invoice') " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) dolibarr_print_error ( $db );
}
}
if ( $conf -> commande -> enabled )
{
include_once ( DOL_DOCUMENT_ROOT . '/includes/modules/commande/modules_commande.php' );
$model = new ModelePDFCommandes ();
$modellist = $model -> liste_modeles ( $db );
if ( sizeof ( $modellist ) == 0 )
{
// Aucun model par defaut.
$sql = " insert into llx_document_model(nom,type) values('einstein','order') " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) dolibarr_print_error ( $db );
}
}
2006-06-04 01:25:56 +02:00
if ( $conf -> expedition -> enabled )
{
include_once ( DOL_DOCUMENT_ROOT . '/expedition/mods/pdf/ModelePdfExpedition.class.php' );
$model = new ModelePDFExpedition ();
$modellist = $model -> liste_modeles ( $db );
if ( sizeof ( $modellist ) == 0 )
{
// Aucun model par defaut.
$sql = " insert into llx_document_model(nom,type) values('rouget','shipping') " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) dolibarr_print_error ( $db );
}
}
2006-06-03 01:20:36 +02:00
//print $langs->trans("AlreadyDone");
}
2006-05-14 20:32:45 +02:00
?>