26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'variouspayment';
42 public $table_element =
'payment_various';
47 public $picto =
'payment';
75 public $category_transaction;
85 public $accountancy_code;
90 public $subledger_account;
116 public $categorie_transaction;
121 public $fk_user_author;
126 public $fk_user_modif;
142 public $bank_num_releve;
174 public $fields = array(
187 $this->element =
'payment_various';
188 $this->table_element =
'payment_various';
198 public function update($user =
null, $notrigger = 0)
200 global $conf, $langs;
205 $this->amount = trim($this->amount);
206 $this->label = trim($this->label);
207 $this->note = trim($this->note);
208 $this->fk_bank = (int) $this->fk_bank;
209 $this->fk_user_author = (int) $this->fk_user_author;
210 $this->fk_user_modif = (int) $this->fk_user_modif;
215 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_various SET";
217 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
219 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
220 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
221 $sql .=
" sens=".(int) $this->sens.
",";
222 $sql .=
" amount=".price2num($this->amount).
",";
223 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
224 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
225 $sql .=
" label='".$this->db->escape($this->label).
"',";
226 $sql .=
" note='".$this->db->escape($this->note).
"',";
227 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
228 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
229 $sql .=
" fk_projet='".$this->db->escape($this->fk_project).
"',";
230 $sql .=
" fk_bank=".($this->fk_bank > 0 ? $this->fk_bank :
"null").
",";
231 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
232 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
233 $sql .=
" WHERE rowid=".((int) $this->
id);
235 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
238 $this->error =
"Error ".$this->db->lasterror();
244 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
255 $this->
db->rollback();
268 public function fetch($id, $user =
null)
276 $sql .=
" v.amount,";
277 $sql .=
" v.fk_typepayment,";
278 $sql .=
" v.num_payment,";
280 $sql .=
" v.note as note_private,";
281 $sql .=
" v.accountancy_code,";
282 $sql .=
" v.subledger_account,";
283 $sql .=
" v.fk_projet as fk_project,";
284 $sql .=
" v.fk_bank,";
285 $sql .=
" v.fk_user_author,";
286 $sql .=
" v.fk_user_modif,";
287 $sql .=
" b.fk_account,";
288 $sql .=
" b.fk_type,";
289 $sql .=
" b.rappro,";
290 $sql .=
" b.num_releve as bank_num_releve";
291 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
292 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
293 $sql .=
" WHERE v.rowid = ".((int) $id);
295 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
299 $obj = $this->
db->fetch_object(
$resql);
301 $this->
id = $obj->rowid;
302 $this->
ref = $obj->rowid;
303 $this->tms = $this->
db->jdate($obj->tms);
304 $this->datep = $this->
db->jdate($obj->datep);
305 $this->datev = $this->
db->jdate($obj->datev);
306 $this->sens = $obj->sens;
307 $this->amount = $obj->amount;
308 $this->type_payment = $obj->fk_typepayment;
309 $this->num_payment = $obj->num_payment;
310 $this->label = $obj->label;
311 $this->note = $obj->note_private;
312 $this->note_private = $obj->note_private;
313 $this->subledger_account = $obj->subledger_account;
314 $this->accountancy_code = $obj->accountancy_code;
315 $this->fk_project = $obj->fk_project;
316 $this->fk_bank = $obj->fk_bank;
317 $this->fk_user_author = $obj->fk_user_author;
318 $this->fk_user_modif = $obj->fk_user_modif;
319 $this->fk_account = $obj->fk_account;
320 $this->fk_type = $obj->fk_type;
321 $this->rappro = $obj->rappro;
322 $this->bank_num_releve = $obj->bank_num_releve;
328 $this->error =
"Error ".$this->db->lasterror();
340 public function delete($user)
342 global $conf, $langs;
347 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
354 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
355 $sql .=
" WHERE rowid=".((int) $this->
id);
357 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
360 $this->error =
"Error ".$this->db->lasterror();
385 $this->accountancy_code =
'';
386 $this->subledger_account =
'';
389 $this->fk_user_author =
'';
390 $this->fk_user_modif =
'';
400 $newamount =
price2num($this->amount,
'MT');
403 if (!($newamount) > 0 || empty($this->datep)) {
418 global $conf, $langs;
424 $this->amount =
price2num(trim($this->amount));
425 $this->label = trim($this->label);
426 $this->note = trim($this->note);
427 $this->fk_bank = (int) $this->fk_bank;
428 $this->fk_user_author = (int) $this->fk_user_author;
429 $this->fk_user_modif = (int) $this->fk_user_modif;
430 $this->fk_account = (int) $this->fk_account;
431 if (empty($this->fk_account) && isset($this->accountid)) {
432 $this->fk_account = $this->accountid;
437 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
440 if ($this->amount < 0 || $this->amount ==
'') {
441 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
444 if (
isModEnabled(
'banque') && (empty($this->fk_account) || $this->fk_account <= 0)) {
445 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
448 if (
isModEnabled(
'banque') && (empty($this->type_payment) || $this->type_payment <= 0)) {
449 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
456 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_various (";
461 $sql .=
", fk_typepayment";
462 $sql .=
", num_payment";
467 $sql .=
", accountancy_code";
468 $sql .=
", subledger_account";
469 $sql .=
", fk_projet";
470 $sql .=
", fk_user_author";
476 $sql .=
"'".$this->db->idate($this->datep).
"'";
477 $sql .=
", '".$this->db->idate($this->datev).
"'";
478 $sql .=
", '".$this->db->escape($this->sens).
"'";
479 $sql .=
", ".price2num($this->amount);
480 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
481 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
483 $sql .=
", '".$this->db->escape($this->note).
"'";
485 $sql .=
", '".$this->db->escape($this->label).
"'";
486 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
487 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
488 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
489 $sql .=
", ".((int) $user->id);
490 $sql .=
", '".$this->db->idate($now).
"'";
492 $sql .=
", ".((int) $conf->entity);
495 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
496 $result = $this->
db->query($sql);
498 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
499 $this->
ref = $this->id;
504 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
507 $result = $acc->fetch($this->fk_account);
515 if ($this->sens ==
'0') {
519 $bank_line_id = $acc->addline(
523 $sign * abs($this->amount),
525 ($this->category_transaction > 0 ? $this->category_transaction : 0),
535 if ($bank_line_id > 0) {
538 $this->error = $acc->error;
544 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
546 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
548 $this->error = $acc->error;
554 $this->error = $acc->error;
560 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
573 $this->
db->rollback();
577 $this->error = $this->
db->error();
578 $this->
db->rollback();
593 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.((int) $id_bank);
594 $sql .=
" WHERE rowid = ".((int) $this->
id);
595 $result = $this->
db->query($sql);
613 return $this->
LibStatut($this->statut, $mode);
627 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
638 $statusType =
'status'.$status;
640 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
654 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
656 global $db, $conf, $langs, $hookmanager;
659 if (!empty($conf->dol_no_mouse_hover)) {
665 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
667 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
669 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
671 if ($option !=
'nolink') {
673 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
674 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
675 $add_save_lastsearch_values = 1;
677 if ($add_save_lastsearch_values) {
678 $url .=
'&save_lastsearch_values=1';
683 if (empty($notooltip)) {
684 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
685 $label = $langs->trans(
"ShowMyObject");
686 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
688 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
689 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
691 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
694 $linkstart =
'<a href="'.$url.
'"';
695 $linkstart .= $linkclose.
'>';
698 $result .= $linkstart;
700 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
702 if ($withpicto != 2) {
703 $result .= $this->ref;
709 $hookmanager->initHooks(array(
'variouspayment'));
710 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
711 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
713 $result = $hookmanager->resPrint;
715 $result .= $hookmanager->resPrint;
729 $sql =
'SELECT v.rowid, v.datec, v.fk_user_author';
730 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_various as v';
731 $sql .=
' WHERE v.rowid = '.((int) $id);
733 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
734 $result = $this->
db->query($sql);
737 if ($this->
db->num_rows($result)) {
738 $obj = $this->
db->fetch_object($result);
739 $this->
id = $obj->rowid;
740 if ($obj->fk_user_author) {
741 $cuser =
new User($this->
db);
742 $cuser->fetch($obj->fk_user_author);
743 $this->user_creation = $cuser;
745 $this->date_creation = $this->
db->jdate($obj->datec);
746 if ($obj->fk_user_modif) {
747 $muser =
new User($this->
db);
748 $muser->fetch($obj->fk_user_modif);
749 $this->user_modif = $muser;
751 $this->date_modif = $this->
db->jdate($obj->tms);
753 $this->
db->free($result);
766 $banklineid = $this->fk_bank;
768 $alreadydispatched = 0;
772 $sql =
" SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='".$this->
db->escape($type).
"' AND ab.fk_doc = ".((int) $banklineid);
775 $obj = $this->
db->fetch_object(
$resql);
777 $alreadydispatched = $obj->nb;
780 $this->error = $this->
db->lasterror();
784 if ($alreadydispatched) {