dolibarr 19.0.3
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25require '../../main.inc.php';
26
27require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
29
30// Load translation files required by the page
31$langs->loadLangs(array("bills", "accountancy"));
32
33$action = GETPOST('action', 'aZ09');
34$cancel = GETPOST('cancel', 'alpha');
35$backtopage = GETPOST('backtopage', 'alpha');
36
37$codeventil = GETPOST('codeventil', 'int');
38$id = GETPOST('id', 'int');
39
40// Security check
41if (!isModEnabled('accounting')) {
43}
44if ($user->socid > 0) {
46}
47if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
49}
50
51
52
53/*
54 * Actions
55 */
56
57if ($action == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) {
58 if (!$cancel) {
59 if ($codeventil < 0) {
60 $codeventil = 0;
61 }
62
63 $sql = " UPDATE ".MAIN_DB_PREFIX."facturedet";
64 $sql .= " SET fk_code_ventilation = ".((int) $codeventil);
65 $sql .= " WHERE rowid = ".((int) $id);
66
67 $resql = $db->query($sql);
68 if (!$resql) {
69 setEventMessages($db->lasterror(), null, 'errors');
70 } else {
71 setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
72 if ($backtopage) {
73 header("Location: ".$backtopage);
74 exit();
75 }
76 }
77 } else {
78 header("Location: ./lines.php");
79 exit();
80 }
81}
82
83
84/*
85 * View
86 */
87$help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
88
89llxHeader("", $langs->trans('FicheVentilation'), $help_url);
90
91if ($cancel == $langs->trans("Cancel")) {
92 $action = '';
93}
94
95/*
96 * Create
97 */
98$form = new Form($db);
99$facture_static = new Facture($db);
100$formaccounting = new FormAccounting($db);
101
102if (!empty($id)) {
103 $sql = "SELECT f.ref, f.rowid as facid, l.fk_product, l.description, l.price,";
104 $sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,";
105 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
106 $sql .= " ppe.accountancy_code_sell as code_sell,";
107 } else {
108 $sql .= " p.accountancy_code_sell as code_sell,";
109 }
110 $sql .= " l.fk_code_ventilation, aa.account_number, aa.label";
111 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
112 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
113 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
114 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
115 }
116 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
117 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = l.fk_facture";
118 $sql .= " WHERE f.fk_statut > 0 AND l.rowid = ".((int) $id);
119 $sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
120
121 dol_syslog("/accounting/customer/card.php", LOG_DEBUG);
122 $result = $db->query($sql);
123
124 if ($result) {
125 $num_lines = $db->num_rows($result);
126 $i = 0;
127
128 if ($num_lines) {
129 $objp = $db->fetch_object($result);
130
131 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
132 print '<input type="hidden" name="token" value="'.newToken().'">';
133 print '<input type="hidden" name="action" value="ventil">';
134 print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
135
136 print load_fiche_titre($langs->trans('CustomersVentilation'), '', 'title_accountancy');
137
138 print dol_get_fiche_head();
139
140 print '<table class="border centpercent">';
141
142 // Ref facture
143 print '<tr><td>'.$langs->trans("Invoice").'</td>';
144 $facture_static->ref = $objp->ref;
145 $facture_static->id = $objp->facid;
146 print '<td>'.$facture_static->getNomUrl(1).'</td>';
147 print '</tr>';
148
149 print '<tr><td width="20%">'.$langs->trans("Line").'</td>';
150 print '<td>'.nl2br($objp->description).'</td></tr>';
151 print '<tr><td width="20%">'.$langs->trans("Account").'</td><td>';
152 print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
153 print '</td></tr>';
154 print '</table>';
155
156 print dol_get_fiche_end();
157
158 print '<div class="center">';
159 print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
160 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
161 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
162 print '</div>';
163
164 print '</form>';
165 } else {
166 print "Error";
167 }
168 } else {
169 print "Error";
170 }
171} else {
172 print "Error ID incorrect";
173}
174
175// End of page
176llxFooter();
177$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.