NEW Can change VAT rate of all lines of a draft object in one step.

This commit is contained in:
Laurent Destailleur 2020-07-06 22:48:22 +02:00
parent 33a78dbcef
commit 14c98f277b
5 changed files with 51 additions and 16 deletions

View File

@ -775,8 +775,16 @@ if (empty($reshook))
}
}
}
} // Add line
elseif ($action == 'addline' && $usercancreate) {
} elseif ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha')) {
// Define vat_rate
$vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
$vat_rate = str_replace('*', '', $vat_rate);
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
foreach($object->lines as $line) {
$result = $object->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $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, $line->multicurrency_subprice);
}
} elseif ($action == 'addline' && $usercancreate) { // Add line
// Set if we used free entry or predefined product
$predef = '';
$product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : '');

View File

@ -725,15 +725,15 @@ class Propal extends CommonObject
/**
* Update a proposal line
*
* @param int $rowid Id de la ligne
* @param float $pu Prix unitaire (HT ou TTC selon price_base_type)
* @param int $rowid Id of line
* @param float $pu Unit price (HT or TTC depending on price_base_type)
* @param float $qty Quantity
* @param float $remise_percent Remise effectuee sur le produit
* @param float $txtva Taux de TVA
* @param float $remise_percent Discount on line
* @param float $txtva VAT Rate (Can be '1.23' or '1.23 (ABC)')
* @param float $txlocaltax1 Local tax 1 rate
* @param float $txlocaltax2 Local tax 2 rate
* @param string $desc Description
* @param string $price_base_type HT ou TTC
* @param string $price_base_type HT or TTC
* @param int $info_bits Miscellaneous informations
* @param int $special_code Special code (also used by externals modules!)
* @param int $fk_parent_line Id of parent line (0 in most cases, used by modules adding sublevels into lines).
@ -4121,6 +4121,8 @@ class PropaleLigne extends CommonObjectLine
$pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
if (empty($this->id) && ! empty($this->rowid)) $this->id = $this->rowid;
// Clean parameters
if (empty($this->tva_tx)) $this->tva_tx = 0;
if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
@ -4194,7 +4196,7 @@ class PropaleLigne extends CommonObjectLine
$sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql .= " WHERE rowid = ".$this->rowid;
$sql .= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
@ -4202,7 +4204,6 @@ class PropaleLigne extends CommonObjectLine
{
if (!$error)
{
$this->id = $this->rowid;
$result = $this->insertExtraFields();
if ($result < 0)
{

View File

@ -624,10 +624,16 @@ if (empty($reshook))
$result = $object->set_remise($user, GETPOST('remise_percent'));
} elseif ($action == 'setremiseabsolue' && $usercancreate) {
$result = $object->set_remise_absolue($user, GETPOST('remise_absolue'));
}
// Add a new line
elseif ($action == 'addline' && $usercancreate)
} elseif ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha')) {
// Define vat_rate
$vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
$vat_rate = str_replace('*', '', $vat_rate);
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
foreach($object->lines as $line) {
$result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
}
} elseif ($action == 'addline' && $usercancreate) // Add a new line
{
$langs->load('errors');
$error = 0;

View File

@ -1867,8 +1867,16 @@ if (empty($reshook))
$_GET["originid"] = $_POST["originid"];
setEventMessages($object->error, $object->errors, 'errors');
}
} // Add a new line
elseif ($action == 'addline' && $usercancreate)
} elseif ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha')) {
// Define vat_rate
$vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
$vat_rate = str_replace('*', '', $vat_rate);
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
foreach($object->lines as $line) {
$result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice);
}
} elseif ($action == 'addline' && $usercancreate) // Add a new line
{
$langs->load('errors');
$error = 0;

View File

@ -59,7 +59,19 @@ if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier'
}
// VAT
print '<td class="linecolvat right" style="width: 80px">'.$langs->trans('VAT').'</td>';
print '<td class="linecolvat right" style="width: 80px">'.$langs->trans('VAT');
if (in_array($object->element, array('propal', 'commande', 'facture')) && $object->status == $object::STATUS_DRAFT)
{
global $mysoc;
print img_edit($langs->trans("UpdateForAllLines"), 0, 'class="clickvatforalllines opacitymedium paddingleft"');
print '<script>$(document).ready(function() { $(".clickvatforalllines").click(function() { jQuery(".classvatforalllines").toggle(); }); });</script>';
print '<div class="classvatforalllines hidden inline-block nowraponall">';
//print '<input class="inline-block maxwidth50" type="text" name="vatforalllines" id="vatforalllines" value="">';
print $form->load_tva('vatforalllines', '', $mysoc, $object->thirdparty, 0, 0, '', false, 1);
print '<input class="inline-block" type="submit" name="submitforalllines" value="'.$langs->trans("Update").'">';
print '</div>';
}
print '</td>';
// Price HT
print '<td class="linecoluht right" style="width: 80px">'.$langs->trans('PriceUHT').'</td>';