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