Skip to content

Instantly share code, notes, and snippets.

@spirit1977
Created June 30, 2023 10:41
Show Gist options
  • Save spirit1977/27f829319e66528f31e697fb560b38c3 to your computer and use it in GitHub Desktop.
Save spirit1977/27f829319e66528f31e697fb560b38c3 to your computer and use it in GitHub Desktop.
<?php
$page_name = 'create_order';
require_once 'includes/config.php';
require_once 'vendor/vendor/autoload.php';
use BillbeeDe\BillbeeAPI\Model\Order;
use BillbeeDe\BillbeeAPI\Model\OrderItem;
use BillbeeDe\BillbeeAPI\Model\Product;
use BillbeeDe\BillbeeAPI\Model\Address;
use BillbeeDe\BillbeeAPI\Model\Customer;
$emoose->check_user_logged_in();
$client = new \BillbeeDe\BillbeeAPI\Client($user, $apiPassword, $apiKey);
$rsshop = '';
$label_error_message = '';
if(isset($_SESSION['user']['id']) and ($_SESSION['user']['id'] == 1 or $_SESSION['user']['id'] == 9))
{
$allowed_sites = $emoose->get_all_sites_list();
}
else
{
$allowed_sites = $emoose->allowed_sites_list($_SESSION['user']['id']);
}
if(isset($_POST['search_text'])){
$productsResponse = $emoose->product_search($_POST['search_text'], implode(',',$_POST['shop_id']));
$temp = array_unique(array_column($productsResponse, 'product_id'));
$unique_arr = array_intersect_key($productsResponse, $temp);
$productArray = [];
foreach($unique_arr as $array){
$productArray[] = $array;
}
echo json_encode($productArray);die;
}
if(isset($_POST['productId'])){
$productsResponse = $emoose->get_product_details_from_api($_POST['productId']);
echo json_encode($productsResponse);die;
}
if(isset($_POST['formSubmit'])){
$url = '';
$isAddNote = 'false';
foreach($_FILES['shipping_labels']['name'] as $key => $shipping_labels)
{
if($shipping_labels != ''){
$shippinglabels = str_replace(" ","-",$shipping_labels);
$name = time().$shippinglabels;
$temp_name = $_FILES['shipping_labels']['tmp_name'][$key];
$path = 'assets/media/shipping_labels/'.$name;
move_uploaded_file($temp_name,$path);
$tiny_url = $emoose->get_tiny_url($config_site_url.$path);
if($key == 0){
$url .= 'Uploads: '.PHP_EOL.$tiny_url. PHP_EOL;
}else{
$url .= $tiny_url. PHP_EOL;
}
}
}
if(isset($_POST['notes']) && !empty($_POST['notes'])){
$isAddNote = 'true';
$order_notes .= 'Hinweis: '.$_POST['notes']. PHP_EOL;
}
if($url != ''){
$isAddNote = 'true';
}
$order_notes .= $url;
$myOrder = new Order();
$myAddress = new Address();
$customer = new Customer();
$myOrder->sellerComment = $order_notes;
$customer->name = $_POST['first_name'].' '.$_POST['last_name'];
if(isset($_POST['email']) && !empty($_POST['email'])){
$customer->email = $_POST['email'];
}
$myAddress->firstName = $_POST['first_name'];
$myAddress->lastName = $_POST['last_name'];
if(isset($_POST['sender_company_name']) && !empty($_POST['sender_company_name'])){
$myAddress->company = $_POST['sender_company_name'];
}
if(isset($_POST['email']) && !empty($_POST['email'])){
$myAddress->email = $_POST['email'];
}
$myAddress->street = $_POST['sender_street'];
$myAddress->country = $_POST['customer_country'];
$myAddress->city = $_POST['sender_city'];
$myAddress->zip = $_POST['sender_postal_code'];
if(isset($_POST['line2']) && !empty($_POST['line2'])){
$myAddress->line2 = $_POST['line2'];
}
$myAddress->houseNumber = $_POST['sender_house_number'];
$rsshop = $_POST['rsshop'];
$myOrder->acceptLossOfReturnRight = true;
$myOrder->state = 3;
if($isAddNote == 'true'){
$myOrder->tags = ['In Klaerung'];
}else{
$myOrder->tags = [];
}
$myOrder->paymentMethod = 22;
$myOrder->shippingCost = 0.00;
$myOrder->adjustmentCost = 0.00;
$myOrder->totalCost = 0.00;
$myOrder->createdAt = date('Y-m-d H:i:s');
$orderItems = [];
foreach($_POST['product_id'] as $key => $product_id){
$order_items = new orderItem();
$product = new Product();
$product->id = (int)$product_id;
$product_detail = $emoose->get_product_details_from_api($product->id);
$product->title = $_POST['product_title'][$key];
if($_POST['product_sku'][$key] != ''){
//$product->sku = $_POST['product_sku'][$key];
}
if($_POST['product_ean'][$key] != ''){
//$product->ean = $_POST['product_ean'][$key];
}
$product_price = str_replace(',','.',$_POST['product_price'][$key]);
$product->soldAmount = (float)$product_price;
$order_items->product = $product;
$order_items->totalPrice = (float)$product_price*$_POST['product_qty'][$key];
$order_items->unrebatedTotalPrice = (float)$product_price*$_POST['product_qty'][$key];
$order_items->taxAmount = 0.00;
$order_items->discount = 0.00;
$order_items->dontAdjustStock = false;
$order_items->quantity = (float)$_POST['product_qty'][$key];
$orderItems[] = $order_items;
}
$myOrder->orderItems = $orderItems;
$myOrder->invoiceAddress = $myAddress;
$myOrder->customer = $customer;
// echo '<pre>';
// print_r($rsshop);die;
$shop = end($rsshop);
if(isset($_POST['order_number']) && !empty($_POST['order_number'])){
$order_number = $_POST['order_number'];
}else{
$order_number = date('Y-m-d-H-i');
}
$myOrder->orderNumber = $order_number;
$order = $client->createOrder($myOrder,$shop);
// echo '<pre>';
// print_r($order);die;
if($order){
header( 'Location: create_order.php?success=true' );
}
}
?>
<?php require_once 'header.php'; ?>
<div class="content fs-6 d-flex flex-column-fluid" id="kt_content">
<!--begin::Container-->
<div class="container table-responsive">
<!--begin::Row-->
<div class="row g-0 g-xl-5 g-xxl-8">
<div class="col-xl-12">
<!--begin::Stats Widget 3-->
<div class="card bg-emoose card-stretch mb-5 mb-xxl-8 mw-custom">
<!--begin::Body-->
<div class="card-body">
<!--begin::Section-->
<!--begin::Title-->
<div class="mb-10">
<h3 class="fw-bold text-dark mb-5 fs-1">Versandauftrag</h3>
<p style="text-align: justify;margin-top: 10px;">Dieses <a style="color: #fff;" href="pre_fba_order.php">Formular</a> bitte ausschließlich zum Einzelversand an Endkunden oder Firmen nutzen. Für den Versand von vollen Verpackungseinheiten an Amazon (PRE-FBA) bitte das PRE-FBA Formular nutzen.<br>
Für Aufträge, die weder Einzelversand, noch Versand an Amazon sind, bitte eine Mail senden an <a style="color: #fff;" href="mailto:fulfillment@emoose.de">fulfillment@emoose.de.</a></p>
</div>
<!--end::Title-->
<!-- <form method="post" name="" action=""> -->
<div class="row">
<!--begin::Form Group-->
<div class="mb-10 col-xl-12">
<div class="tab-content">
<!-- Tab Genral -->
<div class="tab-pane active" id="tabs-1" role="tabpanel">
<?php
if(isset($_GET['success']) && $_GET['success'] == 'true')
{
?>
<h3 class="alert alert-success"><?php echo 'Auftrag wurde erfolgreich erstellt'; ?></h3>
<?php
}
?>
<form name="genral_form" action="" method="post" id="genral_form" class="genral_form" enctype="multipart/form-data">
<div class="row mx-0">
<div class="mb-md-0 mb-10 col-xl-6">
<label>Shop auswählen*</label>
<select name="rsshop[]" id="rsshop"
class="form-select form-select-lg form-select-solid mt-2 fw-bold fs-6 text-gray-600"
data-control="select2" data-hide-search="false" multiple requried>
<option value="">Shop auswählen*</option>
<?php
foreach($allowed_sites as $shop) {
$selected = ''; if(isset($rsshop) and $rsshop and $rsshop == $shop['shop_id']) $selected = 'selected="selected"';
?>
<option value="<?php echo $shop['shop_id']; ?>"
<?php echo $selected; ?>>
<?php echo $shop['shop_title']; ?></option>
<?php } ?>
</select>
</div>
<div class="mb-10 col-xl-6">
<label>Empfänger E-Mail Adresse für Tracking</label>
<input type="email" name="email" id="email" value=""
class="form-control form-control-solid mt-2" placeholder="Empfänger E-Mail Adresse für Tracking">
</div>
<div class="mb-10 col-xl-6">
<label>PDF Upload für gestellte Lieferscheine / Rechnungen</label>
<span class="form-control form-control-solid mt-2 cursor-pointer" onclick="document.getElementById('shipping_labels').click()">PDF wählen <span id="uploaded_files"></span></span>
<input type="file" name="shipping_labels[]" style="visibility:hidden;" id="shipping_labels" value=""
class="form-control form-control-solid mt-2 position-absolute"
multiple accept="application/pdf">
</div>
<div class="mb-10 col-xl-6">
<label>Eigene, individuelle Bestellnummer oder Kundenbestellnummer</label>
<input type="text" name="order_number" id="order_number" value=""
class="form-control form-control-solid mt-2" placeholder="Eigene, individuelle Bestellnummer oder Kundenbestellnummer">
</div>
<div class="col-lg-12"><h5>Adresse Empfänger</h5></div>
<div class="mb-10 col-lg-6 form-group"><input type="text" name="sender_company_name" id="sender_company_name" value="" class="form-control form-control-solid" placeholder="Firma oder Postnummer" autofill="off" /></div>
<div class="mb-10 col-lg-6 form-group">
<select name="customer_country" id="customer_country" class="form-select form-select-solid fw-bold fs-6 text-gray-600 h-6011px" data-control="select2" data-hide-search="true">
<?php
foreach($COUNTRIES_ARRAY as $key => $value) {
if($key=='DE'){
$isSelectedCountry="selected";
}else{
$isSelectedCountry="";
}
?>
<option <?php echo $isSelectedCountry ?> value="<?= $key ?>" ><?= htmlspecialchars($value) ?></option>
<?php
}
?>
</select>
<!-- <input type="text" name="customer_country" id="customer_country" value="" class="form-control form-control-solid" placeholder="Country" autofill="off" /> -->
</div>
<!-- <div class="mb-10 col-lg-6 form-group"><input type="text" name="sender_name" id="sender_name" value="" class="form-control form-control-solid" placeholder="Contact Person" autofill="off" /></div> -->
<div class="mb-10 col-lg-6 form-group"><input type="text" required name="first_name" id="first_name" value="" oninput="checkShop();" class="form-control form-control-solid" placeholder="Vorname *" autofill="off" /></div>
<div class="mb-10 col-lg-6 form-group"><input type="text" required name="last_name" id="last_name" value="" class="form-control form-control-solid" placeholder="Nachname *" autofill="off" /></div>
<div class="mb-10 col-lg-6 form-group"><input type="text" required name="sender_street" id="sender_street" value="" class="form-control form-control-solid" placeholder="Straße oder Packstation *" autofill="off" /></div>
<div class="mb-10 col-lg-6 form-group"><input type="text" required name="sender_house_number" id="sender_house_number" value="" class="form-control form-control-solid" placeholder="Hausnummer oder Nummer Packstaion *" autofill="off" /></div>
<div class="mb-10 col-lg-6 form-group"><input type="text" name="line2" id="line2" value="" class="form-control form-control-solid" placeholder="Adresszusatz oder Nummer Packstation" autofill="off" /></div>
<div class="mb-10 col-lg-6 form-group"><input type="text" required name="sender_postal_code" id="sender_postal_code" value="" class="form-control form-control-solid" placeholder="PLZ *" autofill="off" /></div>
<div class="mb-10 col-lg-6 form-group"><input type="text" required name="sender_city" id="sender_city" value="" class="form-control form-control-solid" placeholder="Stadt *" autofill="off" /></div>
<div class="mb-10 col-xl-8">
<textarea type="text" name="notes" id="notes"
class="form-control form-control-solid text-start min-h-50"
placeholder="Bestellnotizen / Auftragshinweise sofern relevant zur Auftragsdurchführung"></textarea>
</div>
<div class="pb-2">
<div class="row pb-1 mx-0">
<div class="col-8">
<span>Produkt</span>
</div>
<div class="ms-auto col-4">
<div class="row">
<span class="col-5 ms-auto">Menge Artikel</span>
<span class="col-3 ms-3">Preis</span>
<span class="col-2"></span>
</div>
</div>
</div>
<div class="positions" id="positions">
<div class="positions_inner" id="positions_inner">
<div class="row position_details-0 border-top p-2 pb-3 mb-3 mx-0" style="background-color:#8eae69;">
<div class="col-8 d-flex px-0">
<!-- <img src="https://www.emoose.de/wp-content/uploads/2016/07/rsz_logo_emoose_72dpi.jpg"
alt="" class="image_left me-3" style="height: 64px;"> -->
<div class="right_sideOf_image w-100 d-flex align-items-start">
<div id="search_input"
class="search_input position-relative w-100">
<div
class="form-control d-flex justify-content-between p-2 pe-3">
<input type="text" name="product_title[]" oninput="getProducts(0)" id="search-0"
class="search_input_feild search_input_feild-0 form-control border-0 p-0" autocomplete="off" value=""
placeholder="Artikel wählen" required>
<input type="hidden" name="product_id[]" id="product_id-0" value="" />
<input type="hidden" name="product_sku[]" id="product_sku-0" value="" />
<input type="hidden" name="product_ean[]" id="product_ean-0" value="" />
<i class="bi bi-search"></i>
</div>
<ul id="search_input_list-0"
class="d-none search_input_list list-unstyled rounded bg-light p-3 shadow-lg position-absolute w-100">
</ul>
</div>
</div>
</div>
<div class="ms-auto col-4 px-0">
<div class="row mx-0">
<div class="ms-auto col-5 px-1">
<input type="number" name="product_qty[]"
id="artical_number-0" min="1" placeholder="1"
class="form-control w-75 form-control-solid p-2"
required="">
</div>
<div class="ms-3 col-3 px-1">
<input type="text" name="product_price[]"
id="price-0" min="0" onkeypress="CheckNumeric(event);" placeholder="0,00"
class="form-control form-control-solid p-2"
required="">
</div>
<div class="col-2 px-1 d-flex flex-nowrap">
<a href="javascript:void(0);" onclick="removePosition_color(0)"
class="btn btn-icon btn-sm btn-dark">
<i class="far fa-trash-alt" aria-hidden="true"></i>
</a>
</div>
</div>
<span id="av_product_stock-0" class="max_valueText d-none mt-4 text-end d-block me-6" style="font-size:14px;">verfügbare Lagermenge: <span id="av_product_stock_val-0" style="color: #334dcc; font-weight: bold;"></span></span>
</div>
</div>
</div>
</div>
<div class="row mx-0 mt-10">
<div class="col-md-10 ps-0">
<p style="text-align: justify;">Hast du als Kunde mehrere Kanäle, dann wähle bitte alle aus. Nicht jeder Artikel ist je nach deiner Konfiguration zwingend bei jedem Kanal hinterlegt.</p>
</div>
<div class="col-md-6 ps-0 mt-2">
<div class="new-position_btn">
<a href="javascript:void(0);" id="new_position" class="btn me-1 btn-dark fw-bolder">
<i class="bi bi-plus"></i> Artikel hinzufügen
</a>
</div>
</div>
</div>
</div>
<div class="mb-md-0 mb-10 col-xl-8 mt-5">
<input type="submit" name="formSubmit" id="formSubmit" value="Versandauftrag übermitteln"
class="btn btn-dark px-11 py-4 fw-bolder fs-3 me-3" />
</div>
</div>
<input type="hidden" name="t" value="<?php echo time(); ?>" />
</form>
</div>
</div>
</div>
</div>
<!-- </form> -->
</div>
<!--end::Body-->
</div>
<!--end::Stats Widget 3-->
</div>
</div>
<!--end::Row-->
</div>
<!--end::Container-->
</div>
<!--end::Content-->
<?php require_once 'footer.php'; ?>
<script>
$(document).ready(function(){
// possitions Tab append function
var class3_id = 1;
jQuery('#new_position').click(function() {
$('#positions_inner:last-child').append('<div class="row position_details-'+class3_id+' border-top p-2 pb-3 mb-3 mx-0" style="background-color:#8eae69;"><div class="col-8 d-flex px-0"><div class="right_sideOf_image w-100 d-flex align-items-start"><div id="search_input" class="search_input position-relative w-100"><div class="form-control d-flex justify-content-between p-2 pe-3"><input type="text" name="product_title[]" autocomplete="off" oninput="getProducts('+class3_id+')" required id="search-'+class3_id+'" class="search_input_feild form-control border-0 p-0" placeholder="Artikel wählen"><input type="hidden" name="product_sku[]" id="product_sku-'+class3_id+'" value="" /><input type="hidden" name="product_ean[]" id="product_ean-'+class3_id+'" value="" /><input type="hidden" name="product_id[]" id="product_id-'+class3_id+'" value="" /><i class="bi bi-search"></i></div><ul id="search_input_list-'+class3_id+'" class="d-none search_input_list list-unstyled rounded bg-light p-3 shadow-lg position-absolute w-100"></ul></div></div></div><div class="ms-auto col-4 px-0"><div class="row mx-0"><div class="ms-auto col-5 px-1"><input type="number" name="product_qty[]" min="1" id="artical_number-'+class3_id+'" class="form-control w-75 form-control-solid p-2" placeholder="1" required=""></div><div class="ms-3 col-3 px-1"><input type="text" name="product_price[]" onkeypress="CheckNumeric(event);" min="0" id="price-'+class3_id+'" class="form-control form-control-solid p-2" placeholder="0,00" required=""></div><div class="col-2 px-1 d-flex flex-nowrap"><a href="javascript:void(0);" onclick="removePosition_color('+class3_id+')" class="btn btn-icon btn-sm btn-dark"><i class="far fa-trash-alt" aria-hidden="true"></i></a></div></div><span id="av_product_stock-'+class3_id+'" class="max_valueText d-none mt-4 text-end d-block me-6" style="font-size:14px;">verfügbare Lagermeng: <span id="av_product_stock_val-'+class3_id+'" style="color: #334dcc;font-weight: bold;"></span></span></div></div>');
class3_id++;
});
});
function getProducts(index){
if($("#search-"+index).val() == ''){
$('#search_input_list-'+index).addClass('d-none');
return false;
}
var rsshop = $('#rsshop').val();
//console.log(rsshop);
$.ajax({
type: 'POST',
url: "",
data: {search_text:$("#search-"+index).val(),shop_id:rsshop},
success: function(resultData) {
var JSONArray = $.parseJSON(resultData);
var productData = [];
if(JSONArray == ''){
$('#search_input_list-'+index).addClass('d-none');
return false;
}
for(let product of JSONArray){
var product_sku = product['product_sku'].replace("'", "-");
var data = '<li class="list_item border-bottom bdr_clr_black py-3 cursor-pointer d-flex" onClick="getProductDetail('+product['product_id']+','+index+')"><p class="list_item_content w-75 d-inline-block right_content px-3">'+product['product_title']+'</p><p class="list_item_content right_content px-3 d-inline-block ms-auto">'+product['product_sku']+'</p></li>';
productData.push(data);
}
$('#search_input_list-'+index).removeClass('d-none');
$('#search_input_list-'+index).html(productData);
}
});
}
function getProductDetail(product_id,index){
$.ajax({
type: 'POST',
url: "",
data: {productId:product_id},
success: function(resultData) {
var JSONArray = $.parseJSON(resultData);
//var productSku = product_sku.replace("-", "'");
//var productSku = product_sku;
$('#search-'+index).val(JSONArray.title[0].text);
$('#price-'+index).val(JSONArray.price);
$('#product_id-'+index).val(product_id);
$('#product_sku-'+index).val(JSONArray.sku);
$('#product_ean-'+index).val(JSONArray.ean);
$('#av_product_stock-'+index).removeClass('d-none');
$('#av_product_stock_val-'+index).text(JSONArray.stockCurrent);
$("#artical_number-"+index).attr('max',JSONArray.stockCurrent);
$('#search_input_list-'+index).addClass('d-none');
$('#search_input_list-'+index).html('');
}
});
}
// possitions Tab append function
function removePosition_color(classId){
$('.position_details-'+classId).remove();
}
$("#shipping_labels").change(function(){
var files = $(this)[0].files;
if(files.length > 1){
$("#uploaded_files").html('('+files.length+' Dateien hochgeladen)');
}else{
$("#uploaded_files").html('('+files.length+' Datei hochgeladen)');
}
});
function checkShop(){
var shop = $('#rsshop').val();
if(shop == ''){
alert('Shop auswählen is required!');
$('#email').val('');
}
}
function CheckNumeric(e) {
if (window.event) // IE
{
if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8 && e.keyCode != 44) {
event.returnValue = false;
return false;
}
}
else { // Fire Fox
if ((e.which < 48 || e.which > 57) & e.which != 8 && e.which != 44) {
e.preventDefault();
return false;
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment