コード例 #1
0
 /**
  * Create
  *
  * @param 	User		$user				User object
  * @param 	int			$id					Id
  * @param 	string		$motif				Motif
  * @param 	int	$date_rejet			Date rejet
  * @param 	int			$bonid				Bon id
  * @param 	int			$facturation		Facturation
  * @return	void
  */
 function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0)
 {
     global $langs, $conf;
     $error = 0;
     $this->id = $id;
     $this->bon_id = $bonid;
     $now = dol_now();
     dol_syslog("RejetPrelevement::Create id {$id}");
     $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
     $facs = $this->getListInvoices(1);
     $this->db->begin();
     // Insert refused line into database
     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_rejet (";
     $sql .= "fk_prelevement_lignes";
     $sql .= ", date_rejet";
     $sql .= ", motif";
     $sql .= ", fk_user_creation";
     $sql .= ", date_creation";
     $sql .= ", afacturer";
     $sql .= ") VALUES (";
     $sql .= $id;
     $sql .= ", '" . $this->db->idate($date_rejet) . "'";
     $sql .= ", " . $motif;
     $sql .= ", " . $user->id;
     $sql .= ", '" . $this->db->idate($now) . "'";
     $sql .= ", " . $facturation;
     $sql .= ")";
     $result = $this->db->query($sql);
     if (!$result) {
         dol_syslog("RejetPrelevement::create Erreur 4");
         dol_syslog("RejetPrelevement::create Erreur 4 {$sql}");
         $error++;
     }
     // Tag the line to refused
     $sql = " UPDATE " . MAIN_DB_PREFIX . "prelevement_lignes ";
     $sql .= " SET statut = 3";
     $sql .= " WHERE rowid = " . $id;
     if (!$this->db->query($sql)) {
         dol_syslog("RejetPrelevement::create Erreur 5");
         $error++;
     }
     $num = count($facs);
     for ($i = 0; $i < $num; $i++) {
         $fac = new Facture($this->db);
         $fac->fetch($facs[$i][0]);
         // Make a negative payment
         $pai = new Paiement($this->db);
         $pai->amounts = array();
         /*
          * We replace the comma with a point otherwise some
          * PHP installs sends only the part integer negative
          */
         $pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * -1);
         $pai->datepaye = $date_rejet;
         $pai->paiementid = 3;
         // type of payment: withdrawal
         $pai->num_paiement = $fac->ref;
         if ($pai->create($this->user) < 0) {
             $error++;
             dol_syslog("RejetPrelevement::Create Error creation payment invoice " . $facs[$i][0]);
         } else {
             $result = $pai->addPaymentToBank($user, 'payment', '(InvoiceRefused)', $bankaccount, '', '');
             if ($result < 0) {
                 dol_syslog("RejetPrelevement::Create AddPaymentToBan Error");
                 $error++;
             }
             // Payment validation
             if ($pai->valide() < 0) {
                 $error++;
                 dol_syslog("RejetPrelevement::Create Error payment validation");
             }
         }
         //Tag invoice as unpaid
         dol_syslog("RejetPrelevement::Create set_unpaid fac " . $fac->ref);
         $fac->set_unpaid($user);
         //TODO: Must be managed by notifications module
         // Send email to sender of the standing order request
         $this->_send_email($fac);
     }
     if ($error == 0) {
         dol_syslog("RejetPrelevement::Create Commit");
         $this->db->commit();
     } else {
         dol_syslog("RejetPrelevement::Create Rollback");
         $this->db->rollback();
     }
 }
コード例 #2
0
ファイル: card.php プロジェクト: ADDAdev/Dolibarr
    $object->fetch($id);
    $result = $object->delete();
    if ($result > 0) {
        $db->commit();
        header("Location: list.php");
        exit;
    } else {
        $langs->load("errors");
        setEventMessage($langs->trans($object->error), 'errors');
        $db->rollback();
    }
}
if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->facture->paiement) {
    $db->begin();
    $object->fetch($id);
    if ($object->valide() > 0) {
        $db->commit();
        // Loop on each invoice linked to this payment to rebuild PDF
        $factures = array();
        foreach ($factures as $id) {
            $fac = new Facture($db);
            $fac->fetch($id);
            $outputlangs = $langs;
            if (!empty($_REQUEST['lang_id'])) {
                $outputlangs = new Translate("", $conf);
                $outputlangs->setDefaultLang($_REQUEST['lang_id']);
            }
            if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
                $fac->generateDocument($fac->modelpdf, $outputlangs);
            }
        }
コード例 #3
0
ファイル: fiche.php プロジェクト: remyyounes/dolibarr
	}
	else
	{
	    $langs->load("errors");
		$mesg='<div class="error">'.$langs->trans($paiement->error).'</div>';
        $db->rollback();
	}
}

if ($action == 'confirm_valide' && GETPOST('confirm') == 'yes' && $user->rights->facture->paiement)
{
	$db->begin();

	$paiement = new Paiement($db);
    $paiement->fetch($id);
	if ($paiement->valide() > 0)
	{
		$db->commit();

		// Loop on each invoice linked to this payment to rebuild PDF
		$factures=array();
		foreach($factures as $id)
		{
			$fac = new Facture($db);
			$fac->fetch($id);

			$outputlangs = $langs;
			if (! empty($_REQUEST['lang_id']))
			{
				$outputlangs = new Translate("",$conf);
				$outputlangs->setDefaultLang($_REQUEST['lang_id']);