2
0
forked from Wavyzz/dolibarr

Fixing style errors.

This commit is contained in:
stickler-ci
2020-01-14 14:34:36 +00:00
parent 43aa5ec658
commit ece3face5e
4 changed files with 373 additions and 338 deletions

View File

@@ -116,7 +116,7 @@ foreach ($header as $value) {
} }
$sqlCreate .= ", PRIMARY KEY (`id`)) ENGINE = InnoDB"; $sqlCreate .= ", PRIMARY KEY (`id`)) ENGINE = InnoDB";
$resql = $db->query($sqlCreate); $resql = $db->query($sqlCreate);
if ($resql !== FALSE) { if ($resql !== false) {
print "Table $table_name created\n"; print "Table $table_name created\n";
} else { } else {
var_dump($db->errno()); var_dump($db->errno());
@@ -136,7 +136,7 @@ for ($i = 1; $i <= $record_numbers; $i++) {
if ($endlinenb && $i > $endlinenb) if ($endlinenb && $i > $endlinenb)
continue; continue;
$row = dbase_get_record_with_names($fhandle, $i); $row = dbase_get_record_with_names($fhandle, $i);
if ($row === FALSE || (isset($row["deleted"]) && $row["deleted"] == '1')) if ($row === false || (isset($row["deleted"]) && $row["deleted"] == '1'))
continue; continue;
$sqlInsert = "INSERT INTO `$table_name`($fields) VALUES (null,"; $sqlInsert = "INSERT INTO `$table_name`($fields) VALUES (null,";
array_shift($row); // remove delete column array_shift($row); // remove delete column
@@ -152,8 +152,8 @@ for ($i = 1; $i <= $record_numbers; $i++) {
var_dump($row, $db->errno()); var_dump($row, $db->errno());
die(); die();
} }
// $fields = (object) $row; // $fields = (object) $row;
// var_dump($fields); // var_dump($fields);
continue; continue;
} }
die(); die();
@@ -179,7 +179,8 @@ fclose($fhandleerr);
exit($error); exit($error);
function replaceable_echo($message, $force_clear_lines = NULL) { function replaceable_echo($message, $force_clear_lines = null)
{
static $last_lines = 0; static $last_lines = 0;
if (!is_null($force_clear_lines)) { if (!is_null($force_clear_lines)) {

View File

@@ -89,145 +89,145 @@ if (!$ret > 0) {
$sql = "SELECT * FROM `$table` WHERE 1"; $sql = "SELECT * FROM `$table` WHERE 1";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
while ($fields = $db->fetch_array($resql)) { while ($fields = $db->fetch_array($resql)) {
$errorrecord = 0; $errorrecord = 0;
if ($fields === FALSE) if ($fields === false)
continue; continue;
$nboflines++; $nboflines++;
$produit = new Product($db); $produit = new Product($db);
$produit->type = 0; $produit->type = 0;
$produit->status = 1; $produit->status = 1;
$produit->ref = trim($fields['REF']); $produit->ref = trim($fields['REF']);
if ($produit->ref == '') if ($produit->ref == '')
continue; continue;
print "Process line nb " . $j . ", ref " . $produit->ref; print "Process line nb " . $j . ", ref " . $produit->ref;
$produit->label = trim($fields['LIBELLE']); $produit->label = trim($fields['LIBELLE']);
if ($produit->label == '') if ($produit->label == '')
$produit->label = $produit->ref; $produit->label = $produit->ref;
if (empty($produit->label)) if (empty($produit->label))
continue; continue;
//$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : '')); //$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : ''));
// $produit->volume = price2num($fields[8]); // $produit->volume = price2num($fields[8]);
// $produit->volume_unit = 0; // $produit->volume_unit = 0;
$produit->weight = price2num($fields['MASSE']); $produit->weight = price2num($fields['MASSE']);
$produit->weight_units = 0; // -3 = g $produit->weight_units = 0; // -3 = g
//$produit->customcode = $fields[10]; //$produit->customcode = $fields[10];
$produit->barcode = str_pad($fields['CODE'], 12, "0", STR_PAD_LEFT); $produit->barcode = str_pad($fields['CODE'], 12, "0", STR_PAD_LEFT);
$produit->barcode_type = '2'; $produit->barcode_type = '2';
$produit->import_key = $fields['CODE']; $produit->import_key = $fields['CODE'];
$produit->status = 1; $produit->status = 1;
$produit->status_buy = 1; $produit->status_buy = 1;
$produit->finished = 1; $produit->finished = 1;
// $produit->multiprices[0] = price2num($fields['TARIF0']); // $produit->multiprices[0] = price2num($fields['TARIF0']);
// $produit->multiprices[1] = price2num($fields['TARIF1']); // $produit->multiprices[1] = price2num($fields['TARIF1']);
// $produit->multiprices[2] = price2num($fields['TARIF2']); // $produit->multiprices[2] = price2num($fields['TARIF2']);
// $produit->multiprices[3] = price2num($fields['TARIF3']); // $produit->multiprices[3] = price2num($fields['TARIF3']);
// $produit->multiprices[4] = price2num($fields['TARIF4']); // $produit->multiprices[4] = price2num($fields['TARIF4']);
// $produit->multiprices[5] = price2num($fields['TARIF5']); // $produit->multiprices[5] = price2num($fields['TARIF5']);
// $produit->multiprices[6] = price2num($fields['TARIF6']); // $produit->multiprices[6] = price2num($fields['TARIF6']);
// $produit->multiprices[7] = price2num($fields['TARIF7']); // $produit->multiprices[7] = price2num($fields['TARIF7']);
// $produit->multiprices[8] = price2num($fields['TARIF8']); // $produit->multiprices[8] = price2num($fields['TARIF8']);
// $produit->multiprices[9] = price2num($fields['TARIF9']); // $produit->multiprices[9] = price2num($fields['TARIF9']);
// $produit->price_min = null; // $produit->price_min = null;
// $produit->price_min_ttc = null; // $produit->price_min_ttc = null;
// $produit->price = price2num($fields[11]); // $produit->price = price2num($fields[11]);
// $produit->price_ttc = price2num($fields[12]); // $produit->price_ttc = price2num($fields[12]);
// $produit->price_base_type = 'TTC'; // $produit->price_base_type = 'TTC';
// $produit->tva_tx = price2num($fields[13]); // $produit->tva_tx = price2num($fields[13]);
$produit->tva_tx = (int) ($tvas[$fields['CODTVA']]); $produit->tva_tx = (int) ($tvas[$fields['CODTVA']]);
$produit->tva_npr = 0; $produit->tva_npr = 0;
// $produit->cost_price = price2num($fields[16]); // $produit->cost_price = price2num($fields[16]);
//compta //compta
$produit->accountancy_code_buy = trim($fields['COMACH']); $produit->accountancy_code_buy = trim($fields['COMACH']);
$produit->accountancy_code_sell = trim($fields['COMVEN']); $produit->accountancy_code_sell = trim($fields['COMVEN']);
// $produit->accountancy_code_sell_intra=trim($fields['COMVEN']); // $produit->accountancy_code_sell_intra=trim($fields['COMVEN']);
// $produit->accountancy_code_sell_export=trim($fields['COMVEN']); // $produit->accountancy_code_sell_export=trim($fields['COMVEN']);
// Extrafields // Extrafields
// $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]); // $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]);
$produit->seuil_stock_alerte = $fields['STALERTE']; $produit->seuil_stock_alerte = $fields['STALERTE'];
$ret = $produit->create($user, 0); $ret = $produit->create($user, 0);
if ($ret < 0) { if ($ret < 0) {
print " - Error in create result code = " . $ret . " - " . $produit->errorsToString(); print " - Error in create result code = " . $ret . " - " . $produit->errorsToString();
$errorrecord++; $errorrecord++;
} else { } else {
print " - Creation OK with ref " . $produit->ref . " - id = " . $ret; print " - Creation OK with ref " . $produit->ref . " - id = " . $ret;
} }
dol_syslog("Add prices"); dol_syslog("Add prices");
// If we use price level, insert price for each level // If we use price level, insert price for each level
if (!$errorrecord && 1) { if (!$errorrecord && 1) {
//$ret1 = $produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array()); //$ret1 = $produit->updatePrice($produit->price_ttc, $produit->price_base_type, $user, $produit->tva_tx, $produit->price_min, 1, $produit->tva_npr, 0, 0, array());
$ret1 = false; $ret1 = false;
for ($i = 0; $i < 10; $i++) { for ($i = 0; $i < 10; $i++) {
if ($fields['TARIF' . ($i)] == 0) if ($fields['TARIF' . ($i)] == 0)
continue; continue;
$ret1 = $ret1 || $produit->updatePrice(price2num($fields['TARIF' . ($i)]), 'HT', $user, $produit->tva_tx, $produit->price_min, $i + 1, $produit->tva_npr, 0, 0, array()) < 0; $ret1 = $ret1 || $produit->updatePrice(price2num($fields['TARIF' . ($i)]), 'HT', $user, $produit->tva_tx, $produit->price_min, $i + 1, $produit->tva_npr, 0, 0, array()) < 0;
} }
if ($ret1) { if ($ret1) {
print " - Error in updatePrice result " . $produit->errorsToString(); print " - Error in updatePrice result " . $produit->errorsToString();
$errorrecord++; $errorrecord++;
} else { } else {
print " - updatePrice OK"; print " - updatePrice OK";
} }
} }
// dol_syslog("Add multilangs"); // dol_syslog("Add multilangs");
// Add alternative languages // Add alternative languages
// if (!$errorrecord && 1) { // if (!$errorrecord && 1) {
// $produit->multilangs['fr_FR'] = array('label' => $produit->label, 'description' => $produit->description, 'note' => $produit->note_private); // $produit->multilangs['fr_FR'] = array('label' => $produit->label, 'description' => $produit->description, 'note' => $produit->note_private);
// $produit->multilangs['en_US'] = array('label' => $fields[3], 'description' => $produit->description, 'note' => $produit->note_private); // $produit->multilangs['en_US'] = array('label' => $fields[3], 'description' => $produit->description, 'note' => $produit->note_private);
// //
// $ret = $produit->setMultiLangs($user); // $ret = $produit->setMultiLangs($user);
// if ($ret < 0) { // if ($ret < 0) {
// print " - Error in setMultiLangs result code = " . $ret . " - " . $produit->errorsToString(); // print " - Error in setMultiLangs result code = " . $ret . " - " . $produit->errorsToString();
// $errorrecord++; // $errorrecord++;
// } else { // } else {
// print " - setMultiLangs OK"; // print " - setMultiLangs OK";
// } // }
// } // }
dol_syslog("Add stocks"); dol_syslog("Add stocks");
// stocks // stocks
if (!$errorrecord && $fields['STOCK'] != 0) { if (!$errorrecord && $fields['STOCK'] != 0) {
$rets = $produit->correct_stock($user, 1, $fields['STOCK'], 0, 'Stock importé'); $rets = $produit->correct_stock($user, 1, $fields['STOCK'], 0, 'Stock importé');
if ($rets < 0) { if ($rets < 0) {
print " - Error in correct_stock result " . $produit->errorsToString(); print " - Error in correct_stock result " . $produit->errorsToString();
$errorrecord++; $errorrecord++;
} else { } else {
print " - correct_stock OK"; print " - correct_stock OK";
} }
} }
//update date créa //update date créa
if (!$errorrecord) { if (!$errorrecord) {
$date = substr($fields['DATCREA'], 0, 4) . '-' . substr($fields['DATCREA'], 4, 2) . '-' . substr($fields['DATCREA'], 6, 2); $date = substr($fields['DATCREA'], 0, 4) . '-' . substr($fields['DATCREA'], 4, 2) . '-' . substr($fields['DATCREA'], 6, 2);
$retd = $db->query("UPDATE `llx_product` SET `datec` = '$date 00:00:00' WHERE `llx_product`.`rowid` = $produit->id"); $retd = $db->query("UPDATE `llx_product` SET `datec` = '$date 00:00:00' WHERE `llx_product`.`rowid` = $produit->id");
if ($retd < 1) { if ($retd < 1) {
print " - Error in update date créa result " . $produit->errorsToString(); print " - Error in update date créa result " . $produit->errorsToString();
$errorrecord++; $errorrecord++;
} else { } else {
print " - update date créa OK"; print " - update date créa OK";
} }
} }
print "\n"; print "\n";
if ($errorrecord) { if ($errorrecord) {
print( 'Error on record nb ' . $i . " - " . $produit->errorsToString() . "\n"); print( 'Error on record nb ' . $i . " - " . $produit->errorsToString() . "\n");
var_dump($db); var_dump($db);
die(); die();
$error++; // $errorrecord will be reset $error++; // $errorrecord will be reset
} }
$j++; $j++;
} else } else
die("error : $sql"); die("error : $sql");

View File

@@ -145,202 +145,202 @@ $sql = "SELECT * FROM `$table` WHERE 1 "; //ORDER BY REMISE DESC,`LCIVIL` DESC";
$resql = $db->query($sql); $resql = $db->query($sql);
//$db->begin(); //$db->begin();
if ($resql) if ($resql)
while ($fields = $db->fetch_array($resql)) { while ($fields = $db->fetch_array($resql)) {
$i++; $i++;
$errorrecord = 0; $errorrecord = 0;
if ($startlinenb && $i < $startlinenb) if ($startlinenb && $i < $startlinenb)
continue; continue;
if ($endlinenb && $i > $endlinenb) if ($endlinenb && $i > $endlinenb)
continue; continue;
$nboflines++; $nboflines++;
$object = new Societe($db); $object = new Societe($db);
$object->import_key = $fields['CODE']; $object->import_key = $fields['CODE'];
$object->state = 1; $object->state = 1;
$object->client = 3; $object->client = 3;
$object->fournisseur = 0; $object->fournisseur = 0;
$object->name = $fields['FCIVIL'] . ' ' . $fields['FNOM']; $object->name = $fields['FCIVIL'] . ' ' . $fields['FNOM'];
//$object->name_alias = $fields[0] != $fields[13] ? trim($fields[0]) : ''; //$object->name_alias = $fields[0] != $fields[13] ? trim($fields[0]) : '';
$date = $fields['DATCREA'] ? $fields['DATCREA'] : ($fields['DATMOD'] ? $fields['DATMOD'] : '20200101'); $date = $fields['DATCREA'] ? $fields['DATCREA'] : ($fields['DATMOD'] ? $fields['DATMOD'] : '20200101');
$object->code_client = 'CU' . substr($date, 2, 2) . substr($date, 4, 2) . '-' . str_pad(substr($fields['CODE'], 0, 5), 5, "0", STR_PAD_LEFT); $object->code_client = 'CU' . substr($date, 2, 2) . substr($date, 4, 2) . '-' . str_pad(substr($fields['CODE'], 0, 5), 5, "0", STR_PAD_LEFT);
$object->address = trim($fields['FADR1']); $object->address = trim($fields['FADR1']);
if ($fields['FADR2']) if ($fields['FADR2'])
$object->address .= "\n" . trim($fields['FADR2']); $object->address .= "\n" . trim($fields['FADR2']);
if ($fields['FADR3']) if ($fields['FADR3'])
$object->address .= "\n" . trim($fields['FADR3']); $object->address .= "\n" . trim($fields['FADR3']);
$object->zip = trim($fields['FPOSTE']); $object->zip = trim($fields['FPOSTE']);
$object->town = trim($fields['FVILLE']); $object->town = trim($fields['FVILLE']);
if ($fields['FPAYS']) if ($fields['FPAYS'])
$object->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['FPAYS']))), 'c_country', 'label', 'rowid'); $object->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['FPAYS']))), 'c_country', 'label', 'rowid');
else else
$object->country_id = 1; $object->country_id = 1;
$object->phone = trim($fields['FTEL']) ? trim($fields['FTEL']) : trim($fields['FCONTACT']); $object->phone = trim($fields['FTEL']) ? trim($fields['FTEL']) : trim($fields['FCONTACT']);
$object->phone = substr($object->phone, 0, 20); $object->phone = substr($object->phone, 0, 20);
$object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']); $object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']);
$object->fax = substr($object->fax, 0, 20); $object->fax = substr($object->fax, 0, 20);
$object->email = trim($fields['FMAIL']); $object->email = trim($fields['FMAIL']);
// $object->idprof2 = trim($fields[29]); // $object->idprof2 = trim($fields[29]);
$object->tva_intra = str_replace(['.', ' '], '', $fields['TVAINTRA']); $object->tva_intra = str_replace(['.', ' '], '', $fields['TVAINTRA']);
$object->tva_intra = substr($object->tva_intra, 0, 20); $object->tva_intra = substr($object->tva_intra, 0, 20);
$object->default_lang = 'fr_FR'; $object->default_lang = 'fr_FR';
$object->cond_reglement_id = dol_getIdFromCode($db, 'PT_ORDER', 'c_payment_term', 'code', 'rowid', 1); $object->cond_reglement_id = dol_getIdFromCode($db, 'PT_ORDER', 'c_payment_term', 'code', 'rowid', 1);
$object->multicurrency_code = 'EUR'; $object->multicurrency_code = 'EUR';
if ($fields['REMISE'] != '0.00') { if ($fields['REMISE'] != '0.00') {
$object->remise_percent = abs($fields['REMISE']); $object->remise_percent = abs($fields['REMISE']);
} }
// $object->code_client = $fields[9]; // $object->code_client = $fields[9];
// $object->code_fournisseur = $fields[10]; // $object->code_fournisseur = $fields[10];
if ($fields['FCIVIL']) { if ($fields['FCIVIL']) {
$labeltype = in_array($fields['FCIVIL'], $civilPrivate) ? 'TE_PRIVATE' : 'TE_SMALL'; $labeltype = in_array($fields['FCIVIL'], $civilPrivate) ? 'TE_PRIVATE' : 'TE_SMALL';
$object->typent_id = dol_getIdFromCode($db, $labeltype, 'c_typent', 'code'); $object->typent_id = dol_getIdFromCode($db, $labeltype, 'c_typent', 'code');
} }
// Set price level // Set price level
$object->price_level = $fields['TARIF'] + 1; $object->price_level = $fields['TARIF'] + 1;
// if ($labeltype == 'Revendeur') // if ($labeltype == 'Revendeur')
// $object->price_level = 2; // $object->price_level = 2;
print "Process line nb " . $i . ", code " . $fields['CODE'] . ", name " . $object->name; print "Process line nb " . $i . ", code " . $fields['CODE'] . ", name " . $object->name;
// Extrafields // Extrafields
$object->array_options['options_banque'] = $fields['BANQUE']; $object->array_options['options_banque'] = $fields['BANQUE'];
$object->array_options['options_banque2'] = $fields['BANQUE2']; $object->array_options['options_banque2'] = $fields['BANQUE2'];
$object->array_options['options_banquevalid'] = $fields['VALID']; $object->array_options['options_banquevalid'] = $fields['VALID'];
if (!$errorrecord) { if (!$errorrecord) {
$ret = $object->create($user); $ret = $object->create($user);
if ($ret < 0) { if ($ret < 0) {
print " - Error in create result code = " . $ret . " - " . $object->errorsToString(); print " - Error in create result code = " . $ret . " - " . $object->errorsToString();
$errorrecord++; $errorrecord++;
var_dump($object->code_client, $db); var_dump($object->code_client, $db);
die(); die();
} else { } else {
print " - Creation OK with name " . $object->name . " - id = " . $ret; print " - Creation OK with name " . $object->name . " - id = " . $ret;
} }
} }
if (!$errorrecord) { if (!$errorrecord) {
dol_syslog("Set price level"); dol_syslog("Set price level");
$object->set_price_level($object->price_level, $user); $object->set_price_level($object->price_level, $user);
} }
if (!$errorrecord && @$object->remise_percent) { if (!$errorrecord && @$object->remise_percent) {
dol_syslog("Set remise client"); dol_syslog("Set remise client");
$object->set_remise_client($object->remise_percent, 'Importé', $user); $object->set_remise_client($object->remise_percent, 'Importé', $user);
} }
dol_syslog("Add contact"); dol_syslog("Add contact");
// Insert an invoice contact if there is an invoice email != standard email // Insert an invoice contact if there is an invoice email != standard email
if (!$errorrecord && ($fields['LCIVIL'] || $fields['LNOM'])) { if (!$errorrecord && ($fields['LCIVIL'] || $fields['LNOM'])) {
$madame = array("MADAME", $madame = array("MADAME",
"MADEMOISELLE", "MADEMOISELLE",
"MELLE", "MELLE",
"MLLE", "MLLE",
"MM", "MM",
"Mme", "Mme",
"MNE", "MNE",
); );
$monsieur = array("M", $monsieur = array("M",
"M ET MME", "M ET MME",
"M MME", "M MME",
"M.", "M.",
"M. MME", "M. MME",
"M. OU Mme", "M. OU Mme",
"M.ou Madame", "M.ou Madame",
"MONSEUR", "MONSEUR",
"MONSIER", "MONSIER",
"MONSIEU", "MONSIEU",
"MONSIEUR", "MONSIEUR",
"monsieur:mme", "monsieur:mme",
"MONSIEUR¨", "MONSIEUR¨",
"MONSIEZUR", "MONSIEZUR",
"MONSIUER", "MONSIUER",
"MONSKIEUR", "MONSKIEUR",
"MR", "MR",
); );
$ret1 = $ret2 = 0; $ret1 = $ret2 = 0;
$contact = new Contact($db); $contact = new Contact($db);
if (in_array($fields['LCIVIL'], $madame)) { if (in_array($fields['LCIVIL'], $madame)) {
// une dame // une dame
$contact->civility_id = 'MME'; $contact->civility_id = 'MME';
$contact->lastname = $fields['LNOM']; $contact->lastname = $fields['LNOM'];
} elseif (in_array($fields['LCIVIL'], $monsieur)) { } elseif (in_array($fields['LCIVIL'], $monsieur)) {
// un monsieur // un monsieur
$contact->civility_id = 'MR'; $contact->civility_id = 'MR';
$contact->lastname = $fields['LNOM']; $contact->lastname = $fields['LNOM'];
} elseif (in_array($fields['LCIVIL'], ['DOCTEUR'])) { } elseif (in_array($fields['LCIVIL'], ['DOCTEUR'])) {
// un monsieur // un monsieur
$contact->civility_id = 'DR'; $contact->civility_id = 'DR';
$contact->lastname = $fields['LNOM']; $contact->lastname = $fields['LNOM'];
} else { } else {
// un a rattraper // un a rattraper
$contact->lastname = $fields['LCIVIL'] . " " . $fields['LNOM']; $contact->lastname = $fields['LCIVIL'] . " " . $fields['LNOM'];
} }
$contact->address = trim($fields['LADR1']); $contact->address = trim($fields['LADR1']);
if ($fields['LADR2']) if ($fields['LADR2'])
$contact->address .= "\n" . trim($fields['LADR2']); $contact->address .= "\n" . trim($fields['LADR2']);
if ($fields['LADR3']) if ($fields['LADR3'])
$contact->address .= "\n" . trim($fields['LADR3']); $contact->address .= "\n" . trim($fields['LADR3']);
$contact->zip = trim($fields['LPOSTE']); $contact->zip = trim($fields['LPOSTE']);
$contact->town = trim($fields['LVILLE']); $contact->town = trim($fields['LVILLE']);
if ($fields['FPAYS']) if ($fields['FPAYS'])
$contact->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['LPAYS']))), 'c_country', 'label', 'rowid'); $contact->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['LPAYS']))), 'c_country', 'label', 'rowid');
else else
$contact->country_id = 1; $contact->country_id = 1;
$contact->email = $fields['LMAIL']; $contact->email = $fields['LMAIL'];
$contact->phone = trim($fields['LTEL']) ? trim($fields['LTEL']) : trim($fields['LCONTACT']); $contact->phone = trim($fields['LTEL']) ? trim($fields['LTEL']) : trim($fields['LCONTACT']);
$contact->fax = trim($fields['LFAX']) ? trim($fields['LFAX']) : trim($fields['LCONTACT']); $contact->fax = trim($fields['LFAX']) ? trim($fields['LFAX']) : trim($fields['LCONTACT']);
$contact->socid = $object->id; $contact->socid = $object->id;
$ret1 = $contact->create($user); $ret1 = $contact->create($user);
if ($ret1 > 0) { if ($ret1 > 0) {
//$ret2=$contact->add_contact($object->id, 'BILLING'); //$ret2=$contact->add_contact($object->id, 'BILLING');
} }
if ($ret1 < 0 || $ret2 < 0) { if ($ret1 < 0 || $ret2 < 0) {
print " - Error in create contact result code = " . $ret1 . " " . $ret2 . " - " . $contact->errorsToString(); print " - Error in create contact result code = " . $ret1 . " " . $ret2 . " - " . $contact->errorsToString();
$errorrecord++; $errorrecord++;
} else { } else {
print " - create contact OK"; print " - create contact OK";
} }
} }
//update date créa //update date créa
if (!$errorrecord) { if (!$errorrecord) {
$datec = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2); $datec = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2);
$retd = $db->query("UPDATE `llx_societe` SET `datec` = '$datec 00:00:00' WHERE `rowid` = $object->id"); $retd = $db->query("UPDATE `llx_societe` SET `datec` = '$datec 00:00:00' WHERE `rowid` = $object->id");
if ($retd < 1) { if ($retd < 1) {
print " - Error in update date créa result " . $object->errorsToString(); print " - Error in update date créa result " . $object->errorsToString();
$errorrecord++; $errorrecord++;
} else { } else {
print " - update date créa OK"; print " - update date créa OK";
} }
} }
print "\n"; print "\n";
if ($errorrecord) { if ($errorrecord) {
print( 'Error on record nb ' . $i . " - " . $object->errorsToString() . "\n"); print( 'Error on record nb ' . $i . " - " . $object->errorsToString() . "\n");
var_dump($db, $object, $contact); var_dump($db, $object, $contact);
// $db->rollback(); // $db->rollback();
die(); die();
$error++; // $errorrecord will be reset $error++; // $errorrecord will be reset
} }
$j++; $j++;
} else } else
die("error : $sql"); die("error : $sql");
$db->commit(); $db->commit();

