Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 829 | Revision 853 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
381 lars 1
<?php
2
 
383 lars 3
    namespace App\Http\Controllers;
381 lars 4
 
829 lars 5
    use App\Models\Item as ItemAlias;
817 lars 6
    use App\Http\Controllers\ShippingController;
719 lars 7
 
728 lars 8
    class BasketController extends Controller
383 lars 9
    {
713 lars 10
        public array $items         = array();
11
        public array $paymentInfo   = array();
12
        public array $shipmentCosts = array();
697 lars 13
 
714 lars 14
        public array $paymentMethods = array();
15
 
383 lars 16
        //
705 lars 17
        private function getPaymentInfo(): void
701 lars 18
        {
19
            $buffer = array(
20
                "itemAmt"      => array(
21
 
22
                    1 => 0.00,
23
                ),
24
                "itemAmtNetto" => array(
25
 
26
                    1 => 0.00,
27
                ),
28
                "itemTax"      => array(
29
 
30
                    1 => 0.00,
31
                ),
32
                "shipAmt"      => 0.00,
33
                "shipTax"      => array(
34
 
35
                    1 => 0.00,
36
                ),
37
                "Amt"          => 0.00,
38
                "Tax"          => 0.00,
39
                "Total"        => 0.00,
40
            );
41
            if ( $_SESSION["SHOP"]["BASKET"]->items )
42
            {
709 lars 43
                $Land = 47;
707 lars 44
                if ( ( isset( $_SESSION['SHOP']['Lieferadresse'] ) && $_SESSION['SHOP']['Lieferadresse'] == "true" ) || ( isset( $_GET["liefer"] ) && $_GET["liefer"] == 1 ) || isset( $_SESSION['SHOP']['buy']['Persdata']['liefer_Land'] ) )
701 lars 45
                {
46
                    $Land = $_SESSION['SHOP']['buy']['Persdata']['liefer_Land'];
47
                }
708 lars 48
                elseif ( isset( $_SESSION['SHOP']['buy']['Persdata']['Land'] ) )
701 lars 49
                {
50
                    $Land = $_SESSION['SHOP']['buy']['Persdata']['Land'];
51
                }
52
                if ( !isset( $GLOBALS["steuern"][$Land] ) )
53
                {
54
                    $Land = 47;
55
                }
56
                $taxArr = $GLOBALS["steuern"][$Land];
57
                foreach ( $_SESSION["SHOP"]["BASKET"]->items as $bItem )
58
                {
717 lars 59
                    if ( !$bItem->code )
701 lars 60
                    {
720 lars 61
                        $item = ItemAlias::find( $bItem->id );
701 lars 62
                        if ( !isset( $bItem->tax ) )
63
                        {
64
                            $bItem->tax = $item->tax1;
65
                        }
66
                        $tax = $taxArr[$bItem->tax];
67
                        $bPreis = $bItem->menge * $bItem->price;
68
                        $buffer["itemAmt"][$bItem->tax] += $bPreis;
69
                    }
70
                    else
71
                    {
72
                        $tax = 0;
73
                        $bPreis = $bItem->price;
74
                        $buffer["discount"] = $bPreis * -1;
75
                    }
725 lars 76
                    if ( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] )
701 lars 77
                    {
78
                        $buffer["itemTax"][$bItem->tax] += round( $bPreis * $tax / 100, 2 );
79
                    }
80
                    else
81
                    {
82
                        $buffer["itemTax"][$bItem->tax] += round( $bItem->price * $tax / ( 100 + $tax ), 2 ) * $bItem->menge;
83
                    }
84
                    $buffer["Amt"] += $bPreis;
85
                }
86
                if ( !( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] == 1 ) )
87
                {
88
                    foreach ( $buffer["itemTax"] as $tax => $amt )
89
                    {
90
                        $buffer["itemAmtNetto"][$tax] = $buffer["itemAmt"][$tax] - round( $amt, 2 );
91
                    }
92
                }
725 lars 93
                if ( isset( $_SESSION["SHOP"]["VERSAND"] ) && $_SESSION["SHOP"]["VERSAND"] )
701 lars 94
                {
95
                    $t = 1;
96
                    $bItem = $_SESSION["SHOP"]["VERSAND"];
97
                    $buffer["shipAmt"] = $bItem["preis"];
98
                    $buffer["Amt"] += $bItem["preis"];
99
                    if ( $GLOBALS["INI"]["netto_preise"] )
100
                    {
101
                        $netto = array_sum( $buffer["itemAmt"] );
102
                        $t = $buffer["itemAmt"][0] / $netto;
103
                    }
104
                    if ( !isset( $GLOBALS["steuern"][$Land] ) )
105
                    {
106
                        $Land = 47;
107
                    }
108
                    $taxArr = $GLOBALS["steuern"][$Land];
109
                    if ( $t == 1 )
110
                    {
111
                        $tax = $taxArr[0];
112
                        if ( $GLOBALS["INI"]["netto_preise"] )
113
                        {
114
                            $buffer["shipTax"][0] += $bItem->price * $tax / 100;
115
                        }
116
                        else
117
                        {
118
                            $buffer["shipTax"][0] += $bItem->price * $tax / ( 100 + $tax );
119
                        }
120
                    }
121
                    elseif ( $t == 0 )
122
                    {
123
                        $tax = $taxArr[1];
124
                        if ( $GLOBALS["INI"]["netto_preise"] )
125
                        {
126
                            $buffer["shipTax"][1] += $bItem->price * $tax / 100;
127
                        }
128
                        else
129
                        {
130
                            $buffer["shipTax"][1] += $bItem->price * $tax / ( 100 + $tax );
131
                        }
132
                    }
133
                    else
134
                    {
135
                        $tax = $taxArr[0];
725 lars 136
                        if ( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] )
701 lars 137
                        {
138
                            $buffer["shipTax"][0] += ( $bItem->price * $tax / 100 ) * $t;
139
                        }
140
                        else
141
                        {
142
                            $buffer["shipTax"][0] += ( $bItem->price * $tax / ( 100 + $tax ) ) * $t;
143
                        }
144
                        $tax = $taxArr[1];
725 lars 145
                        if ( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] )
701 lars 146
                        {
147
                            $buffer["shipTax"][1] += ( $bItem->price * $tax / 100 ) * ( 1 - $t );
148
                        }
149
                        else
150
                        {
151
                            $buffer["shipTax"][0] += ( $bItem->price * $tax / ( 100 + $tax ) ) * ( 1 - $t );
152
                        }
153
                    }
