26 require
'../../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
40 $langs->loadLangs(array(
"compta",
"banks",
"bills",
"users",
"accountancy",
"categories"));
44 $action =
GETPOST(
'action',
'alpha');
46 $cancel =
GETPOST(
'cancel',
'aZ09');
47 $backtopage =
GETPOST(
'backtopage',
'alpha');
49 $accountid =
GETPOST(
"accountid") > 0 ?
GETPOST(
"accountid",
"int") : 0;
50 $label =
GETPOST(
"label",
"alpha");
53 $paymenttype =
GETPOST(
"paymenttype",
"aZ09");
54 $accountancy_code =
GETPOST(
"accountancy_code",
"alpha");
55 $projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') :
GETPOST(
'fk_project',
'int'));
56 if (
isModEnabled(
'accounting') && !empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
57 $subledger_account =
GETPOST(
"subledger_account",
"alpha") > 0 ?
GETPOST(
"subledger_account",
"alpha") :
'';
59 $subledger_account =
GETPOST(
"subledger_account",
"alpha");
63 $socid =
GETPOST(
"socid",
"int");
65 $socid = $user->socid;
72 $hookmanager->initHooks(array(
'variouscard',
'globalcard'));
80 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
85 if (empty($reshook)) {
87 if ($action ==
'classin' && $user->rights->banque->modifier) {
89 $object->setProject(
GETPOST(
'projectid'));
93 if ($action !=
'addlink') {
94 $urltogo = $backtopage ? $backtopage :
dol_buildpath(
'/compta/bank/various_payment/list.php', 1);
95 header(
"Location: ".$urltogo);
98 if ($id > 0 || !empty($ref)) {
99 $ret = $object->fetch($id, $ref);
104 if ($action ==
'add') {
114 $object->accountid =
GETPOST(
"accountid",
'int') > 0 ?
GETPOST(
"accountid",
"int") : 0;
115 $object->datev = $datev;
116 $object->datep = $datep;
118 $object->label =
GETPOST(
"label",
'restricthtml');
119 $object->note =
GETPOST(
"note",
'restricthtml');
121 $object->num_payment =
GETPOST(
"num_payment",
'alpha');
122 $object->chqemetteur =
GETPOST(
"chqemetteur",
'alpha');
123 $object->chqbank =
GETPOST(
"chqbank",
'alpha');
124 $object->fk_user_author = $user->id;
125 $object->category_transaction =
GETPOST(
"category_transaction",
'alpha');
127 $object->accountancy_code =
GETPOST(
"accountancy_code") > 0 ?
GETPOST(
"accountancy_code",
"alpha") :
"";
128 $object->subledger_account = $subledger_account;
131 $object->fk_project =
GETPOSTINT(
'fk_project');
133 if (empty($datep) || empty($datev)) {
134 $langs->load(
'errors');
135 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
138 if (empty($object->amount)) {
139 $langs->load(
'errors');
140 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Amount")),
null,
'errors');
143 if (
isModEnabled(
"banque") && !$object->accountid > 0) {
144 $langs->load(
'errors');
145 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
148 if (empty($object->type_payment) || $object->type_payment < 0) {
149 $langs->load(
'errors');
150 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PaymentMode")),
null,
'errors');
153 if (
isModEnabled(
'accounting') && !$object->accountancy_code) {
154 $langs->load(
'errors');
155 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AccountAccounting")),
null,
'errors');
158 if ($object->sens < 0) {
159 $langs->load(
'errors');
160 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Sens")),
null,
'errors');
167 $ret = $object->create($user);
170 $urltogo = ($backtopage ? $backtopage : DOL_URL_ROOT.
'/compta/bank/various_payment/list.php');
171 header(
"Location: ".$urltogo);
183 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
184 $result = $object->fetch($id);
186 if ($object->rappro == 0) {
189 $ret = $object->delete($user);
191 if ($object->fk_bank) {
193 $result = $accountline->fetch($object->fk_bank);
195 $result = $accountline->delete($user);
201 header(
"Location: ".DOL_URL_ROOT.
'/compta/bank/various_payment/list.php');
204 $object->error = $accountline->error;
213 setEventMessages(
'Error try do delete a line linked to a conciliated bank transaction',
null,
'errors');
217 if ($action ==
'setsubledger_account') {
220 $result = $object->fetch($id);
222 $object->subledger_account = $subledger_account;
224 $res = $object->update($user);
235 if ($action ==
'confirm_clone' && $confirm !=
'yes') {
239 if ($action ==
'confirm_clone' && $confirm ==
'yes' && ($user->rights->banque->modifier)) {
246 if ($object->id > 0) {
247 $object->id = $object->ref =
null;
249 if (
GETPOST(
'clone_label',
'alphanohtml')) {
250 $object->label =
GETPOST(
'clone_label',
'alphanohtml');
252 $object->label = $langs->trans(
"CopyOf").
' '.$object->label;
255 $newdatepayment =
dol_mktime(0, 0, 0,
GETPOST(
'clone_date_paymentmonth',
'int'),
GETPOST(
'clone_date_paymentday',
'int'),
GETPOST(
'clone_date_paymentyear',
'int'));
256 $newdatevalue =
dol_mktime(0, 0, 0,
GETPOST(
'clone_date_valuemonth',
'int'),
GETPOST(
'clone_date_valueday',
'int'),
GETPOST(
'clone_date_valueyear',
'int'));
257 if ($newdatepayment) {
258 $object->datep = $newdatepayment;
260 if (!empty($newdatevalue)) {
261 $object->datev = $newdatevalue;
263 $object->datev = $newdatepayment;
267 $object->sens =
GETPOST(
"clone_sens",
'int');
269 $object->sens = $object->sens;
272 if (
GETPOST(
"clone_amount",
"alpha")) {
275 $object->amount =
price2num($object->amount);
278 if ($object->check()) {
279 $id = $object->create($user);
284 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
318 $result = $object->fetch($id);
325 $title = $object->ref.
" - ".$langs->trans(
'Card');
326 if ($action ==
'create') {
327 $title = $langs->trans(
"NewVariousPayment");
329 $help_url =
'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
335 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/bankcateg.class.php';
338 foreach ($bankcateg->fetchAll() as $bankcategory) {
339 $options[$bankcategory->id] = $bankcategory->label;
343 if ($action ==
'create') {
345 if (!empty($conf->use_javascript_ajax)) {
346 print
"\n".
'<script type="text/javascript">';
347 print
'$(document).ready(function () {
349 $("#selectpaymenttype").change(function() {
352 function setPaymentType()
354 console.log("setPaymentType");
355 var code = $("#selectpaymenttype option:selected").val();
356 if (code == \'CHQ\' || code == \'VIR\')
360 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
362 if ($(\'#fieldchqemetteur\').val() == \'\')
364 var emetteur = jQuery(\'#thirdpartylabel\').val();
365 $(\'#fieldchqemetteur\').val(emetteur);
370 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
371 $(\'#fieldchqemetteur\').val(\'\');
378 print
' </script>'.
"\n";
381 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
382 print
'<input type="hidden" name="token" value="'.newToken().
'">';
383 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
384 print
'<input type="hidden" name="action" value="add">';
386 print
load_fiche_titre($langs->trans(
"NewVariousPayment"),
'',
'object_payment');
390 print
'<table class="border centpercent">';
393 print
'<tr><td class="titlefieldcreate">';
394 print
$form->editfieldkey(
'DatePayment',
'datep',
'', $object, 0,
'string',
'', 1).
'</td><td>';
395 print
$form->selectDate((empty($datep) ?-1 : $datep),
"datep",
'',
'',
'',
'add', 1, 1);
400 print
$form->editfieldkey(
'DateValue',
'datev',
'', $object, 0).
'</td><td>';
401 print
$form->selectDate((empty($datev) ?-1 : $datev),
"datev",
'',
'',
'',
'add', 1, 1);
406 print
$form->editfieldkey(
'Label',
'label',
'', $object, 0,
'string',
'', 1).
'</td><td>';
407 print
'<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans(
"VariousPayment")).
'">';
412 print
$form->editfieldkey(
'Amount',
'amount',
'', $object, 0,
'string',
'', 1).
'</td><td>';
413 print
'<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.
'">';
419 print
$form->editfieldkey(
'BankAccount',
'selectaccountid',
'', $object, 0,
'string',
'', 1).
'</td><td>';
420 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
421 print
$form->select_comptes($accountid,
"accountid", 0,
'', 2,
'', 0,
'', 1);
426 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'PaymentMode').
'</span></td><td>';
427 $form->select_types_paiements($paymenttype,
'paymenttype',
'', 2);
433 print
'<tr><td><label for="num_payment">'.$langs->trans(
'Numero');
434 print
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
435 print
'</label></td>';
436 print
'<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST(
"num_payment").
'"></td></tr>'.
"\n";
439 print
'<tr><td class="'.(GETPOST(
'paymenttype') ==
'CHQ' ?
'fieldrequired ' :
'').
'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans(
'CheckTransmitter');
440 print
' <em>('.$langs->trans(
"ChequeMaker").
')</em>';
441 print
'</label></td>';
442 print
'<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST(
'chqemetteur',
'alphanohtml').
'"></td></tr>';
445 print
'<tr><td><label for="chqbank">'.$langs->trans(
'Bank');
446 print
' <em>('.$langs->trans(
"ChequeBank").
')</em>';
447 print
'</label></td>';
448 print
'<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST(
'chqbank',
'alphanohtml').
'"></td></tr>';
454 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"AccountAccounting").
'</td>';
456 print $formaccounting->select_account($accountancy_code,
'accountancy_code', 1,
null, 1, 1);
459 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"AccountAccounting").
'</td>';
460 print
'<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.
'">';
466 print
'<tr><td>'.$langs->trans(
"SubledgerAccount").
'</td>';
468 if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
469 print $formaccounting->select_auxaccount($subledger_account,
'subledger_account', 1,
'');
471 print
'<input type="text" class="maxwidth200 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.
'">';
475 print
'<tr><td>'.$langs->trans(
"SubledgerAccount").
'</td>';
476 print
'<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.
'">';
482 $labelsens =
$form->textwithpicto(
'Sens', $langs->trans(
"AccountingDirectionHelp"));
483 print
$form->editfieldkey($labelsens,
'sens',
'', $object, 0,
'string',
'', 1).
'</td><td>';
484 $sensarray = array(
'0' => $langs->trans(
"Debit"),
'1' => $langs->trans(
"Credit"));
485 print
$form->selectarray(
'sens', $sensarray, $sens, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1);
493 $langs->load(
"projects");
495 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
496 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
497 print $formproject->select_projects(-1, $projectid,
'fk_project', 0, 0, 1, 1, 0, 0, 0,
'', 1);
503 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
504 print $hookmanager->resPrint;
507 if (is_array($options) && count($options) && $conf->categorie->enabled) {
508 print
'<tr><td>'.$langs->trans(
"RubriquesTransactions").
'</td><td>';
509 print
img_picto(
'',
'category').Form::selectarray(
'category_transaction', $options,
GETPOST(
'category_transaction'), 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth300', 1);
517 print
$form->buttonsSaveCancel();
530 $alreadyaccounted = $object->getVentilExportCompta();
535 if ($action ===
'clone') {
536 $set_value_help =
$form->textwithpicto(
'', $langs->trans($langs->trans(
"AccountingDirectionHelp")));
537 $sensarray = array(
'0' => $langs->trans(
"Debit"),
'1' => $langs->trans(
"Credit"));
539 $formquestion = array(
540 array(
'type' =>
'text',
'name' =>
'clone_label',
'label' => $langs->trans(
"Label"),
'value' => $langs->trans(
"CopyOf").
' '.$object->label),
541 array(
'type' =>
'date',
'tdclass'=>
'fieldrequired',
'name' =>
'clone_date_payment',
'label' => $langs->trans(
"DatePayment"),
'value' => -1),
542 array(
'type' =>
'date',
'name' =>
'clone_date_value',
'label' => $langs->trans(
"DateValue"),
'value' => -1),
543 array(
'type' =>
'other',
'tdclass'=>
'fieldrequired',
'name' =>
'clone_accountid',
'label' => $langs->trans(
"BankAccount"),
'value' =>
$form->select_comptes($object->fk_account,
"accountid", 0,
'', 1,
'', 0,
'minwidth200', 1)),
544 array(
'type' =>
'text',
'name' =>
'clone_amount',
'label' => $langs->trans(
"Amount"),
'value' =>
price($object->amount)),
545 array(
'type' =>
'select',
'name' =>
'clone_sens',
'label' => $langs->trans(
"Sens").
' '.$set_value_help,
'values' => $sensarray,
'default' => $object->sens),
548 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneVariousPayment', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 350);
552 if ($action ==
'delete') {
553 $text = $langs->trans(
'ConfirmDeleteVariousPayment');
554 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'DeleteVariousPayment'), $text,
'confirm_delete',
'',
'', 2);
557 print
dol_get_fiche_head($head,
'card', $langs->trans(
"VariousPayment"), -1, $object->picto);
559 $morehtmlref =
'<div class="refidno">';
562 $langs->load(
"projects");
563 $morehtmlref .= $langs->trans(
'Project').
' ';
564 if ($user->rights->banque->modifier) {
565 if ($action !=
'classify') {
566 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
568 if ($action ==
'classify') {
570 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
571 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
572 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
573 $morehtmlref .= $formproject->select_projects(0, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
574 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
575 $morehtmlref .=
'</form>';
577 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1,
'',
'maxwidth300');
580 if (!empty($object->fk_project)) {
582 $proj->fetch($object->fk_project);
583 $morehtmlref .= $proj->getNomUrl(1);
589 $morehtmlref .=
'</div>';
590 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/bank/various_payment/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
594 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
596 print
'<div class="fichecenter">';
597 print
'<div class="underbanner clearboth"></div>';
599 print
'<table class="border centpercent tableforfield">';
602 print
'<tr><td class="titlefield">'.$langs->trans(
"Label").
'</td><td>'.$object->label.
'</td></tr>';
606 print
'<td>'.$langs->trans(
"DatePayment").
'</td><td>';
611 print
'<tr><td>'.$langs->trans(
"DateValue").
'</td><td>';
616 if ($object->sens ==
'1') {
617 $sens = $langs->trans(
"Credit");
619 $sens = $langs->trans(
"Debit");
621 print
'<tr><td>'.$langs->trans(
"Sens").
'</td><td>'.$sens.
'</td></tr>';
623 print
'<tr><td>'.$langs->trans(
"Amount").
'</td><td><span class="amount">'.
price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span></td></tr>';
626 print
'<tr><td class="nowrap">';
627 print $langs->trans(
"AccountAccounting");
631 $accountingaccount->fetch(
'', $object->accountancy_code, 1);
633 print $accountingaccount->getNomUrl(0, 1, 1,
'', 1);
635 print $object->accountancy_code;
640 print
'<tr><td class="nowrap">';
641 print
$form->editfieldkey(
'SubledgerAccount',
'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier),
'string',
'', 0);
643 print
$form->editfieldval(
'SubledgerAccount',
'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier),
'string',
'', 0);
646 $bankaccountnotfound = 0;
650 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
651 print
'<td colspan="3">';
652 if ($object->fk_bank > 0) {
654 $result = $bankline->fetch($object->fk_bank);
657 $bankaccountnotfound = 1;
659 print $bankline->getNomUrl(1, 0,
'showall');
662 $bankaccountnotfound = 1;
664 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordfound").
'</span>';
672 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
678 print
'<div class="clearboth"></div>';
686 print
'<div class="tabsAction">'.
"\n";
692 if ($user->rights->banque->modifier) {
693 print
'<div class="inline-block divButAction"><a class="butAction" href="'.dol_buildpath(
"/compta/bank/various_payment/card.php", 1).
'?id='.$object->id.
'&action=clone">'.$langs->trans(
"ToClone").
"</a></div>";
697 if (empty($object->rappro) || $bankaccountnotfound) {
698 if (!empty($user->rights->banque->modifier)) {
699 if ($alreadyaccounted) {
700 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"Accounted").
'">'.$langs->trans(
"Delete").
'</a></div>';
702 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a></div>';
705 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans(
"NotAllowed"))).
'">'.$langs->trans(
"Delete").
'</a></div>';
708 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"LinkedToAConciliatedTransaction").
'">'.$langs->trans(
"Delete").
'</a></div>';