dolibarr 21.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
4 * Copyright (C) 2013-2024 Alexandre Spangaro <aspangaro@easya.solutions>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26require '../../main.inc.php';
27
28require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
30
39// Load translation files required by the page
40$langs->loadLangs(array("bills", "accountancy"));
41
42$action = GETPOST('action', 'aZ09');
43$cancel = GETPOST('cancel', 'alpha');
44$backtopage = GETPOST('backtopage', 'alpha');
45
46$codeventil = GETPOSTINT('codeventil');
47$id = GETPOSTINT('id');
48
49// Security check
50if (!isModEnabled('accounting')) {
52}
53if ($user->socid > 0) {
55}
56if (!$user->hasRight('accounting', 'bind', 'write')) {
58}
59
60
61
62/*
63 * Actions
64 */
65
66if ($action == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) {
67 if (!$cancel) {
68 if ($codeventil < 0) {
69 $codeventil = 0;
70 }
71
72 $sql = " UPDATE ".MAIN_DB_PREFIX."facturedet";
73 $sql .= " SET fk_code_ventilation = ".((int) $codeventil);
74 $sql .= " WHERE rowid = ".((int) $id);
75
76 $resql = $db->query($sql);
77 if (!$resql) {
78 setEventMessages($db->lasterror(), null, 'errors');
79 } else {
80 setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
81 if ($backtopage) {
82 header("Location: ".$backtopage);
83 exit();
84 }
85 }
86 } else {
87 header("Location: ./lines.php");
88 exit();
89 }
90}
91
92
93/*
94 * View
95 */
96$help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
97
98llxHeader("", $langs->trans('FicheVentilation'), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-customer page-card');
99
100if ($cancel == $langs->trans("Cancel")) {
101 $action = '';
102}
103
104/*
105 * Create
106 */
107$form = new Form($db);
108$facture_static = new Facture($db);
109$formaccounting = new FormAccounting($db);
110
111if (!empty($id)) {
112 $sql = "SELECT f.ref, f.rowid as facid, l.fk_product, l.description, l.price,";
113 $sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.fk_code_ventilation,";
114 $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label,";
115 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
116 $sql .= " ppe.accountancy_code_sell as code_sell,";
117 } else {
118 $sql .= " p.accountancy_code_sell as code_sell,";
119 }
120 $sql .= " aa.account_number, aa.label";
121 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
122 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
123 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
124 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
125 }
126 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
127 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = l.fk_facture";
128 $sql .= " WHERE f.fk_statut > 0 AND l.rowid = ".((int) $id);
129 $sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
130
131 dol_syslog("/accounting/customer/card.php", LOG_DEBUG);
132 $result = $db->query($sql);
133
134 if ($result) {
135 $num_lines = $db->num_rows($result);
136 $i = 0;
137
138 if ($num_lines) {
139 $objp = $db->fetch_object($result);
140
141 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
142 print '<input type="hidden" name="token" value="'.newToken().'">';
143 print '<input type="hidden" name="action" value="ventil">';
144 print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
145
146 print load_fiche_titre($langs->trans('CustomersVentilation'), '', 'title_accountancy');
147
148 print dol_get_fiche_head();
149
150 print '<table class="border centpercent">';
151
152 // Ref invoice
153 print '<tr><td>'.$langs->trans("Invoice").'</td>';
154 $facture_static->ref = $objp->ref;
155 $facture_static->id = $objp->facid;
156 print '<td>'.$facture_static->getNomUrl(1).'</td>';
157 print '</tr>';
158
159 print '<tr><td>'.$langs->trans("Description").'</td>';
160 print '<td>'.dolPrintHTML($objp->description).'</td></tr>';
161
162 print '<tr><td>'.$langs->trans("ProductLabel").'</td>';
163 print '<td>'.dol_trunc($objp->product_label, 24).'</td></tr>';
164
165 print '<tr><td>'.$langs->trans("Account").'</td><td>';
166 print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
167 print '</td></tr>';
168
169 print '</table>';
170
171 print dol_get_fiche_end();
172
173 print '<div class="center">';
174 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
175 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
176 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
177 print '</div>';
178
179 print '</form>';
180 } else {
181 print "Error";
182 }
183 } else {
184 print "Error";
185 }
186} else {
187 print "Error ID incorrect";
188}
189
190// End of page
191llxFooter();
192$db->close();
$id
Definition account.php:48
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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 invoices.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
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.