New global conf MAIN_DEPOSIT_MULTI_TVA to manage multi tva on deposit
This commit is contained in:
parent
e58743ea5b
commit
0f421dc2b4
@ -1020,14 +1020,35 @@ if (empty($reshook))
|
|||||||
$typeamount = GETPOST('typedeposit', 'alpha');
|
$typeamount = GETPOST('typedeposit', 'alpha');
|
||||||
$valuedeposit = GETPOST('valuedeposit', 'int');
|
$valuedeposit = GETPOST('valuedeposit', 'int');
|
||||||
|
|
||||||
if ($typeamount == 'amount')
|
$amountdeposit = array();
|
||||||
|
if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA))
|
||||||
{
|
{
|
||||||
$amountdeposit = $valuedeposit;
|
if ($typeamount == 'amount') $amount = $valuedeposit;
|
||||||
|
else $amount = $srcobject->total_ttc * ($valuedeposit / 100);
|
||||||
|
|
||||||
|
$TTotalByTva = array();
|
||||||
|
foreach ($srcobject->lines as &$line)
|
||||||
|
{
|
||||||
|
$TTotalByTva[$line->tva_tx] += $line->total_ttc ;
|
||||||
|
}
|
||||||
|
|
||||||
|
$amount_to_diff = 0;
|
||||||
|
foreach ($TTotalByTva as $tva => &$total)
|
||||||
|
{
|
||||||
|
$coef = $total / $srcobject->total_ttc; // Calc coef
|
||||||
|
$am = $amount * $coef;
|
||||||
|
$amount_ttc_diff += $am;
|
||||||
|
$amountdeposit[$tva] += $am / (1 + $tva / 100); // Convert into HT for the addline
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($typeamount == 'amount')
|
||||||
|
{
|
||||||
|
$amountdeposit[] = $valuedeposit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$amountdeposit = 0;
|
|
||||||
|
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
$totalamount = 0;
|
$totalamount = 0;
|
||||||
@ -1042,7 +1063,7 @@ if (empty($reshook))
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($totalamount != 0) {
|
if ($totalamount != 0) {
|
||||||
$amountdeposit = ($totalamount * $valuedeposit) / 100;
|
$amountdeposit[] = ($totalamount * $valuedeposit) / 100;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setEventMessages($srcobject->error, $srcobject->errors, 'errors');
|
setEventMessages($srcobject->error, $srcobject->errors, 'errors');
|
||||||
@ -1050,11 +1071,16 @@ if (empty($reshook))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$amount_ttc_diff = $amountdeposit[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($amountdeposit as $tva => $amount)
|
||||||
|
{
|
||||||
$result = $object->addline(
|
$result = $object->addline(
|
||||||
$langs->trans('Deposit'),
|
$langs->trans('Deposit'),
|
||||||
$amountdeposit, // subprice
|
$amount, // subprice
|
||||||
1, // quantity
|
1, // quantity
|
||||||
$lines[$i]->tva_tx, // vat rate
|
$tva, // vat rate
|
||||||
0, // localtax1_tx
|
0, // localtax1_tx
|
||||||
0, // localtax2_tx
|
0, // localtax2_tx
|
||||||
(empty($conf->global->INVOICE_PRODUCTID_DEPOSIT)?0:$conf->global->INVOICE_PRODUCTID_DEPOSIT), // fk_product
|
(empty($conf->global->INVOICE_PRODUCTID_DEPOSIT)?0:$conf->global->INVOICE_PRODUCTID_DEPOSIT), // fk_product
|
||||||
@ -1076,6 +1102,17 @@ if (empty($reshook))
|
|||||||
$langs->trans('Deposit')
|
$langs->trans('Deposit')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$diff = $object->total_ttc - $amount_ttc_diff;
|
||||||
|
|
||||||
|
if ($diff != 0)
|
||||||
|
{
|
||||||
|
$object->fetch_lines();
|
||||||
|
$subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx);
|
||||||
|
$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
|
else
|
||||||
{
|
{
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user