From 16fc7d512ba7afd2d0945994989ccf51e653d059 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 8 Mar 2023 20:24:18 +0100 Subject: [PATCH] WIP Work on deposit for other payment mode than CHQ. --- htdocs/compta/paiement/cheque/card.php | 55 ++++-- .../cheque/class/remisecheque.class.php | 42 +++-- htdocs/compta/paiement/cheque/index.php | 166 ++++++++++-------- .../install/mysql/migration/17.0.0-18.0.0.sql | 2 + .../mysql/tables/llx_bordereau_cheque.sql | 1 + 5 files changed, 171 insertions(+), 95 deletions(-) diff --git a/htdocs/compta/paiement/cheque/card.php b/htdocs/compta/paiement/cheque/card.php index 1aebdace757..a4deeb51b90 100644 --- a/htdocs/compta/paiement/cheque/card.php +++ b/htdocs/compta/paiement/cheque/card.php @@ -42,6 +42,11 @@ $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); +$type = GETPOST('type'); +if (empty($type)) { + $type = 'CHQ'; +} + $object = new RemiseCheque($db); $sortfield = GETPOST('sortfield', 'aZ09comma'); @@ -60,6 +65,7 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; $upload_dir = $conf->bank->multidir_output[$object->entity ? $object->entity : $conf->entity]."/checkdeposits"; + // filter by dates from / to $search_date_start_day = GETPOST('search_date_start_day', 'int'); $search_date_start_month = GETPOST('search_date_start_month', 'int'); @@ -132,8 +138,8 @@ if ($action == 'setref' && $user->rights->banque->cheque) { } if ($action == 'create' && GETPOST("accountid", "int") > 0 && $user->rights->banque->cheque) { - if (is_array(GETPOST('toRemise'))) { - $result = $object->create($user, GETPOST("accountid", "int"), 0, GETPOST('toRemise')); + if (GETPOSTISARRAY('toRemise')) { + $result = $object->create($user, GETPOST("accountid", "int"), 0, GETPOST('toRemise', 'array:int')); if ($result > 0) { if ($object->statut == 1) { // If statut is validated, we build doc $object->fetch($object->id); // To force to reload all properties in correct property name @@ -286,7 +292,12 @@ if (GETPOST('removefilter')) { $filteraccountid = 0; } -$title = $langs->trans("Cheques")." - ".$langs->trans("Card"); +if ($type == 'CHQ') { + $title = $langs->trans("Cheques"); +} else { + $title = $type; +} + $helpurl = ""; llxHeader("", $title, $helpurl); @@ -302,7 +313,7 @@ if ($action == 'new') { $hselected = $h; $h++; - print load_fiche_titre($langs->trans("Cheques"), '', 'bank_account'); + print load_fiche_titre($title, '', 'bank_account'); } else { $result = $object->fetch($id, $ref); if ($result < 0) { @@ -357,18 +368,29 @@ if ($action == 'new') { $now = dol_now(); - print ''.$langs->trans("SelectChequeTransactionAndGenerate").'

'."\n"; + if ($type == 'CHQ') { + print ''.$langs->trans("SelectChequeTransactionAndGenerate").'

'."\n"; + } else { + print ''.$langs->trans("SelectPaymentTransactionAndGenerate", $type).'

'."\n"; + } print '
'; print ''; print ''; + print ''; print dol_get_fiche_head(); print ''; //print ''; // Filter - print '
'.$langs->trans('Date').''.dol_print_date($now,'day').'
'.$langs->trans("DateChequeReceived").''; + print '
'; + if ($type == 'CHQ') { + print $langs->trans("DateChequeReceived"); + } else { + print $langs->trans("DatePaymentForDeposit"); + } + print ''; // filter by dates from / to print '
'; print $form->selectDate($search_date_start, 'search_date_start_', 0, 0, 1, '', 1, 1, 0, '', '', '', '', 1, '', $langs->trans('From')); @@ -402,7 +424,7 @@ if ($action == 'new') { $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (b.fk_account = ba.rowid)"; - $sql .= " WHERE b.fk_type = 'CHQ'"; + $sql .= " WHERE b.fk_type = '".$db->escape($type)."'"; $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; $sql .= " AND b.fk_bordereau = 0"; $sql .= " AND b.amount > 0"; @@ -437,7 +459,11 @@ if ($action == 'new') { } if ($i == 0) { - print '
'.$langs->trans("NoWaitingChecks").'