View File

@@ -8,7 +8,8 @@ define('DBASE_RDWR', 2);
define('DBASE_TYPE_DBASE', 0); define('DBASE_TYPE_DBASE', 0);
define('DBASE_TYPE_FOXPRO', 1); define('DBASE_TYPE_FOXPRO', 1);
class DBase { class DBase
{
private $fd; private $fd;
private $headerLength = 0; private $headerLength = 0;
@@ -18,7 +19,8 @@ class DBase {
private $recordCount = 0; private $recordCount = 0;
//resource dbase_open ( string $filename , int $mode ) //resource dbase_open ( string $filename , int $mode )
public static function open($filename, $mode) { public static function open($filename, $mode)
{
if (!file_exists($filename)) if (!file_exists($filename))
return false; return false;
$modes = array('r', 'w', 'r+'); $modes = array('r', 'w', 'r+');
@@ -30,7 +32,8 @@ class DBase {
} }
//resource dbase_create ( string $filename , array $fields [, int $type = DBASE_TYPE_DBASE ] ) //resource dbase_create ( string $filename , array $fields [, int $type = DBASE_TYPE_DBASE ] )
public static function create($filename, $fields, $type = DBASE_TYPE_DBASE) { public static function create($filename, $fields, $type = DBASE_TYPE_DBASE)
{
if (file_exists($filename)) if (file_exists($filename))
return false; return false;
$fd = fopen($filename, 'c+'); $fd = fopen($filename, 'c+');
@@ -93,7 +96,8 @@ class DBase {
} }
// Create DBase instance // Create DBase instance
private function __construct($fd) { private function __construct($fd)
{
$this->fd = $fd; $this->fd = $fd;
// Byte 4-7 (32-bit number): Number of records in the database file. Currently 0 // Byte 4-7 (32-bit number): Number of records in the database file. Currently 0
fseek($this->fd, 4, SEEK_SET); fseek($this->fd, 4, SEEK_SET);
@@ -116,27 +120,32 @@ class DBase {
} }
//bool dbase_close ( resource $dbase_identifier ) //bool dbase_close ( resource $dbase_identifier )
public function close() { public function close()
{
fclose($this->fd); fclose($this->fd);
} }
//array dbase_get_header_info ( resource $dbase_identifier ) //array dbase_get_header_info ( resource $dbase_identifier )
public function get_header_info() { public function get_header_info()
{
return $this->fields; return $this->fields;
} }
//int dbase_numfields ( resource $dbase_identifier ) //int dbase_numfields ( resource $dbase_identifier )
public function numfields() { public function numfields()
{
return $this->fieldCount; return $this->fieldCount;
} }
//int dbase_numrecords ( resource $dbase_identifier ) //int dbase_numrecords ( resource $dbase_identifier )
public function numrecords() { public function numrecords()
{
return $this->recordCount; return $this->recordCount;
} }
//bool dbase_add_record ( resource $dbase_identifier , array $record ) //bool dbase_add_record ( resource $dbase_identifier , array $record )
public function add_record($record) { public function add_record($record)
{
if (count($record) != $this->fieldCount) if (count($record) != $this->fieldCount)
return false; return false;
// Seek to end of file, minus the end of file marker // Seek to end of file, minus the end of file marker
@@ -153,7 +162,8 @@ class DBase {
} }
//bool dbase_replace_record ( resource $dbase_identifier , array $record , int $record_number ) //bool dbase_replace_record ( resource $dbase_identifier , array $record , int $record_number )
public function replace_record($record, $record_number) { public function replace_record($record, $record_number)
{
if (count($record) != $this->fieldCount) if (count($record) != $this->fieldCount)
return false; return false;
if ($record_number < 1 || $record_number > $this->recordCount) if ($record_number < 1 || $record_number > $this->recordCount)
@@ -164,7 +174,8 @@ class DBase {
} }
//bool dbase_delete_record ( resource $dbase_identifier , int $record_number ) //bool dbase_delete_record ( resource $dbase_identifier , int $record_number )
public function delete_record($record_number) { public function delete_record($record_number)
{
if ($record_number < 1 || $record_number > $this->recordCount) if ($record_number < 1 || $record_number > $this->recordCount)
return false; return false;
fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1))); fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
@@ -173,7 +184,8 @@ class DBase {
} }
//array dbase_get_record ( resource $dbase_identifier , int $record_number ) //array dbase_get_record ( resource $dbase_identifier , int $record_number )
public function get_record($record_number) { public function get_record($record_number)
{
if ($record_number < 1 || $record_number > $this->recordCount) if ($record_number < 1 || $record_number > $this->recordCount)
return false; return false;
fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1))); fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1)));
@@ -186,7 +198,7 @@ class DBase {
$value = strtolower($value); $value = strtolower($value);
if ($value == 't' || $value == 'y') if ($value == 't' || $value == 'y')
$value = true; $value = true;
else if ($value == 'f' || $value == 'n') elseif ($value == 'f' || $value == 'n')
$value = false; $value = false;
else else
$value = null; $value = null;
@@ -197,7 +209,8 @@ class DBase {
} }
//array dbase_get_record_with_names ( resource $dbase_identifier , int $record_number ) //array dbase_get_record_with_names ( resource $dbase_identifier , int $record_number )
public function get_record_with_names($record_number) { public function get_record_with_names($record_number)
{
if ($record_number < 1 || $record_number > $this->recordCount) if ($record_number < 1 || $record_number > $this->recordCount)
return false; return false;
$record = $this->get_record($record_number); $record = $this->get_record($record_number);
@@ -209,7 +222,8 @@ class DBase {
} }
//bool dbase_pack ( resource $dbase_identifier ) //bool dbase_pack ( resource $dbase_identifier )
public function pack() { public function pack()
{
$in_offset = $out_offset = $this->headerLength; $in_offset = $out_offset = $this->headerLength;
$new_count = 0; $new_count = 0;
$rec_count = $this->recordCount; $rec_count = $this->recordCount;
@@ -236,7 +250,8 @@ class DBase {
* A few utilitiy functions * A few utilitiy functions
*/ */
private static function length($field) { private static function length($field)
{
switch ($field[1]) { switch ($field[1]) {
case 'D': // Date: Numbers and a character to separate month, day, and year (stored internally as 8 digits in YYYYMMDD format) case 'D': // Date: Numbers and a character to separate month, day, and year (stored internally as 8 digits in YYYYMMDD format)
return 8; return 8;
@@ -257,15 +272,18 @@ class DBase {
* Functions for reading and writing bytes * Functions for reading and writing bytes
*/ */
private static function getChar8($fd) { private static function getChar8($fd)
{
return ord(fread($fd, 1)); return ord(fread($fd, 1));
} }
private static function putChar8($fd, $value) { private static function putChar8($fd, $value)
{
return fwrite($fd, chr($value)); return fwrite($fd, chr($value));
} }
private static function getInt16($fd, $n = 1) { private static function getInt16($fd, $n = 1)
{
$data = fread($fd, 2 * $n); $data = fread($fd, 2 * $n);
$i = unpack("S$n", $data); $i = unpack("S$n", $data);
if ($n == 1) if ($n == 1)
@@ -274,11 +292,13 @@ class DBase {
return array_merge($i); return array_merge($i);
} }
private static function putInt16($fd, $value) { private static function putInt16($fd, $value)
{
return fwrite($fd, pack('S', $value)); return fwrite($fd, pack('S', $value));
} }
private static function getInt32($fd, $n = 1) { private static function getInt32($fd, $n = 1)
{
$data = fread($fd, 4 * $n); $data = fread($fd, 4 * $n);
$i = unpack("L$n", $data); $i = unpack("L$n", $data);
if ($n == 1) if ($n == 1)
@@ -287,15 +307,18 @@ class DBase {
return array_merge($i); return array_merge($i);
} }
private static function putInt32($fd, $value) { private static function putInt32($fd, $value)
{
return fwrite($fd, pack('L', $value)); return fwrite($fd, pack('L', $value));
} }
private static function putString($fd, $value, $length = 254) { private static function putString($fd, $value, $length = 254)
{
$ret = fwrite($fd, pack('A' . $length, $value)); $ret = fwrite($fd, pack('A' . $length, $value));
} }
private function putRecord($record) { private function putRecord($record)
{
foreach ($this->fields as $i => &$field) { foreach ($this->fields as $i => &$field) {
$value = $record[$i]; $value = $record[$i];
// Number types are right aligned with spaces // Number types are right aligned with spaces
@@ -306,56 +329,67 @@ class DBase {
} }
return true; return true;
} }
} }
if (!function_exists('dbase_open')) { if (!function_exists('dbase_open')) {
function dbase_open($filename, $mode) { function dbase_open($filename, $mode)
{
return DBase::open($filename, $mode); return DBase::open($filename, $mode);
} }
function dbase_create($filename, $fields, $type = DBASE_TYPE_DBASE) { function dbase_create($filename, $fields, $type = DBASE_TYPE_DBASE)
{
return DBase::create($filename, $fields, $type); return DBase::create($filename, $fields, $type);
} }
function dbase_close($dbase_identifier) { function dbase_close($dbase_identifier)
{
return $dbase_identifier->close(); return $dbase_identifier->close();
} }
function dbase_get_header_info($dbase_identifier) { function dbase_get_header_info($dbase_identifier)
{
return $dbase_identifier->get_header_info(); return $dbase_identifier->get_header_info();
} }
function dbase_numfields($dbase_identifier) { function dbase_numfields($dbase_identifier)
{
$dbase_identifier->numfields(); $dbase_identifier->numfields();
} }
function dbase_numrecords($dbase_identifier) { function dbase_numrecords($dbase_identifier)
{
return $dbase_identifier->numrecords(); return $dbase_identifier->numrecords();
} }
function dbase_add_record($dbase_identifier, $record) { function dbase_add_record($dbase_identifier, $record)
{
return $dbase_identifier->add_record($record); return $dbase_identifier->add_record($record);
} }
function dbase_delete_record($dbase_identifier, $record_number) { function dbase_delete_record($dbase_identifier, $record_number)
{
return $dbase_identifier->delete_record($record_number); return $dbase_identifier->delete_record($record_number);
} }
function dbase_replace_record($dbase_identifier, $record, $record_number) { function dbase_replace_record($dbase_identifier, $record, $record_number)
{
return $dbase_identifier->replace_record($record, $record_number); return $dbase_identifier->replace_record($record, $record_number);
} }
function dbase_get_record($dbase_identifier, $record_number) { function dbase_get_record($dbase_identifier, $record_number)
{
return $dbase_identifier->get_record($record_number); return $dbase_identifier->get_record($record_number);
} }
function dbase_get_record_with_names($dbase_identifier, $record_number) { function dbase_get_record_with_names($dbase_identifier, $record_number)
{
return $dbase_identifier->get_record_with_names($record_number); return $dbase_identifier->get_record_with_names($record_number);
} }
function dbase_pack($dbase_identifier) { function dbase_pack($dbase_identifier)
{
return $dbase_identifier->pack(); return $dbase_identifier->pack();
} }