i am working in Accounts and i have to add expense. So for that i used the following code inside model
public function accounts_entry($type,$ledger_type,$amount,$against,$remarks,$entity_name,$posting_date,
$ref_no,$ref_date,$payment_method,$fiscal_year)
{
$this->account = $ledger_type;
$this->debit = $amount;
$this->credit = 0;
$this->against = $against;
$this->remarks = $remarks;
$this->entity_name = $entity_name;
....
$this->save();
}
For each entry of expense i have to do two entries into table tabGLEntry(with value in debit and credit fields interchanged). If i try the same code once more then the last value will be saved. How can i save the model two times. I don’t wanna use $model= new Tableglentry ();
In Yii1 i could have used
`$this->unsetAttributes();` after `$this->save();` that way i could have saved both entries. Is there any such way in Yii2? (unsetAttributes is not there in Yii2)
Edit:-
i don’t want to use new model object. so i tried like this
$this->isNewRecord = true;
if($this->save())
{
$this->setAttributes(['account'=>NULL,'debit' => NULL,'credit'=>NULL,'against' => NULL,
'remarks'=>NULL,'entity_name' => NULL,'posting_date'=>NULL,'reference_no' => NULL,'reference_date'=>NULL,
'payment_method_id' => NULL,'voucher_category'=>NULL,'fiscal_year' => NULL,'voucher_no'=>NULL,'name' => NULL,]);
}
so i thought it will solve my problem but it didn’t. I got an error like this
only my first entry is getting saved other one is not because both are getting same id value(Primary key)