diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php index 97f5d96903f..92799c2cd10 100644 --- a/htdocs/compta/prelevement/card.php +++ b/htdocs/compta/prelevement/card.php @@ -63,6 +63,9 @@ if (! $sortorder) $sortorder='DESC'; $object = new BonPrelevement($db,""); +// Load object +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals + /* * Actions @@ -70,9 +73,7 @@ $object = new BonPrelevement($db,""); if ( $action == 'confirm_delete' ) { - $object->fetch($id, $ref); - - $res=$object->delete(); + $res=$object->delete($user); if ($res > 0) { header("Location: index.php"); @@ -83,8 +84,6 @@ if ( $action == 'confirm_delete' ) // Seems to no be used and replaced with $action == 'infocredit if ( $action == 'confirm_credite' && GETPOST('confirm','alpha') == 'yes') { - $object->fetch($id, $ref); - $res=$object->set_credite(); if ($res >= 0) { @@ -97,8 +96,6 @@ if ($action == 'infotrans' && $user->rights->prelevement->bons->send) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $object->fetch($id, $ref); - $dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int')); /* @@ -132,7 +129,6 @@ if ($action == 'infotrans' && $user->rights->prelevement->bons->send) // Set direct debit order to credited, create payment and close invoices if ($action == 'infocredit' && $user->rights->prelevement->bons->credit) { - $object->fetch($id, $ref); $dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int')); $error = $object->set_infocredit($user, $dt); @@ -156,8 +152,6 @@ llxHeader('',$langs->trans("WithdrawalsReceipts")); if ($id > 0 || $ref) { - $object->fetch($id, $ref); - $head = prelevement_prepare_head($object); dol_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment'); @@ -414,13 +408,8 @@ if ($id > 0 || $ref) { dol_print_error($db); } - - - - } - llxFooter(); $db->close(); diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 188b0236e5f..d829a7c5ada 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -313,7 +313,7 @@ class BonPrelevement extends CommonObject $this->_fetched = 1; - return 0; + return 1; } else { @@ -1110,9 +1110,10 @@ class BonPrelevement extends CommonObject /** * Get object and lines from database * + * @param User $user Object user that delete * @return int >0 if OK, <0 if KO */ - function delete() + function delete($user=null) { $this->db->begin(); diff --git a/htdocs/compta/prelevement/factures.php b/htdocs/compta/prelevement/factures.php index 60215005446..6cc82869966 100644 --- a/htdocs/compta/prelevement/factures.php +++ b/htdocs/compta/prelevement/factures.php @@ -71,7 +71,7 @@ llxHeader('',$langs->trans("WithdrawalsReceipts")); if ($prev_id > 0 || $ref) { - if ($object->fetch($prev_id, $ref) == 0) + if ($object->fetch($prev_id, $ref) >= 0) { $head = prelevement_prepare_head($object); dol_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment'); diff --git a/htdocs/compta/prelevement/fiche-rejet.php b/htdocs/compta/prelevement/fiche-rejet.php index f4cb8040a6f..9489eeec4e9 100644 --- a/htdocs/compta/prelevement/fiche-rejet.php +++ b/htdocs/compta/prelevement/fiche-rejet.php @@ -63,7 +63,7 @@ llxHeader('',$langs->trans("WithdrawalsReceipts")); if ($prev_id > 0 || $ref) { - if ($object->fetch($prev_id, $ref) == 0) + if ($object->fetch($prev_id, $ref) >= 0) { $head = prelevement_prepare_head($object); dol_fiche_head($head, 'rejects', $langs->trans("WithdrawalsReceipts"), -1, 'payment'); @@ -152,7 +152,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; $sql.= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl"; $sql.= " , ".MAIN_DB_PREFIX."societe as s"; $sql.= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr"; -$sql.= " WHERE p.rowid=".$prev_id; +$sql.= " WHERE p.rowid=".$object->id; $sql.= " AND pl.fk_prelevement_bons = p.rowid"; $sql.= " AND p.entity = ".$conf->entity; $sql.= " AND pl.fk_soc = s.rowid"; diff --git a/htdocs/compta/prelevement/fiche-stat.php b/htdocs/compta/prelevement/fiche-stat.php index a5583dffa6d..539331d1f71 100644 --- a/htdocs/compta/prelevement/fiche-stat.php +++ b/htdocs/compta/prelevement/fiche-stat.php @@ -58,9 +58,9 @@ $object = new BonPrelevement($db,""); llxHeader('',$langs->trans("WithdrawalsReceipts")); -if ($prev_id) +if ($prev_id > 0 || $ref) { - if ($object->fetch($prev_id) == 0) + if ($object->fetch($prev_id, $ref) >= 0) { $head = prelevement_prepare_head($object); dol_fiche_head($head, 'statistics', $langs->trans("WithdrawalsReceipts"), -1, 'payment'); @@ -144,7 +144,7 @@ if ($prev_id) $sql = "SELECT sum(pl.amount), pl.statut"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; - $sql.= " WHERE pl.fk_prelevement_bons = ".$prev_id; + $sql.= " WHERE pl.fk_prelevement_bons = ".$object->id; $sql.= " GROUP BY pl.statut"; $resql=$db->query($sql);