Exemplo n.º 1
0
 /**
  *	Create payment in database
  *
  *	@param		User	$user        			Object of creating user
  *	@param		int		$closepaidinvoices   	1=Also close payed invoices to paid, 0=Do nothing more
  *	@return     int         					id of created payment, < 0 if error
  */
 function create($user, $closepaidinvoices = 0)
 {
     global $langs, $conf;
     $error = 0;
     // Clean parameters
     $this->total = 0;
     foreach ($this->amounts as $key => $value) {
         $newvalue = price2num($value, 'MT');
         $this->amounts[$key] = $newvalue;
         $this->total += $newvalue;
     }
     $this->total = price2num($this->total);
     $this->db->begin();
     if ($this->total != 0) {
         $now = dol_now();
         $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiementfourn (';
         $sql .= 'datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
         $sql .= " VALUES ('" . $this->db->idate($now) . "',";
         $sql .= " '" . $this->db->idate($this->datepaye) . "', '" . $this->total . "', " . $this->paiementid . ", '" . $this->num_paiement . "', '" . $this->db->escape($this->note) . "', " . $user->id . ", 0)";
         dol_syslog("PaiementFourn::create", LOG_DEBUG);
         $resql = $this->db->query($sql);
         if ($resql) {
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . 'paiementfourn');
             // Insere tableau des montants / factures
             foreach ($this->amounts as $key => $amount) {
                 $facid = $key;
                 if (is_numeric($amount) && $amount != 0) {
                     $amount = price2num($amount);
                     $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
                     $sql .= ' VALUES (' . $facid . ',' . $this->id . ',\'' . $amount . '\')';
                     $resql = $this->db->query($sql);
                     if ($resql) {
                         // If we want to closed payed invoices
                         if ($closepaidinvoices) {
                             $invoice = new FactureFournisseur($this->db);
                             $invoice->fetch($facid);
                             $paiement = $invoice->getSommePaiement();
                             //$creditnotes=$invoice->getSumCreditNotesUsed();
                             $creditnotes = 0;
                             //$deposits=$invoice->getSumDepositsUsed();
                             $deposits = 0;
                             $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
                             $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
                             if ($remaintopay == 0) {
                                 $result = $invoice->set_paid($user, '', '');
                             } else {
                                 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing.");
                             }
                         }
                     } else {
                         dol_syslog('Paiement::Create Erreur INSERT dans paiement_facture ' . $facid);
                         $error++;
                     }
                 } else {
                     dol_syslog('PaiementFourn::Create Montant non numerique', LOG_ERR);
                 }
             }
             if (!$error) {
                 // Call trigger
                 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
                 if ($result < 0) {
                     $error++;
                 }
                 // End call triggers
             }
         } else {
             $this->error = $this->db->lasterror();
             $error++;
         }
     } else {
         $this->error = "ErrorTotalIsNull";
         dol_syslog('PaiementFourn::Create Error ' . $this->error, LOG_ERR);
         $error++;
     }
     if ($this->total != 0 && $error == 0) {
         $this->db->commit();
         dol_syslog('PaiementFourn::Create Ok Total = ' . $this->total);
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Exemplo n.º 2
0
if ($_REQUEST['action'] == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes')
{
    if ($user->rights->fournisseur->facture->creer)
    {
        $facturefourn = new FactureFournisseur($db);
        $facturefourn->fetch($facid);
        $facturefourn->deleteline($_REQUEST['lineid']);
        $_GET['action'] = '';
    }
}

if ($_REQUEST['action'] == 'confirm_paid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->creer)
{
    $facturefourn=new FactureFournisseur($db);
    $facturefourn->fetch($_GET['facid']);
    $result=$facturefourn->set_paid($user);
}

// Set supplier ref
if (($_POST['action'] == 'setref_supplier' || $_POST['action'] == 'set_ref_supplier') && $user->rights->fournisseur->facture->creer)
{
    $facturefourn = new FactureFournisseur($db);
    $facturefourn->fetch($facid);
    $result=$facturefourn->set_ref_supplier($user, $_POST['ref_supplier']);
    $_GET['facid']=$facid;
}

// Set supplier ref
if (($_POST['action'] == 'setlabel') && $user->rights->fournisseur->facture->creer)
{
    $facturefourn = new FactureFournisseur($db);
Exemplo n.º 3
0
        $mesg = '<div class="error">' . $object->error . '</div>';
    }
} elseif ($action == 'confirm_delete_line' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) {
    $object->fetch($id);
    $ret = $object->deleteline(GETPOST('lineid'));
    if ($ret > 0) {
        header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
        exit;
    } else {
        $mesg = '<div class="error">' . $object->error . '</div>';
        /* Fix bug 1485 : Reset action to avoid asking again confirmation on failure */
        $action = '';
    }
} elseif ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) {
    $object->fetch($id);
    $result = $object->set_paid($user);
    if ($result < 0) {
        setEventMessage($object->error, 'errors');
    }
}
// Set supplier ref
if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer) {
    $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'));
    if ($result < 0) {
        dol_print_error($db, $object->error);
    }
}
// conditions de reglement
if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer) {
    $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
} else {
Exemplo n.º 4
0
	/**
	 *    Create payment in database
	 *    @param      user        			Object of creating user
	 *    @param       closepaidinvoices   	1=Also close payed invoices to paid, 0=Do nothing more
	 *    @return     int         			id of created payment, < 0 if error
	 */
	function create($user,$closepaidinvoices=0)
	{
		global $langs,$conf;

		$error = 0;

		// Clean parameters
		$this->total = 0;
		foreach ($this->amounts as $key => $value)
		{
			$value = price2num($value);
			$val = round($value, 2);
			$this->amounts[$key] = $val;
			$this->total += $val;
		}
		$this->total = price2num($this->total);


		$this->db->begin();

		if ($this->total <> 0) // On accepte les montants negatifs
		{
			$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
			$sql.= 'datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
			$sql.= ' VALUES ('.$this->db->idate(mktime()).',';
			$sql.= " ".$this->db->idate($this->datepaye).", '".$this->total."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.", 0)";

			dol_syslog("PaiementFourn::create sql=".$sql);
			$resql = $this->db->query($sql);
			if ($resql)
			{
				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');

				// Insere tableau des montants / factures
				foreach ($this->amounts as $key => $amount)
				{
					$facid = $key;
					if (is_numeric($amount) && $amount <> 0)
					{
						$amount = price2num($amount);
						$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
						$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
						$resql=$this->db->query($sql);
						if ($resql)
						{
							// If we want to closed payed invoices
						    if ($closepaidinvoices)
						    {
						        $invoice=new FactureFournisseur($this->db);
						        $invoice->fetch($facid);
	                            $paiement = $invoice->getSommePaiement();
	                            //$creditnotes=$invoice->getSumCreditNotesUsed();
	                            $creditnotes=0;
	                            //$deposits=$invoice->getSumDepositsUsed();
	                            $deposits=0;
	                            $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
	                            $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
	                            if ($remaintopay == 0)
	                            {
	    					        $result=$invoice->set_paid($user,'','');
	                            }
	                            else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
							}
						}
						else
						{
							dol_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid);
							$error++;
						}
						
					}
					else
					{
						dol_syslog('PaiementFourn::Create Montant non numerique',LOG_ERR);
					}
				}

				if (! $error)
				{
		            // Appel des triggers
		            include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
		            $interface=new Interfaces($this->db);
		            $result=$interface->run_triggers('PAYMENT_SUPPLIER_CREATE',$this,$user,$langs,$conf);
					if ($result < 0) { $error++; $this->errors=$interface->errors; }
		            // Fin appel triggers
				}
			}
			else
			{
				$this->error=$this->db->lasterror();
				dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
				$error++;
			}
		}
		else
		{
			$this->error="ErrorTotalIsNull";
			dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
			$error++;
		}

		if ($this->total <> 0 && $error == 0) // On accepte les montants negatifs
		{
			$this->db->commit();
			dol_syslog('PaiementFourn::Create Ok Total = '.$this->total);
			return $this->id;
		}
		else
		{
			$this->db->rollback();
			return -1;
		}
	}