dolibarr 21.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
4 * Copyright (C) 2013-2024 Alexandre Spangaro <aspangaro@easya.solutions>
5 * Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
6 * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
9 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 *
24 */
30require '../../main.inc.php';
31
32require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array("bills", "accountancy"));
45
46$action = GETPOST('action', 'aZ09');
47$cancel = GETPOST('cancel', 'alpha');
48$backtopage = GETPOST('backtopage', 'alpha');
49
50$codeventil = GETPOSTINT('codeventil');
51$id = GETPOSTINT('id');
52
53// Security check
54if (!isModEnabled('accounting')) {
56}
57if ($user->socid > 0) {
59}
60if (!$user->hasRight('accounting', 'bind', 'write')) {
62}
63
64
65/*
66 * Actions
67 */
68
69if ($action == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) {
70 if (!$cancel) {
71 if ($codeventil < 0) {
72 $codeventil = 0;
73 }
74
75 $sql = " UPDATE ".MAIN_DB_PREFIX."facture_fourn_det";
76 $sql .= " SET fk_code_ventilation = ".((int) $codeventil);
77 $sql .= " WHERE rowid = ".((int) $id);
78
79 $resql = $db->query($sql);
80 if (!$resql) {
81 setEventMessages($db->lasterror(), null, 'errors');
82 } else {
83 setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
84 if ($backtopage) {
85 header("Location: ".$backtopage);
86 exit();
87 }
88 }
89 } else {
90 header("Location: ./lines.php");
91 exit();
92 }
93}
94
95
96
97/*
98 * View
99 */
100$help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
101
102llxHeader("", $langs->trans('FicheVentilation'), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-supplier page-card');
103
104if ($cancel == $langs->trans("Cancel")) {
105 $action = '';
106}
107
108// Create
109$form = new Form($db);
110$facturefournisseur_static = new FactureFournisseur($db);
111$formaccounting = new FormAccounting($db);
112
113if (!empty($id)) {
114 $sql = "SELECT f.ref as ref, f.rowid as facid, l.fk_product, l.description, l.rowid, l.fk_code_ventilation, ";
115 $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label,";
116 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
117 $sql .= " ppe.accountancy_code_buy as code_buy,";
118 } else {
119 $sql .= " p.accountancy_code_buy as code_buy,";
120 }
121 $sql .= " aa.account_number, aa.label";
122 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as l";
123 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
124 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
125 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
126 }
127 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
128 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = l.fk_facture_fourn ";
129 $sql .= " WHERE f.fk_statut > 0 AND l.rowid = ".((int) $id);
130 $sql .= " AND f.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
131
132 dol_syslog("/accounting/supplier/card.php", LOG_DEBUG);
133 $result = $db->query($sql);
134
135 if ($result) {
136 $num_lines = $db->num_rows($result);
137 $i = 0;
138
139 if ($num_lines) {
140 $objp = $db->fetch_object($result);
141
142 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
143 print '<input type="hidden" name="token" value="'.newToken().'">';
144 print '<input type="hidden" name="action" value="ventil">';
145 print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
146
147 print load_fiche_titre($langs->trans('SuppliersVentilation'), '', 'title_accountancy');
148
149 print dol_get_fiche_head();
150
151 print '<table class="border centpercent">';
152
153 // Ref invoice
154 print '<tr><td>'.$langs->trans("BillsSuppliers").'</td>';
155 $facturefournisseur_static->ref = $objp->ref;
156 $facturefournisseur_static->id = $objp->facid;
157 print '<td>'.$facturefournisseur_static->getNomUrl(1).'</td>';
158 print '</tr>';
159
160 print '<tr><td>'.$langs->trans("Description").'</td>';
161 print '<td>'.dolPrintHTML($objp->description).'</td></tr>';
162
163 print '<tr><td>'.$langs->trans("ProductLabel").'</td>';
164 print '<td>'.dol_trunc($objp->product_label, 24).'</td></tr>';
165
166 print '<tr><td>'.$langs->trans("Account").'</td><td>';
167 print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
168 print '</td></tr>';
169
170 print '</table>';
171
172 print dol_get_fiche_end();
173
174 print '<div class="center">';
175 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
176 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
177 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
178 print '</div>';
179
180 print '</form>';
181 } else {
182 print "Error";
183 }
184 } else {
185 print "Error";
186 }
187} else {
188 print "Error ID incorrect";
189}
190
191// End of page
192llxFooter();
193$db->close();
$id
Definition account.php:48
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage suppliers invoices.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.