コード例 #1
4
 /**
  *
  * @param \yii\web\Application $app
  * @param array                $config
  */
 protected function initialize($app, $config)
 {
     if ($app instanceof \yii\web\Application) {
         if (ArrayHelper::getValue($config, 'attach_client_behavior', true)) {
             $app->attachBehavior(ClientBehavior::className(), ClientBehavior::className());
         }
         AppHelper::registerAccessHandler(models\Sales::className(), components\AccessHandler::className());
     }
 }
コード例 #2
0
ファイル: Sales.php プロジェクト: jimminababan/sangkilbiz3
 public function search($params)
 {
     $query = SalesModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id_sales' => $this->id_sales, 'id_branch' => $this->id_branch, 'id_customer' => $this->id_customer, 'id_cashdrawer' => $this->id_cashdrawer, 'sales_date' => $this->sales_date, 'status' => $this->status, 'create_by' => $this->create_by, 'update_by' => $this->update_by]);
     $query->andFilterWhere(['like', 'sales_num', $this->sales_num])->andFilterWhere(['like', 'discount', $this->discount])->andFilterWhere(['like', 'create_at', $this->create_at])->andFilterWhere(['like', 'update_at', $this->update_at]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: Sales.php プロジェクト: jimminababan/sangkilbiz3
 public static function modelClass()
 {
     return MSales::className();
 }
コード例 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSaless()
 {
     return $this->hasMany(Sales::className(), ['id_cashdrawer' => 'id_cashdrawer']);
 }
コード例 #5
0
 /**
  * Finds the Sales model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param  integer               $id
  * @return Sales                 the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Sales::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #6
0
ファイル: SalesDtl.php プロジェクト: jimminababan/sangkilbiz3
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdSales()
 {
     return $this->hasOne(Sales::className(), ['id_sales' => 'id_sales']);
 }
コード例 #7
0
ファイル: Invoice.php プロジェクト: jimminababan/sangkilbiz3
 public function createFromSales($data, $model = null)
 {
     $inv_vals = ArrayHelper::map($data['details'], 'id_sales', 'value');
     $ids = array_keys($inv_vals);
     $vendors = [];
     $sales_values = Sales::find()->where(['id_sales' => $ids])->indexBy('id_sales')->asArray()->all();
     $vendor = null;
     foreach ($purchase_values as $row) {
         $vendor = $row['id_customer'];
         $vendors[$row['id_customer']] = true;
     }
     if (count($vendors) !== 1) {
         throw new UserException('Vendor harus sama');
     }
     $sales_invoiced = InvoiceDtl::find()->select(['id_reff', 'total' => 'sum(trans_value)'])->where(['reff_type' => InvoiceDtl::TYPE_SALES, 'id_reff' => $ids])->groupBy('id_reff')->indexBy('id_reff')->asArray()->all();
     $data['id_vendor'] = $vendor;
     $data['invoice_type'] = MInvoice::TYPE_OUT;
     $details = [];
     foreach ($inv_vals as $id => $value) {
         $sisa = $sales_values[$id]['sales_value'] - $purchase_values[$id]['discount'];
         if (isset($sales_invoiced[$id])) {
             $sisa -= $sales_invoiced[$id]['total'];
         }
         if ($value > $sisa) {
             throw new UserException('Tagihan lebih besar dari sisa');
         }
         $details[] = ['id_reff' => $id, 'trans_value' => $value];
     }
     $data['details'] = $details;
     return static::create($data, $model);
 }