ANpassungen für den Import

This commit is contained in:
Daniel Greim 2023-09-29 10:31:39 +02:00
parent a97fec167c
commit 5119c70b0f
2 changed files with 295 additions and 23 deletions

View File

@ -2,6 +2,7 @@
namespace App\Command;
use App\Entity\Order;
use App\Repository\OrderRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
@ -44,22 +45,133 @@ class HiltesExportCommand extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->info('Start Hiltes Export');
$l = $this->hiltes->loginToHiltes('','');
if(!$l){
dd('Login faild'.'STOP '.__METHOD__.' / '.__LINE__);
}
$orders = $this->orderRepository->findAll();
dump($orders);
#dump($orders);
/**
* @var Order
*/
$order = false;
foreach ($orders as $order) {
$this->hiltes->addOrder($order);
if($order->getStatus()>0) continue;
$tA = $order->getData();#json_decode($order->getData());
#dd($order->getData());
#dd(array(
# 'orderdate'=> $tA['orderdate'],
# 'time'=> strtotime($tA['orderdate']),
# 'gmdate '=> gmdate ('d-m-Y\TH:i:s.v\Z',strtotime($tA['orderdate'])),
#));
#*** Umkonvertieren des Datumstings *****************
$tA['orderdate'] = gmdate ('Y-m-d\TH:i:s.v\Z',strtotime($tA['orderdate']));
#****
$arr = array(
'SalesDate' => $tA['orderdate'],
"BranchNumber" => 8, #Die Filialnummer
"ShopNumber" => 1, #Die Shopnummer
"DistributionChannel" => 5, #Der Vertriebskanal
'SaleList' => array(),
'CustomerList' => array(),
);
#*** Items ***************
if(!empty($tA['data']) && is_array($tA['data'])){
# Noch nötig
# "CalculatedSellingPrice" => 0, #X Kalkulierter Verkaufspreis
# "AchievedSalesPrice" => 0, #X Erzielter Verkaufspreis
$tSalNr = array();
foreach ($tA['data'] as $v){
$SalesNumber = (!empty($v['gtin']) ? $v['gtin'] : $v['sku']);
if(preg_match('/^([0-9]+)_/',$SalesNumber,$tP)){
$SalesNumber = $tP[1];
}
if(isset($tSalNr[$SalesNumber])){
$tSalNr[$SalesNumber]++;
$SalesNumber.= $tSalNr[$SalesNumber];
}else{
$tSalNr[$SalesNumber] = 0;
}
#dump($SalesNumber);
#********
$v['CalculatedSellingPrice'] = 100.00;
$v['AchievedSalesPrice'] = 90.00;
$arr['SaleList'][] = array(
"SalesLabel" => 'Ean',#$v['sku'],#X
"SalesLabelNumber" => $SalesNumber,#X
"SalesGoodsGroupNumber" => 0,
"SizeDescription" => '',#"string",
"CustomerNumber" => 0,
"TypeOfEstate" => 0,
"Amount" => $v['menge'],#X
"CalculatedSellingPrice" => $v['CalculatedSellingPrice'], #X Kalkulierter Verkaufspreis
"AchievedSalesPrice" => $v['AchievedSalesPrice'], #X Erzielter Verkaufspreis
"TransactionType" => "Sale", #X Die Vorgangsart Sale=Verkauf Exchange=Umtausch / Storno
"ReceiptNumber" => 0, #Die Belegnummer
"DateOfSale" => $tA['orderdate'],#X das Verkaufsdatum mit Verkaufszeit
"PaymentMethod" => 'Invoice',#X "CreditCard",
"Currency" => 'EUR',#X "string",
"Unit" => "Piece",#X
"DistributionChannel" => 'JTL',#"string"
);
}
}
#*** Kundne *******************************
$arr['CustomerList'][] = array(
"CustomerNumber" => 99999, # Fake Daten
"Surname" => 'MAX',#"string",
"Forename" => 'MUSTERMANN',#"string",
"AddressCity" => 'ERFURT',#"string",
"AddressZipCode" => '99084',"string",
"AddressStreet" => 'MusterStrasse 22',#"string",
"AddressCountry" => 'DE',#"string",
#*** Nicht nötig
#"CardNumber" => 0,
#"SalutionNumber" => 0,
#"PostOfficeBox" => '',#"string",
#"PostOfficeBoxZipCode" => '',#"string",
#"Title" => '',#"string",
#"PhoneNumber1" => '',#"string",
#"PhoneNumber2" => '',#"string",
#"FaxNumber" => '',#"string",
#"BirthDay" => '',#"2023-09-14T11:54:26.708Z",
#"Gender" => 'Male',
#"EmailAddress" => '',#"string",
#"Discount" => 0,
#"Limit" => 0,
#"LockMark" => 'Unblocked',
#"DubiousMark" => 'Undubious',
#"DubiousText" => '',#"string",
#"DirectDebit" => '',#true,
#"BankName1" => '',#"string",
#"BankAccountNumber1" => '',#"string",
#"BankCodeNumber1" => '',#"string",
#"BankName2" => '',#"string",
#"BankAccountNumber2" => '',#"string",
#"BankCodeNumber2" => '',#"string",
#"BankName3" => '',#"string",
#"BankAccountNumber3" => '',#"string",
#"BankCodeNumber3" => '',#"string",
#"CreditcardNumber1" => '',#"string",
#"CreditcardNumber2" => '',#"string",
#"CreditcardNumber3" => '',#"string",
#"CreditcardNumber4" => '',#"string",
#"ChangeIndicator" => '',#true,
#"Newsletter" => '',#true,
#"Password" => '',#"string",
#"AdBan" => '',#true
);
$data = $this->hiltes->createJson($arr);
}
$this->hiltes->export('Test Test');
$this->hiltes->sendOrderToHiltes($data);
$io->success('Done!');

