Skip to content

Commit

Permalink
NEW Can enter price tax incl on vendor proposal and purchase orders
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 5, 2019
1 parent bbb5b43 commit d3b4a91
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 53 deletions.
39 changes: 19 additions & 20 deletions htdocs/fourn/commande/card.php
Expand Up @@ -114,6 +114,7 @@
$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


/*
Expand Down Expand Up @@ -432,7 +433,7 @@
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))
Expand Down Expand Up @@ -494,7 +495,7 @@
0, // We already have the $idprod always defined
$ref_supplier,
$remise_percent,
'HT',
$price_base_type,
$pu_ttc,
$type,
$tva_npr,
Expand All @@ -511,7 +512,7 @@
// 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)
{
Expand All @@ -523,8 +524,6 @@
}
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') : '');
Expand Down Expand Up @@ -552,7 +551,7 @@
$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;
Expand Down Expand Up @@ -652,28 +651,28 @@
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');
Expand All @@ -689,7 +688,7 @@
}
}

$result = $object->updateline(
$result = $object->updateline(
$lineid,
$_POST['product_desc'],
$ht,
Expand Down Expand Up @@ -2282,7 +2281,7 @@

// 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;
Expand Down
4 changes: 2 additions & 2 deletions htdocs/fourn/facture/card.php
Expand Up @@ -1175,7 +1175,7 @@
}
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'))
Expand Down Expand Up @@ -1332,7 +1332,7 @@
$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;
Expand Down
96 changes: 70 additions & 26 deletions htdocs/supplier_proposal/card.php
Expand Up @@ -77,6 +77,9 @@
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);

Expand All @@ -92,9 +95,6 @@
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
Expand Down Expand Up @@ -565,9 +565,9 @@
$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)) {
Expand All @@ -585,7 +585,7 @@
// 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);

Expand All @@ -595,7 +595,7 @@
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))
Expand Down Expand Up @@ -632,23 +632,21 @@

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,
Expand All @@ -669,7 +667,7 @@
$label,
$array_options,
$ref_supplier,
$fk_unit,
$productsupplier->fk_unit,
'',
0,
$productsupplier->fourn_multicurrency_unitprice
Expand Down Expand Up @@ -730,6 +728,8 @@
{
$db->commit();

$ret=$object->fetch($object->id); // Reload to get new records

// Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{
Expand Down Expand Up @@ -798,32 +798,52 @@
// 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]);
}
Expand Down Expand Up @@ -869,9 +889,33 @@

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();
Expand Down Expand Up @@ -1705,8 +1749,8 @@
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;

Expand Down
20 changes: 15 additions & 5 deletions htdocs/supplier_proposal/class/supplier_proposal.class.php
Expand Up @@ -655,9 +655,10 @@ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocalt
* @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;

Expand All @@ -684,10 +685,17 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
// 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];
Expand Down Expand Up @@ -726,7 +734,9 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
$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;
Expand Down

0 comments on commit d3b4a91

Please sign in to comment.