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);
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";
200 if ($this->tms) $sql .=
" tms='".$this->db->idate($this->tms).
"',";
201 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
202 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
203 $sql .=
" sens=".(int) $this->sens.
",";
204 $sql .=
" amount=".price2num($this->amount).
",";
205 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
206 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
207 $sql .=
" label='".$this->db->escape($this->label).
"',";
208 $sql .=
" note='".$this->db->escape($this->
note).
"',";
209 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
210 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
211 $sql .=
" fk_projet='".$this->db->escape($this->fk_project).
"',";
212 $sql .=
" fk_bank=".($this->fk_bank > 0 ? $this->fk_bank :
"null").
",";
213 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
214 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
215 $sql .=
" WHERE rowid=".$this->id;
217 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
220 $this->error =
"Error ".$this->db->lasterror();
226 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
227 if ($result < 0) $error++;
235 $this->
db->rollback();
248 public function fetch($id, $user = null)
257 $sql .=
" v.amount,";
258 $sql .=
" v.fk_typepayment,";
259 $sql .=
" v.num_payment,";
262 $sql .=
" v.accountancy_code,";
263 $sql .=
" v.subledger_account,";
264 $sql .=
" v.fk_projet as fk_project,";
265 $sql .=
" v.fk_bank,";
266 $sql .=
" v.fk_user_author,";
267 $sql .=
" v.fk_user_modif,";
268 $sql .=
" b.fk_account,";
269 $sql .=
" b.fk_type,";
271 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
272 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
273 $sql .=
" WHERE v.rowid = ".$id;
275 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
281 $obj = $this->
db->fetch_object(
$resql);
283 $this->
id = $obj->rowid;
284 $this->ref = $obj->rowid;
285 $this->tms = $this->
db->jdate($obj->tms);
286 $this->datep = $this->
db->jdate($obj->datep);
287 $this->datev = $this->
db->jdate($obj->datev);
288 $this->sens = $obj->sens;
289 $this->amount = $obj->amount;
290 $this->type_payment = $obj->fk_typepayment;
291 $this->num_payment = $obj->num_payment;
292 $this->label = $obj->label;
293 $this->
note = $obj->note;
294 $this->subledger_account = $obj->subledger_account;
295 $this->accountancy_code = $obj->accountancy_code;
296 $this->fk_project = $obj->fk_project;
297 $this->fk_bank = $obj->fk_bank;
298 $this->fk_user_author = $obj->fk_user_author;
299 $this->fk_user_modif = $obj->fk_user_modif;
300 $this->fk_account = $obj->fk_account;
301 $this->fk_type = $obj->fk_type;
302 $this->rappro = $obj->rappro;
308 $this->error =
"Error ".$this->db->lasterror();
320 public function delete($user)
322 global $conf, $langs;
327 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
328 if ($result < 0)
return -1;
332 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
333 $sql .=
" WHERE rowid=".$this->id;
335 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
338 $this->error =
"Error ".$this->db->lasterror();
363 $this->accountancy_code =
'';
364 $this->subledger_account =
'';
367 $this->fk_user_author =
'';
368 $this->fk_user_modif =
'';
378 $newamount =
price2num($this->amount,
'MT');
381 if (!($newamount) > 0 || empty($this->datep)) {
396 global $conf, $langs;
402 $this->amount =
price2num(trim($this->amount));
403 $this->label = trim($this->label);
405 $this->fk_bank = (int) $this->fk_bank;
406 $this->fk_user_author = (int) $this->fk_user_author;
407 $this->fk_user_modif = (int) $this->fk_user_modif;
408 $this->fk_account = (int) $this->fk_account;
409 if (empty($this->fk_account) && isset($this->accountid)) {
410 $this->fk_account = $this->accountid;
416 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
419 if ($this->amount < 0 || $this->amount ==
'')
421 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
424 if (!empty($conf->banque->enabled) && (empty($this->fk_account) || $this->fk_account <= 0))
426 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
429 if (!empty($conf->banque->enabled) && (empty($this->type_payment)))
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";
445 if ($this->
note) $sql .=
", note";
447 $sql .=
", accountancy_code";
448 $sql .=
", subledger_account";
449 $sql .=
", fk_projet";
450 $sql .=
", fk_user_author";
456 $sql .=
"'".$this->db->idate($this->datep).
"'";
457 $sql .=
", '".$this->db->idate($this->datev).
"'";
458 $sql .=
", '".$this->db->escape($this->sens).
"'";
459 $sql .=
", ".price2num($this->amount);
460 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
461 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
462 if ($this->
note) $sql .=
", '".$this->db->escape($this->
note).
"'";
463 $sql .=
", '".$this->db->escape($this->label).
"'";
464 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
465 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
466 $sql .=
", ".($this->fk_project > 0 ? $this->fk_project : 0);
467 $sql .=
", ".$user->id;
468 $sql .=
", '".$this->db->idate($now).
"'";
470 $sql .=
", ".$conf->entity;
473 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
474 $result = $this->
db->query($sql);
477 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
478 $this->ref = $this->id;
482 if (!empty($conf->banque->enabled) && !empty($this->amount))
485 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
488 $result = $acc->fetch($this->fk_account);
494 if ($this->sens ==
'0') $sign = -1;
496 $bank_line_id = $acc->addline(
500 $sign * abs($this->amount),
502 ($this->category_transaction > 0 ? $this->category_transaction : 0),
512 if ($bank_line_id > 0) {
515 $this->error = $acc->error;
522 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
524 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
527 $this->error = $acc->error;
534 $this->error = $acc->error;
540 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
541 if ($result < 0) $error++;
550 $this->
db->rollback();
554 $this->error = $this->
db->error();
555 $this->
db->rollback();
570 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.$id_bank;
571 $sql .=
' WHERE rowid = '.$this->id;
572 $result = $this->
db->query($sql);
608 return $langs->trans($this->statuts[$status]);
609 } elseif ($mode == 1) {
610 return $langs->trans($this->statuts_short[$status]);
611 } elseif ($mode == 2) {
612 if ($status == 0)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts_short[$status]);
613 elseif ($status == 1)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts_short[$status]);
614 elseif ($status == 2)
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts_short[$status]);
615 } elseif ($mode == 3) {
616 if ($status == 0 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
617 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
618 elseif ($status == 2 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
619 } elseif ($mode == 4) {
620 if ($status == 0 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
621 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut4').
' '.$langs->trans($this->statuts[$status]);
622 elseif ($status == 2 && !empty($this->statuts_short[$status]))
return img_picto($langs->trans($this->statuts_short[$status]),
'statut6').
' '.$langs->trans($this->statuts[$status]);
623 } elseif ($mode == 5) {
624 if ($status == 0 && !empty($this->statuts_short[$status]))
return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut0');
625 elseif ($status == 1 && !empty($this->statuts_short[$status]))
return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut4');
626 elseif ($status == 2 && !empty($this->statuts_short[$status]))
return $langs->trans($this->statuts_short[$status]).
' '.
img_picto($langs->trans($this->statuts_short[$status]),
'statut6');
641 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
643 global $db, $conf, $langs, $hookmanager;
646 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
650 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
652 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
654 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
656 if ($option !=
'nolink')
659 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
660 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
661 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
665 if (empty($notooltip))
667 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
669 $label = $langs->trans(
"ShowMyObject");
670 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
672 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
673 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
681 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
683 $linkstart =
'<a href="'.$url.
'"';
684 $linkstart .= $linkclose.
'>';
687 $result .= $linkstart;
688 if ($withpicto) $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);
689 if ($withpicto != 2) $result .= $this->ref;
694 $hookmanager->initHooks(array(
'variouspayment'));
695 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
696 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
697 if ($reshook > 0) $result = $hookmanager->resPrint;
698 else $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 = '.$id;
715 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
716 $result = $this->
db->query($sql);
720 if ($this->
db->num_rows($result))
722 $obj = $this->
db->fetch_object($result);
723 $this->
id = $obj->rowid;
724 if ($obj->fk_user_author)
726 $cuser =
new User($this->
db);
727 $cuser->fetch($obj->fk_user_author);
728 $this->user_creation = $cuser;
730 $this->date_creation = $this->
db->jdate($obj->datec);
731 if ($obj->fk_user_modif)
733 $muser =
new User($this->
db);
734 $muser->fetch($obj->fk_user_modif);
735 $this->user_modif = $muser;
737 $this->date_modif = $this->
db->jdate($obj->tms);
739 $this->
db->free($result);
752 $banklineid = $this->fk_bank;
754 $alreadydispatched = 0;
758 $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 = ".$banklineid;
762 $obj = $this->
db->fetch_object(
$resql);
765 $alreadydispatched = $obj->nb;
768 $this->error = $this->
db->lasterror();
772 if ($alreadydispatched)
__construct($db)
Constructor.
Class to manage various payments.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
dol_now($mode= 'auto')
Return date for now.
fetch($id, $user=null)
Load object in memory from database.
Class to manage Dolibarr users.
update_fk_bank($id_bank)
Update link between payment various and line generate into llx_bank.
$conf db
API class for accounts.
Class to manage bank accounts.
getVentilExportCompta()
Return if a various payment linked to a bank line id was dispatched into bookkeeping.
check()
Check if a miscellaneous payment can be created into database.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
initAsSpecimen()
Initialise an instance with random values.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print $_SERVER["PHP_SELF"]
Edit parameters.
info($id)
Information on record.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
call_trigger($triggerName, $user)
Call trigger based on this instance.
getNomUrl($withpicto=0, $option= '', $save_lastsearch_value=-1, $notooltip=0, $morecss= '')
Send name clicable (with possibly the picto)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getLibStatut($mode=0)
Retourne le libelle du statut.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
create($user)
Create in database.
update($user=null, $notrigger=0)
Update database.