protected function createInvoice($params)
 {
     $invoice = new InvoiceHdr();
     $invoice->id_vendor = $params['id_vendor'];
     $invoice->inv_date = $params['date'];
     $invoice->inv_value = $params['value'];
     $invoice->type = $params['type'];
     $invoice->due_date = date('Y-m-d', strtotime('+1 month'));
     $invoice->status = 0;
     if (!$invoice->save()) {
         throw new UserException(implode("\n", $invoice->getFirstErrors()));
     }
     $invDtl = new InvoiceDtl();
     $invDtl->id_invoice = $invoice->id_invoice;
     $invDtl->id_reff = $params['id_ref'];
     $invDtl->trans_value = $params['value'];
     if (!$invDtl->save()) {
         throw new UserException(implode("\n", $invDtl->getFirstErrors()));
     }
 }
 public function search($params)
 {
     $query = InvoiceHdrModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id_invoice' => $this->id_invoice, 'type' => $this->type, 'inv_date' => $this->inv_date, 'due_date' => $this->due_date, 'id_vendor' => $this->id_vendor, 'status' => $this->status, 'create_by' => $this->create_by, 'update_by' => $this->update_by]);
     $query->andFilterWhere(['like', 'inv_num', $this->inv_num])->andFilterWhere(['like', 'inv_value', $this->inv_value])->andFilterWhere(['like', 'create_date', $this->create_date])->andFilterWhere(['like', 'update_date', $this->update_date]);
     return $dataProvider;
 }
 /**
  * Finds the InvoiceHdr model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return InvoiceHdr the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = InvoiceHdr::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdInvoices()
 {
     return $this->hasMany(InvoiceHdr::className(), ['id_invoice' => 'id_invoice'])->viaTable('payment_dtl', ['id_payment' => 'id_payment']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdInvoice()
 {
     return $this->hasOne(InvoiceHdr::className(), ['id_invoice' => 'id_invoice']);
 }