Merge remote-tracking branch 'origin/3.7' into develop

Conflicts:
	htdocs/compta/facture.php
	htdocs/fourn/class/fournisseur.product.class.php
This commit is contained in:
Laurent Destailleur 2015-02-28 03:11:15 +01:00
commit ef14e4e7ed
31 changed files with 2338 additions and 2254 deletions

View File

@ -302,6 +302,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
// Check if we need to also synchronize user information // Check if we need to also synchronize user information
$nosyncuser=0; $nosyncuser=0;
@ -471,6 +472,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
// Check parameters // Check parameters
if (empty($morphy) || $morphy == "-1") { if (empty($morphy) || $morphy == "-1") {

View File

@ -89,6 +89,7 @@ if ($action == 'add' && $user->rights->adherent->configurer)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$adht); $ret = $extrafields->setOptionalsFromPost($extralabels,$adht);
if ($ret < 0) $error++;
if ($adht->libelle) if ($adht->libelle)
{ {
@ -126,6 +127,7 @@ if ($action == 'update' && $user->rights->adherent->configurer)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$adht); $ret = $extrafields->setOptionalsFromPost($extralabels,$adht);
if ($ret < 0) $error++;
$adht->update($user); $adht->update($user);

View File

@ -127,6 +127,7 @@ if ($action == 'add' && $user->rights->categorie->creer)
if ($parent != "-1") $object->fk_parent = $parent; if ($parent != "-1") $object->fk_parent = $parent;
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! $object->label) if (! $object->label)
{ {

View File

@ -90,6 +90,7 @@ if ($action == 'update' && $user->rights->categorie->creer)
if (empty($categorie->error)) if (empty($categorie->error))
{ {
$ret = $extrafields->setOptionalsFromPost($extralabels,$categorie); $ret = $extrafields->setOptionalsFromPost($extralabels,$categorie);
if ($ret < 0) $error++;
if ($categorie->update($user) > 0) if ($categorie->update($user) > 0)
{ {

View File

@ -275,6 +275,7 @@ if ($action == 'add')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! $error) if (! $error)
{ {
@ -430,6 +431,7 @@ if ($action == 'update')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! $error) if (! $error)
{ {

View File

@ -1110,10 +1110,10 @@ if (empty($reshook))
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error)
{
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('propaldao')); $hookmanager->initHooks(array('propaldao'));

View File

@ -93,6 +93,8 @@ if ($id > 0 || ! empty($ref)) {
$hookmanager->initHooks(array('ordercard','globalcard')); $hookmanager->initHooks(array('ordercard','globalcard'));
$permissionnote = $user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php $permissionnote = $user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php
$permissionedit = $user->rights->commande->creer; // Used by the include of actions_lineupdown.inc.php
/* /*
* Actions * Actions
@ -104,7 +106,11 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook)) if (empty($reshook))
{ {
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once if ($cancel) $action='';
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
// Action clone object // Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->commande->creer) if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->commande->creer)
@ -281,8 +287,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) if (! $error)
{ {
@ -375,10 +380,10 @@ if (empty($reshook))
} else { } else {
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error)
{
$object_id = $object->create($user); $object_id = $object->create($user);
// If some invoice's lines already known // If some invoice's lines already known
@ -1046,56 +1051,7 @@ if (empty($reshook))
} }
} }
/* if ($action == 'builddoc') // In get or post
* Ordonnancement des lignes
*/
else if ($action == 'up' && $user->rights->commande->creer) {
$object->line_up(GETPOST('rowid'));
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '#' . GETPOST('rowid'));
exit();
}
else if ($action == 'down' && $user->rights->commande->creer) {
$object->line_down(GETPOST('rowid'));
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '#' . GETPOST('rowid'));
exit();
}
else if ($action == 'builddoc') // In get or post
{ {
/* /*
* Generate order document * Generate order document
@ -1126,8 +1082,10 @@ if (empty($reshook))
} }
// Remove file in doc form // Remove file in doc form
else if ($action == 'remove_file') { if ($action == 'remove_file')
if ($object->id > 0) { {
if ($object->id > 0)
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$langs->load("other"); $langs->load("other");
@ -1142,14 +1100,15 @@ if (empty($reshook))
} }
} }
else if ($action == 'update_extras') { if ($action == 'update_extras')
{
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error)
{
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('orderdao')); $hookmanager->initHooks(array('orderdao'));

View File

@ -646,7 +646,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error ++; if ($ret < 0) $error++;
// Replacement invoice // Replacement invoice
if ($_POST['type'] == Facture::TYPE_REPLACEMENT) if ($_POST['type'] == Facture::TYPE_REPLACEMENT)
@ -1788,8 +1788,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) { if (! $error) {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)

View File

@ -200,6 +200,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! GETPOST("lastname")) if (! GETPOST("lastname"))
{ {
@ -303,6 +304,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
$result = $object->update($contactid, $user); $result = $object->update($contactid, $user);

View File

@ -359,6 +359,7 @@ if ($action == 'add' && $user->rights->contrat->creer)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error++;
$result = $object->create($user); $result = $object->create($user);
if ($result > 0) if ($result > 0)
@ -725,19 +726,20 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra
// Fill array 'array_options' with data from update form // Fill array 'array_options' with data from update form
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0) if ($ret < 0) $error++;
$error ++;
if (! $error) {
if (! $error)
{
$result = $object->insertExtraFields(); $result = $object->insertExtraFields();
if ($result < 0) { if ($result < 0)
$error ++; {
$error++;
} }
} else if ($reshook < 0) }
$error ++; else if ($reshook < 0) $error++;
if ($error) { if ($error)
{
$action = 'edit_extras'; $action = 'edit_extras';
setEventMessage($object->error,'errors'); setEventMessage($object->error,'errors');
} }

View File

@ -23,7 +23,7 @@
// $action must be defined // $action must be defined
// $permission must be defined to permission to edit object // $permissionnote must be defined to permission to edit object
// $object must be defined (object is loaded in this file with fetch) // $object must be defined (object is loaded in this file with fetch)
// $id must be defined (object is loaded in this file with fetch) // $id must be defined (object is loaded in this file with fetch)

View File

@ -2568,9 +2568,10 @@ abstract class CommonObject
* @param string $buyer Object of buyer third party * @param string $buyer Object of buyer third party
* @param string $selected Object line selected * @param string $selected Object line selected
* @param int $dateSelector 1=Show also date range input fields * @param int $dateSelector 1=Show also date range input fields
* @param int $permtoedit Permission to edit line
* @return void * @return void
*/ */
function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0, $permtoedit=0)
{ {
global $conf, $hookmanager, $inputalsopricewithtax, $usermargins, $langs, $user; global $conf, $hookmanager, $inputalsopricewithtax, $usermargins, $langs, $user;
@ -2659,7 +2660,7 @@ abstract class CommonObject
} }
else else
{ {
$this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline,$permtoedit);
} }
$i++; $i++;
@ -2680,9 +2681,10 @@ abstract class CommonObject
* @param string $buyer Object of buyer third party * @param string $buyer Object of buyer third party
* @param string $selected Object line selected * @param string $selected Object line selected
* @param object $extrafieldsline Object of extrafield line attribute * @param object $extrafieldsline Object of extrafield line attribute
* @param int $permtoedit Permission to edit
* @return void * @return void
*/ */
function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0,$permtoedit=0)
{ {
global $conf,$langs,$user,$object,$hookmanager; global $conf,$langs,$user,$object,$hookmanager;
global $form,$bc,$bcdd; global $form,$bc,$bcdd;
@ -3502,7 +3504,8 @@ abstract class CommonObject
/** /**
* Add/Update all extra fields values for the current object. * Add/Update all extra fields values for the current object.
* All data to describe values to insert are stored into $this->array_options=array('keyextrafield'=>'valueextrafieldtoadd') * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
* This function delte record with all extrafields and insert them again from the array $this->array_options.
* *
* @return int -1=error, O=did nothing, 1=OK * @return int -1=error, O=did nothing, 1=OK
*/ */

View File

@ -1264,7 +1264,7 @@ class ExtraFields
* @param array $extralabels $array of extrafields * @param array $extralabels $array of extrafields
* @param object $object Object * @param object $object Object
* @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset. * @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset.
* @return int 1 if array_options set / 0 if no value * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example)
*/ */
function setOptionalsFromPost($extralabels,&$object,$onlykey='') function setOptionalsFromPost($extralabels,&$object,$onlykey='')
{ {

View File

@ -25,6 +25,8 @@
* $langs * $langs
* $dateSelector * $dateSelector
* $forceall (0 by default, 1 for supplier invoices/orders) * $forceall (0 by default, 1 for supplier invoices/orders)
* $element (used to test $user->rights->$element->creer)
* $permtoedit (used to replace test $user->rights->$element->creer)
* $senderissupplier (0 by default, 1 for supplier invoices/orders) * $senderissupplier (0 by default, 1 for supplier invoices/orders)
* $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
* $usemargins (0 to disable all margins columns, 1 to show according to margin setup) * $usemargins (0 to disable all margins columns, 1 to show according to margin setup)
@ -167,7 +169,7 @@ if (empty($usemargins)) $usemargins=0;
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo price($line->total_ht); ?></td> <td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo price($line->total_ht); ?></td>
<?php } ?> <?php } ?>
<?php if ($this->statut == 0 && $user->rights->$element->creer) { ?> <?php if ($this->statut == 0 && ($user->rights->$element->creer || $permtoedit)) { ?>
<td align="center"><?php $coldisplay++; ?> <td align="center"><?php $coldisplay++; ?>
<?php if (($line->info_bits & 2) == 2) { ?> <?php if (($line->info_bits & 2) == 2) { ?>
<?php } else { ?> <?php } else { ?>

View File

@ -214,13 +214,13 @@ class CommandeFournisseur extends CommonOrder
$sql.= " l.qty,"; $sql.= " l.qty,";
$sql.= " l.tva_tx, l.remise_percent, l.subprice,"; $sql.= " l.tva_tx, l.remise_percent, l.subprice,";
$sql.= " l.localtax1_tx, l. localtax2_tx, l.total_localtax1, l.total_localtax2,"; $sql.= " l.localtax1_tx, l. localtax2_tx, l.total_localtax1, l.total_localtax2,";
$sql.= " l.total_ht, l.total_tva, l.total_ttc,"; $sql.= " l.total_ht, l.total_tva, l.total_ttc, l.special_code, l.fk_parent_line, l.rang,";
$sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc,"; $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc,";
$sql.= " l.date_start, l.date_end"; $sql.= " l.date_start, l.date_end";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
$sql.= " WHERE l.fk_commande = ".$this->id; $sql.= " WHERE l.fk_commande = ".$this->id;
$sql.= " ORDER BY l.rowid"; $sql.= " ORDER BY l.rang, l.rowid";
//print $sql; //print $sql;
dol_syslog(get_class($this)."::fetch get lines", LOG_DEBUG); dol_syslog(get_class($this)."::fetch get lines", LOG_DEBUG);
@ -267,6 +267,11 @@ class CommandeFournisseur extends CommonOrder
$line->date_start = $this->db->jdate($objp->date_start); $line->date_start = $this->db->jdate($objp->date_start);
$line->date_end = $this->db->jdate($objp->date_end); $line->date_end = $this->db->jdate($objp->date_end);
$this->special_line = $objp->special_line;
$this->fk_parent_line = $objp->fk_parent_line;
$this->rang = $objp->rang;
$this->lines[$i] = $line; $this->lines[$i] = $line;
$i++; $i++;
@ -1117,9 +1122,10 @@ class CommandeFournisseur extends CommonOrder
* @param bool $notrigger Disable triggers * @param bool $notrigger Disable triggers
* @param int $date_start Date start of service * @param int $date_start Date start of service
* @param int $date_end Date end of service * @param int $date_end Date end of service
* @param array $array_option extrafields array
* @return int <=0 if KO, >0 if OK * @return int <=0 if KO, >0 if OK
*/ */
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null) function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_option=0)
{ {
global $langs,$mysoc; global $langs,$mysoc;
@ -1773,9 +1779,10 @@ class CommandeFournisseur extends CommonOrder
* @param int $notrigger Disable triggers * @param int $notrigger Disable triggers
* @param timestamp $date_start Date start of service * @param timestamp $date_start Date start of service
* @param timestamp $date_end Date end of service * @param timestamp $date_end Date end of service
* @param array $array_option extrafields array
* @return int < 0 if error, > 0 if ok * @return int < 0 if error, > 0 if ok
*/ */
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='') function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_option=0)
{ {
global $mysoc; global $mysoc;
dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type"); dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type");
@ -2167,6 +2174,14 @@ class CommandeFournisseur extends CommonOrder
*/ */
class CommandeFournisseurLigne extends CommonOrderLine class CommandeFournisseurLigne extends CommonOrderLine
{ {
var $db;
var $error;
public $element='commande_fournisseurdet';
public $table_element='commande_fournisseurdet';
var $oldline;
// From llx_commandedet // From llx_commandedet
var $qty; var $qty;
var $tva_tx; var $tva_tx;

View File

@ -450,7 +450,7 @@ class FactureFournisseur extends CommonInvoice
$result=$this->fetch_lines(); $result=$this->fetch_lines();
if ($result < 0) if ($result < 0)
{ {
$this->error=$this->db->error(); $this->error=$this->db->lasterror();
return -3; return -3;
} }
@ -482,11 +482,12 @@ class FactureFournisseur extends CommonInvoice
{ {
$sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx, f.tva'; $sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx, f.tva';
$sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 '; $sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 ';
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits'; $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line';
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc'; $sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid';
$sql.= ' WHERE fk_facture_fourn='.$this->id; $sql.= ' WHERE fk_facture_fourn='.$this->id;
$sql.= ' ORDER BY f.rang, f.rowid';
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
$resql_rows = $this->db->query($sql); $resql_rows = $this->db->query($sql);
@ -500,7 +501,9 @@ class FactureFournisseur extends CommonInvoice
{ {
$obj = $this->db->fetch_object($resql_rows); $obj = $this->db->fetch_object($resql_rows);
$this->lines[$i] = new stdClass(); $this->lines[$i] = new FactureFournisseurLigne($this->db);
$this->lines[$i]->id = $obj->rowid;
$this->lines[$i]->rowid = $obj->rowid; $this->lines[$i]->rowid = $obj->rowid;
$this->lines[$i]->description = $obj->description; $this->lines[$i]->description = $obj->description;
$this->lines[$i]->product_ref = $obj->product_ref; // Internal reference $this->lines[$i]->product_ref = $obj->product_ref; // Internal reference
@ -524,6 +527,9 @@ class FactureFournisseur extends CommonInvoice
$this->lines[$i]->fk_product = $obj->fk_product; $this->lines[$i]->fk_product = $obj->fk_product;
$this->lines[$i]->product_type = $obj->product_type; $this->lines[$i]->product_type = $obj->product_type;
$this->lines[$i]->info_bits = $obj->info_bits; $this->lines[$i]->info_bits = $obj->info_bits;
$this->lines[$i]->fk_parent_line = $obj->fk_parent_line;
$this->lines[$i]->special_code = $obj->special_code;
$this->lines[$i]->rang = $obj->rang;
$i++; $i++;
} }
@ -1109,11 +1115,12 @@ class FactureFournisseur extends CommonInvoice
* @param int $type Type of line (0=product, 1=service) * @param int $type Type of line (0=product, 1=service)
* @param int $rang Position of line * @param int $rang Position of line
* @param int $notrigger Disable triggers * @param int $notrigger Disable triggers
* @param array $array_option extrafields array
* @return int >0 if OK, <0 if KO * @return int >0 if OK, <0 if KO
* *
* FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order. * FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order.
*/ */
function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false) function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_option=0)
{ {
dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type", LOG_DEBUG); dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@ -1202,9 +1209,12 @@ class FactureFournisseur extends CommonInvoice
* @param int $type Type of line (0=product, 1=service) * @param int $type Type of line (0=product, 1=service)
* @param double $remise_percent Pourcentage de remise de la ligne * @param double $remise_percent Pourcentage de remise de la ligne
* @param int $notrigger Disable triggers * @param int $notrigger Disable triggers
* @param timestamp $date_start Date start of service
* @param timestamp $date_end Date end of service
* @param array $array_option extrafields array
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false) function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_option=0)
{ {
global $mysoc; global $mysoc;
dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent", LOG_DEBUG); dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent", LOG_DEBUG);
@ -1820,8 +1830,25 @@ class FactureFournisseur extends CommonInvoice
/** /**
* Class to manage line invoices * Class to manage line invoices
*/ */
class FactureFournisseurLigne extends CommonInvoiceLine class FactureFournisseurLigne extends CommonInvoice
{ {
var $db;
var $error;
public $element='facture_fourn_det';
public $table_element='facture_fourn_det';
var $oldline;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db= $db;
}
} }

View File

@ -487,12 +487,18 @@ class ProductFournisseur extends Product
* *
* @param int $prodid Product id * @param int $prodid Product id
* @param int $qty Minimum quantity * @param int $qty Minimum quantity
* @return int <0 if KO, >0 if OK * @return int <0 if KO, 0=Not found of no product id provided, >0 if OK
*/ */
function find_min_price_product_fournisseur($prodid, $qty=0) function find_min_price_product_fournisseur($prodid, $qty=0)
{ {
global $conf; global $conf;
if (empty($prodid))
{
dol_syslog("Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING);
return 0;
}
$this->product_fourn_price_id = ''; $this->product_fourn_price_id = '';
$this->product_fourn_id = ''; $this->product_fourn_id = '';
$this->fourn_ref = ''; $this->fourn_ref = '';

View File

@ -109,67 +109,72 @@ else if (! empty($socid) && $socid > 0)
} }
$permissionnote=$user->rights->fournisseur->commande->creer; // Used by the include of actions_setnotes.inc.php $permissionnote=$user->rights->fournisseur->commande->creer; // Used by the include of actions_setnotes.inc.php
$permissiontoedit=$user->rights->fournisseur->commande->creer; // Used by the include of actions_lineupdown.inc.php
/* /*
* Actions * Actions
*/ */
if ($cancel) $action='';
$parameters=array('socid'=>$socid); $parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once if (empty($reshook))
if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer)
{ {
if ($cancel) $action='';
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer)
{
$result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha')); $result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha'));
if ($result < 0) dol_print_error($db, $object->error); if ($result < 0) dol_print_error($db, $object->error);
} }
// conditions de reglement // conditions de reglement
if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer) if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer)
{ {
$result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
} }
// mode de reglement // mode de reglement
if ($action == 'setmode' && $user->rights->fournisseur->commande->creer) if ($action == 'setmode' && $user->rights->fournisseur->commande->creer)
{ {
$result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
} }
// bank account // bank account
if ($action == 'setbankaccount' && $user->rights->fournisseur->commande->creer) if ($action == 'setbankaccount' && $user->rights->fournisseur->commande->creer)
{ {
$result=$object->setBankAccount(GETPOST('fk_account', 'int')); $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
} }
// date de livraison // date de livraison
if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->creer) if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->creer)
{ {
$result=$object->set_date_livraison($user,$datelivraison); $result=$object->set_date_livraison($user,$datelivraison);
if ($result < 0) if ($result < 0)
{ {
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
// Set project // Set project
if ($action == 'classin' && $user->rights->fournisseur->commande->creer) if ($action == 'classin' && $user->rights->fournisseur->commande->creer)
{ {
$object->setProject($projectid); $object->setProject($projectid);
} }
if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer) if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
{ {
$result = $object->set_remise($user, $_POST['remise_percent']); $result = $object->set_remise($user, $_POST['remise_percent']);
} }
if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver) if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver)
{ {
if (in_array($object->statut, array(1, 2, 5, 6, 7, 9))) if (in_array($object->statut, array(1, 2, 5, 6, 7, 9)))
{ {
if ($object->statut == 1) $newstatus=0; // Validated->Draft if ($object->statut == 1) $newstatus=0; // Validated->Draft
@ -190,13 +195,13 @@ if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver)
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
} }
/* /*
* Add a line into product * Add a line into product
*/ */
if ($action == 'addline' && $user->rights->fournisseur->commande->creer) if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
{ {
$langs->load('errors'); $langs->load('errors');
$error = 0; $error = 0;
@ -221,6 +226,18 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
$qty = GETPOST('qty'.$predef); $qty = GETPOST('qty'.$predef);
$remise_percent=GETPOST('remise_percent'.$predef); $remise_percent=GETPOST('remise_percent'.$predef);
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
// Unset extrafield
if (is_array($extralabelsline)) {
// Get extra fields
foreach ($extralabelsline as $key => $value) {
unset($_POST["options_" . $key]);
}
}
if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0) if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0)
{ {
setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors'); setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors');
@ -295,7 +312,8 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
'', '',
'', '',
$date_start, $date_start,
$date_end $date_end,
$array_options
); );
} }
if ($idprod == -2 || $idprod == 0) if ($idprod == -2 || $idprod == 0)
@ -333,14 +351,14 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
{ {
$price_base_type = 'HT'; $price_base_type = 'HT';
$ht = price2num($_POST['price_ht']); $ht = price2num($_POST['price_ht']);
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end); $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end, $array_options);
} }
else else
{ {
$ttc = price2num($_POST['price_ttc']); $ttc = price2num($_POST['price_ttc']);
$ht = $ttc / (1 + ($tauxtva / 100)); $ht = $ttc / (1 + ($tauxtva / 100));
$price_base_type = 'HT'; $price_base_type = 'HT';
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end); $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options);
} }
} }
@ -401,13 +419,13 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
{ {
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
/* /*
* Mise a jour d'une ligne dans la commande * Mise a jour d'une ligne dans la commande
*/ */
if ($action == 'updateline' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel')) if ($action == 'updateline' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel'))
{ {
if ($_POST["elrowid"]) if ($_POST["elrowid"])
{ {
$line = new CommandeFournisseurLigne($db); $line = new CommandeFournisseurLigne($db);
@ -421,6 +439,17 @@ if ($action == 'updateline' && $user->rights->fournisseur->commande->creer && !
$localtax1_tx=get_localtax($_POST['tva_tx'],1,$mysoc,$object->thirdparty); $localtax1_tx=get_localtax($_POST['tva_tx'],1,$mysoc,$object->thirdparty);
$localtax2_tx=get_localtax($_POST['tva_tx'],2,$mysoc,$object->thirdparty); $localtax2_tx=get_localtax($_POST['tva_tx'],2,$mysoc,$object->thirdparty);
// Extrafields Lines
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline);
// Unset extrafield POST Data
if (is_array($extralabelsline)) {
foreach ($extralabelsline as $key => $value) {
unset($_POST["options_" . $key]);
}
}
$result = $object->updateline( $result = $object->updateline(
$_POST['elrowid'], $_POST['elrowid'],
$_POST['eldesc'], $_POST['eldesc'],
@ -435,7 +464,8 @@ if ($action == 'updateline' && $user->rights->fournisseur->commande->creer && !
isset($_POST["type"])?$_POST["type"]:$line->product_type, isset($_POST["type"])?$_POST["type"]:$line->product_type,
false, false,
$date_start, $date_start,
$date_end $date_end,
$array_option
); );
unset($_POST['qty']); unset($_POST['qty']);
unset($_POST['type']); unset($_POST['type']);
@ -475,10 +505,10 @@ if ($action == 'updateline' && $user->rights->fournisseur->commande->creer && !
dol_print_error($db,$object->error); dol_print_error($db,$object->error);
exit; exit;
} }
} }
if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer) if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
{ {
$result = $object->deleteline(GETPOST('lineid')); $result = $object->deleteline(GETPOST('lineid'));
if ($result >= 0) if ($result >= 0)
@ -508,13 +538,13 @@ if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->rights
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
exit; exit;
} }
} }
if ($action == 'confirm_valid' && $confirm == 'yes' && if ($action == 'confirm_valid' && $confirm == 'yes' &&
((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->commande->creer)) ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->commande->creer))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_order_advance->validate))) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_order_advance->validate)))
) )
{ {
$object->date_commande=dol_now(); $object->date_commande=dol_now();
$result = $object->valid($user); $result = $object->valid($user);
if ($result >= 0) if ($result >= 0)
@ -547,10 +577,10 @@ if ($action == 'confirm_valid' && $confirm == 'yes' &&
{ {
$action='confirm_approve'; $action='confirm_approve';
} }
} }
if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver) if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
{ {
$idwarehouse=GETPOST('idwarehouse', 'int'); $idwarehouse=GETPOST('idwarehouse', 'int');
$qualified_for_stock_change=0; $qualified_for_stock_change=0;
@ -598,10 +628,10 @@ if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fourniss
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
} }
if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver) if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
{ {
$result = $object->refuse($user); $result = $object->refuse($user);
if ($result > 0) if ($result > 0)
{ {
@ -612,10 +642,10 @@ if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->fournisse
{ {
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander) if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
{ {
$result = $object->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']); $result = $object->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']);
if ($result > 0) if ($result > 0)
{ {
@ -629,11 +659,11 @@ if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fournis
{ {
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer)
{ {
$result=$object->delete($user); $result=$object->delete($user);
if ($result > 0) if ($result > 0)
{ {
@ -644,11 +674,11 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisse
{ {
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
// Action clone object // Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer) if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
{ {
if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
{ {
setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors'); setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
@ -670,11 +700,11 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fournisseu
} }
} }
} }
} }
// Receive // Receive
if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner) if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner)
{ {
if ($_POST["type"]) if ($_POST["type"])
{ {
@ -700,10 +730,10 @@ if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner
{ {
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Delivery")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Delivery")), 'errors');
} }
} }
if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander) if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
{ {
$result = $object->cancel($user); $result = $object->cancel($user);
if ($result > 0) if ($result > 0)
{ {
@ -714,44 +744,10 @@ if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->fournisse
{ {
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
// Line ordering if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) // En get ou en post
if ($action == 'up' && $user->rights->fournisseur->commande->creer)
{
$object->line_up($_GET['rowid']);
$outputlangs = $langs;
if (! empty($_REQUEST['lang_id']))
{ {
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
exit;
}
if ($action == 'down' && $user->rights->fournisseur->commande->creer)
{
$object->line_down($_GET['rowid']);
$outputlangs = $langs;
if (! empty($_REQUEST['lang_id']))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
exit;
}
if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) // En get ou en post
{
// Build document // Build document
// Save last template used to generate document // Save last template used to generate document
@ -769,11 +765,11 @@ if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) // En
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
} }
// Delete file in doc form // Delete file in doc form
if ($action == 'remove_file' && $object->id > 0 && $user->rights->fournisseur->commande->creer) if ($action == 'remove_file' && $object->id > 0 && $user->rights->fournisseur->commande->creer)
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$langs->load("other"); $langs->load("other");
$upload_dir = $conf->fournisseur->commande->dir_output; $upload_dir = $conf->fournisseur->commande->dir_output;
@ -781,16 +777,16 @@ if ($action == 'remove_file' && $object->id > 0 && $user->rights->fournisseur->c
$ret=dol_delete_file($file,0,0,0,$object); $ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
} }
if ($action == 'update_extras') if ($action == 'update_extras')
{ {
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if ($ret < 0) $error++; if ($ret < 0) $error++;
if (!$error) if (! $error)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !! // FIXME le hook fait double emploi avec le trigger !!
@ -818,13 +814,13 @@ if ($action == 'update_extras')
{ {
$action = 'edit_extras'; $action = 'edit_extras';
} }
} }
/* /*
* Create an order * Create an order
*/ */
if ($action == 'add' && $user->rights->fournisseur->commande->creer) if ($action == 'add' && $user->rights->fournisseur->commande->creer)
{ {
$error=0; $error=0;
if ($socid <1) if ($socid <1)
@ -849,19 +845,26 @@ if ($action == 'add' && $user->rights->fournisseur->commande->creer)
$object->date_livraison = $datelivraison; $object->date_livraison = $datelivraison;
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
if (! $error)
{
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
}
if (! $error)
{
$id = $object->create($user); $id = $object->create($user);
if ($id < 0) if ($id < 0)
{ {
$error++; $error++;
setEventMessage($langs->trans($object->error), 'errors');
}
} }
if ($error) if ($error)
{ {
$langs->load("errors"); $langs->load("errors");
$db->rollback(); $db->rollback();
setEventMessage($langs->trans($object->error), 'errors');
$action='create'; $action='create';
$_GET['socid']=$_POST['socid']; $_GET['socid']=$_POST['socid'];
} }
@ -872,13 +875,13 @@ if ($action == 'add' && $user->rights->fournisseur->commande->creer)
exit; exit;
} }
} }
} }
/* /*
* Add file in email form * Add file in email form
*/ */
if (GETPOST('addfile')) if (GETPOST('addfile'))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
// Set tmp user directory TODO Use a dedicated directory for temp mails files // Set tmp user directory TODO Use a dedicated directory for temp mails files
@ -887,13 +890,13 @@ if (GETPOST('addfile'))
dol_add_file_process($upload_dir_tmp,0,0); dol_add_file_process($upload_dir_tmp,0,0);
$action='presend'; $action='presend';
} }
/* /*
* Remove file in email form * Remove file in email form
*/ */
if (GETPOST('removedfile')) if (GETPOST('removedfile'))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
// Set tmp user directory // Set tmp user directory
@ -903,22 +906,22 @@ if (GETPOST('removedfile'))
// TODO Delete only files that was uploaded from email form // TODO Delete only files that was uploaded from email form
dol_remove_file_process($_POST['removedfile'],0); dol_remove_file_process($_POST['removedfile'],0);
$action='presend'; $action='presend';
} }
/* /*
* Send mail * Send mail
*/ */
if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel')) if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
{ {
$langs->load('mails'); $langs->load('mails');
if ($object->id > 0) if ($object->id > 0)
{ {
// $ref = dol_sanitizeFileName($object->ref); // $ref = dol_sanitizeFileName($object->ref);
// $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; // $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
// if (is_readable($file)) // if (is_readable($file))
// { // {
if (GETPOST('sendto','alpha')) if (GETPOST('sendto','alpha'))
{ {
// Le destinataire a ete fourni via le champ libre // Le destinataire a ete fourni via le champ libre
@ -1035,7 +1038,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
setEventMessage($mesg, 'errors'); setEventMessage($mesg, 'errors');
} }
} }
/* } /* }
else else
{ {
$langs->load("other"); $langs->load("other");
@ -1057,10 +1060,10 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")), 'errors'); setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")), 'errors');
dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.'); dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
} }
} }
if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('cancel')) if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('cancel'))
{ {
$ws_url = $object->thirdparty->webservices_url; $ws_url = $object->thirdparty->webservices_url;
$ws_key = $object->thirdparty->webservices_key; $ws_key = $object->thirdparty->webservices_key;
$ws_user = GETPOST('ws_user','alpha'); $ws_user = GETPOST('ws_user','alpha');
@ -1150,10 +1153,10 @@ if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('
setEventMessage($langs->trans("RemoteOrderRef")." ".$result_order["ref"], 'mesgs'); setEventMessage($langs->trans("RemoteOrderRef")." ".$result_order["ref"], 'mesgs');
} }
} }
} }
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->commande->creer) if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->commande->creer)
{ {
if ($action == 'addcontact') if ($action == 'addcontact')
{ {
if ($object->id > 0) if ($object->id > 0)
@ -1201,6 +1204,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fourniss
dol_print_error($db); dol_print_error($db);
} }
} }
}
} }
@ -1717,7 +1721,7 @@ elseif (! empty($object->id))
// Show object lines // Show object lines
$inputalsopricewithtax=1; $inputalsopricewithtax=1;
if (! empty($object->lines)) if (! empty($object->lines))
$ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1); $ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1, $user->rights->fournisseur->commande->creer);
$num = count($object->lines); $num = count($object->lines);

View File

@ -86,29 +86,34 @@ if ($id > 0 || ! empty($ref))
} }
$permissionnote=$user->rights->fournisseur->facture->creer; // Used by the include of actions_setnotes.inc.php $permissionnote=$user->rights->fournisseur->facture->creer; // Used by the include of actions_setnotes.inc.php
$permissionedit=$user->rights->fournisseur->facture->creer; // Used by the include of actions_lineupdown.inc.php
/* /*
* Actions * Actions
*/ */
if ($cancel) $action='';
$parameters=array('socid'=>$socid); $parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once if (empty($reshook))
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes')
{ {
// if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"])) if ($cancel) $action='';
// {
// $mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>'; include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
// }
// else include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
// {
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes')
{
// if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
// {
// $mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
// }
// else
// {
$result=$object->createFromClone($id); $result=$object->createFromClone($id);
if ($result > 0) if ($result > 0)
{ {
@ -121,14 +126,14 @@ if ($action == 'confirm_clone' && $confirm == 'yes')
setEventMessage($langs->trans($object->error), 'errors'); setEventMessage($langs->trans($object->error), 'errors');
$action=''; $action='';
} }
// } // }
} }
elseif ($action == 'confirm_valid' && $confirm == 'yes' && elseif ($action == 'confirm_valid' && $confirm == 'yes' &&
((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->facture->creer)) ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->facture->creer))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_invoice_advance->validate))) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
) )
{ {
$idwarehouse=GETPOST('idwarehouse'); $idwarehouse=GETPOST('idwarehouse');
$object->fetch($id); $object->fetch($id);
@ -164,10 +169,10 @@ elseif ($action == 'confirm_valid' && $confirm == 'yes' &&
setEventMessages($object->error,$object->errors,'errors'); setEventMessages($object->error,$object->errors,'errors');
} }
} }
} }
elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer) elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
{ {
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$result=$object->delete($id); $result=$object->delete($id);
@ -180,10 +185,10 @@ elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fourn
{ {
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
elseif ($action == 'confirm_delete_line' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) elseif ($action == 'confirm_delete_line' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
{ {
$object->fetch($id); $object->fetch($id);
$ret = $object->deleteline(GETPOST('lineid')); $ret = $object->deleteline(GETPOST('lineid'));
if ($ret > 0) if ($ret > 0)
@ -197,60 +202,60 @@ elseif ($action == 'confirm_delete_line' && $confirm == 'yes' && $user->rights->
/* Fix bug 1485 : Reset action to avoid asking again confirmation on failure */ /* Fix bug 1485 : Reset action to avoid asking again confirmation on failure */
$action=''; $action='';
} }
} }
elseif ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) elseif ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->set_paid($user); $result=$object->set_paid($user);
if ($result<0) if ($result<0)
{ {
setEventMessage($object->error,'errors'); setEventMessage($object->error,'errors');
} }
} }
// Set supplier ref // Set supplier ref
if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer) if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer)
{ {
$result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha')); $result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha'));
if ($result < 0) dol_print_error($db, $object->error); if ($result < 0) dol_print_error($db, $object->error);
} }
// conditions de reglement // conditions de reglement
if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer) if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer)
{ {
$result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
} }
// mode de reglement // mode de reglement
else if ($action == 'setmode' && $user->rights->fournisseur->commande->creer) else if ($action == 'setmode' && $user->rights->fournisseur->commande->creer)
{ {
$result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
} }
// bank account // bank account
else if ($action == 'setbankaccount' && $user->rights->fournisseur->facture->creer) { else if ($action == 'setbankaccount' && $user->rights->fournisseur->facture->creer) {
$result=$object->setBankAccount(GETPOST('fk_account', 'int')); $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
} }
// Set label // Set label
elseif ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) elseif ($action == 'setlabel' && $user->rights->fournisseur->facture->creer)
{ {
$object->fetch($id); $object->fetch($id);
$object->label=$_POST['label']; $object->label=$_POST['label'];
$result=$object->update($user); $result=$object->update($user);
if ($result < 0) dol_print_error($db); if ($result < 0) dol_print_error($db);
} }
elseif ($action == 'setdatef' && $user->rights->fournisseur->facture->creer) elseif ($action == 'setdatef' && $user->rights->fournisseur->facture->creer)
{ {
$object->fetch($id); $object->fetch($id);
$object->date=dol_mktime(12,0,0,$_POST['datefmonth'],$_POST['datefday'],$_POST['datefyear']); $object->date=dol_mktime(12,0,0,$_POST['datefmonth'],$_POST['datefday'],$_POST['datefyear']);
if ($object->date_echeance && $object->date_echeance < $object->date) $object->date_echeance=$object->date; if ($object->date_echeance && $object->date_echeance < $object->date) $object->date_echeance=$object->date;
$result=$object->update($user); $result=$object->update($user);
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
elseif ($action == 'setdate_lim_reglement' && $user->rights->fournisseur->facture->creer) elseif ($action == 'setdate_lim_reglement' && $user->rights->fournisseur->facture->creer)
{ {
$object->fetch($id); $object->fetch($id);
$object->date_echeance=dol_mktime(12,0,0,$_POST['date_lim_reglementmonth'],$_POST['date_lim_reglementday'],$_POST['date_lim_reglementyear']); $object->date_echeance=dol_mktime(12,0,0,$_POST['date_lim_reglementmonth'],$_POST['date_lim_reglementday'],$_POST['date_lim_reglementyear']);
if (! empty($object->date_echeance) && $object->date_echeance < $object->date) if (! empty($object->date_echeance) && $object->date_echeance < $object->date)
@ -260,11 +265,11 @@ elseif ($action == 'setdate_lim_reglement' && $user->rights->fournisseur->factur
} }
$result=$object->update($user); $result=$object->update($user);
if ($result < 0) dol_print_error($db,$object->error); if ($result < 0) dol_print_error($db,$object->error);
} }
// Delete payment // Delete payment
elseif ($action == 'deletepaiement' && $user->rights->fournisseur->facture->creer) elseif ($action == 'deletepaiement' && $user->rights->fournisseur->facture->creer)
{ {
$object->fetch($id); $object->fetch($id);
if ($object->statut == 1 && $object->paye == 0) if ($object->statut == 1 && $object->paye == 0)
{ {
@ -275,11 +280,11 @@ elseif ($action == 'deletepaiement' && $user->rights->fournisseur->facture->cree
setEventMessage($paiementfourn->error, 'errors'); setEventMessage($paiementfourn->error, 'errors');
} }
} }
} }
// Create // Create
elseif ($action == 'add' && $user->rights->fournisseur->facture->creer) elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
{ {
$error=0; $error=0;
$datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); $datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
@ -315,7 +320,7 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) $error ++; if ($ret < 0) $error++;
$tmpproject = GETPOST('projectid', 'int'); $tmpproject = GETPOST('projectid', 'int');
@ -504,11 +509,11 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
exit; exit;
} }
} }
} }
// Edit line // Edit line
elseif ($action == 'updateline' && $user->rights->fournisseur->facture->creer) elseif ($action == 'updateline' && $user->rights->fournisseur->facture->creer)
{ {
$db->begin(); $db->begin();
$object->fetch($id); $object->fetch($id);
@ -536,17 +541,29 @@ elseif ($action == 'updateline' && $user->rights->fournisseur->facture->creer)
} }
else else
{ {
$label = $_POST['desc']; $label = $_POST['desc'];
$type = $_POST["type"]?$_POST["type"]:0; $type = $_POST["type"]?$_POST["type"]:0;
} }
$date_start=dol_mktime(GETPOST('date_start'.$date_pf.'hour'), GETPOST('date_start'.$date_pf.'min'), 0, GETPOST('date_start'.$date_pf.'month'), GETPOST('date_start'.$date_pf.'day'), GETPOST('date_start'.$date_pf.'year'));
$date_end=dol_mktime(GETPOST('date_end'.$date_pf.'hour'), GETPOST('date_end'.$date_pf.'min'), 0, GETPOST('date_end'.$date_pf.'month'), GETPOST('date_end'.$date_pf.'day'), GETPOST('date_end'.$date_pf.'year'));
$localtax1_tx= get_localtax($_POST['tauxtva'], 1, $mysoc,$object->thirdparty); $localtax1_tx= get_localtax($_POST['tauxtva'], 1, $mysoc,$object->thirdparty);
$localtax2_tx= get_localtax($_POST['tauxtva'], 2, $mysoc,$object->thirdparty); $localtax2_tx= get_localtax($_POST['tauxtva'], 2, $mysoc,$object->thirdparty);
$remise_percent=GETPOST('remise_percent'); $remise_percent=GETPOST('remise_percent');
$result=$object->updateline(GETPOST('lineid'), $label, $pu, GETPOST('tauxtva'), $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('idprod'), $price_base_type, 0, $type, $remise_percent); // Extrafields Lines
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline);
// Unset extrafield POST Data
if (is_array($extralabelsline)) {
foreach ($extralabelsline as $key => $value) {
unset($_POST["options_" . $key]);
}
}
$result=$object->updateline(GETPOST('lineid'), $label, $pu, GETPOST('tauxtva'), $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('idprod'), $price_base_type, 0, $type, $remise_percent, 0, $date_start, $date_end, $array_options);
if ($result >= 0) if ($result >= 0)
{ {
unset($_POST['label']); unset($_POST['label']);
@ -557,10 +574,10 @@ elseif ($action == 'updateline' && $user->rights->fournisseur->facture->creer)
$db->rollback(); $db->rollback();
setEventMessage($object->error,'errors'); setEventMessage($object->error,'errors');
} }
} }
elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer) elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
{ {
$db->begin(); $db->begin();
$ret=$object->fetch($id); $ret=$object->fetch($id);
@ -593,6 +610,18 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
$qty = GETPOST('qty'.$predef); $qty = GETPOST('qty'.$predef);
$remise_percent=GETPOST('remise_percent'.$predef); $remise_percent=GETPOST('remise_percent'.$predef);
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
// Unset extrafield
if (is_array($extralabelsline)) {
// Get extra fields
foreach ($extralabelsline as $key => $value) {
unset($_POST["options_" . $key]);
}
}
if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0) if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0)
{ {
setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors'); setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors');
@ -647,9 +676,10 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
$localtax2_tx= get_localtax($tvatx, 2, $mysoc,$object->thirdparty); $localtax2_tx= get_localtax($tvatx, 2, $mysoc,$object->thirdparty);
$type = $productsupplier->type; $type = $productsupplier->type;
$price_base_type = 'HT';
// TODO Save the product supplier ref into database into field ref_supplier (must rename field ref into ref_supplier first) // TODO Save the product supplier ref into database into field ref_supplier (must rename field ref into ref_supplier first)
$result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, '', '', 0, $npr); $result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, '', '', 0, $npr, $price_base_type, $type, -1, 0, $array_options);
} }
if ($idprod == -2 || $idprod == 0) if ($idprod == -2 || $idprod == 0)
{ {
@ -688,7 +718,7 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
$price_base_type = 'HT'; $price_base_type = 'HT';
//print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0 //print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0
$result=$object->addline($product_desc, $ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type); $result=$object->addline($product_desc, $ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type, -1, 0, $array_options);
} }
else else
{ {
@ -696,7 +726,7 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
$ht = $ttc / (1 + ($tva_tx / 100)); $ht = $ttc / (1 + ($tva_tx / 100));
$price_base_type = 'HT'; $price_base_type = 'HT';
//print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0 //print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0
$result=$object->addline($product_desc, $ht, $tva_tx,$localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type); $result=$object->addline($product_desc, $ht, $tva_tx,$localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type, -1, 0, $array_options);
} }
} }
@ -760,18 +790,18 @@ elseif ($action == 'addline' && $user->rights->fournisseur->facture->creer)
} }
$action = ''; $action = '';
} }
elseif ($action == 'classin') elseif ($action == 'classin')
{ {
$object->fetch($id); $object->fetch($id);
$result=$object->setProject($_POST['projectid']); $result=$object->setProject($_POST['projectid']);
} }
// Set invoice to draft status // Set invoice to draft status
elseif ($action == 'edit' && $user->rights->fournisseur->facture->creer) elseif ($action == 'edit' && $user->rights->fournisseur->facture->creer)
{ {
$object->fetch($id); $object->fetch($id);
$totalpaye = $object->getSommePaiement(); $totalpaye = $object->getSommePaiement();
@ -805,11 +835,11 @@ elseif ($action == 'edit' && $user->rights->fournisseur->facture->creer)
$action=''; $action='';
} }
} }
// Set invoice to validated/unpaid status // Set invoice to validated/unpaid status
elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer) elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer)
{ {
$result = $object->fetch($id); $result = $object->fetch($id);
if ($object->statut == 2 if ($object->statut == 2
|| ($object->statut == 3 && $object->close_code != 'replaced')) || ($object->statut == 3 && $object->close_code != 'replaced'))
@ -825,18 +855,18 @@ elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer)
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
} }
// Link invoice to order // Link invoice to order
if (GETPOST('linkedOrder')) { if (GETPOST('linkedOrder')) {
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$result = $object->add_object_linked('commande', GETPOST('linkedOrder')); $result = $object->add_object_linked('commande', GETPOST('linkedOrder'));
} }
// Add file in email form // Add file in email form
if (GETPOST('addfile')) if (GETPOST('addfile'))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
// Set tmp user directory TODO Use a dedicated directory for temp mails files // Set tmp user directory TODO Use a dedicated directory for temp mails files
@ -845,11 +875,11 @@ if (GETPOST('addfile'))
dol_add_file_process($upload_dir_tmp,0,0); dol_add_file_process($upload_dir_tmp,0,0);
$action='presend'; $action='presend';
} }
// Remove file in email form // Remove file in email form
if (! empty($_POST['removedfile'])) if (! empty($_POST['removedfile']))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
// Set tmp user directory // Set tmp user directory
@ -859,22 +889,22 @@ if (! empty($_POST['removedfile']))
// TODO Delete only files that was uploaded from email form // TODO Delete only files that was uploaded from email form
dol_remove_file_process($_POST['removedfile'],0); dol_remove_file_process($_POST['removedfile'],0);
$action='presend'; $action='presend';
} }
// Send mail // Send mail
if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
{ {
$langs->load('mails'); $langs->load('mails');
$object->fetch($id); $object->fetch($id);
$result=$object->fetch_thirdparty(); $result=$object->fetch_thirdparty();
if ($result > 0) if ($result > 0)
{ {
// $ref = dol_sanitizeFileName($object->ref); // $ref = dol_sanitizeFileName($object->ref);
// $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf'; // $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf';
// if (is_readable($file)) // if (is_readable($file))
// { // {
if ($_POST['sendto']) if ($_POST['sendto'])
{ {
// Le destinataire a ete fourni via le champ libre // Le destinataire a ete fourni via le champ libre
@ -1000,7 +1030,7 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P
setEventMessage($langs->trans('ErrorMailRecipientIsEmpty'), 'errors'); setEventMessage($langs->trans('ErrorMailRecipientIsEmpty'), 'errors');
dol_syslog('Recipient email is empty'); dol_syslog('Recipient email is empty');
} }
/* } /* }
else else
{ {
$langs->load("errors"); $langs->load("errors");
@ -1016,11 +1046,11 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P
} }
//$action = 'presend'; //$action = 'presend';
} }
// Build document // Build document
elseif ($action == 'builddoc') if ($action == 'builddoc')
{ {
// Save modele used // Save modele used
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
@ -1042,10 +1072,10 @@ elseif ($action == 'builddoc')
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
} }
// Make calculation according to calculationrule // Make calculation according to calculationrule
elseif ($action == 'calculate') if ($action == 'calculate')
{ {
$calculationrule=GETPOST('calculationrule'); $calculationrule=GETPOST('calculationrule');
$object->fetch($id); $object->fetch($id);
@ -1056,10 +1086,10 @@ elseif ($action == 'calculate')
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
} }
// Delete file in doc form // Delete file in doc form
elseif ($action == 'remove_file') if ($action == 'remove_file')
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if ($object->fetch($id)) if ($object->fetch($id))
@ -1071,15 +1101,14 @@ elseif ($action == 'remove_file')
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
} }
} }
elseif ($action == 'update_extras') if ($action == 'update_extras')
{ {
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
if ($ret < 0) $error++;
if($ret < 0) $error++;
if (!$error) if (!$error)
{ {
@ -1110,10 +1139,10 @@ elseif ($action == 'update_extras')
{ {
$action = 'edit_extras'; $action = 'edit_extras';
} }
} }
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer) if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer)
{ {
if ($action == 'addcontact') if ($action == 'addcontact')
{ {
$result = $object->fetch($id); $result = $object->fetch($id);
@ -1171,6 +1200,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fourniss
dol_print_error($db); dol_print_error($db);
} }
} }
}
} }
@ -1998,7 +2028,7 @@ else
// Show object lines // Show object lines
if (! empty($object->lines)) if (! empty($object->lines))
$ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1); $ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1, $user->rights->fournisseur->facture->creer);
$num=count($object->lines); $num=count($object->lines);

View File

@ -219,3 +219,11 @@ create table llx_facture_fourn_det_extrafields
ALTER TABLE llx_facture_fourn_det_extrafields ADD INDEX idx_facture_fourn_det_extrafields (fk_object); ALTER TABLE llx_facture_fourn_det_extrafields ADD INDEX idx_facture_fourn_det_extrafields (fk_object);
ALTER TABLE llx_facture_fourn_det ADD COLUMN special_code integer DEFAULT 0;
ALTER TABLE llx_facture_fourn_det ADD COLUMN rang integer DEFAULT 0;
ALTER TABLE llx_facture_fourn_det ADD COLUMN fk_parent_line integer NULL after fk_facture_fourn;
ALTER TABLE llx_commande_fournisseurdet ADD COLUMN special_code integer DEFAULT 0;
ALTER TABLE llx_commande_fournisseurdet ADD COLUMN rang integer DEFAULT 0;
ALTER TABLE llx_commande_fournisseurdet ADD COLUMN fk_parent_line integer NULL after fk_commande;

View File

@ -22,6 +22,7 @@ create table llx_commande_fournisseurdet
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_commande integer NOT NULL, fk_commande integer NOT NULL,
fk_parent_line integer NULL,
fk_product integer, fk_product integer,
ref varchar(50), -- supplier product ref ref varchar(50), -- supplier product ref
label varchar(255), -- product label label varchar(255), -- product label
@ -44,5 +45,7 @@ create table llx_commande_fournisseurdet
date_start datetime DEFAULT NULL, -- date debut si service date_start datetime DEFAULT NULL, -- date debut si service
date_end datetime DEFAULT NULL, -- date fin si service date_end datetime DEFAULT NULL, -- date fin si service
info_bits integer DEFAULT 0, -- TVA NPR ou non info_bits integer DEFAULT 0, -- TVA NPR ou non
special_code integer DEFAULT 0, -- code pour les lignes speciales
rang integer DEFAULT 0,
import_key varchar(14) import_key varchar(14)
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -51,7 +51,7 @@ create table llx_commandedet
buy_price_ht double(24,8) DEFAULT 0, -- buying price buy_price_ht double(24,8) DEFAULT 0, -- buying price
fk_product_fournisseur_price integer DEFAULT NULL, -- reference of supplier price when line was added (may be used to update buy_price_ht current price when future invoice will be created) fk_product_fournisseur_price integer DEFAULT NULL, -- reference of supplier price when line was added (may be used to update buy_price_ht current price when future invoice will be created)
special_code integer UNSIGNED DEFAULT 0, -- code pour les lignes speciales special_code integer DEFAULT 0, -- code pour les lignes speciales
rang integer DEFAULT 0, rang integer DEFAULT 0,
import_key varchar(14) import_key varchar(14)
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -22,6 +22,7 @@ create table llx_facture_fourn_det
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_facture_fourn integer NOT NULL, fk_facture_fourn integer NOT NULL,
fk_parent_line integer NULL,
fk_product integer NULL, fk_product integer NULL,
ref varchar(50), -- supplier product ref ref varchar(50), -- supplier product ref
label varchar(255), -- product label label varchar(255), -- product label
@ -45,5 +46,7 @@ create table llx_facture_fourn_det
date_end datetime DEFAULT NULL, -- date fin si service date_end datetime DEFAULT NULL, -- date fin si service
info_bits integer DEFAULT 0, -- TVA NPR ou non info_bits integer DEFAULT 0, -- TVA NPR ou non
fk_code_ventilation integer DEFAULT 0 NOT NULL, fk_code_ventilation integer DEFAULT 0 NOT NULL,
special_code integer DEFAULT 0, -- code pour les lignes speciales
rang integer DEFAULT 0,
import_key varchar(14) import_key varchar(14)
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -262,8 +262,12 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! $error)
{
$id = $object->create($user); $id = $object->create($user);
}
if ($id > 0) if ($id > 0)
{ {
@ -339,8 +343,9 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if ($object->check()) if (! $error && $object->check())
{ {
if ($object->update($object->id, $user) > 0) if ($object->update($object->id, $user) > 0)
{ {

View File

@ -148,6 +148,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
$result = $object->create($user); $result = $object->create($user);
if ($result > 0) if ($result > 0)
@ -224,10 +225,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) if ($ret < 0) $error++;
{
$error++;
}
} }
if (! $error) if (! $error)

View File

@ -91,14 +91,17 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! $error)
{
$result=$object->update($user); $result=$object->update($user);
if ($result < 0) if ($result < 0)
{ {
setEventMessages($object->error,$object->errors,'errors'); setEventMessages($object->error,$object->errors,'errors');
} }
} }
}
else else
{ {
$action='edit'; $action='edit';

View File

@ -250,6 +250,7 @@ if ($action == 'add')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label($adh->table_element); $extralabels=$extrafields->fetch_name_optionals_label($adh->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$adh); $ret = $extrafields->setOptionalsFromPost($extralabels,$adh);
if ($ret < 0) $error++;
$result=$adh->create($user); $result=$adh->create($user);
if ($result > 0) if ($result > 0)

View File

@ -193,7 +193,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (GETPOST('deletephoto')) $object->logo = ''; if (GETPOST('deletephoto')) $object->logo = '';
else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']); else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);

View File

@ -211,6 +211,7 @@ if ($action == 'add' && $canadduser)
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
// Set entity of new user // Set entity of new user
$entity=GETPOST('entity','int'); $entity=GETPOST('entity','int');
@ -361,6 +362,7 @@ if ($action == 'update' && ! $_POST["cancel"])
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! empty($conf->multicompany->enabled)) if (! empty($conf->multicompany->enabled))
{ {
@ -385,8 +387,9 @@ if ($action == 'update' && ! $_POST["cancel"])
if (GETPOST('deletephoto')) $object->photo=''; if (GETPOST('deletephoto')) $object->photo='';
if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
if (! $error)
{
$ret=$object->update($user); $ret=$object->update($user);
if ($ret < 0) if ($ret < 0)
{ {
$error++; $error++;
@ -400,6 +403,7 @@ if ($action == 'update' && ! $_POST["cancel"])
setEventMessage($object->error, 'errors'); setEventMessage($object->error, 'errors');
} }
} }
}
if (! $error && isset($_POST['contactid'])) if (! $error && isset($_POST['contactid']))
{ {

View File

@ -101,6 +101,7 @@ if ($action == 'add')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0;
else $object->entity = $_POST["entity"]; else $object->entity = $_POST["entity"];
@ -183,6 +184,7 @@ if ($action == 'update')
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0;
else $object->entity = $_POST["entity"]; else $object->entity = $_POST["entity"];