forked from Wavyzz/dolibarr
Merge pull request #23758 from marcusdeangabriel/PROPALE_MODIFY_MARGIN_RATES
NEW Can modify margin rates in offers like VAT rates.
This commit is contained in:
@@ -914,6 +914,37 @@ if (empty($reshook)) {
|
||||
foreach ($object->lines as $line) {
|
||||
$result = $object->updateline($line->id, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
|
||||
}
|
||||
} elseif ($action == 'addline' && GETPOST('submitforallmargins', 'alpha') && GETPOST('marginforalllines') !== '' && $usercancreate) {
|
||||
// Define margin
|
||||
$margin_rate = (GETPOST('marginforalllines') ? GETPOST('marginforalllines') : 0);
|
||||
foreach ($object->lines as &$line) {
|
||||
$subprice = price2num($line->pa_ht * (1 + $margin_rate/100), 'MU');
|
||||
$prod = new Product($db);
|
||||
$prod->fetch($line->fk_product);
|
||||
if ($prod->price_min > $subprice) {
|
||||
$price_subprice = price($subprice, 0, $outlangs, 1, -1, -1, 'auto');
|
||||
$price_price_min = price($prod->price_min, 0, $outlangs, 1, -1, -1, 'auto');
|
||||
setEventMessages($prod->ref.' - '.$prod->label.' ('.$price_subprice.' < '.$price_price_min.' '.strtolower($langs->trans("MinPrice")).')'."\n", null, 'warnings');
|
||||
}
|
||||
// Manage $line->subprice and $line->multicurrency_subprice
|
||||
$multicurrency_subprice = $subprice * $line->multicurrency_subprice / $line->subprice;
|
||||
// Update DB
|
||||
$result = $object->updateline($line->id, $subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_rate, $line->localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $multicurrency_subprice);
|
||||
// Update $object with new margin info
|
||||
$line->price = $subprice;
|
||||
$line->marge_tx = $margin_rate;
|
||||
$line->marque_tx = $margin_rate * $line->pa_ht / $subprice;
|
||||
$line->total_ht = $line->qty * $subprice;
|
||||
$line->total_tva = $line->tva_tx * $line->qty * $subprice;
|
||||
$line->total_ttc = (1 + $line->tva_tx) * $line->qty * $subprice;
|
||||
// Manage $line->subprice and $line->multicurrency_subprice
|
||||
$line->multicurrency_total_ht = $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice;
|
||||
$line->multicurrency_total_tva = $line->tva_tx * $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice;
|
||||
$line->multicurrency_total_ttc = (1 + $line->tva_tx) * $line->qty * $subprice * $line->multicurrency_subprice / $line->subprice;
|
||||
// Used previous $line->subprice and $line->multicurrency_subprice above, now they can be set to their new values
|
||||
$line->subprice = $subprice;
|
||||
$line->multicurrency_subprice = $multicurrency_subprice;
|
||||
}
|
||||
} elseif ($action == 'addline' && $usercancreate) { // Add line
|
||||
// Set if we used free entry or predefined product
|
||||
$predef = '';
|
||||
|
||||
@@ -141,7 +141,17 @@ if ($usemargins && isModEnabled('margin') && empty($user->socid)) {
|
||||
}
|
||||
|
||||
if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) {
|
||||
print '<th class="linecolmargin2 margininfos right" style="width: 50px">'.$langs->trans('MarginRate').'</th>';
|
||||
print '<th class="linecolmargin2 margininfos right" style="width: 50px">'.$langs->trans('MarginRate');
|
||||
if ($user->hasRight("propal", "creer")) {
|
||||
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?mode=marginforalllines&id='.$object->id.'">'.img_edit($langs->trans("UpdateForAllLines"), 0, 'class="clickmarginforalllines opacitymedium paddingleft cursorpointer"').'</a>';
|
||||
if (GETPOST('mode', 'aZ09') == 'marginforalllines') {
|
||||
print '<div class="classmarginforalllines inline-block nowraponall">';
|
||||
print '<input type="number" name="marginforalllines" min="0" max="999.9" value="20.0" step="0.1"><label>%</label>';
|
||||
print '<input class="inline-block button smallpaddingimp" type="submit" name="submitforallmargins" value="'.$langs->trans("Update").'">';
|
||||
print '</div>';
|
||||
}
|
||||
}
|
||||
print '</th>';
|
||||
}
|
||||
if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) {
|
||||
print '<th class="linecolmargin2 margininfos right" style="width: 50px">'.$langs->trans('MarkRate').'</th>';
|
||||
|
||||
@@ -6,6 +6,7 @@ TotalMargin=Total Margin
|
||||
MarginOnProducts=Margin / Products
|
||||
MarginOnServices=Margin / Services
|
||||
MarginRate=Margin rate
|
||||
ModifyMarginRates=Modify margin rates
|
||||
MarkRate=Mark rate
|
||||
DisplayMarginRates=Display margin rates
|
||||
DisplayMarkRates=Display mark rates
|
||||
|
||||
@@ -8,6 +8,7 @@ MarginOnServices=Marge / Services
|
||||
MarginRate=Taux de marge
|
||||
MarkRate=Taux de marque
|
||||
DisplayMarginRates=Afficher les taux de marge
|
||||
ModifyMarginRates=Modifier les taux de marge
|
||||
DisplayMarkRates=Afficher les taux de marque
|
||||
InputPrice=Saisir un prix
|
||||
margin=Gestion des marges
|
||||
|
||||
Reference in New Issue
Block a user