Skip to content

Commit

Permalink
Added method stock() for article
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Krämer committed Jun 1, 2019
1 parent 6eab1cc commit a37ebda
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Models/Database/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Bios2000\Models\Database;

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

class Article extends Bios2000Master
{
Expand Down Expand Up @@ -33,4 +34,29 @@ public function additionaltext($lang = 0)
{
return $this->hasMany('Bios2000\Models\Database\ArticleAdditionaltext', 'ARTNR', 'ARTNR')->where('SPRACHE', $lang);
}

public function stock()
{
$article_stock = 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();

return $article_stock;
}
}

0 comments on commit a37ebda

Please sign in to comment.