mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
NEW Can enter price tax incl on vendor proposal and purchase orders
This commit is contained in:
parent
bbb5b43e94
commit
d3b4a91f41
|
|
@ -114,6 +114,7 @@ elseif (! empty($socid) && $socid > 0)
|
|||
$permissionnote=$user->rights->fournisseur->commande->creer; // Used by the include of actions_setnotes.inc.php
|
||||
$permissiondellink=$user->rights->fournisseur->commande->creer; // Used by the include of actions_dellink.inc.php
|
||||
$permissiontoedit=$user->rights->fournisseur->commande->creer; // Used by the include of actions_lineupdown.inc.php
|
||||
$permissiontoadd=$user->rights->fournisseur->commande->creer; // Used by the include of actions_addupdatedelete.inc.php
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -432,7 +433,7 @@ if (empty($reshook))
|
|||
if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg))
|
||||
{
|
||||
$idprod=$reg[1];
|
||||
$res=$productsupplier->fetch($idprod); // Load product from its ID
|
||||
$res=$productsupplier->fetch($idprod); // Load product from its id
|
||||
// Call to init some price properties of $productsupplier
|
||||
// So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
|
||||
if (! empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER))
|
||||
|
|
@ -494,7 +495,7 @@ if (empty($reshook))
|
|||
0, // We already have the $idprod always defined
|
||||
$ref_supplier,
|
||||
$remise_percent,
|
||||
'HT',
|
||||
$price_base_type,
|
||||
$pu_ttc,
|
||||
$type,
|
||||
$tva_npr,
|
||||
|
|
@ -511,7 +512,7 @@ if (empty($reshook))
|
|||
// Product not selected
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")).' '.$langs->trans("or").' '.$langs->trans("NoPriceDefinedForThisSupplier"), null, 'errors');
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');
|
||||
}
|
||||
if ($idprod == -1)
|
||||
{
|
||||
|
|
@ -523,8 +524,6 @@ if (empty($reshook))
|
|||
}
|
||||
elseif (empty($error)) // $price_ht is already set
|
||||
{
|
||||
$pu_ht = price2num($price_ht, 'MU');
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
|
||||
$tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
|
||||
$tva_tx = str_replace('*', '', $tva_tx);
|
||||
$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
|
||||
|
|
@ -552,7 +551,7 @@ if (empty($reshook))
|
|||
$price_base_type = 'HT';
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'MU');
|
||||
|
||||
$result=$object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, '', '', $date_start, $date_end, $array_options, $fk_unit, $pu_ht_devise);
|
||||
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, '', '', $date_start, $date_end, $array_options, $fk_unit, $pu_ht_devise);
|
||||
}
|
||||
|
||||
//print "xx".$tva_tx; exit;
|
||||
|
|
@ -652,28 +651,28 @@ if (empty($reshook))
|
|||
if (preg_match('/\*/', $vat_rate))
|
||||
$info_bits |= 0x01;
|
||||
|
||||
// Define vat_rate
|
||||
// Define vat_rate
|
||||
$vat_rate = str_replace('*', '', $vat_rate);
|
||||
$localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
|
||||
$localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
|
||||
|
||||
if (GETPOST('price_ht') != '')
|
||||
{
|
||||
$price_base_type = 'HT';
|
||||
$ht = price2num(GETPOST('price_ht'));
|
||||
$price_base_type = 'HT';
|
||||
$ht = price2num(GETPOST('price_ht'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$vatratecleaned = $vat_rate;
|
||||
if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) // If vat is "xx (yy)"
|
||||
{
|
||||
$vatratecleaned = trim($reg[1]);
|
||||
$vatratecode = $reg[2];
|
||||
}
|
||||
$vatratecleaned = $vat_rate;
|
||||
if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) // If vat is "xx (yy)"
|
||||
{
|
||||
$vatratecleaned = trim($reg[1]);
|
||||
$vatratecode = $reg[2];
|
||||
}
|
||||
|
||||
$ttc = price2num(GETPOST('price_ttc'));
|
||||
$ht = $ttc / (1 + ($vatratecleaned / 100));
|
||||
$price_base_type = 'HT';
|
||||
$ttc = price2num(GETPOST('price_ttc'));
|
||||
$ht = $ttc / (1 + ($vatratecleaned / 100));
|
||||
$price_base_type = 'HT';
|
||||
}
|
||||
|
||||
$pu_ht_devise = GETPOST('multicurrency_subprice');
|
||||
|
|
@ -689,7 +688,7 @@ if (empty($reshook))
|
|||
}
|
||||
}
|
||||
|
||||
$result = $object->updateline(
|
||||
$result = $object->updateline(
|
||||
$lineid,
|
||||
$_POST['product_desc'],
|
||||
$ht,
|
||||
|
|
@ -2282,7 +2281,7 @@ elseif (! empty($object->id))
|
|||
|
||||
// Add free products/services form
|
||||
global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
|
||||
$forceall=1; $dateSelector=0; $inputalsopricewithtax=0;
|
||||
$forceall=1; $dateSelector=0; $inputalsopricewithtax=1;
|
||||
$senderissupplier=2; // $senderissupplier=2 is same than 1 but disable test on minimum qty and disable autofill qty with minimum.
|
||||
//if (! empty($conf->global->SUPPLIER_ORDER_WITH_NOPRICEDEFINED)) $senderissupplier=2;
|
||||
if (! empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) $senderissupplier=1;
|
||||
|
|
|
|||
|
|
@ -1175,7 +1175,7 @@ if (empty($reshook))
|
|||
}
|
||||
if ($prod_entry_mode =='free' && GETPOST('price_ht')==='' && GETPOST('price_ttc')==='' && $price_ht_devise==='') // Unit price can be 0 but not ''
|
||||
{
|
||||
setEventMessages($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), null, 'errors');
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice')), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
if ($prod_entry_mode =='free' && ! GETPOST('dp_desc'))
|
||||
|
|
@ -1332,7 +1332,7 @@ if (empty($reshook))
|
|||
$price_base_type = 'HT';
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'MU');
|
||||
|
||||
$result=$object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_ht_devise, $ref_supplier);
|
||||
$result = $object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_ht_devise, $ref_supplier);
|
||||
}
|
||||
|
||||
//print "xx".$tva_tx; exit;
|
||||
|
|
|
|||
|
|
@ -77,6 +77,9 @@ $NBLINES = 4;
|
|||
if (! empty($user->societe_id)) $socid = $user->societe_id;
|
||||
$result = restrictedArea($user, 'supplier_proposal', $id);
|
||||
|
||||
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
|
||||
$hookmanager->initHooks(array('supplier_proposalcard','globalcard'));
|
||||
|
||||
$object = new SupplierProposal($db);
|
||||
$extrafields = new ExtraFields($db);
|
||||
|
||||
|
|
@ -92,9 +95,6 @@ if ($id > 0 || ! empty($ref)) {
|
|||
dol_print_error('', $object->error);
|
||||
}
|
||||
|
||||
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
|
||||
$hookmanager->initHooks(array('supplier_proposalcard','globalcard'));
|
||||
|
||||
$permissionnote = $user->rights->supplier_proposal->creer; // Used by the include of actions_setnotes.inc.php
|
||||
$permissiondellink=$user->rights->supplier_proposal->creer; // Used by the include of actions_dellink.inc.php
|
||||
$permissiontoedit=$user->rights->supplier_proposal->creer; // Used by the include of actions_lineupdown.inc.php
|
||||
|
|
@ -565,9 +565,9 @@ if (empty($reshook))
|
|||
$error ++;
|
||||
}
|
||||
|
||||
if ($prod_entry_mode == 'free' && empty($idprod) && $price_ht == '') // Unit price can be 0 but not ''. Also price can be negative for proposal.
|
||||
if ($prod_entry_mode == 'free' && empty($idprod) && GETPOST('price_ht')==='' && GETPOST('price_ttc')==='' && $price_ht_devise === '') // Unit price can be 0 but not ''. Also price can be negative for proposal.
|
||||
{
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPrice")), null, 'errors');
|
||||
$error ++;
|
||||
}
|
||||
if ($prod_entry_mode == 'free' && empty($idprod) && empty($product_desc)) {
|
||||
|
|
@ -585,7 +585,7 @@ if (empty($reshook))
|
|||
// Ecrase $pu par celui du produit
|
||||
// Ecrase $desc par celui du produit
|
||||
// Ecrase $txtva par celui du produit
|
||||
if ($prod_entry_mode != 'free' && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
|
||||
if (($prod_entry_mode != 'free') && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
|
||||
{
|
||||
$productsupplier = new ProductFournisseur($db);
|
||||
|
||||
|
|
@ -595,7 +595,7 @@ if (empty($reshook))
|
|||
if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg))
|
||||
{
|
||||
$idprod=$reg[1];
|
||||
$res=$productsupplier->fetch($idprod);
|
||||
$res=$productsupplier->fetch($idprod); // Load product from its ID
|
||||
// Call to init some price properties of $productsupplier
|
||||
// So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
|
||||
if (! empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER))
|
||||
|
|
@ -632,23 +632,21 @@ if (empty($reshook))
|
|||
|
||||
if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
|
||||
|
||||
$pu_ht = $productsupplier->fourn_pu;
|
||||
|
||||
$type = $productsupplier->type;
|
||||
$price_base_type = ($productsupplier->fourn_price_base_type?$productsupplier->fourn_price_base_type:'HT');
|
||||
|
||||
$ref_supplier = $productsupplier->ref_supplier;
|
||||
|
||||
$fk_unit = $productsupplier->fk_unit;
|
||||
|
||||
$tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
$tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
|
||||
if (empty($tva_tx)) $tva_npr=0;
|
||||
$localtax1_tx= get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
|
||||
$localtax2_tx= get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
|
||||
|
||||
$result=$object->addline(
|
||||
$pu_ht = $productsupplier->fourn_pu;
|
||||
if (empty($pu_ht)) $pu_ht = 0; // If pu is '' or null, we force to have a numeric value
|
||||
|
||||
$result=$object->addline(
|
||||
$desc,
|
||||
$pu_ht,
|
||||
$qty,
|
||||
|
|
@ -669,7 +667,7 @@ if (empty($reshook))
|
|||
$label,
|
||||
$array_options,
|
||||
$ref_supplier,
|
||||
$fk_unit,
|
||||
$productsupplier->fk_unit,
|
||||
'',
|
||||
0,
|
||||
$productsupplier->fourn_multicurrency_unitprice
|
||||
|
|
@ -730,6 +728,8 @@ if (empty($reshook))
|
|||
{
|
||||
$db->commit();
|
||||
|
||||
$ret=$object->fetch($object->id); // Reload to get new records
|
||||
|
||||
// Define output language
|
||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
||||
{
|
||||
|
|
@ -798,32 +798,52 @@ if (empty($reshook))
|
|||
// Mise a jour d'une ligne dans la demande de prix
|
||||
elseif ($action == 'updateline' && $user->rights->supplier_proposal->creer && GETPOST('save') == $langs->trans("Save")) {
|
||||
|
||||
$vat_rate=(GETPOST('tva_tx')?GETPOST('tva_tx'):0);
|
||||
|
||||
// Define info_bits
|
||||
$info_bits = 0;
|
||||
if (preg_match('/\*/', GETPOST('tva_tx')))
|
||||
if (preg_match('/\*/', $vat_rate))
|
||||
$info_bits |= 0x01;
|
||||
|
||||
// Clean parameters
|
||||
// Clean parameters
|
||||
$description = dol_htmlcleanlastbr(GETPOST('product_desc', 'none'));
|
||||
|
||||
// Define vat_rate
|
||||
$vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
|
||||
$vat_rate = str_replace('*', '', $vat_rate);
|
||||
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty);
|
||||
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty);
|
||||
$pu_ht = GETPOST('price_ht') ? GETPOST('price_ht') : 0;
|
||||
$localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
|
||||
$localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
|
||||
|
||||
if (GETPOST('price_ht') != '')
|
||||
{
|
||||
$price_base_type = 'HT';
|
||||
$ht = price2num(GETPOST('price_ht'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$vatratecleaned = $vat_rate;
|
||||
if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) // If vat is "xx (yy)"
|
||||
{
|
||||
$vatratecleaned = trim($reg[1]);
|
||||
$vatratecode = $reg[2];
|
||||
}
|
||||
|
||||
$ttc = price2num(GETPOST('price_ttc'));
|
||||
$ht = $ttc / (1 + ($vatratecleaned / 100));
|
||||
$price_base_type = 'HT';
|
||||
}
|
||||
|
||||
$pu_ht_devise = GETPOST('multicurrency_subprice');
|
||||
|
||||
// Add buying price
|
||||
$fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
|
||||
$buyingprice = (GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
|
||||
|
||||
// Extrafields
|
||||
// Extrafields Lines
|
||||
$extrafieldsline = new ExtraFields($db);
|
||||
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
|
||||
$array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line);
|
||||
// Unset extrafield
|
||||
// Unset extrafield POST Data
|
||||
if (is_array($extralabelsline)) {
|
||||
// Get extra fields
|
||||
foreach ($extralabelsline as $key => $value) {
|
||||
unset($_POST["options_" . $key]);
|
||||
}
|
||||
|
|
@ -869,9 +889,33 @@ if (empty($reshook))
|
|||
|
||||
if (! $error) {
|
||||
$db->begin();
|
||||
|
||||
$ref_supplier = GETPOST('fourn_ref', 'alpha');
|
||||
$fk_unit = GETPOST('units');
|
||||
$result = $object->updateline(GETPOST('lineid'), $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $array_options, $ref_supplier, $fk_unit);
|
||||
|
||||
$result = $object->updateline(
|
||||
GETPOST('lineid'),
|
||||
$ht,
|
||||
GETPOST('qty'),
|
||||
GETPOST('remise_percent'),
|
||||
$vat_rate,
|
||||
$localtax1_rate,
|
||||
$localtax2_rate,
|
||||
$description,
|
||||
$price_base_type,
|
||||
$info_bits,
|
||||
$special_code,
|
||||
GETPOST('fk_parent_line'),
|
||||
0,
|
||||
$fournprice,
|
||||
$buyingprice,
|
||||
$label,
|
||||
$type,
|
||||
$array_options,
|
||||
$ref_supplier,
|
||||
$fk_unit,
|
||||
$pu_ht_devise
|
||||
);
|
||||
|
||||
if ($result >= 0) {
|
||||
$db->commit();
|
||||
|
|
@ -1705,8 +1749,8 @@ if ($action == 'create')
|
|||
print '<table id="tablelines" class="noborder noshadow" width="100%">';
|
||||
|
||||
// Add free products/services form
|
||||
global $forceall, $senderissupplier, $dateSelector;
|
||||
$forceall=1; $dateSelector=0;
|
||||
global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
|
||||
$forceall=1; $dateSelector=0; $inputalsopricewithtax=1;
|
||||
$senderissupplier=2; // $senderissupplier=2 is same than 1 but disable test on minimum qty.
|
||||
if (! empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) $senderissupplier=1;
|
||||
|
||||
|
|
|
|||
|
|
@ -655,9 +655,10 @@ class SupplierProposal extends CommonObject
|
|||
* @param array $array_option extrafields array
|
||||
* @param string $ref_supplier Supplier price reference
|
||||
* @param int $fk_unit Id of the unit to use.
|
||||
* @param double $pu_ht_devise Unit price in currency
|
||||
* @return int 0 if OK, <0 if KO
|
||||
*/
|
||||
public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $array_option = 0, $ref_supplier = '', $fk_unit = '')
|
||||
public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $array_option = 0, $ref_supplier = '', $fk_unit = '', $pu_ht_devise = 0)
|
||||
{
|
||||
global $conf,$user,$langs, $mysoc;
|
||||
|
||||
|
|
@ -684,10 +685,17 @@ class SupplierProposal extends CommonObject
|
|||
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
|
||||
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
|
||||
|
||||
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
|
||||
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
|
||||
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty);
|
||||
|
||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
|
||||
// Clean vat code
|
||||
$vat_src_code='';
|
||||
if (preg_match('/\((.*)\)/', $txtva, $reg))
|
||||
{
|
||||
$vat_src_code = $reg[1];
|
||||
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
|
||||
}
|
||||
|
||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
$total_ttc = $tabprice[2];
|
||||
|
|
@ -726,7 +734,9 @@ class SupplierProposal extends CommonObject
|
|||
$this->line->label = $label;
|
||||
$this->line->desc = $desc;
|
||||
$this->line->qty = $qty;
|
||||
$this->line->product_type = $type;
|
||||
$this->line->product_type = $type;
|
||||
|
||||
$this->line->vat_src_code = $vat_src_code;
|
||||
$this->line->tva_tx = $txtva;
|
||||
$this->line->localtax1_tx = $txlocaltax1;
|
||||
$this->line->localtax2_tx = $txlocaltax2;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user