| Current Path : /var/www/html/crm/models/ |
| Current File : /var/www/html/crm/models/DeliveryOrderItem.php |
<?php
namespace app\models;
use Yii;
use app\models\Grn;
/**
* This is the model class for table "delivery_order_item".
*
* @property int $id
* @property int $doc_id
* @property int $product_id
* @property string $uom
* @property int $quantity
* @property string $unit_price
* @property string $discount
* @property string $total
* @property string $created_dt
* @property int $created_by
* @property string $updated_dt
* @property int $updated_by
*/
class DeliveryOrderItem extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'delivery_order_item';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['doc_id', 'product_id', 'quantity', 'created_by', 'updated_by'], 'integer'],
[['created_dt', 'updated_dt', 'remarks', 'total', 'unit_price', 'discount', 'owner_type', 'owner_id'], 'safe'],
[['uom'], 'string', 'max' => 20],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'doc_id' => 'Doc ID',
'product_id' => 'Product ID',
'uom' => 'Uom',
'quantity' => 'Quantity',
'unit_price' => 'Unit Price',
'discount' => 'Discount',
'total' => 'Total',
'created_dt' => 'Created Dt',
'created_by' => 'Created By',
'updated_dt' => 'Updated Dt',
'updated_by' => 'Updated By',
];
}
public function getqtysend($doc_id, $product_id) {
$totalsend = 0;
//get quantity send
if (($model = static::findOne(['doc_id' => $doc_id, 'product_id' => $product_id])) !== null) {
$totalsend = $model->quantity;
}
//get product already received
$totalreturn = 0;
$modelgrn = Grn::find()->where(['do_id' => $doc_id])->andwhere(['product_id' => $product_id])->all();
if (!empty($modelgrn)) {
foreach ($modelgrn as $rowgrn) {
$totalreturn+=$rowgrn->quantity;
}
}
$output = $totalsend - $totalreturn;
return $output;
}
public function getownertype($doc_id, $product_id) {
$output = '';
if (($model = static::findOne(['doc_id' => $doc_id, 'product_id' => $product_id])) !== null) {
$output = $model->owner_type;
}
return $output;
}
public function getownerid($doc_id, $product_id) {
$output = '';
if (($model = static::findOne(['doc_id' => $doc_id, 'product_id' => $product_id])) !== null) {
$output = $model->owner_id;
}
return $output;
}
}