示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = GoodsMovementModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'warehouse_id' => $this->warehouse_id, 'date' => $this->date, 'type' => $this->type, 'reff_type' => $this->reff_type, 'reff_id' => $this->reff_id, 'vendor_id' => $this->vendor_id, 'status' => $this->status, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'number', $this->number])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
示例#2
0
 /**
  * Creates a new Invoice model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Invoice();
     $dgets = Yii::$app->request->get();
     $model->load($dgets);
     $model->reff_type = $model->type == $model::TYPE_INCOMING ? $model::REFF_PURCH : null;
     $model->reff_type = $model->type == $model::TYPE_OUTGOING ? $model::REFF_SALES : $model->reff_type;
     $model->status = Invoice::STATUS_DRAFT;
     $model->date = date('Y-m-d');
     $model->due_date = date('Y-m-d', time() + 30 * 24 * 3600);
     $model->value = 0;
     if (isset($dgets['goodsMovement']['id'])) {
         $gmv = \backend\models\inventory\GoodsMovement::find()->where(['=', 'id', $dgets['goodsMovement']['id']])->with(['vendor'])->one();
         $model->reff_type = $model::REFF_GOODS_MOVEMENT;
         $model->reff_id = $gmv->id;
         $model->vendor_id = $gmv->vendor_id;
         $model->vendor_name = $gmv->vendor->name;
         $model->description = 'GR Invoice';
         $gmItems = [];
         $subtotal = 0;
         foreach ($gmv->items as $rvalue) {
             $ditem = new \backend\models\accounting\InvoiceDtl();
             $ditem->item_id = $rvalue->product_id;
             $ditem->qty = $rvalue->qty;
             $ditem->item_value = $rvalue->cogs;
             $subtotal += $rvalue->qty * $rvalue->cogs;
             $gmItems[] = $ditem;
         }
         $model->value = $subtotal;
         $model->items = $gmItems;
     }
     if ($model->load(Yii::$app->request->post())) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $model->items = Yii::$app->request->post('InvoiceDtl', []);
             if ($model->save()) {
                 $transaction->commit();
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } catch (\Exception $exc) {
             $transaction->rollBack();
             throw $exc;
         }
         $transaction->rollBack();
     }
     return $this->render('create', ['model' => $model]);
 }
示例#3
0
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="col-lg-12">
    <div class='btn-group pull-right'>
        <?php 
echo Html::button('New Good Movement', ['class' => 'btn bg-aqua', 'type' => 'button']);
?>
        
        <?php 
echo Html::button('<span class="caret"></span><span class="sr-only">Toggle Dropdown</span>', ['class' => 'btn btn-default dropdown-toggle', 'aria-expanded' => false, 'type' => 'button', 'data-toggle' => 'dropdown']);
?>
        <ul class="dropdown-menu" role="menu">
            <li><?php 
echo Html::a('Receive', ['create', 'type' => $searchModel::TYPE_RECEIVE]);
?>
</li>
            <li><?php 
echo Html::a('Issue', ['create', 'type' => $searchModel::TYPE_ISSUE]);
?>
</li>
        </ul>        
    </div>
</div>
<br><br>
<div class="col-lg-12 goods-movement-index">
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'tableOptions' => ['class' => 'table table-hover'], 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'number', 'nmReffType', ['attribute' => 'warehouse_id', 'value' => 'warehouse.name', 'filter' => Warehouse::selectOptions()], ['attribute' => 'vendor_id', 'value' => 'vendor.name'], 'Date', ['attribute' => 'type', 'value' => 'nmType', 'filter' => GoodsMovement::enums('TYPE_')], ['attribute' => 'status', 'value' => 'nmStatus', 'filter' => GoodsMovement::enums('STATUS_')], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getGMovement()
 {
     return $this->hasOne(\backend\models\inventory\GoodsMovement::className(), ['id' => 'reff_id']);
 }
示例#5
0
 /**
  * Deletes an existing Sales model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if ($model->status == Sales::STATUS_DRAFT) {
         $model->delete();
         return $this->redirect(['index']);
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         // gl
         $gl = GlHeader::findOne(['reff_type' => GlHeader::REFF_SALES, 'reff_id' => $id]);
         // movement
         $movement = $gl != null ? GoodsMovement::findOne(['reff_type' => GoodsMovement::REFF_SALES, 'reff_id' => $id]) : null;
         // invoice from movement
         $invoice = $movement != null ? Invoice::findOne(['reff_type' => Invoice::REFF_GOODS_MOVEMENT, 'reff_id' => $movement->id]) : null;
         // payment invoive
         $payments = $invoice != null ? $invoice->payments : [];
         foreach ($payments as $payment) {
             if (!$payment->delete()) {
                 throw new UserException('Cannot delete payment');
             }
         }
         if (count($payments) > 0 && $invoice->delete() && $movement->delete() && $gl->reserve() && $model->delete()) {
             //do nothing
             $transaction->commit();
             return $this->redirect(['index']);
         } else {
             throw new UserException('Something error');
         }
     } catch (\Exception $exc) {
         $transaction->rollBack();
         throw $exc;
     }
 }
示例#6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMovement()
 {
     return $this->hasOne(GoodsMovement::className(), ['id' => 'movement_id']);
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMovements()
 {
     return $this->hasMany(GoodsMovement::className(), ['reff_id' => 'id'])->andOnCondition(['reff_type' => self::REFF_SELF]);
 }
 /**
  * Finds the GoodsMovement model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return GoodsMovement the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GoodsMovement::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#9
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use backend\models\inventory\GoodsMovement;
use backend\models\master\Warehouse;
/* @var $this yii\web\View */
/* @var $searchModel GoodsMovement */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = $searchModel->type == GoodsMovement::TYPE_RECEIVE ? 'Penerimaan' : 'Mutasi';
$this->title = $searchModel->type == GoodsMovement::TYPE_ISSUE ? 'Pengeluaran' : $this->title;
$this->title .= ' Barang';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="col-lg-12">
    <div class='btn-group pull-right'>
        <?php 
echo $searchModel->type ? Html::a($searchModel->type == GoodsMovement::TYPE_RECEIVE ? 'Penerimaan Baru' : 'Pengeluaran Baru', ['inventory/gm-manual/create', 'type' => $searchModel->type], ['class' => 'btn btn-default']) : '';
?>
    </div>
</div>
<br><br>
<div class="col-lg-12 goods-movement-index">
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'tableOptions' => ['class' => 'table table-hover'], 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'number', ['attribute' => 'type', 'value' => 'nmType', 'filter' => GoodsMovement::enums('TYPE_')], 'description', ['attribute' => 'warehouse_id', 'value' => 'warehouse.name', 'filter' => Warehouse::selectOptions()], ['attribute' => 'vendor_id', 'value' => 'vendor.name', 'filter' => \backend\models\master\Vendor::selectOptions()], 'date', ['attribute' => 'status', 'value' => 'nmStatus', 'filter' => GoodsMovement::enums('STATUS_')], ['label' => 'Invoice Number', 'format' => 'raw', 'value' => function ($model) {
    return $model->invoice != null ? Html::a($model->invoice->number, ['/accounting/invoice/view', 'id' => $model->invoice->id]) : '';
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
示例#10
0
 public function revertAdjust()
 {
     $gm = GoodsMovement::findOne(['reff_type' => self::REFF_SELF, 'reff_id' => $this->id]);
     $gm->status = GoodsMovement::STATUS_CANCELED;
     return $gm->save();
 }
示例#11
0
            $items[] = $item;
        }
        return $items;
    }
    protected function findActivePeriode()
    {
        $dPeriode = \backend\models\accounting\AccPeriode::find()->active()->one();
        if ($dPeriode != null) {
            return $dPeriode->id;
        }
        throw new NotFoundHttpException('There is no active periode..');
    }
    /**
     * Execute before child save. If return false, child not saved
     * @param GoodsMovementDtl $child
     * @return boolean Description
     */
    public function beforeRSave($child)
    {
        return $child->qty != 0;
    }
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [['class' => 'mdm\\converter\\DateConverter', 'type' => 'date', 'logicalFormat' => 'php:d-m-Y', 'attributes' => ['Date' => 'date']], 'yii\\behaviors\\BlameableBehavior', 'yii\\behaviors\\TimestampBehavior', ['class' => 'dee\\tools\\StateChangeBehavior', 'states' => [[null, self::STATUS_RELEASED, 'updateStock', 1], [self::STATUS_DRAFT, self::STATUS_RELEASED, 'updateStock', 1], [self::STATUS_DRAFT, self::STATUS_RELEASED, 'postGL', 1], [self::STATUS_RELEASED, self::STATUS_DRAFT, 'updateStock', -1], [self::STATUS_RELEASED, self::STATUS_DRAFT, 'postGL', -1], [self::STATUS_RELEASED, self::STATUS_CANCELED, 'updateStock', -1], [self::STATUS_RELEASED, self::STATUS_CANCELED, 'postGL', -1], [self::STATUS_RELEASED, null, 'updateStock', -1]]]];
    }
}
GoodsMovement::$references = (require 'mv_reference.php');