require_once( "mysql.php" ); require_once( "email.php" ); function getCart( $sid ) { global $user; $cart = array( ); $result = queryCart( $sid ); $i = 0; $cart['weight'] = 0; $cart['maxlength'] = 0; $cart['maxwidth'] = 0; $cart['maxgirth'] = 0; $cart['shipping_credit'] = 0; $cart['nettotal'] = 0; while( $row = mysqli_fetch_assoc( $result ) ) { //echo "cart part
"; $cart[$i]['qty'] = $row['qty']; $cart[$i]['pn'] = $row['pn']; $cart[$i]['name'] = $row['name']; $cart[$i]['taxclass'] = $row['taxclass']; $cart[$i]['id'] = $row['id']; $cart[$i]['haz'] = $row['haz']; $cart[$i]['ovsz'] = $row['ovsz']; $cart[$i]['weight'] = $row['weight'] * $row['qty']; $cart['weight'] += $cart[$i]['weight']; $cart['shipping_credit'] += $row['shipping_credit'] * $row['qty']; $cart[$i]['stock'] = $row['stock']; $cart[$i]['stockeast'] = $row['stockeast']; $cart[$i]['stockwest'] = $row['stockwest']; $cart[$i]['length'] = $row['l']; $cart[$i]['width'] = $row['b']; $cart[$i]['height'] = $row['h']; $cart[$i]['qty_as_core'] = $row['qty_as_core']; $cart[$i]['stockyingling'] = $row['stockyingling']; $cart[$i]['shipclass'] = $row['shipclass']; if ( $row['leadtime_days_min'] || $row['leadtime_days_max'] ) { $cart[$i]['leadtimedays'] = $row['leadtime_days_min']. "-" . $row['leadtime_days_max']; } $cart[$i]['url_seo'] = $row['url_seo']; //echo $cart[$i]['leadtimedays']; if( $row['price_override'] ) { $cart[$i]['price'] = $row['price_override']; } else { $cart[$i]['price'] = $row['price']; } $cart[$i]['originalprice'] = $row['price']; if ( isset( $user['pricelist'] ) && $row['pricelist_' . $user['pricelist']] > 0 ) { //echo "PRICELIST ACTIVE"; $cart[$i]['price'] = $row['pricelist_' . $user['pricelist']]; } $cart['nettotal'] += $cart[$i]['price'] * $row['qty']; if ( $cart[$i]['haz'] ) { $cart['haz'] = true; } if ( $cart[$i]['ovsz'] ) { $cart['ovsz'] = true; } if ( $cart[$i]['shipclass'] == 'TB' ) { $cart['ovsz'] = true; } $cart['maxlength'] = max( $cart['maxlength'], $cart[$i]['length'], $cart[$i]['width'], $cart[$i]['height'] ); $dims = array( $cart[$i]['length'], $cart[$i]['width'], $cart[$i]['height'] ); sort( $dims ); // print_r( $dims ); $girth = $dims[2] + 2 * $dims[1] + 2 * $dims[0]; //echo "GIRTH: " . $girth . "
"; $cart['maxgirth'] = max( $cart['maxgirth'], $girth ); $width = $dims[1]; // echo "W:" . $width; $cart['maxwidth'] = max( $cart['maxwidth'], $width ); $i++; } $cart['nofitems'] = $i; return $cart; } function updateCartQty( $pn, $qty, $sid ) { if ( $qty < 0 ) { addError( "Invalid quantity for part number " . $pn ); } $sql = sprintf( "select c.qty,p.corepn from cart c join prod p on c.pn=p.pn where c.sid='%s' and c.pn='%s'", $sid, $pn ); $result = query( $sql ); if ( $row = mysqli_fetch_row( $result ) ) { $coreQtyChange = $qty - $row[0]; $corepn = $row[1]; } $sql = sprintf( "update cart set qty=%.3f where sid='%s' and pn='%s'", $qty, $sid, $pn ); $result = queryAffectedRows( $sql ); if ( $result > 0 ) { addSuccess( "Updated quantity for part number " . $pn ); } if ( $corepn != "" ) { //echo "updating core qty: " . $corepn . " " . $coreQtyChange; updateCoreQty( $sid, $corepn, $coreQtyChange ); } return ( $result > 0 ) ; } function cartRemove( $sid, $pn ) { $sql = sprintf( "select c.qty,p.corepn from cart c join prod p on c.pn=p.pn where c.sid='%s' and c.pn='%s'", $sid, $pn ); $result = query( $sql ); if ( $row = mysqli_fetch_row( $result ) ) { $qty = $row[0]; $corepn = $row[1]; } $sql = sprintf( "delete from cart where sid='%s' and pn='%s'", $sid, $pn ); query( $sql ); if ( $corepn != "" ) { updateCoreQty( $sid, $corepn, -$qty ); } } function cartEmpty( $cart ) { if ( $cart['nofitems'] == 0 ) { return true; } else { return false; } } function chargeVat( $shipcountry, $shippostcode, $vatidvalid ) { $chargevat = true; if ( $shipcountry != "de") { $result = queryEUCountries( $shipcountry ); if( $row = mysqli_fetch_row( $result ) ) { if ( $row[0] == 0 ) { $chargevat = false; } else { if ( $vatidvalid ) { $chargevat = false; } if ( $shipcountry == "es" ) { if ( substr( $shippostcode, 0, 2 ) == "35" || substr( $shippostcode, 0, 2 ) == "38" ) { $chargevat = false; } } } } } return $chargevat; } function checkout_paymethod( $cart, $user, $sid, $paymethod, $additional_data, $bank_code, $bank_account, $account_owner, $klarna_status ) { $subtotalnet = 0; $vat = 0; $shippingdisc = 0; $shippingdiscnet = 0; for ( $i = 0; $i < $cart['nofitems']; $i++ ) { $linetotalnet = $cart[$i]['qty'] * $cart[$i]['price']; $subtotalnet += $cart[$i]['qty'] * $cart[$i]['price']; $vat += $linetotalnet * ( getTaxRate( $cart[$i]['taxclass'] ) / 100 ); } $type_shipdisc = 'SHIPDISC'; $result = queryActiveCoupons( $user['id'], $type_shipdisc ); $coupon = mysqli_fetch_assoc( $result ); $shippingnet = getShipPrice( $user['shipmethod'], $user, $cart ); $vat += ( $shippingnet * getTaxRate( 1 ) / 100 ); if ( $coupon && $coupon['disc_type'] == 'SHIPDISC' ) { $coupon_description = 'Shipping Discount (' . $coupon['description'] . ')'; $shippingdisc = min( $shippingnet, $coupon['max_disc'] ); } $vat -= ( $shippingdiscnet * getTaxRate( 1 ) / 100 ); if ( ! $user['chargevat'] ) { $vat = 0; } $fees = 0; $shippingprice = $shippingnet - $shippingdisc; $total = round( $subtotalnet + $shippingprice + $fees, 2 ) + round( $vat, 2 ); $sql = sprintf( "insert into ordercounter () values ()" ); $id = "SAS-W" . queryInsertId( $sql ); // $id = "W" . queryInsertId( $sql ); echo "ORDER NUMBER: " . $id . "
"; $klarna_invno = ""; if ( $paymethod == "klarna_invoice" || $paymethod == "klarna_account" ) { $klarna_invno = $additional_data; } $comments = isset( $user['comments'] ) ? $user['comments'] : ""; $reference = isset( $user['reference'] ) ? $user['reference'] : ""; // $sql = sprintf( "insert into orders (id,user_id,status,created,subtotal,shipping,fees,vat,total,comments,vatid,bill_name1,bill_name2,bill_street,bill_houseno,bill_postcode,bill_city,bill_country,ship_name1,ship_name2,ship_street,ship_houseno,ship_postcode,ship_city,ship_country,ship_phone,shipmethod,reference,email,paymethod,klarna_invno,klarna_status,ups_ap_id,ups_ap_cpid,ups_ap_networkid,ups_ap_name,ups_ap_street,ups_ap_zip,ups_ap_city,ups_ap_locationhint,ups_ap_openinghours,ups_ap_image,ups_ap_label_ShopId,ups_ap_label_street,ups_ap_label_name,ups_ap_APid,ups_ap_consigneestreet1) select '%s',%d,%d,CURRENT_TIMESTAMP,%.2f,%.2f,%.2f,%.2f,%.2f,'%s',u.vatid,u.bill_name1,u.bill_name2,u.bill_street,u.bill_houseno,u.bill_postcode,u.bill_city,u.bill_country,u.ship_name1,u.ship_name2,u.ship_street,u.ship_houseno,u.ship_postcode,u.ship_city,u.ship_country,u.ship_phone,'%s','%s',u.email,'%s','%s','%s',u.ups_ap_id,u.ups_ap_cpid,u.ups_ap_networkid,u.ups_ap_name,u.ups_ap_street,u.ups_ap_zip,u.ups_ap_city,u.ups_ap_locationhint,u.ups_ap_openinghours,u.ups_ap_image,u.ups_ap_label_ShopId,u.ups_ap_label_street,u.ups_ap_label_name,u.ups_ap_APid,u.ups_ap_consigneestreet1 from cart c join prod p on c.pn=p.pn join user u where sid='%s' and u.id=%d", $id, $user['id'], 0, $subtotalnet, $shippingprice, $fees, $vat, $total, escapesql( $comments ), $user['shipmethod'], escapesql( $reference ), $paymethod, $klarna_invno, $klarna_status, $sid, $user['id'] ); $sql = sprintf( "insert into orders (id,user_id,status,created,subtotal,shipping,fees,vat,total,comments,vatid,bill_name1,bill_name2,bill_street,bill_houseno,bill_postcode,bill_city,bill_country,ship_name1,ship_name2,ship_street,ship_houseno,ship_postcode,ship_city,ship_country,ship_phone,shipmethod,reference,email,paymethod,klarna_invno,klarna_status,ups_ap_id,ups_ap_cpid,ups_ap_networkid,ups_ap_name,ups_ap_street,ups_ap_zip,ups_ap_city,ups_ap_locationhint,ups_ap_openinghours,ups_ap_image,ups_ap_label_ShopId,ups_ap_label_street,ups_ap_label_name,ups_ap_APid,ups_ap_consigneestreet1) select '%s',%d,%d,CURRENT_TIMESTAMP,%.2f,%.2f,%.2f,%.2f,%.2f,'%s',u.vatid,u.bill_name1,u.bill_name2,u.bill_street,u.bill_houseno,u.bill_postcode,u.bill_city,u.bill_country,u.ship_name1,u.ship_name2,u.ship_street,u.ship_houseno,u.ship_postcode,u.ship_city,u.ship_country,u.ship_phone,'%s','%s',u.email,'%s','%s','%s',u.ups_ap_id,u.ups_ap_cpid,u.ups_ap_networkid,u.ups_ap_name,u.ups_ap_street,u.ups_ap_zip,u.ups_ap_city,u.ups_ap_locationhint,u.ups_ap_openinghours,u.ups_ap_image,u.ups_ap_label_ShopId,u.ups_ap_label_street,u.ups_ap_label_name,u.ups_ap_APid,u.ups_ap_consigneestreet1 from user u where u.id=%d", $id, $user['id'], 0, $subtotalnet, $shippingprice, $fees, $vat, $total, escapesql( $comments ), $user['shipmethod'], escapesql( $reference ), $paymethod, $klarna_invno, $klarna_status, $user['id'] ); // echo $sql; query( $sql ); if ( $paymethod == "directdebit" ) { $bank_account = str_replace( ' ', '', $bank_account ); $sql = sprintf( "insert into directdebit (order_id,account_holder,iban,created,todo_import) values ('%s','%s','%s',CURRENT_TIMESTAMP,1)", $id, $account_owner, $bank_account ); query( $sql ); } /* $sql = sprintf( "select c.pn,c.qty,p.price,p.taxclass,p.name,p.stock,p.stockeast,p.stockwest from cart c join prod p on c.pn=p.pn where sid='%s' order by id", $sid ); // echo $sql . "
"; $result = query( $sql ); */ $i = 0; //print_r( $cart ); $duedate = "0000-00-00"; for( $i = 0; $i < $cart['nofitems']; $i++ ) //$cart as $key => $part ) //while( $part = mysqli_fetch_assoc( $result ) ) { $part = $cart[$i]; $duedate = getShipDateByQtyRequested( $part['qty'], $part['stock'], $part['stockeast'], $part['stockwest'], $part['stockyingling'] ); //echo $duedate . "
"; if ( $part['originalprice'] != 0 ) { $discount = sprintf( "%.1f%%", ( ( 1 - ( $part['price'] / $part['originalprice'] ) ) * 100 ) ); // echo "DISC: " . $discount . "
"; } else { $discount = 0; } $sql = sprintf( "insert into orderpos (taxrate,pos,order_id,pn,qty,price,name,due_date_original,stock_snapshot,stock_snapshot_west,stock_snapshot_east,originalprice,discount) values (%.1f,%d,'%s','%s',%.3f,%.2f,'%s','%s',%.3f,%.3f,%.3f,%.2f,%.1f)", getTaxRate( $part['taxclass'] ), $i+1, $id, $part['pn'], $part['qty'], $part['price'], $part['name'], $duedate, $part['stock'], $part['stockwest'], $part['stockeast'], $part['originalprice'], $discount ); //echo $sql . "
"; query( $sql ); //die( ); } //$sql = sprintf( "insert into orderpos (pos,order_id,pn,qty,price) select '%s',c.pn,c.qty,p.price from cart c join prod p on c.pn=p.pn where sid='%s'", $id, $sid ); //echo $sql; //query( $sql ); $sql = sprintf( "delete from cart where sid='%s'", $sid ); query( $sql ); addOrderHistory( $id, "web", "Order Received" ); $order = mysqli_fetch_assoc( queryOrderByOrderId( $id ) ); emailOrderConfirmation( $user, $order ); //addSuccess("Order received! Your order number is W" . $id . "." ); $checkout_result['id'] = $id; $checkout_result['amount'] = $total; return $checkout_result; } function getOrderStatusName( $statuscode ) { switch( $statuscode ) { case 0: return "SELECT PAYMENT METHOD"; case 1: return "NEW"; case 2: return "REVIEW"; case 3: return "OPEN"; case 4: return "ALLOCATING PRODUCTS"; case 5: return "WAITING FOR PAYMENT"; case 6: return "PULLED"; case 7: return "INVOICED"; case 50: return "PROFORMA"; case 98: return "MIGRATION"; case 99: return "CANCELLED"; default: return "unknown"; } } function cancel( $orderid, $userid ) { $sql = sprintf( "update orders set todo_cancel=1 where id='%s' and user_id=%d", $orderid, $userid ); query( $sql ); addOrderHistory( $orderid, "web", "Cancellation request sent" ); } function addOrderHistory( $orderid, $event, $info ) { $sql = sprintf( "insert into orderhistory (created,order_id,event,info) values (CURRENT_TIMESTAMP,'%s','%s','%s')", $orderid, $event, $info ); query( $sql ); } function updateComments( $comments ) { global $sessiondur; setcookie( "comments", $comments, time() + $sessiondur ); } function updateReference( $reference ) { global $sessiondur; setcookie( "reference", $reference, time() + $sessiondur ); } function deleteCart( $sid ) { $sql = sprintf( "delete from cart where sid='%s'", $sid ); query( $sql ); addMessage( "All items removed from shopping cart" ); } function myorder( $orderid, $user ) { $myorder = false; $result = queryOrderOwner( $orderid ); if( $row = mysqli_fetch_assoc( $result ) ) { if ( isset( $user['id'] ) && $row['user_id'] == $user['id'] ) { $myorder = true; } } return $myorder; } ?> 
Warning: Cannot modify header information - headers already sent by (output started at C:\www\www.aircraftspruce.eu\php\cart.php:36) in C:\www\www.aircraftspruce.eu\php\session.php on line 89

Warning: Cannot modify header information - headers already sent by (output started at C:\www\www.aircraftspruce.eu\php\cart.php:36) in C:\www\www.aircraftspruce.eu\php\session.php on line 497

Warning: Cannot modify header information - headers already sent by (output started at C:\www\www.aircraftspruce.eu\php\cart.php:36) in C:\www\www.aircraftspruce.eu\php\session.php on line 521

Fatal error: Uncaught Error: Call to undefined function chargeVat() in C:\www\www.aircraftspruce.eu\php\session.php:193 Stack trace: #0 C:\www\www.aircraftspruce.eu\php\shop.php(30): getUser('MWKP1786adb3044...') #1 C:\www\www.aircraftspruce.eu\index.php(2): require_once('C:\\www\\www.airc...') #2 {main} thrown in C:\www\www.aircraftspruce.eu\php\session.php on line 193