예제 #1
0
 public function search($params)
 {
     $query = CoaModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id_coa' => $this->id_coa, 'id_parent' => $this->id_parent, 'coa_type' => $this->coa_type, 'create_by' => $this->create_by, 'update_by' => $this->update_by]);
     $query->andFilterWhere(['like', 'cd_account', $this->cd_account])->andFilterWhere(['like', 'nm_account', $this->nm_account])->andFilterWhere(['like', 'normal_balance', $this->normal_balance])->andFilterWhere(['like', 'create_at', $this->create_at])->andFilterWhere(['like', 'update_at', $this->update_at]);
     return $dataProvider;
 }
예제 #2
0
 public static function getMasters($masters)
 {
     if (!is_array($masters)) {
         $masters = preg_split('/\\s*,\\s*/', trim($masters), -1, PREG_SPLIT_NO_EMPTY);
     }
     $masters = array_flip($masters);
     $result = [];
     if (isset($masters['coa'])) {
         $query = Coa::find()->where(['not', ['id_parent' => null]]);
         //id_parent is not null
         $coas = [];
         foreach ($query->asArray()->all() as $row) {
             $coas[] = ['id' => $row['id_coa'], 'cd_coa' => $row['cd_account'], 'label' => "{$row['cd_account']}-{$row['nm_account']}", 'value' => $row['nm_account']];
         }
         $result['coas'] = $coas;
     }
     return $result;
 }
예제 #3
0
 public function actionCoaList($term = '')
 {
     $query = Coa::find()->orderBy('cd_account');
     if (!empty($term)) {
         $query->where(['LIKE', 'lower(nm_account)', strtolower($term)]);
     }
     $rCoa = [];
     foreach ($query->all() as $row) {
         $rCoa[] = ['id' => $row->id_coa, 'label' => $row->cd_account . ': ' . $row->nm_account];
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return $rCoa;
 }
예제 #4
0
 /**
  * @return integer
  */
 public static function getAccountByCode($code)
 {
     $coa = Coa::findOne(['lower(cd_account)' => strtolower($code)]);
     if ($coa) {
         return $coa->id_coa;
     }
     throw new UserException('Akun tidak ditemukan');
 }
예제 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdCoa()
 {
     return $this->hasOne(Coa::className(), ['id_coa' => 'id_coa']);
 }
예제 #6
0
 public static function getMasters($masters)
 {
     if (!is_array($masters)) {
         $masters = preg_split('/\\s*,\\s*/', trim($masters), -1, PREG_SPLIT_NO_EMPTY);
     }
     $masters = array_flip($masters);
     $result = [];
     // master product
     if (isset($masters['products'])) {
         $products = [];
         $query_master = (new Query())->select(['id' => 'p.id_product', 'cd' => 'p.cd_product', 'nm' => 'p.nm_product', 'u.id_uom', 'u.nm_uom', 'pu.isi'])->from(['p' => '{{%product}}'])->innerJoin(['pu' => '{{%product_uom}}'], 'pu.id_product=p.id_product')->innerJoin(['u' => '{{%uom}}'], 'u.id_uom=pu.id_uom')->orderBy(['p.id_product' => SORT_ASC, 'pu.isi' => SORT_ASC]);
         foreach ($query_master->all() as $row) {
             $id = $row['id'];
             if (!isset($products[$id])) {
                 $products[$id] = ['id' => $row['id'], 'cd' => $row['cd'], 'text' => $row['nm'], 'label' => $row['nm']];
             }
             $products[$id]['uoms'][$row['id_uom']] = ['id' => $row['id_uom'], 'nm' => $row['nm_uom'], 'isi' => $row['isi']];
         }
         $result['products'] = $products;
     }
     // barcodes
     if (isset($masters['barcodes'])) {
         $barcodes = [];
         $query_barcode = (new Query())->select(['barcode' => 'lower(barcode)', 'id' => 'id_product'])->from('{{%product_child}}')->union((new Query())->select(['lower(cd_product)', 'id_product'])->from('{{%product}}'));
         foreach ($query_barcode->all() as $row) {
             $barcodes[$row['barcode']] = $row['id'];
         }
         $result['barcodes'] = $barcodes;
     }
     // price_category
     if (isset($masters['price_category'])) {
         $price_category = [];
         $query_price_category = (new Query())->select(['id_price_category', 'nm_price_category'])->from('{{%price_category}}');
         foreach ($query_price_category->all() as $row) {
             $price_category[$row['id_price_category']] = $row['nm_price_category'];
         }
         $result['price_category'] = $price_category;
     }
     // prices
     if (isset($masters['prices'])) {
         $prices = [];
         $query_prices = (new Query())->select(['p.id_product', 'id_price_category', 'price'])->from(['p' => '{{%product}}'])->leftJoin(['pc' => '{{%price}}'], '[[p.id_product]]=[[pc.id_product]]');
         foreach ($query_prices->all() as $row) {
             if ($row['id_price_category']) {
                 $prices[$row['id_product']][$row['id_price_category']] = $row['price'];
             } else {
                 $prices[$row['id_product']] = [];
             }
         }
         $result['prices'] = $prices;
     }
     // customer
     if (isset($masters['customers'])) {
         $result['customers'] = (new Query())->select(['id' => 'id_customer', 'label' => 'nm_customer'])->from('{{%customer}}')->all();
     }
     // supplier
     if (isset($masters['suppliers'])) {
         $result['suppliers'] = (new Query())->select(['id' => 'id_supplier', 'label' => 'nm_supplier'])->from('{{%supplier}}')->all();
     }
     // product_supplier
     if (isset($masters['product_supplier'])) {
         $prod_supp = [];
         $query_prod_supp = (new Query())->select(['id_supplier', 'id_product'])->from('{{%product_supplier}}');
         foreach ($query_prod_supp->all() as $row) {
             $prod_supp[$row['id_supplier']][] = $row['id_product'];
         }
         $result['product_supplier'] = $prod_supp;
     }
     // product_stock
     if (isset($masters['product_stock'])) {
         $prod_stock = [];
         $query_prod_stock = (new Query())->select(['id_warehouse', 'id_product', 'qty_stock'])->from('{{%product_stock}}');
         foreach ($query_prod_stock->all() as $row) {
             $prod_stock[$row['id_warehouse']][$row['id_product']] = $row['qty_stock'];
         }
         $result['product_stock'] = $prod_stock;
     }
     // accounting
     // coa
     if (isset($masters['coas'])) {
         $query = Coa::find()->where(['not', ['id_parent' => null]]);
         //id_parent is not null
         $coas = [];
         foreach ($query->asArray()->all() as $row) {
             $coas[] = ['id' => $row['id_coa'], 'cd_coa' => $row['cd_account'], 'label' => "{$row['cd_account']}-{$row['nm_account']}", 'value' => $row['nm_account']];
         }
         $result['coas'] = $coas;
     }
     return $result;
 }
예제 #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCoas()
 {
     return $this->hasMany(Coa::className(), ['id_parent' => 'id_coa']);
 }