/**
  *      Delete a social contribution
  *
  *      @param		User    $user   Object user making delete
  *      @return     		int 	<0 if KO, >0 if OK
  */
 function delete($user)
 {
     $error = 0;
     $this->db->begin();
     // Get bank transaction lines for this social contributions
     include_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
     $account = new Account($this->db);
     $lines_url = $account->get_url('', $this->id, 'sc');
     // Delete bank urls
     foreach ($lines_url as $line_url) {
         if (!$error) {
             $accountline = new AccountLine($this->db);
             $accountline->fetch($line_url['fk_bank']);
             $result = $accountline->delete_urls($user);
             if ($result < 0) {
                 $error++;
             }
         }
     }
     // Delete payments
     if (!$error) {
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "paiementcharge where fk_charge='" . $this->id . "'";
         dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
         $resql = $this->db->query($sql);
         if (!$resql) {
             $error++;
             $this->error = $this->db->lasterror();
         }
     }
     if (!$error) {
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "chargesociales where rowid='" . $this->id . "'";
         dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
         $resql = $this->db->query($sql);
         if (!$resql) {
             $error++;
             $this->error = $this->db->lasterror();
         }
     }
     if (!$error) {
         $this->db->commit();
         return 1;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Ejemplo n.º 2
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;
     $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;
     }
 }
Ejemplo n.º 3
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
	 *      @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;
		}
	}