* Copyright (C) 2018-2020 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/bank/various_payment/card.php * \ingroup bank * \brief Page of various expenses */ // Load Dolibarr environment require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; if (isModEnabled('project')) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } // Load translation files required by the page $langs->loadLangs(array("compta", "banks", "bills", "users", "accountancy", "categories")); // Get parameters $id = GETPOST('id', 'int'); $action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm'); $cancel = GETPOST('cancel', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); $accountid = GETPOST("accountid") > 0 ? GETPOST("accountid", "int") : 0; $label = GETPOST("label", "alpha"); $sens = GETPOST("sens", "int"); $amount = price2num(GETPOST("amount", "alpha")); $paymenttype = GETPOST("paymenttype", "aZ09"); $accountancy_code = GETPOST("accountancy_code", "alpha"); $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int')); if (isModEnabled('accounting') && !empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { $subledger_account = GETPOST("subledger_account", "alpha") > 0 ? GETPOST("subledger_account", "alpha") : ''; } else { $subledger_account = GETPOST("subledger_account", "alpha"); } // Security check $socid = GETPOST("socid", "int"); if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'banque', '', '', ''); $object = new PaymentVarious($db); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('variouscard', 'globalcard')); /** * Actions */ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if (empty($reshook)) { // Link to a project if ($action == 'classin' && $user->rights->banque->modifier) { $object->fetch($id); $object->setProject(GETPOST('projectid')); } if ($cancel) { if ($action != 'addlink') { $urltogo = $backtopage ? $backtopage : dol_buildpath('/compta/bank/various_payment/list.php', 1); header("Location: ".$urltogo); exit; } if ($id > 0 || !empty($ref)) { $ret = $object->fetch($id, $ref); } $action = ''; } if ($action == 'add') { $error = 0; $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int')); $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int')); if (empty($datev)) { $datev = $datep; } $object->ref = ''; // TODO $object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0; $object->datev = $datev; $object->datep = $datep; $object->amount = price2num(GETPOST("amount", 'alpha')); $object->label = GETPOST("label", 'restricthtml'); $object->note = GETPOST("note", 'restricthtml'); $object->type_payment = dol_getIdFromCode($db, GETPOST('paymenttype'), 'c_paiement', 'code', 'id', 1); $object->num_payment = GETPOST("num_payment", 'alpha'); $object->chqemetteur = GETPOST("chqemetteur", 'alpha'); $object->chqbank = GETPOST("chqbank", 'alpha'); $object->fk_user_author = $user->id; $object->category_transaction = GETPOST("category_transaction", 'alpha'); $object->accountancy_code = GETPOST("accountancy_code") > 0 ? GETPOST("accountancy_code", "alpha") : ""; $object->subledger_account = $subledger_account; $object->sens = GETPOSTINT('sens'); $object->fk_project = GETPOSTINT('fk_project'); if (empty($datep) || empty($datev)) { $langs->load('errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $error++; } if (empty($object->amount)) { $langs->load('errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); $error++; } if (isModEnabled("banque") && !$object->accountid > 0) { $langs->load('errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors'); $error++; } if (empty($object->type_payment) || $object->type_payment < 0) { $langs->load('errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors'); $error++; } if (isModEnabled('accounting') && !$object->accountancy_code) { $langs->load('errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors'); $error++; } if ($object->sens < 0) { $langs->load('errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Sens")), null, 'errors'); $error++; } if (!$error) { $db->begin(); $ret = $object->create($user); if ($ret > 0) { $db->commit(); $urltogo = ($backtopage ? $backtopage : DOL_URL_ROOT.'/compta/bank/various_payment/list.php'); header("Location: ".$urltogo); exit; } else { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); $action = "create"; } } $action = 'create'; } if ($action == 'confirm_delete' && $confirm == 'yes') { $result = $object->fetch($id); if ($object->rappro == 0) { $db->begin(); $ret = $object->delete($user); if ($ret > 0) { if ($object->fk_bank) { $accountline = new AccountLine($db); $result = $accountline->fetch($object->fk_bank); if ($result > 0) { $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing) } } if ($result >= 0) { $db->commit(); header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/list.php'); exit; } else { $object->error = $accountline->error; $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } } else { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } } else { setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors'); } } if ($action == 'setsubledger_account') { $db->begin(); $result = $object->fetch($id); $object->subledger_account = $subledger_account; $res = $object->update($user); if ($res > 0) { $db->commit(); } else { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } } } // Action clone object if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; } if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->modifier)) { $db->begin(); $originalId = $id; $object->fetch($id); if ($object->id > 0) { $object->id = $object->ref = null; if (GETPOST('clone_label', 'alphanohtml')) { $object->label = GETPOST('clone_label', 'alphanohtml'); } else { $object->label = $langs->trans("CopyOf").' '.$object->label; } $newdatepayment = dol_mktime(0, 0, 0, GETPOST('clone_date_paymentmonth', 'int'), GETPOST('clone_date_paymentday', 'int'), GETPOST('clone_date_paymentyear', 'int')); $newdatevalue = dol_mktime(0, 0, 0, GETPOST('clone_date_valuemonth', 'int'), GETPOST('clone_date_valueday', 'int'), GETPOST('clone_date_valueyear', 'int')); if ($newdatepayment) { $object->datep = $newdatepayment; } if (!empty($newdatevalue)) { $object->datev = $newdatevalue; } else { $object->datev = $newdatepayment; } if (GETPOSTISSET("clone_sens")) { $object->sens = GETPOST("clone_sens", 'int'); } else { $object->sens = $object->sens; } if (GETPOST("clone_amount", "alpha")) { $object->amount = price2num(GETPOST("clone_amount", "alpha")); } else { $object->amount = price2num($object->amount); } if ($object->check()) { $id = $object->create($user); if ($id > 0) { $db->commit(); $db->close(); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { $id = $originalId; $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } } else { $id = $originalId; $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } } else { $db->rollback(); dol_print_error($db, $object->error); } } /* * View */ $form = new Form($db); if (isModEnabled('accounting')) { $formaccounting = new FormAccounting($db); } if (isModEnabled('project')) { $formproject = new FormProjets($db); } if ($id) { $object = new PaymentVarious($db); $result = $object->fetch($id); if ($result <= 0) { dol_print_error($db); exit; } } $title = $object->ref." - ".$langs->trans('Card'); if ($action == 'create') { $title = $langs->trans("NewVariousPayment"); } $help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen'; llxHeader('', $title, $help_url); $options = array(); // Load bank groups require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php'; $bankcateg = new BankCateg($db); foreach ($bankcateg->fetchAll() as $bankcategory) { $options[$bankcategory->id] = $bankcategory->label; } // Create mode if ($action == 'create') { // Update fields properties in realtime if (!empty($conf->use_javascript_ajax)) { print "\n".''."\n"; } print '
'; print ''; print ''; print ''; print load_fiche_titre($langs->trans("NewVariousPayment"), '', 'object_payment'); print dol_get_fiche_head('', ''); print ''; // Date payment print ''; // Date value for bank print ''; // Label print ''; // Amount print ''; // Bank if (isModEnabled("banque")) { print ''; } // Type payment print '\n"; print ''; // Number if (isModEnabled("banque")) { print ''; print ''."\n"; // Check transmitter print ''; print ''; // Bank name print ''; print ''; } // Accountancy account if (isModEnabled('accounting')) { // TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code print ''; print ''; } else { // For external software print ''; print ''; } // Subledger account if (isModEnabled('accounting')) { print ''; print ''; } else { // For external software print ''; print ''; } // Sens print ''; // Project if (isModEnabled('project')) { $formproject = new FormProjets($db); // Associated project $langs->load("projects"); print ''; } // Other attributes $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Category if (is_array($options) && count($options) && $conf->categorie->enabled) { print ''; } print '
'; print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).''; print $form->selectDate((empty($datep) ?-1 : $datep), "datep", '', '', '', 'add', 1, 1); print '
'; print $form->editfieldkey('DateValue', 'datev', '', $object, 0).''; print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1); print '
'; print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).''; print ''; print '
'; print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).''; print ''; print '
'; print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); print $form->select_comptes($accountid, "accountid", 0, '', 2, '', 0, '', 1); // Show list of main accounts (comptes courants) print '
'.$langs->trans('PaymentMode').''; $form->select_types_paiements($paymenttype, 'paymenttype', '', 2); print "
'.$langs->trans("AccountAccounting").''; print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1); print '
'.$langs->trans("AccountAccounting").''; print '
'.$langs->trans("SubledgerAccount").''; if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, ''); } else { print ''; } print '
'.$langs->trans("SubledgerAccount").''; print '
'; $labelsens = $form->textwithpicto('Sens', $langs->trans("AccountingDirectionHelp")); print $form->editfieldkey($labelsens, 'sens', '', $object, 0, 'string', '', 1).''; $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit")); print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1); print '
'.$langs->trans("Project").''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1); print '
'.$langs->trans("RubriquesTransactions").''; print img_picto('', 'category').Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1); print '
'; print dol_get_fiche_end(); print $form->buttonsSaveCancel(); print '
'; } /* ************************************************************************** */ /* */ /* View mode */ /* */ /* ************************************************************************** */ if ($id) { $alreadyaccounted = $object->getVentilExportCompta(); $head = various_payment_prepare_head($object); // Clone confirmation if ($action === 'clone') { $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp"))); $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit")); $formquestion = array( array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label), array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1), array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1), 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)), array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)), array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens").' '.$set_value_help, 'values' => $sensarray, 'default' => $object->sens), ); print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350); } // Confirmation of the removal of the Various Payment if ($action == 'delete') { $text = $langs->trans('ConfirmDeleteVariousPayment'); print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVariousPayment'), $text, 'confirm_delete', '', '', 2); } print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto); $morehtmlref = '
'; // Project if (isModEnabled('project')) { $langs->load("projects"); $morehtmlref .= $langs->trans('Project').' '; if ($user->rights->banque->modifier) { if ($action != 'classify') { $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; } if ($action == 'classify') { //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); $morehtmlref .= '
'; $morehtmlref .= ''; $morehtmlref .= ''; $morehtmlref .= $formproject->select_projects(0, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= ''; $morehtmlref .= '
'; } else { $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300'); } } else { if (!empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); $morehtmlref .= $proj->getNomUrl(1); } else { $morehtmlref .= ''; } } } $morehtmlref .= '
'; $linkback = ''.$langs->trans("BackToList").''; $morehtmlright = ''; dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); print '
'; print '
'; print ''; // Label print ''; // Payment date print ""; print ''; // Value date print ''; // Debit / Credit if ($object->sens == '1') { $sens = $langs->trans("Credit"); } else { $sens = $langs->trans("Debit"); } print ''; print ''; // Accountancy code print ''; // Subledger account print ''; $bankaccountnotfound = 0; if (isModEnabled('banque')) { print ''; print ''; print ''; print ''; } // Other attributes $parameters = array('socid'=>$object->id); include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; print '
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("DatePayment").''; print dol_print_date($object->datep, 'day'); print '
'.$langs->trans("DateValue").''; print dol_print_date($object->datev, 'day'); print '
'.$langs->trans("Sens").''.$sens.'
'.$langs->trans("Amount").''.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'
'; print $langs->trans("AccountAccounting"); print ''; if (isModEnabled('accounting')) { $accountingaccount = new AccountingAccount($db); $accountingaccount->fetch('', $object->accountancy_code, 1); print $accountingaccount->getNomUrl(0, 1, 1, '', 1); } else { print $object->accountancy_code; } print '
'; print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0); print ''; print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0); print '
'.$langs->trans('BankTransactionLine').''; if ($object->fk_bank > 0) { $bankline = new AccountLine($db); $result = $bankline->fetch($object->fk_bank); if ($result <= 0) { $bankaccountnotfound = 1; } else { print $bankline->getNomUrl(1, 0, 'showall'); } } else { $bankaccountnotfound = 1; print ''.$langs->trans("NoRecordfound").''; } print '
'; print '
'; print '
'; print dol_get_fiche_end(); /* * Action bar */ print '
'."\n"; // TODO // Add button modify // Clone if ($user->rights->banque->modifier) { print '"; } // Delete if (empty($object->rappro) || $bankaccountnotfound) { if (!empty($user->rights->banque->modifier)) { if ($alreadyaccounted) { print ''; } else { print ''; } } else { print ''; } } else { print ''; } print "
"; } // End of page llxFooter(); $db->close();