26require_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(
202 public function update($user =
null, $notrigger = 0)
204 global $conf, $langs;
209 $this->amount = trim($this->amount);
210 $this->label = trim($this->label);
211 $this->note = trim($this->note);
212 $this->fk_bank = (int) $this->fk_bank;
213 $this->fk_user_author = (int) $this->fk_user_author;
214 $this->fk_user_modif = (int) $this->fk_user_modif;
219 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_various SET";
221 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
223 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
224 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
225 $sql .=
" sens=".(int) $this->sens.
",";
226 $sql .=
" amount=".price2num($this->amount).
",";
227 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
228 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
229 $sql .=
" label='".$this->db->escape($this->label).
"',";
230 $sql .=
" note='".$this->db->escape($this->note).
"',";
231 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
232 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
233 $sql .=
" fk_projet='".$this->db->escape($this->fk_project).
"',";
234 $sql .=
" fk_bank=".($this->fk_bank > 0 ? $this->fk_bank :
"null").
",";
235 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
236 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
237 $sql .=
" WHERE rowid=".((int) $this->
id);
239 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
240 $resql = $this->db->query($sql);
242 $this->error =
"Error ".$this->db->lasterror();
248 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
259 $this->db->rollback();
272 public function fetch($id, $user =
null)
280 $sql .=
" v.amount,";
281 $sql .=
" v.fk_typepayment,";
282 $sql .=
" v.num_payment,";
284 $sql .=
" v.note as note_private,";
285 $sql .=
" v.accountancy_code,";
286 $sql .=
" v.subledger_account,";
287 $sql .=
" v.fk_projet as fk_project,";
288 $sql .=
" v.fk_bank,";
289 $sql .=
" v.fk_user_author,";
290 $sql .=
" v.fk_user_modif,";
291 $sql .=
" b.fk_account,";
292 $sql .=
" b.fk_type,";
293 $sql .=
" b.rappro,";
294 $sql .=
" b.num_releve as bank_num_releve";
295 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
296 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
297 $sql .=
" WHERE v.rowid = ".((int) $id);
299 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
300 $resql = $this->db->query($sql);
302 if ($this->db->num_rows($resql)) {
303 $obj = $this->db->fetch_object($resql);
305 $this->
id = $obj->rowid;
306 $this->
ref = $obj->rowid;
307 $this->tms = $this->db->jdate($obj->tms);
308 $this->datep = $this->db->jdate($obj->datep);
309 $this->datev = $this->db->jdate($obj->datev);
310 $this->sens = $obj->sens;
311 $this->amount = $obj->amount;
312 $this->type_payment = $obj->fk_typepayment;
313 $this->num_payment = $obj->num_payment;
314 $this->label = $obj->label;
315 $this->note = $obj->note_private;
316 $this->note_private = $obj->note_private;
317 $this->subledger_account = $obj->subledger_account;
318 $this->accountancy_code = $obj->accountancy_code;
319 $this->fk_project = $obj->fk_project;
320 $this->fk_bank = $obj->fk_bank;
321 $this->fk_user_author = $obj->fk_user_author;
322 $this->fk_user_modif = $obj->fk_user_modif;
323 $this->fk_account = $obj->fk_account;
324 $this->fk_type = $obj->fk_type;
325 $this->rappro = $obj->rappro;
326 $this->bank_num_releve = $obj->bank_num_releve;
328 $this->db->free($resql);
332 $this->error =
"Error ".$this->db->lasterror();
344 public function delete($user)
346 global $conf, $langs;
351 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
358 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
359 $sql .=
" WHERE rowid=".((int) $this->
id);
361 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
362 $resql = $this->db->query($sql);
364 $this->error =
"Error ".$this->db->lasterror();
389 $this->accountancy_code =
'';
390 $this->subledger_account =
'';
393 $this->fk_user_author =
'';
394 $this->fk_user_modif =
'';
404 $newamount =
price2num($this->amount,
'MT');
407 if (!($newamount) > 0 || empty($this->datep)) {
422 global $conf, $langs;
428 $this->amount =
price2num(trim($this->amount));
429 $this->label = trim($this->label);
430 $this->note = trim($this->note);
431 $this->fk_bank = (int) $this->fk_bank;
432 $this->fk_user_author = (int) $this->fk_user_author;
433 $this->fk_user_modif = (int) $this->fk_user_modif;
434 $this->fk_account = (int) $this->fk_account;
435 if (empty($this->fk_account) && isset($this->accountid)) {
436 $this->fk_account = $this->accountid;
441 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
444 if ($this->amount < 0 || $this->amount ==
'') {
445 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
448 if (isModEnabled(
"banque") && (empty($this->fk_account) || $this->fk_account <= 0)) {
449 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
452 if (isModEnabled(
"banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
453 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
460 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_various (";
465 $sql .=
", fk_typepayment";
466 $sql .=
", num_payment";
471 $sql .=
", accountancy_code";
472 $sql .=
", subledger_account";
473 $sql .=
", fk_projet";
474 $sql .=
", fk_user_author";
480 $sql .=
"'".$this->db->idate($this->datep).
"'";
481 $sql .=
", '".$this->db->idate($this->datev).
"'";
482 $sql .=
", '".$this->db->escape($this->sens).
"'";
483 $sql .=
", ".price2num($this->amount);
484 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
485 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
487 $sql .=
", '".$this->db->escape($this->note).
"'";
489 $sql .=
", '".$this->db->escape($this->label).
"'";
490 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
491 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
492 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
493 $sql .=
", ".((int) $user->id);
494 $sql .=
", '".$this->db->idate($now).
"'";
496 $sql .=
", ".((int) $conf->entity);
499 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
500 $result = $this->db->query($sql);
502 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
503 $this->
ref = $this->id;
506 if (isModEnabled(
"banque") && !empty($this->amount)) {
508 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
511 $result = $acc->fetch($this->fk_account);
519 if ($this->sens ==
'0') {
523 $bank_line_id = $acc->addline(
527 $sign * abs($this->amount),
529 ($this->category_transaction > 0 ? $this->category_transaction : 0),
539 if ($bank_line_id > 0) {
542 $this->error = $acc->error;
548 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
550 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
552 $this->error = $acc->error;
558 $this->error = $acc->error;
564 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
577 $this->db->rollback();
581 $this->error = $this->db->error();
582 $this->db->rollback();
597 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.((int) $id_bank);
598 $sql .=
" WHERE rowid = ".((int) $this->
id);
599 $result = $this->db->query($sql);
665 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
667 global $db, $conf, $langs, $hookmanager;
670 if (!empty($conf->dol_no_mouse_hover)) {
676 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
678 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
680 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
682 if ($option !=
'nolink') {
684 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
685 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
686 $add_save_lastsearch_values = 1;
688 if ($add_save_lastsearch_values) {
689 $url .=
'&save_lastsearch_values=1';
694 if (empty($notooltip)) {
696 $label = $langs->trans(
"ShowMyObject");
697 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
699 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
700 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
702 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
705 $linkstart =
'<a href="'.$url.
'"';
706 $linkstart .= $linkclose.
'>';
709 $result .= $linkstart;
711 $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);
713 if ($withpicto != 2) {
714 $result .= $this->ref;
720 $hookmanager->initHooks(array(
'variouspayment'));
721 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
722 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
724 $result = $hookmanager->resPrint;
726 $result .= $hookmanager->resPrint;
740 $sql =
'SELECT v.rowid, v.datec, v.fk_user_author';
741 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_various as v';
742 $sql .=
' WHERE v.rowid = '.((int) $id);
744 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
745 $result = $this->db->query($sql);
748 if ($this->db->num_rows($result)) {
749 $obj = $this->db->fetch_object($result);
751 $this->
id = $obj->rowid;
752 $this->user_creation = $obj->fk_user_author;
753 $this->user_modification_id = $obj->fk_user_modif;
754 $this->date_creation = $this->db->jdate($obj->datec);
755 $this->date_modification = $this->db->jdate($obj->tms);
757 $this->db->free($result);
770 $banklineid = $this->fk_bank;
772 $alreadydispatched = 0;
776 $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);
777 $resql = $this->db->query($sql);
779 $obj = $this->db->fetch_object($resql);
781 $alreadydispatched = $obj->nb;
784 $this->error = $this->db->lasterror();
788 if ($alreadydispatched) {
805 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
807 $return =
'<div class="box-flex-item box-flex-grow-zero">';
808 $return .=
'<div class="info-box info-box-sm">';
809 $return .=
'<span class="info-box-icon bg-infobox-action">';
811 $return .=
'</span>';
812 $return .=
'<div class="info-box-content">';
813 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
814 if ($selected >= 0) {
815 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
817 if (property_exists($this,
'fk_bank')) {
818 $return .=
' | <span class="info-box-status ">'.$this->fk_bank.
'</span>';
820 if (property_exists($this,
'datep')) {
821 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datep),
'day').
'</span>';
823 if (property_exists($this,
'type_payment') && !empty($this->type_payment)) {
824 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Payment", $this->type_payment).
'</span> : <span class="info-box-label">'.$this->type_payment.
'</span>';
826 if (property_exists($this,
'accountancy_code')) {
827 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label" title="'.$this->accountancy_code.
'">'.$this->accountancy_code.
'</span>';
829 if (property_exists($this,
'amount')) {
830 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Debit").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
846 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
865 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
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.
lengthAccountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
LibStatut($status, $mode=0)
Return the label of a given status.
fetch($id, $user=null)
Load object in memory from database.
info($id)
Information on record.
lengthAccounta($account)
Return Auxiliary accounting account of thirdparties with defined length.
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)
Return the label of the status.
update($user=null, $notrigger=0)
Update database.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
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)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut