dolibarr  7.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-2017 Alexandre Spangaro <aspangaro@zendsi.com>
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 <http://www.gnu.org/licenses/>.
18  */
19 
25 require '../../main.inc.php';
26 
27 // Class
28 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
29 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
30 
31 // Langs
32 $langs->load("bills");
33 $langs->load("accountancy");
34 
35 $action = GETPOST('action', 'alpha');
36 $cancel = GETPOST('cancel', 'alpha');
37 $backtopage = GETPOST('backtopage', 'alpha');
38 
39 $codeventil = GETPOST('codeventil');
40 $id = GETPOST('id');
41 
42 // Security check
43 if ($user->societe_id > 0)
45 
46 
47 /*
48  * Actions
49  */
50 
51 if ($action == 'ventil' && $user->rights->accounting->bind->write)
52 {
53  if (! $cancel)
54  {
55  if ($codeventil < 0) $codeventil = 0;
56 
57  $sql = " UPDATE " . MAIN_DB_PREFIX . "facturedet";
58  $sql .= " SET fk_code_ventilation = " . $codeventil;
59  $sql .= " WHERE rowid = " . $id;
60 
61  $resql = $db->query($sql);
62  if (! $resql) {
63  setEventMessages($db->lasterror(), null, 'errors');
64  }
65  else
66  {
67  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
68  if ($backtopage)
69  {
70  header("Location: ".$backtopage);
71  exit();
72  }
73  }
74  } else {
75  header("Location: ./lines.php");
76  exit();
77  }
78 }
79 
80 
81 /*
82  * View
83  */
84 
85 llxHeader("", $langs->trans('FicheVentilation'));
86 
87 if ($cancel == $langs->trans("Cancel")) {
88  $action = '';
89 }
90 
91 /*
92  * Create
93  */
94 $form = new Form($db);
95 $facture_static = new Facture($db);
96 $formaccounting = new FormAccounting($db);
97 
98 if (! empty($id)) {
99  $sql = "SELECT f.facnumber, f.rowid as facid, l.fk_product, l.description, l.price,";
100  $sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, p.accountancy_code_sell as code_sell,";
101  $sql .= " l.fk_code_ventilation, aa.account_number, aa.label";
102  $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as l";
103  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
104  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
105  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = l.fk_facture";
106  $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id;
107  $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy
108 
109  dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG);
110  $result = $db->query($sql);
111 
112  if ($result) {
113  $num_lines = $db->num_rows($result);
114  $i = 0;
115 
116  if ($num_lines) {
117 
118  $objp = $db->fetch_object($result);
119 
120  print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
121  print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
122  print '<input type="hidden" name="action" value="ventil">';
123  print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
124 
125  print load_fiche_titre($langs->trans('CustomersVentilation'), '', 'title_setup');
126 
127  dol_fiche_head();
128 
129  print '<table class="border" width="100%">';
130 
131  // Ref facture
132  print '<tr><td>' . $langs->trans("Invoice") . '</td>';
133  $facture_static->ref = $objp->facnumber;
134  $facture_static->id = $objp->facid;
135  print '<td>' . $facture_static->getNomUrl(1) . '</td>';
136  print '</tr>';
137 
138  print '<tr><td width="20%">' . $langs->trans("Line") . '</td>';
139  print '<td>' . nl2br($objp->description) . '</td></tr>';
140  print '<tr><td width="20%">' . $langs->trans("Account") . '</td><td>';
141  print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
142  print '</td></tr>';
143  print '</table>';
144 
145  dol_fiche_end();
146 
147  print '<div class="center">';
148  print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
149  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
150  print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
151  print '</div>';
152 
153  print '</form>';
154  } else {
155  print "Error";
156  }
157  } else {
158  print "Error";
159  }
160 } else {
161  print "Error ID incorrect";
162 }
163 
164 llxFooter();
165 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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
Class to manage invoices.