/** * Create a expedition line * * @param int $entrepot_id Id of warehouse * @param int $origin_line_id Id of source line * @param int $qty Quantity * @param array $array_options extrafields array * @return int <0 if KO, >0 if OK */ function create_line($entrepot_id, $origin_line_id, $qty, $array_options = 0) { global $conf; $error = 0; $sql = "INSERT INTO " . MAIN_DB_PREFIX . "expeditiondet ("; $sql .= "fk_expedition"; $sql .= ", fk_entrepot"; $sql .= ", fk_origin_line"; $sql .= ", qty"; $sql .= ") VALUES ("; $sql .= $this->id; $sql .= ", " . ($entrepot_id ? $entrepot_id : 'null'); $sql .= ", " . $origin_line_id; $sql .= ", " . $qty; $sql .= ")"; dol_syslog(get_class($this) . "::create_line", LOG_DEBUG); if (!$this->db->query($sql)) { $error++; } if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) { $expeditionline = new ExpeditionLigne($this->db); $expeditionline->array_options = $array_options; $expeditionline->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $expeditionline->table_element); $result = $expeditionline->insertExtraFields(); if ($result < 0) { $this->error[] = $expeditionline->error; $error++; } } if (!$error) { return 1; } else { return -1; } }