* Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2013-2024 Alexandre Spangaro * Copyright (C) 2024 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/accountancy/customer/card.php * \ingroup Accountancy (Double entries) * \brief Card customer ventilation */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Load translation files required by the page $langs->loadLangs(array("bills", "accountancy")); $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); $codeventil = GETPOSTINT('codeventil'); $id = GETPOSTINT('id'); // Security check if (!isModEnabled('accounting')) { accessforbidden(); } if ($user->socid > 0) { accessforbidden(); } if (!$user->hasRight('accounting', 'bind', 'write')) { accessforbidden(); } /* * Actions */ if ($action == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) { if (!$cancel) { if ($codeventil < 0) { $codeventil = 0; } $sql = " UPDATE ".MAIN_DB_PREFIX."facturedet"; $sql .= " SET fk_code_ventilation = ".((int) $codeventil); $sql .= " WHERE rowid = ".((int) $id); $resql = $db->query($sql); if (!$resql) { setEventMessages($db->lasterror(), null, 'errors'); } else { setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); if ($backtopage) { header("Location: ".$backtopage); exit(); } } } else { header("Location: ./lines.php"); exit(); } } /* * View */ $help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Liaisons_comptables'; llxHeader("", $langs->trans('FicheVentilation'), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-customer page-card'); if ($cancel == $langs->trans("Cancel")) { $action = ''; } /* * Create */ $form = new Form($db); $facture_static = new Facture($db); $formaccounting = new FormAccounting($db); if (!empty($id)) { $sql = "SELECT f.ref, f.rowid as facid, l.fk_product, l.description, l.price,"; $sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.fk_code_ventilation,"; $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label,"; if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { $sql .= " ppe.accountancy_code_sell as code_sell,"; } else { $sql .= " p.accountancy_code_sell as code_sell,"; } $sql .= " aa.account_number, aa.label"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product"; if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON l.fk_code_ventilation = aa.rowid"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = l.fk_facture"; $sql .= " WHERE f.fk_statut > 0 AND l.rowid = ".((int) $id); $sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy dol_syslog("/accounting/customer/card.php", LOG_DEBUG); $result = $db->query($sql); if ($result) { $num_lines = $db->num_rows($result); $i = 0; if ($num_lines) { $objp = $db->fetch_object($result); print '
'."\n"; print ''; print ''; print ''; print load_fiche_titre($langs->trans('CustomersVentilation'), '', 'title_accountancy'); print dol_get_fiche_head(); print ''; // Ref invoice print ''; $facture_static->ref = $objp->ref; $facture_static->id = $objp->facid; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Invoice").''.$facture_static->getNomUrl(1).'
'.$langs->trans("Description").''.dolPrintHTML($objp->description).'
'.$langs->trans("ProductLabel").''.dol_trunc($objp->product_label, 24).'
'.$langs->trans("Account").''; print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1); print '
'; print dol_get_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } else { print "Error"; } } else { print "Error"; } } else { print "Error ID incorrect"; } // End of page llxFooter(); $db->close();