26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'payment_various';
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(
196 public function update($user =
null, $notrigger = 0)
198 global $conf, $langs;
203 $this->amount = trim($this->amount);
204 $this->label = trim($this->label);
205 $this->note = trim($this->note);
206 $this->fk_bank = (int) $this->fk_bank;
207 $this->fk_user_author = (int) $this->fk_user_author;
208 $this->fk_user_modif = (int) $this->fk_user_modif;
213 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_various SET";
215 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
217 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
218 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
219 $sql .=
" sens=".(int) $this->sens.
",";
220 $sql .=
" amount=".price2num($this->amount).
",";
221 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
222 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
223 $sql .=
" label='".$this->db->escape($this->label).
"',";
224 $sql .=
" note='".$this->db->escape($this->note).
"',";
225 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
226 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
227 $sql .=
" fk_projet='".$this->db->escape($this->fk_project).
"',";
228 $sql .=
" fk_bank=".($this->fk_bank > 0 ? $this->fk_bank :
"null").
",";
229 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
230 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
231 $sql .=
" WHERE rowid=".((int) $this->
id);
233 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
234 $resql = $this->db->query(
$sql);
236 $this->error =
"Error ".$this->db->lasterror();
242 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
253 $this->db->rollback();
266 public function fetch($id, $user =
null)
274 $sql .=
" v.amount,";
275 $sql .=
" v.fk_typepayment,";
276 $sql .=
" v.num_payment,";
278 $sql .=
" v.note as note_private,";
279 $sql .=
" v.accountancy_code,";
280 $sql .=
" v.subledger_account,";
281 $sql .=
" v.fk_projet as fk_project,";
282 $sql .=
" v.fk_bank,";
283 $sql .=
" v.fk_user_author,";
284 $sql .=
" v.fk_user_modif,";
285 $sql .=
" b.fk_account,";
286 $sql .=
" b.fk_type,";
287 $sql .=
" b.rappro,";
288 $sql .=
" b.num_releve as bank_num_releve";
289 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
290 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
291 $sql .=
" WHERE v.rowid = ".((int) $id);
293 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
294 $resql = $this->db->query(
$sql);
296 if ($this->db->num_rows($resql)) {
297 $obj = $this->db->fetch_object($resql);
299 $this->
id = $obj->rowid;
300 $this->
ref = $obj->rowid;
301 $this->tms = $this->db->jdate($obj->tms);
302 $this->datep = $this->db->jdate($obj->datep);
303 $this->datev = $this->db->jdate($obj->datev);
304 $this->sens = $obj->sens;
305 $this->amount = $obj->amount;
306 $this->type_payment = $obj->fk_typepayment;
307 $this->num_payment = $obj->num_payment;
308 $this->label = $obj->label;
309 $this->note = $obj->note_private;
310 $this->note_private = $obj->note_private;
311 $this->subledger_account = $obj->subledger_account;
312 $this->accountancy_code = $obj->accountancy_code;
313 $this->fk_project = $obj->fk_project;
314 $this->fk_bank = $obj->fk_bank;
315 $this->fk_user_author = $obj->fk_user_author;
316 $this->fk_user_modif = $obj->fk_user_modif;
317 $this->fk_account = $obj->fk_account;
318 $this->fk_type = $obj->fk_type;
319 $this->rappro = $obj->rappro;
320 $this->bank_num_releve = $obj->bank_num_releve;
322 $this->db->free($resql);
326 $this->error =
"Error ".$this->db->lasterror();
338 public function delete($user)
340 global $conf, $langs;
345 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
352 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
353 $sql .=
" WHERE rowid=".((int) $this->
id);
355 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
356 $resql = $this->db->query(
$sql);
358 $this->error =
"Error ".$this->db->lasterror();
383 $this->accountancy_code =
'';
384 $this->subledger_account =
'';
387 $this->fk_user_author =
'';
388 $this->fk_user_modif =
'';
398 $newamount =
price2num($this->amount,
'MT');
401 if (!($newamount) > 0 || empty($this->datep)) {
416 global $conf, $langs;
422 $this->amount =
price2num(trim($this->amount));
423 $this->label = trim($this->label);
424 $this->note = trim($this->note);
425 $this->fk_bank = (int) $this->fk_bank;
426 $this->fk_user_author = (int) $this->fk_user_author;
427 $this->fk_user_modif = (int) $this->fk_user_modif;
428 $this->fk_account = (int) $this->fk_account;
429 if (empty($this->fk_account) && isset($this->accountid)) {
430 $this->fk_account = $this->accountid;
435 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
438 if ($this->amount < 0 || $this->amount ==
'') {
439 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
442 if (
isModEnabled(
"banque") && (empty($this->fk_account) || $this->fk_account <= 0)) {
443 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
446 if (
isModEnabled(
"banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
447 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
454 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_various (";
459 $sql .=
", fk_typepayment";
460 $sql .=
", num_payment";
465 $sql .=
", accountancy_code";
466 $sql .=
", subledger_account";
467 $sql .=
", fk_projet";
468 $sql .=
", fk_user_author";
474 $sql .=
"'".$this->db->idate($this->datep).
"'";
475 $sql .=
", '".$this->db->idate($this->datev).
"'";
476 $sql .=
", '".$this->db->escape($this->sens).
"'";
477 $sql .=
", ".price2num($this->amount);
478 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
479 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
481 $sql .=
", '".$this->db->escape($this->note).
"'";
483 $sql .=
", '".$this->db->escape($this->label).
"'";
484 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
485 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
486 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
487 $sql .=
", ".((int) $user->id);
488 $sql .=
", '".$this->db->idate($now).
"'";
490 $sql .=
", ".((int) $conf->entity);
493 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
494 $result = $this->db->query(
$sql);
496 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
497 $this->
ref = $this->id;
502 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
505 $result = $acc->fetch($this->fk_account);
513 if ($this->sens ==
'0') {
517 $bank_line_id = $acc->addline(
521 $sign * abs($this->amount),
523 ($this->category_transaction > 0 ? $this->category_transaction : 0),
533 if ($bank_line_id > 0) {
536 $this->error = $acc->error;
542 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
544 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
546 $this->error = $acc->error;
552 $this->error = $acc->error;
558 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
571 $this->db->rollback();
575 $this->error = $this->db->error();
576 $this->db->rollback();
591 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.((int) $id_bank);
592 $sql .=
" WHERE rowid = ".((int) $this->
id);
593 $result = $this->db->query(
$sql);
611 return $this->
LibStatut($this->statut, $mode);
625 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
636 $statusType =
'status'.$status;
638 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
652 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
654 global $db, $conf, $langs, $hookmanager;
657 if (!empty($conf->dol_no_mouse_hover)) {
663 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
665 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
667 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
669 if ($option !=
'nolink') {
671 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
672 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
673 $add_save_lastsearch_values = 1;
675 if ($add_save_lastsearch_values) {
676 $url .=
'&save_lastsearch_values=1';
681 if (empty($notooltip)) {
682 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
683 $label = $langs->trans(
"ShowMyObject");
684 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
686 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
687 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
689 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
692 $linkstart =
'<a href="'.$url.
'"';
693 $linkstart .= $linkclose.
'>';
696 $result .= $linkstart;
698 $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);
700 if ($withpicto != 2) {
701 $result .= $this->ref;
707 $hookmanager->initHooks(array(
'variouspayment'));
708 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
709 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
711 $result = $hookmanager->resPrint;
713 $result .= $hookmanager->resPrint;
727 $sql =
'SELECT v.rowid, v.datec, v.fk_user_author';
728 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_various as v';
729 $sql .=
' WHERE v.rowid = '.((int) $id);
731 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
732 $result = $this->db->query(
$sql);
735 if ($this->db->num_rows($result)) {
736 $obj = $this->db->fetch_object($result);
737 $this->
id = $obj->rowid;
738 if ($obj->fk_user_author) {
739 $cuser =
new User($this->db);
740 $cuser->fetch($obj->fk_user_author);
741 $this->user_creation = $cuser;
743 $this->date_creation = $this->db->jdate($obj->datec);
744 if ($obj->fk_user_modif) {
745 $muser =
new User($this->db);
746 $muser->fetch($obj->fk_user_modif);
747 $this->user_modif = $muser;
749 $this->date_modif = $this->db->jdate($obj->tms);
751 $this->db->free($result);
764 $banklineid = $this->fk_bank;
766 $alreadydispatched = 0;
770 $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);
771 $resql = $this->db->query(
$sql);
773 $obj = $this->db->fetch_object($resql);
775 $alreadydispatched = $obj->nb;
778 $this->error = $this->db->lasterror();
782 if ($alreadydispatched) {
799 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
801 $return =
'<div class="box-flex-item box-flex-grow-zero">';
802 $return .=
'<div class="info-box info-box-sm">';
803 $return .=
'<span class="info-box-icon bg-infobox-action">';
805 $return .=
'</span>';
806 $return .=
'<div class="info-box-content">';
807 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
808 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
809 if (property_exists($this,
'fk_bank')) {
810 $return .=
' | <span class="info-box-status ">'.$this->fk_bank.
'</span>';
812 if (property_exists($this,
'datep')) {
813 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datep),
'day').
'</span>';
815 if (property_exists($this,
'type_payment') && !empty($this->type_payment)) {
816 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Payment", $this->type_payment).
'</span> : <span class="info-box-label">'.$this->type_payment.
'</span>';
818 if (property_exists($this,
'accountancy_code')) {
819 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label" title="'.$this->accountancy_code.
'">'.$this->accountancy_code.
'</span>';
821 if (property_exists($this,
'amount')) {
822 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Debit").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
838 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
857 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';