'; + if ($type == 'CHQ') { + print '
'.$langs->trans("NoWaitingChecks").'

'; + } else { + print '
'.$langs->trans("NoWaitingPaymentForDeposit", $type).'

'; + } } } @@ -462,6 +488,7 @@ if ($action == 'new') { print ''; print ''; print ''; + print ''; print ''; $moreforfilter = ''; @@ -469,11 +496,17 @@ if ($action == 'new') { print ''."\n"; print ''; - print ''."\n"; + print ''."\n"; print '\n"; print '\n"; print '\n"; - print '\n"; + print '\n"; print '\n"; print '\n"; print '
'.$langs->trans("DateChequeReceived").''; + if ($type == 'CHQ') { + print $langs->trans("DateChequeReceived"); + } else { + print $langs->trans("DatePaymentForDepositReceived", $type); + } + print ''.$langs->trans("ChequeNumber")."'.$langs->trans("CheckTransmitter")."'.$langs->trans("Bank")."'.$langs->trans("Amount")."'.$langs->trans("Amount")."'.$langs->trans("Payment")."'.$langs->trans("LineRecord")."'.$langs->trans("Select")."
"; @@ -632,7 +665,7 @@ if ($action == 'new') { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.fk_account = ba.rowid)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid"; $sql .= " WHERE ba.entity IN (".getEntity('bank_account').")"; - $sql .= " AND b.fk_type= 'CHQ'"; + $sql .= " AND b.fk_type= '".$db->escape($type)."'"; $sql .= " AND b.fk_bordereau = ".((int) $object->id); $sql .= $db->order($sortfield, $sortorder); diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index eb70c9cebaf..ceed5a98a61 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -53,6 +53,8 @@ class RemiseCheque extends CommonObject //! Numero d'erreur Plage 1024-1279 public $errno; + public $type = 'CHQ'; // 'CHQ', 'TRA', ... + public $amount; public $date_bordereau; public $account_id; @@ -92,9 +94,9 @@ class RemiseCheque extends CommonObject { global $conf; - $sql = "SELECT bc.rowid, bc.datec, bc.fk_user_author, bc.fk_bank_account, bc.amount, bc.ref, bc.statut, bc.nbcheque, bc.ref_ext"; - $sql .= ", bc.date_bordereau as date_bordereau"; - $sql .= ", ba.label as account_label"; + $sql = "SELECT bc.rowid, bc.datec, bc.fk_user_author, bc.fk_bank_account, bc.amount, bc.ref, bc.statut, bc.nbcheque, bc.ref_ext,"; + $sql .= " bc.date_bordereau as date_bordereau, bc.type,"; + $sql .= " ba.label as account_label"; $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid"; $sql .= " WHERE bc.entity = ".$conf->entity; @@ -118,6 +120,7 @@ class RemiseCheque extends CommonObject $this->nbcheque = $obj->nbcheque; $this->statut = $obj->statut; $this->ref_ext = $obj->ref_ext; + $this->type = $obj->type; if ($this->statut == 0) { $this->ref = "(PROV".$this->id.")"; @@ -154,6 +157,11 @@ class RemiseCheque extends CommonObject dol_syslog("RemiseCheque::Create start", LOG_DEBUG); + // Clean parameters + if (empty($this->type)) { + $this->type = 'CHQ'; + } + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque ("; @@ -167,6 +175,7 @@ class RemiseCheque extends CommonObject $sql .= ", entity"; $sql .= ", nbcheque"; $sql .= ", ref_ext"; + $sql .= ", type"; $sql .= ") VALUES ("; $sql .= "'".$this->db->idate($now)."'"; $sql .= ", '".$this->db->idate($now)."'"; @@ -178,6 +187,7 @@ class RemiseCheque extends CommonObject $sql .= ", ".((int) $conf->entity); $sql .= ", 0"; $sql .= ", ''"; + $sql .= ", '".$this->db->escape($this->type)."'"; $sql .= ")"; $resql = $this->db->query($sql); @@ -278,9 +288,9 @@ class RemiseCheque extends CommonObject } /** - * Supprime la remise en base + * Delete deposit from database * - * @param User $user Utilisateur qui effectue l'operation + * @param User $user User that delete * @return int */ public function delete($user = '') @@ -464,10 +474,11 @@ class RemiseCheque extends CommonObject /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) * - * @param User $user Objet user + * @param User $user Objet user + * @param string $type Type of payment mode deposit ('CHQ', 'TRA', ...) * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK */ - public function load_board($user) + public function load_board($user, $type = 'CHQ') { // phpcs:enable global $conf, $langs; @@ -481,7 +492,7 @@ class RemiseCheque extends CommonObject $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql .= " WHERE b.fk_account = ba.rowid"; $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; - $sql .= " AND b.fk_type = 'CHQ'"; + $sql .= " AND b.fk_type = '".$this->db->escape($type)."'"; $sql .= " AND b.fk_bordereau = 0"; $sql .= " AND b.amount > 0"; @@ -518,9 +529,10 @@ class RemiseCheque extends CommonObject /** * Charge indicateurs this->nb de tableau de bord * - * @return int <0 if ko, >0 if ok + * @param string $type Type of payment mode deposit ('CHQ', 'TRA', ...) + * @return int <0 if ko, >0 if ok */ - public function load_state_board() + public function load_state_board($type = 'CHQ') { // phpcs:enable global $user; @@ -534,7 +546,7 @@ class RemiseCheque extends CommonObject $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql .= " WHERE b.fk_account = ba.rowid"; $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; - $sql .= " AND b.fk_type = 'CHQ'"; + $sql .= " AND b.fk_type = '".$this->db->escape($type)."'"; $sql .= " AND b.amount > 0"; $resql = $this->db->query($sql); @@ -615,7 +627,7 @@ class RemiseCheque extends CommonObject // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. - $sav_charseSupprimert_output = $outputlangs->charset_output; + $sav_charset_output = $outputlangs->charset_output; $result = $docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs); if ($result > 0) { @@ -664,7 +676,7 @@ class RemiseCheque extends CommonObject $sql .= " SET amount = ".price2num($total); $sql .= ", nbcheque = ".((int) $nb); $sql .= " WHERE rowid = ".((int) $this->id); - $sql .= " AND entity = ".$conf->entity; + $sql .= " AND entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { @@ -813,7 +825,7 @@ class RemiseCheque extends CommonObject $sql = "SELECT MAX(rowid)"; $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque"; - $sql .= " WHERE rowid < ".$this->id; + $sql .= " WHERE rowid < ".((int) $this->id); $sql .= " AND entity = ".$conf->entity; $result = $this->db->query($sql); @@ -825,7 +837,7 @@ class RemiseCheque extends CommonObject $sql = "SELECT MIN(rowid)"; $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque"; - $sql .= " WHERE rowid > ".$this->id; + $sql .= " WHERE rowid > ".((int) $this->id); $sql .= " AND entity = ".$conf->entity; $result = $this->db->query($sql); diff --git a/htdocs/compta/paiement/cheque/index.php b/htdocs/compta/paiement/cheque/index.php index 394de095104..5e1b69f655d 100644 --- a/htdocs/compta/paiement/cheque/index.php +++ b/htdocs/compta/paiement/cheque/index.php @@ -66,16 +66,11 @@ print load_fiche_titre($langs->trans("ChequesArea"), $newcardbutton, $checkdepos print '
'; -$sql = "SELECT count(b.rowid) as nb"; -$sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; -$sql .= ", ".MAIN_DB_PREFIX."bank_account as ba"; -$sql .= " WHERE ba.rowid = b.fk_account"; -$sql .= " AND ba.entity IN (".getEntity('bank_account').")"; -$sql .= " AND b.fk_type = 'CHQ'"; -$sql .= " AND b.fk_bordereau = 0"; -$sql .= " AND b.amount > 0"; +// List of payment mode to support +// Example: BANK_PAYMENT_MODES_FOR_DEPOSIT_MANAGEMENT = 'CHQ','TRA' +$conf->global->BANK_PAYMENT_MODES_FOR_DEPOSIT_MANAGEMENT = 'CHQ,TRA'; +$arrayofpaymentmodetomanage = explode(',', getDolGlobalString('BANK_PAYMENT_MODES_FOR_DEPOSIT_MANAGEMENT', 'CHQ')); -$resql = $db->query($sql); print '
'; print ''; @@ -83,19 +78,38 @@ print ''; print '\n"; print "\n"; -if ($resql) { - $num = ''; - if ($obj = $db->fetch_object($resql)) { - $num = $obj->nb; +foreach ($arrayofpaymentmodetomanage as $val) { + $sql = "SELECT count(b.rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql .= " WHERE ba.rowid = b.fk_account"; + $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; + $sql .= " AND b.fk_type = '".$db->escape($val)."'"; + $sql .= " AND b.fk_bordereau = 0"; + $sql .= " AND b.amount > 0"; + + $resql = $db->query($sql); + if ($resql) { + $num = ''; + if ($obj = $db->fetch_object($resql)) { + $num = $obj->nb; + } + print ''; + print ''; + print ''; + } else { + dol_print_error($db); } - print ''; - print ''; - print ''; -} else { - dol_print_error($db); } + print "
'.$langs->trans("BankChecks")."
'; + if ($val == 'CHQ') { + print $langs->trans("BankChecksToReceipt"); + } else { + print $val; + } + print ''; + print ''.dol_escape_htmltag($num).''; + print '
'.$langs->trans("BankChecksToReceipt").''; - print ''.$num.''; - print '
\n"; @@ -103,64 +117,78 @@ print '
'; $max = 10; -$sql = "SELECT bc.rowid, bc.date_bordereau as db, bc.amount, bc.ref as ref,"; -$sql .= " bc.statut, bc.nbcheque,"; -$sql .= " ba.ref as bref, ba.label, ba.rowid as bid, ba.number, ba.currency_code, ba.account_number, ba.fk_accountancy_journal,"; -$sql .= " aj.code"; -$sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc, ".MAIN_DB_PREFIX."bank_account as ba"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_journal as aj ON aj.rowid = ba.fk_accountancy_journal"; -$sql .= " WHERE ba.rowid = bc.fk_bank_account"; -$sql .= " AND bc.entity = ".$conf->entity; -$sql .= " ORDER BY bc.date_bordereau DESC, rowid DESC"; -$sql .= $db->plimit($max); +foreach ($arrayofpaymentmodetomanage as $val) { + $sql = "SELECT bc.rowid, bc.date_bordereau as db, bc.amount, bc.ref as ref,"; + $sql .= " bc.statut, bc.nbcheque, bc.type,"; + $sql .= " ba.ref as bref, ba.label, ba.rowid as bid, ba.number, ba.currency_code, ba.account_number, ba.fk_accountancy_journal,"; + $sql .= " aj.code"; + $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc, ".MAIN_DB_PREFIX."bank_account as ba"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_journal as aj ON aj.rowid = ba.fk_accountancy_journal"; + $sql .= " WHERE ba.rowid = bc.fk_bank_account"; + $sql .= " AND bc.entity = ".((int) $conf->entity); + $sql .= " AND bc.type = '".$db->escape($type)."'"; + $sql .= " ORDER BY bc.date_bordereau DESC, rowid DESC"; + $sql .= $db->plimit($max); -$resql = $db->query($sql); -if ($resql) { - print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table - print ''; - print ''; - print ''; - print '"; - print ''; - print ''; - print ''; - print ''; - print "\n"; + $resql = $db->query($sql); + if ($resql) { + print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table + print '
'.$langs->trans("LastCheckReceiptShort", $max).''.$langs->trans("Date")."'.$langs->trans("Account").''.$langs->trans("NbOfCheques").''.$langs->trans("Amount").''.$langs->trans("Status").'
'; + print ''; + print ''; + print '"; + print ''; + print ''; + print ''; + print ''; + print "\n"; - while ($objp = $db->fetch_object($resql)) { - $checkdepositstatic->id = $objp->rowid; - $checkdepositstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid); - $checkdepositstatic->statut = $objp->statut; + $i = 0; + while ($objp = $db->fetch_object($resql)) { + $i++; - $accountstatic->id = $objp->bid; - $accountstatic->ref = $objp->bref; - $accountstatic->label = $objp->label; - $accountstatic->number = $objp->number; - $accountstatic->currency_code = $objp->currency_code; - $accountstatic->account_number = $objp->account_number; - $accountstatic->accountancy_journal = $objp->code; - $accountstatic->fk_accountancy_journal = $objp->fk_accountancy_journal; + $checkdepositstatic->id = $objp->rowid; + $checkdepositstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid); + $checkdepositstatic->statut = $objp->statut; - print ''."\n"; + $accountstatic->id = $objp->bid; + $accountstatic->ref = $objp->bref; + $accountstatic->label = $objp->label; + $accountstatic->number = $objp->number; + $accountstatic->currency_code = $objp->currency_code; + $accountstatic->account_number = $objp->account_number; + $accountstatic->accountancy_journal = $objp->code; + $accountstatic->fk_accountancy_journal = $objp->fk_accountancy_journal; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''."\n"; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + } + if ($i == 0) { + print ''; + } + print "
'; + if ($val == 'CHQ') { + print $langs->trans("LastCheckReceiptShort", $max); + } else { + print $langs->trans("LastPaymentForDepositShort", $max, $val); + } + print ''.$langs->trans("Date")."'.$langs->trans("Account").''.$langs->trans("NbOfCheques").''.$langs->trans("Amount").''.$langs->trans("Status").'
'.$checkdepositstatic->getNomUrl(1).''.dol_print_date($db->jdate($objp->db), 'day').''.$accountstatic->getNomUrl(1).''.$objp->nbcheque.''.price($objp->amount).''.$checkdepositstatic->LibStatut($objp->statut, 3).'
'.$checkdepositstatic->getNomUrl(1).''.dol_print_date($db->jdate($objp->db), 'day').''.$accountstatic->getNomUrl(1).''.$objp->nbcheque.''.price($objp->amount).''.$checkdepositstatic->LibStatut($objp->statut, 3).'
'.$langs->trans("None").'
"; + print '
'; + + $db->free($resql); + } else { + dol_print_error($db); } - print "
"; - print '
'; - - $db->free($resql); -} else { - dol_print_error($db); } - print ''; // End of page diff --git a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql index 6ae41a359dc..0f16c182e73 100644 --- a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql +++ b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql @@ -98,3 +98,5 @@ UPDATE llx_prelevement_demande SET type = 'ban' WHERE ext_payment_id IS NULL AND ALTER TABLE llx_recruitment_recruitmentcandidature ADD COLUMN fk_user integer; +ALTER TABLE llx_bordereau_cheque ADD COLUMN type VARCHAR(6) DEFAULT 'CHQ'; + diff --git a/htdocs/install/mysql/tables/llx_bordereau_cheque.sql b/htdocs/install/mysql/tables/llx_bordereau_cheque.sql index 9b1d6e24ad4..65100ccaae1 100644 --- a/htdocs/install/mysql/tables/llx_bordereau_cheque.sql +++ b/htdocs/install/mysql/tables/llx_bordereau_cheque.sql @@ -26,6 +26,7 @@ create table llx_bordereau_cheque rowid integer AUTO_INCREMENT PRIMARY KEY, ref varchar(30) NOT NULL, -- ref ref_ext varchar(255), -- ref_ext + type varchar(6) DEFAULT 'CHQ', -- 'CHQ', 'TRA', ... datec datetime NOT NULL, date_bordereau date, amount double(24,8) NOT NULL,