Check required extrafields on orders
This commit is contained in:
parent
bddbc6f6b2
commit
7ee4e42710
@ -275,117 +275,130 @@ else if ($action == 'add' && $user->rights->commande->creer)
|
||||
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||
if($ret < 0)
|
||||
$error++;
|
||||
|
||||
$object_id = $object->create($user);
|
||||
if(!$error) {
|
||||
$object_id = $object->create($user);
|
||||
|
||||
if ($object_id > 0)
|
||||
{
|
||||
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
|
||||
|
||||
$classname = ucfirst($subelement);
|
||||
$srcobject = new $classname($db);
|
||||
|
||||
dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
|
||||
$result=$srcobject->fetch($object->origin_id);
|
||||
if ($result > 0)
|
||||
if ($object_id > 0)
|
||||
{
|
||||
$lines = $srcobject->lines;
|
||||
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
|
||||
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
|
||||
|
||||
$fk_parent_line=0;
|
||||
$num=count($lines);
|
||||
$classname = ucfirst($subelement);
|
||||
$srcobject = new $classname($db);
|
||||
|
||||
for ($i=0;$i<$num;$i++)
|
||||
dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
|
||||
$result=$srcobject->fetch($object->origin_id);
|
||||
if ($result > 0)
|
||||
{
|
||||
$label=(! empty($lines[$i]->label)?$lines[$i]->label:'');
|
||||
$desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
|
||||
$product_type=(! empty($lines[$i]->product_type)?$lines[$i]->product_type:0);
|
||||
$lines = $srcobject->lines;
|
||||
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
|
||||
|
||||
// Dates
|
||||
// TODO mutualiser
|
||||
$date_start=$lines[$i]->date_debut_prevue;
|
||||
if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
|
||||
if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
|
||||
$date_end=$lines[$i]->date_fin_prevue;
|
||||
if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
|
||||
if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
|
||||
$fk_parent_line=0;
|
||||
$num=count($lines);
|
||||
|
||||
// Reset fk_parent_line for no child products and special product
|
||||
if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
|
||||
$fk_parent_line = 0;
|
||||
}
|
||||
|
||||
$result = $object->addline(
|
||||
$object_id,
|
||||
$desc,
|
||||
$lines[$i]->subprice,
|
||||
$lines[$i]->qty,
|
||||
$lines[$i]->tva_tx,
|
||||
$lines[$i]->localtax1_tx,
|
||||
$lines[$i]->localtax2_tx,
|
||||
$lines[$i]->fk_product,
|
||||
$lines[$i]->remise_percent,
|
||||
$lines[$i]->info_bits,
|
||||
$lines[$i]->fk_remise_except,
|
||||
'HT',
|
||||
0,
|
||||
$date_start,
|
||||
$date_end,
|
||||
$product_type,
|
||||
$lines[$i]->rang,
|
||||
$lines[$i]->special_code,
|
||||
$fk_parent_line,
|
||||
$lines[$i]->fk_fournprice,
|
||||
$lines[$i]->pa_ht,
|
||||
$label
|
||||
);
|
||||
|
||||
if ($result < 0)
|
||||
for ($i=0;$i<$num;$i++)
|
||||
{
|
||||
$error++;
|
||||
break;
|
||||
$label=(! empty($lines[$i]->label)?$lines[$i]->label:'');
|
||||
$desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
|
||||
$product_type=(! empty($lines[$i]->product_type)?$lines[$i]->product_type:0);
|
||||
|
||||
// Dates
|
||||
// TODO mutualiser
|
||||
$date_start=$lines[$i]->date_debut_prevue;
|
||||
if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
|
||||
if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
|
||||
$date_end=$lines[$i]->date_fin_prevue;
|
||||
if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
|
||||
if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
|
||||
|
||||
// Reset fk_parent_line for no child products and special product
|
||||
if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
|
||||
$fk_parent_line = 0;
|
||||
}
|
||||
|
||||
$result = $object->addline(
|
||||
$object_id,
|
||||
$desc,
|
||||
$lines[$i]->subprice,
|
||||
$lines[$i]->qty,
|
||||
$lines[$i]->tva_tx,
|
||||
$lines[$i]->localtax1_tx,
|
||||
$lines[$i]->localtax2_tx,
|
||||
$lines[$i]->fk_product,
|
||||
$lines[$i]->remise_percent,
|
||||
$lines[$i]->info_bits,
|
||||
$lines[$i]->fk_remise_except,
|
||||
'HT',
|
||||
0,
|
||||
$date_start,
|
||||
$date_end,
|
||||
$product_type,
|
||||
$lines[$i]->rang,
|
||||
$lines[$i]->special_code,
|
||||
$fk_parent_line,
|
||||
$lines[$i]->fk_fournprice,
|
||||
$lines[$i]->pa_ht,
|
||||
$label
|
||||
);
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
|
||||
// Defined the new fk_parent_line
|
||||
if ($result > 0 && $lines[$i]->product_type == 9) {
|
||||
$fk_parent_line = $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Defined the new fk_parent_line
|
||||
if ($result > 0 && $lines[$i]->product_type == 9) {
|
||||
$fk_parent_line = $result;
|
||||
}
|
||||
// Hooks
|
||||
$parameters=array('objFrom'=>$srcobject);
|
||||
$reshook=$hookmanager->executeHooks('createFrom',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
|
||||
if ($reshook < 0) $error++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$srcobject->error;
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Hooks
|
||||
$parameters=array('objFrom'=>$srcobject);
|
||||
$reshook=$hookmanager->executeHooks('createFrom',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
|
||||
if ($reshook < 0) $error++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$srcobject->error;
|
||||
$mesg=$object->error;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$object->error;
|
||||
$error++;
|
||||
// Required extrafield left blank, error message already defined by setOptionalsFromPost()
|
||||
$action='create';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||
if($ret < 0)
|
||||
$error++;
|
||||
|
||||
$object_id = $object->create($user);
|
||||
if(!$error) {
|
||||
$object_id = $object->create($user);
|
||||
|
||||
// If some invoice's lines already known
|
||||
$NBLINES=8;
|
||||
for ($i = 1 ; $i <= $NBLINES ; $i++)
|
||||
{
|
||||
if ($_POST['idprod'.$i])
|
||||
// If some invoice's lines already known
|
||||
$NBLINES=8;
|
||||
for ($i = 1 ; $i <= $NBLINES ; $i++)
|
||||
{
|
||||
$xid = 'idprod'.$i;
|
||||
$xqty = 'qty'.$i;
|
||||
$xremise = 'remise_percent'.$i;
|
||||
$object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);
|
||||
if ($_POST['idprod'.$i])
|
||||
{
|
||||
$xid = 'idprod'.$i;
|
||||
$xqty = 'qty'.$i;
|
||||
$xremise = 'remise_percent'.$i;
|
||||
$object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1130,23 +1143,32 @@ else if ($action == 'update_extras')
|
||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||
|
||||
// Actions on extra fields (by external module or standard code)
|
||||
// FIXME le hook fait double emploi avec le trigger !!
|
||||
$hookmanager->initHooks(array('orderdao'));
|
||||
$parameters=array('id'=>$object->id);
|
||||
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
if (empty($reshook))
|
||||
{
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
||||
if($ret < 0)
|
||||
$error++;
|
||||
|
||||
if(!$error) {
|
||||
// Actions on extra fields (by external module or standard code)
|
||||
// FIXME le hook fait double emploi avec le trigger !!
|
||||
$hookmanager->initHooks(array('orderdao'));
|
||||
$parameters=array('id'=>$object->id);
|
||||
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
if (empty($reshook))
|
||||
{
|
||||
$result=$object->insertExtraFields();
|
||||
if ($result < 0)
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
||||
{
|
||||
$error++;
|
||||
$result=$object->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($reshook < 0) $error++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$action = 'edit_extras';
|
||||
}
|
||||
else if ($reshook < 0) $error++;
|
||||
|
||||
}
|
||||
|
||||
@ -1335,7 +1357,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer)
|
||||
if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer)
|
||||
{
|
||||
if ($action == 'addcontact')
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user