28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'payment_various';
44 public $table_element =
'payment_various';
49 public $picto =
'payment';
105 public $category_transaction;
115 public $accountancy_code;
120 public $subledger_account;
151 public $categorie_transaction;
156 public $fk_user_author;
161 public $fk_user_modif;
177 public $bank_num_releve;
209 public $fields = array(
237 public function update($user =
null, $notrigger = 0)
239 global
$conf, $langs;
245 $this->label = trim($this->label);
246 $this->note = trim($this->note);
247 $this->fk_bank = (int) $this->fk_bank;
248 $this->fk_user_author = (int) $this->fk_user_author;
249 $this->fk_user_modif = (int) $this->fk_user_modif;
254 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_various SET";
256 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
258 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
259 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
260 $sql .=
" sens=".(int) $this->sens.
",";
261 $sql .=
" amount=".price2num($this->
amount).
",";
262 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
263 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
264 $sql .=
" label='".$this->db->escape($this->label).
"',";
265 $sql .=
" note='".$this->db->escape($this->note).
"',";
266 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
267 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
268 $sql .=
" fk_projet='".$this->db->escape((
string) $this->fk_project).
"',";
269 $sql .=
" fk_bank=".($this->fk_bank > 0 ? ((int) $this->fk_bank) :
"null").
",";
270 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
271 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
272 $sql .=
" WHERE rowid=".((int) $this->
id);
274 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
275 $resql = $this->db->query($sql);
277 $this->error =
"Error ".$this->db->lasterror();
287 if (!$error && !$notrigger) {
289 $result = $this->call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
300 $this->db->rollback();
313 public function fetch($id, $user =
null)
321 $sql .=
" v.amount,";
322 $sql .=
" v.fk_typepayment,";
323 $sql .=
" v.num_payment,";
325 $sql .=
" v.note as note_private,";
326 $sql .=
" v.accountancy_code,";
327 $sql .=
" v.subledger_account,";
328 $sql .=
" v.fk_projet as fk_project,";
329 $sql .=
" v.fk_bank,";
330 $sql .=
" v.fk_user_author,";
331 $sql .=
" v.fk_user_modif,";
332 $sql .=
" b.fk_account,";
333 $sql .=
" b.fk_type,";
334 $sql .=
" b.rappro,";
335 $sql .=
" b.num_releve as bank_num_releve";
336 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
337 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
338 $sql .=
" WHERE v.rowid = ".((int) $id);
340 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
341 $resql = $this->db->query($sql);
343 if ($this->db->num_rows($resql)) {
344 $obj = $this->db->fetch_object($resql);
346 $this->
id = $obj->rowid;
347 $this->
ref = $obj->rowid;
348 $this->tms = $this->db->jdate($obj->tms);
349 $this->datep = $this->db->jdate($obj->datep);
350 $this->datev = $this->db->jdate($obj->datev);
351 $this->sens = $obj->sens;
352 $this->
amount = $obj->amount;
353 $this->type_payment = $obj->fk_typepayment;
354 $this->num_payment = $obj->num_payment;
355 $this->label = $obj->label;
356 $this->note = $obj->note_private;
357 $this->note_private = $obj->note_private;
358 $this->subledger_account = $obj->subledger_account;
359 $this->accountancy_code = $obj->accountancy_code;
360 $this->fk_project = $obj->fk_project;
361 $this->fk_bank = $obj->fk_bank;
362 $this->fk_user_author = $obj->fk_user_author;
363 $this->fk_user_modif = $obj->fk_user_modif;
364 $this->fk_account = $obj->fk_account;
365 $this->fk_type = $obj->fk_type;
366 $this->rappro = $obj->rappro;
367 $this->bank_num_releve = $obj->bank_num_releve;
373 $this->db->free($resql);
377 $this->error =
"Error ".$this->db->lasterror();
389 public function delete($user)
391 global
$conf, $langs;
396 $result = $this->call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
403 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
404 $sql .=
" WHERE rowid=".((int) $this->
id);
406 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
407 $resql = $this->db->query($sql);
409 $this->error =
"Error ".$this->db->lasterror();
432 $this->label =
'Specimen payment';
433 $this->accountancy_code =
'';
434 $this->subledger_account =
'';
437 $this->fk_user_author = 0;
438 $this->fk_user_modif = 0;
453 if (!($newamount) > 0 || empty($this->datep)) {
468 global
$conf, $langs;
475 $this->label = trim($this->label);
476 $this->note = trim($this->note);
477 $this->fk_bank = (int) $this->fk_bank;
478 $this->fk_user_author = (int) $this->fk_user_author;
479 $this->fk_user_modif = (int) $this->fk_user_modif;
480 $this->fk_account = (int) $this->fk_account;
481 if (empty($this->fk_account) && isset($this->accountid)) {
482 $this->fk_account = $this->accountid;
487 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
491 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
494 if (
isModEnabled(
"bank") && (empty($this->fk_account) || $this->fk_account <= 0)) {
495 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
498 if (
isModEnabled(
"bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
499 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
506 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_various (";
511 $sql .=
", fk_typepayment";
512 $sql .=
", num_payment";
517 $sql .=
", accountancy_code";
518 $sql .=
", subledger_account";
519 $sql .=
", fk_projet";
520 $sql .=
", fk_user_author";
526 $sql .=
"'".$this->db->idate($this->datep).
"'";
527 $sql .=
", '".$this->db->idate($this->datev).
"'";
528 $sql .=
", '".$this->db->escape((
string) $this->sens).
"'";
529 $sql .=
", ".price2num($this->
amount);
530 $sql .=
", '".$this->db->escape((
string) $this->type_payment).
"'";
531 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
533 $sql .=
", '".$this->db->escape($this->note).
"'";
535 $sql .=
", '".$this->db->escape($this->label).
"'";
536 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
537 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
538 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
539 $sql .=
", ".((int) $user->id);
540 $sql .=
", '".$this->db->idate($now).
"'";
542 $sql .=
", ".((int)
$conf->entity);
545 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
546 $result = $this->db->query($sql);
548 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
549 $this->
ref = (string) $this->
id;
560 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
563 $result = $acc->fetch($this->fk_account);
565 dol_print_error($this->db);
571 if ($this->sens ==
'0') {
575 $bank_line_id = $acc->addline(
577 (
string) $this->type_payment,
579 $sign * abs($this->
amount),
581 ($this->category_transaction > 0 ? $this->category_transaction : 0),
591 if ($bank_line_id > 0) {
594 $this->error = $acc->error;
600 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
602 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
604 $this->error = $acc->error;
610 $this->error = $acc->error;
616 $result = $this->call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
629 $this->db->rollback();
633 $this->error = $this->db->error();
634 $this->db->rollback();
649 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.((int) $id_bank);
650 $sql .=
" WHERE rowid = ".((int) $this->
id);
651 $result = $this->db->query($sql);
655 $this->fk_bank = (int) $id_bank;
658 dol_print_error($this->db);
720 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
722 global $db,
$conf, $langs, $hookmanager;
725 if (!empty(
$conf->dol_no_mouse_hover)) {
731 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
733 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
735 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
737 if ($option !=
'nolink') {
739 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
740 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
741 $add_save_lastsearch_values = 1;
743 if ($add_save_lastsearch_values) {
744 $url .=
'&save_lastsearch_values=1';
749 if (empty($notooltip)) {
751 $label = $langs->trans(
"ShowMyObject");
752 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
754 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
755 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
757 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
760 $linkstart =
'<a href="'.$url.
'"';
761 $linkstart .= $linkclose.
'>';
764 $result .= $linkstart;
766 $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);
768 if ($withpicto != 2) {
769 $result .= $this->ref;
775 $hookmanager->initHooks(array(
'variouspayment'));
776 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
777 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
779 $result = $hookmanager->resPrint;
781 $result .= $hookmanager->resPrint;
795 $sql =
'SELECT v.rowid, v.datec, v.fk_user_author, fk_user_modif, tms';
796 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_various as v';
797 $sql .=
' WHERE v.rowid = '.((int) $id);
799 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
800 $result = $this->db->query($sql);
803 if ($this->db->num_rows($result)) {
804 $obj = $this->db->fetch_object($result);
806 $this->
id = $obj->rowid;
807 $this->user_creation = $obj->fk_user_author;
808 $this->user_creation_id = $obj->fk_user_author;
809 $this->user_modification_id = $obj->fk_user_modif;
810 $this->date_creation = $this->db->jdate($obj->datec);
811 $this->date_modification = $this->db->jdate($obj->tms);
813 $this->db->free($result);
815 dol_print_error($this->db);
827 $banklineid = $this->fk_bank;
829 $alreadydispatched = 0;
833 $sql =
" SELECT ".($mode ?
'DISTINCT piece_num' :
'COUNT(ab.rowid)').
" as nb";
834 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type = '".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $banklineid);
835 $resql = $this->db->query($sql);
837 $obj = $this->db->fetch_object($resql);
839 $alreadydispatched = $obj->nb;
842 $this->error = $this->db->lasterror();
846 if ($alreadydispatched) {
847 return $alreadydispatched;
863 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
864 $bankline = ((empty($arraydata[
'bankline']) || empty($arraydata[
'bankline']->
id)) ? 0 : $arraydata[
'bankline']);
865 $formatedaccountancycode = (empty($arraydata[
'formatedaccountancycode']) ?
'' : $arraydata[
'formatedaccountancycode']);
867 $return =
'<div class="box-flex-item box-flex-grow-zero">';
868 $return .=
'<div class="info-box info-box-sm">';
869 $return .=
'<span class="info-box-icon bg-infobox-action">';
870 $return .= img_picto(
'', $this->picto);
871 $return .=
'</span>';
872 $return .=
'<div class="info-box-content">';
873 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
874 if ($selected >= 0) {
875 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
877 if (!empty($bankline) && $bankline instanceof
AccountLine) {
878 $return .=
' | <span class="info-box-status ">'.$bankline->getNomUrl(1).
'</span>';
880 if (property_exists($this,
'datep')) {
881 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->datep,
'day').
'</span>';
882 if ($this->type_payment) {
883 $return .=
' - <span class="info-box-label">'.$this->type_payment.
'</span>';
886 if (!empty($formatedaccountancycode)) {
887 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label" title="'.$this->accountancy_code.
'">';
888 $return .= $formatedaccountancycode;
889 $return .=
'</span>';
890 } elseif (property_exists($this,
'accountancy_code')) {
891 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label" title="'.$this->accountancy_code.
'">'.$this->accountancy_code.
'</span>';
894 if (property_exists($this,
'amount')) {
895 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Debit").
'</span> : <span class="info-box-label amount">'.
price($this->
amount).
'</span>';
911 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
930 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.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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)
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount