Debug v19

This commit is contained in:
Laurent Destailleur 2023-11-07 14:18:33 +01:00
parent e5d9fb10e5
commit 1e2d06bf80
4 changed files with 116 additions and 59 deletions

View file

@ -961,7 +961,7 @@ class BonPrelevement extends CommonObject
$sql .= ", f.ref, sr.bic, sr.iban_prefix, sr.frstrecur";
} else {
$sql .= ", CONCAT(s.firstname,' ',s.lastname) as name";
$sql .= ", f.ref, sr.bic, sr.iban_prefix";
$sql .= ", f.ref, sr.bic, sr.iban_prefix, 'FRST' as frstrecur";
}
if ($sourcetype != 'salary') {
if ($type != 'bank-transfer') {
@ -977,21 +977,30 @@ class BonPrelevement extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."salary as f";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_demande as pd ON f.rowid = pd.fk_salary";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as s ON s.rowid = f.fk_user";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user_rib as sr ON s.rowid = sr.fk_user";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user_rib as sr ON s.rowid = sr.fk_user"; // TODO Add AND sr.default_rib = 1 here
}
if ($sourcetype != 'salary') {
if ($type != 'bank-transfer') {
$sql .= " WHERE f.entity IN (".getEntity('invoice').')';
} else {
$sql .= " WHERE f.entity IN (".getEntity('supplier_invoice').')';
}
} else {
$sql .= " WHERE f.entity IN (".getEntity('salary').')';
}
$sql .= " WHERE f.entity IN (".getEntity('invoice').')';
if ($sourcetype != 'salary') {
$sql .= " AND f.fk_statut = 1"; // Invoice validated
$sql .= " AND f.paye = 0";
$sql .= " AND f.total_ttc > 0";
} else {
//$sql .= " AND f.fk_statut = 1"; // Invoice validated
$sql .= " AND f.paye = 0";
$sql .= " AND f.amount > 0";
}
$sql .= " AND pd.traite = 0";
$sql .= " AND pd.ext_payment_id IS NULL";
if ($sourcetype != 'salary') {
$sql .= " AND sr.type = 'ban' ";
$sql .= " AND sr.type = 'ban'"; // TODO Add AND sr.type = 'ban' for users too
}
if ($did > 0) {
$sql .= " AND pd.rowid = ".((int) $did);
@ -1003,7 +1012,7 @@ class BonPrelevement extends CommonObject
$i = 0;
while ($i < $num) {
$row = $this->db->fetch_row($resql);
$row = $this->db->fetch_row($resql); // TODO Replace with fetch_object()
$factures[$i] = $row; // All fields
if ($row[7] == 0) {

View file

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2010-2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2023 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
@ -31,6 +31,7 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
@ -41,18 +42,18 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
// Load translation files required by the page
$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies', 'bills'));
$type = GETPOST('type', 'aZ09');
// Get supervariables
$action = GETPOST('action', 'aZ09');
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
$mode = GETPOST('mode', 'alpha') ?GETPOST('mode', 'alpha') : 'real';
$type = GETPOST('type', 'aZ09');
$sourcetype = GETPOST('sourcetype', 'aZ09');
$format = GETPOST('format', 'aZ09');
$id_bankaccount = GETPOST('id_bankaccount', 'int');
$executiondate = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
$sourcetype = GETPOST('sourcetype', 'alpha');
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
@ -101,7 +102,6 @@ if (empty($reshook)) {
}
if ($action == 'create') {
$default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
$sourcetype = GETPOST('sourcetype', 'alpha');
//var_dump($default_account);var_dump($conf->global->$default_account);var_dump($id_bankaccount);exit;
if ($id_bankaccount != getDolGlobalInt($default_account)) {
@ -221,7 +221,7 @@ if ($type) {
}
if (!GETPOSTISSET('sourcetype')) {
if ($sourcetype != 'salary') {
$nb = $bprev->nbOfInvoiceToPay($type);
$pricetowithdraw = $bprev->SommeAPrelever($type);
} else {
@ -260,16 +260,13 @@ if ($mesg) {
}
print '<div class="tabsAction">'."\n";
if (!GETPOSTISSET('sourcetype')) {
print '<form action="'.$_SERVER['PHP_SELF'].'?action=create" method="POST">';
} else {
print '<form action="'.$_SERVER['PHP_SELF'].'?action=create&type='.$type.'&sourcetype='.$sourcetype.'" method="POST">';
}
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
print '<input type="hidden" name="action" value="create">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="type" value="'.$type.'">';
if (GETPOSTISSET('sourcetype')) {
print '<input type="hidden" name="sourcetype" value="'.$sourcetype.'">';
}
print '<input type="hidden" name="sourcetype" value="'.$sourcetype.'">';
if ($nb) {
if ($pricetowithdraw) {
$title = $langs->trans('BankToReceiveWithdraw').': ';
@ -363,40 +360,52 @@ print '<br>';
/*
* Invoices waiting for withdraw
*/
if (!GETPOSTISSET('sourcetype')) {
if ($sourcetype != 'salary') {
$sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
if ($type == 'bank-transfer') {
$sql .= " f.ref_supplier,";
}
$sql .= " pfd.rowid as request_row_id, pfd.date_demande, pfd.amount";
$sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount";
if ($type == 'bank-transfer') {
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
} else {
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
}
$sql .= " ".MAIN_DB_PREFIX."societe as s,";
$sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pfd";
$sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
$sql .= " WHERE s.rowid = f.fk_soc";
$sql .= " AND f.entity IN (".getEntity('invoice').")";
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
}
//$sql .= " AND pfd.amount > 0";
//$sql .= " AND pd.amount > 0";
$sql .= " AND f.total_ttc > 0"; // Avoid credit notes
$sql .= " AND pfd.traite = 0";
$sql .= " AND pfd.ext_payment_id IS NULL";
$sql .= " AND pd.traite = 0";
$sql .= " AND pd.ext_payment_id IS NULL";
if ($type == 'bank-transfer') {
$sql .= " AND pfd.fk_facture_fourn = f.rowid";
$sql .= " AND pd.fk_facture_fourn = f.rowid";
} else {
$sql .= " AND pfd.fk_facture = f.rowid";
$sql .= " AND pd.fk_facture = f.rowid";
}
if ($socid > 0) {
$sql .= " AND f.fk_soc = ".((int) $socid);
}
} else {
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."salary as s, ";
$sql .= MAIN_DB_PREFIX."prelevement_demande as pd";
$sql .= " WHERE s.rowid = pd.fk_salary AND s.paye = 0 AND pd.traite = 0";
$sql = "SELECT s.ref, s.rowid, s.amount, CONCAT(u.lastname, ' ', u.firstname) as name, u.rowid as uid,";
$sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount";
$sql .= " FROM ".MAIN_DB_PREFIX."salary as s,";
$sql .= " ".MAIN_DB_PREFIX."user as u,";
$sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
$sql .= " WHERE s.fk_user = u.rowid";
$sql .= " AND s.entity IN (".getEntity('salary').")";
/*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND s.fk_statut = ".Facture::STATUS_VALIDATED;
}*/
$sql .= " AND s.amount > 0";
$sql .= " AND pd.traite = 0";
$sql .= " AND pd.ext_payment_id IS NULL";
$sql .= " AND s.rowid = pd.fk_salary AND s.paye = ".Salary::STATUS_UNPAID;
$sql .= " AND pd.traite = 0";
}
$nbtotalofrecords = '';
@ -522,8 +531,9 @@ if ($resql) {
} else {
$bac = new UserBankAccount($db);
$bac->fetch(0, '', $obj->fk_user);
$salary = new Salary($db);
$salary->fetch($obj->fk_salary);
$salary->fetch($obj->rowid);
}
print '<tr class="oddeven">';
@ -563,7 +573,7 @@ if ($resql) {
print '</td>';
} else {
print '<td class="tdoverflowmax100">';
$user->fetch($obj->fk_user);
$user->fetch($obj->uid);
print $user->getNomUrl(-1);
print '</td>';
}

View file

@ -132,14 +132,14 @@ if ($type == 'bank-transfer') {
if ($sourcetype != 'salary') {
$sql = "SELECT f.ref, f.rowid, f.total_ttc,";
$sql .= " s.nom as name, s.rowid as socid,";
$sql .= " pfd.date_demande as date_demande, pfd.amount, pfd.fk_user_demande";
$sql .= " pd.date_demande as date_demande, pd.amount, pd.fk_user_demande";
if ($type != 'bank-transfer') {
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
} else {
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
}
$sql .= " ".MAIN_DB_PREFIX."societe as s,";
$sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pfd";
$sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
@ -152,20 +152,20 @@ if ($sourcetype != 'salary') {
$sql .= " AND f.fk_soc = ".((int) $socid);
}
if (!$status) {
$sql .= " AND pfd.traite = 0";
$sql .= " AND pd.traite = 0";
}
$sql .= " AND pfd.ext_payment_id IS NULL";
$sql .= " AND pd.ext_payment_id IS NULL";
if ($status) {
$sql .= " AND pfd.traite = ".((int) $status);
$sql .= " AND pd.traite = ".((int) $status);
}
$sql .= " AND f.total_ttc > 0";
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
}
if ($type != 'bank-transfer') {
$sql .= " AND pfd.fk_facture = f.rowid";
$sql .= " AND pd.fk_facture = f.rowid";
} else {
$sql .= " AND pfd.fk_facture_fourn = f.rowid";
$sql .= " AND pd.fk_facture_fourn = f.rowid";
}
if ($search_facture) {
$sql .= natural_search("f.ref", $search_facture);
@ -177,17 +177,30 @@ if ($sourcetype != 'salary') {
} else {
$sql = "SELECT s.rowid,s.amount as total_ttc, pd.amount,";
$sql .= " s.fk_user, pd.date_demande, pd.fk_salary, CONCAT(u.firstname,' ',u.lastname) as nom";
$sql .= " FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."user as u, ";
$sql .= MAIN_DB_PREFIX."prelevement_demande as pd";
$sql .= " FROM ".MAIN_DB_PREFIX."salary as s, ".MAIN_DB_PREFIX."user as u,";
$sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
$sql .= " WHERE s.rowid = pd.fk_salary";
$sql .= " AND u.rowid = s.fk_user";
$sql .=" AND s.paye = 0 AND pd.traite = 0";
$sql .= " AND s.entity IN (".getEntity("salary").")";
/*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND s.statut = ".Salary::STATUS_UNPAID;
}*/
if (!$status) {
$sql .= " AND pd.traite = 0";
}
$sql .= " AND pd.ext_payment_id IS NULL";
if ($status) {
$sql .= " AND pd.traite = ".((int) $status);
}
$sql .= " AND s.amount > 0";
$sql .= " AND s.paye = ".Salary::STATUS_UNPAID;
if ($search_facture) {
$sql .= natural_search("s.rowid", $search_facture);
}
if ($search_societe) {
$sql .= natural_search("CONCAT(u.firstname,' ',u.lastname)", $search_societe);
}
//print $sql;
}
// Count total nb of records
$nbtotalofrecords = '';
@ -248,26 +261,41 @@ $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circl
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit);
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="liste centpercent">';
print '<tr class="liste_titre">';
print_liste_field_titre(($sourcetype ? "RefSalary" : "Bill"), $_SERVER["PHP_SELF"]);
print_liste_field_titre(($sourcetype ? "Employee" :"Company"), $_SERVER["PHP_SELF"]);
print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
print_liste_field_titre('');
print '</tr>';
print '<tr class="liste_titre">';
// Action column
if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print '</td>';
}
print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="'.dol_escape_htmltag($search_facture).'"></td>';
print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
print '<td class="liste_titre"></td>';
print '<td class="liste_titre"></td>';
// Action column
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print '</td>';
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print '</td>';
}
print '</tr>';
print '<tr class="liste_titre">';
if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print_liste_field_titre('');
}
print_liste_field_titre(($sourcetype ? "RefSalary" : "Bill"), $_SERVER["PHP_SELF"]);
print_liste_field_titre(($sourcetype ? "Employee" :"Company"), $_SERVER["PHP_SELF"]);
print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'right ');
print_liste_field_titre("DateRequest", $_SERVER["PHP_SELF"], "", "", $param, '', '', '', 'center ');
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print_liste_field_titre('');
}
print '</tr>';
$userstatic = new User($db);
@ -287,6 +315,11 @@ while ($i < min($num, $limit)) {
}
print '<tr class="oddeven">';
// Action column
if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print '<td class="right"></td>';
}
// Ref facture
print '<td>';
if ($sourcetype != 'salary') {
@ -314,13 +347,18 @@ while ($i < min($num, $limit)) {
print '<td class="center">'.dol_print_date($db->jdate($obj->date_demande), 'day').'</td>';
print '<td class="right"></td>';
// Action column
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print '<td class="right"></td>';
}
print '</tr>';
$i++;
}
print "</table><br>";
print "</table>";
print "</div>";
print "<br>";
print '</form>';

View file

@ -13,8 +13,8 @@
* Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
* Copyright (C) 2015-2018 Charlene Benke <charlie@patas-monkey.com>
* Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018 David Beniamine <David.Beniamine@Tetras-Libre.fr>
* Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018 David Beniamine <David.Beniamine@Tetras-Libre.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