diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 2103c50dd99..3338317702b 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -359,7 +359,7 @@ if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->v
if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate))
{
$idwarehouse=GETPOST('idwarehouse');
-
+
$object->fetch($id);
$object->fetch_thirdparty();
@@ -380,13 +380,13 @@ if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS
$sql = 'SELECT pf.amount';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
$sql.= ' WHERE pf.fk_facture = '.$object->id;
-
+
$result = $db->query($sql);
if ($result)
{
$i = 0;
$num = $db->num_rows($result);
-
+
while ($i < $num)
{
$objp = $db->fetch_object($result);
@@ -398,17 +398,17 @@ if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS
{
dol_print_error($db,'');
}
-
+
$resteapayer = $object->total_ttc - $totalpaye;
-
+
// On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
$ventilExportCompta = $object->getVentilExportCompta();
-
+
// On verifie si aucun paiement n'a ete effectue
if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
{
$object->set_draft($user, $idwarehouse);
-
+
// Define output language
$outputlangs = $langs;
$newlang='';
@@ -1937,8 +1937,13 @@ else
if ($object->paye) $resteapayer=0;
$resteapayeraffiche=$resteapayer;
- $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
- $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
+ //$filterabsolutediscount="fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
+ //$filtercreditnote="fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
+ $filterabsolutediscount="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')";
+ $filtercreditnote="fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'";
+
+ $absolute_discount=$soc->getAvailableDiscounts('',$filterabsolutediscount);
+ $absolute_creditnote=$soc->getAvailableDiscounts('',$filtercreditnote);
$absolute_discount=price2num($absolute_discount,'MT');
$absolute_creditnote=price2num($absolute_creditnote,'MT');
@@ -2259,9 +2264,8 @@ else
else
{
// Remise dispo de type remise fixe (not credit note)
- $filter='fk_facture_source IS NULL';
print '
';
- $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filter, $resteapayer, ' ('.$addabsolutediscount.')');
+ $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount, $resteapayer, ' ('.$addabsolutediscount.')');
}
}
else
@@ -2291,9 +2295,8 @@ else
else
{
// Remise dispo de type avoir
- $filter='fk_facture_source IS NOT NULL';
if (! $absolute_discount) print '
';
- $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filter, $resteapayer);
+ $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer);
}
}
if (! $absolute_discount && ! $absolute_creditnote)
diff --git a/htdocs/compta/paiement/liste.php b/htdocs/compta/paiement/liste.php
index 22e9f9463a3..a9237f22b11 100644
--- a/htdocs/compta/paiement/liste.php
+++ b/htdocs/compta/paiement/liste.php
@@ -89,13 +89,12 @@ else
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid AND s.entity = ".$conf->entity;
if (!$user->rights->societe->client->voir && !$socid)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
}
$sql.= " WHERE p.fk_paiement = c.id";
- $sql.= " AND s.entity = ".$conf->entity;
if (!$user->rights->societe->client->voir && !$socid)
{
$sql.= " AND sc.fk_user = " .$user->id;
diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php
index c0f2a76c933..74c8b6ec707 100644
--- a/htdocs/compta/stats/cabyuser.php
+++ b/htdocs/compta/stats/cabyuser.php
@@ -35,7 +35,7 @@ accessforbidden();
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->global->COMPTA_MODE;
-if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
+if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta");
$sortorder=isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
$sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
@@ -121,7 +121,10 @@ else {
$builddate=time();
//$exportlink=$langs->trans("NotYetAvailable");
}
-report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
+$moreparam=array();
+if (! empty($modecompta)) $moreparam['modecompta']=$modecompta;
+
+report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,$moreparam);
// Charge tableau
@@ -136,7 +139,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= " f.type = 0"; // Standard
$sql.= " OR f.type = 1"; // Replacement
$sql.= " OR f.type = 2"; // Credit note
- //$sql.= " OR f.type = 3"; // We do not include deposit
+ $sql.= " OR f.type = 3"; // Deposit
$sql.= ")";
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
}
diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php
index 521045f1516..10ae1903620 100644
--- a/htdocs/compta/stats/casoc.php
+++ b/htdocs/compta/stats/casoc.php
@@ -32,7 +32,7 @@ $langs->load("companies");
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->global->COMPTA_MODE;
-if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
+if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta");
$sortorder=isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
$sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
@@ -124,7 +124,9 @@ else {
$builddate=time();
//$exportlink=$langs->trans("NotYetAvailable");
}
-report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
+$moreparam=array();
+if (! empty($modecompta)) $moreparam['modecompta']=$modecompta;
+report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,$moreparam);
// Charge tableau
@@ -139,7 +141,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= " f.type = 0"; // Standard
$sql.= " OR f.type = 1"; // Replacement
$sql.= " OR f.type = 2"; // Credit note
- //$sql.= " OR f.type = 3"; // We do not include deposit
+ $sql.= " OR f.type = 3"; // Deposit
$sql.= ")";
$sql.= " AND f.fk_soc = s.rowid";
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php
index 52c571298ce..ebbec0f43af 100644
--- a/htdocs/compta/stats/index.php
+++ b/htdocs/compta/stats/index.php
@@ -87,7 +87,7 @@ if ($modecompta == 'CREANCES-DETTES') {
$sql.= " f.type = 0"; // Standard
$sql.= " OR f.type = 1"; // Replacement
$sql.= " OR f.type = 2"; // Credit note
- //$sql.= " OR f.type = 3"; // We do not include deposit
+ $sql.= " OR f.type = 3"; // Deposit
$sql.= ")";
} else {
/*
@@ -221,7 +221,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
if ($cum[$case])
{
$now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
- print ''.price($cum[$case],1).'';
+ print ''.price($cum[$case],1).'';
}
else
{
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 38ef6df39d2..e23d5694880 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2023,6 +2023,7 @@ abstract class CommonObject
* TODO Move this into an output class file (htmlline.class.php)
* If lines are into a template, title must also be into a template
* But for the moment we don't know if it's possible as we keep a method available on overloaded objects.
+ *
* @param $action GET/POST action
* @param $line Selected object line to output
* @param $var Is it a an odd line
diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php
index 093a227ced0..a759be3df03 100644
--- a/htdocs/core/class/discount.class.php
+++ b/htdocs/core/class/discount.class.php
@@ -352,7 +352,7 @@ class DiscountAbsolute
$sql.= " WHERE (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available
if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id;
if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id;
- if ($filter) $sql.=' AND '.$filter;
+ if ($filter) $sql.=' AND ('.$filter.')';
if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue);
dol_syslog(get_class($this)."::getAvailableDiscounts sql=".$sql,LOG_DEBUG);
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 587ad9470a1..f7ddd7cfc24 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -2710,7 +2710,7 @@ class Form
* @param float $amount Total amount available
* @param string $filter SQL filter on discounts
* @param int $maxvalue Max value for lines that can be selected
- * @param string $more More string to add
+ * @param string $more More string to add
* @return void
*/
function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $amount, $filter='', $maxvalue=0, $more='')
@@ -2723,19 +2723,19 @@ class Form
print '';
print '
| '; - if (! $filter || $filter=='fk_facture_source IS NULL') print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': '; + //if (! $filter || $filter=="fk_facture_source IS NULL") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': '; // If we want deposit to be substracted to payments only and not to total of final invoice + if (! $filter || $filter=="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': '; else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': '; $newfilter='fk_facture IS NULL AND fk_facture_line IS NULL'; // Remises disponibles - if ($filter) $newfilter.=' AND '.$filter; + if ($filter) $newfilter.=' AND ('.$filter.')'; $nbqualifiedlines=$this->select_remises($selected,$htmlname,$newfilter,$socid,$maxvalue); print ' | '; print ''; if ($nbqualifiedlines > 0) { - print ' trans("UseCredit"); - print '" title="'.$langs->trans("UseCreditNoteInInvoicePayment").'">'; + print ' '; } if ($more) print $more; print ' | '; diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 341fe8529cc..3db6fe164c8 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -748,6 +748,14 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl $discount->fetch($object->lines[$i]->fk_remise_except); $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source); } + elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except) + { + $discount=new DiscountAbsolute($db); + $discount->fetch($object->lines[$i]->fk_remise_except); + $libelleproduitservice=$outputlangs->transnoentities("DiscountFromDeposit",$discount->ref_facture_source); + // Add date of deposit + if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')'; + } else { if ($idprod) diff --git a/htdocs/core/lib/report.lib.php b/htdocs/core/lib/report.lib.php index 2df28ab9218..79c3efb8dfc 100644 --- a/htdocs/core/lib/report.lib.php +++ b/htdocs/core/lib/report.lib.php @@ -24,15 +24,17 @@ /** * Show header of a VAT report -* @param nom Name of report -* @param variante Link for alternate report -* @param period Period of report -* @param periodlink Link to switch period -* @param description Description -* @param builddate Date generation -* @param exportlink Link for export or '' +* +* @param $nom Name of report +* @param $variante Link for alternate report +* @param $period Period of report +* @param $periodlink Link to switch period +* @param $description Description +* @param $builddate Date generation +* @param $exportlink Link for export or '' +* @param $moreparam Array with list of params to add into form */ -function report_header($nom,$variante='',$period,$periodlink,$description,$builddate,$exportlink='') +function report_header($nom,$variante='',$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array()) { global $langs; @@ -44,6 +46,10 @@ function report_header($nom,$variante='',$period,$periodlink,$description,$build dol_fiche_head($head, $hselected, $societe->nom); print '