$newpsq = empty($newpsq) ? 0 : $newpsq; break; // We found submited price } } } else { $level = 0; $newprice = price2num($_POST["price"], 'MU'); $newprice_min = price2num($_POST["price_min"], 'MU'); $newpricebase = $_POST["price_base_type"]; $newnpr = preg_match('/\\*/', $_POST["tva_tx"]) ? 1 : 0; $newvat = str_replace('*', '', $_POST["tva_tx"]); $newpsq = GETPOST('psqflag'); $newpsq = empty($newpsq) ? 0 : $newpsq; } if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0) { $action = ''; $mesg = '<div class="ok">' . $langs->trans("RecordSaved") . '</div>'; } else { $action = 'edit_price'; $mesg = '<div class="error">' . $object->error . '</div>'; } } else { if ($action == 'delete' && $user->rights->produit->supprimer) { $result = $object->log_price_delete($user, $_GET["lineid"]); if ($result < 0) { $mesg = '<div class="error">' . $object->error . '</div>'; } } } /**
$newprice = price2num($objectstatic->multiprices_ttc[$level], 'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) $newminprice = $objectstatic->multiprices_min_ttc[$level]; } else { $newprice = price2num($objectstatic->multiprices[$level], 'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) $newminprice = $objectstatic->multiprices_min[$level]; } if ($newminprice > $newprice) { $newminprice = $newprice; } $newvat = str_replace('*', '', $newvatrate); $newnpr = $objectstatic->multiprices_recuperableonly[$level]; $newlevel = $level; //print "$objectstatic->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr<br>\n"; $retm = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr); if ($retm < 0) { $error++; break; } if ($newlevel == 1) { $updatelevel1 = true; } } // Update single price $price_base_type = $objectstatic->price_base_type; // Get price_base_type of product/service to keep the same for update if ($price_base_type == 'TTC') { $newprice = price2num($objectstatic->price_ttc, 'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) $newminprice = $objectstatic->price_min_ttc;
/** * Update a product or service * * @param array $authentication Array of authentication information * @param Product $product Product * @return array Array result */ function updateProductOrService($authentication, $product) { global $db, $conf, $langs; $now = dol_now(); dol_syslog("Function: updateProductOrService login="******"You must choose between price or price_net to provide price."; } if ($product['barcode'] && !$product['barcode_type']) { $errror++; $errorcode = 'KO'; $errorlabel = "You must set a barcode type when setting a barcode."; } if (!$error) { include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; $newobject = new Product($db); $newobject->fetch($product['id']); if (isset($product['ref'])) { $newobject->ref = $product['ref']; } if (isset($product['ref_ext'])) { $newobject->ref_ext = $product['ref_ext']; } $newobject->type = $product['type']; $newobject->libelle = $product['label']; // @deprecated $newobject->label = $product['label']; $newobject->description = $product['description']; $newobject->note = $product['note']; $newobject->status = $product['status_tosell']; $newobject->status_buy = $product['status_tobuy']; $newobject->price = $product['price_net']; $newobject->price_ttc = $product['price']; $newobject->tva_tx = $product['vat_rate']; $newobject->price_base_type = $product['price_base_type']; $newobject->date_creation = $now; if ($product['barcode']) { $newobject->barcode = $product['barcode']; $newobject->barcode_type = $product['barcode_type']; } $newobject->stock_reel = $product['stock_real']; $newobject->pmp = $product['pmp']; $newobject->seuil_stock_alert = $product['stock_alert']; $newobject->country_id = $product['country_id']; if ($product['country_code']) { $newobject->country_id = getCountry($product['country_code'], 3); } $newobject->customcode = $product['customcode']; $newobject->canvas = $product['canvas']; /*foreach($product['lines'] as $line) { $newline=new FactureLigne($db); $newline->type=$line['type']; $newline->desc=$line['desc']; $newline->fk_product=$line['fk_product']; $newline->total_ht=$line['total_net']; $newline->total_vat=$line['total_vat']; $newline->total_ttc=$line['total']; $newline->vat=$line['vat_rate']; $newline->qty=$line['qty']; $newline->fk_product=$line['product_id']; }*/ //var_dump($product['ref_ext']); //var_dump($product['lines'][0]['type']); $extrafields = new ExtraFields($db); $extralabels = $extrafields->fetch_name_optionals_label('product', true); foreach ($extrafields->attribute_label as $key => $label) { $key = 'options_' . $key; $newobject->array_options[$key] = $product[$key]; } $db->begin(); $result = $newobject->update($newobject->id, $fuser); if ($result <= 0) { $error++; } else { // Update stock if stock count is provided and differs from database after creation or update if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) { require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; $savstockreal = $newobject->stock_reel; $newobject->load_stock(); // This overwrite ->stock_reel $getstockreal = $newobject->stock_reel; if ($savstockreal != $getstockreal) { $warehouse = new Entrepot($this->db); $warehouse->fetch(0, $product['warehouse_ref']); if ($warehouse->id > 0) { if ($savstockreal - $getstockreal > 0) { $result = $newobject->correct_stock($fuser, $warehouse->id, $savstockreal - $getstockreal, 0, 'Correction from external call (Web Service)', 0, 'WS' . dol_print_date($now, 'dayhourlog')); } if ($savstockreal - $getstockreal > 0) { $result = $newobject->correct_stock($fuser, $warehouse->id, $savstockreal - $getstockreal, 1, 'Correction from external call (Web Service)', 0, 'WS' . dol_print_date($now, 'dayhourlog')); } if ($result <= 0) { $error++; $newobject->error = 'You set a different value for stock, but correction of stock count (before=' . $getstockreal . ', after=' . $savstockreal . ') fails with error ' . $newobject->error; } } else { $error++; $newobject->error = 'You set a different value for stock but we failed to find warehouse ' . $product['warehouse_ref'] . ' to make correction.'; } } } } if (!$error) { if ($newobject->price_base_type == 'HT') { $result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser); if ($result <= 0) { $error++; } } elseif ($newobject->price_base_type == 'TTC') { $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type); if ($result <= 0) { $error++; } } } if (!$error) { $db->commit(); $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref); } else { $db->rollback(); $error++; $errorcode = 'KO'; $errorlabel = $newobject->error; } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }
function import2Dolibarr($object, $typeimport) { global $conf; global $langs; $this->process_msg = ''; $error = 0; $fp = @fopen($this->filename, "r"); if ($fp) { switch ($object) { case 'ImportStock': $doliprod = new Product($this->db); $i = 0; while ($ligne = fgetcsv($fp, 1000, ";")) { $doliprod->id = ''; $i++; if ($this->firstline && $i == 1) { continue; } if ($conf->global->IMPORT_BARCODE) { $ligne[0] = $this->get_product_by_barcode($ligne[0]); } if ($doliprod->fetch('', $ligne[0]) <= 0) { $this->process_msg .= $langs->trans("ErrProdNoExist", $ligne[0], $doliprod->error) . "\n"; } else { $pid = $doliprod->id; $doliprod->ref = $ligne[0]; $entrepot = $ligne[1]; $newstock = $ligne[2]; $price = $ligne[3]; if ($conf->global->IMPORT_TOTAL_STOCK) { $doliprod->load_stock(); dol_syslog("stock produit " . $doliprod->stock_warehouse[$entrepot]->real . " entrepot " . $entrepot . " " . $doliprod->stock_reel, LOG_DEBUG); // correction de stock $delta = 0; if ($newstock > $doliprod->stock_warehouse[$entrepot]->real) { $delta = $newstock - $doliprod->stock_warehouse[$entrepot]->real; $sens = 0; } elseif ($newstock < $doliprod->stock_warehouse[$entrepot]->real) { $delta = $doliprod->stock_warehouse[$entrepot]->real - $newstock; $sens = 1; } if ($delta) { $res = $doliprod->correct_stock($this->user, $entrepot, $delta, $sens, $langs->trans("StockCorrection"), $price); if ($res < 0) { $this->process_msg .= $langs->trans("ErrMovStock", $ligne[0], $doliprod->error) . "\n"; $error++; } } dol_syslog("maj stock delta = " . $delta . " sens " . $sens, LOG_DEBUG); } else { $res = $doliprod->correct_stock($this->user, $entrepot, abs($newstock), $newstock > 0 ? 0 : 1, $langs->trans("StockCorrection"), $price); if ($res < 0) { $this->process_msg .= $langs->trans("ErrMovStock", $ligne[0], $doliprod->error) . "\n"; $error++; } } } } break; case 'ImportProduct': //$doliprod = new Product($this->db); $i = 0; while ($ligne = fgetcsv($fp, 1000, ";")) { $i++; $doliprod = new Product($this->db); $doliprod->id = ''; if ($this->firstline && $i == 1) { continue; } if ($doliprod->fetch('', $ligne[0]) < 0) { $this->process_msg .= $langs->trans("ErrProdNoExist", $ligne[0], $doliprod->error) . "\n"; } else { $pid = $doliprod->id; $doliprod->ref = $ligne[0]; if (!empty($ligne[1])) { $doliprod->libelle = $ligne[1]; } if (!empty($ligne[2])) { $doliprod->status = $ligne[2]; } $doliprod->status_buy = 1; if (!empty($ligne[3])) { $doliprod->description = $ligne[3]; } if (!empty($ligne[4])) { $doliprod->price = $ligne[4]; } if (!empty($ligne[5])) { $doliprod->tva_tx = $ligne[5]; } if (!empty($ligne[6])) { $doliprod->weight = $ligne[6]; } if (!empty($ligne[7])) { $doliprod->volume = $ligne[7]; } if (!empty($ligne[9])) { $doliprod->barcode = $ligne[9]; } if (!empty($ligne[9])) { $doliprod->barcode_type = dol_getIdFromCode($this->db, $ligne[10], 'c_barcode_type', 'libelle', 'rowid'); } if (!empty($ligne[10])) { $doliprod->type = $ligne[11]; } $doliprod->price_base_type = 'HT'; $this->db->begin; switch ($typeimport) { case 'C': if ($pid > 0) { if ($doliprod->update($pid, $this->user) < 0) { $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n"; $error++; } if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0) { $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n"; $error++; } } else { if ($doliprod->create($this->user) < 0) { $this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error) . "\n"; $error++; } else { // image et code barre if ($ligne[8]) { $this->add_photo_web($conf->produit->dir_output, $ligne[8], $doliprod->id); } /*if ($ligne[9]) { if ($doliprod->setValueFrom('fk_barcode_type', 2) < 0){ $this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n"; // TODO paramétrer $error++; } if ($doliprod->setValueFrom('barcode', $ligne[9]) < 0 ){ $this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n"; $error++; } }*/ } } break; /*case 'M': if ($pid>0) { if ($doliprod->update($pid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } if (version_compare(DOL_VERSION, 3.5) >= 0){ if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } } else{ if ($doliprod->updatePrice($doliprod->id, $doliprod->price, $doliprod->price_base_type, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrProdNoExist", $ligne[0])."\n"; break;*/ /*case 'M': if ($pid>0) { if ($doliprod->update($pid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } if (version_compare(DOL_VERSION, 3.5) >= 0){ if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } } else{ if ($doliprod->updatePrice($doliprod->id, $doliprod->price, $doliprod->price_base_type, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrProdNoExist", $ligne[0])."\n"; break;*/ case 'D': if ($pid > 0) { if ($doliprod->delete($pid) < 0) { $this->process_msg .= $langs->trans("ErrProductDelete", $ligne[0], $doliprod->error) . "\n"; $error++; } } else { $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ErrProdNoExist", $ligne[0]) . "\n"; } } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } } // while break; case 'ImportThirtdparty': $i = 0; //$societe = new Societe($this->db); while ($ligne = fgetcsv($fp, 1000, ";")) { $i++; $societe = new Societe($this->db); if ($this->firstline && $i == 1) { continue; } if (!$ligne[0]) { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrNameRequired") . "\n"; continue; } // vérifier par code_client if ($ligne[13]) { $sid = $this->get_socbyclientcode($ligne[13]); } else { if ($ligne[14]) { $sid = $this->get_socbysuplliercode($ligne[14]); } } if ($sid > 0) { $societe->fetch($sid); } else { $sid = $societe->fetch('', $ligne[0]); } if ($ligne[12]) { $pid = dol_getIdFromCode($this->db, $ligne[12], "c_pays", "code", "rowid"); } else { $pid = ''; } if ($pid <= 0) { $pid = ''; } $did = ''; $societe->id = $sid; $societe->name = $ligne[0]; $societe->particulier = 0; //Société $societe->address = $ligne[1] . "\n" . $ligne[2] . "\n" . $ligne[3]; $societe->zip = $ligne[4]; $societe->town = $ligne[5]; $societe->state_id = $did; if ($ligne[12]) { $societe->country_code = $ligne[12]; } $societe->country_id = $pid; dol_syslog("codes {$pid} " . $lige[12], LOG_DEBUG); $societe->phone = $ligne[6]; $societe->fax = $ligne[7]; $societe->email = $ligne[8]; $societe->url = $ligne[9]; $societe->idprof1 = $ligne[10]; switch ($ligne[11]) { case '0': $societe->fournisseur = 0; $societe->client = $ligne[11]; break; case '1': $societe->fournisseur = 0; $societe->client = $ligne[11]; break; case '2': $societe->fournisseur = 0; $societe->client = $ligne[11]; break; case '10': $societe->client = 0; $societe->fournisseur = 1; break; default: break; } if ($ligne[13]) { $societe->code_client = $ligne[13]; } if ($ligne[14]) { $societe->code_fournisseur = $ligne[14]; } /*if ($ligne[15]) $societe->array_options["options_zone"]=$ligne[15]; if (!empty($ligne[16])) $societe->array_options["options_CA"]=$ligne[16]; if (!empty($ligne[17])) { if ($ligne[17] <= 5) $societe->effectif_id = 1; elseif ($ligne[17] <= 10) $societe->effectif_id = 2; elseif ($ligne[17] <= 50) $societe->effectif_id = 3; elseif ($ligne[17] <= 100) $societe->effectif_id = 4; elseif ($ligne[17] <= 500) $societe->effectif_id = 5; else $societe->effectif_id = 7; } dol_syslog("effectif " . $lige[17].' '.$societe->effectif_id." ".print_r($societe->array_options, true), LOG_DEBUG);*/ $this->db->begin; switch ($typeimport) { case 'C': if ($sid > 0) { if ($societe->update($sid, $this->user) < 0) { $this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error) . "\n"; $error++; } } elseif ($societe->create($this->user) < 0) { $this->process_msg .= $langs->trans("ErrCompanyCreate", $ligne[0], $societe->error) . "\n"; $error++; } break; /*case 'M': if ($sid>0) { if ($societe->update($sid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error)."\n"; $error++; } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("CompanyNoExist", $ligne[0])."\n"; break;*/ /*case 'M': if ($sid>0) { if ($societe->update($sid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error)."\n"; $error++; } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("CompanyNoExist", $ligne[0])."\n"; break;*/ case 'D': if ($sid > 0) { if ($societe->delete($sid) < 0) { $this->process_msg .= $langs->trans("ErrCompanyDelete", $ligne[0], $societe->error) . "\n"; $error++; } } else { $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("CompanyNoExist", $ligne[0]) . "\n"; } } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } break; case 'ImportContact': $i = 0; //$contact=new Contact($this->db); //$societe = new Societe($this->db); while ($ligne = fgetcsv($fp, 1000, ";")) { $i++; $contact = new Contact($this->db); $societe = new Societe($this->db); if ($this->firstline && $i == 1) { continue; } //if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n"; if ($ligne[0]) { $socid = $this->get_socbyclientcode($ligne[0]); } else { if ($ligne[1]) { $socid = $this->get_socbysuplliercode($ligne[1]); } } if ($socid < 0) { $this->process_msg .= $i . " " . $langs->trans("ErrCompanyRequired") . "\n"; } else { $societe->fetch($socid); } if (!$societe->id) { $this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0] . " " . $ligne[1]) . "\n"; continue; } if (empty($ligne[2])) { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrNameRequired") . "\n"; continue; } $contactid = $this->get_contact_id($socid, $ligne[2], $ligne[3]); $contact->id = $contactid; $contact->civilite_id = $ligne[4]; $contact->lastname = $ligne[2]; $contact->firstname = $ligne[3]; if ($ligne[5] || $ligne[6] || $ligne[7]) { $contact->address = $ligne[5] . "\n" . $ligne[6] . "\n" . $ligne[7]; } else { $contact->address = $societe->address; } if ($ligne[8]) { $contact->zip = $ligne[8]; } else { $contact->zip = $societe->zip; } if ($ligne[9]) { $contact->town = $ligne[9]; } else { $contact->town = $societe->town; } if ($ligne[10]) { $pid = dol_getIdFromCode($this->db, $ligne[10], "c_pays", "code", "rowid"); if ($pid <= 0) { $pid = ''; } $contact->country_id = $pid; $contact->country_code = $ligne[10]; } else { $contact->country_id = $societe->country_id; $contact->country_code = $societe->country_code; } $contact->socid = $socid; // fk_soc $contact->status = 1; $contact->email = $ligne[11]; $contact->phone_pro = $ligne[12]; $contact->fax = $ligne[13]; $contact->phone_mobile = $ligne[14]; $contact->priv = 0; $this->db - begin; switch ($typeimport) { case 'C': if ($contactid > 0) { if ($contact->update($contactid, $this->user) < 0) { $this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error) . "\n"; $error++; } } elseif ($contact->create($this->user) < 0) { $this->process_msg .= $langs->trans("ErrContactCreate", $ligne[2], $contact->error) . "\n"; $error++; } break; /*case 'M': if ($contactid>0) { if ($contact->update($contactid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error)."\n"; $error++; } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[2])."\n"; break;*/ /*case 'M': if ($contactid>0) { if ($contact->update($contactid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error)."\n"; $error++; } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[2])."\n"; break;*/ case 'D': if ($contactid > 0) { if ($contact->delete($contactid) < 0) { $this->process_msg .= $langs->trans("ErrContactDelete", $ligne[2], $contact->error) . "\n"; $error++; } } else { $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ContactNoExist", $ligne[2]) . "\n"; } } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } break; /*case 'ImportActions': $i=0; $contact=new Contact($this->db); $societe = new Societe($this->db); $actioncomm = new ActionComm($this->db); $actuser = new User($this->db); while ($ligne = fgetcsv($fp,1000,";")) { $i++; if ($this->firstline && $i== 1) continue; //if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n"; //else $socid = $societe->id; $socid = $this->get_socbyclientcode($ligne[0]); if ($socid < 0 ) $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrCompanyRequired")."\n"; else $societe->fetch($socid); $socid = $societe->id; if (!$socid) { $this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0])."\n"; continue; } //action sur un contact de la soc if ($ligne[1]) { $contactid = $this->get_contact_id($socid, $ligne[1], $ligne[2]) ; if ($contactid < 0) { $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[1].' '. $ligne[2])."\n"; // réinitialiser ?? continue; } else $contact->fetch($contactid); } $usertodo = ''; if ($ligne[9]) { $usertodo=new User($this->db); if ( $usertodo->fetch('',$ligne[9]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[9])."\n"; } $userdone= '' ; if ($ligne[10]) { $usertodo=new User($this->db); if ( $usertodo->fetch('',$ligne[10]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[10])."\n"; } $datep = ''; if ($ligne[6]) { // voir date $n = sscanf($ligne[6],"%02d/%02d/%04d", $d_day, $d_mon, $d_year); if ($n==3) $datep=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year); if (!$datep) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[6])."\n"; } else $datep =''; $datef=''; if ($ligne[7]) { // voir la date $n = sscanf($ligne[7],"%02d/%02d/%04d", $d_day, $d_mon, $d_year); if ($n==3)$datef=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year); if (!$datef) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[7])."\n"; } else $datef =''; //$datef=''; $actioncomm->societe = $societe; if ($ligne[1]) $actioncomm->contact = $contact; else $actioncomm->contact = ''; $actioncomm->type_code = $ligne[3]; $actioncomm->priority = $ligne[4]; $actioncomm->location = '' ; $actioncomm->label = $ligne[5]; $actioncomm->datep = $datep; $actioncomm->datef = $datef; $actioncomm->percentage = $ligne[8]; $actioncomm->usertodo = $usertodo; $actioncomm->userdone = $userdone; $actioncomm->note =$ligne[11]; switch ($typeimport) { case 'C': $this->db->begin(); if ($actioncomm->add($this->user) < 0) { $this->process_msg .= $langs->trans("ErrActionCreate", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; case 'M': $this->db->begin(); if($actioncomm->update($user) < 0){ $this->process_msg .= $langs->trans("ErrActionUpdate", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; case 'D': $this->db->begin(); if($actioncomm->delete() < 0){ $this->process_msg .= $langs->trans("ErrActionDelete", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; } } break;*/ /*case 'ImportActions': $i=0; $contact=new Contact($this->db); $societe = new Societe($this->db); $actioncomm = new ActionComm($this->db); $actuser = new User($this->db); while ($ligne = fgetcsv($fp,1000,";")) { $i++; if ($this->firstline && $i== 1) continue; //if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n"; //else $socid = $societe->id; $socid = $this->get_socbyclientcode($ligne[0]); if ($socid < 0 ) $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrCompanyRequired")."\n"; else $societe->fetch($socid); $socid = $societe->id; if (!$socid) { $this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0])."\n"; continue; } //action sur un contact de la soc if ($ligne[1]) { $contactid = $this->get_contact_id($socid, $ligne[1], $ligne[2]) ; if ($contactid < 0) { $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[1].' '. $ligne[2])."\n"; // réinitialiser ?? continue; } else $contact->fetch($contactid); } $usertodo = ''; if ($ligne[9]) { $usertodo=new User($this->db); if ( $usertodo->fetch('',$ligne[9]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[9])."\n"; } $userdone= '' ; if ($ligne[10]) { $usertodo=new User($this->db); if ( $usertodo->fetch('',$ligne[10]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[10])."\n"; } $datep = ''; if ($ligne[6]) { // voir date $n = sscanf($ligne[6],"%02d/%02d/%04d", $d_day, $d_mon, $d_year); if ($n==3) $datep=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year); if (!$datep) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[6])."\n"; } else $datep =''; $datef=''; if ($ligne[7]) { // voir la date $n = sscanf($ligne[7],"%02d/%02d/%04d", $d_day, $d_mon, $d_year); if ($n==3)$datef=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year); if (!$datef) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[7])."\n"; } else $datef =''; //$datef=''; $actioncomm->societe = $societe; if ($ligne[1]) $actioncomm->contact = $contact; else $actioncomm->contact = ''; $actioncomm->type_code = $ligne[3]; $actioncomm->priority = $ligne[4]; $actioncomm->location = '' ; $actioncomm->label = $ligne[5]; $actioncomm->datep = $datep; $actioncomm->datef = $datef; $actioncomm->percentage = $ligne[8]; $actioncomm->usertodo = $usertodo; $actioncomm->userdone = $userdone; $actioncomm->note =$ligne[11]; switch ($typeimport) { case 'C': $this->db->begin(); if ($actioncomm->add($this->user) < 0) { $this->process_msg .= $langs->trans("ErrActionCreate", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; case 'M': $this->db->begin(); if($actioncomm->update($user) < 0){ $this->process_msg .= $langs->trans("ErrActionUpdate", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; case 'D': $this->db->begin(); if($actioncomm->delete() < 0){ $this->process_msg .= $langs->trans("ErrActionDelete", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; } } break;*/ case 'Importtarif': // ref four $i = 0; $this->process_msg = ''; $error = 0; /*$doliprod = new Product($this->db); $product = new ProductFournisseur($this->db); $societe = new Societe($this->db);*/ while ($ligne = fgetcsv($fp, 1000, ";")) { $doliprod->id = ''; $i++; $doliprod = new Product($this->db); $product = new ProductFournisseur($this->db); $societe = new Societe($this->db); if ($this->firstline && $i == 1) { continue; } // recherche du fournisseur if ($societe->fetch('', $ligne[2]) > 0) { $sid = $societe->id; } else { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrComppanyNoExist", $ligne[2]) . "\n"; $sid = ''; } if ($doliprod->fetch('', $ligne[0]) > 0) { $pid = $doliprod->id; } else { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrProductNoExist", $ligne[0], $doliprod->error) . "\n"; $pid = ''; } if ($sid > 0 && $pid > 0) { $result = $product->fetch($doliprod->id); if ($result > 0) { $this->db->begin(); switch ($typeimport) { case 'C': $ret = $product->add_fournisseur($this->user, $sid, $ligne[1], $ligne[3]); if ($ret < 0 && $ret != -3) { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrCreatePrice", $product->error) . "\n"; $error++; } $ret = $product->update_buyprice($ligne[3], $ligne[4], $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5]); if ($ret < 0 && $ret != -3) { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrCreatePrice", $product->error) . "\n"; $error++; } break; /*case 'M': { // gestion du prix obligatoire $supplier=new Fournisseur($this->db); $result=$supplier->fetch($sid); $ret=$product->update_buyprice($ligne[3], $ligne[4] , $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5] ); if ($ret < 0) { $this->process_msg .= $langs->trans("Untreated", $i)." ".$langs->trans("Qty").$ligne[3]. ", ".$langs->trans("Price").$ligne[4]." ".$langs->trans("ErrUpdatePrice", $product->error)."\n"; $error ++; } } break;*/ /*case 'M': { // gestion du prix obligatoire $supplier=new Fournisseur($this->db); $result=$supplier->fetch($sid); $ret=$product->update_buyprice($ligne[3], $ligne[4] , $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5] ); if ($ret < 0) { $this->process_msg .= $langs->trans("Untreated", $i)." ".$langs->trans("Qty").$ligne[3]. ", ".$langs->trans("Price").$ligne[4]." ".$langs->trans("ErrUpdatePrice", $product->error)."\n"; $error ++; } } break;*/ case 'D': // suprresion de la ligne avec le même nb d'article et le même prix $sql = "SELECT pfp.rowid FROM " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp"; $sql .= " WHERE pfp.quantity = '" . $ligne[3] . "' AND pfp.ref_fourn = '" . $ligne[1]; $sql .= "' AND pfp.fk_soc = '" . $sid . "' AND pfp.fk_product='" . $pid . "'"; $sql .= " AND pfp.entity = " . $conf->entity; $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj->rowid > 0) { $result = $product->remove_product_fournisseur_price($obj->rowid); } else { $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ErrDeletePrice", $product->error) . "\n"; $error++; } } else { $this->process_msg .= "Error SQL= " . $sql . "\n"; $error++; } break; } //switch } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } // fournisseur trouvé } // traitement ligne // while reffour break; } // fin switch fclose($fp); } else { $this->error = $langs->trans("ErrOpenFile") . $nomfich; $error = -1; } return $error; }
$result['premium'] = $premium; ajaxReturn($result); exit; } elseif ($_POST['me_action'] == 'SAVEPRICE') { $target_id = tep_db_prepare_input($_POST['target_id']); $price_uvp = tep_db_prepare_input($_POST['price_uvp']); $price_default = tep_db_prepare_input($_POST['price_default']); $price_uvp_sp = $_POST['price_uvp_sp']; $price_selling_b2c = isset($_POST['price_selling_b2c']) ? $_POST['price_selling_b2c'] : array(); $price_selling_b2b = isset($_POST['price_selling_b2b']) ? $_POST['price_selling_b2b'] : array(); $price_option = $_POST['price_option']; $target_id_exp = explode('-', $target_id); $product_id = $target_id_exp[2]; $product = new Product($product_id); if (!SERVER_IS_LOCAL) { $product->updatePrice($price_uvp, $price_default); } foreach ($price_selling_b2c as $spid => $price) { $show_discount = $price_option[$spid] == 'true'; $product->updatePriceSelling($spid, $price_uvp_sp[$spid], $price, $show_discount); } foreach ($price_selling_b2b as $spid => $prices) { $activate_discount = $price_option[$spid] == 'true'; $product->updatePriceSellingB2B($spid, $prices['nd'], $prices['d'], $activate_discount); } $message = 'Price has been saved successfully'; $product_table = drawProductPriceTable($product, $message); echo utf8_encode($product_table); exit; } elseif ($_POST['me_action'] == 'PREVIEWPRICE') { $price = tep_db_prepare_input($_POST['price']);
$ret=$object->fetch($obj->rowid); if ($ret) { if ($price_base_type == 'TTC') { $newprice=price2num($object->price_ttc,'MU'); // Second param must be MU (we want a unit price so 'MT'. If unit price was on 4 decimal, we must keep 4 decimals) } else { $newprice=price2num($object->price,'MU'); // Second param must be MU (we want a unit price so 'MT'. If unit price was on 4 decimal, we must keep 4 decimals) } $newvat=str_replace('*','',$newvatrate); $ret=$object->updatePrice($object->id, $newprice, $price_base_type, $user, $newvat); if ($ret < 0) $error++; } $i++; } if (! $error) { $db->commit(); } else { $db->rollback(); } }
break; // We found submited price } } } else { $level=0; $newprice=price2num($_POST["price"],'MU'); $newprice_min=price2num($_POST["price_min"],'MU'); $newpricebase=$_POST["price_base_type"]; $newnpr=(preg_match('/\*/',$_POST["tva_tx"]) ? 1 : 0); $newvat=str_replace('*','',$_POST["tva_tx"]); $newecotax=price2num($_POST["ecotax"],'MU'); } if ($object->updatePrice($object->id, $newprice, $newpricebase, $user, $newvat, $newprice_min, $newecotax, $level, $newnpr) > 0) { $action = ''; $mesg = '<div class="ok">'.$langs->trans("RecordSaved").'</div>'; } else { $action = 'edit_price'; $mesg = '<div class="error">'.$object->error.'</div>'; } } else if ($action == 'delete' && $user->rights->produit->supprimer) { $result=$object->log_price_delete($user,$_GET["lineid"]); if ($result < 0) $mesg='<div class="error">'.$object->error.'</div>'; }