Esempio n. 1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getInvoice()
 {
     return $this->hasOne(Invoice::className(), ['id' => 'invoice_id']);
 }
Esempio n. 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getInvoices()
 {
     return $this->hasMany(Invoice::className(), ['id' => 'invoice_id'])->viaTable('{{%payment_dtl}}', ['payment_id' => 'id']);
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     return array_merge($behaviors, [['class' => 'mdm\\converter\\DateConverter', 'attributes' => ['Date' => 'date', 'DueDate' => 'due_date']], ['class' => 'mdm\\converter\\EnumConverter', 'attributes' => ['nmType' => 'type'], 'enumPrefix' => 'TYPE_']]);
 }
Esempio n. 4
0
 /**
  *
  * @param  array                           $data
  * @param  \biz\core\accounting\models\Payment $model
  * @return \biz\core\accounting\models\Payment
  * @throws UserException
  */
 public function createFromInvoice($data, $model = null)
 {
     /* @var $model MPayment */
     $pay_vals = ArrayHelper::map($data['details'], 'id_invoice', 'value');
     $ids = array_keys($pay_vals);
     $invoice_values = Invoice::find()->where(['id_invoice' => $ids])->indexBy('id_invoice')->asArray()->all();
     $vendor = $inv_type = null;
     $vendors = $inv_types = [];
     foreach ($invoice_values as $row) {
         $vendor = $row['id_vendor'];
         $vendors[$vendor] = true;
         $inv_type = $row['invoice_type'];
         $inv_types[$inv_type] = true;
     }
     if (count($vendors) !== 1) {
         throw new UserException('Vendor harus sama');
     }
     if (count($inv_types) !== 1) {
         throw new UserException('Type invoice harus sama');
     }
     $invoice_paid = PaymentDtl::find()->select(['id_invoice', 'total' => 'sum(payment_value)'])->where(['id_invoice' => $ids])->groupBy('id_invoice')->indexBy('id_invoice')->asArray()->all();
     $data['id_vendor'] = $vendor;
     $data['payment_type'] = $inv_type;
     $details = [];
     foreach ($inv_vals as $id => $value) {
         $sisa = $invoice_values[$id]['invoice_value'];
         if (isset($invoice_paid[$id])) {
             $sisa -= $invoice_paid[$id]['total'];
         }
         if ($value > $sisa) {
             throw new UserException('Tagihan lebih besar dari sisa');
         }
         $details[] = ['id_invoice' => $id, 'payment_value' => $value];
     }
     $data['details'] = $details;
     return $this->create($data, $model);
 }