View File

@ -12,6 +12,11 @@ class Hiltes
// init file system
protected $fsObject;
protected $current_dir_path;
protected $apiKey;
protected $hiltesApiHash = '';
protected $hiltesUsr = 'admin';
protected $hiltesPass = '1996';
protected $hiltesApiUrl = 'https://api.orangejungle.eu';
public function __construct()
{
@ -20,7 +25,6 @@ class Hiltes
}
/**
* Aufbau des Dateinamens:
* WU + Datum(TTMM) + Fortlaufendenummer (x2) + . +Filialnummer(x4)
@ -55,9 +59,7 @@ class Hiltes
*/
public function export(string $data)
{
try {
$new_file_path = $this->current_dir_path . "/hiltes/c2h/".$this->createFileName();
if (!$this->fsObject->exists($new_file_path))
@ -134,6 +136,164 @@ class Hiltes
'Werbesperre'=> '0', // 0 = keine Werbung, 1 = Werbung
];
}
public function createJson($data){
$arr = array(
'File' => array(
"BranchNumber" => $data['BranchNumber'], #Die Filialnummer
"ShopNumber" => $data['ShopNumber'], #Die Shopnummer
"SalesDate" => $data['SalesDate'], #Das Umsatzdatu
"DistributionChannel" => $data['DistributionChannel'] #Der Vertriebskanal
),
'SaleList' => array(
),
'CustomerList' => array(
),
);
#*** Sale List
if(!empty($data['SaleList'])){
foreach ($data['SaleList'] as $v){
$arr['SaleList'][] = array(
"SalesLabel" => $v['SalesLabel'], #Das Etikettkennzeichen
"SalesLabelNumber" => $v['SalesLabelNumber'], #Etikettennummer
"SalesGoodsGroupNumber" => $v['SalesGoodsGroupNumber'],
#"SizeDescription" => $v['SizeDescription'],
#"CustomerNumber" => $v['CustomerNumber'],
#"TypeOfEstate" => $v['TypeOfEstate'],
"Amount" => $v['Amount'],
"CalculatedSellingPrice" => $v['CalculatedSellingPrice'],
"AchievedSalesPrice" => $v['AchievedSalesPrice'],
"TransactionType" => $v['TransactionType'],
#"ReceiptNumber" => $v['ReceiptNumber'],
"DateOfSale" => $data['SalesDate'],#"2023-09-14T11:54:26.708Z",
"PaymentMethod" => $v['PaymentMethod'],
"Currency" => $v['Currency'],
"Unit" => $v['Unit'],
"DistributionChannel" => $v['DistributionChannel']
);
}
}
#*** Sale List
if(true){
foreach ($data['CustomerList'] as $v){
$arr['CustomerList'][] = array(
"CustomerNumber" => $v['CustomerNumber'],
#"CardNumber" => $v['CardNumber'],
#"SalutionNumber" => $v['SalutionNumber'],
"Surname" => $v['Surname'],
"Forename" => $v['Forename'],
"AddressCity" => $v['AddressCity'],
"AddressZipCode" => $v['AddressZipCode'],
"AddressStreet" => $v['AddressStreet'],
"AddressCountry" => $v['AddressCountry'],
#"PostOfficeBox" => $v['PostOfficeBox'],
#"PostOfficeBoxZipCode" => $v['PostOfficeBoxZipCode'],
#"Title" => $v['Title'],
#"PhoneNumber1" => $v['PhoneNumber1'],
#"PhoneNumber2" => $v['PhoneNumber2'],
#"FaxNumber" => $v['FaxNumber'],#"string",
#"BirthDay" => $v['BirthDay'],
#"Gender" => $v['Gender'],
#"EmailAddress" => $v['EmailAddress'],
#"Discount" => $v['Discount'],
#"Limit" => $v['Limit'],
#"LockMark" => $v['LockMark'],
#"DubiousMark" => $v['DubiousMark'],
#"DubiousText" => $v['DubiousText'],
#"DirectDebit" => $v['DirectDebit'],
#"BankName1" => $v['BankName1'],#"string",
#"BankAccountNumber1" => $v['BankAccountNumber1'],#"string",
#"BankCodeNumber1" => $v['BankCodeNumber1'],#"string",
#"BankName2" => $v['BankName2'],#"string",
#"BankAccountNumber2" => $v['BankAccountNumber2'],#"string",
#"BankCodeNumber2" => $v['BankCodeNumber2'],#"string",
#"BankName3" => $v['BankName3'],#"string",
#"BankAccountNumber3" => $v['BankAccountNumber3'],#"string",
#"BankCodeNumber3" => $v['BankCodeNumber3'],#"string",
#"CreditcardNumber1" => $v['CreditcardNumber1'],#"string",
#"CreditcardNumber2" => $v['CreditcardNumber2'],#"string",
#"CreditcardNumber3" => $v['CreditcardNumber3'],#"string",
#"CreditcardNumber4" => $v['CreditcardNumber4'],#"string",
#"ChangeIndicator" => $v['ChangeIndicator'],
#"Newsletter" => $v['Newsletter'],
#"Password" => $v['Password'],
#"AdBan" => $v['AdBan']
);
}
}
#dump($arr);
return $arr;
}
public function sendToHiltes($url,$param,$auth=false){
if($auth){
#var_export($this->hiltesApiHash);
#var_export($url);
#var_export($param);
}
$ch = curl_init($url);
if($auth){
$authorization = "Authorization: Bearer ".$this->hiltesApiHash;
}else{
$authorization = false;
}
#dump($param);
# Setup request to send json via POST.
$payload = json_encode( $param );
#dump($payload);
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json',$authorization));
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
public function loginToHiltes($usr,$pass){
$url = $this->hiltesApiUrl.'/api/Authentication/authenticate';
/*
{
"Username": "string",
"Password": "string"
}
*/
$param = array(
'Username' => (!empty($usr) ? $usr : $this->hiltesUsr),
'Password' => (!empty($pass) ? $pass : $this->hiltesPass),
# 'parse_mode' => 'html',
# 'disable_notification' => $disable_notification,
# 'text' => $message_text
);
$r = $this->sendToHiltes($url,$param);
$t = json_decode($r,true);
if($t['Success']){
$this->hiltesApiHash = $t['Data'];
return true;
}else{
dump($r);
dump('Login Error');
return false;
}
}
public function sendOrderToHiltes($data){
$url = $this->hiltesApiUrl.'/api/WebSale/import';
/*
{
"Username": "string",
"Password": "string"
}
*/
$param = $data;
dump($param);
$r = $this->sendToHiltes($url,$param,true);
$t = json_decode($r,true);
if($t['Success']){
$this->hiltesApiHash = $t['Data'];
}else{
dump($r);
dd('Login Error');
}
}
}