dolibarr  16.0.5
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-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
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  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  *
23  */
29 require '../../main.inc.php';
30 
31 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("bills", "accountancy"));
36 
37 $action = GETPOST('action', 'aZ09');
38 $cancel = GETPOST('cancel', 'alpha');
39 $backtopage = GETPOST('backtopage', 'alpha');
40 
41 $codeventil = GETPOST('codeventil', 'int');
42 $id = GETPOST('id', 'int');
43 
44 // Security check
45 if (!isModEnabled('accounting')) {
47 }
48 if ($user->socid > 0) {
50 }
51 if (empty($user->rights->accounting->mouvements->lire)) {
53 }
54 
55 
56 /*
57  * Actions
58  */
59 
60 if ($action == 'ventil' && $user->rights->accounting->bind->write) {
61  if (!$cancel) {
62  if ($codeventil < 0) {
63  $codeventil = 0;
64  }
65 
66  $sql = " UPDATE ".MAIN_DB_PREFIX."facture_fourn_det";
67  $sql .= " SET fk_code_ventilation = ".((int) $codeventil);
68  $sql .= " WHERE rowid = ".((int) $id);
69 
70  $resql = $db->query($sql);
71  if (!$resql) {
72  setEventMessages($db->lasterror(), null, 'errors');
73  } else {
74  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
75  if ($backtopage) {
76  header("Location: ".$backtopage);
77  exit();
78  }
79  }
80  } else {
81  header("Location: ./lines.php");
82  exit();
83  }
84 }
85 
86 
87 
88 /*
89  * View
90  */
91 llxHeader("", $langs->trans('FicheVentilation'));
92 
93 if ($cancel == $langs->trans("Cancel")) {
94  $action = '';
95 }
96 
97 // Create
98 $form = new Form($db);
99 $facturefournisseur_static = new FactureFournisseur($db);
100 $formaccounting = new FormAccounting($db);
101 
102 if (!empty($id)) {
103  $sql = "SELECT f.ref as ref, f.rowid as facid, l.fk_product, l.description, l.rowid, l.fk_code_ventilation, ";
104  $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label,";
105  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
106  $sql .= " ppe.accountancy_code_buy as code_buy,";
107  } else {
108  $sql .= " p.accountancy_code_buy as code_buy,";
109  }
110  $sql .= " aa.account_number, aa.label";
111  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as l";
112  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
113  if (!empty($conf->global->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_fourn as f ON f.rowid = l.fk_facture_fourn ";
118  $sql .= " WHERE f.fk_statut > 0 AND l.rowid = ".((int) $id);
119  $sql .= " AND f.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
120 
121  dol_syslog("/accounting/supplier/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('SuppliersVentilation'), '', 'title_accountancy');
137 
138  print dol_get_fiche_head();
139 
140  print '<table class="border centpercent">';
141 
142  // ref invoice
143  print '<tr><td>'.$langs->trans("BillsSuppliers").'</td>';
144  $facturefournisseur_static->ref = $objp->ref;
145  $facturefournisseur_static->id = $objp->facid;
146  print '<td>'.$facturefournisseur_static->getNomUrl(1).'</td>';
147  print '</tr>';
148 
149  print '<tr><td width="20%">'.$langs->trans("Line").'</td>';
150  print '<td>'.stripslashes(nl2br($objp->description)).'</td></tr>';
151  print '<tr><td width="20%">'.$langs->trans("ProductLabel").'</td>';
152  print '<td>'.dol_trunc($objp->product_label, 24).'</td>';
153  print '<tr><td width="20%">'.$langs->trans("Account").'</td><td>';
154  print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
155  print '</td></tr>';
156  print '</table>';
157 
158  print dol_get_fiche_end();
159 
160  print '<div class="center">';
161  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
162  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
163  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
164  print '</div>';
165 
166  print '</form>';
167  } else {
168  print "Error";
169  }
170  } else {
171  print "Error";
172  }
173 } else {
174  print "Error ID incorrect";
175 }
176 
177 // End of page
178 llxFooter();
179 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:53
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59