154
                }
155
                foreach ( $taxArr as $ind => $tax )
156
                {
157
                    $buffer["TaxRates"][$ind] = $tax;
158
                }
159
                $buffer["Tax"] = round( array_sum( $buffer["itemTax"] ) + array_sum( $buffer["shipTax"] ), 2 );
725 lars 160
                if ( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] )
701 lars 161
                {
162
                    $buffer["Total"] = round( $buffer["Amt"] + $buffer["Tax"], 2 );
163
                }
164
                else
165
                {
166
                    $buffer["Total"] = $buffer["Amt"];
167
                }
168
            }
705 lars 169
            $this->paymentInfo = $buffer;
701 lars 170
        }
383 lars 171
 
701 lars 172
        public function addItem()
656 lars 173
        {
668 lars 174
            $preis = 0;
705 lars 175
            if ( request( "preis" ) )
668 lars 176
            {
705 lars 177
                $preis = request( "preis" );
668 lars 178
            }
730 lars 179
            $bItem = new BasketItemController( \request( "Menge" ), $preis, \request( "item" ) );
670 lars 180
            $bItem->addinfo = "";
663 lars 181
            // addons aus konfigurator
705 lars 182
            $addon = \request( "addon" );
183
            if ( is_array( $addon ) )
663 lars 184
            {
705 lars 185
                foreach ( $addon as $itemID )
663 lars 186
                {
187
                    if ( $expl = explode( "#", $itemID ) )
188
                    {
189
                        if ( $expl[0] != 0 )
190
                        {
191
                            $itemID = $expl[0];
829 lars 192
                        }
193
                        $preis = 0;
741 lars 194
                        if ( $expl[1] != 0 )
195
                        {
196
                            $preis = $expl[1];
663 lars 197
                        }
198
                    }
199
                    if ( is_numeric( $itemID ) )
200
                    {
741 lars 201
                        $aItem = new BasketItemController( 1, $preis, $itemID );
829 lars 202
                        $bItem->addinfo .= "<br>" . $aItem->name;
203
                        $bItem->price += $preis;
663 lars 204
                    }
205
                }
206
            }
829 lars 207
            $key = sha1( $bItem->name . $bItem->addinfo );
738 lars 208
            if ( isset( $_SESSION["SHOP"]["BASKET"]->items[$key] ) )
209
            {
210
                $bItem->menge += $_SESSION["SHOP"]["BASKET"]->items[$key]->menge;
829 lars 211
            }
731 lars 212
            $_SESSION["SHOP"]["BASKET"]->items[$key] = $bItem;
705 lars 213
            $this->getPaymentInfo();
713 lars 214
            $this->getShipmentCosts();
829 lars 215
        }
713 lars 216
 
829 lars 217
        public function editItem()
218
        {
219
            $key = request( "id" );
220
            $menge = request( "menge" );
746 lars 221
            $_SESSION["SHOP"]["BASKET"]->items[$key]->menge = $menge;
737 lars 222
            $this->getPaymentInfo();
829 lars 223
            $this->getShipmentCosts();
224
        }
737 lars 225
 
733 lars 226
        public function delItem()
227
        {
228
            $key = request( "id" );
229
            unset( $_SESSION["SHOP"]["BASKET"]->items[$key] );
736 lars 230
            $this->getPaymentInfo();
231
            $this->getShipmentCosts();
733 lars 232
        }
233
 
713 lars 234
        private function getShipmentCosts()
829 lars 235
        {
236
            $sc = new ShippingController();
237
            $buffer = $sc->getShippingOptions();
843 lars 238
            $_SESSION["SHOP"]["BASKET"]->shipmentCosts = $buffer;
829 lars 239
        }
240
 
241
        public function getBasketGewicht()
242
        {
243
            $gewicht = 0;
244
            foreach ( $this->items as $item )
245
            {
246
                $gewicht += $item->gewicht;
247
            }
248
            return $gewicht;
249
        }
383 lars 250
    }