25 require
'../../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
39 $langs->loadLangs(array(
"compta",
"banks",
"bills",
"users",
"accountancy",
"categories"));
43 $action =
GETPOST(
'action',
'alpha');
45 $cancel =
GETPOST(
'cancel',
'aZ09');
46 $backtopage =
GETPOST(
'backtopage',
'alpha');
48 $accountid =
GETPOST(
"accountid") > 0 ?
GETPOST(
"accountid",
"int") : 0;
49 $label =
GETPOST(
"label",
"alpha");
52 $paymenttype =
GETPOST(
"paymenttype",
"aZ09");
53 $accountancy_code =
GETPOST(
"accountancy_code",
"alpha");
54 $projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') :
GETPOST(
'fk_project',
'int'));
55 if (
isModEnabled(
'accounting') && !empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
56 $subledger_account =
GETPOST(
"subledger_account",
"alpha") > 0 ?
GETPOST(
"subledger_account",
"alpha") :
'';
58 $subledger_account =
GETPOST(
"subledger_account",
"alpha");
62 $socid =
GETPOST(
"socid",
"int");
64 $socid = $user->socid;
71 $hookmanager->initHooks(array(
'variouscard',
'globalcard'));
79 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
84 if (empty($reshook)) {
86 if ($action ==
'classin' && $user->rights->banque->modifier) {
88 $object->setProject(
GETPOST(
'projectid'));
92 if ($action !=
'addlink') {
93 $urltogo = $backtopage ? $backtopage :
dol_buildpath(
'/compta/bank/various_payment/list.php', 1);
94 header(
"Location: ".$urltogo);
97 if ($id > 0 || !empty($ref)) {
98 $ret = $object->fetch($id, $ref);
103 if ($action ==
'add') {
113 $object->accountid =
GETPOST(
"accountid",
'int') > 0 ?
GETPOST(
"accountid",
"int") : 0;
114 $object->datev = $datev;
115 $object->datep = $datep;
117 $object->label =
GETPOST(
"label",
'restricthtml');
118 $object->note =
GETPOST(
"note",
'restricthtml');
120 $object->num_payment =
GETPOST(
"num_payment",
'alpha');
121 $object->chqemetteur =
GETPOST(
"chqemetteur",
'alpha');
122 $object->chqbank =
GETPOST(
"chqbank",
'alpha');
123 $object->fk_user_author = $user->id;
124 $object->category_transaction =
GETPOST(
"category_transaction",
'alpha');
126 $object->accountancy_code =
GETPOST(
"accountancy_code") > 0 ?
GETPOST(
"accountancy_code",
"alpha") :
"";
127 $object->subledger_account = $subledger_account;
130 $object->fk_project =
GETPOSTINT(
'fk_project');
132 if (empty($datep) || empty($datev)) {
133 $langs->load(
'errors');
134 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
137 if (empty($object->amount)) {
138 $langs->load(
'errors');
139 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Amount")),
null,
'errors');
142 if (
isModEnabled(
'banque') && !$object->accountid > 0) {
143 $langs->load(
'errors');
144 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
147 if (empty($object->type_payment) || $object->type_payment < 0) {
148 $langs->load(
'errors');
149 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PaymentMode")),
null,
'errors');
152 if (
isModEnabled(
'accounting') && !$object->accountancy_code) {
153 $langs->load(
'errors');
154 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AccountAccounting")),
null,
'errors');
157 if ($object->sens < 0) {
158 $langs->load(
'errors');
159 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Sens")),
null,
'errors');
166 $ret = $object->create($user);
169 $urltogo = ($backtopage ? $backtopage : DOL_URL_ROOT.
'/compta/bank/various_payment/list.php');
170 header(
"Location: ".$urltogo);
182 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
183 $result = $object->fetch($id);
185 if ($object->rappro == 0) {
188 $ret = $object->delete($user);
190 if ($object->fk_bank) {
192 $result = $accountline->fetch($object->fk_bank);
194 $result = $accountline->delete($user);
200 header(
"Location: ".DOL_URL_ROOT.
'/compta/bank/various_payment/list.php');
203 $object->error = $accountline->error;
212 setEventMessages(
'Error try do delete a line linked to a conciliated bank transaction',
null,
'errors');
216 if ($action ==
'setsubledger_account') {
219 $result = $object->fetch($id);
221 $object->subledger_account = $subledger_account;
223 $res = $object->update($user);
234 if ($action ==
'confirm_clone' && $confirm !=
'yes') {
238 if ($action ==
'confirm_clone' && $confirm ==
'yes' && ($user->rights->banque->modifier)) {
245 if ($object->id > 0) {
246 $object->id = $object->ref =
null;
248 if (
GETPOST(
'clone_label',
'alphanohtml')) {
249 $object->label =
GETPOST(
'clone_label',
'alphanohtml');
251 $object->label = $langs->trans(
"CopyOf").
' '.$object->label;
254 $newdatepayment =
dol_mktime(0, 0, 0,
GETPOST(
'clone_date_paymentmonth',
'int'),
GETPOST(
'clone_date_paymentday',
'int'),
GETPOST(
'clone_date_paymentyear',
'int'));
255 $newdatevalue =
dol_mktime(0, 0, 0,
GETPOST(
'clone_date_valuemonth',
'int'),
GETPOST(
'clone_date_valueday',
'int'),
GETPOST(
'clone_date_valueyear',
'int'));
256 if ($newdatepayment) {
257 $object->datep = $newdatepayment;
259 if (!empty($newdatevalue)) {
260 $object->datev = $newdatevalue;
262 $object->datev = $newdatepayment;
266 $object->sens =
GETPOST(
"clone_sens",
'int');
268 $object->sens = $object->sens;
271 if (
GETPOST(
"clone_amount",
"alpha")) {
274 $object->amount =
price2num($object->amount);
277 if ($object->check()) {
278 $id = $object->create($user);
283 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
308 llxHeader(
"", $langs->trans(
"VariousPayment"));
320 $result = $object->fetch($id);
330 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/bankcateg.class.php';
333 foreach ($bankcateg->fetchAll() as $bankcategory) {
334 $options[$bankcategory->id] = $bankcategory->label;
338 if ($action ==
'create') {
340 if (!empty($conf->use_javascript_ajax)) {
341 print
"\n".
'<script type="text/javascript">';
342 print
'$(document).ready(function () {
344 $("#selectpaymenttype").change(function() {
347 function setPaymentType()
349 console.log("setPaymentType");
350 var code = $("#selectpaymenttype option:selected").val();
351 if (code == \'CHQ\' || code == \'VIR\')
355 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
357 if ($(\'#fieldchqemetteur\').val() == \'\')
359 var emetteur = jQuery(\'#thirdpartylabel\').val();
360 $(\'#fieldchqemetteur\').val(emetteur);
365 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
366 $(\'#fieldchqemetteur\').val(\'\');
373 print
' </script>'.
"\n";
376 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
377 print
'<input type="hidden" name="token" value="'.newToken().
'">';
378 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
379 print
'<input type="hidden" name="action" value="add">';
381 print
load_fiche_titre($langs->trans(
"NewVariousPayment"),
'',
'object_payment');
385 print
'<table class="border centpercent">';
388 print
'<tr><td class="titlefieldcreate">';
389 print
$form->editfieldkey(
'DatePayment',
'datep',
'', $object, 0,
'string',
'', 1).
'</td><td>';
390 print
$form->selectDate((empty($datep) ?-1 : $datep),
"datep",
'',
'',
'',
'add', 1, 1);
395 print
$form->editfieldkey(
'DateValue',
'datev',
'', $object, 0).
'</td><td>';
396 print
$form->selectDate((empty($datev) ?-1 : $datev),
"datev",
'',
'',
'',
'add', 1, 1);
401 print
$form->editfieldkey(
'Label',
'label',
'', $object, 0,
'string',
'', 1).
'</td><td>';
402 print
'<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans(
"VariousPayment")).
'">';
407 print
$form->editfieldkey(
'Amount',
'amount',
'', $object, 0,
'string',
'', 1).
'</td><td>';
408 print
'<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.
'">';
414 print
$form->editfieldkey(
'BankAccount',
'selectaccountid',
'', $object, 0,
'string',
'', 1).
'</td><td>';
415 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
416 print
$form->select_comptes($accountid,
"accountid", 0,
'', 2,
'', 0,
'', 1);
421 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'PaymentMode').
'</span></td><td>';
422 $form->select_types_paiements($paymenttype,
'paymenttype',
'', 2);
428 print
'<tr><td><label for="num_payment">'.$langs->trans(
'Numero');
429 print
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
430 print
'</label></td>';
431 print
'<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST(
"num_payment").
'"></td></tr>'.
"\n";
434 print
'<tr><td class="'.(GETPOST(
'paymenttype') ==
'CHQ' ?
'fieldrequired ' :
'').
'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans(
'CheckTransmitter');
435 print
' <em>('.$langs->trans(
"ChequeMaker").
')</em>';
436 print
'</label></td>';
437 print
'<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST(
'chqemetteur',
'alphanohtml').
'"></td></tr>';
440 print
'<tr><td><label for="chqbank">'.$langs->trans(
'Bank');
441 print
' <em>('.$langs->trans(
"ChequeBank").
')</em>';
442 print
'</label></td>';
443 print
'<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST(
'chqbank',
'alphanohtml').
'"></td></tr>';
449 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"AccountAccounting").
'</td>';
451 print $formaccounting->select_account($accountancy_code,
'accountancy_code', 1,
null, 1, 1);
454 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"AccountAccounting").
'</td>';
455 print
'<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.
'">';
461 print
'<tr><td>'.$langs->trans(
"SubledgerAccount").
'</td>';
463 if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
464 print $formaccounting->select_auxaccount($subledger_account,
'subledger_account', 1,
'');
466 print
'<input type="text" class="maxwidth200 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.
'">';
470 print
'<tr><td>'.$langs->trans(
"SubledgerAccount").
'</td>';
471 print
'<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.
'">';
477 $labelsens =
$form->textwithpicto(
'Sens', $langs->trans(
"AccountingDirectionHelp"));
478 print
$form->editfieldkey($labelsens,
'sens',
'', $object, 0,
'string',
'', 1).
'</td><td>';
479 $sensarray = array(
'0' => $langs->trans(
"Debit"),
'1' => $langs->trans(
"Credit"));
480 print
$form->selectarray(
'sens', $sensarray, $sens, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1);
488 $langs->load(
"projects");
490 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
491 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
492 print $formproject->select_projects(-1, $projectid,
'fk_project', 0, 0, 1, 1, 0, 0, 0,
'', 1);
498 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
499 print $hookmanager->resPrint;
502 if (is_array($options) && count($options) && $conf->categorie->enabled) {
503 print
'<tr><td>'.$langs->trans(
"RubriquesTransactions").
'</td><td>';
504 print
img_picto(
'',
'category').Form::selectarray(
'category_transaction', $options,
GETPOST(
'category_transaction'), 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth300', 1);
512 print
$form->buttonsSaveCancel();
525 $alreadyaccounted = $object->getVentilExportCompta();
530 if ($action ===
'clone') {
531 $set_value_help =
$form->textwithpicto(
'', $langs->trans($langs->trans(
"AccountingDirectionHelp")));
532 $sensarray = array(
'0' => $langs->trans(
"Debit"),
'1' => $langs->trans(
"Credit"));
534 $formquestion = array(
535 array(
'type' =>
'text',
'name' =>
'clone_label',
'label' => $langs->trans(
"Label"),
'value' => $langs->trans(
"CopyOf").
' '.$object->label),
536 array(
'type' =>
'date',
'tdclass'=>
'fieldrequired',
'name' =>
'clone_date_payment',
'label' => $langs->trans(
"DatePayment"),
'value' => -1),
537 array(
'type' =>
'date',
'name' =>
'clone_date_value',
'label' => $langs->trans(
"DateValue"),
'value' => -1),
538 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)),
539 array(
'type' =>
'text',
'name' =>
'clone_amount',
'label' => $langs->trans(
"Amount"),
'value' =>
price($object->amount)),
540 array(
'type' =>
'select',
'name' =>
'clone_sens',
'label' => $langs->trans(
"Sens").
' '.$set_value_help,
'values' => $sensarray,
'default' => $object->sens),
543 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneVariousPayment', $object->ref),
'confirm_clone', $formquestion,
'yes', 1, 350);
547 if ($action ==
'delete') {
548 $text = $langs->trans(
'ConfirmDeleteVariousPayment');
549 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
'DeleteVariousPayment'), $text,
'confirm_delete',
'',
'', 2);
552 print
dol_get_fiche_head($head,
'card', $langs->trans(
"VariousPayment"), -1, $object->picto);
554 $morehtmlref =
'<div class="refidno">';
557 $langs->load(
"projects");
558 $morehtmlref .= $langs->trans(
'Project').
' ';
559 if ($user->rights->banque->modifier) {
560 if ($action !=
'classify') {
561 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
563 if ($action ==
'classify') {
565 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
566 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
567 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
568 $morehtmlref .= $formproject->select_projects(0, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
569 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
570 $morehtmlref .=
'</form>';
572 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
575 if (!empty($object->fk_project)) {
577 $proj->fetch($object->fk_project);
578 $morehtmlref .= $proj->getNomUrl(1);
584 $morehtmlref .=
'</div>';
585 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/bank/various_payment/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
589 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
591 print
'<div class="fichecenter">';
592 print
'<div class="underbanner clearboth"></div>';
594 print
'<table class="border centpercent tableforfield">';
597 print
'<tr><td class="titlefield">'.$langs->trans(
"Label").
'</td><td>'.$object->label.
'</td></tr>';
601 print
'<td>'.$langs->trans(
"DatePayment").
'</td><td>';
606 print
'<tr><td>'.$langs->trans(
"DateValue").
'</td><td>';
611 if ($object->sens ==
'1') {
612 $sens = $langs->trans(
"Credit");
614 $sens = $langs->trans(
"Debit");
616 print
'<tr><td>'.$langs->trans(
"Sens").
'</td><td>'.$sens.
'</td></tr>';
618 print
'<tr><td>'.$langs->trans(
"Amount").
'</td><td><span class="amount">'.
price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span></td></tr>';
621 print
'<tr><td class="nowrap">';
622 print $langs->trans(
"AccountAccounting");
626 $accountingaccount->fetch(
'', $object->accountancy_code, 1);
628 print $accountingaccount->getNomUrl(0, 1, 1,
'', 1);
630 print $object->accountancy_code;
635 print
'<tr><td class="nowrap">';
636 print
$form->editfieldkey(
'SubledgerAccount',
'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier),
'string',
'', 0);
638 print
$form->editfieldval(
'SubledgerAccount',
'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier),
'string',
'', 0);
641 $bankaccountnotfound = 0;
645 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
646 print
'<td colspan="3">';
647 if ($object->fk_bank > 0) {
649 $result = $bankline->fetch($object->fk_bank);
652 $bankaccountnotfound = 1;
654 print $bankline->getNomUrl(1, 0,
'showall');
657 $bankaccountnotfound = 1;
659 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordfound").
'</span>';
667 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
673 print
'<div class="clearboth"></div>';
681 print
'<div class="tabsAction">'.
"\n";
687 if ($user->rights->banque->modifier) {
688 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>";
692 if (empty($object->rappro) || $bankaccountnotfound) {
693 if (!empty($user->rights->banque->modifier)) {
694 if ($alreadyaccounted) {
695 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"Accounted").
'">'.$langs->trans(
"Delete").
'</a></div>';
697 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a></div>';
700 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans(
"NotAllowed"))).
'">'.$langs->trans(
"Delete").
'</a></div>';
703 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"LinkedToAConciliatedTransaction").
'">'.$langs->trans(
"Delete").
'</a></div>';