diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php
index 70580ee6a76..6c30ab2ff9e 100644
--- a/htdocs/compta/paiement/class/paiement.class.php
+++ b/htdocs/compta/paiement/class/paiement.class.php
@@ -58,6 +58,8 @@ class Paiement extends CommonObject
public $picto = 'payment';
public $facid;
+ public $socid;
+
public $datepaye;
public $date; // same than $datepaye
@@ -921,21 +923,21 @@ class Paiement extends CommonObject
/**
* Updates the payment number
*
- * @param string $num New num
- * @return int <0 if KO, 0 if OK
+ * @param string $num_payment New num
+ * @return int <0 if KO, 0 if OK
*/
- public function update_num($num)
+ public function update_num($num_payment)
{
// phpcs:enable
- if (!empty($num) && $this->statut != 1) {
+ if (!empty($num_payment) && $this->statut != 1) {
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
- $sql .= " SET num_paiement = '".$this->db->escape($num)."'";
+ $sql .= " SET num_paiement = '".$this->db->escape($num_payment)."'";
$sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
- $this->num_payment = $this->db->escape($num);
+ $this->num_payment = $this->db->escape($num_payment);
return 0;
} else {
$this->error = 'Error -1 '.$this->db->error();
diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php
index f806d8325ff..2cacdd686bc 100644
--- a/htdocs/compta/paiement/list.php
+++ b/htdocs/compta/paiement/list.php
@@ -51,10 +51,6 @@ $facid = GETPOST('facid', 'int');
$socid = GETPOST('socid', 'int');
$userid = GETPOST('userid', 'int');
-// Security check
-if ($user->socid) $socid = $user->socid;
-$result = restrictedArea($user, 'facture', $facid, '');
-
$search_ref = GETPOST("search_ref", "alpha");
$search_date_startday = GETPOST('search_date_startday', 'int');
$search_date_startmonth = GETPOST('search_date_startmonth', 'int');
@@ -70,6 +66,7 @@ $search_account = GETPOST("search_account", "int");
$search_payment_num = GETPOST('search_payment_num', 'alpha');
$search_amount = GETPOST("search_amount", 'alpha'); // alpha because we must be able to search on "< x"
$search_status = GETPOST('search_status', 'intcomma');
+$search_sale = GETPOST('search_sale', 'int');
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
@@ -117,6 +114,15 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
$hookmanager->initHooks(array('paymentlist'));
$object = new Paiement($db);
+if (!$user->hasRight('societe', 'client', 'voir')) {
+ $search_sale = $user->id;
+}
+
+// Security check
+if ($user->socid) $socid = $user->socid;
+$result = restrictedArea($user, 'facture', $facid, '');
+
+
/*
* Actions
*/
@@ -154,6 +160,7 @@ if (empty($reshook)) {
}
}
+
/*
* View
*/
@@ -168,8 +175,8 @@ llxHeader('', $langs->trans('ListPayment'));
if (GETPOST("orphelins", "alpha")) {
// Payments not linked to an invoice. Should not happend. For debug only.
- $sql = "SELECT p.rowid, p.ref, p.datep, p.amount, p.statut, p.num_paiement";
- $sql .= ", c.code as paiement_code";
+ $sql = "SELECT p.rowid, p.ref, p.datep, p.amount, p.statut, p.num_paiement,";
+ $sql .= " c.code as paiement_code";
// Add fields from hooks
$parameters = array();
@@ -185,8 +192,7 @@ if (GETPOST("orphelins", "alpha")) {
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
} else {
- // DISTINCT is to avoid duplicate when there is a link to sales representatives
- $sql = "SELECT DISTINCT p.rowid, p.ref, p.datep, p.fk_bank, p.amount, p.statut, p.num_paiement";
+ $sql = "SELECT p.rowid, p.ref, p.datep, p.fk_bank, p.amount, p.statut, p.num_paiement";
$sql .= ", c.code as paiement_code";
$sql .= ", ba.rowid as bid, ba.ref as bref, ba.label as blabel, ba.number, ba.account_number as account_number, ba.fk_accountancy_journal as accountancy_journal";
$sql .= ", s.rowid as socid, s.nom as name, s.email";
@@ -205,13 +211,7 @@ if (GETPOST("orphelins", "alpha")) {
$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";
- if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
- }
$sql .= " WHERE p.entity IN (".getEntity('invoice').")";
- if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
- $sql .= " AND sc.fk_user = ".((int) $user->id);
- }
if ($socid > 0) {
$sql .= " AND f.fk_soc = ".((int) $socid);
}
@@ -248,6 +248,14 @@ if (GETPOST("orphelins", "alpha")) {
if ($search_company) {
$sql .= natural_search('s.nom', $search_company);
}
+ // Search on sale representative
+ if ($search_sale && $search_sale != '-1') {
+ if ($search_sale == -2) {
+ $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc)";
+ } elseif ($search_sale > 0) {
+ $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
+ }
+ }
if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
@@ -464,79 +472,107 @@ if (!empty($arrayfields['p.statut']['checked'])) {
// Fields from hook
$parameters = array('arrayfields'=>$arrayfields);
-$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
+$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Action column
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print '
';
+ print ' ';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print ' ';
}
-print "";
+print ''."\n";
+
+$totalarray = array();
+$totalarray['nbfield'] = 0;
// Fields title label
// --------------------------------------------------------------------
print '';
+// Action column
if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
+ $totalarray['nbfield']++;
}
if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['p.ref']['checked'])) {
print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['p.datep']['checked'])) {
print_liste_field_titre($arrayfields['p.datep']['label'], $_SERVER["PHP_SELF"], "p.datep", '', $param, '', $sortfield, $sortorder, 'center ');
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['s.nom']['checked'])) {
print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['c.libelle']['checked'])) {
print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", '', $param, '', $sortfield, $sortorder);
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['p.num_paiement']['checked'])) {
print_liste_field_titre($arrayfields['p.num_paiement']['label'], $_SERVER["PHP_SELF"], "p.num_paiement", '', $param, '', $sortfield, $sortorder, '', $arrayfields['p.num_paiement']['tooltip']);
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['transaction']['checked'])) {
print_liste_field_titre($arrayfields['transaction']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['ba.label']['checked'])) {
print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], "ba.label", '', $param, '', $sortfield, $sortorder);
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['p.amount']['checked'])) {
print_liste_field_titre($arrayfields['p.amount']['label'], $_SERVER["PHP_SELF"], "p.amount", '', $param, 'class="right"', $sortfield, $sortorder);
+ $totalarray['nbfield']++;
}
if (!empty($arrayfields['p.statut']['checked'])) {
print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", '', $param, 'class="right"', $sortfield, $sortorder);
+ $totalarray['nbfield']++;
}
-
+// Extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
-
+// Action column
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
+ $totalarray['nbfield']++;
}
-print " ";
+print ''."\n";
-$checkedCount = 0;
-foreach ($arrayfields as $column) {
- if ($column['checked']) {
- $checkedCount++;
+// Detect if we need a fetch on each output line
+$needToFetchEachLine = 0;
+if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
+ foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
+ if (!is_null($val) && preg_match('/\$object/', $val)) {
+ $needToFetchEachLine++; // There is at least one compute field that use $object
+ }
}
}
+
+// Loop on record
+// --------------------------------------------------------------------
$i = 0;
+$savnbfield = $totalarray['nbfield'];
$totalarray = array();
$totalarray['nbfield'] = 0;
-while ($i < min($num, $limit)) {
+$imaxinloop = ($limit ? min($num, $limit) : $num);
+while ($i < $imaxinloop) {
$objp = $db->fetch_object($resql);
+ if (empty($objp)) {
+ break; // Should not happen
+ }
$object->id = $objp->rowid;
$object->ref = ($objp->ref ? $objp->ref : $objp->rowid);
@@ -545,144 +581,183 @@ while ($i < min($num, $limit)) {
$companystatic->name = $objp->name;
$companystatic->email = $objp->email;
- print '';
-
- // Action column
- if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print ' ';
- if (!$i) {
- $totalarray['nbfield']++;
+ if ($mode == 'kanban') {
+ if ($i == 0) {
+ print ' ';
+ print '';
}
+ // Output Kanban
+ $selected = -1;
+ if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
+ $selected = 0;
+ if (in_array($object->id, $arrayofselected)) {
+ $selected = 1;
+ }
+ }
+ //print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
+ print $object->getKanbanView('', array('selected' => $selected));
+ if ($i == ($imaxinloop - 1)) {
+ print '
';
+ print ' ';
+ }
+ } else {
+ // Show line of result
+ $j = 0;
+ print '';
+
+ // Action column
+ if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
+ print '';
+ if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
+ $selected = 0;
+ if (in_array($object->id, $arrayofselected)) {
+ $selected = 1;
+ }
+ print ' ';
+ }
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // No
+ if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
+ print ''.(($offset * $limit) + $i).' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Ref
+ if (!empty($arrayfields['p.ref']['checked'])) {
+ print ''.$object->getNomUrl(1).' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Date
+ if (!empty($arrayfields['p.datep']['checked'])) {
+ $dateformatforpayment = 'dayhour';
+ print ''.dol_print_date($db->jdate($objp->datep), $dateformatforpayment, 'tzuser').' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Thirdparty
+ if (!empty($arrayfields['s.nom']['checked'])) {
+ print '';
+ if ($objp->socid > 0) {
+ print $companystatic->getNomUrl(1, '', 24);
+ }
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Payment type
+ if (!empty($arrayfields['c.libelle']['checked'])) {
+ print ''.$langs->trans("PaymentTypeShort".$objp->paiement_code).' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Filter: Cheque number (fund transfer)
+ if (!empty($arrayfields['p.num_paiement']['checked'])) {
+ print ''.$objp->num_paiement.' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Bank transaction
+ if (!empty($arrayfields['transaction']['checked'])) {
+ print '';
+ if ($objp->fk_bank > 0) {
+ $bankline->fetch($objp->fk_bank);
+ print $bankline->getNomUrl(1, 0);
+ }
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Bank account
+ if (!empty($arrayfields['ba.label']['checked'])) {
+ print '';
+ if ($objp->bid > 0) {
+ $accountstatic->id = $objp->bid;
+ $accountstatic->ref = $objp->bref;
+ $accountstatic->label = $objp->blabel;
+ $accountstatic->number = $objp->number;
+ $accountstatic->account_number = $objp->account_number;
+
+ $accountingjournal = new AccountingJournal($db);
+ $accountingjournal->fetch($objp->accountancy_journal);
+ $accountstatic->accountancy_journal = $accountingjournal->code;
+
+ print $accountstatic->getNomUrl(1);
+ }
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Amount
+ if (!empty($arrayfields['p.amount']['checked'])) {
+ print ''.price($objp->amount).' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ $totalarray['pos'][$totalarray['nbfield']] = 'amount';
+ }
+ if (empty($totalarray['val']['amount'])) {
+ $totalarray['val']['amount'] = $objp->amount;
+ } else {
+ $totalarray['val']['amount'] += $objp->amount;
+ }
+ }
+
+ // Status
+ if (!empty($arrayfields['p.statut']['checked'])) {
+ print '';
+ if ($objp->statut == 0) {
+ print '';
+ }
+ print $object->LibStatut($objp->statut, 5);
+ if ($objp->statut == 0) {
+ print ' ';
+ }
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ // Action column
+ if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
+ print '';
+ if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
+ $selected = 0;
+ if (in_array($object->id, $arrayofselected)) {
+ $selected = 1;
+ }
+ print ' ';
+ }
+ print ' ';
+ if (!$i) {
+ $totalarray['nbfield']++;
+ }
+ }
+
+ print ' '."\n";
}
- // No
- if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
- print ''.(($offset * $limit) + $i).' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Ref
- if (!empty($arrayfields['p.ref']['checked'])) {
- print ''.$object->getNomUrl(1).' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Date
- if (!empty($arrayfields['p.datep']['checked'])) {
- $dateformatforpayment = 'dayhour';
- print ''.dol_print_date($db->jdate($objp->datep), $dateformatforpayment, 'tzuser').' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Thirdparty
- if (!empty($arrayfields['s.nom']['checked'])) {
- print '';
- if ($objp->socid > 0) {
- print $companystatic->getNomUrl(1, '', 24);
- }
- print ' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Payment type
- if (!empty($arrayfields['c.libelle']['checked'])) {
- print ''.$langs->trans("PaymentTypeShort".$objp->paiement_code).' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Filter: Cheque number (fund transfer)
- if (!empty($arrayfields['p.num_paiement']['checked'])) {
- print ''.$objp->num_paiement.' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Bank transaction
- if (!empty($arrayfields['transaction']['checked'])) {
- print '';
- if ($objp->fk_bank > 0) {
- $bankline->fetch($objp->fk_bank);
- print $bankline->getNomUrl(1, 0);
- }
- print ' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Bank account
- if (!empty($arrayfields['ba.label']['checked'])) {
- print '';
- if ($objp->bid > 0) {
- $accountstatic->id = $objp->bid;
- $accountstatic->ref = $objp->bref;
- $accountstatic->label = $objp->blabel;
- $accountstatic->number = $objp->number;
- $accountstatic->account_number = $objp->account_number;
-
- $accountingjournal = new AccountingJournal($db);
- $accountingjournal->fetch($objp->accountancy_journal);
- $accountstatic->accountancy_journal = $accountingjournal->code;
-
- print $accountstatic->getNomUrl(1);
- }
- print ' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Amount
- if (!empty($arrayfields['p.amount']['checked'])) {
- print ''.price($objp->amount).' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- $totalarray['pos'][$checkedCount] = 'amount';
- if (empty($totalarray['val']['amount'])) {
- $totalarray['val']['amount'] = $objp->amount;
- } else {
- $totalarray['val']['amount'] += $objp->amount;
- }
- }
-
- // Status
- if (!empty($arrayfields['p.statut']['checked'])) {
- print '';
- if ($objp->statut == 0) {
- print '';
- }
- print $object->LibStatut($objp->statut, 5);
- if ($objp->statut == 0) {
- print ' ';
- }
- print ' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- // Action column
- if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
- print ' ';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- }
-
- print '';
-
$i++;
}
@@ -697,12 +772,19 @@ if ($num == 0) {
$colspan++;
}
}
- print ''.$langs->trans("NoRecordFound").' ';
+ print ''.$langs->trans("NoRecordFound").' ';
}
-print "";
-print "";
-print "";
+$db->free($resql);
+
+$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
+$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+print $hookmanager->resPrint;
+
+print ''."\n";
+print ''."\n";
+
+print ''."\n";
// End of page
llxFooter();
diff --git a/htdocs/compta/tva/class/paymentvat.class.php b/htdocs/compta/tva/class/paymentvat.class.php
index 72c1f42933b..173c7408de2 100644
--- a/htdocs/compta/tva/class/paymentvat.class.php
+++ b/htdocs/compta/tva/class/paymentvat.class.php
@@ -367,9 +367,6 @@ class PaymentVAT extends CommonObject
if (isset($this->fk_typepaiement)) {
$this->fk_typepaiement = (int) $this->fk_typepaiement;
}
- if (isset($this->num_paiement)) {
- $this->num_paiement = trim($this->num_paiement); // deprecated
- }
if (isset($this->num_payment)) {
$this->num_payment = trim($this->num_payment);
}
@@ -566,8 +563,6 @@ class PaymentVAT extends CommonObject
*/
public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
{
- global $conf;
-
// Clean data
$this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
diff --git a/htdocs/core/modules/supplier_invoice/doc/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/doc/pdf_canelle.modules.php
index 11c234b532c..01f61e6899d 100644
--- a/htdocs/core/modules/supplier_invoice/doc/pdf_canelle.modules.php
+++ b/htdocs/core/modules/supplier_invoice/doc/pdf_canelle.modules.php
@@ -982,7 +982,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
//
// Loop on each payment
- $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
+ $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
$sql .= " cp.code";
$sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
@@ -1005,7 +1005,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
$pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
- $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
+ $pdf->MultiCell(30, 3, $row->num_payment, 0, 'L', 0);
$pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php
index a9347882d1e..cc182047cbc 100644
--- a/htdocs/fourn/class/paiementfourn.class.php
+++ b/htdocs/fourn/class/paiementfourn.class.php
@@ -299,6 +299,7 @@ class PaiementFourn extends Paiement
$discount->discount_type = 1; // Supplier discount
$discount->description = '(DEPOSIT)';
$discount->fk_soc = $invoice->socid;
+ $discount->socid = $invoice->socid;
$discount->fk_invoice_supplier_source = $invoice->id;
// Loop on each vat rate
@@ -729,8 +730,6 @@ class PaiementFourn extends Paiement
*/
public function initAsSpecimen($option = '')
{
- global $user, $langs, $conf;
-
$now = dol_now();
$arraynow = dol_getdate($now);
$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
diff --git a/htdocs/fourn/paiement/list.php b/htdocs/fourn/paiement/list.php
index f643fd040b1..ef1607277ea 100644
--- a/htdocs/fourn/paiement/list.php
+++ b/htdocs/fourn/paiement/list.php
@@ -68,6 +68,7 @@ $search_payment_type = GETPOST('search_payment_type');
$search_cheque_num = GETPOST('search_cheque_num', 'alpha');
$search_bank_account = GETPOST('search_bank_account', 'int');
$search_amount = GETPOST('search_amount', 'alpha'); // alpha because we must be able to search on '< x'
+$search_sale = GETPOST('search_sale', 'int');
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
@@ -113,6 +114,10 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
$hookmanager->initHooks(array('paymentsupplierlist'));
$object = new PaiementFourn($db);
+if (!$user->hasRight('societe', 'client', 'voir')) {
+ $search_sale = $user->id;
+}
+
// Security check
if ($user->socid) {
$socid = $user->socid;
@@ -176,18 +181,14 @@ $accountstatic = new Account($db);
$companystatic = new Societe($db);
$paymentfournstatic = new PaiementFourn($db);
-$sql = 'SELECT p.rowid, p.ref, p.datep, p.amount as pamount, p.num_paiement';
-$sql .= ', s.rowid as socid, s.nom as name, s.email';
-$sql .= ', c.code as paiement_type, c.libelle as paiement_libelle';
-$sql .= ', ba.rowid as bid, ba.ref as bref, ba.label as blabel, ba.number, ba.account_number as account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.fk_accountancy_journal as accountancy_journal';
-if (!$user->hasRight("societe", "client", "voir")) {
- $sql .= ', sc.fk_soc, sc.fk_user';
-}
-$sql .= ', SUM(pf.amount)';
-
+$sql = 'SELECT p.rowid, p.ref, p.datep, p.amount as pamount, p.num_paiement as num_payment,';
+$sql .= ' s.rowid as socid, s.nom as name, s.email,';
+$sql .= ' c.code as paiement_type, c.libelle as paiement_libelle,';
+$sql .= ' ba.rowid as bid, ba.ref as bref, ba.label as blabel, ba.number, ba.account_number as account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.fk_accountancy_journal as accountancy_journal,';
+$sql .= ' SUM(pf.amount)';
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p';
-$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn';
-$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn';
+$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid = pf.fk_paiementfourn';
+$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid = pf.fk_facturefourn';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
@@ -196,10 +197,7 @@ if (!$user->hasRight("societe", "client", "voir")) {
$sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
}
-$sql .= ' WHERE f.entity = '.$conf->entity;
-if (!$user->hasRight("societe", "client", "voir")) {
- $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.((int) $user->id);
-}
+$sql .= ' WHERE f.entity = '.((int) $conf->entity);
if ($socid > 0) {
$sql .= ' AND f.fk_soc = '.((int) $socid);
}
@@ -231,15 +229,20 @@ if ($search_bank_account > 0) {
if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
+// Search on sale representative
+if ($search_sale && $search_sale != '-1') {
+ if ($search_sale == -2) {
+ $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc)";
+ } elseif ($search_sale > 0) {
+ $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
+ }
+}
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
$sql .= ' GROUP BY p.rowid, p.ref, p.datep, p.amount, p.num_paiement, s.rowid, s.nom, s.email, c.code, c.libelle,';
$sql .= ' ba.rowid, ba.ref, ba.label, ba.number, ba.account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.fk_accountancy_journal';
-if (!$user->hasRight("societe", "client", "voir")) {
- $sql .= ', sc.fk_soc, sc.fk_user';
-}
$sql .= $db->order($sortfield, $sortorder);
@@ -573,7 +576,7 @@ while ($i < min($num, $limit)) {
// Pyament type
if (!empty($arrayfields['c.libelle']['checked'])) {
$payment_type = $langs->trans("PaymentType".$objp->paiement_type) != ("PaymentType".$objp->paiement_type) ? $langs->trans("PaymentType".$objp->paiement_type) : $objp->paiement_libelle;
- print ''.$payment_type.' '.dol_trunc($objp->num_paiement, 32).' ';
+ print ''.$payment_type.' '.dol_trunc($objp->num_payment, 32).' ';
if (!$i) {
$totalarray['nbfield']++;
}
@@ -581,7 +584,7 @@ while ($i < min($num, $limit)) {
// Cheque number (fund transfer)
if (!empty($arrayfields['p.num_paiement']['checked'])) {
- print ''.$objp->num_paiement.' ';
+ print ''.$objp->num_payment.' ';
if (!$i) {
$totalarray['nbfield']++;
}