diff --git a/dev/initdata/import-dbf.php b/dev/initdata/import-dbf.php index 954f1c8b2ec..de904ca76e1 100644 --- a/dev/initdata/import-dbf.php +++ b/dev/initdata/import-dbf.php @@ -116,7 +116,7 @@ foreach ($header as $value) { } $sqlCreate .= ", PRIMARY KEY (`id`)) ENGINE = InnoDB"; $resql = $db->query($sqlCreate); -if ($resql !== FALSE) { +if ($resql !== false) { print "Table $table_name created\n"; } else { var_dump($db->errno()); @@ -136,7 +136,7 @@ for ($i = 1; $i <= $record_numbers; $i++) { if ($endlinenb && $i > $endlinenb) continue; $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; $sqlInsert = "INSERT INTO `$table_name`($fields) VALUES (null,"; array_shift($row); // remove delete column @@ -152,8 +152,8 @@ for ($i = 1; $i <= $record_numbers; $i++) { var_dump($row, $db->errno()); die(); } -// $fields = (object) $row; -// var_dump($fields); + // $fields = (object) $row; + // var_dump($fields); continue; } die(); @@ -179,7 +179,8 @@ fclose($fhandleerr); exit($error); -function replaceable_echo($message, $force_clear_lines = NULL) { +function replaceable_echo($message, $force_clear_lines = null) +{ static $last_lines = 0; if (!is_null($force_clear_lines)) { diff --git a/dev/initdata/importdb-products.php b/dev/initdata/importdb-products.php index 249ae129b58..08e960dfdc6 100644 --- a/dev/initdata/importdb-products.php +++ b/dev/initdata/importdb-products.php @@ -89,145 +89,145 @@ if (!$ret > 0) { $sql = "SELECT * FROM `$table` WHERE 1"; $resql = $db->query($sql); if ($resql) - while ($fields = $db->fetch_array($resql)) { - $errorrecord = 0; - if ($fields === FALSE) - continue; - $nboflines++; +while ($fields = $db->fetch_array($resql)) { + $errorrecord = 0; + if ($fields === false) + continue; + $nboflines++; - $produit = new Product($db); - $produit->type = 0; - $produit->status = 1; - $produit->ref = trim($fields['REF']); - if ($produit->ref == '') - continue; - print "Process line nb " . $j . ", ref " . $produit->ref; - $produit->label = trim($fields['LIBELLE']); - if ($produit->label == '') - $produit->label = $produit->ref; - if (empty($produit->label)) - continue; - //$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : '')); -// $produit->volume = price2num($fields[8]); -// $produit->volume_unit = 0; - $produit->weight = price2num($fields['MASSE']); - $produit->weight_units = 0; // -3 = g - //$produit->customcode = $fields[10]; - $produit->barcode = str_pad($fields['CODE'], 12, "0", STR_PAD_LEFT); - $produit->barcode_type = '2'; - $produit->import_key = $fields['CODE']; + $produit = new Product($db); + $produit->type = 0; + $produit->status = 1; + $produit->ref = trim($fields['REF']); + if ($produit->ref == '') + continue; + print "Process line nb " . $j . ", ref " . $produit->ref; + $produit->label = trim($fields['LIBELLE']); + if ($produit->label == '') + $produit->label = $produit->ref; + if (empty($produit->label)) + continue; + //$produit->description = trim($fields[4] . "\n" . ($fields[5] ? $fields[5] . ' x ' . $fields[6] . ' x ' . $fields[7] : '')); + // $produit->volume = price2num($fields[8]); + // $produit->volume_unit = 0; + $produit->weight = price2num($fields['MASSE']); + $produit->weight_units = 0; // -3 = g + //$produit->customcode = $fields[10]; + $produit->barcode = str_pad($fields['CODE'], 12, "0", STR_PAD_LEFT); + $produit->barcode_type = '2'; + $produit->import_key = $fields['CODE']; - $produit->status = 1; - $produit->status_buy = 1; + $produit->status = 1; + $produit->status_buy = 1; - $produit->finished = 1; + $produit->finished = 1; -// $produit->multiprices[0] = price2num($fields['TARIF0']); -// $produit->multiprices[1] = price2num($fields['TARIF1']); -// $produit->multiprices[2] = price2num($fields['TARIF2']); -// $produit->multiprices[3] = price2num($fields['TARIF3']); -// $produit->multiprices[4] = price2num($fields['TARIF4']); -// $produit->multiprices[5] = price2num($fields['TARIF5']); -// $produit->multiprices[6] = price2num($fields['TARIF6']); -// $produit->multiprices[7] = price2num($fields['TARIF7']); -// $produit->multiprices[8] = price2num($fields['TARIF8']); -// $produit->multiprices[9] = price2num($fields['TARIF9']); -// $produit->price_min = null; -// $produit->price_min_ttc = null; -// $produit->price = price2num($fields[11]); -// $produit->price_ttc = price2num($fields[12]); -// $produit->price_base_type = 'TTC'; -// $produit->tva_tx = price2num($fields[13]); - $produit->tva_tx = (int) ($tvas[$fields['CODTVA']]); - $produit->tva_npr = 0; -// $produit->cost_price = price2num($fields[16]); - //compta + // $produit->multiprices[0] = price2num($fields['TARIF0']); + // $produit->multiprices[1] = price2num($fields['TARIF1']); + // $produit->multiprices[2] = price2num($fields['TARIF2']); + // $produit->multiprices[3] = price2num($fields['TARIF3']); + // $produit->multiprices[4] = price2num($fields['TARIF4']); + // $produit->multiprices[5] = price2num($fields['TARIF5']); + // $produit->multiprices[6] = price2num($fields['TARIF6']); + // $produit->multiprices[7] = price2num($fields['TARIF7']); + // $produit->multiprices[8] = price2num($fields['TARIF8']); + // $produit->multiprices[9] = price2num($fields['TARIF9']); + // $produit->price_min = null; + // $produit->price_min_ttc = null; + // $produit->price = price2num($fields[11]); + // $produit->price_ttc = price2num($fields[12]); + // $produit->price_base_type = 'TTC'; + // $produit->tva_tx = price2num($fields[13]); + $produit->tva_tx = (int) ($tvas[$fields['CODTVA']]); + $produit->tva_npr = 0; + // $produit->cost_price = price2num($fields[16]); + //compta - $produit->accountancy_code_buy = trim($fields['COMACH']); - $produit->accountancy_code_sell = trim($fields['COMVEN']); -// $produit->accountancy_code_sell_intra=trim($fields['COMVEN']); -// $produit->accountancy_code_sell_export=trim($fields['COMVEN']); - // Extrafields -// $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]); + $produit->accountancy_code_buy = trim($fields['COMACH']); + $produit->accountancy_code_sell = trim($fields['COMVEN']); + // $produit->accountancy_code_sell_intra=trim($fields['COMVEN']); + // $produit->accountancy_code_sell_export=trim($fields['COMVEN']); + // Extrafields + // $produit->array_options['options_ecotaxdeee'] = price2num($fields[17]); - $produit->seuil_stock_alerte = $fields['STALERTE']; - $ret = $produit->create($user, 0); - if ($ret < 0) { - print " - Error in create result code = " . $ret . " - " . $produit->errorsToString(); - $errorrecord++; - } else { - print " - Creation OK with ref " . $produit->ref . " - id = " . $ret; - } + $produit->seuil_stock_alerte = $fields['STALERTE']; + $ret = $produit->create($user, 0); + if ($ret < 0) { + print " - Error in create result code = " . $ret . " - " . $produit->errorsToString(); + $errorrecord++; + } else { + 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 (!$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 = false; - for ($i = 0; $i < 10; $i++) { - if ($fields['TARIF' . ($i)] == 0) - 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; - } - if ($ret1) { - print " - Error in updatePrice result " . $produit->errorsToString(); - $errorrecord++; - } else { - print " - updatePrice OK"; - } - } + // If we use price level, insert price for each level + 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 = false; + for ($i = 0; $i < 10; $i++) { + if ($fields['TARIF' . ($i)] == 0) + 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; + } + if ($ret1) { + print " - Error in updatePrice result " . $produit->errorsToString(); + $errorrecord++; + } else { + print " - updatePrice OK"; + } + } -// dol_syslog("Add multilangs"); - // Add alternative languages -// if (!$errorrecord && 1) { -// $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); -// -// $ret = $produit->setMultiLangs($user); -// if ($ret < 0) { -// print " - Error in setMultiLangs result code = " . $ret . " - " . $produit->errorsToString(); -// $errorrecord++; -// } else { -// print " - setMultiLangs OK"; -// } -// } + // dol_syslog("Add multilangs"); + // Add alternative languages + // if (!$errorrecord && 1) { + // $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); + // + // $ret = $produit->setMultiLangs($user); + // if ($ret < 0) { + // print " - Error in setMultiLangs result code = " . $ret . " - " . $produit->errorsToString(); + // $errorrecord++; + // } else { + // print " - setMultiLangs OK"; + // } + // } - dol_syslog("Add stocks"); - // stocks - if (!$errorrecord && $fields['STOCK'] != 0) { - $rets = $produit->correct_stock($user, 1, $fields['STOCK'], 0, 'Stock importé'); - if ($rets < 0) { - print " - Error in correct_stock result " . $produit->errorsToString(); - $errorrecord++; - } else { - print " - correct_stock OK"; - } - } + dol_syslog("Add stocks"); + // stocks + if (!$errorrecord && $fields['STOCK'] != 0) { + $rets = $produit->correct_stock($user, 1, $fields['STOCK'], 0, 'Stock importé'); + if ($rets < 0) { + print " - Error in correct_stock result " . $produit->errorsToString(); + $errorrecord++; + } else { + print " - correct_stock OK"; + } + } - //update date créa - if (!$errorrecord) { - $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"); - if ($retd < 1) { - print " - Error in update date créa result " . $produit->errorsToString(); - $errorrecord++; - } else { - print " - update date créa OK"; - } - } - print "\n"; + //update date créa + if (!$errorrecord) { + $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"); + if ($retd < 1) { + print " - Error in update date créa result " . $produit->errorsToString(); + $errorrecord++; + } else { + print " - update date créa OK"; + } + } + print "\n"; - if ($errorrecord) { - print( 'Error on record nb ' . $i . " - " . $produit->errorsToString() . "\n"); - var_dump($db); - die(); - $error++; // $errorrecord will be reset - } - $j++; - } else + if ($errorrecord) { + print( 'Error on record nb ' . $i . " - " . $produit->errorsToString() . "\n"); + var_dump($db); + die(); + $error++; // $errorrecord will be reset + } + $j++; +} else die("error : $sql"); diff --git a/dev/initdata/importdb-thirdparties.php b/dev/initdata/importdb-thirdparties.php index af92ce70261..195c1d16b82 100644 --- a/dev/initdata/importdb-thirdparties.php +++ b/dev/initdata/importdb-thirdparties.php @@ -145,202 +145,202 @@ $sql = "SELECT * FROM `$table` WHERE 1 "; //ORDER BY REMISE DESC,`LCIVIL` DESC"; $resql = $db->query($sql); //$db->begin(); if ($resql) - while ($fields = $db->fetch_array($resql)) { - $i++; - $errorrecord = 0; +while ($fields = $db->fetch_array($resql)) { + $i++; + $errorrecord = 0; - if ($startlinenb && $i < $startlinenb) - continue; - if ($endlinenb && $i > $endlinenb) - continue; + if ($startlinenb && $i < $startlinenb) + continue; + if ($endlinenb && $i > $endlinenb) + continue; - $nboflines++; + $nboflines++; - $object = new Societe($db); - $object->import_key = $fields['CODE']; - $object->state = 1; - $object->client = 3; - $object->fournisseur = 0; + $object = new Societe($db); + $object->import_key = $fields['CODE']; + $object->state = 1; + $object->client = 3; + $object->fournisseur = 0; - $object->name = $fields['FCIVIL'] . ' ' . $fields['FNOM']; - //$object->name_alias = $fields[0] != $fields[13] ? trim($fields[0]) : ''; + $object->name = $fields['FCIVIL'] . ' ' . $fields['FNOM']; + //$object->name_alias = $fields[0] != $fields[13] ? trim($fields[0]) : ''; - $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); + $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->address = trim($fields['FADR1']); - if ($fields['FADR2']) - $object->address .= "\n" . trim($fields['FADR2']); - if ($fields['FADR3']) - $object->address .= "\n" . trim($fields['FADR3']); + $object->address = trim($fields['FADR1']); + if ($fields['FADR2']) + $object->address .= "\n" . trim($fields['FADR2']); + if ($fields['FADR3']) + $object->address .= "\n" . trim($fields['FADR3']); - $object->zip = trim($fields['FPOSTE']); - $object->town = trim($fields['FVILLE']); - if ($fields['FPAYS']) - $object->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['FPAYS']))), 'c_country', 'label', 'rowid'); - else - $object->country_id = 1; - $object->phone = trim($fields['FTEL']) ? trim($fields['FTEL']) : trim($fields['FCONTACT']); - $object->phone = substr($object->phone, 0, 20); - $object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']); - $object->fax = substr($object->fax, 0, 20); - $object->email = trim($fields['FMAIL']); -// $object->idprof2 = trim($fields[29]); - $object->tva_intra = str_replace(['.', ' '], '', $fields['TVAINTRA']); - $object->tva_intra = substr($object->tva_intra, 0, 20); - $object->default_lang = 'fr_FR'; + $object->zip = trim($fields['FPOSTE']); + $object->town = trim($fields['FVILLE']); + if ($fields['FPAYS']) + $object->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['FPAYS']))), 'c_country', 'label', 'rowid'); + else + $object->country_id = 1; + $object->phone = trim($fields['FTEL']) ? trim($fields['FTEL']) : trim($fields['FCONTACT']); + $object->phone = substr($object->phone, 0, 20); + $object->fax = trim($fields['FFAX']) ? trim($fields['FFAX']) : trim($fields['FCONTACT']); + $object->fax = substr($object->fax, 0, 20); + $object->email = trim($fields['FMAIL']); + // $object->idprof2 = trim($fields[29]); + $object->tva_intra = str_replace(['.', ' '], '', $fields['TVAINTRA']); + $object->tva_intra = substr($object->tva_intra, 0, 20); + $object->default_lang = 'fr_FR'; - $object->cond_reglement_id = dol_getIdFromCode($db, 'PT_ORDER', 'c_payment_term', 'code', 'rowid', 1); - $object->multicurrency_code = 'EUR'; + $object->cond_reglement_id = dol_getIdFromCode($db, 'PT_ORDER', 'c_payment_term', 'code', 'rowid', 1); + $object->multicurrency_code = 'EUR'; - if ($fields['REMISE'] != '0.00') { - $object->remise_percent = abs($fields['REMISE']); - } + if ($fields['REMISE'] != '0.00') { + $object->remise_percent = abs($fields['REMISE']); + } -// $object->code_client = $fields[9]; -// $object->code_fournisseur = $fields[10]; + // $object->code_client = $fields[9]; + // $object->code_fournisseur = $fields[10]; - if ($fields['FCIVIL']) { - $labeltype = in_array($fields['FCIVIL'], $civilPrivate) ? 'TE_PRIVATE' : 'TE_SMALL'; - $object->typent_id = dol_getIdFromCode($db, $labeltype, 'c_typent', 'code'); - } + if ($fields['FCIVIL']) { + $labeltype = in_array($fields['FCIVIL'], $civilPrivate) ? 'TE_PRIVATE' : 'TE_SMALL'; + $object->typent_id = dol_getIdFromCode($db, $labeltype, 'c_typent', 'code'); + } - // Set price level - $object->price_level = $fields['TARIF'] + 1; -// if ($labeltype == 'Revendeur') -// $object->price_level = 2; + // Set price level + $object->price_level = $fields['TARIF'] + 1; + // if ($labeltype == 'Revendeur') + // $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 - $object->array_options['options_banque'] = $fields['BANQUE']; - $object->array_options['options_banque2'] = $fields['BANQUE2']; - $object->array_options['options_banquevalid'] = $fields['VALID']; + // Extrafields + $object->array_options['options_banque'] = $fields['BANQUE']; + $object->array_options['options_banque2'] = $fields['BANQUE2']; + $object->array_options['options_banquevalid'] = $fields['VALID']; - if (!$errorrecord) { - $ret = $object->create($user); - if ($ret < 0) { - print " - Error in create result code = " . $ret . " - " . $object->errorsToString(); - $errorrecord++; - var_dump($object->code_client, $db); - die(); - } else { - print " - Creation OK with name " . $object->name . " - id = " . $ret; - } - } + if (!$errorrecord) { + $ret = $object->create($user); + if ($ret < 0) { + print " - Error in create result code = " . $ret . " - " . $object->errorsToString(); + $errorrecord++; + var_dump($object->code_client, $db); + die(); + } else { + print " - Creation OK with name " . $object->name . " - id = " . $ret; + } + } - if (!$errorrecord) { - dol_syslog("Set price level"); - $object->set_price_level($object->price_level, $user); - } - if (!$errorrecord && @$object->remise_percent) { - dol_syslog("Set remise client"); - $object->set_remise_client($object->remise_percent, 'Importé', $user); - } + if (!$errorrecord) { + dol_syslog("Set price level"); + $object->set_price_level($object->price_level, $user); + } + if (!$errorrecord && @$object->remise_percent) { + dol_syslog("Set remise client"); + $object->set_remise_client($object->remise_percent, 'Importé', $user); + } - dol_syslog("Add contact"); - // Insert an invoice contact if there is an invoice email != standard email - if (!$errorrecord && ($fields['LCIVIL'] || $fields['LNOM'])) { - $madame = array("MADAME", - "MADEMOISELLE", - "MELLE", - "MLLE", - "MM", - "Mme", - "MNE", - ); - $monsieur = array("M", - "M ET MME", - "M MME", - "M.", - "M. MME", - "M. OU Mme", - "M.ou Madame", - "MONSEUR", - "MONSIER", - "MONSIEU", - "MONSIEUR", - "monsieur:mme", - "MONSIEUR¨", - "MONSIEZUR", - "MONSIUER", - "MONSKIEUR", - "MR", - ); - $ret1 = $ret2 = 0; + dol_syslog("Add contact"); + // Insert an invoice contact if there is an invoice email != standard email + if (!$errorrecord && ($fields['LCIVIL'] || $fields['LNOM'])) { + $madame = array("MADAME", + "MADEMOISELLE", + "MELLE", + "MLLE", + "MM", + "Mme", + "MNE", + ); + $monsieur = array("M", + "M ET MME", + "M MME", + "M.", + "M. MME", + "M. OU Mme", + "M.ou Madame", + "MONSEUR", + "MONSIER", + "MONSIEU", + "MONSIEUR", + "monsieur:mme", + "MONSIEUR¨", + "MONSIEZUR", + "MONSIUER", + "MONSKIEUR", + "MR", + ); + $ret1 = $ret2 = 0; - $contact = new Contact($db); - if (in_array($fields['LCIVIL'], $madame)) { - // une dame - $contact->civility_id = 'MME'; - $contact->lastname = $fields['LNOM']; - } elseif (in_array($fields['LCIVIL'], $monsieur)) { - // un monsieur - $contact->civility_id = 'MR'; - $contact->lastname = $fields['LNOM']; - } elseif (in_array($fields['LCIVIL'], ['DOCTEUR'])) { - // un monsieur - $contact->civility_id = 'DR'; - $contact->lastname = $fields['LNOM']; - } else { - // un a rattraper - $contact->lastname = $fields['LCIVIL'] . " " . $fields['LNOM']; - } - $contact->address = trim($fields['LADR1']); - if ($fields['LADR2']) - $contact->address .= "\n" . trim($fields['LADR2']); - if ($fields['LADR3']) - $contact->address .= "\n" . trim($fields['LADR3']); + $contact = new Contact($db); + if (in_array($fields['LCIVIL'], $madame)) { + // une dame + $contact->civility_id = 'MME'; + $contact->lastname = $fields['LNOM']; + } elseif (in_array($fields['LCIVIL'], $monsieur)) { + // un monsieur + $contact->civility_id = 'MR'; + $contact->lastname = $fields['LNOM']; + } elseif (in_array($fields['LCIVIL'], ['DOCTEUR'])) { + // un monsieur + $contact->civility_id = 'DR'; + $contact->lastname = $fields['LNOM']; + } else { + // un a rattraper + $contact->lastname = $fields['LCIVIL'] . " " . $fields['LNOM']; + } + $contact->address = trim($fields['LADR1']); + if ($fields['LADR2']) + $contact->address .= "\n" . trim($fields['LADR2']); + if ($fields['LADR3']) + $contact->address .= "\n" . trim($fields['LADR3']); - $contact->zip = trim($fields['LPOSTE']); - $contact->town = trim($fields['LVILLE']); - if ($fields['FPAYS']) - $contact->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['LPAYS']))), 'c_country', 'label', 'rowid'); - else - $contact->country_id = 1; - $contact->email = $fields['LMAIL']; - $contact->phone = trim($fields['LTEL']) ? trim($fields['LTEL']) : trim($fields['LCONTACT']); - $contact->fax = trim($fields['LFAX']) ? trim($fields['LFAX']) : trim($fields['LCONTACT']); - $contact->socid = $object->id; + $contact->zip = trim($fields['LPOSTE']); + $contact->town = trim($fields['LVILLE']); + if ($fields['FPAYS']) + $contact->country_id = dol_getIdFromCode($db, trim(ucwords(strtolower($fields['LPAYS']))), 'c_country', 'label', 'rowid'); + else + $contact->country_id = 1; + $contact->email = $fields['LMAIL']; + $contact->phone = trim($fields['LTEL']) ? trim($fields['LTEL']) : trim($fields['LCONTACT']); + $contact->fax = trim($fields['LFAX']) ? trim($fields['LFAX']) : trim($fields['LCONTACT']); + $contact->socid = $object->id; - $ret1 = $contact->create($user); - if ($ret1 > 0) { - //$ret2=$contact->add_contact($object->id, 'BILLING'); - } - if ($ret1 < 0 || $ret2 < 0) { - print " - Error in create contact result code = " . $ret1 . " " . $ret2 . " - " . $contact->errorsToString(); - $errorrecord++; - } else { - print " - create contact OK"; - } - } + $ret1 = $contact->create($user); + if ($ret1 > 0) { + //$ret2=$contact->add_contact($object->id, 'BILLING'); + } + if ($ret1 < 0 || $ret2 < 0) { + print " - Error in create contact result code = " . $ret1 . " " . $ret2 . " - " . $contact->errorsToString(); + $errorrecord++; + } else { + print " - create contact OK"; + } + } - //update date créa - if (!$errorrecord) { - $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"); - if ($retd < 1) { - print " - Error in update date créa result " . $object->errorsToString(); - $errorrecord++; - } else { - print " - update date créa OK"; - } - } - print "\n"; + //update date créa + if (!$errorrecord) { + $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"); + if ($retd < 1) { + print " - Error in update date créa result " . $object->errorsToString(); + $errorrecord++; + } else { + print " - update date créa OK"; + } + } + print "\n"; - if ($errorrecord) { - print( 'Error on record nb ' . $i . " - " . $object->errorsToString() . "\n"); - var_dump($db, $object, $contact); -// $db->rollback(); - die(); - $error++; // $errorrecord will be reset - } - $j++; - } else + if ($errorrecord) { + print( 'Error on record nb ' . $i . " - " . $object->errorsToString() . "\n"); + var_dump($db, $object, $contact); + // $db->rollback(); + die(); + $error++; // $errorrecord will be reset + } + $j++; +} else die("error : $sql"); $db->commit(); diff --git a/dev/initdata/includes/dbase.class.php b/dev/initdata/includes/dbase.class.php index 99cc4480b5f..ba0e18db15d 100644 --- a/dev/initdata/includes/dbase.class.php +++ b/dev/initdata/includes/dbase.class.php @@ -8,7 +8,8 @@ define('DBASE_RDWR', 2); define('DBASE_TYPE_DBASE', 0); define('DBASE_TYPE_FOXPRO', 1); -class DBase { +class DBase +{ private $fd; private $headerLength = 0; @@ -18,7 +19,8 @@ class DBase { private $recordCount = 0; //resource dbase_open ( string $filename , int $mode ) - public static function open($filename, $mode) { + public static function open($filename, $mode) + { if (!file_exists($filename)) return false; $modes = array('r', 'w', 'r+'); @@ -30,7 +32,8 @@ class 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)) return false; $fd = fopen($filename, 'c+'); @@ -93,7 +96,8 @@ class DBase { } // Create DBase instance - private function __construct($fd) { + private function __construct($fd) + { $this->fd = $fd; // Byte 4-7 (32-bit number): Number of records in the database file. Currently 0 fseek($this->fd, 4, SEEK_SET); @@ -116,27 +120,32 @@ class DBase { } //bool dbase_close ( resource $dbase_identifier ) - public function close() { + public function close() + { fclose($this->fd); } //array dbase_get_header_info ( resource $dbase_identifier ) - public function get_header_info() { + public function get_header_info() + { return $this->fields; } //int dbase_numfields ( resource $dbase_identifier ) - public function numfields() { + public function numfields() + { return $this->fieldCount; } //int dbase_numrecords ( resource $dbase_identifier ) - public function numrecords() { + public function numrecords() + { return $this->recordCount; } //bool dbase_add_record ( resource $dbase_identifier , array $record ) - public function add_record($record) { + public function add_record($record) + { if (count($record) != $this->fieldCount) return false; // 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 ) - public function replace_record($record, $record_number) { + public function replace_record($record, $record_number) + { if (count($record) != $this->fieldCount) return false; if ($record_number < 1 || $record_number > $this->recordCount) @@ -164,7 +174,8 @@ class DBase { } //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) return false; 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 ) - public function get_record($record_number) { + public function get_record($record_number) + { if ($record_number < 1 || $record_number > $this->recordCount) return false; fseek($this->fd, $this->headerLength + ($this->recordLength * ($record_number - 1))); @@ -186,7 +198,7 @@ class DBase { $value = strtolower($value); if ($value == 't' || $value == 'y') $value = true; - else if ($value == 'f' || $value == 'n') + elseif ($value == 'f' || $value == 'n') $value = false; else $value = null; @@ -197,7 +209,8 @@ class DBase { } //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) return false; $record = $this->get_record($record_number); @@ -209,7 +222,8 @@ class DBase { } //bool dbase_pack ( resource $dbase_identifier ) - public function pack() { + public function pack() + { $in_offset = $out_offset = $this->headerLength; $new_count = 0; $rec_count = $this->recordCount; @@ -236,7 +250,8 @@ class DBase { * A few utilitiy functions */ - private static function length($field) { + private static function length($field) + { switch ($field[1]) { case 'D': // Date: Numbers and a character to separate month, day, and year (stored internally as 8 digits in YYYYMMDD format) return 8; @@ -257,15 +272,18 @@ class DBase { * Functions for reading and writing bytes */ - private static function getChar8($fd) { + private static function getChar8($fd) + { return ord(fread($fd, 1)); } - private static function putChar8($fd, $value) { + private static function putChar8($fd, $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); $i = unpack("S$n", $data); if ($n == 1) @@ -274,11 +292,13 @@ class DBase { return array_merge($i); } - private static function putInt16($fd, $value) { + private static function putInt16($fd, $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); $i = unpack("L$n", $data); if ($n == 1) @@ -287,15 +307,18 @@ class DBase { return array_merge($i); } - private static function putInt32($fd, $value) { + private static function putInt32($fd, $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)); } - private function putRecord($record) { + private function putRecord($record) + { foreach ($this->fields as $i => &$field) { $value = $record[$i]; // Number types are right aligned with spaces @@ -306,57 +329,68 @@ class DBase { } return true; } - } if (!function_exists('dbase_open')) { - function dbase_open($filename, $mode) { + function 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); } - function dbase_close($dbase_identifier) { + function dbase_close($dbase_identifier) + { return $dbase_identifier->close(); } - function dbase_get_header_info($dbase_identifier) { + function dbase_get_header_info($dbase_identifier) + { return $dbase_identifier->get_header_info(); } - function dbase_numfields($dbase_identifier) { + function dbase_numfields($dbase_identifier) + { $dbase_identifier->numfields(); } - function dbase_numrecords($dbase_identifier) { + function dbase_numrecords($dbase_identifier) + { return $dbase_identifier->numrecords(); } - function dbase_add_record($dbase_identifier, $record) { + function dbase_add_record($dbase_identifier, $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); } - 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); } - function dbase_get_record($dbase_identifier, $record_number) { + function dbase_get_record($dbase_identifier, $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); } - function dbase_pack($dbase_identifier) { + function dbase_pack($dbase_identifier) + { return $dbase_identifier->pack(); } -} \ No newline at end of file +}