Your IP : 216.73.216.79


Current Path : /var/www/html/crm/models/
Upload File :
Current File : /var/www/html/crm/models/Grn.php

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "grn".
 *
 * @property int $id
 * @property string $uuid
 * @property int $do_id
 * @property int $cust_id
 * @property int $com_id
 * @property int $product_id
 * @property int $quantity
 * @property string $received_dt
 * @property string $remarks
 * @property string $created_dt
 * @property int $created_by
 * @property string $updated_dt
 * @property int $updated_by
 */
class Grn extends \yii\db\ActiveRecord {

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return 'grn';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['uuid', 'do_id', 'cust_id', 'com_id', 'product_id', 'quantity', 'received_dt'], 'required'],
            [['do_id', 'cust_id', 'com_id', 'product_id', 'quantity', 'created_by', 'updated_by', 'resale_qty', 'noresale_qty'], 'integer'],
            [['received_dt', 'created_dt', 'updated_dt', 'status_inspection', 'inspect_by', 'inspect_dt', 'parent_id', 'owner_type', 'owner_id'], 'safe'],
            [['remarks'], 'string'],
                //[['uuid'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'uuid' => 'Uuid',
            'do_id' => 'DO Number',
            'cust_id' => 'Customer',
            'com_id' => 'Company',
            'product_id' => 'Product',
            'quantity' => 'Quantity',
            'received_dt' => 'Received Date',
            'remarks' => 'Remarks',
            'created_dt' => 'Created Dt',
            'created_by' => 'Created By',
            'updated_dt' => 'Updated Dt',
            'updated_by' => 'Updated By',
            'status_inspection' => 'Inspection Status',
            'resale_qty' => 'Quantity Resellable',
            'noresale_qty' => 'Quantity Not Resellable',
            'inspect_by' => 'Checked By',
            'inspect_dt' => 'Updated Date',
        ];
    }

    public function returnqty($product_id, $company_id) {
        $sql_ext = "";
        if ($company_id != 0)
            $sql_ext = " AND com_id='$company_id'";
        $sql = "SELECT SUM(quantity) FROM grn WHERE product_id='$product_id'" . $sql_ext;
        $total = (int) Yii::$app->db->createCommand($sql)->queryScalar();
        return $total;
    }

    public function pendinglabel($product_id, $company_id) {
        $sql_ext = "";
        if ($company_id != 0)
            $sql_ext = " AND com_id='$company_id'";
        $sql = "SELECT SUM(quantity) FROM grn WHERE product_id='$product_id' AND status_inspection='pending'" . $sql_ext;
        $total = (int) Yii::$app->db->createCommand($sql)->queryScalar();
        if ($total != 0) {
            return '&nbsp;&nbsp;<span class="kt-font-danger" data-toggle="tooltip" data-placement="top" title="' . $total . ' returned stock still pending inspection">
                <i class="fas fa-exclamation-triangle"></i>
                </span>';
        }
    }

}