Skip to content
Snippets Groups Projects
Commit 3087b6c0 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: errors in expedition module migration

parent 61ac0182
No related branches found
No related tags found
No related merge requests found
...@@ -1613,8 +1613,6 @@ function migrate_module_menus($db,$langs,$conf) ...@@ -1613,8 +1613,6 @@ function migrate_module_menus($db,$langs,$conf)
* Correspondance des expeditions et des commandes clients dans la table llx_co_exp * Correspondance des expeditions et des commandes clients dans la table llx_co_exp
*/ */
function migrate_commande_expedition($db,$langs,$conf) function migrate_commande_expedition($db,$langs,$conf)
{
if ($conf->expedition->enabled)
{ {
print '<tr><td colspan="4">'; print '<tr><td colspan="4">';
...@@ -1625,12 +1623,15 @@ function migrate_commande_expedition($db,$langs,$conf) ...@@ -1625,12 +1623,15 @@ function migrate_commande_expedition($db,$langs,$conf)
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
if ($obj) if ($obj)
{ {
$error = 0;
$db->begin();
$sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e"; $sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$i = 0; $i = 0;
$error = 0;
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
if ($num) if ($num)
...@@ -1653,10 +1654,13 @@ function migrate_commande_expedition($db,$langs,$conf) ...@@ -1653,10 +1654,13 @@ function migrate_commande_expedition($db,$langs,$conf)
print ". "; print ". ";
$i++; $i++;
} }
}
if ($error == 0) if ($error == 0)
{ {
$db->commit(); $db->commit();
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande"; $sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande";
print $langs->trans('FieldRenamed')."<br>\n";
$db->query($sql); $db->query($sql);
} }
else else
...@@ -1664,10 +1668,10 @@ function migrate_commande_expedition($db,$langs,$conf) ...@@ -1664,10 +1668,10 @@ function migrate_commande_expedition($db,$langs,$conf)
$db->rollback(); $db->rollback();
} }
} }
}
else else
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
$db->rollback();
} }
} }
else else
...@@ -1676,14 +1680,11 @@ function migrate_commande_expedition($db,$langs,$conf) ...@@ -1676,14 +1680,11 @@ function migrate_commande_expedition($db,$langs,$conf)
} }
print '</td></tr>'; print '</td></tr>';
} }
}
/* /*
* Correspondance des livraisons et des commandes clients dans la table llx_co_liv * Correspondance des livraisons et des commandes clients dans la table llx_co_liv
*/ */
function migrate_commande_livraison($db,$langs,$conf) function migrate_commande_livraison($db,$langs,$conf)
{
if ($conf->livraison_bon->enabled)
{ {
print '<tr><td colspan="4">'; print '<tr><td colspan="4">';
...@@ -1694,6 +1695,10 @@ function migrate_commande_livraison($db,$langs,$conf) ...@@ -1694,6 +1695,10 @@ function migrate_commande_livraison($db,$langs,$conf)
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
if ($obj) if ($obj)
{ {
$error = 0;
$db->begin();
$sql = "SELECT l.rowid, l.fk_commande"; $sql = "SELECT l.rowid, l.fk_commande";
$sql.= ", c.ref_client, c.date_livraison"; $sql.= ", c.ref_client, c.date_livraison";
$sql.= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c"; $sql.= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c";
...@@ -1702,13 +1707,10 @@ function migrate_commande_livraison($db,$langs,$conf) ...@@ -1702,13 +1707,10 @@ function migrate_commande_livraison($db,$langs,$conf)
if ($resql) if ($resql)
{ {
$i = 0; $i = 0;
$error = 0;
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
if ($num) if ($num)
{ {
$db->begin();
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
...@@ -1738,10 +1740,13 @@ function migrate_commande_livraison($db,$langs,$conf) ...@@ -1738,10 +1740,13 @@ function migrate_commande_livraison($db,$langs,$conf)
print ". "; print ". ";
$i++; $i++;
} }
}
if ($error == 0) if ($error == 0)
{ {
$db->commit(); $db->commit();
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande"; $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande";
print $langs->trans('FieldRenamed')."<br>\n";
$db->query($sql); $db->query($sql);
} }
else else
...@@ -1749,10 +1754,10 @@ function migrate_commande_livraison($db,$langs,$conf) ...@@ -1749,10 +1754,10 @@ function migrate_commande_livraison($db,$langs,$conf)
$db->rollback(); $db->rollback();
} }
} }
}
else else
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
$db->rollback();
} }
} }
else else
...@@ -1761,24 +1766,27 @@ function migrate_commande_livraison($db,$langs,$conf) ...@@ -1761,24 +1766,27 @@ function migrate_commande_livraison($db,$langs,$conf)
} }
print '</td></tr>'; print '</td></tr>';
} }
}
/* /*
* Migration des détails commandes dans les détails livraisons * Migration des détails commandes dans les détails livraisons
*/ */
function migrate_detail_livraison($db,$langs,$conf) function migrate_detail_livraison($db,$langs,$conf)
{
if ($conf->livraison->enabled)
{ {
print '<tr><td colspan="4">'; print '<tr><td colspan="4">';
print '<br>'; print '<br>';
print '<b>'.$langs->trans('MigrationDeliveryDetail')."</b><br>\n"; print '<b>'.$langs->trans('MigrationDeliveryDetail')."</b><br>\n";
// This is done if field fk_commande_ligne exists.
// If not this means migration was already done.
$result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet","fk_commande_ligne"); $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet","fk_commande_ligne");
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
if ($obj) if ($obj)
{ {
$error = 0;
$db->begin();
$sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht"; $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
$sql.= ", ld.fk_livraison"; $sql.= ", ld.fk_livraison";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
...@@ -1787,13 +1795,10 @@ function migrate_detail_livraison($db,$langs,$conf) ...@@ -1787,13 +1795,10 @@ function migrate_detail_livraison($db,$langs,$conf)
if ($resql) if ($resql)
{ {
$i = 0; $i = 0;
$error = 0;
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
if ($num) if ($num)
{ {
$db->begin();
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
...@@ -1843,10 +1848,13 @@ function migrate_detail_livraison($db,$langs,$conf) ...@@ -1843,10 +1848,13 @@ function migrate_detail_livraison($db,$langs,$conf)
$i++; $i++;
} }
}
if ($error == 0) if ($error == 0)
{ {
$db->commit(); $db->commit();
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer"; $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
print $langs->trans('FieldRenamed')."<br>\n";
$db->query($sql); $db->query($sql);
} }
else else
...@@ -1854,10 +1862,10 @@ function migrate_detail_livraison($db,$langs,$conf) ...@@ -1854,10 +1862,10 @@ function migrate_detail_livraison($db,$langs,$conf)
$db->rollback(); $db->rollback();
} }
} }
}
else else
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
$db->rollback();
} }
} }
else else
...@@ -1873,9 +1881,8 @@ function migrate_detail_livraison($db,$langs,$conf) ...@@ -1873,9 +1881,8 @@ function migrate_detail_livraison($db,$langs,$conf)
} }
print '</td></tr>'; print '</td></tr>';
} }
}
/* A faire egalement: Modif statut paye et fk_facture des factures payés completement /* A faire egalement: Modif statut paye et fk_facture des factures payes completement
On recherche facture incorrecte: On recherche facture incorrecte:
select f.rowid, f.total_ttc as t1, sum(pf.amount) as t2 from llx_facture as f, llx_paiement_facture as pf where pf.fk_facture=f.rowid and f.fk_statut in(2,3) and paye=0 and close_code is null group by f.rowid select f.rowid, f.total_ttc as t1, sum(pf.amount) as t2 from llx_facture as f, llx_paiement_facture as pf where pf.fk_facture=f.rowid and f.fk_statut in(2,3) and paye=0 and close_code is null group by f.rowid
......
...@@ -143,7 +143,10 @@ MigrationPaymentsNothingUpdatable=No more payments that can be corrected ...@@ -143,7 +143,10 @@ MigrationPaymentsNothingUpdatable=No more payments that can be corrected
# Contracts Update # Contracts Update
MigrationContractsUpdate=Contract data correction MigrationContractsUpdate=Contract data correction
MigrationContractsNumberToUpdate=%s contract(s) to update
MigrationContractsLineCreation=Create contract line for contract ref %s
MigrationContractsNothingToUpdate=No more things to do MigrationContractsNothingToUpdate=No more things to do
MigrationContractsFieldDontExist=Field fk_facture does not exists anymore. Nothing to do.
# Contracts Empty Dates Update # Contracts Empty Dates Update
MigrationContractsEmptyDatesUpdate=Contract empty date correction MigrationContractsEmptyDatesUpdate=Contract empty date correction
...@@ -172,4 +175,8 @@ MigrationReopeningContractsNothingToUpdate=No closed contract to open ...@@ -172,4 +175,8 @@ MigrationReopeningContractsNothingToUpdate=No closed contract to open
MigrationBankTransfertsUpdate=Update links between bank transaction and a bank transfert MigrationBankTransfertsUpdate=Update links between bank transaction and a bank transfert
MigrationBankTransfertsNothingToUpdate=All links are up to date MigrationBankTransfertsNothingToUpdate=All links are up to date
# Migration delivery
MigrationShipmentOrderMatching=Sendings receipt update
MigrationDeliveryOrderMatching=Delivery receipt update
MigrationDeliveryDetail=Delivery update
...@@ -177,5 +177,8 @@ MigrationReopeningContractsNothingToUpdate=Pas ou plus de contrats ...@@ -177,5 +177,8 @@ MigrationReopeningContractsNothingToUpdate=Pas ou plus de contrats
MigrationBankTransfertsUpdate=Mise a jour des liens entre ecriture bancaire et un transfert entre compte MigrationBankTransfertsUpdate=Mise a jour des liens entre ecriture bancaire et un transfert entre compte
MigrationBankTransfertsNothingToUpdate=Aucun lien non à jour MigrationBankTransfertsNothingToUpdate=Aucun lien non à jour
# Migration delivery
MigrationShipmentOrderMatching=Mise a jour bon expedition
MigrationDeliveryOrderMatching=Mise a jour bon reception
MigrationDeliveryDetail=Mise a jour bon reception
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment