27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'payment_various';
43 public $table_element =
'payment_various';
48 public $picto =
'payment';
104 public $category_transaction;
114 public $accountancy_code;
119 public $subledger_account;
145 public $categorie_transaction;
150 public $fk_user_author;
155 public $fk_user_modif;
171 public $bank_num_releve;
203 public $fields = array(
231 public function update($user =
null, $notrigger = 0)
233 global
$conf, $langs;
238 $this->amount = (float)
price2num($this->amount);
239 $this->label = trim($this->label);
240 $this->note = trim($this->note);
241 $this->fk_bank = (int) $this->fk_bank;
242 $this->fk_user_author = (int) $this->fk_user_author;
243 $this->fk_user_modif = (int) $this->fk_user_modif;
248 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_various SET";
250 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
252 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
253 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
254 $sql .=
" sens=".(int) $this->sens.
",";
255 $sql .=
" amount=".price2num($this->amount).
",";
256 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
257 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
258 $sql .=
" label='".$this->db->escape($this->label).
"',";
259 $sql .=
" note='".$this->db->escape($this->note).
"',";
260 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
261 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
262 $sql .=
" fk_projet='".$this->db->escape((
string) $this->fk_project).
"',";
263 $sql .=
" fk_bank=".($this->fk_bank > 0 ? $this->fk_bank :
"null").
",";
264 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
265 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
266 $sql .=
" WHERE rowid=".((int) $this->
id);
268 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
269 $resql = $this->db->query($sql);
271 $this->error =
"Error ".$this->db->lasterror();
277 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
288 $this->db->rollback();
301 public function fetch($id, $user =
null)
309 $sql .=
" v.amount,";
310 $sql .=
" v.fk_typepayment,";
311 $sql .=
" v.num_payment,";
313 $sql .=
" v.note as note_private,";
314 $sql .=
" v.accountancy_code,";
315 $sql .=
" v.subledger_account,";
316 $sql .=
" v.fk_projet as fk_project,";
317 $sql .=
" v.fk_bank,";
318 $sql .=
" v.fk_user_author,";
319 $sql .=
" v.fk_user_modif,";
320 $sql .=
" b.fk_account,";
321 $sql .=
" b.fk_type,";
322 $sql .=
" b.rappro,";
323 $sql .=
" b.num_releve as bank_num_releve";
324 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
325 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
326 $sql .=
" WHERE v.rowid = ".((int) $id);
328 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
329 $resql = $this->db->query($sql);
331 if ($this->db->num_rows($resql)) {
332 $obj = $this->db->fetch_object($resql);
334 $this->
id = $obj->rowid;
335 $this->
ref = $obj->rowid;
336 $this->tms = $this->db->jdate($obj->tms);
337 $this->datep = $this->db->jdate($obj->datep);
338 $this->datev = $this->db->jdate($obj->datev);
339 $this->sens = $obj->sens;
340 $this->amount = $obj->amount;
341 $this->type_payment = $obj->fk_typepayment;
342 $this->num_payment = $obj->num_payment;
343 $this->label = $obj->label;
344 $this->note = $obj->note_private;
345 $this->note_private = $obj->note_private;
346 $this->subledger_account = $obj->subledger_account;
347 $this->accountancy_code = $obj->accountancy_code;
348 $this->fk_project = $obj->fk_project;
349 $this->fk_bank = $obj->fk_bank;
350 $this->fk_user_author = $obj->fk_user_author;
351 $this->fk_user_modif = $obj->fk_user_modif;
352 $this->fk_account = $obj->fk_account;
353 $this->fk_type = $obj->fk_type;
354 $this->rappro = $obj->rappro;
355 $this->bank_num_releve = $obj->bank_num_releve;
357 $this->db->free($resql);
361 $this->error =
"Error ".$this->db->lasterror();
373 public function delete($user)
375 global
$conf, $langs;
380 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
387 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
388 $sql .=
" WHERE rowid=".((int) $this->
id);
390 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
391 $resql = $this->db->query($sql);
393 $this->error =
"Error ".$this->db->lasterror();
416 $this->label =
'Specimen payment';
417 $this->accountancy_code =
'';
418 $this->subledger_account =
'';
421 $this->fk_user_author = 0;
422 $this->fk_user_modif = 0;
434 $newamount =
price2num($this->amount,
'MT');
437 if (!($newamount) > 0 || empty($this->datep)) {
452 global
$conf, $langs;
458 $this->amount = (float)
price2num($this->amount);
459 $this->label = trim($this->label);
460 $this->note = trim($this->note);
461 $this->fk_bank = (int) $this->fk_bank;
462 $this->fk_user_author = (int) $this->fk_user_author;
463 $this->fk_user_modif = (int) $this->fk_user_modif;
464 $this->fk_account = (int) $this->fk_account;
465 if (empty($this->fk_account) && isset($this->accountid)) {
466 $this->fk_account = $this->accountid;
471 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
474 if ($this->amount < 0 || $this->amount ==
'') {
475 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
478 if (isModEnabled(
"bank") && (empty($this->fk_account) || $this->fk_account <= 0)) {
479 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
482 if (isModEnabled(
"bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
483 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
490 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_various (";
495 $sql .=
", fk_typepayment";
496 $sql .=
", num_payment";
501 $sql .=
", accountancy_code";
502 $sql .=
", subledger_account";
503 $sql .=
", fk_projet";
504 $sql .=
", fk_user_author";
510 $sql .=
"'".$this->db->idate($this->datep).
"'";
511 $sql .=
", '".$this->db->idate($this->datev).
"'";
512 $sql .=
", '".$this->db->escape((
string) $this->sens).
"'";
513 $sql .=
", ".price2num($this->amount);
514 $sql .=
", '".$this->db->escape((
string) $this->type_payment).
"'";
515 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
517 $sql .=
", '".$this->db->escape($this->note).
"'";
519 $sql .=
", '".$this->db->escape($this->label).
"'";
520 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
521 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
522 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
523 $sql .=
", ".((int) $user->id);
524 $sql .=
", '".$this->db->idate($now).
"'";
526 $sql .=
", ".((int)
$conf->entity);
529 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
530 $result = $this->db->query($sql);
532 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
533 $this->
ref = (string) $this->
id;
536 if (isModEnabled(
"bank") && !empty($this->amount)) {
538 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
541 $result = $acc->fetch($this->fk_account);
549 if ($this->sens ==
'0') {
553 $bank_line_id = $acc->addline(
555 (
string) $this->type_payment,
557 $sign * abs($this->amount),
559 ($this->category_transaction > 0 ? $this->category_transaction : 0),
569 if ($bank_line_id > 0) {
572 $this->error = $acc->error;
578 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
580 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
582 $this->error = $acc->error;
588 $this->error = $acc->error;
595 $result = $this->
call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
609 $this->db->rollback();
613 $this->error = $this->db->error();
614 $this->db->rollback();
629 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.((int) $id_bank);
630 $sql .=
" WHERE rowid = ".((int) $this->
id);
631 $result = $this->db->query($sql);
635 $this->fk_bank = (int) $id_bank;
652 return $this->
LibStatut($this->statut, $mode);
700 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
702 global $db,
$conf, $langs, $hookmanager;
705 if (!empty(
$conf->dol_no_mouse_hover)) {
711 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
713 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
715 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
717 if ($option !=
'nolink') {
719 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
720 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
721 $add_save_lastsearch_values = 1;
723 if ($add_save_lastsearch_values) {
724 $url .=
'&save_lastsearch_values=1';
729 if (empty($notooltip)) {
731 $label = $langs->trans(
"ShowMyObject");
732 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
734 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
735 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
737 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
740 $linkstart =
'<a href="'.$url.
'"';
741 $linkstart .= $linkclose.
'>';
744 $result .= $linkstart;
746 $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);
748 if ($withpicto != 2) {
749 $result .= $this->ref;
755 $hookmanager->initHooks(array(
'variouspayment'));
756 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
757 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
759 $result = $hookmanager->resPrint;
761 $result .= $hookmanager->resPrint;
775 $sql =
'SELECT v.rowid, v.datec, v.fk_user_author, fk_user_modif, tms';
776 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_various as v';
777 $sql .=
' WHERE v.rowid = '.((int) $id);
779 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
780 $result = $this->db->query($sql);
783 if ($this->db->num_rows($result)) {
784 $obj = $this->db->fetch_object($result);
786 $this->
id = $obj->rowid;
787 $this->user_creation = $obj->fk_user_author;
788 $this->user_creation_id = $obj->fk_user_author;
789 $this->user_modification_id = $obj->fk_user_modif;
790 $this->date_creation = $this->db->jdate($obj->datec);
791 $this->date_modification = $this->db->jdate($obj->tms);
793 $this->db->free($result);
807 $banklineid = $this->fk_bank;
809 $alreadydispatched = 0;
813 $sql =
" SELECT ".($mode ?
'DISTINCT piece_num' :
'COUNT(ab.rowid)').
" as nb";
814 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type = '".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $banklineid);
815 $resql = $this->db->query($sql);
817 $obj = $this->db->fetch_object($resql);
819 $alreadydispatched = $obj->nb;
822 $this->error = $this->db->lasterror();
826 if ($alreadydispatched) {
827 return $alreadydispatched;
843 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
844 $bankline = ((empty($arraydata[
'bankline']) || empty($arraydata[
'bankline']->
id)) ? 0 : $arraydata[
'bankline']);
845 $formatedaccountancycode = (empty($arraydata[
'formatedaccountancycode']) ?
'' : $arraydata[
'formatedaccountancycode']);
847 $return =
'<div class="box-flex-item box-flex-grow-zero">';
848 $return .=
'<div class="info-box info-box-sm">';
849 $return .=
'<span class="info-box-icon bg-infobox-action">';
851 $return .=
'</span>';
852 $return .=
'<div class="info-box-content">';
853 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
854 if ($selected >= 0) {
855 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
857 if (!empty($bankline) && $bankline instanceof
AccountLine) {
858 $return .=
' | <span class="info-box-status ">'.$bankline->getNomUrl(1).
'</span>';
860 if (property_exists($this,
'datep')) {
861 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datep),
'day').
'</span>';
862 if ($this->type_payment) {
863 $return .=
' - <span class="info-box-label">'.$this->type_payment.
'</span>';
866 if (!empty($formatedaccountancycode)) {
867 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label" title="'.$this->accountancy_code.
'">';
868 $return .= $formatedaccountancycode;
869 $return .=
'</span>';
870 } elseif (property_exists($this,
'accountancy_code')) {
871 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label" title="'.$this->accountancy_code.
'">'.$this->accountancy_code.
'</span>';
874 if (property_exists($this,
'amount')) {
875 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Debit").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
891 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
910 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.
Class to manage bank transaction lines.
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 clickable (with possibly the picto)
initAsSpecimen()
Initialise an instance with random values.
getVentilExportCompta($mode=0)
Return if a various payment linked to a bank line id was dispatched into bookkeeping.
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.
getLibStatut($mode=0)
Return the label of the status.
update($user=null, $notrigger=0)
Update database.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...