Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr.git in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
eldy committed Sep 11, 2012
2 parents 4c05112 + 7712b1c commit c291ea2
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 121 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Expand Up @@ -43,10 +43,11 @@ For users:
- New: [ task #498 ] Improvement of the block to add products/services lines.
- New: ECM autodir works also for files joined to products and services.
- New: Add a selection module for emailing to enter a recipient from gui.
- New: Allow to search product from barcodes directly from the permanent mini search left box
- New: Allow to search product from barcodes directly from invoices, proposals... through AJAX
New experimental modules:
- New: Add margin and commissions management module.
- New: Add holiday module.
- New: Allow to search product from barcodes directly from the permanent mini search left box

- Fix: [ bug #499 ]: Supplier order input method not translated
- Fix: No images into product description lines as PDF generation does
Expand Down
12 changes: 7 additions & 5 deletions htdocs/admin/menus/edit.php
Expand Up @@ -373,17 +373,19 @@ function init_topleft()
print '<tr><td>'.$langs->trans('MenuModule').'</td><td>'.$menu->module.'</td><td>'.$langs->trans('DetailMenuModule').'</td></tr>';

// Handler
print '<tr><td class="fieldrequired">'.$langs->trans('MenuHandler').'</td><td>'.$menu->menu_handler.'</td><td>'.$langs->trans('DetailMenuHandler').'</td></tr>';
if ($menu->menu_handler == 'all') $handler = $langs->trans('AllMenus');
else $handler = $menu->menu_handler;
print '<tr><td class="fieldrequired">'.$langs->trans('MenuHandler').'</td><td>'.$handler.'</td><td>'.$langs->trans('DetailMenuHandler').'</td></tr>';

// User
print '<tr><td nowrap="nowrap" class="fieldrequired">'.$langs->trans('MenuForUsers').'</td><td><select class="flat" name="user">';
print '<option value="2"'.($menu->user==2?' selected="true"':'').'>'.$langs->trans("All").'</option>';
print '<option value="0"'.($menu->user==0?' selected="true"':'').'>'.$langs->trans('Interne').'</option>';
print '<option value="1"'.($menu->user==1?' selected="true"':'').'>'.$langs->trans('Externe').'</option>';
print '<option value="2"'.($menu->user==2?' selected="true"':'').'>'.$langs->trans("AllMenus").'</option>';
print '<option value="0"'.($menu->user==0?' selected="true"':'').'>'.$langs->trans('Internal').'</option>';
print '<option value="1"'.($menu->user==1?' selected="true"':'').'>'.$langs->trans('External').'</option>';
print '</select></td><td>'.$langs->trans('DetailUser').'</td></tr>';

// Type
print '<tr><td class="fieldrequired">'.$langs->trans('Type').'</td><td>'.$menu->type.'</td><td>'.$langs->trans('DetailType').'</td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans('Type').'</td><td>'.$langs->trans(ucfirst($menu->type)).'</td><td>'.$langs->trans('DetailType').'</td></tr>';

// MenuId Parent
print '<tr><td class="fieldrequired">'.$langs->trans('MenuIdParent').'</td>';
Expand Down
4 changes: 3 additions & 1 deletion htdocs/admin/pdf.php
Expand Up @@ -269,7 +269,9 @@
if ($resql)
{
$obj=$db->fetch_object($resql);
$pdfformatlabel=$obj->label.' - '.round($obj->width).'x'.round($obj->height).' '.$obj->unit;
$paperKey = $langs->trans('PaperFormat'.$obj->code);
$unitKey = $langs->trans('SizeUnit'.$obj->unit);
$pdfformatlabel = ($paperKey == 'PaperFormat'.$obj->code ? $obj->label : $paperKey).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
}
}
print $pdfformatlabel;
Expand Down
2 changes: 2 additions & 0 deletions htdocs/compta/facture/class/facture.class.php
Expand Up @@ -110,6 +110,8 @@ class Facture extends CommonInvoice
var $nbtodolate;
var $specimen;

var $fac_rec;


/**
* Constructor
Expand Down
11 changes: 11 additions & 0 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -12,6 +12,7 @@
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1196,6 +1197,11 @@ function select_produits_do($selected='',$htmlname='productid',$filtertype='',$l
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '%".$filterkey."%'";
$sql.=")";
}

if (! empty($conf->barcode->enabled))
{
$sql .= " OR p.barcode LIKE '".$filterkey."'";
}
}
$sql.= $db->order("p.ref");
$sql.= $db->plimit($limit);
Expand Down Expand Up @@ -1441,6 +1447,11 @@ function select_produits_fournisseurs_do($socid,$selected='',$htmlname='producti
{
$sql.=" AND (pfp.ref_fourn LIKE '%".$filterkey."%' OR p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%')";
}

if (! empty($conf->barcode->enabled))
{
$sql .= " OR p.barcode LIKE '".$filterkey."'";
}
}
$sql.= " ORDER BY pfp.ref_fourn DESC";

Expand Down
4 changes: 3 additions & 1 deletion htdocs/core/class/html.formadmin.class.php
Expand Up @@ -339,7 +339,9 @@ function select_paper_format($selected='',$htmlname='paperformat_id',$filter=0,$
while ($i < $num)
{
$obj=$this->db->fetch_object($resql);
$paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.$obj->unit;
$unitKey = $langs->trans('SizeUnit'.$obj->unit);

$paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);

$i++;
}
Expand Down
226 changes: 156 additions & 70 deletions htdocs/core/lib/price.lib.php
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,109 +20,194 @@

/**
* \file htdocs/core/lib/price.lib.php
* \brief Librairie contenant les fonctions pour calculer un prix.
* \brief Library with functions to calculate prices
*/


/**
* Calculate totals (net, vat, ...) of a line.
* Value for localtaxX_type are '0' : local tax not applied
* '1' : local tax apply on products and services without vat (vat is not applied on local tax)
* '2' : local tax apply on products and services before vat (vat is calculated on amount + localtax)
* '3' : local tax apply on products without vat (vat is not applied on local tax)
* '4' : local tax apply on products before vat (vat is calculated on amount + localtax)
* '5' : local tax apply on services without vat (vat is not applied on local tax)
* '6' : local tax apply on services before vat (vat is calculated on amount + localtax)
* '7' : local tax is a fix amount applied on global invoice
*
* @param int $qty Quantity
* @param float $pu Unit price (HT or TTC selon price_base_type)
* @param float $remise_percent_ligne Discount for line
* @param float $txtva Vat rate
* @param float $txlocaltax1 Localtax1 rate (used for some countries only, like spain)
* @param float $txlocaltax2 Localtax2 rate (used for some countries only, like spain)
* @param float $pu Unit price (HT or TTC selon price_base_type)
* @param float $remise_percent_ligne Discount for line
* @param float $txtva Vat rate
* @param float $localtax1_rate Localtax1 rate (used for some countries only, like spain). Can also be negative
* @param float $localtax2_rate Localtax2 rate (used for some countries only, like spain). Can also be negative
* @param float $remise_percent_global 0
* @param string $price_base_type HT=on calcule sur le HT, TTC=on calcule sur le TTC
* @param int $info_bits Miscellanous informations on line
* @return result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount)
* @param int $type 0/1=Product/service
* @param string $localtax1_type Localtax1 type (used for some countries only, like spain)
* @param string $localtax2_type Localtax2 type (used for some countries only, like spain)
* @return result[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount, ...)
*/
function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $txlocaltax1=0, $txlocaltax2=0, $remise_percent_global=0, $price_base_type='HT', $info_bits=0)
function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $localtax1_rate=0, $localtax2_rate=0, $remise_percent_global=0, $price_base_type='HT', $info_bits=0, $type=0, $localtax1_type = '?', $localtax2_type = '?')
{
global $conf,$mysoc;

$result=array();

// We work to define prices using the price without tax
// TODO Remove this code. Added for backward compatibility. To remove once localtaxX_type is provided by caller.
if ($localtax1_type == '?')
{
if ($mysoc->country_code=='ES') $localtax1_type='1';
else $localtax1_type='0';
}
if ($localtax2_type == '?')
{
if ($mysoc->country_code=='ES') $localtax2_type='1';
else $localtax2_type='0';
}

// initialize total (may be HT or TTC depending on price_base_type)
$tot_sans_remise = $pu * $qty;
$tot_avec_remise_ligne = $tot_sans_remise * (1 - ($remise_percent_ligne / 100));
$tot_avec_remise = $tot_avec_remise_ligne * (1 - ($remise_percent_global / 100));

// initialize result
for ($i=0; $i <= 15; $i++)
$result[$i] = 0;

// if there's some localtax including vat, we calculate localtaxes (we will add later)
$localtaxes = array(0,0,0);
$apply_tax = false;
switch($localtax1_type) {
case '2': // localtax on product or service
$apply_tax = true;
break;
case '4': // localtax on product
if ($type == 0) $apply_tax = true;
break;
case '6': // localtax on service
if ($type == 1) $apply_tax = true;
break;
}
if ($apply_tax) {
$result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT');
$localtaxes[0] += $result[14];

$result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT');
$localtaxes[1] += $result[9];

$result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU');
$localtaxes[2] += $result[11];
}

$apply_tax = false;
switch($localtax2_type) {
case '2': // localtax on product or service
$apply_tax = true;
break;
case '4': // localtax on product
if ($type == 0) $apply_tax = true;
break;
case '6': // localtax on service
if ($type == 1) $apply_tax = true;
break;
}
if ($apply_tax) {
$result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT');
$localtaxes[0] += $result[15];

$result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT');
$localtaxes[1] += $result[10];

$result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU');
$localtaxes[2] += $result[12];
}

//dol_syslog("price.lib::calcul_price_total $qty, $pu, $remise_percent_ligne, $txtva, $price_base_type $info_bits");
if ($price_base_type == 'HT')
{
// We work to define prices using the price without tax
$result[6] = price2num($tot_sans_remise, 'MT');
$result[8] = price2num($tot_sans_remise * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result8bis= price2num($tot_sans_remise * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[7] = price2num($result8bis - $result[6], 'MT');
$result[8] = price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result8bis= price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[7] = price2num($result8bis - ($result[6] + $localtaxes[0]), 'MT');

$result[0] = price2num($tot_avec_remise, 'MT');
$result[2] = price2num($tot_avec_remise * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result2bis= price2num($tot_avec_remise * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)

$result[1] = price2num($result2bis - $result[0], 'MT'); // Total VAT = TTC - HT
$result[2] = price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result2bis= price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[1] = price2num($result2bis - ($result[0] + $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax)

$result[3] = price2num($pu, 'MU');
$result[5] = price2num($pu * (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
$result5bis= price2num($pu * (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
$result[4] = price2num($result5bis - $result[3], 'MU');
}
else
{
$result[8] = price2num($tot_sans_remise, 'MT');
$result[6] = price2num($tot_sans_remise / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result6bis= price2num($tot_sans_remise / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[7] = price2num($result[8] - $result6bis, 'MT');

$result[2] = price2num($tot_avec_remise, 'MT');
$result[0] = price2num($tot_avec_remise / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result0bis= price2num($tot_avec_remise / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)

$result[1] = price2num($result[2] - $result0bis, 'MT'); // Total VAT = TTC - HT

$result[5] = price2num($pu, 'MU');
$result[3] = price2num($pu / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
$result3bis= price2num($pu / (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
$result[4] = price2num($result[5] - $result3bis, 'MU');
}

// Local taxes 1. Local tax1 is a second tax that is added after standard one)
if ($txlocaltax1 > 0)
{
$result[14] = price2num(($result[6] * ( 1 + ( $txlocaltax1 / 100))) - $result[6], 'MT'); // amount tax1 for total_ht_without_discount
$result[9] = price2num(($result[0] * ( 1 + ( $txlocaltax1 / 100))) - $result[0], 'MT'); // amount tax1 for total_ht
$result[11] = price2num(($result[3] * ( 1 + ( $txlocaltax1 / 100))) - $pu, 'MU'); // amount tax1 for pu_ht

$result[8] = price2num($result[8] + $result[14], 'MT'); // total_ttc_without_discount + tax1
$result[2] = price2num($result[2] + $result[9], 'MT'); // total_ttc + tax1
$result[5] = price2num($result[5] + $result[11], 'MU'); // pu_ht + tax1
$result[5] = price2num(($pu + $localtaxes[2]) * (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
$result5bis= price2num(($pu + $localtaxes[2]) * (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
$result[4] = price2num($result5bis - ($result[3] + $localtaxes[2]), 'MU');
}
else
{
$result[14] = 0;
$result[9] = 0;
$result[11] = 0;
// We work to define prices using the price with tax
$result[8] = price2num($tot_sans_remise + $localtaxes[0], 'MT');
$result[6] = price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result6bis= price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[7] = price2num($result[8] - ($result6bis + $localtaxes[0]), 'MT');

$result[2] = price2num($tot_avec_remise + $localtaxes[1], 'MT');
$result[0] = price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
$result0bis= price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
$result[1] = price2num($result[2] - ($result0bis + $localtaxes[1]), 'MT'); // Total VAT = TTC - HT

$result[5] = price2num(($pu + $localtaxes[2]), 'MU');
$result[3] = price2num(($pu + $localtaxes[2]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
$result3bis= price2num(($pu + $localtaxes[2]) / (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
$result[4] = price2num($result[5] - ($result3bis + $localtaxes[2]), 'MU');
}

// Local taxes 2. Local tax2 is a second tax that is substracted after standard one)
// Example: Country = Spain, localtax2 is IRPF
if ($txlocaltax2 > 0)
{
$result[15] = price2num(($result[6] * ( 1 + ( $txlocaltax2 / 100))) - $result[6], 'MT'); // amount tax2 for total_ht_without_discount
$result[10] = price2num(($result[0] * ( 1 + ( $txlocaltax2 / 100))) - $result[0], 'MT'); // amount tax2 for total_ht
$result[12] = price2num(($result[3] * ( 1 + ( $txlocaltax2 / 100))) - $pu, 'MU'); // amount tax2 for pu_ht

$result[8] = price2num($result[8] - $result[15], 'MT'); // total_ttc_without_discount + tax2
$result[2] = price2num($result[2] - $result[10], 'MT'); // total_ttc + tax2
$result[5] = price2num($result[5] - $result[12], 'MU'); // pu_ttc + tax2
}
else
{
$result[15] = 0;
$result[10] = 0;
$result[12] = 0;
}
// if there's some localtax without vat, we calculate localtaxes (we will add them at end)
$apply_tax = false;
switch($localtax1_type) {
case '1': // localtax on product or service
$apply_tax = true;
break;
case '3': // localtax on product
if ($type == 0) $apply_tax = true;
break;
case '5': // localtax on service
if ($type == 1) $apply_tax = true;
break;
}
if ($apply_tax) {
$result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax1 for total_ht_without_discount
$result[8] += $result[14]; // total_ttc_without_discount + tax1

$result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax1 for total_ht
$result[2] += $result[9]; // total_ttc + tax1

$result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); // amount tax1 for pu_ht
$result[5] += $result[11]; // pu_ht + tax1
}

$apply_tax = false;
switch($localtax2_type) {
case '1': // localtax on product or service
$apply_tax = true;
break;
case '3': // localtax on product
if ($type == 0) $apply_tax = true;
break;
case '5': // localtax on service
if ($type == 1) $apply_tax = true;
break;
}
if ($apply_tax) {
$result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax2 for total_ht_without_discount
$result[8] += $result[15]; // total_ttc_without_discount + tax2

$result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax2 for total_ht
$result[2] += $result[10]; // total_ttc + tax2

$result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); // amount tax2 for pu_ht
$result[5] += $result[12]; // pu_ht + tax2
}

// If rounding is not using base 10 (rare)
if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT))
Expand Down

0 comments on commit c291ea2

Please sign in to comment.