Skip to content

Commit

Permalink
Merge pull request #7 from BernhardK91/1.0.0
Browse files Browse the repository at this point in the history
Version 1.0.0
  • Loading branch information
BernhardK91 authored May 11, 2020
2 parents 8e63e37 + ea42c8c commit d6b235b
Show file tree
Hide file tree
Showing 54 changed files with 1,473 additions and 592 deletions.
7 changes: 6 additions & 1 deletion src/Bios2000.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
use Bios2000\Models\Database\ProductionOrderPositions;
use Bios2000\Models\Database\RepresentativeSales;

/**
* Class Bios2000
* @package Bios2000
* @deprecated
*/
class Bios2000
{

Expand Down Expand Up @@ -90,4 +95,4 @@ public function productionOrderPositions()
{
return new ProductionOrderPositions;
}
}
}
44 changes: 44 additions & 0 deletions src/Models/Adresse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Bios2000\Models;

use Eloquent;

/**
* Class Adresse
* @mixin Eloquent
* @package Bios2000\Models
*/
class Adresse extends Bios2000Master
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'ADRESSEN';

/**
* Primary Key
*
* @var string
*/
protected $primaryKey = 'KUNU';

/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['ANLAGE_DATUM', 'AENDERUNG_DATUM'];

/**
* Returns contact persons relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function ansprechpartner()
{
return $this->hasMany(Ansprechpartner::class, 'KUNU', 'KUNU');
}
}
44 changes: 44 additions & 0 deletions src/Models/Ansprechpartner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Bios2000\Models;

use Bios2000\Models\Bios2000Master;
use Bios2000\Traits\HasCompositePrimaryKey;
use Eloquent;

/**
* Class Ansprechpartner
* @mixin Eloquent
* @package Bios2000\Models
*/
class Ansprechpartner extends Bios2000Master
{
use HasCompositePrimaryKey;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'ANSPRECHPARTNER';

/**
* Primary Keys
*
* @var array
*/
protected $primaryKey = ['NUMMER', 'KUERZEL'];

public $incrementing = false;

/**
* Returns customer/supplier (address) relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function adresse()
{
return $this->belongsTo(Adresse::class, 'KUNU', 'KUNU');
}

}
157 changes: 157 additions & 0 deletions src/Models/Archiv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

namespace Bios2000\Models;

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Exception;
use Illuminate\Support\Facades\Schema;
use function foo\func;

/*
* TODO: This should be optimized.
*/

/**
* Class Archiv
* @package Bios2000\Models
*/
class Archiv
{

/**
* Returns meta data of a single delivery note
*
* @param int $number
* @return mixed
*/
public static function deliverynote(int $number)
{
$filter = [
'ART' => 'LS',
'BELEG' => $number,
];

/*
* Return only first Result
*/
return (new Archiv)->aw($filter)[0][0];
}

/**
* Returns meta data of a single delivery note
*
* @param int $number
* @return mixed
*/
public static function deliverynotePosten(int $number)
{
$filter = [
'ART' => 'LS',
'BELEG' => $number,
];

/*
* Return only first Result
*/
return (new Archiv)->aw($filter, false)[0];
}

/**
* Returns result filtered by $arguments of "Auftragswesen" (AW)
*
* @param array $arguments
* @param bool $kopf
* @return Collection
*/
private function aw(array $arguments, bool $kopf = true)
{
return $this->archive('AW', $arguments, $kopf);
}

/**
* Returns result of all archives filtered by $arguments, selected by $archive
*
* @param string $archive
* @param array $arguments
* @param bool $kopf (default: true) true = _KOPF, false = _POSTEN
* @return Collection
*/
private function archive(string $archive, array $arguments, bool $kopf = true)
{
$year = date('Y');

$result = new Collection();

while (1) {
if ($kopf) {
$tableName = config('database.connections.bios2000.dba') . '.dbo.' . $archive . '_ARCHIV_' . $year . '_KOPF';
} else {
$tableName = config('database.connections.bios2000.dba') . '.dbo.' . $archive . '_ARCHIV_' . $year . '_POSTEN';
}

try {
DB::connection('bios2000')->table($tableName)->select('ART')->first();
} catch (Exception $e) {
if ($year == date('Y')) continue;
break;
}

if ($kopf) {
if (DB::connection('bios2000')->table($tableName)
->where($arguments)
->orderBy('VERSION', 'desc')
->count() != 0) {

if ($year < date('Y')) {
$dbResult = Cache::rememberForever('bios2000_archive_' . $archive . '_' . $year . '_kopf_' . implode('-', $arguments),
function () use ($tableName, $arguments) {
return DB::connection('bios2000')->table($tableName)
->where($arguments)
->orderBy('VERSION', 'desc')->get()->all();
});
} else {
$dbResult = DB::connection('bios2000')->table($tableName)
->where($arguments)
->orderBy('VERSION', 'desc')->get()->all();
}

$result->push($dbResult);
}

} else {
if (DB::connection('bios2000')->table($tableName)
->where('POSITIONS_NR', '!=', null)
->where($arguments)
->orderBy('VERSION', 'desc')
->count() != 0) {

if ($year < date('Y')) {
$dbResult = Cache::rememberForever('bios2000_archive_' . $archive . '_' . $year . '_posten_' . implode('-', $arguments),
function () use ($tableName, $arguments) {
return DB::connection('bios2000')->table($tableName)
->where('POSITIONS_NR', '!=', null)
->where($arguments)
->orderBy('VERSION', 'desc')->get()->all();
});

} else {
$dbResult = DB::connection('bios2000')->table($tableName)
->where('POSITIONS_NR', '!=', null)
->where($arguments)
->orderBy('VERSION', 'desc')->get()->all();
}

$result->push($dbResult);

}
}

$year--;
}

return $result;
}

}
5 changes: 5 additions & 0 deletions src/Models/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
use Illuminate\Support\Facades\DB;
use Exception;

/**
* Class Archive
* @package Bios2000\Models
* @deprecated
*/
class Archive
{

Expand Down
93 changes: 93 additions & 0 deletions src/Models/Artikel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Bios2000\Models;

use Bios2000\Models\Bios2000Master;
use Eloquent;
use Illuminate\Support\Facades\DB;

/**
* Class Artikel
* @mixin Eloquent
* @package Bios2000\Models
*/
class Artikel extends Bios2000Master
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'ARTIKEL_STAMM';

/**
* Primary Key
*
* @var string
*/
protected $primaryKey = 'ARTNR';

public $incrementing = false;

/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['ANLAGE_DATUM', 'AENDERUNG_DATUM'];

/**
* Return chaotic warehouse relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function chaotLager()
{
return $this->hasMany(ChaotLager::class, 'ARTNR', 'ARTNR');
}

/**
* Returns additional texts relationship.
*
* @param int $lang Language number (optional, default is german)
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function zusatztexte($lang = 0)
{
return $this->hasMany(ArtikelZusatztext::class, 'ARTNR', 'ARTNR')
->where('SPRACHE', $lang);
}

/**
* Return warehouses relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function lager()
{
return $this->hasMany(ArtikelLager::class, 'ARTNR', 'ARTNR');
}

public function bestand()
{
return DB::connection($this->connection)->table('ARTIKEL_LAGER')
->select(DB::raw("sum(BESTAND)-(SELECT ISNULL(sum(d.BESTAND), 0.00) FROM ARTIKEL_LAGER d (NOLOCK) WHERE
(d.ARTNR = '" . $this->ARTNR . "' AND d.LAGER = -1)) -(SELECT ISNULL(sum(d.BESTAND), 0.00) FROM
ARTIKEL_LAGER d (NOLOCK) WHERE (d.ARTNR = '" . $this->ARTNR . "' AND d.LAGER IN (SELECT y.NUMMER FROM
SCHLUESSEL y WHERE y.ART = 'LG' AND y.EU_KZ = 'J' ))) as SUM_BESTAND"))
->addSelect(DB::raw("sum(BESTELLT) as SUM_BESTELLT"))
->addSelect(DB::raw("sum(RUECKSTAND) as SUM_RUECKSTAND"))
->addSelect(DB::raw("sum(MIBEST) as SUM_MIBEST"))
->addSelect(DB::raw("sum(SOLLBEST) as SUM_SOLLBEST"))
->addSelect(DB::raw("sum(BBK) as SUM_BBK"))
->addSelect(DB::raw("(SELECT ISNULL(sum(a.GELIEFERT), 0.00) FROM AUFTRAG_POSTEN a (NOLOCK) WHERE (a.ART = 'A' AND a.ZEILEN_ART = 'L' AND a.ARTNR = '" . $this->ARTNR . "'))
+(SELECT ISNULL(sum(d.BESTAND), 0.00) FROM ARTIKEL_LAGER d (NOLOCK) WHERE (d.ARTNR = '" . $this->ARTNR . "' AND d.LAGER = -1))
+(SELECT ISNULL(sum(p.ABRUFMENGE), 0.00) FROM VDA_ABRUF_POSTEN p (NOLOCK)
LEFT OUTER JOIN VDA_ABRUF_KOPF k (NOLOCK) ON (p.NUMMER = k.NUMMER)
WHERE (k.ARTNR = '" . $this->ARTNR . "') AND (k.TESTKENNZEICHEN = 0) AND (p.GELIEFERT_FLAG = 'J'))
+(SELECT ISNULL(sum(g.GELIEFERT),0.00) FROM PACKMITTEL_ARTNR_GELIEFERT g (NOLOCK) WHERE (g.ARTNR = '" . $this->ARTNR . "')) as SUM_RESERVIERT"))
->where('ARTNR', '=', $this->ARTNR)
->where('LAGER', '!=', '6')// 6 = Sperrlager
->first();
}
}
Loading

0 comments on commit d6b235b

Please sign in to comment.