dolibarr  17.0.4
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-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 
25 require '../../main.inc.php';
26 
27 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
28 require_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
41 if (!isModEnabled('accounting')) {
43 }
44 if ($user->socid > 0) {
46 }
47 if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
49 }
50 
51 
52 
53 /*
54  * Actions
55  */
56 
57 if ($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 
88 llxHeader("", $langs->trans('FicheVentilation'));
89 
90 if ($cancel == $langs->trans("Cancel")) {
91  $action = '';
92 }
93 
94 /*
95  * Create
96  */
97 $form = new Form($db);
98 $facture_static = new Facture($db);
99 $formaccounting = new FormAccounting($db);
100 
101 if (!empty($id)) {
102  $sql = "SELECT f.ref, f.rowid as facid, l.fk_product, l.description, l.price,";
103  $sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,";
104  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
105  $sql .= " ppe.accountancy_code_sell as code_sell,";
106  } else {
107  $sql .= " p.accountancy_code_sell as code_sell,";
108  }
109  $sql .= " l.fk_code_ventilation, aa.account_number, aa.label";
110  $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
111  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
112  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
113  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
114  }
115  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
116  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = l.fk_facture";
117  $sql .= " WHERE f.fk_statut > 0 AND l.rowid = ".((int) $id);
118  $sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
119 
120  dol_syslog("/accounting/customer/card.php", LOG_DEBUG);
121  $result = $db->query($sql);
122 
123  if ($result) {
124  $num_lines = $db->num_rows($result);
125  $i = 0;
126 
127  if ($num_lines) {
128  $objp = $db->fetch_object($result);
129 
130  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
131  print '<input type="hidden" name="token" value="'.newToken().'">';
132  print '<input type="hidden" name="action" value="ventil">';
133  print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
134 
135  print load_fiche_titre($langs->trans('CustomersVentilation'), '', 'title_accountancy');
136 
137  print dol_get_fiche_head();
138 
139  print '<table class="border centpercent">';
140 
141  // Ref facture
142  print '<tr><td>'.$langs->trans("Invoice").'</td>';
143  $facture_static->ref = $objp->ref;
144  $facture_static->id = $objp->facid;
145  print '<td>'.$facture_static->getNomUrl(1).'</td>';
146  print '</tr>';
147 
148  print '<tr><td width="20%">'.$langs->trans("Line").'</td>';
149  print '<td>'.nl2br($objp->description).'</td></tr>';
150  print '<tr><td width="20%">'.$langs->trans("Account").'</td><td>';
151  print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
152  print '</td></tr>';
153  print '</table>';
154 
155  print dol_get_fiche_end();
156 
157  print '<div class="center">';
158  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
159  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
160  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
161  print '</div>';
162 
163  print '</form>';
164  } else {
165  print "Error";
166  }
167  } else {
168  print "Error";
169  }
170 } else {
171  print "Error ID incorrect";
172 }
173 
174 // End of page
175 llxFooter();
176 $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:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
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.