Customers Add+Edit, API WP

This commit is contained in:
Kevin Adametz 2020-06-12 14:46:51 +02:00
parent dc63fa9fb2
commit 75a0f9a38a
120 changed files with 11894 additions and 6134 deletions

View file

@ -29,7 +29,7 @@ class CustomerPriority
return $shopping_users;
}
public static function checkOne($shopping_user, $mail=false){
public static function checkOne($shopping_user, $mail=false, $newCustomer = true){
//look for entry
if(self::entryExists($shopping_user)){
return 'exists';
@ -40,16 +40,23 @@ class CustomerPriority
}
return 'like';
}
self::newCustomer($shopping_user);
return 'update';
if($newCustomer){
self::newCustomer($shopping_user);
}
return 'new';
}
public static function setIsLike($shopping_user, $set_like_shopping_user, $send_member_mail)
public static function setIsLike($shopping_user, $set_like_shopping_user, $send_member_mail, $change_shopping_user=false)
{
if ($shopping_user->id === $set_like_shopping_user->id) {
//set new customer for shopping_user
self::newCustomer($shopping_user);
if($change_shopping_user){
self::newCustomerNumber($shopping_user);
$send_member_mail = false;
}else{
self::newCustomer($shopping_user);
}
} else {
//set existing customer for shopping_user
self::existingCustomer($shopping_user, $set_like_shopping_user);
@ -104,6 +111,71 @@ class CustomerPriority
}
}
public static function checkChangeOne($shopping_user, $data, $mail=false){
$matches = [];
$change = [];
$ret = 'update';
//email geändert
if(isset($data['billing_email']) && $shopping_user->billing_email != $data['billing_email']){
$found = ShoppingUser::where('auth_user_id', '=', NULL)
->where('number', '!=', NULL) //has number
->where('id', '!=', $shopping_user->id)
->where('billing_email', '=', $data['billing_email'])
->get()->pluck('number', 'id')->unique()->toArray();
if($found && count($found)){
foreach ($found as $key=>$val){
$matches[$key] = $val;
}
$ret = 'exists';
$change['billing_email'] = $data['billing_email'];
}
}
//Anschrift geändert
if(isset($data['billing_lastname']) && isset($data['billing_zipcode']) && ($shopping_user->billing_lastname != $data['billing_lastname'] || $shopping_user->billing_zipcode != $data['billing_zipcode'])){
$found = ShoppingUser::select('*')
->where('auth_user_id', '=', NULL)
->where('number', '!=', NULL) //has number
->where('id', '!=', $shopping_user->id)
->where('billing_lastname', '=', $data['billing_lastname'])
->where('billing_zipcode', '=', $data['billing_zipcode'])
->get()->pluck('number', 'id')->unique()->toArray();
if($found && count($found)){
foreach ($found as $key=>$val){
$matches[$key] = $val;
}
$ret = 'like';
$change['billing_lastname'] = $data['billing_lastname'];
$change['billing_zipcode'] = $data['billing_zipcode'];
}
}
if($matches){
$shopping_user->is_like = true;
$shopping_user->setNotice(self::$user_notice_key, $matches);
$shopping_user->save();
}
//look for entry
if($matches && $mail){ //send mail
Mail::to(config('app.info_mail'))->send(new MailInfo($shopping_user, 'change_is_like_customer', $change));
}
return $ret;
}
public static function checkNewOne($shopping_user, $mail=false){
if(self::entryLike($shopping_user)){
if($mail){ //send mail
Mail::to(config('app.info_mail'))->send(new MailInfo($shopping_user, 'check_is_like_customer'));
}
//return 'like';
}
$shopping_user->number = self::nextNumber();
$shopping_user->save();
return true;
}
private static function entryExists($shopping_user){
//check same email
$matches = ShoppingUser::where('auth_user_id', '=', NULL)
@ -155,8 +227,16 @@ class CustomerPriority
}
}
private static function changeCustomer($shopping_user, $member_id, $number){
private static function newCustomerNumber($shopping_user)
{
\App\Services\Shop::newUserOrder($shopping_user->number);
$shopping_user->number = self::nextNumber();
$shopping_user->save();
\App\Services\Shop::newUserOrder($shopping_user->number);
}
private static function changeCustomer($shopping_user, $member_id, $number){
$old_number = $shopping_user->number;
$shopping_user->member_id = $member_id;
$shopping_user->number = $number;
@ -167,12 +247,10 @@ class CustomerPriority
}
\App\Services\Shop::newUserOrder($old_number);
\App\Services\Shop::newUserOrder($number);
}
private static function existingCustomer($shopping_user, $set_like_shopping_user){
$old_number = $shopping_user->number;
$shopping_user->member_id = $set_like_shopping_user->member_id;
$shopping_user->number = $set_like_shopping_user->number;
$shopping_user->save();

View file

@ -13,6 +13,7 @@ class Payment
'paid' => "bezahlt",
'appointed' => "offen",
'failed' => "abbruch",
'extern' => "extern",
'NULL' => 'keine Zahlung',
];
@ -20,6 +21,7 @@ class Payment
'paid' => "success",
'appointed' => "warning",
'failed' => "danger",
'extern' => "success",
];
@ -41,6 +43,9 @@ class Payment
if($shopping_order->mode === 'test'){
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_order->mode).' - '.self::getFormattedTxaction($shopping_order->txaction).'</span>';
}
if($shopping_order->mode === 'dev'){
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_order->mode).' - '.self::getFormattedTxaction($shopping_order->txaction).'</span>';
}
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_order->txaction).'">'.self::getFormattedTxaction($shopping_order->txaction).'</span>';
}

