/** * Mise a jour des totaux lignes de commande fournisseur * * @param DoliDB $db Database handler * @param Translate $langs Object langs * @param Conf $conf Object conf * @return void */ function migrate_price_commande_fournisseur($db, $langs, $conf) { $db->begin(); print '<tr><td colspan="4">'; print '<br>'; print '<b>' . $langs->trans('MigrationSupplierOrder') . "</b><br>\n"; // Liste des lignes commande non a jour $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as tva_taux, cd.info_bits,"; $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global"; $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet as cd, " . MAIN_DB_PREFIX . "commande_fournisseur as c"; $sql .= " WHERE cd.fk_commande = c.rowid"; $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)"; dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { while ($i < $num) { $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; $info_bits = $obj->info_bits; // On met a jour les 3 nouveaux champs $commandeligne = new CommandeFournisseurLigne($db); $commandeligne->fetch($rowid); $result = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, $remise_percent_global, 'HT', $info_bits, 0); $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("upgrade2: Line {$rowid}: commandeid={$obj->rowid} pu={$pu} qty={$qty} tva_taux={$txtva} remise_percent={$remise_percent} remise_global={$remise_percent_global} -> {$total_ht}, {$total_tva}, {$total_ttc}"); print ". "; $commandeligne->update_total(); /* On touche pas a facture mere $commande = new Commande($db); $commande->id = $obj->rowid; if ( $commande->fetch($commande->id) >= 0 ) { if ( $commande->update_price() > 0 ) { print ". "; } else { print "Error id=".$commande->id; } } else { print "Error #3"; } */ $i++; } } else { print $langs->trans("AlreadyDone"); } $db->free($resql); /* $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet"; $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0"; $resql=$db->query($sql); if (! $resql) { dol_print_error($db); } */ $db->commit(); } else { print "Error #1 " . $db->error(); $db->rollback(); } print '<br>'; print '</td></tr>'; }