diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 0d124c34f32..3e59b92a146 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1386,12 +1386,12 @@ if (empty($reshook)) dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines or deposit lines"); $result = $srcobject->fetch($object->origin_id); - // If deposit invoice - if ($_POST['type'] == Facture::TYPE_DEPOSIT) - { - $typeamount = GETPOST('typedeposit', 'alpha'); - $valuedeposit = GETPOST('valuedeposit', 'int'); + $typeamount = GETPOST('typedeposit', 'aZ09'); + $valuedeposit = GETPOST('valuedeposit', 'int'); + // If deposit invoice + if ($_POST['type'] == Facture::TYPE_DEPOSIT && in_array($typeamount, array('amount', 'variable'))) + { $amountdeposit = array(); if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) { @@ -1419,7 +1419,7 @@ if (empty($reshook)) { $amountdeposit[0] = $valuedeposit; } - else + elseif ($typeamount == 'variable') { if ($result > 0) { @@ -1449,11 +1449,15 @@ if (empty($reshook)) $amount_ttc_diff = $amountdeposit[0]; } + foreach ($amountdeposit as $tva => $amount) { if (empty($amount)) continue; - $arraylist = array('amount' => 'FixAmount', 'variable' => 'VarAmount'); + $arraylist = array( + 'amount' => 'FixAmount', + 'variable' => 'VarAmount' + ); $descline = '(DEPOSIT)'; //$descline.= ' - '.$langs->trans($arraylist[$typeamount]); if ($typeamount == 'amount') { @@ -1500,7 +1504,8 @@ if (empty($reshook)) $object->updateline($object->lines[0]->id, $object->lines[0]->desc, $subprice_diff, $object->lines[0]->qty, $object->lines[0]->remise_percent, $object->lines[0]->date_start, $object->lines[0]->date_end, $object->lines[0]->tva_tx, 0, 0, 'HT', $object->lines[0]->info_bits, $object->lines[0]->product_type, 0, 0, 0, $object->lines[0]->pa_ht, $object->lines[0]->label, 0, array(), 100); } } - else + + if ($_POST['type'] != Facture::TYPE_DEPOSIT || ($_POST['type'] == Facture::TYPE_DEPOSIT && $typeamount == 'variablealllines')) { if ($result > 0) { @@ -1511,6 +1516,16 @@ if (empty($reshook)) $lines = $srcobject->lines; } + // If we create a deposit with all lines and a percent, we change amount + if ($_POST['type'] == Facture::TYPE_DEPOSIT && $typeamount == 'variablealllines') { + if (is_array($lines)) { + foreach($lines as $line) { + // We keep ->subprice and ->pa_ht, but we change the qty + $line->qty = price2num($line->qty * $valuedeposit / 100, 'MS'); + } + } + } + $fk_parent_line = 0; $num = count($lines); for ($i = 0; $i < $num; $i++) @@ -2994,8 +3009,12 @@ if ($action == 'create') if (($origin == 'propal') || ($origin == 'commande')) { print '