diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 5566ce4d90d..814c58b92f3 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -253,6 +253,7 @@ class Commande extends CommonOrder if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); + $mouvP->origin = &$this; // We decrement stock of product (and sub-products) $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderValidatedInDolibarr",$num)); if ($result < 0) { $error++; } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index d08feba9b14..4995ab7eab0 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -643,8 +643,37 @@ else if ($action == 'add' && $user->rights->facture->creer) { $id = $object->create($user); + if(GETPOST('invoiceAvoirWithLines', 'int')==1 && $id>0) { + + $facture_source = new Facture($db); // fetch origin object + if($facture_source->fetch($object->fk_facture_source)>0) { + + foreach($facture_source->lines as $line) { + + $line->fk_facture = $object->id; + + $line->subprice =-$line->subprice; // invert price for object + $line->pa_ht = -$line->pa_ht; + $line->total_ht=-$line->total_ht; + $line->total_tva=-$line->total_tva; + $line->total_ttc=-$line->total_ttc; + $line->total_localtax1=-$line->total_localtax1; + $line->total_localtax2=-$line->total_localtax2; + + $line->insert(); + + $object->lines[] = $line; // insert new line in current object + } + + $object->update_price(1); + } + + } + // Add predefined lines - for($i = 1; $i <= $NBLINES; $i ++) { + /* + TODO delete + for($i = 1; $i <= $NBLINES; $i ++) { if ($_POST ['idprod' . $i]) { $product = new Product($db); $product->fetch($_POST ['idprod' . $i]); @@ -652,7 +681,7 @@ else if ($action == 'add' && $user->rights->facture->creer) { $endday = dol_mktime(12, 0, 0, $_POST ['date_end' . $i . 'month'], $_POST ['date_end' . $i . 'day'], $_POST ['date_end' . $i . 'year']); $result = $object->addline($product->description, $product->price, $_POST ['qty' . $i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST ['idprod' . $i], $_POST ['remise_percent' . $i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type); } - } + }*/ } } @@ -2000,12 +2029,12 @@ if ($action == 'create') if (empty($origin) && $socid > 0) { // Credit note - print '