dolibarr  7.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-2017 Alexandre Spangaro <aspangaro@zendsi.com>
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 <http://www.gnu.org/licenses/>.
22  *
23  */
29 require '../../main.inc.php';
30 
31 // Class
32 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
34 
35 // Langs
36 $langs->load("bills");
37 $langs->load("accountancy");
38 
39 $action = GETPOST('action', 'alpha');
40 $cancel = GETPOST('cancel', 'alpha');
41 $backtopage = GETPOST('backtopage', 'alpha');
42 
43 $codeventil = GETPOST('codeventil');
44 $id = GETPOST('id');
45 
46 // Security check
47 if ($user->societe_id > 0)
49 
50 
51 /*
52  * Actions
53  */
54 
55 if ($action == 'ventil' && $user->rights->accounting->bind->write)
56 {
57  if (! $cancel)
58  {
59  if ($codeventil < 0) $codeventil = 0;
60 
61  $sql = " UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det";
62  $sql .= " SET fk_code_ventilation = " . $codeventil;
63  $sql .= " WHERE rowid = " . $id;
64 
65  $resql = $db->query($sql);
66  if (! $resql) {
67  setEventMessages($db->lasterror(), null, 'errors');
68  }
69  else
70  {
71  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
72  if ($backtopage)
73  {
74  header("Location: ".$backtopage);
75  exit();
76  }
77  }
78  } else {
79  header("Location: ./lines.php");
80  exit();
81  }
82 }
83 
84 
85 
86 /*
87  * View
88  */
89 llxHeader("", $langs->trans('FicheVentilation'));
90 
91 if ($cancel == $langs->trans("Cancel")) {
92  $action = '';
93 }
94 
95 // Create
96 $form = new Form($db);
97 $facturefournisseur_static = new FactureFournisseur($db);
98 $formaccounting = new FormAccounting($db);
99 
100 if (! empty($id)) {
101  $sql = "SELECT f.ref as facnumber, f.rowid as facid, l.fk_product, l.description, l.rowid, l.fk_code_ventilation, ";
102  $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label";
103  $sql .= ", aa.account_number, aa.label";
104  $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as l";
105  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
106  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
107  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = l.fk_facture_fourn ";
108  $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id;
109  $sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy
110 
111  dol_syslog("/accounting/supplier/card.php sql=" . $sql, LOG_DEBUG);
112  $result = $db->query($sql);
113 
114  if ($result) {
115  $num_lines = $db->num_rows($result);
116  $i = 0;
117 
118  if ($num_lines) {
119  $objp = $db->fetch_object($result);
120 
121  print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
122  print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
123  print '<input type="hidden" name="action" value="ventil">';
124  print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
125 
126  print load_fiche_titre($langs->trans('SuppliersVentilation'), '', 'title_setup');
127 
128  dol_fiche_head();
129 
130  print '<table class="border" width="100%">';
131 
132  // ref invoice
133  print '<tr><td>' . $langs->trans("BillsSuppliers") . '</td>';
134  $facturefournisseur_static->ref = $objp->facnumber;
135  $facturefournisseur_static->id = $objp->facid;
136  print '<td>' . $facturefournisseur_static->getNomUrl(1) . '</td>';
137  print '</tr>';
138 
139  print '<tr><td width="20%">' . $langs->trans("Line") . '</td>';
140  print '<td>' . stripslashes(nl2br($objp->description)) . '</td></tr>';
141  print '<tr><td width="20%">' . $langs->trans("ProductLabel") . '</td>';
142  print '<td>' . dol_trunc($objp->product_label, 24) . '</td>';
143  print '<tr><td width="20%">' . $langs->trans("Account") . '</td><td>';
144  print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
145  print '</td></tr>';
146  print '</table>';
147 
148  dol_fiche_end();
149 
150  print '<div class="center">';
151  print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
152  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
153  print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
154  print '</div>';
155 
156  print '</form>';
157  } else {
158  print "Error";
159  }
160  } else {
161  print "Error";
162  }
163 } else {
164  print "Error ID incorrect";
165 }
166 
167 llxFooter();
168 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
Class to manage suppliers invoices.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
print
Draft customers invoices.
Definition: index.php:91
Class to manage generation of HTML components for accounting management.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013