diff --git a/htdocs/comm/propal/tpl/linkedobjectblock.tpl.php b/htdocs/comm/propal/tpl/linkedobjectblock.tpl.php
index e2f13032e05..a13d80c083c 100644
--- a/htdocs/comm/propal/tpl/linkedobjectblock.tpl.php
+++ b/htdocs/comm/propal/tpl/linkedobjectblock.tpl.php
@@ -52,18 +52,18 @@ foreach($linkedObjectBlock as $key => $objectlink)
$trclass=($var?'pair':'impair');
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total';
?>
-
- | trans("CustomerOrder"); ?> |
- getNomUrl(1); ?> |
- ref_client; ?> |
- date,'day'); ?> |
- " >
+ | trans("CustomerOrder"); ?>
+ global->MAIN_ENABLE_IMPORT_LINKED_OBJECT_LINES) print '
+ |
+ getNomUrl(1); ?> |
+ ref_client; ?> |
+ date,'day'); ?> |
+ rights->commande->lire) {
$total = $total + $objectlink->total_ht;
echo price($objectlink->total_ht);
} ?> |
- getLibStatut(3); ?> |
-
+ | getLibStatut(3); ?> |
+
element != 'shipping') {
diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index d438c505a8d..9113115b42d 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -2095,6 +2095,82 @@ if (empty($reshook))
exit();
}
+ // add lines from objectlinked
+ elseif($action == 'import_lines_from_object'
+ && $user->rights->facture->creer
+ && $object->statut == Facture::STATUS_DRAFT
+ && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION))
+ {
+ $fromElement = GETPOST('fromelement');
+ $fromElementid = GETPOST('fromelementid');
+ $importLines = GETPOST('line_checkbox');
+
+ if(!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid))
+ {
+ if($fromElement == 'commande')
+ {
+ dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class');
+ $lineClassName = 'OrderLine';
+ }
+ $nextRang = count($object->lines) + 1;
+ $importCount = 0;
+ $error = 0;
+ foreach($importLines as $lineId)
+ {
+ $lineId = intval($lineId);
+ $originLine = new $lineClassName($db);
+ if(intval($fromElementid) > 0 && $originLine->fetch( $lineId ) > 0)
+ {
+ $originLine->fetch_optionals($lineId);
+ $desc = $originLine->desc;
+ $pu_ht = $originLine->subprice;
+ $qty = $originLine->qty;
+ $txtva = $originLine->tva_tx;
+ $txlocaltax1 = $originLine->localtax1_tx;
+ $txlocaltax2 = $originLine->localtax2_tx;
+ $fk_product = $originLine->fk_product;
+ $remise_percent = $originLine->remise_percent;
+ $date_start = $originLine->date_start;
+ $date_end = $originLine->date_end;
+ $ventil = 0;
+ $info_bits = $originLine->info_bits;
+ $fk_remise_except = $originLine->fk_remise_except;
+ $price_base_type='HT';
+ $pu_ttc=0;
+ $type = $originLine->product_type;
+ $rang=$nextRang++;
+ $special_code = $originLine->special_code;
+ $origin = $originLine->element;
+ $origin_id = $originLine->id;
+ $fk_parent_line=0;
+ $fk_fournprice=$originLine->fk_fournprice;
+ $pa_ht = $originLine->pa_ht;
+ $label = $originLine->label;
+ $array_options = $originLine->array_options;
+ $situation_percent = 100;
+ $fk_prev_id = '';
+ $fk_unit = $originLine->fk_unit;
+ $pu_ht_devise = $originLine->multicurrency_subprice;
+
+ $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $ventil, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $type, $rang, $special_code, $origin, $origin_id, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $situation_percent, $fk_prev_id, $fk_unit,$pu_ht_devise);
+ if($res > 0){
+ $importCount++;
+ }else{
+ $error++;
+ }
+ }
+ else{
+ $error++;
+ }
+ }
+
+ if($error)
+ {
+ setEventMessage($langs->trans('ErrorsOnXLines',$error), 'errors');
+ }
+ }
+ }
+
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
@@ -4156,7 +4232,7 @@ else if ($id > 0 || ! empty($ref))
// Form to add new line
if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline' && ($object->is_first() || !$object->situation_cycle_ref))
{
- if ($action != 'editline')
+ if ($action != 'editline' && $action != 'selectlines')
{
// Add free products/services
$object->formAddObjectLine(1, $mysoc, $soc);
@@ -4448,8 +4524,16 @@ else if ($id > 0 || ! empty($ref))
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice'));
- $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
-
+
+ $compatibleImportElementsList = false;
+ if($user->rights->facture->creer
+ && $object->statut == Facture::STATUS_DRAFT
+ && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION) )
+ {
+ $compatibleImportElementsList = array('commande'); // import from linked elements
+ }
+ $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem,$compatibleImportElementsList);
+
// Show online payment link
$useonlinepayment = (! empty($conf->paypal->enabled) || ! empty($conf->stripe->enabled) || ! empty($conf->paybox->enabled));
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 0e8217c2bf8..77238e5b62d 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -769,10 +769,16 @@ class Facture extends CommonInvoice
}
else if ($reshook < 0) $error++;*/
- // Call trigger
- $result=$this->call_trigger('BILL_CREATE',$user);
- if ($result < 0) $error++;
- // End call triggers
+ if (! $error)
+ {
+ if (! $notrigger)
+ {
+ // Call trigger
+ $result=$this->call_trigger('BILL_CREATE',$user);
+ if ($result < 0) $error++;
+ // End call triggers
+ }
+ }
if (! $error)
{
diff --git a/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php b/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php
index d2dd999350d..3964800fd2b 100644
--- a/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php
+++ b/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php
@@ -47,12 +47,12 @@ foreach($linkedObjectBlock as $key => $objectlink)
$trclass=($var?'pair':'impair');
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total';
?>
- |
- | trans("CustomerInvoice"); ?> |
- getNomUrl(1); ?> |
- ref_client; ?> |
- date,'day'); ?> |
- " data-element="element; ?>" data-id="id; ?>" >
+ | trans("CustomerInvoice"); ?> |
+ getNomUrl(1); ?> |
+ ref_client; ?> |
+ date,'day'); ?> |
+ rights->facture->lire) {
$sign = 1;
if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = -1;
@@ -66,8 +66,8 @@ foreach($linkedObjectBlock as $key => $objectlink)
echo ''.price($objectlink->total_ht).'';
}
} ?> |
- getLibStatut(3); ?> |
- id.'&action=dellink&dellinkid='.$key; ?>">transnoentitiesnoconv("RemoveLink"), 'unlink'); ?> |
+ getLibStatut(3); ?> |
+ id.'&action=dellink&dellinkid='.$key; ?>">transnoentitiesnoconv("RemoveLink"), 'unlink'); ?> |
1)
}
?>
-
\ No newline at end of file
+
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 92a4208a5d0..a620afd900b 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -3735,6 +3735,14 @@ abstract class CommonObject
print '