From 9c73bb1aefc4273b0ba890c6eb3792e79b9f4d88 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 6 Feb 2020 14:15:41 +0100 Subject: [PATCH] NEW Can create an deposit from order using a percentage of qty. --- htdocs/compta/facture/card.php | 39 +++++++++++++++++++++++++--------- htdocs/langs/en_US/bills.lang | 1 + 2 files changed, 30 insertions(+), 10 deletions(-) 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 ''; - $arraylist = array('amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), 'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit'))); - print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1); + $arraylist = array( + 'amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')), + 'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')), + 'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines') + ); + print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit', 'aZ09'), 0, 0, 0, '', 1); print ''; print ''.$langs->trans('Value').':'; } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 66391b4f07d..6d7c61784f7 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -419,6 +419,7 @@ PaymentCondition14DENDMONTH=Within 14 days following the end of the month FixAmount=Fixed amount - 1 line with label '%s' VarAmount=Variable amount (%% tot.) VarAmountOneLine=Variable amount (%% tot.) - 1 line with label '%s' +VarAmountAllLines=Variable amount (%% tot.) - all same lines # PaymentType PaymentTypeVIR=Bank transfer PaymentTypeShortVIR=Bank transfer