File: D:/HostingSpaces/SBogers10/molennooitgedagtbudel.nl/wwwroot/kms/bestelling_verzending_aanmaken.php
<?php
include_once('sendcloudApi.php');
if(isset($_POST['verzenden'])){
$verzenden = true;
}
$order_id = $_GET['order_id'];
$order_id = checkData($order_id);
$filter = $_GET['filter'];
$filter = checkData($filter);
$maand = $_GET['maand'];
$maand = checkData($maand);
$q_order = "SELECT * FROM kms_orders WHERE kms_orders.order_id = '".$order_id."'";
$r_order = mysql_query($q_order);
$rec_order = mysql_fetch_assoc($r_order);
if($verzenden){
if($rec_order['bezorgadresWijktAf'] == "no"){
$naam = $rec_order['voornaam']." ";
if(!empty($rec_order['tussenvoegsel'])){ $naam .= $rec_order['tussenvoegsel']." "; }
$naam .= $rec_order['achternaam'];
$naam = addslashes(html_entity_decode($naam));
$bedrijfsnaam = addslashes(html_entity_decode($rec_order['bedrijfsnaam']));
$adres = $rec_order['straatnaam']." ".$rec_order['huisnummer'];
if(!empty($rec_order['toevoeging'])){ $adres .= "-".$rec_order['toevoeging']; }
$adres = addslashes(html_entity_decode($adres));
$postcode = addslashes(html_entity_decode($rec_order['postcode']));
$woonplaats = addslashes(html_entity_decode($rec_order['woonplaats']));
$land = addslashes(html_entity_decode($rec_order['land']));
if($land == "Nederland"){ $landCode = "NL"; $shipment_id = 1; }else{ $landCode = "BE"; $shipment_id = 4204; }
}else{
$naam = $rec_order['voornaamBezorg']." ";
if(!empty($rec_order['tussenvoegselBezorg'])){ $naam .= $rec_order['tussenvoegselBezorg']." "; }
$naam .= $rec_order['achternaamBezorg'];
$naam = addslashes(html_entity_decode($naam));
$bedrijfsnaam = addslashes(html_entity_decode($rec_order['bedrijfsnaamBezorg']));
$adres = $rec_order['straatnaamBezorg']." ".$rec_order['huisnummerBezorg'];
if(!empty($rec_order['toevoegingBezorg'])){ $adres .= "-".$rec_order['toevoegingBezorg']; }
$adres = addslashes(html_entity_decode($adres));
$postcode = addslashes(html_entity_decode($rec_order['postcodeBezorg']));
$woonplaats = addslashes(html_entity_decode($rec_order['woonplaatsBezorg']));
$land = addslashes(html_entity_decode($rec_order['landBezorg']));
if($land == "Nederland"){ $landCode = "NL"; $shipment_id = 1; }else{ $landCode = "BE"; $shipment_id = 4204; }
}
if($land == "Nederland"){ $aantal_zendingen = round($rec_order['verzendkosten'] / 6.9); }else{ $aantal_zendingen = round($rec_order['verzendkosten'] / 8.75); }
$parcel_id = "";
for($i=0;$i<$aantal_zendingen;$i++){
$api = new SendcloudApi('live', 'jlp63pqdPXz3Ef5qXFXq','My4Tkw05JEWvjSb');
$parcelArray = array(
'name'=> html_entity_decode($naam),
'company_name' => html_entity_decode($bedrijfsnaam),
'address' => html_entity_decode($adres),
'city' => html_entity_decode($woonplaats),
'postal_code' => html_entity_decode($postcode),
'telephone' => $rec_order['telefoonnummer'],
'requestShipment' => true, // set to true when you want to request a shipment
'email' => $rec_order['emailadres'],
'country' => $landCode,
'shipment' => array(
'id' => $shipment_id
),
'order_number' => $rec_order['ordernummer']
);
$parcel = $api->parcels->create($parcelArray);
$parcel_id .= $parcel['id'];
if($i != ($aantal_zendingen-1)) $parcel_id .= ',';
}
if(!empty($parcel_id)){
$zending_aanmaken_succesvol = true;
$q_parcel_post = sprintf("UPDATE kms_orders SET parcel_id = '%s' WHERE kms_orders.order_id='%s'", $parcel_id, $order_id);
$r_parcel_post = mysql_query($q_parcel_post);
}else{
$zending_aanmaken_succesvol = false;
}
if($zending_aanmaken_succesvol){
if($r_parcel_post){
echo("<h1>Verzending succesvol aangemaakt</h1><br />");
echo("<p><strong>Aantal aangemaakte pakketten is: ".$aantal_zendingen."</strong></p><br />");
echo("<p>De verzending is succesvol aangemaakt bij Sendcloud en PostNL. Wacht enkele seconden en print dan het verzendlabel via onderstaande knop.</p><br /><br />");
echo("<a target=\"_blank\" class=\"submit_knop\" href=\"/kms/bestelling_label_printen.php?parcel_id=".$parcel_id."\" title=\"Labels printen\">Labels printen</a>");
}else{
echo("<h1>Verzending aanmaken mislukt</h1><br />");
echo("<p>Het is mislukt om een verzending aan te maken.</p><br /><br />");
}
}else{
echo("<h1>Verzending aanmaken mislukt</h1><br />");
echo("<p>Het is mislukt om een verzending aan te maken.</p><br /><br />");
}
echo("<br /><br /><a class=\"submit_annuleren\" href=\"/kms/index.php?p=bestelling_info&order_id=".$order_id."&filter=".$filter."&maand=".$maand."\" title=\"Terug naar overzicht\">Terug naar overzicht</a>");
}else{
?>
<h1>Zending aanmaken voor bestelling <?php echo(html_entity_decode($rec_order['ordernummer'])); ?></h1>
<?php if(!empty($rec_order['parcel_id'])){ ?>
<p>Deze zending is al aangemaakt.<br /><br />
<?php echo("<a target=\"_blank\" class=\"submit_knop\" href=\"/kms/bestelling_label_printen.php?parcel_id=".$rec_order['parcel_id']."\" title=\"Label printen\">Label printen</a>"); ?>
<a class="submit_annuleren" href="index.php?p=bestelling_info&order_id=<?php echo($order_id); ?>&filter=<?php echo($filter);?>&maand=<?php echo($maand); ?>" title="Terug">Terug</a>
<?php }else{ ?>
<p>Weet u zeker dat u een zending aan wil maken voor deze order?<br /><br />
<form action="<?php $_SERVER['PHP_SELF']; ?>" id="aanmelden" name="aanmelden" method="post">
<div>
<input name="verzenden" type="submit" value="Zending aanmaken" class="submit" />
<a class="submit_annuleren" href="index.php?p=bestelling_info&order_id=<?php echo($order_id); ?>&filter=<?php echo($filter);?>&maand=<?php echo($maand); ?>" title="Annuleren">Annuleren</a>
</div>
</form>
<?php
}
}
?>