View file

@ -8,7 +8,7 @@ class Shop
{
public static function userOrders() {
$shopping_users = ShoppingUser::whereHas('shopping_order', function($q) {
$q->where('txaction', 'paid')->OrWhere('txaction', 'appointed');
$q->where('txaction', 'paid')->OrWhere('txaction', 'appointed')->OrWhere('txaction', 'extern');
})->where('orders', '=', NULL)->get();
foreach ($shopping_users as $shopping_user) {
if ($shopping_user->number) {
@ -24,17 +24,19 @@ class Shop
}
public static function newUserOrder($number){
$shopping_users = ShoppingUser::where('number', '=', $number)->get();
$orders = 1;
foreach ($shopping_users as $shopping_user) {
if($shopping_user->shopping_order && ($shopping_user->shopping_order->txaction === 'paid' || $shopping_user->shopping_order->txaction === 'appointed')){
$shopping_user->orders = $orders++;
if($number > 0){
$shopping_users = ShoppingUser::where('number', '=', $number)->get();
$orders = 1;
foreach ($shopping_users as $shopping_user) {
if($shopping_user->shopping_order && ($shopping_user->shopping_order->txaction === 'paid' || $shopping_user->shopping_order->txaction === 'appointed' || $shopping_user->shopping_order->txaction === 'extern')){
$shopping_user->orders = $orders++;
}else{
$shopping_user->orders = NULL;
}
$shopping_user->save();
}else{
$shopping_user->orders = NULL;
}
$shopping_user->save();
}
}
}

View file

@ -37,11 +37,20 @@ class Util
return 'd.m.Y - H:i';
}
public static function formatNumber($value){
public static function _format_number($value){
return preg_replace("/[^0-9,]/", "", $value);
}
public static function reFormatNumber($value){
return (float) str_replace(',', '.', self::_format_number($value));
}
public static function formatNumber($value, $dec=2){
if(\App::getLocale() === "en"){
return number_format($value, 2, '.', ',');
return number_format($value, $dec, '.', ',');
}
return number_format($value, 2, ',', '.');
return number_format($value, $dec, ',', '.');
}
public static function utf8ize( $mixed ) {

View file

@ -183,7 +183,7 @@ class Yard extends Cart
public function subtotalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$taxRate =config('cart.tax');
$total = floatval($this->total(2, '.', '')) + $this->shipping;
$total = (float) ($this->total(2, '.', '')) + $this->shipping;
$totalTax = $total/ (100 + $taxRate) * $taxRate;
return $this->numberFormat(($total - $totalTax), $decimals, $decimalPoint, $thousandSeperator);
}
@ -192,7 +192,7 @@ class Yard extends Cart
public function taxWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$taxRate =config('cart.tax');
$total = floatval($this->total(2, '.', '')) + $this->shipping;
$total = (float) ($this->total(2, '.', '')) + $this->shipping;
$totalTax = $total/ (100 + $taxRate) * $taxRate;
return $this->numberFormat($totalTax, $decimals, $decimalPoint, $thousandSeperator);
}
@ -200,7 +200,7 @@ class Yard extends Cart
public function totalWithShipping($decimals = null, $decimalPoint = null, $thousandSeperator = null)
{
$total = floatval($this->total(2, '.', '')) + $this->shipping;
$total = (float) ($this->total(2, '.', '')) + $this->shipping;
return $this->numberFormat($total, $decimals, $decimalPoint, $thousandSeperator);
}