/
action.change_stock.php
75 lines (67 loc) · 1.76 KB
/
action.change_stock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
##############################################################################
## Cette page incrémente/décrémente le stock ##
##############################################################################
if( !isset($gCms) ) exit;
if (!$this->CheckPermission('Use Commandes'))
{
echo $this->ShowErrors($this->Lang('needpermission'));
return;
}
if( isset($params['cancel']) )
{
$this->RedirectToAdminTab('commandesclients');
return;
}
//debug_display($params, 'Parameters');
$db =& $this->GetDb();
if(isset($params['id_items']) && $params['id_items'] != '')
{
$id_items = $params['id_items'];
}
if(isset($params['record_id']) && $params['record_id'] != '')
{
$record_id = $params['record_id'];
}
else
{
$this->SetMessage('il manque des paramètres !');
$this->RedirectToAdminTab('stock');
}
if(isset($params['qte']))
{
$qte = $params['qte'];
}
if(isset($params['credit']) && $params['credit'] == 'plus')
{
$new_qte = $qte + 1;
}
else
{
$new_qte = $qte - 1;
}
if($new_qte <= 0)
{
$query = "DELETE FROM ".cms_db_prefix()."module_commandes_stock WHERE id = ?";
$dbresult = $db->Execute($query, array($record_id));
}
else
{
//faudrait recalculer le montant du stock restant...
$query1 = "SELECT prix_unitaire FROM ".cms_db_prefix()."module_commandes_items WHERE id = ?";
$dbresult1 = $db->Execute($query1, array($id_items));
$row = $dbresult1->FetchRow();
$prix_unitaire = $row['prix_unitaire'];
$prix_total = $new_qte*$prix_unitaire;
$query = "UPDATE ".cms_db_prefix()."module_commandes_stock SET quantite = ?, prix_total = ? WHERE id = ?";
$dbresult = $db->Execute($query, array($new_qte,$prix_total,$record_id));
}
if($dbresult)
{
$this->SetMessage('Stock modifié');
$this->RedirectToAdminTab('stock');
}
#
#EOF
#
?>