/** * Delete a subscription * * @param User $user User that delete * @return int <0 if KO, 0 if not found, >0 if OK */ function delete($user) { // It subscription is linked to a bank transaction, we get it if ($this->fk_bank) { require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; $accountline = new AccountLine($this->db); $result = $accountline->fetch($this->fk_bank); } $this->db->begin(); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "cotisation WHERE rowid = " . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->affected_rows($resql); if ($num) { require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; $member = new Adherent($this->db); $result = $member->fetch($this->fk_adherent); $result = $member->update_end_date($user); if ($accountline->rowid > 0) { $result = $accountline->delete($user); // Return false if refused because line is conciliated if ($result > 0) { $this->db->commit(); return 1; } else { $this->error = $accountline->error; $this->db->rollback(); return -1; } } else { $this->db->commit(); return 1; } } else { $this->db->commit(); return 0; } } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } }
$insertid = $object->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user); if ($insertid > 0) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id . "&action=addline"); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } else { $action = 'addline'; } } if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->modifier) { $accline = new AccountLine($db); $result = $accline->fetch(GETPOST("rowid")); $result = $accline->delete(); } /* * View */ llxHeader('', $langs->trans("FinancialAccount") . '-' . $langs->trans("Transactions")); $societestatic = new Societe($db); $userstatic = new User($db); $chargestatic = new ChargeSociales($db); $loanstatic = new Loan($db); $memberstatic = new Adherent($db); $paymentstatic = new Paiement($db); $paymentsupplierstatic = new PaiementFourn($db); $paymentvatstatic = new TVA($db); $paymentsalstatic = new PaymentSalary($db); $donstatic = new Don($db);
/** * Supprime un paiement ainsi que les lignes qu'il a genere dans comptes * Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse * Si le paiement porte sur au moins une facture a "payee", on refuse * * @param int $notrigger No trigger * @return int <0 si ko, >0 si ok */ function delete($notrigger = 0) { global $conf, $user, $langs; $error = 0; $bank_line_id = $this->bank_line; $this->db->begin(); // Verifier si paiement porte pas sur une facture classee // Si c'est le cas, on refuse la suppression $billsarray = $this->getBillsArray('fk_statut > 1'); if (is_array($billsarray)) { if (count($billsarray)) { $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible"; $this->db->rollback(); return -1; } } else { $this->db->rollback(); return -2; } $accline = new AccountLine($this->db); // Delete bank urls. If payment is on a conciliated line, return error. if ($bank_line_id) { $result = $accline->fetch($bank_line_id); if ($result == 0) { $accline->rowid = $bank_line_id; } // If not found, we set artificially rowid to allow delete of llx_bank_url $result = $accline->delete_urls($user); if ($result < 0) { $this->error = $accline->error; $this->db->rollback(); return -3; } } // Delete payment (into paiement_facture and paiement) $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'paiement_facture'; $sql .= ' WHERE fk_paiement = ' . $this->id; dol_syslog($sql); $result = $this->db->query($sql); if ($result) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'paiement'; $sql .= ' WHERE rowid = ' . $this->id; dol_syslog($sql); $result = $this->db->query($sql); if (!$result) { $this->error = $this->db->lasterror(); $this->db->rollback(); return -3; } // Supprimer l'ecriture bancaire si paiement lie a ecriture if ($bank_line_id) { $result = $accline->delete($user); if ($result < 0) { $this->error = $accline->error; $this->db->rollback(); return -4; } } if (!$notrigger) { // Appel des triggers $result = $this->call_trigger('PAYMENT_DELETE', $user); if ($result < 0) { $this->db->rollback(); return -1; } // Fin appel triggers } $this->db->commit(); return 1; } else { $this->error = $this->db->error; $this->db->rollback(); return -5; } }
$action = "create"; } } $action = 'create'; } if ($action == 'delete') { $result = $object->fetch($id); if ($object->rappro == 0) { $db->begin(); $ret = $object->delete($user); if ($ret > 0) { if ($object->fk_bank) { $accountline = new AccountLine($db); $result = $accountline->fetch($object->fk_bank); if ($result > 0) { $result = $accountline->delete($user); } // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing) } if ($result >= 0) { $db->commit(); header("Location: " . DOL_URL_ROOT . '/compta/salaries/index.php'); exit; } else { $object->error = $accountline->error; $db->rollback(); setEventMessage($object->error, 'errors'); } } else { $db->rollback(); setEventMessage($object->error, 'errors');
$langs->load("errors"); $mesg = '<div class="error">' . $langs->trans("ErrorPleaseTypeBankTransactionReportName") . '</div>'; } if (!$error) { header('Location: ' . DOL_URL_ROOT . '/compta/bank/rappro.php?account=' . $id); // To avoid to submit twice and allow back exit; } } /* * Action suppression ecriture */ if ($action == 'del') { $bankline = new AccountLine($db); $bankline->fetch($_GET["rowid"]); $result = $bankline->delete($user); if ($result < 0) { dol_print_error($db, $bankline->error); } } // Load bank groups $sql = "SELECT rowid, label FROM " . MAIN_DB_PREFIX . "bank_categ ORDER BY label"; $resql = $db->query($sql); $options = ""; if ($resql) { $var = True; $num = $db->num_rows($resql); if ($num > 0) { $options .= '<option value="0"' . (GETPOST('cat') ? '' : ' selected="true"') . '> </option>'; } $i = 0;
/** * Supprime un paiement ainsi que les lignes qu'il a genere dans comptes * Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse * Si le paiement porte sur au moins une facture a "payee", on refuse * * @param int $notrigger No trigger * @return int <0 si ko, >0 si ok */ function delete($notrigger = 0) { global $conf, $user, $langs; $bank_line_id = $this->bank_line; $this->db->begin(); // Verifier si paiement porte pas sur une facture a l'etat payee // Si c'est le cas, on refuse la suppression $billsarray = $this->getBillsArray('paye=1'); if (is_array($billsarray)) { if (count($billsarray)) { $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice"; $this->db->rollback(); return -1; } } else { $this->db->rollback(); return -2; } // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee // Si c'est le cas, on refuse le delete if ($bank_line_id) { $accline = new AccountLine($this->db, $bank_line_id); $accline->fetch($bank_line_id); if ($accline->rappro) { $this->error = "ErrorCantDeletePaymentReconciliated"; $this->db->rollback(); return -3; } } // Efface la ligne de paiement (dans paiement_facture et paiement) $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn'; $sql .= ' WHERE fk_paiementfourn = ' . $this->id; $resql = $this->db->query($sql); if ($resql) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'paiementfourn'; $sql .= ' WHERE rowid = ' . $this->id; $result = $this->db->query($sql); if (!$result) { $this->error = $this->db->error(); $this->db->rollback(); return -3; } // Supprimer l'ecriture bancaire si paiement lie a ecriture if ($bank_line_id) { $accline = new AccountLine($this->db); $result = $accline->fetch($bank_line_id); if ($result > 0) { $result = $accline->delete(); } if ($result < 0) { $this->error = $accline->error; $this->db->rollback(); return -4; } } if (!$notrigger) { // Appel des triggers $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user); if ($result < 0) { $this->db->rollback(); return -1; } // Fin appel triggers } $this->db->commit(); return 1; } else { $this->error = $this->db->error; $this->db->rollback(); return -5; } }
/** * Supprime un paiement ainsi que les lignes qu'il a genere dans comptes * Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse * Si le paiement porte sur au moins une facture a "payee", on refuse * * @param int $notrigger No trigger * @return int <0 si ko, >0 si ok */ function delete($notrigger = 0) { $bank_line_id = $this->bank_line; $this->db->begin(); // Verifier si paiement porte pas sur une facture a l'etat payee // Si c'est le cas, on refuse la suppression $billsarray = $this->getBillsArray('paye=1'); if (is_array($billsarray)) { if (count($billsarray)) { $this->error = 'Can\'t delete a payment shared by at least one invoice with status payed'; $this->db->rollback(); return -1; } } else { $this->db->rollback(); return -2; } // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee // Si c'est le cas, on refuse le delete if ($bank_line_id) { $accline = new AccountLine($this->db, $bank_line_id); $accline->fetch($bank_line_id); if ($accline->rappro) { $this->error = 'Impossible de supprimer un paiement qui a genere une ecriture qui a ete rapprochee'; $this->db->rollback(); return -3; } } // Efface la ligne de paiement (dans paiement_facture et paiement) $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn'; $sql .= ' WHERE fk_paiementfourn = ' . $this->id; dol_syslog("sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'paiementfourn'; $sql .= ' WHERE rowid = ' . $this->id; dol_syslog("sql=" . $sql); $result = $this->db->query($sql); if (!$result) { $this->error = $this->db->error(); $this->db->rollback(); return -3; } // Supprimer l'ecriture bancaire si paiement lie a ecriture if ($bank_line_id) { $accline = new AccountLine($this->db); $accline->fetch($bank_line_id); $result = $accline->delete(); if ($result < 0) { $this->error = $accline->error; $this->db->rollback(); return -4; } } $this->db->commit(); return 1; } else { $this->error = $this->db->error; $this->db->rollback(); return -5; } }
/** * Delete object in database * * @param User $user User that delete * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ function delete($user, $notrigger = 0) { global $conf, $langs; $error = 0; dol_syslog(get_class($this) . "::delete"); $this->db->begin(); if ($this->bank_line > 0) { $accline = new AccountLine($this->db); $accline->fetch($this->bank_line); $result = $accline->delete(); if ($result < 0) { $this->errors[] = $accline->error; $error++; } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "paiementcharge"; $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } } if (!$error) { if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action call a trigger. //// Call triggers //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; //$interface=new Interfaces($this->db); //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); //if ($result < 0) { $error++; $this->errors=$interface->errors; } //// End call triggers } } // Commit or rollback if ($error) { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); $this->error .= $this->error ? ', ' . $errmsg : $errmsg; } $this->db->rollback(); return -1 * $error; } else { $this->db->commit(); return 1; } }
/** * Supprime un paiement ainsi que les lignes qu'il a genere dans comptes * Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse * Si le paiement porte sur au moins une facture a "payee", on refuse * @return int <0 si ko, >0 si ok */ function delete($notrigger=0) { global $conf, $user, $langs; $error=0; $bank_line_id = $this->bank_line; $this->db->begin(); // Verifier si paiement porte pas sur une facture classee // Si c'est le cas, on refuse la suppression $billsarray=$this->getBillsArray('fk_statut > 1'); if (is_array($billsarray)) { if (sizeof($billsarray)) { $this->error="ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible"; $this->db->rollback(); return -1; } } else { $this->db->rollback(); return -2; } // Delete bank urls. If payment if on a conciliated line, return error. if ($bank_line_id) { $accline = new AccountLine($this->db); $accline->fetch($bank_line_id); $result=$accline->delete_urls($user); if ($result < 0) { $this->error=$accline->error; $this->db->rollback(); return -3; } } // Delete payment (into paiement_facture and paiement) $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture'; $sql.= ' WHERE fk_paiement = '.$this->id; $result = $this->db->query($sql); if ($result) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement'; $sql.= ' WHERE rowid = '.$this->id; $result = $this->db->query($sql); if (! $result) { $this->error=$this->db->lasterror(); $this->db->rollback(); return -3; } // Supprimer l'ecriture bancaire si paiement lie a ecriture if ($bank_line_id) { $accline = new AccountLine($this->db); $accline->fetch($bank_line_id); $result=$accline->delete(); if ($result < 0) { $this->error=$accline->error; $this->db->rollback(); return -4; } } if (! $notrigger) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('PAYMENT_DELETE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } $this->db->commit(); return 1; } else { $this->error=$this->db->error; $this->db->rollback(); return -5; } }