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;
156 public $categorie_transaction;
161 public $fk_user_author;
166 public $fk_user_modif;
182 public $bank_num_releve;
214 public $fields = array(
242 public function update($user =
null, $notrigger = 0)
244 global
$conf, $langs;
250 $this->label = trim($this->label);
251 $this->note = trim($this->note);
252 $this->fk_bank = (int) $this->fk_bank;
253 $this->fk_user_author = (int) $this->fk_user_author;
254 $this->fk_user_modif = (int) $this->fk_user_modif;
259 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_various SET";
261 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
263 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
264 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
265 $sql .=
" sens=".(int) $this->sens.
",";
266 $sql .=
" amount=".price2num($this->
amount).
",";
267 $sql .=
" fk_typepayment=".(int) $this->type_payment.
",";
268 $sql .=
" num_payment='".$this->db->escape($this->num_payment).
"',";
269 $sql .=
" label='".$this->db->escape($this->label).
"',";
270 $sql .=
" note='".$this->db->escape($this->note).
"',";
271 $sql .=
" accountancy_code='".$this->db->escape($this->accountancy_code).
"',";
272 $sql .=
" subledger_account='".$this->db->escape($this->subledger_account).
"',";
273 $sql .=
" fk_projet='".$this->db->escape((
string) $this->fk_project).
"',";
274 $sql .=
" fk_soc=".($this->fk_soc > 0 ? ((int) $this->fk_soc) :
"null").
",";
275 $sql .=
" fk_bank=".($this->fk_bank > 0 ? ((int) $this->fk_bank) :
"null").
",";
276 $sql .=
" fk_user_author=".(int) $this->fk_user_author.
",";
277 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
278 $sql .=
" WHERE rowid=".((int) $this->
id);
280 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
281 $resql = $this->db->query($sql);
283 $this->error =
"Error ".$this->db->lasterror();
293 if (!$error && !$notrigger) {
295 $result = $this->call_trigger(
'PAYMENT_VARIOUS_MODIFY', $user);
306 $this->db->rollback();
319 public function fetch($id, $user =
null)
327 $sql .=
" v.amount,";
328 $sql .=
" v.fk_typepayment,";
329 $sql .=
" v.num_payment,";
331 $sql .=
" v.note as note_private,";
332 $sql .=
" v.accountancy_code,";
333 $sql .=
" v.subledger_account,";
334 $sql .=
" v.fk_projet as fk_project,";
335 $sql .=
" v.fk_soc,";
336 $sql .=
" v.fk_bank,";
337 $sql .=
" v.fk_user_author,";
338 $sql .=
" v.fk_user_modif,";
339 $sql .=
" b.fk_account,";
340 $sql .=
" b.fk_type,";
341 $sql .=
" b.rappro,";
342 $sql .=
" b.num_releve as bank_num_releve";
343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_various as v";
344 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON v.fk_bank = b.rowid";
345 $sql .=
" WHERE v.rowid = ".((int) $id);
347 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
348 $resql = $this->db->query($sql);
350 if ($this->db->num_rows($resql)) {
351 $obj = $this->db->fetch_object($resql);
353 $this->
id = $obj->rowid;
354 $this->
ref = $obj->rowid;
355 $this->tms = $this->db->jdate($obj->tms);
356 $this->datep = $this->db->jdate($obj->datep);
357 $this->datev = $this->db->jdate($obj->datev);
358 $this->sens = $obj->sens;
359 $this->
amount = $obj->amount;
360 $this->type_payment = $obj->fk_typepayment;
361 $this->num_payment = $obj->num_payment;
362 $this->label = $obj->label;
363 $this->note = $obj->note_private;
364 $this->note_private = $obj->note_private;
365 $this->subledger_account = $obj->subledger_account;
366 $this->accountancy_code = $obj->accountancy_code;
367 $this->fk_project = $obj->fk_project;
368 $this->fk_soc = $obj->fk_soc;
369 $this->socid = $obj->fk_soc;
370 $this->fk_bank = $obj->fk_bank;
371 $this->fk_user_author = $obj->fk_user_author;
372 $this->fk_user_modif = $obj->fk_user_modif;
373 $this->fk_account = $obj->fk_account;
374 $this->fk_type = $obj->fk_type;
375 $this->rappro = $obj->rappro;
376 $this->bank_num_releve = $obj->bank_num_releve;
382 $this->db->free($resql);
386 $this->error =
"Error ".$this->db->lasterror();
398 public function delete($user)
400 global
$conf, $langs;
405 $result = $this->call_trigger(
'PAYMENT_VARIOUS_DELETE', $user);
412 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_various";
413 $sql .=
" WHERE rowid=".((int) $this->
id);
415 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
416 $resql = $this->db->query($sql);
418 $this->error =
"Error ".$this->db->lasterror();
423 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
424 $dir =
$conf->bank->dir_output.
'/various_payment/'.((int) $this->
id);
425 if (file_exists($dir)) {
448 $this->label =
'Specimen payment';
449 $this->accountancy_code =
'';
450 $this->subledger_account =
'';
453 $this->fk_user_author = 0;
454 $this->fk_user_modif = 0;
469 if (!($newamount) > 0 || empty($this->datep)) {
484 global
$conf, $langs;
491 $this->label = trim($this->label);
492 $this->note = trim($this->note);
493 $this->fk_bank = (int) $this->fk_bank;
494 $this->fk_user_author = (int) $this->fk_user_author;
495 $this->fk_user_modif = (int) $this->fk_user_modif;
496 $this->fk_account = (int) $this->fk_account;
497 if (empty($this->fk_account) && isset($this->accountid)) {
498 $this->fk_account = $this->accountid;
503 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
507 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
510 if (
isModEnabled(
"bank") && (empty($this->fk_account) || $this->fk_account <= 0)) {
511 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
514 if (
isModEnabled(
"bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
515 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
522 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_various (";
527 $sql .=
", fk_typepayment";
528 $sql .=
", num_payment";
533 $sql .=
", accountancy_code";
534 $sql .=
", subledger_account";
535 $sql .=
", fk_projet";
537 $sql .=
", fk_user_author";
543 $sql .=
"'".$this->db->idate($this->datep).
"'";
544 $sql .=
", '".$this->db->idate($this->datev).
"'";
545 $sql .=
", '".$this->db->escape((
string) $this->sens).
"'";
546 $sql .=
", ".price2num($this->
amount);
547 $sql .=
", '".$this->db->escape((
string) $this->type_payment).
"'";
548 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
550 $sql .=
", '".$this->db->escape($this->note).
"'";
552 $sql .=
", '".$this->db->escape($this->label).
"'";
553 $sql .=
", '".$this->db->escape($this->accountancy_code).
"'";
554 $sql .=
", '".$this->db->escape($this->subledger_account).
"'";
555 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
556 $sql .=
", ".($this->fk_soc > 0 ? ((int) $this->fk_soc) :
"NULL");
557 $sql .=
", ".((int) $user->id);
558 $sql .=
", '".$this->db->idate($now).
"'";
560 $sql .=
", ".((int)
$conf->entity);
563 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
564 $result = $this->db->query($sql);
566 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_various");
567 $this->
ref = (string) $this->
id;
578 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
581 $result = $acc->fetch($this->fk_account);
583 dol_print_error($this->db);
589 if ($this->sens ==
'0') {
593 $bank_line_id = $acc->addline(
595 (
string) $this->type_payment,
597 $sign * abs($this->
amount),
599 ($this->category_transaction > 0 ? $this->category_transaction : 0),
609 if ($bank_line_id > 0) {
612 $this->error = $acc->error;
618 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id=';
620 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
"(VariousPayment)",
"payment_various");
622 $this->error = $acc->error;
628 if (!$error &&
getDolGlobalString(
'BANK_VARIOUS_PAYMENT_USE_THIRDPARTY') && $this->fk_soc > 0) {
629 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
631 $thirdparty =
new Societe($this->db);
632 if ($thirdparty->fetch($this->fk_soc) > 0) {
633 $result = $acc->add_url_line($bank_line_id, $thirdparty->id, DOL_URL_ROOT.
'/societe/card.php?socid=', $thirdparty->name,
'company');
635 $this->error = $acc->error;
639 $this->error = $thirdparty->error;
645 $this->error = $acc->error;
652 $result = $this->call_trigger(
'PAYMENT_VARIOUS_CREATE', $user);
666 $this->db->rollback();
670 $this->error = $this->db->error();
671 $this->db->rollback();
686 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'payment_various SET fk_bank = '.((int) $id_bank);
687 $sql .=
" WHERE rowid = ".((int) $this->
id);
688 $result = $this->db->query($sql);
692 $this->fk_bank = (int) $id_bank;
695 dol_print_error($this->db);
757 public function getNomUrl($withpicto = 0, $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
759 global $db,
$conf, $langs, $hookmanager;
762 if (!empty(
$conf->dol_no_mouse_hover)) {
768 $label =
'<u>'.$langs->trans(
"ShowVariousPayment").
'</u>';
770 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
772 $url = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.$this->id;
774 if ($option !=
'nolink') {
776 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
777 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
778 $add_save_lastsearch_values = 1;
780 if ($add_save_lastsearch_values) {
781 $url .=
'&save_lastsearch_values=1';
786 if (empty($notooltip)) {
788 $label = $langs->trans(
"ShowMyObject");
789 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
791 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
792 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
794 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
797 $linkstart =
'<a href="'.$url.
'"';
798 $linkstart .= $linkclose.
'>';
801 $result .= $linkstart;
803 $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);
805 if ($withpicto != 2) {
806 $result .= $this->ref;
812 $hookmanager->initHooks(array(
'variouspayment'));
813 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
814 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
816 $result = $hookmanager->resPrint;
818 $result .= $hookmanager->resPrint;
832 $sql =
'SELECT v.rowid, v.datec, v.fk_user_author, fk_user_modif, tms';
833 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_various as v';
834 $sql .=
' WHERE v.rowid = '.((int) $id);
836 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
837 $result = $this->db->query($sql);
840 if ($this->db->num_rows($result)) {
841 $obj = $this->db->fetch_object($result);
843 $this->
id = $obj->rowid;
844 $this->user_creation = $obj->fk_user_author;
845 $this->user_creation_id = $obj->fk_user_author;
846 $this->user_modification_id = $obj->fk_user_modif;
847 $this->date_creation = $this->db->jdate($obj->datec);
848 $this->date_modification = $this->db->jdate($obj->tms);
850 $this->db->free($result);
852 dol_print_error($this->db);
864 $banklineid = $this->fk_bank;
866 $alreadydispatched = 0;
870 $sql =
" SELECT ".($mode ?
'DISTINCT piece_num' :
'COUNT(ab.rowid)').
" as nb";
871 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type = '".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $banklineid);
872 $resql = $this->db->query($sql);
874 $obj = $this->db->fetch_object($resql);
876 $alreadydispatched = $obj->nb;
879 $this->error = $this->db->lasterror();
883 if ($alreadydispatched) {
884 return $alreadydispatched;
900 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
901 $bankline = ((empty($arraydata[
'bankline']) || empty($arraydata[
'bankline']->
id)) ? 0 : $arraydata[
'bankline']);
902 $formatedaccountancycode = (empty($arraydata[
'formatedaccountancycode']) ?
'' : $arraydata[
'formatedaccountancycode']);
904 $return =
'<div class="box-flex-item box-flex-grow-zero">';
905 $return .=
'<div class="info-box info-box-sm">';
906 $return .=
'<span class="info-box-icon bg-infobox-action">';
907 $return .= img_picto(
'', $this->picto);
908 $return .=
'</span>';
909 $return .=
'<div class="info-box-content">';
910 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
911 if ($selected >= 0) {
912 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
914 if (!empty($bankline) && $bankline instanceof
AccountLine) {
915 $return .=
' | <span class="info-box-status ">'.$bankline->getNomUrl(1).
'</span>';
917 if (property_exists($this,
'datep')) {
918 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->datep,
'day').
'</span>';
919 if ($this->type_payment) {
920 $return .=
' - <span class="info-box-label">'.$this->type_payment.
'</span>';
923 if (!empty($formatedaccountancycode)) {
924 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label" title="'.$this->accountancy_code.
'">';
925 $return .= $formatedaccountancycode;
926 $return .=
'</span>';
927 } elseif (property_exists($this,
'accountancy_code')) {
928 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label" title="'.$this->accountancy_code.
'">'.$this->accountancy_code.
'</span>';
931 if (property_exists($this,
'amount')) {
932 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Debit").
'</span> : <span class="info-box-label amount">'.
price($this->
amount).
'</span>';
948 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
967 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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)
Class to manage third parties objects (customers, suppliers, prospects...)
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
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