diff --git a/htdocs/compta/bank/class/paymentvarious.class.php b/htdocs/compta/bank/class/paymentvarious.class.php
index 5c8031f2702..6c2e12ba500 100644
--- a/htdocs/compta/bank/class/paymentvarious.class.php
+++ b/htdocs/compta/bank/class/paymentvarious.class.php
@@ -93,7 +93,18 @@ class PaymentVarious extends CommonObject
public $fk_project;
/**
- * @var int ID
+ * @var int Bank account ID
+ */
+ public $fk_account;
+
+ /**
+ * @var int Bank account ID
+ * @deprecated See fk_account
+ */
+ public $accountid;
+
+ /**
+ * @var int ID record into llx_bank
*/
public $fk_bank;
@@ -102,11 +113,6 @@ class PaymentVarious extends CommonObject
*/
public $categorie_transaction;
- /**
- * @var int Account ID
- */
- public $accountid;
-
/**
* @var int ID
*/
@@ -397,6 +403,10 @@ class PaymentVarious extends CommonObject
$this->fk_bank = (int) $this->fk_bank;
$this->fk_user_author = (int) $this->fk_user_author;
$this->fk_user_modif = (int) $this->fk_user_modif;
+ $this->fk_account = (int) $this->fk_account;
+ if (empty($this->fk_account) && isset($this->accountid)) { // For compatibility
+ $this->fk_account = $this->accountid;
+ }
// Check parameters
if (!$this->label)
@@ -409,9 +419,9 @@ class PaymentVarious extends CommonObject
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
return -5;
}
- if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
+ if (!empty($conf->banque->enabled) && (empty($this->fk_account) || $this->fk_account <= 0))
{
- $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
+ $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
return -6;
}
if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
@@ -454,7 +464,7 @@ class PaymentVarious extends CommonObject
$sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 0);
$sql .= ", ".$user->id;
$sql .= ", '".$this->db->idate($now)."'";
- $sql .= ", NULL";
+ $sql .= ", NULL"; // Filled later
$sql .= ", ".$conf->entity;
$sql .= ")";
@@ -473,7 +483,7 @@ class PaymentVarious extends CommonObject
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db);
- $result = $acc->fetch($this->accountid);
+ $result = $acc->fetch($this->fk_account);
if ($result <= 0) dol_print_error($this->db);
// Insert payment into llx_bank
@@ -495,7 +505,7 @@ class PaymentVarious extends CommonObject
$this->datev
);
- // Update fk_bank into llx_paiement.
+ // Update fk_bank into llx_payment_various
// So we know the payment which has generate the banking ecriture
if ($bank_line_id > 0) {
$this->update_fk_bank($bank_line_id);
diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php
index db539e060d2..dfdad0b589b 100644
--- a/htdocs/compta/bank/various_payment/card.php
+++ b/htdocs/compta/bank/various_payment/card.php
@@ -491,7 +491,7 @@ if ($id)
);
$formquestion[] = array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1);
$formquestion[] = array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1);
- $formquestion[] = array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($accountid, "accountid", 0, '', 1));
+ $formquestion[] = array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($accountid, "accountid", 0, '', 1, '', 0, 'minwidth200', 1));
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 300);
}
diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php
index 8a1655cdefb..3072dcdee2b 100644
--- a/htdocs/compta/resultat/clientfourn.php
+++ b/htdocs/compta/resultat/clientfourn.php
@@ -229,6 +229,8 @@ if ($modecompta == 'BOOKKEEPING')
print "\n";
+$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
+
if ($modecompta == 'BOOKKEEPING')
{
@@ -438,16 +440,97 @@ if ($modecompta == 'BOOKKEEPING')
if ($total_ttc == 0)
{
print '
| | ';
- print ''.$langs->trans("None").' | ';
+ print ''.$langs->trans("None").' | ';
print '
';
}
+ $total_ht_income += $total_ht;
+ $total_ttc_income += $total_ttc;
print '';
if ($modecompta == 'CREANCES-DETTES')
print '| '.price($total_ht).' | ';
print ''.price($total_ttc).' | ';
print '
';
+ /*
+ * Donations
+ */
+
+ if (!empty($conf->don->enabled))
+ {
+ print '| '.$langs->trans("Donations").' |
';
+
+ if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES')
+ {
+ if ($modecompta == 'CREANCES-DETTES')
+ {
+ $sql = "SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
+ $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
+ $sql .= " WHERE p.entity IN (".getEntity('donation').")";
+ $sql .= " AND fk_statut in (1,2)";
+ } else {
+ $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
+ $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
+ $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
+ $sql .= " WHERE p.entity IN (".getEntity('donation').")";
+ $sql .= " AND fk_statut >= 2";
+ }
+ if (!empty($date_start) && !empty($date_end))
+ $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
+ }
+ $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm";
+ $newsortfield = $sortfield;
+ if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'p.societe, p.firstname, p.lastname, dm';
+ if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
+ if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
+ $sql .= $db->order($newsortfield, $sortorder);
+
+ dol_syslog("get dunning");
+ $result = $db->query($sql);
+ $subtotal_ht = 0;
+ $subtotal_ttc = 0;
+ if ($result)
+ {
+ $num = $db->num_rows($result);
+ $i = 0;
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($result);
+
+ $total_ht += $obj->amount;
+ $total_ttc += $obj->amount;
+ $subtotal_ht += $obj->amount;
+ $subtotal_ttc += $obj->amount;
+
+ print '| | ';
+
+ print "".$langs->trans("Donation")." name."&search_name=".$obj->firstname." ".$obj->lastname."\">".$obj->name." ".$obj->firstname." ".$obj->lastname." | \n";
+
+ if ($modecompta == 'CREANCES-DETTES') print ''.price($obj->amount).' | ';
+ print ''.price($obj->amount).' | ';
+ print '
';
+ $i++;
+ }
+ } else {
+ print '| | ';
+ print ''.$langs->trans("None").' | ';
+ print '
';
+ }
+ } else {
+ dol_print_error($db);
+ }
+
+ $total_ht_income += $subtotal_ht;
+ $total_ttc_income += $subtotal_ttc;
+ print '';
+ if ($modecompta == 'CREANCES-DETTES')
+ print '| '.price($subtotal_ht).' | ';
+ print ''.price($subtotal_ttc).' | ';
+ print '
';
+ }
/*
* Suppliers invoices
@@ -515,7 +598,7 @@ if ($modecompta == 'BOOKKEEPING')
}
} else {
print '| | ';
- print ''.$langs->trans("None").' | ';
+ print ''.$langs->trans("None").' | ';
print '
';
}
@@ -523,6 +606,9 @@ if ($modecompta == 'BOOKKEEPING')
} else {
dol_print_error($db);
}
+
+ $total_ht_outcome += $subtotal_ht;
+ $total_ttc_outcome += $subtotal_ttc;
print '';
if ($modecompta == 'CREANCES-DETTES')
print '| '.price(-$subtotal_ht).' | ';
@@ -530,7 +616,6 @@ if ($modecompta == 'BOOKKEEPING')
print '
';
-
/*
* Charges sociales non deductibles
*/
@@ -592,12 +677,15 @@ if ($modecompta == 'BOOKKEEPING')
}
} else {
print '| | ';
- print ''.$langs->trans("None").' | ';
+ print ''.$langs->trans("None").' | ';
print '
';
}
} else {
dol_print_error($db);
}
+
+ $total_ht_outcome += $subtotal_ht;
+ $total_ttc_outcome += $subtotal_ttc;
print '';
if ($modecompta == 'CREANCES-DETTES')
print '| '.price(-$subtotal_ht).' | ';
@@ -667,36 +755,21 @@ if ($modecompta == 'BOOKKEEPING')
}
} else {
print '
| | ';
- print ''.$langs->trans("None").' | ';
+ print ''.$langs->trans("None").' | ';
print '
';
}
} else {
dol_print_error($db);
}
+
+ $total_ht_outcome += $subtotal_ht;
+ $total_ttc_outcome += $subtotal_ttc;
print '';
if ($modecompta == 'CREANCES-DETTES')
print '| '.price(-$subtotal_ht).' | ';
print ''.price(-$subtotal_ttc).' | ';
print '
';
- if ($mysoc->tva_assuj == 'franchise') // Non assujetti
- {
- // Total
- print '';
- print '| | ';
- print '
';
-
- print '| '.$langs->trans("Profit").' | ';
- if ($modecompta == 'CREANCES-DETTES')
- print ''.price($total_ht).' | ';
- print ''.price($total_ttc).' | ';
- print '
';
-
- print '';
- print '| | ';
- print '
';
- }
-
/*
* Salaries
@@ -759,12 +832,15 @@ if ($modecompta == 'BOOKKEEPING')
}
} else {
print '| | ';
- print ''.$langs->trans("None").' | ';
+ print ''.$langs->trans("None").' | ';
print '
';
}
} else {
dol_print_error($db);
}
+
+ $total_ht_outcome += $subtotal_ht;
+ $total_ttc_outcome += $subtotal_ttc;
print '';
if ($modecompta == 'CREANCES-DETTES')
print '| '.price(-$subtotal_ht).' | ';
@@ -841,98 +917,26 @@ if ($modecompta == 'BOOKKEEPING')
}
} else {
print '
| | ';
- print ''.$langs->trans("None").' | ';
+ print ''.$langs->trans("None").' | ';
print '
';
}
} else {
dol_print_error($db);
}
+
+ $total_ht_outcome += $subtotal_ht;
+ $total_ttc_outcome += $subtotal_ttc;
print '';
if ($modecompta == 'CREANCES-DETTES') print '| '.price(-$subtotal_ht).' | ';
print ''.price(-$subtotal_ttc).' | ';
print '
';
}
- /*
- * Donations
- */
-
- if (!empty($conf->don->enabled))
- {
- print '| '.$langs->trans("Donations").' |
';
-
- if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES')
- {
- if ($modecompta == 'CREANCES-DETTES')
- {
- $sql = "SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
- $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
- $sql .= " WHERE p.entity IN (".getEntity('donation').")";
- $sql .= " AND fk_statut in (1,2)";
- } else {
- $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
- $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
- $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
- $sql .= " WHERE p.entity IN (".getEntity('donation').")";
- $sql .= " AND fk_statut >= 2";
- }
- if (!empty($date_start) && !empty($date_end))
- $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
- }
- $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm";
- $newsortfield = $sortfield;
- if ($newsortfield == 's.nom, s.rowid') $newsortfield = 'p.societe, p.firstname, p.lastname, dm';
- if ($newsortfield == 'amount_ht') $newsortfield = 'amount';
- if ($newsortfield == 'amount_ttc') $newsortfield = 'amount';
- $sql .= $db->order($newsortfield, $sortorder);
-
- dol_syslog("get dunning");
- $result = $db->query($sql);
- $subtotal_ht = 0;
- $subtotal_ttc = 0;
- if ($result)
- {
- $num = $db->num_rows($result);
- $i = 0;
- if ($num)
- {
- while ($i < $num)
- {
- $obj = $db->fetch_object($result);
-
- $total_ht += $obj->amount;
- $total_ttc += $obj->amount;
- $subtotal_ht += $obj->amount;
- $subtotal_ttc += $obj->amount;
-
- print '| | ';
-
- print "".$langs->trans("Donation")." name."&search_name=".$obj->firstname." ".$obj->lastname."\">".$obj->name." ".$obj->firstname." ".$obj->lastname." | \n";
-
- if ($modecompta == 'CREANCES-DETTES') print ''.price($obj->amount).' | ';
- print ''.price($obj->amount).' | ';
- print '
';
- $i++;
- }
- } else {
- print '| | ';
- print ''.$langs->trans("None").' | ';
- print '
';
- }
- } else {
- dol_print_error($db);
- }
- print '';
- if ($modecompta == 'CREANCES-DETTES')
- print '| '.price($subtotal_ht).' | ';
- print ''.price($subtotal_ttc).' | ';
- print '
';
- }
/*
* Various Payments
*/
+ //$conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY = 1;
if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->banque->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
{
@@ -953,12 +957,14 @@ if ($modecompta == 'BOOKKEEPING')
$result = $db->query($sql);
if ($result)
{
- // Debit
+ // Debit (payment of suppliers for example)
$obj = $db->fetch_object($result);
if (isset($obj->amount))
{
$subtotal_ht += -$obj->amount;
$subtotal_ttc += -$obj->amount;
+ $total_ht_outcome += $obj->amount;
+ $total_ttc_outcome += $obj->amount;
}
print '| | ';
print "".$langs->trans("Debit")." | \n";
@@ -966,12 +972,14 @@ if ($modecompta == 'BOOKKEEPING')
print ''.price(-$obj->amount)." | \n";
print "
\n";
- // Credit
+ // Credit (payment received from customer for example)
$obj = $db->fetch_object($result);
if (isset($obj->amount))
{
$subtotal_ht += $obj->amount;
$subtotal_ttc += $obj->amount;
+ $total_ht_income += $obj->amount;
+ $total_ttc_income += $obj->amount;
}
print '| | ';
print "".$langs->trans("Credit")." | \n";
@@ -1030,6 +1038,8 @@ if ($modecompta == 'BOOKKEEPING')
}
$total_ht += $subtotal_ht;
$total_ttc += $subtotal_ttc;
+ $total_ht_income += $subtotal_ht;
+ $total_ttc_income += $subtotal_ttc;
print '
';
if ($modecompta == 'CREANCES-DETTES')
print '| '.price($subtotal_ht).' | ';
@@ -1050,7 +1060,7 @@ if ($modecompta == 'BOOKKEEPING')
{
if ($modecompta == 'CREANCES-DETTES')
{
- // TVA a payer
+ // VAT to pay
$amount = 0;
$sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.tva) as amount";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
@@ -1091,13 +1101,15 @@ if ($modecompta == 'BOOKKEEPING')
} else {
dol_print_error($db);
}
+ $total_ht_outcome -= 0;
+ $total_ttc_outcome -= $amount;
print '
| | ';
print "".$langs->trans("VATToPay")." | \n";
print ' | '."\n";
print ''.price($amount)." | \n";
print "
\n";
- // TVA a recuperer
+ // VAT to retreive
$amount = 0;
$sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
@@ -1139,6 +1151,9 @@ if ($modecompta == 'BOOKKEEPING')
} else {
dol_print_error($db);
}
+ $total_ht_income += 0;
+ $total_ttc_income += $amount;
+
print '| | ';
print ''.$langs->trans("VATToCollect")." | \n";
print ' | '."\n";
@@ -1182,10 +1197,12 @@ if ($modecompta == 'BOOKKEEPING')
} else {
dol_print_error($db);
}
+ $total_ht_outcome -= 0;
+ $total_ttc_outcome -= $amount;
print '
| | ';
print "".$langs->trans("VATPaid")." | \n";
if ($modecompta == 'CREANCES-DETTES')
- print ''.price($amount)." | \n";
+ print ' | '."\n";
print ''.price($amount)." | \n";
print "
\n";
@@ -1226,16 +1243,18 @@ if ($modecompta == 'BOOKKEEPING')
} else {
dol_print_error($db);
}
+ $total_ht_income += 0;
+ $total_ttc_income += $amount;
print '| | ';
print "".$langs->trans("VATCollected")." | \n";
if ($modecompta == 'CREANCES-DETTES')
- print ''.price($amount)." | \n";
+ print ' | '."\n";
print ''.price($amount)." | \n";
print "
\n";
}
}
- if ($mysoc->tva_assuj != 'franchise') // Assujetti
+ if ($mysoc->tva_assuj != '0') // Assujetti
{
print '';
if ($modecompta == 'CREANCES-DETTES')
@@ -1250,25 +1269,31 @@ $object = array(&$total_ht, &$total_ttc);
$parameters["mode"] = $modecompta;
$parameters["date_start"] = $date_start;
$parameters["date_end"] = $date_end;
-$parameters["bc"] = $bc;
// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('externalbalance'));
$reshook = $hookmanager->executeHooks('addBalanceLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
print $hookmanager->resPrint;
-if ($mysoc->tva_assuj != 'franchise') // Assujetti
-{
- // Total
- print '
';
- print '| | ';
- print '
';
+// Total
+print '';
+print '| | ';
+print '
';
- print '| '.$langs->trans("Profit").' | ';
- if ($modecompta == 'CREANCES-DETTES')
- print ''.price(price2num($total_ht, 'MT')).' | ';
- print ''.price(price2num($total_ttc, 'MT')).' | ';
- print '
';
-}
+print '| '.$langs->trans("Outcome").' | ';
+if ($modecompta == 'CREANCES-DETTES')
+ print ''.price(price2num(-$total_ht_outcome, 'MT')).' | ';
+print ''.price(price2num(-$total_ttc_outcome, 'MT')).' | ';
+print '
';
+print '| '.$langs->trans("Income").' | ';
+if ($modecompta == 'CREANCES-DETTES')
+ print ''.price(price2num($total_ht_income, 'MT')).' | ';
+print ''.price(price2num($total_ttc_income, 'MT')).' | ';
+print '
';
+print '| '.$langs->trans("Profit").' | ';
+if ($modecompta == 'CREANCES-DETTES')
+ print ''.price(price2num($total_ht, 'MT')).' | ';
+print ''.price(price2num($total_ttc, 'MT')).' | ';
+print '
';
print "";
print '
';
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index bfdea016ea6..47c025b0c0a 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -355,7 +355,7 @@ abstract class CommonObject
public $last_main_doc;
/**
- * @var int Bank account ID
+ * @var int Bank account ID sometimes, ID of record into llx_bank sometimes
* @deprecated
* @see $fk_account
*/
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 14bbf007542..492a4899376 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3939,13 +3939,16 @@ class Form
* @param string $moreattrib To add more attribute on select
* @param int $showcurrency Show currency in label
* @param string $morecss More CSS
+ * @param int $nooutput 1=Return string, do not send to output
* @return int <0 if error, Num of bank account found if OK (0, 1, 2, ...)
*/
- public function select_comptes($selected = '', $htmlname = 'accountid', $status = 0, $filtre = '', $useempty = 0, $moreattrib = '', $showcurrency = 0, $morecss = '')
+ public function select_comptes($selected = '', $htmlname = 'accountid', $status = 0, $filtre = '', $useempty = 0, $moreattrib = '', $showcurrency = 0, $morecss = '', $nooutput = 0)
{
// phpcs:enable
global $langs, $conf;
+ $out = '';
+
$langs->load("admin");
$num = 0;
@@ -3964,10 +3967,10 @@ class Form
$i = 0;
if ($num)
{
- print '";
+ $out .= ajax_combobox('select'.$htmlname);
} else {
- if ($status == 0) print ''.$langs->trans("NoActiveBankAccountDefined").'';
- else print ''.$langs->trans("NoBankAccountFound").'';
+ if ($status == 0) $out .= ''.$langs->trans("NoActiveBankAccountDefined").'';
+ else $out .= ''.$langs->trans("NoBankAccountFound").'';
}
} else {
dol_print_error($this->db);
}
+ // Output or return
+ if (empty($nooutput)) print $out;
+ else return $out;
+
return $num;
}