diff --git a/ChangeLog b/ChangeLog
index 6498158b912..d018c4ec8ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,8 +5,8 @@ English Dolibarr ChangeLog
***** ChangeLog for 3.7 compared to 3.6.* *****
For users:
-New: [ task #867 ] Remove ESAEB external module code from core
--
+New: [ task #867 ] Remove ESAEB external module code from core.
+New: Can create proposal from an intervention.
For translators:
- Update language files.
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index dbc76feeeef..3630ef2be10 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -237,11 +237,13 @@ else if ($action == 'add' && $user->rights->propal->creer) {
$error ++;
}
- if (! $error) {
+ if (! $error)
+ {
$db->begin();
// Si on a selectionne une propal a copier, on realise la copie
- if (GETPOST('createmode') == 'copy' && GETPOST('copie_propal')) {
+ if (GETPOST('createmode') == 'copy' && GETPOST('copie_propal'))
+ {
if ($object->fetch(GETPOST('copie_propal')) > 0) {
$object->ref = GETPOST('ref');
$object->datep = $datep;
@@ -287,7 +289,8 @@ else if ($action == 'add' && $user->rights->propal->creer) {
$object->origin = GETPOST('origin');
$object->origin_id = GETPOST('originid');
- for($i = 1; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i ++) {
+ for($i = 1; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i ++)
+ {
if ($_POST ['idprod' . $i]) {
$xid = 'idprod' . $i;
$xqty = 'qty' . $i;
@@ -304,8 +307,137 @@ else if ($action == 'add' && $user->rights->propal->creer) {
}
}
- if (! $error) {
- $id = $object->create($user);
+ if (! $error)
+ {
+ if ($origin && $originid)
+ {
+ // Parse element/subelement (ex: project_task)
+ $element = $subelement = $origin;
+ if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
+ $element = $regs [1];
+ $subelement = $regs [2];
+ }
+
+ // For compatibility
+ if ($element == 'order') {
+ $element = $subelement = 'commande';
+ }
+ if ($element == 'propal') {
+ $element = 'comm/propal';
+ $subelement = 'propal';
+ }
+ if ($element == 'contract') {
+ $element = $subelement = 'contrat';
+ }
+ if ($element == 'inter') {
+ $element = $subelement = 'ficheinter';
+ }
+ if ($element == 'shipping') {
+ $element = $subelement = 'expedition';
+ }
+
+ $object->origin = $origin;
+ $object->origin_id = $originid;
+
+ // Possibility to add external linked objects with hooks
+ $object->linked_objects [$object->origin] = $object->origin_id;
+ if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) {
+ $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
+ }
+
+ $id = $object->create($user);
+
+ if ($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)
+ {
+ $lines = $srcobject->lines;
+ if (empty($lines) && method_exists($srcobject, 'fetch_lines')) $lines = $srcobject->fetch_lines();
+
+ $fk_parent_line=0;
+ $num=count($lines);
+ for ($i=0;$i<$num;$i++)
+ {
+ $label=(! empty($lines[$i]->label)?$lines[$i]->label:'');
+ $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
+
+ // Positive line
+ $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
+
+ // Date start
+ $date_start = false;
+ if ($lines[$i]->date_debut_prevue)
+ $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
+ $date_end = false;
+ if ($lines[$i]->date_fin_prevue)
+ $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;
+ }
+
+ // Extrafields
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) {
+ $lines[$i]->fetch_optionals($lines[$i]->rowid);
+ $array_option = $lines[$i]->array_options;
+ }
+
+ $tva_tx=get_default_tva($mysoc, $object->thirdparty);
+
+ $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_option);
+
+ if ($result > 0) {
+ $lineid = $result;
+ } else {
+ $lineid = 0;
+ $error ++;
+ break;
+ }
+
+ // 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 {
+ $mesgs [] = $srcobject->error;
+ $error ++;
+ }
+ } else {
+ $mesgs [] = $object->error;
+ $error ++;
+ }
+ } // Standard creation
+ else
+ {
+ $id = $object->create($user);
+ }
if ($id > 0) {
// Insertion contact par defaut si defini
@@ -1105,6 +1237,61 @@ if ($action == 'create') {
if ($socid > 0)
$res = $soc->fetch($socid);
+ // Load objectsrc
+ if (! empty($origin) && ! empty($originid))
+ {
+ // Parse element/subelement (ex: project_task)
+ $element = $subelement = $origin;
+ if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
+ $element = $regs [1];
+ $subelement = $regs [2];
+ }
+
+ if ($element == 'project') {
+ $projectid = $originid;
+ } else {
+ // For compatibility
+ if ($element == 'order' || $element == 'commande') {
+ $element = $subelement = 'commande';
+ }
+ if ($element == 'propal') {
+ $element = 'comm/propal';
+ $subelement = 'propal';
+ }
+ if ($element == 'contract') {
+ $element = $subelement = 'contrat';
+ }
+ if ($element == 'shipping') {
+ $element = $subelement = 'expedition';
+ }
+
+ dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
+
+ $classname = ucfirst($subelement);
+ $objectsrc = new $classname($db);
+ $objectsrc->fetch($originid);
+ if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
+ $objectsrc->fetch_lines();
+ $objectsrc->fetch_thirdparty();
+
+ $projectid = (! empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
+ $ref_client = (! empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
+ $ref_int = (! empty($objectsrc->ref_int) ? $objectsrc->ref_int : '');
+
+ $soc = $objectsrc->thirdparty;
+
+ $cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
+ $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
+ $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0));
+ $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0));
+ $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$dateinvoice);
+
+ // Replicate extrafields
+ $objectsrc->fetch_optionals($originid);
+ $object->array_options = $objectsrc->array_options;
+ }
+ }
+
$object = new Propal($db);
print '
";
+
+
+ // Show origin lines
+ if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) {
+ print ' ';
+
+ $title = $langs->trans('ProductsAndServices');
+ print_titre($title);
+
+ print '';
+
+ $objectsrc->printOriginLinesList();
+
+ print '
';
+ }
+
} else {
/*
* Show object in view mode
@@ -1982,7 +2233,7 @@ if ($action == 'create') {
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/'));
$file = $fileparams ['fullname'];
-
+
// Define output language
$outputlangs = $langs;
$newlang = '';
@@ -1990,16 +2241,16 @@ if ($action == 'create') {
$newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang))
$newlang = $object->client->default_lang;
-
+
// Build document if it not exists
if (! $file || ! is_readable($file)) {
-
+
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
-
+
$result = propale_pdf_create($db, $object, GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
dol_print_error($db, $result);
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 8b37f6196c9..555640a50ce 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -802,11 +802,11 @@ else if ($action == 'add' && $user->rights->facture->creer)
$object->fetch_thirdparty();
// If creation from another object of another module (Example: origin=propal, originid=1)
- if ($_POST['origin'] && $_POST['originid'])
+ if ($origin && $originid)
{
// Parse element/subelement (ex: project_task)
- $element = $subelement = $_POST['origin'];
- if (preg_match('/^([^_]+)_([^_]+)/i', $_POST['origin'], $regs)) {
+ $element = $subelement = $origin;
+ if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
$element = $regs [1];
$subelement = $regs [2];
}
@@ -829,8 +829,8 @@ else if ($action == 'add' && $user->rights->facture->creer)
$element = $subelement = 'expedition';
}
- $object->origin = $_POST['origin'];
- $object->origin_id = $_POST['originid'];
+ $object->origin = $origin;
+ $object->origin_id = $originid;
// Possibility to add external linked objects with hooks
$object->linked_objects [$object->origin] = $object->origin_id;
@@ -889,19 +889,19 @@ else if ($action == 'add' && $user->rights->facture->creer)
$langs->trans('Deposit'),
$amountdeposit, // subprice
1, // quantity
- $lines [$i]->tva_tx, 0, // localtax1_tx
+ $lines[$i]->tva_tx, 0, // localtax1_tx
0, // localtax2_tx
0, // fk_product
0, // remise_percent
0, // date_start
0, // date_end
- 0, $lines [$i]->info_bits, // info_bits
+ 0, $lines[$i]->info_bits, // info_bits
0, // info_bits
'HT',
0,
0, // product_type
1,
- $lines [$i]->special_code,
+ $lines[$i]->special_code,
$object->origin,
0,
0,
@@ -932,15 +932,15 @@ else if ($action == 'add' && $user->rights->facture->creer)
$label=(! empty($lines[$i]->label)?$lines[$i]->label:'');
$desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
- if ($lines [$i]->subprice < 0)
+ if ($lines[$i]->subprice < 0)
{
// Negative line, we create a discount line
$discount = new DiscountAbsolute($db);
$discount->fk_soc = $object->socid;
- $discount->amount_ht = abs($lines [$i]->total_ht);
- $discount->amount_tva = abs($lines [$i]->total_tva);
- $discount->amount_ttc = abs($lines [$i]->total_ttc);
- $discount->tva_tx = $lines [$i]->tva_tx;
+ $discount->amount_ht = abs($lines[$i]->total_ht);
+ $discount->amount_tva = abs($lines[$i]->total_tva);
+ $discount->amount_ttc = abs($lines[$i]->total_ttc);
+ $discount->tva_tx = $lines[$i]->tva_tx;
$discount->fk_user = $user->id;
$discount->description = $desc;
$discountid = $discount->create($user);
@@ -953,38 +953,38 @@ else if ($action == 'add' && $user->rights->facture->creer)
}
} else {
// Positive line
- $product_type = ($lines [$i]->product_type ? $lines [$i]->product_type : 0);
+ $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
// Date start
$date_start = false;
- if ($lines [$i]->date_debut_prevue)
- $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;
+ if ($lines[$i]->date_debut_prevue)
+ $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
$date_end = false;
- if ($lines [$i]->date_fin_prevue)
- $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;
+ if ($lines[$i]->date_fin_prevue)
+ $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) {
+ if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
$fk_parent_line = 0;
}
// Extrafields
- if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines [$i], 'fetch_optionals')) {
- $lines [$i]->fetch_optionals($lines [$i]->rowid);
- $array_option = $lines [$i]->array_options;
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) {
+ $lines[$i]->fetch_optionals($lines[$i]->rowid);
+ $array_option = $lines[$i]->array_options;
}
- $result = $object->addline($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, $date_start, $date_end, 0, $lines [$i]->info_bits, $lines [$i]->fk_remise_except, 'HT', 0, $product_type, $lines [$i]->rang, $lines [$i]->special_code, $object->origin, $lines [$i]->rowid, $fk_parent_line, $lines [$i]->fk_fournprice, $lines [$i]->pa_ht, $label, $array_option);
+ $result = $object->addline($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, $date_start, $date_end, 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $object->origin, $lines[$i]->rowid, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_option);
if ($result > 0) {
$lineid = $result;
@@ -995,7 +995,7 @@ else if ($action == 'add' && $user->rights->facture->creer)
}
// Defined the new fk_parent_line
- if ($result > 0 && $lines [$i]->product_type == 9) {
+ if ($result > 0 && $lines[$i]->product_type == 9) {
$fk_parent_line = $result;
}
}
@@ -1841,6 +1841,7 @@ if ($action == 'create')
if ($socid > 0)
$res = $soc->fetch($socid);
+ // Load objectsrc
if (! empty($origin) && ! empty($originid))
{
// Parse element/subelement (ex: project_task)
@@ -2252,10 +2253,9 @@ if ($action == 'create')
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
print $doleditor->Create(1);
- // print '';
-
// Private note
- if (empty($user->societe_id)) {
+ if (empty($user->societe_id))
+ {
print '';
print '' . $langs->trans('NotePrivate') . ' ';
print '';
@@ -2266,10 +2266,13 @@ if ($action == 'create')
}
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
print $doleditor->Create(1);
- // print ' ';
+ // print '
+ print '';
}
- if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) {
+ // Lines from source
+ if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
+ {
// TODO for compatibility
if ($origin == 'contrat') {
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
@@ -2293,6 +2296,8 @@ if ($action == 'create')
$newclassname = 'Order';
elseif ($newclassname == 'Expedition')
$newclassname = 'Sending';
+ elseif ($newclassname == 'Fichinter')
+ $newclassname = 'Intervention';
print '' . $langs->trans($newclassname) . ' ' . $objectsrc->getNomUrl(1) . ' ';
print '' . $langs->trans('TotalHT') . ' ' . price($objectsrc->total_ht) . ' ';
@@ -2362,7 +2367,10 @@ if ($action == 'create')
print "\n";
// Button "Create Draft"
- print ' ';
+ print '';
+ print ' ';
+ print ' ';
+ print ' ';
print "\n";
@@ -3620,7 +3628,7 @@ if ($action == 'create')
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/'));
$file = $fileparams ['fullname'];
-
+
// Define output language
$outputlangs = $langs;
$newlang = '';
@@ -3631,7 +3639,7 @@ if ($action == 'create')
// Build document if it not exists
if (! $file || ! is_readable($file)) {
-
+
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 1f5d14b7529..e08a076624e 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -1115,6 +1115,7 @@ class Form
* @param int $maxlength Maximum length of string into list (0=no limit)
* @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status
* @return string HTML select string
+ * @see select_dolgroups
*/
function select_dolusers($selected='', $htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0)
{
@@ -4196,6 +4197,7 @@ class Form
* @param int $enableonly Array list of groups id to be enabled. All other must be disabled
* @param int $force_entity 0 or Id of environment to force
* @return void
+ * @see select_dolusers
*/
function select_dolgroups($selected='', $htmlname='groupid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0)
{
diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php
index a66fb341cff..6ed1bbb2f59 100644
--- a/htdocs/fichinter/fiche.php
+++ b/htdocs/fichinter/fiche.php
@@ -1543,6 +1543,17 @@ else if ($id > 0 || ! empty($ref))
else print '';
}
+ // Proposal
+ if (! empty($conf->propal->enabled) && $object->statut > 0)
+ {
+ $langs->load("propal");
+ if ($object->statut < 2)
+ {
+ if ($user->rights->propal->creer) print '';
+ else print '';
+ }
+ }
+
// Invoicing
if (! empty($conf->facture->enabled) && $object->statut > 0)
{
@@ -1582,7 +1593,7 @@ else if ($id > 0 || ! empty($ref))
/*
* Built documents
- */
+ */
$filename=dol_sanitizeFileName($object->ref);
$filedir=$conf->ficheinter->dir_output . "/".$object->ref;
$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
@@ -1616,7 +1627,7 @@ else if ($id > 0 || ! empty($ref))
/*
* Action presend
- */
+ */
if ($action == 'presend')
{
$ref = dol_sanitizeFileName($object->ref);