bonjour je cherche a compter deux tva différente dans cette exemple:
SousTotal: 1626
totaltva 5.5 : 16,2
Totaltav 19,6: 98
Total:1003
Bien sur il ne faut tenir en compte des chiffres que j'ai mis au azard.
Version imprimable
bonjour je cherche a compter deux tva différente dans cette exemple:
SousTotal: 1626
totaltva 5.5 : 16,2
Totaltav 19,6: 98
Total:1003
Bien sur il ne faut tenir en compte des chiffres que j'ai mis au azard.
Et la question est ???
désoler !!! il été tard
je cherche a récupérer la tva de différent produits qui aurai des tva différente
ex:
1 produit prix 100€HT tva 19.6 montant de la tva 19,6€
total TTC 119,6€ TTC
1 produit prix 100€HT tva 5,5 montant de la tva 5,5€
total TTC 105,5€ TTC
et de mettre le tva dans un dans un total
Total TVA 19,6 = 19,6
Total TVA 5,5 = 5,5
voici le shema:
tous passe par la sessionCode:
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 Produit: actAs: DmSortable: I18n: fields: [ ref,name,stocks,indices, contents, is_active ] Timestampable: ~ Sluggable: fields: [name] unique: true Searchable: fields: [name, code] columns: tarifsdegresif_id: { type: integer } tva_id: { type: integer , notnull : true} tarif: { type: float, notnull: true } ref: { type: string(155), notnull: true } quantity: { type: integer, notnull: true } name: { type: string(100), notnull: true } contents: { type: clob, extra: markdown } author: { type: integer, notnull: true } is_active: { type: boolean, notnull: true, default: false } image: { type: integer } stocks: { type: boolean, notnull: false , default: 1 } commentaire: { type: string(100), notnull: false } relations: Image: class: DmMedia local: image foreignAlias: Produits Author: class: DmUser local: author foreignAlias: Produits Groups: class: DmGroup local: produit_id foreign: dm_group_id refClass: DmUserGroup2 foreignAlias: Produits Tva: { onDelete: CASCADE, local: tva_id, foreign: id, foreignAlias: Produits } Tarifsdegresif: { onDelete: CASCADE, local: tarifsdegresif_id, foreign: id, foreignAlias: Produits } Marque: { class: Marque, local: produit_id, foreign: marque_id, refClass: ProduitMarque, foreignAlias: Produits } Tva: actAs: Timestampable: DmVersionable: columns: indices: { type: float, notnull: true } is_active: { type: boolean, notnull: true, default: false }
l'idée est:
si j'ai un produit id tva 1 envoie a total tva1 la tva
mais je vois pas comment faire, si quelqu'un a un exemple
je passe mon produit en session
ca me donne bien le produit avec le tva mes comment faire pour calcul le total des tva par tvaCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 $cart = $this->getUser()->getAttribute('cart', new cartCore()); public function get_contents() { $items = array(); foreach($this->items as $tmp_item) { $item = FALSE; $item['id'] = $tmp_item; $item['qty'] = $this->itemqtys[$tmp_item]; $item['tarif'] = $this->itemprices[$tmp_item]; $item['name'] = $this->itemname[$tmp_item]; $item['tva'] = $this->itemtvas[$tmp_item]; $item['tva_id'] = $tmp_tva; $item['subtotal'] = $item['qty'] * $item['tarif']; $item['totaltva'] = $item['tarif'] * $item['tva']/100; $items[] = $item; } return $items; }
Déjà il est déconseiller de mettre en session un objet quelconque car derrière ça prends de la place sur le serveur, la session n'a plus de limite de taille, etc. en plus si tu veux avoir 2 onglets ouvert tu vas faire des conflits et interagir sur les mauvaises données (c'est mon point de vue).
Ensuite, je ne comprends pas ton exemple car tu set un $car que tu n'utilise pas du tout.
Et je ne vois pas le problème réel, car si tu as le produit, tu as donc ça TVA, tu fais le calcul et tu as le coût de la TVA.
Qu'est ce que tu n'arrive pas a faire ?
en faite je n'arrive pas a additionner la tva des produit en fonction de id tva
ex : tous les produit qui a la tva 19.6 (tva_id =1)
done un total de tva a 19,6 ex: 1234
pour ce qui etais du code je voulais faire simple alors voici le code au comple
fiche action:
fichier cartCoreCode:
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 public function executeCheckout(sfWebRequest $request) { $cart = $this->getUser()->getAttribute('cart', new cartCore()); if ($request->getParameter('update_cart')) { $qty = $request->getParameter('itemqty'); $id = $request->getParameter('itemid'); if (($qty != null) and ($id != null)) { $product = Doctrine::getTable('produit')->createQuery('a')->where('id=' . $id)->execute(); ///////////////////SECTION NOT WORKING //TODO: Cart quantities update properly, but there are no errors when requesting more than available stock. $qtyInStock = $product[0]['quantity']; if ($qtyInStock < $qty) { $cart->qtyerror = "Sorry, there are only " . $qtyInStock . " " . $product[0]['name'] . " left in stock."; } else { $cart->update_item($id, $qty); $this->redirect($request->getReferer()); } } } else if ($request->getParameter('terminer')) { $qty = $request->getParameter('itemqty'); $id = $request->getParameter('itemid'); $tva = $request->getParameter('producttva'); $price = $request->getParameter('productprice'); $status = 1; $us = $this->getUser()->getGuardUser()->getId(); $commandes = new Commandes(); $commandes->setDmUserId($us); $commandes->setStatusId($status); $commandes->save(); $d = $commandes->id; foreach ($cart->get_contents() as $item) { $achat = new achat(); $achat->setProduitId($item["id"]); $achat->setCommandesId($d); $qtc = $achat->setQuantity($item["qty"]); $achat->setTotalprix($item["qty"] * $item['tarif']); $achat->save(); } $cart->empty_cart(); $this->redirect('/thankyou?' . http_build_query($params)); } }
Code:
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236 <?php class cartCore { //Cart Item Data private $items = array(); private $itemprices = array(); private $itemqtys = array(); private $itemname = array(); private $tvaid = array(); private $itemtvas = array(); private $itemtvas2 = array(); private $tvas = array(); private $photopath = array(); private $weights = array(); private $urls = array(); private $counttva1 = array(); private $total = 0; private $itemcount = 0; private $selectedQuoteAmount = 0; public $agreed = false; public $agreeshown = false; //Properties public function getTotal() { return ($this->total*(1 + $this->tax_percentage/100)) + $this->selectedQuoteAmount - $this->coupondiscount; } public function getSubTotal() { return $this->total; } public function getItemCount() { return $this->itemcount; } public function getTva() { return $this->tvas; } public function getTvacount() { return $this->counttva1; } public function getTax() { return $this->tax_percentage; } public function getTotaltva() { return $this->totaltva; } //returns cart contents in array format public function get_contents() { $items = array(); foreach($this->items as $tmp_item) { $item = FALSE; $item['id'] = $tmp_item; $item['qty'] = $this->itemqtys[$tmp_item]; $item['tarif'] = $this->itemprices[$tmp_item]; $item['name'] = $this->itemname[$tmp_item]; $item['tva'] = $this->itemtvas[$tmp_item]; $item['tva_id'] = $item_tva_id; $item['subtotal'] = $item['qty'] * $item['tarif']; $item['totaltva'] = $item['tarif'] * $item['tva']/100; $items[] = $item; } return $items; } public function refresh_shipping_quotes() { $this->processZipCode($this->zipcode); //US //$this->processPostalCode($this->zipcode); //Canada } //Reset cart data private function reset_cart() { $this->empty_cart(); unset($this->quotes); $this->totalWeight = 0; $this->zipcode = ""; $this->state = ""; $this->validatedaddress = ""; $this->tax_percentage = 0; $this->selectedQuoteAmount = 0; $this->agreed = false; $this->agreeshown = false; $this->coupondiscount = 0; $this->couponcode = ""; } //Add item to cart public function add_item($item_id, $item_qty=1, $item_price, $item_name, $item_tva, $item_tva_id) { $valid_item_qty = $valid_item_price = false; if (preg_match("/^[0-9-]+$/i", $item_qty)) { $valid_item_qty = true; } if (is_numeric($item_price)){ $valid_item_price = true; } if ($item_tva_id) { } if ($valid_item_qty !== false && $valid_item_price !== false) { //if already in cart, increment quantity if (isset($this->itemqtys[$item_id]) && ($this->itemqtys[$item_id] > 0)) { $this->itemqtys[$item_id] = $item_qty + $this->itemqtys[$item_id]; $this->_update_total(); } //new item else { $this->items[] = $item_id; $this->itemqtys[$item_id] = $item_qty; $this->itemprices[$item_id] = $item_price; $this->itemname[$item_id] = $item_name; $this->itemtvas2[] = $item_tva_id; $this->itemtvas[$item_tva_id] = $item_tva; // $this->itemtvas_id[$item_id] = $item_tva; } unset($this->quotes); $this->_update_total(); sfContext::getInstance()->getUser()->setAttribute('cart', $this); return true; } else if ($valid_item_qty !== true) { $error_type = 'qty'; return $error_type; } else if ($valid_item_price !== true) { $error_type = 'tarif'; return $error_type; } else { $error_type = "qty"; return $error_type; } } //Update item already in carte public function update_item($item_id, $item_qty) { if (preg_match("/^[0-9-]+$/i", $item_qty)) { if($item_qty < 1){ $this->del_item($item_id); } else{ $this->itemqtys[$item_id] = $item_qty;} unset($this->quotes); $this->_update_total(); return true; } else { return false; } } //Remove item from cart public function del_item($item_id) { $ti = array(); $this->itemqtys[$item_id] = 0; foreach($this->items as $item) { if($item != $item_id) { $ti[] = $item;} } $this->items = $ti; unset($this->quotes); $this->_update_total(); } //Remove all cart items public function empty_cart() { $this->total = 0; $this->itemcount = 0; $this->items = array(); $this->itemprices = array(); $this->itemqtys = array(); $this->itemname = array(); $this->itemtvas = array(); } public function add_tva($item_id,$item_tva,$item_price){ ; ; } //Update the cart totals private function _update_total() { $this->itemcount = 0; $this->total = 0; // $this->totalWeight = 0; if(sizeof($this->items > 0)) { foreach($this->items as $item) { count($this->items); $this->total = ($this->itemprices[$item] * $this->itemqtys[$item]); $this->itemcount = $this->itemqtys[$item]; $this->tvas = $this->itemtvas[$item]; // } } } } } ?>