* * 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. */ /** * \file bankimport/card.php * \ingroup bankimport * \brief Card page for a single bank transaction */ // Load Dolibarr environment $res = 0; if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; } if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; } if (!$res && file_exists("../main.inc.php")) { $res = @include "../main.inc.php"; } if (!$res && file_exists("../../main.inc.php")) { $res = @include "../../main.inc.php"; } if (!$res) { die("Include of main fails"); } require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; dol_include_once('/bankimport/class/banktransaction.class.php'); dol_include_once('/bankimport/lib/bankimport.lib.php'); /** * @var Conf $conf * @var DoliDB $db * @var Translate $langs * @var User $user */ $langs->loadLangs(array("bankimport@bankimport", "banks", "bills")); $id = GETPOSTINT('id'); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); // Security check if (!$user->hasRight('bankimport', 'read')) { accessforbidden(); } /* * Actions */ $object = new BankImportTransaction($db); if ($id > 0 || !empty($ref)) { $result = $object->fetch($id, $ref); if ($result <= 0) { setEventMessages($langs->trans("RecordNotFound"), null, 'errors'); } } // Set status if ($action == 'setstatus' && $object->id > 0) { $newstatus = GETPOSTINT('status'); $result = $object->setStatus($newstatus, $user); if ($result > 0) { setEventMessages($langs->trans("StatusUpdated"), null, 'mesgs'); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else { setEventMessages($object->error, null, 'errors'); } } // Find matches if ($action == 'findmatches' && $object->id > 0) { $matches = $object->findMatches(); if (count($matches) > 0) { $_SESSION['bankimport_matches_'.$object->id] = $matches; setEventMessages($langs->trans("MatchesFound", count($matches)), null, 'mesgs'); } else { setEventMessages($langs->trans("NoMatchesFound"), null, 'warnings'); } } // Link to object if ($action == 'linkto' && $object->id > 0) { $linktype = GETPOST('linktype', 'alpha'); $linkid = GETPOSTINT('linkid'); if ($linktype && $linkid > 0) { $result = $object->linkTo($linktype, $linkid, $user); if ($result > 0) { setEventMessages($langs->trans("LinkCreated"), null, 'mesgs'); unset($_SESSION['bankimport_matches_'.$object->id]); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else { setEventMessages($object->error, null, 'errors'); } } } /* * View */ $form = new Form($db); $title = $langs->trans("Transaction").' - '.$object->ref; llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-bankimport page-card'); if ($object->id > 0) { print '
'; // Title print load_fiche_titre($langs->trans("Transaction"), '', 'bank'); // Card header print '
'; print ''; // Reference print ''; print ''; print ''; print ''; // IBAN print ''; print ''; print ''; print ''; // Date print ''; print ''; print ''; print ''; // Value date if ($object->date_value) { print ''; print ''; print ''; print ''; } // Name print ''; print ''; print ''; print ''; // Counterparty IBAN if ($object->counterparty_iban) { print ''; print ''; print ''; print ''; } // Amount print ''; print ''; print ''; print ''; // Label if ($object->label) { print ''; print ''; print ''; print ''; } // Description print ''; print ''; print ''; print ''; // End-to-End ID if ($object->end_to_end_id) { print ''; print ''; print ''; print ''; } // Mandate ID if ($object->mandate_id) { print ''; print ''; print ''; print ''; } // Status print ''; print ''; print ''; print ''; // Linked invoice if ($object->fk_facture > 0) { require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $invoice = new Facture($db); $invoice->fetch($object->fk_facture); print ''; print ''; print ''; print ''; } // Linked supplier invoice if ($object->fk_facture_fourn > 0) { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; $invoice = new FactureFournisseur($db); $invoice->fetch($object->fk_facture_fourn); print ''; print ''; print ''; print ''; } // Linked PDF statement if (!empty($object->fk_statement)) { dol_include_once('/bankimport/class/bankstatement.class.php'); $stmt = new BankImportStatement($db); $stmt->fetch($object->fk_statement); print ''; print ''; print ''; print ''; } // Linked third party if ($object->fk_societe > 0) { require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $soc = new Societe($db); $soc->fetch($object->fk_societe); print ''; print ''; print ''; print ''; } // Import date print ''; print ''; print ''; print ''; print '
'.$langs->trans("Ref").''.dol_escape_htmltag($object->ref).'
'.$langs->trans("AccountIBAN").''.dol_escape_htmltag($object->iban).'
'.$langs->trans("Date").''.dol_print_date($object->date_trans, 'day').'
'.$langs->trans("DateValue").''.dol_print_date($object->date_value, 'day').'
'.$langs->trans("Counterparty").''.dol_escape_htmltag($object->name).'
'.$langs->trans("CounterpartyIBAN").''.dol_escape_htmltag($object->counterparty_iban).'
'.$langs->trans("Amount").''; if ($object->amount >= 0) { print '+'.price($object->amount, 0, $langs, 1, -1, 2, $object->currency).''; } else { print ''.price($object->amount, 0, $langs, 1, -1, 2, $object->currency).''; } print '
'.$langs->trans("Label").''.dol_escape_htmltag($object->label).'
'.$langs->trans("Description").''.nl2br(dol_escape_htmltag($object->description)).'
'.$langs->trans("EndToEndId").''.dol_escape_htmltag($object->end_to_end_id).'
'.$langs->trans("MandateId").''.dol_escape_htmltag($object->mandate_id).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("Invoice").''.$invoice->getNomUrl(1).'
'.$langs->trans("SupplierInvoice").''.$invoice->getNomUrl(1).'
'.$langs->trans("PDFStatement").''; print ''; print img_picto($langs->trans("ViewPDFStatement"), 'pdf').' '; print $langs->trans("StatementNumber").' '.$stmt->statement_number.'/'.$stmt->statement_year; print ''; if ($stmt->date_from && $stmt->date_to) { print ' ('.dol_print_date($stmt->date_from, 'day').' - '.dol_print_date($stmt->date_to, 'day').')'; } print '
'.$langs->trans("ThirdParty").''.$soc->getNomUrl(1).'
'.$langs->trans("DateCreation").''.dol_print_date($object->datec, 'dayhour').'
'; print '
'; // Actions buttons print '
'; if ($object->status == BankImportTransaction::STATUS_NEW) { // Find matches button print ''.$langs->trans("FindMatches").''; // Set as ignored print ''.$langs->trans("SetAsIgnored").''; } if ($object->status == BankImportTransaction::STATUS_IGNORED) { // Reopen print ''.$langs->trans("Reopen").''; } print '
'; // Show matches if found $matches = $_SESSION['bankimport_matches_'.$object->id] ?? array(); if (!empty($matches)) { print '
'; print load_fiche_titre($langs->trans("MatchesFound", count($matches)), '', 'object_invoice'); print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Translate match reasons $reasonLabels = array( 'ref' => $langs->trans("MatchByRef"), 'ref_client' => $langs->trans("MatchByClientRef"), 'ref_supplier' => $langs->trans("MatchBySupplierRef"), 'amount' => $langs->trans("MatchByAmount"), 'amount_close' => $langs->trans("MatchByAmountClose"), 'name_exact' => $langs->trans("MatchByNameExact"), 'name_similar' => $langs->trans("MatchByNameSimilar"), 'iban' => $langs->trans("MatchByIBAN") ); foreach ($matches as $match) { print ''; print ''; // Get invoice link if ($match['type'] == 'facture') { require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $inv = new Facture($db); $inv->fetch($match['id']); print ''; } else { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; $inv = new FactureFournisseur($db); $inv->fetch($match['id']); print ''; } // Third party with link if ($match['socid'] > 0) { require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $soc = new Societe($db); $soc->fetch($match['socid']); print ''; } else { print ''; } print ''; print ''; // Score with color $scoreColor = $match['match_score'] >= 80 ? 'green' : ($match['match_score'] >= 60 ? 'orange' : 'gray'); print ''; // Match reasons as badges print ''; print ''; print ''; } print '
'.$langs->trans("Type").''.$langs->trans("Ref").''.$langs->trans("ThirdParty").''.$langs->trans("Amount").''.$langs->trans("DateDue").''.$langs->trans("Score").''.$langs->trans("MatchReason").'
'.($match['type'] == 'facture' ? $langs->trans("Invoice") : $langs->trans("SupplierInvoice")).''.$inv->getNomUrl(1).''.$inv->getNomUrl(1).''.$soc->getNomUrl(1).''.dol_escape_htmltag($match['socname']).''.price($match['amount'], 0, $langs, 1, -1, 2, 'EUR').''.($match['date_due'] ? dol_print_date($match['date_due'], 'day') : '-').''.$match['match_score'].'%'; if (!empty($match['match_reasons'])) { foreach ($match['match_reasons'] as $reason) { $label = $reasonLabels[$reason] ?? $reason; print ''.$label.' '; } } print ''; print ''.$langs->trans("Link").''; print '
'; print '
'; } } else { print '
'.$langs->trans("RecordNotFound").'
'; } // Back link print '
'; print ''.$langs->trans("BackToList").''; print '
'; llxFooter(); $db->close();