/var/www/hkosl.com/littleark/webadmin/models/ProProductSku.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php

class ProProductSku extends BaseModel
{
    protected 
$table "pro_product_sku";

    public function 
proProduct()
    {
        return 
$this->belongsTo('ProProduct''product_id');
    }

    public function 
proImages()
    {
        return 
$this->hasMany('ProImage''sku_id');
    }

    public function 
supplier()
    {
        return 
$this->belongsTo('Supplier''supplier_id');
    }

    public function 
warehouseProductskus()
    {
        return 
$this->hasMany('WarehouseProductsku''sku_id');
    }

    public function 
proInstallments()
    {
        return 
$this->hasMany('ProInstallment''sku_id''id');
    }

    public function 
getProductName($wlangcode null)
    {
        
$wlangcode $wlangcode ?: $_SESSION["wlangcode"];
        return 
$this->proProduct->{"name_{$wlangcode}"};
    }

    public function 
getColorName($wlangcode null)
    {
        
$wlangcode $wlangcode ?: $_SESSION["wlangcode"];
        switch (
$this->color_code) {
            case 
"":
            case 
"N/A":
                return 
"";
            default:
                return 
$this->{"color_name_{$wlangcode}"};
        }
    }

    public function 
getSizeName($wlangcode null)
    {
        
$wlangcode $wlangcode ?: $_SESSION["wlangcode"];
        switch (
$this->size_code) {
            case 
"":
            case 
"N/A":
                return 
"";
            default:
                return 
$this->{"size_detail_{$wlangcode}"};
        }
    }

    public function 
getConfigName($wlangcode null)
    {
        
$wlangcode $wlangcode ?: $_SESSION["wlangcode"];
        switch (
$this->config_code) {
            case 
"":
            case 
"N/A":
                return 
"";
            default:
                return 
$this->{"config_name_{$wlangcode}"};
        }
    }

    public function 
getProductSkuName($wlangcode null)
    {
        
$wlangcode $wlangcode ?: $_SESSION["wlangcode"];

        
$sku_attr = ($this->getColorName($wlangcode) ? $this->getColorName($wlangcode) . " " "")
            . (
$this->getSizeName($wlangcode) ? $this->getSizeName($wlangcode) . " " "")
            . (
$this->getConfigName($wlangcode) ? $this->getConfigName($wlangcode) . " " "");

        
$s $this->getProductName($wlangcode);
        if (
$sku_attr) {
            
$sku_attr substr($sku_attr0, -1);
            
$s .= "({$sku_attr})";
        }

        return 
$s;
    }

    public function 
getAvailableQty()
    {
        return 
$this->qty $this->reserved_qty;
    }

    public function 
getInventoryQty($warehouse_id false)
    {
        
$query Inventory::whereDeleted(0)
            ->
where('productsku_id'$this->id)
            ->
where('qty''>'0);

        if (
$warehouse_id) {
            
$query->where('warehouse_id'$warehouse_id);
        }
        return 
$query->sum('qty');
    }

    public function 
getCurrentOrderQty(){}

    public function 
getSupplierRemainingQty(){}

    
// public function getAvailableQty(){
    //  inventoryQty/$qty - currentOrderQty - reservedQty
    // }
}