194 |
|
|
195 |
function add_payement($user) |
function add_payement($user) |
196 |
{ |
{ |
197 |
|
global $conf,$langs; |
198 |
|
|
199 |
|
$this->db->begin(); |
200 |
|
|
201 |
|
// Validation parameteres |
202 |
|
$this->amount=price2num($this->amount); |
203 |
|
if ($conf->banque->enabled) |
204 |
|
{ |
205 |
|
if (! $this->accountid) |
206 |
|
{ |
207 |
|
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Account")); |
208 |
|
return -3; |
209 |
|
} |
210 |
|
} |
211 |
|
if ($this->amount <= 0) |
212 |
|
{ |
213 |
|
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); |
214 |
|
return -4; |
215 |
|
} |
216 |
|
|
217 |
|
// Insertion dans table des paiement tva |
218 |
$sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep, datev, amount"; |
$sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep, datev, amount"; |
219 |
if ($this->note) $sql.=", note"; |
if ($this->note) $sql.=", note"; |
220 |
if ($this->label) $sql.=", label"; |
if ($this->label) $sql.=", label"; |
221 |
$sql.= ") "; |
$sql.= ") "; |
222 |
$sql.= " VALUES ('".$this->db->idate($this->datep)."',"; |
$sql.= " VALUES ('".$this->db->idate($this->datep)."',"; |
223 |
$sql.= "'".$this->db->idate($this->datev)."'," . ereg_replace(",",".",$this->amount); |
$sql.= "'".$this->db->idate($this->datev)."'," . $this->amount; |
224 |
if ($this->note) $sql.=", '".addslashes($this->note)."'"; |
if ($this->note) $sql.=", '".addslashes($this->note)."'"; |
225 |
if ($this->label) $sql.=", '".addslashes($this->label)."'"; |
if ($this->label) $sql.=", '".addslashes($this->label)."'"; |
226 |
$sql.= ")"; |
$sql.= ")"; |
228 |
$result = $this->db->query($sql); |
$result = $this->db->query($sql); |
229 |
if ($result) |
if ($result) |
230 |
{ |
{ |
231 |
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); |
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // \todo devrait s'appeler paiementtva |
232 |
if ($this->id > 0) |
if ($this->id > 0) |
233 |
{ |
{ |
234 |
|
if ($conf->banque->enabled) |
235 |
|
{ |
236 |
|
// Insertion dans llx_bank |
237 |
|
|
238 |
// Insertion dans llx_bank |
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php'); |
|
$acc = new Account($this->db, $this->accountid); |
|
|
$bank_line_id = $acc->addline($this->db->idate($this->datep), $this->paymenttype, $this->label, -abs($this->amount), '', '', $user); |
|
|
|
|
|
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi la ligne de tva qui a généré l'écriture bancaire |
|
|
if ($bank_line_id) { |
|
|
// $tva->update_fk_bank($bank_line_id); |
|
|
} |
|
|
|
|
|
// Mise a jour liens (pour chaque charge concernée par le paiement) |
|
|
//foreach ($paiement->amounts as $key => $value) |
|
|
//{ |
|
|
// $chid = $key; |
|
|
// $fac = new Facture($db); |
|
|
// $fac->fetch($chid); |
|
|
// $fac->fetch_client(); |
|
|
// $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); |
|
|
// $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom); |
|
|
//} |
|
|
|
|
|
} |
|
239 |
|
|
240 |
return $this->id; |
$acc = new Account($this->db, $this->accountid); |
241 |
|
$bank_line_id = $acc->addline($this->db->idate($this->datep), $this->paymenttype, $this->label, -abs($this->amount), '', '', $user); |
242 |
|
|
243 |
|
// Mise a jour fk_bank dans llx_paiementtva. On connait ainsi la ligne de tva qui a généré l'écriture bancaire |
244 |
|
if ($bank_line_id) { |
245 |
|
// $tva->update_fk_bank($bank_line_id); |
246 |
|
} |
247 |
|
|
248 |
|
// Mise a jour liens (pour chaque charge concernée par le paiement) |
249 |
|
//foreach ($paiement->amounts as $key => $value) |
250 |
|
//{ |
251 |
|
// $chid = $key; |
252 |
|
// $fac = new Facture($db); |
253 |
|
// $fac->fetch($chid); |
254 |
|
// $fac->fetch_client(); |
255 |
|
// $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); |
256 |
|
// $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom); |
257 |
|
//} |
258 |
|
} |
259 |
|
$this->db->commit(); |
260 |
|
return $this->id; |
261 |
|
} |
262 |
|
else |
263 |
|
{ |
264 |
|
$this->error=$this->db->error(); |
265 |
|
$this->db->rollback(); |
266 |
|
return -2; |
267 |
|
} |
268 |
} |
} |
269 |
else |
else |
270 |
{ |
{ |
271 |
$this->error=$this->db->error(); |
$this->error=$this->db->error(); |
272 |
|
$this->db->rollback(); |
273 |
return -1; |
return -1; |
274 |
} |
} |
275 |
} |
} |