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(
193 $this->element =
'payment_various';
194 $this->table_element =
'payment_various';
204 public function update($user =
null, $notrigger = 0)
206 global $conf, $langs;
211 $this->amount = trim($this->amount);
212 $this->label = trim($this->label);
213 $this->note = trim($this->note);
214 $this->fk_bank = (int) $this->fk_bank;
215 $this->fk_user_author = (int) $this->fk_user_author;
216 $this->fk_user_modif = (int) $this->fk_user_modif;
221 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_various SET";
223 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
225 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
226 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
227 $sql .=
" sens=".(int) $this->sens.
",";
228 $sql .=
" amount=".price2num($this->amount).
",";
229 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
230 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
231 $sql .=
" label='".$this->db->escape($this->label).
"',";
232 $sql .=
" note='".$this->db->escape($this->note).
"',";
233 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
234 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
235 $sql .=
" fk_projet='".$this->db->escape($this->fk_project).
"',";
236 $sql .=
" fk_bank=".($this->fk_bank > 0 ? $this->fk_bank :
"null").
",";
237 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
238 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
239 $sql .=
" WHERE rowid=".((int) $this->
id);
241 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
244 $this->error =
"Error ".$this->db->lasterror();
250 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
261 $this->
db->rollback();
274 public function fetch($id, $user =
null)
282 $sql .=
" v.amount,";
283 $sql .=
" v.fk_typepayment,";
284 $sql .=
" v.num_payment,";
286 $sql .=
" v.note as note_private,";
287 $sql .=
" v.accountancy_code,";
288 $sql .=
" v.subledger_account,";
289 $sql .=
" v.fk_projet as fk_project,";
290 $sql .=
" v.fk_bank,";
291 $sql .=
" v.fk_user_author,";
292 $sql .=
" v.fk_user_modif,";
293 $sql .=
" b.fk_account,";
294 $sql .=
" b.fk_type,";
295 $sql .=
" b.rappro,";
296 $sql .=
" b.num_releve as bank_num_releve";
297 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
298 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
299 $sql .=
" WHERE v.rowid = ".((int) $id);
301 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
305 $obj = $this->
db->fetch_object(
$resql);
307 $this->
id = $obj->rowid;
308 $this->
ref = $obj->rowid;
309 $this->tms = $this->
db->jdate($obj->tms);
310 $this->datep = $this->
db->jdate($obj->datep);
311 $this->datev = $this->
db->jdate($obj->datev);
312 $this->sens = $obj->sens;
313 $this->amount = $obj->amount;
314 $this->type_payment = $obj->fk_typepayment;
315 $this->num_payment = $obj->num_payment;
316 $this->label = $obj->label;
317 $this->note = $obj->note_private;
318 $this->note_private = $obj->note_private;
319 $this->subledger_account = $obj->subledger_account;
320 $this->accountancy_code = $obj->accountancy_code;
321 $this->fk_project = $obj->fk_project;
322 $this->fk_bank = $obj->fk_bank;
323 $this->fk_user_author = $obj->fk_user_author;
324 $this->fk_user_modif = $obj->fk_user_modif;
325 $this->fk_account = $obj->fk_account;
326 $this->fk_type = $obj->fk_type;
327 $this->rappro = $obj->rappro;
328 $this->bank_num_releve = $obj->bank_num_releve;
334 $this->error =
"Error ".$this->db->lasterror();
346 public function delete($user)
348 global $conf, $langs;
353 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
360 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
361 $sql .=
" WHERE rowid=".((int) $this->
id);
363 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
366 $this->error =
"Error ".$this->db->lasterror();
391 $this->accountancy_code =
'';
392 $this->subledger_account =
'';
395 $this->fk_user_author =
'';
396 $this->fk_user_modif =
'';
406 $newamount =
price2num($this->amount,
'MT');
409 if (!($newamount) > 0 || empty($this->datep)) {
424 global $conf, $langs;
430 $this->amount =
price2num(trim($this->amount));
431 $this->label = trim($this->label);
432 $this->note = trim($this->note);
433 $this->fk_bank = (int) $this->fk_bank;
434 $this->fk_user_author = (int) $this->fk_user_author;
435 $this->fk_user_modif = (int) $this->fk_user_modif;
436 $this->fk_account = (int) $this->fk_account;
437 if (empty($this->fk_account) && isset($this->accountid)) {
438 $this->fk_account = $this->accountid;
443 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
446 if ($this->amount < 0 || $this->amount ==
'') {
447 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
450 if (
isModEnabled(
"banque") && (empty($this->fk_account) || $this->fk_account <= 0)) {
451 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
454 if (
isModEnabled(
"banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
455 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
462 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_various (";
467 $sql .=
", fk_typepayment";
468 $sql .=
", num_payment";
473 $sql .=
", accountancy_code";
474 $sql .=
", subledger_account";
475 $sql .=
", fk_projet";
476 $sql .=
", fk_user_author";
482 $sql .=
"'".$this->db->idate($this->datep).
"'";
483 $sql .=
", '".$this->db->idate($this->datev).
"'";
484 $sql .=
", '".$this->db->escape($this->sens).
"'";
485 $sql .=
", ".price2num($this->amount);
486 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
487 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
489 $sql .=
", '".$this->db->escape($this->note).
"'";
491 $sql .=
", '".$this->db->escape($this->label).
"'";
492 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
493 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
494 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
495 $sql .=
", ".((int) $user->id);
496 $sql .=
", '".$this->db->idate($now).
"'";
498 $sql .=
", ".((int) $conf->entity);
501 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
502 $result = $this->
db->query($sql);
504 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
505 $this->
ref = $this->id;
510 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
513 $result = $acc->fetch($this->fk_account);
521 if ($this->sens ==
'0') {
525 $bank_line_id = $acc->addline(
529 $sign * abs($this->amount),
531 ($this->category_transaction > 0 ? $this->category_transaction : 0),
541 if ($bank_line_id > 0) {
544 $this->error = $acc->error;
550 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
552 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
554 $this->error = $acc->error;
560 $this->error = $acc->error;
566 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
579 $this->
db->rollback();
583 $this->error = $this->
db->error();
584 $this->
db->rollback();
599 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.((int) $id_bank);
600 $sql .=
" WHERE rowid = ".((int) $this->
id);
601 $result = $this->
db->query($sql);
619 return $this->
LibStatut($this->statut, $mode);
635 if (empty($status)) {
639 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
648 $statusType =
'status'.$status;
650 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
664 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
666 global $db, $conf, $langs, $hookmanager;
669 if (!empty($conf->dol_no_mouse_hover)) {
675 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
677 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
679 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
681 if ($option !=
'nolink') {
683 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
684 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
685 $add_save_lastsearch_values = 1;
687 if ($add_save_lastsearch_values) {
688 $url .=
'&save_lastsearch_values=1';
693 if (empty($notooltip)) {
694 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
695 $label = $langs->trans(
"ShowMyObject");
696 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
698 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
699 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
701 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
704 $linkstart =
'<a href="'.$url.
'"';
705 $linkstart .= $linkclose.
'>';
708 $result .= $linkstart;
710 $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);
712 if ($withpicto != 2) {
713 $result .= $this->ref;
719 $hookmanager->initHooks(array(
'variouspayment'));
720 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
721 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
723 $result = $hookmanager->resPrint;
725 $result .= $hookmanager->resPrint;
739 $sql =
'SELECT v.rowid, v.datec, v.fk_user_author';
740 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_various as v';
741 $sql .=
' WHERE v.rowid = '.((int) $id);
743 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
744 $result = $this->
db->query($sql);
747 if ($this->
db->num_rows($result)) {
748 $obj = $this->
db->fetch_object($result);
749 $this->
id = $obj->rowid;
750 if ($obj->fk_user_author) {
751 $cuser =
new User($this->
db);
752 $cuser->fetch($obj->fk_user_author);
753 $this->user_creation = $cuser;
755 $this->date_creation = $this->
db->jdate($obj->datec);
756 if ($obj->fk_user_modif) {
757 $muser =
new User($this->
db);
758 $muser->fetch($obj->fk_user_modif);
759 $this->user_modif = $muser;
761 $this->date_modif = $this->
db->jdate($obj->tms);
763 $this->
db->free($result);
776 $banklineid = $this->fk_bank;
778 $alreadydispatched = 0;
782 $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);
785 $obj = $this->
db->fetch_object(
$resql);
787 $alreadydispatched = $obj->nb;
790 $this->error = $this->
db->lasterror();
794 if ($alreadydispatched) {
Class to manage bank accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage various payments.
update_fk_bank($id_bank)
Update link between payment various and line generate into llx_bank.
getNomUrl($withpicto=0, $option='', $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Send name clicable (with possibly the picto)
initAsSpecimen()
Initialise an instance with random values.
const STATUS_DRAFT
Draft status.
create($user)
Create in database.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
fetch($id, $user=null)
Load object in memory from database.
info($id)
Information on record.
check()
Check if a miscellaneous payment can be created into database.
__construct(DoliDB $db)
Constructor.
getVentilExportCompta()
Return if a various payment linked to a bank line id was dispatched into bookkeeping.
getLibStatut($mode=0)
Retourne le libelle du statut.
update($user=null, $notrigger=0)
Update database.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.