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;
158 public $fields = array(
171 $this->element =
'payment_various';
172 $this->table_element =
'payment_various';
182 public function update($user =
null, $notrigger = 0)
184 global $conf, $langs;
189 $this->amount = trim($this->amount);
190 $this->label = trim($this->label);
191 $this->note = trim($this->note);
192 $this->fk_bank = (int) $this->fk_bank;
193 $this->fk_user_author = (int) $this->fk_user_author;
194 $this->fk_user_modif = (int) $this->fk_user_modif;
199 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_various SET";
201 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
203 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
204 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
205 $sql .=
" sens=".(int) $this->sens.
",";
206 $sql .=
" amount=".price2num($this->amount).
",";
207 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
208 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
209 $sql .=
" label='".$this->db->escape($this->label).
"',";
210 $sql .=
" note='".$this->db->escape($this->note).
"',";
211 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
212 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
213 $sql .=
" fk_projet='".$this->db->escape($this->fk_project).
"',";
214 $sql .=
" fk_bank=".($this->fk_bank > 0 ? $this->fk_bank :
"null").
",";
215 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
216 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
217 $sql .=
" WHERE rowid=".((int) $this->
id);
219 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
222 $this->error =
"Error ".$this->db->lasterror();
228 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
239 $this->
db->rollback();
252 public function fetch($id, $user =
null)
261 $sql .=
" v.amount,";
262 $sql .=
" v.fk_typepayment,";
263 $sql .=
" v.num_payment,";
266 $sql .=
" v.accountancy_code,";
267 $sql .=
" v.subledger_account,";
268 $sql .=
" v.fk_projet as fk_project,";
269 $sql .=
" v.fk_bank,";
270 $sql .=
" v.fk_user_author,";
271 $sql .=
" v.fk_user_modif,";
272 $sql .=
" b.fk_account,";
273 $sql .=
" b.fk_type,";
275 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
276 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
277 $sql .=
" WHERE v.rowid = ".((int) $id);
279 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
283 $obj = $this->
db->fetch_object(
$resql);
285 $this->
id = $obj->rowid;
286 $this->
ref = $obj->rowid;
287 $this->tms = $this->
db->jdate($obj->tms);
288 $this->datep = $this->
db->jdate($obj->datep);
289 $this->datev = $this->
db->jdate($obj->datev);
290 $this->sens = $obj->sens;
291 $this->amount = $obj->amount;
292 $this->type_payment = $obj->fk_typepayment;
293 $this->num_payment = $obj->num_payment;
294 $this->label = $obj->label;
295 $this->note = $obj->note;
296 $this->subledger_account = $obj->subledger_account;
297 $this->accountancy_code = $obj->accountancy_code;
298 $this->fk_project = $obj->fk_project;
299 $this->fk_bank = $obj->fk_bank;
300 $this->fk_user_author = $obj->fk_user_author;
301 $this->fk_user_modif = $obj->fk_user_modif;
302 $this->fk_account = $obj->fk_account;
303 $this->fk_type = $obj->fk_type;
304 $this->rappro = $obj->rappro;
310 $this->error =
"Error ".$this->db->lasterror();
322 public function delete($user)
324 global $conf, $langs;
329 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
336 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
337 $sql .=
" WHERE rowid=".((int) $this->
id);
339 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
342 $this->error =
"Error ".$this->db->lasterror();
367 $this->accountancy_code =
'';
368 $this->subledger_account =
'';
371 $this->fk_user_author =
'';
372 $this->fk_user_modif =
'';
382 $newamount =
price2num($this->amount,
'MT');
385 if (!($newamount) > 0 || empty($this->datep)) {
400 global $conf, $langs;
406 $this->amount =
price2num(trim($this->amount));
407 $this->label = trim($this->label);
408 $this->note = trim($this->note);
409 $this->fk_bank = (int) $this->fk_bank;
410 $this->fk_user_author = (int) $this->fk_user_author;
411 $this->fk_user_modif = (int) $this->fk_user_modif;
412 $this->fk_account = (int) $this->fk_account;
413 if (empty($this->fk_account) && isset($this->accountid)) {
414 $this->fk_account = $this->accountid;
419 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
422 if ($this->amount < 0 || $this->amount ==
'') {
423 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
426 if (
isModEnabled(
"banque") && (empty($this->fk_account) || $this->fk_account <= 0)) {
427 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
430 if (
isModEnabled(
"banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
431 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
438 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_various (";
443 $sql .=
", fk_typepayment";
444 $sql .=
", num_payment";
449 $sql .=
", accountancy_code";
450 $sql .=
", subledger_account";
451 $sql .=
", fk_projet";
452 $sql .=
", fk_user_author";
458 $sql .=
"'".$this->db->idate($this->datep).
"'";
459 $sql .=
", '".$this->db->idate($this->datev).
"'";
460 $sql .=
", '".$this->db->escape($this->sens).
"'";
461 $sql .=
", ".price2num($this->amount);
462 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
463 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
465 $sql .=
", '".$this->db->escape($this->note).
"'";
467 $sql .=
", '".$this->db->escape($this->label).
"'";
468 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
469 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
470 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
471 $sql .=
", ".((int) $user->id);
472 $sql .=
", '".$this->db->idate($now).
"'";
474 $sql .=
", ".((int) $conf->entity);
477 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
478 $result = $this->
db->query($sql);
480 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
481 $this->
ref = $this->id;
486 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
489 $result = $acc->fetch($this->fk_account);
497 if ($this->sens ==
'0') {
501 $bank_line_id = $acc->addline(
505 $sign * abs($this->amount),
507 ($this->category_transaction > 0 ? $this->category_transaction : 0),
517 if ($bank_line_id > 0) {
520 $this->error = $acc->error;
526 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
528 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
530 $this->error = $acc->error;
536 $this->error = $acc->error;
542 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
555 $this->
db->rollback();
559 $this->error = $this->
db->error();
560 $this->
db->rollback();
575 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.((int) $id_bank);
576 $sql .=
" WHERE rowid = ".((int) $this->
id);
577 $result = $this->
db->query($sql);
595 return $this->
LibStatut($this->statut, $mode);
609 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
620 $statusType =
'status'.$status;
622 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
636 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
638 global $db, $conf, $langs, $hookmanager;
641 if (!empty($conf->dol_no_mouse_hover)) {
647 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
649 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
651 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
653 if ($option !=
'nolink') {
655 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
656 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
657 $add_save_lastsearch_values = 1;
659 if ($add_save_lastsearch_values) {
660 $url .=
'&save_lastsearch_values=1';
665 if (empty($notooltip)) {
666 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
667 $label = $langs->trans(
"ShowMyObject");
668 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
670 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
671 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
673 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
676 $linkstart =
'<a href="'.$url.
'"';
677 $linkstart .= $linkclose.
'>';
680 $result .= $linkstart;
682 $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);
684 if ($withpicto != 2) {
685 $result .= $this->ref;
691 $hookmanager->initHooks(array(
'variouspayment'));
692 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
693 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
695 $result = $hookmanager->resPrint;
697 $result .= $hookmanager->resPrint;
711 $sql =
'SELECT v.rowid, v.datec, v.fk_user_author';
712 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_various as v';
713 $sql .=
' WHERE v.rowid = '.((int) $id);
715 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
716 $result = $this->
db->query($sql);
719 if ($this->
db->num_rows($result)) {
720 $obj = $this->
db->fetch_object($result);
721 $this->
id = $obj->rowid;
722 if ($obj->fk_user_author) {
723 $cuser =
new User($this->
db);
724 $cuser->fetch($obj->fk_user_author);
725 $this->user_creation = $cuser;
727 $this->date_creation = $this->
db->jdate($obj->datec);
728 if ($obj->fk_user_modif) {
729 $muser =
new User($this->
db);
730 $muser->fetch($obj->fk_user_modif);
731 $this->user_modif = $muser;
733 $this->date_modif = $this->
db->jdate($obj->tms);
735 $this->
db->free($result);
748 $banklineid = $this->fk_bank;
750 $alreadydispatched = 0;
754 $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);
757 $obj = $this->
db->fetch_object(
$resql);
759 $alreadydispatched = $obj->nb;
762 $this->error = $this->
db->lasterror();
766 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.
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.