/** * Mise a jour des totaux lignes de facture * * @param DoliDB $db Database handler * @param Translate $langs Object langs * @param Conf $conf Object conf * @return void */ function migrate_price_facture($db, $langs, $conf) { $err = 0; $db->begin(); print '<tr><td colspan="4">'; 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_tx as tva_taux, fd.total_ttc, fd.info_bits,"; $sql .= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "facture as f"; $sql .= " WHERE fd.fk_facture = f.rowid"; $sql .= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)"; //print $sql; dolibarr_install_syslog("upgrade2::migrate_price_facture", 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; $total_ttc_f = $obj->total_ttc_f; $info_bits = $obj->info_bits; // On met a jour les 3 nouveaux champs $facligne = new FactureLigne($db); $facligne->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]; $facligne->total_ht = $total_ht; $facligne->total_tva = $total_tva; $facligne->total_ttc = $total_ttc; dolibarr_install_syslog("upgrade2: 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 ". "; $facligne->update_total(); /* On touche a facture mere uniquement si total_ttc = 0 */ if (!$total_ttc_f) { $facture = new Facture($db); $facture->id = $obj->facid; if ($facture->fetch($facture->id) >= 0) { if ($facture->update_price() > 0) { //print $facture->id; } else { print "Error id=" . $facture->id; $err++; } } else { print "Error #3"; $err++; } } print " "; $i++; } } else { print $langs->trans("AlreadyDone"); } $db->free($resql); $db->commit(); } else { print "Error #1 " . $db->error(); $err++; $db->rollback(); } print '<br>'; print '</td></tr>'; }